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

PMP (Physical Memory Protection) on LicheePi4A #29

Open
fabian-thomas opened this issue Mar 28, 2024 · 5 comments
Open

PMP (Physical Memory Protection) on LicheePi4A #29

fabian-thomas opened this issue Mar 28, 2024 · 5 comments

Comments

@fabian-thomas
Copy link

fabian-thomas commented Mar 28, 2024

[Not sure if this is the correct place to post something like this. Please redirect me if this is not the right place.]

Hey,

I'm currently working on a research project on RISC-V where I try to protect memory regions from either OpenSBI or the kernel. Unfortunately I can't get PMP to work on the LicheePi4a (also not on the BeagleV Ahead, related post: https://forum.beagleboard.org/t/pmp-physical-memory-protection-on-beaglev-ahead/37928/1).

Every time I boot up the system, the OpenSBI PMP detection prints:

Boot HART PMP Count       : 0
Boot HART PMP Granularity : 0
Boot HART PMP Address Bits: 0

This detection simply checks if the PMP CSRs are writable, so I'm pretty confident that it should print 8 or 16 if the chip behaves correctly (The official C910 documentation states that there are options with either 8 or 16 PMP registers, so I assume my machine has at least 8).

My current guess is that either PMP is broken on the C910 (TH1520) or that some software I currently have no control of already sets the PMP registers and sets them locked so that I can't change them later. What stands against this guess is that reading from the pmp registers returns 0, which I would not assume even in the locked case.

I already tried to patch the two projects I'm currently aware of that could setup PMP related functionality:

  • U-Boot (used https://github.com/chainsx/thead-u-boot); I even ripped out any occurence of pmpcfg and pmpaddr in the entire repo to be sure that it does not set up PMP
  • OpenSBI (also tried upstream which failed with init_coldboot: timer init failed (error -3))

Here are my main questions:

  1. Has someone found PMP working on the C910 (TH1520)?
  2. I found that the Linux kernel sets up PMP in early boot when it is compiled with M_MODE. Is PMP required to be setup to do memory writes? I assumed when PMP is not setup it just performs no checks.
  3. Is there some other software involved in setting up PMP before U-Boot or in between the jump from U-Boot to OpenSBI?
@RevySR
Copy link

RevySR commented Mar 29, 2024

OpenSBI (also tried upstream which failed with init_coldboot: timer init failed (error -3))

You might try this branch
https://github.com/revyos/opensbi/tree/th1520-v1.4

@fabian-thomas
Copy link
Author

OpenSBI (also tried upstream which failed with init_coldboot: timer init failed (error -3))

You might try this branch https://github.com/revyos/opensbi/tree/th1520-v1.4

Thanks for posting this. This SBI version works, but still doesn't recognize any PMP registers.

It seems to refer to the following code

https://github.com/revyos/thead-u-boot/blob/e0247b8a622a08256bb876fe706eedd3d5d645f7/board/thead/light-c910/spl.c#L83

https://github.com/revyos/thead-u-boot/blob/e0247b8a622a08256bb876fe706eedd3d5d645f7/board/thead/ice-c910/spl.c#L20

I haven't tried that exact u-boot repo, but I tried at least 3 different repositories with different versions. I previously also removed these lines and tried with that but with no luck yet.

Do you know what the lines in the first link you sent do? (e.g., writel(0x0 >> 12, (void *)(PMP_BASE_ADDR + 0x104));)
What is this PMP_BASE_ADDR? Is that something that the hardware queries for a PMP configuration? I can't find it in any other repository.

@fabian-thomas
Copy link
Author

Found something here. I understand this as, PMP_BASE_ADDR=ffdc020000 is mapped to the pmp registers.

I tried writing pmp configuration to this memory range, but I still can't get PMP to work. It seems like RISC-Vs WILR mechanics keep dropping the interesting bits from the values I write into pmpcfg0 (first 8 bytes at PMP_BASE_ADDR). Every time I write and then read, the bits PMP_A=0x18 are cleared.

If anyone is able to write meaningful configurations there please keep me updated. Looking at this again I got another question:
Where do the initial values in this range come from?

@RevySR
Copy link

RevySR commented Jun 27, 2024

The th1520's pmp is a non-standard implementation, so you're assuming it can't be enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants