diff options
author | Arturs Artamonovs <dos21h@gmail.com> | 2025-06-26 01:33:11 +0100 |
---|---|---|
committer | Arturs Artamonovs <dos21h@gmail.com> | 2025-06-26 01:33:11 +0100 |
commit | 6b1c7e6a4de9c4e3d703da6f6b015c9a681d053b (patch) | |
tree | e3162d4f72a25defb19db39fa6d78eb7cb448e1d /md | |
parent | fadac1567aed13591a7ccf463b5887b083d2299f (diff) | |
download | md-content-6b1c7e6a4de9c4e3d703da6f6b015c9a681d053b.tar.gz md-content-6b1c7e6a4de9c4e3d703da6f6b015c9a681d053b.zip |
Update raspi5 baremetal examples all works and boots
Diffstat (limited to 'md')
-rw-r--r-- | md/index.md | 1 | ||||
-rw-r--r-- | md/writeup/raspberry5_baremetal_helloworld.md | 126 |
2 files changed, 83 insertions, 44 deletions
diff --git a/md/index.md b/md/index.md index 9bb36df..5b9d384 100644 --- a/md/index.md +++ b/md/index.md @@ -6,6 +6,7 @@ title: Writeup page <!-- Test [AM modulation](writeup/am_modulation.md)--> +[Raspberry PI5 baremetal hello world](writeup/raspberry5_baremetal_helloworld.md) [Kernel programming](notes/kernel/topics.md) [QEMU ARM64](writeup/qemu_arm64.md) [BladeRF quick guide](writeup/bladerf_quick_guide.md) diff --git a/md/writeup/raspberry5_baremetal_helloworld.md b/md/writeup/raspberry5_baremetal_helloworld.md index ba5a575..6d31ca6 100644 --- a/md/writeup/raspberry5_baremetal_helloworld.md +++ b/md/writeup/raspberry5_baremetal_helloworld.md @@ -13,7 +13,6 @@ for your system. ## Source code - ### boot.S ``` @@ -87,8 +86,34 @@ clean: rm -rf *.o *.img *.elf ``` + +### linker.ld +```ld +SECTIONS +{ + . = 0x80000; /* Kernel load address for AArch64 */ + .text : { KEEP(*(.text.boot)) *(.text .text.* .gnu.linkonce.t*) } + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r*) } + PROVIDE(_data = .); + .data : { *(.data .data.* .gnu.linkonce.d*) } + .bss (NOLOAD) : { + . = ALIGN(16); + __bss_start = .; + *(.bss .bss.*) + *(COMMON) + __bss_end = .; + } + _end = .; + + /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } +} +__bss_size = (__bss_end - __bss_start)>>3; +``` + ### config.txt ``` +arm_64bit=1 +kernel=kernel8.img enable_jtag_gpio=1 ``` @@ -99,12 +124,21 @@ make ### Prepare for a boot - +Create usual distro of your like. +Mount sdcard and backup original configs and original kernel. ```sh -cp +cd /mnt/dir +cp config.txt config.txt.bkp +cp kernel8.img kernel8.img.original ``` +Copy kerne8.img and config.txt + +```sh +cp /project/dir/config.txt /mnt/dir +cp /project/dir/kernel8.img /mnt/dir +``` ## Debugging with OpenOCD+GDB @@ -122,42 +156,45 @@ that suppose to work. Copy it for example in default openocd script location in: ```tcl -# bcm2712.cfg # SPDX-License-Identifier: GPL-2.0-or-later -# OpenOCD target config file -# This file is based on target/bcm2711.cfg -# I have checked that it works with Open On-Chip Debugger 0.12.0 -# using the Raspberry Pi Debug-Probe interface -transport select swd -adapter speed 1000 +# The Broadcom BCM2712 used in Raspberry Pi 5 +# No documentation was found on Broadcom website + +# Partial information is available in Raspberry Pi website: +# https://www.raspberrypi.com/documentation/computers/processors.html#bcm2712 + +# v1.0 initial revision - trejan on forums.raspberrypi.com if { [info exists CHIPNAME] } { - set _CHIPNAME $CHIPNAME + set _CHIPNAME $CHIPNAME } else { - set _CHIPNAME bcm2712 + set _CHIPNAME bcm2712 } if { [info exists CHIPCORES] } { - set _cores $CHIPCORES + set _cores $CHIPCORES } else { - set _cores 4 + set _cores 4 } if { [info exists USE_SMP] } { - set _USE_SMP $USE_SMP + set _USE_SMP $USE_SMP } else { - set _USE_SMP 0 + set _USE_SMP 0 } if { [info exists DAP_TAPID] } { - set _DAP_TAPID $DAP_TAPID + set _DAP_TAPID $DAP_TAPID } else { - set _DAP_TAPID 0x2ba00477 + set _DAP_TAPID 0x4ba00477 } -# swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_DAP_TAPID -swd newdap $_CHIPNAME cpu -expected-id $_DAP_TAPID +transport select swd + +swd newdap $_CHIPNAME cpu -expected-id $_DAP_TAPID -irlen 4 +adapter speed 4000 + dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu # MEM-AP for direct access @@ -170,17 +207,17 @@ set _CTIBASE {0x80020000 0x80120000 0x80220000 0x80320000} set _smp_command "target smp" for { set _core 0 } { $_core < $_cores } { incr _core } { - set _CTINAME $_CHIPNAME.cti$_core - set _TARGETNAME $_CHIPNAME.cpu$_core + set _CTINAME $_CHIPNAME.cti$_core + set _TARGETNAME $_CHIPNAME.cpu$_core - cti create $_CTINAME -dap $_CHIPNAME.dap -ap-num 0 -baseaddr [lindex $_CTIBASE $_core] - target create $_TARGETNAME aarch64 -dap $_CHIPNAME.dap -ap-num 0 -dbgbase [lindex $_DBGBASE $_core] -cti $_CTINAME + cti create $_CTINAME -dap $_CHIPNAME.dap -ap-num 0 -baseaddr [lindex $_CTIBASE $_core] + target create $_TARGETNAME aarch64 -dap $_CHIPNAME.dap -ap-num 0 -dbgbase [lindex $_DBGBASE $_core] -cti $_CTINAME - set _smp_command "$_smp_command $_TARGETNAME" + set _smp_command "$_smp_command $_TARGETNAME" } if {$_USE_SMP} { - eval $_smp_command + eval $_smp_command } # default target is cpu0 @@ -193,37 +230,38 @@ Connecting pico probe and doint step by step analysis of basic loop Start openocd server -``` +```sh openocd -f interface/cmsis-dap.cfg -f target/bcm2712.cfg ``` -Connect with gdb +Start gdb or gdb-multiarch -``` +```sh gdb ``` +Restart the raspi5 with prepared files on sdcard + and run inside gdb shell -``` +```sh tar ext :3333 ``` + you should be connected to the openocd jtag session now press Ctrl+C ## Links +https://www.raspberrypi.com/documentation/computers/config_txt.html +https://wiki.osdev.org/Raspberry_Pi_Bare_Bones +https://www.rpi4os.com/part1-bootstrapping/ +https://www.valvers.com/open-software/raspberry-pi/bare-metal-programming-in-c-part-1/ +https://www.raspberrypi.com/documentation/microcontrollers/debug-probe.html +https://macoy.me/blog/programming/RaspberryPi5Debugging +https://gist.github.com/tnishinaga/219122a5f1e3973668ee78c0fb1c7bf9 +https://forums.raspberrypi.com/viewtopic.php?p=2172522#p2172522 +https://github.com/DSERIOUSGUY/HobOS +https://developer.arm.com/documentation/ka006096/latest/ +https://github.com/raspberrypi/firmware +https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_mono/ld.html#SEC6 -https://www.raspberrypi.com/documentation/computers/config_txt.html -https://wiki.osdev.org/Raspberry_Pi_Bare_Bones - -https://www.rpi4os.com/part1-bootstrapping/ - -https://www.valvers.com/open-software/raspberry-pi/bare-metal-programming-in-c-part-1/ - -https://www.raspberrypi.com/documentation/microcontrollers/debug-probe.html - -https://macoy.me/blog/programming/RaspberryPi5Debugging -https://gist.github.com/tnishinaga/219122a5f1e3973668ee78c0fb1c7bf9 -https://forums.raspberrypi.com/viewtopic.php?p=2172522#p2172522 - -https://github.com/DSERIOUSGUY/HobOS |