apps/bootblocktool-R1_3_0/bootblocktool.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <linux/version.h>
#include <mtd/mtd-user.h>

Include dependency graph for bootblocktool.c:

Go to the source code of this file.

Defines

#define EMPTYMAGIC   0xffffffff
#define PARAMMAGIC_PRIMARY   0xbeefcace
#define PARAMMAGIC_BACKUP   0xdeadbabe
#define MAX_PARAM_NAME_LEN   0xff
#define MAX_RECORD_LEN   0xffff
#define ERR_NO_MAGIC   -3
#define ERR_END_OF_PARAMS   -2
#define ERR_OTHER   -1
#define NO_ERROR   0
#define NAND_NOR_COMPATIBILITY_MODE   (1)
#define ROUND_UP(len, pagesize)   ((((len) - 1) & ~((pagesize) - 1)) + (pagesize))
#define BLOCK_START(offset, blocksize)   (((offset) & ((blocksize) -1)) == 0)
#define BLOCK_ADDR(offset, blocksize)   ((offset) & ~((blocksize) -1))
#define D(x)

Enumerations

enum  Toutput_type { SCRIPT, NAMEVALUE }

Functions

static void printUsage (void)
static void die (const char *)
static void listParams (Toutput_type output_type)
static int readParam (const char *name, char **value, int *firstfree)
static int writeParam (const char *name, const char *value)
static int writeMagic (int file, int *offset)
static int readParamAt (int f, int offset, char **name, int *nameLen, char **value, int *valueLen, int *totlen)
static int writeParamAt (int f, int offset, const char *name, const char *value)
static void skipBadBlocks (int fd, int *offset)
static int getChipParams (void)
static int setFlashParams (void)
int main (int argc, char **argv)

Variables

static const char * dev = "/dev/part/rescue"
const char usage []
const char HTML_END [] = " "
static int useHTML = 0
static int setExitErr = 0
static int exitStat = 0
static int PARAMMAGIC = PARAMMAGIC_PRIMARY
static int FlashOffset
static int FlashEnd
static int nandFlash = 0
static unsigned int blockSize
static unsigned int pageSize


Define Documentation

#define BLOCK_ADDR ( offset,
blocksize   )     ((offset) & ~((blocksize) -1))

Definition at line 196 of file bootblocktool.c.

#define BLOCK_START ( offset,
blocksize   )     (((offset) & ((blocksize) -1)) == 0)

Definition at line 194 of file bootblocktool.c.

Referenced by listParams(), and readParam().

#define D ( x   ) 

Definition at line 245 of file bootblocktool.c.

#define EMPTYMAGIC   0xffffffff

*************************************************************************** ! ! FILE NAME : bootblocktool.c ! ! DESCRIPTION: Handles bootblock parameters ! ! --------------------------------------------------------------------------- ! (C) Copyright 2000-2007, Axis Communications AB, LUND, SWEDEN ! ! 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., 675 Mass Ave, Cambridge, MA 02139, USA. ! --------------------------------------------------------------------------- ! HISTORY ! ! DATE NAME CHANGES ! ---- ---- ------- !

