From: Stefan E. <se...@us...> - 2001-11-05 09:21:27
|
Update of /cvsroot/blob/blob/src/blob In directory usw-pr-cvs1:/tmp/cvs-serv11224 Modified Files: system3.c Log Message: - added commands for raw flash writing/erasing (until partitioning support) - added command for raw file download Index: system3.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/system3.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- system3.c 2001/10/29 11:42:58 1.4 +++ system3.c 2001/11/05 09:21:24 1.5 @@ -2,6 +2,8 @@ * system3.c: PT System3 specific stuff * * Copyright (C) 2001 Erik Mouw (J.A...@it...) + * Copyright (C) 2001 Stefan Eletzhofer + * (ste...@ww...) * * 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 @@ -21,16 +23,45 @@ #ident "$Id$" +/********************************************************************** + * includes + */ + #ifdef HAVE_CONFIG_H # include <blob/config.h> #endif +#include <blob/main.h> +#include <blob/arch.h> +#include <blob/errno.h> +#include <blob/error.h> +#include <blob/util.h> +#include <blob/serial.h> #include <blob/flash.h> #include <blob/init.h> +#include <blob/command.h> +#include <blob/uucodec.h> +/********************************************************************** + * defines + */ +/* 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)) +/********************************************************************** + * globals + */ + +extern blob_status_t blob_status; + +/********************************************************************** + * module globals + */ + /* flash descriptor for System3 flash. */ /* System 3 uses 2xINTEL e28F640 Chips */ static flash_descriptor_t system3_flash_descriptors[] = @@ -44,10 +75,20 @@ /* NULL block */ }, }; - - +/********************************************************************** + * static functions + */ +/********************************************************************* + * init_system3_flash + * + * AUTOR: SELETZ + * REVISED: + * + * inits system 3 flash driver + * + */ static void init_system3_flash_driver(void) { flash_descriptors = system3_flash_descriptors; @@ -55,3 +96,138 @@ } __initlist(init_system3_flash_driver, INIT_LEVEL_OTHER_STUFF); + + + +/********************************************************************* + * cmd_download_file + * + * AUTOR: SELETZ + * REVISED: + * + * Download a file to arbitary memory location + * + */ +int cmd_download_file( int argc, char *argv[] ) +{ + int ret = 0; + u32 dest = 0L; + u32 len = 0L; + + if ( argc < 3 ) ERR( -EINVAL ); + + ret = strtou32( argv[1], &dest ); + if ( ret < 0 ) ERR( -EINVAL ); + + ret = strtou32( argv[2], &len ); + if ( ret < 0 ) ERR( -EINVAL ); + + SerialOutputString("Switching to download speed\n"); + SerialOutputString("You have 60 seconds to switch your terminal emulator to the same speed and\n"); + SerialOutputString("start downloading. After that " PACKAGE " will switch back to term speed.\n"); + + SerialInit(blob_status.downloadSpeed); + + ret = UUDecode((char *)dest, len); + if ( ret == len ) { + SerialOutputString("Received "); + SerialOutputDec(ret); + SerialOutputString(" (0x"); + SerialOutputHex(ret); + SerialOutputString(") bytes.\n"); + ret = 0; + } else { + SerialOutputString("error during uudecode\n"); + } + + SerialOutputString("\n(Please switch your terminal emulator back to terminal speed\n"); + SerialInit(blob_status.terminalSpeed); + +DONE: + return ret; +} +static char downloadhelp[] = "download_file destadr filelength\n" +"download file to memory\n"; +__commandlist( cmd_download_file, "download_file", downloadhelp ); + +/********************************************************************* + * cmd_flash_write + * + * AUTOR: SELETZ + * REVISED: + * + * Command wrapper for low-level flash write access + * + */ +static int cmd_flash_write( int argc, char *argv[] ) +{ + int ret = 0; + u32 src = 0L; + u32 dest = 0L; + u32 len = 0L; + + if ( argc < 4 ) ERR( -EINVAL ); + + ret = strtou32( argv[1], &src ); + if ( ret < 0 ) ERR( -EINVAL ); + + ret = strtou32( argv[2], &dest ); + if ( ret < 0 ) ERR( -EINVAL ); + + ret = strtou32( argv[3], &len ); + if ( ret < 0 ) ERR( -EINVAL ); + + if ( len & (0x3) ) { + len = (len>>2) + 1; + } else { + len = len>>2; + } + + _DBGU32( src ); + _DBGU32( dest ); + _DBGU32( len ); + + ret = flash_write_region( (u32 *)dest, (u32*)src, len ); +DONE: + return ret; +} +static char flashwritehelp[] = "flash_write srcadr destadr size(bytes)\n" +"flash a memory region\n"; +__commandlist( cmd_flash_write, "flash_write", flashwritehelp ); + +/********************************************************************* + * cmd_flash_erase + * + * AUTOR: SELETZ + * REVISED: + * + * Command wrapper for low-level flash erasing + * + */ +static int cmd_flash_erase( int argc, char *argv[] ) +{ + int ret = 0; + u32 dest = 0L; + u32 len = 0L; + + if ( argc < 3 ) ERR( -EINVAL ); + + ret = strtou32( argv[1], &dest ); + if ( ret < 0 ) ERR( -EINVAL ); + + ret = strtou32( argv[2], &len ); + if ( ret < 0 ) ERR( -EINVAL ); + + if ( len & (0x3) ) { + len = (len>>2) + 1; + } else { + len = len>>2; + } + + ret = flash_erase_region( (u32 *)dest, len ); +DONE: + return ret; +} +static char flasherasehelp[] = "flash_erase adr size(bytes)\n" +"erase a flash region\n"; +__commandlist( cmd_flash_erase, "flash_erase", flasherasehelp ); |