From 62928dc964016ccdd512a486bc3c6e9289854c02 Mon Sep 17 00:00:00 2001 From: Ram Chandra Jangir Date: Thu, 1 Feb 2018 16:23:46 +0530 Subject: [PATCH] sysupgrade: Add SBL_NAND_PREAMBLE if preamble bytes exist in image Now we are adding preamble value to read SBL header if ubi section is present in the image. But in case of NOR+NAND images, though we are having SBL in NOR and ubi section is also present and NAND_PREAMBLE is getting added. which is breaking NOR+NAND sysupgrade. Added functionality to compare first 12 bytes of section with pre defined PREAMBLE value. If values matches, add the NAND_PREAMBLE to read SBL header. Change-Id: I704ee86cc50aa3ce3b2ab6ec34beab866ffde4b9 Signed-off-by: Anto Norbert --- tools/sysupgrade.c | 16 ++++++++++++++-- tools/sysupgrade.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/sysupgrade.c b/tools/sysupgrade.c index d0fd632790..fe206877fe 100644 --- a/tools/sysupgrade.c +++ b/tools/sysupgrade.c @@ -413,6 +413,18 @@ char *find_value(char *buffer, char *search, int size) return NULL; } +/** + * check_nand_preamble() compares first 12 bytes of section with + * pre defined PREAMBLE value and returns 0 if both value matches + */ +int check_nand_preamble(uint8_t *mfp) +{ + char magic[12] = { 0xd1, 0xdc, 0x4b, 0x84, + 0x34, 0x10, 0xd7, 0x73, + 0x5a, 0x43, 0x0b, 0x7d }; + return memcmp(magic, mfp, sizeof(magic)); +} + /** * get_sw_id_from_component_bin() parses the MBN header & checks image size v/s * code size. If both differ, it means signature & certificates are @@ -452,7 +464,7 @@ int get_sw_id_from_component_bin(struct image_section *section) mbn_hdr = (Mbn_Hdr *)fp; if (strstr(section->file, sections[4].type)) { - uint32_t preamble = sections[2].is_present ? SBL_NAND_PREAMBLE : 0; + uint32_t preamble = !check_nand_preamble(fp) ? SBL_NAND_PREAMBLE : 0; Sbl_Hdr *sbl_hdr = (Sbl_Hdr *)(fp + preamble); sig_cert_size = sbl_hdr->image_size - sbl_hdr->code_size; @@ -922,7 +934,7 @@ int split_code_signature_cert_from_component_bin(struct image_section *section, mbn_hdr = (Mbn_Hdr *)fp; if (strstr(section->file, sections[4].type)) { - uint32_t preamble = sections[2].is_present ? SBL_NAND_PREAMBLE : 0; + uint32_t preamble = !check_nand_preamble(fp) ? SBL_NAND_PREAMBLE : 0; sbl_hdr = (Sbl_Hdr *)(fp + preamble); src_offset = preamble; diff --git a/tools/sysupgrade.h b/tools/sysupgrade.h index 3c158d7879..2be276084b 100644 --- a/tools/sysupgrade.h +++ b/tools/sysupgrade.h @@ -126,3 +126,4 @@ int generate_hash(char *, char *, char *); int is_component_authenticated(char *, char *, char *); int is_image_authenticated(void); int do_board_upgrade_check(char *); +int check_nand_preamble(uint8_t *);