refactor: Remove -Wno-format from storage related components

This commit is contained in:
Adam Múdry 2023-10-17 16:13:32 +02:00 committed by BOT
parent c79dc27961
commit e151184da7
25 changed files with 135 additions and 131 deletions

View File

@ -41,5 +41,3 @@ if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set_property(SOURCE ${cache_srcs} APPEND_STRING PROPERTY COMPILE_FLAGS
" -fno-inline-small-functions -fno-inline-functions-called-once")
endif()
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -7,6 +7,7 @@
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <inttypes.h>
#if __has_include(<bsd/string.h>)
// for strlcpy
#include <bsd/string.h>
@ -106,8 +107,8 @@ esp_err_t esp_partition_file_mmap(const uint8_t **part_desc_addr_start)
if (strlen(s_esp_partition_file_mmap_ctrl_input.flash_file_name) > 0) {
// Open existing file. If size or partition table file were specified, raise errors
if (s_esp_partition_file_mmap_ctrl_input.flash_file_size > 0) {
ESP_LOGE(TAG, "Flash emulation file size: %u was specified while together with the file name: %s (illegal). Use file size = 0",
s_esp_partition_file_mmap_ctrl_input.flash_file_size,
ESP_LOGE(TAG, "Flash emulation file size: %" PRIu32" was specified while together with the file name: %s (illegal). Use file size = 0",
(uint32_t) s_esp_partition_file_mmap_ctrl_input.flash_file_size,
s_esp_partition_file_mmap_ctrl_input.flash_file_name);
return ESP_ERR_INVALID_ARG;
}
@ -133,9 +134,9 @@ esp_err_t esp_partition_file_mmap(const uint8_t **part_desc_addr_start)
// conflicting input
if (has_partfile != has_len) {
ESP_LOGE(TAG, "Invalid combination of Partition file name: %s flash file size: %u was specified. Use either both parameters or none.",
ESP_LOGE(TAG, "Invalid combination of Partition file name: %s flash file size: %" PRIu32 " was specified. Use either both parameters or none.",
s_esp_partition_file_mmap_ctrl_input.partition_file_name,
s_esp_partition_file_mmap_ctrl_input.flash_file_size);
(uint32_t) s_esp_partition_file_mmap_ctrl_input.flash_file_size);
return ESP_ERR_INVALID_ARG;
}
@ -211,7 +212,7 @@ esp_err_t esp_partition_file_mmap(const uint8_t **part_desc_addr_start)
break;
}
ESP_LOGV(TAG, "SPIFLASH memory emulation file created: %s (size: %d B)", s_esp_partition_file_mmap_ctrl_act.flash_file_name, s_esp_partition_file_mmap_ctrl_act.flash_file_size);
ESP_LOGV(TAG, "SPIFLASH memory emulation file created: %s (size: %" PRIu32 " B)", s_esp_partition_file_mmap_ctrl_act.flash_file_name, (uint32_t) s_esp_partition_file_mmap_ctrl_act.flash_file_size);
// create memory-mapping for the flash holder file
if ((s_spiflash_mem_file_buf = mmap(NULL, s_esp_partition_file_mmap_ctrl_act.flash_file_size, PROT_READ | PROT_WRITE, MAP_SHARED, s_spiflash_mem_file_fd, 0)) == MAP_FAILED) {
@ -242,10 +243,10 @@ esp_err_t esp_partition_file_mmap(const uint8_t **part_desc_addr_start)
// check whether partition table fits into the memory mapped file
if (partition_table_file_size + ESP_PARTITION_TABLE_OFFSET > s_esp_partition_file_mmap_ctrl_act.flash_file_size) {
ESP_LOGE(TAG, "Flash file: %s (size: %d B) cannot hold partition table requiring %d B",
ESP_LOGE(TAG, "Flash file: %s (size: %" PRIu32 " B) cannot hold partition table requiring %d B",
s_esp_partition_file_mmap_ctrl_act.flash_file_name,
s_esp_partition_file_mmap_ctrl_act.flash_file_size,
partition_table_file_size + ESP_PARTITION_TABLE_OFFSET);
(uint32_t) s_esp_partition_file_mmap_ctrl_act.flash_file_size,
(int) (partition_table_file_size + ESP_PARTITION_TABLE_OFFSET));
ret = ESP_ERR_INVALID_SIZE;
break;
}
@ -294,9 +295,9 @@ esp_err_t esp_partition_file_mmap(const uint8_t **part_desc_addr_start)
ESP_LOGV(TAG, " label: %s", p_part_item->label);
ESP_LOGV(TAG, " type: %s", esp_partition_type_to_str(p_part_item->type));
ESP_LOGV(TAG, " subtype: %s", esp_partition_subtype_to_str(p_part_item->type, p_part_item->subtype));
ESP_LOGV(TAG, " offset: 0x%08X", p_part_item->pos.offset);
ESP_LOGV(TAG, " size: %d", p_part_item->pos.size);
ESP_LOGV(TAG, " flags: %d", p_part_item->flags);
ESP_LOGV(TAG, " offset: 0x%08" PRIX32, (uint32_t) p_part_item->pos.offset);
ESP_LOGV(TAG, " size: %" PRIu32, (uint32_t) p_part_item->pos.size);
ESP_LOGV(TAG, " flags: %" PRIu32, (uint32_t) p_part_item->flags);
part_ptr += sizeof(esp_partition_info_t);
}
@ -383,7 +384,7 @@ esp_err_t esp_partition_write(const esp_partition_t *partition, size_t dst_offse
}
void *dst_addr = s_spiflash_mem_file_buf + partition->address + dst_offset;
ESP_LOGV(TAG, "esp_partition_write(): partition=%s dst_offset=%zu src=%p size=%zu (real dst address: %p)", partition->label, dst_offset, src, size, dst_addr);
ESP_LOGV(TAG, "esp_partition_write(): partition=%s dst_offset=%" PRIu32 " src=%p size=%" PRIu32 " (real dst address: %p)", partition->label, (uint32_t) dst_offset, src, (uint32_t) size, dst_addr);
// local size, can be modified by the write hook in case of simulated power-off
size_t new_size = size;
@ -428,7 +429,7 @@ esp_err_t esp_partition_read(const esp_partition_t *partition, size_t src_offset
}
void *src_addr = s_spiflash_mem_file_buf + partition->address + src_offset;
ESP_LOGV(TAG, "esp_partition_read(): partition=%s src_offset=%zu dst=%p size=%zu (real src address: %p)", partition->label, src_offset, dst, size, src_addr);
ESP_LOGV(TAG, "esp_partition_read(): partition=%s src_offset=%" PRIu32 " dst=%p size=%" PRIu32 " (real src address: %p)", partition->label, (uint32_t) src_offset, dst, (uint32_t) size, src_addr);
memcpy(dst, src_addr, size);
@ -464,7 +465,7 @@ esp_err_t esp_partition_erase_range(const esp_partition_t *partition, size_t off
}
void *target_addr = s_spiflash_mem_file_buf + partition->address + offset;
ESP_LOGV(TAG, "esp_partition_erase_range(): partition=%s offset=%zu size=%zu (real target address: %p)", partition->label, offset, size, target_addr);
ESP_LOGV(TAG, "esp_partition_erase_range(): partition=%s offset=%" PRIu32 " size=%" PRIu32 " (real target address: %p)", partition->label, (uint32_t) offset, (uint32_t) size, target_addr);
// local size to be potentially updated by the hook in case of power-off event
size_t new_size = size;
@ -496,7 +497,7 @@ esp_err_t esp_partition_mmap(const esp_partition_t *partition, size_t offset, si
esp_partition_mmap_memory_t memory,
const void **out_ptr, esp_partition_mmap_handle_t *out_handle)
{
ESP_LOGV(TAG, "esp_partition_mmap(): partition=%s offset=%zu size=%zu", partition->label, offset, size);
ESP_LOGV(TAG, "esp_partition_mmap(): partition=%s offset=%" PRIu32 " size=%" PRIu32 "", partition->label, (uint32_t) offset, (uint32_t) size);
assert(partition != NULL);
if (offset > partition->size) {

View File

@ -1,4 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES test_utils esp_partition esp_system app_update bootloader_support spi_flash)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -40,5 +40,3 @@ else()
target_sources(${COMPONENT_LIB} PRIVATE "src/nvs_encrypted_partition.cpp")
target_link_libraries(${COMPONENT_LIB} PRIVATE idf::mbedtls)
endif()
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -1,9 +1,10 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "nvs_page.hpp"
#include <inttypes.h>
#include <esp_rom_crc.h>
#include <cstdio>
#include <cstring>
@ -1063,7 +1064,8 @@ const char* Page::pageStateToName(PageState ps)
void Page::debugDump() const
{
printf("state=%x (%s) addr=%x seq=%d\nfirstUsed=%d nextFree=%d used=%d erased=%d\n", (uint32_t) mState, pageStateToName(mState), mBaseAddress, mSeqNumber, static_cast<int>(mFirstUsedEntry), static_cast<int>(mNextFreeEntry), mUsedEntryCount, mErasedEntryCount);
printf("state=%" PRIx32 " (%s) addr=%" PRIx32 " seq=%" PRIu32 "\nfirstUsed=%" PRIu32 " nextFree=%" PRIu32 " used=%" PRIu16 " erased=%" PRIu16 "\n",
static_cast<uint32_t>(mState), pageStateToName(mState), mBaseAddress, mSeqNumber, static_cast<uint32_t>(mFirstUsedEntry), static_cast<uint32_t>(mNextFreeEntry), mUsedEntryCount, mErasedEntryCount);
size_t skip = 0;
for (size_t i = 0; i < ENTRY_COUNT; ++i) {
printf("%3d: ", static_cast<int>(i));
@ -1080,7 +1082,8 @@ void Page::debugDump() const
Item item;
readEntry(i, item);
if (skip == 0) {
printf("W ns=%2u type=%2u span=%3u key=\"%s\" chunkIdx=%d len=%d\n", item.nsIndex, static_cast<unsigned>(item.datatype), item.span, item.key, item.chunkIndex, (item.span != 1)?((int)item.varLength.dataSize):-1);
printf("W ns=%2" PRIu8 " type=%2" PRIu8 " span=%3" PRIu8 " key=\"%s\" chunkIdx=%" PRIu8 " len=%" PRIi32 "\n",
item.nsIndex, static_cast<uint8_t>(item.datatype), item.span, item.key, item.chunkIndex, (item.span != 1)?(static_cast<int32_t>(item.varLength.dataSize)):(-1));
if (item.span > 0 && item.span <= ENTRY_COUNT - i) {
skip = item.span - 1;
} else {

View File

@ -13,5 +13,3 @@ idf_component_register(SRCS "sdmmc_cmd.c"
INCLUDE_DIRS include
REQUIRES driver
PRIV_REQUIRES soc esp_timer)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <inttypes.h>
#include "esp_timer.h"
#include "sdmmc_common.h"
@ -19,15 +20,15 @@ esp_err_t sdmmc_send_cmd(sdmmc_card_t* card, sdmmc_command_t* cmd)
}
int slot = card->host.slot;
ESP_LOGV(TAG, "sending cmd slot=%d op=%d arg=%x flags=%x data=%p blklen=%d datalen=%d timeout=%d",
slot, cmd->opcode, cmd->arg, cmd->flags, cmd->data, cmd->blklen, cmd->datalen, cmd->timeout_ms);
ESP_LOGV(TAG, "sending cmd slot=%d op=%" PRIu32 " arg=%" PRIx32 " flags=%x data=%p blklen=%" PRIu32 " datalen=%" PRIu32 " timeout=%" PRIu32,
slot, cmd->opcode, cmd->arg, cmd->flags, cmd->data, (uint32_t) cmd->blklen, (uint32_t) cmd->datalen, cmd->timeout_ms);
esp_err_t err = (*card->host.do_transaction)(slot, cmd);
if (err != 0) {
ESP_LOGD(TAG, "cmd=%d, sdmmc_req_run returned 0x%x", cmd->opcode, err);
ESP_LOGD(TAG, "cmd=%" PRIu32 ", sdmmc_req_run returned 0x%x", cmd->opcode, err);
return err;
}
int state = MMC_R1_CURRENT_STATE(cmd->response);
ESP_LOGV(TAG, "cmd response %08x %08x %08x %08x err=0x%x state=%d",
ESP_LOGV(TAG, "cmd response %08" PRIx32 " %08" PRIx32 " %08" PRIx32 " %08" PRIx32 " err=0x%x state=%d",
cmd->response[0],
cmd->response[1],
cmd->response[2],
@ -481,7 +482,7 @@ esp_err_t sdmmc_write_sectors_dma(sdmmc_card_t* card, const void* src,
return err;
}
if (++count % 16 == 0) {
ESP_LOGV(TAG, "waiting for card to become ready (%d)", count);
ESP_LOGV(TAG, "waiting for card to become ready (%" PRIu32 ")", (uint32_t) count);
}
}
/* SPI mode: although card busy indication is based on the busy token,
@ -496,12 +497,12 @@ esp_err_t sdmmc_write_sectors_dma(sdmmc_card_t* card, const void* src,
return err;
}
if (status & SD_SPI_R2_CARD_LOCKED) {
ESP_LOGE(TAG, "%s: write failed, card is locked: r2=0x%04x",
ESP_LOGE(TAG, "%s: write failed, card is locked: r2=0x%04" PRIx32,
__func__, status);
return ESP_ERR_INVALID_STATE;
}
if (status != 0) {
ESP_LOGE(TAG, "%s: card status indicates an error after write operation: r2=0x%04x",
ESP_LOGE(TAG, "%s: card status indicates an error after write operation: r2=0x%04" PRIx32,
__func__, status);
return ESP_ERR_INVALID_RESPONSE;
}
@ -687,7 +688,7 @@ esp_err_t sdmmc_erase_sectors(sdmmc_card_t* card, size_t start_sector,
return err;
}
if (status != 0) {
ESP_LOGE(TAG, "%s: card status indicates an error after erase operation: r2=0x%04x",
ESP_LOGE(TAG, "%s: card status indicates an error after erase operation: r2=0x%04" PRIx32,
__func__, status);
return ESP_ERR_INVALID_RESPONSE;
}

View File

@ -15,6 +15,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <inttypes.h>
#include "sdmmc_common.h"
static const char* TAG = "sdmmc_common";
@ -52,14 +53,14 @@ esp_err_t sdmmc_init_ocr(sdmmc_card_t* card)
return err;
}
}
ESP_LOGD(TAG, "host_ocr=0x%x card_ocr=0x%x", host_ocr, card->ocr);
ESP_LOGD(TAG, "host_ocr=0x%" PRIx32 " card_ocr=0x%" PRIx32, host_ocr, card->ocr);
/* Clear all voltage bits in host's OCR which the card doesn't support.
* Don't touch CCS bit because in SPI mode cards don't report CCS in ACMD41
* response.
*/
host_ocr &= (card->ocr | (~SD_OCR_VOL_MASK));
ESP_LOGD(TAG, "sdmmc_card_init: host_ocr=%08x, card_ocr=%08x", host_ocr, card->ocr);
ESP_LOGD(TAG, "sdmmc_card_init: host_ocr=%08" PRIx32 ", card_ocr=%08" PRIx32, host_ocr, card->ocr);
return ESP_OK;
}
@ -286,12 +287,12 @@ void sdmmc_card_print_info(FILE* stream, const sdmmc_card_t* card)
if (print_csd) {
fprintf(stream, "CSD: ver=%d, sector_size=%d, capacity=%d read_bl_len=%d\n",
(card->is_mmc ? card->csd.csd_ver : card->csd.csd_ver + 1),
(int) (card->is_mmc ? card->csd.csd_ver : card->csd.csd_ver + 1),
card->csd.sector_size, card->csd.capacity, card->csd.read_block_len);
if (card->is_mmc) {
fprintf(stream, "EXT CSD: bus_width=%d\n", (1 << card->log_bus_width));
fprintf(stream, "EXT CSD: bus_width=%" PRIu32 "\n", (uint32_t) (1 << card->log_bus_width));
} else if (!card->is_sdio){ // make sure card is SD
fprintf(stream, "SSR: bus_width=%d\n", (card->ssr.cur_bus_width ? 4 : 1));
fprintf(stream, "SSR: bus_width=%" PRIu32 "\n", (uint32_t) (card->ssr.cur_bus_width ? 4 : 1));
}
}
if (print_scr) {

View File

@ -15,6 +15,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <inttypes.h>
#include "sdmmc_common.h"
#include "esp_attr.h"
#include "esp_compiler.h"
@ -240,7 +241,7 @@ esp_err_t sdmmc_io_read_byte(sdmmc_card_t* card, uint32_t function,
{
esp_err_t ret = sdmmc_io_rw_direct(card, function, addr, SD_ARG_CMD52_READ, out_byte);
if (unlikely(ret != ESP_OK)) {
ESP_LOGE(TAG, "%s: sdmmc_io_rw_direct (read 0x%x) returned 0x%x", __func__, addr, ret);
ESP_LOGE(TAG, "%s: sdmmc_io_rw_direct (read 0x%" PRIx32 ") returned 0x%x", __func__, addr, ret);
}
return ret;
}
@ -252,7 +253,7 @@ esp_err_t sdmmc_io_write_byte(sdmmc_card_t* card, uint32_t function,
esp_err_t ret = sdmmc_io_rw_direct(card, function, addr,
SD_ARG_CMD52_WRITE | SD_ARG_CMD52_EXCHANGE, &tmp_byte);
if (unlikely(ret != ESP_OK)) {
ESP_LOGE(TAG, "%s: sdmmc_io_rw_direct (write 0x%x) returned 0x%x", __func__, addr, ret);
ESP_LOGE(TAG, "%s: sdmmc_io_rw_direct (write 0x%" PRIu32 ") returned 0x%x", __func__, addr, ret);
return ret;
}
if (out_byte != NULL) {

View File

@ -15,6 +15,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <inttypes.h>
#include <unistd.h>
#include "sdmmc_common.h"
@ -298,7 +299,7 @@ uint32_t sdmmc_mmc_get_erase_timeout_ms(const sdmmc_card_t* card, int arg, size_
/* TODO: calculate erase timeout based on ext_csd (trim_timeout) */
uint32_t timeout_ms = SDMMC_SD_DISCARD_TIMEOUT * erase_size_kb / card->csd.sector_size;
timeout_ms = MAX(1000, timeout_ms);
ESP_LOGD(TAG, "%s: erase timeout %u s (erasing %u kB, %ums per sector)",
__func__, timeout_ms / 1000, erase_size_kb, SDMMC_SD_DISCARD_TIMEOUT);
ESP_LOGD(TAG, "%s: erase timeout %" PRIu32 " s (erasing %" PRIu32 " kB, %" PRIu32 " ms per sector)",
__func__, (uint32_t) (timeout_ms / 1000), (uint32_t) erase_size_kb, (uint32_t) SDMMC_SD_DISCARD_TIMEOUT);
return timeout_ms;
}

View File

@ -15,6 +15,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <inttypes.h>
#include "esp_timer.h"
#include "sdmmc_common.h"
@ -160,7 +161,7 @@ esp_err_t sdmmc_init_sd_wait_data_ready(sdmmc_card_t* card)
return err;
}
if (++count % 16 == 0) {
ESP_LOGV(TAG, "waiting for card to become ready (%d)", count);
ESP_LOGV(TAG, "waiting for card to become ready (%" PRIu32 ")", count);
}
}
return ESP_OK;
@ -210,12 +211,12 @@ esp_err_t sdmmc_send_cmd_switch_func(sdmmc_card_t* card,
/* busy response is never sent */
} else if (resp_ver == 1) {
if (SD_SFUNC_BUSY(resp->data, group) & (1 << function)) {
ESP_LOGD(TAG, "%s: response indicates function %d:%d is busy",
ESP_LOGD(TAG, "%s: response indicates function %" PRIu32 ":%" PRIu32 " is busy",
__func__, group, function);
return ESP_ERR_INVALID_STATE;
}
} else {
ESP_LOGD(TAG, "%s: got an invalid version of SWITCH_FUNC response: 0x%02x",
ESP_LOGD(TAG, "%s: got an invalid version of SWITCH_FUNC response: 0x%02" PRIx32,
__func__, resp_ver);
return ESP_ERR_INVALID_RESPONSE;
}
@ -446,15 +447,15 @@ uint32_t sdmmc_sd_get_erase_timeout_ms(const sdmmc_card_t* card, int arg, size_t
uint32_t timeout_sec = card->ssr.erase_offset +
card->ssr.erase_timeout * (erase_size_kb + card->ssr.alloc_unit_kb - 1) /
(card->ssr.erase_size_au * card->ssr.alloc_unit_kb);
ESP_LOGD(TAG, "%s: erase timeout %u s (erasing %u kB, ES=%u, ET=%u, EO=%u, AU=%u kB)",
__func__, timeout_sec, erase_size_kb, card->ssr.erase_size_au,
card->ssr.erase_timeout, card->ssr.erase_offset, card->ssr.alloc_unit_kb);
ESP_LOGD(TAG, "%s: erase timeout %" PRIu32 " s (erasing %" PRIu32 " kB, ES=%" PRIu32 ", ET=%" PRIu32 ", EO=%" PRIu32 ", AU=%" PRIu32 " kB)",
__func__, timeout_sec, (uint32_t) erase_size_kb, (uint32_t) card->ssr.erase_size_au,
(uint32_t) card->ssr.erase_timeout, (uint32_t) card->ssr.erase_offset, (uint32_t) card->ssr.alloc_unit_kb);
return timeout_sec * 1000;
} else {
uint32_t timeout_ms = SDMMC_SD_DISCARD_TIMEOUT * erase_size_kb / card->csd.sector_size;
timeout_ms = MAX(1000, timeout_ms);
ESP_LOGD(TAG, "%s: erase timeout %u s (erasing %u kB, %ums per sector)",
__func__, timeout_ms / 1000, erase_size_kb, SDMMC_SD_DISCARD_TIMEOUT);
ESP_LOGD(TAG, "%s: erase timeout %" PRIu32 " s (erasing %" PRIu32 " kB, %" PRIu32 " ms per sector)",
__func__, (uint32_t) (timeout_ms / 1000), (uint32_t) erase_size_kb, (uint32_t) SDMMC_SD_DISCARD_TIMEOUT);
return timeout_ms;
}
} else {

View File

@ -2,4 +2,3 @@ idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES cmock sdmmc test_utils
)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -71,5 +71,4 @@ if(NOT BOOTLOADER_BUILD AND NOT CONFIG_APP_BUILD_TYPE_PURE_RAM_APP)
# will be replaced with MMU requirements
idf_component_optional_requires(PRIVATE esp_psram)
endif()
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
endif()

View File

@ -2,4 +2,3 @@ idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES cmock test_utils spi_flash bootloader_support app_update
driver esp_timer)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -4,4 +4,3 @@ set(srcs "test_app_main.c"
idf_component_register(SRCS ${srcs}
PRIV_REQUIRES unity spi_flash bootloader_support esp_partition
WHOLE_ARCHIVE)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -1,10 +1,11 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "esp_log.h"
#include "unity.h"
#include "esp_flash.h"
@ -45,13 +46,13 @@ static void setup_tests(void)
{
const esp_partition_t *part = get_test_data_partition();
start = part->address;
printf("Test data partition @ 0x%x\n", start);
printf("Test data partition @ 0x%" PRIx32 "\n", (uint32_t) start);
}
static void verify_erased_flash(size_t offset, size_t length)
{
uint8_t *readback = (uint8_t *)heap_caps_malloc(SPI_FLASH_SEC_SIZE, MALLOC_CAP_32BIT | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
printf("verify erased 0x%x - 0x%x\n", offset, offset + length);
printf("verify erased 0x%" PRIx32 " - 0x%" PRIx32 "\n", (uint32_t) offset, (uint32_t) (offset + length));
TEST_ASSERT_EQUAL_HEX(ESP_OK,
esp_flash_read(NULL, readback, offset, length));
for (int i = 0; i < length; i++) {
@ -111,7 +112,7 @@ TEST_CASE("test 16 byte encrypted writes", "[flash_encryption]")
static void test_encrypted_write(size_t offset, const uint8_t *data, size_t length)
{
uint8_t readback[length];
printf("encrypt %d bytes at 0x%x\n", length, offset);
printf("encrypt %" PRIu32 " bytes at 0x%" PRIx32 "\n", (uint32_t) length, (uint32_t) offset);
TEST_ASSERT_EQUAL_HEX(ESP_OK,
esp_flash_write_encrypted(NULL, offset, data, length));
@ -160,7 +161,7 @@ TEST_CASE("test read & write random encrypted data", "[flash_encryption]")
len = SPI_FLASH_SEC_SIZE - offset;
}
printf("write %d bytes to 0x%08x...\n", len, start + offset);
printf("write %d bytes to 0x%08" PRIx32 "...\n", len, (uint32_t) (start + offset));
err = esp_flash_write_encrypted(NULL, start + offset, data_buf, len);
TEST_ESP_OK(err);
@ -178,7 +179,7 @@ TEST_CASE("test read & write random encrypted data", "[flash_encryption]")
err = esp_flash_read_encrypted(NULL, start + offset, data_buf, len);
TEST_ESP_OK(err);
printf("compare %d bytes at 0x%08x...\n", len, start + offset);
printf("compare %d bytes at 0x%08" PRIx32 "...\n", len, (uint32_t) (start + offset));
TEST_ASSERT_EQUAL_HEX8_ARRAY(cmp_buf + offset, data_buf, len);
offset += len;
@ -193,7 +194,7 @@ static const char plainttext_data[] = "$$$$#### Welcome! This is flash encryptio
static void test_encrypted_write_new_impl(size_t offset, const uint8_t *data, size_t length)
{
uint8_t *readback = (uint8_t *)heap_caps_malloc(SPI_FLASH_SEC_SIZE, MALLOC_CAP_32BIT | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
printf("encrypt %d bytes at 0x%x\n", length, offset);
printf("encrypt %" PRIu32 " bytes at 0x%" PRIx32 "\n", (uint32_t) length, (uint32_t) offset);
TEST_ASSERT_EQUAL_HEX(ESP_OK,
esp_flash_write_encrypted(NULL, offset, data, length));
@ -289,7 +290,7 @@ TEST_CASE("test read & write encrypted data(16 bytes alianed but 32 bytes unalig
if (start % 32 == 0) {
start += 16;
}
printf("Write data partition @ 0x%x\n", start);
printf("Write data partition @ 0x%" PRIx32 "\n", (uint32_t) start);
ESP_LOG_BUFFER_HEXDUMP(TAG, plainttext_data, sizeof(plainttext_data), ESP_LOG_INFO);
printf("Encrypteed writting......\n");

View File

@ -9,5 +9,3 @@ idf_component_register(SRCS "Partition.cpp"
PRIV_INCLUDE_DIRS private_include
REQUIRES esp_partition
PRIV_REQUIRES spi_flash)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -3,8 +3,11 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_log.h"
#include "Partition.h"
#include <inttypes.h>
static const char *TAG = "wl_partition";
Partition::Partition(const esp_partition_t *partition)
@ -28,9 +31,9 @@ esp_err_t Partition::erase_range(size_t start_address, size_t size)
{
esp_err_t result = esp_partition_erase_range(this->partition, start_address, size);
if (result == ESP_OK) {
ESP_LOGV(TAG, "erase_range - start_address=0x%08x, size=0x%08x, result=0x%08x", start_address, size, result);
ESP_LOGV(TAG, "erase_range - start_address=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) start_address, (uint32_t) size, result);
} else {
ESP_LOGE(TAG, "erase_range - start_address=0x%08x, size=0x%08x, result=0x%08x", start_address, size, result);
ESP_LOGE(TAG, "erase_range - start_address=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) start_address, (uint32_t) size, result);
}
return result;
}

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -8,6 +8,7 @@
#include "SPI_Flash.h"
#include "spi_flash_mmap.h"
#include "esp_flash.h"
#include <inttypes.h>
static const char *TAG = "spi_flash";
@ -26,9 +27,9 @@ esp_err_t SPI_Flash::erase_sector(size_t sector)
{
esp_err_t result = esp_flash_erase_region(NULL, sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);;
if (result == ESP_OK) {
ESP_LOGV(TAG, "erase_sector - sector=0x%08x, result=0x%08x", sector, result);
ESP_LOGV(TAG, "erase_sector - sector=0x%08" PRIx32 ", result=0x%08x", (uint32_t) sector, result);
} else {
ESP_LOGE(TAG, "erase_sector - sector=0x%08x, result=0x%08x", sector, result);
ESP_LOGE(TAG, "erase_sector - sector=0x%08" PRIx32 ", result=0x%08x", (uint32_t) sector, result);
}
return result;
}
@ -38,9 +39,9 @@ esp_err_t SPI_Flash::erase_range(size_t start_address, size_t size)
size = size * SPI_FLASH_SEC_SIZE;
esp_err_t result = esp_flash_erase_region(NULL, start_address, size);
if (result == ESP_OK) {
ESP_LOGV(TAG, "erase_range - start_address=0x%08x, size=0x%08x, result=0x%08x", start_address, size, result);
ESP_LOGV(TAG, "erase_range - start_address=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) start_address, (uint32_t) size, result);
} else {
ESP_LOGE(TAG, "erase_range - start_address=0x%08x, size=0x%08x, result=0x%08x", start_address, size, result);
ESP_LOGE(TAG, "erase_range - start_address=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) start_address, (uint32_t) size, result);
}
return result;
}
@ -49,9 +50,9 @@ esp_err_t SPI_Flash::write(size_t dest_addr, const void *src, size_t size)
{
esp_err_t result = esp_flash_write(NULL, src, dest_addr, size);
if (result == ESP_OK) {
ESP_LOGV(TAG, "write - dest_addr=0x%08x, size=0x%08x, result=0x%08x", dest_addr, size, result);
ESP_LOGV(TAG, "write - dest_addr=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) dest_addr, (uint32_t) size, result);
} else {
ESP_LOGE(TAG, "write - dest_addr=0x%08x, size=0x%08x, result=0x%08x", dest_addr, size, result);
ESP_LOGE(TAG, "write - dest_addr=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) dest_addr, (uint32_t) size, result);
}
return result;
}
@ -60,9 +61,9 @@ esp_err_t SPI_Flash::read(size_t src_addr, void *dest, size_t size)
{
esp_err_t result = esp_flash_read(NULL, dest, src_addr, size);
if (result == ESP_OK) {
ESP_LOGV(TAG, "read - src_addr=0x%08x, size=0x%08x, result=0x%08x", src_addr, size, result);
ESP_LOGV(TAG, "read - src_addr=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) src_addr, (uint32_t) size, result);
} else {
ESP_LOGE(TAG, "read - src_addr=0x%08x, size=0x%08x, result=0x%08x", src_addr, size, result);
ESP_LOGE(TAG, "read - src_addr=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) src_addr, (uint32_t) size, result);
}
return result;
}

View File

@ -6,13 +6,14 @@
#include "WL_Ext_Perf.h"
#include "Partition.h"
#include <stdlib.h>
#include <inttypes.h>
#include "esp_log.h"
static const char *TAG = "wl_ext_perf";
#define WL_EXT_RESULT_CHECK(result) \
if (result != ESP_OK) { \
ESP_LOGE(TAG,"%s(%d): result = 0x%08x", __FUNCTION__, __LINE__, result); \
ESP_LOGE(TAG,"%s(%d): result = 0x%08" PRIx32, __FUNCTION__, __LINE__, (uint32_t) result); \
return (result); \
}
@ -76,7 +77,7 @@ esp_err_t WL_Ext_Perf::erase_sector_fit(uint32_t first_erase_sector, uint32_t co
{
// This method works with one flash device sector and able to erase "count" of fatfs sectors from this first_erase_sector
esp_err_t result = ESP_OK;
ESP_LOGV(TAG, "%s begin, first_erase_sector = 0x%08x, count = %i", __func__, first_erase_sector, count);
ESP_LOGV(TAG, "%s begin, first_erase_sector = 0x%08" PRIx32 ", count = %" PRIu32, __func__, first_erase_sector, count);
uint32_t flash_sector_base_addr = first_erase_sector / this->flash_fat_sector_size_factor;
uint32_t pre_check_start = first_erase_sector % this->flash_fat_sector_size_factor;
@ -136,7 +137,7 @@ esp_err_t WL_Ext_Perf::erase_range(size_t start_address, size_t size)
// erase complete sector and restore data of area which should not be erased.
// For the rest check area, this operation not needed because complete flash device sector will be erased.
ESP_LOGV(TAG, "%s begin, addr = 0x%08x, size = %i", __func__, start_address, size);
ESP_LOGV(TAG, "%s begin, addr = 0x%08" PRIx32 ", size = %" PRIu32, __func__, (uint32_t) start_address, (uint32_t) size);
uint32_t sectors_count = size / this->fat_sector_size;
// Calculate pre check values
@ -164,7 +165,7 @@ esp_err_t WL_Ext_Perf::erase_range(size_t start_address, size_t size)
result = this->erase_sector_fit(start_address / this->fat_sector_size, pre_check_count);
WL_EXT_RESULT_CHECK(result);
}
ESP_LOGV(TAG, "%s rest_check_start = %i, pre_check_count=%i, rest_check_count=%i, post_check_count=%i", __func__, rest_check_start, pre_check_count, rest_check_count, post_check_count);
ESP_LOGV(TAG, "%s rest_check_start = %" PRIu32 ", pre_check_count=%" PRIu32 ", rest_check_count=%" PRIu32 ", post_check_count=%" PRIu32, __func__, rest_check_start, pre_check_count, rest_check_count, post_check_count);
// Clear rest_check_count sectors
if (rest_check_count > 0) {

View File

@ -1,17 +1,18 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "WL_Ext_Safe.h"
#include <stdlib.h>
#include <inttypes.h>
#include "esp_log.h"
static const char *TAG = "wl_ext_safe";
#define WL_EXT_RESULT_CHECK(result) \
if (result != ESP_OK) { \
ESP_LOGE(TAG,"%s(%d): result = 0x%08x", __FUNCTION__, __LINE__, result); \
ESP_LOGE(TAG,"%s(%d): result = 0x%08" PRIx32, __FUNCTION__, __LINE__, (uint32_t) result); \
return (result); \
}
@ -77,7 +78,7 @@ esp_err_t WL_Ext_Safe::init()
size_t WL_Ext_Safe::get_flash_size()
{
ESP_LOGV(TAG, "%s size = %i", __func__, WL_Ext_Perf::get_flash_size() - 2 * this->flash_sector_size);
ESP_LOGV(TAG, "%s size = %" PRIu32, __func__, (uint32_t) (WL_Ext_Perf::get_flash_size() - 2 * this->flash_sector_size));
return WL_Ext_Perf::get_flash_size() - 2 * this->flash_sector_size;
}
@ -89,7 +90,7 @@ esp_err_t WL_Ext_Safe::recover()
WL_Ext_Safe_State state;
result = this->read(this->buff_trans_state_addr, &state, sizeof(WL_Ext_Safe_State));
WL_EXT_RESULT_CHECK(result);
ESP_LOGV(TAG, "%s recover, start_addr = 0x%08x, sector_base_addr = 0x%08x, sector_base_addr_offset= %i, count=%i", __func__, state.sector_restore_sign, state.sector_base_addr, state.sector_base_addr_offset, state.count);
ESP_LOGV(TAG, "%s recover, start_addr = 0x%08" PRIx32 ", sector_base_addr = 0x%08" PRIx32 ", sector_base_addr_offset= %" PRIu32 ", count=%" PRIu32, __func__, state.sector_restore_sign, state.sector_base_addr, state.sector_base_addr_offset, state.count);
// check if we have any incomplete transaction pending.
if (state.sector_restore_sign == WL_EXT_SAFE_OK) {
@ -129,7 +130,7 @@ esp_err_t WL_Ext_Safe::erase_sector_fit(uint32_t first_erase_sector, uint32_t co
uint32_t pre_check_start = first_erase_sector % this->flash_fat_sector_size_factor;
// Except pre check and post check data area, read and store all other data to sector_buffer
ESP_LOGV(TAG, "%s first_erase_sector=0x%08x, count = %i", __func__, first_erase_sector, count);
ESP_LOGV(TAG, "%s first_erase_sector=0x%08" PRIx32 ", count = %" PRIu32, __func__, first_erase_sector, count);
for (int i = 0; i < this->flash_fat_sector_size_factor; i++) {
if ((i < pre_check_start) || (i >= count + pre_check_start)) {
result = this->read(flash_sector_base_addr * this->flash_sector_size + i * this->fat_sector_size,

View File

@ -12,6 +12,7 @@
#include "crc32.h"
#include <string.h>
#include <stddef.h>
#include <inttypes.h>
static const char *TAG = "wl_flash";
#ifndef WL_CFG_CRC_CONST
@ -20,7 +21,7 @@ static const char *TAG = "wl_flash";
#define WL_RESULT_CHECK(result) \
if (result != ESP_OK) { \
ESP_LOGE(TAG,"%s(%d): result = 0x%08x", __FUNCTION__, __LINE__, result); \
ESP_LOGE(TAG,"%s(%d): result = 0x%08" PRIx32, __FUNCTION__, __LINE__, (uint32_t) result); \
return (result); \
}
@ -40,7 +41,7 @@ WL_Flash::~WL_Flash()
esp_err_t WL_Flash::config(wl_config_t *cfg, Partition *partition)
{
ESP_LOGV(TAG, "%s partition_start_addr=0x%08x, wl_partition_size=0x%08x, wl_page_size=0x%08x, flash_sector_size=0x%08x, wl_update_rate=0x%08x, wl_pos_update_record_size=0x%08x, version=0x%08x, wl_temp_buff_size=0x%08x", __func__,
ESP_LOGV(TAG, "%s partition_start_addr=0x%08" PRIx32 ", wl_partition_size=0x%08" PRIx32 ", wl_page_size=0x%08" PRIx32 ", flash_sector_size=0x%08" PRIx32 ", wl_update_rate=0x%08" PRIx32 ", wl_pos_update_record_size=0x%08" PRIx32 ", version=0x%08" PRIx32 ", wl_temp_buff_size=0x%08" PRIx32 , __func__,
(uint32_t) cfg->wl_partition_start_addr,
cfg->wl_partition_size,
cfg->wl_page_size,
@ -87,7 +88,7 @@ esp_err_t WL_Flash::config(wl_config_t *cfg, Partition *partition)
ptrdiff_t flash_sz = ((this->cfg.wl_partition_size - this->state_size * 2 - this->cfg_size) / this->cfg.wl_page_size - 1) * this->cfg.wl_page_size; // -1 remove dummy block
this->flash_size = ((this->cfg.wl_partition_size - this->state_size * 2 - this->cfg_size) / this->cfg.wl_page_size - 1) * this->cfg.wl_page_size; // -1 remove dummy block
ESP_LOGD(TAG, "%s - config result: state_size=0x%08x, cfg_size=0x%08x, addr_cfg=0x%08x, addr_state1=0x%08x, addr_state2=0x%08x, flash_size=0x%08x", __func__,
ESP_LOGD(TAG, "%s - config result: state_size=0x%08" PRIx32 ", cfg_size=0x%08" PRIx32 ", addr_cfg=0x%08" PRIx32 ", addr_state1=0x%08" PRIx32 ", addr_state2=0x%08" PRIx32 ", flash_size=0x%08" PRIx32, __func__,
(uint32_t) this->state_size,
(uint32_t) this->cfg_size,
(uint32_t) this->addr_cfg,
@ -130,7 +131,7 @@ esp_err_t WL_Flash::init()
uint32_t crc1 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)&this->state, check_size);
uint32_t crc2 = crc32::crc32_le(WL_CFG_CRC_CONST, (uint8_t *)state_copy, check_size);
ESP_LOGD(TAG, "%s - config ID=%i, stored ID=%i, wl_sec_erase_cycle_count=%i, wl_block_size=%i, wl_max_sec_erase_cycle_count=%i, wl_dummy_sec_pos=%i, wl_dummy_sec_move_count=0x%8.8X",
ESP_LOGD(TAG, "%s - config ID=%" PRIu32 ", stored ID=%" PRIu32 ", wl_sec_erase_cycle_count=%" PRIu32 ", wl_block_size=%" PRIu32 ", wl_max_sec_erase_cycle_count=%" PRIu32 ", wl_dummy_sec_pos=%" PRIu32 ", wl_dummy_sec_move_count=0x%8.8" PRIX32,
__func__,
this->cfg.version,
this->state.version,
@ -140,7 +141,7 @@ esp_err_t WL_Flash::init()
this->state.wl_dummy_sec_pos,
this->state.wl_dummy_sec_move_count);
ESP_LOGD(TAG, "%s starts: crc1= 0x%08x, crc2 = 0x%08x, this->state.crc= 0x%08x, state_copy->crc= 0x%08x, version=%i, read_version=%i", __func__, crc1, crc2, this->state.crc32, state_copy->crc32, this->cfg.version, this->state.version);
ESP_LOGD(TAG, "%s starts: crc1= 0x%08" PRIx32 ", crc2 = 0x%08" PRIx32 ", this->state.crc= 0x%08" PRIx32 ", state_copy->crc= 0x%08" PRIx32 ", version=%" PRIu32 ", read_version=%" PRIu32, __func__, crc1, crc2, this->state.crc32, state_copy->crc32, this->cfg.version, this->state.version);
if ((crc1 == this->state.crc32) && (crc2 == state_copy->crc32)) {
// The state is OK. Check the ID
if (this->state.version != this->cfg.version) {
@ -167,13 +168,13 @@ esp_err_t WL_Flash::init()
}
}
}
ESP_LOGD(TAG, "%s: crc1=0x%08x, crc2 = 0x%08x, result= 0x%08x", __func__, crc1, crc2, (uint32_t)result);
ESP_LOGD(TAG, "%s: crc1=0x%08" PRIx32 ", crc2 = 0x%08" PRIx32 ", result= 0x%08" PRIx32 , __func__, crc1, crc2, (uint32_t)result);
result = this->recoverPos();
WL_RESULT_CHECK(result);
}
} else if ((crc1 != this->state.crc32) && (crc2 != state_copy->crc32)) { // This is just new flash or new version
// Check if this is new version or just new instance of WL
ESP_LOGD(TAG, "%s: try to update version - crc1= 0x%08x, crc2 = 0x%08x, result= 0x%08x", __func__, (uint32_t)crc1, (uint32_t)crc2, (uint32_t)result);
ESP_LOGD(TAG, "%s: try to update version - crc1= 0x%08" PRIx32 ", crc2 = 0x%08" PRIx32 ", result= 0x%08" PRIx32 , __func__, (uint32_t)crc1, (uint32_t)crc2, (uint32_t)result);
result = this->updateVersion();
if (result == ESP_FAIL) {
ESP_LOGD(TAG, "%s: init flash sections", __func__);
@ -232,11 +233,11 @@ esp_err_t WL_Flash::init()
}
if (result != ESP_OK) {
this->initialized = false;
ESP_LOGE(TAG, "%s: returned 0x%08x", __func__, (uint32_t)result);
ESP_LOGE(TAG, "%s: returned 0x%08" PRIx32 , __func__, (uint32_t)result);
return result;
}
this->initialized = true;
ESP_LOGD(TAG, "%s - wl_dummy_sec_move_count= 0x%08x", __func__, (uint32_t)this->state.wl_dummy_sec_move_count);
ESP_LOGD(TAG, "%s - wl_dummy_sec_move_count= 0x%08" PRIx32 , __func__, (uint32_t)this->state.wl_dummy_sec_move_count);
return ESP_OK;
}
@ -251,7 +252,7 @@ esp_err_t WL_Flash::recoverPos()
result = this->partition->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, this->temp_buff, this->cfg.wl_pos_update_record_size);
pos_bits = this->OkBuffSet(i);
WL_RESULT_CHECK(result);
ESP_LOGV(TAG, "%s - check pos: result=0x%08x, position= %i, pos_bits= 0x%08x", __func__, (uint32_t)result, (uint32_t)position, (uint32_t)pos_bits);
ESP_LOGV(TAG, "%s - check pos: result=0x%08" PRIx32 ", position= %" PRIu32 ", pos_bits= 0x%08" PRIx32 , __func__, (uint32_t) result, (uint32_t) position, (uint32_t) pos_bits);
if (pos_bits == false) {
break; // we have found position
}
@ -261,7 +262,7 @@ esp_err_t WL_Flash::recoverPos()
if (this->state.wl_dummy_sec_pos == this->state.wl_part_max_sec_pos) {
this->state.wl_dummy_sec_pos--;
}
ESP_LOGD(TAG, "%s - this->state.wl_dummy_sec_pos= 0x%08x, position= 0x%08x, result= 0x%08x, wl_part_max_sec_pos= 0x%08x", __func__, (uint32_t)this->state.wl_dummy_sec_pos, (uint32_t)position, (uint32_t)result, (uint32_t)this->state.wl_part_max_sec_pos);
ESP_LOGD(TAG, "%s - this->state.wl_dummy_sec_pos= 0x%08" PRIx32 ", position= 0x%08" PRIx32 ", result= 0x%08" PRIx32 ", wl_part_max_sec_pos= 0x%08" PRIx32 , __func__, (uint32_t)this->state.wl_dummy_sec_pos, (uint32_t)position, (uint32_t)result, (uint32_t)this->state.wl_part_max_sec_pos);
ESP_LOGV(TAG, "%s done", __func__);
return result;
}
@ -301,8 +302,8 @@ esp_err_t WL_Flash::initSections()
result = this->partition->write(this->addr_cfg, &this->cfg, sizeof(wl_config_t));
WL_RESULT_CHECK(result);
ESP_LOGD(TAG, "%s - this->state->wl_max_sec_erase_cycle_count= 0x%08x, this->state->wl_part_max_sec_pos= 0x%08x", __func__, this->state.wl_max_sec_erase_cycle_count, this->state.wl_part_max_sec_pos);
ESP_LOGD(TAG, "%s - result= 0x%08x", __func__, result);
ESP_LOGD(TAG, "%s - this->state->wl_max_sec_erase_cycle_count= 0x%08" PRIx32 ", this->state->wl_part_max_sec_pos= 0x%08" PRIx32 , __func__, this->state.wl_max_sec_erase_cycle_count, this->state.wl_part_max_sec_pos);
ESP_LOGD(TAG, "%s - result= 0x%08x" , __func__, result);
return result;
}
@ -336,24 +337,24 @@ esp_err_t WL_Flash::updateV1_V2()
uint32_t v1_crc1 = this->state.wl_device_id;
uint32_t v1_crc2 = state_copy->wl_device_id;
ESP_LOGD(TAG, "%s - process crc1=0x%08x, crc2=0x%08x, v1_crc1=0x%08x, v1_crc2=0x%08x, version=%i", __func__, crc1, crc2, v1_crc1, v1_crc2, this->state.version);
ESP_LOGD(TAG, "%s - process crc1=0x%08" PRIx32 ", crc2=0x%08" PRIx32 ", v1_crc1=0x%08" PRIx32 ", v1_crc2=0x%08" PRIx32 ", version=%" PRIu32, __func__, crc1, crc2, v1_crc1, v1_crc2, this->state.version);
if ((crc1 == v1_crc1) && (crc2 == v1_crc2) && (v1_crc1 == v1_crc2) && (this->state.version == 1) && (state_copy->version == 1)) {
// Here we have to update all internal structures
ESP_LOGI(TAG, "%s Update from V1 to V2, crc=0x%08x, ", __func__, crc1);
ESP_LOGI(TAG, "%s Update from V1 to V2, crc=0x%08" PRIx32 ", ", __func__, crc1);
uint32_t pos = 0;
for (size_t i = 0; i < this->state.wl_part_max_sec_pos; i++) {
uint8_t pos_bits;
result = this->partition->read(this->addr_state1 + sizeof(wl_state_t) + i * this->cfg.wl_pos_update_record_size, &pos_bits, 1);
WL_RESULT_CHECK(result);
ESP_LOGV(TAG, "%s- result= 0x%08x, pos= %i, pos_bits= 0x%08x", __func__, (uint32_t)result, (uint32_t)pos, (uint32_t)pos_bits);
ESP_LOGV(TAG, "%s- result= 0x%08" PRIx32 ", pos= %" PRIu32 ", pos_bits= 0x%08" PRIx32 , __func__, (uint32_t) result, (uint32_t) pos, (uint32_t) pos_bits);
pos = i;
if (pos_bits == 0xff) {
break; // we have found position
}
}
ESP_LOGI(TAG, "%s wl_part_max_sec_pos=%i, pos=%i, state.ver=%i, state2.ver=%i", __func__, (uint32_t)this->state.wl_part_max_sec_pos, (uint32_t)pos, (uint32_t)this->state.version, (uint32_t)state_copy->version);
ESP_LOGI(TAG, "%s wl_part_max_sec_pos=%" PRIu32 ", pos=%" PRIu32 ", state.ver=%" PRIu32 ", state2.ver=%" PRIu32, __func__, (uint32_t) this->state.wl_part_max_sec_pos, (uint32_t) pos, (uint32_t) this->state.version, (uint32_t) state_copy->version);
if (pos == this->state.wl_part_max_sec_pos) {
pos--;
}
@ -381,7 +382,7 @@ esp_err_t WL_Flash::updateV1_V2()
WL_RESULT_CHECK(result);
result = this->partition->write(this->addr_state2, &this->state, sizeof(wl_state_t));
WL_RESULT_CHECK(result);
ESP_LOGD(TAG, "%s - wl_dummy_sec_move_count= 0x%08x, pos= 0x%08x", __func__, this->state.wl_dummy_sec_move_count, this->state.wl_dummy_sec_pos);
ESP_LOGD(TAG, "%s - wl_dummy_sec_move_count= 0x%08" PRIx32 ", pos= 0x%08" PRIx32 , __func__, this->state.wl_dummy_sec_move_count, this->state.wl_dummy_sec_pos);
memset(this->temp_buff, 0, this->cfg.wl_pos_update_record_size);
for (uint32_t i = 0 ; i <= pos; i++) {
@ -430,7 +431,7 @@ esp_err_t WL_Flash::updateWL()
}
// Here we have to move the block and increase the state
this->state.wl_sec_erase_cycle_count = 0;
ESP_LOGV(TAG, "%s - wl_sec_erase_cycle_count= 0x%08x, pos= 0x%08x", __func__, this->state.wl_sec_erase_cycle_count, this->state.wl_dummy_sec_pos);
ESP_LOGV(TAG, "%s - wl_sec_erase_cycle_count= 0x%08" PRIx32 ", pos= 0x%08" PRIx32 , __func__, this->state.wl_sec_erase_cycle_count, this->state.wl_dummy_sec_pos);
// copy data to dummy block
size_t data_addr = this->state.wl_dummy_sec_pos + 1; // next block, [pos+1] copy to [pos]
if (data_addr >= this->state.wl_part_max_sec_pos) {
@ -440,7 +441,7 @@ esp_err_t WL_Flash::updateWL()
this->dummy_addr = this->cfg.wl_partition_start_addr + this->state.wl_dummy_sec_pos * this->cfg.wl_page_size;
result = this->partition->erase_range(this->dummy_addr, this->cfg.wl_page_size);
if (result != ESP_OK) {
ESP_LOGE(TAG, "%s - erase wl dummy sector result= 0x%08x", __func__, result);
ESP_LOGE(TAG, "%s - erase wl dummy sector result= 0x%08x" , __func__, result);
this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time
return result;
}
@ -449,13 +450,13 @@ esp_err_t WL_Flash::updateWL()
for (size_t i = 0; i < copy_count; i++) {
result = this->partition->read(data_addr + i * this->cfg.wl_temp_buff_size, this->temp_buff, this->cfg.wl_temp_buff_size);
if (result != ESP_OK) {
ESP_LOGE(TAG, "%s - not possible to read buffer, will try next time, result= 0x%08x", __func__, result);
ESP_LOGE(TAG, "%s - not possible to read buffer, will try next time, result= 0x%08x" , __func__, result);
this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time
return result;
}
result = this->partition->write(this->dummy_addr + i * this->cfg.wl_temp_buff_size, this->temp_buff, this->cfg.wl_temp_buff_size);
if (result != ESP_OK) {
ESP_LOGE(TAG, "%s - not possible to write buffer, will try next time, result= 0x%08x", __func__, result);
ESP_LOGE(TAG, "%s - not possible to write buffer, will try next time, result= 0x%08x" , __func__, result);
this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time
return result;
}
@ -468,14 +469,14 @@ esp_err_t WL_Flash::updateWL()
// write state to mem. We updating only affected bits
result |= this->partition->write(this->addr_state1 + sizeof(wl_state_t) + byte_pos, this->temp_buff, this->cfg.wl_pos_update_record_size);
if (result != ESP_OK) {
ESP_LOGE(TAG, "%s - update position 1 result= 0x%08x", __func__, result);
ESP_LOGE(TAG, "%s - update position 1 result= 0x%08x" , __func__, result);
this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time
return result;
}
this->fillOkBuff(this->state.wl_dummy_sec_pos);
result |= this->partition->write(this->addr_state2 + sizeof(wl_state_t) + byte_pos, this->temp_buff, this->cfg.wl_pos_update_record_size);
if (result != ESP_OK) {
ESP_LOGE(TAG, "%s - update position 2 result= 0x%08x", __func__, result);
ESP_LOGE(TAG, "%s - update position 2 result= 0x%08x" , __func__, result);
this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1; // we will update next time
return result;
}
@ -499,13 +500,13 @@ esp_err_t WL_Flash::updateWL()
WL_RESULT_CHECK(result);
result = this->partition->write(this->addr_state2, &this->state, sizeof(wl_state_t));
WL_RESULT_CHECK(result);
ESP_LOGD(TAG, "%s - wl_dummy_sec_move_count= 0x%08x, wl_dummy_sec_pos= 0x%08x, ", __func__, this->state.wl_dummy_sec_move_count, this->state.wl_dummy_sec_pos);
ESP_LOGD(TAG, "%s - wl_dummy_sec_move_count= 0x%08" PRIx32 ", wl_dummy_sec_pos= 0x%08" PRIx32 ", ", __func__, this->state.wl_dummy_sec_move_count, this->state.wl_dummy_sec_pos);
}
// Save structures to the flash... and check result
if (result == ESP_OK) {
ESP_LOGV(TAG, "%s - result= 0x%08x", __func__, result);
ESP_LOGV(TAG, "%s - result= 0x%08x" , __func__, result);
} else {
ESP_LOGE(TAG, "%s - result= 0x%08x", __func__, result);
ESP_LOGE(TAG, "%s - result= 0x%08x" , __func__, result);
}
return result;
}
@ -518,7 +519,7 @@ size_t WL_Flash::calcAddr(size_t addr)
} else {
result += this->cfg.wl_page_size;
}
ESP_LOGV(TAG, "%s - addr= 0x%08x -> result= 0x%08x, dummy_addr= 0x%08x", __func__, (uint32_t) addr, (uint32_t) result, (uint32_t)dummy_addr);
ESP_LOGV(TAG, "%s - addr= 0x%08" PRIx32 " -> result= 0x%08" PRIx32 ", dummy_addr= 0x%08" PRIx32 , __func__, (uint32_t) addr, (uint32_t) result, (uint32_t)dummy_addr);
return result;
}
@ -545,7 +546,7 @@ esp_err_t WL_Flash::erase_sector(size_t sector)
if (!this->initialized) {
return ESP_ERR_INVALID_STATE;
}
ESP_LOGD(TAG, "%s - sector= 0x%08x", __func__, (uint32_t) sector);
ESP_LOGD(TAG, "%s - sector= 0x%08" PRIx32 , __func__, (uint32_t) sector);
result = this->updateWL();
WL_RESULT_CHECK(result);
size_t virt_addr = this->calcAddr(sector * this->cfg.flash_sector_size);
@ -560,14 +561,14 @@ esp_err_t WL_Flash::erase_range(size_t start_address, size_t size)
if (!this->initialized) {
return ESP_ERR_INVALID_STATE;
}
ESP_LOGD(TAG, "%s - start_address= 0x%08x, size= 0x%08x", __func__, (uint32_t) start_address, (uint32_t) size);
ESP_LOGD(TAG, "%s - start_address= 0x%08" PRIx32 ", size= 0x%08" PRIx32 , __func__, (uint32_t) start_address, (uint32_t) size);
size_t erase_count = (size + this->cfg.flash_sector_size - 1) / this->cfg.flash_sector_size;
size_t start_sector = start_address / this->cfg.flash_sector_size;
for (size_t i = 0; i < erase_count; i++) {
result = this->erase_sector(start_sector + i);
WL_RESULT_CHECK(result);
}
ESP_LOGV(TAG, "%s - result= 0x%08x", __func__, result);
ESP_LOGV(TAG, "%s - result= 0x%08x" , __func__, result);
return result;
}
@ -577,7 +578,7 @@ esp_err_t WL_Flash::write(size_t dest_addr, const void *src, size_t size)
if (!this->initialized) {
return ESP_ERR_INVALID_STATE;
}
ESP_LOGD(TAG, "%s - dest_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) dest_addr, (uint32_t) size);
ESP_LOGD(TAG, "%s - dest_addr= 0x%08" PRIx32 ", size= 0x%08" PRIx32 , __func__, (uint32_t) dest_addr, (uint32_t) size);
uint32_t count = (size - 1) / this->cfg.wl_page_size;
for (size_t i = 0; i < count; i++) {
size_t virt_addr = this->calcAddr(dest_addr + i * this->cfg.wl_page_size);
@ -596,11 +597,11 @@ esp_err_t WL_Flash::read(size_t src_addr, void *dest, size_t size)
if (!this->initialized) {
return ESP_ERR_INVALID_STATE;
}
ESP_LOGD(TAG, "%s - src_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) src_addr, (uint32_t) size);
ESP_LOGD(TAG, "%s - src_addr= 0x%08" PRIx32 ", size= 0x%08" PRIx32 , __func__, (uint32_t) src_addr, (uint32_t) size);
uint32_t count = (size - 1) / this->cfg.wl_page_size;
for (size_t i = 0; i < count; i++) {
size_t virt_addr = this->calcAddr(src_addr + i * this->cfg.wl_page_size);
ESP_LOGV(TAG, "%s - real_addr= 0x%08x, size= 0x%08x", __func__, (uint32_t) (this->cfg.wl_partition_start_addr + virt_addr), (uint32_t) size);
ESP_LOGV(TAG, "%s - real_addr= 0x%08" PRIx32 ", size= 0x%08" PRIx32 , __func__, (uint32_t) (this->cfg.wl_partition_start_addr + virt_addr), (uint32_t) size);
result = this->partition->read(this->cfg.wl_partition_start_addr + virt_addr, &((uint8_t *)dest)[i * this->cfg.wl_page_size], this->cfg.wl_page_size);
WL_RESULT_CHECK(result);
}
@ -624,6 +625,6 @@ esp_err_t WL_Flash::flush()
esp_err_t result = ESP_OK;
this->state.wl_sec_erase_cycle_count = this->state.wl_max_sec_erase_cycle_count - 1;
result = this->updateWL();
ESP_LOGD(TAG, "%s - result= 0x%08x, wl_dummy_sec_move_count= 0x%08x", __func__, result, this->state.wl_dummy_sec_move_count);
ESP_LOGD(TAG, "%s - result= 0x%08x, wl_dummy_sec_move_count= 0x%08" PRIx32, __func__, result, this->state.wl_dummy_sec_move_count);
return result;
}

View File

@ -3,4 +3,3 @@ idf_component_register(SRCS test_wl.c
PRIV_REQUIRES wear_levelling unity spi_flash
EMBED_FILES test_partition_v1.bin
)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -1,9 +1,10 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <inttypes.h>
#include "unity.h"
#include "unity_fixture.h"
#include "wear_levelling.h"
@ -120,7 +121,7 @@ static void read_write_task(void *param)
uint32_t rval;
err = wl_read(args->handle, args->offset + i * sizeof(rval), &rval, sizeof(rval));
if (err != ESP_OK || rval != val) {
printf("E: i=%d, cnt=%d rval=%d val=%d\n\n", i, args->word_count, rval, val);
printf("E: i=%" PRIu32 ", cnt=%" PRIu32 " rval=%" PRIu32 " val=%" PRIu32 "\n\n", (uint32_t) i, (uint32_t) args->word_count, rval, val);
args->result = ESP_FAIL;
goto done;
}
@ -225,7 +226,7 @@ TEST(wear_levelling, write_doesnt_touch_other_sectors)
// Erase 8 sectors
TEST_ESP_OK(wl_erase_range(handle, 0, sector_size * TEST_SECTORS_COUNT));
// Write data to all sectors
printf("Check 1 sector_size=0x%08x\n", sector_size);
printf("Check 1 sector_size=0x%08" PRIx32 "\n", (uint32_t) sector_size);
// Set initial random value
uint32_t init_val = rand();
@ -256,7 +257,7 @@ TEST(wear_levelling, write_doesnt_touch_other_sectors)
uint32_t end;
end = esp_cpu_get_cycle_count();
uint32_t ms = (end - start) / (esp_clk_cpu_freq() / 1000);
printf("loop %4i pass, time= %ims\n", m, ms);
printf("loop %4d pass, time= %" PRIu32 "ms\n", m, ms);
if (ms > 10000) {
break;
}
@ -288,13 +289,13 @@ TEST(wear_levelling, version_update)
}
fake_partition.size = (size_t)(test_partition_v1_bin_end - test_partition_v1_bin_start);
printf("Data file size = %i, partition address = 0x%08x, file addr=0x%08x\n", (uint32_t)fake_partition.size, (uint32_t)fake_partition.address, (uint32_t)test_partition_v1_bin_start);
printf("Data file size = %" PRIu32 ", partition address = 0x%08" PRIx32 ", file addr=0x%08" PRIx32 "\n", (uint32_t) fake_partition.size, (uint32_t) fake_partition.address, (uint32_t) test_partition_v1_bin_start);
esp_partition_erase_range(&fake_partition, 0, fake_partition.size);
esp_partition_write(&fake_partition, 0, test_partition_v1_bin_start, fake_partition.size);
for (int i = 0; i < 3; i++) {
printf("Pass %i\n", i);
printf("Pass %d\n", i);
wl_handle_t handle;
TEST_ESP_OK(wl_mount(&fake_partition, &handle));
size_t sector_size = wl_sector_size(handle);
@ -308,7 +309,7 @@ TEST(wear_levelling, version_update)
for (int i = 0; i < sector_size / sizeof(uint32_t); i++) {
uint32_t compare_val = init_val + i + m * sector_size;
if (buff[i] != compare_val) {
printf("error compare: 0x%08x != 0x%08x \n", buff[i], compare_val);
printf("error compare: 0x%08" PRIx32 " != 0x%08" PRIx32 " \n", buff[i], compare_val);
}
TEST_ASSERT_EQUAL( buff[i], compare_val);
}

View File

@ -136,14 +136,14 @@ esp_err_t wl_mount(const esp_partition_t *partition, wl_handle_t *out_handle)
// Configure data needed by WL layer for respective flash driver
result = wl_flash->config(&cfg, part);
if (ESP_OK != result) {
ESP_LOGE(TAG, "%s: config instance=0x%08x, result=0x%x", __func__, *out_handle, result);
ESP_LOGE(TAG, "%s: config instance=0x%08" PRIx32 ", result=0x%x", __func__, *out_handle, result);
goto out;
}
// Initialise sectors used by WL layer for respective flash driver
result = wl_flash->init();
if (ESP_OK != result) {
ESP_LOGE(TAG, "%s: init instance=0x%08x, result=0x%x", __func__, *out_handle, result);
ESP_LOGE(TAG, "%s: init instance=0x%08" PRIx32 ", result=0x%x", __func__, *out_handle, result);
goto out;
}
@ -258,11 +258,11 @@ static esp_err_t check_handle(wl_handle_t handle, const char *func)
return ESP_ERR_NOT_FOUND;
}
if (handle >= MAX_WL_HANDLES) {
ESP_LOGE(TAG, "%s: instance[0x%08x] out of range", func, handle);
ESP_LOGE(TAG, "%s: instance[0x%08" PRIx32 "] out of range", func, handle);
return ESP_ERR_INVALID_ARG;
}
if (s_instances[handle].instance == NULL) {
ESP_LOGE(TAG, "%s: instance[0x%08x] not initialized", func, handle);
ESP_LOGE(TAG, "%s: instance[0x%08" PRIx32 "] not initialized", func, handle);
return ESP_ERR_NOT_FOUND;
}
return ESP_OK;