#define MTD_WRITEABLE_CMD 1
/* default values for mtdids and mtdparts variables */
-#if defined(MTDIDS_DEFAULT)
-static const char *const mtdids_default = MTDIDS_DEFAULT;
+#if !defined(MTDIDS_DEFAULT)
+#ifdef CONFIG_MTDIDS_DEFAULT
+#define MTDIDS_DEFAULT CONFIG_MTDIDS_DEFAULT
#else
-static const char *const mtdids_default = NULL;
+#define MTDIDS_DEFAULT NULL
#endif
-
-#if defined(MTDPARTS_DEFAULT)
-static const char *const mtdparts_default = MTDPARTS_DEFAULT;
+#endif
+#if !defined(MTDPARTS_DEFAULT)
+#ifdef CONFIG_MTDPARTS_DEFAULT
+#define MTDPARTS_DEFAULT CONFIG_MTDPARTS_DEFAULT
#else
-static const char *const mtdparts_default = NULL;
+#define MTDPARTS_DEFAULT NULL
+#endif
+#endif
+#if defined(CONFIG_SYS_MTDPARTS_RUNTIME)
+extern void board_mtdparts_default(const char **mtdids, const char **mtdparts);
#endif
+static const char *mtdids_default = MTDIDS_DEFAULT;
+static const char *mtdparts_default = MTDPARTS_DEFAULT;
/* copies of last seen 'mtdids', 'mtdparts' and 'partition' env variables */
#define MTDIDS_MAXLEN 128
struct mtd_device *current_mtd_dev = NULL;
u8 current_mtd_partnum = 0;
+u8 use_defaults;
+
static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num);
/* command line only routines */
part = list_entry(pentry, struct part_info, link);
debug("spread_partitions: device = %s%d, partition %d ="
- " (%s) 0x%08x@0x%08x\n",
+ " (%s) 0x%08llx@0x%08llx\n",
MTD_DEV_TYPE(dev->id->type), dev->id->num,
part_num, part->name, part->size,
part->offset);
}
#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
+/**
+ * The mtdparts variable tends to be long. If we need to access it
+ * before the env is relocated, then we need to use our own stack
+ * buffer. gd->env_buf will be too small.
+ *
+ * @param buf temporary buffer pointer MTDPARTS_MAXLEN long
+ * @return mtdparts variable string, NULL if not found
+ */
+static const char *getenv_mtdparts(char *buf)
+{
+ if (gd->flags & GD_FLG_ENV_READY)
+ return getenv("mtdparts");
+ if (getenv_f("mtdparts", buf, MTDPARTS_MAXLEN) != -1)
+ return buf;
+ return NULL;
+}
+
/**
* Accept character string describing mtd partitions and call device_parse()
* for each entry. Add created devices to the global devices list.
*/
static int parse_mtdparts(const char *const mtdparts)
{
- const char *p = mtdparts;
+ const char *p;
struct mtd_device *dev;
int err = 1;
char tmp_parts[MTDPARTS_MAXLEN];
- debug("\n---parse_mtdparts---\nmtdparts = %s\n\n", p);
+ debug("\n---parse_mtdparts---\nmtdparts = %s\n\n", mtdparts);
/* delete all devices and partitions */
if (mtd_devices_init() != 0) {
}
/* re-read 'mtdparts' variable, mtd_devices_init may be updating env */
- if (gd->flags & GD_FLG_ENV_READY) {
- p = getenv("mtdparts");
- } else {
- p = tmp_parts;
- getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
- }
+ p = getenv_mtdparts(tmp_parts);
+ if (!p)
+ p = mtdparts;
if (strncmp(p, "mtdparts=", 9) != 0) {
printf("mtdparts variable doesn't start with 'mtdparts='\n");
}
p += 9;
- while (p && (*p != '\0')) {
+ while (*p != '\0') {
err = 1;
if ((device_parse(p, &p, &dev) != 0) || (!dev))
break;
list_add_tail(&dev->link, &devices);
err = 0;
}
- if (err == 1) {
+ if (err == 1)
device_delall(&devices);
- return 1;
- }
- return 0;
+ return err;
}
/**
return 0;
}
+
/**
* Parse and initialize global mtdids mapping and create global
* device/partition list.
memset(last_ids, 0, MTDIDS_MAXLEN);
memset(last_parts, 0, MTDPARTS_MAXLEN);
memset(last_partition, 0, PARTITION_MAXLEN);
+#if defined(CONFIG_SYS_MTDPARTS_RUNTIME)
+ board_mtdparts_default(&mtdids_default, &mtdparts_default);
+#endif
+ use_defaults = 1;
initialized = 1;
}
/* get variables */
ids = getenv("mtdids");
- /*
- * The mtdparts variable tends to be long. If we need to access it
- * before the env is relocated, then we need to use our own stack
- * buffer. gd->env_buf will be too small.
- */
- if (gd->flags & GD_FLG_ENV_READY) {
- parts = getenv("mtdparts");
- } else {
- parts = tmp_parts;
- getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
- }
+ parts = getenv_mtdparts(tmp_parts);
current_partition = getenv("partition");
/* save it for later parsing, cannot rely on current partition pointer
debug("last_partition : %s\n", last_partition);
debug("env_partition : %s\n", current_partition);
- /* if mtdids varible is empty try to use defaults */
+ /* if mtdids variable is empty try to use defaults */
if (!ids) {
if (mtdids_default) {
debug("mtdids variable not defined, using default\n");
return 1;
}
- /* do no try to use defaults when mtdparts variable is not defined,
- * just check the length */
- if (!parts)
- printf("mtdparts variable not set, see 'help mtdparts'\n");
+ /* use defaults when mtdparts variable is not defined
+ * once mtdparts is saved environment, drop use_defaults flag */
+ if (!parts) {
+ if (mtdparts_default && use_defaults) {
+ parts = mtdparts_default;
+ if (setenv("mtdparts", (char *)parts) == 0)
+ use_defaults = 0;
+ } else
+ printf("mtdparts variable not set, see 'help mtdparts'\n");
+ }
if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
{
if (argc == 2) {
if (strcmp(argv[1], "default") == 0) {
- setenv("mtdids", (char *)mtdids_default);
- setenv("mtdparts", (char *)mtdparts_default);
+ setenv("mtdids", NULL);
+ setenv("mtdparts", NULL);
setenv("partition", NULL);
+ use_defaults = 1;
mtdparts_init();
return 0;
if (!strcmp(&argv[1][3], ".spread")) {
spread_partition(mtd, p, &next_offset);
- debug("increased %s to %d bytes\n", p->name, p->size);
+ debug("increased %s to %llu bytes\n", p->name, p->size);
}
#endif