tools: add script: mkimage_signed.sh for sign u-boot binary
authorPrzemyslaw Marczak <p.marczak@samsung.com>
Thu, 10 Apr 2014 13:03:40 +0000 (15:03 +0200)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 21 Jan 2019 07:07:58 +0000 (16:07 +0900)
This script appends given binary image by signature header.
Script takes two arguments:
- @arg1: binary name
- @arg2: config name

Script usage:
./mkimage_signed.sh binary.img config_name
e.g.:
./mkimage_signed.sh u-boot-dtb.bin trats2_config

Sign header is stored on last 512 bytes of input binary.
Maximum imput binary size is 1MB - 512 Bytes = 1048064 Bytes.

The maximum size is limited by first bootloader (s-boot).
Now it is configured to load exactly 2048 blocks (1MB).
Current u-boot-dtb.bin size for trats2 is less than 600 KBytes,
so the size limit should not be an issue.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
tool:mkimage_signed: add tizen_defconfig support

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
tool: mkimage_signed: Add odroid-xu3_defconfig support

This patch add odroid-xu3_defconfig for Odroid XU3 board.

Signed-off-by: Inha Song <ideal.song@samsung.com>
[jh80.chung: Cherry-pick from u-boot of tizen tree to use mkimage_singed.sh]
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Change-Id: I7463fc47dd85c08a508ec76ead60bc4479b805b3

tools/mkimage_signed.sh [new file with mode: 0755]

diff --git a/tools/mkimage_signed.sh b/tools/mkimage_signed.sh
new file mode 100755 (executable)
index 0000000..74e9b90
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/bash
+
+# U-BOOT binary signature tool
+#
+# Copyright (C) 2014 Samsung Electronics
+# Przemyslaw Marczak <p.marczak@samsung.com>
+
+
+# Sign header:
+#{
+# uint32_t magic;      /* image magic number */
+# uint32_t size;       /* image data size */
+# uint32_t valid;      /* valid flag */
+# char date[12];       /* image creation timestamp - YYMMDDHH */
+# char version[24];    /* image version */
+# char bd_name[16];    /* target board name */
+# char reserved[448];  /* reserved */
+#}
+
+INPUT_ARGS=2
+INPUT_BIN=${1}
+CONFIG=${2}
+
+OUTPUT_BIN="u-boot-mmc.bin"
+OUTPUT_SIZE=$((1024*1024))
+
+SIGN_HDR_SIZE=512
+INPUT_SIZE_LIMIT=$((${OUTPUT_SIZE} - ${SIGN_HDR_SIZE}))
+
+# Check arguments count
+if [ $# != $INPUT_ARGS ]; then
+       echo Bad arguments number!
+       echo "Usage:"
+       echo "./mksigimage.sh input.bin config"
+       echo "e.g.:"
+       echo "./mksigimage.sh u-boot-multi.bin tizen_config"
+       exit
+fi
+
+echo "#####################################"
+echo "Running script: $0"
+echo "Config: $CONFIG"
+echo "Input binary: $INPUT_BIN"
+
+# Check if given binary exists
+if [ -s $INPUT_BIN ]; then
+       # Check given binary size
+       INPUT_SIZE=`du -b $INPUT_BIN | awk '{print $1}'`
+
+       if [ ${INPUT_SIZE} -gt ${INPUT_SIZE_LIMIT} ]; then
+               echo "Input binary size exceeds size limit!"
+               echo "Max input size: ${INPUT_SIZE_LIMIT}"
+               exit
+       else
+               echo "Input bytes: $INPUT_SIZE (Max size: ${INPUT_SIZE_LIMIT} B)"
+       fi
+else
+       echo "File: $INPUT_BIN not exists!"
+       exit
+fi
+
+echo -n "BoOt" > sig-magic
+echo -n `date +%Y%m%d%H` > sig-date
+echo -n "none" > sig-product
+
+if [ $CONFIG == "tizen_defconfig" ]; then
+       echo -n "slp_midasq" > sig-board
+elif [ $CONFIG == "odroid-xu3_defconfig" ]; then
+       echo -n "odroid_xu3" > sig-board
+else
+       echo -n "slp_u1" > sig-board
+fi
+
+cat sig-magic /dev/zero | head -c 12 > sig-tmp
+cat sig-tmp sig-date /dev/zero | head -c 24 > sig-tmp2
+cat sig-tmp2 sig-product /dev/zero | head -c 48 > sig-tmp
+cat sig-tmp sig-board /dev/zero | head -c 512 > sig-hdr
+cat $INPUT_BIN /dev/zero | head -c 1048064 > u-boot-pad.bin
+cat u-boot-pad.bin sig-hdr > $OUTPUT_BIN
+
+echo
+echo "Header info:"
+echo "HDR length:   $SIGN_HDR_SIZE Bytes"
+echo "SIG magic:   \"`cat sig-magic`\""
+echo "SIG size:     0"
+echo "SIG valid:    0"
+echo "SIG date:    \"`cat sig-date`\" (YYMMDDHH)"
+echo "SIG version: \"none\""
+echo "SIG board:   \"`cat sig-board`\""
+
+rm -f sig-* u-boot-pad.bin
+
+echo 
+echo "Output signed binary: ${OUTPUT_BIN}"
+echo "#####################################"
+