board:samsung: add sign to u-boot-mmc.bin and sign check to thor
authorInha Song <ideal.song@samsung.com>
Mon, 28 Oct 2013 06:52:53 +0000 (15:52 +0900)
committerLukasz Majewski <l.majewski@samsung.com>
Mon, 31 Mar 2014 08:19:58 +0000 (10:19 +0200)
Changes:
- Makefile: append u-boot-mmc.bin image by signature header
- add call to check_board_signature() before do dfu_write in thor downlaoder

new files:
- board/samsung/common/sig_header.c
- include/samsung/sighdr.h

Signed-off-by: Inha Song <ideal.song@samsung.com>
Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Makefile
board/samsung/common/Makefile
board/samsung/common/sig_header.c [new file with mode: 0644]
drivers/usb/gadget/f_thor.c
include/samsung/sighdr.h [new file with mode: 0644]

index e5f5a8c..545eecf 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -709,6 +709,7 @@ ifneq ($(CONFIG_SPL_TARGET),)
 ALL-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
 endif
 ALL-$(CONFIG_REMAKE_ELF) += u-boot.elf
+ALL-$(CONFIG_SIG) += u-boot-sig.bin
 
 # enable combined SPL/u-boot/dtb rules for tegra
 ifneq ($(CONFIG_TEGRA),)
@@ -1068,6 +1069,24 @@ nand_spl: prepare
        @echo >&2 "=================================================="
        @echo >&2
 
+u-boot-sig.bin:        u-boot.bin
+               @echo -n "BoOt" > sig-magic
+               @echo -n `date +%Y%m%d%H` > sig-date
+               @echo -n "none" > sig-product
+ifeq ($(BOARD),trats)
+               @echo -n "slp_u1" > sig-board
+else
+               @echo -n "slp_midasq" > sig-board
+endif
+               @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 u-boot.bin /dev/zero | head -c 1048064 > u-boot-pad.bin
+               @cat u-boot-pad.bin sig-hdr > u-boot-mmc.bin
+
+               @rm -f sig-* u-boot-pad.bin
+
 nand_spl/u-boot-spl-16k.bin: nand_spl
        @:
 
index 7d2bb8c..f4aa9d8 100644 (file)
@@ -9,6 +9,7 @@ obj-$(CONFIG_SOFT_I2C_MULTI_BUS) += multi_i2c.o
 obj-$(CONFIG_THOR_FUNCTION) += thor.o
 obj-$(CONFIG_CMD_USB_MASS_STORAGE) += ums.o
 obj-$(CONFIG_MISC_COMMON) += misc.o
+obj-$(CONFIG_SIG) += sig_header.o
 
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_BOARD_COMMON)     += board.o
diff --git a/board/samsung/common/sig_header.c b/board/samsung/common/sig_header.c
new file mode 100644 (file)
index 0000000..47a5e1d
--- /dev/null
@@ -0,0 +1,47 @@
+#include <common.h>
+#include <samsung/sighdr.h>
+
+static struct sig_header *
+get_image_signature(phys_addr_t base_addr, phys_size_t size)
+{
+       struct sig_header *hdr;
+
+       hdr = (struct sig_header *)(base_addr + size - HDR_SIZE);
+       if (hdr->magic != HDR_BOOT_MAGIC) {
+               debug("can't found signature\n");
+               return NULL;
+       }
+
+       return hdr;
+}
+
+int check_board_signature(char *fname, phys_addr_t dn_addr, phys_size_t size)
+{
+       struct sig_header *bh_target;
+       struct sig_header *bh_addr;
+
+       /* u-boot-mmc.bin */
+       if (strcmp(fname, "u-boot-mmc.bin"))
+               return 0;
+
+       /* can't found signature in target - download continue */
+       bh_target = get_image_signature((phys_addr_t)CONFIG_SYS_TEXT_BASE,
+                                       size);
+       if (!bh_target)
+               return 0;
+
+       /* can't found signature in address - download stop */
+       bh_addr = get_image_signature(dn_addr, size);
+       if (!bh_addr)
+               return -1;
+
+       if (strncmp(bh_target->bd_name, bh_addr->bd_name,
+                   ARRAY_SIZE(bh_target->bd_name))) {
+               debug("board name Inconsistency\n");
+               return -1;
+       }
+
+       debug("board signature check OK\n");
+
+       return 0;
+}
index 02a670d..514113b 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/usb/cdc.h>
 #include <g_dnl.h>
 #include <dfu.h>
+#include <samsung/sighdr.h>
 #include <libtizen.h>
 #include <samsung/misc.h>
 #include <usb.h>
@@ -217,6 +218,16 @@ static int download_tail(long long int left, int cnt)
 
        debug("%s: left: %llu cnt: %d\n", __func__, left, cnt);
 
+#ifdef CONFIG_SIG
+       /* check board signature when download u-boot-mmc.bin */
+       ret = check_board_signature(f_name, (phys_addr_t)transfer_buffer,
+                                   (phys_size_t)thor_file_size);
+       if (ret) {
+               printf("Wrong board signature in file: %s.\n", f_name);
+               return ret;
+       }
+#endif
+
        if (left) {
                ret = dfu_write(dfu_get_entity(alt_setting_num),
                                transfer_buffer, left, cnt++);
diff --git a/include/samsung/sighdr.h b/include/samsung/sighdr.h
new file mode 100644 (file)
index 0000000..571e010
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef __HEADER_H__
+#define __HEADER_H__
+
+#define HDR_BOOT_MAGIC         0x744f6f42      /* BoOt */
+
+#define HDR_SIZE               sizeof(struct sig_header)
+
+/* HDR_SIZE - 512 */
+struct sig_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 */
+};
+
+int check_board_signature(char *fname, phys_addr_t dn_addr, phys_size_t size);
+#endif