diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/cmd_bootm.c | 6 | ||||
-rw-r--r-- | common/cmd_display.c | 26 | ||||
-rw-r--r-- | common/cmd_flash.c | 12 | ||||
-rw-r--r-- | common/cmd_mem.c | 8 | ||||
-rw-r--r-- | common/cmd_mtdparts.c | 261 | ||||
-rw-r--r-- | common/cmd_nand.c | 341 | ||||
-rw-r--r-- | common/cmd_net.c | 2 | ||||
-rw-r--r-- | common/cmd_tsi148.c | 4 | ||||
-rw-r--r-- | common/dlmalloc.c | 2 | ||||
-rw-r--r-- | common/env_common.c | 2 | ||||
-rw-r--r-- | common/env_mmc.c | 30 | ||||
-rw-r--r-- | common/fdt_support.c | 135 | ||||
-rw-r--r-- | common/image.c | 16 | ||||
-rw-r--r-- | common/usb_storage.c | 39 |
14 files changed, 631 insertions, 253 deletions
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index db59e6f..ce3c77c 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -308,7 +308,6 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] } #if defined(CONFIG_OF_LIBFDT) -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) /* find flattened device tree */ ret = boot_get_fdt (flag, argc, argv, &images, &images.ft_addr, &images.ft_len); @@ -319,7 +318,6 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] set_working_fdt_addr(images.ft_addr); #endif -#endif } images.os.start = (ulong)os_hdr; @@ -474,7 +472,7 @@ static int bootm_start_standalone(ulong iflag, int argc, char * const argv[]) static cmd_tbl_t cmd_bootm_sub[] = { U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""), U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""), -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) +#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""), #endif #ifdef CONFIG_OF_LIBFDT @@ -530,7 +528,7 @@ int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load)); break; -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) +#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH case BOOTM_STATE_RAMDISK: { ulong rd_len = images.rd_end - images.rd_start; diff --git a/common/cmd_display.c b/common/cmd_display.c index 6c11aa6..d5d5d8c 100644 --- a/common/cmd_display.c +++ b/common/cmd_display.c @@ -23,40 +23,32 @@ #include <common.h> #include <command.h> +#include <led-display.h> #undef DEBUG_DISP -#define DISP_SIZE 8 -#define CWORD_CLEAR 0x80 -#define CLEAR_DELAY (110 * 2) - int do_display (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int i; - int pos; /* Clear display */ - *((volatile char*)(CONFIG_SYS_DISP_CWORD)) = CWORD_CLEAR; - udelay(1000 * CLEAR_DELAY); + display_set(DISPLAY_CLEAR | DISPLAY_HOME); if (argc < 2) return (0); - for (pos = 0, i = 1; i < argc && pos < DISP_SIZE; i++) { - char *p = argv[i], c; + for (i = 1; i < argc; i++) { + char *p = argv[i]; - if (i > 1) { - *((volatile uchar *) (CONFIG_SYS_DISP_CHR_RAM + pos++)) = ' '; -#ifdef DEBUG_DISP - putc(' '); -#endif + if (i > 1) { /* Insert a space between strings */ + display_putc(' '); } - while ((c = *p++) != '\0' && pos < DISP_SIZE) { - *((volatile uchar *) (CONFIG_SYS_DISP_CHR_RAM + pos++)) = c; + while ((*p)) { #ifdef DEBUG_DISP - putc(c); + putc(*p); #endif + display_putc(*p++); } } diff --git a/common/cmd_flash.c b/common/cmd_flash.c index 2a02eb9..4493948 100644 --- a/common/cmd_flash.c +++ b/common/cmd_flash.c @@ -31,7 +31,7 @@ #include <dataflash.h> #endif -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS) +#if defined(CONFIG_CMD_MTDPARTS) #include <jffs2/jffs2.h> /* partition handling routines */ @@ -327,7 +327,7 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) flash_info_t *info; ulong bank, addr_first, addr_last; int n, sect_first, sect_last; -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS) +#if defined(CONFIG_CMD_MTDPARTS) struct mtd_device *dev; struct part_info *part; u8 dev_type, dev_num, pnum; @@ -357,7 +357,7 @@ int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return rcode; } -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS) +#if defined(CONFIG_CMD_MTDPARTS) /* erase <part-id> - erase partition */ if ((argc == 2) && (mtd_id_parse(argv[1], NULL, &dev_type, &dev_num) == 0)) { mtdparts_init(); @@ -463,7 +463,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH) ulong addr_first, addr_last; #endif -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS) +#if defined(CONFIG_CMD_MTDPARTS) struct mtd_device *dev; struct part_info *part; u8 dev_type, dev_num, pnum; @@ -553,7 +553,7 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return rcode; } -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS) +#if defined(CONFIG_CMD_MTDPARTS) /* protect on/off <part-id> */ if ((argc == 3) && (mtd_id_parse(argv[2], NULL, &dev_type, &dev_num) == 0)) { mtdparts_init(); @@ -681,7 +681,7 @@ int flash_sect_protect (int p, ulong addr_first, ulong addr_last) /**************************************************/ -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS) +#if defined(CONFIG_CMD_MTDPARTS) # define TMP_ERASE "erase <part-id>\n - erase partition\n" # define TMP_PROT_ON "protect on <part-id>\n - protect partition\n" # define TMP_PROT_OFF "protect off <part-id>\n - make partition writable\n" diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 44834ea..f7a442a 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -337,6 +337,10 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ngood++; addr1 += size; addr2 += size; + + /* reset watchdog from time to time */ + if ((count % (64 << 10)) == 0) + WATCHDOG_RESET(); } printf("Total of %ld %s%s were the same\n", @@ -447,6 +451,10 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) *((u_char *)dest) = *((u_char *)addr); addr += size; dest += size; + + /* reset watchdog from time to time */ + if ((count % (64 << 10)) == 0) + WATCHDOG_RESET(); } return 0; } diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c index ceec5a9..5481c88 100644 --- a/common/cmd_mtdparts.c +++ b/common/cmd_mtdparts.c @@ -15,6 +15,9 @@ * Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4 * kernel tree. * + * (C) Copyright 2008 + * Harald Welte, OpenMoko, Inc., Harald Welte <laforge@openmoko.org> + * * $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $ * Copyright 2002 SYSGO Real-Time Solutions GmbH * @@ -286,6 +289,29 @@ static void current_save(void) index_partitions(); } + +/** + * Produce a mtd_info given a type and num. + * + * @param type mtd type + * @param num mtd number + * @param mtd a pointer to an mtd_info instance (output) + * @return 0 if device is valid, 1 otherwise + */ +static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd) +{ + char mtd_dev[16]; + + sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num); + *mtd = get_mtd_device_nm(mtd_dev); + if (IS_ERR(*mtd)) { + printf("Device %s not found!\n", mtd_dev); + return 1; + } + + return 0; +} + /** * Performs sanity check for supplied flash partition. * Table of existing MTD flash devices is searched and partition device @@ -297,17 +323,12 @@ static void current_save(void) */ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part) { - struct mtd_info *mtd; - char mtd_dev[16]; + struct mtd_info *mtd = NULL; int i, j; ulong start; - sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(id->type), id->num); - mtd = get_mtd_device_nm(mtd_dev); - if (IS_ERR(mtd)) { - printf("Partition %s not found on device %s!\n", part->name, mtd_dev); + if (get_mtd_info(id->type, id->num, &mtd)) return 1; - } part->sector_size = mtd->erasesize; @@ -684,20 +705,17 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i /** * Check device number to be within valid range for given device type. * - * @param dev device to validate + * @param type mtd type + * @param num mtd number + * @param size a pointer to the size of the mtd device (output) * @return 0 if device is valid, 1 otherwise */ int mtd_device_validate(u8 type, u8 num, u32 *size) { - struct mtd_info *mtd; - char mtd_dev[16]; + struct mtd_info *mtd = NULL; - sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num); - mtd = get_mtd_device_nm(mtd_dev); - if (IS_ERR(mtd)) { - printf("Device %s not found!\n", mtd_dev); + if (get_mtd_info(type, num, &mtd)) return 1; - } *size = mtd->size; @@ -1200,38 +1218,93 @@ static int generate_mtdparts_save(char *buf, u32 buflen) return ret; } +#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) /** - * Format and print out a partition list for each device from global device - * list. + * Get the net size (w/o bad blocks) of the given partition. + * + * @param mtd the mtd info + * @param part the partition + * @return the calculated net size of this partition */ -static void list_partitions(void) +static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part) +{ + uint64_t i, net_size = 0; + + if (!mtd->block_isbad) + return part->size; + + for (i = 0; i < part->size; i += mtd->erasesize) { + if (!mtd->block_isbad(mtd, part->offset + i)) + net_size += mtd->erasesize; + } + + return net_size; +} +#endif + +static void print_partition_table(void) { struct list_head *dentry, *pentry; struct part_info *part; struct mtd_device *dev; int part_num; - debug("\n---list_partitions---\n"); list_for_each(dentry, &devices) { dev = list_entry(dentry, struct mtd_device, link); + /* list partitions for given device */ + part_num = 0; +#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) + struct mtd_info *mtd; + + if (get_mtd_info(dev->id->type, dev->id->num, &mtd)) + return; + + printf("\ndevice %s%d <%s>, # parts = %d\n", + MTD_DEV_TYPE(dev->id->type), dev->id->num, + dev->id->mtd_id, dev->num_parts); + printf(" #: name\t\tsize\t\tnet size\toffset\t\tmask_flags\n"); + + list_for_each(pentry, &dev->parts) { + u32 net_size; + char *size_note; + + part = list_entry(pentry, struct part_info, link); + net_size = net_part_size(mtd, part); + size_note = part->size == net_size ? " " : " (!)"; + printf("%2d: %-20s0x%08x\t0x%08x%s\t0x%08x\t%d\n", + part_num, part->name, part->size, + net_size, size_note, part->offset, + part->mask_flags); +#else /* !defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */ printf("\ndevice %s%d <%s>, # parts = %d\n", MTD_DEV_TYPE(dev->id->type), dev->id->num, dev->id->mtd_id, dev->num_parts); printf(" #: name\t\tsize\t\toffset\t\tmask_flags\n"); - /* list partitions for given device */ - part_num = 0; list_for_each(pentry, &dev->parts) { part = list_entry(pentry, struct part_info, link); printf("%2d: %-20s0x%08x\t0x%08x\t%d\n", part_num, part->name, part->size, part->offset, part->mask_flags); - +#endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */ part_num++; } } + if (list_empty(&devices)) printf("no partitions defined\n"); +} + +/** + * Format and print out a partition list for each device from global device + * list. + */ +static void list_partitions(void) +{ + struct part_info *part; + + debug("\n---list_partitions---\n"); + print_partition_table(); /* current_mtd_dev is not NULL only when we have non empty device list */ if (current_mtd_dev) { @@ -1355,6 +1428,101 @@ static int delete_partition(const char *id) return 1; } +#if defined(CONFIG_CMD_MTDPARTS_SPREAD) +/** + * Increase the size of the given partition so that it's net size is at least + * as large as the size member and such that the next partition would start on a + * good block if it were adjacent to this partition. + * + * @param mtd the mtd device + * @param part the partition + * @param next_offset pointer to the offset of the next partition after this + * partition's size has been modified (output) + */ +static void spread_partition(struct mtd_info *mtd, struct part_info *part, + uint64_t *next_offset) +{ + uint64_t net_size, padding_size = 0; + int truncated; + + mtd_get_len_incl_bad(mtd, part->offset, part->size, &net_size, + &truncated); + + /* + * Absorb bad blocks immediately following this + * partition also into the partition, such that + * the next partition starts with a good block. + */ + if (!truncated) { + mtd_get_len_incl_bad(mtd, part->offset + net_size, + mtd->erasesize, &padding_size, &truncated); + if (truncated) + padding_size = 0; + else + padding_size -= mtd->erasesize; + } + + if (truncated) { + printf("truncated partition %s to %lld bytes\n", part->name, + (uint64_t) net_size + padding_size); + } + + part->size = net_size + padding_size; + *next_offset = part->offset + part->size; +} + +/** + * Adjust all of the partition sizes, such that all partitions are at least + * as big as their mtdparts environment variable sizes and they each start + * on a good block. + * + * @return 0 on success, 1 otherwise + */ +static int spread_partitions(void) +{ + struct list_head *dentry, *pentry; + struct mtd_device *dev; + struct part_info *part; + struct mtd_info *mtd; + int part_num; + uint64_t cur_offs; + + list_for_each(dentry, &devices) { + dev = list_entry(dentry, struct mtd_device, link); + + if (get_mtd_info(dev->id->type, dev->id->num, &mtd)) + return 1; + + part_num = 0; + cur_offs = 0; + list_for_each(pentry, &dev->parts) { + part = list_entry(pentry, struct part_info, link); + + debug("spread_partitions: device = %s%d, partition %d =" + " (%s) 0x%08x@0x%08x\n", + MTD_DEV_TYPE(dev->id->type), dev->id->num, + part_num, part->name, part->size, + part->offset); + + if (cur_offs > part->offset) + part->offset = cur_offs; + + spread_partition(mtd, part, &cur_offs); + + part_num++; + } + } + + index_partitions(); + + if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) { + printf("generated mtdparts too long, reseting to null\n"); + return 1; + } + return 0; +} +#endif /* CONFIG_CMD_MTDPARTS_SPREAD */ + /** * Accept character string describing mtd partitions and call device_parse() * for each entry. Add created devices to the global devices list. @@ -1782,9 +1950,13 @@ int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } /* mtdparts add <mtd-dev> <size>[@<offset>] <name> [ro] */ - if (((argc == 5) || (argc == 6)) && (strcmp(argv[1], "add") == 0)) { + if (((argc == 5) || (argc == 6)) && (strncmp(argv[1], "add", 3) == 0)) { #define PART_ADD_DESC_MAXLEN 64 char tmpbuf[PART_ADD_DESC_MAXLEN]; +#if defined(CONFIG_CMD_MTDPARTS_SPREAD) + struct mtd_info *mtd; + uint64_t next_offset; +#endif u8 type, num, len; struct mtd_device *dev; struct mtd_device *dev_tmp; @@ -1819,15 +1991,25 @@ int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) debug("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type), dev->id->num, dev->id->mtd_id); - if ((dev_tmp = device_find(dev->id->type, dev->id->num)) == NULL) { + p = list_entry(dev->parts.next, struct part_info, link); + +#if defined(CONFIG_CMD_MTDPARTS_SPREAD) + if (get_mtd_info(dev->id->type, dev->id->num, &mtd)) + return 1; + + if (!strcmp(&argv[1][3], ".spread")) { + spread_partition(mtd, p, &next_offset); + debug("increased %s to %d bytes\n", p->name, p->size); + } +#endif + + dev_tmp = device_find(dev->id->type, dev->id->num); + if (dev_tmp == NULL) { device_add(dev); - } else { + } else if (part_add(dev_tmp, p) != 0) { /* merge new partition with existing ones*/ - p = list_entry(dev->parts.next, struct part_info, link); - if (part_add(dev_tmp, p) != 0) { - device_del(dev); - return 1; - } + device_del(dev); + return 1; } if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) { @@ -1845,6 +2027,11 @@ int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return delete_partition(argv[2]); } +#if defined(CONFIG_CMD_MTDPARTS_SPREAD) + if ((argc == 2) && (strcmp(argv[1], "spread") == 0)) + return spread_partitions(); +#endif /* CONFIG_CMD_MTDPARTS_SPREAD */ + return cmd_usage(cmdtp); } @@ -1867,8 +2054,20 @@ U_BOOT_CMD( " - delete partition (e.g. part-id = nand0,1)\n" "mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]\n" " - add partition\n" +#if defined(CONFIG_CMD_MTDPARTS_SPREAD) + "mtdparts add.spread <mtd-dev> <size>[@<offset>] [<name>] [ro]\n" + " - add partition, padding size by skipping bad blocks\n" +#endif "mtdparts default\n" - " - reset partition table to defaults\n\n" + " - reset partition table to defaults\n" +#if defined(CONFIG_CMD_MTDPARTS_SPREAD) + "mtdparts spread\n" + " - adjust the sizes of the partitions so they are\n" + " at least as big as the mtdparts variable specifies\n" + " and they each start on a good block\n\n" +#else + "\n" +#endif /* CONFIG_CMD_MTDPARTS_SPREAD */ "-----\n\n" "this command uses three environment variables:\n\n" "'partition' - keeps current partition identifier\n\n" diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 3f1d077..634d036 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -10,6 +10,13 @@ * (C) Copyright 2006-2007 OpenMoko, Inc. * Added 16-bit nand support * (C) 2004 Texas Instruments + * + * Copyright 2010 Freescale Semiconductor + * The portions of this file whose copyright is held by Freescale and which + * are not considered a derived work of GPL v2-only code may be distributed + * and/or modified under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. */ #include <common.h> @@ -30,10 +37,16 @@ int find_dev_and_part(const char *id, struct mtd_device **dev, u8 *part_num, struct part_info **part); #endif -static int nand_dump(nand_info_t *nand, ulong off, int only_oob) +static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat) { int i; u_char *datbuf, *oobbuf, *p; + static loff_t last; + + if (repeat) + off = last + nand->writesize; + + last = off; datbuf = malloc(nand->writesize + nand->oobsize); oobbuf = malloc(nand->oobsize); @@ -85,74 +98,132 @@ static int nand_dump(nand_info_t *nand, ulong off, int only_oob) /* ------------------------------------------------------------------------- */ -static inline int str2long(char *p, ulong *num) +static int set_dev(int dev) +{ + if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || + !nand_info[dev].name) { + puts("No such device\n"); + return -1; + } + + if (nand_curr_device == dev) + return 0; + + printf("Device %d: %s", dev, nand_info[dev].name); + puts("... is now current device\n"); + nand_curr_device = dev; + +#ifdef CONFIG_SYS_NAND_SELECT_DEVICE + board_nand_select_device(nand_info[dev].priv, dev); +#endif + + return 0; +} + +static inline int str2off(const char *p, loff_t *num) +{ + char *endptr; + + *num = simple_strtoull(p, &endptr, 16); + return *p != '\0' && *endptr == '\0'; +} + +static inline int str2long(const char *p, ulong *num) { char *endptr; *num = simple_strtoul(p, &endptr, 16); - return (*p != '\0' && *endptr == '\0') ? 1 : 0; + return *p != '\0' && *endptr == '\0'; } -static int -arg_off_size(int argc, char * const argv[], nand_info_t *nand, ulong *off, size_t *size) +static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size) { - int idx = nand_curr_device; -#if defined(CONFIG_CMD_MTDPARTS) +#ifdef CONFIG_CMD_MTDPARTS struct mtd_device *dev; struct part_info *part; u8 pnum; + int ret; - if (argc >= 1 && !(str2long(argv[0], off))) { - if ((mtdparts_init() == 0) && - (find_dev_and_part(argv[0], &dev, &pnum, &part) == 0)) { - if (dev->id->type != MTD_DEV_TYPE_NAND) { - puts("not a NAND device\n"); - return -1; - } - *off = part->offset; - if (argc >= 2) { - if (!(str2long(argv[1], (ulong *)size))) { - printf("'%s' is not a number\n", argv[1]); - return -1; - } - if (*size > part->size) - *size = part->size; - } else { - *size = part->size; - } - idx = dev->id->num; - *nand = nand_info[idx]; - goto out; - } + ret = mtdparts_init(); + if (ret) + return ret; + + ret = find_dev_and_part(partname, &dev, &pnum, &part); + if (ret) + return ret; + + if (dev->id->type != MTD_DEV_TYPE_NAND) { + puts("not a NAND device\n"); + return -1; } + + *off = part->offset; + *size = part->size; + *idx = dev->id->num; + + ret = set_dev(*idx); + if (ret) + return ret; + + return 0; +#else + puts("offset is not a number\n"); + return -1; #endif +} - if (argc >= 1) { - if (!(str2long(argv[0], off))) { - printf("'%s' is not a number\n", argv[0]); - return -1; - } - } else { +static int arg_off(const char *arg, int *idx, loff_t *off, loff_t *maxsize) +{ + if (!str2off(arg, off)) + return get_part(arg, idx, off, maxsize); + + if (*off >= nand_info[*idx].size) { + puts("Offset exceeds device limit\n"); + return -1; + } + + *maxsize = nand_info[*idx].size - *off; + return 0; +} + +static int arg_off_size(int argc, char *const argv[], int *idx, + loff_t *off, loff_t *size) +{ + int ret; + loff_t maxsize; + + if (argc == 0) { *off = 0; + *size = nand_info[*idx].size; + goto print; } - if (argc >= 2) { - if (!(str2long(argv[1], (ulong *)size))) { - printf("'%s' is not a number\n", argv[1]); - return -1; - } - } else { - *size = nand->size - *off; + ret = arg_off(argv[0], idx, off, &maxsize); + if (ret) + return ret; + + if (argc == 1) { + *size = maxsize; + goto print; } -#if defined(CONFIG_CMD_MTDPARTS) -out: -#endif - printf("device %d ", idx); - if (*size == nand->size) + if (!str2off(argv[1], size)) { + printf("'%s' is not a number\n", argv[1]); + return -1; + } + + if (*size > maxsize) { + puts("Size exceeds partition or device limit\n"); + return -1; + } + +print: + printf("device %d ", *idx); + if (*size == nand_info[*idx].size) puts("whole chip\n"); else - printf("offset 0x%lx, size 0x%zx\n", *off, *size); + printf("offset 0x%llx, size 0x%llx\n", + (unsigned long long)*off, (unsigned long long)*size); return 0; } @@ -200,14 +271,20 @@ static void do_nand_status(nand_info_t *nand) #ifdef CONFIG_ENV_OFFSET_OOB unsigned long nand_env_oob_offset; -int do_nand_env_oob(cmd_tbl_t *cmdtp, nand_info_t *nand, - int argc, char * const argv[]) +int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[]) { int ret; uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)]; - + nand_info_t *nand = &nand_info[0]; char *cmd = argv[1]; + if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !nand->name) { + puts("no devices available\n"); + return 1; + } + + set_dev(0); + if (!strcmp(cmd, "get")) { ret = get_nand_env_oob(nand, &nand_env_oob_offset); if (ret) @@ -215,16 +292,21 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, nand_info_t *nand, printf("0x%08lx\n", nand_env_oob_offset); } else if (!strcmp(cmd, "set")) { - ulong addr; - size_t dummy_size; + loff_t addr; + loff_t maxsize; struct mtd_oob_ops ops; + int idx = 0; if (argc < 3) goto usage; - if (arg_off_size(argc - 2, argv + 2, nand, &addr, - &dummy_size) < 0) { - printf("Offset or partition name expected\n"); + if (arg_off(argv[2], &idx, &addr, &maxsize)) { + puts("Offset or partition name expected\n"); + return 1; + } + + if (idx != 0) { + puts("Partition not on first NAND device\n"); return 1; } @@ -264,8 +346,8 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, nand_info_t *nand, if (addr != nand_env_oob_offset) { printf("Verification of env offset in OOB failed: " - "0x%08lx expected but got 0x%08lx\n", - addr, nand_env_oob_offset); + "0x%08llx expected but got 0x%08lx\n", + (unsigned long long)addr, nand_env_oob_offset); return 1; } } else { @@ -293,9 +375,9 @@ static void nand_print_info(int idx) int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { - int i, dev, ret = 0; - ulong addr, off; - size_t size; + int i, ret = 0; + ulong addr; + loff_t off, size; char *cmd, *s; nand_info_t *nand; #ifdef CONFIG_SYS_NAND_QUIET @@ -304,6 +386,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) int quiet = 0; #endif const char *quiet_str = getenv("quiet"); + int dev = nand_curr_device; + int repeat = flag & CMD_FLAG_REPEAT; /* at least two arguments please */ if (argc < 2) @@ -314,6 +398,10 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) cmd = argv[1]; + /* Only "dump" is repeatable. */ + if (repeat && strcmp(cmd, "dump")) + return 0; + if (strcmp(cmd, "info") == 0) { putc('\n'); @@ -325,68 +413,45 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) } if (strcmp(cmd, "device") == 0) { - if (argc < 3) { putc('\n'); - if ((nand_curr_device < 0) || - (nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE)) + if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE) puts("no devices available\n"); else - nand_print_info(nand_curr_device); + nand_print_info(dev); return 0; } - dev = (int)simple_strtoul(argv[2], NULL, 10); - if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev].name) { - puts("No such device\n"); - return 1; - } - printf("Device %d: %s", dev, nand_info[dev].name); - puts("... is now current device\n"); - nand_curr_device = dev; -#ifdef CONFIG_SYS_NAND_SELECT_DEVICE - /* - * Select the chip in the board/cpu specific driver - */ - board_nand_select_device(nand_info[dev].priv, dev); -#endif + dev = (int)simple_strtoul(argv[2], NULL, 10); + set_dev(dev); return 0; } - if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 && - strncmp(cmd, "dump", 4) != 0 && - strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 && - strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 && - strcmp(cmd, "biterr") != 0 && - strcmp(cmd, "lock") != 0 && strcmp(cmd, "unlock") != 0 -#ifdef CONFIG_ENV_OFFSET_OOB - && strcmp(cmd, "env.oob") != 0 -#endif - ) - goto usage; - #ifdef CONFIG_ENV_OFFSET_OOB /* this command operates only on the first nand device */ - if (strcmp(cmd, "env.oob") == 0) { - return do_nand_env_oob(cmdtp, &nand_info[0], - argc - 1, argv + 1); - } + if (strcmp(cmd, "env.oob") == 0) + return do_nand_env_oob(cmdtp, argc - 1, argv + 1); #endif - /* the following commands operate on the current device */ - if (nand_curr_device < 0 || nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE || - !nand_info[nand_curr_device].name) { + /* The following commands operate on the current device, unless + * overridden by a partition specifier. Note that if somehow the + * current device is invalid, it will have to be changed to a valid + * one before these commands can run, even if a partition specifier + * for another device is to be used. + */ + if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || + !nand_info[dev].name) { puts("\nno devices available\n"); return 1; } - nand = &nand_info[nand_curr_device]; + nand = &nand_info[dev]; if (strcmp(cmd, "bad") == 0) { - printf("\nDevice %d bad blocks:\n", nand_curr_device); + printf("\nDevice %d bad blocks:\n", dev); for (off = 0; off < nand->size; off += nand->erasesize) if (nand_block_isbad(nand, off)) - printf(" %08lx\n", off); + printf(" %08llx\n", (unsigned long long)off); return 0; } @@ -395,23 +460,52 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) * 0 1 2 3 4 * nand erase [clean] [off size] */ - if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) { + if (strncmp(cmd, "erase", 5) == 0 || strncmp(cmd, "scrub", 5) == 0) { nand_erase_options_t opts; /* "clean" at index 2 means request to write cleanmarker */ int clean = argc > 2 && !strcmp("clean", argv[2]); int o = clean ? 3 : 2; - int scrub = !strcmp(cmd, "scrub"); + int scrub = !strncmp(cmd, "scrub", 5); + int part = 0; + int chip = 0; + int spread = 0; + int args = 2; + + if (cmd[5] != 0) { + if (!strcmp(&cmd[5], ".spread")) { + spread = 1; + } else if (!strcmp(&cmd[5], ".part")) { + part = 1; + args = 1; + } else if (!strcmp(&cmd[5], ".chip")) { + chip = 1; + args = 0; + } else { + goto usage; + } + } + + /* + * Don't allow missing arguments to cause full chip/partition + * erases -- easy to do accidentally, e.g. with a misspelled + * variable name. + */ + if (argc != o + args) + goto usage; - printf("\nNAND %s: ", scrub ? "scrub" : "erase"); + printf("\nNAND %s: ", cmd); /* skip first two or three arguments, look for offset and size */ - if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0) + if (arg_off_size(argc - o, argv + o, &dev, &off, &size) != 0) return 1; + nand = &nand_info[dev]; + memset(&opts, 0, sizeof(opts)); opts.offset = off; opts.length = size; opts.jffs2 = clean; opts.quiet = quiet; + opts.spread = spread; if (scrub) { puts("Warning: " @@ -449,19 +543,14 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) if (argc < 3) goto usage; - s = strchr(cmd, '.'); off = (int)simple_strtoul(argv[2], NULL, 16); - - if (s != NULL && strcmp(s, ".oob") == 0) - ret = nand_dump(nand, off, 1); - else - ret = nand_dump(nand, off, 0); + ret = nand_dump(nand, off, !strcmp(&cmd[4], ".oob"), repeat); return ret == 0 ? 1 : 0; - } if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) { + size_t rwsize; int read; if (argc < 4) @@ -471,23 +560,26 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */ printf("\nNAND %s: ", read ? "read" : "write"); - if (arg_off_size(argc - 3, argv + 3, nand, &off, &size) != 0) + if (arg_off_size(argc - 3, argv + 3, &dev, &off, &size) != 0) return 1; + nand = &nand_info[dev]; + rwsize = size; + s = strchr(cmd, '.'); if (!s || !strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i")) { if (read) - ret = nand_read_skip_bad(nand, off, &size, + ret = nand_read_skip_bad(nand, off, &rwsize, (u_char *)addr); else - ret = nand_write_skip_bad(nand, off, &size, + ret = nand_write_skip_bad(nand, off, &rwsize, (u_char *)addr); } else if (!strcmp(s, ".oob")) { /* out-of-band data */ mtd_oob_ops_t ops = { .oobbuf = (u8 *)addr, - .ooblen = size, + .ooblen = rwsize, .mode = MTD_OOB_RAW }; @@ -500,7 +592,7 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) return 1; } - printf(" %zu bytes %s: %s\n", size, + printf(" %zu bytes %s: %s\n", rwsize, read ? "read" : "written", ret ? "ERROR" : "OK"); return ret == 0 ? 0 : 1; @@ -561,10 +653,10 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) } if (strcmp(cmd, "unlock") == 0) { - if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0) + if (arg_off_size(argc - 2, argv + 2, &dev, &off, &size) < 0) return 1; - if (!nand_unlock(nand, off, size)) { + if (!nand_unlock(&nand_info[dev], off, size)) { puts("NAND flash successfully unlocked\n"); } else { puts("Error unlocking NAND flash, " @@ -588,11 +680,16 @@ U_BOOT_CMD( "nand write - addr off|partition size\n" " read/write 'size' bytes starting at offset 'off'\n" " to/from memory address 'addr', skipping bad blocks.\n" - "nand erase [clean] [off size] - erase 'size' bytes from\n" - " offset 'off' (entire device if not specified)\n" + "nand erase[.spread] [clean] [off [size]] - erase 'size' bytes " + "from offset 'off'\n" + " With '.spread', erase enough for given file size, otherwise,\n" + " 'size' includes skipped bad blocks.\n" + "nand erase.part [clean] partition - erase entire mtd partition'\n" + "nand erase.chip [clean] - erase entire chip'\n" "nand bad - show bad blocks\n" "nand dump[.oob] off - dump page\n" - "nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n" + "nand scrub off size | scrub.part partition | scrub.chip\n" + " really clean NAND erasing bad blocks (UNSAFE)\n" "nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n" "nand biterr off - make a bit error at offset (UNSAFE)" #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK diff --git a/common/cmd_net.c b/common/cmd_net.c index 3ffb9df..44d17db 100644 --- a/common/cmd_net.c +++ b/common/cmd_net.c @@ -54,6 +54,7 @@ U_BOOT_CMD( "[loadAddress] [[hostIPaddr:]bootfilename]" ); +#ifdef CONFIG_CMD_RARP int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { return netboot_common (RARP, cmdtp, argc, argv); @@ -64,6 +65,7 @@ U_BOOT_CMD( "boot image via network using RARP/TFTP protocol", "[loadAddress] [[hostIPaddr:]bootfilename]" ); +#endif #if defined(CONFIG_CMD_DHCP) int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) diff --git a/common/cmd_tsi148.c b/common/cmd_tsi148.c index 1e83c88..6dc9dab 100644 --- a/common/cmd_tsi148.c +++ b/common/cmd_tsi148.c @@ -419,7 +419,7 @@ int do_tsi148(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc > 5) vam = simple_strtoul(argv[5], NULL, 16); if (argc > 6) - vdw = simple_strtoul(argv[7], NULL, 16); + vdw = simple_strtoul(argv[6], NULL, 16); switch (cmd) { case 'c': @@ -465,7 +465,7 @@ int do_tsi148(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } U_BOOT_CMD( - tsi148, 8, 1, do_tsi148, + tsi148, 7, 1, do_tsi148, "initialize and configure Turndra Tsi148\n", "init\n" " - initialize tsi148\n" diff --git a/common/dlmalloc.c b/common/dlmalloc.c index ae5702d..fce7a76 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1152,7 +1152,7 @@ struct malloc_chunk INTERNAL_SIZE_T size; /* Size in bytes, including overhead. */ struct malloc_chunk* fd; /* double links -- used only if free. */ struct malloc_chunk* bk; -}; +} __attribute__((__may_alias__)) ; typedef struct malloc_chunk* mchunkptr; diff --git a/common/env_common.c b/common/env_common.c index 88f068c..5acda4d 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -237,8 +237,8 @@ void env_relocate (void) set_default_env(NULL); #else show_boot_progress (-60); -#endif set_default_env("!bad CRC"); +#endif } else { env_relocate_spec (); } diff --git a/common/env_mmc.c b/common/env_mmc.c index cc288d4..3d7fceb 100644 --- a/common/env_mmc.c +++ b/common/env_mmc.c @@ -29,6 +29,7 @@ #include <linux/stddef.h> #include <malloc.h> #include <mmc.h> +#include <errno.h> /* references to names in env_common.c */ extern uchar default_environment[]; @@ -96,13 +97,23 @@ inline int write_env(struct mmc *mmc, unsigned long size, int saveenv(void) { + env_t env_new; + ssize_t len; + char *res; struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); if (init_mmc_for_env(mmc)) return 1; + res = (char *)&env_new.data; + len = hexport('\0', &res, ENV_SIZE); + if (len < 0) { + error("Cannot export environment: errno = %d\n", errno); + return 1; + } + env_new.crc = crc32(0, env_new.data, ENV_SIZE); printf("Writing to MMC(%d)... ", CONFIG_SYS_MMC_ENV_DEV); - if (write_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr)) { + if (write_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, (u_char *)&env_new)) { puts("failed\n"); return 1; } @@ -129,18 +140,21 @@ inline int read_env(struct mmc *mmc, unsigned long size, void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) + char buf[CONFIG_ENV_SIZE]; + struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); - if (init_mmc_for_env(mmc)) + if (init_mmc_for_env(mmc)) { + use_default(); return; + } - if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr)) - return use_default(); - - if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) - return use_default(); + if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) { + use_default(); + return; + } - gd->env_valid = 1; + env_import(buf, 1); #endif } diff --git a/common/fdt_support.c b/common/fdt_support.c index 0ed6e77..90e9097 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -362,10 +362,40 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat, do_fixup_by_compat(fdt, compat, prop, &val, 4, create); } -int fdt_fixup_memory(void *blob, u64 start, u64 size) +/* + * Get cells len in bytes + * if #NNNN-cells property is 2 then len is 8 + * otherwise len is 4 + */ +static int get_cells_len(void *blob, char *nr_cells_name) { - int err, nodeoffset, len = 0; - u8 tmp[16]; + const u32 *cell; + + cell = fdt_getprop(blob, 0, nr_cells_name, NULL); + if (cell && *cell == 2) + return 8; + + return 4; +} + +/* + * Write a 4 or 8 byte big endian cell + */ +static void write_cell(u8 *addr, u64 val, int size) +{ + int shift = (size - 1) * 8; + while (size-- > 0) { + *addr++ = (val >> shift) & 0xff; + shift -= 8; + } +} + +int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) +{ + int err, nodeoffset; + int addr_cell_len, size_cell_len, len; + u8 tmp[banks * 8]; + int bank; const u32 *addrcell, *sizecell; err = fdt_check_header(blob); @@ -391,44 +421,15 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size) return err; } - addrcell = fdt_getprop(blob, 0, "#address-cells", NULL); - /* use shifts and mask to ensure endianness */ - if ((addrcell) && (*addrcell == 2)) { - tmp[0] = (start >> 56) & 0xff; - tmp[1] = (start >> 48) & 0xff; - tmp[2] = (start >> 40) & 0xff; - tmp[3] = (start >> 32) & 0xff; - tmp[4] = (start >> 24) & 0xff; - tmp[5] = (start >> 16) & 0xff; - tmp[6] = (start >> 8) & 0xff; - tmp[7] = (start ) & 0xff; - len = 8; - } else { - tmp[0] = (start >> 24) & 0xff; - tmp[1] = (start >> 16) & 0xff; - tmp[2] = (start >> 8) & 0xff; - tmp[3] = (start ) & 0xff; - len = 4; - } + addr_cell_len = get_cells_len(blob, "#address-cells"); + size_cell_len = get_cells_len(blob, "#size-cells"); - sizecell = fdt_getprop(blob, 0, "#size-cells", NULL); - /* use shifts and mask to ensure endianness */ - if ((sizecell) && (*sizecell == 2)) { - tmp[0+len] = (size >> 56) & 0xff; - tmp[1+len] = (size >> 48) & 0xff; - tmp[2+len] = (size >> 40) & 0xff; - tmp[3+len] = (size >> 32) & 0xff; - tmp[4+len] = (size >> 24) & 0xff; - tmp[5+len] = (size >> 16) & 0xff; - tmp[6+len] = (size >> 8) & 0xff; - tmp[7+len] = (size ) & 0xff; - len += 8; - } else { - tmp[0+len] = (size >> 24) & 0xff; - tmp[1+len] = (size >> 16) & 0xff; - tmp[2+len] = (size >> 8) & 0xff; - tmp[3+len] = (size ) & 0xff; - len += 4; + for (bank = 0, len = 0; bank < banks; bank++) { + write_cell(tmp + len, start[bank], addr_cell_len); + len += addr_cell_len; + + write_cell(tmp + len, size[bank], size_cell_len); + len += size_cell_len; } err = fdt_setprop(blob, nodeoffset, "reg", tmp, len); @@ -440,6 +441,11 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size) return 0; } +int fdt_fixup_memory(void *blob, u64 start, u64 size) +{ + return fdt_fixup_memory_banks(blob, &start, &size, 1); +} + void fdt_fixup_ethernet(void *fdt) { int node, i, j; @@ -667,6 +673,16 @@ int fdt_fixup_nor_flash_size(void *blob) } #endif +int fdt_increase_size(void *fdt, int add_len) +{ + int newlen; + + newlen = fdt_totalsize(fdt) + add_len; + + /* Open in place with a new len */ + return fdt_open_into(fdt, fdt, newlen); +} + #ifdef CONFIG_FDT_FIXUP_PARTITIONS #include <jffs2/load_kernel.h> #include <mtd_node.h> @@ -701,16 +717,6 @@ int fdt_del_subnodes(const void *blob, int parent_offset) return 0; } -int fdt_increase_size(void *fdt, int add_len) -{ - int newlen; - - newlen = fdt_totalsize(fdt) + add_len; - - /* Open in place with a new len */ - return fdt_open_into(fdt, fdt, newlen); -} - int fdt_del_partitions(void *blob, int parent_offset) { const void *prop; @@ -1189,3 +1195,32 @@ int fdt_alloc_phandle(void *blob) return phandle + 1; } + +#if defined(CONFIG_VIDEO) +int fdt_add_edid(void *blob, const char *compat, unsigned char *edid_buf) +{ + int noff; + int ret; + + noff = fdt_node_offset_by_compatible(blob, -1, compat); + if (noff != -FDT_ERR_NOTFOUND) { + debug("%s: %s\n", fdt_get_name(blob, noff, 0), compat); +add_edid: + ret = fdt_setprop(blob, noff, "edid", edid_buf, 128); + if (ret == -FDT_ERR_NOSPACE) { + ret = fdt_increase_size(blob, 512); + if (!ret) + goto add_edid; + else + goto err_size; + } else if (ret < 0) { + printf("Can't add property: %s\n", fdt_strerror(ret)); + return ret; + } + } + return 0; +err_size: + printf("Can't increase blob size: %s\n", fdt_strerror(ret)); + return ret; +} +#endif diff --git a/common/image.c b/common/image.c index 3a2f25e..385464d 100644 --- a/common/image.c +++ b/common/image.c @@ -992,7 +992,7 @@ int boot_get_ramdisk (int argc, char * const argv[], bootm_headers_t *images, return 0; } -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) +#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH /** * boot_ramdisk_high - relocate init ramdisk * @lmb: pointer to lmb handle, will be used for memory mgmt @@ -1081,7 +1081,7 @@ int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, error: return -1; } -#endif /* defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) */ +#endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */ #ifdef CONFIG_OF_LIBFDT static void fdt_error (const char *msg) @@ -1252,7 +1252,7 @@ int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, *of_size = of_len; } else { *of_flat_tree = fdt_blob; - of_len = (CONFIG_SYS_BOOTMAPSZ + bootmap_base) - (ulong)fdt_blob; + of_len = *of_size + CONFIG_SYS_FDT_PAD; lmb_reserve(lmb, (ulong)fdt_blob, of_len); fdt_set_totalsize(*of_flat_tree, of_len); @@ -1561,7 +1561,7 @@ int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *imag goto error; } - if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) { + if (fdt_totalsize(fdt_blob) != fdt_len) { fdt_error ("fdt size != image size"); goto error; } @@ -1575,7 +1575,7 @@ int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *imag } *of_flat_tree = fdt_blob; - *of_size = be32_to_cpu (fdt_totalsize (fdt_blob)); + *of_size = fdt_totalsize(fdt_blob); debug (" of_flat_tree at 0x%08lx size 0x%08lx\n", (ulong)*of_flat_tree, *of_size); @@ -1588,7 +1588,7 @@ error: } #endif /* CONFIG_OF_LIBFDT */ -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) +#ifdef CONFIG_SYS_BOOT_GET_CMDLINE /** * boot_get_cmdline - allocate and initialize kernel cmdline * @lmb: pointer to lmb handle, will be used for memory mgmt @@ -1630,7 +1630,9 @@ int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, return 0; } +#endif /* CONFIG_SYS_BOOT_GET_CMDLINE */ +#ifdef CONFIG_SYS_BOOT_GET_KBD /** * boot_get_kbd - allocate and initialize kernel copy of board info * @lmb: pointer to lmb handle, will be used for memory mgmt @@ -1663,7 +1665,7 @@ int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base) return 0; } -#endif /* CONFIG_PPC || CONFIG_M68K */ +#endif /* CONFIG_SYS_BOOT_GET_KBD */ #endif /* !USE_HOSTCC */ #if defined(CONFIG_FIT) diff --git a/common/usb_storage.c b/common/usb_storage.c index 76949b8..613c4f0 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -204,6 +204,22 @@ int usb_stor_info(void) return 1; } +static unsigned int usb_get_max_lun(struct us_data *us) +{ + int len; + unsigned char result; + len = usb_control_msg(us->pusb_dev, + usb_rcvctrlpipe(us->pusb_dev, 0), + US_BBB_GET_MAX_LUN, + USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, + 0, us->ifnum, + &result, sizeof(result), + USB_CNTL_TIMEOUT * 5); + USB_STOR_PRINTF("Get Max LUN -> len = %i, result = %i\n", + len, (int) result); + return (len > 0) ? result : 0; +} + /******************************************************************************* * scan the usb and reports device info * to the user if mode = 1 @@ -241,13 +257,22 @@ int usb_stor_scan(int mode) break; /* no more devices avaiable */ if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) { - /* ok, it is a storage devices - * get info and fill it in + /* OK, it's a storage device. Iterate over its LUNs + * and populate `usb_dev_desc'. */ - if (usb_stor_get_info(dev, &usb_stor[usb_max_devs], - &usb_dev_desc[usb_max_devs]) == 1) + int lun, max_lun, start = usb_max_devs; + + max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]); + for (lun = 0; + lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV; + lun++) { + usb_dev_desc[usb_max_devs].lun = lun; + if (usb_stor_get_info(dev, &usb_stor[start], + &usb_dev_desc[usb_max_devs]) == 1) { usb_max_devs++; } + } + } /* if storage device */ if (usb_max_devs == USB_MAX_STOR_DEV) { printf("max USB Storage Device reached: %d stopping\n", @@ -882,6 +907,7 @@ static int usb_inquiry(ccb *srb, struct us_data *ss) do { memset(&srb->cmd[0], 0, 12); srb->cmd[0] = SCSI_INQUIRY; + srb->cmd[1] = srb->lun << 5; srb->cmd[4] = 36; srb->datalen = 36; srb->cmdlen = 12; @@ -905,6 +931,7 @@ static int usb_request_sense(ccb *srb, struct us_data *ss) ptr = (char *)srb->pdata; memset(&srb->cmd[0], 0, 12); srb->cmd[0] = SCSI_REQ_SENSE; + srb->cmd[1] = srb->lun << 5; srb->cmd[4] = 18; srb->datalen = 18; srb->pdata = &srb->sense_buf[0]; @@ -924,6 +951,7 @@ static int usb_test_unit_ready(ccb *srb, struct us_data *ss) do { memset(&srb->cmd[0], 0, 12); srb->cmd[0] = SCSI_TST_U_RDY; + srb->cmd[1] = srb->lun << 5; srb->datalen = 0; srb->cmdlen = 12; if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD) @@ -943,6 +971,7 @@ static int usb_read_capacity(ccb *srb, struct us_data *ss) do { memset(&srb->cmd[0], 0, 12); srb->cmd[0] = SCSI_RD_CAPAC; + srb->cmd[1] = srb->lun << 5; srb->datalen = 8; srb->cmdlen = 12; if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD) @@ -957,6 +986,7 @@ static int usb_read_10(ccb *srb, struct us_data *ss, unsigned long start, { memset(&srb->cmd[0], 0, 12); srb->cmd[0] = SCSI_READ10; + srb->cmd[1] = srb->lun << 5; srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff; srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff; srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff; @@ -973,6 +1003,7 @@ static int usb_write_10(ccb *srb, struct us_data *ss, unsigned long start, { memset(&srb->cmd[0], 0, 12); srb->cmd[0] = SCSI_WRITE10; + srb->cmd[1] = srb->lun << 5; srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff; srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff; srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff; |