hvk: add scripts for Kernel/U-Boot compilation
authorHugo Villeneuve <hugo@hugovil.com>
Thu, 13 Apr 2023 14:18:00 +0000 (10:18 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Thu, 1 Jun 2023 20:52:40 +0000 (16:52 -0400)
scripts/Makefile.am
scripts/hvk-common.sh [new file with mode: 0644]
scripts/hvk-compile-sendpatch.sh [new file with mode: 0755]
scripts/hvk-compile.sh [new file with mode: 0755]
scripts/hvk-configure.sh [new file with mode: 0755]
scripts/hvk-debug.sh [new file with mode: 0755]
scripts/hvk-dt.sh [new file with mode: 0755]
scripts/hvk-init.sh [new file with mode: 0755]
scripts/hvk-save-defconfig.sh [new file with mode: 0755]
scripts/hvk-x86.sh [new file with mode: 0644]

index 6fcbe18..d04f78b 100644 (file)
@@ -21,6 +21,15 @@ dist_bin_SCRIPTS = \
     setdate \
     strip-debug-symbols \
     tildes-clean \
+    hvk-common.sh \
+    hvk-compile.sh \
+    hvk-compile-sendpatch.sh \
+    hvk-configure.sh \
+    hvk-debug.sh \
+    hvk-init.sh \
+    hvk-save-defconfig.sh \
+    hvk-dt.sh \
+    hvk-x86.sh \
     hv-hg-functions.sh \
     hg-format-patch hg-update-subrepos \
     git-hg-sub-import git-hg-sub-update \
diff --git a/scripts/hvk-common.sh b/scripts/hvk-common.sh
new file mode 100644 (file)
index 0000000..7f332da
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+if [ -f include/linux/linux_logo.h ]; then
+    mode=linux
+elif [ -f include/asm-generic/u-boot.h ]; then
+    mode=uboot
+else
+    echo "Error: no kernel or U-Boot repo detected, aborting."
+    exit 1
+fi
+
+if [ -f .hvk ]; then
+    # Source project definition file (in project's git repo):
+    source .hvk
+else
+    # Source x86 generic definition file
+    source ${SCRIPTPATH}/hvk-x86.sh
+fi
+
+: ${MAKEJOBS:="-j$(nproc)"}
+
+KMAKE="make ${MAKEJOBS}"
+
+# Needed to compile sample userspace programs (rtc-test):
+export CROSS_COMPILE_KCFLAGS=${KCFLAGS}
+
+# Arg1: src file
+# Arg2: destination user@host
+copy_exec()
+{
+    scp ${1} ${2}:/tmp
+    ssh ${2} "install -m 755 /tmp/$(basename ${1}) \${HOME}"
+}
diff --git a/scripts/hvk-compile-sendpatch.sh b/scripts/hvk-compile-sendpatch.sh
new file mode 100755 (executable)
index 0000000..eb76229
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+set -e
+
+# Compile and validate all DT/schemas, usefull when testing each patch in a
+# series.
+
+hvk-compile.sh
+hvk-dt.sh
diff --git a/scripts/hvk-compile.sh b/scripts/hvk-compile.sh
new file mode 100755 (executable)
index 0000000..11b2ce6
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+source ${SCRIPTPATH}/hvk-common.sh
+
+${KMAKE}
+
+if [ x"${mode}" = x"linux" ]; then
+    ${KMAKE} modules_prepare
+    ${KMAKE} modules
+
+    if [ x"${DTB_SRC}" != x"" ]; then
+        ${KMAKE} dtbs
+    fi
+elif [ x"${mode}" = x"uboot" ]; then
+    ${KMAKE} u-boot-initial-env
+fi
+
+if [ ${#} -eq 1 ]; then
+    EVK_IP="${1}"
+
+    scp ${BOOT_SRC}/Image root@${EVK_IP}:${BOOT_DEST}/Image-latest
+
+    scp ${DTB_SRC} root@${EVK_IP}:${BOOT_DEST}/latest.dtb
+
+    rm -rf modules-tmp
+    ${KMAKE} INSTALL_MOD_PATH=modules-tmp modules_install
+    pushd modules-tmp/lib/
+    tar cf - modules/* | gzip -9 > /tmp/modules.tar.gz
+    popd
+
+    scp /tmp/modules.tar.gz root@${EVK_IP}:/tmp
+
+    ssh root@${EVK_IP} "cd /lib && tar -xf /tmp/modules.tar.gz"
+    rm /tmp/modules.tar.gz
+
+    # Switch to latest kernel and DTB:
+    ssh root@${EVK_IP} "fw_setenv image Image-latest; fw_setenv fdt_file latest.dtb"
+fi
diff --git a/scripts/hvk-configure.sh b/scripts/hvk-configure.sh
new file mode 100755 (executable)
index 0000000..cf71e91
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+source ${SCRIPTPATH}/hvk-common.sh
+
+${KMAKE} menuconfig
diff --git a/scripts/hvk-debug.sh b/scripts/hvk-debug.sh
new file mode 100755 (executable)
index 0000000..298b6fe
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+source ${SCRIPTPATH}/hvk-common.sh
+
+KVER_BASE=$(make kernelversion)
+
+# -W:
+# Not all compiler warnings are enabled by default. Build the
+# kernel with "make EXTRA_CFLAGS=-W" to get the full set.
+#
+# C=1: run Sparse semantic checker for C programs
+# W=1: Enable extra build checks:
+#   1: warnings which may be relevant and do not occur too often
+# V=1: Disable Makefile silent mode
+
+
+# Temporaire: désactivé W=1 car cause un problème avec kernel 5.17-rc...
+#KMAKE="${KMAKE} W=1 C=1 KCFLAGS=-W"
+KMAKE="${KMAKE} C=1 KCFLAGS=-W"
+
+# The path to the specific drivers we want to compile:
+DRIVER_PATH[0]=drivers/rtc
+DRIVER_NAME[0]=rtc-pcf2127
+
+DRIVER_PATH[1]=drivers/iio/adc
+DRIVER_NAME[1]=ti-ads7924
+
+if [ ${#} -eq 1 ]; then
+    EVK_IP="${1}"
+fi
+
+k=0
+for driver_path in "${DRIVER_PATH[@]}"; do
+    p="${DRIVER_PATH[${k}]}"
+    n="${DRIVER_NAME[${k}]}"
+
+    ${KMAKE} M=${p}
+
+    if [ x"${EVK_IP}" != x"" ]; then
+       scp ${p}/${n}.ko root@${EVK_IP}:/lib/modules/${KVER_BASE}*/kernel/${p}/
+    fi
+
+    k=$((${k} + 1))
+done
+
+${KMAKE} dtbs
+
+${KMAKE} samples
+
+if [ x"${EVK_IP}" != x"" ]; then
+    scp ${DTB_SRC} root@${EVK_IP}:${DTB_DEST}
+    if [ -f samples/rtc-test/rtc-test ]; then
+       scp samples/rtc-test/rtc-test root@${EVK_IP}:
+    fi
+
+    #ssh root@${EVK_IP} "/sbin/depmod -a"
+fi
diff --git a/scripts/hvk-dt.sh b/scripts/hvk-dt.sh
new file mode 100755 (executable)
index 0000000..aae437f
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+source ${SCRIPTPATH}/hvk-common.sh
+
+if [ x"${DTS_BOARD}" != x"" ]; then
+    DTB_FILES="${DTB_FILES} ${DTS_BOARD}.dtb"
+fi
+
+if [ x"${DTB_FILES}" != x"" ]; then
+    # See https://lore.kernel.org/lkml/20221102214654.axyptitp5kpq3wcq@notapiano/T/
+    ${KMAKE} CHECK_DTBS=y ${DTB_FILES}
+fi
+
+DT_CHECKER="${KMAKE} DT_CHECKER_FLAGS=-m dt_binding_check"
+
+if [ x"${DT_SCHEMA_FILES}" != x"" ]; then
+    ${DT_CHECKER} DT_SCHEMA_FILES=${DT_SCHEMA_FILES}
+fi
+
+# To check all:
+#${DT_CHECKER}
+
+#${KMAKE} checkstack
diff --git a/scripts/hvk-init.sh b/scripts/hvk-init.sh
new file mode 100755 (executable)
index 0000000..8e7fb1c
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+source ${SCRIPTPATH}/hvk-common.sh
+
+if [ x"${DEFCONFIG_AUTOGEN}" != x"" ]; then
+    if [ -x ${DEFCONFIG_AUTOGEN} ]; then
+        dir=$(dirname ${DEFCONFIG_AUTOGEN})
+        echo "Autogen defconfig from configuration fragments..."
+        pushd ${dir}
+        ./$(basename ${DEFCONFIG_AUTOGEN})
+        popd
+    else
+        echo "Error: cannot execute configuration autogen script"
+        exit 1
+    fi
+fi
+
+if [ x"${DEFCONFIG_BOARD}" = x"all" ]; then
+    ${KMAKE} allyesconfig
+else
+    ${KMAKE} ${DEFCONFIG_BOARD}_defconfig
+fi
+
+if [ x"${1}" = x"yocto" ]; then
+    LOCALVERSION="${YOCTO_LOCALVERSION}"
+
+    # Add GIT revision to the local version
+    head=`git --git-dir=.git rev-parse --verify --short HEAD 2> /dev/null`
+
+    SCMVERSION=$(printf "%s%s" +g $head)
+else
+    LOCALVERSION="-latest"
+    SCMVERSION=""
+fi
+
+echo "Force local kernel version to: ${LOCALVERSION}"
+sed -e "s/^\(CONFIG_LOCALVERSION=\"\).*/\1${LOCALVERSION}\"/" -i .config
+
+echo ${SCMVERSION} > .scmversion
+
+${KMAKE} olddefconfig
diff --git a/scripts/hvk-save-defconfig.sh b/scripts/hvk-save-defconfig.sh
new file mode 100755 (executable)
index 0000000..8e1f653
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+source ${SCRIPTPATH}/hvk-common.sh
+
+if [ x"${DEFCONFIG_BOARD}" = x"all" ]; then
+    "Error, cannot save defconfig for \"all\""
+    exit 1
+fi
+
+cfg_prefix="arch/${ARCH}/"
+
+if [ x"${mode}" = x"uboot" ]; then
+    cfg_prefix=""
+fi
+
+${KMAKE} savedefconfig
+cp defconfig ${cfg_prefix}configs/${DEFCONFIG_BOARD}_defconfig
diff --git a/scripts/hvk-x86.sh b/scripts/hvk-x86.sh
new file mode 100644 (file)
index 0000000..bc37085
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+DEFCONFIG_BOARD=all
+
+ARCH=x86
+
+# List of DT schema files to validate:
+DT_SCHEMA_FILES="\
+    Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml \
+"