From: Inha Song Date: Mon, 28 Oct 2013 06:52:53 +0000 (+0900) Subject: board:samsung: add sign to u-boot-mmc.bin and sign check to thor X-Git-Tag: accepted/tizen/generic/20140310.101015~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e65fa3956050265fecbe55a11aa5a2b7fdfb3239;p=kernel%2Fu-boot.git board:samsung: add sign to u-boot-mmc.bin and sign check to thor 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 Signed-off-by: Przemyslaw Marczak --- diff --git a/Makefile b/Makefile index ecac292..34a3180 100644 --- a/Makefile +++ b/Makefile @@ -716,6 +716,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),) @@ -1075,6 +1076,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 @: diff --git a/board/samsung/common/Makefile b/board/samsung/common/Makefile index 52ccc84..a62cd85 100644 --- a/board/samsung/common/Makefile +++ b/board/samsung/common/Makefile @@ -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 index 0000000..47a5e1d --- /dev/null +++ b/board/samsung/common/sig_header.c @@ -0,0 +1,47 @@ +#include +#include + +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; +} diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index 7845118..a97c567 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -221,6 +222,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 index 0000000..571e010 --- /dev/null +++ b/include/samsung/sighdr.h @@ -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