@@ -363,23 +363,66 @@ if(CONFIG_MCUBOOT_BOOT_BANNER)
363
363
zephyr_sources (kernel/banner.c )
364
364
endif ()
365
365
366
- if (SYSBUILD )
367
- function (align_up num align result )
368
- math (EXPR out "(((${num} ) + ((${align} ) - 1)) & ~((${align} ) - 1))" )
369
- set (${result} "${out} " PARENT_SCOPE )
370
- endfunction ()
366
+ function (align_up num align result )
367
+ math (EXPR out "(((${num} ) + ((${align} ) - 1)) & ~((${align} ) - 1))" )
368
+ set (${result} "${out} " PARENT_SCOPE )
369
+ endfunction ()
370
+
371
+ function (dt_get_parent node )
372
+ string (FIND "${${node} }" "/" pos REVERSE )
373
+
374
+ if (pos EQUAL -1 )
375
+ message (ERROR "Unable to get parent of node: ${${node} }" )
376
+ endif ()
371
377
372
- function (dt_get_parent node )
373
- string (FIND "${${node} }" "/" pos REVERSE )
378
+ string (SUBSTRING "${${node} }" 0 ${pos} ${node} )
379
+ set (${node} "${${node} }" PARENT_SCOPE )
380
+ endfunction ()
381
+
382
+ if (CONFIG_BOOT_MAX_IMG_SECTORS_AUTO )
383
+ dt_nodelabel (slot0_flash NODELABEL "slot0_partition" )
384
+ dt_prop (slot0_size PATH "${slot0_flash} " PROPERTY "reg" INDEX 1 )
385
+ dt_get_parent (slot0_flash )
386
+ dt_get_parent (slot0_flash )
387
+ dt_prop (erase_size_slot0 PATH "${slot0_flash} " PROPERTY "erase-block-size" )
388
+
389
+ if (NOT DEFINED slot0_size )
390
+ message (WARNING "Unable to determine size of slot0 partition, cannot calculate minimum sector usage" )
391
+ elseif (NOT DEFINED erase_size_slot0 )
392
+ message (WARNING "Unable to determine erase size of slot0 partition, cannot calculate minimum sector usage" )
393
+ else ()
394
+ math (EXPR slot_min_sectors "${slot0_size} / ${erase_size_slot0} " )
395
+ endif ()
396
+
397
+ if (NOT CONFIG_SINGLE_APPLICATION_SLOT )
398
+ dt_nodelabel (slot1_flash NODELABEL "slot1_partition" )
399
+ dt_prop (slot1_size PATH "${slot1_flash} " PROPERTY "reg" INDEX 1 )
400
+ dt_get_parent (slot1_flash )
401
+ dt_get_parent (slot1_flash )
402
+ dt_prop (erase_size_slot1 PATH "${slot1_flash} " PROPERTY "erase-block-size" )
403
+
404
+ if (NOT DEFINED slot1_size )
405
+ message (WARNING "Unable to determine size of slot1 partition, cannot calculate minimum sector usage" )
406
+ elseif (NOT DEFINED erase_size_slot1 )
407
+ message (WARNING "Unable to determine erase size of slot1 partition, cannot calculate minimum sector usage" )
408
+ else ()
409
+ math (EXPR slot1_min_sectors "${slot1_size} / ${erase_size_slot1} " )
374
410
375
- if (pos EQUAL -1 )
376
- message (ERROR "Unable to get parent of node: ${${node} }" )
411
+ if ("${slot1_min_sectors} " GREATER "${slot_min_sectors} " )
412
+ set (slot_min_sectors ${slot1_min_sectors} )
413
+ endif ()
377
414
endif ()
415
+ endif ()
378
416
379
- string (SUBSTRING "${${node} }" 0 ${pos} ${node} )
380
- set (${node} "${${node} }" PARENT_SCOPE )
381
- endfunction ()
417
+ if (DEFINED slot_min_sectors AND "${slot_min_sectors} " GREATER "0" )
418
+ zephyr_compile_definitions ("MIN_SECTOR_COUNT=${slot_min_sectors} " )
419
+ message ("Calculated maximum number of sectors: ${slot_min_sectors} " )
420
+ else ()
421
+ message (WARNING "Unable to calculate minimum number of sector sizes, falling back to 128 sector default. Please disable CONFIG_BOOT_MAX_IMG_SECTORS_AUTO and set CONFIG_BOOT_MAX_IMG_SECTORS to the required value" )
422
+ endif ()
423
+ endif ()
382
424
425
+ if (SYSBUILD )
383
426
if (CONFIG_SINGLE_APPLICATION_SLOT OR CONFIG_BOOT_FIRMWARE_LOADER OR CONFIG_BOOT_SWAP_USING_SCRATCH OR CONFIG_BOOT_SWAP_USING_MOVE OR CONFIG_BOOT_UPGRADE_ONLY OR CONFIG_BOOT_DIRECT_XIP OR CONFIG_BOOT_RAM_LOAD )
384
427
# TODO: RAM LOAD support
385
428
dt_nodelabel (slot0_flash NODELABEL "slot0_partition" )
@@ -495,7 +538,11 @@ if(SYSBUILD)
495
538
endif ()
496
539
497
540
if (CONFIG_BOOT_SWAP_USING_SCRATCH OR CONFIG_BOOT_SWAP_USING_MOVE )
498
- math (EXPR boot_status_data_size "${CONFIG_BOOT_MAX_IMG_SECTORS} * (3 * ${write_size} )" )
541
+ if (CONFIG_BOOT_MAX_IMG_SECTORS_AUTO AND DEFINED slot_min_sectors AND "${slot_min_sectors} " GREATER "0" )
542
+ math (EXPR boot_status_data_size "${slot_min_sectors} * (3 * ${write_size} )" )
543
+ else ()
544
+ math (EXPR boot_status_data_size "${CONFIG_BOOT_MAX_IMG_SECTORS} * (3 * ${write_size} )" )
545
+ endif ()
499
546
else ()
500
547
set (boot_status_data_size 0 )
501
548
endif ()
0 commit comments