Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cflashy: macos compatibility #501

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

petemoore
Copy link

@petemoore petemoore commented Nov 13, 2024

It seems that macOS supports fewer serial baud rates than Linux, and so the incompatible baud rates have been removed when compiling under macOS.

pmoore@Peters-MacBook-Pro-2:~/git/circle fix-cflashy-macos $ cat /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/sys/termios.h | grep '#define B[0-9][0-9]*' | sort -n -k3
#define B0      0
#define B50     50
#define B75     75
#define B110    110
#define B134    134
#define B150    150
#define B200    200
#define B300    300
#define B600    600
#define B1200   1200
#define B1800   1800
#define B2400   2400
#define B4800   4800
#define B7200   7200
#define B9600   9600
#define B14400  14400
#define B19200  19200
#define B28800  28800
#define B38400  38400
#define B57600  57600
#define B76800  76800
#define B115200 115200
#define B230400 230400

I've only tested that this fixes the compilation. I have not tested the compiled binary, please let me know if that is required. Many thanks Rene!

Originally raised in #499.

macOS supports fewer serial baud rates than Linux, and so
the incompatible baud rates have been removed when compiling
under macOS.
@rsta2
Copy link
Owner

rsta2 commented Nov 14, 2024

That's a better solution. Thanks! I don't know, if you have an USB-to-serial adapter, which can be connected between your Mac and RPi? That would be required for a test. Otherwise I would merge the PR without a bootloader test, because it's already an improvement.

@petemoore
Copy link
Author

petemoore commented Nov 14, 2024

I'm on a trip with just my laptop for the next couple of weeks, so feel free to merge, thanks Rene! I'm happy to also test it when I am back in Germany.

@rsta2
Copy link
Owner

rsta2 commented Nov 14, 2024

OK, no problem. Have a nice trip, Pete!

@petemoore
Copy link
Author

Hi Rene! I'm back home and finally got round to trying this out, but am getting the rainbow splash screen on my rpi400 when booting the bootloader. Any idea what I might be doing wrong? Many thanks!

