Skip to content

MMU Support for RISCV Arch #81717

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

Open
akifejaz opened this issue Nov 21, 2024 · 3 comments
Open

MMU Support for RISCV Arch #81717

akifejaz opened this issue Nov 21, 2024 · 3 comments
Assignees
Labels
area: RISCV RISCV Architecture (32-bit & 64-bit) Feature Request A request for a new feature

Comments

@akifejaz
Copy link

Describe the bug

I've tried to enable CONFIG_MMU for my qemu_riscv64 board, but build fails giving some linker stage error related to undefine z_mapped_start & arch_mem_map symbols.

west build -p always -b qemu_riscv64 samples/hello_world
image

To Reproduce

Steps to reproduce the behavior:

  1. git checkout afce532
  2. add CONFIG_MMU=y in prj.conf
  3. west build -p always -b qemu_riscv64 samples/hello_world

Is there no MMU Support for RISCV arch till now? Because I find out this article it doesn't mention about MMU (memory management Unit) related anything ??
https://docs.zephyrproject.org/latest/hardware/arch/risc-v.html

Please help me in this regard, like if its enabled is there anything else I've to configured.
Best,
Akif

@akifejaz akifejaz added the bug The issue is a bug, or the PR is fixing a bug label Nov 21, 2024
@henrikbrixandersen henrikbrixandersen added the area: RISCV RISCV Architecture (32-bit & 64-bit) label Nov 21, 2024
@fkokosinski
Copy link
Member

Hi,

I can't seem to reproduce the exact error you've attached using the instructions you've provided, but

Is there no MMU Support for RISCV arch

That's correct, Zepyr's RISC-V port, as of date, doesn't support MMU.

If you try to build Zephyr for RISC-V with MMU support enabled, you should see a warning message about unsatisfied Kconfig dependencies:

% west build -p always -b qemu_riscv64 samples/hello_world -- -DCONFIG_MMU=y
[...]
warning: MMU (defined at kernel/Kconfig.vm:101) was assigned the value 'y' but got the value 'n'.
Check these unsatisfied dependencies: CPU_HAS_MMU (=n). See
http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_MMU and/or look up MMU in the
menuconfig/guiconfig interface. The Application Development Primer, Setting Configuration Values,
and Kconfig - Tips and Best Practices sections of the manual might be helpful too.

@fkokosinski fkokosinski added Feature Request A request for a new feature and removed bug The issue is a bug, or the PR is fixing a bug labels Nov 22, 2024
@akifejaz
Copy link
Author

I can't seem to reproduce the exact error you've attached using the instructions you've provided, but

Hi @fkokosinski Thanks for response, yeah I forgot to mention I also enabled an internal flag CPU_HAS_MMU from arch/Kconfig

Changes:

diff --git a/samples/hello_world/prj.conf b/samples/hello_world/prj.conf
index b2a4ba59104..3dec296304f 100644
--- a/samples/hello_world/prj.conf
+++ b/samples/hello_world/prj.conf
@@ -1 +1 @@
-# nothing here
+CONFIG_MMU=y
t_aejaz@ip<>:~/Zephyr/zephyrproject/zephyr$ git diff arch/Kconfig
diff --git a/arch/Kconfig b/arch/Kconfig
index 355a6247af3..7bb338d7763 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -783,6 +783,7 @@ config CPU_HAS_MPU

 config CPU_HAS_MMU
        bool
+       default y
        help
          This hidden option is selected when the CPU has a Memory Management Unit
          (MMU).

Full Build Logs:

