build: s5j: introduce a new kconfig, CONFIG_SAMSUNG_NS2
authorHeesub Shin <heesub.shin@samsung.com>
Mon, 13 Mar 2017 00:52:50 +0000 (09:52 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Mon, 17 Apr 2017 10:08:14 +0000 (19:08 +0900)
Bootloader of S5J platform requires the raw binary to have SHA256
checksum and some magic numbers at the first 32bytes of the binary.
Second stage boot loaders checks it to verify the integrity.

This commit introduces a new Kconfig entry, CONFIG_SAMSUNG_NS2, and a
small python script for putting SHA256 checksum into the header.

Change-Id: I95b24d97094b2c9c87ee1b30a6fb7883fed9fc64
Signed-off-by: Heesub Shin <heesub.shin@samsung.com>
os/Kconfig
os/Makefile.unix
os/Makefile.win
os/tools/s5jchksum.py [new file with mode: 0755]

index 7c08ef6..ff82b19 100644 (file)
@@ -270,6 +270,15 @@ config RAW_BINARY
                different loaders using the GNU objcopy program.  This option
                should not be selected if you are not using the GNU toolchain.
 
+config SAMSUNG_NS2
+       bool "Samsung NS2 binary format"
+       select RAW_BINARY
+       default n
+       ---help---
+               Create the tinyara.head.bin from the raw binary, putting
+               a checksum value into it. It is used with S5J boot loaders,
+               which check the integrity of the binary using SHA256 at boot.
+
 menuconfig UBOOT_UIMAGE
        bool "U-Boot uImage"
        select RAW_BINARY
index a0a2f50..3bb0d94 100644 (file)
@@ -493,6 +493,10 @@ ifeq ($(CONFIG_RAW_BINARY),y)
        @echo "CP: $(BIN_EXE).bin"
        $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
 endif
+ifeq ($(CONFIG_SAMSUNG_NS2),y)
+       @echo "ATTACHNS2: $(BIN).bin --> $(BIN).head.bin"
+       $(Q) tools/s5jchksum.py $(BIN).bin $(BIN).head.bin
+endif
 ifeq ($(CONFIG_UBOOT_UIMAGE),y)
        @echo "MKIMAGE: uImage"
        $(Q) mkimage -A arm -O linux -C none -T kernel -a $(CONFIG_UIMAGE_LOAD_ADDRESS) \
index 35d34d6..dbccda0 100644 (file)
@@ -466,6 +466,10 @@ ifeq ($(CONFIG_RAW_BINARY),y)
        @echo "CP: $(BIN_EXE).bin"
        $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
 endif
+ifeq ($(CONFIG_SAMSUNG_NS2),y)
+       @echo "ATTACHNS2: $(BIN) --> $(BIN).head.bin"
+       $(Q) tools/s5jchksum.py $(BIN).bin $(BIN).head.bin
+endif
 
 # $(BIN)
 #
diff --git a/os/tools/s5jchksum.py b/os/tools/s5jchksum.py
new file mode 100755 (executable)
index 0000000..4f8207a
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+
+import os
+import sys
+import hashlib
+
+inputfile  = sys.argv[1]
+outputfile = sys.argv[2]
+
+header = 32
+tail   = 272
+
+with open(inputfile, 'rb') as fin, open(outputfile, 'wb') as fout:
+    data = fin.read()
+    fout.write(data)
+
+    size = fin.tell()
+    fin.seek(header, 0)
+    size -= (header + tail)
+
+    data = fin.read(size)
+    h = hashlib.sha256(data);
+    digest = h.digest()[:4]
+
+    fout.seek(4, 0)
+    fout.write(digest)