Log
bootblocktool.c,v
! Revision 1.1.1.1 2008/11/27 20:04:01 elphel ! ! ! Revision 1.1.1.1 2007/06/29 12:39:49 elphel ! This is a fresh tree based on elphel353-2.10 ! ! Revision 1.1 2007/06/29 12:39:49 spectr_rain ! *** empty log message *** ! ! Revision 1.28 2007/02/23 14:26:11 karljope ! Merged task_branch--nandflash_support ! ! Revision 1.27 2007/01/10 15:43:05 karljope ! Copyright statement added. ! ! Revision 1.26.2.11 2007/02/21 18:11:01 karljope ! Sync with HEAD ! ! Revision 1.26.2.10 2007/02/13 13:14:19 karljope ! Made it compile for kernels older than 2.6.19 again ! ! Revision 1.26.2.9 2007/02/07 16:00:22 karljope ! * Removed inclusion of linux/compiler.h as the file is no longer available. ! What was it used for? Compiles fine without it anyway. ! * Added a space in HTML_END to avoid warning. Why do we use it when we ! obviously don't intend to print anything? ! ! Revision 1.26.2.8 2007/01/23 21:41:57 ricardw ! Cleaned file of all tabs. ! ! Revision 1.26.2.7 2007/01/19 15:36:13 ricardw ! Freed wrong pointer in readParam loop, fixed. Also free parvalue in same ! function if caller is not interested in value. ! ! Revision 1.26.2.6 2007/01/19 14:44:35 ricardw ! Fixes from review 070115: ! Added checks so that the implementation limit of max one block of parameters ! and max one page per parameter are not exceeded. ! Removed tabs in file. ! Plug memory leak in loop in readParam. ! Miscellaneous code cleanup. ! ! Revision 1.26.2.5 2006/11/22 12:30:50 ricardw ! Name change of rescue partition /dev/part/crescue -> /dev/part/rescue. ! ! Revision 1.26.2.4 2006/11/14 07:34:54 ricardw ! Conditonally use fwinfo area only when fwinfo set in axis config. ! ! Revision 1.26.2.3 2006/11/09 15:46:29 ricardw ! imageinfo -> fwinfo (name change). ! Added backwards compatbility for old kernels (<2.6.18, <2.6.0). ! ! Revision 1.26.2.2 2006/10/13 15:31:08 ricardw ! Modified to use image info area instead of hard coded addresses. ! ! Revision 1.26.2.1 2006/10/13 13:51:20 ricardw ! Initial support for NAND flash. ! ! Revision 1.26 2006/08/14 12:01:53 martinnn ! Added option -err which sets exit status on errors. ! ! Revision 1.25 2004/11/08 14:54:11 ulfo ! Corrected the HTTP header ! ! Revision 1.24 2004/02/11 17:52:31 henriken ! '-w' argument parsing bug fixes: ! ! * ignore variables submitted without a value ! * stop on variables with empty name ! ! Revision 1.23 2002/08/04 19:22:31 andorzn ! * Added include of errrno.h. ! * Added syslog messages. ! * Added and corrected logging/printing of errno values. ! * Removed some magic numbers. ! ! Revision 1.22 2002/01/23 13:48:00 johana ! Clarified/reformatted usage. ! ! Revision 1.21 2002/01/22 14:26:13 orjanf ! Added -backup option (changes flash offset and magic). ! ! Revision 1.20 2001/06/12 12:06:41 jonashg ! Print usage instead of segfault. ! ! Revision 1.19 2001/03/27 14:16:59 jonashg ! Removed warning message. sftpd will be modified. ! ! Revision 1.18 2000/12/19 09:40:29 pkj ! Added option -nocgi (must be the first option supplied) to prevent ! output of Content-Type when run through a web-script (PHP). ! ! Revision 1.17 2000/11/22 17:27:22 johana ! Fixed parsing bugs for -w and -c (it worked if there happend to be ! 0x00 after the argv, easaly detected if tested on host, ! the bugs are probably in apps/paramtool as well where that code was taken from, ! but there are no (good) reasons to use paramtool nowadays anyway:-) ! Fixed null terminating of name in readParamAt. (It happend to work if the ! allocated memory contained 0x00..) ! ! Changed all FILE* operations to the unbuffered versions using filedescriptors, ! fseek and fwrite was very weird on my host. ! ! Revision 1.16 2000/08/30 12:07:02 olak ! added printf used by sftpd ! ! Revision 1.15 2000/08/24 16:45:33 johana ! Added unistd.h to remove warning (getpid()) ! ! Revision 1.14 2000/08/09 18:03:42 finn ! More cleanup. ! ! Revision 1.13 2000/08/07 16:05:17 finn ! Cleanup. ! ! Revision 1.12 2000/07/04 13:21:02 johana ! Support same parameters as paramtool: -w and -c ! Added -lenv option to print all parameters in setenv format. ! !

Definition at line 177 of file bootblocktool.c.

Referenced by listParams(), and readParam().

#define ERR_END_OF_PARAMS   -2

Definition at line 185 of file bootblocktool.c.

Referenced by listParams(), readParam(), and readParamAt().

#define ERR_NO_MAGIC   -3

Definition at line 184 of file bootblocktool.c.

Referenced by readParam(), and writeParam().

#define ERR_OTHER   -1

Definition at line 186 of file bootblocktool.c.

Referenced by readParam(), readParamAt(), writeMagic(), writeParam(), and writeParamAt().

#define MAX_PARAM_NAME_LEN   0xff

Definition at line 181 of file bootblocktool.c.

Referenced by writeParam().

#define MAX_RECORD_LEN   0xffff

