-
Notifications
You must be signed in to change notification settings - Fork 135
Implement filesystem-based partition state management #608
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
326b46e
Implement filesystem-based partition state management
julek-wolfssl 64e3e1f
Makefile: Add library_fs target and improve clean rules
julek-wolfssl 23cd0ff
library: Fix printf type casting in error reporting
julek-wolfssl 05caf80
Add Partition Manager CLI docs
julek-wolfssl 88c036d
config: Add example configuration for library_fs mode
julek-wolfssl 432c453
Makefile: running just `make` should produce the lib not the example bin
julek-wolfssl bfc8ebf
Minor build fixes.
dgarske File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| ARCH=sim | ||
| TARGET=library_fs | ||
|
|
||
| SIGN?=ED25519 | ||
| HASH?=SHA256 | ||
| IMAGE_HEADER_SIZE?=256 | ||
| DEBUG=0 | ||
| SPMATH?=0 | ||
| SPMATHALL?=0 | ||
|
|
||
| # Required for library (libwolfboot.a) | ||
| NO_LOADER=1 | ||
| USE_GCC_HEADLESS=0 | ||
|
|
||
| # Flash Partition Filename | ||
| WOLFBOOT_PARTITION_FILENAME=\"/dev/mtd0\" | ||
|
|
||
| # Flash Sector Size | ||
| WOLFBOOT_SECTOR_SIZE=0x2000 | ||
| # Application Partition Size | ||
| WOLFBOOT_PARTITION_SIZE=0xA000 | ||
| # Location in flash for wolfBoot | ||
| WOLFBOOT_ORIGIN=0x0 | ||
| # Location in flash for boot partition | ||
| WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10000 | ||
| # Location in flash for update partition | ||
| WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x8000 | ||
| # Location in flash for swap | ||
| WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xFFE00 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| /* library_fs.c | ||
| * | ||
| * Copyright (C) 2025 wolfSSL Inc. | ||
| * | ||
| * This file is part of wolfBoot. | ||
| * | ||
| * wolfBoot is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * wolfBoot is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #include "image.h" | ||
| #include "printf.h" | ||
| #include "wolfboot/wolfboot.h" | ||
|
|
||
| /* Helper function to convert partition ID to string */ | ||
| static const char* partition_name(uint8_t part) | ||
| { | ||
| switch (part) { | ||
| case PART_BOOT: | ||
| return "BOOT"; | ||
| case PART_UPDATE: | ||
| return "UPDATE"; | ||
| default: | ||
| return "UNKNOWN"; | ||
| } | ||
| } | ||
|
|
||
| /* Helper function to convert state value to string */ | ||
| static const char* state_name(uint8_t state) | ||
| { | ||
| switch (state) { | ||
| case IMG_STATE_NEW: | ||
| return "NEW"; | ||
| case IMG_STATE_UPDATING: | ||
| return "UPDATING"; | ||
| case IMG_STATE_SUCCESS: | ||
| return "SUCCESS"; | ||
| default: | ||
| return "UNKNOWN"; | ||
| } | ||
| } | ||
|
|
||
| /* Print partition state */ | ||
| static int cmd_get_state(uint8_t part) | ||
| { | ||
| uint8_t state; | ||
| int ret; | ||
|
|
||
| ret = wolfBoot_get_partition_state(part, &state); | ||
| if (ret != 0) { | ||
| wolfBoot_printf("Error: Failed to get state for %s partition (error: %d)\n", | ||
| partition_name(part), ret); | ||
| return -1; | ||
| } | ||
|
|
||
| wolfBoot_printf("%s partition state: %s (0x%02X)\n", | ||
| partition_name(part), state_name(state), state); | ||
| return 0; | ||
| } | ||
|
|
||
| /* Print all partition states */ | ||
| static int cmd_get_all_states(void) | ||
| { | ||
| int ret = 0; | ||
|
|
||
| wolfBoot_printf("=== Partition States ===\n"); | ||
|
|
||
| if (cmd_get_state(PART_BOOT) != 0) | ||
| ret = -1; | ||
|
|
||
| if (cmd_get_state(PART_UPDATE) != 0) | ||
| ret = -1; | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| /* Trigger an update */ | ||
| static int cmd_update_trigger(void) | ||
| { | ||
| wolfBoot_printf("Triggering update...\n"); | ||
| wolfBoot_update_trigger(); | ||
| wolfBoot_printf("Update triggered successfully. UPDATE partition set to UPDATING state.\n"); | ||
| return 0; | ||
| } | ||
|
|
||
| /* Mark current boot as successful */ | ||
| static int cmd_success(void) | ||
| { | ||
| wolfBoot_printf("Marking BOOT partition as SUCCESS...\n"); | ||
| wolfBoot_success(); | ||
| wolfBoot_printf("BOOT partition marked as SUCCESS.\n"); | ||
| return 0; | ||
| } | ||
|
|
||
| /* Print usage information */ | ||
| static void print_usage(const char* prog_name) | ||
| { | ||
| wolfBoot_printf("wolfBoot Partition Manager CLI\n"); | ||
| wolfBoot_printf("\nUsage: %s <command> [options]\n\n", prog_name); | ||
| wolfBoot_printf("Commands:\n"); | ||
| wolfBoot_printf(" status - Show state of all partitions\n"); | ||
| wolfBoot_printf(" get-boot - Get BOOT partition state\n"); | ||
| wolfBoot_printf(" get-update - Get UPDATE partition state\n"); | ||
| wolfBoot_printf(" update-trigger - Trigger an update (sets UPDATE partition to UPDATING)\n"); | ||
| wolfBoot_printf(" success - Mark BOOT partition as SUCCESS\n"); | ||
| wolfBoot_printf(" help - Show this help message\n"); | ||
| wolfBoot_printf("\nPartitions:\n"); | ||
| wolfBoot_printf(" BOOT - Currently running firmware partition\n"); | ||
| wolfBoot_printf(" UPDATE - Staging partition for new firmware\n"); | ||
| wolfBoot_printf("\nExamples:\n"); | ||
| wolfBoot_printf(" %s status - Display all partition states\n", prog_name); | ||
| wolfBoot_printf(" %s update-trigger - Stage an update for next boot\n", prog_name); | ||
| wolfBoot_printf(" %s success - Confirm current firmware is working\n", prog_name); | ||
| wolfBoot_printf("\n"); | ||
| } | ||
|
|
||
| int main(int argc, const char* argv[]) | ||
| { | ||
| int ret = 0; | ||
|
|
||
| /* Check for argument count */ | ||
| if (argc != 2) { | ||
| print_usage(argv[0]); | ||
| return 1; | ||
| } | ||
|
|
||
| const char* command = argv[1]; | ||
|
|
||
| /* Process commands */ | ||
| if (strcmp(command, "status") == 0) { | ||
| ret = cmd_get_all_states(); | ||
| } | ||
| else if (strcmp(command, "get-boot") == 0) { | ||
| ret = cmd_get_state(PART_BOOT); | ||
| } | ||
| else if (strcmp(command, "get-update") == 0) { | ||
| ret = cmd_get_state(PART_UPDATE); | ||
| } | ||
| else if (strcmp(command, "update-trigger") == 0) { | ||
| ret = cmd_update_trigger(); | ||
| } | ||
| else if (strcmp(command, "success") == 0) { | ||
| ret = cmd_success(); | ||
| } | ||
| else if (strcmp(command, "help") == 0 || strcmp(command, "--help") == 0 || | ||
| strcmp(command, "-h") == 0) { | ||
| print_usage(argv[0]); | ||
| ret = 0; | ||
| } | ||
| else { | ||
| wolfBoot_printf("Error: Unknown command '%s'\n\n", command); | ||
| print_usage(argv[0]); | ||
| ret = 1; | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.