X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=inline;f=common%2Fcmd_jffs2.c;h=c031d8034919ee9a7e902ca258e64ddf42b113da;hb=5d9a5efa4b332f442b54a755d49969123c3a8742;hp=16f5b7aea9784733ab9851bf51a93f6c8fae45bc;hpb=55d150d95dbd4612f229e1f503c3a6aa8ed08a96;p=oweals%2Fu-boot.git diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c index 16f5b7aea9..c031d80349 100644 --- a/common/cmd_jffs2.c +++ b/common/cmd_jffs2.c @@ -91,19 +91,23 @@ #include #include #include -#include #include #include - -#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) - #include +#if defined(CONFIG_CMD_NAND) +#ifdef CONFIG_NAND_LEGACY +#include +#else /* !CONFIG_NAND_LEGACY */ +#include +#include +#endif /* !CONFIG_NAND_LEGACY */ +#endif /* enable/disable debugging messages */ -#define DEBUG -#undef DEBUG +#define DEBUG_JFFS +#undef DEBUG_JFFS -#ifdef DEBUG +#ifdef DEBUG_JFFS # define DEBUGF(fmt, args...) printf(fmt ,##args) #else # define DEBUGF(fmt, args...) @@ -123,7 +127,7 @@ /* this flag needs to be set in part_info struct mask_flags * field for read-only partitions */ -#define MTD_WRITEABLE 1 +#define MTD_WRITEABLE_CMD 1 #ifdef CONFIG_JFFS2_CMDLINE /* default values for mtdids and mtdparts variables */ @@ -163,10 +167,19 @@ struct list_head devices; static struct mtd_device *current_dev = NULL; static u8 current_partnum = 0; +#if defined(CONFIG_CMD_CRAMFS) extern int cramfs_check (struct part_info *info); extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename); extern int cramfs_ls (struct part_info *info, char *filename); extern int cramfs_info (struct part_info *info); +#else +/* defining empty macros for function names is ugly but avoids ifdef clutter + * all over the code */ +#define cramfs_check(x) (0) +#define cramfs_load(x,y,z) (-1) +#define cramfs_ls(x,y) (0) +#define cramfs_info(x) (0) +#endif static struct part_info* jffs2_part_info(struct mtd_device *dev, unsigned int part_num); @@ -228,13 +241,53 @@ static void memsize_format(char *buf, u32 size) #define SIZE_KB ((u32)1024) if ((size % SIZE_GB) == 0) - sprintf(buf, "%lug", size/SIZE_GB); + sprintf(buf, "%ug", size/SIZE_GB); else if ((size % SIZE_MB) == 0) - sprintf(buf, "%lum", size/SIZE_MB); + sprintf(buf, "%um", size/SIZE_MB); else if (size % SIZE_KB == 0) - sprintf(buf, "%luk", size/SIZE_KB); + sprintf(buf, "%uk", size/SIZE_KB); else - sprintf(buf, "%lu", size); + sprintf(buf, "%u", size); +} + +/** + * This routine does global indexing of all partitions. Resulting index for + * current partition is saved in 'mtddevnum'. Current partition name in + * 'mtddevname'. + */ +static void index_partitions(void) +{ + char buf[16]; + u16 mtddevnum; + struct part_info *part; + struct list_head *dentry; + struct mtd_device *dev; + + DEBUGF("--- index partitions ---\n"); + + if (current_dev) { + mtddevnum = 0; + list_for_each(dentry, &devices) { + dev = list_entry(dentry, struct mtd_device, link); + if (dev == current_dev) { + mtddevnum += current_partnum; + sprintf(buf, "%d", mtddevnum); + setenv("mtddevnum", buf); + break; + } + mtddevnum += dev->num_parts; + } + + part = jffs2_part_info(current_dev, current_partnum); + setenv("mtddevname", part->name); + + DEBUGF("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name); + } else { + setenv("mtddevnum", NULL); + setenv("mtddevname", NULL); + + DEBUGF("=> mtddevnum NULL\n=> mtddevname NULL\n"); + } } /** @@ -260,6 +313,7 @@ static void current_save(void) DEBUGF("=> partition NULL\n"); } + index_partitions(); } /** @@ -273,9 +327,9 @@ static void current_save(void) */ static int part_validate_nor(struct mtdids *id, struct part_info *part) { -#if (CONFIG_COMMANDS & CFG_CMD_FLASH) +#if defined(CONFIG_CMD_FLASH) /* info for FLASH chips */ - extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; + extern flash_info_t flash_info[]; flash_info_t *flash; int offset_aligned; u32 end_offset; @@ -322,12 +376,11 @@ static int part_validate_nor(struct mtdids *id, struct part_info *part) */ static int part_validate_nand(struct mtdids *id, struct part_info *part) { -#if defined(CONFIG_JFFS2_NAND) && (CONFIG_COMMANDS & CFG_CMD_NAND) +#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND) /* info for NAND chips */ - extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE]; - struct nand_chip *nand; + nand_info_t *nand; - nand = &nand_dev_desc[id->num]; + nand = &nand_info[id->num]; if ((unsigned long)(part->offset) % nand->erasesize) { printf("%s%d: partition (%s) start offset alignment incorrect\n", @@ -363,7 +416,7 @@ static int part_validate(struct mtdids *id, struct part_info *part) part->size = id->size - part->offset; if (part->offset > id->size) { - printf("%s: offset %08lx beyond flash size %08lx\n", + printf("%s: offset %08x beyond flash size %08x\n", id->mtd_id, part->offset, id->size); return 1; } @@ -398,6 +451,8 @@ static int part_validate(struct mtdids *id, struct part_info *part) */ static int part_del(struct mtd_device *dev, struct part_info *part) { + u8 current_save_needed = 0; + /* if there is only one partition, remove whole device */ if (dev->num_parts == 1) return device_del(dev); @@ -414,20 +469,25 @@ static int part_del(struct mtd_device *dev, struct part_info *part) if (curr_pi == part) { printf("current partition deleted, resetting current to 0\n"); current_partnum = 0; - current_save(); } else if (part->offset <= curr_pi->offset) { current_partnum--; - current_save(); } + current_save_needed = 1; } } - +#ifdef CONFIG_NAND_LEGACY jffs2_free_cache(part); +#endif list_del(&part->link); free(part); dev->num_parts--; + if (current_save_needed > 0) + current_save(); + else + index_partitions(); + return 0; } @@ -445,7 +505,9 @@ static void part_delall(struct list_head *head) list_for_each_safe(entry, n, head) { part_tmp = list_entry(entry, struct part_info, link); +#ifdef CONFIG_NAND_LEGACY jffs2_free_cache(part_tmp); +#endif list_del(entry); free(part_tmp); } @@ -469,6 +531,8 @@ static int part_sort_add(struct mtd_device *dev, struct part_info *part) if (list_empty(&dev->parts)) { DEBUGF("part_sort_add: list empty\n"); list_add(&part->link, &dev->parts); + dev->num_parts++; + index_partitions(); return 0; } @@ -492,18 +556,23 @@ static int part_sort_add(struct mtd_device *dev, struct part_info *part) if (new_pi->offset <= pi->offset) { list_add_tail(&part->link, entry); + dev->num_parts++; if (curr_pi && (pi->offset <= curr_pi->offset)) { /* we are modyfing partitions for the current * device, update current */ current_partnum++; current_save(); + } else { + index_partitions(); } - return 0; } } + list_add_tail(&part->link, &dev->parts); + dev->num_parts++; + index_partitions(); return 0; } @@ -524,7 +593,6 @@ static int part_add(struct mtd_device *dev, struct part_info *part) if (part_sort_add(dev, part) != 0) return 1; - dev->num_parts++; return 0; } @@ -594,7 +662,7 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i /* test for options */ mask_flags = 0; if (strncmp(p, "ro", 2) == 0) { - mask_flags |= MTD_WRITEABLE; + mask_flags |= MTD_WRITEABLE_CMD; p += 2; } @@ -657,10 +725,11 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i static int device_validate(u8 type, u8 num, u32 *size) { if (type == MTD_DEV_TYPE_NOR) { -#if (CONFIG_COMMANDS & CFG_CMD_FLASH) +#if defined(CONFIG_CMD_FLASH) if (num < CFG_MAX_FLASH_BANKS) { - extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; + extern flash_info_t flash_info[]; *size = flash_info[num].size; + return 0; } @@ -670,10 +739,14 @@ static int device_validate(u8 type, u8 num, u32 *size) printf("support for FLASH devices not present\n"); #endif } else if (type == MTD_DEV_TYPE_NAND) { -#if defined(CONFIG_JFFS2_NAND) && (CONFIG_COMMANDS & CFG_CMD_NAND) +#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND) if (num < CFG_MAX_NAND_DEVICE) { +#ifndef CONFIG_NAND_LEGACY + *size = nand_info[num].size; +#else extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE]; *size = nand_dev_desc[num].totlen; +#endif return 0; } @@ -735,9 +808,10 @@ static int device_del(struct mtd_device *dev) current_partnum = 0; } current_save(); + return 0; } - + index_partitions(); return 0; } @@ -771,13 +845,20 @@ static struct mtd_device* device_find(u8 type, u8 num) */ static void device_add(struct mtd_device *dev) { + u8 current_save_needed = 0; + if (list_empty(&devices)) { current_dev = dev; current_partnum = 0; - current_save(); + current_save_needed = 1; } list_add_tail(&dev->link, &devices); + + if (current_save_needed > 0) + current_save(); + else + index_partitions(); } /** @@ -896,7 +977,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_ } memset(dev, 0, sizeof(struct mtd_device)); dev->id = id; - dev->num_parts = num_parts; + dev->num_parts = 0; /* part_sort_add increments num_parts */ INIT_LIST_HEAD(&dev->parts); INIT_LIST_HEAD(&dev->link); @@ -1109,7 +1190,7 @@ static int generate_mtdparts(char *buf, u32 buflen) } /* ro mask flag */ - if (part->mask_flags && MTD_WRITEABLE) { + if (part->mask_flags && MTD_WRITEABLE_CMD) { len = 2; if (len > maxlen) goto cleanup; @@ -1193,7 +1274,7 @@ static void list_partitions(void) part_num = 0; list_for_each(pentry, &dev->parts) { part = list_entry(pentry, struct part_info, link); - printf(" %d: %-22s\t0x%08x\t0x%08x\t%d\n", + printf("%2d: %-20s0x%08x\t0x%08x\t%d\n", part_num, part->name, part->size, part->offset, part->mask_flags); @@ -1207,7 +1288,7 @@ static void list_partitions(void) if (current_dev) { part = jffs2_part_info(current_dev, current_partnum); if (part) { - printf("\nactive partition: %s%d,%d - (%s) 0x%08lx @ 0x%08lx\n", + printf("\nactive partition: %s%d,%d - (%s) 0x%08x @ 0x%08x\n", MTD_DEV_TYPE(current_dev->id->type), current_dev->id->num, current_partnum, part->name, part->size, part->offset); @@ -1225,7 +1306,7 @@ static void list_partitions(void) * Given partition identifier in form of , find * corresponding device and verify partition number. * - * @param id string describing device and partition + * @param id string describing device and partition or partition name * @param dev pointer to the requested device (output) * @param part_num verified partition number (output) * @param part pointer to requested partition (output) @@ -1234,11 +1315,23 @@ static void list_partitions(void) int find_dev_and_part(const char *id, struct mtd_device **dev, u8 *part_num, struct part_info **part) { + struct list_head *dentry, *pentry; u8 type, dnum, pnum; const char *p; DEBUGF("--- find_dev_and_part ---\nid = %s\n", id); + list_for_each(dentry, &devices) { + *part_num = 0; + *dev = list_entry(dentry, struct mtd_device, link); + list_for_each(pentry, &(*dev)->parts) { + *part = list_entry(pentry, struct part_info, link); + if (strcmp((*part)->name, id) == 0) + return 0; + (*part_num)++; + } + } + p = id; *dev = NULL; *part = NULL; @@ -1548,7 +1641,7 @@ int mtdparts_init(void) ids_changed = 1; if (parse_mtdids(ids) != 0) { - device_delall(&devices); + devices_init(); return 1; } @@ -1810,7 +1903,7 @@ int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return !(size > 0); } - return 0; + return 1; } /** @@ -1846,9 +1939,9 @@ int do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) ret = jffs2_1pass_ls(part, filename); } - return (ret == 1); + return ret ? 0 : 1; } - return 0; + return 1; } /** @@ -1884,9 +1977,9 @@ int do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) ret = jffs2_1pass_info(part); } - return (ret == 1); + return ret ? 0 : 1; } - return 0; + return 1; } /* command line only */ @@ -2104,5 +2197,3 @@ U_BOOT_CMD( #endif /* #ifdef CONFIG_JFFS2_CMDLINE */ /***************************************************/ - -#endif /* CFG_CMD_JFFS2 */