OVMS3-idf/components
Ivan Grokhotkov cbb84e8f5e esp32s2: fix THREADPTR calculation, re-enable FreeRTOS TLS tests
1. Clarify THREADPTR calculation in FreeRTOS code, explaining where
the constant 0x10 offset comes from.

2. On the ESP32-S2, .flash.rodata section had different default
alignment (8 bytes instead of 16), which resulted in different offset
of the TLS sections. Unfortunately I haven’t found a way to query
section alignment from C code, or to use a constant value to define
section alignment in the linker script. The linker scripts are
modified to force a fixed 16 byte alignment for .flash.rodata on the
ESP32 and ESP32-S2beta. Note that the base address of .flash.rodata
was already 16 byte aligned, so this has not changed the actual
memory layout of the application.

Full explanation of the calculation below.

Assume we have the TLS template section base address
(tls_section_vma), the address of a TLS variable in the template
(address), and the final relocation value (offset). The linker
calculates:
offset = address - tls_section_vma + align_up(TCB_SIZE, alignment).

At run time, the TLS section gets copied from _thread_local_start
(in .rodata) to task_thread_local_start. Let’s assume that an address
of a variable in the runtime TLS section is runtime_address.
Access to this address will happen by calculating THREADPTR + offset.
So, by a series of substitutions:

THREADPTR + offset = runtime_address THREADPTR = runtime_address - offset
THREADPTR = runtime_address - (address - tls_section_vma + align_up(TCB_SIZE, alignment)) THREADPTR = (runtime_address - address) + tls_section_vma - align_up(TCB_SIZE, alignment)

The difference between runtime_address and address is same as the
difference between task_thread_local_start and _thread_local_start.
And tls_section_vma is the address of .rodata section, i.e.
_rodata_start. So we arrive to

THREADPTR = task_thread_local_start - _thread_local_start + _rodata_start - align_up(TCB_SIZE, alignment).

The idea with TCB_SIZE being added to the THREADPTR when computing
the relocation was to let the OS save TCB pointer in the TREADPTR
register. The location of the run-time TLS section was assumed to be
immediately after the TCB, aligned to whatever the section alignment
was. However in our case the problem is that the run-time TLS section
is stored not next to the TCB, but at the top of the stack. Plus,
even if it was stored next to the TCB, the size of a FreeRTOS TCB is
not equal to 8 bytes (TCB_SIZE hardcoded in the linker). So we have
to calculate THREADPTR in a slightly obscure way, to compensate for
these differences.

