OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:59 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 12:43 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Hi. I'm making my own OS and would like to port it to Raspberry Pis (currently only the Raspberry Pi 4). Unfortunately, I can't find any information on a Aarch32 Bootloader for the Raspberry Pi 4. I was going to use the bootloader from the OSDev Wiki Page, but I don't know what registers I need to change it to. If you're confused on what "bootloader" I'm talking about, I'm talking about boot.S. Also, how do I make a malloc command? My original OS has a kmalloc, but I'm not sure if the code would work for Aarch32. The reason I need a malloc command is to use the USB drivers made by Chadderz121 on Github. Any information would be helpful.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 1:19 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
I would just use UEFI to boot on Raspberry Pi 4: https://github.com/pftf/RPi4. Also see https://rpi4-uefi.dev/.

There is also a version for Raspberry Pi 3 here (which I've been using without any problems): https://github.com/pftf/RPi3

If you don't want to use UEFI, I would still look at the source code to understand how to boot on Raspberry Pi 4.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 1:29 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
I get what you're saying, but I'm trying to make it as Aarch32 code, not Aarch64. I also don't know how to get that UEFI to boot my OS. Also using boot.S would also let me set some things on boot I could want.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 1:45 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
zap8600 wrote:
Unfortunately, I can't find any information on a Aarch32 Bootloader for the Raspberry Pi 4.

It's very similar to the 32-bit boot stub for the Pi 2. Here's a boot stub that can be assembled to support either Pi 2 or 32-bit Pi 4. You could potentially use the same binary for both, if you don't need the boot stub to do anything model-specific.

Why 32-bit instead of 64-bit?

zap8600 wrote:
Also, how do I make a malloc command? My original OS has a kmalloc, but I'm not sure if the code would work for Aarch32.

If your kmalloc doesn't already follow the ABI alignment requirements, you might need to modify it a bit, but it shouldn't require any big changes. The big changes will be the hardware-specific parts of your PMM and VMM.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 2:11 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Octocontrabass wrote:
zap8600 wrote:
Unfortunately, I can't find any information on a Aarch32 Bootloader for the Raspberry Pi 4.

It's very similar to the 32-bit boot stub for the Pi 2. Here's a boot stub that can be assembled to support either Pi 2 or 32-bit Pi 4. You could potentially use the same binary for both, if you don't need the boot stub to do anything model-specific.

I possibly might need to model-specific things in the future. I won't really use the boot stub you are talking about though, because I want it to be understandable. I am new to this stuff. Can I just compile the Pi 2 boot stub.
Octocontrabass wrote:
Why 32-bit instead of 64-bit?

Because my original OS is 32-bit and Aarch32 is closer to that. It is just a preference I have for the less advanced stuff until I get better.

Octocontrabass wrote:
zap8600 wrote:
Also, how do I make a malloc command? My original OS has a kmalloc, but I'm not sure if the code would work for Aarch32.

If your kmalloc doesn't already follow the ABI alignment requirements, you might need to modify it a bit, but it shouldn't require any big changes. The big changes will be the hardware-specific parts of your PMM and VMM.

ABI alignment? PMM? VMM? I'm sorry, I'm new to this stuff. You can check out My OS's kmalloc and see if it'll work.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 3:11 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
zap8600 wrote:
Can I just compile the Pi 2 boot stub.

Probably, yeah.

zap8600 wrote:
ABI alignment? PMM? VMM?

The ARM ABI is here. You don't have to read all of it! Your malloc() function needs to return pointers that are appropriately aligned for the type of data that's going to be stored.

This is a good starting point for reading about PMM and VMM.

zap8600 wrote:
You can check out My OS's kmalloc and see if it'll work.

You've combined your physical memory allocator and your heap allocator. You could make it work by starting at a different address and fixing it to return properly aligned memory, but you really should throw the whole thing away and write a proper physical memory manager. (And what happens if you run out of memory?)


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 3:57 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Do you have any tips on making a physical memory manager? Like I said, I'm new to this.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 4:55 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
There's some information here that might help. The simplest option is a bitmap, with each bit indicating whether a particular page-sized block of physical memory is free. This should work pretty well for a Raspberry Pi, since RAM is one contiguous block, but the bitmap might be excessively large on x86 since there can be large holes of unusable addresses between usable memory.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 5:28 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Well, for me, the bitmap sounds good. How do I get and return addresses? How do I access the RAM? How do I check the pages? Where should the check start?


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Fri Feb 04, 2022 5:45 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
zap8600 wrote:
How do I get and return addresses?

Do you mean from the bitmap? Usually the physical address is something like "(byte_offset * 8 + bit_offset) * PAGE_SIZE".

zap8600 wrote:
How do I access the RAM? How do I check the pages? Where should the check start?

I don't understand these questions at all. Aren't you already accessing RAM? What needs to be checked?


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Mon Feb 07, 2022 12:15 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Hi. So I'm looking at this page on memory managers, and I have some questions. How do I access the RAM? How do I check for the End of Memory status? How do I allocate a page? I have more questions, but I'll go through it little by little.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Mon Feb 07, 2022 1:10 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
zap8600 wrote:
How do I access the RAM?

What do you mean? You're already accessing RAM. All of your kernel's code and data is in RAM.

zap8600 wrote:
How do I check for the End of Memory status?

Read the block header. If it says it's the end, it's the end.

zap8600 wrote:
How do I allocate a page?

If you're using paging for memory management, call your virtual memory manager. Your virtual memory manager will call your physical memory manager. Your physical memory manager will locate an available page, mark the page unavailable, and return its physical address to the virtual memory manager. Your virtual memory manager will update the page tables to map that page's physical address at your desired virtual address.

If you're not using paging for memory management, then you don't have to worry about pages. You can allocate memory some other way. Even if you don't use paging for memory management, you must still use paging to enable all of the caches on ARM CPUs.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Mon Feb 07, 2022 5:34 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Octocontrabass wrote:
zap8600 wrote:
How do I check for the End of Memory status?

Read the block header. If it says it's the end, it's the end.

But how exactly do I read the block header. Do you have an example?

Octocontrabass wrote:
zap8600 wrote:
How do I allocate a page?

If you're using paging for memory management, call your virtual memory manager. Your virtual memory manager will call your physical memory manager. Your physical memory manager will locate an available page, mark the page unavailable, and return its physical address to the virtual memory manager. Your virtual memory manager will update the page tables to map that page's physical address at your desired virtual address.

How do I locate these pages? How do I mark them? How I get the address? How do I make a page table? Do you have an example?


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Mon Feb 07, 2022 7:16 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
zap8600 wrote:
But how exactly do I read the block header. Do you have an example?

The block header is part of your allocator. You create the block header, so you get to decide how to read it.

zap8600 wrote:
How do I locate these pages?

On many systems, the firmware will tell you where to find memory (e.g. UEFI boot services or a device tree). But if you're only concerned about the Raspberry Pi 4, you can look up a memory map and hardcode the addresses. Keep in mind your kernel will be loaded somewhere in that memory, so you can't blindly assume all memory in the memory map will be available!

zap8600 wrote:
How do I mark them?

However you like. For example, if your physical memory manager uses a bitmap to track available memory, you might clear the bit corresponding to the page.

zap8600 wrote:
How I get the address?

However you like. For example, if your physical memory manager uses a bitmap to track available memory, you might multiply the bit offset by the page size to get the physical address.

zap8600 wrote:
How do I make a page table?

Reserve some memory somewhere (perhaps a special .bss section in your binary?) and fill it out according to the ARMv7-A manual. The wiki has some information that may help you. (In 32-bit mode, ARMv8 CPUs are compatible with ARMv7.)

zap8600 wrote:
Do you have an example?

Which part are you looking for an example of?


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Mon Feb 07, 2022 11:58 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Octocontrabass wrote:
zap8600 wrote:
Do you have an example?
Which part are you looking for an example of?
I guess just anything on the subject. Like, how do I make a block header? Or, how do I set up a basic bitmap system? What is an ideal page size? How would I reserve some space in a .bss? How do I even read these values from RAM? How could I setup this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], Google [Bot] and 33 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group