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

shell cmd: "devmem load" only works for addresses below 0x80000000 #81343

Open
AaronFontaine-DojoFive opened this issue Nov 13, 2024 · 0 comments
Labels
bug The issue is a bug, or the PR is fixing a bug

Comments

@AaronFontaine-DojoFive
Copy link

Describe the bug

Shell command "devmem load" works properly only if the address parameter is less than 0x80000000. If it is equal to or above 0x80000000, then a bus fault will occur after the first byte (i.e. the first two hex characters) have been entered into the shell.

The problem is that cmd_load() is using strtol() when assigning to bytes and data. Everywhere else in zephyr/subsys/shell/modules/devmem_service.c uses strtoul(). This seems to be an oversight in the cmd_load() function since addresses can never be negative.

If the value is outside the range of a signed long, then strtol() returns LONG_MAX, which in my case is 0x7FFFFFFF. This then gets used as the address to start writing bytes to. As soon as the first byte is entered in the shell, bypass_cb() tries to write it and bus faults.

To Reproduce

Steps to reproduce the behavior:

  1. Choose any MCU that places a memory region above 0x80000000. In my case, the STM32H7 maps the external SDRAM starting at 0xC0000000.
  2. Ensure that the shell is enabled. CONFIG_SHELL=y in prj.conf.
  3. Build and flash the board and connect a terminal program to the shell
  4. Issue command devmem load 0xC0000000
  5. Start typing hexadecimal characters
  6. After 2 characters, a bus fault occurs

Expected behavior

"devmem load" works for addresses above 0x80000000.

Impact

Minimal. I can work around this, by changing the strotol() calls to strtoul(), but it requires managing and applying a Zephyr patch file in the West workspace.

Logs and console output

[00:00:21.883,000] <err> os: ***** BUS FAULT *****
[00:00:21.883,000] <err> os:   Imprecise data bus error
[00:00:21.883,000] <err> os: r0/a1:  0x00000023  r1/a2:  0x00000000  r2/a3:  0x2400cc70
[00:00:21.883,000] <err> os: r3/a4:  0x00000000 r12/ip:  0x0000000f r14/lr:  0x0800884d
[00:00:21.883,000] <err> os:  xpsr:  0x41000000
[00:00:21.883,000] <err> os: Faulting instruction address (r15/pc): 0x08009004
[00:00:21.883,000] <err> os: >>> ZEPHYR FATAL ERROR 26: Unknown error on CPU 0
[00:00:21.883,000] <err> os: Current thread: 0x24009608 (shell_uart)

0x08009004 is in shell_process().
0x0800884d is in bypass_cb().

Environment (please complete the following information):

  • OS: WSL/Ubuntu 22.04 on Windows 10 22H2
  • Zephyr SDK sdk0.16.5-1
  • v3.6.0, but problem is not fixed in v3.7.0

Additional context

None

@AaronFontaine-DojoFive AaronFontaine-DojoFive added the bug The issue is a bug, or the PR is fixing a bug label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

1 participant