diff --git a/api/api.c b/api/api.c index c5f6edb..1cdc72b 100644 --- a/api/api.c +++ b/api/api.c @@ -495,45 +495,47 @@ static int API_env_set(va_list ap) */ static int API_env_enum(va_list ap) { - int i, n; - char *last, **next; + int i; + char *last, **next, *s; + ENTRY *match, search; + static char *buf; last = (char *)va_arg(ap, u_int32_t); if ((next = (char **)va_arg(ap, u_int32_t)) == NULL) return API_EINVAL; - if (last == NULL) - /* start over */ - *next = ((char *)env_get_addr(0)); - else { - *next = last; - - for (i = 0; env_get_char(i) != '\0'; i = n + 1) { - for (n = i; env_get_char(n) != '\0'; ++n) { - if (n >= CONFIG_ENV_SIZE) { - /* XXX shouldn't we set *next = NULL?? */ - return 0; - } - } - - if (envmatch((uchar *)last, i) < 0) - continue; - - /* try to get next name */ - i = n + 1; - if (env_get_char(i) == '\0') { - /* no more left */ - *next = NULL; - return 0; - } - - *next = ((char *)env_get_addr(i)); - return 0; + /* + * This leverages realloc's behavior of growing but never shrinking the + * existing buffer. + */ + if (last == NULL) { + i = 0; + buf = realloc(buf, 512); /* Start with reasonable size buf. */ + } else { + buf = realloc(buf, strlen(last) + 1); + strcpy(buf, last); + if ((s = strchr(buf, '=')) != NULL) + *s = 0; + search.key = buf; + if ((i = hsearch_r(search, FIND, &match, &env_htab, 0)) == 0) { + i = API_EINVAL; + goto done; } } + /* hmatch on empty string is effectively "get next entry after i". */ + if ((i = hmatch_r("", i, &match, &env_htab)) == 0) + goto done; + buf = realloc(buf, strlen(match->key) + strlen(match->data) + 2); + snprintf(buf, buflen, "%s=%s", match->key, match->data); + *next = buf; return 0; +done: + free(buf); + buf = NULL; + *next = NULL; + return i; } /* diff --git a/api/api_storage.c b/api/api_storage.c index b76b07d..89d071e 100644 --- a/api/api_storage.c +++ b/api/api_storage.c @@ -107,10 +107,13 @@ static int dev_stor_get(int type, int first, int *more, struct device_info *di) if (first) { di->cookie = (void *)get_dev(specs[type].name, 0); - if (di->cookie == NULL) + if (di->cookie == NULL) { return 0; - else + } else { found = 1; + if (specs[type].max_dev > 1) + *more = 1; + } } else { for (i = 0; i < specs[type].max_dev; i++) @@ -146,7 +149,8 @@ static int dev_stor_get(int type, int first, int *more, struct device_info *di) dd = (block_dev_desc_t *)di->cookie; if (dd->type == DEV_TYPE_UNKNOWN) { debugf("device instance exists, but is not active.."); - found = 0; + di->di_stor.block_count = 0; + di->di_stor.block_size = 0; } else { di->di_stor.block_count = dd->lba; di->di_stor.block_size = dd->blksz; diff --git a/common/cmd_elf.c b/common/cmd_elf.c index ab9c7e3..e5ad434 100644 --- a/common/cmd_elf.c +++ b/common/cmd_elf.c @@ -35,22 +35,12 @@ unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), unsigned long ret; /* - * QNX images require the data cache is disabled. - * Data cache is already flushed, so just turn it off. - */ - int dcache = dcache_status(); - if (dcache) - dcache_disable(); - - /* - * pass address parameter as argv[0] (aka command name), - * and all remaining args + * FreeBSD wants the caches enabled while ubldr runs, and as of r276397 + * the kernel can tolerate being entered with internal (but not external + * PL310) caches enabled on armv6/7 systems. So don't disable caches + * here, just launch the program directly. */ ret = entry(argc, argv); - - if (dcache) - dcache_enable(); - return ret; } diff --git a/common/cmd_test.c b/common/cmd_test.c index c93fe78..b0837de 100644 --- a/common/cmd_test.c +++ b/common/cmd_test.c @@ -65,9 +65,14 @@ static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char * const *ap; int i, op, left, adv, expr, last_expr, last_unop, last_binop; - /* args? */ - if (argc < 3) + /* + * If no args, that's bogus, return false. + * If op is -z and no other args, answer is Yes, string is empty. + */ + if (argc < 2) return 1; + else if (argc == 2) + return !(strcmp(argv[1], "-z") == 0); #ifdef DEBUG { diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index a26f3ce..8c14baf 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -20,6 +20,7 @@ static struct list_head mmc_devices; static int cur_dev_num = -1; +static int mmc_error_print_max = -1; __weak int board_mmc_getwp(struct mmc *mmc) { @@ -1262,9 +1263,14 @@ void mmc_destroy(struct mmc *mmc) block_dev_desc_t *mmc_get_dev(int dev) { struct mmc *mmc = find_mmc_device(dev); - if (!mmc || mmc_init(mmc)) + if (!mmc) return NULL; + /* If mmc_init fails, mmc->block_dev will be of type + * DEV_TYPE_UNKNOWN with blksz and lba set to zero. + */ + mmc_init(mmc); + return &mmc->block_dev; } #endif @@ -1298,7 +1304,7 @@ int mmc_start_init(struct mmc *mmc) err = mmc_go_idle(mmc); if (err) - return err; + goto done; /* The internal partition reset to user partition(0) at every CMD0*/ mmc->part_num = 0; @@ -1315,15 +1321,33 @@ int mmc_start_init(struct mmc *mmc) if (err && err != IN_PROGRESS) { #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT) - printf("Card did not respond to voltage select!\n"); + if (mmc_error_print_max < 4) { + mmc_error_print_max++; + printf("Card did not respond to voltage select!\n"); + + if (mmc_error_print_max == 4) { + printf("Discarding further error messages\n"); + } + } #endif - return UNUSABLE_ERR; +// return UNUSABLE_ERR; + goto done; } } if (err == IN_PROGRESS) mmc->init_in_progress = 1; +done: + if (err) { + mmc->has_init = 0; + mmc->block_dev.type = DEV_TYPE_UNKNOWN; + mmc->block_dev.blksz = 0; + mmc->block_dev.lba = 0; + } else { + mmc->has_init = 1; + } + return err; } diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c index 8183df3..758646a 100644 --- a/drivers/net/rtl8169.c +++ b/drivers/net/rtl8169.c @@ -610,12 +610,12 @@ static int rtl_send(struct eth_device *dev, void *packet, int length) puts("tx timeout/error\n"); printf("%s elapsed time : %lu\n", __func__, currticks()-stime); #endif - ret = 0; + ret = -1; } else { #ifdef DEBUG_RTL8169_TX puts("tx done\n"); #endif - ret = length; + ret = 0; } /* Delay to make net console (nc) work properly */ udelay(20); diff --git a/include/configs/jetson-tk1.h b/include/configs/jetson-tk1.h index 0fc15ba..59a137a 100644 --- a/include/configs/jetson-tk1.h +++ b/include/configs/jetson-tk1.h @@ -110,6 +110,9 @@ #define CONFIG_CMD_NET #define CONFIG_CMD_DHCP +/* API support for UBLDR */ +#define CONFIG_API + #include "tegra-common-usb-gadget.h" #include "tegra-common-post.h" diff --git a/include/configs/tegra-common.h b/include/configs/tegra-common.h index 3f2121d..e799e7b 100644 --- a/include/configs/tegra-common.h +++ b/include/configs/tegra-common.h @@ -158,4 +158,9 @@ #include #endif +#ifndef CONFIG_SPL_BUILD +#define CONFIG_SYS_DCACHE_OFF +#define CONFIG_CMD_CACHE +#endif + #endif /* _TEGRA_COMMON_H_ */