Skip to content

Add a sample to read the partition table #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
01001fa
Add an example of extract and enumerate partition table information
oyama Mar 17, 2025
a0ceb2b
update comments
oyama Mar 17, 2025
d2883d1
Remove redundant attribute specifiers
oyama Mar 17, 2025
1015067
Rename structs, specify partition family, remove magic numbers
oyama Mar 19, 2025
8b87449
Changed partition table reads to be split into fixed-length field sec…
oyama Mar 19, 2025
c5aa4c1
Update flash/partition_info/partition_info.c
oyama Mar 21, 2025
2496fe7
panic if the table cannot be retrieved
oyama Mar 21, 2025
5681d71
fixed TYPO `patitions`
oyama Mar 21, 2025
0f96a36
rename to match the partition struct
oyama Mar 21, 2025
9bdba25
remove WORD_SIZE
oyama Mar 21, 2025
7d9edfa
update comment
oyama Mar 21, 2025
87eddec
remove unused define
oyama Mar 21, 2025
bbb1656
remove unused defined WORD_SIZE
oyama Mar 21, 2025
8f3564d
Name unified to flags_and_permissions
oyama Mar 21, 2025
ee6d8d6
Unify pico-sdk header file includes to ""
oyama Mar 25, 2025
b463a69
Fix typo in comment: change "Reads a fixed size fields" to "Reads fix…
oyama Mar 25, 2025
555ded5
Rename the position field in the partition table to “pos"
oyama Mar 25, 2025
9bce48c
Changed function names to prevent misleading as if they were SDK APIs.
oyama Mar 25, 2025
b5c2fbe
Initialize `pt->partition_count = 0`
oyama Mar 25, 2025
0889622
The fields of the partition table read are added `assert()`
oyama Mar 25, 2025
8dd6b0e
Check the return code of `open_partition_table`
oyama Mar 26, 2025
b53dfbc
Define and use SECTOR_SIZE
oyama Mar 26, 2025
4822ae3
Fix partition name work buffer length
oyama Mar 26, 2025
c5fd635
Mask the first bit of the partition name length field
oyama Mar 26, 2025
c88a23c
Add `has_partition` flag
oyama Mar 26, 2025
869bf75
rename `open_partition_table` to `read_partition_table`
oyama Mar 26, 2025
4005c6f
Use the predefined `FLASH_SECTOR_SIZE`
oyama Mar 26, 2025
8d1d467
rename `has_partition` to `has_partition_table`
oyama Mar 26, 2025
ce5b409
Skip printing empty partitions
oyama Mar 26, 2025
d9909f9
Added printing of extra family IDs
oyama Mar 27, 2025
ce6dda8
Add `p->has_name`
oyama Mar 27, 2025
7edee22
Changed default_family to be registered at `new`
oyama Mar 27, 2025
1066f75
Unify alloc/free hierarchy
oyama Mar 27, 2025
b118961
Move `PARTITION_EXTRA_FAMILY_ID_MAX` to uf2_family_ids.h
oyama Mar 27, 2025
c37dcbe
Change `pos` to `pos_` in the block to avoid conflicts
oyama Mar 27, 2025
9c19b3c
Fixed typo from `extra_family_id_and_name` to `extra_family_ids_and_n…
oyama Mar 27, 2025
cda403e
Removed redundant brackets
oyama Mar 27, 2025
a0e81bd
Move comment for `PARTITION_NAME_MAX`
oyama Mar 28, 2025
ff8d2b4
Utilize `p->has_name`. Add `p->has_id`
oyama Mar 28, 2025
9eb7c33
Add sample extra family id to `pt.json`
oyama Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions flash/partition_info/partition_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
typedef struct {
uint32_t table[PARTITION_TABLE_FIXED_INFO_SIZE];
uint32_t fields;
bool has_partition;
int partition_count;
uint32_t unpartitioned_space_first_sector;
uint32_t unpartitioned_space_last_sector;
Expand Down Expand Up @@ -64,7 +65,9 @@ int open_partition_table(pico_partition_table_t *pt) {
size_t pos = 0;
pt->fields = pt->table[pos++];
assert(pt->fields == flags);
pt->partition_count = pt->table[pos++] & 0x000000FF;
pt->partition_count = pt->table[pos] & 0x000000FF;
pt->has_partition = pt->table[pos] & 0x00000100;
pos++;
uint32_t location = pt->table[pos++];
pt->unpartitioned_space_first_sector = PART_LOC_FIRST(location);
pt->unpartitioned_space_last_sector = PART_LOC_LAST(location);
Expand Down Expand Up @@ -132,14 +135,19 @@ int main() {
if (rc != 0) {
panic("rom_get_partition_table_info returned %d", pt.status);
}

if (!pt.has_partition) {
printf("there is no partition table\n");
} else if (pt.partition_count == 0) {
printf("the partition table is empty\n");
}
printf("un-partitioned_space: S(%s%s) NSBOOT(%s%s) NS(%s%s)\n",
(pt.flags_and_permissions & PICOBIN_PARTITION_PERMISSION_S_R_BITS ? "r" : ""),
(pt.flags_and_permissions & PICOBIN_PARTITION_PERMISSION_S_W_BITS ? "w" : ""),
(pt.flags_and_permissions & PICOBIN_PARTITION_PERMISSION_NSBOOT_R_BITS ? "r" : ""),
(pt.flags_and_permissions & PICOBIN_PARTITION_PERMISSION_NSBOOT_W_BITS ? "w" : ""),
(pt.flags_and_permissions & PICOBIN_PARTITION_PERMISSION_NS_R_BITS ? "r" : ""),
(pt.flags_and_permissions & PICOBIN_PARTITION_PERMISSION_NS_W_BITS ? "w" : ""));

printf("partitions:\n");
pico_partition_t p;
while (read_next_partition(&pt, &p)) {
Expand Down