Commit 1871ad51 authored by Jens Korinth's avatar Jens Korinth
Browse files

Implement SD card generator for PyNQ, ZC706

* extended the zedboard version
* fixed devicetrees, now working out-of-the-box
* automated extraction of root FS
* patching root FS for network stuff, removing Jupyter, but keeping the
  autoresizing, which is pretty neat
* PyNQ is non-trivial to rebuild; decided to extract directly from the
  image
* PyNQ image is downloaded from public URL at Digilent (minimal
  footprint in git)
* not enough space to put linux-xlnx on board; maybe increase image
  size? or provide script to automate the process
parent 3053b5f9
......@@ -3,17 +3,27 @@ BOARD=${1:-zedboard}
VERSION=${2:-2016.4}
SDCARD=${3:-}
DIR="$BOARD/$VERSION"
LOGDIR="$DIR/logs"
CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
BUILD_LINUX_LOG="$PWD/build-linux.log"
BUILD_UBOOT_LOG="$PWD/build-uboot.log"
BUILD_SSBL_LOG="$PWD/build-ssbl.log"
BUILD_UIMAGE_LOG="$PWD/build-uimage.log"
BUILD_FSBL_LOG="$PWD/build-fsbl.log"
BUILD_BOOTBIN_LOG="$PWD/build-bootbin.log"
PREPARE_SD_LOG="$PWD/prepare-sd.log"
ROOTFS_IMG="$PWD/rootfs.img"
### LOGFILES ###################################################################
BUILD_LINUX_LOG="$PWD/$LOGDIR/build-linux.log"
BUILD_UBOOT_LOG="$PWD/$LOGDIR/build-uboot.log"
BUILD_SSBL_LOG="$PWD/$LOGDIR/build-ssbl.log"
BUILD_UIMAGE_LOG="$PWD/$LOGDIR/build-uimage.log"
BUILD_FSBL_LOG="$PWD/$LOGDIR/build-fsbl.log"
BUILD_BOOTBIN_LOG="$PWD/$LOGDIR/build-bootbin.log"
BUILD_DEVICETREE_LOG="$PWD/$LOGDIR/build-devicetree.log"
PREPARE_SD_LOG="$PWD/$LOGDIR/prepare-sd.log"
EXTRACT_BL_LOG="$PWD/extract-bl.log"
EXTRACT_RFS_LOG="$PWD/extract-rfs.log"
PYNQ_VERSION="pynq_z1_image_2017_02_10"
PYNQ_IMAGE="$PWD/pynq/$PYNQ_VERSION.zip"
PYNQ_IMAGE_URL="https://s3-us-west-2.amazonaws.com/digilent/Products/PYNQ/$PYNQ_VERSION.zip"
# fetch status
FETCH_UBOOT_OK=1
FETCH_LINUX_OK=1
FETCH_PYNQ_IMAGE_OK=1
# build status
BUILD_UBOOT_OK=1
BUILD_LINUX_OK=1
......@@ -108,6 +118,46 @@ get_u-boot () {
fi
}
get_pynq_image () {
if [[ ! -f $PYNQ_IMAGE ]]; then
# echo "Fetching PyNQ standard image ..."
mkdir -p `dirname $PYNQ_IMAGE` 2> /dev/null &&
curl -s $PYNQ_IMAGE_URL -o $PYNQ_IMAGE
fi
}
extract_pynq_bl () {
if [[ ! -f $PWD/pynq/BOOT.BIN ]]; then
pushd $PWD/pynq > $EXTRACT_BL_LOG 2>&1 &&
IMG=${PYNQ_VERSION}.img
if [[ -f $IMG ]]; then
echo "Unzipping $PYNQ_IMAGE to extract $IMG ..." >> $EXTRACT_BL_LOG 2>&1 &&
unzip -u $PYNQ_IMAGE >> $EXTRACT_BL_LOG 2>&1
fi &&
mkdir -p img >> $EXTRACT_BL_LOG 2>&1 &&
sudo mount -oloop,offset=1M $IMG img >> $EXTRACT_BL_LOG 2>&1 &&
sudo cp img/BOOT.BIN $VERSION/BOOT.BIN >> $EXTRACT_BL_LOG 2>&1 &&
sudo chown $USER $VERSION/BOOT.BIN >> $EXTRACT_BL_LOG 2>&1 &&
sudo cp img/devicetree.dtb $VERSION/devicetree.dtb >> $EXTRACT_BL_LOG 2>&1 &&
sudo chown $USER $VERSION/devicetree.dtb >> $EXTRACT_BL_LOG 2>&1 &&
sudo cp img/uEnv.txt ../uenv/uEnv-pynq.txt >> $EXTRACT_BL_LOG 2>&1 &&
sudo chown $USER ../uenv/uEnv-pynq.txt >> $EXTRACT_BL_LOG 2>&1 &&
sudo umount img >> $EXTRACT_BL_LOG 2>&1 &&
rmdir img >> $EXTRACT_BL_LOG 2>&1 &&
echo "BOOT.BIN and devicetree.dtb are ready in $DIR." >> $EXTRACT_BL_LOG 2>&1
fi
}
extract_pynq_rootfs () {
if [[ ! -f $ROOTFS_IMG ]]; then
IMG=$PWD/pynq/${PYNQ_VERSION}.img
START=$(fdisk -l $IMG | awk 'END { print $2 }')
COUNT=$(fdisk -l $IMG | awk 'END { print $4 }')
echo "Extracting root image from $IMG, start=$START and count = $COUNT" > $EXTRACT_RFS_LOG 2>&1 &&
dd if=$IMG of=$ROOTFS_IMG skip=$START count=$COUNT >> $EXTRACT_RFS_LOG 2>&1
fi
}
build_u-boot () {
if [[ ! -e $DIR/u-boot-xlnx/tools/mkimage ]]; then
# echo "Building u-boot $VERSION ..."
......@@ -116,11 +166,10 @@ build_u-boot () {
DEFCONFIG=zynq_zed_defconfig
;;
"zc706")
DEFCONFIG=zynq_zed_defconfig
DEFCONFIG=zynq_zc706_defconfig
;;
"pynq")
echo "Cannot build U-Boot for PyNQ yet."
exit 1
DEFCONFIG=zynq_zed_defconfig
;;
esac
make -C $DIR/u-boot-xlnx CROSS_COMPILE=$CROSS_COMPILE ARCH=arm $DEFCONFIG > /dev/null 2>&1 &&
......@@ -209,6 +258,9 @@ set_property -dict [list \
CONFIG.PCW_IRQ_F2P_INTR {1} \
CONFIG.PCW_TTC0_PERIPHERAL_ENABLE {0} \
CONFIG.PCW_EN_CLK1_PORT {1} ] \$ps
if {[tapasco::get_speed_grad] < -1} {
set_property -dict [list CONFIG.PCW_APU_PERIPHERAL_FREQMHZ {800}] \$ps
}
set clk [lindex [get_bd_pins -of_objects \$ps -filter { TYPE == clk && DIR == O }] 0]
connect_bd_net \$clk [get_bd_pins -of_objects \$ps -filter { TYPE == clk && DIR == I}]
validate_bd_design
......@@ -244,55 +296,97 @@ EOF
popd > /dev/null
}
build_devtree () {
# "Building devicetree ..."
case $BOARD in
"zedboard")
cp $DIR/linux-xlnx/arch/arm/boot/dts/zynq-7000.dtsi $DIR/ > $BUILD_DEVICETREE_LOG 2>&1
cp $DIR/linux-xlnx/arch/arm/boot/dts/skeleton.dtsi $DIR/ > $BUILD_DEVICETREE_LOG 2>&1
cat $DIR/linux-xlnx/arch/arm/boot/dts/zynq-zed.dts | sed 's/#include/\/include\//' > $DIR/devicetree.dts
;;
"zc706")
cp $DIR/linux-xlnx/arch/arm/boot/dts/zynq-7000.dtsi $DIR/ > $BUILD_DEVICETREE_LOG 2>&1
cp $DIR/linux-xlnx/arch/arm/boot/dts/skeleton.dtsi $DIR/ > $BUILD_DEVICETREE_LOG 2>&1
cat $DIR/linux-xlnx/arch/arm/boot/dts/zynq-zed.dts | sed 's/#include/\/include\//' > $DIR/devicetree.dts
;;
esac
pushd $DIR > /dev/null &&
linux-xlnx/scripts/dtc/dtc -I dts -O dtb -o devicetree.dtb devicetree.dts > $BUILD_DEVICETREE_LOG 2>&1 &&
popd > /dev/null
}
prepare_sd () {
sudo dd if=/dev/zero of=$SDCARD bs=1024 count=1 > $PREPARE_SD_LOG 2>&1 &&
echo "Erasing first 4GiB of SDcard $SDCARD ..." > $PREPARE_SD_LOG &&
#sudo dd if=/dev/zero of=$SDCARD bs=1M count=4096 >> $PREPARE_SD_LOG 2>&1 &&
sudo dd if=/dev/zero of=$SDCARD bs=1024 count=1 >> $PREPARE_SD_LOG 2>&1 &&
echo "Repartitioning SDcard $SDCARD ..." >> $PREPARE_SD_LOG &&
sudo sfdisk ${SDCARD} >> $PREPARE_SD_LOG 2>&1 << EOF
2048 204800 c, *
206848 7655424 83 -
EOF
sudo mkfs.vfat -F 32 -n BOOT ${SDCARD}1 >> $PREPARE_SD_LOG 2>&1
sudo mkfs.ext4 -qF -L root ${SDCARD}2 >> $PREPARE_SD_LOG 2>&1
mkdir -p `basename ${SDCARD}1` 2> /dev/null
sudo mount ${SDCARD}1 `basename ${SDCARD}1` >> $PREPARE_SD_LOG 2>&1 &&
sudo mkfs.ext4 -F -L root ${SDCARD}2 >> $PREPARE_SD_LOG 2>&1
copy_files_to_boot &&
sudo umount `basename ${SDCARD}1` >> $PREPARE_SD_LOG 2>&1 &&
rmdir `basename ${SDCARD}1` 2> /dev/null &&
echo "dd'ing rootfs onto second partition, this will take a while ..." >> $PREPARE_SD_LOG &&
tar xJf pynq.rootfs.img.tar.xz | sudo dd of=${SDCARD}2 bs=10M >> $PREPARE_SD_LOG 2>&1
copy_files_to_root
}
copy_files_to_boot () {
TO=`basename ${SDCARD}1`/
echo "Copying $DIR/BOOT.BIN to $TO ..." >> $PREPARE_SD_LOG 2>&1
sudo cp $DIR/BOOT.BIN $TO >> $PREPARE_SD_LOG 2>&1
echo "Coping $DIR/linux-xlnx/arch/arm/boot/uImage to $TO ..." >> $PREPARE_SD_LOG 2>&1
sudo cp $DIR/linux-xlnx/arch/arm/boot/uImage $TO >> $PREPARE_SD_LOG 2>&1
case $BOARD in
"zedboard")
echo "Copying $DIR/linux-xlnx/arch/arm/boot/dts/zynq-zed.dtb to ${TO}devicetree.dtb ..." >> $PREPARE_SD_LOG 2>&1
sudo cp $DIR/u-boot-xlnx/arch/arm/dts/zynq-zed.dtb ${TO}devicetree.dtb >> $PREPARE_SD_LOG 2>&1
;;
"zc706")
echo "Copying $DIR/linux-xlnx/arch/arm/boot/dts/zynq-zc706.dtb ${TO}devicetree.dtb ..." >> $PREPARE_SD_LOG 2>&1
sudo cp $DIR/u-boot-xlnx/arch/arm/dts/zynq-zc706.dtb ${TO}devicetree.dtb >> $PREPARE_SD_LOG 2>&1
;;
*)
;;
esac
TO=`basename ${SDCARD}1`
echo "Preparing BOOT partition ..." >> $PREPARE_SD_LOG &&
mkdir -p $TO >> $PREPARE_SD_LOG 2>&1 &&
sudo mount ${SDCARD}1 $TO >> $PREPARE_SD_LOG 2>&1 &&
echo "Copying $DIR/BOOT.BIN to $TO ..." >> $PREPARE_SD_LOG 2>&1 &&
sudo cp $DIR/BOOT.BIN $TO >> $PREPARE_SD_LOG 2>&1 &&
echo "Copying $DIR/linux-xlnx/arch/arm/boot/uImage to $TO ..." >> $PREPARE_SD_LOG 2>&1 &&
sudo cp $DIR/linux-xlnx/arch/arm/boot/uImage $TO >> $PREPARE_SD_LOG 2>&1 &&
echo "Copying $DIR/devicetree.dtb to $TO ..." >> $PREPARE_SD_LOG 2>&1 &&
sudo cp $DIR/devicetree.dtb $TO >> $PREPARE_SD_LOG 2>&1 &&
echo "Copying uenv/uEnv-$BOARD.txt to $TO/uEnv.txt ..." >> $PREPARE_SD_LOG 2>&1 &&
sudo cp uenv/uEnv-$BOARD.txt $TO/uEnv.txt >> $PREPARE_SD_LOG 2>&1
sudo umount $TO >> $PREPARE_SD_LOG 2>&1 &&
rmdir $TO 2> /dev/null &&
echo "Boot partition ready." >> $PREPARE_SD_LOG
}
copy_files_to_root () {
TO=`basename ${SDCARD}2`
echo "dd'ing rootfs onto second partition, this will take a while ..." >> $PREPARE_SD_LOG &&
sudo dd if=$ROOTFS_IMG of=${SDCARD}2 bs=10M >> $PREPARE_SD_LOG 2>&1
mkdir -p $TO 2> /dev/null
sudo mount ${SDCARD}2 $TO >> $PREPARE_SD_LOG 2>&1 >> $PREPARE_SD_LOG 2>&1 &&
echo "Setting hostname to $BOARD ... " >> $PREPARE_SD_LOG &&
sudo sh -c "echo $BOARD > $TO/etc/hostname" >> $PREPARE_SD_LOG 2>&1 &&
#echo "Copying Linux to /linux-xlnx ... " >> $PREPARE_SD_LOG &&
#sudo sh -c "cp -r $DIR/linux-xlnx $TO/" >> $PREPARE_SD_LOG 2>&1 &&
echo "Replacing rc.local ... " >> $PREPARE_SD_LOG &&
sudo sh -c "cp $PWD/misc/rc.local $TO/etc/rc.local" >> $PREPARE_SD_LOG 2>&1 &&
sudo umount $TO >> $PREPARE_SD_LOG 2>&1 &&
rmdir $TO 2> /dev/null &&
echo "RootFS partition ready." >> $PREPARE_SD_LOG
}
################################################################################
################################################################################
echo "Cross compiler ABI is set to $CROSS_COMPILE."
echo "Board is $BOARD."
echo "Version is $VERSION."
echo "SD card device is $SDCARD."
mkdir -p $LOGDIR 2> /dev/null
check_board
check_compiler
check_hsi
check_vivado
check_sdcard
echo "And so it begins ..."
################################################################################
if [[ $BOARD != "pynq" ]]; then
echo "Fetching Linux kernel and U-Boot sources ..."
else
echo "Fetching Linux kernel, U-Boot sources and PyNQ default image ..."
fi
FETCH_LINUX_OK=$(get_linux; echo $? &)
FETCH_UBOOT_OK=$(get_u-boot; echo $? &)
FETCH_PYNQ_OK=$(if [[ $BOARD == "pynq" ]]; then get_pynq_image; fi; echo $? &)
wait
if [[ $FETCH_LINUX_OK -ne 0 ]]; then
echo "Fetching Linux failed, check logs.."
......@@ -302,11 +396,15 @@ if [[ $FETCH_UBOOT_OK -ne 0 ]]; then
echo "Fetching U-Boot failed, check logs."
exit 1
fi
if [[ $FETCH_PYNQ_OK -ne 0 ]]; then
echo "Fetching PyNQ failed, check logs."
exit 1
fi
################################################################################
echo "Ok, got the sources, will build now ..."
echo "Building Linux kernel and U-Boot tools ..."
BUILD_UBOOT_OK=$(build_u-boot; echo $? &)
echo "Building Linux kernel (output in $BUILD_LINUX_LOG) and U-Boot tools (output in $BUILD_UBOOT_LOG)..."
BUILD_LINUX_OK=$(build_linux; echo $? &)
BUILD_UBOOT_OK=$(build_u-boot; echo $? &)
wait
if [[ $BUILD_LINUX_OK -ne 0 ]]; then
echo "Building Linux failed, check log: $BUILD_LINUX_LOG"
......@@ -316,36 +414,68 @@ if [[ $BUILD_UBOOT_OK -ne 0 ]]; then
echo "Building U-Boot failed, check log: $BUILD_UBOOT_LOG"
exit 1
fi
echo "Building U-Boot SSBL and uImage ..."
BUILD_SSBL_OK=$(build_ssbl; echo $? &)
################################################################################
if [[ $BOARD != "pynq" ]]; then
echo "Building U-Boot SSBL (output in $BUILD_SSBL_LOG) and uImage (output in $BUILD_UIMAGE_LOG) ..."
else
echo "Building uImage (output in $BUILD_UIMAGE_LOG) ..."
fi
BUILD_UIMAGE_OK=$(build_uimage; echo $? &)
BUILD_SSBL_OK=$(if [[ $BOARD != "pynq" ]]; then build_ssbl; fi; echo $? &)
wait
if [[ $BUILD_SSBL_OK -ne 0 ]]; then
"Echo building U-Boot SSBL failed, check log: $BUILD_SSBL_LOG"
exit 1
fi
if [[ $BUILD_UIMAGE_OK -ne 0 ]]; then
"Echo building uImage failed, check log: $BUILD_UIMAGE_LOG"
"Building uImage failed, check log: $BUILD_UIMAGE_LOG"
exit 1
fi
echo "Build FSBL ..."
BUILD_FSBL_OK=$(build_fsbl; echo $? &)
wait
if [[ $BUILD_FSBL_OK -ne 0 ]]; then
"Echo building FSBL failed, check log: $BUILD_FSBL_LOG"
if [[ $BUILD_SSBL_OK -ne 0 ]]; then
"Building U-Boot SSBL failed, check log: $BUILD_SSBL_LOG"
exit 1
fi
echo "Generating BOOT.BIN ..."
BUILD_BOOTBIN_OK=$(build_bootbin; echo $? &)
################################################################################
if [[ $BOARD != "pynq" ]]; then
echo "Build FSBL (output in $BUILD_FSBL_LOG) ..."
BUILD_FSBL_OK=$(build_fsbl; echo $? &)
wait
if [[ $BUILD_FSBL_OK -ne 0 ]]; then
"Building FSBL failed, check log: $BUILD_FSBL_LOG"
exit 1
fi
echo "Building devicetree (output in $BUILD_DEVICETREE_LOG) and generating BOOT.BIN (output in $BUILD_BOOTBIN_LOG) ..."
BUILD_BOOTBIN_OK=$(build_bootbin; echo $? &)
BUILD_DEVICETREE_OK=$(build_devtree; echo $? &)
wait
if [[ $BUILD_BOOTBIN_OK -ne 0 ]]; then
echo "Building BOOT.BIN failed, check log: $BUILD_BOOTBIN_LOG"
exit 1
fi
echo "Done - find BOOT.BIN is here: $DIR/BOOT.BIN."
if [[ $BUILD_DEVICETREE_OK -ne 0 ]]; then
echo "Building devicetree failed, check log: $BUILD_DEVICETREE_LOG"
exit 1
fi
else
echo "Extract FSBL and devicetree from $PYNQ_IMAGE (output in $EXTRACT_BL_LOG) ..."
EXTRACT_PYNQ_OK=$(extract_pynq_bl; echo $? &)
wait
if [[ ! -f $DIR/BOOT.BIN ]]; then
echo "Extracting FSBL failed, check log: $EXTRACT_BL_LOG"
exit 1
fi
if [[ ! -f $DIR/devicetree.dtb ]]; then
echo "Extracting devicetree.dtb failed, check log: $EXTRACT_BL_LOG"
exit 1
fi
fi
################################################################################
echo "Extracting root FS (output in $EXTRACT_RFS_LOG) ..."
EXTRACT_RFS_OK=$(extract_pynq_rootfs; echo $? &)
wait
if [[ $BUILD_BOOTBIN_OK -ne 0 ]]; then
echo "Echo building BOOT.BIN failed, check log: $BUILD_BOOTBIN_LOG"
exit 1
if [[ $EXTRACT_RFS_OK -ne 0 ]]; then
echo "Extracting root FS failed, check log: $EXTRACT_RFS_LOG"
fi
echo "Done - find BOOT.BIN is here: $DIR/BOOT.BIN."
################################################################################
if [[ -n $SDCARD ]]; then
echo "Preparing $SDCARD, this may take a while ..."
echo "Preparing $SDCARD, this may take a while (output in $PREPARE_SD_LOG) ..."
PREPARE_SD_OK=$(prepare_sd; echo $? &)
if [[ $PREPARE_SD_OK -ne 0 ]]; then
echo "Preparing SD card failed, check log: $PREPARE_SD_LOG"
......
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Adding Jupyter scripts to bring up network and start Jupyter server
/root/0_resizefs.sh
#/root/1_network.sh >/dev/null 2>&1 &
#/root/2_jupyter_server.sh
#/root/3_pl_server.sh
#/root/4_boot_leds.sh
dhclient eth0
ifconfig eth0:0 down
# Force ntp update
systemctl stop ntp
ntpdate 0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org\
2.ubuntu.pool.ntp.org 3.ubuntu.pool.ntp.org
systemctl start ntp
exit 0
bootargs=console=ttyPS0,115200 root=/dev/mmcblk0p2 rootwait rw earlyprintk
ethaddr=00:0a:35:00:01:20
kernel_load_address=0x3000000
kernel_image=uImage
devicetree_load_address=0x2A00000
devicetree_image=devicetree.dtb
sdboot=if mmcinfo; then load mmc 0 ${kernel_load_address} ${kernel_image} && load mmc 0 ${devicetree_load_address} ${devicetree_image} && bootm ${kernel_load_address} - ${devicetree_load_address}; fi
bootargs=console=ttyPS0,115200 root=/dev/mmcblk0p2 rootwait rw earlyprintk
ethaddr=00:0a:35:00:01:21
kernel_load_address=0x3000000
kernel_image=uImage
devicetree_load_address=0x2A00000
devicetree_image=devicetree.dtb
sdboot=if mmcinfo; then load mmc 0 ${kernel_load_address} ${kernel_image} && load mmc 0 ${devicetree_load_address} ${devicetree_image} && bootm ${kernel_load_address} - ${devicetree_load_address}; fi
autoload=y
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment