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

Flash interface refactoring #3385

Merged
merged 1 commit into from
Nov 15, 2023

Conversation

cepetr
Copy link
Contributor

@cepetr cepetr commented Nov 2, 2023

I've refactored the code for handling flash programming/erasing with following goals:

  1. Define clear responsibilities of modules
  2. Clean up interfaces
  3. Reduce duplicate code
  4. Move code where it should be

The result is not perfect, and achieving perfection would require deep ploughing, but the refactoring has successfully reduced some technical debt and leaves room for further enhancements and improvements.

The significant change is that flash_common.h has been split into flash_area.h and flash_ll.h. All code dealing with flash areas now resides in flash_area.c. HAL drivers for flash implement interface defined in flash_ll.h.

flash-refactoring drawio

@cepetr cepetr self-assigned this Nov 2, 2023
@cepetr cepetr force-pushed the cepetr/u5/flash-refactor branch 2 times, most recently from 1641d98 to c4d508e Compare November 6, 2023 14:54
@cepetr cepetr added T3T1 core Trezor Core firmware. Runs on Trezor Model T and T2B1. storage Trezor's internal storage implementation T1B1 legacy Trezor One T2T1 Trezor Model T T2B1 Trezor Safe 3 labels Nov 7, 2023
@cepetr cepetr changed the base branch from tychovrahe/u5/basic_support to cepetr/bootargs November 7, 2023 13:54
Copy link
Contributor

@TychoVrahe TychoVrahe left a comment

Choose a reason for hiding this comment

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

Couple of comments below.

core/embed/trezorhal/flash_otp.h Outdated Show resolved Hide resolved
storage/flash_area.c Show resolved Hide resolved
storage/flash_area.h Outdated Show resolved Hide resolved
storage/flash_area.c Show resolved Hide resolved
storage/flash_area.c Show resolved Hide resolved
storage/flash_area.c Outdated Show resolved Hide resolved
core/embed/trezorhal/stm32u5/flash.c Outdated Show resolved Hide resolved
storage/flash_area.c Outdated Show resolved Hide resolved
storage/flash_ll.h Show resolved Hide resolved
Copy link
Contributor

@TychoVrahe TychoVrahe left a comment

Choose a reason for hiding this comment

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

lgtm, please fix the residual style issues, squash and add [no changelog] to the commit message

Base automatically changed from cepetr/bootargs to tychovrahe/u5/basic_support November 14, 2023 12:32
@cepetr cepetr force-pushed the cepetr/u5/flash-refactor branch 4 times, most recently from 8a6223f to 1bb4680 Compare November 14, 2023 15:03
@TychoVrahe
Copy link
Contributor

One more thing to solve before merging this into U5 branch: since trustzone initialization refactor has now been merged and the allocation of flash pages between secure/non-secure is no longer only dependent on option bytes, flash_sector_is_secure needs to address this too.

@cepetr cepetr changed the base branch from tychovrahe/u5/basic_support to cepetr/u5/stackprot-refactor November 15, 2023 14:19
@cepetr
Copy link
Contributor Author

cepetr commented Nov 15, 2023

@TychoVrahe After our discussion, I've removed the detection of secure and non-secure pages, see a74a954

@cepetr cepetr force-pushed the cepetr/u5/stackprot-refactor branch from 3f94ef5 to 64508fa Compare November 15, 2023 14:44
Base automatically changed from cepetr/u5/stackprot-refactor to tychovrahe/u5/basic_support November 15, 2023 14:57
@cepetr cepetr merged commit 966ced9 into tychovrahe/u5/basic_support Nov 15, 2023
7 of 9 checks passed
@cepetr cepetr deleted the cepetr/u5/flash-refactor branch November 15, 2023 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Trezor Core firmware. Runs on Trezor Model T and T2B1. storage Trezor's internal storage implementation T1B1 legacy Trezor One T2B1 Trezor Safe 3 T2T1 Trezor Model T T3T1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants