satyria
Posts: 7
Joined: Sun May 12, 2013 5:41 pm

Emulator for directly programing RPi

Fri Jul 24, 2020 3:38 pm

Hi Guys,
I am looking for a way to recreate and program the hardware of the Raspberry PI directly. I am not here, for example, running Rasberian or the like, but I want to be able to program this directly, such as at https://www.cl.cam.ac.uk/projects/raspb ... orials/os/
I've programmed a few things for this myself, but what bothers me about the way it works is that I have to constantly rewrite an SD card to test my attempts.
I need the following things, which the emulator should support, at least it would be nice:
Graphics, sound, USB
I don't need any other hardware (e.g. GPIO etc.)
I would have Linux or Windows as the host operating system.
Can someone help me here?
Thank you very much, Matthias

trejan
Posts: 2118
Joined: Tue Jul 02, 2019 2:28 pm

Re: Emulator for directly programing RPi

Fri Jul 24, 2020 3:42 pm

There is no emulator that emulates all the low level Pi specific hardware. It wouldn't be a quick or easy job to write one either.

If you don't want to constantly rewrite cards then set up your Pi to netboot and load your binaries using that.

satyria
Posts: 7
Joined: Sun May 12, 2013 5:41 pm

Re: Emulator for directly programing RPi

Sat Jul 25, 2020 10:41 am

Thank you for your answer.

I almost thought so. So I'll keep changing the SD card. Often had problems that the SD card gave up at some point.

Greetings, Matthias

Schnoogle
Posts: 129
Joined: Sun Feb 11, 2018 4:47 pm

Re: Emulator for directly programing RPi

Sat Jul 25, 2020 2:49 pm

Hey,

there are also some bare metal bootloader available. You put only those BL on your SD card and once the Pi is powered up you can send the kernel to test via UART or other data transfer, depending on the supported mechanics of the bootloader.

This will reduce the SD card dance quite significantly ;)

ejolson
Posts: 5373
Joined: Tue Mar 18, 2014 11:47 am

Re: Emulator for directly programing RPi

Sat Jul 25, 2020 3:41 pm

satyria wrote:
Sat Jul 25, 2020 10:41 am
I almost thought so. So I'll keep changing the SD card. Often had problems that the SD card gave up at some point.
Rather than swapping cards, you can load bare-metal images over USB using rpiboot. This is how people developing software for the compute modules often do things but it also works on the Zero and the 4B. Note that rpiboot does not work with 1B, 2B or 3B models.

bzt
Posts: 563
Joined: Sat Oct 14, 2017 9:57 pm

Re: Emulator for directly programing RPi

Sat Jul 25, 2020 10:25 pm

I don't get it. What's wrong with qemu? It is the perfect candidate for what the OP wants.
You can run it as "qemu -M raspi2" to emulate 32 bit RPi2 (for those Cambridge tutorials the OP linked), or "qemu -M raspi3" for 64 bit.

It is true, that the emulation is not fully complete, but pretty good. A full emulation also exists, but you have to compile that from source, because it hasn't been merged with the qemu mainline.
satyria wrote:
Fri Jul 24, 2020 3:38 pm
Hi Guys,
I am looking for a way to recreate and program the hardware of the Raspberry PI directly. I am not here, for example, running Rasberian or the like, but I want to be able to program this directly, such as at https://www.cl.cam.ac.uk/projects/raspb ... orials/os/
I've programmed a few things for this myself, but what bothers me about the way it works is that I have to constantly rewrite an SD card to test my attempts.
You could try the aforementioned rpiboot, or if that's too heavy to your taste, then you can use a small chainloader like raspbootcom or imgrecv too. My raspi3 tutorials has a minimal chainloader example, which loads your kernel over serial line. But qemu would be my first choice.
satyria wrote:
Fri Jul 24, 2020 3:38 pm
I need the following things, which the emulator should support, at least it would be nice:
Graphics, sound, USB
This is pretty vague list :-) Graphics is supported (framebuffer and other stuff, but not 3D accelerations), sound and USB also to some extent.
satyria wrote:
Fri Jul 24, 2020 3:38 pm
I don't need any other hardware (e.g. GPIO etc.)
I would have Linux or Windows as the host operating system.
Qemu is available for both Linux and Windows. Kernel senders (for the serial port chainloaders) also available for both Linux and Windows.

Cheers,
bzt

trejan
Posts: 2118
Joined: Tue Jul 02, 2019 2:28 pm

Re: Emulator for directly programing RPi

Sat Jul 25, 2020 10:59 pm

@satyria The tutorial you're looking at is only for a Pi 1. The memory map was changed on Pi 2/3 and Pi 4. If you're using a newer Pi then you'll need to adjust the tutorial addresses. The same will apply to QEMU as it only emulates a Pi 2 and a Pi 3.
bzt wrote:
Sat Jul 25, 2020 10:25 pm
I don't get it. What's wrong with qemu? It is the perfect candidate for what the OP wants.
I know about the Pi support in QEMU but it doesn't implement everything OP requested. They wanted the emulator to support graphics, sound and USB. QEMU doesn't do Pi sound, USB and a load of other peripherals. It only does the basic BCM2835 framebuffer but I suspect that is okay. A bunch of the VC mailbox properties are stubbed out including some of the graphics ones so I'm not sure all the ones used in the tutorial will work.

satyria
Posts: 7
Joined: Sun May 12, 2013 5:41 pm

