(review comment) remove hal_otp.h

pull/740/head
Daniele Lacamera 2026-03-31 07:20:45 +02:00
parent 6b6d27de5c
commit 909fbeb35e
4 changed files with 2 additions and 114 deletions

View File

@ -25,7 +25,6 @@
#include <string.h>
#include "hal.h"
#include "hal_otp.h"
#include "hal/stm32h5.h"
#include "hal/armv8m_tz.h"
@ -765,7 +764,7 @@ void hal_prepare_boot(void)
int hal_flash_otp_set_readonly(uint32_t flashAddress, uint16_t length)
{
uint32_t start_block = (flashAddress - FLASH_OTP_BASE) / FLASH_OTP_BLOCK_SIZE;
uint32_t count = hal_otp_blocks_for_length(length, FLASH_OTP_BLOCK_SIZE);
uint32_t count = (length + FLASH_OTP_BLOCK_SIZE - 1U) / FLASH_OTP_BLOCK_SIZE;
uint32_t bmap = 0;
unsigned int i;
if (start_block + count > 32)

View File

@ -1,35 +0,0 @@
/* hal_otp.h
*
* OTP helper definitions.
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef WOLFBOOT_HAL_OTP_H
#define WOLFBOOT_HAL_OTP_H
#include <stdint.h>
static inline uint32_t hal_otp_blocks_for_length(uint32_t length,
uint32_t block_size)
{
return (length + block_size - 1U) / block_size;
}
#endif /* WOLFBOOT_HAL_OTP_H */

View File

@ -49,7 +49,7 @@ TESTS:=unit-parser unit-fdt unit-extflash unit-string unit-spi-flash unit-aes128
unit-update-flash-enc unit-update-ram unit-pkcs11_store unit-psa_store unit-disk \
unit-update-disk unit-multiboot unit-boot-x86-fsp unit-qspi-flash unit-tpm-rsa-exp \
unit-image-nopart unit-image-sha384 unit-image-sha3-384 unit-store-sbrk \
unit-tpm-blob unit-policy-sign unit-rot-auth unit-sdhci-response-bits unit-hal-otp
unit-tpm-blob unit-policy-sign unit-rot-auth unit-sdhci-response-bits
TESTS+=unit-tpm-check-rot-auth
all: $(TESTS)
@ -167,9 +167,6 @@ unit-sdhci-response-bits: ../../include/target.h unit-sdhci-response-bits.c
gcc -o $@ $^ $(CFLAGS) -ffunction-sections -fdata-sections $(LDFLAGS) \
-Wl,--gc-sections
unit-hal-otp: ../../include/target.h unit-hal-otp.c
gcc -o $@ $^ $(CFLAGS) $(LDFLAGS)
unit-aes128: ../../include/target.h unit-extflash.c
gcc -o $@ $^ $(CFLAGS) $(LDFLAGS)

View File

@ -1,73 +0,0 @@
/* unit-hal-otp.c
*
* Unit tests for OTP block rounding helpers.
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <check.h>
#include <stdint.h>
#include "../../include/hal_otp.h"
#define FLASH_OTP_BLOCK_SIZE 64U
#define OTP_BLOCKS 32U
START_TEST(test_rounds_partial_block_before_bounds_check)
{
uint32_t start_block = OTP_BLOCKS - 1U;
uint32_t count = hal_otp_blocks_for_length(1U, FLASH_OTP_BLOCK_SIZE);
ck_assert_uint_eq(count, 1U);
ck_assert_uint_gt(start_block + count, OTP_BLOCKS - 1U);
}
END_TEST
START_TEST(test_exact_multiple_keeps_exact_block_count)
{
ck_assert_uint_eq(
hal_otp_blocks_for_length(FLASH_OTP_BLOCK_SIZE * 2U, FLASH_OTP_BLOCK_SIZE),
2U);
}
END_TEST
static Suite *hal_otp_suite(void)
{
Suite *s = suite_create("hal-otp");
TCase *tc = tcase_create("rounding");
tcase_add_test(tc, test_rounds_partial_block_before_bounds_check);
tcase_add_test(tc, test_exact_multiple_keeps_exact_block_count);
suite_add_tcase(s, tc);
return s;
}
int main(void)
{
int fails;
Suite *s = hal_otp_suite();
SRunner *sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
fails = srunner_ntests_failed(sr);
srunner_free(sr);
return fails;
}