Skip to content

Commit ea806c2

Browse files
committed
pbio/drv/block_device_test: Update expected data map.
A driver is not supposed to include things from pbsys, but it makes sense for this test driver, ensuring that the dummy block device has the expected contents when we change the format, instead of hard coding it.
1 parent 605d72b commit ea806c2

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

lib/pbio/drv/block_device/block_device_test.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
#include <pbdrv/block_device.h>
1616

17+
#include <pbio/version.h>
18+
19+
#include <pbsys/storage.h>
20+
1721
/**
1822
* The following script is compiled using pybricksdev compile hello.py
1923
* in MULTI_MPY_V6.
@@ -46,22 +50,17 @@ const uint8_t script[] = {
4650
0x34, 0x01, 0x59, 0x11, 0x07, 0x65, 0x51, 0x63,
4751
};
4852

49-
#define MAX_PROGRAM_SIZE ((PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE)-(PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE_USER)-sizeof(uint32_t) * 2)
50-
51-
/**
52-
* Mimics data structure expected by pbsys.
53-
*/
54-
static struct {
55-
uint32_t write_size;
56-
uint8_t user_data[PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE_USER];
57-
uint32_t program_size;
58-
uint8_t program_data[MAX_PROGRAM_SIZE] __attribute__((aligned(sizeof(void *))));
53+
static union {
54+
pbsys_storage_data_map_t data_map;
55+
uint8_t blockdev[PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE];
5956
} blockdev = { 0 };
6057

6158
void pbdrv_block_device_init(void) {
62-
blockdev.program_size = sizeof(script);
63-
memcpy(blockdev.program_data, script, sizeof(script));
64-
blockdev.write_size = sizeof(blockdev) - sizeof(blockdev.program_data) + blockdev.program_size;
59+
pbsys_storage_data_map_t *map = &blockdev.data_map;
60+
map->program_size = sizeof(script);
61+
map->stored_firmware_version = PBIO_HEXVERSION;
62+
memcpy(&map->program_data, script, sizeof(script));
63+
map->write_size = sizeof(pbsys_storage_data_map_t) + map->program_size;
6564
}
6665

6766
PT_THREAD(pbdrv_block_device_read(struct pt *pt, uint32_t offset, uint8_t *buffer, uint32_t size, pbio_error_t *err)) {

0 commit comments

Comments
 (0)