]> git.sur5r.net Git - u-boot/blobdiff - lib/hashtable.c
ARM: relocation: don't undef CONFIG_SYS_ARM_WITHOUT_RELOC
[u-boot] / lib / hashtable.c
index 2f3b5c8d1026eaa7cc9edd0864e505fcd9056d40..57802cfb6ded27e14490e601c1cc081d0829a368 100644 (file)
 # include <linux/string.h>
 #endif
 
+#ifndef        CONFIG_ENV_MIN_ENTRIES  /* minimum number of entries */
+#define        CONFIG_ENV_MIN_ENTRIES 64
+#endif
+#ifndef        CONFIG_ENV_MAX_ENTRIES  /* maximum number of entries */
+#define        CONFIG_ENV_MAX_ENTRIES 512
+#endif
+
 #include "search.h"
 
 /*
@@ -636,15 +643,24 @@ int himport_r(struct hsearch_data *htab,
         * table size is based on heuristics: in a sample of some 70+
         * existing systems we found an average size of 39+ bytes per entry
         * in the environment (for the whole key=value pair). Assuming a
-        * size of 7 per entry (= safety factor of >5) should provide enough
-        * safety margin for any existing environment definitons and still
+        * size of 8 per entry (= safety factor of ~5) should provide enough
+        * safety margin for any existing environment definitions and still
         * allow for more than enough dynamic additions. Note that the
         * "size" argument is supposed to give the maximum enviroment size
-        * (CONFIG_ENV_SIZE).
+        * (CONFIG_ENV_SIZE).  This heuristics will result in
+        * unreasonably large numbers (and thus memory footprint) for
+        * big flash environments (>8,000 entries for 64 KB
+        * envrionment size), so we clip it to a reasonable value.
+        * On the other hand we need to add some more entries for free
+        * space when importing very small buffers. Both boundaries can
+        * be overwritten in the board config file if needed.
         */
 
        if (!htab->table) {
-               int nent = size / 7;
+               int nent = CONFIG_ENV_MIN_ENTRIES + size / 8;
+
+               if (nent > CONFIG_ENV_MAX_ENTRIES)
+                       nent = CONFIG_ENV_MAX_ENTRIES;
 
                debug("Create Hash Table: N=%d\n", nent);
 
@@ -705,17 +721,19 @@ int himport_r(struct hsearch_data *htab,
 
                hsearch_r(e, ENTER, &rv, htab);
                if (rv == NULL) {
-                       printf("himport_r: can't insert \"%s=%s\" into hash table\n", name, value);
+                       printf("himport_r: can't insert \"%s=%s\" into hash table\n",
+                               name, value);
                        return 0;
                }
 
-               debug("INSERT: %p ==> name=\"%s\" value=\"%s\"\n", rv, name,
-                      value);
-               debug("        table = %p, size = %d, filled = %d\n", htab,
-                      htab->size, htab->filled);
+               debug("INSERT: table %p, filled %d/%d rv %p ==> name=\"%s\" value=\"%s\"\n",
+                       htab, htab->filled, htab->size,
+                       rv, name, value);
        } while ((dp < data + size) && *dp);    /* size check needed for text */
                                                /* without '\0' termination */
+       debug("INSERT: free(data = %p)\n", data);
        free(data);
 
+       debug("INSERT: done\n");
        return 1;               /* everything OK */
 }