From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [Drivers PATCH 17/19] imls: Add support to list images in NAND device
Date: Tue, 6 Nov 2012 17:30:26 -0600 [thread overview]
Message-ID: <1352244626.21833.12@snotra> (raw)
In-Reply-To: <09794284905d5ef15a117c85b9db44092402317a.1351877124.git.vipin.kumar@st.com> (from vipin.kumar@st.com on Fri Nov 2 12:40:02 2012)
On 11/02/2012 12:40:02 PM, Vipin Kumar wrote:
> imls does not list the images in NAND devices. This patch implements
> this
> support for legacy type images.
>
> Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
> ---
> common/cmd_bootm.c | 98
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 98 insertions(+)
>
> diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
> index 83fa5d7..ca3c430 100644
> --- a/common/cmd_bootm.c
> +++ b/common/cmd_bootm.c
> @@ -62,6 +62,11 @@
> #include <linux/lzo.h>
> #endif /* CONFIG_LZO */
>
> +#if defined(CONFIG_CMD_NAND)
> +#include <linux/err.h>
> +#include <nand.h>
> +#endif
You shouldn't need to ifdef-protect header files.
> DECLARE_GLOBAL_DATA_PTR;
>
> #ifndef CONFIG_SYS_BOOTM_LEN
> @@ -1221,6 +1226,99 @@ next_sector: ;
> next_bank: ;
> }
>
> +#if defined(CONFIG_CMD_NAND)
> + printf("\n");
> + nand_info_t *nand;
> + image_header_t image_header;
> + image_header_t *header = &image_header;
> + int nand_dev = nand_curr_device;
> + unsigned long img_size;
> + size_t hdr_size, read_len;
> + loff_t off;
> + unsigned int crc;
> + u_char *data;
> +
> + /* the following commands operate on the current device */
> + if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
> + puts("\nNo NAND devices available\n");
> + return 0;
> + }
Please move the NAND and NOR code into their own functions.
> +
> + for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE;
> nand_dev++) {
> +
> + nand = &nand_info[nand_dev];
> + if ((!nand->name) || (!nand->size))
> + continue;
Redundant parentheses.
> + data = malloc(nand->writesize);
> + if (!data) {
> + puts("No memory available to list NAND
> images\n");
> + return 0;
> + }
> +
> + for (off = 0; off < nand->size; off += nand->erasesize)
> {
> + int ret;
> +
> + if (nand_block_isbad(nand, off))
> + continue;
> +
> + hdr_size = sizeof(image_header_t);
> + ret = nand_read(nand, off, &hdr_size, (u_char
> *)header);
> + if (ret < 0 && ret != -EUCLEAN)
> + continue;
I guess you don't use nand_read_skip_bad() because you don't want to
allocate a buffer for the whole image... How about moving this code to
nand_util.c? That would at least allow some refactoring rather than
duplication.
> + if (!image_check_hcrc(header))
> + continue;
> +
> + printf("Legacy Image at NAND device %d offset
> %08lX:\n",
> + nand_dev, (ulong)off);
> + image_print_contents(header);
Shouldn't you check for FIT images as well?
> + puts(" Verifying Checksum ... ");
> + crc = 0;
> + img_size = ntohl(header->ih_size);
> + img_size += hdr_size;
> +
> + while (img_size > 0) {
> + int blockoff = 0;
> +
> + while (nand_block_isbad(nand, off)) {
> + off += nand->erasesize;
> + if (off >= nand->size)
> + goto out;
> + }
> +
> + do {
> + read_len = min(img_size,
> +
> nand->writesize);
> + ret = nand_read(nand, off +
> blockoff,
> + &read_len,
> data);
> + if (ret < 0 && ret != -EUCLEAN)
> + break;
> +
> + crc = crc32(crc, data +
> hdr_size,
> + read_len -
> hdr_size);
> + img_size -= read_len;
> + blockoff += read_len;
> + hdr_size = 0;
> + } while (img_size &&
> + (blockoff <
> nand->erasesize));
> +
> + off += nand->erasesize;
> + if (off >= nand->size)
> + goto out;
> + }
> + off -= nand->erasesize;
> +out:
> + if (crc != ntohl(header->ih_dcrc))
> + puts(" Bad Data CRC\n");
> + else
> + puts("OK\n");
> + }
Please refactor this into separate functions to improve readability.
Maybe put a nand_crc_skip_bad() function into nand_util.c?
-Scott
next prev parent reply other threads:[~2012-11-06 23:30 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1351876757.git.vipin.kumar@st.com>
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 01/19] mtd/st_smi: Clear error flags while initiating a fresh write Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 02/19] mtd/st_smi: Add support for Micron N25Q128 Flash Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 03/19] mtd/st_smi: Avoid issuing multiple WE commands Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 04/19] mtd/st_smi: Write to flash in a tight loop Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 05/19] mtd/st_smi: Use page sizes respective to flash Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 06/19] usbh/ehci: Increase timeout for enumeration Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 07/19] sdhci: Add sdhci support for spear devices Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 08/19] net/designware: Do not select MIIPORT for RGMII interface Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 10/19] usb/gadget/designware_otg: Add support for designware otg Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 11/19] usb/host/ehci: Add support for EHCI on spear Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 12/19] usbtty: adapt buffers for large packet support Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 13/19] net/macb: Add arch specific routine to get mdio control Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [Drivers PATCH 14/19] net/macb: workaround for transmission hang issue Vipin Kumar
2013-02-03 11:19 ` Albert ARIBAUD
2013-02-28 12:59 ` Albert ARIBAUD
2013-03-01 3:08 ` Bo Shen
2013-03-01 3:40 ` Vipin Kumar
2013-03-01 3:48 ` Bo Shen
2013-03-01 3:41 ` Vipin Kumar
2013-03-01 7:28 ` Albert ARIBAUD
2013-03-01 7:55 ` Vipin Kumar
2012-11-02 17:40 ` [U-Boot] [Drivers PATCH 15/19] misc/crypto: Add support for C3 Vipin Kumar
2012-11-02 17:40 ` [U-Boot] [Drivers PATCH 16/19] armv7/ltimer: Add support for local timer on armv7 cpus Vipin Kumar
2012-11-02 17:40 ` [U-Boot] [Drivers PATCH 17/19] imls: Add support to list images in NAND device Vipin Kumar
2012-11-06 23:30 ` Scott Wood [this message]
2012-11-07 5:15 ` Vipin Kumar
2012-11-07 20:49 ` Scott Wood
2012-11-02 17:40 ` [U-Boot] [Drivers PATCH 18/19] u-boot/spl: Add u-boot-spl.img to u-boot targets Vipin Kumar
2012-11-02 17:40 ` [U-Boot] [Drivers PATCH 19/19] arm/boards: Define a new config option CONFIG_BOOT_PARAMS_P Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr13xx PATCH 1/7] spear1340: Add support for spear1340 SoC Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr13xx PATCH 2/7] spear1310: Add support for spear1310 SoC Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr13xx PATCH 3/7] spear1340evb: Add support for evb machine Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr13xx PATCH 4/7] spear1310evb: " Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr13xx PATCH 5/7] spear1340lcad: Add support for LCAD machine Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr13xx PATCH 6/7] spear1340evb: Add SPL support Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr13xx PATCH 7/7] spear1310evb: " Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 1/9] spear: Add cache support Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 2/9] spear3xx: Add pinmux support Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 3/9] spear320plc: Correct the MACB interface Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 4/9] spear/configs: Modify several configurations Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 5/9] spear320: Add support for SD/MMC Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 6/9] spear320-hmi: Add support for hmi machine Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 7/9] spear6xx/spear3xx: Add support to boot via NAND device Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 8/9] spear/spl: Add support to boot from Parallel NOR device Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Enhancement PATCH 9/9] spear300evb: Add SPL support Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 01/11] SPEAr: Remove extra spear board configurations Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 02/11] spear/configs: Split config files hierarchically into plat, arch, soc and board Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 03/11] spear/include: Clean up the spear include files Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 04/11] spear/board: Cleanup spear related board files Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 05/11] spear: Append MISC_ as prefix to misc register bitmasks Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 06/11] spear: Read ethaddr from I2C memory Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 07/11] spear: Cleanup SoC area Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 08/11] spear/spl: Cleanup spear SPL Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 09/11] spear: Add POST memory support Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 10/11] spear: Enable ehci support Vipin Kumar
2012-11-02 17:39 ` [U-Boot] [SPEAr Fixes PATCH 11/11] spear3xx: FIX: Enable access to memory for spear310 and spear320 Vipin Kumar
2012-11-07 14:10 ` [U-Boot] [PATCH 00/46] Enhance spear support Stefan Roese
2012-11-08 4:58 ` Vipin Kumar
2012-11-08 4:58 ` Vipin Kumar
[not found] ` <509CD19A.2060903@st.com>
2012-11-09 11:56 ` Stefan Roese
2012-11-10 8:48 ` Albert ARIBAUD
2012-11-11 6:11 ` Stefan Roese
2012-11-11 7:50 ` Wolfgang Denk
2012-11-11 17:49 ` Albert ARIBAUD
2012-11-12 9:34 ` Armando Visconti
2012-11-12 10:35 ` Vipin Kumar
2012-11-21 9:24 ` Wolfgang Denk
2012-11-30 11:15 ` Armando Visconti
2012-11-30 12:34 ` Wolfgang Denk
2012-11-30 14:10 ` Armando Visconti
2012-12-03 5:51 ` Vipin Kumar
2012-11-20 9:46 ` Vipin Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1352244626.21833.12@snotra \
--to=scottwood@freescale.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox