[SOLVED] BCM2835 MMU setup

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
SimonHA
Posts: 12
Joined: Thu Nov 10, 2016 4:00 pm

[SOLVED] BCM2835 MMU setup

Post by SimonHA »

Hi guys,

I'm working with a Raspberry Pi Zero (BCM2835) and are currently trying to setup the MMU.
I have tried working with the MMU on a Odroid-C1 with great success.
However, that was a newer architecture (v7 vs v6) and I cannot copy my work entirely from there.
I would appreciate if I could get some help from someone who has worked with the Pi Zero.
Here is my current setup, which halts the system (an exception I assume). It works with the simple 1 MB section mapping:

First, I set the TLB address to 0x10000, where I have 4KB available for the table.

Code: Select all

MCR P15, 0, R0, C2, C0, 0
Next, I map the entire table PA = VA as sections with full privileged access and strong order.
Thus, the table content looks like this:

Code: Select all

00000410
00100410
00200410
00300410
00400410
00500410
...
Next, I enable the MMU with the following procedure:

Code: Select all

# Invalidate cache, tlb and DSB.
MOV R0, #0
MCR P15, 0, R0, C7, C7, 0
MCR P15, 0, R0, C8, C7, 0
MCR P15, 0, R0, C7, C10, 4

# Set domain access.
MOV R0, #0xFFFFFFFF
MCR P15, 0, R0, C3, C0, 0

# Setup MMU.
MRC P15, 0, R0, C1, C0, 0

# Enable MMU.
ORR R0, R0, #0x1

# Disable caching.
BIC R0, R0, #(1 << 2)
BIC R0, R0, #(1 << 12)

# Enables subpage.
ORR R0, R0, #(1 << 23)

# Enables TEX-mapping.
ORR R0, R0, #(1 << 28)

MCR P15, 0, R0, C1, C0, 0 <-- This is where it dies.
I know it dies right after. I have tried to turn off the led on the board right after saving the register but it never runs.
If anyone has suggestions to make it work, I would be very happy as I can move on with my little kernel :)

Best regards,
Simon
Last edited by SimonHA on Sat Jun 10, 2017 2:58 pm, edited 1 time in total.
User avatar
eryjus
Member
Member
Posts: 286
Joined: Fri Oct 21, 2011 9:47 pm
Libera.chat IRC: eryjus
Location: Tustin, CA USA

Re: BCM2835 MMU setup

Post by eryjus »

I recently completed the set up for the MMU for my rpi2b which has the same BCM2835 SoC but a different CPU. I am not sure how helpful this will be and I have not had the opportunity to research the differences. Also, disclaimer: I have coded the setup and tested to the best of my ability without actually having enabled the setup yet (I'm focused on the loader for now).

I offer up my code for you to review if it provides any benefit. Some places to look are:
https://github.com/eryjus/century/blob/master/README.md -- which contains the rpi2b VMM address space
https://github.com/eryjus/century/blob/ ... pi2b/mmu.c
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
linuxyne
Member
Member
Posts: 211
Joined: Sat Jul 02, 2016 7:02 am

Re: BCM2835 MMU setup

Post by linuxyne »

When mapping sections, an entry such as '00000410' is invalid and generates translation fault (the 2 LSBs are 00).
SimonHA
Posts: 12
Joined: Thu Nov 10, 2016 4:00 pm

Re: BCM2835 MMU setup

Post by SimonHA »

Thank you for your help. I had a typo where I translated binary 10 into hex 0x10.
Now it works! :D
User avatar
zaval
Member
Member
Posts: 659
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: BCM2835 MMU setup

Post by zaval »

I'm just curious, why you chose the least capable board from the range? you end up messing with a fairly out dated architecture version, nobody else is using armv6 now.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
SimonHA
Posts: 12
Joined: Thu Nov 10, 2016 4:00 pm

Re: BCM2835 MMU setup

Post by SimonHA »

Hi zaval,

I understand your point of view and your arguments a definitely correct!
The kernel is just a hobby project but I hope I can use it to have a light weight kernel for my hardware projects,
where I need a microcontroller with a bit more power than normally.
The Pi Zero is very cheap and compact for my design needs.
A few years ago I did work with an Odroid C1 and managed to make a kernel with multi-processor support and
the support to write simple multi-threaded C-libraries. However, this was part of a technology project course.
Now I want to make my little kernel called MinOS with focus on I/O for hardware projects with better design and code.

Best regards,
Simon
Post Reply