Index: apps/diskmode/Makefile |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | COMPRESS := true |
5 | 5 | |
6 | 6 | EMCOREDIR ?= ../../emcore/trunk/ |
| 7 | +LIBBOOTDIR ?= ../../libs/boot/ |
7 | 8 | |
8 | 9 | ifeq ($(shell uname),WindowsNT) |
9 | 10 | CCACHE := |
— | — | @@ -17,7 +18,7 @@ |
18 | 19 | OBJCOPY := $(CROSS)objcopy |
19 | 20 | ELF2ECA := $(CROSS)elf2emcoreapp |
20 | 21 | |
21 | | -LIBINCLUDES := |
| 22 | +LIBINCLUDES := -I$(LIBBOOTDIR)/export |
22 | 23 | |
23 | 24 | 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 |
24 | 25 | LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --emit-relocs --gc-sections |
Index: apps/diskmode/main.c |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 |
|
28 | 28 |
|
29 | 29 | #include "emcoreapp.h"
|
| 30 | +#include "libboot.h"
|
30 | 31 |
|
31 | 32 |
|
32 | 33 | #define SCSI_TEST_UNIT_READY 0x00
|
— | — | @@ -328,6 +329,16 @@ |
329 | 330 | static volatile bool ejected = false;
|
330 | 331 | static uint8_t __attribute__((aligned(32))) storage_buffer[0x10000];
|
331 | 332 |
|
| 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 | +
|
332 | 343 | static void listen()
|
333 | 344 | {
|
334 | 345 | usb_start_rx(usb, outep, &cbw, sizeof(cbw));
|
— | — | @@ -842,8 +853,18 @@ |
843 | 854 | &usb_c1,
|
844 | 855 | };
|
845 | 856 |
|
| 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 | +
|
846 | 864 | static void main(int argc, const char** argv)
|
847 | 865 | {
|
| 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 | +
|
848 | 869 | storage_get_info(0, &storage_info);
|
849 | 870 |
|
850 | 871 | if (!storage_info.sector_size) panicf(PANIC_KILLTHREAD, "Sector size is zero!\n");
|
— | — | @@ -911,7 +932,30 @@ |
912 | 933 |
|
913 | 934 | usbmanager_uninstall_custom();
|
914 | 935 |
|
| 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 | +
|
915 | 958 | disk_mount(0);
|
| 959 | + execimage(bootinfo.app, false, bootinfo.argc, bootinfo.argv);
|
916 | 960 | }
|
917 | 961 |
|
918 | 962 |
|