t_aejaz@ip-172-32-3-31:~/Zephyr/zephyrproject/zephyr$ west build -p always -b qemu_riscv64 samples/hello_world
-- west build: making build dir /home/t_aejaz/Zephyr/zephyrproject/zephyr/build pristine
-- west build: generating a build system
ZEPHYR_BASE is set to: /home/t_aejaz/Zephyr/zephyrproject/zephyr
Loading Zephyr default modules (Zephyr base).
-- Application: /home/t_aejaz/Zephyr/zephyrproject/zephyr/samples/hello_world
-- CMake version: 3.30.2
-- Found Python3: /home/t_aejaz/Zephyr/zephyrproject/.venv/bin/python3 (found suitable version "3.10.12", minimum required is "3.10") found components: Interpre
ter
-- Cache files will be written to: /home/t_aejaz/.cache/zephyr
-- Zephyr version: 4.0.0-rc1 (/home/t_aejaz/Zephyr/zephyrproject/zephyr)
-- Found west (found suitable version "1.3.0", minimum required is "0.14.0")
-- Board: qemu_riscv64, qualifiers: qemu_virt_riscv64
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.16.8 (/home/t_aejaz/Zephyr/zephyr-sdk-0.16.8)
-- Found toolchain: zephyr 0.16.8 (/home/t_aejaz/Zephyr/zephyr-sdk-0.16.8)
-- Found Dtc: /home/t_aejaz/Zephyr/zephyr-sdk-0.16.8/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6")
-- Found BOARD.dts: /home/t_aejaz/Zephyr/zephyrproject/zephyr/boards/qemu/riscv64/qemu_riscv64.dts
-- Generated zephyr.dts: /home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/zephyr.dts
-- Generated pickled edt: /home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/edt.pickle
-- Generated zephyr.dts: /home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: /home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/include/generated/zephyr/devicetree_generated.h
-- Including generated dts.cmake file: /home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/dts.cmake
Parsing /home/t_aejaz/Zephyr/zephyrproject/zephyr/Kconfig
Loaded configuration '/home/t_aejaz/Zephyr/zephyrproject/zephyr/boards/qemu/riscv64/qemu_riscv64_defconfig'
Merged configuration '/home/t_aejaz/Zephyr/zephyrproject/zephyr/samples/hello_world/prj.conf'
Configuration saved to '/home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/.config'
Kconfig header saved to '/home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/include/generated/zephyr/autoconf.h'
-- Found GnuLd: /home/t_aejaz/Zephyr/zephyr-sdk-0.16.8/riscv64-zephyr-elf/riscv64-zephyr-elf/bin/ld.bfd (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/t_aejaz/Zephyr/zephyr-sdk-0.16.8/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gcc
Zephyr package found at: /home/t_aejaz/Zephyr/zephyrproject/zephyr/share/zephyr-package/cmake
-- Configuring done (6.5s)
-- Generating done (0.1s)
-- Build files have been written to: /home/t_aejaz/Zephyr/zephyrproject/zephyr/build
-- west build: building application
[1/103] Preparing syscall dependency handling

[2/103] Generating include/generated/zephyr/version.h
-- Zephyr version: 4.0.0-rc1 (/home/t_aejaz/Zephyr/zephyrproject/zephyr), build: v4.0.0-rc1-10-gafce5329f772
[98/103] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/zephyr_pre0.map
: && ccache /home/t_aejaz/Zephyr/zephyr-sdk-0.16.8/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gcc  -gdwarf-4 -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/riscv/core/offsets/offsets.c.obj  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/riscv/core/libarch__riscv__core.a  zephyr/lib/libc/picolibc/liblib__libc__picolibc.a  zephyr/lib/libc/common/liblib__libc__common.a  zephyr/drivers/interrupt_controller/libdrivers__interrupt_controller.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L/home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr  zephyr/arch/common/libisr_tables.a  -mcmodel=medany  -mabi=lp64  -march=rv64imac_zicsr_zifencei  -fuse-ld=bfd  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  -specs=picolibc.specs  -DPICOLIBC_LONG_LONG_PRINTF_SCANF -L"/home/t_aejaz/Zephyr/zephyr-sdk-0.16.8/riscv64-zephyr-elf/bin/../lib/gcc/riscv64-zephyr-elf/12.2.0/rv64imac_zicsr_zifencei/lp64/medany" -lc -lgcc && cd /home/t_aejaz/Zephyr/zephyrproject/zephyr/build/zephyr && /usr/bin/cmake -E true
/home/t_aejaz/Zephyr/zephyr-sdk-0.16.8/riscv64-zephyr-elf/bin/../lib/gcc/riscv64-zephyr-elf/12.2.0/../../../../riscv64-zephyr-elf/bin/ld.bfd: zephyr/kernel/libkernel.a(mmu.c.obj): in function `k_mem_map_phys_bare':
/home/t_aejaz/Zephyr/zephyrproject/zephyr/kernel/mmu.c:976: undefined reference to `arch_mem_map'
/home/t_aejaz/Zephyr/zephyr-sdk-0.16.8/riscv64-zephyr-elf/bin/../lib/gcc/riscv64-zephyr-elf/12.2.0/../../../../riscv64-zephyr-elf/bin/ld.bfd: zephyr/kernel/libkernel.a(mmu.c.obj): in function `z_mem_manage_init':
/home/t_aejaz/Zephyr/zephyrproject/zephyr/kernel/mmu.c:1103: undefined reference to `z_mapped_start'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/t_aejaz/Zephyr/zephyrproject/zephyr/build

@kgingerale
Copy link

Hey!
My group chose to try and work on this issue as part of our grade for our masters class. We have the baseline code written for sv32 and are working on testing it now. However, we have run into a situation where PTE permission flags are not being enforced, even when the thread is in user mode (also tried not having user mode/threads setup, just in a basic main.c). Has anyone seen something similar, or is there a quirk with QEMU’s RISC-V MMU emulation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: RISCV RISCV Architecture (32-bit & 64-bit) Feature Request A request for a new feature
Projects
None yet
Development

No branches or pull requests

6 participants