Initial commit

Initial commit.
This commit is contained in:
kntran1
2026-03-23 14:40:39 -05:00
parent e84b2b4166
commit 4e2a5258a5
872 changed files with 165227 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
# Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
#
# SPDX-License-Identifier: Apache-2.0
set(MBEDTLS_ASN1_DIR "${MCUBOOT_ROOT_DIR}/ext/mbedtls-asn1")
set(CRYPTO_INC
${MBEDTLS_ASN1_DIR}/include
)
set(crypto_srcs
# Additionally pull in just the ASN.1 parser from Mbed TLS.
${MBEDTLS_ASN1_DIR}/src/asn1parse.c
${MBEDTLS_ASN1_DIR}/src/platform_util.c
)
if (DEFINED CONFIG_ESP_USE_MBEDTLS)
message(FATAL_ERROR "EC256 signature verification using Mbed TLS lib is not supported")
elseif (DEFINED CONFIG_ESP_USE_TINYCRYPT)
set(TINYCRYPT_DIR ${MCUBOOT_ROOT_DIR}/ext/tinycrypt/lib)
list(APPEND CRYPTO_INC
${TINYCRYPT_DIR}/include
)
list(APPEND crypto_srcs
${ESPRESSIF_PORT_DIR}/keys.c
${TINYCRYPT_DIR}/source/utils.c
${TINYCRYPT_DIR}/source/sha256.c
${TINYCRYPT_DIR}/source/ecc.c
${TINYCRYPT_DIR}/source/ecc_dsa.c
)
endif()

View File

