Commit d985d22a authored by Gustavo Henrique Nihei's avatar Gustavo Henrique Nihei Committed by Fabio Utzig
Browse files

espressif: Use BOOT_LOG_* macros instead of the MCUBOOT_LOG_*

Also refined the include directives, by removing unused headers and
making the usage of brackets and quotes a bit more coherent,

Signed-off-by: default avatarGustavo Henrique Nihei <gustavo.nihei@espressif.com>
parent b8c5a6da
Loading
Loading
Loading
Loading
+9 −8
Changes for boot/espressif/main.c: 9 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -5,18 +5,19 @@
 */

#include <bootutil/bootutil.h>
#include <bootutil/bootutil_log.h>
#include <bootutil/fault_injection_hardening.h>
#include <bootutil/image.h>

#include <mcuboot_config/mcuboot_logging.h>
#include "bootloader_init.h"

#include <os/os_malloc.h>
#include <bootloader_init.h>
#include <esp_loader.h>
#include "esp_loader.h"
#include "os/os_malloc.h"

void do_boot(struct boot_rsp *rsp)
{
    MCUBOOT_LOG_INF("br_image_off = 0x%x", rsp->br_image_off);
    MCUBOOT_LOG_INF("ih_hdr_size = 0x%x", rsp->br_hdr->ih_hdr_size);
    BOOT_LOG_INF("br_image_off = 0x%x", rsp->br_image_off);
    BOOT_LOG_INF("ih_hdr_size = 0x%x", rsp->br_hdr->ih_hdr_size);
    int slot = (rsp->br_image_off == CONFIG_ESP_APPLICATION_PRIMARY_START_ADDRESS) ? 0 : 1;
    esp_app_image_load(slot, rsp->br_hdr->ih_hdr_size);
}
@@ -26,7 +27,7 @@ int main()
    bootloader_init();
    struct boot_rsp rsp;
#ifdef MCUBOOT_VER
    MCUBOOT_LOG_INF("*** Booting MCUBoot build %s  ***", MCUBOOT_VER);
    BOOT_LOG_INF("*** Booting MCUBoot build %s  ***", MCUBOOT_VER);
#endif

    os_heap_init();
@@ -34,7 +35,7 @@ int main()
    fih_int fih_rc = FIH_FAILURE;
    FIH_CALL(boot_go, fih_rc, &rsp);
    if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
        MCUBOOT_LOG_ERR("Unable to find bootable image");
        BOOT_LOG_ERR("Unable to find bootable image");
        FIH_PANIC;
    }
    do_boot(&rsp);
+22 −27
Changes for boot/espressif/port/esp_loader.c: 22 added lines, 27 removed lines.
Original line number Diff line number Diff line
@@ -5,28 +5,23 @@
 */

#include <string.h>
#include <soc/soc.h>

#include <bootutil/bootutil_log.h>
#include <bootutil/fault_injection_hardening.h>

#include "bootloader_flash_priv.h"
#include "soc/soc_memory_layout.h"
#include <bootloader_flash.h>
#include <bootloader_flash_priv.h>

#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
#include <soc/dport_reg.h>
#if CONFIG_IDF_TARGET_ESP32
#include "esp32/rom/uart.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/rom/uart.h"
#elif CONFIG_IDF_TARGET_ESP32C3
#include "esp32c3/rom/uart.h"
#endif

#include "rom/cache.h"
#include "rom/efuse.h"
#include "rom/ets_sys.h"
#include "rom/spi_flash.h"
#include "rom/crc.h"
#include "rom/rtc.h"
#include "rom/gpio.h"
#include "rom/uart.h"

#include <esp_loader.h>
#include <bootutil/fault_injection_hardening.h>
#include <flash_map_backend/flash_map_backend.h>
#include <mcuboot_config/mcuboot_logging.h>
#include "esp_loader.h"
#include "flash_map_backend/flash_map_backend.h"

#define ESP_LOAD_HEADER_MAGIC 0xace637d3   /* Magic is derived from sha256sum of espmcuboot */

