From aeb896b55c384d7f9a6e9a29f74cf560c6392c5b Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 16 Feb 2025 19:54:41 +0100 Subject: linux for toradex module support initial import --- yocto/README | 179 ++++++++++++++++++++++++++++ yocto/kernel_lvds_freq.patch | 62 ++++++++++ yocto/overlays/Makefile | 7 ++ yocto/overlays/mikroPhone-panel_overlay.dts | 131 ++++++++++++++++++++ 4 files changed, 379 insertions(+) create mode 100644 yocto/README create mode 100644 yocto/kernel_lvds_freq.patch create mode 100644 yocto/overlays/Makefile create mode 100644 yocto/overlays/mikroPhone-panel_overlay.dts diff --git a/yocto/README b/yocto/README new file mode 100644 index 0000000..ef99121 --- /dev/null +++ b/yocto/README @@ -0,0 +1,179 @@ +- release matrix page: +https://developer.toradex.com/software/toradex-embedded-software/embedded-linux-release-matrix/ + +- resources: +https://docs.u-boot.org/en/stable/board/toradex/verdin-imx8mp.html +https://developer.toradex.com/linux-bsp/os-development/build-yocto/build-a-reference-image-with-yocto-projectopenembedded/ +https://developer.toradex.com/linux-bsp/os-development/build-u-boot-and-linux-kernel-from-source-code/build-u-boot/ +https://developer.toradex.com/linux-bsp/os-development/build-u-boot-and-linux-kernel-from-source-code/build-linux-kernel-from-source-code/ +https://developer.toradex.com/linux-bsp/os-development/build-u-boot-and-linux-kernel-from-source-code/build-device-tree-overlays-from-source-code/ + +- install dependencies: +# dependencies for yocto: +apt-get install gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 python3-subunit zstd liblz4-tool file locales libacl1 +apt-get install curl git + +# dependencies for u-boot: +apt-get install bc build-essential git libncurses5-dev lzop perl libssl-dev bison flex swig libyaml-dev pkg-config python3-dev +apt-get install u-boot-tools + +# dependencies for kernel: + apt-get install bc build-essential git libncurses5-dev lzop perl libssl-dev bison flex +apt-get install u-boot-tools + +locale-gen en_US.UTF-8 +# configure git +git config --global user.name "John Doe" +git config --global user.email johndoe@example.com + +- make build directory: +mkdir /build +cd build + + +prepare build environment +------------------------- + +mkdir /build/tools +cd /build/tools + +- install repo bootstrap binary: +mkdir bin +curl https://commondatastorage.googleapis.com/git-repo-downloads/repo > bin/repo +chmod 755 bin/repo + +- install the ARM GCC toolchain: +mkdir arm +cd arm +wget https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz +tar xvf arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz +ln -s arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-linux-gnu gcc-linaro-aarch64 +cd .. + +- install device tree compiler tool: +git clone https://git.kernel.org/pub/scm/utils/dtc/dtc.git -b v1.7.2 +cd dtc +make +cp dtc ../bin/ +cd .. + +- export variables: +cd .. +vi start.sh +... +export ARCH=arm64 +export DTC_FLAGS="-@" +export PATH=/build/tools/gcc-linaro-aarch64/bin:/build/tools/bin:$PATH +export CROSS_COMPILE=aarch64-none-linux-gnu- +... +chmod 755 start.sh +. ./start.sh + + +yocto image +----------- + +- clone meta-information +mkdir oe-core +cd oe-core +# branch: repo init -u git://git.toradex.com/toradex-manifest.git -b scarthgap-7.x.y -m tdxref/default.xml +# specific tag: +repo init -u git://git.toradex.com/toradex-manifest.git -b refs/tags/7.1.0 -m tdxref/default.xml +repo sync +# repeat sync until successful + +- setup environment: +. export + +- edit config: +vi conf/local.conf +... +# set MACHINE: +MACHINE ?= "verdin-imx8mp" +# append: +ACCEPT_FSL_EULA = "1" +TOOLCHAIN_TARGET_TASK:append = " kernel-devsrc" +... + +- build: +bitbake -k tdx-reference-minimal-image -c populate_sdk + +- machine.conf in: layers/meta-toradex-nxp/conf/machine/verdin-imx8mp.conf +- distro.conf in: layers/meta-toradex-distro/conf/distro/*.conf +- demo images in: layers/meta-toradex-demos/recipes-images/images/*.bb + +u-boot +------ + +cd /build +git clone https://source.denx.de/u-boot/u-boot.git +cd u-boot +# adjust tag according to version used in yocto (from release matrix page) +git checkout tags/v2024.07 +git checkout -b toradex-v2024.07 +mkdir patches +cd patches +cp ../../oe-core/layers/meta-toradex-bsp-common/recipes-bsp/u-boot/u-boot-toradex/* . +# adjust recipe according to version used in yocto (from release matrix page) +PATCH_RECIPE=../../oe-core/layers/meta-toradex-bsp-common/recipes-bsp/u-boot/u-boot-toradex_2024.07.bb +# apply patches in order +git am `grep -n TDX_PATCHES $PATCH_RECIPE | echo $((\`cut -f1 -d:\` + 1)) | xargs -I line_no tail $PATCH_RECIPE --lines=+line_no | grep -v ^\" | cut -d / -f 3 | sed -e "s/ \\\\\\\\//g"` +cd .. +# build ATF (TF-A) +git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git +cd trusted-firmware-a +make PLAT=imx8mp IMX_BOOT_UART_BASE=0x30880000 bl31 +cp build/imx8mp/release/bl31.bin .. +cd .. +# get DDR firmware +wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx-8.10.1.bin +chmod +x firmware-imx-8.10.1.bin +./firmware-imx-8.10.1.bin +cp firmware-imx-8.10.1/firmware/ddr/synopsys/lpddr4*_202006.bin . +# finally, build u-boot +make mrproper +make verdin-imx8mp_defconfig +# dts in: dts/upstream/src/arm64/freescale/imx8mp-verdin-wifi-*.dts +# arch/arm/dts/imx8mp-verdin-wifi-dev-u-boot.dtsi +# make menuconfig (choose dts to build) +make -j$(nproc) 2>&1 | tee build.log + + +kernel +------ + +cd /build +# adjust branch and commit according to version used in yocto: +# vi oe-core/layers/meta-toradex-nxp/recipes-kernel/linux/linux-toradex_*.bb (search for SRCBRANCH, SRCREV_machine) +git clone -b toradex_6.6-2.1.x-imx git://git.toradex.com/linux-toradex.git +cd linux-toradex +git checkout 3493ccd66900420e2462daf4db187b315b50469e +cp ../oe-core/build/deploy/images/verdin-imx8mp/kernel-config .config +# verify config +make olddefconfig +# copy yocto/kernel_lvds_freq.patch from mikroPhone repo +# apply LVDS patch +patch < ../kernel_lvds_freq.patch +# build kernel and dtb +make -j$(nproc) Image.gz 2>&1 | tee build.log +make freescale/imx8mp-verdin-wifi-dev.dtb +# ls ./arch/arm64/boot/Image.gz +# ls ./arch/arm64/boot/dts/freescale/imx8mp-verdin-wifi-dev.dtb +# build kernel modules +make -j$(nproc) modules 2>&1 | tee build.log +mkdir modules +INSTALL_MOD_PATH=`pwd`/modules make modules_install +cd modules +tar -czf ../modules.tar.gz . +cd .. + + +overlay +------- + +# toradex overlays (match branch to kernel branch) +# git clone -b toradex_6.6-2.1.x-imx git://git.toradex.com/device-tree-overlays.git +# copy yocto/overlays from mikroPhone repo +cd overlays +STAGING_KERNEL_DIR=../linux-toradex make mikroPhone-panel_overlay.dtbo +cd .. diff --git a/yocto/kernel_lvds_freq.patch b/yocto/kernel_lvds_freq.patch new file mode 100644 index 0000000..9955bc4 --- /dev/null +++ b/yocto/kernel_lvds_freq.patch @@ -0,0 +1,62 @@ +diff --git a/arch/arm64/boot/dts/freescale/imx8mp.dtsi b/arch/arm64/boot/dts/freescale/imx8mp.dtsi +index 55adf1bf45d9..c875474e6c45 100644 +--- a/arch/arm64/boot/dts/freescale/imx8mp.dtsi ++++ b/arch/arm64/boot/dts/freescale/imx8mp.dtsi +@@ -752,7 +752,7 @@ clk: clock-controller@30380000 { + <800000000>, + <393216000>, + <361267200>, +- <1039500000>; ++ <252000000>; + }; + + src: reset-controller@30390000 { +diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c +index 6c17786ecb9f..8c9840f08c0e 100644 +--- a/drivers/clk/imx/clk-pll14xx.c ++++ b/drivers/clk/imx/clk-pll14xx.c +@@ -75,6 +75,7 @@ static const struct imx_pll14xx_rate_table imx_pll1443x_tbl[] = { + PLL_1443X_RATE(49152000U, 393, 3, 6, 0x374c), + PLL_1443X_RATE(45158400U, 241, 2, 6, 0xd845), + PLL_1443X_RATE(40960000U, 109, 1, 6, 0x3a07), ++ PLL_1443X_RATE(252000000U, 84, 2, 2, 0), + }; + + struct imx_pll14xx_clk imx_1443x_pll = { +diff --git a/drivers/gpu/drm/imx/imx8mp-ldb.c b/drivers/gpu/drm/imx/imx8mp-ldb.c +index e3f5c5e6e842..55dbafa863cf 100644 +--- a/drivers/gpu/drm/imx/imx8mp-ldb.c ++++ b/drivers/gpu/drm/imx/imx8mp-ldb.c +@@ -186,15 +186,6 @@ imx8mp_ldb_encoder_atomic_check(struct drm_encoder *encoder, + return -EINVAL; + } + +- /* +- * Due to limited video PLL frequency points on i.MX8mp, +- * we do mode fixup here in case any mode is unsupported. +- */ +- if (ldb->dual) +- mode->clock = mode->clock > 100000 ? 148500 : 74250; +- else +- mode->clock = 74250; +- + return 0; + } + +@@ -212,16 +203,6 @@ imx8mp_ldb_encoder_mode_valid(struct drm_encoder *encoder, + if (ldb_ch->panel) + return MODE_OK; + +- /* +- * Due to limited video PLL frequency points on i.MX8mp, +- * we do mode valid check here. +- */ +- if (ldb->dual && mode->clock != 74250 && mode->clock != 148500) +- return MODE_NOCLOCK; +- +- if (!ldb->dual && mode->clock != 74250) +- return MODE_NOCLOCK; +- + return MODE_OK; + } + diff --git a/yocto/overlays/Makefile b/yocto/overlays/Makefile new file mode 100644 index 0000000..b574d5d --- /dev/null +++ b/yocto/overlays/Makefile @@ -0,0 +1,7 @@ +DTC ?= dtc + +P = .preprocessed +%.dtbo: %.dts + cpp -nostdinc -I "$(STAGING_KERNEL_DIR)/arch/arm64/boot/dts" -I "$(STAGING_KERNEL_DIR)/include" -undef -x assembler-with-cpp $< $<$P + $(DTC) $(DTC_FLAGS) -Hepapr -I dts -O dtb -i "$(STAGING_KERNEL_DIR)/arch/arm64/boot/dts/" -o $@ $<$P + rm $<$P diff --git a/yocto/overlays/mikroPhone-panel_overlay.dts b/yocto/overlays/mikroPhone-panel_overlay.dts new file mode 100644 index 0000000..0bc14b3 --- /dev/null +++ b/yocto/overlays/mikroPhone-panel_overlay.dts @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/* + * Copyright 2023 Toradex + */ + +// adapted from: https://git.toradex.com/cgit/device-tree-overlays.git/tree/overlays/verdin-imx8mp_panel-cap-touch-10inch-lvds_overlay.dts?h=toradex_6.6-2.2.x-imx +// Verdin iMX8M Plus single-channel LVDS + +/dts-v1/; +/plugin/; + +#include +#include +#include +#include "freescale/imx8mp-pinfunc.h" + +/ { + compatible = "toradex,verdin-imx8mp"; +}; + +&{/} { + backlight_lvds_native: backlight-lvds-native { + compatible = "pwm-backlight"; + pinctrl-names = "default"; + brightness-levels = <0 45 63 88 119 158 203 255>; + default-brightness-level = <4>; + /* Verdin PWM_1 (SODIMM 15) */ + pwms = <&pwm1 0 6666667>; + }; + + panel-lvds-native { + compatible = "panel-lvds"; + backlight = <&backlight_lvds_native>; + data-mapping = "vesa-24"; + height-mm = <136>; + width-mm = <217>; + + panel-timing { + clock-frequency = <36000000>; + hactive = <480>; + hfront-porch = <23 60 71>; + hsync-len = <15 40 47>; + hback-porch = <23 60 71>; + + vactive = <854>; + vfront-porch = <5 7 10>; + vsync-len = <6 9 12>; + vback-porch = <5 7 10>; + + hsync-active = <0>; + vsync-active = <0>; + de-active = <0>; + pixelclk-active = <1>; /* positive edge */ + }; + + port { + panel_lvds_native_in: endpoint { + remote-endpoint = <&lvds_out>; + }; + }; + }; +}; + +&gpu_2d { + status = "okay"; +}; + +&gpu_3d { + status = "okay"; +}; + +/* Verdin I2C_1 */ +&i2c1 { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + + gt911@5d { + compatible = "goodix,gt911"; + reg = <0x5d>; + pinctrl-names = "default"; + pinctrl-0 = <&gpio1>; + /* Verdin GPIO_3 (SODIMM 210) */ + interrupt-parent = <&gpio1>; + interrupts = <5 IRQ_TYPE_EDGE_FALLING>; + /* Verdin GPIO_4 (SODIMM 212) */ + reset-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>; + status = "okay"; + }; +}; + +&lcdif2 { + status = "okay"; +}; + +&ldb { + status = "okay"; + + lvds-channel@0 { + #address-cells = <1>; + #size-cells = <0>; + fsl,data-mapping = "spwg"; + fsl,data-width = <24>; + status = "okay"; + + port@1 { + reg = <1>; + + lvds_out: endpoint { + remote-endpoint = <&panel_lvds_native_in>; + }; + }; + }; +}; + +&ldb_phy { + status = "okay"; +}; + +&mix_gpu_ml { + status = "okay"; +}; + +&ml_vipsi { + status = "okay"; +}; + +/* Verdin PWM_2 */ +&pwm1 { + status = "okay"; +}; -- cgit v1.2.3