Commit ce3a69e2 authored by Guido Gunther's avatar Guido Gunther

Merge branch 'master' into 'master'

Merge in NXP mfgtools (uuu) and test scripts

See merge request Librem5/librem5-devkit-tools!1
parents a32ab19f ab009d9e
......@@ -66,7 +66,7 @@ you can e.g. create via Debian's deboostrap.
For that to work the *BOOT MODE* switch needs to be set to *eMMC* (instead of *USB*).
* Installing a minimal Linux the eMMC
You can dd a prebuil image on there or you can just debootstrap from
You can dd a prebuilt image on there or you can just debootstrap from
scratch, this can be useful if you don't want that many services
starting up by default:
......@@ -83,7 +83,144 @@ pulling kernel and device tree via tftp though:
setenv emmcboot "setenv bootargs ${args_common} debug root=/dev/mmcblk0p2; dhcp ${loadaddr} Image-librem5-devkit; dhcp ${fdt_addr} librem5-devkit.dtb; booti ${loadaddr} - ${fdt_addr}"
#+END_SRC
* TODO Flash uboot
* Install uuu
** By hand
The NXP mfgtool uuu is required to boot a board that has no bootloader or is otherwise "bricked". Either download, build and install uuu :
#+BEGIN_SRC
git clone https://github.com/NXPmicro/mfgtools
cd mfgtools
cmake ./
make
sudo make install
#+END_SRC
** Using the handy script
#+BEGIN_SRC
scripts/build_uuu.sh -i
#+END_SRC
* Download Target Binaries
You can manually download or build the required binaries. There is also a convenience script to download prebuilt binaries from the Purism servers.
#+BEGIN_SRC
scripts/fetch_latest.sh -xk
#+END_SRC
* Flash uboot
** Using SDP
The uboot that gets flashed is files/u-boot-devkit-recovery.imx . Put the "Boot Mode" switch in the USB position.
#+BEGIN_SRC
sudo uuu uuu_scripts/u-boot_flash_librem5-devkit.lst
#+END_SRC
You can also just boot to u-boot without flashing anything
#+BEGIN_SRC
sudo uuu uuu_scripts/u-boot_librem5-devkit.lst
#+END_SRC
** From u-boot using tftp
You must have a tftp server setup for this
#+BEGIN_SRC
setenv ipaddr <tftp server ip>
setenv serverip <target ip addr>
tftp 0x43000000 u-boot-devkit-recovery.imx
mmc write 0x43000000 0x42 0x800
#+END_SRC
** From the kernel command line
Download the u-boot binary u-boot-devkit-recovery.imx
#+BEGIN_SRC
dd if=u-boot-devkit-recovery.imx of=/dev/mmcblk0 bs=1024 seek=33
#+END_SRC
* Flash eMMC
** Using SDP
The eMMC that gets flashed is files/devkit.img . Put the "Boot Mode" switch in the USB position.
THIS WILL ERASE EVERYTHING ON YOUR eMMC.
#+BEGIN_SRC
sudo uuu uuu_scripts/flash_librem5-devkit.lst
#+END_SRC
* Create test initramfs
** Download the latest image and kernel
Download the latest kernel and RS9116 out of tree modules.
#+BEGIN_SRC
./scripts/fetch_latest.sh -k
#+END_SRC
** Extract the kernel
The kernel needs to be extracted from the deb for the SDP boot.
#+BEGIN_SRC
./scripts/extract_kernel.sh
#+END_SRC
** Build the test filesystem tarball
This will create a minimal debian rootfs tarball to be used to create an initramfs. If you need additional packages you can add them to the packages variable in the script.
#+BEGIN_SRC
./scripts/create_tarball.sh
#+END_SRC
** Create the initramfs
This will take the tarball created above and customize it to be able to flash the RS9116 module and also adds some test scripts.
#+BEGIN_SRC
./scripts/create_initramfs.sh -t build/test_rootfs.tgz -o files/test_initramfs.img
#+END_SRC
You can include a locally generated kernel, modules and devicetree as well
#+BEGIN_SRC
./scripts/create_initramfs.sh -t build/test_rootfs.tgz -o files/test_initramfs.img -i <path to kernel>
#+END_SRC
** Boot the initramfs
The initramfs can be booted on a board with an empty eMMC for testing and RS9116 flashing. Ensure the boot mode switch is switched to USB boot. Run the command below and then plug in the USB C port of the devkit.
#+BEGIN_SRC
sudo uuu uuu_scripts/test_librem5.lst
#+END_SRC
** Reflash the RS9116
By default no rsi_* modules get loaded. The modules without firmware are in "/lib/modules/<kernel_ver>/drivers/net/wireless/rsi" . The create_initramfs script above adds the rsi firmware and reflash modules in "/usr/src".
There is a convenience script "flash_rsi.sh" that wiil perform the necessary steps. What the script does is it backs up the rsi modules in /lib/modules, copies the firmware into lib firmware and the modprobes the rsi flashing modules. It replaces the original modules when it's done.
Run the script on the target to reflash.
#+BEGIN_SRC
root@pureos-test:~# flash_rsi.sh
#+END_SRC
** RS9116 normal operation
To use the RS9116 without flashing just load the modules by hand.
#+BEGIN_SRC
root@pureos-test:~# modprobe rsi_sdio
#+END_SRC
* Hardware Components
** LCD Panel
......
#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#
# prerequisites 'libusb-1.0-0-dev libzip-dev'
usage() {
echo "Usage : $1 "
echo " -i install uuu as well"
}
cwd=$(pwd)
install_uuu=0
while getopts "hi" opt; do
case ${opt} in
i)
install_uuu=1
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
usage "$0"
exit 0
;;
h )
usage "$0"
exit 0
;;
esac
done
CWD=`pwd`
mkdir -p build
cd build
git clone https://source.puri.sm/Librem5/mfgtools
cd mfgtools
cmake ./
make
if [ "${install_uuu}" == 1 ]; then
sudo make install
fi
#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#
set -e
usage() {
echo "Usage : $0 -t <rootfs tarball> -o <initramfs>"
echo " -i <path> install local kernel from path"
}
build_initrd=0
customize=1
tar_file=
initramfs=
while getopts "t:o:i:" opt; do
case ${opt} in
t)
tar_file=$OPTARG
;;
o)
initramfs=$OPTARG
;;
i)
kernel_path=$OPTARG
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
usage "$0"
exit 0
;;
h )
usage "$0"
exit 0
;;
esac
done
if [ -z "${tar_file}" ] || [ -z "${initramfs}" ]; then
usage
exit 1
fi
[ ! -e build ] && mkdir -p build
DIR=`mktemp -d`
BASE=`basename ${initramfs}`
cwd=`pwd`
echo "Creating initramfs ${initramfs} from ${tar_file} in ${DIR}"
fakeroot tar -xf ${tar_file} -C ${DIR}
if [ ! -z "${kernel_path}" ]; then
cp ${kernel_path}/arch/arm64/boot/Image files/
cp ${kernel_path}/arch/arm64/boot/dts/freescale/librem5-evk.dtb files/
fakeroot rm -rf ${DIR}/lib/modules/*
cd ${kernel_path} && make modules_install INSTALL_MOD_PATH=${DIR}
find ${DIR}/lib/modules -name "*.ko" -exec aarch64-linux-gnu-strip --strip-debug \{\} \;
cd ${cwd}
fi
if [ "${customize}" == 1 ]; then
fakeroot scripts/root.sh ${DIR}
fi
cd ${DIR}
if [ "${build_initrd}" == 1 ]; then
find . -print0 | cpio --null -o --format=newc | gzip -9 > ${cwd}/build/${BASE}.image
else
fakeroot genext2fs -d . -N 24000 -b 300000 ${cwd}/build/${BASE}.image
fi
#gzip ${cwd}/build/${BASE}.image
mkimage -n 'Test Ramdisk' -A arm64 -O linux -T ramdisk -C gzip -d ${cwd}/build/${BASE}.image ${cwd}/${initramfs}
cd ${cwd}
rm -fr ${DIR}
#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#
packages="whiptail iperf3 wireless-tools"
usage() {
echo "Usage : $1 "
echo " -d <kernel_deb> use this deb"
}
cwd=$(pwd)
build_prep=0
arch=arm64
while getopts "hd:b" opt; do
case ${opt} in
d)
kernel_deb=$OPTARG
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
usage "$0"
exit 0
;;
h )
usage "$0"
exit 0
;;
esac
done
if [ -z ${kernel_deb} ]; then
kernel_deb=`ls -t files/linux-image-* | grep -v dbg | head -n1`
fi
echo "Installing kernel ${kernel_deb}"
[ ! -e build ] && mkdir -p build
package_list=""
for package in ${packages}; do
package_list="${package_list} --package=${package}"
done
echo "packages ${packages}"
echo "package_list ${package_list}"
if [ ! -e build/test_roofs.tgz ]; then
sudo vmdebootstrap \
--arch=arm64 --no-extlinux --no-kernel\
--no-update-initramfs --enable-dhcp \
--foreign=/usr/bin/qemu-aarch64-static \
--verbose --log "build/test_img.log" \
--tarball="build/test_rootfs.tgz" \
--configure-apt \
--distribution "buster" \
--serial-console-command "/sbin/getty -L ttymxc0 115200 vt100" \
--root-password='root' --hostname='pureos-test' --user=purism/123456 --sudo \
--owner "$(whoami)" ${package_list} \
--custom-package=${kernel_deb}
fi
#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#
usage() {
echo "Usage : $1 "
echo " -d <kernel_deb> extract this deb"
echo " -b extract kernel and headers for out of tree module build"
}
cwd=$(pwd)
kernel_deb=
build_prep=0
arch=arm64
while getopts "hd:b" opt; do
case ${opt} in
d)
kernel_deb=$OPTARG
;;
b)
build_prep=1
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
usage "$0"
exit 0
;;
h )
usage "$0"
exit 0
;;
esac
done
if [ -z ${kernel_deb} ]; then
kernel_deb=`ls -t files/linux-image-* | grep -v dbg | head -n1`
fi
echo "Installing kernel ${kernel_deb}"
VERSION=${kernel_deb%_${arch}.deb}
VERSION=${VERSION##*/}
VERSION=${VERSION##linux-image-}
VERSION=${VERSION%_*}
SRC_DIR=`dirname ${kernel_deb}`
headers=${kernel_deb##*/}
headers=linux-headers-${headers##linux-image-}
if [ "${build_prep}" == 1 ]; then
DIR=${cwd}/build/${VERSION}
rm -r ${DIR}
else
DIR=`mktemp -d -p build`
fi
echo "disecting debian kernel ${VERSION} in ${DIR}"
dpkg-deb -R ${kernel_deb} ${DIR}
if [ "${build_prep}" == 1 ]; then
rm -r ${DIR}/DEBIAN
dpkg-deb -R ${SRC_DIR}/${headers} ${DIR}
rm -r ${DIR}/DEBIAN
dpkg-deb -R ${SRC_DIR}/linux-libc-dev_${VERSION}*${arch}.deb ${DIR}
fi
mv ${DIR}/boot/vmlinuz-${VERSION} ${DIR}/boot/Image.gz
gunzip ${DIR}/boot/Image.gz
cp ${DIR}/boot/Image files/
cp ${DIR}/usr/lib/linux-image-${VERSION}/freescale/*.dtb files/
if [ "${build_prep}" != 1 ]; then
rm -r ${DIR}
fi
#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#
usage() {
echo "Usage : $1 "
echo " -h Display this help message."
echo " -T [ci|unstable] use the artifacts from this build for the image"
echo " -x extract the image for flashing"
echo " -k get the kernel binaries as well"
}
build_type=ci
pureos_board=devkit
extract=0
get_kernel=0
while getopts "xkhT:" opt; do
case ${opt} in
T)
build_type=$OPTARG
;;
x)
extract=1
;;
k)
get_kernel=1
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
usage "$0"
exit 0
;;
h )
usage "$0"
exit 0
;;
esac
done
[ ! -e files ] && mkdir files
base_url=https://storage.puri.sm/librem5/binaries/${build_type}/latest/
wget -N "${base_url}/${pureos_board}.img.xz" -P files/
if [ "${extract}" == 1 ] &&
[ ! -e files/${pureos_board}.img ] ||
[ files/${pureos_board}.img.xz -nt files/${pureos_board}.img ]; then
xz -vdk files/${pureos_board}.img.xz
fi
wget -N "${base_url}/files/uboot-${pureos_board}-recovery/u-boot-${pureos_board}-recovery.imx" -P files/
wget -N "${base_url}/files/uboot-${pureos_board}/u-boot-${pureos_board}.imx" -P files/
wget -N "${base_url}/files/uboot-${pureos_board}/m4.bin" -P files/
if [ "${get_kernel}" == 1 ]; then
wget -r -np -R "index.html*" -N https://arm01.puri.sm/job/Kernel_builds/job/Emcraft_Kernel_CI_build/lastSuccessfulBuild/artifact/files/*zip*/files.zip -nH --cut-dirs=8 -P files
cd files
unzip -oj files.zip
gzip -f rsi_upgrade.tar
gzip -f rsi_firmware.tar
fi
#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#
if [ $# -ne 1 ]; then
echo "usage: $0 <rootfs dir>"
exit
fi
cwd=`pwd`
DIR=$1
echo "Customizing rootfs"
set -x
cat << EOF > "${DIR}/etc/rc.local"
#!/bin/bash
resize2fs /dev/ram0
exit 0
EOF
chmod +x ${DIR}/etc/rc.local
cat << EOF > "${DIR}/etc/systemd/system/rc-local.service"
[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local
[Service]
Type=oneshot
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
mkdir -p ${DIR}/etc/systemd/system/multi-user.target.wants
ln -s /etc/systemd/system/rc-local.service ${DIR}/etc/systemd/system/multi-user.target.wants/rc-local.service
mkdir -p ${DIR}/usr/src
cp files/rsi*tar.gz ${DIR}/usr/src
cat << EOF > "${DIR}/etc/modprobe.d/rsi_91x.conf"
# This is for wlan sta + BT
options dev_oper_mode=13 rsi_zone_enabled=1
blacklist rsi_sdio
EOF
mkdir -p ${DIR}/usr/local/bin
cp test_scripts/* ${DIR}/usr/local/bin
#mkdir -p ${DIR}/lib/firmware
#tar -xf files/rsi_firmware.tar.gz -C ${DIR}/lib/firmware
#cd ${DIR}/lib/modules/4.18.*/kernel/drivers/net/wireless/rsi &&
# tar -xf ${cwd}/files/rsi_upgrade.tar.gz
set +x
#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#
rsi_path=/lib/modules/$(uname -r)/kernel/drivers/net/wireless/rsi
mv ${rsi_path}/rsi_91x.ko ${rsi_path}/rsi_91x.ko.bak
mv ${rsi_path}/rsi_sdio.ko ${rsi_path}/rsi_sdio.ko.bak
mv ${rsi_path}/rsi_usb.ko ${rsi_path}/rsi_usb.ko.bak
rmmod rsi_sdio rsi_usb rsi_91x
tar -xf /usr/src/rsi_upgrade.tar.gz -C ${rsi_path}
mkdir -p /lib/firmware
tar -xf /usr/src/rsi_firmware.tar.gz -C /lib/firmware
modprobe rsi_91x dev_oper_mode=13 rsi_zone_enabled=1
modprobe rsi_sdio
mv ${rsi_path}/rsi_91x.ko.bak ${rsi_path}/rsi_91x.ko
mv ${rsi_path}/rsi_sdio.ko.bak ${rsi_path}/rsi_sdio.ko
mv ${rsi_path}/rsi_usb.ko.bak ${rsi_path}/rsi_usb.ko
rmmod rsi_sdio rsi_usb rsi_91x
modprobe rsi_91x dev_oper_mode=13 rsi_zone_enabled=1
modprobe rsi_sdio
#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#
while true; do
cat /sys/class/thermal/thermal_zone0/temp
sleep 30
done
uuu_version 1.0.1
SDP: boot -f ../files/u-boot-devkit-recovery.imx
# This command will be run when use SPL
SDPU: delay 1000
SDPU: write -f ../files/u-boot-devkit-recovery.imx -offset 0x57c00
SDPU: jump
# This command will be run when ROM support stream mode
SDPS: boot -f ../files/u-boot-devkit-recovery.imx
SDPU: delay 1000
#FB: ucmd setenv fastboot_buffer 0x43000000
FB: ucmd setenv fastboot_dev mmc
FB: ucmd setenv mmcdev 0
FB: flash -raw2sparse all ../files/devkit.img
FB: Done
uuu_version 1.0.1
SDP: boot -f ../files/u-boot-devkit-recovery.imx
# This command will be run when use SPL
SDPU: delay 1000
SDPU: write -f ../files/u-boot-devkit-recovery.imx -offset 0x57c00
SDPU: jump