Skip to content

Commit

Permalink
linux: unify linux source
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mateusz-holenko committed Jun 2, 2020
1 parent bbe7798 commit 9e8611d
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 119 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ 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
Expand Down
15 changes: 15 additions & 0 deletions configs/linux-rootfs/README
Original file line number Diff line number Diff line change
@@ -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
# or cp ../buildroot_vexriscv.config
make olddefconfig
make

(3) the resulting image is in output/images
31 changes: 31 additions & 0 deletions configs/linux-rootfs/buildroot_mor1kx.config
Original file line number Diff line number Diff line change
@@ -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

41 changes: 41 additions & 0 deletions configs/linux-rootfs/buildroot_vexriscv.config
Original file line number Diff line number Diff line change
@@ -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

20 changes: 20 additions & 0 deletions configs/linux-rootfs/rootfs_overlay/etc/profile
Original file line number Diff line number Diff line change
@@ -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
182 changes: 63 additions & 119 deletions scripts/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=openrisc-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"
Expand Down Expand Up @@ -228,72 +220,24 @@ 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

if [ ${CPU} = mor1kx ]; then
KERNEL_BINARY=vmlinux.bin
make O="$TARGET_LINUX_BUILD_DIR" litex_defconfig
elif [ ${CPU} = vexriscv ]; then
(
cd $LINUX_SRC
echo "Building Linux in $TARGET_LINUX_BUILD_DIR"
mkdir -p $TARGET_LINUX_BUILD_DIR

fetch_file $ROOTFS_LOCATION/litex_vexriscv_linux.config $CONFIG_MD5 $TARGET_LINUX_BUILD_DIR/.config
fetch_file $RESOURCES_LOCATION/$ROOTFS_MD5-$ROOTFS $ROOTFS_MD5 $TARGET_LINUX_BUILD_DIR/${CPU_ARCH}-rootfs.cpio
fetch_file $RESOURCES_LOCATION/$DTB_MD5-$DTB $DTB_MD5 $TARGET_LINUX_BUILD_DIR/$DTB

fetch_file $ROOTFS_LOCATION/$DTB_MD5-rv32.dtb $DTB_MD5 $TARGET_LINUX_BUILD_DIR/rv32.dtb
make O="$TARGET_LINUX_BUILD_DIR" litex_defconfig
time make O="$TARGET_LINUX_BUILD_DIR" -j$JOBS

KERNEL_BINARY=Image
make O="$TARGET_LINUX_BUILD_DIR" olddefconfig
fi
if [ ${CPU} = mor1kx ]; then
KERNEL_BINARY=vmlinux.bin
${CROSS_COMPILE}objcopy -O binary $TARGET_LINUX_BUILD_DIR/vmlinux $TARGET_LINUX_BUILD_DIR/arch/${ARCH}/boot/${KERNEL_BINARY}
elif [ ${CPU} = vexriscv ]; then
KERNEL_BINARY=Image
fi

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
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
)

0 comments on commit 9e8611d

Please sign in to comment.