Skip to content

Commit a0ceb2b

Browse files
committed
update comments
1 parent 01001fa commit a0ceb2b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

flash/partition_info/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ pico_embed_pt_in_binary(partition_info ${CMAKE_CURRENT_LIST_DIR}/pt.json)
88
pico_enable_stdio_usb(partition_info 1)
99
pico_add_extra_outputs(partition_info)
1010
example_auto_set_url(partition_info)
11-

flash/partition_info/partition_info.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/**
2+
* Copyright (c) 2025 Hiroyuki OYAMA <[email protected]>
3+
* Copyright (c) 2023 Raspberry Pi (Trading) Ltd.
24
*
35
* SPDX-License-Identifier: BSD-3-Clause
46
*/
@@ -11,6 +13,8 @@
1113
#define PART_LOC_FIRST(x) ( ((x) & PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_FIRST_SECTOR_LSB )
1214
#define PART_LOC_LAST(x) ( ((x) & PICOBIN_PARTITION_LOCATION_LAST_SECTOR_BITS) >> PICOBIN_PARTITION_LOCATION_LAST_SECTOR_LSB )
1315

16+
#define WORD_SIZE 4
17+
1418
/*
1519
* Stores partition table information and data read status
1620
*/
@@ -50,13 +54,13 @@ int pico_partitions_open(pico_partition_t *pt, int flags) {
5054
return rc;
5155
}
5256
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
5558
uint32_t location = workarea[2];
5659
pt->unpartitioned_space_first_sector = PART_LOC_FIRST(location);
5760
pt->unpartitioned_space_last_sector = PART_LOC_LAST(location);
5861
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
6064
pt->current_partition = 0;
6165

6266
return 0;
@@ -92,9 +96,10 @@ size_t pico_partitions_parse(pico_partition_t *pt, pico_partition_entry_t *p) {
9296
uint8_t *name_src = name_field + 1;
9397
memcpy(p->name, name_src, name_length);
9498
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;
98103
} else {
99104
p->name[0] = '\0';
100105
}

0 commit comments

Comments
 (0)