From: Stefan E. <se...@us...> - 2002-05-09 13:29:19
|
Update of /cvsroot/blob/blob/src/blob In directory usw-pr-cvs1:/tmp/cvs-serv10359 Modified Files: system3.c Log Message: - flash io driver Now one can write using io drivers to blob flash partitions. Next step ist the system update function. See io_cmd(). Index: system3.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/system3.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- system3.c 8 May 2002 19:23:16 -0000 1.17 +++ system3.c 9 May 2002 13:29:16 -0000 1.18 @@ -107,7 +107,7 @@ */ #if SYSTEM3_DEBUG -static int sys3_dbg = 1; +static int sys3_dbg = 2; #else static int sys3_dbg = 0; #endif @@ -248,7 +248,7 @@ msleep( 1 ); - //sa1111_init(); + sa1111_init(); MEM(SYSTEM3_CTRL_1) = 0x04; @@ -396,7 +396,7 @@ int pcmcia_init() { printf( "PT Digital Board PCMCIA init\n" ); - sa1111_init(); + //sa1111_init(); return 0; } @@ -575,8 +575,8 @@ 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" ); + /* chain blob partition io driver to flash */ + ret = io_chain_driver( "BLOB_PART", "FLASH" ); if ( ret ) return -EINVAL; /* select a file */ @@ -584,21 +584,8 @@ 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" ); + ret = io_configure( iopart, "config" ); if ( ret ) return -EINVAL; printf( "selected partition\n" ); @@ -606,31 +593,8 @@ ret = io_copy( iopart, iotar, io_get_size( iotar ) ); if ( ret ) return -EINVAL; - printf( "copied file\n" ); - -/* - Future uses/extensions: - - raw flash access: - iofl = io_get_byname( "FLASH" ); - ret = io_configure( iofl, 0x00300000 ); // base offset to r/w - - filesystem access: - iocramfs = io_get_byname( "CRAMFS" ); or - ioext2 = io_get_byname( "EXT2FS" ); or - iofat = io_get_byname( "FAT32" ); - - Partitioning: - iopart = io_get_byname( "BLOBPART" ); - io_configure( iopart, "kernel" ); + printf( "flashed file\n" ); - Flash kernel coming from a cramfs file on CF: - io_chain_driver( "BLOB_PART", "FLASH" ); // write chain - io_chain_driver( "CRAMFS", "CF" ); // read chain - io_configure( iocramfs, "zImage" ); // select "zImage" file - io_configure( iopart, "kernel" ); // select "kernel" partition - io_copy( iopart, iocramfs, io_get_size( iocramfs ) ); - */ return 0; } static char io_help[] = "io test function\n"; @@ -757,6 +721,124 @@ /* defer writing to our child */ return io_write((void *)((u32)dest + part->offset), src, amount, child); +} + +/********************************************************************** + * 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( &io_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( 1, "%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( 1, "%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( 1, "%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( 1, "%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( 1, "%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)); } /***************************************************************** |