1
1
/******************************************************************************
2
2
* 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.
4
4
* SPDX-License-Identifier: MIT
5
5
*
6
6
* Vikram Sreenivasa Batchali <[email protected] >
27
27
#define XBIU_IDEN_STR_LEN (0x4U)
28
28
#define XBIU_QSPI_MFG_INFO_SIZE (0x100U)
29
29
#define XBIU_IMG_REVISON_OFFSET (0x70U)
30
+ #define XBIU_IMG_VERSION_OFFSET (0x9U)
30
31
#define XBIU_IMG_REVISON_SIZE (0x24U)
32
+ #define XBIU_IMG_VERSION_SIZE (0x4U)
33
+ #define XBIU_IMG_VERSION_CHECK (1.03F)
34
+
31
35
32
36
/* The below enums denote persistent registers in Qspi Flash */
33
37
struct sys_persistent_state {
@@ -72,10 +76,12 @@ static int print_qspi_mfg_info(void);
72
76
static void print_usage (void );
73
77
static int print_image_rev_info (char * qspi_mtd_file , char * image_name );
74
78
static int clear_multiboot_val (void );
79
+ static int extract_image_version (char * qspi_mtd_file );
75
80
76
81
/* Variable definitions */
77
82
static char * srcaddr = NULL ;
78
83
static unsigned int image_size ;
84
+ static float img_ver ;
79
85
static struct sys_boot_img_info boot_img_info __attribute__ ((aligned (4U )));
80
86
81
87
static const unsigned int crc_table [] = {
@@ -167,6 +173,7 @@ int main(int argc, char *argv[])
167
173
{
168
174
int ret = XST_FAILURE ;
169
175
char qspi_mtd_file [20U ] = {0U };
176
+ char last_boot_img [20U ] = {0U };
170
177
char image_file_name [100U ] = {0U };
171
178
char image_name [8 ] = {0U };
172
179
int opt ;
@@ -271,11 +278,13 @@ int main(int argc, char *argv[])
271
278
strcpy (image_name , "ImageB" );
272
279
boot_img_info .persistent_state .img_b_bootable = 0U ;
273
280
strcpy (qspi_mtd_file , "/dev/mtd7" );
281
+ strcpy (last_boot_img , "/dev/mtd5" );
274
282
} else {
275
283
printf ("Updating BootFW image to ImageA bank\n" );
276
284
strcpy (image_name , "ImageA" );
277
285
boot_img_info .persistent_state .img_a_bootable = 0U ;
278
286
strcpy (qspi_mtd_file , "/dev/mtd5" );
287
+ strcpy (last_boot_img , "/dev/mtd7" );
279
288
}
280
289
281
290
printf ("Marking target image as non bootable\n" );
@@ -302,11 +311,17 @@ int main(int argc, char *argv[])
302
311
if (ret < 0 )
303
312
goto END ;
304
313
305
- printf ("Clearing multiboot register value\n" );
306
- ret = clear_multiboot_val ();
314
+ ret = extract_image_version (last_boot_img );
307
315
if (ret != XST_SUCCESS )
308
316
goto END ;
309
317
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
+
310
325
printf ("%s successfully updated to %s bank\n" , image_file_name , image_name );
311
326
printf ("Reboot the system to boot the updated BootFW image\n" );
312
327
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)
834
849
return ret ;
835
850
}
836
851
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
+
837
899
/*****************************************************************************/
838
900
/**
839
901
* @brief
0 commit comments