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 <norbrt@codeaurora.org>
This commit is contained in:
Ram Chandra Jangir 2018-02-01 16:23:46 +05:30
parent f40cda9a42
commit 62928dc964
2 changed files with 15 additions and 2 deletions

View file

@ -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;

View file

@ -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 *);