All this work was done on a Raspberry Pi 3, that´s a 1.2 GHz 64-bit quad-core ARMv8 CPU and later on a Raspberry Pi 2.
I used the Raspberry as development platform, but you can cross-compile if you want.
Operative System:
I used Minibian, a reduced Debian Linux (no GUI), in order to get it visit https://minibianpi.wordpress.com/
To get an AMP environment we need to boot Linux with at most three cores and reserve one for bare-metal. Also RAM needs to be separated, i.e. lower 512 MB for OS and upper 512Mb for bare-metal.
Linux kernel accepts boot time parameters that can be used to force kernel to override the default hardware using.
With "maxcpus" and "mem" boot parms we will get the job done, but.... standard Raspberry Pi boot process involves GPU bootloader, ARM bootloader, and a config.txt with some possible configuration options (not really full compilant linux boot parameters). Setting maxcpus=3 and mem=512 in config.txt result in a system boot with 3 active cores, but very inestable, even it crash with ethernet cable connected. And the "mem" parameter has no effect (Linux gets all RAM).
Here comes U-Boot to help us,
Bootloader:
Following step is based on Tim's post about
"Booting a Raspberry Pi2, with u-boot and HYP enabled"
NOTE; Last updates are mandatory for Raspberry Pi 3!! Be sure to do:
apt-get install rpi-update
rpi-update
U-boot is a flexible bootloader intended for embedded systems. Clone and compile it:
git clone git://git.denx.de/u-boot.git
cd u-boot
make rpi_2_defconfig
make all
Copy u-boot.bin to your SD and change config.txt to read:
kernel=u-boot.bin
|
Using CH340 from ex-arduino nano |
Now you need a serial console to boot and (press any key) to get U-boot prompt to set and save environment vars:
setenv machid 0x00000c42
setenv bootargs= earlyprintk console=tty0 console=ttyAM0 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait noinitrd mem=512M maxcpus=3
saveenv
Create a boot.sc.source file containing:
fatload mmc 0:1 ${fdt_addr_r} bcm2710-rpi-3-b.dtb
fatload mmc 0:1 ${kernel_addr_r} kernel7.img
bootz ${kernel_addr_r} - ${fdt_addr_r}
And do:
mkimage -A arm -O linux -T script -C none -n boot.scr -d boot.scr.source boot.scr
Move the obtained boot.scr file to SD root.
+If you don't have a serial adapter you can get example files in the boot folder at the
repository
Now Linux boots with 3 cores (draws only 3 berries during boot) and half memory (512Mb)
Test it with
free
cat /proc/cpuinfo
We have remaining hardware resources for simultaneous baremetal app run: AMP!
Read Step 2 for Bare Metal Coding
+If you have experience obtaining a Raspberry Pi uboot.env file from Linux with fw_setenv please let me know. This will avoid the serial adapter for succeeding bootargs mods.