freemyipod r918 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r917‎ | r918 | r919 >
Date:17:23, 27 April 2014
Author:user890104
Status:new
Tags:
Comment:
diskmode: Make it more friendly to the users
Modified paths:
  • /apps/diskmode/Makefile (modified) (history)
  • /apps/diskmode/main.c (modified) (history)

Diff [purge]

Index: apps/diskmode/Makefile
@@ -3,6 +3,7 @@
44 COMPRESS := true
55
66 EMCOREDIR ?= ../../emcore/trunk/
 7+LIBBOOTDIR ?= ../../libs/boot/
78
89 ifeq ($(shell uname),WindowsNT)
910 CCACHE :=
@@ -17,7 +18,7 @@
1819 OBJCOPY := $(CROSS)objcopy
1920 ELF2ECA := $(CROSS)elf2emcoreapp
2021
21 -LIBINCLUDES :=
 22+LIBINCLUDES := -I$(LIBBOOTDIR)/export
2223
2324 CFLAGS += -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -I$(EMCOREDIR)/export $(LIBINCLUDES) -ffunction-sections -fdata-sections -mcpu=arm940t -DARM_ARCH=4 -marm
2425 LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --emit-relocs --gc-sections
Index: apps/diskmode/main.c
@@ -26,6 +26,7 @@
2727
2828
2929 #include "emcoreapp.h"
 30+#include "libboot.h"
3031
3132
3233 #define SCSI_TEST_UNIT_READY 0x00
@@ -328,6 +329,16 @@
329330 static volatile bool ejected = false;
330331 static uint8_t __attribute__((aligned(32))) storage_buffer[0x10000];
331332
 333+struct bootinfo_t
 334+{
 335+ bool valid;
 336+ void* firmware;
 337+ int size;
 338+ void* app;
 339+ int argc;
 340+ const char** argv;
 341+};
 342+
332343 static void listen()
333344 {
334345 usb_start_rx(usb, outep, &cbw, sizeof(cbw));
@@ -842,8 +853,18 @@
843854 &usb_c1,
844855 };
845856
 857+struct emcorelib_header* loadlib(uint32_t identifier, uint32_t version, char* filename)
 858+{
 859+ struct emcorelib_header* lib = get_library(identifier, version, LIBSOURCE_BOOTFLASH, filename);
 860+ if (!lib) panicf(PANIC_KILLTHREAD, "Could not load %s", filename);
 861+ return lib;
 862+}
 863+
846864 static void main(int argc, const char** argv)
847865 {
 866+ cprintf(3, "Welcome to Disk mode! Please wait until your device is detected by your operating system. It should not take more than 1-2 minutes. In case of issues, please ask for support.\n\n");
 867+ cprintf(3, "When you're done transferring files, please use your operating system's Eject/Unmount option before unplugging the device.\n\n");
 868+
848869 storage_get_info(0, &storage_info);
849870
850871 if (!storage_info.sector_size) panicf(PANIC_KILLTHREAD, "Sector size is zero!\n");
@@ -911,7 +932,30 @@
912933
913934 usbmanager_uninstall_custom();
914935
 936+ cprintf(3, "Disk mode completed successfully. Returning to the bootmenu...\n\n");
 937+
 938+ struct bootinfo_t bootinfo =
 939+ {
 940+ .valid = false,
 941+ .firmware = NULL,
 942+ .size = 0,
 943+ .app = NULL,
 944+ .argc = 0,
 945+ .argv = NULL
 946+ };
 947+
 948+ struct emcorelib_header* libboot = loadlib(LIBBOOT_IDENTIFIER,
 949+ LIBBOOT_API_VERSION, "libboot ");
 950+ struct libboot_api* boot = (struct libboot_api*)libboot->api;
 951+
 952+ boot->load_from_flash(&bootinfo.app, &bootinfo.size, false, "bootmenu", 0);
 953+
 954+ if (!bootinfo.app) {
 955+ panicf(PANIC_KILLTHREAD, "Unable to start the bootmenu! Press MENU+SELECT to reboot your device.\n");
 956+ }
 957+
915958 disk_mount(0);
 959+ execimage(bootinfo.app, false, bootinfo.argc, bootinfo.argv);
916960 }
917961
918962