diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/cmd_bedbug.c | 1 | ||||
-rw-r--r-- | common/cmd_bmp.c | 4 | ||||
-rw-r--r-- | common/cmd_dcr.c | 1 | ||||
-rw-r--r-- | common/cmd_fdc.c | 29 | ||||
-rw-r--r-- | common/cmd_i2c.c | 1 | ||||
-rw-r--r-- | common/cmd_mem.c | 10 | ||||
-rw-r--r-- | common/cmd_nvedit.c | 137 | ||||
-rw-r--r-- | common/cmd_pci.c | 1 | ||||
-rw-r--r-- | common/cmd_tsi148.c | 7 | ||||
-rw-r--r-- | common/cmd_universe.c | 4 | ||||
-rw-r--r-- | common/env_common.c | 52 | ||||
-rw-r--r-- | common/env_dataflash.c | 36 | ||||
-rw-r--r-- | common/env_eeprom.c | 106 | ||||
-rw-r--r-- | common/env_embedded.c | 47 | ||||
-rw-r--r-- | common/env_flash.c | 185 | ||||
-rw-r--r-- | common/env_mgdisk.c | 7 | ||||
-rw-r--r-- | common/env_mmc.c | 80 | ||||
-rw-r--r-- | common/env_nand.c | 109 | ||||
-rw-r--r-- | common/env_nowhere.c | 12 | ||||
-rw-r--r-- | common/env_nvram.c | 28 | ||||
-rw-r--r-- | common/env_onenand.c | 23 | ||||
-rw-r--r-- | common/env_sf.c | 55 | ||||
-rw-r--r-- | common/fdt_support.c | 8 | ||||
-rw-r--r-- | common/hush.c | 1 | ||||
-rw-r--r-- | common/lcd.c | 18 | ||||
-rw-r--r-- | common/modem.c | 1 | ||||
-rw-r--r-- | common/usb.c | 13 |
27 files changed, 429 insertions, 547 deletions
diff --git a/common/cmd_bedbug.c b/common/cmd_bedbug.c index 2bd62e2..87b108f 100644 --- a/common/cmd_bedbug.c +++ b/common/cmd_bedbug.c @@ -15,7 +15,6 @@ DECLARE_GLOBAL_DATA_PTR; extern void show_regs __P ((struct pt_regs *)); extern int run_command __P ((const char *, int)); -extern char console_buffer[]; ulong dis_last_addr = 0; /* Last address disassembled */ ulong dis_last_len = 20; /* Default disassembler length */ diff --git a/common/cmd_bmp.c b/common/cmd_bmp.c index 23fc82f..682f395 100644 --- a/common/cmd_bmp.c +++ b/common/cmd_bmp.c @@ -237,9 +237,7 @@ static int bmp_display(ulong addr, int x, int y) } #if defined(CONFIG_LCD) - extern int lcd_display_bitmap (ulong, int, int); - - ret = lcd_display_bitmap ((unsigned long)bmp, x, y); + ret = lcd_display_bitmap((ulong)bmp, x, y); #elif defined(CONFIG_VIDEO) extern int video_display_bitmap (ulong, int, int); diff --git a/common/cmd_dcr.c b/common/cmd_dcr.c index 45fe66a..568e226 100644 --- a/common/cmd_dcr.c +++ b/common/cmd_dcr.c @@ -68,7 +68,6 @@ int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) /* DCR's value */ int nbytes; - extern char console_buffer[]; /* Validate arguments */ if (argc < 2) diff --git a/common/cmd_fdc.c b/common/cmd_fdc.c index 40d12f6..4fe410d 100644 --- a/common/cmd_fdc.c +++ b/common/cmd_fdc.c @@ -428,8 +428,8 @@ int fdc_terminate(FDC_COMMAND_STRUCT *pCMD) int fdc_read_data(unsigned char *buffer, unsigned long blocks,FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG) { /* first seek to start address */ - unsigned long len,lastblk,readblk,i,timeout,ii,offset; - unsigned char pcn,c,retriesrw,retriescal; + unsigned long len,readblk,i,timeout,ii,offset; + unsigned char c,retriesrw,retriescal; unsigned char *bufferw; /* working buffer */ int sect_size; int flags; @@ -442,18 +442,19 @@ int fdc_read_data(unsigned char *buffer, unsigned long blocks,FDC_COMMAND_STRUCT offset=0; if(fdc_seek(pCMD,pFG)==FALSE) { stop_fdc_drive(pCMD); - enable_interrupts(); + if (flags) + enable_interrupts(); return FALSE; } if((pCMD->result[STATUS_0]&0x20)!=0x20) { printf("Seek error Status: %02X\n",pCMD->result[STATUS_0]); stop_fdc_drive(pCMD); - enable_interrupts(); + if (flags) + enable_interrupts(); return FALSE; } - pcn=pCMD->result[STATUS_PCN]; /* current track */ /* now determine the next seek point */ - lastblk=pCMD->blnr + blocks; + /* lastblk=pCMD->blnr + blocks; */ /* readblk=(pFG->head*pFG->sect)-(pCMD->blnr%(pFG->head*pFG->sect)); */ readblk=pFG->sect-(pCMD->blnr%pFG->sect); PRINTF("1st nr of block possible read %ld start %ld\n",readblk,pCMD->blnr); @@ -467,7 +468,8 @@ retryrw: pCMD->cmd[COMMAND]=FDC_CMD_READ; if(fdc_issue_cmd(pCMD,pFG)==FALSE) { stop_fdc_drive(pCMD); - enable_interrupts(); + if (flags) + enable_interrupts(); return FALSE; } for (i=0;i<len;i++) { @@ -488,14 +490,16 @@ retryrw: if(retriesrw++>FDC_RW_RETRIES) { if (retriescal++>FDC_CAL_RETRIES) { stop_fdc_drive(pCMD); - enable_interrupts(); + if (flags) + enable_interrupts(); return FALSE; } else { PRINTF(" trying to recalibrate Try %d\n",retriescal); if(fdc_recalibrate(pCMD,pFG)==FALSE) { stop_fdc_drive(pCMD); - enable_interrupts(); + if (flags) + enable_interrupts(); return FALSE; } retriesrw=0; @@ -528,7 +532,8 @@ retrycal: /* a seek is necessary */ if(fdc_seek(pCMD,pFG)==FALSE) { stop_fdc_drive(pCMD); - enable_interrupts(); + if (flags) + enable_interrupts(); return FALSE; } if((pCMD->result[STATUS_0]&0x20)!=0x20) { @@ -536,10 +541,10 @@ retrycal: stop_fdc_drive(pCMD); return FALSE; } - pcn=pCMD->result[STATUS_PCN]; /* current track */ }while(TRUE); /* start over */ stop_fdc_drive(pCMD); /* switch off drive */ - enable_interrupts(); + if (flags) + enable_interrupts(); return TRUE; } diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c index a0c5291..e795139 100644 --- a/common/cmd_i2c.c +++ b/common/cmd_i2c.c @@ -449,7 +449,6 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg ulong data; int size = 1; int nbytes; - extern char console_buffer[]; if (argc != 3) return cmd_usage(cmdtp); diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 461ee19..f7e76d6 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -33,7 +33,6 @@ #include <dataflash.h> #endif #include <watchdog.h> -#include <asm/io.h> #ifdef CMD_MEM_DEBUG #define PRINTF(fmt,args...) printf (fmt ,##args) @@ -142,13 +141,9 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) # endif { - ulong bytes = size * length; - void *buf = map_physmem(addr, bytes, MAP_WRBACK); - /* Print the lines. */ - print_buffer(addr, buf, size, length, DISP_LINE_LEN / size); - addr += bytes; - unmap_physmem(buf, bytes); + print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size); + addr += size*length; } #endif @@ -982,7 +977,6 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) { ulong addr, i; int nbytes, size; - extern char console_buffer[]; if (argc != 2) return cmd_usage(cmdtp); diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 396a171..7409a36 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -125,7 +125,7 @@ static int env_print(char *name) } /* print whole list */ - len = hexport_r(&env_htab, '\n', &res, 0); + len = hexport_r(&env_htab, '\n', &res, 0, 0, NULL); if (len > 0) { puts(res); @@ -165,7 +165,8 @@ int do_env_print (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #ifdef CONFIG_CMD_GREPENV -static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_env_grep(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) { ENTRY *match; unsigned char matched[env_htab.size / 8]; @@ -178,7 +179,7 @@ static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ while (arg <= argc) { idx = 0; - while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) { + while (idx = hstrstr_r(argv[arg], idx, &match, &env_htab)) { if (!(matched[idx / 8] & (1 << (idx & 7)))) { puts(match->key); puts("="); @@ -199,8 +200,7 @@ static int do_env_grep (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ * Set a new environment variable, * or replace or delete an existing one. */ - -int _do_env_set (int flag, int argc, char * const argv[]) +int _do_env_set(int flag, int argc, char * const argv[]) { bd_t *bd = gd->bd; int i, len; @@ -211,7 +211,8 @@ int _do_env_set (int flag, int argc, char * const argv[]) name = argv[1]; if (strchr(name, '=')) { - printf("## Error: illegal character '=' in variable name \"%s\"\n", name); + printf("## Error: illegal character '=' in variable name" + "\"%s\"\n", name); return 1; } @@ -259,12 +260,12 @@ int _do_env_set (int flag, int argc, char * const argv[]) */ if (ep) { /* variable exists */ #ifndef CONFIG_ENV_OVERWRITE - if ((strcmp(name, "serial#") == 0) || - ((strcmp(name, "ethaddr") == 0) + if (strcmp(name, "serial#") == 0 || + (strcmp(name, "ethaddr") == 0 #if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR) - && (strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0) + && strcmp(ep->data, MK_STR(CONFIG_ETHADDR)) != 0 #endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */ - ) ) { + )) { printf("Can't overwrite \"%s\"\n", name); return 1; } @@ -284,8 +285,8 @@ int _do_env_set (int flag, int argc, char * const argv[]) baudrate); return 1; } - printf ("## Switch baudrate to %d bps and press ENTER ...\n", - baudrate); + printf("## Switch baudrate to %d bps and" + "press ENTER ...\n", baudrate); udelay(50000); gd->baudrate = baudrate; #if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2) @@ -294,15 +295,13 @@ int _do_env_set (int flag, int argc, char * const argv[]) serial_setbrg(); udelay(50000); - for (;;) { - if (getc() == '\r') - break; - } + while (getc() != '\r') + ; } } /* Delete only ? */ - if ((argc < 3) || argv[2] == NULL) { + if (argc < 3 || argv[2] == NULL) { int rc = hdelete_r(name, &env_htab); return !rc; } @@ -323,13 +322,13 @@ int _do_env_set (int flag, int argc, char * const argv[]) while ((*s++ = *v++) != '\0') ; - *(s-1) = ' '; + *(s - 1) = ' '; } if (s != value) *--s = '\0'; - e.key = name; - e.data = value; + e.key = name; + e.data = value; hsearch_r(e, ENTER, &ep, &env_htab); free(value); if (!ep) { @@ -342,7 +341,6 @@ int _do_env_set (int flag, int argc, char * const argv[]) * Some variables should be updated when the corresponding * entry in the environment is changed */ - if (strcmp(name, "ipaddr") == 0) { char *s = argv[2]; /* always use only one arg */ char *e; @@ -351,8 +349,9 @@ int _do_env_set (int flag, int argc, char * const argv[]) for (addr = 0, i = 0; i < 4; ++i) { ulong val = s ? simple_strtoul(s, &e, 10) : 0; addr <<= 8; - addr |= (val & 0xFF); - if (s) s = (*e) ? e+1 : e; + addr |= val & 0xFF; + if (s) + s = *e ? e + 1 : e; } bd->bi_ip_addr = htonl(addr); return 0; @@ -373,7 +372,7 @@ int setenv(const char *varname, const char *varvalue) { const char * const argv[4] = { "setenv", varname, varvalue, NULL }; - if ((varvalue == NULL) || (varvalue[0] == '\0')) + if (varvalue == NULL || varvalue[0] == '\0') return _do_env_set(0, 2, (char * const *)argv); else return _do_env_set(0, 3, (char * const *)argv); @@ -405,7 +404,7 @@ int setenv_addr(const char *varname, const void *addr) { char str[17]; - sprintf(str, "%x", (uintptr_t)addr); + sprintf(str, "%lx", (uintptr_t)addr); return setenv(varname, str); } @@ -423,7 +422,6 @@ int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #if defined(CONFIG_CMD_ASKENV) int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - extern char console_buffer[CONFIG_SYS_CBSIZE]; char message[CONFIG_SYS_CBSIZE]; int size = CONFIG_SYS_CBSIZE - 1; int i, len, pos; @@ -453,9 +451,10 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (pos) message[pos++] = ' '; - strcpy(message+pos, argv[i]); + strcpy(message + pos, argv[i]); pos += strlen(argv[i]); } + message[pos] = '\0'; size = simple_strtoul(argv[argc - 1], NULL, 10); break; @@ -516,20 +515,19 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) */ char *getenv(const char *name) { - if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */ + if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */ ENTRY e, *ep; WATCHDOG_RESET(); - e.key = name; - e.data = NULL; + e.key = name; + e.data = NULL; hsearch_r(e, FIND, &ep, &env_htab); return ep ? ep->data : NULL; } /* restricted capabilities before import */ - if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0) return (char *)(gd->env_buf); @@ -543,7 +541,7 @@ int getenv_f(const char *name, char *buf, unsigned len) { int i, nxt; - for (i = 0; env_get_char(i) != '\0'; i = nxt+1) { + for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { int val, n; for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) { @@ -557,7 +555,8 @@ int getenv_f(const char *name, char *buf, unsigned len) /* found; copy out */ for (n = 0; n < len; ++n, ++buf) { - if ((*buf = env_get_char(val++)) == '\0') + *buf = env_get_char(val++); + if (*buf == '\0') return n; } @@ -569,6 +568,7 @@ int getenv_f(const char *name, char *buf, unsigned len) return n; } + return -1; } @@ -593,11 +593,8 @@ ulong getenv_ulong(const char *name, int base, ulong default_val) } #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) - int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - extern char *env_name_spec; - printf("Saving Environment to %s...\n", env_name_spec); return saveenv() ? 1 : 0; @@ -608,7 +605,6 @@ U_BOOT_CMD( "save environment variables to persistent storage", "" ); - #endif @@ -617,29 +613,32 @@ U_BOOT_CMD( * * s1 is either a simple 'name', or a 'name=value' pair. * i2 is the environment index for a 'name2=value2' pair. - * If the names match, return the index for the value2, else NULL. + * If the names match, return the index for the value2, else -1. */ - int envmatch(uchar *s1, int i2) { while (*s1 == env_get_char(i2++)) if (*s1++ == '=') return i2; + if (*s1 == '\0' && env_get_char(i2-1) == '=') return i2; + return -1; } -static int do_env_default(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_env_default(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) { - if ((argc != 2) || (strcmp(argv[1], "-f") != 0)) + if (argc != 2 || strcmp(argv[1], "-f") != 0) return cmd_usage(cmdtp); set_default_env("## Resetting to default environment\n"); return 0; } -static int do_env_delete(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_env_delete(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) { printf("Not implemented yet\n"); return 0; @@ -647,7 +646,7 @@ static int do_env_delete(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv #ifdef CONFIG_CMD_EXPORTENV /* - * env export [-t | -b | -c] addr [size] + * env export [-t | -b | -c] [-s size] addr [var ...] * -t: export as text format; if size is given, data will be * padded with '\0' bytes; if not, one terminating '\0' * will be added (which is included in the "filesize" @@ -657,8 +656,12 @@ static int do_env_delete(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv * '\0', list end marked by double "\0\0") * -c: export as checksum protected environment format as * used for example by "saveenv" command + * -s size: + * size of output buffer * addr: memory address where environment gets stored - * size: size of output buffer + * var... List of variable names that get included into the + * export. Without arguments, the whole environment gets + * exported. * * With "-c" and size is NOT given, then the export command will * format the data as currently used for the persistent storage, @@ -687,11 +690,12 @@ static int do_env_delete(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv * * => env import -d -t ${backup_addr} */ -static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_env_export(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) { char buf[32]; char *addr, *cmd, *res; - size_t size; + size_t size = 0; ssize_t len; env_t *envp; char sep = '\n'; @@ -715,6 +719,11 @@ static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv sep = '\0'; chk = 1; break; + case 's': /* size given */ + if (--argc <= 0) + return cmd_usage(cmdtp); + size = simple_strtoul(*++argv, NULL, 16); + goto NXTARG; case 't': /* text format */ if (fmt++) goto sep_err; @@ -724,6 +733,7 @@ static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv return cmd_usage(cmdtp); } } +NXTARG: ; } if (argc < 1) @@ -731,18 +741,16 @@ static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv addr = (char *)simple_strtoul(argv[0], NULL, 16); - if (argc == 2) { - size = simple_strtoul(argv[1], NULL, 16); + if (size) memset(addr, '\0', size); - } else { - size = 0; - } + + argc--; + argv++; if (sep) { /* export as text file */ - len = hexport_r(&env_htab, sep, &addr, size); + len = hexport_r(&env_htab, sep, &addr, size, argc, argv); if (len < 0) { - error("Cannot export environment: errno = %d\n", - errno); + error("Cannot export environment: errno = %d\n", errno); return 1; } sprintf(buf, "%zX", (size_t)len); @@ -758,15 +766,14 @@ static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv else /* export as raw binary data */ res = addr; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, argc, argv); if (len < 0) { - error("Cannot export environment: errno = %d\n", - errno); + error("Cannot export environment: errno = %d\n", errno); return 1; } if (chk) { - envp->crc = crc32(0, envp->data, ENV_SIZE); + envp->crc = crc32(0, envp->data, ENV_SIZE); #ifdef CONFIG_ENV_ADDR_REDUND envp->flags = ACTIVE_FLAG; #endif @@ -777,8 +784,7 @@ static int do_env_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv return 0; sep_err: - printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", - cmd); + printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd); return 1; } #endif @@ -796,7 +802,8 @@ sep_err: * size: length of input data; if missing, proper '\0' * termination is mandatory */ -static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_env_import(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) { char *cmd, *addr; char sep = '\n'; @@ -862,7 +869,7 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv " - truncated\n", MAX_ENV_SIZE); } ++size; - printf("## Info: input data size = %zd = 0x%zX\n", size, size); + printf("## Info: input data size = %zu = 0x%zX\n", size, size); } if (chk) { @@ -894,10 +901,6 @@ sep_err: } #endif -#if defined(CONFIG_CMD_RUN) -extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); -#endif - /* * New command line interface: "env" command with subcommands */ @@ -965,7 +968,7 @@ U_BOOT_CMD( #if defined(CONFIG_CMD_EDITENV) "env edit name - edit environment variable\n" #endif - "env export [-t | -b | -c] addr [size] - export environment\n" + "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n" #if defined(CONFIG_CMD_GREPENV) "env grep string [...] - search environment\n" #endif diff --git a/common/cmd_pci.c b/common/cmd_pci.c index 92631ea..1e477bc 100644 --- a/common/cmd_pci.c +++ b/common/cmd_pci.c @@ -341,7 +341,6 @@ pci_cfg_modify (pci_dev_t bdf, ulong addr, ulong size, ulong value, int incrflag { ulong i; int nbytes; - extern char console_buffer[]; uint val4; ushort val2; u_char val1; diff --git a/common/cmd_tsi148.c b/common/cmd_tsi148.c index 6dc9dab..7f48ea2 100644 --- a/common/cmd_tsi148.c +++ b/common/cmd_tsi148.c @@ -53,7 +53,7 @@ static TSI148_DEV *dev; int tsi148_init(void) { - int j, result, lastError = 0; + int j, result; pci_dev_t busdevfn; unsigned int val; @@ -69,8 +69,7 @@ int tsi148_init(void) dev = malloc(sizeof(*dev)); if (NULL == dev) { puts("Tsi148: No memory!\n"); - result = -1; - goto break_20; + return -1; } memset(dev, 0, sizeof(*dev)); @@ -139,8 +138,6 @@ int tsi148_init(void) break_30: free(dev); dev = NULL; - break_20: - lastError = result; return result; } diff --git a/common/cmd_universe.c b/common/cmd_universe.c index a86a574..58384f3 100644 --- a/common/cmd_universe.c +++ b/common/cmd_universe.c @@ -46,7 +46,7 @@ static UNI_DEV *dev; int universe_init(void) { - int j, result, lastError = 0; + int j, result; pci_dev_t busdevfn; unsigned int val; @@ -126,8 +126,6 @@ int universe_init(void) break_30: free(dev); break_20: - lastError = result; - return result; } diff --git a/common/env_common.c b/common/env_common.c index c7e9bea..8a71096 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -34,13 +34,6 @@ DECLARE_GLOBAL_DATA_PTR; -extern env_t *env_ptr; - -extern void env_relocate_spec (void); -extern uchar env_get_char_spec(int); - -static uchar env_get_char_init (int index); - /************************************************************************ * Default settings to be used when no valid environment is found */ @@ -94,7 +87,7 @@ const uchar default_environment[] = { "serverip=" MK_STR(CONFIG_SERVERIP) "\0" #endif #ifdef CONFIG_SYS_AUTOLOAD - "autoload=" CONFIG_SYS_AUTOLOAD "\0" + "autoload=" CONFIG_SYS_AUTOLOAD "\0" #endif #ifdef CONFIG_PREBOOT "preboot=" CONFIG_PREBOOT "\0" @@ -117,13 +110,13 @@ const uchar default_environment[] = { #ifdef CONFIG_LOADADDR "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0" #endif -#ifdef CONFIG_CLOCKS_IN_MHZ +#ifdef CONFIG_CLOCKS_IN_MHZ "clocks_in_mhz=1\0" #endif #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0) "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0" #endif -#ifdef CONFIG_EXTRA_ENV_SETTINGS +#ifdef CONFIG_EXTRA_ENV_SETTINGS CONFIG_EXTRA_ENV_SETTINGS #endif "\0" @@ -131,38 +124,30 @@ const uchar default_environment[] = { struct hsearch_data env_htab; -static uchar env_get_char_init (int index) +static uchar env_get_char_init(int index) { - uchar c; - /* if crc was bad, use the default environment */ if (gd->env_valid) - c = env_get_char_spec(index); + return env_get_char_spec(index); else - c = default_environment[index]; - - return (c); + return default_environment[index]; } -uchar env_get_char_memory (int index) +uchar env_get_char_memory(int index) { return *env_get_addr(index); } -uchar env_get_char (int index) +uchar env_get_char(int index) { - uchar c; - /* if relocated to RAM */ if (gd->flags & GD_FLG_RELOC) - c = env_get_char_memory(index); + return env_get_char_memory(index); else - c = env_get_char_init(index); - - return (c); + return env_get_char_init(index); } -const uchar *env_get_addr (int index) +const uchar *env_get_addr(int index) { if (gd->env_valid) return (uchar *)(gd->env_addr + index); @@ -181,7 +166,7 @@ void set_default_env(const char *s) if (*s == '!') { printf("*** Warning - %s, " "using default environment\n\n", - s+1); + s + 1); } else { puts(s); } @@ -190,9 +175,9 @@ void set_default_env(const char *s) } if (himport_r(&env_htab, (char *)default_environment, - sizeof(default_environment), '\0', 0) == 0) { + sizeof(default_environment), '\0', 0) == 0) error("Environment import failed: errno = %d\n", errno); - } + gd->flags |= GD_FLG_ENV_READY; } @@ -227,22 +212,20 @@ int env_import(const char *buf, int check) return 0; } -void env_relocate (void) +void env_relocate(void) { #if defined(CONFIG_NEEDS_MANUAL_RELOC) - extern void env_reloc(void); - env_reloc(); #endif if (gd->env_valid == 0) { #if defined(CONFIG_ENV_IS_NOWHERE) /* Environment not changable */ set_default_env(NULL); #else - show_boot_progress (-60); + show_boot_progress(-60); set_default_env("!bad CRC"); #endif } else { - env_relocate_spec (); + env_relocate_spec(); } } @@ -272,6 +255,7 @@ int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf) if (idx) cmdv[found++] = "..."; + cmdv[found] = NULL; return found; } diff --git a/common/env_dataflash.c b/common/env_dataflash.c index 1d57079..3c5af37 100644 --- a/common/env_dataflash.c +++ b/common/env_dataflash.c @@ -27,25 +27,17 @@ DECLARE_GLOBAL_DATA_PTR; -env_t *env_ptr = NULL; +env_t *env_ptr; -char * env_name_spec = "dataflash"; - -extern int read_dataflash(unsigned long addr, unsigned long size, - char *result); -extern int write_dataflash(unsigned long addr_dest, - unsigned long addr_src, unsigned long size); -extern int AT91F_DataflashInit(void); - -extern uchar default_environment[]; +char *env_name_spec = "dataflash"; uchar env_get_char_spec(int index) { uchar c; - read_dataflash(CONFIG_ENV_ADDR + index + offsetof(env_t,data), + read_dataflash(CONFIG_ENV_ADDR + index + offsetof(env_t, data), 1, (char *)&c); - return (c); + return c; } void env_relocate_spec(void) @@ -68,12 +60,12 @@ int saveenv(void) char *res; res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); + env_new.crc = crc32(0, env_new.data, ENV_SIZE); return write_dataflash(CONFIG_ENV_ADDR, (unsigned long)&env_new, @@ -88,7 +80,7 @@ int saveenv(void) */ int env_init(void) { - ulong crc, len, new; + ulong crc, len = ENV_SIZE, new = 0; unsigned off; uchar buf[64]; @@ -101,25 +93,23 @@ int env_init(void) read_dataflash(CONFIG_ENV_ADDR + offsetof(env_t, crc), sizeof(ulong), (char *)&crc); - new = 0; - len = ENV_SIZE; - off = offsetof(env_t,data); + off = offsetof(env_t, data); while (len > 0) { int n = (len > sizeof(buf)) ? sizeof(buf) : len; read_dataflash(CONFIG_ENV_ADDR + off, n, (char *)buf); - new = crc32 (new, buf, n); + new = crc32(new, buf, n); len -= n; off += n; } if (crc == new) { - gd->env_addr = offsetof(env_t,data); - gd->env_valid = 1; + gd->env_addr = offsetof(env_t, data); + gd->env_valid = 1; } else { - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = 0; + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 0; } return 0; diff --git a/common/env_eeprom.c b/common/env_eeprom.c index 0a179ad..b66bba2 100644 --- a/common/env_eeprom.c +++ b/common/env_eeprom.c @@ -37,13 +37,13 @@ DECLARE_GLOBAL_DATA_PTR; -env_t *env_ptr = NULL; +env_t *env_ptr; char *env_name_spec = "EEPROM"; int env_eeprom_bus = -1; static int eeprom_bus_read(unsigned dev_addr, unsigned offset, - uchar *buffer, unsigned cnt) + uchar *buffer, unsigned cnt) { int rcode; #if defined(CONFIG_I2C_ENV_EEPROM_BUS) @@ -57,7 +57,7 @@ static int eeprom_bus_read(unsigned dev_addr, unsigned offset, if (dev != NULL) env_eeprom_bus = dev->busid; else - printf ("error adding env eeprom bus.\n"); + printf("error adding env eeprom bus.\n"); } if (old_bus != env_eeprom_bus) { i2c_set_bus_num(env_eeprom_bus); @@ -69,7 +69,7 @@ static int eeprom_bus_read(unsigned dev_addr, unsigned offset, } #endif - rcode = eeprom_read (dev_addr, offset, buffer, cnt); + rcode = eeprom_read(dev_addr, offset, buffer, cnt); #if defined(CONFIG_I2C_ENV_EEPROM_BUS) if (old_bus != env_eeprom_bus) @@ -79,7 +79,7 @@ static int eeprom_bus_read(unsigned dev_addr, unsigned offset, } static int eeprom_bus_write(unsigned dev_addr, unsigned offset, - uchar *buffer, unsigned cnt) + uchar *buffer, unsigned cnt) { int rcode; #if defined(CONFIG_I2C_ENV_EEPROM_BUS) @@ -94,24 +94,22 @@ static int eeprom_bus_write(unsigned dev_addr, unsigned offset, return rcode; } -uchar env_get_char_spec (int index) +uchar env_get_char_spec(int index) { uchar c; - unsigned int off; - off = CONFIG_ENV_OFFSET; + unsigned int off = CONFIG_ENV_OFFSET; #ifdef CONFIG_ENV_OFFSET_REDUND if (gd->env_valid == 2) off = CONFIG_ENV_OFFSET_REDUND; #endif eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, - off + index + offsetof(env_t,data), - &c, 1); + off + index + offsetof(env_t, data), &c, 1); - return (c); + return c; } -void env_relocate_spec (void) +void env_relocate_spec(void) { char buf[CONFIG_ENV_SIZE]; unsigned int off = CONFIG_ENV_OFFSET; @@ -121,9 +119,7 @@ void env_relocate_spec (void) off = CONFIG_ENV_OFFSET_REDUND; #endif eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, - off, - (uchar *)buf, - CONFIG_ENV_SIZE); + off, (uchar *)buf, CONFIG_ENV_SIZE); env_import(buf, 1); } @@ -133,17 +129,17 @@ int saveenv(void) env_t env_new; ssize_t len; char *res; - int rc; - unsigned int off = CONFIG_ENV_OFFSET; + int rc; + unsigned int off = CONFIG_ENV_OFFSET; #ifdef CONFIG_ENV_OFFSET_REDUND - unsigned int off_red = CONFIG_ENV_OFFSET_REDUND; - char flag_obsolete = OBSOLETE_FLAG; + unsigned int off_red = CONFIG_ENV_OFFSET_REDUND; + char flag_obsolete = OBSOLETE_FLAG; #endif BUG_ON(env_ptr != NULL); res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; @@ -152,32 +148,28 @@ int saveenv(void) #ifdef CONFIG_ENV_OFFSET_REDUND if (gd->env_valid == 1) { - off = CONFIG_ENV_OFFSET_REDUND; - off_red = CONFIG_ENV_OFFSET; + off = CONFIG_ENV_OFFSET_REDUND; + off_red = CONFIG_ENV_OFFSET; } env_new.flags = ACTIVE_FLAG; #endif rc = eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR, - off, - (uchar *)&env_new, - CONFIG_ENV_SIZE); + off, (uchar *)&env_new, CONFIG_ENV_SIZE); #ifdef CONFIG_ENV_OFFSET_REDUND if (rc == 0) { eeprom_bus_write(CONFIG_SYS_DEF_EEPROM_ADDR, - off_red + offsetof(env_t,flags), - (uchar *)&flag_obsolete, - 1); + off_red + offsetof(env_t, flags), + (uchar *)&flag_obsolete, 1); + if (gd->env_valid == 1) gd->env_valid = 2; else gd->env_valid = 1; - } #endif - return rc; } @@ -187,17 +179,13 @@ int saveenv(void) * We are still running from ROM, so data use is limited. * Use a (moderately small) buffer on the stack */ - #ifdef CONFIG_ENV_OFFSET_REDUND int env_init(void) { - ulong len; - ulong crc[2], crc_tmp; + ulong len, crc[2], crc_tmp; unsigned int off, off_env[2]; - uchar buf[64]; - int crc_ok[2] = {0,0}; - unsigned char flags[2]; - int i; + uchar buf[64], flags[2]; + int i, crc_ok[2] = {0, 0}; eeprom_init(); /* prepare for EEPROM read/write */ @@ -207,39 +195,39 @@ int env_init(void) for (i = 0; i < 2; i++) { /* read CRC */ eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, - off_env[i] + offsetof(env_t,crc), - (uchar *)&crc[i], sizeof(ulong)); + off_env[i] + offsetof(env_t, crc), + (uchar *)&crc[i], sizeof(ulong)); /* read FLAGS */ eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, - off_env[i] + offsetof(env_t,flags), - (uchar *)&flags[i], sizeof(uchar)); + off_env[i] + offsetof(env_t, flags), + (uchar *)&flags[i], sizeof(uchar)); crc_tmp = 0; len = ENV_SIZE; - off = off_env[i] + offsetof(env_t,data); + off = off_env[i] + offsetof(env_t, data); while (len > 0) { int n = (len > sizeof(buf)) ? sizeof(buf) : len; eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, off, - buf, n); + buf, n); crc_tmp = crc32(crc_tmp, buf, n); len -= n; off += n; } + if (crc_tmp == crc[i]) crc_ok[i] = 1; } if (!crc_ok[0] && !crc_ok[1]) { - gd->env_addr = 0; - gd->env_valid = 0; + gd->env_addr = 0; + gd->env_valid = 0; return 0; } else if (crc_ok[0] && !crc_ok[1]) { gd->env_valid = 1; - } - else if (!crc_ok[0] && crc_ok[1]) { + } else if (!crc_ok[0] && crc_ok[1]) { gd->env_valid = 2; } else { /* both ok - check serial */ @@ -249,18 +237,18 @@ int env_init(void) gd->env_valid = 2; else if (flags[0] == 0xFF && flags[1] == 0) gd->env_valid = 2; - else if(flags[1] == 0xFF && flags[0] == 0) + else if (flags[1] == 0xFF && flags[0] == 0) gd->env_valid = 1; else /* flags are equal - almost impossible */ gd->env_valid = 1; } if (gd->env_valid == 2) - gd->env_addr = off_env[1] + offsetof(env_t,data); + gd->env_addr = off_env[1] + offsetof(env_t, data); else if (gd->env_valid == 1) - gd->env_addr = off_env[0] + offsetof(env_t,data); + gd->env_addr = off_env[0] + offsetof(env_t, data); - return (0); + return 0; } #else int env_init(void) @@ -273,12 +261,12 @@ int env_init(void) /* read old CRC */ eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR, - CONFIG_ENV_OFFSET+offsetof(env_t,crc), - (uchar *)&crc, sizeof(ulong)); + CONFIG_ENV_OFFSET + offsetof(env_t, crc), + (uchar *)&crc, sizeof(ulong)); new = 0; len = ENV_SIZE; - off = offsetof(env_t,data); + off = offsetof(env_t, data); while (len > 0) { int n = (len > sizeof(buf)) ? sizeof(buf) : len; @@ -291,13 +279,13 @@ int env_init(void) } if (crc == new) { - gd->env_addr = offsetof(env_t,data); - gd->env_valid = 1; + gd->env_addr = offsetof(env_t, data); + gd->env_valid = 1; } else { - gd->env_addr = 0; - gd->env_valid = 0; + gd->env_addr = 0; + gd->env_valid = 0; } - return (0); + return 0; } #endif diff --git a/common/env_embedded.c b/common/env_embedded.c index 6ce1307..80fb29d 100644 --- a/common/env_embedded.c +++ b/common/env_embedded.c @@ -22,17 +22,14 @@ */ #ifndef __ASSEMBLY__ -#define __ASSEMBLY__ /* Dirty trick to get only #defines */ +#define __ASSEMBLY__ /* Dirty trick to get only #defines */ #endif -#define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */ +#define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */ #include <config.h> #undef __ASSEMBLY__ #include <environment.h> -/* - * Handle HOSTS that have prepended - * crap on symbol names, not TARGETS. - */ +/* Handle HOSTS that have prepended crap on symbol names, not TARGETS. */ #if defined(__APPLE__) /* Leading underscore on symbols */ # define SYM_CHAR "_" @@ -52,34 +49,36 @@ * U-Boot itself. */ #if (defined(CONFIG_SYS_USE_PPCENV) || defined(CONFIG_NAND_U_BOOT)) && \ - defined(ENV_CRC) /* Environment embedded in U-Boot .ppcenv section */ + defined(ENV_CRC) /* Environment embedded in U-Boot .ppcenv section */ /* XXX - This only works with GNU C */ -# define __PPCENV__ __attribute__ ((section(".ppcenv"))) -# define __PPCTEXT__ __attribute__ ((section(".text"))) +# define __PPCENV__ __attribute__ ((section(".ppcenv"))) +# define __PPCTEXT__ __attribute__ ((section(".text"))) #elif defined(USE_HOSTCC) /* Native for 'tools/envcrc' */ -# define __PPCENV__ /*XXX DO_NOT_DEL_THIS_COMMENT*/ -# define __PPCTEXT__ /*XXX DO_NOT_DEL_THIS_COMMENT*/ +# define __PPCENV__ /*XXX DO_NOT_DEL_THIS_COMMENT*/ +# define __PPCTEXT__ /*XXX DO_NOT_DEL_THIS_COMMENT*/ #else /* Environment is embedded in U-Boot's .text section */ /* XXX - This only works with GNU C */ -# define __PPCENV__ __attribute__ ((section(".text"))) -# define __PPCTEXT__ __attribute__ ((section(".text"))) +# define __PPCENV__ __attribute__ ((section(".text"))) +# define __PPCTEXT__ __attribute__ ((section(".text"))) #endif /* * Macros to generate global absolutes. */ #if defined(__bfin__) -# define GEN_SET_VALUE(name, value) asm (".set " GEN_SYMNAME(name) ", " GEN_VALUE(value)) +# define GEN_SET_VALUE(name, value) \ + asm(".set " GEN_SYMNAME(name) ", " GEN_VALUE(value)) #else -# define GEN_SET_VALUE(name, value) asm (GEN_SYMNAME(name) " = " GEN_VALUE(value)) -#endif -#define GEN_SYMNAME(str) SYM_CHAR #str -#define GEN_VALUE(str) #str -#define GEN_ABS(name, value) \ - asm (".globl " GEN_SYMNAME(name)); \ - GEN_SET_VALUE(name, value) +# define GEN_SET_VALUE(name, value) \ + asm(GEN_SYMNAME(name) " = " GEN_VALUE(value)) +#endif +#define GEN_SYMNAME(str) SYM_CHAR #str +#define GEN_VALUE(str) #str +#define GEN_ABS(name, value) \ + asm(".globl " GEN_SYMNAME(name)); \ + GEN_SET_VALUE(name, value) /* * Macros to transform values @@ -93,7 +92,7 @@ * computed CRC. Otherwise define it as ~0. */ #if !defined(ENV_CRC) -# define ENV_CRC ~0 +# define ENV_CRC (~0) #endif env_t environment __PPCENV__ = { @@ -151,7 +150,7 @@ env_t environment __PPCENV__ = { "serverip=" MK_STR(CONFIG_SERVERIP) "\0" #endif #ifdef CONFIG_SYS_AUTOLOAD - "autoload=" CONFIG_SYS_AUTOLOAD "\0" + "autoload=" CONFIG_SYS_AUTOLOAD "\0" #endif #ifdef CONFIG_ROOTPATH "rootpath=" CONFIG_ROOTPATH "\0" @@ -180,7 +179,7 @@ env_t environment __PPCENV__ = { #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0) "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0" #endif -#ifdef CONFIG_EXTRA_ENV_SETTINGS +#ifdef CONFIG_EXTRA_ENV_SETTINGS CONFIG_EXTRA_ENV_SETTINGS #endif "\0" /* Term. env_t.data with 2 NULs */ diff --git a/common/env_flash.c b/common/env_flash.c index 50ca4ffa..a99f850 100644 --- a/common/env_flash.c +++ b/common/env_flash.c @@ -39,19 +39,18 @@ DECLARE_GLOBAL_DATA_PTR; #if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_FLASH) #define CMD_SAVEENV #elif defined(CONFIG_ENV_ADDR_REDUND) -#error Cannot use CONFIG_ENV_ADDR_REDUND without CONFIG_CMD_SAVEENV & CONFIG_CMD_FLASH +#error CONFIG_ENV_ADDR_REDUND must have CONFIG_CMD_SAVEENV & CONFIG_CMD_FLASH #endif -#if defined(CONFIG_ENV_SIZE_REDUND) && (CONFIG_ENV_SIZE_REDUND < CONFIG_ENV_SIZE) +#if defined(CONFIG_ENV_SIZE_REDUND) && \ + (CONFIG_ENV_SIZE_REDUND < CONFIG_ENV_SIZE) #error CONFIG_ENV_SIZE_REDUND should not be less then CONFIG_ENV_SIZE #endif -char * env_name_spec = "Flash"; +char *env_name_spec = "Flash"; #ifdef ENV_IS_EMBEDDED - -extern uchar environment[]; -env_t *env_ptr = (env_t *)(&environment[0]); +env_t *env_ptr = &environment; static env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR; @@ -59,7 +58,6 @@ static env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR; env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; static env_t *flash_addr = (env_t *)CONFIG_ENV_ADDR; - #endif /* ENV_IS_EMBEDDED */ #if defined(CMD_SAVEENV) || defined(CONFIG_ENV_ADDR_REDUND) @@ -74,17 +72,14 @@ static env_t *flash_addr_new = (env_t *)CONFIG_ENV_ADDR_REDUND; static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1; #endif /* CONFIG_ENV_ADDR_REDUND */ -extern const uchar default_environment[]; - uchar env_get_char_spec(int index) { - return (*((uchar *)(gd->env_addr + index))); + return *((uchar *)(gd->env_addr + index)); } #ifdef CONFIG_ENV_ADDR_REDUND - -int env_init(void) +int env_init(void) { int crc1_ok = 0, crc2_ok = 0; @@ -95,33 +90,34 @@ int env_init(void) ulong addr1 = (ulong)&(flash_addr->data); ulong addr2 = (ulong)&(flash_addr_new->data); - crc1_ok = (crc32(0, flash_addr->data, ENV_SIZE) == flash_addr->crc); - crc2_ok = (crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc); - - if (crc1_ok && ! crc2_ok) { - gd->env_addr = addr1; - gd->env_valid = 1; - } else if (! crc1_ok && crc2_ok) { - gd->env_addr = addr2; - gd->env_valid = 1; - } else if (! crc1_ok && ! crc2_ok) { - gd->env_addr = addr_default; - gd->env_valid = 0; + crc1_ok = crc32(0, flash_addr->data, ENV_SIZE) == flash_addr->crc; + crc2_ok = + crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc; + + if (crc1_ok && !crc2_ok) { + gd->env_addr = addr1; + gd->env_valid = 1; + } else if (!crc1_ok && crc2_ok) { + gd->env_addr = addr2; + gd->env_valid = 1; + } else if (!crc1_ok && !crc2_ok) { + gd->env_addr = addr_default; + gd->env_valid = 0; } else if (flag1 == ACTIVE_FLAG && flag2 == OBSOLETE_FLAG) { - gd->env_addr = addr1; - gd->env_valid = 1; + gd->env_addr = addr1; + gd->env_valid = 1; } else if (flag1 == OBSOLETE_FLAG && flag2 == ACTIVE_FLAG) { - gd->env_addr = addr2; - gd->env_valid = 1; + gd->env_addr = addr2; + gd->env_valid = 1; } else if (flag1 == flag2) { - gd->env_addr = addr1; - gd->env_valid = 2; + gd->env_addr = addr1; + gd->env_valid = 2; } else if (flag1 == 0xFF) { - gd->env_addr = addr1; - gd->env_valid = 2; + gd->env_addr = addr1; + gd->env_valid = 2; } else if (flag2 == 0xFF) { - gd->env_addr = addr2; - gd->env_valid = 2; + gd->env_addr = addr2; + gd->env_valid = 2; } return 0; @@ -132,74 +128,70 @@ int saveenv(void) { env_t env_new; ssize_t len; - char *saved_data = NULL; - char *res; - int rc = 1; + char *res, *saved_data = NULL; char flag = OBSOLETE_FLAG, new_flag = ACTIVE_FLAG; + int rc = 1; #if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE ulong up_data = 0; #endif - debug("Protect off %08lX ... %08lX\n", - (ulong)flash_addr, end_addr); + debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr, end_addr); - if (flash_sect_protect(0, (ulong)flash_addr, end_addr)) { + if (flash_sect_protect(0, (ulong)flash_addr, end_addr)) goto done; - } debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr_new, end_addr_new); - if (flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new)) { + if (flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new)) goto done; - } res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); goto done; } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); - env_new.flags = new_flag; + env_new.crc = crc32(0, env_new.data, ENV_SIZE); + env_new.flags = new_flag; #if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE - up_data = (end_addr_new + 1 - ((long)flash_addr_new + CONFIG_ENV_SIZE)); + up_data = end_addr_new + 1 - ((long)flash_addr_new + CONFIG_ENV_SIZE); debug("Data to save 0x%lX\n", up_data); if (up_data) { - if ((saved_data = malloc(up_data)) == NULL) { + saved_data = malloc(up_data); + if (saved_data == NULL) { printf("Unable to save the rest of sector (%ld)\n", up_data); goto done; } memcpy(saved_data, - (void *)((long)flash_addr_new + CONFIG_ENV_SIZE), up_data); + (void *)((long)flash_addr_new + CONFIG_ENV_SIZE), + up_data); debug("Data (start 0x%lX, len 0x%lX) saved at 0x%p\n", (long)flash_addr_new + CONFIG_ENV_SIZE, up_data, saved_data); } #endif puts("Erasing Flash..."); - debug(" %08lX ... %08lX ...", - (ulong)flash_addr_new, end_addr_new); + debug(" %08lX ... %08lX ...", (ulong)flash_addr_new, end_addr_new); - if (flash_sect_erase((ulong)flash_addr_new, end_addr_new)) { + if (flash_sect_erase((ulong)flash_addr_new, end_addr_new)) goto done; - } puts("Writing to Flash... "); debug(" %08lX ... %08lX ...", (ulong)&(flash_addr_new->data), - sizeof(env_ptr->data)+(ulong)&(flash_addr_new->data)); - if ((rc = flash_write((char *)&env_new, - (ulong)flash_addr_new, - sizeof(env_new))) || - (rc = flash_write(&flag, - (ulong)&(flash_addr->flags), - sizeof(flash_addr->flags))) ) { - flash_perror(rc); - goto done; - } + sizeof(env_ptr->data) + (ulong)&(flash_addr_new->data)); + rc = flash_write((char *)&env_new, (ulong)flash_addr_new, + sizeof(env_new)); + if (rc) + goto perror; + + rc = flash_write(&flag, (ulong)&(flash_addr->flags), + sizeof(flash_addr->flags)); + if (rc) + goto perror; #if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE if (up_data) { /* restore the rest of sector */ @@ -207,16 +199,14 @@ int saveenv(void) (long)flash_addr_new + CONFIG_ENV_SIZE, up_data); if (flash_write(saved_data, (long)flash_addr_new + CONFIG_ENV_SIZE, - up_data)) { - flash_perror(rc); - goto done; - } + up_data)) + goto perror; } #endif puts("done\n"); { - env_t * etmp = flash_addr; + env_t *etmp = flash_addr; ulong ltmp = end_addr; flash_addr = flash_addr_new; @@ -227,12 +217,15 @@ int saveenv(void) } rc = 0; + goto done; +perror: + flash_perror(rc); done: if (saved_data) free(saved_data); /* try to re-protect */ - (void) flash_sect_protect(1, (ulong)flash_addr, end_addr); - (void) flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new); + flash_sect_protect(1, (ulong)flash_addr, end_addr); + flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new); return rc; } @@ -240,35 +233,34 @@ done: #else /* ! CONFIG_ENV_ADDR_REDUND */ -int env_init(void) +int env_init(void) { if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { - gd->env_addr = (ulong)&(env_ptr->data); - gd->env_valid = 1; - return(0); + gd->env_addr = (ulong)&(env_ptr->data); + gd->env_valid = 1; + return 0; } - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = 0; + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 0; return 0; } #ifdef CMD_SAVEENV - int saveenv(void) { env_t env_new; ssize_t len; int rc = 1; - char *res; - char *saved_data = NULL; + char *res, *saved_data = NULL; #if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE ulong up_data = 0; - up_data = (end_addr + 1 - ((long)flash_addr + CONFIG_ENV_SIZE)); + up_data = end_addr + 1 - ((long)flash_addr + CONFIG_ENV_SIZE); debug("Data to save 0x%lx\n", up_data); if (up_data) { - if ((saved_data = malloc(up_data)) == NULL) { + saved_data = malloc(up_data); + if (saved_data == NULL) { printf("Unable to save the rest of sector (%ld)\n", up_data); goto done; @@ -282,14 +274,13 @@ int saveenv(void) } #endif /* CONFIG_ENV_SECT_SIZE */ - debug("Protect off %08lX ... %08lX\n", - (ulong)flash_addr, end_addr); + debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr, end_addr); if (flash_sect_protect(0, (long)flash_addr, end_addr)) goto done; res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); goto done; @@ -302,32 +293,31 @@ int saveenv(void) puts("Writing to Flash... "); rc = flash_write((char *)&env_new, (long)flash_addr, CONFIG_ENV_SIZE); - if (rc != 0) { - flash_perror(rc); - goto done; - } + if (rc != 0) + goto perror; + #if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE if (up_data) { /* restore the rest of sector */ debug("Restoring the rest of data to 0x%lx len 0x%lx\n", (ulong)flash_addr + CONFIG_ENV_SIZE, up_data); if (flash_write(saved_data, (long)flash_addr + CONFIG_ENV_SIZE, - up_data)) { - flash_perror(rc); - goto done; - } + up_data)) + goto perror; } #endif puts("done\n"); rc = 0; + goto done; +perror: + flash_perror(rc); done: if (saved_data) free(saved_data); /* try to re-protect */ - (void) flash_sect_protect(1, (long)flash_addr, end_addr); + flash_sect_protect(1, (long)flash_addr, end_addr); return rc; } - #endif /* CMD_SAVEENV */ #endif /* CONFIG_ENV_ADDR_REDUND */ @@ -347,8 +337,7 @@ void env_relocate_spec(void) } if (flash_addr_new->flags != OBSOLETE_FLAG && - crc32(0, flash_addr_new->data, ENV_SIZE) == - flash_addr_new->crc) { + crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc) { char flag = OBSOLETE_FLAG; gd->env_valid = 2; @@ -372,8 +361,8 @@ void env_relocate_spec(void) } if (gd->env_valid == 2) - puts ("*** Warning - some problems detected " - "reading environment; recovered successfully\n\n"); + puts("*** Warning - some problems detected " + "reading environment; recovered successfully\n\n"); #endif /* CONFIG_ENV_ADDR_REDUND */ env_import((char *)flash_addr, 1); diff --git a/common/env_mgdisk.c b/common/env_mgdisk.c index a69923b..5dd92e7 100644 --- a/common/env_mgdisk.c +++ b/common/env_mgdisk.c @@ -27,18 +27,15 @@ #include <linux/stddef.h> #include <mg_disk.h> -/* references to names in env_common.c */ -extern uchar default_environment[]; - char *env_name_spec = "MG_DISK"; -env_t *env_ptr = 0; +env_t *env_ptr; DECLARE_GLOBAL_DATA_PTR; uchar env_get_char_spec(int index) { - return (*((uchar *)(gd->env_addr + index))); + return *((uchar *)(gd->env_addr + index)); } void env_relocate_spec(void) diff --git a/common/env_mmc.c b/common/env_mmc.c index 83f40f4..8441c77 100644 --- a/common/env_mmc.c +++ b/common/env_mmc.c @@ -32,23 +32,14 @@ #include <search.h> #include <errno.h> -/* references to names in env_common.c */ -extern uchar default_environment[]; - char *env_name_spec = "MMC"; #ifdef ENV_IS_EMBEDDED -extern uchar environment[]; -env_t *env_ptr = (env_t *)(&environment[0]); +env_t *env_ptr = &environment; #else /* ! ENV_IS_EMBEDDED */ -env_t *env_ptr = NULL; +env_t *env_ptr; #endif /* ENV_IS_EMBEDDED */ -/* local functions */ -#if !defined(ENV_IS_EMBEDDED) -static void use_default(void); -#endif - DECLARE_GLOBAL_DATA_PTR; #if !defined(CONFIG_ENV_OFFSET) @@ -60,9 +51,8 @@ static int __mmc_get_env_addr(struct mmc *mmc, u32 *env_addr) *env_addr = CONFIG_ENV_OFFSET; return 0; } -__attribute__((weak, alias("__mmc_get_env_addr"))) -int mmc_get_env_addr(struct mmc *mmc, u32 *env_addr); - +int mmc_get_env_addr(struct mmc *mmc, u32 *env_addr) + __attribute__((weak, alias("__mmc_get_env_addr"))); uchar env_get_char_spec(int index) { @@ -72,13 +62,13 @@ uchar env_get_char_spec(int index) int env_init(void) { /* use default */ - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = 1; + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 1; return 0; } -int init_mmc_for_env(struct mmc *mmc) +static int init_mmc_for_env(struct mmc *mmc) { if (!mmc) { puts("No MMC card found\n"); @@ -87,21 +77,20 @@ int init_mmc_for_env(struct mmc *mmc) if (mmc_init(mmc)) { puts("MMC init failed\n"); - return -1; + return -1; } return 0; } #ifdef CONFIG_CMD_SAVEENV - -inline int write_env(struct mmc *mmc, unsigned long size, - unsigned long offset, const void *buffer) +static inline int write_env(struct mmc *mmc, unsigned long size, + unsigned long offset, const void *buffer) { uint blk_start, blk_cnt, n; - blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len; - blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len; + blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len; + blk_cnt = ALIGN(size, mmc->write_bl_len) / mmc->write_bl_len; n = mmc->block_dev.block_write(CONFIG_SYS_MMC_ENV_DEV, blk_start, blk_cnt, (u_char *)buffer); @@ -115,21 +104,19 @@ int saveenv(void) ssize_t len; char *res; struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); - u32 offset; + u32 offset; - if (init_mmc_for_env(mmc)) - return 1; - - if(mmc_get_env_addr(mmc, &offset)) + if (init_mmc_for_env(mmc) || mmc_get_env_addr(mmc, &offset)) return 1; res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); + + env_new.crc = crc32(0, env_new.data, ENV_SIZE); printf("Writing to MMC(%d)... ", CONFIG_SYS_MMC_ENV_DEV); if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)&env_new)) { puts("failed\n"); @@ -141,13 +128,13 @@ int saveenv(void) } #endif /* CONFIG_CMD_SAVEENV */ -inline int read_env(struct mmc *mmc, unsigned long size, - unsigned long offset, const void *buffer) +static inline int read_env(struct mmc *mmc, unsigned long size, + unsigned long offset, const void *buffer) { uint blk_start, blk_cnt, n; - blk_start = ALIGN(offset, mmc->read_bl_len) / mmc->read_bl_len; - blk_cnt = ALIGN(size, mmc->read_bl_len) / mmc->read_bl_len; + blk_start = ALIGN(offset, mmc->read_bl_len) / mmc->read_bl_len; + blk_cnt = ALIGN(size, mmc->read_bl_len) / mmc->read_bl_len; n = mmc->block_dev.block_read(CONFIG_SYS_MMC_ENV_DEV, blk_start, blk_cnt, (uchar *)buffer); @@ -159,32 +146,15 @@ void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) char buf[CONFIG_ENV_SIZE]; - struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); u32 offset; - if (init_mmc_for_env(mmc)) { - use_default(); - return; - } + if (init_mmc_for_env(mmc) || mmc_get_env_addr(mmc, &offset)) + return set_default_env(NULL); - if(mmc_get_env_addr(mmc, &offset)) { - use_default(); - return ; - } - - if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) { - use_default(); - return; - } + if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) + return set_default_env(NULL); env_import(buf, 1); #endif } - -#if !defined(ENV_IS_EMBEDDED) -static void use_default() -{ - set_default_env(NULL); -} -#endif diff --git a/common/env_nand.c b/common/env_nand.c index 14446a6..ce13def 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -44,10 +44,11 @@ #if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_NAND) #define CMD_SAVEENV #elif defined(CONFIG_ENV_OFFSET_REDUND) -#error Cannot use CONFIG_ENV_OFFSET_REDUND without CONFIG_CMD_SAVEENV & CONFIG_CMD_NAND +#error CONFIG_ENV_OFFSET_REDUND must have CONFIG_CMD_SAVEENV & CONFIG_CMD_NAND #endif -#if defined(CONFIG_ENV_SIZE_REDUND) && (CONFIG_ENV_SIZE_REDUND != CONFIG_ENV_SIZE) +#if defined(CONFIG_ENV_SIZE_REDUND) && \ + (CONFIG_ENV_SIZE_REDUND != CONFIG_ENV_SIZE) #error CONFIG_ENV_SIZE_REDUND should be the same as CONFIG_ENV_SIZE #endif @@ -55,26 +56,21 @@ #define CONFIG_ENV_RANGE CONFIG_ENV_SIZE #endif -/* references to names in env_common.c */ -extern uchar default_environment[]; - char *env_name_spec = "NAND"; - #if defined(ENV_IS_EMBEDDED) -extern uchar environment[]; -env_t *env_ptr = (env_t *)(&environment[0]); +env_t *env_ptr = &environment; #elif defined(CONFIG_NAND_ENV_DST) env_t *env_ptr = (env_t *)CONFIG_NAND_ENV_DST; #else /* ! ENV_IS_EMBEDDED */ -env_t *env_ptr = 0; +env_t *env_ptr; #endif /* ENV_IS_EMBEDDED */ DECLARE_GLOBAL_DATA_PTR; -uchar env_get_char_spec (int index) +uchar env_get_char_spec(int index) { - return ( *((uchar *)(gd->env_addr + index)) ); + return *((uchar *)(gd->env_addr + index)); } /* @@ -99,16 +95,14 @@ int env_init(void) env_t *tmp_env2; tmp_env2 = (env_t *)((ulong)env_ptr + CONFIG_ENV_SIZE); - crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc); + crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc; #endif - tmp_env1 = env_ptr; - - crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc); + crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; if (!crc1_ok && !crc2_ok) { - gd->env_addr = 0; - gd->env_valid = 0; + gd->env_addr = 0; + gd->env_valid = 0; return 0; } else if (crc1_ok && !crc2_ok) { @@ -119,13 +113,13 @@ int env_init(void) gd->env_valid = 2; } else { /* both ok - check serial */ - if(tmp_env1->flags == 255 && tmp_env2->flags == 0) + if (tmp_env1->flags == 255 && tmp_env2->flags == 0) gd->env_valid = 2; - else if(tmp_env2->flags == 255 && tmp_env1->flags == 0) + else if (tmp_env2->flags == 255 && tmp_env1->flags == 0) gd->env_valid = 1; - else if(tmp_env1->flags > tmp_env2->flags) + else if (tmp_env1->flags > tmp_env2->flags) gd->env_valid = 1; - else if(tmp_env2->flags > tmp_env1->flags) + else if (tmp_env2->flags > tmp_env1->flags) gd->env_valid = 2; else /* flags are equal - almost impossible */ gd->env_valid = 1; @@ -141,11 +135,11 @@ int env_init(void) gd->env_addr = (ulong)env_ptr->data; #else /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */ - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = 1; + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 1; #endif /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */ - return (0); + return 0; } #ifdef CMD_SAVEENV @@ -158,7 +152,6 @@ int writeenv(size_t offset, u_char *buf) size_t end = offset + CONFIG_ENV_RANGE; size_t amount_saved = 0; size_t blocksize, len; - u_char *char_ptr; blocksize = nand_info[0].erasesize; @@ -169,9 +162,9 @@ int writeenv(size_t offset, u_char *buf) offset += blocksize; } else { char_ptr = &buf[amount_saved]; - if (nand_write(&nand_info[0], offset, &len, - char_ptr)) + if (nand_write(&nand_info[0], offset, &len, char_ptr)) return 1; + offset += blocksize; amount_saved += len; } @@ -200,23 +193,22 @@ int saveenv(void) return 1; res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); - env_new.flags = ++env_flags; /* increase the serial */ + env_new.crc = crc32(0, env_new.data, ENV_SIZE); + env_new.flags = ++env_flags; /* increase the serial */ - if(gd->env_valid == 1) { + if (gd->env_valid == 1) { puts("Erasing redundant NAND...\n"); nand_erase_options.offset = CONFIG_ENV_OFFSET_REDUND; if (nand_erase_opts(&nand_info[0], &nand_erase_options)) return 1; puts("Writing to redundant NAND... "); - ret = writeenv(CONFIG_ENV_OFFSET_REDUND, - (u_char *)&env_new); + ret = writeenv(CONFIG_ENV_OFFSET_REDUND, (u_char *)&env_new); } else { puts("Erasing NAND...\n"); nand_erase_options.offset = CONFIG_ENV_OFFSET; @@ -224,8 +216,7 @@ int saveenv(void) return 1; puts("Writing to NAND... "); - ret = writeenv(CONFIG_ENV_OFFSET, - (u_char *)&env_new); + ret = writeenv(CONFIG_ENV_OFFSET, (u_char *)&env_new); } if (ret) { puts("FAILED!\n"); @@ -234,14 +225,14 @@ int saveenv(void) puts("done\n"); - gd->env_valid = (gd->env_valid == 2 ? 1 : 2); + gd->env_valid = gd->env_valid == 2 ? 1 : 2; return ret; } #else /* ! CONFIG_ENV_OFFSET_REDUND */ int saveenv(void) { - int ret = 0; + int ret = 0; env_t env_new; ssize_t len; char *res; @@ -255,12 +246,12 @@ int saveenv(void) return 1; res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); + env_new.crc = crc32(0, env_new.data, ENV_SIZE); puts("Erasing Nand...\n"); if (nand_erase_opts(&nand_info[0], &nand_erase_options)) @@ -278,17 +269,17 @@ int saveenv(void) #endif /* CONFIG_ENV_OFFSET_REDUND */ #endif /* CMD_SAVEENV */ -int readenv(size_t offset, u_char * buf) +int readenv(size_t offset, u_char *buf) { size_t end = offset + CONFIG_ENV_RANGE; size_t amount_loaded = 0; size_t blocksize, len; - u_char *char_ptr; blocksize = nand_info[0].erasesize; if (!blocksize) return 1; + len = min(blocksize, CONFIG_ENV_SIZE); while (amount_loaded < CONFIG_ENV_SIZE && offset < end) { @@ -296,12 +287,15 @@ int readenv(size_t offset, u_char * buf) offset += blocksize; } else { char_ptr = &buf[amount_loaded]; - if (nand_read_skip_bad(&nand_info[0], offset, &len, char_ptr)) + if (nand_read_skip_bad(&nand_info[0], offset, + &len, char_ptr)) return 1; + offset += blocksize; amount_loaded += len; } } + if (amount_loaded != CONFIG_ENV_SIZE) return 1; @@ -312,14 +306,14 @@ int readenv(size_t offset, u_char * buf) int get_nand_env_oob(nand_info_t *nand, unsigned long *result) { struct mtd_oob_ops ops; - uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)]; + uint32_t oob_buf[ENV_OFFSET_SIZE / sizeof(uint32_t)]; int ret; - ops.datbuf = NULL; - ops.mode = MTD_OOB_AUTO; - ops.ooboffs = 0; - ops.ooblen = ENV_OFFSET_SIZE; - ops.oobbuf = (void *) oob_buf; + ops.datbuf = NULL; + ops.mode = MTD_OOB_AUTO; + ops.ooboffs = 0; + ops.ooblen = ENV_OFFSET_SIZE; + ops.oobbuf = (void *)oob_buf; ret = nand->read_oob(nand, ENV_OFFSET_SIZE, &ops); if (ret) { @@ -349,13 +343,10 @@ void env_relocate_spec(void) tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE); tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE); - - if ((tmp_env1 == NULL) || (tmp_env2 == NULL)) { + if (tmp_env1 == NULL || tmp_env2 == NULL) { puts("Can't allocate buffers for environment\n"); - free(tmp_env1); - free(tmp_env2); set_default_env("!malloc() failed"); - return; + goto done; } if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) @@ -364,14 +355,12 @@ void env_relocate_spec(void) if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2)) puts("No Valid Redundant Environment Area found\n"); - crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc); - crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc); + crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; + crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc; if (!crc1_ok && !crc2_ok) { - free(tmp_env1); - free(tmp_env2); set_default_env("!bad CRC"); - return; + goto done; } else if (crc1_ok && !crc2_ok) { gd->env_valid = 1; } else if (!crc1_ok && crc2_ok) { @@ -388,7 +377,6 @@ void env_relocate_spec(void) gd->env_valid = 2; else /* flags are equal - almost impossible */ gd->env_valid = 1; - } free(env_ptr); @@ -401,6 +389,7 @@ void env_relocate_spec(void) env_flags = ep->flags; env_import((char *)ep, 0); +done: free(tmp_env1); free(tmp_env2); @@ -412,7 +401,7 @@ void env_relocate_spec(void) * device i.e., nand_dev_desc + 0. This is also the behaviour using * the new NAND code. */ -void env_relocate_spec (void) +void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) int ret; diff --git a/common/env_nowhere.c b/common/env_nowhere.c index 75ef78d..8a3ca19 100644 --- a/common/env_nowhere.c +++ b/common/env_nowhere.c @@ -31,9 +31,7 @@ DECLARE_GLOBAL_DATA_PTR; -env_t *env_ptr = NULL; - -extern uchar default_environment[]; +env_t *env_ptr; void env_relocate_spec(void) { @@ -41,7 +39,7 @@ void env_relocate_spec(void) uchar env_get_char_spec(int index) { - return ( *((uchar *)(gd->env_addr + index)) ); + return *((uchar *)(gd->env_addr + index)); } /* @@ -51,8 +49,8 @@ uchar env_get_char_spec(int index) */ int env_init(void) { - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = 0; + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 0; - return (0); + return 0; } diff --git a/common/env_nvram.c b/common/env_nvram.c index 544ce47..726eaac 100644 --- a/common/env_nvram.c +++ b/common/env_nvram.c @@ -52,21 +52,19 @@ DECLARE_GLOBAL_DATA_PTR; #ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE extern void *nvram_read(void *dest, const long src, size_t count); extern void nvram_write(long dest, const void *src, size_t count); -env_t *env_ptr = NULL; +env_t *env_ptr; #else env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; #endif -char * env_name_spec = "NVRAM"; - -extern uchar default_environment[]; +char *env_name_spec = "NVRAM"; uchar env_get_char_spec(int index) { #ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE uchar c; - nvram_read(&c, CONFIG_ENV_ADDR+index, 1); + nvram_read(&c, CONFIG_ENV_ADDR + index, 1); return c; #else @@ -81,7 +79,7 @@ void env_relocate_spec(void) #if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE) nvram_read(buf, CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); #else - memcpy(buf, (void*)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); + memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); #endif env_import(buf, 1); } @@ -94,7 +92,7 @@ int saveenv(void) int rcode = 0; res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; @@ -110,7 +108,6 @@ int saveenv(void) return rcode; } - /* * Initialize Environment use * @@ -123,18 +120,19 @@ int env_init(void) uchar data[ENV_SIZE]; nvram_read(&crc, CONFIG_ENV_ADDR, sizeof(ulong)); - nvram_read(data, CONFIG_ENV_ADDR+sizeof(ulong), ENV_SIZE); + nvram_read(data, CONFIG_ENV_ADDR + sizeof(ulong), ENV_SIZE); if (crc32(0, data, ENV_SIZE) == crc) { - gd->env_addr = (ulong)CONFIG_ENV_ADDR + sizeof(long); + gd->env_addr = (ulong)CONFIG_ENV_ADDR + sizeof(long); #else if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { - gd->env_addr = (ulong)&(env_ptr->data); + gd->env_addr = (ulong)&env_ptr->data; #endif - gd->env_valid = 1; + gd->env_valid = 1; } else { - gd->env_addr = (ulong)&default_environment[0]; - gd->env_valid = 0; + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 0; } - return (0); + + return 0; } diff --git a/common/env_onenand.c b/common/env_onenand.c index 5e04a06..0ad2fc7 100644 --- a/common/env_onenand.c +++ b/common/env_onenand.c @@ -31,31 +31,22 @@ #include <malloc.h> #include <search.h> #include <errno.h> +#include <onenand_uboot.h> #include <linux/mtd/compat.h> #include <linux/mtd/mtd.h> #include <linux/mtd/onenand.h> -extern struct mtd_info onenand_mtd; -extern struct onenand_chip onenand_chip; - -/* References to names in env_common.c */ -extern uchar default_environment[]; - char *env_name_spec = "OneNAND"; #define ONENAND_MAX_ENV_SIZE 4096 #define ONENAND_ENV_SIZE(mtd) (ONENAND_MAX_ENV_SIZE - ENV_HEADER_SIZE) -#ifdef ENV_IS_EMBEDDED -extern uchar environment[]; -#endif /* ENV_IS_EMBEDDED */ - DECLARE_GLOBAL_DATA_PTR; uchar env_get_char_spec(int index) { - return (*((uchar *)(gd->env_addr + index))); + return *((uchar *)(gd->env_addr + index)); } void env_relocate_spec(void) @@ -67,7 +58,7 @@ void env_relocate_spec(void) int rc; size_t retlen; #ifdef ENV_IS_EMBEDDED - char *buf = (char *)&environment[0]; + char *buf = (char *)&environment; #else loff_t env_addr = CONFIG_ENV_ADDR; char onenand_env[ONENAND_MAX_ENV_SIZE]; @@ -83,7 +74,7 @@ void env_relocate_spec(void) if (mtd->writesize) /* Ignore read fail */ mtd->read(mtd, env_addr, ONENAND_MAX_ENV_SIZE, - &retlen, (u_char *)buf); + &retlen, (u_char *)buf); else mtd->writesize = MAX_ONENAND_PAGESIZE; #endif /* !ENV_IS_EMBEDDED */ @@ -109,7 +100,7 @@ int saveenv(void) }; res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; @@ -133,7 +124,7 @@ int saveenv(void) } if (mtd->write(mtd, env_addr, ONENAND_MAX_ENV_SIZE, &retlen, - (u_char *)&env_new)) { + (u_char *)&env_new)) { printf("OneNAND: write failed at 0x%llx\n", instr.addr); return 2; } @@ -144,7 +135,7 @@ int saveenv(void) int env_init(void) { /* use default */ - gd->env_addr = (ulong) & default_environment[0]; + gd->env_addr = (ulong)&default_environment[0]; gd->env_valid = 1; return 0; diff --git a/common/env_sf.c b/common/env_sf.c index d3b36d0..592b870 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -36,7 +36,7 @@ # define CONFIG_ENV_SPI_BUS 0 #endif #ifndef CONFIG_ENV_SPI_CS -# define CONFIG_ENV_SPI_CS 0 +# define CONFIG_ENV_SPI_CS 0 #endif #ifndef CONFIG_ENV_SPI_MAX_HZ # define CONFIG_ENV_SPI_MAX_HZ 1000000 @@ -46,19 +46,16 @@ #endif #ifdef CONFIG_ENV_OFFSET_REDUND -static ulong env_offset = CONFIG_ENV_OFFSET; -static ulong env_new_offset = CONFIG_ENV_OFFSET_REDUND; +static ulong env_offset = CONFIG_ENV_OFFSET; +static ulong env_new_offset = CONFIG_ENV_OFFSET_REDUND; -#define ACTIVE_FLAG 1 -#define OBSOLETE_FLAG 0 +#define ACTIVE_FLAG 1 +#define OBSOLETE_FLAG 0 #endif /* CONFIG_ENV_OFFSET_REDUND */ DECLARE_GLOBAL_DATA_PTR; -/* references to names in env_common.c */ -extern uchar default_environment[]; - -char * env_name_spec = "SPI Flash"; +char *env_name_spec = "SPI Flash"; static struct spi_flash *env_flash; @@ -68,17 +65,13 @@ uchar env_get_char_spec(int index) } #if defined(CONFIG_ENV_OFFSET_REDUND) - int saveenv(void) { env_t env_new; ssize_t len; - char *res; - u32 saved_size, saved_offset; - char *saved_buffer = NULL; - u32 sector = 1; + char *res, *saved_buffer = NULL, flag = OBSOLETE_FLAG; + u32 saved_size, saved_offset, sector = 1; int ret; - char flag = OBSOLETE_FLAG; if (!env_flash) { env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, @@ -91,13 +84,13 @@ int saveenv(void) } res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } - env_new.crc = crc32(0, env_new.data, ENV_SIZE); - env_new.flags = ACTIVE_FLAG; + env_new.crc = crc32(0, env_new.data, ENV_SIZE); + env_new.flags = ACTIVE_FLAG; if (gd->env_valid == 1) { env_new_offset = CONFIG_ENV_OFFSET_REDUND; @@ -148,21 +141,21 @@ int saveenv(void) goto done; } - ret = spi_flash_write(env_flash, - env_offset + offsetof(env_t, flags), - sizeof(env_new.flags), &flag); + ret = spi_flash_write(env_flash, env_offset + offsetof(env_t, flags), + sizeof(env_new.flags), &flag); if (ret) goto done; puts("done\n"); - gd->env_valid = (gd->env_valid == 2 ? 1 : 2); + gd->env_valid = gd->env_valid == 2 ? 1 : 2; printf("Valid environment: %d\n", (int)gd->env_valid); done: if (saved_buffer) free(saved_buffer); + return ret; } @@ -248,18 +241,14 @@ err_read: out: free(tmp_env1); free(tmp_env2); - - return; } #else int saveenv(void) { - u32 saved_size, saved_offset; - char *saved_buffer = NULL; - u32 sector = 1; - int ret = 1; + u32 saved_size, saved_offset, sector = 1; + char *res, *saved_buffer = NULL; + int ret = 1; env_t env_new; - char *res; ssize_t len; if (!env_flash) { @@ -277,9 +266,9 @@ int saveenv(void) saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE; saved_offset = CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE; saved_buffer = malloc(saved_size); - if (!saved_buffer) { + if (!saved_buffer) goto done; - } + ret = spi_flash_read(env_flash, saved_offset, saved_size, saved_buffer); if (ret) @@ -293,7 +282,7 @@ int saveenv(void) } res = (char *)&env_new.data; - len = hexport_r(&env_htab, '\0', &res, ENV_SIZE); + len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); goto done; @@ -325,6 +314,7 @@ int saveenv(void) done: if (saved_buffer) free(saved_buffer); + return ret; } @@ -348,7 +338,6 @@ void env_relocate_spec(void) } ret = env_import(buf, 1); - if (ret) gd->env_valid = 1; out: diff --git a/common/fdt_support.c b/common/fdt_support.c index bdda64d..593f16c 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -49,8 +49,8 @@ DECLARE_GLOBAL_DATA_PTR; * Convenience function to find a node and return it's property or a * default value if it doesn't exist. */ -u32 fdt_getprop_u32_default(void *fdt, const char *path, const char *prop, - const u32 dflt) +u32 fdt_getprop_u32_default(const void *fdt, const char *path, + const char *prop, const u32 dflt) { const u32 *val; int off; @@ -61,7 +61,7 @@ u32 fdt_getprop_u32_default(void *fdt, const char *path, const char *prop, val = fdt_getprop(fdt, off, prop, NULL); if (val) - return *val; + return fdt32_to_cpu(*val); else return dflt; } @@ -372,7 +372,7 @@ static int get_cells_len(void *blob, char *nr_cells_name) const u32 *cell; cell = fdt_getprop(blob, 0, nr_cells_name, NULL); - if (cell && *cell == 2) + if (cell && fdt32_to_cpu(*cell) == 2) return 8; return 4; diff --git a/common/hush.c b/common/hush.c index 2495a6d..e8e24d7 100644 --- a/common/hush.c +++ b/common/hush.c @@ -1000,7 +1000,6 @@ static void get_user_input(struct in_str *i) fflush(stdout); i->p = the_command; #else - extern char console_buffer[]; int n; static char the_command[CONFIG_SYS_CBSIZE]; diff --git a/common/lcd.c b/common/lcd.c index d9cb8ca..6313ec0 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -57,12 +57,14 @@ /* ** FONT DATA */ /************************************************************************/ #include <video_font.h> /* Get font data, width and height */ +#include <video_font_data.h> /************************************************************************/ /* ** LOGO DATA */ /************************************************************************/ #ifdef CONFIG_LCD_LOGO # include <bmp_logo.h> /* Get logo data, width and height */ +# include <bmp_logo_data.h> # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16) # error Default Color Map overlaps with Logo Color Map # endif @@ -78,7 +80,6 @@ static inline void lcd_putc_xy (ushort x, ushort y, uchar c); static int lcd_init (void *lcdbase); -static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]); static void *lcd_logo (void); static int lcd_getbgcolor (void); @@ -353,7 +354,14 @@ int drv_lcd_init (void) } /*----------------------------------------------------------------------*/ -static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) +static +int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + lcd_clear(); + return 0; +} + +void lcd_clear(void) { #if LCD_BPP == LCD_MONOCHROME /* Setting the palette */ @@ -394,12 +402,10 @@ static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[] console_col = 0; console_row = 0; - - return (0); } U_BOOT_CMD( - cls, 1, 1, lcd_clear, + cls, 1, 1, do_lcd_clear, "clear screen", "" ); @@ -413,7 +419,7 @@ static int lcd_init (void *lcdbase) lcd_ctrl_init (lcdbase); lcd_is_enabled = 1; - lcd_clear (NULL, 1, 1, NULL); /* dummy args */ + lcd_clear(); lcd_enable (); /* Initialize the console */ diff --git a/common/modem.c b/common/modem.c index a017b29..e37e1ea 100644 --- a/common/modem.c +++ b/common/modem.c @@ -62,7 +62,6 @@ int mdm_init (void) char env_str[16]; char *init_str; int i; - extern char console_buffer[]; extern void enable_putc(void); extern int hwflow_onoff(int); diff --git a/common/usb.c b/common/usb.c index bed5116..4418c70 100644 --- a/common/usb.c +++ b/common/usb.c @@ -263,18 +263,24 @@ int usb_maxpacket(struct usb_device *dev, unsigned long pipe) return dev->epmaxpacketin[((pipe>>15) & 0xf)]; } -/* The routine usb_set_maxpacket_ep() is extracted from the loop of routine +/* + * The routine usb_set_maxpacket_ep() is extracted from the loop of routine * usb_set_maxpacket(), because the optimizer of GCC 4.x chokes on this routine * when it is inlined in 1 single routine. What happens is that the register r3 * is used as loop-count 'i', but gets overwritten later on. * This is clearly a compiler bug, but it is easier to workaround it here than * to update the compiler (Occurs with at least several GCC 4.{1,2},x * CodeSourcery compilers like e.g. 2007q3, 2008q1, 2008q3 lite editions on ARM) + * + * NOTE: Similar behaviour was observed with GCC4.6 on ARMv5. */ static void __attribute__((noinline)) -usb_set_maxpacket_ep(struct usb_device *dev, struct usb_endpoint_descriptor *ep) +usb_set_maxpacket_ep(struct usb_device *dev, int if_idx, int ep_idx) { int b; + struct usb_endpoint_descriptor *ep; + + ep = &dev->config.if_desc[if_idx].ep_desc[ep_idx]; b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; @@ -313,8 +319,7 @@ int usb_set_maxpacket(struct usb_device *dev) for (i = 0; i < dev->config.desc.bNumInterfaces; i++) for (ii = 0; ii < dev->config.if_desc[i].desc.bNumEndpoints; ii++) - usb_set_maxpacket_ep(dev, - &dev->config.if_desc[i].ep_desc[ii]); + usb_set_maxpacket_ep(dev, i, ii); return 0; } |