From: Stefan E. <se...@us...> - 2003-04-03 14:32:55
|
Update of /cvsroot/blob/blob/src/lib In directory sc8-pr-cvs1:/tmp/cvs-serv1077 Added Files: gio_flash.c gio_part_blob.c gio_ram.c Log Message: - gio "drivers" for flash, ram and blob partitions. Needed for the sysupd command. --- NEW FILE: gio_flash.c --- /********************************************************************** * GIO flash "driver" * * Copyright (C) 2003, Stefan Eletzhofer <ste...@el...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: gio_flash.c,v 1.1 2003/04/03 14:32:50 seletz Exp $ * */ /********************************************************************** * Includes */ #ifdef HAVE_CONFIG_H # include <blob/config.h> #endif #include <blob/types.h> #include <blob/errno.h> #include <blob/util.h> #include <blob/command.h> #include <blob/init.h> #include <blob/flash.h> #include <blob/generic_io.h> /********************************************************************** * defines */ #define DEBUG 0 #if DEBUG # define DBG( x, args... ) if ( dbg>=x ) printf( args ); #else # define DBG( x, args... ) #endif /********************************************************************** * module globals */ #if DEBUG static int dbg = 1; #else static int dbg = 0; #endif static char module_version[] = "$Id: gio_flash.c,v 1.1 2003/04/03 14:32:50 seletz Exp $"; /********************************************************************** * static functions */ /********************************************************************** * 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 ); /* 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)); } /* register flash io driver */ void init_flash_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; } --- NEW FILE: gio_part_blob.c --- /********************************************************************** * blob partition reading for GIO * * Copyright (C) 2003, Stefan Eletzhofer <ste...@el...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: gio_part_blob.c,v 1.1 2003/04/03 14:32:50 seletz Exp $ * */ /********************************************************************** * Includes */ #ifdef HAVE_CONFIG_H # include <blob/config.h> #endif #include <blob/types.h> #include <blob/errno.h> #include <blob/util.h> #include <blob/command.h> #include <blob/init.h> #include <blob/partition.h> #include <blob/generic_io.h> /********************************************************************** * defines */ #define DEBUG 0 #if DEBUG # define DBG( x, args... ) if ( dbg>=x ) printf( args ); #else # define DBG( x, args... ) #endif /********************************************************************** * module globals */ #if DEBUG static int dbg = 1; #else static int dbg = 0; #endif static char module_version[] = "$Id: gio_part_blob.c,v 1.1 2003/04/03 14:32:50 seletz Exp $"; /********************************************************************** * static functions */ /********************************************************************** * 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) */ static 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 ); /* initialize driver struct */ static 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); } /* register default blob partition io driver */ void init_part_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; } --- NEW FILE: gio_ram.c --- /********************************************************************** * GIO ram "driver" * * Copyright (C) 2003, Stefan Eletzhofer <ste...@el...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: gio_ram.c,v 1.1 2003/04/03 14:32:50 seletz Exp $ * */ /********************************************************************** * Includes */ #ifdef HAVE_CONFIG_H # include <blob/config.h> #endif #include <blob/arch.h> #include <blob/types.h> #include <blob/errno.h> #include <blob/util.h> #include <blob/command.h> #include <blob/init.h> #include <blob/generic_io.h> /********************************************************************** * defines */ #define DEBUG 0 #if DEBUG # define DBG( x, args... ) if ( dbg>=x ) printf( args ); #else # define DBG( x, args... ) #endif #if !defined( RAM_START ) || !defined( RAM_SIZE ) # error "define RAM_START and RAM_SIZE for your platform" #endif /********************************************************************** * module globals */ #if DEBUG static int dbg = 1; #else static int dbg = 0; #endif static char module_version[] = "$Id: gio_ram.c,v 1.1 2003/04/03 14:32:50 seletz Exp $"; /********************************************************************** * static functions */ static int ram_io_conf( io_driver_t * io, void *conf ); static int ram_io_read( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ); static int ram_io_write( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ); /********************************************************************** * A simple RAM driver * - io driver for RAM access */ int ram_io_init( io_driver_t *io, ram_io_t *ram ) { if ( !io || !ram ) return -EINVAL; io->private_data = (void *)ram; io->io_size = ram->len - ram->pos; io->conf = ram_io_conf; io->read = ram_io_read; io->write = ram_io_write; io->child_io = NULL; return 0; } static int ram_io_conf( io_driver_t * io, void *conf ) { ram_io_t *ram; if ( !io || !conf ) return -EINVAL; ram = (ram_io_t*)io->private_data; if ( !ram ) return -EINVAL; if ( (u32)conf >= ram->len ) return -EINVAL; ram->pos = (u32)conf; io->io_size = ram->len - (u32)ram->pos; return 0; } static int ram_io_read( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ) { u32 offset; ram_io_t *ram; DBG( 1, "%s: dest=%p, src=%p, amount=%d, io=%p\n", __FUNCTION__, dest, src, amount, io ); if ( !io || !dest ) return -EINVAL; ram = (ram_io_t*)io->private_data; if ( !ram ) return -EINVAL; offset = ram->start + (u32)ram->pos; DBG( 1, "%s: dest=%p, src=%p(=%p), amount=%d, io=%p\n", __FUNCTION__, dest, src, (void*)(src +offset), amount, io ); memcpy( dest, (void *)(offset + (u32)src), amount); return 0; } static int ram_io_write( unsigned char *dest, unsigned char *src, size_t amount, io_driver_t *io ) { u32 offset; ram_io_t *ram; if ( !io || !src ) return -EINVAL; ram = (ram_io_t*)io->private_data; if ( !ram ) return -EINVAL; offset = ram->start + (u32)ram->pos; DBG( 1, "%s: dest=%p(=%p), src=%p, amount=%d, io=%p\n", __FUNCTION__, dest, (void*)(dest +offset), src, amount, io ); memcpy((void *)(offset + (u32)dest), src, amount); return 0; } /********************************************************************** * init ram pools */ void init_ram_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; } |