X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fenv_common.c;h=19149b513dc0eb1a68f3b120c2e11ea23a754dff;hb=98e99e5a48e8eb3987c89f5316929313601ed7d6;hp=88f068cc38b8e9785569d87c328ae70034a4d395;hpb=e67f46286440a53fb1d693152667ea3b1a6b3060;p=u-boot diff --git a/common/env_common.c b/common/env_common.c index 88f068cc38..19149b513d 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -47,7 +47,7 @@ static uchar env_get_char_init (int index); #define XMK_STR(x) #x #define MK_STR(x) XMK_STR(x) -uchar default_environment[] = { +const uchar default_environment[] = { #ifdef CONFIG_BOOTARGS "bootargs=" CONFIG_BOOTARGS "\0" #endif @@ -129,6 +129,8 @@ uchar default_environment[] = { "\0" }; +struct hsearch_data env_htab; + static uchar env_get_char_init (int index) { uchar c; @@ -160,7 +162,7 @@ uchar env_get_char (int index) return (c); } -uchar *env_get_addr (int index) +const uchar *env_get_addr (int index) { if (gd->env_valid) return (uchar *)(gd->env_addr + index); @@ -187,7 +189,7 @@ void set_default_env(const char *s) puts("Using default environment\n\n"); } - if (himport((char *)default_environment, + if (himport_r(&env_htab, (char *)default_environment, sizeof(default_environment), '\0', 0) == 0) { error("Environment import failed: errno = %d\n", errno); } @@ -213,7 +215,7 @@ int env_import(const char *buf, int check) } } - if (himport((char *)ep->data, ENV_SIZE, '\0', 0)) { + if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0)) { gd->flags |= GD_FLG_ENV_READY; return 1; } @@ -227,7 +229,7 @@ int env_import(const char *buf, int check) void env_relocate (void) { -#if !defined(CONFIG_RELOC_FIXUP_WORKS) +#if defined(CONFIG_NEEDS_MANUAL_RELOC) extern void env_reloc(void); env_reloc(); @@ -237,49 +239,39 @@ void env_relocate (void) set_default_env(NULL); #else show_boot_progress (-60); -#endif set_default_env("!bad CRC"); +#endif } else { env_relocate_spec (); } } -#if 0 /* need to reimplement - def CONFIG_AUTO_COMPLETE */ +#ifdef CONFIG_AUTO_COMPLETE int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf) { - int i, nxt, len, vallen, found; - const char *lval, *rval; + ENTRY *match; + int found, idx; + idx = 0; found = 0; cmdv[0] = NULL; - len = strlen(var); - /* now iterate over the variables and select those that match */ - for (i=0; env_get_char(i) != '\0'; i=nxt+1) { - - for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) - ; - - lval = (char *)env_get_addr(i); - rval = strchr(lval, '='); - if (rval != NULL) { - vallen = rval - lval; - rval++; - } else - vallen = strlen(lval); + while ((idx = hmatch_r(var, idx, &match, &env_htab))) { + int vallen = strlen(match->key) + 1; - if (len > 0 && (vallen < len || memcmp(lval, var, len) != 0)) - continue; - - if (found >= maxv - 2 || bufsz < vallen + 1) { - cmdv[found++] = "..."; + if (found >= maxv - 2 || bufsz < vallen) break; - } + cmdv[found++] = buf; - memcpy(buf, lval, vallen); buf += vallen; bufsz -= vallen; - *buf++ = '\0'; bufsz--; + memcpy(buf, match->key, vallen); + buf += vallen; + bufsz -= vallen; } + qsort(cmdv, found, sizeof(cmdv[0]), strcmp_compar); + + if (idx) + cmdv[found++] = "..."; cmdv[found] = NULL; return found; }