====== Raspberry Pi ====== * LOOK HERE: [[http://www.frank-durr.de/?p=203]] ===== Installing Mini Image ===== - Download the raw image [[https://minibianpi.wordpress.com/]] cd ~/work/pi wget <> - Uncompress the image md5sum 2016-03-12-jessie-minibian.tar.gz # verify that you get # 136cac722a4f78f49b54971ae1cc03ee 2016-03-12-jessie-minibian.tar.gz tar -zxvf 2016-03-12-jessie-minibian.tar.gz - Direct copy this image to your memory stick (mine is /dev/sdv but choose wisely!) time sudo /bin/dd bs=1M if=2016-03-12-jessie-minibian.img of=/dev/sdX - Resize the partition with **gparted** - Make **/dev/sdb2** fill the sdcard sudo gparted /dev/sdb :!::!: DO NOT DO THIS... USE **gparted** :!::!: Manually resize partition - Resize the partition to fill the entire sd scard - Display the partitions and figure out which is the partition to modify lsblk - Show the drive geometry sudo parted /dev/sdX (parted) unit chs (parted) print Model: Generic STORAGE DEVICE (scsi) Disk /dev/sdb: 490975,3,15 Sector size (logical/physical): 512B/512B BIOS cylinder,head,sector geometry: 490976,4,16. Each cylinder is 32.8kB. Partition Table: msdos Number Start End Type File system Flags 1 0,1,0 1953,3,15 primary fat16 2 1954,0,0 25407,3,15 primary ext4 - Remove partition 2 (parted) rm 2 - Define 2 now as all of the the drive (this goes with the geometry above) mkpart primary 1954,0,0 490975,3,15 ===== Cross Compiling ===== * [[https://www.raspberrypi.org/documentation/linux/kernel/building.md]] Attempting to cross compile on the GUI computer ==== GUI Compiler Setup ==== - Grab the toolchain cd ~/work mkdir pi cd ~/work/pi git clone https://github.com/raspberrypi/tools - Add this to your **PATH** - First edit your profile nano ~/.profile - And add this line # add raspberry pi toolchain to path PATH="$HOME/work/pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:$PATH" - Grab source code cd ~/work/pi git clone --depth=1 https://github.com/raspberrypi/linux ==== GUI Compile ==== Try compiling the source we just downloaded - Step one: setup cd ~/work/pi/linux KERNEL=kernel7 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig - Step two: build make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j `getconf _NPROCESSORS_ONLN` Install on the sd card - Create mount points and mount the card partitions to them cd /mnt sudo mkdir pisdcard sudo mkdir pisdcard/fat32 sudo mkdir pisdcard/ext4 sudo mount /dev/sdb1 /mnt/pisdcard/fat32 sudo mount /dev/sdb2 /mnt/pisdcard/ext4 - Install the kernel on the **ext4** partition # go where the kernel is that you want to install cd /home/lvis/work/pi/linux_original sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/pisdcard/ext4 modules_install - Backup the kernel on there, and then install our new kernel on the fat32 partition sudo cp /mnt/pisdcard/fat32/$KERNEL.img /mnt/pisdcard/fat32/$KERNEL-backup.img sudo scripts/mkknlimg arch/arm/boot/zImage /mnt/pisdcard/fat32/$KERNEL.img sudo cp arch/arm/boot/dts/*.dtb /mnt/pisdcard/fat32/ sudo cp arch/arm/boot/dts/overlays/*.dtb* /mnt/pisdcard/fat32/overlays/ sudo cp arch/arm/boot/dts/overlays/README /mnt/pisdcard/fat32/overlays/ sync sudo umount /mnt/pisdcard/fat32 sudo umount /mnt/pisdcard/ext4 ==== GUI RT PREEMPT Patch Compile ==== - Copy code and patch cd ~/work/pi wget https://www.kernel.org/pub/linux/kernel/projects/rt/4.9/patch-4.9.13-rt10.patch.xz rsync -vaP linux_original/ linux_4.9.13_rt10/ cd /home/lvis/work/pi/linux_4.9.13_rt10 xz -dc ../patch-4.9.13-rt10.patch.xz | patch -p1 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- clean - Setup cd ~/work/pi/linux_4.9.13_rt10 KERNEL=kernel7 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig - Modify the **.config** file to enable RT_PREEMPT - Load up the x11 configuration editor make xconfig - Search for "PREEMPT" - Processor type and features - Preemption Model (Fully Preemptible Kernel (RT)) - Timer frequency (1000 HZ) - Power management and ACPI options - REMOVE Device power management core functionality - CPU Frequency scaling - REMOVE CPU Frequency scaling - - Verify with a quick grep lvis@lvis-desktop:~/work/pi/linux_4.9.13_rt10$ cat .config | grep PREEMPT CONFIG_PREEMPT_RCU=y CONFIG_PREEMPT=y CONFIG_HAVE_PREEMPT_LAZY=y # CONFIG_PREEMPT_NONE is not set # CONFIG_PREEMPT_VOLUNTARY is not set CONFIG_PREEMPT__LL=y # CONFIG_PREEMPT_RTB is not set # CONFIG_PREEMPT_RT_FULL is not set CONFIG_PREEMPT_COUNT=y CONFIG_DEBUG_PREEMPT=y # CONFIG_PREEMPT_TRACER is not set - Build (had to press enter a BUNCH of times to accept defaults when I changed kernel config) make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j `getconf _NPROCESSORS_ONLN` Install on the sd card - Create mount points and mount the card partitions to them cd /mnt sudo mkdir pisdcard sudo mkdir pisdcard/fat32 sudo mkdir pisdcard/ext4 sudo mount /dev/sdb1 /mnt/pisdcard/fat32 sudo mount /dev/sdb2 /mnt/pisdcard/ext4 - Install the kernel on the **ext4** partition # go where the kernel is that you want to install cd ~/work/pi/linux_4.9.13_rt10 sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/pisdcard/ext4 modules_install - Backup the kernel on there, and then install our new kernel on the fat32 partition sudo cp /mnt/pisdcard/fat32/$KERNEL.img /mnt/pisdcard/fat32/$KERNEL-backup.img sudo scripts/mkknlimg arch/arm/boot/zImage /mnt/pisdcard/fat32/$KERNEL.img sudo cp arch/arm/boot/dts/*.dtb /mnt/pisdcard/fat32/ sudo cp arch/arm/boot/dts/overlays/*.dtb* /mnt/pisdcard/fat32/overlays/ sudo cp arch/arm/boot/dts/overlays/README /mnt/pisdcard/fat32/overlays/ - Add this line to **/boot/cmdline.txt** which can cause kernel panic if not disabled - Edit this file sudo nano /mnt/pisdcard/fat32/cmdline.txt - and add these statements # found this additional one too # http://www.frank-durr.de/?p=203 # Most people also disable the Low Latency Mode (llm) for the SD card: sdhci_bcm2708.enable_llm=0 dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0 - Unmount the drives sync # just run this before unmounting the drives.. flush the cache sudo umount /mnt/pisdcard/fat32 sudo umount /mnt/pisdcard/ext4 ==== Boot Pi ==== - Insert sd card into Pi - FIXME Insert the keyboard into the Pi (WITHOUT a device in there... the kernel panics on boot!) - Default user/pass is **root** and **raspberry** which I changed to the lvis standard password ===== Cyclic Test ===== We want to run cyclic test on here to make sure that the performance on the Pi is what we need /home/lvis/work/pi/linux_4.9.13_rt10 - Update our software apt-get update apt-get upgrade - Install **gcc** **git** apt-get install build-essential git - Download the cyclic test code (found from here: [[https://rt.wiki.kernel.org/index.php/Cyclictest]]) mkdir ~/work cd ~/work git clone git://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git - Checkout the stable version cd ~/work/rt-tests git fetch git checkout stable/v1.0 - Compile and install make all cp ./cyclictest /usr/local/bin/ - Try it out cyclictest -a -t -n -p99 # use priority 80 and interval of 4khz cyclictest -m -t -p 80 -n -i 250 ===== Xenomai ===== cd /home/lvis/work/pi mkdir download cd download wget https://xenomai.org/downloads/ipipe/v4.x/arm/ipipe-core-4.1.18-arm-9.patch wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.1.18.tar.xz wget https://xenomai.org/downloads/xenomai/stable/latest/xenomai-3.0.3.tar.bz2 wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.43.tar.xz wget https://xenomai.org/downloads/ipipe/v4.x/arm/ipipe-core-4.4.43-arm-7.patch # uncompress kernel cd /home/lvis/work/pi tar xf download/linux-4.1.18.tar.xz mv linux-4.1.18 linux-4.1.18-ipipe tar xf download/linux-4.4.43.tar.xz mv linux-4.4.43 linux-4.4.43-ipipe # uncompress xenomai tar xvf download/xenomai-3.0.3.tar.bz2 # copy the latest ipipe patch for 4.1.18 in to the patch directory cd /home/lvis/work/pi/xenomai-3.0.3 # cp ../download/ipipe-core-4.1.18-arm-9.patch kernel/cobalt/arch/arm/patches/ cp -a ../download/ipipe-core-4.4.43-arm-7.patch xenomai-3.0.3/kernel/cobalt/arch/arm/patches/ # patch kernel cd ~/work/pi/xenomai-3.0.3 ./scripts/prepare-kernel.sh --linux=~/work/pi/linux-4.1.18-ipipe ./scripts/prepare-kernel.sh --linux=~/work/pi/linux-4.4.43-ipipe # and type "arm" for architecture (no errors) # configure kernel (first default, then we change it) KERNEL=kernel7 cd ../linux-4.1.18-ipipe cd ../linux-4.4.43-ipipe #### make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig * CPU Power Management * Turn it all off * Kernel Features * Preemption Model (Preemptible Kernel (Low-Latency Desktop)) * Kernel Features * [NO] Allow for memory compaction * Kernel Features * [NO] Contiguous Memory Allocator │ Selected by: COMPACTION [=y] && MMU [=y] || CMA [=y] && HAVE_MEMBLOCK [=y] && MMU [=y] ** for sage build, not doing this ** enabling this CONFIG_XENO_OPT_SHIRQ * Had to disable the Intel ethernet modules... it had an error, just disabled ALL Intel ethernet... * Had to disable lustre driver from device -> staging * Had to disable CAIF virtio transport driver make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j `getconf _NPROCESSORS_ONLN` ===== Xenomai Pi Compiled ===== This did compile for me, haven't tried it yet! --- //[[david@lattice.net|David Lloyd Rabine]] 2017/03/04 20:55// cd ~/work/pi tar xf download/linux-4.4.43.tar.xz mv linux-4.4.43 linux-4.4.43-ipipe cd xenomai-3.0.3 scripts/prepare-kernel.sh --arch=arm --linux=~/work/pi/linux-4.4.43-ipipe cd ~/work/pi/linux-4.4.43-ipipe export KERNEL=kernel7 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2835_defconfig # make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs # no modules!? make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage dtbs -j `getconf _NPROCESSORS_ONLN` cd /mnt sudo mkdir pisdcard sudo mkdir pisdcard/fat32 sudo mkdir pisdcard/ext4 sudo mount /dev/sdb1 /mnt/pisdcard/fat32 sudo mount /dev/sdb2 /mnt/pisdcard/ext4 # go where the kernel is that you want to install cd ~/work/pi/linux-4.4.43-ipipe sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/pisdcard/ext4 modules_install # and the rest sudo cp /mnt/pisdcard/fat32/$KERNEL.img /mnt/pisdcard/fat32/$KERNEL-backup.img sudo scripts/mkknlimg arch/arm/boot/zImage /mnt/pisdcard/fat32/$KERNEL.img sudo cp arch/arm/boot/dts/*.dtb /mnt/pisdcard/fat32/ sudo cp arch/arm/boot/dts/overlays/*.dtb* /mnt/pisdcard/fat32/overlays/ sudo cp arch/arm/boot/dts/overlays/README /mnt/pisdcard/fat32/overlays/ Xenomai Application Example from /home/david/src/pi/xenomai-3.0.3/demo/posix/cobalt/eth_p_all.c pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m); while(1) { } Another good example **/home/david/src/pi/xenomai-3.0.3/demo/posix/cobalt/xddp-echo.c** This example sends data down the pipe to keep from context switching which is probably what is causing Dan's code to not keep up. * This is an excellent example that has a real time thread and a non-real time thread that communicate. ===== Xenomai Pi 3 Compile HOWTO ===== Using this as the basis: [[https://www.blaess.fr/christophe/2016/05/22/xenomai-3-sur-raspberry-pi-2/]] - Grab Xenomai cd ~/work/pi/download wget <> - What patches do we have? cd ~/work/pi/ tar xf download/xenomai-3.0.3.tar.bz2 ls xenomai-3.0.3/kernel/cobalt/arch/arm/patches/ # # results ipipe-core-3.10.32-arm-13.patch ipipe-core-3.18.20-arm-11.patch ipipe-core-4.1.18-arm-9.patch README ipipe-core-3.14.44-arm-16.patch ipipe-core-4.1.18-arm-8.patch ipipe-core-4.4.43-arm-7.patch - Grab the source code from the **git** repository git clone https://github.com/raspberrypi/linux cd linux git checkout rpi-4.4.y - Create a new Xenomai branch git checkout -b xenomai-3.0.3 - Dry run the patch patch --dry-run -p1 <../xenomai-3.0.3/kernel/cobalt/arch/arm/patches/ipipe-core-4.4.43-arm-7.patch - Patch the kennel assuming you saw no FAILS in the dry run test cd .. xenomai-3.0.3/scripts/prepare-kernel.sh --linux=linux --arch=arm --ipipe=xenomai-3.0.3/kernel/cobalt/arch/arm/patches/ipipe-core-4.4.43-arm-7.patch - Build the default configuration KERNEL=kernel7 cd linux make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2835_defconfig - Configure the kernel make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig - Make these changes - Kernel Features ---> - Preemptible Kernel (Low-Latency Desktop) - DISBLE Allow for memory compaction - DISABLE Contiguous Memory Allocator - CPU Power Management ---> OFF everything - Kernel hacking - DISABLE KGDB: kernel debugger - Compile! make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j 6 - Ran this with the 3.1.18 kernel... seems like that might work.