-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/linux_esp_hw_support' into 'master'
linux target: add support for building esp_hw_support, soc and hal components for linux target See merge request espressif/esp-idf!21502
- Loading branch information
Showing
21 changed files
with
250 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
components/esp_hw_support/host_test/host_test_linux/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# For more information about build system see | ||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
set(COMPONENTS main) | ||
project(test_hw_support_linux) |
3 changes: 3 additions & 0 deletions
3
components/esp_hw_support/host_test/host_test_linux/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
| Supported Targets | Linux | | ||
| ----------------- | ----- | | ||
|
3 changes: 3 additions & 0 deletions
3
components/esp_hw_support/host_test/host_test_linux/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
idf_component_register(SRCS "test_hw_support_linux.c" | ||
INCLUDE_DIRS "." | ||
PRIV_REQUIRES unity) |
78 changes: 78 additions & 0 deletions
78
components/esp_hw_support/host_test/host_test_linux/main/test_hw_support_linux.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "unity.h" | ||
#include "esp_random.h" | ||
|
||
/* Note: these are just sanity tests, the implementation of esp_random do not produce cryptographically secure numbers on Linux | ||
*/ | ||
|
||
TEST_CASE("call esp_random()", "[random]") | ||
{ | ||
const size_t NUM_RANDOM = 128; /* in most cases this is massive overkill */ | ||
|
||
uint32_t zeroes = UINT32_MAX; | ||
uint32_t ones = 0; | ||
for (int i = 0; i < NUM_RANDOM - 1; i++) { | ||
uint32_t r = esp_random(); | ||
ones |= r; | ||
zeroes &= ~r; | ||
} | ||
|
||
/* assuming a 'white' random distribution, we can expect | ||
usually at least one time each bit will be zero and at | ||
least one time each will be one. Statistically this | ||
can still fail, just *very* unlikely to. */ | ||
TEST_ASSERT_EQUAL_HEX32(0, zeroes); | ||
TEST_ASSERT_EQUAL_HEX32(UINT32_MAX, ones); | ||
} | ||
|
||
TEST_CASE("call esp_fill_random()", "[random]") | ||
{ | ||
const size_t NUM_BUF = 200; | ||
const size_t BUF_SZ = 16; | ||
uint8_t buf[NUM_BUF][BUF_SZ]; | ||
uint8_t zero_buf[BUF_SZ]; | ||
uint8_t one_buf[BUF_SZ]; | ||
|
||
bzero(buf, sizeof(buf)); | ||
bzero(one_buf, sizeof(zero_buf)); | ||
memset(zero_buf, 0xFF, sizeof(one_buf)); | ||
|
||
for (int i = 0; i < NUM_BUF; i++) { | ||
esp_fill_random(buf[i], BUF_SZ); | ||
} | ||
/* No two 128-bit buffers should be the same | ||
(again, statistically this could happen but it's very unlikely) */ | ||
for (int i = 0; i < NUM_BUF; i++) { | ||
for (int j = 0; j < NUM_BUF; j++) { | ||
if (i != j) { | ||
TEST_ASSERT_NOT_EQUAL(0, memcmp(buf[i], buf[j], BUF_SZ)); | ||
} | ||
} | ||
} | ||
|
||
/* Do the same all bits are zero and one at least once test across the buffers */ | ||
for (int i = 0; i < NUM_BUF; i++) { | ||
for (int x = 0; x < BUF_SZ; x++) { | ||
zero_buf[x] &= ~buf[i][x]; | ||
one_buf[x] |= buf[i][x]; | ||
} | ||
} | ||
for (int x = 0; x < BUF_SZ; x++) { | ||
TEST_ASSERT_EQUAL_HEX8(0, zero_buf[x]); | ||
TEST_ASSERT_EQUAL_HEX8(0xFF, one_buf[x]); | ||
} | ||
} | ||
|
||
|
||
|
||
void app_main(void) | ||
{ | ||
printf("Running heap linux API host test app"); | ||
unity_run_menu(); | ||
} |
1 change: 1 addition & 0 deletions
1
components/esp_hw_support/host_test/host_test_linux/sdkconfig.defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_IDF_TARGET="linux" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2013-2021 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <string.h> | ||
#include "esp_chip_info.h" | ||
|
||
void esp_chip_info(esp_chip_info_t *out_info) | ||
{ | ||
memset(out_info, 0, sizeof(*out_info)); | ||
|
||
out_info->model = CHIP_POSIX_LINUX; | ||
|
||
// TODO: May need to adjust once networking becomes available on POSIX/Linux | ||
out_info->features = 0; | ||
out_info->revision = 0; | ||
out_info->cores = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdlib.h> | ||
#include <time.h> | ||
#include <stdint.h> | ||
#include <assert.h> | ||
#include <string.h> | ||
#include <sys/param.h> | ||
|
||
#include "esp_log.h" | ||
|
||
static const char* TAG = "esp-random"; | ||
|
||
static void __attribute__((constructor)) esp_random_init() | ||
{ | ||
srand(time(NULL)); | ||
ESP_LOGW(TAG, "esp_random do not provide a cryptographically secure numbers on Linux, and should never be used for anything security related"); | ||
} | ||
|
||
uint32_t esp_random(void) | ||
{ | ||
/* Adding INT32_MAX to shift the results such that after conversion to uint32_t we still get 32 bits of random data */ | ||
return (rand() + INT32_MAX); | ||
} | ||
|
||
void esp_fill_random(void *buf, size_t len) | ||
{ | ||
assert(buf != NULL); | ||
uint8_t *buf_bytes = (uint8_t *)buf; | ||
while (len > 0) { | ||
uint32_t word = esp_random(); | ||
uint32_t to_copy = MIN(sizeof(word), len); | ||
memcpy(buf_bytes, &word, to_copy); | ||
buf_bytes += to_copy; | ||
len -= to_copy; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
idf_component_register(SRCS "lldesc.c" | ||
"dport_access_common.c" | ||
idf_build_get_property(target IDF_TARGET) | ||
|
||
# On Linux the soc component is a simple wrapper, without much functionality | ||
if(NOT ${target} STREQUAL "linux") | ||
set(srcs "lldesc.c" | ||
"dport_access_common.c") | ||
endif() | ||
|
||
idf_component_register(SRCS ${srcs} | ||
INCLUDE_DIRS include | ||
LDFRAGMENTS "linker.lf") | ||
|
||
idf_build_get_property(target IDF_TARGET) | ||
add_subdirectory(${target}) | ||
|
||
target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/ld/${target}.peripherals.ld") | ||
if(NOT CONFIG_IDF_TARGET_LINUX) | ||
target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/ld/${target}.peripherals.ld") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target_include_directories(${COMPONENT_LIB} INTERFACE . include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// The long term plan is to have a single soc_caps.h for each peripheral. | ||
// During the refactoring and multichip support development process, we | ||
// seperate these information into periph_caps.h for each peripheral and | ||
// include them here. | ||
|
||
/* | ||
* These defines are parsed and imported as kconfig variables via the script | ||
* `tools/gen_soc_caps_kconfig/gen_soc_caps_kconfig.py` | ||
* | ||
* If this file is changed the script will automatically run the script | ||
* and generate the kconfig variables as part of the pre-commit hooks. | ||
* | ||
* It can also be ran manually with `./tools/gen_soc_caps_kconfig/gen_soc_caps_kconfig.py 'components/soc/esp32c3/include/soc/'` | ||
* | ||
* For more information see `tools/gen_soc_caps_kconfig/README.md` | ||
* | ||
*/ | ||
|
||
#pragma once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
tools/test_apps/linux_compatible/hello_world_linux_compatible/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
idf_component_register(SRCS "hello_world_main.c" | ||
INCLUDE_DIRS "") | ||
|
||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters