@@ -101,26 +101,15 @@ def concatenate_firmware_and_storage_files(firmware_filename: str,
101101 new_binary = combine_firmware_and_config (firmware_binary , board_config_binary , user_config_binary ,
102102 replace_extra = replace_extra )
103103 else :
104- # this was kind of fine, but combining multiple calls of convert_binary_to_uf2 produced
105- # incorrect total block counts in the file, which picotool handled with some squirrely
106- # double-output behavior that has me worried it'd cause a real issue, so doing the
107- # crude padding + write of empty blocks, for now...
108- #
109- # new_binary = convert_binary_to_uf2(firmware_binary)
110- # if board_config_binary:
111- # new_binary += convert_binary_to_uf2(pad_config_to_storage_size(board_config_binary),
112- # start=BOARD_CONFIG_BINARY_LOCATION)
113- # if user_config_binary:
114- # new_binary += convert_binary_to_uf2(pad_config_to_storage_size(user_config_binary),
115- # start=USER_CONFIG_BINARY_LOCATION)
116- #
117- # the correct way to do the above would be to pass a list of {offset,binary_data} to convert...,
118- # and have it calculate the total block size before starting to write, and then iterating over
119- # the three lists. doable, just not on the top of my mind right now
120- new_binary = storage .convert_binary_to_uf2 ([
121- (0 , combine_firmware_and_config (firmware_binary , board_config_binary , user_config_binary ,
122- replace_extra = replace_extra )),
123- ])
104+ binary_list = [(0 , firmware_binary )]
105+ # we must pad to storage start in order for the UF2 write addresses to make sense
106+ if board_config_binary :
107+ binary_list .append ((storage .BOARD_CONFIG_BINARY_LOCATION ,
108+ storage .pad_config_to_storage_size (board_config_binary )))
109+ if user_config_binary :
110+ binary_list .append ((storage .USER_CONFIG_BINARY_LOCATION ,
111+ storage .pad_config_to_storage_size (user_config_binary )))
112+ new_binary = storage .convert_binary_to_uf2 (binary_list )
124113
125114 if combined_filename :
126115 with open (combined_filename , 'wb' ) as combined :
@@ -257,6 +246,7 @@ def write_new_config_to_filename(config: Message, filename: str, inject: bool =
257246 binary = storage .serialize_config_with_footer (config )
258247 with open (filename , 'wb' ) as file :
259248 if filename [- 4 :] == '.uf2' :
249+ # we must pad to storage start in order for the UF2 write addresses to make sense
260250 file .write (storage .convert_binary_to_uf2 ([
261251 (storage .USER_CONFIG_BINARY_LOCATION , storage .pad_config_to_storage_size (binary )),
262252 ]))
0 commit comments