From 49911bbfa9310ddc71e3c9b771fe6b75bf1f210c Mon Sep 17 00:00:00 2001 From: Heesub Shin Date: Mon, 13 Mar 2017 09:52:50 +0900 Subject: [PATCH] build: s5j: introduce a new kconfig, CONFIG_SAMSUNG_NS2 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 --- os/Kconfig | 9 +++++++++ os/Makefile.unix | 4 ++++ os/Makefile.win | 4 ++++ os/tools/s5jchksum.py | 26 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100755 os/tools/s5jchksum.py diff --git a/os/Kconfig b/os/Kconfig index 7c08ef6..ff82b19 100644 --- a/os/Kconfig +++ b/os/Kconfig @@ -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 diff --git a/os/Makefile.unix b/os/Makefile.unix index a0a2f50..3bb0d94 100644 --- a/os/Makefile.unix +++ b/os/Makefile.unix @@ -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) \ diff --git a/os/Makefile.win b/os/Makefile.win index 35d34d6..dbccda0 100644 --- a/os/Makefile.win +++ b/os/Makefile.win @@ -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 index 0000000..4f8207a --- /dev/null +++ b/os/tools/s5jchksum.py @@ -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) -- 2.7.4