pmoore@Petes-iMac:~/git/circle fix-cflashy-macos $ rm -rf /Volumes/RPI/*
pmoore@Petes-iMac:~/git/circle fix-cflashy-macos $ cat Config.mk 
PREFIX64 = aarch64-none-elf-
AARCH = 64
RASPPI = 4
DEFINE += -DDEFAULT_KEYMAP=\"US\"
DEFINE += -DXHCI_DEBUG=1 -DXHCI_DEBUG2=1 -DDEBUG=1 -DUSB_GADGET_DEBUG=1
SERIALPORT = /dev/tty.SLAB_USBtoUART
FLASHBAUD = 115200	
USERBAUD = 115200
USEFLASHY = 0
SDCARD = /Volumes/RPI
pmoore@Petes-iMac:~/git/circle fix-cflashy-macos $ cd boot
pmoore@Petes-iMac:~/git/circle/boot fix-cflashy-macos $ make clean
rm -f bootcode.bin fixup*.dat start*.elf bcm*.dtb *.dtbo kernel*.img armstub*.bin LICENCE.broadcom COPYING.linux
make clean -C "../tools/bootloader"
rm -f *.o
rm -f *.elf
rm -f *.lst
rm -f *.img
make clean -C armstub
rm -f *.o *.elf *.bin *.lst
pmoore@Petes-iMac:~/git/circle/boot fix-cflashy-macos $ make bootloader64
make -C "../tools/bootloader" kernel8.img
aarch64-none-elf-as vectors64.s -o vectors64.o
aarch64-none-elf-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -DDEFAULTBAUD=115200	 -mstrict-align -c periph.c -o periph64.o -DAARCH=64
aarch64-none-elf-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -DDEFAULTBAUD=115200	 -mstrict-align -c bootloader07.c -o bootloader07_64.o -DAARCH=64
aarch64-none-elf-ld vectors64.o periph64.o bootloader07_64.o -T loader64 -o bootloader07_64.elf
aarch64-none-elf-objdump -D bootloader07_64.elf > bootloader07_64.lst
aarch64-none-elf-objcopy bootloader07_64.elf -O binary kernel8.img
make -C "../tools/bootloader" kernel8-rpi4.img
aarch64-none-elf-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -DDEFAULTBAUD=115200	 -mstrict-align -c periph.c -o periph64_rpi4.o -DRPI4 -DAARCH=64
aarch64-none-elf-ld vectors64.o periph64_rpi4.o bootloader07_64.o -T loader64 -o bootloader07_64_rpi4.elf
aarch64-none-elf-objdump -D bootloader07_64_rpi4.elf > bootloader07_64_rpi4.lst
aarch64-none-elf-objcopy bootloader07_64_rpi4.elf -O binary kernel8-rpi4.img
make -C "../tools/bootloader" kernel_2712.img
aarch64-none-elf-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -DDEFAULTBAUD=115200	 -mstrict-align -c periph.c -o periph64_2712.o -DRPI5 -DAARCH=64
aarch64-none-elf-ld vectors64.o periph64_2712.o bootloader07_64.o -T loader64 -o bootloader07_64_2712.elf
aarch64-none-elf-objdump -D bootloader07_64_2712.elf > bootloader07_64_2712.lst
aarch64-none-elf-objcopy bootloader07_64_2712.elf -O binary kernel_2712.img
cp ../tools/bootloader/kernel8.img .
cp ../tools/bootloader/kernel8-rpi4.img .
cp ../tools/bootloader/kernel_2712.img .
pmoore@Petes-iMac:~/git/circle/boot fix-cflashy-macos $ make install64
rm -f bootcode.bin fixup*.dat start*.elf bcm*.dtb *.dtbo kernel*.img armstub*.bin LICENCE.broadcom COPYING.linux
make clean -C "../tools/bootloader"
rm -f *.o
rm -f *.elf
rm -f *.lst
rm -f *.img
make clean -C armstub
rm -f *.o *.elf *.bin *.lst
Downloading LICENCE.broadcom ...
Downloading COPYING.linux ...
Downloading bootcode.bin ...
Downloading start.elf ...
Downloading fixup.dat ...
Downloading start4.elf ...
Downloading fixup4.dat ...
Downloading start_cd.elf ...
Downloading fixup_cd.dat ...
Downloading start4cd.elf ...
Downloading fixup4cd.dat ...
Downloading bcm2710-rpi-zero-2-w.dtb ...
Downloading bcm2711-rpi-4-b.dtb ...
Downloading bcm2711-rpi-400.dtb ...
Downloading bcm2711-rpi-cm4.dtb ...
Downloading bcm2712-rpi-5-b.dtb ...
Downloading bcm2712d0-rpi-5-b.dtb ...
Downloading bcm2712d0.dtbo ...
make -C armstub armstub8-rpi4.bin
aarch64-none-elf-gcc -DGIC=1 -o armstub8-rpi4.o -c armstub8.S
aarch64-none-elf-ld --section-start=.text=0 -o armstub8-rpi4.elf armstub8-rpi4.o
aarch64-none-elf-objdump -D armstub8-rpi4.elf > armstub8-rpi4.lst
aarch64-none-elf-objcopy armstub8-rpi4.elf -O binary armstub8-rpi4.bin
cp armstub/armstub8-rpi4.bin .
make -C "../tools/bootloader" kernel8.img
aarch64-none-elf-as vectors64.s -o vectors64.o
aarch64-none-elf-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -DDEFAULTBAUD=115200	 -mstrict-align -c periph.c -o periph64.o -DAARCH=64
aarch64-none-elf-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -DDEFAULTBAUD=115200	 -mstrict-align -c bootloader07.c -o bootloader07_64.o -DAARCH=64
aarch64-none-elf-ld vectors64.o periph64.o bootloader07_64.o -T loader64 -o bootloader07_64.elf
aarch64-none-elf-objdump -D bootloader07_64.elf > bootloader07_64.lst
aarch64-none-elf-objcopy bootloader07_64.elf -O binary kernel8.img
make -C "../tools/bootloader" kernel8-rpi4.img
aarch64-none-elf-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -DDEFAULTBAUD=115200	 -mstrict-align -c periph.c -o periph64_rpi4.o -DRPI4 -DAARCH=64
aarch64-none-elf-ld vectors64.o periph64_rpi4.o bootloader07_64.o -T loader64 -o bootloader07_64_rpi4.elf
aarch64-none-elf-objdump -D bootloader07_64_rpi4.elf > bootloader07_64_rpi4.lst
aarch64-none-elf-objcopy bootloader07_64_rpi4.elf -O binary kernel8-rpi4.img
make -C "../tools/bootloader" kernel_2712.img
aarch64-none-elf-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -DDEFAULTBAUD=115200	 -mstrict-align -c periph.c -o periph64_2712.o -DRPI5 -DAARCH=64
aarch64-none-elf-ld vectors64.o periph64_2712.o bootloader07_64.o -T loader64 -o bootloader07_64_2712.elf
aarch64-none-elf-objdump -D bootloader07_64_2712.elf > bootloader07_64_2712.lst
aarch64-none-elf-objcopy bootloader07_64_2712.elf -O binary kernel_2712.img
cp ../tools/bootloader/kernel8.img .
cp ../tools/bootloader/kernel8-rpi4.img .
cp ../tools/bootloader/kernel_2712.img .
Copying LICENCE.broadcom ...
Copying COPYING.linux ...
Copying bootcode.bin ...
Copying start.elf ...
Copying fixup.dat ...
Copying start4.elf ...
Copying fixup4.dat ...
Copying start_cd.elf ...
Copying fixup_cd.dat ...
Copying start4cd.elf ...
Copying fixup4cd.dat ...
Copying bcm2710-rpi-zero-2-w.dtb ...
Copying bcm2711-rpi-4-b.dtb ...
Copying bcm2711-rpi-400.dtb ...
Copying bcm2711-rpi-cm4.dtb ...
Copying bcm2712-rpi-5-b.dtb ...
Copying bcm2712d0-rpi-5-b.dtb ...
Copying armstub8-rpi4.bin ...
Copying kernel8.img ...
Copying kernel8-rpi4.img ...
Copying kernel_2712.img ...
mkdir /Volumes/RPI/overlays
Copying bcm2712d0.dtbo ...
cp config64.txt /Volumes/RPI/config.txt
sync
pmoore@Petes-iMac:~/git/circle/boot fix-cflashy-macos $ find /Volumes/RPI -type f -exec shasum -a 256 {} +
c7283ff51f863d93a275c66e3b4cb08021a5dd4d8c1e7acc47d872fbe52d3d6b  /Volumes/RPI/LICENCE.broadcom
af8067302947c01fd9eee72befa54c7e3ef8a48fecde7fd71277f2290b2bf0f7  /Volumes/RPI/COPYING.linux
af603ebd97e7b692c30195563f7b25656eb05d57838cf1a715ebb470d1614ce4  /Volumes/RPI/bootcode.bin
5b6d7f52d821010f54bfdc2e5b94944b459f493fd59b41ec94544930793aa9a7  /Volumes/RPI/start.elf
77129a82097fd05cd66d1a4f458f23b94a07d7b0ed1c5d64b2558f2aaad29aa5  /Volumes/RPI/fixup.dat
451e4320cd2390c28e5c0e79e6e5a704f98fa11670ba57d840d16bcae5aeec2e  /Volumes/RPI/start4.elf
21e37b0402974a64779c23621787a37de4706877b78931c94e964db864e8565d  /Volumes/RPI/fixup4.dat
ffe5e339f77e599fa450e274f30a6de57f066559452c33deb8011904f49d9aac  /Volumes/RPI/start_cd.elf
ead1e410073a3773af48fb25b1a8691250d553624aaa3e2345c0147c2a68fd1d  /Volumes/RPI/fixup_cd.dat
9b7055722b062ac2c56367fba328caecd73033d7a4a09a0fff7813399fe62816  /Volumes/RPI/start4cd.elf
ead1e410073a3773af48fb25b1a8691250d553624aaa3e2345c0147c2a68fd1d  /Volumes/RPI/fixup4cd.dat
770fb160f58fadedb170685a772f9318b2aa13c481e0246f81f6a0ba64de137c  /Volumes/RPI/bcm2710-rpi-zero-2-w.dtb
5bc13e0f663531c374cbf4645e511708e40a0774fc7771ae869c5504dc9e39b3  /Volumes/RPI/bcm2711-rpi-4-b.dtb
6c50cc760edcdee5c355970da683a4d81d1f04ddde0d52996ac927cf6c8b0d15  /Volumes/RPI/bcm2711-rpi-400.dtb
a7c1333d1b2272f674a1f0ccd0471b232d8fe09992616d52a59f2dacf79d05fa  /Volumes/RPI/bcm2711-rpi-cm4.dtb
4ed671a505f1df45161bd84234cb2f224438e9b8e0ce9b6791686202c8e39d1e  /Volumes/RPI/bcm2712-rpi-5-b.dtb
16672ed78def8a8721cbe78031ac91cb2e7f88165078137d8cffc0eb0f5c015f  /Volumes/RPI/bcm2712d0-rpi-5-b.dtb
856a1d68639a5691655ffc34d6239b92a5273c9b610806f0716e5fd32725dffd  /Volumes/RPI/armstub8-rpi4.bin
8e8268627dd18ca40dd381de4fa16e55a80aa25b4185cf1151a705f075719b5c  /Volumes/RPI/kernel8.img
db6750da8bcaba889ee9746d562594e2e907f1b59a2f91089f8357b38d1095be  /Volumes/RPI/kernel8-rpi4.img
5b543c9008dcedee434aae4f95c1c39c1d5fc28583c33bc635b06da77fd26ae7  /Volumes/RPI/kernel_2712.img
ed21003ca15a3938d9e05f412ed18113c83abaefe8e1ca3276e3091273ae2e94  /Volumes/RPI/overlays/bcm2712d0.dtbo
58e58d0f4d384cbb88b8e61e1eaa4b631f0551f865ecaa984a579b5398090321  /Volumes/RPI/config.txt
pmoore@Petes-iMac:~/git/circle/boot fix-cflashy-macos $ 

@rsta2
Copy link
Owner

rsta2 commented Dec 4, 2024 via email

@petemoore
Copy link
Author

petemoore commented Dec 4, 2024

Ah thanks Rene. I tested with 08-usbkeyboard but wasn't able to get it working (make flash seemed to hang)

pmoore@Petes-iMac:~/git/circle fix-cflashy-macos $ cd sample/08-usbkeyboard/
pmoore@Petes-iMac:~/git/circle/sample/08-usbkeyboard fix-cflashy-macos $ make flash
  CPP   main.o
  CPP   kernel.o
  LD    kernel8-rpi4.elf
  DUMP  kernel8-rpi4.lst
  COPY  kernel8-rpi4.img
-n   WC    kernel8-rpi4.img => 
  248208
  COPY  kernel8-rpi4.hex
../../tools/cflashy \
		/dev/tty.SLAB_USBtoUART \
		--flashBaud:115200	 \
		--userBaud:115200 \
		--reboot: \
		 \
		kernel8-rpi4.hex

I also tried manually running cflashy with --monitorbut it also seemed to hang, so I Ctrl-C'd out of it.

pmoore@Petes-iMac:~/git/circle/sample/08-usbkeyboard fix-cflashy-macos $ ../../tools/cflashy /dev/tty.SLAB_USBtoUART --flashBaud:115200 --userBaud:115200 --monitor kernel8-rpi4.hex
^C
pmoore@Petes-iMac:~/git/circle/sample/08-usbkeyboard fix-cflashy-macos $

Normally when I tail logs I run screen -h 10000 /dev/tty.SLAB_USBtoUART 115200 so I think /dev/tty.SLAB_USBtoUART should be the correct device, and 115200 should be a supported baud rate. Is there a way to turn up the debug in the bootloader or in cflashy? It is very likely to be a problem on my side. 😬 Thanks Rene!

@rsta2
Copy link
Owner

rsta2 commented Dec 4, 2024 via email

@petemoore
Copy link
Author

Thanks Rene! Indeed it seems to be a problem with my setup then, since I have strange results.
I'm starting my terminal program:

pmoore@Petes-iMac:~/git/circle fix-cflashy-macos $ screen /dev/tty.SLAB_USBtoUART 115200

I then start recording the output (Ctrl-A, H).

Then I turn on the RPI, and 6 bytes are immediately received in the terminal, which produce garbled output, but the raw bytes can be seen in the recording:

pmoore@Petes-iMac:~ $ hexdump screenlog.0 
0000000 20 99 64 90 a2 fc                              
0000006
pmoore@Petes-iMac:~ $

Then I hit R in the terminal, again garbled characters are printed, but in the recording we see an additional 8 bytes:

pmoore@Petes-iMac:~ $ hexdump screenlog.0 
0000000 20 99 64 90 a2 fc 69 60 e9 eb c1 6a 74 81      
000000e
pmoore@Petes-iMac:~ $ 

Then I quit screen (Ctrl-A, k, y).

To test the USB/serial configuration, I built sample/08-usbkeyboard and replaced kernel8-rpi4.img on the bootloader SD card with the usb keyboard kernel of the same name, and created cmdline.txt with logdev=ttyS1 loglevel=4. After putting that back in the rpi400, running the same screen command on my Mac and powering on the rpi400, I can confirm that I received all the debug logs directly in the screen session on my Mac, without any messages being garbled etc. So the physical connection seems ok and the baud rate should also be ok, but I must have something misconfigured, somewhere, because there is no explanation for why the bootloader doesn't work, as that should be independent from cflashy, like you say... 🤔

@rsta2
Copy link
Owner

rsta2 commented Dec 4, 2024 via email

@petemoore
Copy link
Author

Hi Rene,

I'm afraid it didn't change anything. 😬

pmoore@Petes-iMac:~/git/circle fix-cflashy-macos $ cat /Volumes/RPI/config.txt 
#
# Enable 64-bit mode (AArch64)
#
# This file must be copied along with the generated kernel image
# onto a SDHC card with FAT file system, if 64-bit mode is used.
#
# This file also enables the possibility to use two displays with
# the Raspberry Pi 4 and selects the required mode for the USB host
# controller of the Compute Module 4.
#

arm_64bit=1
kernel_address=0x80000

# Enable this for JTAG / SWD debugging!
#enable_jtag_gpio=1

[pi02]
kernel=kernel8.img

[pi2]
kernel=kernel8.img

[pi3]
kernel=kernel8.img

[pi3+]
kernel=kernel8.img

[pi4]
armstub=armstub8-rpi4.bin
kernel=kernel8-rpi4.img
max_framebuffers=2
initial_turbo=0

[cm4]
otg_mode=1

[pi5]
kernel=kernel_2712.img
pmoore@Petes-iMac:~/git/circle fix-cflashy-macos $ hexdump -C screenlog.0 
00000000  20 99 64 90 a2 fc 69 60  e9 eb c1 6a 74 81        | .d...i`...jt.|
0000000e
pmoore@Petes-iMac:~/git/circle fix-cflashy-macos $ 

The hexdump looks to be consistent with the previous version.

@petemoore
Copy link
Author

(I don't know if it is related, but I've configured my rpi400 to TFTP boot if (and only if) there isn't an SD card present, this is how I normally do my bare metal dev, could there be settings in the EEPROM that are interfering?)

@petemoore
Copy link
Author

petemoore commented Dec 4, 2024

I booted into Raspberry Pi OS to have a look at the EEPROM, I'm not sure if it offers any clues...

pmoore@rpi400:~ $ vcgencmd bootloader_version
Apr 29 2021 17:11:25
version c2f8c388c4ee37ad709ace403467d163e8dd91ce (release)
timestamp 1619712685
update-time 1667208514
capabilities 0x0000001f
pmoore@rpi400:~ $ sudo rpi-eeprom-config
[all]
BOOT_UART=0
WAKE_ON_GPIO=1
POWER_OFF_ON_HALT=0
DHCP_TIMEOUT=45000
DHCP_REQ_TIMEOUT=4000
TFTP_FILE_TIMEOUT=30000
ENABLE_SELF_UPDATE=1
DISABLE_HDMI=0
BOOT_ORDER=0xf21

pmoore@rpi400:~ $ find /lib/firmware/raspberrypi/bootloader -type f -exec shasum -a 256 {} +
1309e1955fc7733c9fc89684558966bba0ec50a2e51610f24d07c7f065f9965b  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-07-19.bin
6246230ecd5b472902e6a49c95e857a5e3190c4fa6c462d6a8867e9a5e523a7c  /lib/firmware/raspberrypi/bootloader/stable/vl805-000138a1.bin
d17270f7e0554854f4801245be8c46fe09ddee9af2b8c460eb6e6500838b7115  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-08-02.bin
25e4aca93ad6ced5b6aa1d46a991702226e49a3b72dd01353d8e41a84deb1586  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2021-02-16.bin
b723056ad98f0c0ad2ff3833bcafa8dea996194eb3741b422c7ab160207e102f  /lib/firmware/raspberrypi/bootloader/stable/recovery.bin
5a07872332b53a90316a9f0c83c25998b700eef0b60a1faa918b42b36b425d07  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-06-15.bin
0b2cf17ea40b51e5e1bce986134b784665d0df691843c2491d73168e7f1057ee  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2021-12-02.bin
c3284e160f6329e024f2557de453df66f25df25238156035ab46bb45525db403  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2021-11-22.bin
cbcdb78e88594cf5b9f06ea6fe87d5f85e55c7bd217947a2486c695454df8d68  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2021-07-06.bin
85788f9cb09c8ec5e2c03444297cfa6dc480cf5730cd2dc50a7fb135635aa4c3  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-07-26.bin
88f43e537fd3e390c0447a34f0fc266b2305e32b413d0a969401518035bcac3b  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-07-16.bin
3a46dda0da13b8bf33fd2d00be7b1eec6dd8b92ade6a6b479da5bfb74d5adcff  /lib/firmware/raspberrypi/bootloader/stable/vl805-000137ad.bin
026319dac186d5a9a2533aebfa42dfc33101e14fbde0a4cc6fe02cd71b410af3  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-10-18.bin
a906fb9adbdff5232517655bca9362d0264422c3d3d39f29e6e8e92fffdfcdf6  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2021-01-16.bin
bb1b77f96cb69ba61e55137073134329aa1aeb5856081a1a5deeedb3d6ae65cf  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-04-16.bin
ec0e07c6d6af2663539b5ba148ad9952c73b9f635ee21071aaad9328a43e67a9  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2021-01-11.bin
922fd31b1510f6664961126a21985832f0c7df140bd4f00d4cca47e340c5d267  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-03-10.bin
03b81e39c628ff7d46f47250dc0db99b11fd0d3bf5411d484cf5655ed4d8cf70  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-02-08.bin
a6936c1917cfcd14031fc239bb8fb78b4e61596ed018152069b61553fedff415  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-01-25.bin
87efba8547f725a799e1e6ed66f1e801b5e41533cbf837daeff91e1aa653ec18  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-09-03.bin
514e49703834474a9ac10317895ed1cbf72f01ee55ee8391bd659df383aa8b80  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-04-26.bin
9e958161107c34deecb525d8da21d159eca3d9f5cdc5c8fc8376432857c4fb7d  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-09-02.bin
614d382f32afa2712f403bf05a0cf958370b4aacc489460786168a21f8f18aa2  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2022-07-22.bin
10390a29484ad78ce7eb3e75c8b14f240b42b6d1c9a532844240abec30993928  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2021-04-29.bin
14509822e609f9c03740aab974e51f12529baac23b3a4353c2899c4cbce10faa  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2021-03-18.bin
7062fee943de514c4be4ea61dcdb9edbece68f1bd30958a0264da639993cf528  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-07-31.bin
5bf7b831cf91f91ad40d68a8c14f4705535fcde2ec6a79c924d062804e8b4839  /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-12-11.bin
6246230ecd5b472902e6a49c95e857a5e3190c4fa6c462d6a8867e9a5e523a7c  /lib/firmware/raspberrypi/bootloader/critical/vl805-000138a1.bin
79839865437b5dd70ef39f38f22ced54bce903ce61b73050f78b1b4a01df1638  /lib/firmware/raspberrypi/bootloader/critical/recovery.bin
3a46dda0da13b8bf33fd2d00be7b1eec6dd8b92ade6a6b479da5bfb74d5adcff  /lib/firmware/raspberrypi/bootloader/critical/vl805-000137ad.bin
bb1b77f96cb69ba61e55137073134329aa1aeb5856081a1a5deeedb3d6ae65cf  /lib/firmware/raspberrypi/bootloader/critical/pieeprom-2020-04-16.bin
a6936c1917cfcd14031fc239bb8fb78b4e61596ed018152069b61553fedff415  /lib/firmware/raspberrypi/bootloader/critical/pieeprom-2022-01-25.bin
87efba8547f725a799e1e6ed66f1e801b5e41533cbf837daeff91e1aa653ec18  /lib/firmware/raspberrypi/bootloader/critical/pieeprom-2020-09-03.bin
514e49703834474a9ac10317895ed1cbf72f01ee55ee8391bd659df383aa8b80  /lib/firmware/raspberrypi/bootloader/critical/pieeprom-2022-04-26.bin
10390a29484ad78ce7eb3e75c8b14f240b42b6d1c9a532844240abec30993928  /lib/firmware/raspberrypi/bootloader/critical/pieeprom-2021-04-29.bin
14509822e609f9c03740aab974e51f12529baac23b3a4353c2899c4cbce10faa  /lib/firmware/raspberrypi/bootloader/critical/pieeprom-2021-03-18.bin
1309e1955fc7733c9fc89684558966bba0ec50a2e51610f24d07c7f065f9965b  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-07-19.bin
6246230ecd5b472902e6a49c95e857a5e3190c4fa6c462d6a8867e9a5e523a7c  /lib/firmware/raspberrypi/bootloader/beta/vl805-000138a1.bin
d17270f7e0554854f4801245be8c46fe09ddee9af2b8c460eb6e6500838b7115  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-08-02.bin
f14ba5175dc44d3e61aa96da0b4c9296cca71b36054d68784985fa53c2d8a0f9  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-10-06.bin
b723056ad98f0c0ad2ff3833bcafa8dea996194eb3741b422c7ab160207e102f  /lib/firmware/raspberrypi/bootloader/beta/recovery.bin
a3c3e1764902ea07abde390a0b17e6218b86f948fa648e6c55c93c34d5ddadd4  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-10-03.bin
85788f9cb09c8ec5e2c03444297cfa6dc480cf5730cd2dc50a7fb135635aa4c3  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-07-26.bin
026319dac186d5a9a2533aebfa42dfc33101e14fbde0a4cc6fe02cd71b410af3  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-10-18.bin
7b67f0df9f40166f162e0f31330dbae7f77d6abda696f8d625511fbd6bafc34d  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-10-12.bin
514e49703834474a9ac10317895ed1cbf72f01ee55ee8391bd659df383aa8b80  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-04-26.bin
b1c0fd22ae38c7ce62f5cbc88d56c90f13679281d1aefe183e14864cbe6dcec1  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-05-20.bin
9e958161107c34deecb525d8da21d159eca3d9f5cdc5c8fc8376432857c4fb7d  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-09-02.bin
614d382f32afa2712f403bf05a0cf958370b4aacc489460786168a21f8f18aa2  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-07-22.bin
c33effba82e4b3914bae90bfe83ed50c3a5358d26629be15b452269436d23eeb  /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2022-07-14.bin
c807b4a75cbedbb2e0dba08ee58dffbfc98e0bd900145accad67725c8bc13725  /lib/firmware/raspberrypi/bootloader/release-notes.md
pmoore@rpi400:~ $ 

@rsta2
Copy link
Owner

rsta2 commented Dec 4, 2024 via email

@petemoore
Copy link
Author

Sure, no problem, and thank you for looking into it!

pmoore@rpi400:~ $ sudo rpi-eeprom-update
*** UPDATE AVAILABLE ***
BOOTLOADER: update available
   CURRENT: Thu 29 Apr 2021 04:11:25 PM UTC (1619712685)
    LATEST: Tue 26 Apr 2022 10:24:28 AM UTC (1650968668)
   RELEASE: default (/lib/firmware/raspberrypi/bootloader/default)
            Use raspi-config to change the release.

  VL805_FW: Using bootloader EEPROM
     VL805: up to date
   CURRENT: 000138a1
    LATEST: 000138a1
pmoore@rpi400:~ $ 

@rsta2
Copy link
Owner

rsta2 commented Dec 5, 2024

Thanks. This is much older than expected. I will try to downgrade my RPi 400 to it for a test.

@rsta2
Copy link
Owner

rsta2 commented Dec 5, 2024

I have downgraded my EEPROM firmware to the same version, that is installed on your RPi 400, and I compared the SHA256 checksum of all files on my SD card with the checksums, you have posted. They are identical. Nevertheless everything (cFlashy, test with terminal program) works here. That's difficult to explain. If the setup is the same, it should behave identically. What I don't know is, if there are slightly different versions of the RPi 400. There are no Product Change Notifications for the RPi 400 on the Product Information Portal.

It looks to me, that the baud rate is not set properly in the serial bootloader. This can be caused by the property mailbox call, which fetches the core clock rate from the firmware. The core clock is the base clock for the Mini UART and in a test, it did run at 200 MHz. I would like to make a test with a fixed divider, which is written to the baud rate register of the Mini UART. For 200 MHz core clock and a target rate of 115200 Bps the divider should be 216 (200 MHz / (8 * 115200) - 1).

Would you please extract the attached .zip archive, copy the kernel8-rpi4.img file in it to your SD card and run another test with screen and (if it works) with cFlashy. Thanks!

kernel8-rpi4.zip

@rsta2
Copy link
Owner

rsta2 commented Dec 5, 2024

I did also change the boot configuration to your config. There was no change in behavior. Everything worked here.

@petemoore
Copy link
Author

Hi Rene!

During the day I upgraded my firmware:

pmoore@rpi400:~ $ sudo rpi-eeprom-update
BOOTLOADER: up to date
   CURRENT: Wed Jan 11 05:40:52 PM UTC 2023 (1673458852)
    LATEST: Wed Jan 11 05:40:52 PM UTC 2023 (1673458852)
   RELEASE: default (/lib/firmware/raspberrypi/bootloader/default)
            Use raspi-config to change the release.

  VL805_FW: Using bootloader EEPROM
     VL805: up to date
   CURRENT: 000138c0
    LATEST: 000138c0
pmoore@rpi400:~ $ 

Unfortunately the SD card broke today 😬. However, I was able to serve the new kernel you provided from the TFTP server, and to my surprise, got exactly the same result as before. Even the transmitted bytes were identical:

pmoore@Petes-iMac:~ $ hexdump -C screenlog.0 
00000000  20 99 64 90 a2 fc 69 60  e9 eb c1 6a 74 81        | .d...i`...jt.|
0000000e
pmoore@Petes-iMac:~ $

And the files served:

pmoore@rpimaster:/tftpboot $ find . -type f -exec shasum -a 256 {} + 2>/dev/null | sort -k2
af8067302947c01fd9eee72befa54c7e3ef8a48fecde7fd71277f2290b2bf0f7  ./COPYING.linux
c7283ff51f863d93a275c66e3b4cb08021a5dd4d8c1e7acc47d872fbe52d3d6b  ./LICENCE.broadcom
856a1d68639a5691655ffc34d6239b92a5273c9b610806f0716e5fd32725dffd  ./armstub8-rpi4.bin
770fb160f58fadedb170685a772f9318b2aa13c481e0246f81f6a0ba64de137c  ./bcm2710-rpi-zero-2-w.dtb
5bc13e0f663531c374cbf4645e511708e40a0774fc7771ae869c5504dc9e39b3  ./bcm2711-rpi-4-b.dtb
6c50cc760edcdee5c355970da683a4d81d1f04ddde0d52996ac927cf6c8b0d15  ./bcm2711-rpi-400.dtb
a7c1333d1b2272f674a1f0ccd0471b232d8fe09992616d52a59f2dacf79d05fa  ./bcm2711-rpi-cm4.dtb
4ed671a505f1df45161bd84234cb2f224438e9b8e0ce9b6791686202c8e39d1e  ./bcm2712-rpi-5-b.dtb
16672ed78def8a8721cbe78031ac91cb2e7f88165078137d8cffc0eb0f5c015f  ./bcm2712d0-rpi-5-b.dtb
af603ebd97e7b692c30195563f7b25656eb05d57838cf1a715ebb470d1614ce4  ./bootcode.bin
58e58d0f4d384cbb88b8e61e1eaa4b631f0551f865ecaa984a579b5398090321  ./config.txt
77129a82097fd05cd66d1a4f458f23b94a07d7b0ed1c5d64b2558f2aaad29aa5  ./fixup.dat
21e37b0402974a64779c23621787a37de4706877b78931c94e964db864e8565d  ./fixup4.dat
ead1e410073a3773af48fb25b1a8691250d553624aaa3e2345c0147c2a68fd1d  ./fixup4cd.dat
ead1e410073a3773af48fb25b1a8691250d553624aaa3e2345c0147c2a68fd1d  ./fixup_cd.dat
8ebae3c5191dd9f943493351121b118bc27b526ee3a33dd8d11e4fdd1d39c62a  ./kernel8-rpi4.img
8e8268627dd18ca40dd381de4fa16e55a80aa25b4185cf1151a705f075719b5c  ./kernel8.img
5b543c9008dcedee434aae4f95c1c39c1d5fc28583c33bc635b06da77fd26ae7  ./kernel_2712.img
ed21003ca15a3938d9e05f412ed18113c83abaefe8e1ca3276e3091273ae2e94  ./overlays/bcm2712d0.dtbo
5b6d7f52d821010f54bfdc2e5b94944b459f493fd59b41ec94544930793aa9a7  ./start.elf
451e4320cd2390c28e5c0e79e6e5a704f98fa11670ba57d840d16bcae5aeec2e  ./start4.elf
9b7055722b062ac2c56367fba328caecd73033d7a4a09a0fff7813399fe62816  ./start4cd.elf
ffe5e339f77e599fa450e274f30a6de57f066559452c33deb8011904f49d9aac  ./start_cd.elf
pmoore@rpimaster:/tftpboot $ 

At this point I started digging a bit deeper and I saw that circle uses ARM PL011 rather than Mini UART, so then I had a look at my own project to remind myself what I'm using (as my project logging is working for me on this rpi400). It turns out I'm using Mini UART, like the bootloader. I compared registry settings, and noticed that I am setting AUX_MU_BAUD_REG to 541 rather than 216 (indicating a 500MHz system clock). I tried patching this value directly into bootloader/periph.c but unfortunately it did not improve the situation. I then looked for other register differences between my code and the bootloader, and noticed that I'm setting AUX_MU_IIR_REG to 0x6 whereas the bootloader is setting it to 0xc6. I checked the BCM 2835 ARM Peripherals docs but saw that bits 6 and 7 are read only, and always read as 1, so the two values should be equivalent on write. Applying both changes also did not fix the problem. I did spot a reference to a 250MHz setting here but I haven't had time to see if it is related.

I think I can probably keep digging, but I should probably get some sleep now! Just wanted to give you an update as to where I am at right now...

This is my own Mini UART code for reference which is working for me on the rpi400. My plan is to continue comparing my uart code and the bootloader code until I establish which difference(s) cause the issue. I'll report back if I find the culprit! :-)

Thanks Rene!

btw - do you have any ideas about https://forums.raspberrypi.com/viewtopic.php?t=380418 ? (sorry, unrelated topic!)

@rsta2
Copy link
Owner

rsta2 commented Dec 6, 2024

Thanks Pete, for looking into this deeper! That's really a strange problem.

The core clock (base clock for Mini UART) changes, when the CPU clock is modified by the firmware. I think on the RPi 400 it's 200 MHz, when the CPU runs at 600 MHz. This should be the setup for the serial bootloader, when it gets control. The CPU clock can be risen to 1800 MHz on the RPi 400, the system clock should be 500 MHz then as you say, I haven't tested this.

This timer_init() code seems to be wrong for the RPi 400, but the timer is only used for the delay, which is applied before the go command takes affect, which is normally not used. The go delay on the RPi 400 would be slightly too long then, but this should be not a problem here.

I will have a look onto your MMU problem soon.

@petemoore
Copy link
Author

So this fixed things for me...

pmoore@Peters-MacBook-Pro-2:~/git/circle fix-cflashy-macos $ git diff
diff --git a/boot/config64.txt b/boot/config64.txt
index 0257af6d..5044425b 100644
--- a/boot/config64.txt
+++ b/boot/config64.txt
@@ -31,6 +31,8 @@ kernel=kernel8.img
 armstub=armstub8-rpi4.bin
 kernel=kernel8-rpi4.img
 max_framebuffers=2
+arm_boost=1
+core_freq_min=500
 
 [cm4]
 otg_mode=1
diff --git a/tools/bootloader/periph.c b/tools/bootloader/periph.c
index 2f605cfb..96d3bcfa 100644
--- a/tools/bootloader/periph.c
+++ b/tools/bootloader/periph.c
@@ -191,7 +191,8 @@ void uart_init ( void )
     PUT32(AUX_MU_MCR_REG,0);
     PUT32(AUX_MU_IER_REG,0);
     PUT32(AUX_MU_IIR_REG,0xC6);
-    PUT32(AUX_MU_BAUD_REG,div(get_clock(CLOCK_ID_CORE)/8 + DEFAULTBAUD/2, DEFAULTBAUD) - 1);
+//  PUT32(AUX_MU_BAUD_REG,div(get_clock(CLOCK_ID_CORE)/8 + DEFAULTBAUD/2, DEFAULTBAUD) - 1);
+    PUT32(AUX_MU_BAUD_REG,541);
     ra=GET32(GPFSEL1);
     ra&=~(7<<12); //gpio14
     ra|=2<<12;    //alt5
pmoore@Peters-MacBook-Pro-2:~/git/circle fix-cflashy-macos $ 

In my terminal on startup I see IHEX-F. Every time I hit R I get the same IHEX-F message back:

IHEX-F
IHEX-F
IHEX-F

I realise this might not be the best way of fixing the timing issue, just wanted to let you know it worked for me.

I'll test the macOS cflashy build now...

@petemoore
Copy link
Author

Note, cflashy still doesn't seem to work:

pmoore@Petes-iMac:~/git/circle/sample/08-usbkeyboard fix-bootloader $ make flash
../../tools/cflashy \
		/dev/tty.SLAB_USBtoUART \
		--flashBaud:115200	 \
		--userBaud:115200 \
		--reboot: \
		 \
		kernel8-rpi4.hex

I could try adding some debugging output in cflashy to see what is going on...

rsta2 added a commit that referenced this pull request Dec 12, 2024
Before the Mini UART was used on RPi 1-4, which depends on the core
clock, which varies with the ARM CPU clock. There have been problems
with setting the clock divider before, which should be fixed with using
the PL011 UART. Further modifications:

* Set RxD to pull-up and TxD to pull-none on RPi 1-4
* Use ARM system timer for go delay on RPi 1-4
* Convert ARM address to bus address for mailbox access on all models
* Slightly increase delay before mailbox access

See: #501
@rsta2
Copy link
Owner

rsta2 commented Dec 12, 2024

Thanks for testing! Good to know, how it can get to work. Unfortunately this fix does not directly lead to a solution, because the core clock may be different on other models and requiring to explicitly setting it in config.txt is error prone and may collide with the requirements of the program to be loaded.

That's why I modified the serial bootloader to use the PL011 UART on all RPi models. It was already used on the RPi 5. This UART does not rely on the core clock and has its own clock with a known default clock rate (48 MHz). There are also more fixes (see the commit message) and I hope, that the bootloader will now work for you. It's on the branch bootloader-pl011 at the moment.

I guess cFlashy hangs in the read() from the serial interface on MacOS. I implemented this with zero timeouts for Linux, so that read() immediately returns, when there is no data available. Maybe this does not work on MacOS. Perhaps it requires a fcntl(fd, F_SETFL, O_NONBLOCK) before setting the terminal options on MacOS?

It would be great, if you could cFlashy get to work on MacOS. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants