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

🐛 fix XIP sub-word accesses #320

Merged
merged 3 commits into from
May 19, 2022
Merged

🐛 fix XIP sub-word accesses #320

merged 3 commits into from
May 19, 2022

Conversation

stnolting
Copy link
Owner

@stnolting stnolting commented May 19, 2022

This PR fixes the sub-word read access via the XIP (execute in-place) module (#317 by @jpf91).

Tests ✔️

My setup maps the XIP to base address 0x20000000.

Direct test (running a simple memory test program):

XIP data access test...
XIP.word[0x20000000] = 0xfc800513
XIP.word[0x20000004] = 0x00052023

XIP.half[0x20000000] = 0x00000513
XIP.half[0x20000002] = 0x0000fc80
XIP.half[0x20000004] = 0x00002023
XIP.half[0x20000006] = 0x00000005

XIP.byte[0x20000000] = 0x00000013
XIP.byte[0x20000001] = 0x00000005
XIP.byte[0x20000002] = 0x00000080
XIP.byte[0x20000003] = 0x000000fc
XIP.byte[0x20000004] = 0x00000023
XIP.byte[0x20000005] = 0x00000020
XIP.byte[0x20000006] = 0x00000005
XIP.byte[0x20000007] = 0x00000000

Test via GDB:

(gdb) x/wx 0x20000000
0x20000000:     0xfc800513
(gdb) x/wx 0x20000004
0x20000004:     0x00052023

(gdb) x/wx 0x20000001
0x20000001:     0x23fc8005

(gdb) x/bx 0x20000000
0x20000000:     0x13
(gdb) x/bx 0x20000001
0x20000001:     0x05
(gdb) x/bx 0x20000002
0x20000002:     0x80
(gdb) x/bx 0x20000003
0x20000003:     0xfc
(gdb) x/bx 0x20000004
0x20000004:     0x23

@stnolting stnolting added bug Something isn't working HW hardware-related labels May 19, 2022
@stnolting stnolting self-assigned this May 19, 2022
@stnolting stnolting linked an issue May 19, 2022 that may be closed by this pull request
@stnolting
Copy link
Owner Author

@jpf91

I did some quick tests using the rtl fix from this PR and so far the sub-word accesses seem to be working correctly now. Could you test the modifications, too?

@stnolting stnolting marked this pull request as ready for review May 19, 2022 16:09
@jpf91
Copy link
Contributor

jpf91 commented May 19, 2022

Thank you for addressing this so quickly!

I can confirm this fixes the issue, for both the reduced test case as well as the real application. Here's the hello_world example running with XIP and our custom XIP bootloader (had to shorten the messages a bit to make it fit in 4K ROM):

<< NEORV32 BLDR >>

BLDV: May 19 2022
HWV:  0x01070108
CLK:  0x05f5e100
ISA:  0x40901104 + 0x00000483
SOC:  0x507f402b
IMEM: 0x00000000 bytes @0x00000000
DMEM: 0x00018000 bytes @0x80000000

Boot in 8s. Press key to abort.
CMD: r, u, e


CMD:> u
Erasing flash... 
Awaiting neorv32_exe.bin... OK (0x000011c8 bytes)
CMD:> e
Booting...

                                                                                      ##        ##   ##   ##    
 ##     ##   #########   ########    ########   ##      ##   ########    ########     ##      ################  
####    ##  ##          ##      ##  ##      ##  ##      ##  ##      ##  ##      ##    ##    ####            ####
## ##   ##  ##          ##      ##  ##      ##  ##      ##          ##         ##     ##      ##   ######   ##  
##  ##  ##  #########   ##      ##  #########   ##      ##      #####        ##       ##    ####   ######   ####
##   ## ##  ##          ##      ##  ##    ##     ##    ##           ##     ##         ##      ##   ######   ##  
##    ####  ##          ##      ##  ##     ##     ##  ##    ##      ##   ##           ##    ####            ####
##     ##    #########   ########   ##      ##      ##       ########   ##########    ##      ################  
                                                                                      ##        ##   ##   ##    
Hello world! :)

And the blink_led example of course also works!

So with this and PR 318 it seems that we can now run any program from XIP flash transparently. :-)

@stnolting
Copy link
Owner Author

Great to hear and thanks for the detailed feedback! :D

@stnolting stnolting merged commit d7cfe8d into main May 19, 2022
@stnolting stnolting deleted the fix_xip_subword_accesses branch May 19, 2022 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working HW hardware-related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XIP module: Memory corruption when reading sub-words
2 participants