Re: Emulator for directly programing RPi

Fri Jul 31, 2020 9:05 am

bzt wrote:
Sat Jul 25, 2020 10:25 pm
I don't get it. What's wrong with qemu? It is the perfect candidate for what the OP wants.
You can run it as "qemu -M raspi2" to emulate 32 bit RPi2 (for those Cambridge tutorials the OP linked), or "qemu -M raspi3" for 64 bit.

It is true, that the emulation is not fully complete, but pretty good. A full emulation also exists, but you have to compile that from source, because it hasn't been merged with the qemu mainline.
satyria wrote:
Fri Jul 24, 2020 3:38 pm
Hi Guys,
I am looking for a way to recreate and program the hardware of the Raspberry PI directly. I am not here, for example, running Rasberian or the like, but I want to be able to program this directly, such as at https://www.cl.cam.ac.uk/projects/raspb ... orials/os/
I've programmed a few things for this myself, but what bothers me about the way it works is that I have to constantly rewrite an SD card to test my attempts.
You could try the aforementioned rpiboot, or if that's too heavy to your taste, then you can use a small chainloader like raspbootcom or imgrecv too. My raspi3 tutorials has a minimal chainloader example, which loads your kernel over serial line. But qemu would be my first choice.
satyria wrote:
Fri Jul 24, 2020 3:38 pm
I need the following things, which the emulator should support, at least it would be nice:
Graphics, sound, USB
This is pretty vague list :-) Graphics is supported (framebuffer and other stuff, but not 3D accelerations), sound and USB also to some extent.
satyria wrote:
Fri Jul 24, 2020 3:38 pm
I don't need any other hardware (e.g. GPIO etc.)
I would have Linux or Windows as the host operating system.
Qemu is available for both Linux and Windows. Kernel senders (for the serial port chainloaders) also available for both Linux and Windows.

Cheers,
bzt
Thank you so much!
In the meantime I bought a Raspi 4B and wanted to try your tutorial. First I tried the contact via Serial (tty). Raspi was installed with Raspbian. It worked on Windows and Putty. Under Linux it was only a one-way street (Raspi to Linux), also as root or user with the corresponding rights. I used "screen". I would have preferred Linux, but then I used the tutorial with Windows (Docker). Unfortunately, the text "Hello World" never got through to the terminal.
After changing the firmware (https://www.raspberrypi.org/documentati ... _config.md) the boot process was displayed to me, so the contact was there ...
Well, let's see what's different here than on the RPI 3 ...
Greetings, Matthias

bzt
Posts: 563
Joined: Sat Oct 14, 2017 9:57 pm

Re: Emulator for directly programing RPi

Fri Jul 31, 2020 1:15 pm

satyria wrote:
Fri Jul 31, 2020 9:05 am
Well, let's see what's different here than on the RPI 3 ...
As long as my tutorials concerned, the MMIO base address is different. There are more peripherals on the RPi4, but those are not covered in my tutorials (VC 3D, GIC, etc.). You can find links on the README to other tutorials and sources which do if you need them. For a serial Hello World kernel and accessing the framebuffer the hw is the same.

Btw, MMIO base address is different for RPi boards, because they have extended the memory bus as the board got evolved. This is how I compile my imgrecv loader to support all boards. Note the -DMMIO_BASE command line argument, and that otherwise the code to handle the UART is the same.

Cheers,
bzt

satyria
Posts: 7
Joined: Sun May 12, 2013 5:41 pm

Re: Emulator for directly programing RPi

Fri Jul 31, 2020 4:02 pm

Thanks for this info. I was just experimenting with it.
This program then starts the wonderful color gradient after the start and stands still? According to Putty, he starts start4.elf, then nothing. Is that correct?
Another little note: the names of the BIN have changed in the toolchain. Example: aarch64-elf-gcc -> aarch64-none-elf-gcc

Greetings, Matthias

satyria
Posts: 7
Joined: Sun May 12, 2013 5:41 pm

Re: Emulator for directly programing RPi

Fri Jul 31, 2020 5:29 pm

Apparently the RPi4 is not the same as RPi3. The registers GPPUD, GPPUDCLK0 and GPPUDCLK1 no longer exist there. According to the document (BCM2711 ARM Peripherals), according to the assignment, these would be in a reserved area. I think that's the problem here.
Unfortunately, I also find no solution to how to program this.

Greetings, Matthias

User avatar
rpdom
Posts: 17170
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Emulator for directly programing RPi

Fri Jul 31, 2020 6:59 pm

There are a new set of Pull Up/Down control registers on the 2711 chip. Each one controls the pulls for 16 GPIOs. I don't think a clock register is required to action these. One big difference between them and the previous incarnation of the registers is that they are readable as well as writable, and writing to the will affect all 16 GPIOs, so you need to read the old states before updating any new ones (unless you want to set them all in one go).
Unreadable squiggle

cleverca22
Posts: 776
Joined: Sat Aug 18, 2012 2:33 pm

Re: Emulator for directly programing RPi

Fri Jul 31, 2020 9:13 pm

https://github.com/librerpi/lk/blob/vc4 ... .c#L89-L94

this is some code i wrote to read the pullup config for any pin, and then pretty-print the whole thing

if you reverse the logic, and use the same rules as altfunction registers (clear the relevant bits, then or in a new state), you can change pullups as well

Return to “Bare metal, Assembly language”