From 38abca78d2a58163d622abc88fef3d2a31902c32 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 17 Jun 2011 18:29:05 +0200 Subject: [PATCH] Executor can no execute files. To test: "make MODULE=executor loadables" copy loadable/blinktest.bin to dataflash as test.c0d flash firmware.bin as usual joysitck-right executes test.c0d (joystick-up enters dataflash-masstorage) --- Makefile | 2 +- modules/executor.c | 69 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a146d1e..2f15d6b 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ all: $(OUTFILE).bin protect: $(OUTFILE).bin $(LPCFIX) -p 2 $(OUTFILE).bin -loadables: $(OUTFILE).elf +loadables: $(OUTFILE).bin @cd loadable && $(MAKE) clean: diff --git a/modules/executor.c b/modules/executor.c index 4239a04..975de5e 100644 --- a/modules/executor.c +++ b/modules/executor.c @@ -7,8 +7,6 @@ void backlightInit(void); -#include "loadable/blinktest.h" - void execute (const void *function, uint16_t length){ void (*dst)(void); @@ -27,6 +25,56 @@ void execute (const void *function, uint16_t length){ dst(); }; +#include "filesystem/ff.h" +void put_rc_y (FRESULT rc, int y) { + const TCHAR *p = + _T("OK\0DISK_ERR\0INT_ERR\0NOT_READY\0NO_FILE\0NO_PATH\0INVALID_NAME\0") + _T("DENIED\0EXIST\0INVALID_OBJECT\0WRITE_PROTECTED\0INVALID_DRIVE\0") + _T("NOT_ENABLED\0NO_FILE_SYSTEM\0MKFS_ABORTED\0TIMEOUT\0LOCKED\0") + _T("NOT_ENOUGH_CORE\0TOO_MANY_OPEN_FILES\0"); + FRESULT i; + + for (i = 0; i != rc && *p; i++) { + while(*p++) ; + } + DoString(0,y,p); +} + +void put_rc (FRESULT rc){ + put_rc_y(rc,0); +}; + +void execute_file (const char * fname){ + FRESULT res; + FIL file; + UINT readbytes; + void (*dst)(void); + + dst=(void (*)(void)) 0x10001c00; + + res=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ); + put_rc(res); + if(res){ + return; + }; + + res = f_read(&file, (char *)dst, 1024, &readbytes); + put_rc_y(res,8); + if(res){ + return; + }; + + int dx; + dx=DoString(0,16,"read: "); + DoInt(dx,16,readbytes); + lcdDisplay(0); + + dst=(void (*)(void)) ((uint32_t)(dst) | 1); // Enable Thumb mode! + dst(); + + getInput(); +}; + /**************************************************************************/ void module_executor(void) { @@ -74,9 +122,22 @@ void module_executor(void) { ISPandReset(5); }; - // RAM execute + // DF xecute if(key==BTN_RIGHT){ - execute(loadable_blinktest,loadable_blinktest_size); + DoString(0,0,"Enter RAM!"); + lcdDisplay(0); + while(getInput()!=BTN_NONE); + + FATFS FatFs; /* File system object for logical drive */ + put_rc(f_mount(0, &FatFs)); + + execute_file("0:test.c0d"); + lcdDisplay(0); + while(!getInput()); + }; + + if(key==BTN_UP){ + usbMSCInit(); }; // Display nickname