From patchwork Fri Nov 2 17:40:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Kumar X-Patchwork-Id: 196727 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 2E4682C00C1 for ; Sat, 3 Nov 2012 05:22:24 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 385894B156; Fri, 2 Nov 2012 19:19:38 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b1e4z2lp0Yzz; Fri, 2 Nov 2012 19:19:37 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 76FCC4AF31; Fri, 2 Nov 2012 19:17:17 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CDB1A4AEC9 for ; Fri, 2 Nov 2012 19:17:03 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 71zIjh6dSAIg for ; Fri, 2 Nov 2012 19:17:03 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from eu1sys200aog110.obsmtp.com (eu1sys200aog110.obsmtp.com [207.126.144.129]) by theia.denx.de (Postfix) with ESMTPS id 603984AECA for ; Fri, 2 Nov 2012 19:16:45 +0100 (CET) Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob110.postini.com ([207.126.147.11]) with SMTP ID DSNKUJQODMA1SNAoEgbeTTayF8fQ6Ane01KU@postini.com; Fri, 02 Nov 2012 18:16:46 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id A77631A1; Fri, 2 Nov 2012 17:36:44 +0000 (GMT) Received: from Webmail-ap.st.com (eapex1hubcas2.st.com [10.80.176.10]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id DA170107D; Fri, 2 Nov 2012 17:44:57 +0000 (GMT) Received: from localhost (10.251.136.62) by Webmail-ap.st.com (10.80.176.7) with Microsoft SMTP Server (TLS) id 8.3.245.1; Sat, 3 Nov 2012 01:44:57 +0800 From: Vipin Kumar To: Date: Fri, 2 Nov 2012 23:10:02 +0530 Message-ID: <09794284905d5ef15a117c85b9db44092402317a.1351877124.git.vipin.kumar@st.com> X-Mailer: git-send-email 1.7.10.rc2.10.gb47606 In-Reply-To: <1c8cd3ce05a1064788a96bb4b49f9b82d9caf736.1351877124.git.vipin.kumar@st.com> References: <1c8cd3ce05a1064788a96bb4b49f9b82d9caf736.1351877124.git.vipin.kumar@st.com> MIME-Version: 1.0 Cc: sr@denx.de, spear-devel@list.st.com Subject: [U-Boot] [Drivers PATCH 17/19] imls: Add support to list images in NAND device X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de imls does not list the images in NAND devices. This patch implements this support for legacy type images. Signed-off-by: Vipin Kumar --- 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 #endif /* CONFIG_LZO */ +#if defined(CONFIG_CMD_NAND) +#include +#include +#endif + 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; + } + + for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { + + nand = &nand_info[nand_dev]; + if ((!nand->name) || (!nand->size)) + continue; + + 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; + + if (!image_check_hcrc(header)) + continue; + + printf("Legacy Image at NAND device %d offset %08lX:\n", + nand_dev, (ulong)off); + image_print_contents(header); + + 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"); + } + free(data); + } + +#endif return (0); }