Skip to content

[perso_fw] Refactor code to make the live set of variables during perso stages more clear - #31014

Merged
timothytrippel merged 7 commits into
lowRISC:earlgrey_1.0.0from
xorptr:perso_ft_provisioning_reduce_sram_usage
Aug 26, 2026
Merged

[perso_fw] Refactor code to make the live set of variables during perso stages more clear#31014
timothytrippel merged 7 commits into
lowRISC:earlgrey_1.0.0from
xorptr:perso_ft_provisioning_reduce_sram_usage

Conversation

@xorptr

@xorptr xorptr commented Aug 14, 2026

Copy link
Copy Markdown

This PR changes the perso firmware code to make it clear which set of variables are meant to be live during pre and post endorsement. It also puts the set of variables that are expected to be live during only one of the pre or post endorsement stage in a union to save some space in SRAM.

The PR consists of a series of commits with each commit making simple mechanical changes, trying to keep the behavior of the code same during each commit

  • Move global scope static variables into function local scoped static variables
  • Move variables with size <= 32 bytes on stack
  • Add const qualifier few function parameters
  • Push static variables to a location higher up in the call chain
  • Put static variables into union to save space. NOTE: This assumes that pre endorsement extension won't keep any references to data and use them in post endorsement extension, since putting the variables in a union will overwrite the pre-endorsement variables during post-endorsement stage.
  • Reduce parameter counts in functions
  • Reduce .bss use further by putting more static variables in union

