Update: Cross Building Linux With ELLCC: Part 4 – Building Linux on the Mac
In my last post I described using ELLCC to build Linux for the Raspberry Pi B+. In ELLCC version 0.1.24 I added a script to build Linux for both the Pi B+ and the Pi 2. As a bonus, the script also builds a bunch of userland programs
First grab the latest binary release:
[~] dev% wget http://ellcc.org/releases/ellcc-x86_64-linux-eng-0.1.24.tgz [~] dev% tar xvfp ellcc-x86_64-linux-eng-0.1.24.tgz
Now decide what target to build:
[~] dev% cd ellcc/libecc/ecclinux/ [~/ellcc/libecc/ecclinux] dev% ls 00_rpilinux-4.1.15.patch bin/ etc/ makefile sbin/ 99_llvmlinux-4.1.15.patch build* iproute2.patch ntfs3g.patch sinit/ [~/ellcc/libecc/ecclinux] dev% ./build usage: ./build [options] target options: -nokernel Don't build the Linux kernel -clean Clean up a previous build targets: help This message bcmrpi Raspberry Pi (ARMv6) bcm2709 Raspberry Pi 2 (ARMv7) [~/ellcc/libecc/ecclinux] dev%
Run the build command again, with the board you need as an argument (I’m going to time the build with time):
[~/ellcc/libecc/ecclinux] dev% time ./build bcm2709 ... (lots of output removed) 4984.143u 435.744s 22:52.57 394.8% 0+0k 704+4154968io 2pf+0w [~/ellcc/libecc/ecclinux] dev%
As SpongeBob would say, “23 minutes later.” When the build is finished, the ecclinux directory looks like this:
[~/ellcc/libecc/ecclinux] dev% ls 00_rpilinux-4.1.15.patch bin/ etc/ linux-4.1.15/ sbin/ 99_llvmlinux-4.1.15.patch build* image/ makefile sinit/ arm-linux-engeabihf/ download/ iproute2.patch ntfs3g.patch [~/ellcc/libecc/ecclinux] dev%
There are three new directories: download/ contains tar files that have been downloaded in case you need them again, arm-linux-engeabihf/ is where the build was made for the ARMv7, and image/ is where the binaries were installed. Let’s take a look at image/arm-linux-engeabihf/:
[~/ellcc/libecc/ecclinux] dev% ls image/arm-linux-engeabihf/ bcm2709/ bin/ etc/ lib/ sbin/ usr/ var/ [~/ellcc/libecc/ecclinux] dev%
The bcm2709/ directory is what will be in the /boot directory in the final Raspberry Pi 2 SD image. It has Pi 2 specific files in it, including the kernel:
[~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev% ls bcm2709/ dtbs/ System.map-4.1.15-v7 vmlinuz-4.1.15-v7 [~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev%
Here’s what the bin and sbin directories look like:
[~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev% ls bin/ sbin/ bin/: [* ed* ksh* nltrigger* sha256sum* tty* basename* eject* last* nohup* sha512sum* umount* cal* env* lastlog* od* sleep* uname* cat* ex@ link* pagesize* smdev* unexpand* chattr* expand* ln* passwd* sort* uniq* chgrp* expr* logger* paste* split* unlink* chmod* fallocate* login* pidof* sponge* unshare* chown* false* logname* pivot_root* stat* uptime* chroot* find* ls* printenv* strings* uudecode* chvt* flock* lsattr* printf* su* uuencode* cksum* fold* lsmod* ps* swaplabel* uuidgen* clear* free* lsusb* pwd* swapoff* view@ cmp* freeramdisk* md5sum* readahead* swapon* vim* cols* fsfreeze* mesg* readlink* switch_root* vimdiff@ comm* getconf* mkdir* renice* sync* vimtutor* cp* getty* mkfifo* respawn* sysctl* vtallow* cron* grep* mknod* rm* tail* watch* ctrlaltdel* halt* mkswap* rmdir* tar* wc* cut* head* mktemp* rmmod* tee* which* date* hostname* mount* run_nldev* test* who* dd* hwclock* mountpoint* rview@ tftp* whoami* df* id* mv* rvim@ time* xargs* dirname* insmod* nice* sed* touch* xxd* dmesg* join* nl* seq* tr* yes* du* kill* nldev* setsid* true* echo* killall5* nlmon* sha1sum* truncate* sbin/: badblocks* findfs@ mke2fs* ntfs-3g.secaudit* resize2fs* blkid* fsck* mkfs.ext2@ ntfs-3g.usermap* routef* bridge* fsck.ext2@ mkfs.ext3@ ntfscat* routel* ctstat@ fsck.ext3@ mkfs.ext4@ ntfsclone* rtacct* debugfs* fsck.ext4@ mkfs.ext4dev@ ntfscluster* rtmon* dumpe2fs* fsck.ext4dev@ mkfs.ntfs@ ntfscmp* rtpr* e2freefrag* genl* mklost+found* ntfscp* rtstat@ e2fsck* ifcfg* mkntfs* ntfsfix* sdhcp* e2image* ifstat* mount.lowntfs-3g@ ntfsinfo* sinit* e2label@ ip* mount.ntfs-3g@ ntfslabel* ss* e2undo* lnstat* nstat* ntfsls* tune2fs* e4defrag* logsave* ntfs-3g* ntfsresize* uuidd* filefrag* lowntfs-3g* ntfs-3g.probe* ntfsundelete* [~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev%
Not bad for 23 minutes of work!
If you want to try the kernel on your Pi 2, you need to copy vmlinuz-4.1.15-v7 to the Rasbian /boot directory as kernel7.img. In my case, my Pi 2 is at 192.124.43.100 so I can do this:
[~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev% scp bcm2709/vmlinuz-4.1.15-v7 root@192.124.43.100:/boot/kernel7.img root@192.124.43.100's password: vmlinuz-4.1.15-v7 100% 4355KB 4.3MB/s 00:00 [~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev%
After a reboot:
[rich@dev ~]$ ssh root@192.124.43.100 root@192.124.43.100's password: The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Fri Jan 1 17:28:43 2016 from 192.124.43.2 root@raspberrypi:~# dmesg | less [ 0.000000] Booting Linux on physical CPU 0xf00 [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Initializing cgroup subsys cpuacct [ 0.000000] Linux version 4.1.15-v7 (rich@dev) (ecc 0.1.24 based on clang version 3.8.0 (trunk) (based on LLVM 3.8.0svn)) #1 SMP Mon Jan 4 20:45:34 CST 2016
Not bad. To complete the kernel update you’ll also want to update the kernel modules:
[~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev% ls lib/modules/4.1.15-v7/ kernel/ modules.builtin modules.dep.bin modules.softdep modules.alias modules.builtin.bin modules.devname modules.symbols modules.alias.bin modules.dep modules.order modules.symbols.bin [~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev% scp -r lib/modules/4.1.15-v7/ root@192.124.43.100:/lib/modules root@192.124.43.100's password: Permission denied, please try again. root@192.124.43.100's password: modules.symbols 100% 146KB 146.2KB/s 00:00 modules.dep 100% 131KB 131.1KB/s 00:00 ... modules.builtin.bin 100% 5903 5.8KB/s 00:00 modules.builtin 100% 4341 4.2KB/s 00:00 [~/ellcc/libecc/ecclinux/image/arm-linux-engeabihf] dev%
Reboot again and even the mouse and keyboard work.
In Part 4, I’ll show how to make the SD image and use the userland programs that we’ve built. In the mean time you can copy them to the Pi’s SD card and use them.