ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ota_commit.c
Go to the documentation of this file.
1
23
24#include "ota_commit.h"
25
26#include <stdint.h>
27
28#include "ra8_check.h"
29#include "ra8_err.h"
30
31static const char* s_tag = "OTACMT";
32
40static bool s_pending = false;
41
50
58static uint32_t s_bank_config = 0U;
59
86
91{
92 if ((target != k_ra8_ota_bank_a) && (target != k_ra8_ota_bank_b)) {
94 }
95 if (s_pending) {
97 }
98#ifdef RA8_OFF_TARGET
99 /* Host shadow: record the armed target so the argument-validation + single-shot
100 * idempotency policy stays unit-testable without touching real flash. */
101 s_pending_target = target;
102 s_pending = true;
103 (void)s_tag;
104 return k_ra8_ok;
105#else
106 /* FAIL-CLOSED on silicon (T5-10). Arming a swap means programming the boot
107 * option region (an OFS3 / BTFLG option-byte write behind the PRCR unlock),
108 * which is brick-risky and not yet wired -- it is bench-gated. Refuse with a
109 * real error instead of a fake k_ra8_ok so a caller can never believe a swap
110 * was armed when no flash work happened.
111 * TODO(real OFS3/BTFLG boot-bank option-byte swap write -- bench-gated,
112 * brick-risky): unlock PRCR, program the boot option byte via ra8_flash_*,
113 * re-lock PRCR, confirm by read-back, then arm the shadow and return k_ra8_ok. */
114 (void)s_tag;
116#endif
117}
118
120{
121 RA8_CHECK_NULL_PTR(out_target, s_tag, "pending: out_target");
122 if (!s_pending) {
123 return k_ra8_err_no_data;
124 }
125 *out_target = s_pending_target;
126 return k_ra8_ok;
127}
128
133{
134 /* Mask reserved bits so an NS caller can only touch the bank-select field.
135 * This is the value the real option-region write would persist. */
136 const uint32_t masked = raw_value & (uint32_t)k_ra8_ota_bank_config_allowed;
137#ifdef RA8_OFF_TARGET
138 s_bank_config = masked;
139 return k_ra8_ok;
140#else
141 /* FAIL-CLOSED on silicon (T5-10): persisting the masked value is the same
142 * brick-risky, bench-gated option-region write as swap_bank, so refuse rather
143 * than report a fake success.
144 * TODO(real bank-config option-region write -- bench-gated, brick-risky):
145 * unlock PRCR, program `masked` into the option region, re-lock, confirm. */
146 (void)masked;
148#endif
149}
150
152{
153 RA8_CHECK_NULL_PTR(out_value, s_tag, "get_bank_config: out_value");
154 *out_value = s_bank_config;
155 return k_ra8_ok;
156}
ra8_err_t ra8_ota_commit_set_bank_config(uint32_t raw_value)
Implementation of ra8_ota_commit_set_bank_config() – masks reserved bits, then host shadow under RA8_...
Definition ota_commit.c:132
ra8_err_t ra8_ota_commit_pending(ra8_ota_bank_t *out_target)
Read back the pending swap target (for tests + diagnostics).
Definition ota_commit.c:119
static ra8_ota_bank_t s_pending_target
Bank that will be active after the next reset, when s_pending.
Definition ota_commit.c:49
ra8_err_t ra8_ota_commit_get_bank_config(uint32_t *out_value)
Read back the bank-config shadow (for tests).
Definition ota_commit.c:151
static bool s_pending
Whether a swap-bank request is currently armed.
Definition ota_commit.c:40
ra8_err_t ra8_ota_commit_swap_bank(ra8_ota_bank_t target)
Implementation of ra8_ota_commit_swap_bank() – host shadow under RA8_OFF_TARGET; fail-closed on silic...
Definition ota_commit.c:90
static uint32_t s_bank_config
Shadow of the masked bank-config register.
Definition ota_commit.c:58
ra8_err_t ra8_ota_commit_reset(void)
Reset the OTA commit shadow registers to power-on defaults.
Definition ota_commit.c:79
Secure-side OTA bank commit + flash-bank-config write.
@ k_ra8_ota_bank_config_allowed
Only the 2-bit BANK_SEL field.
Definition ota_commit.h:67
ra8_ota_bank_t
Bank selector used by ra8_ota_commit_swap_bank.
Definition ota_commit.h:51
@ k_ra8_ota_bank_b
Bank B is the next-boot target.
Definition ota_commit.h:53
@ k_ra8_ota_bank_a
Bank A is the next-boot target.
Definition ota_commit.h:52
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
Definition ra8_err.h:180
@ k_ra8_err_no_data
No application data available (e.g.
Definition ra8_err.h:202
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
Definition ra8_err.h:161
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546