Output from bloaty for ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf before this series of commits:

    FILE SIZE        VM SIZE
 --------------  --------------
  36.3%   727Ki   0.0%       0    .symtab
  21.4%   427Ki   0.0%       0    .debug_info
  12.1%   243Ki   0.0%       0    .debug_loc
  10.5%   210Ki   0.0%       0    .debug_line
   5.9%   118Ki   0.0%       0    .debug_str
   3.6%  71.8Ki  44.0%  71.8Ki    .text
   2.5%  50.2Ki   0.0%       0    .debug_abbrev
   1.9%  37.5Ki   0.0%       0    .debug_ranges
   1.8%  36.9Ki   0.0%       0    .strtab
   0.0%       0  19.6%  32.0Ki    .freertos.heap
   0.0%       0  18.6%  30.4Ki    .bss
   1.3%  25.4Ki  15.6%  25.4Ki    .rodata
   1.2%  23.3Ki   0.0%       0    .debug_frame
   0.8%  15.4Ki   0.0%       0    .ot.status_create_record
   0.3%  6.42Ki   0.0%       0    [Unmapped]
   0.2%  3.32Ki   0.0%       0    .logs.fields
   0.0%       0   1.2%  2.00Ki    .non_volatile_counter_3
   0.1%  1.29Ki   0.0%       0    [ELF Section Headers]
   0.0%    1024   0.6%    1024    .manifest
   0.0%     445   0.0%       0    .shstrtab
   0.0%     244   0.1%     244    .data
   0.0%     168   0.1%     168    .crt
   0.0%     160   0.0%       0    [ELF Program Headers]
   0.0%     136   0.0%       0    .debug_aranges
   0.0%     128   0.1%     128    .vectors
   0.0%      66   0.0%       0    .riscv.attributes
   0.0%      52   0.0%       0    [ELF Header]
   0.0%      24   0.0%      24    [LOAD #1 [RWX]]
 100.0%  1.95Mi 100.0%   163Ki    TOTAL

Output from bloaty for ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf after this series of commits:

    FILE SIZE        VM SIZE
 --------------  --------------
  36.3%   726Ki   0.0%       0    .symtab
  21.4%   428Ki   0.0%       0    .debug_info
  12.2%   244Ki   0.0%       0    .debug_loc
  10.5%   210Ki   0.0%       0    .debug_line
   5.9%   119Ki   0.0%       0    .debug_str
   3.6%  71.6Ki  44.4%  71.6Ki    .text
   2.5%  50.3Ki   0.0%       0    .debug_abbrev
   1.9%  37.2Ki   0.0%       0    .debug_ranges
   1.8%  36.4Ki   0.0%       0    .strtab
   0.0%       0  19.8%  32.0Ki    .freertos.heap
   0.0%       0  17.8%  28.8Ki    .bss
   1.3%  25.4Ki  15.8%  25.4Ki    .rodata
   1.2%  23.3Ki   0.0%       0    .debug_frame
   0.8%  15.4Ki   0.0%       0    .ot.status_create_record
   0.3%  6.61Ki   0.0%       0    [Unmapped]
   0.2%  3.32Ki   0.0%       0    .logs.fields
   0.0%       0   1.2%  2.00Ki    .non_volatile_counter_3
   0.1%  1.29Ki   0.0%       0    [ELF Section Headers]
   0.0%    1024   0.6%    1024    .manifest
   0.0%     445   0.0%       0    .shstrtab
   0.0%     220   0.1%     220    .data
   0.0%     168   0.1%     168    .crt
   0.0%     160   0.0%       0    [ELF Program Headers]
   0.0%     136   0.0%       0    .debug_aranges
   0.0%     128   0.1%     128    .vectors
   0.0%      66   0.0%       0    .riscv.attributes
   0.0%      52   0.0%       0    [ELF Header]
 100.0%  1.96Mi 100.0%   161Ki    TOTAL

These changes are on top of PR #30994

@xorptr
xorptr requested review from a team and cfrantz as code owners August 14, 2026 17:42
@xorptr
xorptr requested review from engdoreis and removed request for a team August 14, 2026 17:42
@xorptr
xorptr force-pushed the perso_ft_provisioning_reduce_sram_usage branch from 3e7c2dd to 9ba21b3 Compare August 17, 2026 23:07

typedef struct perso_stage_specific_data {
perso_stage_t stage;
union {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NOTE: This optimization assumes that personalize_extension_pre_cert_endorse does not store any references to the pre-endorsement stage specific data after the call ends. Since the underlying buffer will be re-used for post endorsement specific data, the data pointed to by such references will get invalidated.

Can we add this assumption in commit message somewhere in the comments?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. Added a comment in code on top of struct perso_stage_specific_data declaration (which has the union that necessitates this behavior). Also added a comment in the extension functions declarations in sw/device/silicon_creator/manuf/base/personalize_ext.h

@sasdf sasdf added the CI:Rerun Rerun failed CI jobs label Aug 19, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Aug 19, 2026
size_t curr_cert_size = 0;

// Generate UDS keys and (TBS) cert.
static_assert(sizeof(((perso_stages_shared_data_t *)NULL)->all_certs) >=

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than this construction, should we create a constant that sizes all_certs and then do this comparison with that constant?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Comment on lines +715 to +717
static_assert(sizeof(((perso_stages_shared_data_t *)NULL)->all_certs) >=
kCdi1MaxCertSizeBytes,
"CDI1 cert won't fit into `all_certs`");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And again here: compare constants rather than this exciting sizeof expression.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Comment on lines +680 to +682
static_assert(sizeof(((perso_stages_shared_data_t *)NULL)->all_certs) >=
kCdi0MaxCertSizeBytes,
"CDI0 cert won't fit into `all_certs`");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And again here: compare constants rather than this exciting sizeof expression.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

TRY(personalize_endorse_certificates(uj, &perso_data.stages_shared_data,
post_endorse_data, &cert_offsets));
TRY(hash_all_certs(&post_endorse_data->cert_buffer));
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leave a comment here clearly stating that there is no re-use of data in the post_endorse_data buffer between the stages and that (IIUC), the post_endorse_data buffer is used like a working memory buffer in each stage.

(That is, after each of personalize_endorse_certificates and hash_all_certs use the buffer as a temporary holding buffer and it has no useful data inside of it after the functions return).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Acck. Added a comment here

@sasdf sasdf added the CI:Rerun Rerun failed CI jobs label Aug 20, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Aug 20, 2026
@xorptr
xorptr force-pushed the perso_ft_provisioning_reduce_sram_usage branch from 9ba21b3 to ca72a0e Compare August 20, 2026 23:41

@xorptr xorptr left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Rebased on latest commits from PR #30994, and addressed review comments

size_t curr_cert_size = 0;

// Generate UDS keys and (TBS) cert.
static_assert(sizeof(((perso_stages_shared_data_t *)NULL)->all_certs) >=

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Comment on lines +680 to +682
static_assert(sizeof(((perso_stages_shared_data_t *)NULL)->all_certs) >=
kCdi0MaxCertSizeBytes,
"CDI0 cert won't fit into `all_certs`");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Comment on lines +715 to +717
static_assert(sizeof(((perso_stages_shared_data_t *)NULL)->all_certs) >=
kCdi1MaxCertSizeBytes,
"CDI1 cert won't fit into `all_certs`");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

TRY(personalize_endorse_certificates(uj, &perso_data.stages_shared_data,
post_endorse_data, &cert_offsets));
TRY(hash_all_certs(&post_endorse_data->cert_buffer));
{

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Acck. Added a comment here


typedef struct perso_stage_specific_data {
perso_stage_t stage;
union {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. Added a comment in code on top of struct perso_stage_specific_data declaration (which has the union that necessitates this behavior). Also added a comment in the extension functions declarations in sw/device/silicon_creator/manuf/base/personalize_ext.h

xorptr added 2 commits August 25, 2026 09:11
…ped static variables

This commits moves most of the global static variables into function
local scope.

The motive behind this refactor is to allow better reason about the
liveness of these variables when doing future changes to this code.
The declarations are pushed as deep in the call chain as possible based
on how the variables are used currently

- I removed `static` qualifier from `uds_key_ids` and `cdi_0_key_ids`
  since the compiler could not statically initialize fields with
  `uds_pubkey_id` (because now it is an input to the function)

- I added checks for size of `all_certs` against max size of DICE
  certificates. This should not cause any behavior change since
  `all_certs` is statically allocated to be much larger than max size of
  DICE certificates

- I removed `orig_num_objects_from_host`. Instead the function now has a
  local variable to temporarily store the original count, and the count
  is restored before the function returns

Size for few entries in `.bss` section from
`ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf`
after this change:

```
0.0%       0  18.6%  30.4Ki    .bss
  NAN%       0  26.4%  8.00Ki    provision.all_certs
  NAN%       0  16.5%  5.01Ki    provision.blob_from_host
  NAN%       0  16.5%  5.01Ki    provision.blob_to_host
  NAN%       0  13.2%  4.00Ki    owner_page
  NAN%       0   6.6%  2.00Ki    personalize_endorse_certificates.dice_page
  NAN%       0   6.5%  1.97Ki    main_spi_buf
  NAN%       0   3.3%    1024    hash_certificate.cert_buffer
  NAN%       0   2.3%     708    measure_otp_partition.otp_state
  NAN%       0   1.9%     588    cdi_1_tbs_buffer
  NAN%       0   1.6%     488    cdi_0_tbs_buffer
  NAN%       0   0.9%     272    ottf_console_spi_getc.info
  NAN%       0   0.7%     224    otbn_boot_attestation_key_clear.dmem_backup
  NAN%       0   0.3%     100    pxReadyTasksLists
  NAN%       0   0.2%      64    curr_tbs_signature
  NAN%       0   0.2%      64    personalize_gen_dice_certificates.cdi_0_pubkey
  NAN%       0   0.2%      64    personalize_gen_dice_certificates.curr_pubkey
  NAN%       0   0.2%      64    provision.uds_pubkey
  NAN%       0   0.2%      52    main_console
  NAN%       0   0.1%      40    provision.certgen_inputs
  NAN%       0   0.1%      40    status_report_list
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.attestation_binding_value
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.cdi_0_pubkey_id
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.cdi_1_pubkey_id
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.sealing_binding_value
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.uds_endorsement_key_id
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.zero_digest
  NAN%       0   0.1%      32    provision.otp_creator_sw_cfg_measurement
  NAN%       0   0.1%      32    provision.otp_owner_sw_cfg_measurement
  NAN%       0   0.1%      32    provision.otp_rot_creator_auth_codesign_measurement
  NAN%       0   0.1%      32    provision.otp_rot_creator_auth_state_measurement
  NAN%       0   0.1%      32    provision.uds_pubkey_id
```

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
This commit removes `static` qualifier from few static variables which
were moved to function scope in the previous commit. I arbitraily chose
32 bytes as the limit so as to not increase the total stack usage while
also reducing a little bit of `.bss` section use. The stack variables
are zero-initialized as they were earlier when they were static

Size for few entries in `.bss` section from
`ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf`
after this change:

```
0.0%       0  18.5%  30.1Ki    .bss
  NAN%       0  26.6%  8.00Ki    provision.all_certs
  NAN%       0  16.7%  5.01Ki    provision.blob_from_host
  NAN%       0  16.7%  5.01Ki    provision.blob_to_host
  NAN%       0  13.3%  4.00Ki    owner_page
  NAN%       0   6.7%  2.00Ki    personalize_endorse_certificates.dice_page
  NAN%       0   6.6%  1.97Ki    main_spi_buf
  NAN%       0   3.3%    1024    hash_certificate.cert_buffer
  NAN%       0   2.3%     704    measure_otp_partition.otp_state
  NAN%       0   1.9%     588    cdi_1_tbs_buffer
  NAN%       0   1.6%     488    cdi_0_tbs_buffer
  NAN%       0   0.9%     272    ottf_console_spi_getc.info
  NAN%       0   0.7%     224    otbn_boot_attestation_key_clear.dmem_backup
  NAN%       0   0.3%     100    pxReadyTasksLists
  NAN%       0   0.2%      64    curr_tbs_signature
  NAN%       0   0.2%      64    personalize_gen_dice_certificates.cdi_0_pubkey
  NAN%       0   0.2%      64    personalize_gen_dice_certificates.curr_pubkey
  NAN%       0   0.2%      64    provision.uds_pubkey
  NAN%       0   0.2%      52    main_console
  NAN%       0   0.1%      40    provision.certgen_inputs
  NAN%       0   0.1%      40    status_report_list
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.attestation_binding_value
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.sealing_binding_value
```

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
@xorptr
xorptr force-pushed the perso_ft_provisioning_reduce_sram_usage branch from ca72a0e to 08210eb Compare August 25, 2026 17:03
@xorptr

xorptr commented Aug 25, 2026

Copy link
Copy Markdown
Author

Rebased on latest earlgrey_1.0.0 branch (commit aea6d61c3d38c9bc4b460d6e4ccd40004dc4edf0) and resolved merge conflicts. Also fixed print_certs.c which was updated in earlgrey_1.0.0 to work with the changes in this PR

xorptr added 5 commits August 25, 2026 14:10
This commits makes appropriate function parameters `const` qualified.
The motive behind this change is to make it easier to reason about
mutability of the static variables left in the previous commit.

A notable refactor in this commit is change from
`perso_tlv_get_cert_obj` to `perso_tlv_get_cert_obj_view`. The new
function now returns `perso_tlv_cert_obj_view_t` instead of
`perso_tlv_cert_obj_t`. `perso_tlv_cert_obj_view_t` is similar to
`perso_tlv_cert_obj_t`, but internally it uses const pointers to the
underlying buffer (hence giving only immutable access/view to the
underlying buffer). This allows making the buffer passed to
`perso_tlv_get_cert_obj_view` `const` qualified, which in turn helps
confirm that `personalize_endorse_certificates` uses `blob_to_host` only
for reads.

I also changes `zero_digest` to `const static` so that it can be moved
to `.rodata`

Size for few entries in `.bss` section from
`ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf`
after this change:

```
0.0%       0  18.5%  30.1Ki    .bss
  NAN%       0  26.6%  8.00Ki    provision.all_certs
  NAN%       0  16.7%  5.01Ki    provision.blob_from_host
  NAN%       0  16.7%  5.01Ki    provision.blob_to_host
  NAN%       0  13.3%  4.00Ki    owner_page
  NAN%       0   6.7%  2.00Ki    personalize_endorse_certificates.dice_page
  NAN%       0   6.6%  1.97Ki    main_spi_buf
  NAN%       0   3.3%    1024    hash_certificate.cert_buffer
  NAN%       0   2.3%     704    measure_otp_partition.otp_state
  NAN%       0   1.9%     588    cdi_1_tbs_buffer
  NAN%       0   1.6%     488    cdi_0_tbs_buffer
  NAN%       0   0.9%     272    ottf_console_spi_getc.info
  NAN%       0   0.7%     224    otbn_boot_attestation_key_clear.dmem_backup
  NAN%       0   0.3%     100    pxReadyTasksLists
  NAN%       0   0.2%      64    curr_tbs_signature
  NAN%       0   0.2%      64    personalize_gen_dice_certificates.cdi_0_pubkey
  NAN%       0   0.2%      64    personalize_gen_dice_certificates.curr_pubkey
  NAN%       0   0.2%      64    provision.uds_pubkey
  NAN%       0   0.2%      52    main_console
  NAN%       0   0.1%      40    provision.certgen_inputs
  NAN%       0   0.1%      40    status_report_list
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.attestation_binding_value
  NAN%       0   0.1%      32    personalize_gen_dice_certificates.sealing_binding_value
```

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
…chain

This commit moves the static variables that were not marked with `const`
qualifier up in the call chain. I have moved them to the function where
the 2 major stages of provisioning occur: pre-endorsement and
post-endorsement. The motive behind this changes is to (in the future)
split the variables into different sets based on which stages use them

I also added 2 types `cert_scratch_buffer_t` and
`aligned_dice_storage_page_t` so that the alignment requirement on
`cert_buffer` and `dice_page` can be expressed in function parameters
until it is not needed anymore

Size for few entries in `.bss` section from
`ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf`
after this change:

```
0.0%       0  18.5%  30.1Ki    .bss
  NAN%       0  26.6%  8.00Ki    provision.all_certs
  NAN%       0  16.7%  5.01Ki    provision.blob_from_host
  NAN%       0  16.7%  5.01Ki    provision.blob_to_host
  NAN%       0  13.3%  4.00Ki    owner_page
  NAN%       0   6.7%  2.00Ki    provision.dice_page
  NAN%       0   6.6%  1.97Ki    main_spi_buf
  NAN%       0   3.3%    1024    provision.cert_buffer
  NAN%       0   2.3%     704    provision.otp_state
  NAN%       0   1.9%     588    cdi_1_tbs_buffer
  NAN%       0   1.6%     488    cdi_0_tbs_buffer
  NAN%       0   0.9%     272    ottf_console_spi_getc.info
  NAN%       0   0.7%     224    otbn_boot_attestation_key_clear.dmem_backup
  NAN%       0   0.3%     100    pxReadyTasksLists
  NAN%       0   0.2%      64    curr_tbs_signature
  NAN%       0   0.2%      64    provision.cdi_0_pubkey
  NAN%       0   0.2%      64    provision.curr_pubkey
  NAN%       0   0.2%      64    provision.uds_pubkey
  NAN%       0   0.2%      52    main_console
  NAN%       0   0.1%      40    provision.certgen_inputs
  NAN%       0   0.1%      40    status_report_list
  NAN%       0   0.1%      32    provision.attestation_binding_value
  NAN%       0   0.1%      32    provision.sealing_binding_value
```

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
This commit splits the static variables moved up the call chain in the
previous commit. The variables are split into 2 categories at first
level: variables that are used by both pre-endorsement and
post-endorsement stages, and variables that are used by only one of
those stages. The variables used only by one stage are put into a union
to save space in SRAM. Since the stages occur one after another, only
the stage specific and shared variables need to be live for a given
stage.

**NOTE: This optimization assumes that
`personalize_extension_pre_cert_endorse` does not store any references
to the pre-endorsement stage specific data after the call ends.** Since
the underlying buffer will be re-used for post endorsement specific
data, the data pointed to by such references will get invalidated.

Size for few entries in `.bss` section from
`ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf`
after this change:

```
0.0%       0  18.3%  29.8Ki    .bss
  NAN%       0  72.9%  21.7Ki    provision.perso_data
  NAN%       0  13.4%  4.00Ki    owner_page
  NAN%       0   6.6%  1.97Ki    main_spi_buf
  NAN%       0   1.9%     588    cdi_1_tbs_buffer
  NAN%       0   1.6%     488    cdi_0_tbs_buffer
  NAN%       0   0.9%     272    ottf_console_spi_getc.info
  NAN%       0   0.7%     224    otbn_boot_attestation_key_clear.dmem_backup
  NAN%       0   0.3%     100    pxReadyTasksLists
  NAN%       0   0.2%      64    curr_tbs_signature
  NAN%       0   0.2%      52    main_console
  NAN%       0   0.1%      40    status_report_list
  NAN%       0   0.1%      24    rand_testutils_rng_ctx
```

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
This commit changes the function signatures to reduce the number of
parameters. In the previous commit, the functions had too many
parameters and many parameters had the same type. So a simple mistake
such as swapping 2 parameters in the long list would be hard to detect.
With a smaller list and different types for parameters where possible,
such mistakes could be avoided. New types are also added to help with
reducing the parameters count.

Size for few entries in `.bss` section from
`ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf`
after this change:

```
0.0%       0  18.3%  29.8Ki    .bss
  NAN%       0  72.9%  21.7Ki    provision.perso_data
  NAN%       0  13.4%  4.00Ki    owner_page
  NAN%       0   6.6%  1.97Ki    main_spi_buf
  NAN%       0   1.9%     588    cdi_1_tbs_buffer
  NAN%       0   1.6%     488    cdi_0_tbs_buffer
  NAN%       0   0.9%     272    ottf_console_spi_getc.info
  NAN%       0   0.7%     224    otbn_boot_attestation_key_clear.dmem_backup
  NAN%       0   0.3%     100    pxReadyTasksLists
  NAN%       0   0.2%      64    curr_tbs_signature
  NAN%       0   0.2%      52    main_console
  NAN%       0   0.1%      40    status_report_list
  NAN%       0   0.1%      24    rand_testutils_rng_ctx
  NAN%       0   0.1%      20    xDelayedTaskList1
```

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
… in union

Based on the observation that `dice_page` and `certs_buffer` are not
live together, this commit further splits post-endorsement stage
specific static variables into 2 groups and puts them into a union. This
saves a little bit more space in `.bss` section.

Size for few entries in `.bss` section from
`ft_personalize_emulation_dice_mldsa_sim_qemu_rom_with_fake_keys.elf`
after this change:

```
0.0%       0  17.8%  28.8Ki    .bss
  NAN%       0  72.0%  20.7Ki    provision.perso_data
  NAN%       0  13.9%  4.00Ki    owner_page
  NAN%       0   6.9%  1.97Ki    main_spi_buf
  NAN%       0   2.0%     588    cdi_1_tbs_buffer
  NAN%       0   1.7%     488    cdi_0_tbs_buffer
  NAN%       0   0.9%     272    ottf_console_spi_getc.info
  NAN%       0   0.8%     224    otbn_boot_attestation_key_clear.dmem_backup
  NAN%       0   0.3%     100    pxReadyTasksLists
  NAN%       0   0.2%      64    curr_tbs_signature
  NAN%       0   0.2%      52    main_console
  NAN%       0   0.1%      40    status_report_list
  NAN%       0   0.1%      24    rand_testutils_rng_ctx
  NAN%       0   0.1%      20    xDelayedTaskList1
```

Signed-off-by: Lovepreet Singh <lpsingh@google.com>
@xorptr
xorptr force-pushed the perso_ft_provisioning_reduce_sram_usage branch from 08210eb to 8db9142 Compare August 25, 2026 21:10
@timothytrippel
timothytrippel merged commit 80b97bc into lowRISC:earlgrey_1.0.0 Aug 26, 2026
35 checks passed
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.

4 participants