Skip to content

Commit

Permalink
Merge branch 'feature/esp_app_desc_linux' into 'master'
Browse files Browse the repository at this point in the history
feat(linux): esp_app_format now works on Linux

See merge request espressif/esp-idf!30781
  • Loading branch information
0xjakob committed May 23, 2024
2 parents 9250726 + 562c899 commit 6d5d4f8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 15 deletions.
4 changes: 0 additions & 4 deletions components/esp_app_format/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
idf_build_get_property(target IDF_TARGET)

if(${target} STREQUAL "linux")
return() # This component is not supported by the POSIX/Linux simulator
endif()

if(NOT BOOTLOADER_BUILD)
set(src "esp_app_desc.c")
else()
Expand Down
13 changes: 13 additions & 0 deletions components/esp_app_format/esp_app_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
#include "sdkconfig.h"

#include "esp_log.h"

// startup_internal.h is necessary for startup function definition, which does not exist on Linux (TODO: IDF-9950)
#if !CONFIG_IDF_TARGET_LINUX
#include "esp_private/startup_internal.h"

static const char *TAG = "app_init";
#endif

// Application version info
const __attribute__((weak)) __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
Expand All @@ -31,6 +35,11 @@ const __attribute__((weak)) __attribute__((section(".rodata_desc"))) esp_app_de
#endif
.idf_ver = IDF_VER,

// On Linux we just initialize the hash to some known value for testing
#if CONFIG_IDF_TARGET_LINUX
.app_elf_sha256 = { 0xDE, 0xAD, 0xBE, 0xEF, 0x47, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B},
#endif

#ifdef CONFIG_BOOTLOADER_APP_SECURE_VERSION
.secure_version = CONFIG_BOOTLOADER_APP_SECURE_VERSION,
#else
Expand Down Expand Up @@ -100,6 +109,9 @@ int esp_app_get_elf_sha256(char* dst, size_t size)
return n;
}

// startup function definition and execution does not exist on the Linux target
// (TODO: IDF-9950)
#if !CONFIG_IDF_TARGET_LINUX
ESP_SYSTEM_INIT_FN(init_show_app_info, CORE, BIT(0), 20)
{
// Load the current ELF SHA256
Expand Down Expand Up @@ -127,3 +139,4 @@ ESP_SYSTEM_INIT_FN(init_show_app_info, CORE, BIT(0), 20)
}
return ESP_OK;
}
#endif
6 changes: 6 additions & 0 deletions components/esp_app_format/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps

components/esp_app_format/test_apps:
enable:
- if: IDF_TARGET in ["esp32", "esp32s2", "esp32c3", "linux"]
reason: covers all major arch types, xtensa vs riscv, single vs dual-core
4 changes: 2 additions & 2 deletions components/esp_app_format/test_apps/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C3 | ESP32-S2 | Linux |
| ----------------- | ----- | -------- | -------- | ----- |
11 changes: 6 additions & 5 deletions components/esp_app_format/test_apps/main/test_app_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "esp_app_desc.h"
#include "unity.h"
#include "unity_fixture.h"
#include "inttypes_ext.h"

TEST_GROUP(esp_app_format);

Expand Down Expand Up @@ -40,7 +41,7 @@ TEST(esp_app_format, esp_app_get_elf_sha256_test)
memset(dst, fill, sizeof(dst));
len = sizeof(dst);
res = esp_app_get_elf_sha256(dst, len);
printf("%d: %s (%d)\n", len, dst, res);
printf("%" PRIuSIZE ": %s (%d)\n", len, dst, res);
TEST_ASSERT_EQUAL(sha256_hex_len + 1, res);
TEST_ASSERT_EQUAL(0, memcmp(dst, ref_sha256, res - 1));
TEST_ASSERT_EQUAL_HEX(0, dst[sha256_hex_len]);
Expand All @@ -49,7 +50,7 @@ TEST(esp_app_format, esp_app_get_elf_sha256_test)
memset(dst, fill, sizeof(dst));
len = 9;
res = esp_app_get_elf_sha256(dst, len);
printf("%d: %s (%d)\n", len, dst, res);
printf("%" PRIuSIZE ": %s (%d)\n", len, dst, res);
TEST_ASSERT_EQUAL(9, res);
TEST_ASSERT_EQUAL(0, memcmp(dst, ref_sha256, res - 1));
TEST_ASSERT_EQUAL_HEX(0, dst[8]);
Expand All @@ -59,7 +60,7 @@ TEST(esp_app_format, esp_app_get_elf_sha256_test)
strncpy(ref_sha256, esp_app_get_elf_sha256_str(), sizeof(ref_sha256));
len = strlen(ref_sha256);
TEST_ASSERT_EQUAL(CONFIG_APP_RETRIEVE_LEN_ELF_SHA, len);
printf("\n_Ref: %s (len=%d with null)\n", ref_sha256, len);
printf("\n_Ref: %s (len=%" PRIuSIZE " with null)\n", ref_sha256, len);

TEST_ASSERT_EQUAL(0, esp_app_get_elf_sha256(dst, 0));
TEST_ASSERT_EQUAL(0, esp_app_get_elf_sha256(dst, 1));
Expand All @@ -69,7 +70,7 @@ TEST(esp_app_format, esp_app_get_elf_sha256_test)
memset(dst, 0xCC, sizeof(dst));
TEST_ASSERT_EQUAL(req_len, esp_app_get_elf_sha256(dst, req_len));
len = strlen(dst) + 1; // + 1 for the null terminator
printf("_%02d_: %-15s (len=%d with null)\n", req_len, dst, len);
printf("_%02" PRIuSIZE "_: %-15s (len=%" PRIuSIZE " with null)\n", req_len, dst, len);
TEST_ASSERT_EQUAL(req_len, len);
TEST_ASSERT_EQUAL_STRING_LEN(ref_sha256, dst, len - 1); // -1 without null terminator
}
Expand All @@ -78,7 +79,7 @@ TEST(esp_app_format, esp_app_get_elf_sha256_test)
size_t max_len = CONFIG_APP_RETRIEVE_LEN_ELF_SHA + 1; // + 1 for the null terminator
TEST_ASSERT_EQUAL(max_len, esp_app_get_elf_sha256(dst, 99));
len = strlen(dst) + 1; // + 1 for the null terminator
printf("_99_: %-15s (len=%d with null)\n", dst, len);
printf("_99_: %-15s (len=%" PRIuSIZE " with null)\n", dst, len);
TEST_ASSERT_EQUAL(max_len, len);
TEST_ASSERT_EQUAL_STRING_LEN(ref_sha256, dst, len - 1); // -1 without null terminator
}
Expand Down
13 changes: 10 additions & 3 deletions components/esp_app_format/test_apps/pytest_esp_app_format.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0

import pytest
from pytest_embedded import Dut


@pytest.mark.supported_targets
@pytest.mark.esp32
@pytest.mark.esp32s2
@pytest.mark.esp32c3
@pytest.mark.generic
def test_esp_app_format(dut: Dut) -> None:
dut.expect_unity_test_output()


@pytest.mark.linux
@pytest.mark.host_test
def test_esp_app_format_linux(dut: Dut) -> None:
dut.expect_unity_test_output()
2 changes: 1 addition & 1 deletion components/esp_app_format/test_apps/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# General options for additional checks
CONFIG_HEAP_POISONING_COMPREHENSIVE=y
CONFIG_COMPILER_WARN_WRITE_STRINGS=y
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
#CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y TODO IDF-9967
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
CONFIG_COMPILER_STACK_CHECK=y
Expand Down
3 changes: 3 additions & 0 deletions docs/en/api-guides/host-apps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ Note that any "Yes" here does not necessarily mean a full implementation or mock
* - driver
- Yes
- No
* - esp_app_format
- No
- Yes
* - esp_common
- No
- Yes
Expand Down
3 changes: 3 additions & 0 deletions docs/zh_CN/api-guides/host-apps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ ESP-IDF 已支持使用 `FreeRTOS POSIX/Linux 模拟器 <https://www.freertos.or
* - driver
- 是
- 否
* - esp_app_format
- 否
- 是
* - esp_common
- 否
- 是
Expand Down

0 comments on commit 6d5d4f8

Please sign in to comment.