From patchwork Wed Sep 11 10:01:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 19950 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f69.google.com (mail-qe0-f69.google.com [209.85.128.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3416625E76 for ; Wed, 11 Sep 2013 10:00:04 +0000 (UTC) Received: by mail-qe0-f69.google.com with SMTP id 1sf7303661qec.8 for ; Wed, 11 Sep 2013 03:00:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state: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=CRWS/aEQcs+d8j2I2OXiJeqyFjQsMBEx28hMVhMpTjE=; b=XrXFcRc6QfCQ6NJJw408QQ33jBqymgiVhKA6Y5MzPoeXX4Hap5MTal0pRWrhG2I8f6 BdjdnyoJ36w/7uB8ULgj1HRxkZ2P9C5zbhtbN86gz3ACBdSaA3FhoGjhctPyq8BKrTOf cW/o5HCXoSbyoH2EgqTKlQKVmHIpgJFaTFaFy6f8THOqcpA1oDdOh8K70/L8fuhQaakR 0dyqkegu54TkPwcMoHtNdEpcCg/PsqR50Oa1A75ofKVqBsavlsw++ZpkVfJzkXvZLeE/ 67xFVnWSPdEqJsgCIZXv6SnjNndBtDsjy8SjkIncpyw0qmBc3hV6690QLF5rvDwLejqI 84IQ== X-Received: by 10.236.176.1 with SMTP id a1mr329105yhm.10.1378893604021; Wed, 11 Sep 2013 03:00:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.58.148 with SMTP id r20ls173361qeq.3.gmail; Wed, 11 Sep 2013 03:00:03 -0700 (PDT) X-Received: by 10.58.137.167 with SMTP id qj7mr440689veb.1.1378893603781; Wed, 11 Sep 2013 03:00:03 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id dh7si5771379vcb.38.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 03:00:03 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id jy13so5370413veb.19 for ; Wed, 11 Sep 2013 03:00:03 -0700 (PDT) X-Gm-Message-State: ALoCoQlU2cUJp/wYv01WXYLGRNkL07QmjOHLyQkBjFjJC7ZiFhPt3d0mSOJYW7HLEmE7bIsWTNx+ X-Received: by 10.52.119.228 with SMTP id kx4mr396935vdb.12.1378893603663; Wed, 11 Sep 2013 03:00:03 -0700 (PDT) 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 u4csp47072vcz; Wed, 11 Sep 2013 03:00:03 -0700 (PDT) X-Received: by 10.66.191.137 with SMTP id gy9mr2584150pac.147.1378893602468; Wed, 11 Sep 2013 03:00:02 -0700 (PDT) Received: from mailout4.samsung.com (mailout4.samsung.com. [203.254.224.34]) by mx.google.com with ESMTP id es1si4454506pbc.266.1969.12.31.16.00.00; Wed, 11 Sep 2013 03:00:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.34 as permitted sender) client-ip=203.254.224.34; Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MSY00MNVH3GV0R0@mailout4.samsung.com>; Wed, 11 Sep 2013 18:59:58 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.124]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 31.9A.29948.E1F30325; Wed, 11 Sep 2013 18:59:58 +0900 (KST) X-AuditID: cbfee691-b7f4a6d0000074fc-c0-52303f1e949e Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 77.B5.09055.E1F30325; Wed, 11 Sep 2013 18:59:58 +0900 (KST) Received: from localhost.localdomain.com ([107.108.73.95]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MSY0040PH3CE280@mmp2.samsung.com>; Wed, 11 Sep 2013 18:59:58 +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, panto@antoniou-consulting.com, alim.akhtar@samsung.com Subject: [PATCH 11/12 V3] SPL: EXYNOS: Prepare for variable size SPL support Date: Wed, 11 Sep 2013 15:31:23 +0530 Message-id: <1378893684-27733-12-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.11.7 In-reply-to: <1378893684-27733-1-git-send-email-rajeshwari.s@samsung.com> References: <1378893684-27733-1-git-send-email-rajeshwari.s@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPLMWRmVeSWpSXmKPExsWyRsSkRlfO3iDIoGOyksWDedvYLB6uv8li 0XGkhdFi1+3JLBZTDn9hsfi2ZRujxfLXG9kt3u7tZHfg8Jj3cyKTx+yGiyweCzaVety5tofN 4+ydHYwefVtWMQawRXHZpKTmZJalFunbJXBl/JxxlKlgu0fFgUNnWRoYL1p2MXJySAiYSLy7 d54NwhaTuHBvPZDNxSEksJRR4sOeu2wwRb3T37JCJKYzSqxddIYdwuliktg1ax1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BDkYlHt4bcvpBQqyJZcWVuYcYJTiYlUR4H5gaBAnx piRWVqUW5ccXleakFh9iTAa6aiKzlGhyPjDm80riDY1NzE2NTS1NLEzMLEkTVhLnPdBqHSgk kJ5YkpqdmlqQWgSzhYmDU6qB0fSkruV0i3t6AvpfYrNOLHwSnqt7znnxU4et+4v1nvybekVn o8uqQMaDaybpvpnGftNEqiZ14uyoNZzSvn9NPlmyzWV8F+/3Nd/68IFdAio9Si+OHlLO/J+s bDM7U1l6SomIxZmohqwSnodbjB4+NjYXf7TiY41k50KR6st3FNMFksO8uO+0KLEUZyQaajEX FScCANvFcXrvAgAA 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.128.174 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 V3: - New patch. include/configs/smdk5420.h | 5 ++ spl/Makefile | 7 +- tools/mkexynosspl.c | 166 +++++++++++++++++++++++++++++++++------------ 3 files changed, 134 insertions(+), 44 deletions(-) diff --git a/include/configs/smdk5420.h b/include/configs/smdk5420.h index 0db9c77..5d72824 100644 --- a/include/configs/smdk5420.h +++ b/include/configs/smdk5420.h @@ -38,6 +38,7 @@ #define CONFIG_DISPLAY_CPUINFO #define CONFIG_DISPLAY_BOARDINFO #define CONFIG_BOARD_COMMON +#define CONFIG_VAR_SIZE_SPL /* Enable fdt support for Exynos5420 */ @@ -148,7 +149,11 @@ /* specific .lds file */ #define CONFIG_SPL_LDSCRIPT "board/samsung/common/exynos-uboot-spl.lds" +#ifdef CONFIG_VAR_SIZE_SPL +#define CONFIG_SPL_TEXT_BASE 0x02024410 +#else #define CONFIG_SPL_TEXT_BASE 0x02024400 +#endif #define CONFIG_SPL_MAX_SIZE (14 * 1024) #define CONFIG_SPL_MAX_FOOTPRINT (32 * 1024) diff --git a/spl/Makefile b/spl/Makefile index 28ebc96..56a4ebe 100644 --- a/spl/Makefile +++ b/spl/Makefile @@ -166,8 +166,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..63ab3c6 100644 --- a/tools/mkexynosspl.c +++ b/tools/mkexynosspl.c @@ -14,93 +14,173 @@ #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 = 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; }