Skip to content
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

App storage functionality simplification #865

Draft
wants to merge 2 commits into
base: API_LEVEL_22
Choose a base branch
from

Conversation

iartemov-ledger
Copy link
Collaborator

@iartemov-ledger iartemov-ledger commented Feb 18, 2025

⚠️ This PR for demonstration/discussions only, not supposed to be merged. There will be another PR targeting master.

Corresponds to app-boilerplate change: LedgerHQ/app-boilerplate#147
Corresponds to app-security-key change: LedgerHQ/app-security-key#69

Description

  • the app storage initialization is implicit, still at app boot
  • do we want to perform a delayed initialization (at first use) ? => No, the storage initialization takes place implicitly in SDK at app boot
  • HAVE_APP_STORAGE, APP_STORAGE_SIZE, HAVE_APP_STORAGE_PROP_SETTINGS and HAVE_APP_STORAGE_PROP_DATA have to be define in app's Makefile
  • the variable that points to the NVM is in a special linker section
  • the user can see directly only the app data part
    • struct_version is the header version (the app data versioning has to be done explicitly in the app)
    • size represents the app data size, starts with 0 and grows with writes
  • the API is simplified (1 read, 1 write, 2 setters, 3 getters)
  • ported to:
    • Stax
    • Flex
    • NanoSP
    • NanoX
    • NanoS ?
  • discuss/remove TODOs

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Tests
  • Documentation
  • Other (for changes that might not fit in any category)

Breaking changes

See above ⬆️

@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (API_LEVEL_22@2429c56). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff               @@
##             API_LEVEL_22     #865   +/-   ##
===============================================
  Coverage                ?   83.02%           
===============================================
  Files                   ?        9           
  Lines                   ?      483           
  Branches                ?        0           
===============================================
  Hits                    ?      401           
  Misses                  ?       82           
  Partials                ?        0           
Flag Coverage Δ
unittests 83.02% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

/* Setters */
int32_t app_storage_pwrite(const void *buf, uint32_t nbyte, uint32_t offset);
void app_storage_set_data_version(uint32_t data_version);
void app_storage_increment_data_version(void);
Copy link
Collaborator Author

@iartemov-ledger iartemov-ledger Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarevalo-ledger >> Do we need app_storage_erase() to be able to dynamically reduce app storage size ?
@iartemov-ledger >> To note that from SDK PoV we'll be able to play only if the part at the end of storage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI Neither app-boilerplate nor app-security-key remove some storage data today (in app-security-key there is an erase, but just only to add another data to the very same slot).

/* NVM data (ex-filesystem) */
/* TODO: should we align the start of N_ variables on page size ? */
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current version supports 2 approaches:

  • NVM accessible through app_storage API, backupable and restorable
  • NVM accessible through N_ variable (legacy approach), NOT backupable and restorable

I do not see anything bad to support the both it gives the possibility to user to backuping/restoring some data. And it will work for apps that have not yet migrated to the new API (we'll need tests for all this).

@@ -69,7 +69,11 @@ SECTIONS

_nvram_data = .;

/* App storage */
*(.storage_section)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarevalo-ledger >> to add preprocessor checking for HAVE_APP_STORAGE.

Copy link
Collaborator Author

@iartemov-ledger iartemov-ledger Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not run processor against the .ld files currently.
If no variable is declared in storage_section it will not occupy anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants