From: Stefan E. <se...@us...> - 2003-04-03 14:47:47
|
Update of /cvsroot/blob/blob/src/blob In directory sc8-pr-cvs1:/tmp/cvs-serv9892 Modified Files: system3.c Log Message: - removed #ifdef hell and moved commands and library functions where they belong to. Index: system3.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/system3.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- system3.c 1 Apr 2003 19:01:29 -0000 1.27 +++ system3.c 3 Apr 2003 14:47:42 -0000 1.28 @@ -55,21 +55,12 @@ #include <blob/cf.h> #include <blob/ide.h> #include <blob/tar.h> +#include <net/net.h> #include <net/smc9196.h> /********************************************************************** * 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; } - /* more readable IMHO */ #define MEM( x ) (*((u32 *)(x))) #define SET(reg,bit) ((reg) |= (1<<(bit))) @@ -79,13 +70,8 @@ #if SYSTEM3_DEBUG # define DBG( x, args... ) if ( sys3_dbg>x ) printf( args ) -# define DBGIO( x, io ) if ( sys3_dbg>x ) printf( "%s: " \ - "%s(%p)={ c=%p, r=%p, w=%p,\n\tp=%p, sz=%d, ch=%p,\n\tn='%s' }\n", \ - __FUNCTION__, #io, io, io->conf, io->read, io->write, \ - io->private_data, io->io_size, io->child_io, io->name ); #else # define DBG( x, args... ) -# define DBGIO( x, io ) #endif @@ -196,7 +182,7 @@ next: sizeof(blob_partition_t), offset: ROOTFS_FLASH_BASE, size: ROOTFS_FLASH_LEN, - name: "root.img", + name: "cramfs", flags: BLOB_PART_FLAG_CRAMFS, }, { @@ -270,49 +256,7 @@ } __initlist(system3_init_hardware, INIT_LEVEL_DRIVER_SELECTION); -#if defined(CONFIG_BLOB_PARTITION) -/********************************************************************** - * system3 default partition table - */ -static void system3_set_partition_table(void) -{ - /* the default partition table */ - default_partition_table = system3_default_partition_table; - - /* we don't know where the flash partition table will live, so - * put the pointer at 0x0000000 and let the partition table - * parser figure out. - */ - flash_partition_table = (blob_partition_t*)0x00000000; -} -__initlist(system3_set_partition_table, INIT_LEVEL_OTHER_STUFF); -/* FIXME: need to think if this is the correct init level, we might - * want to have this before the param list stuff starts running */ -#endif - -#if defined(CONFIG_GIO_RAM) -/********************************************************************** - * init system3 ram pools - */ -void init_ram_default_io( void ) -{ - int ret; - static ram_io_t ram0; - static io_driver_t io_ram0; - - ram0.start=RAM_START; - ram0.len=RAM_SIZE; - ram0.pos=0; - - ret = ram_io_init( &io_ram0, &ram0 ); - if ( ret ) return; - - ret = io_register( &io_ram0, "RAM" ); - if ( ret ) return; -} -__initlist(init_ram_default_io, INIT_LEVEL_OTHER_STUFF + 2); -#endif /***************************************************************** * sysver - print system version @@ -346,6 +290,7 @@ */ int sys3dbg_cmd( int argc, char *argv[] ) { + extern int cf_dbg_set(int); int ret; u32 lvl; @@ -437,412 +382,9 @@ } #endif -#if defined(CONFIG_CMD_SYSUPDATE) -/********************************************************************** - * sysupd - update complete system. Flashes - * blob, config, kernel, initrd and cramfs images. - */ - -/* update_umage - Read image "image" from TAR io driver and flash it - * into a BLOB partition - */ -static int update_image( char *image ) -{ - int ret; - - if ( !image ) - return -EINVAL; - - /* select tar file */ - ret = io_configure( "TAR", image ); - if ( ret ) { - printf( "sysupd: can't find image '%s'. Skipping.\n", image ); - return -EINVAL; - } - - /* select partition */ - ret = io_configure( "BLOB_PART", image ); - if ( ret ) { - printf( "sysupd: can't find flash partition '%s'. Skipping.\n", image ); - return -EINVAL; - } - -#if !defined(SYSUPD_DUMMY_COPY) - /* 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 - - return 0; -} - -static int sysupd_cmd( int argc, char *argv[] ) -{ - int ret; - char *update_files[] = { "blob", "config.tar", "zImage", "initrd.gz", - "root.img", "data.img", NULL }; - char *image = NULL; - int i=0; - char *source = "CF"; - - argv++; - - /* source io param */ - if ( argc>1 ) { - source = *argv; - argv++; - argc--; - } - - /* image list */ - if ( argc>1 ) { - char **ptr; - ptr = update_files; - while (argc && ptr ) { - *ptr = *argv; - DBG( 1, "image += '%s'\n", *ptr ); - - argc -= 1; - argv++; - ptr++; - } - *ptr = NULL; - } - - /* configure CF card if CF is source */ - 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; - } - } - - /* 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; - } - - /* read chain: <---TAR<--source(CF or RAM) */ - ret = io_chain_driver( "TAR", source ); - if ( ret ) { - DBG( 1, "%s: io_chain_driver( TAR, %s ) = %d.", __FUNCTION__, source, ret ); - return ret; - } - - /* update all images in list */ - while ( (image=update_files[i++]) != NULL ) { - ret = update_image( image ); - if ( ret == 0 ) - printf( "sysupd: flashed image '%s'\n", image ); - } - - return 0; -} -static char sysupd_help[] = "sysupd [CF|RAM] [image [image]...]\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 - -#if defined(IO_TEST) -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 */ - ret = io_chain_driver( "TAR", "CF" ); - if ( ret ) return -EINVAL; - - /* chain blob partition io driver to flash */ - ret = io_chain_driver( "BLOB_PART", "FLASH" ); - if ( ret ) return -EINVAL; - - /* select a file */ - ret = io_configure( "TAR", "blob" ); - if ( ret ) return -EINVAL; - printf( "selected file\n" ); - - /* select a partition */ - ret = io_configure( "BLOB_PART", "config" ); - if ( ret ) return -EINVAL; - printf( "selected partition\n" ); - - /* copy a file */ - ret = io_copy( "BLOB_PART", "TAR", 0 ); - if ( ret ) return -EINVAL; - - printf( "flashed file\n" ); - - return 0; -} -static char io_help[] = "io test function\n"; -__commandlist(io_cmd, "iotest", io_help); -#endif - -#if defined(CONFIG_GIO_BLOB_PARTITION) -/********************************************************************** - * blob partition io driver - * - * - default blob partition is registered as a default io driver - * - the configure call "selects" a partition by it's name. - * (just like the tar io driver) - */ -int part_io_init( io_driver_t *io ); -static int part_io_conf( io_driver_t * io, void *conf ); -static int part_io_read( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ); -static int part_io_write( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ); - -/* register default blob partition io driver */ -void init_part_default_io( void ) -{ - int ret; - static io_driver_t io_part; - - ret = part_io_init( &io_part ); - if ( ret ) return ; - - ret = io_register( &io_part, "BLOB_PART" ); - if ( ret ) return; - - return; -} -__initlist(init_part_default_io, INIT_LEVEL_OTHER_STUFF + 3); - -/* initialize driver struct */ -int part_io_init( io_driver_t *io ) -{ - if ( !io ) - return -EINVAL; - - io->private_data = NULL; - io->io_size = 0; - io->conf = part_io_conf; - io->read = part_io_read; - io->write = part_io_write; - io->child_io = NULL; - - return 0; -} - -/* configure: select a partition by name */ -static int part_io_conf( io_driver_t * io, void *conf ) -{ - char *name; - const blob_partition_t *part; - - if ( !io || !conf ) - return -EINVAL; - - name = (char *)conf; - if ( !name ) - return -EINVAL; - - part = pt_find_by_name( name ); - if ( !part ) - return -EINVAL; - - DBG( 1, "%s: found partition '%s': offset=%x, size=%x, flags=%x\n", __FUNCTION__, - part->name, part->offset, part->size, part->flags ); - - - io->io_size=part->size; - io->private_data=(void*)part; - - return 0; -} - -static int part_io_read( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ) -{ - blob_partition_t *part; - io_driver_t *child; - - DBG( 1, "%s: dest=%p, src=%p, amount=%d, io=%p\n", __FUNCTION__, - dest, src, amount, io ); - - if ( !io || !dest ) - return -EINVAL; - - child = io_get_child( io ); - if ( !child ) - return -EINVAL; - - part = (blob_partition_t *)io->private_data; - if ( !part ) - return -EINVAL; - - DBG( 1, "%s: using partition '%s'.\n", __FUNCTION__, part->name ); - DBG( 1, "%s: dest=%p, src=%p(=%p), amount=%d, io=%p\n", __FUNCTION__, - dest, src, (void*)(src + part->offset), amount, io ); - - /* defer reading to our child */ - return io_read(dest, (void *)((u32)src + part->offset), amount, child); -} - -static int part_io_write( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ) -{ - blob_partition_t *part; - io_driver_t *child; - - - if ( !io || !src ) - return -EINVAL; - - child = io_get_child( io ); - if ( !child ) - return -EINVAL; - - part = (blob_partition_t *)io->private_data; - if ( !part ) - return -EINVAL; - - DBG( 1, "%s: using partition '%s'.\n", __FUNCTION__, part->name ); - DBG( 1, "%s: dest=%p(=%p), src=%p, amount=%d, io=%p\n", __FUNCTION__, - dest, (void*)(dest + part->offset), src, amount, io ); - - /* defer writing to our child */ - return io_write((void *)((u32)dest + part->offset), src, amount, child); -} -#endif - -#if defined(CONFIG_GIO_FLASH) -/********************************************************************** - * flash io driver - */ -int flash_io_init( io_driver_t *io ); -static int flash_io_conf( io_driver_t * io, void *conf ); -static int flash_io_read( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ); -static int flash_io_write( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ); - -/* register flash io driver */ -void init_flash_default_io( void ) -{ - int ret; - static io_driver_t io_flash; - - ret = flash_io_init( &io_flash ); - if ( ret ) return ; - - ret = io_register( &io_flash, "FLASH" ); - if ( ret ) return; - - ret = io_configure( "FLASH", 0 ); - if ( ret ) return; - - return; -} -__initlist(init_flash_default_io, INIT_LEVEL_OTHER_STUFF + 3); - -/* initialize driver struct */ -int flash_io_init( io_driver_t *io ) -{ - if ( !io ) - return -EINVAL; - - io->private_data = NULL; - io->io_size = 0; - io->conf = flash_io_conf; - io->read = flash_io_read; - io->write = flash_io_write; - io->child_io = NULL; - - return 0; -} - -/* configure: select a base offset within the flash */ -static int flash_io_conf( io_driver_t * io, void *conf ) -{ - u32 offset; - - if ( !io ) - return -EINVAL; - - offset = (u32)conf; - - io->io_size = flash_get_size(); - - if ( offset > io->io_size ) - return -ERANGE; - - io->private_data=(void *)offset; - - return 0; -} - -static int flash_io_read( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ) -{ - u32 offset; - - DBG( 5, "%s: dest=%p, src=%p, amount=%d, io=%p\n", __FUNCTION__, - dest, src, amount, io ); - - if ( !io || !dest ) - return -EINVAL; - - - offset = (u32)io->private_data; - - DBG( 5, "%s: using offset %x.\n", __FUNCTION__, offset ); - - memcpy( dest, (unsigned char *)(offset + (u32)src), amount ); - - return 0; -} - -/* flash write: only on word boundaries! */ -static int flash_io_write( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ) -{ - u32 offset; - u32 adr; - - DBG( 5, "%s: dest=%p, src=%p, amount=%d, io=%p\n", __FUNCTION__, - dest, src, amount, io ); - if ( !io || !src ) - return -EINVAL; - offset = (u32)io->private_data; - DBG( 5, "%s: using offset %x.\n", __FUNCTION__, offset ); - - adr = (u32)dest + offset; - - /* check alignment */ - if ( adr%4 ) { - printf( "%s: misaligned destination address (%x).\n", - __FUNCTION__, adr ); - return -EALIGN; - } - if ( amount%4 ) { - printf( "%s: warning: misaligned amount to write (%d).\n", - __FUNCTION__, amount ); - } - - DBG( 5, "%s: adr=0x%08x, nwords=%d.\n", __FUNCTION__, - adr, amount/4 + (amount%4?1:0)); - - return flash_write_region( (u32 *)adr, (u32*)src, amount/4 + (amount%4?1:0)); -} -#endif /***************************************************************** * misc utility funcs @@ -852,12 +394,6 @@ * manually reference flash and download commands until they * are in libblob. */ -#if 0 -extern int cf_test_module( int argc, char *argv[] ); -extern char cf_help[]; -__commandlist(cf_test_module, "cftest", cf_help); -#endif - #if 1 extern int fwrite_cmd(int argc, char *argv[]); extern char fwrite_help[]; @@ -898,7 +434,6 @@ { int ret = 0; extern int do_arp( u8 *, u8 *); - u8 serverip[4] = { 192, 168, 1, 11 }; u8 servereth[6]; ret = smc_init( 0x18000000 ); @@ -907,7 +442,7 @@ return ret; } - ret = do_arp( servereth, serverip ); + ret = do_arp( servereth, serveripaddress ); printf( "%s: got eth addr %02x:%02x:%02x:%02x:%02x:%02x\n", __FUNCTION__, servereth[0], servereth[1], servereth[2], servereth[3], servereth[4], @@ -918,97 +453,24 @@ char arp_help[] = "arp test command. No args.\n";; __commandlist(arp_cmd, "arp", arp_help); - -int setip_cmd( int argc, char *argv[] ) +#if defined(CONFIG_BLOB_PARTITION) +/********************************************************************** + * system3 default partition table + */ +static void system3_set_partition_table(void) { - extern u8 clientipaddress[4]; - extern u8 serveripaddress[4]; - u8 *ip; - char *ptr, *num; - int i, fini; - - if ( argc < 3 ) - return -EINVAL; - - switch ( argv[1][0] ) { - case 'c': - case 'C': - ip = clientipaddress; - break; - case 's': - case 'S': - ip = serveripaddress; - break; - default: - return -EINVAL; - break; - } - - num = ptr = argv[2]; - fini=0; - for ( i=0; i<4 || !fini; i++ ) { - u32 n; - - while ( *ptr != '\0' && *ptr != '.' ) - ptr++; - - if ( *ptr == '\0' ) - fini = 1; - - *ptr = 0; - - strtou32( num, &n ); - ip[i]=n; - - num = ++ptr; - } - - if ( fini && i<4 ) { - printf( "error parsing ip.\n" ); - return -EINVAL; - } - - printf( "Set IP to %d.%d.%d.%d\n", - ip[0], ip[1], ip[2], ip[3] ); - - return 0; + /* the default partition table */ + default_partition_table = system3_default_partition_table; + + /* we don't know where the flash partition table will live, so + * put the pointer at 0x0000000 and let the partition table + * parser figure out. + */ + flash_partition_table = (blob_partition_t*)0x00000000; } -char setip_help[] = "setip command. Set IP addresses for tftp.\n" -"usage: setip {client|server} ip\n" -"\tip in usual dotted-quad format please.\n";; -__commandlist(setip_cmd, "setip", setip_help); - -int tftp_cmd(int argc, char *argv[]) -{ - int ret = 0; - extern int do_tftp(char *file, unsigned long addr, unsigned long *size); - unsigned long size = 0; - char *tftp_file = "update.tar"; - - if ( argc>1 ) { - tftp_file = argv[1]; - } else { - printf( "No filename given, using '%s'\n", - tftp_file ); - } - - ret = smc_init( 0x18000000 ); - if ( ret ) { - printf( "smc_init failed: %d\n", ret ); - return ret; - } - ret = do_tftp( tftp_file, RAM_START, &size ); - if ( ret ) { - return -EINVAL; - } +__initlist(system3_set_partition_table, INIT_LEVEL_OTHER_STUFF); +/* FIXME: need to think if this is the correct init level, we might + * want to have this before the param list stuff starts running */ +#endif - printf( "%s: file '%s' loaded via tftp to address 0x%08x.\n", - __FUNCTION__, tftp_file, RAM_START ); - return 0; -} -char tftp_help[] = "tftp command.\n" -"usage: tftp filename\n" -"\tdownloads file over TFTP to RAM.\n" -"\tUse setip to set client and server IP addresses\n"; -__commandlist(tftp_cmd, "tftp", tftp_help); |