From e2520eaa746fd7b4f04f1136da7387f46bc9638a Mon Sep 17 00:00:00 2001 From: oyvind Date: Wed, 30 Dec 2009 10:08:59 +0000 Subject: [PATCH] bootloader: add capability to load and run file from ram MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This gives us last chance to bail us out if we screw up the bootloader. Signed-off-by: Øyvind Harboe git-svn-id: http://www.ecosforge.net/ecosforge/trunk/nios2ecos@342 2333b21a-1c27-0410-8132-afba56cb5048 --- bootloader/bootloader/bootloader.c | 43 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/bootloader/bootloader/bootloader.c b/bootloader/bootloader/bootloader.c index 021b5df..0a31fd6 100644 --- a/bootloader/bootloader/bootloader.c +++ b/bootloader/bootloader/bootloader.c @@ -656,6 +656,39 @@ static void upgrade(upgrade_info upgraded_file) } +/* load app into ram and run it. The application will need + * a memory independant piece of code to begin with that + * can be used to launch itself. + */ +static void runfile(const char *name) +{ + struct stat results; + if (stat(name, &results) != 0) + { + fprintf(ser_fp, "Error: could not get length of file"); + reset(); + } + + int runfile_fd; + if ((runfile_fd = open(name, O_RDONLY)) <= 0) + { + fprintf(ser_fp, "Error: failed to open file"); + reset(); + } + void * mem = malloc(results.st_size); + + read(runfile_fd, mem, results.st_size); + + cyg_interrupt_disable(); + ((void(*)(void)) (mem))(); + for (;;) + { + + } + /* never reached */ +} + + static void ymodemUpload(const char *fileName) { int err = 0; @@ -807,18 +840,24 @@ void menu(void) goto start_menu; case '\r': fprintf(ser_fp, "Default firmware file update\r\n"); - ymodemUpload(firmware.file); //fall through + ymodemUpload(firmware.file); upgrade(firmware); break; case 'Y': fprintf(ser_fp, "Single shot bootloader update\r\n"); - ymodemUpload(bootloader.file); //fall through + ymodemUpload(bootloader.file); upgrade(bootloader); break; + case 'R': + fprintf(ser_fp, "Upload and run file from RAM\r\n"); + ymodemUpload("/ram/run"); + runfile("/ram/run"); + break; case ' ': fprintf(ser_fp, "Press format flash\r\n"); fprintf(ser_fp, "Press to start Ymodem upload of a file to a specified file name\r\n"); + fprintf(ser_fp, "Press run file from RAM\r\n"); fprintf(ser_fp, "Press to start single shot update of bootloader\r\n"); fprintf(ser_fp, "Press

set parameter\r\n"); fprintf(ser_fp, "Press show parameter\r\n"); -- 2.11.4.GIT