diff --git a/gp2040ce_bintools/builder.py b/gp2040ce_bintools/builder.py index 32a8b6a..cfc203b 100644 --- a/gp2040ce_bintools/builder.py +++ b/gp2040ce_bintools/builder.py @@ -102,13 +102,24 @@ def concatenate_firmware_and_storage_files(firmware_filename: str, new_binary = combine_firmware_and_config(firmware_binary, board_config_binary, user_config_binary, replace_extra=replace_extra) else: - new_binary = convert_binary_to_uf2(firmware_binary) - if board_config_binary: - new_binary += convert_binary_to_uf2(pad_config_to_storage_size(board_config_binary), - start=BOARD_CONFIG_BINARY_LOCATION) - if user_config_binary: - new_binary += convert_binary_to_uf2(pad_config_to_storage_size(user_config_binary), - start=USER_CONFIG_BINARY_LOCATION) + # this was kind of fine, but combining multiple calls of convert_binary_to_uf2 produced + # incorrect total block counts in the file, which picotool handled with some squirrely + # double-output behavior that has me worried it'd cause a real issue, so doing the + # crude padding + write of empty blocks, for now... + # + # new_binary = convert_binary_to_uf2(firmware_binary) + # if board_config_binary: + # new_binary += convert_binary_to_uf2(pad_config_to_storage_size(board_config_binary), + # start=BOARD_CONFIG_BINARY_LOCATION) + # if user_config_binary: + # new_binary += convert_binary_to_uf2(pad_config_to_storage_size(user_config_binary), + # start=USER_CONFIG_BINARY_LOCATION) + # + # the correct way to do the above would be to pass a list of {offset,binary_data} to convert..., + # and have it calculate the total block size before starting to write, and then iterating over + # the three lists. doable, just not on the top of my mind right now + new_binary = convert_binary_to_uf2(combine_firmware_and_config(firmware_binary, board_config_binary, + user_config_binary, replace_extra=replace_extra)) if combined_filename: with open(combined_filename, 'wb') as combined: diff --git a/tests/test_builder.py b/tests/test_builder.py index b61c651..59b5385 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -121,8 +121,8 @@ def test_concatenate_to_uf2(tmp_path, firmware_binary, config_binary): combined_filename=tmp_file) with open(tmp_file, 'rb') as file: content = file.read() - # size of the file should be 2x firmware in 256 byte blocks + 2x padded board config + 2x padding user config - assert len(content) == 2 * (math.ceil(len(firmware_binary)/256) * 256) + 2 * STORAGE_SIZE + 2 * STORAGE_SIZE + # size of the file should be 2x the binary version, and the binary is 2 MB + assert len(content) == 2 * 2 * 1024 * 1024 def test_concatenate_to_uf2_board_only(tmp_path, firmware_binary, config_binary): @@ -134,8 +134,8 @@ def test_concatenate_to_uf2_board_only(tmp_path, firmware_binary, config_binary) combined_filename=tmp_file) with open(tmp_file, 'rb') as file: content = file.read() - # size of the file should be 2x firmware in 256 byte blocks + 2x padded board config + 2x padding user config - assert len(content) == 2 * (math.ceil(len(firmware_binary)/256) * 256) + 2 * STORAGE_SIZE + # size of the file should be 2x the binary version (minus user config space), and the binary is 2 MB - 16KB + assert len(content) == 2 * (2 * 1024 * 1024 - 16384) def test_padding_firmware(firmware_binary):