Definition at line 182 of file bootblocktool.c.

Referenced by writeParamAt().

#define NAND_NOR_COMPATIBILITY_MODE   (1)

Definition at line 189 of file bootblocktool.c.

#define NO_ERROR   0

Definition at line 187 of file bootblocktool.c.

Referenced by main(), readParam(), writeMagic(), writeParam(), and writeParamAt().

#define PARAMMAGIC_BACKUP   0xdeadbabe

Definition at line 179 of file bootblocktool.c.

Referenced by main().

#define PARAMMAGIC_PRIMARY   0xbeefcace

Definition at line 178 of file bootblocktool.c.

Referenced by setFlashParams().

#define ROUND_UP ( len,
pagesize   )     ((((len) - 1) & ~((pagesize) - 1)) + (pagesize))

Definition at line 192 of file bootblocktool.c.

Referenced by listParams(), readParam(), and writeParamAt().


Enumeration Type Documentation

enum Toutput_type

Enumerator:
SCRIPT 
NAMEVALUE 

Definition at line 250 of file bootblocktool.c.


Function Documentation

static void die ( const char *   )  [static]

Definition at line 586 of file bootblocktool.c.

References exit, HTML_END, stderr, and useHTML.

Referenced by change_broadcast(), change_gateway(), change_ip(), change_netmask(), changeIP(), getChipParams(), listParams(), read_broadcast(), read_gateway(), read_ip(), read_netmask(), readParam(), skipBadBlocks(), xml_simple::stop_element(), and writeParam().

static int getChipParams ( void   )  [static]

Definition at line 1097 of file bootblocktool.c.

References blockSize, D, dev, die(), mtd_info_user::erasesize, fd, MEMGETINFO, MTD_NANDFLASH, nandFlash, mtd_info_user::oobblock, pageSize, and mtd_info_user::type.

Referenced by setFlashParams().

static void listParams ( Toutput_type  output_type  )  [static]

Definition at line 658 of file bootblocktool.c.

References BLOCK_START, blockSize, D, dev, die(), EMPTYMAGIC, ERR_END_OF_PARAMS, f, FlashEnd, FlashOffset, free(), NAMEVALUE, nandFlash, pageSize, PARAMMAGIC, read, readParamAt(), ROUND_UP, SCRIPT, SEEK_SET, skipBadBlocks(), and stderr.

Referenced by main().

int main ( int  argc,
char **  argv 
)

Definition at line 298 of file bootblocktool.c.

References D, dev, exitStat, free(), HTML_END, listParams(), method, name, NAMEVALUE, NO_ERROR, PARAMMAGIC, PARAMMAGIC_BACKUP, printUsage(), readParam(), SCRIPT, setExitErr, setFlashParams(), stderr, useHTML, value, and writeParam().

static void printUsage ( void   )  [static]

Definition at line 570 of file bootblocktool.c.

References exit, stderr, usage, and useHTML.

Referenced by main().

static int readParam ( const char *  name,
char **  value,
int *  firstfree 
) [static]

Definition at line 772 of file bootblocktool.c.

References BLOCK_START, blockSize, D, dev, die(), EMPTYMAGIC, ERR_END_OF_PARAMS, ERR_NO_MAGIC, ERR_OTHER, f, FlashOffset, free(), nandFlash, NO_ERROR, pageSize, PARAMMAGIC, read, readParamAt(), ROUND_UP, SEEK_SET, and skipBadBlocks().

Referenced by main(), and writeParam().

static int readParamAt ( int  f,
int  offset,
char **  name,
int *  nameLen,
char **  value,
int *  valueLen,
int *  totlen 
) [static]

Definition at line 876 of file bootblocktool.c.

References buf, D, ERR_END_OF_PARAMS, ERR_OTHER, FlashEnd, free(), int, malloc(), read, and SEEK_SET.

Referenced by listParams(), and readParam().

static int setFlashParams ( void   )  [static]

Definition at line 1196 of file bootblocktool.c.

References fwinfo::bootblkpar_flash_addr, fwinfo::bootblkpar_flash_end, dev, FlashEnd, FlashOffset, getChipParams(), PARAMMAGIC, and PARAMMAGIC_PRIMARY.

Referenced by main().

static void skipBadBlocks ( int  fd,
int *  offset 
) [static]

Definition at line 1155 of file bootblocktool.c.

