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 vben...@chromium.org
Signed-off-by: Rajeshwari S Shinde rajeshwar...@samsung.com
---
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_LDSCRIPTboard/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 compiler.h
#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