@@ -63,6 +63,10 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
6363
6464static struct boot_loader_state boot_data ;
6565
66+ #if defined(MCUBOOT_DATA_SHARING )
67+ static struct image_max_size image_max_sizes [BOOT_IMAGE_NUMBER ] = {0 };
68+ #endif
69+
6670#if (BOOT_IMAGE_NUMBER > 1 )
6771#define IMAGES_ITER (x ) for ((x) = 0; (x) < BOOT_IMAGE_NUMBER; ++(x))
6872#else
@@ -137,10 +141,6 @@ boot_add_shared_data(struct boot_loader_state *state,
137141#if defined(MCUBOOT_MEASURED_BOOT ) || defined(MCUBOOT_DATA_SHARING )
138142 int rc ;
139143
140- #ifdef MCUBOOT_DATA_SHARING
141- int max_app_size ;
142- #endif
143-
144144#ifdef MCUBOOT_MEASURED_BOOT
145145 rc = boot_save_boot_status (BOOT_CURR_IMG (state ),
146146 boot_img_hdr (state , active_slot ),
@@ -152,10 +152,9 @@ boot_add_shared_data(struct boot_loader_state *state,
152152#endif /* MCUBOOT_MEASURED_BOOT */
153153
154154#ifdef MCUBOOT_DATA_SHARING
155- max_app_size = app_max_size (state );
156155 rc = boot_save_shared_data (boot_img_hdr (state , active_slot ),
157156 BOOT_IMG_AREA (state , active_slot ),
158- active_slot , max_app_size );
157+ active_slot , image_max_sizes );
159158 if (rc != 0 ) {
160159 BOOT_LOG_ERR ("Failed to add data to shared memory area." );
161160 return rc ;
@@ -1841,6 +1840,10 @@ boot_prepare_image_for_update(struct boot_loader_state *state,
18411840 int rc ;
18421841 FIH_DECLARE (fih_rc , FIH_FAILURE );
18431842
1843+ #if defined(MCUBOOT_DATA_SHARING )
1844+ int max_size ;
1845+ #endif
1846+
18441847 /* Determine the sector layout of the image slots and scratch area. */
18451848 rc = boot_read_sectors (state );
18461849 if (rc != 0 ) {
@@ -1867,6 +1870,16 @@ boot_prepare_image_for_update(struct boot_loader_state *state,
18671870 return ;
18681871 }
18691872
1873+ #if defined(MCUBOOT_DATA_SHARING )
1874+ /* Fetch information on maximum sizes for later usage, if needed */
1875+ max_size = app_max_size (state );
1876+
1877+ if (max_size > 0 ) {
1878+ image_max_sizes [BOOT_CURR_IMG (state )].calculated = true;
1879+ image_max_sizes [BOOT_CURR_IMG (state )].max_size = max_size ;
1880+ }
1881+ #endif
1882+
18701883 /* If the current image's slots aren't compatible, no swap is possible.
18711884 * Just boot into primary slot.
18721885 */
@@ -3323,3 +3336,13 @@ void boot_state_clear(struct boot_loader_state *state)
33233336 memset (& boot_data , 0 , sizeof (struct boot_loader_state ));
33243337 }
33253338}
3339+
3340+ #if defined(MCUBOOT_DATA_SHARING )
3341+ /**
3342+ * Fetches the maximum allowed size of the image
3343+ */
3344+ const struct image_max_size * boot_get_max_app_size (void )
3345+ {
3346+ return image_max_sizes ;
3347+ }
3348+ #endif
0 commit comments