|
From: Stefan E. <se...@us...> - 2003-04-03 14:37:29
|
Update of /cvsroot/blob/blob/src/commands
In directory sc8-pr-cvs1:/tmp/cvs-serv5110
Added Files:
setip.c sysupd.c tftp.c
Log Message:
- new commands for tftp uploads and easy firmware update
--- NEW FILE: setip.c ---
/*
* setip.c: set client/server IP
*
* Client and server IP are used for TFTP downloads.
*
* 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
*
*/
#ident "$Id: setip.c,v 1.1 2003/04/03 14:37:25 seletz Exp $"
/**********************************************************************
* Includes
*/
#ifdef HAVE_CONFIG_H
# include <blob/config.h>
#endif
#include <blob/errno.h>
#include <blob/debug.h>
#include <blob/types.h>
#include <blob/util.h>
#include <net/net.h>
#if !defined( CONFIG_NETWORK_SUPPORT )
# error "You must enable NETWORK support."
#endif
/**********************************************************************
* defines
*/
#define SETIP_DEBUG 0
#if SETIP_DEBUG
static int dbg = 1;
# define DBG( x, args... ) if ( dbg>=x ) printf( args )
#else
# define DBG( x, args... )
#endif
/**********************************************************************
* command
*/
int setip_cmd( int argc, char *argv[] )
{
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;
}
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";;
--- NEW FILE: sysupd.c ---
/*
* sysupd.c: system update from CF/RAM card
*
* Update a board's firmware from a tar file located on a CF memory
* card or in RAM.
*
* Copyright (C) 2001 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
*
*/
#ident "$Id: sysupd.c,v 1.1 2003/04/03 14:37:25 seletz Exp $"
/**********************************************************************
* Includes
*/
#ifdef HAVE_CONFIG_H
# include <blob/config.h>
#endif
#include <blob/errno.h>
#include <blob/debug.h>
#include <blob/types.h>
#include <blob/util.h>
#include <blob/generic_io.h>
#include <blob/pcmcia.h>
#include <blob/cf.h>
#include <blob/ide.h>
#include <blob/tar.h>
#if !defined( CONFIG_GIO_SUPPORT )
# error "You must also enable PCMCIA and gereric IO support."
#endif
/* these are the default images */
static char *update_files[] = {
"blob",
"config.tar",
"zImage",
"initrd.gz",
"cramfs",
"data.img"
};
/**********************************************************************
* defines
*/
#define SYSUPD_DEBUG 1
#if SYSUPD_DEBUG
static int dbg = 1;
# define DBG( x, args... ) if ( dbg>=x ) printf( args )
#else
# define DBG( x, args... )
#endif
/**********************************************************************
* 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
*/
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;
}
int sysupd_cmd( int argc, char *argv[] )
{
int ret;
char **images = NULL;
int nimages = sizeof(update_files)/sizeof(char *);
int i=0;
char *source = "CF";
argv++;
/* source io param */
if ( argc>1 ) {
source = *argv;
argv++;
argc--;
}
/* image list */
if ( argc>1 ) {
nimages = argc -1;
images = &argv[0];
} else {
images = update_files;
}
/* 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 */
for ( i=0; i<nimages; i++ ) {
DBG( 1, "images[%d]=%s\n", i, images[i] );
ret = update_image( images[i] );
if ( ret == 0 )
printf( "sysupd: flashed image '%s'\n", images[i] );
DBG( 1, "i=%d\n", i );
}
return 0;
}
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.";
--- NEW FILE: tftp.c ---
/*
* tftp.c: tftp download command
*
* 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
*
*/
#ident "$Id: tftp.c,v 1.1 2003/04/03 14:37:25 seletz Exp $"
/**********************************************************************
* Includes
*/
#ifdef HAVE_CONFIG_H
# include <blob/config.h>
#endif
#include <blob/arch.h>
#include <blob/errno.h>
#include <blob/debug.h>
#include <blob/types.h>
#include <blob/util.h>
#include <net/net.h>
#if !defined( CONFIG_NETWORK_SUPPORT )
# error "You must enable NETWORK support."
#endif
#if !defined( RAM_START )
# error "Please define RAM_START for your arch!"
#endif
/**********************************************************************
* defines
*/
#define TFTP_DEBUG 0
#if TFTP_DEBUG
static int dbg = 1;
# define DBG( x, args... ) if ( dbg>=x ) printf( args )
#else
# define DBG( x, args... )
#endif
/**********************************************************************
* command
*/
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 );
}
/* FIXME: add a arch-specific define for SMC base */
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;
}
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";
|