From: Stefan E. <se...@us...> - 2002-05-08 19:23:19
|
Update of /cvsroot/blob/blob/src/blob In directory usw-pr-cvs1:/tmp/cvs-serv14976 Modified Files: system3.c Log Message: - removed dead code - debuglevel & command to set - added io driver for blob partitions. Now one can do a direct io_copy() from/to blob partitions, see io_cmd(). NOTE: Due to a bug in blob/src/blob/partition.c the partition io driver does not work correctly. I'm debugging partition.c ATM. The partition io driver will not stay in system3.c, once it's tested enough it will go in a separate file. Index: system3.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/system3.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- system3.c 8 May 2002 16:02:53 -0000 1.16 +++ system3.c 8 May 2002 19:23:16 -0000 1.17 @@ -85,7 +85,14 @@ #define SYSTEM3_DEBUG 1 #if SYSTEM3_DEBUG -# define _DBG( fmt, args... ) printf("%s(): " fmt, __FUNCTION__ , ## args) +# 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 @@ -99,6 +106,12 @@ * module globals */ +#if SYSTEM3_DEBUG +static int sys3_dbg = 1; +#else +static int sys3_dbg = 0; +#endif + /* flash descriptor for System3 flash. */ /* System 3 uses 2xINTEL e28F640 Chips */ static const flash_descriptor_t system3_flash_descriptors[] = @@ -128,6 +141,12 @@ 0x00300000 CRAMFS 13312k 0x01000000 +Note: + - system3 partitions are named like the files they're flashed + with. This is to keep updating easy: Just loop through all + files that are on our update media and flash them on the partition + named like the file. + */ static const blob_partition_t system3_default_partition_table[] = { { @@ -262,6 +281,39 @@ /* FIXME: need to think if this is the correct init level, we might * want to have this before the param list stuff starts running */ +/********************************************************************** + * init system3 ram pools + */ +void init_ram_default_io( void ) +{ + int ret; + static ram_io_t ram0, ram1; + static io_driver_t io_ram0, io_ram1; + + /* define 2 pools to play with, each 8 Mb */ + ram0.start=0xd0000000; + ram0.len=8*1024*1024; + 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" ); + if ( ret ) return; +} +__initlist(init_ram_default_io, INIT_LEVEL_OTHER_STUFF + 2); + + /***************************************************************** * sysver - print system version */ @@ -273,14 +325,33 @@ static char sysver_help[] = "print BLOB and system3 version number\n"; __commandlist(sysver_cmd, "sysver", sysver_help); +/********************************************************************** + * sys3dbg - set system3 debug level + */ +int sys3dbg_cmd( int argc, char *argv[] ) +{ + int ret; + u32 lvl; + + if ( argc < 2 ) return -EINVAL; + + ret = strtou32(argv[1], &lvl); + if ( ret < 0 ) return -EINVAL; + + sys3_dbg = lvl; + printf( "sys3dbg: debug level set to %d\n", sys3_dbg ); + + return 0; +} +static char sys3dbg_help[] = "sys3dbg level\n"; +__commandlist(sys3dbg_cmd, "sys3dbg", sys3dbg_help); + /***************************************************************** * sa1111_init - initialize companion chip */ static void sa1111_init() { - _DBG( "%s", "START\n" ); - /* * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111: * (SA-1110 Developer's Manual, section 9.1.2.1) @@ -316,11 +387,6 @@ * Ensure all clocks are initially off. */ SKPCR = 0; - - printf( "SA1111 ID: %08x\n", SBI_SKID ); - - - _DBG( "%s", "DONE\n" ); } #if defined(CONFIG_PCMCIA_SUPPORT) @@ -331,15 +397,6 @@ { printf( "PT Digital Board PCMCIA init\n" ); sa1111_init(); -#if SYSTEM3_DEBUG - printf( "MECR=0x%08x\n", MECR ); - printf( "MSC0=0x%08x\n", MSC0 ); - printf( "MSC1=0x%08x\n", MSC1 ); - printf( "MSC2=0x%08x\n", MSC2 ); - printf( "SA1111_BASE=0x%08x\n", SA1111_VBASE ); - printf( "SBI_SMCR=0x%08x\n", SBI_SMCR ); - printf( "SBI_SKID=0x%08x\n", SBI_SKID ); -#endif return 0; } @@ -361,9 +418,6 @@ char buffer[4096]; - /* set ata debg level high */ - //ataio_dbg_set( 5 ); - ret = pcmcia_init(); if ( ret != 0 ) ERR( -EINVAL ); @@ -426,9 +480,6 @@ printf( "slot %d enabled\n", slot ); - //ret = pcmcia_slot_cfg_reg_get( slot, &cfg_reg ); - //if ( ret != 0 ) ERR( -EINVAL ); - ret = ide_init( &drive, (u32)slot_base ); if ( ret != 0 ) ERR( -EINVAL ); @@ -448,42 +499,6 @@ } #endif -#if 0 - printf( "slot %d base address: %x\n", slot, (u32)slot_base ); - printf( "slot %d config register: %x\n", slot, 0x1f0 ); - - pio_set_iobase_addr( (u32)slot_base, (u32)slot_base + 0x1f0 ); - printf( "\nUsing I/O base addresses %x and %x.\n", - (u32)slot_base, (u32)slot_base + 0x1f0 ); - - /* 2) find out what devices are present -- this is the step */ - /* many driver writers ignore. You really can't just do */ - /* resets and commands without first knowing what is out there. */ - /* Even if you don't care the driver does care. */ - numDev = reg_config(); - printf( "\nFound %d devices on this ATA interface:\n", numDev ); - printf( " Device 0 type is %s.\n", devTypeStr[ reg_config_info[0] ] ); - printf( " Device 1 type is %s.\n", devTypeStr[ reg_config_info[1] ] ); - - /* that's the basics, now do some stuff in polling mode */ - - /* do an ATA soft reset (SRST) and return the command block */ - /* regs for device 0 in struct reg_cmd_info */ - printf( "Soft Reset...\n" ); - ret = reg_reset( 0, 0 ); - if ( ret ) ERR( -EINVAL ); - - ret = reg_pio_data_in( - 0, CMD_IDENTIFY_DEVICE, - 0, 0, - 0, 0, 0, - buffer, - 1, 0 - ); - if ( ret != 0 ) ERR( -EINVAL ); - dumpmem( buffer, 512 ); -#endif - ret = pcmcia_dump_stati(); if ( ret != 0 ) ERR( -EINVAL ); @@ -498,99 +513,11 @@ __commandlist(pcmcia_test, "pcmciatest", pcmciahelp); #endif -/***************************************************************** - * misc utility funcs - */ -static char tohex(char b) -{ - b = b & 0xf; - if (b < 10) return '0' + b; - return 'a' + (b - 10); -} - -static void dumpmem(char *ptr, int len) -{ - char line[80], chars[80], *p, b, *c, *end; - int j; - - end = ptr + len; - while (ptr < end) { - SerialOutputHex((int)ptr); - p = line; - c = chars; - - *p++ = ' '; - for (j = 0; j < 16; j++) { - b = *ptr++; - *p++ = tohex(b >> 4); - *p++ = tohex(b); - *p++ = ' '; - *c++ = ' ' <= b && b <= '~' ? b : '.'; - } - *p = 0; - SerialOutputString(line); - *c = 0; - SerialOutputString(chars); - serial_write('\n'); - } -} int tar_cmd( int argc, char *argv[] ) { -#if 0 - int ret = 0; - u32 start = 0; - u32 dest = 0; - tar_arch_t my_arch; - - tar_dbg_set( 100 ); - - if ( argc<3 ) ERR( -EINVAL ); - - ret = strtou32(argv[2], &start); - if ( ret < 0 ) ERR( -EINVAL ); - - arch_adr.start = (unsigned char *)start; - ret = tar_init( &my_arch, mem_block_get, mem_block_reset, &arch_adr ); - if ( ret ) { - printf( "tar_init: %d\n", ret ); - goto DONE; - } - - switch (argv[1][0]) { - case 't': - case 'T': - ret = tar_tell( &my_arch ); - if ( ret ) { - printf( "tar_tell: %d\n", ret ); - goto DONE; - } - break; - case 'x': - case 'X': - if ( argc<4 ) ERR( -EINVAL ); - - ret = strtou32(argv[4], &dest); - if ( ret < 0 ) ERR( -EINVAL ); - - _DBG( "dest=%p\n", (unsigned char *)dest ); - _DBG( "filename=%s\n", argv[3] ); - - ret = tar_xtract( &my_arch, argv[3], (unsigned char *)dest ); - if ( ret ) { - printf( "tar_xtract: %d\n", ret ); - goto DONE; - } - dumpmem( (unsigned char*)dest, 0x200 ); - break; - } - -DONE: - return ret; -#else /* FIXME: rewrite using io drivers */ return -EINVAL; -#endif } static char tar_help[] = "tar [t|x] src [filename dest]\n"; __commandlist(tar_cmd, "tar", tar_help); @@ -599,21 +526,20 @@ int io_cmd( int argc, char *argv[] ) { int ret; - io_driver_t *iotar, *ioram1, *iocf; + io_driver_t *iotar, *ioram1, *iocf, *iopart; char buffer[1024]; - + io_dbg_set( 100 ); tar_dbg_set( 100 ); -#if 0 - ret = io_test(); - if ( ret ) return -EINVAL; -#endif - ioram1 = io_get_byname( "RAM1" ); if ( !ioram1 ) return -EINVAL; printf( "found 'RAM1': %p\n", ioram1 ); + iopart = io_get_byname( "BLOB_PART" ); + if ( !iopart ) return -EINVAL; + printf( "found 'BLOB_PART': %p\n", iopart ); + iotar = io_get_byname( "TAR" ); if ( !iotar ) return -EINVAL; printf( "found 'TAR': %p\n", iotar ); @@ -629,29 +555,55 @@ return -EINVAL; } - ret = io_read( buffer, (unsigned char *)0, 1024, iocf ); - if ( ret ) { - printf( "io_read() error %d\n", ret ); - return -EINVAL; - } - ret = io_copy( ioram1, iocf, 1024 ); - if ( ret ) { - printf( "io_copy() error %d\n", ret ); - return -EINVAL; + { + /* just a test: read first two sectors ("virtual address" + 0x00000000-0x00001000) into a buffer */ + ret = io_read( buffer, (unsigned char *)0, 1024, iocf ); + if ( ret ) { + printf( "io_read() error %d\n", ret ); + return -EINVAL; + } + /* same as above, just use generic io to pool 1 */ + ret = io_copy( ioram1, iocf, 1024 ); + if ( ret ) { + printf( "io_copy() error %d\n", ret ); + return -EINVAL; + } } - /* have tar io driver reading from RAM0 io driver */ - //ret = io_chain_driver( "TAR", "RAM0" ); + /* 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 ram1 (simulate flash) */ + ret = io_chain_driver( "BLOB_PART", "RAM1" ); + if ( ret ) return -EINVAL; + /* select a file */ ret = io_configure( iotar, "system3.c" ); if ( ret ) return -EINVAL; printf( "selected file\n" ); + { + /* NOTE: partition.c code is buggy. The call below + * finds th "config" partition (which is next to the + * "blob" partition). I'm investigating ... + */ + const blob_partition_t *part; + part = pt_find_by_name( "blob" ); + DBG( 1, "%s: part=%p\n", __FUNCTION__, part ); + if ( part ) { + DBG( 1, "part->name=%s\n", part->name ); + } + } + + /* select a partition */ + ret = io_configure( iopart, "blob" ); + if ( ret ) return -EINVAL; + printf( "selected partition\n" ); + /* copy a file */ - ret = io_copy( ioram1, iotar, io_get_size( iotar ) ); + ret = io_copy( iopart, iotar, io_get_size( iotar ) ); if ( ret ) return -EINVAL; printf( "copied file\n" ); @@ -684,13 +636,173 @@ static char io_help[] = "io test function\n"; __commandlist(io_cmd, "iotest", io_help); -extern int cf_test_module( int argc, char *argv[] ); -extern char cf_help[]; -__commandlist(cf_test_module, "cftest", cf_help); +/********************************************************************** + * 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); +} + +/***************************************************************** + * misc utility funcs + */ +static char tohex(char b) +{ + b = b & 0xf; + if (b < 10) return '0' + b; + return 'a' + (b - 10); +} + +static void dumpmem(char *ptr, int len) +{ + char line[80], chars[80], *p, b, *c, *end; + int j; + + end = ptr + len; + while (ptr < end) { + SerialOutputHex((int)ptr); + p = line; + c = chars; + + *p++ = ' '; + for (j = 0; j < 16; j++) { + b = *ptr++; + *p++ = tohex(b >> 4); + *p++ = tohex(b); + *p++ = ' '; + *c++ = ' ' <= b && b <= '~' ? b : '.'; + } + *p = 0; + SerialOutputString(line); + *c = 0; + SerialOutputString(chars); + serial_write('\n'); + } +} /***************************************************************** * manually reference flash and download commands until they * are in libblob. */ +extern int cf_test_module( int argc, char *argv[] ); +extern char cf_help[]; +__commandlist(cf_test_module, "cftest", cf_help); + extern int fwrite_cmd(int argc, char *argv[]); extern char fwrite_help[]; __commandlist(fwrite_cmd, "fwrite", fwrite_help); |