Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildsystem: Always expose CPU_RAM_BASE & SIZE flags #19746

Merged
merged 1 commit into from
Jun 20, 2023

Conversation

Teufelchen1
Copy link
Contributor

Contribution description

Hello 🐧

This moves the definition of CPU_RAM_BASE/SIZE from being only available in certain situation to be always available.
Reason for change is to simplify common code in the cpu folder.

In cooperation with @benpicco

Testing procedure

Passing CI

Issues/PRs references

First usage will be in the PMP driver. Although there is more code in RIOT that could be refactored to use these defines instead of hacks / hardcoded values.

@github-actions github-actions bot added Area: build system Area: Build system Area: sys Area: System labels Jun 20, 2023
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 20, 2023
@riot-ci
Copy link

riot-ci commented Jun 20, 2023

Murdock results

✔️ PASSED

791d4e3 buildsystem: Always expose CPU_RAM_BASE & SIZE flags

Success Failures Total Runtime
6934 0 6934 11m:17s

Artifacts

@benpicco
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Jun 20, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 561e193 into RIOT-OS:master Jun 20, 2023
@maribu
Copy link
Member

maribu commented Jun 24, 2023

This causes

/bin/sh: 1: arithmetic expression: expecting primary: ""

in the CI :-/

@gschorcht
Copy link
Contributor

This causes

/bin/sh: 1: arithmetic expression: expecting primary: ""

in the CI :-/

It happens for ESP32x because RAM_LEN is not defined.

@gschorcht
Copy link
Contributor

gschorcht commented Jun 25, 2023

Hm, the problem with ESP32x SoC is that they don't have that only one RAM but a number of SRAMs of different sizes, different byte/word access requirements and mapped into different address spaces. Additionally, parts of these SRAMS are used by different hardware components like cache, BT, ...

Just for example an ESP32 has 520 kB SRAM:

Memory Size Address Space Data Bus Remark
SRAM0 192 kB - accessible word-wise via Instruction Bus
SRAM1 128 kB 03xFFE0000 - 0x3FFFFFFF accessible word-wise via Instruction Bus
SRAM2 200 kB 0x3FFAE000 - 0x3FFDFFFF first 8 kByte are used as cache
RTC 8 kB - accessible word-wise via Instruction Bus

The memory.ld.in file which is used directly from the ESP-IDF, defines the usable RAM region as follows:

#define DRAM0_0_SEG_LEN 0x2c200

dram0_0_seg (RW) : org = 0x3FFB0000 + CONFIG_BTDM_RESERVE_DRAM,
                   len = DRAM0_0_SEG_LEN - CONFIG_BTDM_RESERVE_DRAM

That is, only SRAM2 is used as RAM. So we could use 0x3FFB0000 as RAM_START_ADDR if we don't use BT. But if we use BT, the size and the start address of RAM changes because the BT Controller is using the RAM at 0x3FFB0000.

It becomes even more difficult for ESP32-S3. Here the memory.ld.in file computes usable RAM
region and size based on a number of configurations:

#define DRAM_ORG    (RAM_DRAM_START + CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE \
                                    + CONFIG_ESP32S2_DATA_CACHE_SIZE)

dram0_0_seg (RW) : org = DRAM_ORG, len = I_D_RAM_SIZE - STATIC_RAM_SIZE

@maribu
Copy link
Member

maribu commented Jun 25, 2023

At least for native we cannot expose those anyway. So portable code cannot rely on this macros to be sensible anyway.

I expect those only to be used in CPU specific drivers such as memory protection units, DMA drivers, etc. Those will likely have a good understanding of the memory layout and only make use of the macros if they make sense in the context of the platform.

I think it is also fine for platforms that have a more complex memory layout to just not provide these macros. It is better to have no info, than an oversimplification that is misleading.

(But when those macros do match the actual memory layout, I think it is absoutly fine to expose them.)

bors bot added a commit that referenced this pull request Jun 26, 2023
19763: cpu/esp32: define RAM_START_ADDR and RAM_LEN r=maribu a=gschorcht

### Contribution description

This PR fixes the problem
```
/bin/sh: 1: arithmetic expression: expecting primary: ""
```
for ESP32x SoCs that was introduced with PR #19746. The reason for the error message was that `RAM_LEN` was not defined for ESP32x SoCs.

The solution is a bit tricky since ESP32x SoCs use a combination of SRAMs of different sizes and with different byte/word access requirements. Additionally, several hardware components such as the instruction cache or the Bluetooth controller share the RAM so that the start address and the size that is usable may differ depending on the hardware components used and configured parameters like the cache size a.s.o.

Therefore, the DRAM region parameters as defined in the memory layout of the linker scripts are used to define `RAM_START_ADDR` and `RAM_LEN` in `cpu/esp32/Makefile.include`. Some checks have been added to the linker scripts to ensure that the same parameters are used in the linker scripts and for `RAM_LEN` and `RAM_START_ADDR`. This is to ensure that none of the parameters are changed without generating an assertion.

**Note:** Since I don't know for what other purposes than the `riotboot` module these parameters might be relevant, I'm not sure if the values represent what they are supposed to.

### Testing procedure

Green CI with full compilation

### Issues/PRs references

Fixes PR #19746

Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
@benpicco benpicco added this to the Release 2023.07 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants