From 5add6593f49c432464497296fb4f2a032858ffe7 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Sat, 6 Nov 2021 17:29:29 +0800 Subject: [PATCH] ESP8684: Add esp_gdbstub, mbedtls, esp_timer --- components/esp_gdbstub/CMakeLists.txt | 2 + .../esp_gdbstub/esp8684/gdbstub_esp8684.c | 86 +++++++++++++++++++ .../esp8684/gdbstub_target_config.h | 7 ++ components/esp_gdbstub/src/gdbstub.c | 18 ++-- components/esp_timer/src/esp_timer.c | 2 + components/esp_timer/src/system_time.c | 20 ++--- components/mbedtls/Kconfig | 6 +- .../mbedtls/port/esp_ds/esp_rsa_sign_alt.c | 20 ++--- components/mbedtls/port/include/md/esp_md.h | 4 + components/mbedtls/port/md/esp_md.c | 21 ++--- components/mbedtls/port/sha/dma/sha.c | 2 + 11 files changed, 133 insertions(+), 55 deletions(-) create mode 100644 components/esp_gdbstub/esp8684/gdbstub_esp8684.c create mode 100644 components/esp_gdbstub/esp8684/gdbstub_target_config.h diff --git a/components/esp_gdbstub/CMakeLists.txt b/components/esp_gdbstub/CMakeLists.txt index 797448b10a..de74a99b48 100644 --- a/components/esp_gdbstub/CMakeLists.txt +++ b/components/esp_gdbstub/CMakeLists.txt @@ -1,11 +1,13 @@ idf_build_get_property(target IDF_TARGET) +if(NOT "${target}" STREQUAL "esp8684") # TODO: IDF-4135 idf_component_register(SRCS "src/gdbstub.c" "src/packet.c" INCLUDE_DIRS "include" PRIV_INCLUDE_DIRS "private_include" LDFRAGMENTS "linker.lf" REQUIRES "freertos" PRIV_REQUIRES "soc" "esp_rom") +endif() if(CONFIG_IDF_TARGET_ARCH_XTENSA) target_include_directories(${COMPONENT_LIB} PUBLIC "xtensa" "${target}") diff --git a/components/esp_gdbstub/esp8684/gdbstub_esp8684.c b/components/esp_gdbstub/esp8684/gdbstub_esp8684.c new file mode 100644 index 0000000000..ef50621482 --- /dev/null +++ b/components/esp_gdbstub/esp8684/gdbstub_esp8684.c @@ -0,0 +1,86 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "soc/uart_periph.h" +#include "soc/gpio_periph.h" +#include "soc/soc.h" +#include "esp_gdbstub_common.h" +#include "sdkconfig.h" + +#define UART_NUM CONFIG_ESP_CONSOLE_UART_NUM + +#define GDBSTUB_MEM_REGION_COUNT 9 + +#define UART_REG_FIELD_LEN 0x84 + +typedef struct { + intptr_t lower; + intptr_t upper; +} mem_bound_t; + +static const mem_bound_t mem_region_table [GDBSTUB_MEM_REGION_COUNT] = +{ + {SOC_DROM_LOW, SOC_DROM_HIGH}, + {SOC_IROM_LOW, SOC_IROM_HIGH}, + {SOC_IRAM_LOW, SOC_IRAM_HIGH}, + {SOC_DRAM_LOW, SOC_DRAM_HIGH}, + {SOC_IROM_MASK_LOW, SOC_IROM_MASK_HIGH}, + {SOC_DROM_MASK_LOW, SOC_DROM_MASK_HIGH}, + // RTC DRAM and RTC DATA are identical with RTC IRAM, hence we skip them + // We shouldn't read the uart registers since it will disturb the debugging via UART, + // so skip UART part of the peripheral registers. + {DR_REG_UART_BASE + UART_REG_FIELD_LEN, SOC_PERIPHERAL_HIGH}, + {SOC_DEBUG_LOW, SOC_DEBUG_HIGH}, +}; + +static inline bool check_inside_valid_region(intptr_t addr) +{ + for (size_t i = 0; i < GDBSTUB_MEM_REGION_COUNT; i++) { + if (addr >= mem_region_table[i].lower && addr < mem_region_table[i].upper) { + return true; + } + } + + return false; +} + +void esp_gdbstub_target_init() +{ +} + +//assume UART gdbstub channel + +int esp_gdbstub_getchar() +{ + while (REG_GET_FIELD(UART_STATUS_REG(UART_NUM), UART_RXFIFO_CNT) == 0) { + ; + } + return REG_READ(UART_FIFO_AHB_REG(UART_NUM)); +} + +void esp_gdbstub_putchar(int c) +{ + while (REG_GET_FIELD(UART_STATUS_REG(UART_NUM), UART_TXFIFO_CNT) >= 126) { + ; + } + REG_WRITE(UART_FIFO_AHB_REG(UART_NUM), c); +} + +void esp_gdbstub_flush() +{ + //not needed for uart +} + +int esp_gdbstub_readmem(intptr_t addr) +{ + if (!check_inside_valid_region(addr)) { + /* see esp_cpu_configure_region_protection */ + return -1; + } + uint32_t val_aligned = *(uint32_t *)(addr & (~3)); + uint32_t shift = (addr & 3) * 8; + return (val_aligned >> shift) & 0xff; +} diff --git a/components/esp_gdbstub/esp8684/gdbstub_target_config.h b/components/esp_gdbstub/esp8684/gdbstub_target_config.h new file mode 100644 index 0000000000..2cdcefb5f7 --- /dev/null +++ b/components/esp_gdbstub/esp8684/gdbstub_target_config.h @@ -0,0 +1,7 @@ +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once diff --git a/components/esp_gdbstub/src/gdbstub.c b/components/esp_gdbstub/src/gdbstub.c index 1361a64e73..2ef12cd11a 100644 --- a/components/esp_gdbstub/src/gdbstub.c +++ b/components/esp_gdbstub/src/gdbstub.c @@ -1,16 +1,8 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include "esp_gdbstub.h" diff --git a/components/esp_timer/src/esp_timer.c b/components/esp_timer/src/esp_timer.c index fbabcfda4a..0ad6bb76f9 100644 --- a/components/esp_timer/src/esp_timer.c +++ b/components/esp_timer/src/esp_timer.c @@ -33,6 +33,8 @@ #include "esp32c3/rtc.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rtc.h" +#elif CONFIG_IDF_TARGET_ESP8684 +#include "esp8684/rtc.h" #endif #include "sdkconfig.h" diff --git a/components/esp_timer/src/system_time.c b/components/esp_timer/src/system_time.c index d31abaaca7..951d089a82 100644 --- a/components/esp_timer/src/system_time.c +++ b/components/esp_timer/src/system_time.c @@ -1,16 +1,8 @@ -// Copyright 2017 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // Provides strong definition for system time functions relied upon // by core components. @@ -35,6 +27,8 @@ #include "esp32c3/rtc.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rtc.h" +#elif CONFIG_IDF_TARGET_ESP8684 +#include "esp8684/rtc.h" #endif __attribute__((unused)) static const char* TAG = "system_time"; diff --git a/components/mbedtls/Kconfig b/components/mbedtls/Kconfig index 978727db97..9556959323 100644 --- a/components/mbedtls/Kconfig +++ b/components/mbedtls/Kconfig @@ -239,7 +239,7 @@ menu "mbedTLS" config MBEDTLS_HARDWARE_AES bool "Enable hardware AES acceleration" default y - depends on !SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST + depends on !SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST && !IDF_TARGET_ESP8684 help Enable hardware accelerated AES encryption & decryption. @@ -271,7 +271,7 @@ menu "mbedTLS" config MBEDTLS_HARDWARE_MPI bool "Enable hardware MPI (bignum) acceleration" default y - depends on !SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST + depends on !SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST && !IDF_TARGET_ESP8684 help Enable hardware accelerated multiple precision integer operations. @@ -893,7 +893,7 @@ menu "mbedTLS" config MBEDTLS_LARGE_KEY_SOFTWARE_MPI bool "Fallback to software implementation for larger MPI values" depends on MBEDTLS_HARDWARE_MPI - default y if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32H2 # HW max 3072 bits + default y if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32H2 || IDF_TARGET_ESP8684 # HW max 3072 bits default n help Fallback to software implementation for RSA key lengths diff --git a/components/mbedtls/port/esp_ds/esp_rsa_sign_alt.c b/components/mbedtls/port/esp_ds/esp_rsa_sign_alt.c index b0914cf01e..4088be2563 100644 --- a/components/mbedtls/port/esp_ds/esp_rsa_sign_alt.c +++ b/components/mbedtls/port/esp_ds/esp_rsa_sign_alt.c @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "esp_ds.h" #include "rsa_sign_alt.h" @@ -23,6 +15,8 @@ #include "esp32h2/rom/digital_signature.h" #elif CONFIG_IDF_TARGET_ESP32S3 #include "esp32s3/rom/digital_signature.h" +#elif CONFIG_IDF_TARGET_ESP8684 +#include "esp8684/rom/digital_signature.h" #else #error "Selected target does not support esp_rsa_sign_alt (for DS)" #endif diff --git a/components/mbedtls/port/include/md/esp_md.h b/components/mbedtls/port/include/md/esp_md.h index e61b6c4e47..4506264d42 100644 --- a/components/mbedtls/port/include/md/esp_md.h +++ b/components/mbedtls/port/include/md/esp_md.h @@ -19,7 +19,11 @@ extern "C" { #endif +#if CONFIG_IDF_TARGET_ESP8684 +typedef struct mbedtls_md5_context mbedtls_md5_context; +#else typedef struct MD5Context mbedtls_md5_context; +#endif /** * \brief Initialize MD5 context diff --git a/components/mbedtls/port/md/esp_md.c b/components/mbedtls/port/md/esp_md.c index dbd4338209..f15a0b937b 100644 --- a/components/mbedtls/port/md/esp_md.c +++ b/components/mbedtls/port/md/esp_md.c @@ -1,16 +1,8 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and - +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include #include "mbedtls/md5.h" @@ -23,6 +15,7 @@ int esp_md5_finish_ret( mbedtls_md5_context *ctx, unsigned char output[16] ) { esp_rom_md5_final(output, ctx); + return 0; } @@ -30,6 +23,7 @@ int esp_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input, si { esp_rom_md5_update(ctx, input, ilen); + return 0; } @@ -37,6 +31,7 @@ int esp_md5_init_ret( mbedtls_md5_context *ctx ) { esp_rom_md5_init(ctx); + return 0; } diff --git a/components/mbedtls/port/sha/dma/sha.c b/components/mbedtls/port/sha/dma/sha.c index 65046beedb..fc18f28887 100644 --- a/components/mbedtls/port/sha/dma/sha.c +++ b/components/mbedtls/port/sha/dma/sha.c @@ -54,6 +54,8 @@ #include "esp32s3/rom/cache.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/cache.h" +#elif CONFIG_IDF_TARGET_ESP8684 +#include "esp8684/rom/cache.h" #endif #if SOC_SHA_GDMA