@@ -48,7 +43,7 @@ static int load_segment(const struct flash_area *fap, uint32_t data_addr, uint32
{
    const uint32_t *data = (const uint32_t *)bootloader_mmap((fap->fa_off + data_addr), data_len);
    if (!data) {
        MCUBOOT_LOG_ERR("%s: Bootloader nmap failed", __func__);
        BOOT_LOG_ERR("%s: Bootloader mmap failed", __func__);
        return -1;
    }
    memcpy((void *)load_addr, data, data_len);
@@ -67,7 +62,7 @@ void esp_app_image_load(int slot, unsigned int hdr_offset)
    area_id = flash_area_id_from_image_slot(slot);
    rc = flash_area_open(area_id, &fap);
    if (rc != 0) {
        MCUBOOT_LOG_ERR("%s: flash_area_open failed with %d", __func__, rc);
        BOOT_LOG_ERR("%s: flash_area_open failed with %d", __func__, rc);
    }

    const uint32_t *data = (const uint32_t *)bootloader_mmap((fap->fa_off + hdr_offset), sizeof(image_load_header_t));
@@ -75,32 +70,32 @@ void esp_app_image_load(int slot, unsigned int hdr_offset)
    bootloader_munmap(data);

    if (load_header.header_magic != ESP_LOAD_HEADER_MAGIC) {
        MCUBOOT_LOG_ERR("Load header magic verification failed. Aborting");
        BOOT_LOG_ERR("Load header magic verification failed. Aborting");
        FIH_PANIC;
    }

    if (!esp_ptr_in_iram((void *)load_header.iram_dest_addr) || !esp_ptr_in_iram((void *)(load_header.iram_dest_addr + load_header.iram_size))) {
        MCUBOOT_LOG_ERR("IRAM region in load header is not valid. Aborting");
        BOOT_LOG_ERR("IRAM region in load header is not valid. Aborting");
        FIH_PANIC;
    }

    if (!esp_ptr_in_dram((void *)load_header.dram_dest_addr) || !esp_ptr_in_dram((void *)load_header.dram_dest_addr + load_header.dram_size)) {
        MCUBOOT_LOG_ERR("DRAM region in load header is not valid. Aborting");
        BOOT_LOG_ERR("DRAM region in load header is not valid. Aborting");
        FIH_PANIC;
    }

    if (!esp_ptr_in_iram((void *)load_header.entry_addr)) {
        MCUBOOT_LOG_ERR("Application entry point (0x%x) is not in IRAM. Aborting", load_header.entry_addr);
        BOOT_LOG_ERR("Application entry point (0x%x) is not in IRAM. Aborting", load_header.entry_addr);
        FIH_PANIC;
    }

    MCUBOOT_LOG_INF("DRAM segment: start=0x%x, size=0x%x, vaddr=0x%x", load_header.dram_flash_offset, load_header.dram_size, load_header.dram_dest_addr);
    BOOT_LOG_INF("DRAM segment: start=0x%x, size=0x%x, vaddr=0x%x", load_header.dram_flash_offset, load_header.dram_size, load_header.dram_dest_addr);
    load_segment(fap, load_header.dram_flash_offset, load_header.dram_size, load_header.dram_dest_addr);

    MCUBOOT_LOG_INF("IRAM segment: start=0x%x, size=0x%x, vaddr=0x%x", load_header.iram_flash_offset, load_header.iram_size, load_header.iram_dest_addr);
    BOOT_LOG_INF("IRAM segment: start=0x%x, size=0x%x, vaddr=0x%x", load_header.iram_flash_offset, load_header.iram_size, load_header.iram_dest_addr);
    load_segment(fap, load_header.iram_flash_offset, load_header.iram_size, load_header.iram_dest_addr);

    MCUBOOT_LOG_INF("start=0x%x", load_header.entry_addr);
    BOOT_LOG_INF("start=0x%x", load_header.entry_addr);
    uart_tx_wait_idle(0);
    void *start = (void *) load_header.entry_addr;
    ((void (*)(void))start)(); /* Call to application entry address should not return */
+20 −19
Changes for boot/espressif/port/esp_mcuboot.c: 20 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -4,18 +4,19 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

#include "mcuboot_config/mcuboot_logging.h"
#include "flash_map_backend/flash_map_backend.h"
#include "sysflash/sysflash.h"
#include "bootutil/bootutil.h"
#include <bootutil/bootutil.h>
#include <bootutil/bootutil_log.h>

#include "esp_err.h"
#include "bootloader_flash.h"
#include "bootloader_flash_priv.h"

#include "flash_map_backend/flash_map_backend.h"
#include "sysflash/sysflash.h"

#ifndef ARRAY_SIZE
#  define ARRAY_SIZE(arr)           (sizeof(arr) / sizeof((arr)[0]))
#endif
@@ -101,7 +102,7 @@ static const struct flash_area *prv_lookup_flash_area(uint8_t id) {

int flash_area_open(uint8_t id, const struct flash_area **area_outp)
{
    MCUBOOT_LOG_DBG("%s: ID=%d", __func__, (int)id);
    BOOT_LOG_DBG("%s: ID=%d", __func__, (int)id);
    const struct flash_area *area = prv_lookup_flash_area(id);
    *area_outp = area;
    return area != NULL ? 0 : -1;
@@ -168,13 +169,13 @@ int flash_area_read(const struct flash_area *fa, uint32_t off, void *dst,

    const uint32_t end_offset = off + len;
    if (end_offset > fa->fa_size) {
        MCUBOOT_LOG_ERR("%s: Out of Bounds (0x%x vs 0x%x)", __func__, end_offset, fa->fa_size);
        BOOT_LOG_ERR("%s: Out of Bounds (0x%x vs 0x%x)", __func__, end_offset, fa->fa_size);
        return -1;
    }

    bool success = aligned_flash_read(fa->fa_off + off, dst, len);
    if (!success) {
        MCUBOOT_LOG_ERR("%s: Flash read failed", __func__);
        BOOT_LOG_ERR("%s: Flash read failed", __func__);

        return -1;
    }
@@ -191,15 +192,15 @@ int flash_area_write(const struct flash_area *fa, uint32_t off, const void *src,

    const uint32_t end_offset = off + len;
    if (end_offset > fa->fa_size) {
        MCUBOOT_LOG_ERR("%s: Out of Bounds (0x%x vs 0x%x)", __func__, end_offset, fa->fa_size);
        BOOT_LOG_ERR("%s: Out of Bounds (0x%x vs 0x%x)", __func__, end_offset, fa->fa_size);
        return -1;
    }

    const uint32_t start_addr = fa->fa_off + off;
    MCUBOOT_LOG_DBG("%s: Addr: 0x%08x Length: %d", __func__, (int)start_addr, (int)len);
    BOOT_LOG_DBG("%s: Addr: 0x%08x Length: %d", __func__, (int)start_addr, (int)len);

    if (bootloader_flash_write(start_addr, (void *)src, len, false) != ESP_OK) {
        MCUBOOT_LOG_ERR("%s: Flash write failed", __func__);
        BOOT_LOG_ERR("%s: Flash write failed", __func__);
        return -1;
    }

@@ -213,23 +214,23 @@ int flash_area_erase(const struct flash_area *fa, uint32_t off, uint32_t len)
    }

    if ((len % FLASH_SECTOR_SIZE) != 0 || (off % FLASH_SECTOR_SIZE) != 0) {
        MCUBOOT_LOG_ERR("%s: Not aligned on sector Offset: 0x%x Length: 0x%x", __func__,
                    (int)off, (int)len);
        BOOT_LOG_ERR("%s: Not aligned on sector Offset: 0x%x Length: 0x%x",
                     __func__, (int)off, (int)len);
        return -1;
    }

    const uint32_t start_addr = fa->fa_off + off;
    MCUBOOT_LOG_DBG("%s: Addr: 0x%08x Length: %d", __func__, (int)start_addr, (int)len);
    BOOT_LOG_DBG("%s: Addr: 0x%08x Length: %d", __func__, (int)start_addr, (int)len);

    if (bootloader_flash_erase_range(start_addr, len) != ESP_OK) {
        MCUBOOT_LOG_ERR("%s: Flash erase failed", __func__);
        BOOT_LOG_ERR("%s: Flash erase failed", __func__);
        return -1;
    }
#if VALIDATE_PROGRAM_OP
    for (size_t i = 0; i < len; i++) {
        uint8_t *val = (void *)(start_addr + i);
        if (*val != 0xff) {
            MCUBOOT_LOG_ERR("%s: Erase at 0x%x Failed", __func__, (int)val);
            BOOT_LOG_ERR("%s: Erase at 0x%x Failed", __func__, (int)val);
            assert(0);
        }
    }
@@ -271,7 +272,7 @@ int flash_area_get_sectors(int fa_id, uint32_t *count,

int flash_area_id_from_multi_image_slot(int image_index, int slot)
{
    MCUBOOT_LOG_DBG("%s", __func__);
    BOOT_LOG_DBG("%s", __func__);
    switch (slot) {
      case 0:
        return FLASH_AREA_IMAGE_PRIMARY(image_index);
@@ -279,7 +280,7 @@ int flash_area_id_from_multi_image_slot(int image_index, int slot)
        return FLASH_AREA_IMAGE_SECONDARY(image_index);
    }

    MCUBOOT_LOG_ERR("Unexpected Request: image_index=%d, slot=%d", image_index, slot);
    BOOT_LOG_ERR("Unexpected Request: image_index=%d, slot=%d", image_index, slot);
    return -1; /* flash_area_open will fail on that */
}