Skip to content

Commit aa56986

Browse files
committed
Add check for clearing the multiboot register based
on the version of the image Starting from version 1.03, the latest BootFw image clears the multiboot register directly in U-Boot. Consequently, clearing multiboot in the image update utility is no longer needed Signed-off-by: Dasari Sharath Kumar <[email protected]>
1 parent 068a27f commit aa56986

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

image_update.c

+65-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
* Copyright (c) 2021 - 2022 Xilinx, Inc. All rights reserved.
3-
* Copyright (c) 2022 - 2024, Advanced Micro Devices, Inc. All Rights Reserved.
3+
* Copyright (c) 2022 - 2025, Advanced Micro Devices, Inc. All Rights Reserved.
44
* SPDX-License-Identifier: MIT
55
*
66
* Vikram Sreenivasa Batchali <[email protected]>
@@ -27,7 +27,11 @@
2727
#define XBIU_IDEN_STR_LEN (0x4U)
2828
#define XBIU_QSPI_MFG_INFO_SIZE (0x100U)
2929
#define XBIU_IMG_REVISON_OFFSET (0x70U)
30+
#define XBIU_IMG_VERSION_OFFSET (0x9U)
3031
#define XBIU_IMG_REVISON_SIZE (0x24U)
32+
#define XBIU_IMG_VERSION_SIZE (0x4U)
33+
#define XBIU_IMG_VERSION_CHECK (1.03F)
34+
3135

3236
/* The below enums denote persistent registers in Qspi Flash */
3337
struct sys_persistent_state {
@@ -72,10 +76,12 @@ static int print_qspi_mfg_info(void);
7276
static void print_usage(void);
7377
static int print_image_rev_info(char *qspi_mtd_file, char *image_name);
7478
static int clear_multiboot_val(void);
79+
static int extract_image_version(char *qspi_mtd_file);
7580

7681
/* Variable definitions */
7782
static char *srcaddr = NULL;
7883
static unsigned int image_size;
84+
static float img_ver;
7985
static struct sys_boot_img_info boot_img_info __attribute__ ((aligned(4U)));
8086

8187
static const unsigned int crc_table[] = {
@@ -167,6 +173,7 @@ int main(int argc, char *argv[])
167173
{
168174
int ret = XST_FAILURE;
169175
char qspi_mtd_file[20U] = {0U};
176+
char last_boot_img[20U] = {0U};
170177
char image_file_name[100U] = {0U};
171178
char image_name[8] = {0U};
172179
int opt;
@@ -271,11 +278,13 @@ int main(int argc, char *argv[])
271278
strcpy(image_name, "ImageB");
272279
boot_img_info.persistent_state.img_b_bootable = 0U;
273280
strcpy(qspi_mtd_file, "/dev/mtd7");
281+
strcpy(last_boot_img, "/dev/mtd5");
274282
} else {
275283
printf("Updating BootFW image to ImageA bank\n");
276284
strcpy(image_name, "ImageA");
277285
boot_img_info.persistent_state.img_a_bootable = 0U;
278286
strcpy(qspi_mtd_file, "/dev/mtd5");
287+
strcpy(last_boot_img, "/dev/mtd7");
279288
}
280289

281290
printf("Marking target image as non bootable\n");
@@ -302,11 +311,17 @@ int main(int argc, char *argv[])
302311
if (ret < 0)
303312
goto END;
304313

305-
printf("Clearing multiboot register value\n");
306-
ret = clear_multiboot_val();
314+
ret = extract_image_version(last_boot_img);
307315
if (ret != XST_SUCCESS)
308316
goto END;
309317

318+
if(img_ver < XBIU_IMG_VERSION_CHECK){
319+
printf("Clearing multiboot register value\n");
320+
ret = clear_multiboot_val();
321+
if (ret != XST_SUCCESS)
322+
goto END;
323+
}
324+
310325
printf("%s successfully updated to %s bank\n", image_file_name, image_name);
311326
printf("Reboot the system to boot the updated BootFW image\n");
312327
printf("Mark the BootFW image as bootable using -v option ");
@@ -834,6 +849,53 @@ static int print_image_rev_info(char *qspi_mtd_file, char *image_name)
834849
return ret;
835850
}
836851

852+
/*****************************************************************************/
853+
/**
854+
* @brief
855+
* This function extracts the version information from
856+
* the MTD partition of the provided image
857+
*
858+
* @param qspi_mtd_file denotes the mtd partition to be read
859+
*
860+
* @return XST_SUCCESS on SUCCESS and error code on failure
861+
*
862+
*****************************************************************************/
863+
static int extract_image_version(char *qspi_mtd_file)
864+
{
865+
int fd, ret = XST_FAILURE;
866+
char ver_str[XBIU_IMG_REVISON_SIZE + 1U] = {0};
867+
868+
fd = open(qspi_mtd_file, O_RDONLY);
869+
if (fd < 0) {
870+
printf("Open Qspi MTD partition failed\n");
871+
return ret;
872+
}
873+
874+
ret = lseek(fd, XBIU_IMG_REVISON_OFFSET + XBIU_IMG_VERSION_OFFSET, SEEK_SET);
875+
if (ret != XBIU_IMG_REVISON_OFFSET + XBIU_IMG_VERSION_OFFSET) {
876+
printf("Seek Qspi MTD partition failed\n");
877+
goto END;
878+
}
879+
880+
ret = read(fd, ver_str, XBIU_IMG_VERSION_SIZE);
881+
if (ret != XBIU_IMG_VERSION_SIZE) {
882+
printf("Read Qspi MTD partition failed\n");
883+
ret = XST_FAILURE;
884+
goto END;
885+
}
886+
887+
if (ver_str[0U] == 0) {
888+
strncpy(ver_str, "Not defined", XBIU_IMG_VERSION_SIZE);
889+
}
890+
891+
img_ver = atof(ver_str);
892+
ret = XST_SUCCESS;
893+
894+
END:
895+
close(fd);
896+
return ret;
897+
}
898+
837899
/*****************************************************************************/
838900
/**
839901
* @brief

0 commit comments

Comments
 (0)