Add rule to upload stage3 disk image to webserver.
[fedora-riscv.git] / Makefile
index 96da1ca..74e91a0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,8 @@ LOCAL_LINUX_GIT_COPY = $(HOME)/d/linux
 STAGE3_PACKAGES = gcc rpm-build
 
 # Versions of cross-compiled packages.
-BASH_VERSION    = 4.3
+BASH_VERSION      = 4.3
+COREUTILS_VERSION = 8.25
 
 all: stage1 stage2 stage3 stage4
 
@@ -237,6 +238,8 @@ stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
        stage3-chroot/etc/fedora-release \
        stage3-chroot/lib64/libc.so.6 \
        stage3-chroot/bin/bash \
+       stage3-chroot/bin/ls \
+       stage3-chroot/init \
        stage3-disk.img
 
 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
@@ -251,11 +254,13 @@ stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
        git fetch riscv && \
        git checkout -f linux-4.1.y-riscv && \
        make mrproper && \
-       make ARCH=riscv defconfig && \
-       make ARCH=riscv \
-           CONFIG_CROSS_COMPILE=riscv64-unknown-elf- \
-           CONFIG_CMDLINE="root=/dev/htifblk0 init=/bin/bash" \
-           vmlinux
+       make ARCH=riscv defconfig
+       echo CONFIG_CMDLINE=\"root=/dev/htifblk0 init=/init\" >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
+       echo CONFIG_CROSS_COMPILE=riscv64-unknown-elf- >> stage3-kernel/linux-$(KERNEL_VERSION)/.config
+       cd stage3-kernel/linux-$(KERNEL_VERSION) && \
+       make ARCH=riscv olddefconfig
+       cd stage3-kernel/linux-$(KERNEL_VERSION) && \
+       make ARCH=riscv vmlinux
        ls -l $@
 
 # Build an original (x86-64) chroot using supermin.  We then aim to
@@ -305,11 +310,56 @@ bash-$(BASH_VERSION).tar.gz:
        wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
        mv $@-t $@
 
+# Cross-compile coreutils.  Bleah, coreutils cross-compilation is
+# known-broken and upstream don't care, hence the 'touch' command.
+
+COREUTILS_PROGRAMS = arch base32 base64 basename cat chcon chgrp chmod chown chroot cksum comm cp csplit cut date dd df dir dircolors dirname du echo env expand expr factor false fmt fold ginstall groups head hostid hostname id install join kill link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup nproc numfmt od paste pathchk pinky pr printenv printf ptx pwd readlink realpath rm rmdir runcon seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf sleep sort split stat stdbuf stty sum sync tac tail tee test timeout touch tr true truncate tsort tty uname unexpand uniq unlink uptime users vdir wc who whoami yes
+
+stage3-chroot/bin/ls: coreutils-$(COREUTILS_VERSION).tar.xz
+       rm -rf coreutils-$(COREUTILS_VERSION)
+       tar Jxf $^
+       cd coreutils-$(COREUTILS_VERSION) && \
+       ./configure --host=riscv64-unknown-linux-gnu CFLAGS="--sysroot=/usr/sysroot"
+       -cd coreutils-$(COREUTILS_VERSION) && make
+       cd coreutils-$(COREUTILS_VERSION)/man && \
+       for f in $(COREUTILS_PROGRAMS); do touch $$f.1; done
+       cd coreutils-$(COREUTILS_VERSION) && make
+       for f in $(COREUTILS_PROGRAMS); do \
+           cp coreutils-$(COREUTILS_VERSION)/src/$$f stage3-chroot/bin/; \
+       done
+
+coreutils-$(COREUTILS_VERSION).tar.xz:
+       rm -f $@ $@-t
+       wget -O $@-t ftp://ftp.gnu.org/gnu/coreutils/coreutils-$(COREUTILS_VERSION).tar.xz
+       mv $@-t $@
+
+# Create an /init script.
+stage3-chroot/init: init.sh
+       install -m 0755 $^ $@
+
 # Create the stage3 disk image.
 # Note `-s +...' adds spare space to the disk image.
 stage3-disk.img: stage3-chroot
        cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G
 
+# Upload the compressed disk image.
+upload-stage3: stage3-disk.img.xz
+       scp $^ tick:public_html/riscv/
+stage3-disk.img.xz: stage3-disk.img
+       rm -f $@
+       xz --best $^
+
+# Helper which boots stage3 disk image in spike.
+boot-stage3-in-spike: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
+       spike +disk=stage3-disk.img \
+           /usr/bin/bbl stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
+
+# Helper which boots stage3 disk image in qemu.
+boot-stage3-in-qemu: stage3-disk.img stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux
+       qemu-system-riscv -kernel /usr/bin/bbl \
+           -append ./stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
+           -drive file=stage3-disk.img,format=raw -nographic
+
 # Stage 4
 
 stage4: