Skip to content

Commit

Permalink
Merge branch 'feature/coredump_refactor_riscv_support_v4.3' into 'rel…
Browse files Browse the repository at this point in the history
…ease/v4.3'

espcoredump: code refactoring and add support for RISC-V implementation (backport v4.3)

See merge request espressif/esp-idf!12680
  • Loading branch information
projectgus committed Mar 12, 2021
2 parents 3b9af23 + 113bf47 commit 9a2d251
Show file tree
Hide file tree
Showing 21 changed files with 2,125 additions and 966 deletions.
27 changes: 21 additions & 6 deletions components/espcoredump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
idf_component_register(SRCS "src/core_dump_common.c"
"src/core_dump_flash.c"
"src/core_dump_port.c"
"src/core_dump_uart.c"
"src/core_dump_elf.c"
set(srcs "src/core_dump_common.c"
"src/core_dump_checksum.c"
"src/core_dump_flash.c"
"src/core_dump_uart.c"
"src/core_dump_elf.c"
"src/core_dump_binary.c")

set(priv_includes "include_core_dump")

idf_build_get_property(target IDF_TARGET)

if(CONFIG_IDF_TARGET_ARCH_XTENSA)
set(srcs ${srcs} "src/port/xtensa/core_dump_port.c")
set(priv_includes ${priv_includes} "include_core_dump/port/xtensa")
elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
set(srcs ${srcs} "src/port/riscv/core_dump_port.c")
set(priv_includes ${priv_includes} "include_core_dump/port/riscv")
endif()

idf_component_register(SRCS ${srcs}
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "include_core_dump"
PRIV_INCLUDE_DIRS ${priv_includes}
LDFRAGMENTS linker.lf
PRIV_REQUIRES spi_flash app_update mbedtls esp_rom soc)
3 changes: 3 additions & 0 deletions components/espcoredump/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ menu "Core dump"
config ESP_COREDUMP_STACK_SIZE
int "Reserved stack size"
depends on ESP_COREDUMP_ENABLE
# Temporarily disable this feature on Xtensa boards as switching stack
# pointer triggers an exception (IDF-2797)
depends on IDF_TARGET_ARCH_RISCV
default 0
help
Size of the memory to be reserved for core dump stack. If 0 core dump process will run on
Expand Down
8 changes: 8 additions & 0 deletions components/espcoredump/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := src
COMPONENT_PRIV_INCLUDEDIRS := include_core_dump
COMPONENT_ADD_LDFRAGMENTS += linker.lf

ifdef CONFIG_IDF_TARGET_ARCH_XTENSA
COMPONENT_PRIV_INCLUDEDIRS += include_core_dump/port/xtensa
endif

ifdef CONFIG_IDF_TARGET_ARCH_RISCV
COMPONENT_PRIV_INCLUDEDIRS += include_core_dump/port/riscv
endif
12 changes: 6 additions & 6 deletions components/espcoredump/include/esp_core_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ void esp_core_dump_init(void);
* . . . .
* . . . .
* | TCB_ADDR_N | STACK_TOP_N | STACK_END_N | TCB_N | STACK_N |
* | CRC32 |
* | CHECKSUM |
*
* Core dump in flash consists of header and data for every task in the system at the moment of crash.
* For flash data integrity control CRC is used at the end of core the dump data.
* For flash data integrity, a checksum is used at the end of core the dump data.
* The structure of core dump data is described below in details.
* 1) Core dump starts with header:
* 1.1) TOTAL_LEN is total length of core dump data in flash including CRC. Size is 4 bytes.
* 1.1) TOTAL_LEN is total length of core dump data in flash including the checksum. Size is 4 bytes.
* 1.2) VERSION field keeps 4 byte version of core dump.
* 1.2) TASKS_NUM is the number of tasks for which data are stored. Size is 4 bytes.
* 1.3) TCB_SIZE is the size of task's TCB structure. Size is 4 bytes.
Expand All @@ -60,16 +60,16 @@ void esp_core_dump_init(void);
* 2.2) STACK_END is the end of task's stack (address from which task's stack starts). Size is 4 bytes.
* 3) Task header is followed by TCB data. Size is TCB_SIZE bytes.
* 4) Task's stack is placed after TCB data. Size is (STACK_END - STACK_TOP) bytes.
* 5) CRC is placed at the end of the data.
* 5) The checksum is placed at the end of the data.
*/
void esp_core_dump_to_flash(panic_info_t *info);

