@@ -880,9 +880,11 @@ deploy_firmware() {
880880 local _mode
881881 local _jobs=() # List of scheduled job indices
882882 local _messages=() # List of error messages
883- # _job_args_<i> # List of flashrom params per job indice
883+ # _job_args_<i> # List of flashrom params per job indice
884884 # These are created dynamically in schedule_job() and referenced via nameref.
885885 local _jobs_total=0
886+ local _all_flashrom_args=() # An array for all flashrom args from all jobs
887+ local n i # Loop iterators
886888 _mode=" $1 "
887889
888890 # Helper function to schedule a flashrom job
@@ -909,23 +911,6 @@ deploy_firmware() {
909911 args_ref=(" $@ " )
910912 }
911913
912- # Helper function to check whether fd flashing is among arguments
913- # 0 if found, 1 otherwise.
914- check_for_fd () {
915- local -n _args=" $1 "
916- local i
917-
918- # Scan argument array for the exact flashrom region selector "-i fd".
919- # Iterate only up to length-1 since we always inspect pairs (i, i+1).
920- for (( i = 0 ; i < ${# _args[@]} - 1 ; i++ )) ; do
921- if [[ " ${_args[i]} " == " -i" && " ${_args[i + 1]} " == " fd" ]]; then
922- return 0
923- fi
924- done
925-
926- return 1
927- }
928-
929914 if [ " $_mode " == " update" ]; then
930915 echo " Updating Dasharo firmware..."
931916 print_warning " This may take several minutes. Please be patient and do not"
@@ -1033,7 +1018,7 @@ deploy_firmware() {
10331018 # shellcheck disable=SC2178
10341019 local -n args_ref=" _job_args_$i "
10351020
1036- if check_for_fd args_ref; then
1021+ if flashrom_check_for_region fd args_ref; then
10371022 echo " Scheduling dedicated FD update..."
10381023 schedule_job " Failed to flash FD" \
10391024 -p " $PROGRAMMER_BIOS " \
@@ -1050,8 +1035,19 @@ deploy_firmware() {
10501035 fi
10511036 done
10521037
1053- # Last restort check before flashing
1054- if ! flashrom_sanity_check; then
1038+ # Create array of all flashrom params to call flashrom_region_check only once
1039+ for n in " ${! _jobs[@]} " ; do
1040+ i=" ${_jobs[$n]} "
1041+ # _job_args_$i is a dynamically named (runtime-created) global array holding
1042+ # flashrom arguments for a single job.
1043+ # shellcheck disable=SC2178
1044+ local -n args_ref=" _job_args_$i "
1045+
1046+ _all_flashrom_args+=(" ${args_ref[@]} " )
1047+ done
1048+
1049+ # Last resort check before flashing
1050+ if ! flashrom_region_check _all_flashrom_args; then
10551051 return 1
10561052 fi
10571053
0 commit comments