From cddadc1f4b89874dab41f9b9eb64640264d80313 Mon Sep 17 00:00:00 2001 From: ludiazv Date: Tue, 30 May 2023 13:27:31 +0200 Subject: [PATCH] DT overlay support Experimental feature to include DT overlays and custom boot args --- README.md | 68 +++++++++++++++++++ conf/machine/include/sunxi.inc | 5 ++ conf/machine/include/sunxi64.inc | 3 + .../files/sun50i-h616/h616-i2c0.dts | 20 ++++++ .../files/sun50i-h616/h616-i2c1.dts | 20 ++++++ .../files/sun50i-h616/h616-i2c2.dts | 20 ++++++ .../files/sun50i-h616/h616-uart1.dts | 22 ++++++ .../files/sun50i-h616/h616-uart2.dts | 32 +++++++++ .../sunxi-overlays/files/sun50i/h5-i2c0.dts | 20 ++++++ .../sunxi-overlays/files/sun50i/h5-i2c1.dts | 20 ++++++ .../sunxi-overlays/files/sun50i/h5-i2c2.dts | 20 ++++++ .../sunxi-overlays/files/sun50i/h5-uart1.dts | 22 ++++++ .../sunxi-overlays/files/sun50i/h5-uart2.dts | 32 +++++++++ .../sunxi-overlays/files/sun50i/h5-uart3.dts | 32 +++++++++ .../files/sun50i/h5-usbhost0.dts | 27 ++++++++ .../files/sun50i/h5-usbhost1.dts | 27 ++++++++ .../files/sun50i/h5-usbhost2.dts | 27 ++++++++ .../sunxi-overlays/files/sun50i/h6-i2c0.dts | 20 ++++++ .../sunxi-overlays/files/sun50i/h6-i2c1.dts | 20 ++++++ .../sunxi-overlays/files/sun50i/h6-i2c2.dts | 20 ++++++ .../sunxi-overlays/files/sun50i/h6-uart1.dts | 22 ++++++ .../sunxi-overlays/files/sun50i/h6-uart2.dts | 32 +++++++++ .../sunxi-overlays/files/sun50i/h6-uart3.dts | 32 +++++++++ .../sunxi-overlays/files/sun8i/h3-i2c0.dts | 20 ++++++ .../sunxi-overlays/files/sun8i/h3-i2c1.dts | 20 ++++++ .../sunxi-overlays/files/sun8i/h3-i2c2.dts | 20 ++++++ .../sunxi-overlays/files/sun8i/h3-uart1.dts | 22 ++++++ .../sunxi-overlays/files/sun8i/h3-uart2.dts | 22 ++++++ .../sunxi-overlays/files/sun8i/h3-uart3.dts | 22 ++++++ .../files/sun8i/h3-usbhost0.dts | 27 ++++++++ .../files/sun8i/h3-usbhost1.dts | 27 ++++++++ .../files/sun8i/h3-usbhost2.dts | 27 ++++++++ .../files/sun8i/h3-usbhost3.dts | 27 ++++++++ recipes-bsp/sunxi-overlays/gen_builtin.sh | 18 +++++ .../sunxi-overlays/sunxi-overlays-builtin.inc | 38 +++++++++++ recipes-bsp/sunxi-overlays/sunxi-overlays.bb | 11 +++ recipes-bsp/u-boot/files/aarch64/boot.cmd | 61 +++++++++++++++-- recipes-bsp/u-boot/files/arm/boot.cmd | 61 +++++++++++++++-- recipes-bsp/u-boot/u-boot_%.bbappend | 28 ++++++++ recipes-kernel/linux/linux-mainline.inc | 3 + 40 files changed, 1009 insertions(+), 8 deletions(-) create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c0.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-uart1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-uart2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c0.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-uart1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-uart2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-uart3.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost0.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c0.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h6-uart1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h6-uart2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun50i/h6-uart3.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c0.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-uart1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-uart2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-uart3.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost0.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost1.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost2.dts create mode 100644 recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost3.dts create mode 100755 recipes-bsp/sunxi-overlays/gen_builtin.sh create mode 100644 recipes-bsp/sunxi-overlays/sunxi-overlays-builtin.inc create mode 100644 recipes-bsp/sunxi-overlays/sunxi-overlays.bb diff --git a/README.md b/README.md index 838ea71..26eb587 100644 --- a/README.md +++ b/README.md @@ -84,4 +84,72 @@ This code changes the default CPU governor from _fantasy_ to _ondemand_, and tun For additional discussion, see https://github.com/linux-sunxi/meta-sunxi/issues/25 +Custom boot environment & devicetree overlay suppport +===================================================== + +The layer provide a basic custom enviroment for linux mainline that enables: + +- Custom boot argument to be passed to the kernel. +- Basic devicetree overlay support. + +By default this features are disabled and have to be activated including this the bitbake configuration (e.g. local.conf): + +``` +DISTRO_FEATURES:append = " sunxi-env" +``` + +This feature instruct the layer to deploy the file ``` /boot/sunxienv.txt ``` that is loaded during boot customize kernel boot command line. + +DT Overlay support +------------------ + +To enable overlays the following line must be activated in bitbake configuration (e.g. local.conf): + +``` +SUNXI_OVERLAYS_ENABLE:append = " " +``` + +The layer includes a common set for DT overalys organized by family. The list can be found in the +following path ```meta-sunxi/recipes-bs/sunxi-overlays/files//``` + +Once activated the following content will be added to yout image in the boot partition: +``` +/boot/dtbo/*.dbto (all compiled overlays selected in SUNXI_OVERLAYS_ENABLE) +/boot/sunxienv.txt (uboot config file with the full list of devicetree overlays) +``` + +```/boot/sunxienv.txt``` can be modified after the build to activate or deactive the overlays on boot to provide +runtime flexibility or for debugging. A ```.dbto``` file can be also loaded at runtime +if the kernel supports it via sysfs interface using ```cat [dbto file] > /sys/kernel/config/device-tree/overlays/``` + + +Adding custom DT overlays +------------------------- +It is possible to add custom overlay/s via a ```bbappend``` recipe. + +``` +recipies-bsp + - sunxi-overlays + - sunxi-overlays%.bbappend + - files + - + +Inside the .bbappend the following metadata is requried: + +``` +FILESEXTRAPATHS:prepend := "${THISDIR}/files:" +SRC_URI:${SOC_FAMILY}:append = " file://" +``` + +Don't forget to add the custom overlay in your image or local configuration: + +``` +SUNXI_OVERLAYS_ENABLED:append = " " +``` + + + + + + diff --git a/conf/machine/include/sunxi.inc b/conf/machine/include/sunxi.inc index b1f119c..16750db 100644 --- a/conf/machine/include/sunxi.inc +++ b/conf/machine/include/sunxi.inc @@ -41,6 +41,11 @@ SUNXI_BOOT_SPACE ?= "40" IMAGE_BOOT_FILES ?= "${KERNEL_IMAGETYPE} boot.scr" # ship fex file for sunxi kernel, devicetree file for mainline kernel IMAGE_BOOT_FILES += "${@bb.utils.contains('PREFERRED_PROVIDER_virtual/kernel', 'linux-sunxi', '${SUNXI_FEX_FILE}', '${KERNEL_DEVICETREE}', d)}" + +IMAGE_BOOT_FILES:append = " ${@bb.utils.contains('DISTRO_FEATURES', 'sunxi-env', 'sunxienv.txt', '', d)}" +IMAGE_BOOT_FILES:append = " ${@ '' if (d.getVar('SUNXI_OVERLAYS_ENABLE') or "").strip() == "" else 'devicetree/*.dtbo;dtbo/'}" + + WKS_FILES ?= "sunxi-sdcard-image.wks.in" WKS_FILE_DEPENDS ?= "virtual/kernel u-boot" # in case of sunxi kernel, sunxi-board-fex must be built prior wic image assembly diff --git a/conf/machine/include/sunxi64.inc b/conf/machine/include/sunxi64.inc index b1a5f3b..6412fdb 100644 --- a/conf/machine/include/sunxi64.inc +++ b/conf/machine/include/sunxi64.inc @@ -46,6 +46,9 @@ addtask do_fix_device_tree_location after do_write_wks_template before do_image_ SUNXI_BOOT_SPACE ?= "40" IMAGE_BOOT_FILES ?= "${KERNEL_IMAGETYPE} boot.scr ${KERNEL_DEVICETREE}" +IMAGE_BOOT_FILES:append = " ${@bb.utils.contains('DISTRO_FEATURES', 'sunxi-env', 'sunxienv.txt', '', d)}" +IMAGE_BOOT_FILES:append = " ${@ '' if (d.getVar('SUNXI_OVERLAYS_ENABLE') or "").strip() == "" else 'devicetree/*.dtbo;dtbo/'}" + WKS_FILES ?= "sunxi-sdcard-image.wks.in" WKS_FILE_DEPENDS ?= "virtual/kernel u-boot" diff --git a/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c0.dts b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c0.dts new file mode 100644 index 0000000..11a7b7f --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c0.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h616"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c0 = "/soc/i2c@5002000"; + }; + }; + + fragment@1 { + target = <&i2c0>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c1.dts b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c1.dts new file mode 100644 index 0000000..f583271 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c1.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h616"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c1 = "/soc/i2c@5002400"; + }; + }; + + fragment@1 { + target = <&i2c1>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c2.dts b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c2.dts new file mode 100644 index 0000000..febfdb8 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-i2c2.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h616"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c2 = "/soc/i2c@5002800"; + }; + }; + + fragment@1 { + target = <&i2c2>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-uart1.dts b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-uart1.dts new file mode 100644 index 0000000..cede6c1 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-uart1.dts @@ -0,0 +1,22 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h616"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial1 = "/soc/serial@5000400"; + }; + }; + + fragment@1 { + target = <&uart1>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart1_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-uart2.dts b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-uart2.dts new file mode 100644 index 0000000..7624a75 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i-h616/h616-uart2.dts @@ -0,0 +1,32 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h616"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial2 = "/soc/serial@5000800"; + }; + }; + + fragment@1 { + target = <&pio>; + __overlay__ { + uart2_rts_cts: uart2_rts_cts { + pins = "PD21", "PD22"; + function = "uart2"; + }; + }; + }; + + fragment@2 { + target = <&uart2>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart2_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c0.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c0.dts new file mode 100644 index 0000000..55d249d --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c0.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c0 = "/soc/i2c@01c2ac00"; + }; + }; + + fragment@1 { + target = <&i2c0>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c1.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c1.dts new file mode 100644 index 0000000..2528870 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c1.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c1 = "/soc/i2c@01c2b000"; + }; + }; + + fragment@1 { + target = <&i2c1>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c2.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c2.dts new file mode 100644 index 0000000..ff42f01 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-i2c2.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c2 = "/soc/i2c@01c2b400"; + }; + }; + + fragment@1 { + target = <&i2c2>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart1.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart1.dts new file mode 100644 index 0000000..0ce76ef --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart1.dts @@ -0,0 +1,22 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial1 = "/soc/serial@01c28400"; + }; + }; + + fragment@1 { + target = <&uart1>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart1_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart2.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart2.dts new file mode 100644 index 0000000..88cc0cd --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart2.dts @@ -0,0 +1,32 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial2 = "/soc/serial@01c28800"; + }; + }; + + fragment@1 { + target = <&pio>; + __overlay__ { + uart2_rts_cts: uart2_rts_cts { + pins = "PA2", "PA3"; + function = "uart2"; + }; + }; + }; + + fragment@2 { + target = <&uart2>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart2_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart3.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart3.dts new file mode 100644 index 0000000..3ad6cc9 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-uart3.dts @@ -0,0 +1,32 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial3 = "/soc/serial@01c28c00"; + }; + }; + + fragment@1 { + target = <&pio>; + __overlay__ { + uart3_rts_cts: uart3_rts_cts { + pins = "PA15", "PA16"; + function = "uart3"; + }; + }; + }; + + fragment@2 { + target = <&uart3>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart3_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost0.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost0.dts new file mode 100644 index 0000000..c1d79c2 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost0.dts @@ -0,0 +1,27 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target = <&ehci0>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@1 { + target = <&ohci0>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target = <&usbphy>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost1.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost1.dts new file mode 100644 index 0000000..2b4f245 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost1.dts @@ -0,0 +1,27 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target = <&ehci1>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@1 { + target = <&ohci1>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target = <&usbphy>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost2.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost2.dts new file mode 100644 index 0000000..54800e7 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h5-usbhost2.dts @@ -0,0 +1,27 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target = <&ehci2>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@1 { + target = <&ohci2>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target = <&usbphy>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c0.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c0.dts new file mode 100644 index 0000000..7e7ee8c --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c0.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h6"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c0 = "/soc/i2c@5002000"; + }; + }; + + fragment@1 { + target = <&i2c0>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c1.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c1.dts new file mode 100644 index 0000000..1117698 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c1.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h6"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c1 = "/soc/i2c@5002400"; + }; + }; + + fragment@1 { + target = <&i2c1>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c2.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c2.dts new file mode 100644 index 0000000..b627529 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h6-i2c2.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h6"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c2 = "/soc/i2c@5002800"; + }; + }; + + fragment@1 { + target = <&i2c2>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart1.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart1.dts new file mode 100644 index 0000000..44aa94e --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart1.dts @@ -0,0 +1,22 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h6"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial1 = "/soc/serial@5000400"; + }; + }; + + fragment@1 { + target = <&uart1>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart1_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart2.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart2.dts new file mode 100644 index 0000000..7a1860e --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart2.dts @@ -0,0 +1,32 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h6"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial2 = "/soc/serial@5000800"; + }; + }; + + fragment@1 { + target = <&pio>; + __overlay__ { + uart2_rts_cts: uart2_rts_cts { + pins = "PD21", "PD22"; + function = "uart2"; + }; + }; + }; + + fragment@2 { + target = <&uart2>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart2_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart3.dts b/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart3.dts new file mode 100644 index 0000000..38a59ac --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun50i/h6-uart3.dts @@ -0,0 +1,32 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h6"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial3 = "/soc/serial@05000c00"; + }; + }; + + fragment@1 { + target = <&pio>; + __overlay__ { + uart3_rts_cts: uart3_rts_cts { + pins = "PD25", "PD26"; + function = "uart3"; + }; + }; + }; + + fragment@2 { + target = <&uart3>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart3_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c0.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c0.dts new file mode 100644 index 0000000..b457ac7 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c0.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c0 = "/soc/i2c@01c2ac00"; + }; + }; + + fragment@1 { + target = <&i2c0>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c1.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c1.dts new file mode 100644 index 0000000..fd0928a --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c1.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c1 = "/soc/i2c@01c2b000"; + }; + }; + + fragment@1 { + target = <&i2c1>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c2.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c2.dts new file mode 100644 index 0000000..25b75b7 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-i2c2.dts @@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + i2c2 = "/soc/i2c@01c2b400"; + }; + }; + + fragment@1 { + target = <&i2c2>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart1.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart1.dts new file mode 100644 index 0000000..8a4f7e4 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart1.dts @@ -0,0 +1,22 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial1 = "/soc/serial@01c28400"; + }; + }; + + fragment@1 { + target = <&uart1>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart1_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart2.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart2.dts new file mode 100644 index 0000000..499a1b4 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart2.dts @@ -0,0 +1,22 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial2 = "/soc/serial@01c28800"; + }; + }; + + fragment@1 { + target = <&uart2>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart2_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart3.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart3.dts new file mode 100644 index 0000000..b5734c5 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-uart3.dts @@ -0,0 +1,22 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + serial3 = "/soc/serial@01c28c00"; + }; + }; + + fragment@1 { + target = <&uart3>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart3_pins>; + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost0.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost0.dts new file mode 100644 index 0000000..6bd8aed --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost0.dts @@ -0,0 +1,27 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target = <&ehci0>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@1 { + target = <&ohci0>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target = <&usbphy>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost1.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost1.dts new file mode 100644 index 0000000..4c7222b --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost1.dts @@ -0,0 +1,27 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target = <&ehci1>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@1 { + target = <&ohci1>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target = <&usbphy>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost2.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost2.dts new file mode 100644 index 0000000..2b83ec9 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost2.dts @@ -0,0 +1,27 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target = <&ehci2>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@1 { + target = <&ohci2>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target = <&usbphy>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost3.dts b/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost3.dts new file mode 100644 index 0000000..e2f28ab --- /dev/null +++ b/recipes-bsp/sunxi-overlays/files/sun8i/h3-usbhost3.dts @@ -0,0 +1,27 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun8i-h3"; + + fragment@0 { + target = <&ehci3>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@1 { + target = <&ohci3>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target = <&usbphy>; + __overlay__ { + status = "okay"; + }; + }; +}; diff --git a/recipes-bsp/sunxi-overlays/gen_builtin.sh b/recipes-bsp/sunxi-overlays/gen_builtin.sh new file mode 100755 index 0000000..83c33de --- /dev/null +++ b/recipes-bsp/sunxi-overlays/gen_builtin.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# helper script to generate sunxi-overlays-builtin.inc +OFILE="sunxi-overlays-builtin.inc" +echo "# generated by gen_builtin.sh" > $OFILE +for famd in $(ls -1d files/*/); do + fam=${famd##files/} + fam=${fam%%/} + echo "SRC_URI:${fam} = \" \\" >> $OFILE + for f in $(ls ${famd}*.dts); do + echo "file://$(basename $f) \\" >> $OFILE + done + echo "\"" >> $OFILE + families="$families|$fam" +done + +families=${families#|} +echo "COMPATIBLE_MACHINE = \"(${families})\"" >> $OFILE + diff --git a/recipes-bsp/sunxi-overlays/sunxi-overlays-builtin.inc b/recipes-bsp/sunxi-overlays/sunxi-overlays-builtin.inc new file mode 100644 index 0000000..1f762f6 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/sunxi-overlays-builtin.inc @@ -0,0 +1,38 @@ +# generated by gen_builtin.sh +SRC_URI:sun50i = " \ +file://h5-i2c0.dts \ +file://h5-i2c1.dts \ +file://h5-i2c2.dts \ +file://h5-uart1.dts \ +file://h5-uart2.dts \ +file://h5-uart3.dts \ +file://h5-usbhost0.dts \ +file://h5-usbhost1.dts \ +file://h5-usbhost2.dts \ +file://h6-i2c0.dts \ +file://h6-i2c1.dts \ +file://h6-i2c2.dts \ +file://h6-uart1.dts \ +file://h6-uart2.dts \ +file://h6-uart3.dts \ +" +SRC_URI:sun50i-h616 = " \ +file://h616-i2c0.dts \ +file://h616-i2c1.dts \ +file://h616-i2c2.dts \ +file://h616-uart1.dts \ +file://h616-uart2.dts \ +" +SRC_URI:sun8i = " \ +file://h3-i2c0.dts \ +file://h3-i2c1.dts \ +file://h3-i2c2.dts \ +file://h3-uart1.dts \ +file://h3-uart2.dts \ +file://h3-uart3.dts \ +file://h3-usbhost0.dts \ +file://h3-usbhost1.dts \ +file://h3-usbhost2.dts \ +file://h3-usbhost3.dts \ +" +COMPATIBLE_MACHINE = "(sun50i|sun50i-h616|sun8i)" diff --git a/recipes-bsp/sunxi-overlays/sunxi-overlays.bb b/recipes-bsp/sunxi-overlays/sunxi-overlays.bb new file mode 100644 index 0000000..dff17e1 --- /dev/null +++ b/recipes-bsp/sunxi-overlays/sunxi-overlays.bb @@ -0,0 +1,11 @@ + +DESCRIPTION = "Support for sunxi DT overlays" +LICENSE = "MIT" + + +SUNXI_OVERLAYS_ENABLE ??= "" + +require sunxi-overlays-builtin.inc + +inherit devicetree + diff --git a/recipes-bsp/u-boot/files/aarch64/boot.cmd b/recipes-bsp/u-boot/files/aarch64/boot.cmd index fa97399..cdbbb5d 100644 --- a/recipes-bsp/u-boot/files/aarch64/boot.cmd +++ b/recipes-bsp/u-boot/files/aarch64/boot.cmd @@ -1,11 +1,64 @@ -# Default to (primary) SD -rootdev=mmcblk0p2 +# boot.cmd with overlay support +# edit sunxienv.txt to add overlays + +setenv load_addr "0x45000000" +# Default env variables +setenv ov_error "n" +setenv rootdev "mmcblk${devnum}p2" +setenv earlycon "n" +setenv overlays + +echo "meta-sunxi boot devtype=${devtype} devnum=${devnum}" + +# Print boot source +itest.b *0x28 == 0x00 && echo "U-boot loaded from SD" +itest.b *0x28 == 0x01 && echo "U-boot loaded from NAND" +itest.b *0x28 == 0x02 && echo "U-boot loaded from eMMC or secondary SD" +itest.b *0x28 == 0x03 && echo "U-boot loaded from SPI" + +# Load sunxienv.txt +if test -e ${devtype} ${devnum} sunxienv.txt; then + load ${devtype} ${devnum} ${load_addr} sunxienv.txt + env import -t ${load_addr} ${filesize} + echo "sunxienv.txt loaded" +fi + + if itest.b *0x28 == 0x02 ; then # U-Boot loaded from eMMC or secondary SD so use it for rootfs too echo "U-boot loaded from eMMC or secondary SD" rootdev=mmcblk1p2 fi + +# bootargs +if test "${earlycon}" = "y"; then setenv extra "earlycon ${extra}"; fi setenv bootargs console=${console} console=tty1 root=/dev/${rootdev} rootwait panic=10 ${extra} -load mmc 0:1 ${fdt_addr_r} ${fdtfile} -load mmc 0:1 ${kernel_addr_r} Image + +# Load kernel +load ${devtype} ${devnum} ${kernel_addr_r} Image + +# load fdt +load ${devtype} ${devnum} ${fdt_addr_r} ${fdtfile} + +# apply overlays +if test -n "${overlays}"; then + fdt addr ${fdt_addr_r} + fdt resize 65536 + for ov in ${overlays}; do + if load ${devtype} ${devnum} ${load_addr} /dtbo/${ov}.dtbo; then + echo "Applying DT overlay ${ov}.dtbo" + fdt apply ${load_addr} || setenv ov_error "y" + else + setenv ov_error "y" + fi + done + + # Restore orginal fdt if overaly failed + if test "${ov_error}" = "y"; then + echo "Error in DT overaly resoring main DT" + load ${devtype} ${devnum} ${fdt_addr_r} ${fdtfile} + fi +fi + +# Finally boot withou intramfs booti ${kernel_addr_r} - ${fdt_addr_r} diff --git a/recipes-bsp/u-boot/files/arm/boot.cmd b/recipes-bsp/u-boot/files/arm/boot.cmd index 7b4ad7b..b411817 100644 --- a/recipes-bsp/u-boot/files/arm/boot.cmd +++ b/recipes-bsp/u-boot/files/arm/boot.cmd @@ -1,11 +1,64 @@ -# Default to (primary) SD -rootdev=mmcblk0p2 +# boot.cmd with overlay support +# edit sunxienv.txt to add overlays + +setenv load_addr "0x45000000" +# Default env variables +setenv ov_error "n" +setenv rootdev "mmcblk${devnum}p2" +setenv earlycon "n" +setenv overlays + +echo "meta-sunxi boot devtype=${devtype} devnum=${devnum}" + +# Print boot source +itest.b *0x28 == 0x00 && echo "U-boot loaded from SD" +itest.b *0x28 == 0x01 && echo "U-boot loaded from NAND" +itest.b *0x28 == 0x02 && echo "U-boot loaded from eMMC or secondary SD" +itest.b *0x28 == 0x03 && echo "U-boot loaded from SPI" + +# Load sunxienv.txt +if test -e ${devtype} ${devnum} sunxienv.txt; then + load ${devtype} ${devnum} ${load_addr} sunxienv.txt + env import -t ${load_addr} ${filesize} + echo "sunxienv.txt loaded" +fi + + if itest.b *0x28 == 0x02 ; then # U-Boot loaded from eMMC or secondary SD so use it for rootfs too echo "U-boot loaded from eMMC or secondary SD" rootdev=mmcblk1p2 fi + +# bootargs +if test "${earlycon}" = "y"; then setenv extra "earlycon ${extra}"; fi setenv bootargs console=${console} console=tty1 root=/dev/${rootdev} rootwait panic=10 ${extra} -load mmc 0:1 ${fdt_addr_r} ${fdtfile} || load mmc 0:1 ${fdt_addr_r} boot/${fdtfile} -load mmc 0:1 ${kernel_addr_r} zImage || load mmc 0:1 ${kernel_addr_r} boot/zImage || load mmc 0:1 ${kernel_addr_r} uImage || load mmc 0:1 ${kernel_addr_r} boot/uImage + +# load fdt +load ${devtype} ${devnum} ${fdt_addr_r} ${fdtfile} || load ${devtype} ${devnum} ${fdt_addr_r} boot/${fdtfile} + +# apply overlays +if test -n "${overlays}"; then + fdt addr ${fdt_addr_r} + fdt resize 65536 + for ov in ${overlays}; do + if load ${devtype} ${devnum} ${load_addr} /dtbo/${ov}.dtbo; then + echo "Applying DT overlay ${ov}.dtbo" + fdt apply ${load_addr} || setenv ov_error "y" + else + setenv ov_error "y" + fi + done + + # Restore orginal fdt if overaly failed + if test "${ov_error}" = "y"; then + echo "Error in DT overaly resoring main DT" + load ${devtype} ${devnum} ${fdt_addr_r} ${fdtfile} || load ${devtype} ${devnum} ${fdt_addr_r} boot/${fdtfile} + fi +fi + +# Load the kernel +load ${devtype} ${devnum} ${kernel_addr_r} zImage || load ${devtype} ${devnum} ${kernel_addr_r} boot/zImage || load ${devtype} ${devnum} ${kernel_addr_r} uImage || load ${devtype} ${devnum} ${kernel_addr_r} boot/uImage + +# Finally boot withou intramfs bootz ${kernel_addr_r} - ${fdt_addr_r} || bootm ${kernel_addr_r} - ${fdt_addr_r} diff --git a/recipes-bsp/u-boot/u-boot_%.bbappend b/recipes-bsp/u-boot/u-boot_%.bbappend index 8bf4a87..d353f24 100644 --- a/recipes-bsp/u-boot/u-boot_%.bbappend +++ b/recipes-bsp/u-boot/u-boot_%.bbappend @@ -28,3 +28,31 @@ do_compile_sun50i[depends] += "atf-sunxi:do_deploy" do_compile:append:sunxi() { ${B}/tools/mkimage -C none -A arm -T script -d ${WORKDIR}/boot.cmd ${WORKDIR}/${UBOOT_ENV_BINARY} } + +# Add custom env files + +do_install:append:sunxi() { + + if ${@bb.utils.contains('DISTRO_FEATURES','sunxi-env','false','true',d)}; then + return + fi + + echo "# sunxi boot parameters" > ${D}/boot/sunxienv.txt + echo "# extra=" >> ${D}/boot/sunxienv.txt + echo "overlays=${SUNXI_OVERLAYS_ENABLE}" >> ${D}/boot/sunxienv.txt + chmod 0644 ${D}/boot/sunxienv.txt + +} + +do_deploy:append:sunxi() { + + if ${@bb.utils.contains('DISTRO_FEATURES','sunxi-env','false','true',d)}; then + return + fi + + install -Dm 0644 ${D}/boot/sunxienv.txt ${DEPLOYDIR}/sunxienv.txt + +} + +FILES:${PN} += "${@bb.utils.contains('DISTRO_FEATURES','sunxi-env','/boot/sunxienv.txt','',d)}" +RDEPENDS:${PN}:append = " ${@ '' if (d.getVar('SUNXI_OVERLAYS_ENABLE') or "").strip() == "" else 'sunxi-overlays'}" diff --git a/recipes-kernel/linux/linux-mainline.inc b/recipes-kernel/linux/linux-mainline.inc index 9438208..c428b0e 100644 --- a/recipes-kernel/linux/linux-mainline.inc +++ b/recipes-kernel/linux/linux-mainline.inc @@ -16,6 +16,9 @@ DEPENDS += "rsync-native" # Pull in the devicetree files into the rootfs RDEPENDS_${KERNEL_PACKAGE_NAME}-base += "kernel-devicetree" +# if sunxi-env featture is enable devicetrees need to be compiled with symbols +KERNEL_DTC_FLAGS += " ${@bb.utils.contains('DISTRO_FEATURES','sunxi-env','-@ -H epapr','',d)}" + KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT}" S = "${WORKDIR}/linux-${PV}"