Unverified Commit c216d34b authored by Andrzej Puzdrowski's avatar Andrzej Puzdrowski Committed by GitHub
Browse files

Synch up to upstream mcu-tools 3175182f

parents 3b791288 3175182f
Loading
Loading
Loading
Loading
+43 −7
Original line number Diff line number Diff line
@@ -28,15 +28,23 @@
#include "zcbor_encode.h"

#ifdef __ZEPHYR__
#include <sys/reboot.h>
#include <sys/byteorder.h>
#include <sys/__assert.h>
#include <drivers/flash.h>
#include <sys/crc.h>
#include <sys/base64.h>
#include <zephyr/sys/reboot.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/drivers/flash.h>
#include <zephyr/sys/crc.h>
#include <zephyr/sys/base64.h>
#include <hal/hal_flash.h>
#elif __ESPRESSIF__
#include <bootloader_utility.h>
#include <esp_rom_sys.h>
#include <rom/crc.h>
#include <endian.h>
#include <mbedtls/base64.h>
#else
#include <bsp/bsp.h>
#include <hal/hal_system.h>
#include <hal/hal_flash.h>
#include <os/endian.h>
#include <os/os_cputime.h>
#include <crc/crc16.h>
@@ -44,7 +52,6 @@
#endif /* __ZEPHYR__ */

#include <flash_map_backend/flash_map_backend.h>
#include <hal/hal_flash.h>
#include <os/os.h>
#include <os/os_malloc.h>

@@ -53,6 +60,7 @@

#include "boot_serial/boot_serial.h"
#include "boot_serial_priv.h"
#include "mcuboot_config/mcuboot_config.h"

#ifdef MCUBOOT_ERASE_PROGRESSIVELY
#include "bootutil_priv.h"
@@ -80,6 +88,15 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);

#define ntohs(x) sys_be16_to_cpu(x)
#define htons(x) sys_cpu_to_be16(x)
#elif __ESPRESSIF__
#define BASE64_ENCODE_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1)
#define CRC16_INITIAL_CRC       0       /* what to seed crc16 with */

#define ntohs(x) be16toh(x)
#define htons(x) htobe16(x)

#define base64_decode mbedtls_base64_decode
#define base64_encode mbedtls_base64_encode
#endif

#if (BOOT_IMAGE_NUMBER > 1)
@@ -612,6 +629,9 @@ bs_reset(char *buf, int len)
    k_busy_wait(250000);
#endif
    sys_reboot(SYS_REBOOT_COLD);
#elif __ESPRESSIF__
    esp_rom_delay_us(250000);
    bootloader_reset();
#else
    os_cputime_delay_usecs(250000);
    hal_system_reset();
@@ -707,6 +727,10 @@ boot_serial_output(void)
#ifdef __ZEPHYR__
    crc =  crc16_itu_t(CRC16_INITIAL_CRC, (uint8_t *)bs_hdr, sizeof(*bs_hdr));
    crc =  crc16_itu_t(crc, data, len);
#elif __ESPRESSIF__
    /* For ESP32 it was used the CRC API in rom/crc.h */
    crc =  ~crc16_be(~CRC16_INITIAL_CRC, (uint8_t *)bs_hdr, sizeof(*bs_hdr));
    crc =  ~crc16_be(~crc, (uint8_t *)data, len);
#else
    crc = crc16_ccitt(CRC16_INITIAL_CRC, bs_hdr, sizeof(*bs_hdr));
    crc = crc16_ccitt(crc, data, len);
@@ -730,6 +754,10 @@ boot_serial_output(void)
    size_t enc_len;
    base64_encode(encoded_buf, sizeof(encoded_buf), &enc_len, buf, totlen);
    totlen = enc_len;
#elif __ESPRESSIF__
    size_t enc_len;
    base64_encode((unsigned char *)encoded_buf, sizeof(encoded_buf), &enc_len, (unsigned char *)buf, totlen);
    totlen = enc_len;
#else
    totlen = base64_encode(buf, totlen, encoded_buf, 1);
#endif
@@ -754,6 +782,12 @@ boot_serial_in_dec(char *in, int inlen, char *out, int *out_off, int maxout)
    if (err) {
        return -1;
    }
#elif __ESPRESSIF__
    int err;
    err = base64_decode((unsigned char *)&out[*out_off], maxout - *out_off, (size_t *)&rc, (unsigned char *)in, inlen);
    if (err) {
        return -1;
    }
