sameh4
Posts: 34
Joined: Wed Nov 29, 2017 6:58 pm

Dave Welche's bootloaders for RPi3 or other alternative

Sat Dec 02, 2017 5:36 pm

I haven't been able to search the forum today. Every time I do a search, I get a "we have high traffic" results page.

I was trying to search to see if anyone has used Dave Welche's bootloader on the RPi 3? https://github.com/dwelch67/raspberrypi ... loader02.c

His bootloader should work for Pi 2's, A+ and more. But I am not sure if does work for a Pi3. I have not attempted yet. Still waiting on Amazon to deliver the USB to Serial cable.

Other than QEMU, what are other alternatives to the "SD card" problem?

LdB
Posts: 751
Joined: Wed Dec 07, 2016 2:29 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Dec 03, 2017 2:32 pm

The link you have Given is a Pi1 you can tell from the addresses

#define ARM_TIMER_CTL 0x2000B408
#define ARM_TIMER_CNT 0x2000B420

On a Pi2 or Pi3 would be etc

#define ARM_TIMER_CTL 0x3F00B408
#define ARM_TIMER_CNT 0x3F00B420

No idea what you are meaning when you talk about SD card issue?

dwelch67
Posts: 925
Joined: Sat May 26, 2012 5:32 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Dec 03, 2017 2:36 pm

I have a raspberry pi three repo separate from the other, that is just raspberry pi three stuff including a bootloader. there are many alternatives folks keep coming up with other solutions, I even heard there is a way to change the rom in the part to have it pxe boot or something like that (permanent change you cant undo). Mine are basic, simple, ideally understandable, but do require a uart solution, maybe some wires, maybe some soldering if a pi zero. And the goal was not some u-booty thing but a very simple example that does something to show more examples that are not intended to be libraries. There are countless solutions that are intended to be solutions and or bordering on operating systems. It all depends on what you are after.

the pi-three of course being the most complicated of all of them (now the new pi2 has the same core so equally painful). the pi-zero is a good place to start, but see what you see, allowing it to boot into HYP 32 bit mode and/or 64 bit mode. you can still investigate peripherals and things like that but once you want to do interrupts if you have never done them before the pi3 is on the more painful side, there are complete examples out there that should just work though.

dwelch67

dwelch67
Posts: 925
Joined: Sat May 26, 2012 5:32 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Dec 03, 2017 2:36 pm

at the top of the baremetal forum there is a pinned thread that has a log of baremetal resources, look through those to find other solutions as well.

sameh4
Posts: 34
Joined: Wed Nov 29, 2017 6:58 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Wed Dec 06, 2017 12:50 pm

I did find the "boards" directory and the Pi specific directories in there. I didn't manage to get the bootloader07 working correctly, but I am fairly certain that's because I was using minicom and I have no experience with it.

I am thinking of writing a simple one just for practice

lm1
Posts: 6
Joined: Fri Dec 08, 2017 1:47 am

Re: Dave Welche's bootloaders for RPi3 or other alternative

Fri Dec 08, 2017 2:06 am

Let me know I am practicing poor forum etiquette, but I too am having difficulty with bootloader07 (aarch64). I was able to get the tool chain build, via build_aarch64, then I built bootloader07 with "make". I tried burning kernel7.img onto an SD card with etcher, and booting the SD card. But, minicom doesn't show anything, is it supposed to? Am I supposed to burn something other than kernel7.img onto the SD card?

I know I have the USB/Serial cable connected properly because minicom spits out a login prompt when booting with raspian. And I've read various readme files and webpages about the other files (config.txt, etc), but I'm not sure exactly what files from the bootloader07 example to burn to SD or how? Any help would be greatly appreciated. Please advise if I should create a new forum thread.

Best regards.

sameh4
Posts: 34
Joined: Wed Nov 29, 2017 6:58 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Fri Dec 08, 2017 1:28 pm

@lm1 In the bootloader7 directory of the aarch_64 there's a config.txt file that also needs to be on the SD card. That's only for the Pi 3 64 bit version. For the 32 bit version there's no need for it.

You probably already know that any code to work on any Pi, you need the latest bootcode.bin and start.elf firmware. They can be downloaded from

https://github.com/raspberrypi/firmware ... aster/boot

To be fair I haven't gotten those bootloaders to work and I have stopped trying. I am reading and learning so I can write my own for practice.

LdB
Posts: 751
Joined: Wed Dec 07, 2016 2:29 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Fri Dec 08, 2017 2:43 pm

