Page 1 of 1

[SOLVED] BCM2835 MMU setup

Posted: Wed Jun 07, 2017 8:43 am
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

Re: BCM2835 MMU setup

Posted: Wed Jun 07, 2017 1:07 pm
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

Re: BCM2835 MMU setup

Posted: Wed Jun 07, 2017 7:23 pm
by linuxyne
When mapping sections, an entry such as '00000410' is invalid and generates translation fault (the 2 LSBs are 00).

Re: BCM2835 MMU setup

Posted: Thu Jun 08, 2017 8:27 am
by SimonHA
Thank you for your help. I had a typo where I translated binary 10 into hex 0x10.
Now it works! :D

Re: BCM2835 MMU setup

Posted: Thu Jun 08, 2017 11:53 am
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.

Re: BCM2835 MMU setup

Posted: Fri Jun 09, 2017 2:14 am
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