step7中的"read analog filmvalue 466-1"是什么意思

ARMBoot-1.1.0 在 mini2440 开发板上的移植
第11页_Linux编程_Linux公社-Linux系统门户网站
你好,游客
ARMBoot-1.1.0 在 mini2440 开发板上的移植
来源:Linux社区&
修改common/cmd_nvedit.c&&& ,加入环境变量mach_id,如下:&&&& 1&&& /*&&&& 2&&&& * (C) Copyright 2000&&&& 3&&&& * Wolfgang Denk, DENX Software Engineering, wd@denx.de.&&&& 4&&&& *&&&& 5&&&& * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH &www.elinos.com&&&&& 6&&&& * Andreas Heppel &aheppel@sysgo.de&&&&& 7&&& &&&& 8&&&& * See file CREDITS for list of people who contributed to this&&&& 9&&&& * project.&&& 10&&&& *&&& 11&&&& * This prog you can redistribute it and/or&&& 12&&&& * modify it under the terms of the GNU General Public License as&&& 13&&&& * published by the Free Software F either version 2 of&&& 14&&&& * the License, or (at your option) any later version.&&& 15&&&& *&&& 16&&&& * This program is distributed in the hope that it will be useful,&&& 17&&&& * but WITHOUT ANY WARRANTY; without even the implied warranty of&&& 18&&&& * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&&&& See the&&& 19&&&& * GNU General Public License for more details.&&& 20&&&& *&&& 21&&&& * You should have received a copy of the GNU General Public License&&& 22&&&& * alo if not, write to the Free Software&&& 23&&&& * Foundation, Inc., 59 Temple Place, Suite 330, Boston,&&& 24&&&& * MA
USA&&& 25&&&& */&&& 26&&& &&& 27&&& /*&&& 28&&&& * Support for persistent environment data&&& 29&&&& */&&& 30&&& &&& 31&&& #include "armboot.h"&&& 32&&& #include "command.h"&&& 33&&& #include "malloc.h"&&& 34&&& #include "cmd_nvedit.h"&&& 35&&& &&& 36&&& #if (CONFIG_COMMANDS & CFG_CMD_NET)&&& 37&&& #include "net.h"&&& 38&&& #endif&&& 39&&& &&& 40&&& /*&&& 41&&&& * Table with supported baudrates (defined in config_xyz.h)&&& 42&&&& */&&& 43&&& static const unsigned long baudrate_table[] = CFG_BAUDRATE_TABLE;&&& 44&&& #define&&& N_BAUDRATES (sizeof(baudrate_table) / sizeof(baudrate_table[0]))&&& 45&&& &&& 46&&& /*&&& 47&&&& * Default settings to be used when no valid environment is found&&& 48&&&& */&&& 49&&& #define XMK_STR(x)&&& #x&&& 50&&& #define MK_STR(x)&&& XMK_STR(x)&&& 51&&& &&& 52&&& uchar default_environment[] = {&&& 53&&& #ifdef&&& CONFIG_BOOTARGS&&& 54&&&&&&& "bootargs="&&& CONFIG_BOOTARGS&&&&&&&&&&& "\0"&&& 55&&& #endif&&& 56&&& #ifdef&&& CONFIG_BOOTCOMMAND&&& 57&&&&&&& "bootcmd="&&& CONFIG_BOOTCOMMAND&&&&&&& "\0"&&& 58&&& #endif&&& 59&&& #ifdef&&& CONFIG_RAMBOOTCOMMAND&&& 60&&&&&&& "ramboot="&&& CONFIG_RAMBOOTCOMMAND&&&&&&& "\0"&&& 61&&& #endif&&& 62&&& #ifdef&&& CONFIG_NFSBOOTCOMMAND&&& 63&&&&&&& "nfsboot="&&& CONFIG_NFSBOOTCOMMAND&&&&&&& "\0"&&& 64&&& #endif&&& 65&&& #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY &= 0)&&& 66&&&&&&& "bootdelay="&&& MK_STR(CONFIG_BOOTDELAY)&&& "\0"&&& 67&&& #endif&&& 68&&& #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE &= 0)&&& 69&&&&&&& "baudrate="&&& MK_STR(CONFIG_BAUDRATE)&&&&&&& "\0"&&& 70&&& #endif&&& 71&&& #ifdef&&& CONFIG_LOADS_ECHO&&& 72&&&&&&& "loads_echo="&&& MK_STR(CONFIG_LOADS_ECHO)&&& "\0"&&& 73&&& #endif&&& 74&&& #ifdef&&& CONFIG_ETHADDR&&& 75&&&&&&& "ethaddr="&&& MK_STR(CONFIG_ETHADDR)&&&&&&& "\0"&&& 76&&& #endif&&& 77&&& #ifdef&&& CONFIG_ETH2ADDR&&& 78&&&&&&& "eth2addr="&&& MK_STR(CONFIG_ETH2ADDR)&&&&&&& "\0"&&& 79&&& #endif&&& 80&&& #ifdef&&& CONFIG_ETH3ADDR&&& 81&&&&&&& "eth3addr="&&& MK_STR(CONFIG_ETH3ADDR)&&&&&&& "\0"&&& 82&&& #endif&&& 83&&& #ifdef&&& CONFIG_IPADDR&&& 84&&&&&&& "ipaddr="&&& MK_STR(CONFIG_IPADDR)&&&&&&& "\0"&&& 85&&& #endif&&& 86&&& #ifdef&&& CONFIG_SERVERIP&&& 87&&&&&&& "serverip="&&& MK_STR(CONFIG_SERVERIP)&&&&&&& "\0"&&& 88&&& #endif&&& 89&&& #ifdef&&& CFG_AUTOLOAD&&& 90&&&&&&& "autoload="&&& CFG_AUTOLOAD&&&&&&&&&&& "\0"&&& 91&&& #endif&&& 92&&& #ifdef&&& CONFIG_PREBOOT&&& 93&&&&&&& "preboot="&&& CONFIG_PREBOOT&&&&&&&&&&& "\0"&&& 94&&& #endif&&& 95&&& #ifdef&&& CONFIG_ROOTPATH&&& 96&&&&&&& "rootpath="&&& MK_STR(CONFIG_ROOTPATH)&&&&&&& "\0"&&& 97&&& #endif&&& 98&&& #ifdef&&& CONFIG_GATEWAYIP&&& 99&&&&&&& "gatewayip="&&& MK_STR(CONFIG_GATEWAYIP)&&& "\0"&& 100&&& #endif&& 101&&& #ifdef&&& CONFIG_NETMASK&& 102&&&&&&& "netmask="&&& MK_STR(CONFIG_NETMASK)&&&&&&& "\0"&& 103&&& #endif&& 104&&& #ifdef&&& CONFIG_HOSTNAME&& 105&&&&&&& "hostname="&&& MK_STR(CONFIG_HOSTNAME)&&&&&&& "\0"&& 106&&& #endif&& 107&&& #ifdef&&& CONFIG_BOOTFILE&& 108&&&&&&& "bootfile="&&& MK_STR(CONFIG_BOOTFILE)&&&&&&& "\0"&& 109&&& #endif&& 110&&& #ifdef&&& CONFIG_LOADADDR&& 111&&&&&&& "loadaddr="&&& MK_STR(CONFIG_LOADADDR)&&&&&&& "\0"&& 112&&& #endif&& 113&&& #ifdef& CONFIG_CLOCKS_IN_MHZ&& 114&&&&&&& "clocks_in_mhz=1\0"&& 115&&& #endif&& 116&&& #ifdef CONFIG_MACH_MINI2440&& 117&&&&&&& "mach_id="&&&&& MK_STR(CONFIG_MACH_MINI2440)&&& "\0" /* snallie */&& 118&&& #endif&& /* &&&&&& * 116~118定义了一个环境变量mach_id,其默认取值为include/configs/config_mini2440.h中定义的CONFIG_MACH_MINI2440,本文件只有此处改动&&& */&& && 119&&&&&&& "\0"&& 120&&& };&& 121&&& && 122&&& static int envmatch (bd_t *, uchar *, int);&& 123&&& && 124&&& /*&& 125&&&& * return one character from env&& 126&&&& */&& 127&&& static uchar get_env_char(bd_t *bd, int index)&& 128&&& {&& 129&&&&&&&&& 130&&&&&& && 131&&&&&&& /* use RAM copy, if possible */&& 132&&&&&&& if (bd-&bi_env)&& 133&&&&&&& {&& 134&&&&&&& if (index & sizeof(bd-&bi_env_data))&& 135&&&&&&&&& c = bd-&bi_env_data[index];&& 136&&&&&&& else&& 137&&&&&&&&& panic("bad size for get_env_char!\n");&& 138&&&&&&& }&& 139&&&&&&& else&& 140&&&&&&& {&& 141&&&&&&& /* try a board specific lookup */&& 142&&&&&&& if (board_env_getchar(bd, index, &c) & 0)&& 143&&&&&&& {&& 144&&&&&&&&&&& if (index & sizeof(default_environment))&& 145&&&&&&&&&&&&& c = default_environment[index];&& 146&&&&&&&&&&& else && 147&&&&&&&&&&&&& panic("bad size for get_env_char!\n");&& 148&&&&&&& }&& 149&&&&&&& }&& 150&&&&&&&&& 151&&& }&& 152&&& && 153&&& /*&& 154&&&& * return address into environment&& 155&&&& */&& 156&&& static uchar *get_env_addr(bd_t *bd, int index)&& 157&&& {&& 158&&&&&&& uchar *p = 0;&& 159&&&&&& && 160&&&&&&& /* use RAM copy, if possible */&& 161&&&&&&& if (bd-&bi_env)&& 162&&&&&&& {&& 163&&&&&&& if (index & sizeof(bd-&bi_env_data))&& 164&&&&&&&&& p = &bd-&bi_env_data[index];&& 165&&&&&&& else&& 166&&&&&&&&& panic("bad size for get_env_char!\n");&& 167&&&&&&& }&& 168&&&&&&& else&& 169&&&&&&& {&& 170&&&&&&& /* try a board specific lookup */&& 171&&&&&&& if ((p = board_env_getaddr(bd, index)) == 0)&& 172&&&&&&& {&& 173&&&&&&&&&&& if (index & sizeof(default_environment))&& 174&&&&&&&&&&&&& p = &default_environment[index];&& 175&&&&&&&&&&& else && 176&&&&&&&&&&&&& panic("bad size for get_env_char!\n");&& 177&&&&&&& }&& 178&&&&&&& }&& 179&&&&&&&&& 180&&& }&& 181&&& && 182&&& /************************************************************************&& 183&&&& * Command interface: print one or all environment variables&& 184&&&& */&& 185&&& && 186&&& int do_printenv (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])&& 187&&& {&& 188&&&&&&& int i, j, k,&& 189&&&&&&& && 190&&&&&&& if (argc == 1) {&&&&&&& /* Print all env variables&&& */&& 191&&&&&&& for (i=0; get_env_char(bd, i) != '\0'; i=nxt+1) {&& 192&&&&&&&&&&& for (nxt=i; get_env_char(bd, nxt) != '\0'; ++nxt)&& 193&&&&&&&&&&&&& ;&& 194&&&&&&&&&&& for (k=i; k& ++k)&& 195&&&&&&&&&&&&& putc(get_env_char(bd, k));&& 196&&&&&&&&&&& putc& ('\n');&& 197&&&&&&&&&&& && 198&&&&&&&&&&& if (ctrlc()) {&& 199&&&&&&&&&&& printf ("\n ** Abort\n");&& 200&&&&&&&&&&& return 1;&& 201&&&&&&&&&&& }&& 202&&&&&&& }&& 203&&&&&&& && 204&&&&&&& printf("\nEnvironment size: %d/%d bytes\n", i, sizeof(bd-&bi_env_data));&& 205&&&&&&& && 206&&&&&&& return 0;&& 207&&&&&&& }&& 208&&&&&&& && 209&&&&&&& for (i=1; i& ++i) {&&& /* print single env variables&&& */&& 210&&&&&&& char *name = argv[i];&& 211&&&&&&& && 212&&&&&&& k = -1;&& 213&&&&&&& && 214&&&&&&& for (j=0; get_env_char(bd, j) != '\0'; j=nxt+1) {&& 215&&&&&&&&&&& && 216&&&&&&&&&&& for (nxt=j; get_env_char(bd, nxt) != '\0'; ++nxt)&& 217&&&&&&&&&&&&& ;&& 218&&&&&&&&&&& k = envmatch(bd, name, j);&& 219&&&&&&&&&&& if (k & 0) {&& 220&&&&&&&&&&&&& 221&&&&&&&&&&& }&& 222&&&&&&&&&&& puts (name);&& 223&&&&&&&&&&& putc ('=');&& 224&&&&&&&&&&& while (k & nxt)&& 225&&&&&&&&&&&&& putc(get_env_char(bd, k++));&& 226&&&&&&&&&&& putc ('\n');&& 227&&&&&&&&&&&&& 228&&&&&&& }&& 229&&&&&&& if (k & 0)&& 230&&&&&&& {&& 231&&&&&&&&& printf ("## Error: \"%s\" not defined\n", name);&& 232&&&&&&&&& return 1;&& 233&&&&&&& }&& 234&&&&&&& }&& 235&&&&&&& return 0;&& 236&&& }&& 237&&& && 238&&& /************************************************************************&& 239&&&& * Set a new environment variable,&& 240&&&& * or replace or delete an existing one.&& 241&&&& *&& 242&&&& * This function will ONLY work with a in-RAM copy of the environment&& 243&&&& */&& 244&&& && 245&&& int _do_setenv (bd_t *bd, int flag, int argc, char *argv[])&& 246&&& {&& 247&&&&&&& int&& i, len,&& 248&&&&&&& uchar *env, *nxt = 0;&& 249&&&&&&& uchar *&& 250&&&&&&& && 251&&&&&&& /* need writable copy in RAM */&& 252&&&&&&& if (!bd-&bi_env_data)&& 253&&&&&&&&& return 1;&& 254&&& && 255&&&&&&& name = argv[1];&& 256&&&&&&& && 257&&&&&&& /*&& 258&&&&&&&& * search if variable with this name already exists&& 259&&&&&&&& */&& 260&&&&&&& oldval = -1;&& 261&&&&&&& for (env = bd-&bi_env_ * env = nxt+1) {&& 262&&&&&&& for (nxt = * ++nxt)&& 263&&&&&&&&& ;&& 264&&&&&&& if ((oldval = envmatch(bd, name, (ulong)env - (ulong)bd-&bi_env_data)) &= 0)&& 265&&&&&&&&&&& 266&&&&&&& }&& 267&&&&&&& && 268&&&&&&& /*&& 269&&&&&&&& * Delete any existing definition&& 270&&&&&&&& */&& 271&&&&&&& if (oldval &= 0) {&& 272&&& #ifndef CONFIG_ENV_OVERWRITE&& 273&&&&&&& && 274&&&&&&& /*&& 275&&&&&&&& * Ethernet Address and serial# can be set only once&& 276&&&&&&&& */&& 277&&&&&&& if ( (strcmp (name, "serial#") == 0) ||&& 278&&&&&&&&&&& ((strcmp (name, "ethaddr") == 0)&& 279&&& # if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)&& 280&&&&&&&&&&&& && (strcmp (get_env_addr(bd, oldval),MK_STR(CONFIG_ETHADDR)) != 0)&& 281&&& # endif&&& /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */&& 282&&&&&&&&&&&& ) ) {&& 283&&&&&&&&&&& printf ("Can't overwrite \"%s\"\n", name);&& 284&&&&&&&&&&& return 1;&& 285&&&&&&& }&& 286&&& #endif&& 287&&&&&&& && 288&&&&&&& /*&& 289&&&&&&&& * Switch to new baudrate if new baudrate is supported&& 290&&&&&&&& */&& 291&&&&&&& if (strcmp(argv[1],"baudrate") == 0) {&& 292&&&&&&&&&&& int baudrate = simple_strtoul(argv[2], NULL, 10);&& 293&&&&&&&&&&&&& 294&&&&&&&&&&& for (i=0; i&N_BAUDRATES; ++i) {&& 295&&&&&&&&&&& if (baudrate == baudrate_table[i])&& 296&&&&&&&&&&&&&&& 297&&&&&&&&&&& }&& 298&&&&&&&&&&& if (i == N_BAUDRATES) {&& 299&&&&&&&&&&& printf ("## Baudrate %d bps not supported\n",&& 300&&&&&&&&&&&&&&& baudrate);&& 301&&&&&&&&&&& return 1;&& 302&&&&&&&&&&& }&& 303&&&&&&&&&&& printf ("## Switch baudrate to %d bps and press ENTER ...\n",&& 304&&&&&&&&&&&&&&& baudrate);&& 305&&&&&&&&&&& udelay(50000);&& 306&&&&&&&&&&& serial_setbrg (bd, baudrate);&& 307&&&&&&&&&&& udelay(50000);&& 308&&&&&&&&&&& for (;;) {&& 309&&&&&&&&&&& if (getc() == '\r')&& 310&&&&&&&&&&&&&&& 311&&&&&&&&&&& }&& 312&&&&&&&&&&& bd-&bi_baudrate =&& 313&&&&&&& }&& 314&&&&&&& && 315&&&&&&& if (*++nxt == '\0') {&& 316&&&&&&&&&&& if ((ulong)env & (ulong)bd-&bi_env_data) {&& 317&&&&&&&&&&& env--;&& 318&&&&&&&&&&& } else {&& 319&&&&&&&&&&& *env = '\0';&& 320&&&&&&&&&&& }&& 321&&&&&&& } else {&& 322&&&&&&&&&&& for (;;) {&& 323&&&&&&&&&&& *env = *nxt++;&& 324&&&&&&&&&&& if ((*env == '\0') && (*nxt == '\0'))&& 325&&&&&&&&&&&&&&& 326&&&&&&&&&&& ++&& 327&&&&&&&&&&& }&& 328&&&&&&& }&& 329&&&&&&& *++env = '\0';&& 330&&&&&&& }&& 331&&&&&&& /* Delete only ? */&& 332&&&&&&& if ((argc & 3) || argv[2] == NULL) {&&& && 333&&&&&&& /* Update CRC */&& 334&&&&&&& bd-&bi_env_crc = crc32(0, bd-&bi_env_data, sizeof(bd-&bi_env_data));&& 335&&&&&&& return 0;&& 336&&&&&&& }&& 337&&& && 338&&&&&&& /*&& 339&&&&&&&& * Append new definition at the end&& 340&&&&&&&& */&& 341&&&&&&& for (env = bd-&bi_env_ *env || *(env+1); ++env)&& 342&&&&&&&&& ;&& 343&&&&&&& if ((ulong)env & (ulong)bd-&bi_env_data)&& 344&&&&&&&&& ++&& 345&&&&&&& /*&& 346&&&&&&&& * Overflow when:&& 347&&&&&&&& * "name" + "=" + "val" +"\0\0"& & && 348&&&&&&&& *&&&&& sizeof(bd-&bi_env_data) - (env-bd-&bi_env_data)&& 349&&&&&&&& */&& 350&&&&&&& len = strlen(name) + 2;&& 351&&&&&&& /* add '=' for first arg, ' ' for all others */&& 352&&&&&&& for (i=2; i& ++i) {&& 353&&&&&&& len += strlen(argv[i]) + 1;&& 354&&&&&&& }&& 355&&&&&&& if (len & sizeof(bd-&bi_env_data)) {&& 356&&&&&&& printf ("## Error: environment overflow, \"%s\" deleted\n", name);&& 357&&&&&&& return 1;&& 358&&&&&&& }&& 359&&&&&&& while ((*env = *name++) != '\0')&& 360&&&&&&&&& env++;&& 361&&&&&&& for (i=2; i& ++i) {&& 362&&&&&&& char *val = argv[i];&& 363&&&&&&& && 364&&&&&&& *env = (i==2) ? '=' : ' ';&& 365&&&&&&& while ((*++env = *val++) != '\0')&& 366&&&&&&&&& ;&& 367&&&&&&& }&& 368&&&&&&& && 369&&&&&&& /* end is marked with double '\0' */&& 370&&&&&&& *++env = '\0';&& 371&&&&&&& && 372&&&&&&& /* Update CRC */&& 373&&&&&&& bd-&bi_env_crc = crc32(0, bd-&bi_env_data, sizeof(bd-&bi_env_data));&& 374&&& && 375&&&&&&& /*&& 376&&&&&&&& * Some variables should be updated when the corresponding&& 377&&&&&&&& * entry in the enviornment is changed&& 378&&&&&&&& */&& 379&&&&&&& && 380&&&&&&& if (strcmp(argv[1],"ethaddr") == 0) {&& 381&&&&&&& char *s = argv[2];&&& /* always use only one arg */&& 382&&&&&&& char *e;&& 383&&&&&&& for (i=0; i&6; ++i) {&& 384&&&&&&&&&&& bd-&bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;&& 385&&&&&&&&&&& if (s) s = (*e) ? e+1 :&& 386&&&&&&& }&& 387&&&&&&& return 0;&& 388&&&&&&& }&& 389&&& && 390&&&&&&& if (strcmp(argv[1],"ipaddr") == 0) {&& 391&&&&&&& char *s = argv[2];&&& /* always use only one arg */&& 392&&&&&&& char *e;&& 393&&&&&&& bd-&bi_ip_addr = 0;&& 394&&&&&&& for (i=0; i&4; ++i) {&& 395&&&&&&&&&&& ulong val = s ? simple_strtoul(s, &e, 10) : 0;&& 396&&&&&&&&&&& bd-&bi_ip_addr &&= 8;&& 397&&&&&&&&&&& bd-&bi_ip_addr& |= (val & 0xFF);&& 398&&&&&&&&&&& if (s) s = (*e) ? e+1 :&& 399&&&&&&& }&& 400&&&&&&& return 0;&& 401&&&&&&& }&& 402&&& && 403&&&&&&& if (strcmp(argv[1],"loadaddr") == 0) {&& 404&&&&&&& load_addr = simple_strtoul(argv[2], NULL, 16);&& 405&&&&&&& return 0;&& 406&&&&&&& }&& 407&&& && 408&&& #if (CONFIG_COMMANDS & CFG_CMD_NET)&& 409&&&&&&& if (strcmp(argv[1],"bootfile") == 0) {&& 410&&&&&&& copy_filename (BootFile, argv[2], sizeof(BootFile));&& 411&&&&&&& return 0;&& 412&&&&&&& }&& 413&&& #endif&&& /* CFG_CMD_NET */&& 414&&& && 415&&&&&&& return 0;&& 416&&& }&& 417&&& && 418&&& void setenv (bd_t * bd, char *varname, char *varvalue)&& 419&&& {&& 420&&&&&&& char *argv[4] = { "setenv", varname, varvalue, NULL };&& 421&&&&&&& _do_setenv (bd, 0, 3, argv);&& 422&&& }&& 423&&& && 424&&& int do_setenv (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc,&& 425&&&&&&&&&&& char *argv[])&& 426&&& {&& 427&&&&&&& if (argc & 2) {&& 428&&&&&&& printf ("Usage:\n%s\n", cmdtp-&usage);&& 429&&&&&&& return 1;&& 430&&&&&&& }&& 431&&& && 432&&&&&&& return _do_setenv (bd, flag, argc, argv);&& 433&&& }&& 434&&& && 435&&& /************************************************************************&& 436&&&& * Prompt for environment variable&& 437&&&& */&& 438&&& && 439&&& #if (CONFIG_COMMANDS & CFG_CMD_ASKENV)&& 440&&& int do_askenv (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc,&& 441&&&&&&&&&&& char *argv[])&& 442&&& {&& 443&&&&&&& extern char console_buffer[CFG_CBSIZE];&& 444&&&&&&& char message[CFG_CBSIZE];&& 445&&&&&&& int size = CFG_CBSIZE - 1;&& 446&&&&&&&&& 447&&&&&&& char *local_args[4];&& 448&&&&&&& && 449&&&&&&& local_args[0] = argv[0];&& 450&&&&&&& local_args[1] = argv[1];&& 451&&&&&&& local_args[2] = NULL;&& 452&&&&&&& local_args[3] = NULL;&& 453&&&&&&& && 454&&&&&&& if (argc & 2) {&& 455&&&&&&& printf ("Usage:\n%s\n", cmdtp-&usage);&& 456&&&&&&& return 1;&& 457&&&&&&& }&& 458&&&&&&& /* Check the syntax */&& 459&&&&&&& switch (argc) {&& 460&&&&&&& case 1:&& 461&&&&&&& printf ("Usage:\n%s\n", cmdtp-&usage);&& 462&&&&&&& return 1;&& 463&&&&&&& && 464&&&&&&& case 2:&&&&&&& /* askenv envname */&& 465&&&&&&& sprintf (message, "Please enter '%s':", argv[1]);&& 466&&&&&&&&& 467&&&&&&& && 468&&&&&&& case 3:&&&&&&& /* askenv envname size */&& 469&&&&&&& sprintf (message, "Please enter '%s':", argv[1]);&& 470&&&&&&& size = simple_strtoul (argv[2], NULL, 10);&& 471&&&&&&&&& 472&&&&&&& && 473&&&&&&& default:&&& /* askenv envname message1 ... messagen size */&& 474&&&&&&& {&& 475&&&&&&&&&&&&& 476&&&&&&&&&&& int pos = 0;&& 477&&&&&&&&&&& && 478&&&&&&&&&&& for (i = 2; i & argc - 1; i++) {&& 479&&&&&&&&&&& if (pos) {&& 480&&&&&&&&&&&&&&& message[pos++] = ' ';&& 481&&&&&&&&&&& }&& 482&&&&&&&&&&& strcpy (message+pos, argv[i]);&& 483&&&&&&&&&&& pos += strlen(argv[i]);&& 484&&&&&&&&&&& }&& 485&&&&&&&&&&& message[pos] = '\0';&& 486&&&&&&&&&&& size = simple_strtoul (argv[argc - 1], NULL, 10);&& 487&&&&&&& }&& 488&&&&&&& }&& 489&&&&&&& && 490&&&&&&& if (size &= CFG_CBSIZE)&& 491&&&&&&&&& size = CFG_CBSIZE - 1;&& 492&&& && 493&&&&&&& if (size &= 0)&& 494&&&&&&&&& return 1;&& 495&&& && 496&&&&&&& /* prompt for input */&& 497&&&&&&& len = readline (message);&& 498&&& && 499&&&&&&& if (size & len)&& 500&&&&&&&&& console_buffer[size] = '\0';&& 501&&& && 502&&&&&&& len = 2;&& 503&&&&&&& if (console_buffer[0] != '\0') {&& 504&&&&&&& local_args[2] = console_&& 505&&&&&&& len = 3;&& 506&&&&&&& }&& 507&&&&&&& && 508&&&&&&& // Continue calling setenv code&& 509&&&&&&& return _do_setenv (bd, flag, len, local_args);&& 510&&& }&& 511&&& #endif&&& /* CFG_CMD_ASKENV */&& 512&&& && 513&&& /************************************************************************&& 514&&&& * Look up variable from environment,&& 515&&&& * return address of storage for that variable,&& 516&&&& * or NULL if not found&& 517&&&& */&& 518&&& && 519&&& char *getenv (bd_t * bd, uchar *name)&& 520&&& {&& 521&&&&&&& int i,&& 522&&&&&&& && 523&&&&&&& for (i=0; get_env_char(bd, i) != '\0'; i=nxt+1) {&& 524&&&&&&&&& 525&&&&&&& && 526&&&&&&& for (nxt=i; get_env_char(bd, nxt) != '\0'; ++nxt) {&& 527&&&&&&&&&&& if (nxt &= sizeof(bd-&bi_env_data)) {&& 528&&&&&&&&&&& return (NULL);&& 529&&&&&&&&&&& }&& 530&&&&&&& }&& 531&&&&&&& if ((val=envmatch(bd, name, i)) & 0)&& 532&&&&&&&&&&& 533&&&&&&& return (get_env_addr(bd, val));&& 534&&&&&&& }&& 535&&&&&&& && 536&&&&&&& return (NULL);&& 537&&& }&& 538&&& && 539&&& && 540&&& /************************************************************************&& 541&&&& * Match a name / name=value pair&& 542&&&& *&& 543&&&& * s1 is either a simple 'name', or a 'name=value' pair.&& 544&&&& * i2 is the environment index for a 'name2=value2' pair.&& 545&&&& * If the names match, return the index for the value2, else NULL.&& 546&&&& */&& 547&&& && 548&&& static int envmatch (bd_t *bd, uchar *s1, int i2)&& 549&&& {&& 550&&& && 551&&&&&&& while (*s1 == get_env_char(bd, i2++))&& 552&&&&&&&&&&& if (*s1++ == '=')&& 553&&&&&&&&&&&&&&& return(i2);&& 554&&&&&&& if (*s1 == '\0' && get_env_char(bd, i2-1) == '=')&& 555&&&&&&&&&&& return(i2);&& 556&&&&&&& return(-1);&& 557&&& }&& 558&&& && 559&&& && 560&&& #if (CONFIG_COMMANDS & CFG_CMD_ENV)&& 561&&& && 562&&& int do_saveenv& (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])&& 563&&& {&& 564&&&&&&& return (board_env_save(bd, bd-&bi_env, sizeof(env_t))) ? 1 : 0;&& 565&&& }&& 566&&& && 567&&& #endif&&& /* CFG_CMD_ENV */&& 568&&& && 569&&& && 570&&& void env_init(bd_t *bd)&& 571&&& {&& 572&&&&&&& bd-&bi_env = 0;&& 573&&& }&& 574&&& && 575&&& void env_relocate(bd_t *bd)&& 576&&& {&& 577&&&&&&& char *s, *e;&& 578&&&&&&&&& 579&&&&&& && 580&&&&&&& bd-&bi_env = malloc(sizeof(env_t));&& 581&&& && 582&&&&&&& if (board_env_copy(bd, bd-&bi_env, sizeof(env_t)) & 0)&& 583&&&&&&& {&& 584&&&&&&& printf("*** Using default environment\n");&& 585&&&&&&& memcpy(bd-&bi_env_data, default_environment, && 586&&&&&&&&&&&&&& sizeof(default_environment));&& 587&&&&&&& bd-&bi_env_crc = crc32(0, bd-&bi_env_data, sizeof(bd-&bi_env_data));&& 588&&&&&&& }&& 589&&&&&&& && 590&&&&&&& /* now initialise some variables */&& 591&&&&&&& && 592&&&&&&& /* MAC address */&& 593&&&&&&& s = getenv(bd, "ethaddr");&& 594&&&&&&& for (reg=0; reg&6; reg++) && 595&&&&&&& {&& 596&&&&&&& bd-&bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0;&& 597&&&&&&& if (s)&& 598&&&&&&&&& s = (*e) ? e+1 :&& 599&&&&&&& }&& 600&&& && 601&&&&&&& /* IP address */&& 602&&&&&&& bd-&bi_ip_addr = 0;&& 603&&&&&&& s = getenv(bd, "ipaddr");&& 604&&&&&&& for (reg=0; reg&4; ++reg) {&&& && 605&&&&&&&&&&& ulong val = s ? simple_strtoul(s, &e, 10) : 0;&& 606&&&&&&&&&&& bd-&bi_ip_addr &&= 8;&& 607&&&&&&&&&&& bd-&bi_ip_addr& |= (val & 0xFF);&& 608&&&&&&&&&&& if (s)&& 609&&&&&&&&& s = (*e) ? e+1 :&& 610&&&&&&& }&& 611&&&&&&& && 612&&&&&&& if ((s = getenv(bd, "loadaddr")) != NULL) {&&& && 613&&&&&&&&&&& load_addr = simple_strtoul(s, NULL, 16);&& 614&&&&&&& }&& 615&&&&&&& && 616&&& #if (CONFIG_COMMANDS & CFG_CMD_NET)&& 617&&&&&&& if ((s = getenv(bd, "bootfile")) != NULL) {&&& && 618&&&&&&&&&&& copy_filename (BootFile, s, sizeof(BootFile));&& 619&&&&&&& }&& 620&&& #endif& /* CFG_CMD_NET */&& 621&&& }
/////////////11
相关资讯 & & &
& (12/27/:58)
& (02/27/:23)
& (06/08/:51)
& (12/27/:33)
& (01/12/:23)
& (05/15/:47)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款}

我要回帖

更多关于 analog devices公司 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信