#else
    if (*out_off + base64_decode_len(in) >= maxout) {
        return -1;
@@ -781,6 +815,8 @@ boot_serial_in_dec(char *in, int inlen, char *out, int *out_off, int maxout)
    out += sizeof(uint16_t);
#ifdef __ZEPHYR__
    crc = crc16_itu_t(CRC16_INITIAL_CRC, out, len);
#elif __ESPRESSIF__
    crc = ~crc16_be(~CRC16_INITIAL_CRC, (uint8_t *)out, len);
#else
    crc = crc16_ccitt(CRC16_INITIAL_CRC, out, len);
#endif
+2 −2
Original line number Diff line number Diff line
@@ -92,8 +92,8 @@ int cbor_decode_Upload(
	}

	if (!ret) {
		int ret = zcbor_pop_error(states);
		return (ret == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : ret;
		int status = zcbor_pop_error(states);
		return (status == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : status;
	}
	return ZCBOR_SUCCESS;
}
+30 −3
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ endif()
project(mcuboot_${MCUBOOT_TARGET})

add_definitions(-DMCUBOOT_TARGET=${MCUBOOT_TARGET})
add_definitions(-D__ESPRESSIF__=1)

if ("${MCUBOOT_TARGET}" STREQUAL "esp32" OR
    "${MCUBOOT_TARGET}" STREQUAL "esp32s2" OR
@@ -70,6 +71,7 @@ set(APP_EXECUTABLE ${APP_NAME}.elf)

set(MCUBOOT_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
set(BOOTUTIL_DIR ${MCUBOOT_ROOT_DIR}/boot/bootutil)
set(BOOT_SERIAL_DIR ${MCUBOOT_ROOT_DIR}/boot/boot_serial)
set(ESPRESSIF_PORT_DIR ${CMAKE_CURRENT_LIST_DIR})

# Find imgtool.
@@ -207,20 +209,45 @@ target_compile_options(
    ${CFLAGS}
    )

set(port_srcs
    ${CMAKE_CURRENT_LIST_DIR}/port/esp_mcuboot.c
    ${CMAKE_CURRENT_LIST_DIR}/port/esp_loader.c
    ${CMAKE_CURRENT_LIST_DIR}/os.c
    ${CMAKE_CURRENT_LIST_DIR}/serial_adapter.c
    )

if(CONFIG_ESP_MCUBOOT_SERIAL)
    set(MBEDTLS_DIR "${MCUBOOT_ROOT_DIR}/ext/mbedtls")

    list(APPEND bootutil_srcs
        ${BOOT_SERIAL_DIR}/src/boot_serial.c
        ${BOOT_SERIAL_DIR}/src/serial_recovery_cbor.c
        ${BOOT_SERIAL_DIR}/src/zcbor_decode.c
        ${BOOT_SERIAL_DIR}/src/zcbor_encode.c
        ${BOOT_SERIAL_DIR}/src/zcbor_common.c
        )
    list(APPEND port_srcs
        ${CMAKE_CURRENT_LIST_DIR}/serial_adapter.c
        ${MBEDTLS_DIR}/library/base64.c
        )
    list(APPEND CRYPTO_INC
        ${MBEDTLS_DIR}/include
        )
endif()

target_sources(
    ${APP_EXECUTABLE}
    PUBLIC
    ${bootutil_srcs}
    ${crypto_srcs}
    ${CMAKE_CURRENT_LIST_DIR}/port/esp_mcuboot.c
    ${CMAKE_CURRENT_LIST_DIR}/port/esp_loader.c
    ${CMAKE_CURRENT_LIST_DIR}/os.c
    ${port_srcs}
    )

target_include_directories(
    ${APP_EXECUTABLE}
    PUBLIC
    ${BOOTUTIL_DIR}/include
    ${BOOT_SERIAL_DIR}/include
    ${CRYPTO_INC}
    ${CMAKE_CURRENT_LIST_DIR}/include
    )
+3 −0
Original line number Diff line number Diff line
@@ -58,7 +58,10 @@ set(hal_srcs
    ${src_dir}/${MCUBOOT_TARGET}/bootloader_init.c
    ${esp_idf_dir}/components/hal/mpu_hal.c
    ${esp_idf_dir}/components/hal/soc_hal.c
    ${esp_idf_dir}/components/soc/${MCUBOOT_TARGET}/uart_periph.c
    ${esp_idf_dir}/components/soc/${MCUBOOT_TARGET}/gpio_periph.c
    ${esp_idf_dir}/components/bootloader_support/src/bootloader_common_loader.c
    ${esp_idf_dir}/components/bootloader_support/src/bootloader_console.c
    ${esp_idf_dir}/components/bootloader_support/src/bootloader_console_loader.c
    ${esp_idf_dir}/components/bootloader_support/src/bootloader_flash.c
    ${esp_idf_dir}/components/bootloader_support/src/bootloader_flash_config_${MCUBOOT_TARGET}.c
+12 −0
Original line number Diff line number Diff line
@@ -139,6 +139,14 @@
 * "assert" is used. */
#define MCUBOOT_HAVE_ASSERT_H 1

#ifdef CONFIG_ESP_MCUBOOT_SERIAL
#define CONFIG_MCUBOOT_SERIAL
#endif

/* Serial extensions are not implemented
 */
#define MCUBOOT_PERUSER_MGMT_GROUP_ENABLED 0

/*
 * Watchdog feeding
 */
@@ -154,4 +162,8 @@
          bootloader_wdt_feed(); \
      } while (0)

#define MCUBOOT_CPU_IDLE() \
    do {                   \
    } while (0)

#endif /* __MCUBOOT_CONFIG_H__ */
Loading