diff --git a/README.md b/README.md index 2a45c8d..3ee7ce6 100644 --- a/README.md +++ b/README.md @@ -232,11 +232,11 @@ The latest update of the configuration snapshot is from **v0.7.8**. ### Dumping the GP2040-CE board with picotool Some of these tools require a dump of your GP2040-CE board, either the storage section or the whole board, depending on -the context. The storage section of a GP2040-CE board is a reserved 16 KB starting at `0x101FC000`. To dump your board's -storage with picotool: +the context. The user config storage section of a GP2040-CE board is a reserved 32 KB starting at `0x101F8000`. To dump +your board's storage with picotool: ``` -% picotool save -r 101FC000 10200000 memory.bin +% picotool save -r 101F8000 10200000 memory.bin ``` And to dump your whole board: diff --git a/gp2040ce_bintools/storage.py b/gp2040ce_bintools/storage.py index abce92f..dbfc5a2 100644 --- a/gp2040ce_bintools/storage.py +++ b/gp2040ce_bintools/storage.py @@ -17,10 +17,11 @@ from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read logger = logging.getLogger(__name__) -BOARD_CONFIG_BINARY_LOCATION = 0x1F8000 +STORAGE_SIZE = 32768 + +BOARD_CONFIG_BINARY_LOCATION = (2 * 1024 * 1024) - (STORAGE_SIZE * 2) # 0x1F0000 BOARD_CONFIG_BOOTSEL_ADDRESS = 0x10000000 + BOARD_CONFIG_BINARY_LOCATION -STORAGE_SIZE = 16384 -USER_CONFIG_BINARY_LOCATION = 0x1FC000 +USER_CONFIG_BINARY_LOCATION = (2 * 1024 * 1024) - STORAGE_SIZE # 0x1F8000 USER_CONFIG_BOOTSEL_ADDRESS = 0x10000000 + USER_CONFIG_BINARY_LOCATION FOOTER_SIZE = 12 @@ -425,7 +426,7 @@ def visualize(): group.add_argument('--usb', action='store_true', help="retrieve the config from a RP2040 board connected over USB " "and in BOOTSEL mode") group.add_argument('--filename', help=".bin file of a GP2040-CE board's storage section, bytes " - "101FC000-10200000, or of a GP2040-CE's whole board dump " + "101F8000-10200000, or of a GP2040-CE's whole board dump " "if --whole-board is specified") args, _ = parser.parse_known_args() diff --git a/tests/conftest.py b/tests/conftest.py index 32af78e..c1136ba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -42,7 +42,7 @@ def firmware_binary(): @pytest.fixture def storage_dump(): - """Read in a test storage dump file (101FC000-10200000) of a GP2040-CE board.""" + """Read in a test storage dump file (101F8000-10200000) of a GP2040-CE board.""" filename = os.path.join(HERE, 'test-files', 'test-storage-area.bin') with open(filename, 'rb') as file: content = file.read() diff --git a/tests/test-files/test-storage-area.bin b/tests/test-files/test-storage-area.bin index 7aa1449..2d9872f 100644 Binary files a/tests/test-files/test-storage-area.bin and b/tests/test-files/test-storage-area.bin differ diff --git a/tests/test-files/test-whole-board-with-board-config.bin b/tests/test-files/test-whole-board-with-board-config.bin index 973b52b..49592b1 100644 Binary files a/tests/test-files/test-whole-board-with-board-config.bin and b/tests/test-files/test-whole-board-with-board-config.bin differ diff --git a/tests/test_builder.py b/tests/test_builder.py index 0d135c6..5cd27d7 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -57,7 +57,7 @@ def test_concatenate_board_config_to_file(tmp_path): combined_filename=tmp_file) with open(tmp_file, 'rb') as file: content = file.read() - assert len(content) == (2 * 1024 * 1024) - (16 * 1024) + assert len(content) == (2 * 1024 * 1024) - (32 * 1024) def test_concatenate_both_configs_to_file(tmp_path): @@ -180,19 +180,19 @@ def test_dont_always_find_version_string(firmware_binary): def test_padding_firmware(firmware_binary): """Test that firmware is padded to the expected size.""" padded = builder.pad_binary_up_to_user_config(firmware_binary) - assert len(padded) == 2080768 + assert len(padded) == 2064384 def test_padding_firmware_can_truncate(): """Test that firmware is padded to the expected size.""" padded = builder.pad_binary_up_to_user_config(bytearray(b'\x00' * 4 * 1024 * 1024), or_truncate=True) - assert len(padded) == 2080768 + assert len(padded) == 2064384 def test_padding_firmware_to_board(firmware_binary): """Test that firmware is padded to the expected size.""" padded = builder.pad_binary_up_to_board_config(firmware_binary) - assert len(padded) == 2080768 - (16 * 1024) + assert len(padded) == 2064384 - (32 * 1024) def test_firmware_plus_storage_section(firmware_binary, storage_dump): @@ -226,7 +226,7 @@ def test_chunky_firmware_plus_user_config_binary(config_binary): def test_firmware_plus_board_config_binary(firmware_binary, config_binary): """Test that combining firmware and board config produces a valid combined binary.""" almost_whole_board = builder.combine_firmware_and_config(firmware_binary, config_binary, None) - assert len(almost_whole_board) == (2 * 1024 * 1024) - (16 * 1024) + assert len(almost_whole_board) == (2 * 1024 * 1024) - (32 * 1024) # if this is valid, we should be able to find the storage and footer again storage = get_board_storage_section(almost_whole_board) footer_size, _, _ = get_config_footer(storage) diff --git a/tests/test_commands.py b/tests/test_commands.py index a0d45aa..b52bd44 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -51,7 +51,7 @@ def test_concatenate_invocation(tmpdir): with open(out_filename, 'rb') as out_file, open('tests/test-files/test-storage-area.bin', 'rb') as storage_file: out = out_file.read() storage = storage_file.read() - assert out[2080768:2097152] == storage + assert out[2064384:2097152] == storage def test_concatenate_invocation_json(tmpdir): @@ -88,7 +88,7 @@ def test_debug_storage_dump_invocation(): '--filename', 'tests/test-files/test-storage-area.bin'], capture_output=True, encoding='utf8') assert 'boardVersion: "v0.7.5"' in result.stdout - assert 'length of content to look for footer in: 16384' in result.stderr + assert 'length of content to look for footer in: 32768' in result.stderr def test_storage_dump_json_invocation(): diff --git a/tests/test_storage.py b/tests/test_storage.py index f49dc0e..e547a90 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -97,7 +97,7 @@ def test_get_board_config_from_file_whole_board_dump(): """Test that we can open a storage dump file and find its config.""" filename = os.path.join(HERE, 'test-files', 'test-whole-board-with-board-config.bin') config = storage.get_config_from_file(filename, whole_board=True, board_config=True) - assert config.boardVersion == 'v0.7.6-15-g71f4512' + assert config.boardVersion == 'v0.7.8' assert config.addonOptions.bootselButtonOptions.enabled is False @@ -167,7 +167,7 @@ def test_convert_binary_to_uf2_with_offsets(whole_board_with_board_config_dump): assert len(uf2) == 4194304 # binary is 8192 256 byte chunks, UF2 is 512 b per chunk assert uf2[0:4] == b'\x55\x46\x32\x0a' == b'UF2\n' # proper magic assert uf2[8:12] == bytearray(b'\x00\x20\x00\x00') # family ID set - assert uf2[524:528] == bytearray(b'\x00\xc1\x1f\x10') # address to write the second chunk + assert uf2[524:528] == bytearray(b'\x00\x81\x1f\x10') # address to write the second chunk def test_convert_binary_to_uf2_to_binary(whole_board_with_board_config_dump): @@ -215,7 +215,7 @@ def test_read_created_uf2(tmp_path, firmware_binary, config_binary): binary = storage.convert_uf2_to_binary(content) # the converted binary should be aligned properly and of the right size assert len(binary) == 2 * 1024 * 1024 - assert binary[-16384-4:-16384] == storage.FOOTER_MAGIC + assert binary[-32768-4:-32768] == storage.FOOTER_MAGIC assert binary[-4:] == storage.FOOTER_MAGIC user_storage = storage.get_user_storage_section(binary) footer_size, _, _ = storage.get_config_footer(user_storage) @@ -257,13 +257,13 @@ def test_serialize_modified_config_with_footer(storage_dump): def test_pad_config_to_storage(config_binary): """Test that we can properly pad a config section to the correct storage section size.""" storage_section = storage.pad_config_to_storage_size(config_binary) - assert len(storage_section) == 16384 + assert len(storage_section) == 32768 def test_pad_config_to_storage_raises(config_binary): """Test that we raise an exception if the config is bigger than the storage section.""" with pytest.raises(storage.ConfigLengthError): - _ = storage.pad_config_to_storage_size(config_binary * 5) + _ = storage.pad_config_to_storage_size(config_binary * 10) @with_pb2s @@ -280,7 +280,7 @@ def test_get_board_config_from_usb(config_binary): config, _, _ = storage.get_board_config_from_usb() mock_get.assert_called_once() - mock_read.assert_called_with(mock_out, mock_in, 0x101F8000, 16384) + mock_read.assert_called_with(mock_out, mock_in, 0x101F0000, 32768) assert config == storage.get_config(config_binary) @@ -298,7 +298,7 @@ def test_get_user_config_from_usb(config_binary): config, _, _ = storage.get_user_config_from_usb() mock_get.assert_called_once() - mock_read.assert_called_with(mock_out, mock_in, 0x101FC000, 16384) + mock_read.assert_called_with(mock_out, mock_in, 0x101F8000, 32768) assert config == storage.get_config(config_binary)