freemyipod r834 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r833‎ | r834 | r835 >
Date:23:26, 25 December 2011
Author:theseven
Status:new
Tags:
Comment:
iPod Classic boot menu: Major cleanup operation
Modified paths:
  • /apps/bootmenu-ipodclassic/boot.c (modified) (history)
  • /apps/bootmenu-ipodclassic/boot.h (modified) (history)
  • /apps/bootmenu-ipodclassic/main.c (modified) (history)
  • /apps/bootmenu-ipodclassic/main.h (modified) (history)
  • /apps/bootmenu-ipodclassic/mainchooser.c (modified) (history)
  • /apps/bootmenu-ipodclassic/mainchooser.h (modified) (history)
  • /apps/bootmenu-ipodclassic/settingchooser.c (modified) (history)
  • /apps/bootmenu-ipodclassic/settingchooser.h (modified) (history)
  • /apps/bootmenu-ipodclassic/toolchooser.c (modified) (history)
  • /apps/bootmenu-ipodclassic/toolchooser.h (modified) (history)
  • /apps/bootmenu-ipodclassic/tools.c (modified) (history)
  • /apps/bootmenu-ipodclassic/tools.h (modified) (history)

Diff [purge]

Index: apps/bootmenu-ipodclassic/tools.c
@@ -29,7 +29,7 @@
3030 #include "confirmchooser.h"
3131
3232
33 -void run_clearcfg(void** firmware, void** app, int* size)
 33+void run_clearcfg()
3434 {
3535 if (!run_confirmchooser("Really clear Rockbox config?")) return;
3636 remove("/.rockbox/config.cfg");
@@ -37,7 +37,7 @@
3838 message(97, "Rockbox configuration", " has been cleared. ");
3939 }
4040
41 -void run_cleardb(void** firmware, void** app, int* size)
 41+void run_cleardb()
4242 {
4343 if (!run_confirmchooser("Really clear Rockbox database?")) return;
4444 remove("/.rockbox/database_0.tcd");
@@ -69,7 +69,7 @@
7070 progressbar_setpos((struct progressbar_state*)user, current, false);
7171 }
7272
73 -void run_reformat(void** firmware, void** app, int* size)
 73+void run_reformat()
7474 {
7575 if (!run_confirmchooser("Really reformat data partition?")) return;
7676 memcpy(framebuf, bg, 320 * 240 * 3);
Index: apps/bootmenu-ipodclassic/toolchooser.c
@@ -249,15 +249,13 @@
250250 }
251251 };
252252
253 -void run_toolchooser(void** firmware, void** app, int* size)
 253+void run_toolchooser()
254254 {
255 - while (!*firmware && !*app)
 255+ while (!bootinfo.valid)
256256 {
257257 const struct chooser_item* result = ui->chooser_run(&toolchooser);
258258 if (!result || !result->user) return;
259 - void (*selected_function)(void** firmware, void** app, int* size);
260 - selected_function = (void(*)(void** firmware, void** app, int* size))(result->user);
261 - selected_function(firmware, app, size);
 259+ ((void(*)())(result->user))();
262260 }
263261 }
264262
Index: apps/bootmenu-ipodclassic/settingchooser.c
@@ -199,7 +199,7 @@
200200 }
201201 };
202202
203 -void run_settingchooser(void** firmware, void** app, int* size)
 203+void run_settingchooser()
204204 {
205205 bool changes = ui->settingchooser_run(&settingchooser);
206206 if (changes)
Index: apps/bootmenu-ipodclassic/boot.c
@@ -26,21 +26,23 @@
2727 #include "main.h"
2828
2929
30 -void run_powerdown(void** firmware, void** app, int* size)
 30+void run_powerdown()
3131 {
3232 shutdown(true);
3333 power_off();
3434 }
3535
36 -void fastboot_rockbox(void** firmware, void** app, int* size)
 36+void fastboot_rockbox()
3737 {
38 - boot->load_from_file(firmware, size, true, "/.rockbox/rockbox.ipod", 0);
 38+ boot->load_from_file(&bootinfo.firmware, &bootinfo.size, true, "/.rockbox/rockbox.ipod", 0);
 39+ if (bootinfo.firmware) bootinfo.valid = true;
3940 }
4041
41 -void run_rockbox_fallback(void** firmware, void** app, int* size)
 42+void run_rockbox_fallback()
4243 {
43 - boot->load_from_flash(firmware, size, true, "rockbox ", 0x100000);
44 - if (!*firmware)
 44+ boot->load_from_flash(&bootinfo.firmware, &bootinfo.size, true, "rockbox ", 0x100000);
 45+ if (bootinfo.firmware) bootinfo.valid = true;
 46+ else
4547 {
4648 memcpy(framebuf, bg, 320 * 240 * 3);
4749 message(91, "Loading Rockbox failed!", "Returning to main menu.");
@@ -47,7 +49,7 @@
4850 }
4951 }
5052
51 -void run_rockbox(void** firmware, void** app, int* size)
 53+void run_rockbox()
5254 {
5355 int i;
5456 for (i = 1; i <= 96; i += 19)
@@ -60,23 +62,24 @@
6163 rbxlogo, 0, MAX(0, 86 - i), 280);
6264 displaylcd(0, 0, 320, 240, framebuf, 0, 0, 320);
6365 }
64 - fastboot_rockbox(firmware, app, size);
65 - if (!*firmware)
 66+ fastboot_rockbox();
 67+ if (!bootinfo.valid)
