[U-Boot] is it necessary to set "gd->env_valid = 0" in getenv_default()?

Robert P. J. Day rpjday at crashcourse.ca
Tue Sep 6 12:47:14 CEST 2016


  still wandering through the bowels of u-boot environment
manipulation code, and i see this in common/env_common.c:

  /*
   * Look up the variable from the default environment
   */
  char *getenv_default(const char *name)
  {
        char *ret_val;
        unsigned long really_valid = gd->env_valid;
        unsigned long real_gd_flags = gd->flags;

        /* Pretend that the image is bad. */
        gd->flags &= ~GD_FLG_ENV_READY;
        gd->env_valid = 0;                  <--- ?????
        ret_val = getenv(name);
        gd->env_valid = really_valid;
        gd->flags = real_gd_flags;
        return ret_val;
  }

fair enough ... in order to read a variable explicitly from the
(default) environment, temporarily fake that there is nothing in the
hash table, so this statement makes sense:

        gd->flags &= ~GD_FLG_ENV_READY;

but is this one immediately afterwards also necessary?

        gd->env_valid = 0;

because once you get to getenv() as defined in cmd/nvedit.c:

  char *getenv(const char *name)
  {
        if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
                ENTRY e, *ep;

                WATCHDOG_RESET();

                e.key   = name;
                e.data  = NULL;
                hsearch_r(e, FIND, &ep, &env_htab, 0);

                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);

        return NULL;
  }

it seems that the only test is for GD_ENV_FLG_READY, so setting
gd->env_valid=0 seems unnecessary. but perhaps i'm not reading far
enough.

rday

p.s. just to be clear, the meanings of those two gd members is:

  gd->flags & GD_FLG_ENV_READY means the environment has been imported
into a hash table, and

  gd->env_valid means the CRC for the environment in persistent
storage is correct.

do i understand that correctly?



More information about the U-Boot mailing list