@@ -0,0 +1,31 @@
# Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
#
# SPDX-License-Identifier: Apache-2.0
set(MBEDTLS_ASN1_DIR "${MCUBOOT_ROOT_DIR}/ext/mbedtls-asn1")
set(CRYPTO_INC
${MBEDTLS_ASN1_DIR}/include
)
set(crypto_srcs
# Additionally pull in just the ASN.1 parser from Mbed TLS.
${MBEDTLS_ASN1_DIR}/src/asn1parse.c
${MBEDTLS_ASN1_DIR}/src/platform_util.c
)
if (DEFINED CONFIG_ESP_USE_MBEDTLS)
message(FATAL_ERROR "ED25519 image signing using Mbed TLS lib is not supported")
elseif (DEFINED CONFIG_ESP_USE_TINYCRYPT)
set(TINYCRYPT_DIR ${MCUBOOT_ROOT_DIR}/ext/tinycrypt/lib)
set(TINYCRYPT512_DIR ${MCUBOOT_ROOT_DIR}/ext/tinycrypt-sha512/lib)
list(APPEND CRYPTO_INC
${TINYCRYPT_DIR}/include
${TINYCRYPT512_DIR}/include
)
list(APPEND crypto_srcs
${ESPRESSIF_PORT_DIR}/keys.c
${TINYCRYPT_DIR}/source/utils.c
${TINYCRYPT_DIR}/source/sha256.c
${TINYCRYPT512_DIR}/source/sha512.c
${MCUBOOT_ROOT_DIR}/ext/fiat/src/curve25519.c
)
endif()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
# Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
#
# SPDX-License-Identifier: Apache-2.0
if (DEFINED CONFIG_ESP_USE_MBEDTLS)
set(MBEDTLS_DIR ${MCUBOOT_ROOT_DIR}/ext/mbedtls)
set(CRYPTO_INC
${MBEDTLS_DIR}/include
)
set(crypto_srcs
${ESPRESSIF_PORT_DIR}/keys.c
${MBEDTLS_DIR}/library/platform.c
${MBEDTLS_DIR}/library/platform_util.c
${MBEDTLS_DIR}/library/sha256.c
${MBEDTLS_DIR}/library/rsa.c
${MBEDTLS_DIR}/library/bignum.c
${MBEDTLS_DIR}/library/asn1parse.c
${MBEDTLS_DIR}/library/md.c
${MBEDTLS_DIR}/library/memory_buffer_alloc.c
)
if (DEFINED MBEDTLS_CONFIG_FILE)
add_definitions(-DMBEDTLS_CONFIG_FILE=\"${MBEDTLS_CONFIG_FILE}\")
else()
add_definitions(-DMBEDTLS_CONFIG_FILE=\"${ESPRESSIF_PORT_DIR}/include/crypto_config/mbedtls_custom_config.h\")
endif()
elseif (DEFINED CONFIG_ESP_USE_TINYCRYPT)
message(FATAL_ERROR "RSA signature verification using Tinycrypt lib is not supported")
endif()

View File

@@ -0,0 +1,14 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
void start_cpu0_image(int image_index, int slot, unsigned int hdr_offset);
#ifdef CONFIG_ESP_MULTI_PROCESSOR_BOOT
void start_cpu1_image(int image_index, int slot, unsigned int hdr_offset);
#endif
void esp_app_image_load(int image_index, int slot, unsigned int hdr_offset, unsigned int *entry_addr);

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <inttypes.h>
struct flash_area {
uint8_t fa_id; /** The slot/scratch identification */
uint8_t fa_device_id; /** The device id (usually there's only one) */
uint16_t pad16;
uint32_t fa_off; /** The flash offset from the beginning */
uint32_t fa_size; /** The size of this sector */
};
//! Structure describing a sector within a flash area.
struct flash_sector {
//! Offset of this sector, from the start of its flash area (not device).
uint32_t fs_off;
//! Size of this sector, in bytes.
uint32_t fs_size;
};
static inline uint8_t flash_area_get_device_id(const struct flash_area *fa)
{
return (uint8_t)fa->fa_device_id;
}
static inline uint32_t flash_area_get_off(const struct flash_area *fa)
{
return (uint32_t)fa->fa_off;
}
static inline uint32_t flash_area_get_size(const struct flash_area *fa)
{
return (uint32_t)fa->fa_size;
}
static inline uint8_t flash_area_get_id(const struct flash_area *fa)
{
return fa->fa_id;
}
static inline uint32_t flash_sector_get_off(const struct flash_sector *fs)
{
return fs->fs_off;
}
static inline uint32_t flash_sector_get_size(const struct flash_sector *fs)
{
return fs->fs_size;
}
//! Opens the area for use. id is one of the `fa_id`s */
int flash_area_open(uint8_t id, const struct flash_area **area_outp);
void flash_area_close(const struct flash_area *fa);
//! Reads `len` bytes of flash memory at `off` to the buffer at `dst`
int flash_area_read(const struct flash_area *fa, uint32_t off,
void *dst, uint32_t len);
//! Writes `len` bytes of flash memory at `off` from the buffer at `src`
int flash_area_write(const struct flash_area *fa, uint32_t off,
const void *src, uint32_t len);
//! Erases `len` bytes of flash memory at `off`
int flash_area_erase(const struct flash_area *fa,
uint32_t off, uint32_t len);
//! Returns this `flash_area`s alignment
uint32_t flash_area_align(const struct flash_area *area);
//! Returns the value read from an erased flash area byte
uint8_t flash_area_erased_val(const struct flash_area *area);
//! Given flash area ID, return info about sectors within the area
int flash_area_get_sectors(int fa_id, uint32_t *count,
struct flash_sector *sectors);
//! Retrieve the flash sector a given offset belongs to.
int flash_area_sector_from_off(uint32_t off, struct flash_sector *sector);
//! Retrieve the flash sector a given offset belongs to.
int flash_area_get_sector(const struct flash_area *area, uint32_t off,
struct flash_sector *sector);
//! Returns the `fa_id` for slot, where slot is 0 (primary) or 1 (secondary).
//!
//! `image_index` (0 or 1) is the index of the image. Image index is
//! relevant only when multi-image support support is enabled
int flash_area_id_from_multi_image_slot(int image_index, int slot);
int flash_area_id_from_image_slot(int slot);
int flash_area_to_sectors(int idx, int *cnt, struct flash_area *fa);

View File

@@ -0,0 +1,11 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdlib.h>
void os_heap_init(void);

View File

@@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
/**
* Serial write implementation used by MCUboot boot serial structure
* in boot_serial.h
*/
void console_write(const char *str, int cnt);
/**
* Serial read implementation used by MCUboot boot serial structure
* in boot_serial.h
*/
int console_read(char *str, int str_cnt, int *newline);
/**
* Initialize GPIOs used by console serial read/write
*/
void boot_console_init(void);
/**
* Check if serial recovery detection pin is active
*/
bool boot_serial_detect_pin(void);

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <mcuboot_config/mcuboot_config.h>
//! A user-defined identifier for different storage mediums
//! (i.e internal flash, external NOR flash, eMMC, etc)
#define FLASH_DEVICE_INTERNAL_FLASH 0
//! An arbitrarily high slot ID we will use to indicate that
//! there is not slot
#define FLASH_SLOT_DOES_NOT_EXIST 255
//! The slot we will use to track the bootloader allocation
#define FLASH_AREA_BOOTLOADER 0
#define FLASH_AREA_IMAGE_0_PRIMARY 1
#define FLASH_AREA_IMAGE_0_SECONDARY 2
#define FLASH_AREA_IMAGE_SCRATCH 3
#define FLASH_AREA_IMAGE_1_PRIMARY 4
#define FLASH_AREA_IMAGE_1_SECONDARY 5
#if (MCUBOOT_IMAGE_NUMBER == 1)
#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? \
FLASH_AREA_IMAGE_0_PRIMARY : \
FLASH_SLOT_DOES_NOT_EXIST)
#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? \
FLASH_AREA_IMAGE_0_SECONDARY : \
FLASH_SLOT_DOES_NOT_EXIST)
#elif (MCUBOOT_IMAGE_NUMBER == 2)
#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? \
FLASH_AREA_IMAGE_0_PRIMARY : \
((x) == 1) ? \
FLASH_AREA_IMAGE_1_PRIMARY : \
FLASH_SLOT_DOES_NOT_EXIST)
#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? \
FLASH_AREA_IMAGE_0_SECONDARY : \
((x) == 1) ? \
FLASH_AREA_IMAGE_1_SECONDARY : \
FLASH_SLOT_DOES_NOT_EXIST)
#else
#warning "Image slot and flash area mapping is not defined"
#endif