Technically an AARCH64 file should be called Kernel8.img
If has to be that if you are going thru the bootloader without a config.txt as there is a 4 stage search order.

1.) kernel8.img => Cortex-A53 AARCH64
2.) Kernel8-32.img => Cortex-A53 AARCH32
3.) Kernel7.img => Cortex-A7 AARCH32
4.) Kernel.img => arm1176jzf-s AARCH32

Typically I just make the disk image directory with all 4 versions
https://github.com/LdB-ECM/Raspberry-Pi ... er/DiskImg

lm1
Posts: 6
Joined: Fri Dec 08, 2017 1:47 am

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sat Dec 09, 2017 8:19 pm

@LdB, very good to know that about the 4 stage search order. Thanks for sharing!

@sameh4, thanks as well. I just formatted the SD card and copied start.elf, bootcode.bin, kernel7.img, and config.txt to it. Then powered on the device (RPi 3), and now the minicom display reads:
12345678
00200354
IHEX

I think this means the /boards/pi3/aarch64/bootloader7 example is now working on my device (Rpi 3). I'll head back to the readme files (and google) and try to upload code to be executed now.

@dwelch67, thanks for making all these examples available, I appreciate it.

lm1
Posts: 6
Joined: Fri Dec 08, 2017 1:47 am

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sat Dec 09, 2017 10:46 pm

After getting "boards/pi3/aarch64/bootloader7" example on the Pi3, I built "prograspi" from the bootloader01 example directory and tried to load the "boards/pi3/aarch64/uart02" example (uart02.hex) with the following command as non-root user in a terminal:
> ./prograspi uart02.hex /dev/ttyUSB0
> file opened
> port opened

But, the terminal didn't return, looks like prograspi doesn't terminate. Anyone know if that's expected? I set permissions on /dev/ttyUSB0 to be writeable, so I don't think that's an issue.

In the other terminal, with minicom running, I tried typing to see if the uart02 example was running on the Pi3. I think it's supposed to be sending my keystrokes back to minicom to be displayed, but I don't see anything. Any suggestions would be greatly appreciated. I'd like to get this bootloader7 working so I can continue learning these examples.

sameh4
Posts: 34
Joined: Wed Nov 29, 2017 6:58 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sat Dec 09, 2017 10:55 pm

@lm : You are right. That output ending in IHEX means that kernel has booted correctly and is waiting for you to upload a file.

The next thing to do is to make another bin/hex, for example the LED blink. Make sure the linker memory size is correct. That was my problem that I just solved less than one hour ago :)

The memory section should probably have a length of 0x1000 (for starters this is fine) . The bootloader is sitting at 0x20000, and all my examples were incorrectly starting at 0x8000 and were 0x10000; which were overwriting the bootloader itself.

The below linker works just fine.

Code: Select all

MEMORY
{
    ram : ORIGIN = 0x8000, LENGTH = 0x1000
}

SECTIONS
{
    .text : { *(.text*) } > ram
    .bss : { *(.bss*) } > ram
}
Then you want to use Minicom to send the file. The command for that on Linux is Ctr-a then half second wait, then s. It opens a small modal, choose xmodem and use arrows to move up/down, and double tap the space bar to select a directory/file.

Then when the upload finishes and that dialog closes, the kernel should output DADADADA which means the transfer was successful. You then press "g" or "G" and it should execute your program.

Full disclosure, I am using bootloader06 with Pi Zero. One difference is that bootloader06 accepts bin files while bootloader07 accepts hex files.

I have more or less given up on the Pi3 for now until I can get better at the Pi Zero.

lm1
Posts: 6
Joined: Fri Dec 08, 2017 1:47 am

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Dec 10, 2017 1:15 am

@sameh4, thanks again for the help.

Unfortunately, when I try using xmodem from the minicom terminal, I just get this:
Sending uart02.hex, 17 blocks: Give your local XMODEM receive command now.
Xmodem sectors/kbytes sent: 0/ 0k
Retry 0: Timeout on sector ACK
...
Retry 0: Timeout on sector ACK
...

I feel like I have minicom setup correctly as I get output from bootloader7 as described in an earlier post. Any suggestions here would be greatly appreciated.

sameh4
Posts: 34
Joined: Wed Nov 29, 2017 6:58 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Dec 10, 2017 2:24 am

It is very frustrating. That's why I wrote this post last week. The only thing I can say is that I was only able to get bootloader06 to work on the Pi Zero. And only after I discovered I should be shrinking my memory segment in the linker script.

