|
1 | 1 | /** |
| 2 | + * Copyright (c) 2025 Hiroyuki OYAMA <[email protected]> |
| 3 | + * Copyright (c) 2023 Raspberry Pi (Trading) Ltd. |
2 | 4 | * |
3 | 5 | * SPDX-License-Identifier: BSD-3-Clause |
4 | 6 | */ |
|
11 | 13 | #define PART_LOC_FIRST(x) ( ((x) & PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_LSB ) |
12 | 14 | #define PART_LOC_LAST(x) ( ((x) & PICOBIN_PARTITION_LOCATION_LAST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_LAST_SECTOR_LSB ) |
13 | 15 |
|
| 16 | +#define WORD_SIZE 4 |
| 17 | + |
14 | 18 | /* |
15 | 19 | * Stores partition table information and data read status |
16 | 20 | */ |
@@ -50,13 +54,13 @@ int pico_partitions_open(pico_partition_t *pt, int flags) { |
50 | 54 | return rc; |
51 | 55 | } |
52 | 56 | pt->table = workarea; |
53 | | - pt->table_size = rc * 4; // word to bytes |
54 | | - pt->partition_count = ((uint8_t*)workarea)[4]; |
| 57 | + pt->table_size = rc * WORD_SIZE; // word to bytes |
55 | 58 | uint32_t location = workarea[2]; |
56 | 59 | pt->unpartitioned_space_first_sector = PART_LOC_FIRST(location); |
57 | 60 | pt->unpartitioned_space_last_sector = PART_LOC_LAST(location); |
58 | 61 | pt->permission = workarea[3]; |
59 | | - pt->idx = 4; |
| 62 | + pt->partition_count = ((uint8_t*)workarea)[4]; |
| 63 | + pt->idx = 4; // point to the beggining of eath table |
60 | 64 | pt->current_partition = 0; |
61 | 65 |
|
62 | 66 | return 0; |
@@ -92,9 +96,10 @@ size_t pico_partitions_parse(pico_partition_t *pt, pico_partition_entry_t *p) { |
92 | 96 | uint8_t *name_src = name_field + 1; |
93 | 97 | memcpy(p->name, name_src, name_length); |
94 | 98 | p->name[name_length] = '\0'; |
95 | | - size_t total_name_bytes = 1 + name_length; |
96 | | - size_t padded_bytes = (total_name_bytes + 3) & ~((size_t)3); |
97 | | - idx += padded_bytes / 4; |
| 99 | + size_t total_name_field_length = 1 + name_length; |
| 100 | + // Name field is padded to word size |
| 101 | + size_t padded_bytes = (total_name_field_length + 3) & ~((size_t)3); |
| 102 | + idx += padded_bytes / WORD_SIZE; |
98 | 103 | } else { |
99 | 104 | p->name[0] = '\0'; |
100 | 105 | } |
|
0 commit comments