6668 {
6769 message(76, "Loading rockbox.ipod failed!", " Trying fallback image... ");
68 - run_rockbox_fallback(firmware, app, size);
 70+ run_rockbox_fallback();
6971 }
7072 }
7173
72 -void fastboot_umsboot(void** firmware, void** app, int* size)
 74+void fastboot_umsboot()
7375 {
74 - boot->load_from_flash(firmware, size, false, "umsboot ", 0x10000);
 76+ boot->load_from_flash(&bootinfo.firmware, &bootinfo.size, false, "umsboot ", 0x10000);
 77+ if (bootinfo.firmware) bootinfo.valid = true;
7578 }
7679
77 -void run_umsboot(void** firmware, void** app, int* size)
 80+void run_umsboot()
7881 {
79 - fastboot_umsboot(firmware, app, size);
80 - if (!*firmware)
 82+ fastboot_umsboot();
 83+ if (!bootinfo.valid)
8184 {
8285 memcpy(framebuf, bg, 320 * 240 * 3);
8386 message(91, "Loading UMSboot failed!", "Returning to main menu.");
Index: apps/bootmenu-ipodclassic/tools.h
@@ -28,9 +28,9 @@
2929 #include "emcoreapp.h"
3030
3131
32 -extern void run_clearcfg(void** firmware, void** app, int* size);
33 -extern void run_cleardb(void** firmware, void** app, int* size);
34 -extern void run_reformat(void** firmware, void** app, int* size);
 32+extern void run_clearcfg();
 33+extern void run_cleardb();
 34+extern void run_reformat();
3535
3636
3737 #endif
Index: apps/bootmenu-ipodclassic/toolchooser.h
@@ -28,7 +28,7 @@
2929 #include "emcoreapp.h"
3030
3131
32 -extern void run_toolchooser(void** firmware, void** app, int* size);
 32+extern void run_toolchooser();
3333 extern void toolchooser_init();
3434 extern void toolchooser_apply_settings();
3535
Index: apps/bootmenu-ipodclassic/settingchooser.h
@@ -28,7 +28,7 @@
2929 #include "emcoreapp.h"
3030
3131
32 -extern void run_settingchooser(void** firmware, void** app, int* size);
 32+extern void run_settingchooser();
3333 extern void settingchooser_init();
3434 extern void settingchooser_apply_settings();
3535
Index: apps/bootmenu-ipodclassic/mainchooser.c
@@ -171,9 +171,9 @@
172172 }
173173 };
174174
175 -void run_mainchooser(void** firmware, void** app, int* size)
 175+void run_mainchooser()