lm1
Posts: 6
Joined: Fri Dec 08, 2017 1:47 am

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Dec 10, 2017 4:45 am

@sameh4, I think I got it working. I basically started looking at bootloader07.c to find out if I could hack some debug info to the minicom terminal via the uart. That's when I stumbled onto this block of code:
if((ra=='g')||(ra=='G'))
{
uart_send(0x0D);
uart_send('-');
uart_send('-');
uart_send(0x0D);
uart_send(0x0A);
uart_send(0x0A);
BRANCHTO(0x8000);
state=0;
break;
}

It looks like bootloader7 is waiting for a 'g' or 'G' to come across the uart, to bootloader7's main loop, and when it does, then bootloader7 branches to address 0x8000 where the "uart02.hex" (or other code) is presumably loaded.

So, instead of using xmodem from minicom, I used "Send Files" > "ascii" from within minicom. After selecting the "uart02.hex" file, the ascii upload dialog read this:
ASCII upload of "uart02.hex"
2.2 Kbytes transferred at 2260 CPS... Done.
READY: press any key to continue...

But, I couldn't find the "any" key :lol:
I pressed a key, then when I got back to the minicom terminal, I pressed the 'g' key and then the minicom terminal displayed this:
12345678
87654321
0000001C

Having a look at "uart02.c", I can see that the "notmain" function outputs the above 3 strings. So, I'm confident that "uart02.hex" was uploaded and executed. There's a loop in "uart02.c" that reads from the uart and then writes back to it, and I haven't figured out exactly what that does, but I'm not too worried about it. I have the bootloader7 working, and I think I can move forward with learning this setup. Let me know if you need help getting this working on your setup.

sameh4
Posts: 34
Joined: Wed Nov 29, 2017 6:58 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Dec 10, 2017 11:50 am

Computer - "Press any key to prevent nuclear meltdown"
Homer Simpson - "Where's the any key, where's the any key"? :D

It sounds like you got it working! Congrats!

What's next up in your ToDo list?

lm1
Posts: 6
Joined: Fri Dec 08, 2017 1:47 am

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Dec 10, 2017 4:55 pm

Being a complete noob to bare metal, I'm now studying bootloader7 and the broadcom technical specs. I'm gonna try out one of the LED blinking examples first.

dwelch67
Posts: 925
Joined: Sat May 26, 2012 5:32 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Mon Dec 11, 2017 9:33 pm

generally I write and post the blinkers first increasing in complexity and/or rotating through possible timers in the device. unfortunately with the pi the leds are no longer directly tied to gpio pins (for the pi3) which means maybe now you need an led and a resistor and some wires.

I usually write too much text but with the new repos raspberrypi-zero and -three or whatever, I probably went with no text...but even there the bootloader should have some follow these steps instructions (in minicom ctrl this or that).

99% of baremetal is reading/interpreting/understanding, including other peoples code sometimes. and at times ignoring the incorrect text. so if you have a pi-zero then start with the blinkers in the -zero repo (if you have not given up on my examples or rambling text, or coding style, yet).

David

AlfredJingle
Posts: 65
Joined: Thu Mar 03, 2016 10:43 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sat Jan 06, 2018 5:42 pm

Hi,

One thing not yet mentioned is that on the Raspberry the clock of the mini-UART is dependant on the core-freq, (which is not the cpu-freq).

On the pi1 and 2 the core-freq was always 250Mhz, even in Turbo-mode. On the 3 starting turbo-mode changes the core-frequency to 400Mhz, and thus a different division factor is needed in the UART setup of the bootloaders of dwelch. The division factor is the value written to AUX_MU_BAUD_REG. It should be 434 for systems with a core-freq of 250 Mhz and 270 for 400Mhz systems. This is what helped me getting the loader to work on a pi3.
going from a 6502 on an Oric-1 to an ARMv8 is quite a big step...

dwelch67
Posts: 925
Joined: Sat May 26, 2012 5:32 pm

Re: Dave Welche's bootloaders for RPi3 or other alternative

Sun Jan 07, 2018 1:25 pm

This is very typical for uarts, sadly on a platform like this it doesnt have to be this way they could have the uart shifters run off of the 100mhz (or whatever) reference clock not the PLL clock, and or they could allow for a PLL tap for the peripherals. which the system clock at 250MHz should have been, but sure if you start to mess with clock settings on boot, from the default to something else, you can expect to have to mess with the uart divisor. No surprises there.

David (dwelch67).

Return to “Bare metal, Assembly language”

Who is online

Users browsing this forum: No registered users and 3 guests