From 7cb21361290114363933c050784c5d8b6ee32f54 Mon Sep 17 00:00:00 2001 From: Mateusz Holenko Date: Wed, 20 May 2020 18:21:28 +0200 Subject: [PATCH 1/3] linux: unify linux source This commit changes the linux source for VexRiscv and mor1kx to litex-hub/linux. Since this is the same repository as used by linux-on-litex-vexriscv and all the LiteX drivers are included, there is no more need for additional BUILD_BUILDROOT option. This also updates rootfs images for both architectures and adds buildroot configs used to generate them. --- Makefile | 5 +- configs/linux-rootfs/README | 15 ++ configs/linux-rootfs/buildroot_mor1kx.config | 31 +++ .../linux-rootfs/buildroot_vexriscv.config | 41 ++++ .../linux-rootfs/rootfs_overlay/etc/profile | 20 ++ scripts/build-linux.sh | 192 +++++++----------- 6 files changed, 184 insertions(+), 120 deletions(-) create mode 100644 configs/linux-rootfs/README create mode 100644 configs/linux-rootfs/buildroot_mor1kx.config create mode 100644 configs/linux-rootfs/buildroot_vexriscv.config create mode 100644 configs/linux-rootfs/rootfs_overlay/etc/profile diff --git a/Makefile b/Makefile index c5b835f3d..824f562c2 100755 --- a/Makefile +++ b/Makefile @@ -407,11 +407,14 @@ tftp: $(FIRMWARE_FILEBASE).bin ifeq ($(FIRMWARE),linux) cp $(FIRMWARE_FILEBASE).bin $(TFTPD_DIR)/Image cp $(FIRMWARE_DIR)/$(ROOTFS_FILE) $(TFTPD_DIR)/rootfs.cpio -ifeq ($(CPU),vexriscv) cp $(FIRMWARE_DIR)/boot.json $(TFTPD_DIR) +ifeq ($(CPU),vexriscv) cp $(FIRMWARE_DIR)/rv32.dtb $(TFTPD_DIR) cp $(TARGET_BUILD_DIR)/emulator/emulator.bin $(TFTPD_DIR) endif +ifeq ($(CPU),mor1kx) + cp $(FIRMWARE_DIR)/mor1kx.dtb $(TFTPD_DIR) +endif else cp $(FIRMWARE_FILEBASE).bin $(TFTPD_DIR)/boot.bin endif diff --git a/configs/linux-rootfs/README b/configs/linux-rootfs/README new file mode 100644 index 000000000..af8f33cff --- /dev/null +++ b/configs/linux-rootfs/README @@ -0,0 +1,15 @@ +Steps to rebuild a rootfs image using buildroot: + +(1) clone buildroot: + + git clone https://github.com/buildroot/buildroot + cd buildroot + +(2) configure + + cp ../buildroot_mor1kx.config .config + # or cp ../buildroot_vexriscv.config .config + make olddefconfig + make + +(3) the resulting image is in output/images diff --git a/configs/linux-rootfs/buildroot_mor1kx.config b/configs/linux-rootfs/buildroot_mor1kx.config new file mode 100644 index 000000000..8aac59f25 --- /dev/null +++ b/configs/linux-rootfs/buildroot_mor1kx.config @@ -0,0 +1,31 @@ +# +# Target options +# +BR2_or1k=y + +# GCC +BR2_GCC_VERSION_8_X=y +BR2_GCC_VERSION="8.3.0" + +# System +BR2_TARGET_GENERIC_GETTY=y +BR2_TARGET_GENERIC_GETTY_PORT="console" + +# Filesystem +BR2_TARGET_ROOTFS_CPIO=y + +# Kernel headers +BR2_KERNEL_HEADERS_VERSION=y +BR2_DEFAULT_KERNEL_VERSION="5.0.13" +BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_0=y + +# Rootfs overlay +BR2_ROOTFS_OVERLAY="../rootfs_overlay" + +# Extra packages +#BR2_PACKAGE_DHRYSTONE=y +#BR2_PACKAGE_MICROPYTHON=y +#BR2_PACKAGE_SPIDEV_TEST=y +#BR2_PACKAGE_MTD=y +#BR2_PACKAGE_MTD_JFFS_UTILS=y + diff --git a/configs/linux-rootfs/buildroot_vexriscv.config b/configs/linux-rootfs/buildroot_vexriscv.config new file mode 100644 index 000000000..f2c6f7bab --- /dev/null +++ b/configs/linux-rootfs/buildroot_vexriscv.config @@ -0,0 +1,41 @@ +# +# Target options +# +BR2_riscv=y +BR2_RISCV_32=y + +# +# Instruction Set Extensions +# +BR2_riscv_custom=y +BR2_RISCV_ISA_CUSTOM_RVM=y +BR2_RISCV_ISA_CUSTOM_RVA=y +BR2_RISCV_ISA_CUSTOM_RVC=n +BR2_RISCV_ABI_ILP32=y + +# GCC +BR2_GCC_VERSION_8_X=y +BR2_GCC_VERSION="8.3.0" + +# System +BR2_TARGET_GENERIC_GETTY=y +BR2_TARGET_GENERIC_GETTY_PORT="console" + +# Filesystem +BR2_TARGET_ROOTFS_CPIO=y + +# Kernel headers +BR2_KERNEL_HEADERS_VERSION=y +BR2_DEFAULT_KERNEL_VERSION="5.0.13" +BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_0=y + +# Rootfs overlay +BR2_ROOTFS_OVERLAY="../rootfs_overlay" + +# Extra packages +#BR2_PACKAGE_DHRYSTONE=y +#BR2_PACKAGE_MICROPYTHON=y +#BR2_PACKAGE_SPIDEV_TEST=y +#BR2_PACKAGE_MTD=y +#BR2_PACKAGE_MTD_JFFS_UTILS=y + diff --git a/configs/linux-rootfs/rootfs_overlay/etc/profile b/configs/linux-rootfs/rootfs_overlay/etc/profile new file mode 100644 index 000000000..d4f758552 --- /dev/null +++ b/configs/linux-rootfs/rootfs_overlay/etc/profile @@ -0,0 +1,20 @@ +export PATH="/bin:/sbin:/usr/bin:/usr/sbin" + +if [ "$PS1" ]; then + if [ "`id -u`" -eq 0 ]; then + export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\# ' + else + export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' + fi +fi + +export PAGER='/bin/more' +export EDITOR='/bin/vi' + +# Source configuration files from /etc/profile.d +for i in /etc/profile.d/*.sh ; do + if [ -r "$i" ]; then + . $i + fi +done +unset i diff --git a/scripts/build-linux.sh b/scripts/build-linux.sh index 43ebc7be0..b397fa472 100755 --- a/scripts/build-linux.sh +++ b/scripts/build-linux.sh @@ -52,75 +52,67 @@ if ! ${CPU_ARCH}-linux-musl-gcc --version > /dev/null 2>&1; then conda install gcc-${CPU_ARCH}-linux-musl fi -if [ ${CPU} = mor1kx ]; then - LINUX_REMOTE="${LINUX_REMOTE:-https://github.com/timvideos/linux-litex.git}" - LINUX_REMOTE_NAME=timvideos-linux-litex - LINUX_BRANCH=${LINUX_BRANCH:-master-litex} +LINUX_REMOTE="${LINUX_REMOTE:-https://github.com/litex-hub/linux.git}" +LINUX_REMOTE_NAME=litex-hub-linux +LINUX_BRANCH=${LINUX_BRANCH:-litex_buildenv} + +RESOURCES_LOCATION="https://dl.antmicro.com/projects/renode/litex-buildenv/" +if [ ${CPU} = mor1kx ]; then export ARCH=openrisc - # To rebuild, use https://ozlabs.org/~joel/litex_or1k_defconfig - ROOTFS_LOCATION="https://ozlabs.org/~joel/" - ROOTFS=${ARCH}-rootfs.cpio.gz - ROOTFS_MD5="3a254683a7b6f441a4acc0d4c555230a" + ROOTFS=or1k-rootfs.cpio + DTB=mor1kx.dtb + ROOTFS_MD5="c9ef89b45b0d2c34d14978a21f2863bd" + DTB_MD5="0271bc8f63f2d928dc9536ac31a2c6b9" elif [ ${CPU} = vexriscv ]; then - LINUX_REMOTE="${LINUX_REMOTE:-https://github.com/torvalds/linux.git}" - LINUX_REMOTE_NAME=upstream-linux - LINUX_BRANCH=${LINUX_BRANCH:-v5.0} - export ARCH=riscv - ROOTFS_LOCATION="https://antmicro.com/projects/renode/litex-buildenv/" - ROOTFS=${ARCH}32-rootfs.cpio - ROOTFS_MD5="c3a88ff90fbd05dd6dc5773a8202d47f" - DTB_MD5="2dc79321d1c5d4de45fbcb866ce816b1" - CONFIG_MD5="fed2b661016e1b4aad16f17103839dba" + ROOTFS=riscv32-rootfs.cpio + DTB=rv32.dtb + ROOTFS_MD5="7b1a7fb52a1ba056dffb351a036bd0fb" + DTB_MD5="cd6d23543808988fd97447c4ff97392a" else echo "Linux is only supported on mor1kx or vexriscv at the moment." exit 1 fi -if [ ${CPU} = vexriscv ] && [ ${BUILD_BUILDROOT} = 1 ]; then - # do not download linux sources, buildroot comes with its own copy - : -else - # Get linux-litex is needed - LINUX_SRC="$TOP_DIR/third_party/linux" - LINUX_LOCAL="$LINUX_GITLOCAL" # Local place to clone from - LINUX_REMOTE_BIT=$(echo $LINUX_REMOTE | sed -e's-^.*://--' -e's/.git$//') - LINUX_CLONE_FROM="${LINUX_LOCAL:-$LINUX_REMOTE}" +# Get linux-litex is needed +LINUX_SRC="$TOP_DIR/third_party/linux" +LINUX_LOCAL="$LINUX_GITLOCAL" # Local place to clone from +LINUX_REMOTE_BIT=$(echo $LINUX_REMOTE | sed -e's-^.*://--' -e's/.git$//') +LINUX_CLONE_FROM="${LINUX_LOCAL:-$LINUX_REMOTE}" +( + # Download the Linux source for the first time + if [ ! -d "$LINUX_SRC" ]; then ( - # Download the Linux source for the first time - if [ ! -d "$LINUX_SRC" ]; then - ( - cd $(dirname $LINUX_SRC) - echo "Downloading Linux source tree." - echo "If you already have a local git checkout you can set 'LINUX_GITLOCAL' to speed up this step." - git clone $LINUX_CLONE_FROM $LINUX_SRC --branch $LINUX_BRANCH - ) - fi + cd $(dirname $LINUX_SRC) + echo "Downloading Linux source tree." + echo "If you already have a local git checkout you can set 'LINUX_GITLOCAL' to speed up this step." + git clone $LINUX_CLONE_FROM $LINUX_SRC --branch $LINUX_BRANCH + ) + fi - # Change into the dir - cd $LINUX_SRC + # Change into the dir + cd $LINUX_SRC - # Add the remote if it doesn't exist - CURRENT_LINUX_REMOTE_NAME=$(git remote -v | grep fetch | grep "$LINUX_REMOTE_BIT" | sed -e's/\t.*$//') - if [ x"$CURRENT_LINUX_REMOTE_NAME" = x ]; then - git remote add $LINUX_REMOTE_NAME $LINUX_REMOTE - CURRENT_LINUX_REMOTE_NAME=$LINUX_REMOTE_NAME - fi + # Add the remote if it doesn't exist + CURRENT_LINUX_REMOTE_NAME=$(git remote -v | grep fetch | grep "$LINUX_REMOTE_BIT" | sed -e's/\t.*$//') + if [ x"$CURRENT_LINUX_REMOTE_NAME" = x ]; then + git remote add $LINUX_REMOTE_NAME $LINUX_REMOTE + CURRENT_LINUX_REMOTE_NAME=$LINUX_REMOTE_NAME + fi - # Get any new data - git fetch $CURRENT_LINUX_REMOTE_NAME + # Get any new data + git fetch $CURRENT_LINUX_REMOTE_NAME - # Checkout or1k-linux branch it not already on it - if [ "$(git rev-parse --abbrev-ref HEAD)" != "$LINUX_BRANCH" ]; then - if git rev-parse --abbrev-ref $LINUX_BRANCH > /dev/null 2>&1; then - git checkout $LINUX_BRANCH - else - git checkout "$CURRENT_LINUX_REMOTE_NAME/$LINUX_BRANCH" -b $LINUX_BRANCH - fi + # Checkout or1k-linux branch it not already on it + if [ "$(git rev-parse --abbrev-ref HEAD)" != "$LINUX_BRANCH" ]; then + if git rev-parse --abbrev-ref $LINUX_BRANCH > /dev/null 2>&1; then + git checkout $LINUX_BRANCH + else + git checkout "$CURRENT_LINUX_REMOTE_NAME/$LINUX_BRANCH" -b $LINUX_BRANCH fi - ) -fi + fi +) # Get litex-devicetree LITEX_DT_SRC="$TOP_DIR/third_party/litex-devicetree" @@ -221,67 +213,27 @@ BD_REMOTE="${BD_REMOTE:-https://github.com/buildroot/buildroot.git}" BD_SRC="$TOP_DIR/third_party/buildroot" LLV_REMOTE="${LLV_REMOTE:-https://github.com/litex-hub/linux-on-litex-vexriscv.git}" LLV_SRC="$TOP_DIR/third_party/linux-on-litex-vexriscv" -if [ ${CPU} = vexriscv ] && [ ${BUILD_BUILDROOT:-0} = 1 ]; then - ( - if [ ! -d "$BD_SRC" ]; then - ( - cd $(dirname $BD_SRC) - echo "Downloading Buildroot code." - git clone $BD_REMOTE $BD_SRC - if [ x$BD_COMMIT != x ]; then - (cd $BD_SRC; git checkout $BD_COMMIT) - fi - ) - fi - - if [ ! -d "$LLV_SRC" ]; then - ( - cd $(dirname $LLV_SRC) - echo "Downloading Linux on LiteX-VexRiscv code." - git clone $LLV_REMOTE $LLV_SRC - if [ x$LLV_COMMIT != x ]; then - (cd $LLV_SRC; git checkout $LLV_COMMIT) - fi - ) - fi - - GENERATED_JSON="$TARGET_BUILD_DIR/test/csr.json" - if [ ! -f "$GENERATED_JSON" ]; then - make firmware - fi - - echo "Building Linux on LiteX-VexRiscv in $TARGET_LINUX_BUILD_DIR" - mkdir -p $TARGET_LINUX_BUILD_DIR - - $LLV_SRC/json2dts.py $GENERATED_JSON > $TARGET_LINUX_BUILD_DIR/rv32.dts - dtc -I dts -O dtb -o $TARGET_LINUX_BUILD_DIR/rv32.dtb $TARGET_LINUX_BUILD_DIR/rv32.dts - - cd $BD_SRC - make BR2_EXTERNAL=${BR2_EXTERNAL:-$LLV_SRC/buildroot} litex_vexriscv_defconfig - time make - ls -l $BD_SRC/output/images/ - ln -sf $BD_SRC/output/images/Image $TOP_DIR/$FIRMWARE_FILEBASE.bin - ln -sf $BD_SRC/output/images/rootfs.cpio $TARGET_LINUX_BUILD_DIR/$ROOTFS - ) -else - ( - cd $LINUX_SRC - echo "Building Linux in $TARGET_LINUX_BUILD_DIR" - mkdir -p $TARGET_LINUX_BUILD_DIR - - - fetch_file $ROOTFS_LOCATION/$ROOTFS $ROOTFS_MD5 $TARGET_LINUX_BUILD_DIR/$ROOTFS +( + cd $LINUX_SRC + echo "Building Linux in $TARGET_LINUX_BUILD_DIR" + mkdir -p $TARGET_LINUX_BUILD_DIR - if [ ${CPU} = mor1kx ]; then - KERNEL_BINARY=vmlinux.bin - make O="$TARGET_LINUX_BUILD_DIR" litex_defconfig - elif [ ${CPU} = vexriscv ]; then + fetch_file $RESOURCES_LOCATION/$ROOTFS_MD5-$ROOTFS $ROOTFS_MD5 $TARGET_LINUX_BUILD_DIR/$ROOTFS + fetch_file $RESOURCES_LOCATION/$DTB_MD5-$DTB $DTB_MD5 $TARGET_LINUX_BUILD_DIR/$DTB - fetch_file $ROOTFS_LOCATION/litex_vexriscv_linux.config $CONFIG_MD5 $TARGET_LINUX_BUILD_DIR/.config + if [ ${CPU} = mor1kx ]; then + KERNEL_BINARY=vmlinux.bin - fetch_file $ROOTFS_LOCATION/$DTB_MD5-rv32.dtb $DTB_MD5 $TARGET_LINUX_BUILD_DIR/rv32.dtb + cat << EOF > $TARGET_LINUX_BUILD_DIR/boot.json +{ + "mor1kx.dtb": "0x01000000", + "Image": "0x00000000" +} +EOF + elif [ ${CPU} = vexriscv ]; then + KERNEL_BINARY=Image - cat << EOF > $TARGET_LINUX_BUILD_DIR/boot.json + cat << EOF > $TARGET_LINUX_BUILD_DIR/boot.json { "Image": "0x40000000", "rootfs.cpio": "0x40800000", @@ -289,13 +241,15 @@ else "emulator.bin": "0x41100000" } EOF + fi - KERNEL_BINARY=Image - make O="$TARGET_LINUX_BUILD_DIR" olddefconfig - fi + make O="$TARGET_LINUX_BUILD_DIR" litex_defconfig + time make O="$TARGET_LINUX_BUILD_DIR" -j$JOBS - time make O="$TARGET_LINUX_BUILD_DIR" -j$JOBS - ls -l $TARGET_LINUX_BUILD_DIR/arch/${ARCH}/boot/${KERNEL_BINARY} - ln -sf $TARGET_LINUX_BUILD_DIR/arch/${ARCH}/boot/${KERNEL_BINARY} $TOP_DIR/$FIRMWARE_FILEBASE.bin - ) -fi + if [ ${CPU} = mor1kx ]; then + ${CROSS_COMPILE}objcopy -O binary $TARGET_LINUX_BUILD_DIR/vmlinux $TARGET_LINUX_BUILD_DIR/arch/${ARCH}/boot/${KERNEL_BINARY} + fi + + ls -l $TARGET_LINUX_BUILD_DIR/arch/${ARCH}/boot/${KERNEL_BINARY} + ln -sf $TARGET_LINUX_BUILD_DIR/arch/${ARCH}/boot/${KERNEL_BINARY} $TOP_DIR/$FIRMWARE_FILEBASE.bin +) From 5bd869ea00f6f4e07a220a69d7a2ed90b51efcb3 Mon Sep 17 00:00:00 2001 From: Mateusz Holenko Date: Fri, 10 Jul 2020 15:48:02 +0200 Subject: [PATCH 2/3] tests: Adapt linux test This changes the expected boot messages adapting to the new linux version. --- tests/renode/Firmware-linux.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/renode/Firmware-linux.robot b/tests/renode/Firmware-linux.robot index 92f462977..22901f4b9 100644 --- a/tests/renode/Firmware-linux.robot +++ b/tests/renode/Firmware-linux.robot @@ -21,7 +21,7 @@ Boot Wait For Prompt On Uart buildroot login: Write Line To Uart root - Wait For Line On Uart login[48]: root login on 'hvc0' + Wait For Line On Uart root login on 'console' Wait For Prompt On Uart \# Write Line To Uart ls / From 9cb525b0d3931ff6478e06873b94dc54d3b74e0b Mon Sep 17 00:00:00 2001 From: Mateusz Holenko Date: Mon, 13 Jul 2020 10:58:28 +0200 Subject: [PATCH 3/3] Temporarily switch to a built-in DTB file on mor1kx To be reverted after the support for an external DTB file is brought back to LiteX. --- Makefile | 4 ++-- scripts/build-linux.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 824f562c2..bd9c7c072 100755 --- a/Makefile +++ b/Makefile @@ -406,14 +406,14 @@ tftp: $(FIRMWARE_FILEBASE).bin ifeq ($(FIRMWARE),linux) cp $(FIRMWARE_FILEBASE).bin $(TFTPD_DIR)/Image - cp $(FIRMWARE_DIR)/$(ROOTFS_FILE) $(TFTPD_DIR)/rootfs.cpio cp $(FIRMWARE_DIR)/boot.json $(TFTPD_DIR) ifeq ($(CPU),vexriscv) cp $(FIRMWARE_DIR)/rv32.dtb $(TFTPD_DIR) cp $(TARGET_BUILD_DIR)/emulator/emulator.bin $(TFTPD_DIR) + cp $(FIRMWARE_DIR)/$(ROOTFS_FILE) $(TFTPD_DIR)/rootfs.cpio endif ifeq ($(CPU),mor1kx) - cp $(FIRMWARE_DIR)/mor1kx.dtb $(TFTPD_DIR) + # ATM nothing, DTB in the future endif else cp $(FIRMWARE_FILEBASE).bin $(TFTPD_DIR)/boot.bin diff --git a/scripts/build-linux.sh b/scripts/build-linux.sh index b397fa472..7cd173e66 100755 --- a/scripts/build-linux.sh +++ b/scripts/build-linux.sh @@ -64,6 +64,7 @@ if [ ${CPU} = mor1kx ]; then DTB=mor1kx.dtb ROOTFS_MD5="c9ef89b45b0d2c34d14978a21f2863bd" DTB_MD5="0271bc8f63f2d928dc9536ac31a2c6b9" + LINUX_BRANCH=${LINUX_BRANCH:-litex_buildenv-mor1kx} elif [ ${CPU} = vexriscv ]; then export ARCH=riscv ROOTFS=riscv32-rootfs.cpio @@ -226,7 +227,6 @@ LLV_SRC="$TOP_DIR/third_party/linux-on-litex-vexriscv" cat << EOF > $TARGET_LINUX_BUILD_DIR/boot.json { - "mor1kx.dtb": "0x01000000", "Image": "0x00000000" } EOF