References blockSize, die(), FlashEnd, and MEMGETBADBLOCK.

Referenced by listParams(), and readParam().

static int writeMagic ( int  file,
int *  offset 
) [static]

Definition at line 1037 of file bootblocktool.c.

References buf, D, ERR_OTHER, error(), free(), malloc(), memcpy(), memset(), nandFlash, NO_ERROR, pageSize, PARAMMAGIC, SEEK_SET, and write.

Referenced by writeParam().

static int writeParam ( const char *  name,
const char *  value 
) [static]

Definition at line 604 of file bootblocktool.c.

References D, dev, die(), ERR_NO_MAGIC, ERR_OTHER, f, MAX_PARAM_NAME_LEN, NO_ERROR, readParam(), writeMagic(), and writeParamAt().

Referenced by main().

static int writeParamAt ( int  f,
int  offset,
const char *  name,
const char *  value 
) [static]

Definition at line 947 of file bootblocktool.c.

References blockSize, buf, D, ERR_OTHER, error(), FlashEnd, free(), malloc(), MAX_RECORD_LEN, memcpy(), memset(), nandFlash, NO_ERROR, pageSize, ROUND_UP, SEEK_SET, and write.

Referenced by writeParam().


Variable Documentation

unsigned int blockSize [static]

Definition at line 292 of file bootblocktool.c.

Referenced by getChipParams(), listParams(), readParam(), skipBadBlocks(), and writeParamAt().

const char* dev = "/dev/part/rescue" [static]

Definition at line 198 of file bootblocktool.c.

Referenced by checkSclSda(), fpga_read(), fpga_write(), getChipParams(), i2c_ctl(), i2c_getCMOSClock(), i2c_read256b(), i2c_receive(), i2c_send(), i2c_setCMOSClock(), i2c_write256b(), i2cread16(), listParams(), main(), net_init(), read_fpga_reg(), readParam(), receive347(), receive_i2c(), receive_i2c_4(), receive_i2c_n(), send347(), send_i2c(), send_i2c_4(), send_i2c_4_nc(), send_i2c_4a(), sendi2c16(), senspars_read(), senspars_write(), seq_receive(), setFlashParams(), smbus_send(), snd_func_pcm_args_by_class(), and writeParam().

int exitStat = 0 [static]

Definition at line 283 of file bootblocktool.c.

Referenced by main().

int FlashEnd [static]

Definition at line 288 of file bootblocktool.c.

Referenced by listParams(), readParamAt(), setFlashParams(), skipBadBlocks(), and writeParamAt().

int FlashOffset [static]

Definition at line 287 of file bootblocktool.c.

Referenced by listParams(), readParam(), and setFlashParams().

const char HTML_END[] = " "

Definition at line 216 of file bootblocktool.c.

Referenced by die(), and main().

int nandFlash = 0 [static]

Definition at line 290 of file bootblocktool.c.

Referenced by getChipParams(), listParams(), readParam(), writeMagic(), and writeParamAt().

unsigned int pageSize [static]

Definition at line 293 of file bootblocktool.c.

Referenced by getChipParams(), listParams(), readParam(), writeMagic(), and writeParamAt().

int PARAMMAGIC = PARAMMAGIC_PRIMARY [static]

Definition at line 285 of file bootblocktool.c.

Referenced by listParams(), main(), readParam(), setFlashParams(), and writeMagic().

int setExitErr = 0 [static]

Definition at line 282 of file bootblocktool.c.

Referenced by main().

const char usage[]

Initial value:

"Usage: bootblocktool [options] command\n"
"Options:\n"
"  -backup    Makes all subsequent parameters pertain to the backup block\n"
"  -nocgi     Disable CGI detection\n"
"  -d device  The device to use\n"
"  -err       Set exit status != 0 on parameter errors\n"
"Commands:\n"
"  -x name1 name2 ...          ; get\n"
"  -c name:name2:name3         ; get/check\n"
"  -a name1 value1 name2 value2 ... ; set\n"
"  -w name=value:name2=value2       ; set\n"
"  -l     ; list parameters\n"
"  -lenv  ; list parameters in setenv format\n"

Definition at line 200 of file bootblocktool.c.

int useHTML = 0 [static]

Definition at line 281 of file bootblocktool.c.

Referenced by die(), main(), and printUsage().


Generated on Fri Nov 28 00:06:46 2008 for elphel by  doxygen 1.5.1