summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/installbootloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/installbootloader.cpp')
-rw-r--r--rbutil/rbutilqt/installbootloader.cpp184
1 files changed, 184 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/installbootloader.cpp b/rbutil/rbutilqt/installbootloader.cpp
index 85dd369693..1061210649 100644
--- a/rbutil/rbutilqt/installbootloader.cpp
+++ b/rbutil/rbutilqt/installbootloader.cpp
@@ -60,6 +60,12 @@ void BootloaderInstaller::install(Ui::InstallProgressFrm* dp)
60 connect(this,SIGNAL(prepare()),this,SLOT(sansaPrepare())); 60 connect(this,SIGNAL(prepare()),this,SLOT(sansaPrepare()));
61 connect(this,SIGNAL(finish()),this,SLOT(sansaFinish())); 61 connect(this,SIGNAL(finish()),this,SLOT(sansaFinish()));
62 } 62 }
63 else if(m_bootloadermethod == "fwpatcher")
64 {
65 // connect internal signal
66 connect(this,SIGNAL(prepare()),this,SLOT(iriverPrepare()));
67 connect(this,SIGNAL(finish()),this,SLOT(iriverFinish()));
68 }
63 else 69 else
64 { 70 {
65 m_dp->listProgress->addItem(tr("unsupported install Method")); 71 m_dp->listProgress->addItem(tr("unsupported install Method"));
@@ -102,6 +108,12 @@ void BootloaderInstaller::uninstall(Ui::InstallProgressFrm* dp)
102 // connect internal signal 108 // connect internal signal
103 connect(this,SIGNAL(prepare()),this,SLOT(sansaPrepare())); 109 connect(this,SIGNAL(prepare()),this,SLOT(sansaPrepare()));
104 } 110 }
111 else if(m_bootloadermethod == "fwpatcher")
112 {
113 m_dp->listProgress->addItem(tr("No uninstallation possible"));
114 emit done(true);
115 return;
116 }
105 else 117 else
106 { 118 {
107 m_dp->listProgress->addItem(tr("unsupported install Method")); 119 m_dp->listProgress->addItem(tr("unsupported install Method"));
@@ -885,4 +897,176 @@ void BootloaderInstaller::sansaFinish()
885 897
886} 898}
887 899
900/**************************************************
901*** iriver /fwpatcher secific code
902***************************************************/
903
904void BootloaderInstaller::iriverPrepare()
905{
906 char md5sum_str[32];
907 if (!FileMD5(m_origfirmware, md5sum_str)) {
908 m_dp->listProgress->addItem(tr("Could not MD5Sum original firmware"));
909 emit done(true);
910 return;
911 }
912
913 /* Check firmware against md5sums in h120sums and h100sums */
914 series = 0;
915 table_entry = intable(md5sum_str, &h120pairs[0],
916 sizeof(h120pairs)/sizeof(struct sumpairs));
917 if (table_entry >= 0) {
918 series = 120;
919 }
920 else
921 {
922 table_entry = intable(md5sum_str, &h100pairs[0],
923 sizeof(h100pairs)/sizeof(struct sumpairs));
924 if (table_entry >= 0)
925 {
926 series = 100;
927 }
928 else
929 {
930 table_entry = intable(md5sum_str, &h300pairs[0],
931 sizeof(h300pairs)/sizeof(struct sumpairs));
932 if (table_entry >= 0)
933 series = 300;
934 }
935 }
936 if (series == 0)
937 {
938 m_dp->listProgress->addItem(tr("Could not detect firmware type"));
939 emit done(true);
940 return;
941 }
942
943 QString url = m_bootloaderUrlBase + "/iriver/" + m_bootloadername;
944
945 m_dp->listProgress->addItem(tr("Downloading file %1.%2")
946 .arg(QFileInfo(url).baseName(), QFileInfo(url).completeSuffix()));
947
948 // temporary file needs to be opened to get the filename
949 downloadFile.open();
950 m_tempfilename = downloadFile.fileName();
951 downloadFile.close();
952 // get the real file.
953 getter = new HttpGet(this);
954 getter->setProxy(m_proxy);
955 getter->setFile(&downloadFile);
956 getter->getFile(QUrl(url));
957 // connect signals from HttpGet
958 connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
959 //connect(getter, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadRequestFinished(int, bool)));
960 connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
961
962}
963
964void BootloaderInstaller::iriverFinish()
965{
966 // Patch firmware
967 char md5sum_str[32];
968 struct sumpairs *sums;
969 int origin;
970
971 /* get pointer to the correct bootloader.bin */
972 switch(series) {
973 case 100:
974 sums = &h100pairs[0];
975 origin = 0x1f0000;
976 break;
977 case 120:
978 sums = &h120pairs[0];
979 origin = 0x1f0000;
980 break;
981 case 300:
982 sums = &h300pairs[0];
983 origin = 0x3f0000;
984 break;
985 }
986
987 // temporary files needs to be opened to get the filename
988 QTemporaryFile firmwareBin, newBin, newHex;
989 firmwareBin.open();
990 newBin.open();
991 newHex.open();
992 QString firmwareBinName = firmwareBin.fileName();
993 QString newBinName = newBin.fileName();
994 QString newHexName = newHex.fileName();
995 firmwareBin.close();
996 newBin.close();
997 newHex.close();
998
999 // iriver decode
1000 if (iriver_decode(m_origfirmware, firmwareBinName, FALSE, STRIP_NONE,m_dp) == -1)
1001 {
1002 m_dp->listProgress->addItem(tr("Error in descramble"));
1003 firmwareBin.remove();
1004 newBin.remove();
1005 newHex.remove();
1006 emit done(true);
1007 return;
1008 }
1009 // mkboot
1010 if (!mkboot(firmwareBinName, newBinName, m_tempfilename, origin,m_dp))
1011 {
1012 m_dp->listProgress->addItem(tr("Error in patching"));
1013 firmwareBin.remove();
1014 newBin.remove();
1015 newHex.remove();
1016 emit done(true);
1017 return;
1018 }
1019 // iriver_encode
1020 if (iriver_encode(newBinName, newHexName, FALSE,m_dp) == -1)
1021 {
1022 m_dp->listProgress->addItem(tr("Error in scramble"));
1023 firmwareBin.remove();
1024 newBin.remove();
1025 newHex.remove();
1026 emit done(true);
1027 return;
1028 }
1029
1030 /* now md5sum it */
1031 if (!FileMD5(newHexName, md5sum_str))
1032 {
1033 m_dp->listProgress->addItem(tr("Error in checksumming"));
1034 firmwareBin.remove();
1035 newBin.remove();
1036 newHex.remove();
1037 emit done(true);
1038 return;
1039 }
1040 if (strncmp(sums[table_entry].patched, md5sum_str, 32) == 0) {
1041 /* delete temp files */
1042 firmwareBin.remove();
1043 newBin.remove();
1044 }
1045
1046 // Load patched Firmware to player
1047 QString dest;
1048 if(series == 100)
1049 dest = m_mountpoint + "/ihp_100.hex";
1050 else if(series == 120)
1051 dest = m_mountpoint + "/ihp_120.hex";
1052 else if(series == 300)
1053 dest = m_mountpoint + "/H300.hex";
1054 // copy file
1055 if(!newHex.copy(dest))
1056 {
1057 m_dp->listProgress->addItem(tr("Could not copy: %1 to %2")
1058 .arg(newHexName,dest));
1059 emit done(true);
1060 return;
1061 }
1062
1063 downloadFile.remove();
1064 newHex.remove();
1065
1066 m_dp->listProgress->addItem(tr("Bootloader install finished successfully."));
1067 m_dp->buttonAbort->setText(tr("&Ok"));
1068
1069 emit done(false); // success
888 1070
1071
1072}