freemyipod r909 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r908‎ | r909 | r910 >
Date:00:24, 26 March 2014
Author:user890104
Status:new
Tags:
Comment:
UMSboot: Fix a really nasty bug that prevented booting, thanks to TheSeven
Modified paths:
  • /umsboot/src/app/umsboot/main.c (modified) (history)

Diff [purge]

Index: umsboot/src/app/umsboot/main.c
@@ -106,8 +106,9 @@
107107 console_flush(&umsboot_console);
108108 #endif
109109 int found = 0;
 110+ uint16_t ubicluster = 0;
 111+ uint32_t ubisize = 0;
110112 uint16_t cluster = 0;
111 - uint32_t size = 0;
112113 uint16_t totalclusters = 0;
113114 for (i = 0; i < RAMDISK_SECTORSIZE; i += 32)
114115 if (!RAMDISK[1 + fatsectors][i]) break;
@@ -114,14 +115,17 @@
115116 else if (RAMDISK[1 + fatsectors][i] == 0xe5) continue;
116117 else if (((((uint32_t*)RAMDISK[1 + fatsectors])[(i + 8) >> 2]) & 0xffffff) == 0x494255)
117118 {
118 - cluster = ((uint16_t*)RAMDISK[1 + fatsectors])[(i + 26) >> 1];
119 - size = ((uint32_t*)RAMDISK[1 + fatsectors])[(i + 28) >> 2];
 119+ ubicluster = ((uint16_t*)RAMDISK[1 + fatsectors])[(i + 26) >> 1];
 120+ ubisize = ((uint32_t*)RAMDISK[1 + fatsectors])[(i + 28) >> 2];
120121 RAMDISK[1 + fatsectors][i] = 0xe5;
121122 found++;
122123 }
123 - else if (((uint16_t*)RAMDISK[1 + fatsectors])[(i + 26) >> 1])
124 - totalclusters += (((uint32_t*)RAMDISK[1 + fatsectors])[(i + 28) >> 2]
125 - + RAMDISK_SECTORSIZE - 1) / RAMDISK_SECTORSIZE;
 124+ else if ((cluster = ((uint16_t*)RAMDISK[1 + fatsectors])[(i + 26) >> 1]))
 125+ while (cluster != 0xffff)
 126+ {
 127+ cluster = ((uint16_t*)RAMDISK[1])[cluster];
 128+ totalclusters++;
 129+ }
126130 if (!found)
127131 {
128132 #ifdef UMSBOOT_HAVE_CONSOLE
@@ -138,7 +142,7 @@
139143 #endif
140144 continue;
141145 }
142 - if (!size || !cluster)
 146+ if (!ubisize || !ubicluster)
143147 {
144148 #ifdef UMSBOOT_HAVE_CONSOLE
145149 console_puts(&umsboot_console, "UBI file is empty!\nPlease retry.\n");
@@ -147,11 +151,11 @@
148152 continue;
149153 }
150154 uint16_t dest = 0;
151 - while (cluster != 0xffff)
 155+ while (ubicluster != 0xffff)
152156 {
153 - swap(fatsectors + cluster, dest++);
154 - cluster = ((uint16_t*)RAMDISK[swapmap[1 + (cluster / (RAMDISK_SECTORSIZE / 2))]])
155 - [cluster % (RAMDISK_SECTORSIZE / 2)];
 157+ swap(fatsectors + ubicluster, dest++);
 158+ ubicluster = ((uint16_t*)RAMDISK[swapmap[1 + (ubicluster / (RAMDISK_SECTORSIZE / 2))]])
 159+ [ubicluster % (RAMDISK_SECTORSIZE / 2)];
156160 }
157161 #ifdef UMSBOOT_HAVE_CONSOLE
158162 console_puts(&umsboot_console, "Rearranging files...\n");
@@ -171,7 +175,6 @@
172176 {
173177 memcpy(&newdir[newptr], &RAMDISK[swapmap[1 + fatsectors]][i], 0x20);
174178 cluster = ((uint16_t*)newdir)[(newptr + 26) >> 1];
175 - size = ((uint32_t*)newdir)[(newptr + 28) >> 2];
176179 if (cluster)
177180 {
178181 ((uint16_t*)newdir)[(newptr + 26) >> 1] = dest;
@@ -195,6 +198,10 @@
196199 console_puts(&umsboot_console, "Booting UBI file...");
197200 console_flush(&umsboot_console);
198201 #endif
 202+#ifdef DEBUG
 203+ continue;
 204+#else
199205 execfirmware(RAMDISK[0]);
 206+#endif
200207 }
201208 }