crashtest-r0ket/firmware/filesystem/execute.c

102 lines
2.3 KiB
C
Raw Normal View History

#include <sysinit.h>
#include <string.h>
#include "basic/basic.h"
#include "lcd/print.h"
#include "usb/usbmsc.h"
#include "filesystem/ff.h"
#include "filesystem/select.h"
#include "basic/xxtea.h"
2011-08-05 15:39:00 +00:00
#include "SECRETS"
2011-08-05 15:39:00 +00:00
//extern void * sram_top;
/**************************************************************************/
2011-08-05 15:39:00 +00:00
uint8_t execute_file (const char * fname){
FRESULT res;
FIL file;
UINT readbytes;
void (*dst)(void);
/* XXX: why doesn't this work? sram_top contains garbage?
dst=(void (*)(void)) (sram_top);
lcdPrint("T:"); lcdPrintIntHex(dst); lcdNl();
*/
dst=(void (*)(void)) (0x10002000 - RAMCODE);
res=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ);
//lcdPrint("open: ");
//lcdPrintln(f_get_rc_string(res));
//lcdRefresh();
if(res){
2011-08-04 14:57:18 +00:00
return -1;
};
2011-08-03 06:59:55 +00:00
res = f_read(&file, (char *)dst, RAMCODE, &readbytes);
//lcdPrint("read: ");
//lcdPrintln(f_get_rc_string(res));
//lcdRefresh();
if(res){
2011-08-04 14:57:18 +00:00
return -1;
};
2011-08-05 15:39:00 +00:00
#ifdef ENCRYPT_L0DABLE
uint32_t *data;
uint32_t len;
2011-08-05 20:32:00 +00:00
uint32_t mac[4];
data = (uint32_t*)dst;
len = readbytes/4;
if( readbytes & 0xF ){
lcdClear();
lcdPrint("!size");
2011-08-05 15:39:00 +00:00
lcdRefresh();
2011-08-05 17:57:47 +00:00
getInputWait();
2011-08-05 20:32:00 +00:00
getInputWaitRelease();
2011-08-05 15:39:00 +00:00
return -1;
}
2011-08-05 20:32:00 +00:00
2011-08-05 15:39:00 +00:00
xxtea_cbcmac(mac, (uint32_t*)dst, len-4, l0dable_sign_key);
if( data[len-4] != mac[0] || data[len-3] != mac[1]
|| data[len-2] != mac[2] || data[len-1] != mac[3] ){
lcdClear();
2011-08-05 20:32:00 +00:00
lcdPrint("!mac");lcdNl();
//lcdPrintIntHex(mac[0]); lcdNl();
//lcdPrintIntHex(mac[1]); lcdNl();
//lcdPrintIntHex(mac[2]); lcdNl();
//lcdPrintIntHex(mac[3]); lcdNl();
2011-08-05 15:39:00 +00:00
lcdRefresh();
2011-08-05 17:57:47 +00:00
getInputWait();
2011-08-05 20:32:00 +00:00
getInputWaitRelease();
2011-08-05 15:39:00 +00:00
return -1;
}
2011-08-05 15:39:00 +00:00
data = (uint32_t*)dst;
len = readbytes/4;
xxtea_decode_words(data, len-4, l0dable_crypt_key);
#endif
dst=(void (*)(void)) ((uint32_t)(dst) | 1); // Enable Thumb mode!
dst();
2011-08-04 14:57:18 +00:00
return 0;
};
/**************************************************************************/
void executeSelect(char *ext){
char filename[15];
filename[0]='0';
filename[1]=':';
filename[2]=0;
if( selectFile(filename+2,ext) == 0)
2011-08-05 15:39:00 +00:00
execute_file(filename);
};