176176 {
177 - while (!*firmware && !*app)
 177+ while (!bootinfo.valid)
178178 {
179179 const struct chooser_item* result = ui->chooser_run(&mainchooser);
180180 if (!result)
@@ -180,15 +180,15 @@
181181 switch(settings.timeout_item)
182182 {
183183 case 0:
184 - run_powerdown(firmware, app, size);
 184+ run_powerdown();
185185 break;
186186
187187 case 1:
188 - run_rockbox(firmware, app, size);
 188+ run_rockbox();
189189 break;
190190
191191 case 2:
192 - run_umsboot(firmware, app, size);
 192+ run_umsboot();
193193 break;
194194
195195 case 3:
@@ -195,9 +195,7 @@
196196 return;
197197 }
198198 if (!result->user) return;
199 - void (*selected_function)(void** firmware, void** app, int* size);
200 - selected_function = (void(*)(void** firmware, void** app, int* size))(result->user);
201 - selected_function(firmware, app, size);
 199+ ((void(*)())(result->user))();
202200 }
203201 }
204202
Index: apps/bootmenu-ipodclassic/boot.h
@@ -28,12 +28,12 @@
2929 #include "emcoreapp.h"
3030
3131
32 -extern void run_powerdown(void** firmware, void** app, int* size);
33 -extern void fastboot_rockbox(void** firmware, void** app, int* size);
34 -extern void run_rockbox_fallback(void** firmware, void** app, int* size);
35 -extern void run_rockbox(void** firmware, void** app, int* size);
36 -extern void fastboot_umsboot(void** firmware, void** app, int* size);
37 -extern void run_umsboot(void** firmware, void** app, int* size);
 32+extern void run_powerdown();
 33+extern void fastboot_rockbox();
 34+extern void run_rockbox_fallback();
 35+extern void run_rockbox();
 36+extern void fastboot_umsboot();
 37+extern void run_umsboot();
3838
3939
4040 #endif
Index: apps/bootmenu-ipodclassic/mainchooser.h
@@ -28,7 +28,7 @@
2929 #include "emcoreapp.h"
3030
3131
32 -extern void run_mainchooser(void** firmware, void** app, int* size);
 32+extern void run_mainchooser();
3333 extern void mainchooser_init();
3434 extern void mainchooser_apply_settings();
3535
Index: apps/bootmenu-ipodclassic/main.c
@@ -38,6 +38,15 @@
3939 void* bg;
4040 void* icons;
4141 void* rbxlogo;
 42+struct bootinfo_t bootinfo =
 43+{
 44+ .valid = false,
 45+ .firmware = NULL,
 46+ .size = 0,
 47+ .app = NULL,
 48+ .argc = 0,
 49+ .argv = NULL
 50+};
4251
4352
4453 static void main()
@@ -48,28 +57,24 @@
4958 LIBBOOT_API_VERSION, "libboot ");
5059 boot = (struct libboot_api*)libboot->api;
5160
52 - bool terminate = false;
53 - void* firmware = NULL;
54 - void* app = NULL;
55 - int size;
5661
5762 if (!(clickwheel_get_state() & 0x1f))
5863 switch (settings.fastboot_item)
5964 {
6065 case 1:
61 - fastboot_rockbox(&firmware, &app, &size);
 66+ fastboot_rockbox();
6267 break;
6368
6469 case 2:
65 - fastboot_umsboot(&firmware, &app, &size);
 70+ fastboot_umsboot();
6671 break;
6772
6873 case 3:
69 - terminate = true;
 74+ bootinfo.valid = true;
7075 break;
7176 }
7277
73 - if (!firmware && !app && !terminate)
 78+ if (!bootinfo.valid)
7479 {
7580 struct emcorelib_header* libpng = loadlib(LIBPNG_IDENTIFIER, LIBPNG_API_VERSION, "libpng ");
7681 struct libpng_api* png = (struct libpng_api*)libpng->api;
@@ -93,7 +98,7 @@
9499 confirmchooser_init();
95100 snow_init();
96101
97 - run_mainchooser(&firmware, &app, &size);
 102+ run_mainchooser();
98103
99104 free(framebuf2);
100105 free(framebuf);
@@ -107,12 +112,12 @@
108113 release_library(libboot);
109114 library_unload(libboot);
110115
111 - if (firmware)
 116+ if (bootinfo.firmware)
112117 {
113118 shutdown(false);
114 - execfirmware((void*)0x08000000, firmware, size);
 119+ execfirmware((void*)0x08000000, bootinfo.firmware, bootinfo.size);
115120 }
116 - else if (app) execimage(app, false);
 121+ else if (bootinfo.app) execimage(bootinfo.app, false, bootinfo.argc, bootinfo.argv);
117122 else cputs(3, "Dropped into emCORE console.\n");
118123 }
119124
Index: apps/bootmenu-ipodclassic/main.h
@@ -31,6 +31,18 @@
3232 #include "libui.h"
3333
3434
 35+struct bootinfo_t
 36+{
 37+ bool valid;
 38+ void* firmware;
 39+ int size;
 40+ void* app;
 41+ int argc;
 42+ const char** argv;
 43+};
 44+
 45+
 46+extern struct bootinfo_t bootinfo;
3547 extern struct libpng_api* png;
3648 extern struct libboot_api* boot;
3749 extern struct libui_api* ui;