From patchwork Mon Dec 9 08:50:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 22169 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0270523FBA for ; Mon, 9 Dec 2013 08:49:32 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id gq1sf12852750obb.2 for ; Mon, 09 Dec 2013 00:49:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:dlp-filter:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=t3cZ5JR36HERomP8XYoibbmHVinR7Rue2rieoZnIkhU=; b=By56gF5UZs0xgCNU4myWGdsyhIYi5U9roAKMdbc+Praps08Sj83AYne/uYNp+oANKp JYbT0opWVCV8t+EB/xbejn8aXK8jbkiRpPf9ItWgMDP6TbdW9Fl0/fYVEycR+rmxAGCj o3XDSJMP0KWp61/pr7XTiO0EFANIA0w/mE8MWKDGHKl3My7b72x2LPuLg1meia7OshWJ lOoikDiXR47e/ob5dZa/rWZtVHqj52sJVoZidxfi704I736YaPTgzQ1rgcFoYXPdHYpE H5H4W8cIpqs6/1DwFWEEqOHCxf62/RwnrNIZECqGer32KBg+gxEBpD3N3ffgt22kcH6C tGkg== X-Gm-Message-State: ALoCoQm6Zx9GZGwIc5bNv9KIo1KTeRvOeYch/nsYkQcKG3XNsqfnLw1x5q7y1wVbVKCNTIs1ZpdI X-Received: by 10.182.111.70 with SMTP id ig6mr6133537obb.34.1386578972544; Mon, 09 Dec 2013 00:49:32 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.73.69 with SMTP id j5ls2106237qev.48.gmail; Mon, 09 Dec 2013 00:49:32 -0800 (PST) X-Received: by 10.221.29.8 with SMTP id rw8mr251473vcb.56.1386578972400; Mon, 09 Dec 2013 00:49:32 -0800 (PST) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id im16si3578126vec.92.2013.12.09.00.49.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 09 Dec 2013 00:49:32 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id ib11so522649vcb.22 for ; Mon, 09 Dec 2013 00:49:32 -0800 (PST) X-Received: by 10.58.46.18 with SMTP id r18mr10477718vem.4.1386578972314; Mon, 09 Dec 2013 00:49:32 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp89884vcz; Mon, 9 Dec 2013 00:49:31 -0800 (PST) X-Received: by 10.68.172.65 with SMTP id ba1mr19555231pbc.18.1386578965728; Mon, 09 Dec 2013 00:49:25 -0800 (PST) Received: from mailout1.samsung.com (mailout1.samsung.com. [203.254.224.24]) by mx.google.com with ESMTPS id eb3si6582645pbc.356.2013.12.09.00.49.25 for (version=TLSv1 cipher=RC4-MD5 bits=128/128); Mon, 09 Dec 2013 00:49:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.24 as permitted sender) client-ip=203.254.224.24; Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MXJ00C6D76B8RD0@mailout1.samsung.com>; Mon, 09 Dec 2013 17:49:23 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.125]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id 57.94.15154.31485A25; Mon, 09 Dec 2013 17:49:23 +0900 (KST) X-AuditID: cbfee68e-b7fee6d000003b32-49-52a584136386 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 9A.40.15903.31485A25; Mon, 09 Dec 2013 17:49:23 +0900 (KST) Received: from localhost.localdomain.com ([107.108.73.95]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MXJ00KEY75NNA30@mmp1.samsung.com>; Mon, 09 Dec 2013 17:49:23 +0900 (KST) From: Rajeshwari S Shinde To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, chander.kashyap@linaro.org, u-boot-review@google.com, alim.akhtar@samsung.com, trini@ti.com Subject: [PATCH 11/11 V10] SPL: EXYNOS: Prepare for variable size SPL support Date: Mon, 09 Dec 2013 14:20:47 +0530 Message-id: <1386579047-2501-12-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.11.7 In-reply-to: <1386579047-2501-1-git-send-email-rajeshwari.s@samsung.com> References: <1386579047-2501-1-git-send-email-rajeshwari.s@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeLIzCtJLcpLzFFi42JZI2JSqyvcsjTI4O9eMYsH87axWTxcf5PF ouNIC6PFlMNfWCy+bdnGaDF58Xxmi+WvN7JbvN3bye7A4TG74SKLx4JNpR53ru1h8zh7Zwej R9+WVYwex29sZwpgi+KySUnNySxLLdK3S+DKOHtrPlPBQa+Kgw9uMDYwtlh3MXJySAiYSJw8 c48FwhaTuHBvPVsXIxeHkMBSRol7S7rZYYrm/P/IDJFYxChx4eBCqKouJokFh1pYuxg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CjAwajEw7uCdWmQEGtiWXFl7iFGCQ5mJRFe8xqg EG9KYmVValF+fFFpTmrxIcZkoKsmMkuJJucD4z6vJN7Q2MTc1NjU0sTCxMySNGElcd6DrdaB QgLpiSWp2ampBalFMFuYODilGhjVVNo4d17TMss3nOay9SZ7rFGn0Oqls6drCTkb/LS3Xc61 8oHft3VyU/wOMPdI6LVUftXM4G89unsf8xkmpjUHZf+LM9Q8ijmpdfnb2gXZjaaapw9yKahv b95leHqp+r1bt/2+im/llXlWbyElvWuWfdaOT70q2xaXcwnpGgZcqgv66lR5S0uJpTgj0VCL uag4EQCRvdNO8QIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rajeshwari.s@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , When variable size SPL is used, the BL1 expects the SPL to be encapsulated differently: instead of putting the checksum at a fixed offset in the SPL blob, prepend the blob with a header including the size and the checksum. The enhancements include - adding a command line option, '--vs' to indicate the need for the variable size encapsulation - padding the fixed size encapsulated blob with 0xff instead of random memory contents - do not silently truncate the input file, report error instead - no need to explicitly closing files/freeing memory, this all happens on exit; removing cleanups it makes code clearer - profuse commenting - modify Makefile to allow enabling the new feature per board Signed-off-by: Vadim Bendebury Signed-off-by: Rajeshwari S Shinde Acked-by: Simon Glass --- Changes in V2: - None Changes in V3: - None Changes in V4: - Created a common exynos5-dt.h Changes in V5: - None Changes in V6: - None. Changes in V7: - None. Changes in V8: - None Changes in V9: - Rebased on latest code. Changes in V10: - None include/configs/smdk5420.h | 6 ++ spl/Makefile | 7 +- tools/mkexynosspl.c | 167 +++++++++++++++++++++++++++++++++------------ 3 files changed, 136 insertions(+), 44 deletions(-) diff --git a/include/configs/smdk5420.h b/include/configs/smdk5420.h index 9eab7d6..447f8e5 100644 --- a/include/configs/smdk5420.h +++ b/include/configs/smdk5420.h @@ -19,6 +19,8 @@ #define CONFIG_ARCH_DEVICE_TREE exynos5420 +#define CONFIG_VAR_SIZE_SPL + #define CONFIG_SYS_SDRAM_BASE 0x20000000 #define CONFIG_SYS_TEXT_BASE 0x23E00000 @@ -31,7 +33,11 @@ /* select serial console configuration */ #define CONFIG_SERIAL3 /* use SERIAL 3 */ +#ifdef CONFIG_VAR_SIZE_SPL +#define CONFIG_SPL_TEXT_BASE 0x02024410 +#else #define CONFIG_SPL_TEXT_BASE 0x02024400 +#endif #define CONFIG_BOOTCOMMAND "mmc read 20007000 451 2000; bootm 20007000" diff --git a/spl/Makefile b/spl/Makefile index cbd3d27..9eedbdd 100644 --- a/spl/Makefile +++ b/spl/Makefile @@ -174,8 +174,13 @@ endif all: $(ALL-y) ifdef CONFIG_SAMSUNG +ifdef CONFIG_VAR_SIZE_SPL +VAR_SIZE_PARAM = --vs +else +VAR_SIZE_PARAM = +endif $(obj)$(BOARD)-spl.bin: $(obj)u-boot-spl.bin - $(OBJTREE)/tools/mk$(BOARD)spl \ + $(OBJTREE)/tools/mk$(BOARD)spl $(VAR_SIZE_PARAM) \ $(obj)u-boot-spl.bin $(obj)$(BOARD)-spl.bin endif diff --git a/tools/mkexynosspl.c b/tools/mkexynosspl.c index ef685b7..32b786c 100644 --- a/tools/mkexynosspl.c +++ b/tools/mkexynosspl.c @@ -14,93 +14,174 @@ #include #define CHECKSUM_OFFSET (14*1024-4) -#define BUFSIZE (14*1024) #define FILE_PERM (S_IRUSR | S_IWUSR | S_IRGRP \ | S_IWGRP | S_IROTH | S_IWOTH) /* -* Requirement: -* IROM code reads first 14K bytes from boot device. -* It then calculates the checksum of 14K-4 bytes and compare with data at -* 14K-4 offset. -* -* This function takes two filenames: -* IN "u-boot-spl.bin" and -* OUT "$(BOARD)-spl.bin as filenames. -* It reads the "u-boot-spl.bin" in 16K buffer. -* It calculates checksum of 14K-4 Bytes and stores at 14K-4 offset in buffer. -* It writes the buffer to "$(BOARD)-spl.bin" file. -*/ + * Requirement for the fixed size SPL header: + * IROM code reads first (CHECKSUM_OFFSET + 4) bytes from boot device. It then + * calculates the checksum of CHECKSUM_OFFSET bytes and compares with data at + * CHECKSUM_OFFSET location. + * + * Requirement for the variable size SPL header: + + * IROM code reads the below header to find out the size of the blob (total + * size, header size included) and its checksum. Then it reads the rest of the + * blob [i.e size - sizeof(struct var_size_header) bytes], calculates the + * checksum and compares it with value read from the header. + */ +struct var_size_header { + uint32_t spl_size; + uint32_t spl_checksum; + uint32_t reserved[2]; +}; + +static const char *prog_name; + +static void write_to_file(int ofd, void *buffer, int size) +{ + if (write(ofd, buffer, size) == size) + return; + + fprintf(stderr, "%s: Failed to write to output file: %s\n", + prog_name, strerror(errno)); + exit(EXIT_FAILURE); +} +/* + * The argv is expected to include one optional parameter and two filenames: + * [--vs] IN OUT + * + * --vs - turns on the variable size SPL mode + * IN - the u-boot SPL binary, usually u-boot-spl.bin + * OUT - the prepared SPL blob, usually ${BOARD}-spl.bin + * + * This utility first reads the "u-boot-spl.bin" into a buffer. In case of + * fixed size SPL the buffer size is exactly CHECKSUM_OFFSET (such that + * smaller u-boot-spl.bin gets padded with 0xff bytes, the larger than limit + * u-boot-spl.bin causes an error). For variable size SPL the buffer size is + * eqaul to size of the IN file. + * + * Then it calculates checksum of the buffer by just summing up all bytes. + * Then + * + * - for fixed size SPL the buffer is written into the output file and the + * checksum is appended to the file in little endian format, which results + * in checksum added exactly at CHECKSUM_OFFSET. + * + * - for variable size SPL the checksum and file size are stored in the + * var_size_header structure (again, in little endian format) and the + * structure is written into the output file. Then the buffer is written + * into the output file. + */ int main(int argc, char **argv) { - unsigned char buffer[BUFSIZE]; + unsigned char *buffer; int i, ifd, ofd; uint32_t checksum = 0; off_t len; - ssize_t count; + int var_size_flag, read_size, count; struct stat stat; - - if (argc != 3) { - fprintf(stderr, "Usage: %s \n", argv[0]); + const int if_index = argc - 2; /* Input file name index in argv. */ + const int of_index = argc - 1; /* Output file name index in argv. */ + + /* Strip path off the program name. */ + prog_name = strrchr(argv[0], '/'); + if (prog_name) + prog_name++; + else + prog_name = argv[0]; + + if ((argc < 3) || + (argc > 4) || + ((argc == 4) && strcmp(argv[1], "--vs"))) { + fprintf(stderr, "Usage: %s [--vs] \n", + prog_name); exit(EXIT_FAILURE); } - ifd = open(argv[1], O_RDONLY); + /* four args mean variable size SPL wrapper is required */ + var_size_flag = (argc == 4); + + ifd = open(argv[if_index], O_RDONLY); if (ifd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - argv[0], argv[1], strerror(errno)); + prog_name, argv[if_index], strerror(errno)); exit(EXIT_FAILURE); } - ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM); + ofd = open(argv[of_index], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM); if (ifd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", - argv[0], argv[2], strerror(errno)); - close(ifd); + prog_name, argv[of_index], strerror(errno)); exit(EXIT_FAILURE); } if (fstat(ifd, &stat)) { fprintf(stderr, "%s: Unable to get size of %s: %s\n", - argv[0], argv[1], strerror(errno)); - close(ifd); - close(ofd); + prog_name, argv[if_index], strerror(errno)); exit(EXIT_FAILURE); } len = stat.st_size; - count = (len < CHECKSUM_OFFSET) ? len : CHECKSUM_OFFSET; - - if (read(ifd, buffer, count) != count) { - fprintf(stderr, "%s: Can't read %s: %s\n", - argv[0], argv[1], strerror(errno)); + if (var_size_flag) { + read_size = len; + count = len; + } else { + if (len > CHECKSUM_OFFSET) { + fprintf(stderr, + "%s: %s is too big (exceeds %d bytes)\n", + prog_name, argv[if_index], CHECKSUM_OFFSET); + exit(EXIT_FAILURE); + } + count = CHECKSUM_OFFSET; + read_size = len; + } - close(ifd); - close(ofd); + buffer = malloc(count); + if (!buffer) { + fprintf(stderr, + "%s: Failed to allocate %d bytes to store %s\n", + prog_name, count, argv[if_index]); + exit(EXIT_FAILURE); + } + if (read(ifd, buffer, read_size) != read_size) { + fprintf(stderr, "%s: Can't read %s: %s\n", + prog_name, argv[if_index], strerror(errno)); exit(EXIT_FAILURE); } - for (i = 0, checksum = 0; i < CHECKSUM_OFFSET; i++) - checksum += buffer[i]; + /* Pad if needed with 0xff to make flashing faster. */ + if (read_size < count) + memset((char *)buffer + read_size, 0xff, count - read_size); + for (i = 0, checksum = 0; i < count; i++) + checksum += buffer[i]; checksum = cpu_to_le32(checksum); - memcpy(&buffer[CHECKSUM_OFFSET], &checksum, sizeof(checksum)); - - if (write(ofd, buffer, BUFSIZE) != BUFSIZE) { - fprintf(stderr, "%s: Can't write %s: %s\n", - argv[0], argv[2], strerror(errno)); + if (var_size_flag) { + /* Prepare and write out the variable size SPL header. */ + struct var_size_header vsh; + uint32_t spl_size; - close(ifd); - close(ofd); + memset(&vsh, 0, sizeof(vsh)); + memcpy(&vsh.spl_checksum, &checksum, sizeof(checksum)); - exit(EXIT_FAILURE); + spl_size = cpu_to_le32(count + sizeof(struct var_size_header)); + memcpy(&vsh.spl_size, &spl_size, sizeof(spl_size)); + write_to_file(ofd, &vsh, sizeof(vsh)); } + write_to_file(ofd, buffer, count); + + /* For fixed size SPL checksum is appended in the end. */ + if (!var_size_flag) + write_to_file(ofd, &checksum, sizeof(checksum)); + close(ifd); close(ofd); + free(buffer); return EXIT_SUCCESS; }