/**
* @brief Print base64-encoded core dump to UART.
*
* The structure of core dump data is the same as for data stored in flash (@see esp_core_dump_to_flash) with some notes:
* 1) CRC is not present in core dump printed to UART.
* 2) Since CRC is omitted TOTAL_LEN does not include its size.
* 1) The checksum is not present in core dump printed to UART.
* 2) Since checksum is omitted TOTAL_LEN does not include its size.
* 3) Printed base64 data are surrounded with special messages to help user recognize the start and end of actual data.
*/
void esp_core_dump_to_uart(panic_info_t *info);
Expand Down
30 changes: 30 additions & 0 deletions components/espcoredump/include_core_dump/core_dump_binary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2015-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.
#ifndef ESP_CORE_DUMP_BINARY_H_
#define ESP_CORE_DUMP_BINARY_H_

#include "esp_core_dump_types.h"

/**
* @brief Initiate the binary core dump generation.
*
* @param info Exception frame info generated when the panic occured.
* @param write_cfg Structure containing the callbacks that will be called to
* write the generated core dump file.
*
* @return ESP_OK on success, otherwise \see esp_err_t.
*/
esp_err_t esp_core_dump_write_binary(core_dump_write_config_t *write_cfg);

#endif
117 changes: 117 additions & 0 deletions components/espcoredump/include_core_dump/core_dump_checksum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright 2015-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.

/**
* @file
* @brief Core dump checksum interface.
*
* This file contains all the functions required by the core dump component to
* calculate checksums for data to write (or already written) on the flash.
* Currently, both CRC32 and SHA256 are supported, but this interface is
* implementation independent.
*/

#ifndef CORE_DUMP_CHECKSUM_H_
#define CORE_DUMP_CHECKSUM_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Maximum possible length for a checksum (regardless of the
* implentation). This can be modified in the future if a new implementation
* requires a larger size.
*/
#define COREDUMP_CHECKSUM_MAX_LEN 32

/**
* @brief Type describing a checksum context. It is an abstract type as it is
* implementation independent, it is defined in the C source counterpart.
*/
typedef struct core_dump_checksum_ctx core_dump_checksum_ctx;

/**
* @brief Type returned by `esp_core_dump_checksum_finish()`. It describes a
* checksum as an array of bytes. It can also be provided to `esp_core_dump_print_checksum()`.
*/
typedef uint8_t* core_dump_checksum_bytes;


/**
* @brief Get ELF core dump version.
*
* @note Currently, this is used in the core dump header to recognize the
* checksum used for a certain dump, as the version varies with the checksum.
*
* @return Version of the core dump used.
*/
uint32_t esp_core_dump_elf_version(void);

/**
* @brief Initialize checksum calculation for the given context.
*
* @param wr_data Core dump checksum context to fill.
*/
void esp_core_dump_checksum_init(core_dump_checksum_ctx** wr_data);

/**
* @brief Update checksum calculation by integrating the given data in the context.
*
* @param wr_data Core dump checksum context.
* @param data Pointer to the data to integrate in the checksum calculation.
* This is usually the new data to write (or already written) on
* the flash.
*/
void esp_core_dump_checksum_update(core_dump_checksum_ctx* wr_data, void* data, size_t data_len);

/**
* @brief Terminate and return checksum calculated for the given context.
*
* @param wr_data Core dump checksum context. It can be NULL only if chs_ptr is
* also NULL.
* @param chs_ptr Pointer used to return the checksum calculated. It can be
* NULL, in this case, it will be ignored but the correct size
* of the checksum will be returned.
*
* @return The size, in bytes, of the checksum.
*/
uint32_t esp_core_dump_checksum_finish(core_dump_checksum_ctx* wr_data, core_dump_checksum_bytes* chs_ptr);

/**
* @brief Return the size of the checksums.
*
* @note This is equivalent to `esp_core_dump_checksum_finish(NULL, NULL)`.
*
* @return The size, in bytes, of the checksums.
*/
uint32_t esp_core_dump_checksum_size(void);

/**
* @brief Print a message followed by the checksum given as a parameter.
*
* @note The checksum will be printed in hex format and followed by \r\n.
*
* @param msg Message to print before the checksum. Can be NULL.
* @param checksum Checksum to print. Must not be NULL.
*/
void esp_core_dump_print_checksum(const char* msg, core_dump_checksum_bytes checksum);

#ifdef __cplusplus
}
#endif

#endif
11 changes: 10 additions & 1 deletion components/espcoredump/include_core_dump/core_dump_elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
#ifndef ESP_CORE_DUMP_ELF_H_
#define ESP_CORE_DUMP_ELF_H_

#include "esp_core_dump_priv.h"
#include "esp_core_dump_types.h"

/**
* @brief Initiate the ELF core dump generation.
*
* @param info Exception frame info generated when the panic occured.
* @param write_cfg Structre containing the callbacks that will be called to
* write the generated core dump data.
*
* @return ESP_OK on success, otherwise \see esp_err_t.
*/
esp_err_t esp_core_dump_write_elf(core_dump_write_config_t *write_cfg);

#endif
Loading

0 comments on commit 9a2d251

Please sign in to comment.