From: Stefan E. <se...@us...> - 2002-05-10 16:04:25
|
Update of /cvsroot/blob/blob/src/blob In directory usw-pr-cvs1:/tmp/cvs-serv22822 Modified Files: system3.c Log Message: - system update command. Reads images from CF card (stored in a tar file), and flashes them into blob partitions. Index: system3.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/system3.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- system3.c 10 May 2002 14:01:47 -0000 1.19 +++ system3.c 10 May 2002 16:04:23 -0000 1.20 @@ -58,6 +58,11 @@ * defines */ #define CONFIG_PCMCIA_SUPPORT +#define CONFIG_BLOB_PARTITION +#define CONFIG_GIO_RAM +#define CONFIG_GIO_FLASH +#define CONFIG_GIO_BLOB_PARTITION +#define CONFIG_CMD_SYSUPDATE /* this will send a cold shiver through erik's spine ... */ #define ERR( x ) { ret = x; goto DONE; } @@ -290,28 +295,17 @@ void init_ram_default_io( void ) { int ret; - static ram_io_t ram0, ram1; - static io_driver_t io_ram0, io_ram1; + static ram_io_t ram0; + static io_driver_t io_ram0; - /* define 2 pools to play with, each 8 Mb */ - ram0.start=0xd0000000; - ram0.len=8*1024*1024; + ram0.start=RAM_START; + ram0.len=RAM_SIZE; ram0.pos=0; - ram1.start=0xd0800000; - ram1.len=8*1024*1024; - ram1.pos=0; - ret = ram_io_init( &io_ram0, &ram0 ); if ( ret ) return; - ret = ram_io_init( &io_ram1, &ram1 ); - if ( ret ) return; - - ret = io_register( &io_ram0, "RAM0" ); - if ( ret ) return; - - ret = io_register( &io_ram1, "RAM1" ); + ret = io_register( &io_ram0, "RAM" ); if ( ret ) return; } __initlist(init_ram_default_io, INIT_LEVEL_OTHER_STUFF + 2); @@ -344,6 +338,22 @@ sys3_dbg = lvl; printf( "sys3dbg: debug level set to %d\n", sys3_dbg ); + if ( lvl>5 ) { + cf_dbg_set( 5 ); + tar_dbg_set( 5 ); + } else { + cf_dbg_set( 0 ); + tar_dbg_set( 0 ); + } + + if ( lvl>10 ) { + io_dbg_set( 5 ); + pcmcia_dbg_set( 5 ); + } else { + io_dbg_set( 0 ); + pcmcia_dbg_set( 0 ); + } + return 0; } static char sys3dbg_help[] = "sys3dbg level\n"; @@ -404,6 +414,7 @@ } +#if 0 /***************************************************************** * pcmcia_test - test PCMCIA, CF and IDE */ @@ -515,64 +526,98 @@ static char pcmciahelp[] = "pcmcia test\n"; __commandlist(pcmcia_test, "pcmciatest", pcmciahelp); #endif +#endif - -int tar_cmd( int argc, char *argv[] ) -{ - /* FIXME: rewrite using io drivers */ - return -EINVAL; -} -static char tar_help[] = "tar [t|x] src [filename dest]\n"; -__commandlist(tar_cmd, "tar", tar_help); - -#if 0 -extern int io_test(void); -int io_cmd( int argc, char *argv[] ) +#if defined(CONFIG_CMD_SYSUPDATE) +/********************************************************************** + * sysupd - update complete system. Flashes + * blob, config, kernel, initrd and cramfs images. + */ +static int sysupd_cmd( int argc, char *argv[] ) { int ret; - io_driver_t *iotar, *ioram1, *iocf, *iopart; - char buffer[1024]; - - io_dbg_set( 100 ); - tar_dbg_set( 100 ); - - ioram1 = io_get_byname( "RAM1" ); - if ( !ioram1 ) return -EINVAL; - printf( "found 'RAM1': %p\n", ioram1 ); + char *update_files[] = { "blob", "config.tar", "zImage", "initrd.gz", + "cramfs.img", NULL }; + char *image = NULL; + int i=0; + char *source = "CF"; - iopart = io_get_byname( "BLOB_PART" ); - if ( !iopart ) return -EINVAL; - printf( "found 'BLOB_PART': %p\n", iopart ); + if ( argc>1 ) + source = argv[1]; - iotar = io_get_byname( "TAR" ); - if ( !iotar ) return -EINVAL; - printf( "found 'TAR': %p\n", iotar ); + if ( strncmp( source, "CF", 2 ) == 0 ) { + /* CF card is on slot 1 */ + ret = io_configure( "CF", (void *)1 ); + if ( ret ) { + printf( "io_configure() error %d\n", ret ); + return -EINVAL; + } + } - iocf = io_get_byname( "CF" ); - if ( !iocf ) return -EINVAL; - printf( "found 'CF': %p\n", iocf ); + /* write chain: --->blob partition->flash */ + ret = io_chain_driver( "BLOB_PART", "FLASH" ); + if ( ret ) { + DBG( 1, "%s: io_chain_driver() = %d.", __FUNCTION__, ret ); + return ret; + } - /* CF card is on slot 1 */ - ret = io_configure( iocf, (void *)1 ); + /* read chain: <---TAR<--source(CF or RAM) */ + ret = io_chain_driver( "TAR", source ); if ( ret ) { - printf( "io_configure() error %d\n", ret ); - return -EINVAL; + DBG( 1, "%s: io_chain_driver( TAR, %s ) = %d.", __FUNCTION__, source, ret ); + return ret; } - { - /* just a test: read first two sectors ("virtual address" - 0x00000000-0x00001000) into a buffer */ - ret = io_read( buffer, (unsigned char *)0, 1024, iocf ); + while ( (image=update_files[i++]) != NULL ) { + /* select tar file */ + ret = io_configure( "TAR", image ); if ( ret ) { - printf( "io_read() error %d\n", ret ); - return -EINVAL; + printf( "sysupd: can't find image '%s'. Skipping.\n", image ); + continue; } - /* same as above, just use generic io to pool 1 */ - ret = io_copy( ioram1, iocf, 1024 ); + + /* select partition */ + ret = io_configure( "BLOB_PART", image ); if ( ret ) { - printf( "io_copy() error %d\n", ret ); - return -EINVAL; + printf( "sysupd: can't find flash partition '%s'. Skipping.\n", image ); + continue; } + +#if 1 + /* flash tha image, man! */ + ret = io_copy( "BLOB_PART", "TAR", 0 ); + if ( ret ) { + /* ouch! */ + printf( "sysupd: error updating image %s (%d).\n", image, ret ); + return ret; + } +#else + DBG( 1, "%s: io_copy( BLOB_PART, TAR, 0 )\n", __FUNCTION__ ); +#endif + + printf( "sysupd: flashed image '%s'\n", image ); + } + + return 0; +} +static char sysupd_help[] = "sysupd [CF|RAM]\n\nUpdate board firmware from CF card or RAM.\n" + "You have to have a update CF card inserted (for CF updates) _or_ uploaded a\n" + "update image to ram."; +__commandlist(sysupd_cmd, "sysupd", sysupd_help); +#endif + +int io_cmd( int argc, char *argv[] ) +{ + int ret; + + io_dbg_set( 1 ); + tar_dbg_set( 1 ); + + /* CF card is on slot 1 */ + ret = io_configure( "CF", (void *)1 ); + if ( ret ) { + printf( "io_configure() error %d\n", ret ); + return -EINVAL; } /* have tar io driver reading from CF card io driver */ @@ -584,17 +629,17 @@ if ( ret ) return -EINVAL; /* select a file */ - ret = io_configure( iotar, "system3.c" ); + ret = io_configure( "TAR", "blob" ); if ( ret ) return -EINVAL; printf( "selected file\n" ); /* select a partition */ - ret = io_configure( iopart, "config" ); + ret = io_configure( "BLOB_PART", "config" ); if ( ret ) return -EINVAL; printf( "selected partition\n" ); /* copy a file */ - ret = io_copy( iopart, iotar, io_get_size( iotar ) ); + ret = io_copy( "BLOB_PART", "TAR", 0 ); if ( ret ) return -EINVAL; printf( "flashed file\n" ); @@ -603,7 +648,6 @@ } static char io_help[] = "io test function\n"; __commandlist(io_cmd, "iotest", io_help); -#endif #if defined(CONFIG_GIO_BLOB_PARTITION) /********************************************************************** @@ -751,7 +795,7 @@ ret = io_register( &io_flash, "FLASH" ); if ( ret ) return; - ret = io_configure( &io_flash, 0 ); + ret = io_configure( "FLASH", 0 ); if ( ret ) return; return; @@ -860,6 +904,7 @@ return 'a' + (b - 10); } +#if 0 static void dumpmem(char *ptr, int len) { char line[80], chars[80], *p, b, *c, *end; @@ -886,6 +931,8 @@ serial_write('\n'); } } +#endif + /***************************************************************** * manually reference flash and download commands until they * are in libblob. @@ -894,6 +941,7 @@ extern char cf_help[]; __commandlist(cf_test_module, "cftest", cf_help); +#if 0 extern int fwrite_cmd(int argc, char *argv[]); extern char fwrite_help[]; __commandlist(fwrite_cmd, "fwrite", fwrite_help); @@ -901,6 +949,7 @@ extern int ferase_cmd(int argc, char *argv[]); extern char ferase_help[]; __commandlist(ferase_cmd, "ferase", ferase_help); +#endif extern int dlfile_cmd(int argc, char *argv[]); extern char dlfile_help[]; |