|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Secure-side OTA bank commit + flash-bank-config write. More...
Go to the source code of this file.
Enumerations | |
| enum | ra8_ota_bank_t : uint8_t { k_ra8_ota_bank_a = 0U , k_ra8_ota_bank_b = 1U } |
| Bank selector used by ra8_ota_commit_swap_bank. More... | |
| enum | ra8_ota_bank_config_mask_t : uint32_t { k_ra8_ota_bank_config_allowed = 0x00000003U } |
| Allowed-bit masks for the bank-config register. More... | |
Functions | |
| ra8_err_t | ra8_ota_commit_reset (void) |
| Reset the secure OTA shadow (drops any pending commit). | |
| ra8_err_t | ra8_ota_commit_swap_bank (ra8_ota_bank_t target) |
| Arm the boot ROM to start from target on next reset. | |
| ra8_err_t | ra8_ota_commit_pending (ra8_ota_bank_t *out_target) |
| Read back the pending swap target (for tests + diagnostics). | |
| ra8_err_t | ra8_ota_commit_set_bank_config (uint32_t raw_value) |
| Write the bank-config register, masked to the allowed bits. | |
| ra8_err_t | ra8_ota_commit_get_bank_config (uint32_t *out_value) |
| Read back the bank-config shadow (for tests). | |
Secure-side OTA bank commit + flash-bank-config write.
The RA8D2 supports a swappable A/B bank layout in MRAM where the boot ROM picks the active bank from a flash-config option byte. The two operations exposed here are privileged:
Both writes touch the option region (an OFS3 / BTFLG option-byte program behind the PRCR unlock), which is brick-risky and not yet wired – it is bench-gated. On silicon both functions are therefore FAIL-CLOSED: they validate their arguments and then return k_ra8_err_not_supported instead of a fake k_ra8_ok (T5-10). Under RA8_OFF_TARGET they run against an in-memory shadow so the unit tests can verify the masking and re-entry guards without touching real flash. The real ra8_flash_* call sites are marked TODO at each fail-closed branch in the implementation.
Definition in file ota_commit.h.
| enum ra8_ota_bank_config_mask_t : uint32_t |
Allowed-bit masks for the bank-config register.
The bank-config register has a handful of fields the secure side exposes to NS callers; everything else (debug-disable, integrity check mode, lifetime fuses) is filtered out before the write lands.
| Enumerator | |
|---|---|
| k_ra8_ota_bank_config_allowed | Only the 2-bit BANK_SEL field. |
Definition at line 66 of file ota_commit.h.
| enum ra8_ota_bank_t : uint8_t |
Bank selector used by ra8_ota_commit_swap_bank.
| Enumerator | |
|---|---|
| k_ra8_ota_bank_a | Bank A is the next-boot target. |
| k_ra8_ota_bank_b | Bank B is the next-boot target. |
Definition at line 51 of file ota_commit.h.
|
nodiscard |
Read back the bank-config shadow (for tests).
| [out] | out_value | Filtered value. |
| k_ra8_ok | Value written. |
| k_ra8_err_null_ptr | out_value was NULL. |
Definition at line 151 of file ota_commit.c.
References k_ra8_ok, RA8_CHECK_NULL_PTR, s_bank_config, and s_tag.
|
nodiscard |
Read back the pending swap target (for tests + diagnostics).
| [out] | out_target | Pending bank, valid only when the function returns k_ra8_ok. |
| k_ra8_ok | A swap is pending; target written. |
| k_ra8_err_no_data | No swap pending. |
| k_ra8_err_null_ptr | out_target was NULL. |
Definition at line 119 of file ota_commit.c.
References k_ra8_err_no_data, k_ra8_ok, RA8_CHECK_NULL_PTR, s_pending, s_pending_target, and s_tag.
|
nodiscard |
Reset the secure OTA shadow (drops any pending commit).
Reset the secure OTA shadow (drops any pending commit).
Clears the pending swap-bank request, returns the pending target to bank A, and zeroes the bank-config shadow. Used by the unit tests between scenarios and during secure-side bring-up.
| k_ra8_ok | Always; the operation cannot fail. |
Definition at line 79 of file ota_commit.c.
References k_ra8_ok, k_ra8_ota_bank_a, s_bank_config, s_pending, and s_pending_target.
|
nodiscard |
Write the bank-config register, masked to the allowed bits.
Any bit outside k_ra8_ota_bank_config_allowed is masked off first so an NS caller can only touch the bank-select field. Persisting that masked value is an option-region write (same PRCR-unlocked, brick-risky path as ra8_ota_commit_swap_bank); it is not yet wired, so on silicon this function is FAIL-CLOSED: it returns k_ra8_err_not_supported and writes nothing, rather than a fake k_ra8_ok (T5-10). Under RA8_OFF_TARGET it records the masked value in the host shadow so the masking policy stays unit-testable. This is the entry point behind the ra8_nsc_flash_bank_config veneer.
| [in] | raw_value | Raw register value supplied by NS code. |
| k_ra8_ok | (RA8_OFF_TARGET only) masked value recorded in the host shadow. |
| k_ra8_err_not_supported | (silicon build) the real option-region write is bench-gated – fail-closed, nothing written. |
Write the bank-config register, masked to the allowed bits.
Definition at line 132 of file ota_commit.c.
References k_ra8_err_not_supported, k_ra8_ok, k_ra8_ota_bank_config_allowed, and s_bank_config.
Referenced by ra8_nsc_flash_bank_config().
|
nodiscard |
Arm the boot ROM to start from target on next reset.
Arming a boot-bank swap requires programming the boot option region (an OFS3 / BTFLG option-byte write behind the PRCR unlock). That write is brick-risky and is not yet wired – it is bench-gated – so on silicon this function is FAIL-CLOSED: after the argument + idempotency checks it returns k_ra8_err_not_supported and arms nothing, rather than reporting a fake k_ra8_ok for a commit that never touched flash (T5-10). Under RA8_OFF_TARGET it instead records the request in a host shadow so the unit tests can exercise the argument-validation + single-shot idempotency policy without real flash. A caller therefore never mistakes an unwritten option byte for an armed swap.
| [in] | target | Bank selector (k_ra8_ota_bank_a / k_ra8_ota_bank_b). |
| k_ra8_ok | (RA8_OFF_TARGET only) swap armed in the host shadow. |
| k_ra8_err_invalid_arg | target not in ra8_ota_bank_t. |
| k_ra8_err_invalid_state | Another commit is already pending. |
| k_ra8_err_not_supported | (silicon build) the real option-byte bank-swap write is bench-gated – fail-closed, nothing armed. |
Arm the boot ROM to start from target on next reset.
Definition at line 90 of file ota_commit.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_err_not_supported, k_ra8_ok, k_ra8_ota_bank_a, k_ra8_ota_bank_b, s_pending, s_pending_target, and s_tag.
Referenced by ra8_nsc_ota_commit().