X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=common%2Fenv_common.c;h=c3e6388ac0b2379f48f5344c62a5bcf67db88377;hb=6052cbab40e927f94bcb034f1b4c76a18d6729e1;hp=a415ef8efe5d9ba19e2eff4b5c1a990cae08f3fb;hpb=ea882baf9c17cd142c99e3ff640d3ab01daa5cec;p=u-boot diff --git a/common/env_common.c b/common/env_common.c index a415ef8efe..c3e6388ac0 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -129,6 +129,8 @@ uchar default_environment[] = { "\0" }; +struct hsearch_data env_htab; + static uchar env_get_char_init (int index) { uchar c; @@ -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,54 +229,49 @@ int env_import(const char *buf, int check) 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); -#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) - ; + while ((idx = hmatch_r(var, idx, &match, &env_htab))) { + int vallen = strlen(match->key) + 1; - lval = (char *)env_get_addr(i); - rval = strchr(lval, '='); - if (rval != NULL) { - vallen = rval - lval; - rval++; - } else - vallen = strlen(lval); - - 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; }