Closes IDF-1239
2020-01-23 11:29:22 +01:00
..
app_trace global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
app_update global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
asio asio: updated ASIO port to use latest asio and esp-idf features 2020-01-09 21:53:50 +01:00
bootloader global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
bootloader_support global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
bt NimBLE: Use dynamic buffers instead of static memory. 2020-01-23 00:55:51 +08:00
cbor cbor: add tinycbor library and example 2019-08-22 17:44:29 +08:00
coap ESP32/coap_mbedtls:add macro checks 2019-10-09 16:46:46 +08:00
console tools: Mass fixing of empty prototypes (for -Wstrict-prototypes) 2019-08-01 16:28:56 +07:00
cxx C++: rtti unit tests, corresponding CI config 2020-01-13 16:39:21 +08:00
driver global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
efuse global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
esp-tls Merge branch 'bugfix/esp_tls_blocking_timeout' into 'master' 2020-01-20 09:35:23 +08:00
esp32 esp32s2: fix THREADPTR calculation, re-enable FreeRTOS TLS tests 2020-01-23 11:29:22 +01:00
esp32s2 esp32s2: fix THREADPTR calculation, re-enable FreeRTOS TLS tests 2020-01-23 11:29:22 +01:00
esp_adc_cal global: bring up esp32s2(not beta) 2020-01-16 17:41:31 +08:00
esp_common global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
esp_eth global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
esp_event ut: Move tests back from "esp32" subfolder 2020-01-06 17:13:53 +08:00
esp_gdbstub global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
esp_http_client Bugfix for failing OTA example 2019-12-31 14:18:16 +05:30
esp_http_server esp_http_server : Bugfix in parsing of empty header values 2019-09-06 11:02:36 +08:00
esp_https_ota Bugfix for failing OTA example 2019-12-31 14:18:16 +05:30
esp_https_server esp-tls: Naming variables refering to certificates and keys in a neutral way to suggest that both PEM and DER format could be used, added comments descibing important details about using these formats 2019-08-02 09:25:16 +02:00
esp_local_ctrl tools: Mass fixing of empty prototypes (for -Wstrict-prototypes) 2019-08-01 16:28:56 +07:00
esp_netif lwip: Enable IPv6 stateless address autoconfiguration 2020-01-14 07:15:26 +00:00
esp_ringbuf feat(timer): refator timer group driver 2019-11-21 14:14:19 +08:00
esp_rom esp_rom: splict libgcc and libc outof rom.ld bundle file 2020-01-23 00:27:47 +08:00
esp_serial_slave_link essl: new component to communicate with esp serial slave devices 2019-12-03 22:58:41 +08:00
esp_websocket_client tcp_transport/ws_client: websockets now correctly handle messages longer than buffer 2020-01-06 17:18:13 +08:00
esp_wifi global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
espcoredump global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
esptool_py global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
expat heap_caps: small fixes on comments plus cleaning 2019-12-20 13:35:56 -03:00
fatfs Merge branch 'bugfix/fatfs_corrupted_assert' into 'master' 2020-01-14 08:37:07 +08:00
freemodbus freemodbus: fix merge issues 2019-12-10 14:30:25 +08:00
freertos esp32s2: fix THREADPTR calculation, re-enable FreeRTOS TLS tests 2020-01-23 11:29:22 +01:00
heap global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
idf_test global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
jsmn jsmn: define macros in build system 2019-11-29 18:05:24 +08:00
json Update cJSON to v1.7.12 2019-08-14 10:03:27 +10:00
libsodium global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
log global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
lwip Merge branch 'feature/lwip_netinet_tcp_pr4637' into 'master' 2020-01-21 15:00:03 +08:00
mbedtls global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
mdns mdns: fixed typos in the variable names and the comments 2020-01-09 12:50:13 +00:00
mqtt mqtt: update submodule to point to latest commit. 2020-01-09 11:35:49 +00:00
newlib esp_rom: splict libgcc and libc outof rom.ld bundle file 2020-01-23 00:27:47 +08:00
nghttp Modified http_parser to handle ICY uris. 2019-10-11 05:04:08 +00:00
nvs_flash NVS: Changed all new to new (nothrow) 2020-01-15 14:01:35 +08:00
openssl Fix Kconfig issues discovered by upstream Kconfiglib 2019-09-23 16:10:57 +02:00
partition_table esptool_py: create flash target functions 2020-01-15 03:36:47 +00:00
perfmon xtensa: update header file 2019-12-09 09:44:56 +08:00
protobuf-c
protocomm hw crypto: activated hardware acceleration for esp32s2beta 2019-12-12 12:37:29 +08:00
pthread test: Fix possible race in pthread C++ test 2019-12-19 15:55:51 +11:00
sdmmc global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
soc global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
spi_flash global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
spiffs esptool_py: create flash target functions 2020-01-15 03:36:47 +00:00
tcp_transport esp_tls: added connection timeout to esp_tls_conn_new_sync() 2020-01-16 07:32:19 +00:00
tcpip_adapter lwip: Enable IPv6 stateless address autoconfiguration 2020-01-14 07:15:26 +00:00
ulp global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
unity global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
vfs global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
wear_levelling global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
wifi_provisioning wifi_prov_manager: Delay the Wi-Fi connect call 2020-01-07 09:51:54 +00:00
wpa_supplicant global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
xtensa global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00