From patchwork Thu Feb 24 11:22:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 4213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA618C433F5 for ; Thu, 24 Feb 2022 11:23:53 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.8982.1645701832886894897 for ; Thu, 24 Feb 2022 03:23:53 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 78FEA106F; Thu, 24 Feb 2022 03:23:52 -0800 (PST) Received: from e125920.cambridge.arm.com (unknown [10.1.199.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E21123F70D; Thu, 24 Feb 2022 03:23:51 -0800 (PST) From: Peter Hoyes To: meta-arm@lists.yoctoproject.org Cc: diego.sueiro@arm.com, Peter Hoyes Subject: [PATCH honister 1/8] arm-bsp/fvp-baser-aemv8r64: Fix PL011 and SP805 register sizes Date: Thu, 24 Feb 2022 11:22:37 +0000 Message-Id: <20220224112244.1521611-2-peter.hoyes@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224112244.1521611-1-peter.hoyes@arm.com> References: <20220224112244.1521611-1-peter.hoyes@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 24 Feb 2022 11:23:53 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/meta-arm/message/3049 From: Peter Hoyes The Linux kernel expects the peripheral ID register to be just below the end of the address range, which for the PL011 and SP805 is at 0xFE0 not 0xFFE0, so set the size to 0x1000. Issue-Id: SCM-3881 Signed-off-by: Peter Hoyes Change-Id: Iada28e8192d72b1647822c33d13deffe507043b5 --- .../files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meta-arm-bsp/recipes-kernel/linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts b/meta-arm-bsp/recipes-kernel/linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts index dfc6f7e..4d6640a 100644 --- a/meta-arm-bsp/recipes-kernel/linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts +++ b/meta-arm-bsp/recipes-kernel/linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts @@ -111,7 +111,7 @@ uart@9c090000 { compatible = "arm,pl011", "arm,primecell"; - reg = <0x0 0x9c090000 0x0 0x10000>; + reg = <0x0 0x9c090000 0x0 0x1000>; interrupts = <0x0 5 0x4>; clocks = <&refclk24mhz>, <&refclk100mhz>; clock-names = "uartclk", "apb_pclk"; @@ -119,7 +119,7 @@ uart@9c0a0000 { compatible = "arm,pl011", "arm,primecell"; - reg = <0x0 0x9c0a0000 0x0 0x10000>; + reg = <0x0 0x9c0a0000 0x0 0x1000>; interrupts = <0x0 6 0x4>; clocks = <&refclk24mhz>, <&refclk100mhz>; clock-names = "uartclk", "apb_pclk"; @@ -127,7 +127,7 @@ uart@9c0b0000 { compatible = "arm,pl011", "arm,primecell"; - reg = <0x0 0x9c0b0000 0x0 0x10000>; + reg = <0x0 0x9c0b0000 0x0 0x1000>; interrupts = <0x0 7 0x4>; clocks = <&refclk24mhz>, <&refclk100mhz>; clock-names = "uartclk", "apb_pclk"; @@ -135,7 +135,7 @@ uart@9c0c0000 { compatible = "arm,pl011", "arm,primecell"; - reg = <0x0 0x9c0c0000 0x0 0x10000>; + reg = <0x0 0x9c0c0000 0x0 0x1000>; interrupts = <0x0 8 0x4>; clocks = <&refclk24mhz>, <&refclk100mhz>; clock-names = "uartclk", "apb_pclk"; @@ -143,7 +143,7 @@ wdt@9c0f0000 { compatible = "arm,sp805", "arm,primecell"; - reg = <0x0 0x9c0f0000 0x0 0x10000>; + reg = <0x0 0x9c0f0000 0x0 0x1000>; interrupts = <0x0 0 0x4>; clocks = <&refclk24mhz>, <&refclk100mhz>; clock-names = "wdog_clk", "apb_pclk"; From patchwork Thu Feb 24 11:22:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 4214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD39DC433F5 for ; Thu, 24 Feb 2022 11:24:01 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.8990.1645701837670340733 for ; Thu, 24 Feb 2022 03:23:57 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E7501106F; Thu, 24 Feb 2022 03:23:56 -0800 (PST) Received: from e125920.cambridge.arm.com (unknown [10.1.199.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5C4DD3F70D; Thu, 24 Feb 2022 03:23:56 -0800 (PST) From: Peter Hoyes To: meta-arm@lists.yoctoproject.org Cc: diego.sueiro@arm.com, Peter Hoyes Subject: [PATCH honister 2/8] arm/boot-wrapper-aarch64: Upgrade to newer revision Date: Thu, 24 Feb 2022 11:22:38 +0000 Message-Id: <20220224112244.1521611-3-peter.hoyes@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224112244.1521611-1-peter.hoyes@arm.com> References: <20220224112244.1521611-1-peter.hoyes@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 24 Feb 2022 11:24:01 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/meta-arm/message/3050 From: Peter Hoyes Upgrade boot-wrapper-aarch64 to 1044c77062573985f7c994c3b6cef5695f57e955 Hold back gem5 at 8d5a765251d9113c3c0f9fa14de42a9e7486fe8a in bbappend. Issue-Id: SCM-3871 Signed-off-by: Peter Hoyes Change-Id: Ia5ccca2234dd117d530970f9f90469dacbb778e3 --- .../boot-wrapper-aarch64/boot-wrapper-aarch64_git.bb | 2 +- .../boot-wrapper-aarch64/boot-wrapper-aarch64_%.bbappend | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/meta-arm/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64_git.bb b/meta-arm/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64_git.bb index c723517..2f375a4 100644 --- a/meta-arm/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64_git.bb +++ b/meta-arm/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64_git.bb @@ -4,7 +4,7 @@ LICENSE = "BSD" LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=bb63326febfb5fb909226c8e7ebcef5c" SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git" -SRCREV = "8d5a765251d9113c3c0f9fa14de42a9e7486fe8a" +SRCREV = "1044c77062573985f7c994c3b6cef5695f57e955" PV = "git${SRCPV}" diff --git a/meta-gem5/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64_%.bbappend b/meta-gem5/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64_%.bbappend index 57e6b53..3dd2cba 100644 --- a/meta-gem5/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64_%.bbappend +++ b/meta-gem5/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64_%.bbappend @@ -11,3 +11,6 @@ BOOT_WRAPPER_AARCH64_DEVICETREE:gem5-arm64 = "gem5-aarch64.dtb" DEPLOY_DEPEND_LIST ?= "" DEPLOY_DEPEND_LIST:gem5-arm64 = " gem5-aarch64-dtb:do_deploy" do_deploy[depends] += "${DEPLOY_DEPEND_LIST}" + +# The base recipe has been upgraded, so hold back at known working revision +SRCREV = "8d5a765251d9113c3c0f9fa14de42a9e7486fe8a" From patchwork Thu Feb 24 11:22:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 4220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7B7BC433FE for ; Thu, 24 Feb 2022 11:24:01 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9093.1645701840668875188 for ; Thu, 24 Feb 2022 03:24:01 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3A0AA106F; Thu, 24 Feb 2022 03:24:00 -0800 (PST) Received: from e125920.cambridge.arm.com (unknown [10.1.199.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A4243F70D; Thu, 24 Feb 2022 03:23:58 -0800 (PST) From: Peter Hoyes To: meta-arm@lists.yoctoproject.org Cc: diego.sueiro@arm.com, Peter Hoyes Subject: [PATCH honister 3/8] arm-bsp/boot-wrapper-aarch64: Update patches for fvp-baser-aemv8r64 Date: Thu, 24 Feb 2022 11:22:39 +0000 Message-Id: <20220224112244.1521611-4-peter.hoyes@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224112244.1521611-1-peter.hoyes@arm.com> References: <20220224112244.1521611-1-peter.hoyes@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 24 Feb 2022 11:24:01 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/meta-arm/message/3051 From: Peter Hoyes Update the SRCREV to a more recent revision for the fvp-baser-aemv8r64. Update the machine-specific patches, which makes the following changes: * Add PSCI services to /memreserve/ in the device tree using libfdt. * Add --enable-keep-el option, which allows boot-wrapper-aarch64 to boot the next stage at the same exception level. * Update the counter frequency to 100 MHz. Issue-Id: SCM-3871 Signed-off-by: Peter Hoyes Change-Id: I41843e958cf629d69de644bb57b660fb542fc8b7 --- ...oot-wrapper-aarch64-fvp-baser-aemv8r64.inc | 19 +- ...M_SYS-config-by-auto-detect-dtb-node.patch | 67 - ...abels-and-prepare-for-lower-EL-booti.patch | 135 + ...0002-aarch64-Prepare-for-EL1-booting.patch | 48 + ...4-Introduce-EL2-boot-code-for-v8-r64.patch | 314 - ...aarch64-Prepare-for-lower-EL-booting.patch | 55 + ...04-gic-v3-Prepare-for-gicv3-with-EL2.patch | 105 + ...aarch64-Prepare-for-booting-with-EL2.patch | 63 + ...ce-EL2-boot-code-for-Armv8-R-AArch64.patch | 182 + ...-psci-to-choose-between-smc-and-hvc.patch} | 42 +- ...4-Disable-CNTPCT_EL0-trap-for-v8-R64.patch | 48 + .../0009-lds-Mark-the-mem-range.patch | 38 + .../0010-common-Introduce-the-libfdt.patch | 6044 +++++++++++++++++ ...-common-Add-essential-libc-functions.patch | 101 + ...dd-the-libfdt-to-the-Makefile-system.patch | 61 + .../0013-platform-Add-print_hex-func.patch | 67 + ...4-common-Add-mem-usage-to-memreserve.patch | 96 + ...dd-the-enable-keep-el-compile-option.patch | 102 + ...efile-Change-COUNTER_FREQ-to-100-MHz.patch | 34 + 19 files changed, 7219 insertions(+), 402 deletions(-) delete mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0001-Decouple-V2M_SYS-config-by-auto-detect-dtb-node.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0001-aarch64-Rename-labels-and-prepare-for-lower-EL-booti.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0002-aarch64-Prepare-for-EL1-booting.patch delete mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0002-arch64-Introduce-EL2-boot-code-for-v8-r64.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0003-aarch64-Prepare-for-lower-EL-booting.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0004-gic-v3-Prepare-for-gicv3-with-EL2.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0005-aarch64-Prepare-for-booting-with-EL2.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0006-aarch64-Introduce-EL2-boot-code-for-Armv8-R-AArch64.patch rename meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/{0003-Allow-enable-psci-to-choose-between-smc-and-hvc.patch => 0007-Allow-enable-psci-to-choose-between-smc-and-hvc.patch} (71%) create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0008-aarch64-Disable-CNTPCT_EL0-trap-for-v8-R64.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0009-lds-Mark-the-mem-range.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0010-common-Introduce-the-libfdt.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0011-common-Add-essential-libc-functions.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0012-Makefile-Add-the-libfdt-to-the-Makefile-system.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0013-platform-Add-print_hex-func.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0014-common-Add-mem-usage-to-memreserve.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0015-boot-Add-the-enable-keep-el-compile-option.patch create mode 100644 meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0016-Makefile-Change-COUNTER_FREQ-to-100-MHz.patch diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64-fvp-baser-aemv8r64.inc b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64-fvp-baser-aemv8r64.inc index f1bf614..628571f 100644 --- a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64-fvp-baser-aemv8r64.inc +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64-fvp-baser-aemv8r64.inc @@ -2,9 +2,22 @@ COMPATIBLE_MACHINE = "fvp-baser-aemv8r64" FILESEXTRAPATHS:prepend := "${THISDIR}/files/${MACHINE}:" SRC_URI:append = " \ - file://0001-Decouple-V2M_SYS-config-by-auto-detect-dtb-node.patch \ - file://0002-arch64-Introduce-EL2-boot-code-for-v8-r64.patch \ - file://0003-Allow-enable-psci-to-choose-between-smc-and-hvc.patch \ + file://0001-aarch64-Rename-labels-and-prepare-for-lower-EL-booti.patch \ + file://0002-aarch64-Prepare-for-EL1-booting.patch \ + file://0003-aarch64-Prepare-for-lower-EL-booting.patch \ + file://0004-gic-v3-Prepare-for-gicv3-with-EL2.patch \ + file://0005-aarch64-Prepare-for-booting-with-EL2.patch \ + file://0006-aarch64-Introduce-EL2-boot-code-for-Armv8-R-AArch64.patch \ + file://0007-Allow-enable-psci-to-choose-between-smc-and-hvc.patch \ + file://0008-aarch64-Disable-CNTPCT_EL0-trap-for-v8-R64.patch \ + file://0009-lds-Mark-the-mem-range.patch \ + file://0010-common-Introduce-the-libfdt.patch \ + file://0011-common-Add-essential-libc-functions.patch \ + file://0012-Makefile-Add-the-libfdt-to-the-Makefile-system.patch \ + file://0013-platform-Add-print_hex-func.patch \ + file://0014-common-Add-mem-usage-to-memreserve.patch \ + file://0015-boot-Add-the-enable-keep-el-compile-option.patch \ + file://0016-Makefile-Change-COUNTER_FREQ-to-100-MHz.patch \ " BOOT_WRAPPER_AARCH64_CMDLINE = "\ diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0001-Decouple-V2M_SYS-config-by-auto-detect-dtb-node.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0001-Decouple-V2M_SYS-config-by-auto-detect-dtb-node.patch deleted file mode 100644 index f3e03c4..0000000 --- a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0001-Decouple-V2M_SYS-config-by-auto-detect-dtb-node.patch +++ /dev/null @@ -1,67 +0,0 @@ -From 7b8c821c22929cd2d3532f937672fcf05dc7d5d0 Mon Sep 17 00:00:00 2001 -Message-Id: <7b8c821c22929cd2d3532f937672fcf05dc7d5d0.1616744115.git.diego.sueiro@arm.com> -From: Jaxson Han -Date: Thu, 25 Mar 2021 12:35:13 +0800 -Subject: [PATCH 1/2] Decouple V2M_SYS config by auto-detect dtb node - -An auto-detect switch is added to make it an option to enable/disable -'arm,vexpress-sysreg', because not all platforms support this feature. - -Issue-ID: SCM-2221 -Signed-off-by: Jaxson Han -Change-Id: Ib8738aa62ca3902f7bdae2ad9a5a63aa2d225abf - -Upstream-Status: Pending -Signed-off-by: Diego Sueiro ---- - Makefile.am | 2 +- - platform.c | 4 ++++ - 2 files changed, 5 insertions(+), 1 deletion(-) - -diff --git a/Makefile.am b/Makefile.am -index af694b7..e131207 100644 ---- a/Makefile.am -+++ b/Makefile.am -@@ -19,7 +19,7 @@ NR_CPUS := $(shell echo $(CPU_IDS) | tr ',' ' ' | wc -w) - DEFINES = -DCNTFRQ=$(CNTFRQ) - DEFINES += -DCPU_IDS=$(CPU_IDS) - DEFINES += -DNR_CPUS=$(NR_CPUS) --DEFINES += -DSYSREGS_BASE=$(SYSREGS_BASE) -+DEFINES += $(if $(SYSREGS_BASE), -DSYSREGS_BASE=$(SYSREGS_BASE), ) - DEFINES += -DUART_BASE=$(UART_BASE) - DEFINES += -DSTACK_SIZE=256 - -diff --git a/platform.c b/platform.c -index a528a55..d11f568 100644 ---- a/platform.c -+++ b/platform.c -@@ -23,10 +23,12 @@ - - #define PL011(reg) ((void *)UART_BASE + PL011_##reg) - -+#ifdef SYSREGS_BASE - #define V2M_SYS_CFGDATA 0xa0 - #define V2M_SYS_CFGCTRL 0xa4 - - #define V2M_SYS(reg) ((void *)SYSREGS_BASE + V2M_SYS_##reg) -+#endif - - static void print_string(const char *str) - { -@@ -59,6 +61,7 @@ void init_platform(void) - - print_string("Boot-wrapper v0.2\r\n\r\n"); - -+#ifdef SYSREGS_BASE - /* - * CLCD output site MB - */ -@@ -66,4 +69,5 @@ void init_platform(void) - /* START | WRITE | MUXFPGA | SITE_MB */ - raw_writel((1 << 31) | (1 << 30) | (7 << 20) | (0 << 16), - V2M_SYS(CFGCTRL)); -+#endif - } --- -2.17.1 - diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0001-aarch64-Rename-labels-and-prepare-for-lower-EL-booti.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0001-aarch64-Rename-labels-and-prepare-for-lower-EL-booti.patch new file mode 100644 index 0000000..566070a --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0001-aarch64-Rename-labels-and-prepare-for-lower-EL-booti.patch @@ -0,0 +1,135 @@ +From 3e7cfbe39a2a053d2a6b0d928cc172ed9d1c6da8 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 25 May 2021 07:25:00 +0100 +Subject: [PATCH] aarch64: Rename labels and prepare for lower EL booting + +Prepare for booting from lower EL. Rename *_el3 relavant labels with +*_el_max and *_no_el3 with *_keep_el. Since the original _no_el3 means +"We neither do init sequence at this highest EL nor drop to lower EL +when entering to kernel", we rename it with _keep_el to make it more +clear for lower EL initialisation. + +Upstream-Status: Pending +Signed-off-by: Jaxson Han +--- + arch/aarch64/boot.S | 28 ++++++++++++++++++++-------- + arch/aarch64/psci.S | 9 +++++---- + arch/aarch64/spin.S | 4 ++-- + 3 files changed, 27 insertions(+), 14 deletions(-) + +diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S +index 27ba449..84e1646 100644 +--- a/arch/aarch64/boot.S ++++ b/arch/aarch64/boot.S +@@ -21,18 +21,30 @@ ASM_FUNC(_start) + + /* + * EL3 initialisation ++ * Boot sequence ++ * If CurrentEL == EL3, then goto EL3 initialisation and drop to ++ * lower EL before entering the kernel. ++ * Else, no initialisation and keep the current EL before ++ * entering the kernel. + */ + mrs x0, CurrentEL + cmp x0, #CURRENTEL_EL3 +- b.eq 1f ++ b.eq el3_init + ++ /* ++ * We stay in the current EL for entering the kernel ++ */ + mov w0, #1 +- ldr x1, =flag_no_el3 ++ ldr x1, =flag_keep_el + str w0, [x1] + +- b start_no_el3 ++ b start_keep_el + +-1: mov x0, #0x30 // RES1 ++ /* ++ * EL3 initialisation ++ */ ++el3_init: ++ mov x0, #0x30 // RES1 + orr x0, x0, #(1 << 0) // Non-secure EL1 + orr x0, x0, #(1 << 8) // HVC enable + +@@ -124,7 +136,7 @@ ASM_FUNC(_start) + + bl gic_secure_init + +- b start_el3 ++ b start_el_max + + err_invalid_id: + b . +@@ -151,7 +163,7 @@ ASM_FUNC(jump_kernel) + bl find_logical_id + bl setup_stack // Reset stack pointer + +- ldr w0, flag_no_el3 ++ ldr w0, flag_keep_el + cmp w0, #0 // Prepare Z flag + + mov x0, x20 +@@ -160,7 +172,7 @@ ASM_FUNC(jump_kernel) + mov x3, x23 + + b.eq 1f +- br x19 // No EL3 ++ br x19 // Keep current EL + + 1: mov x4, #SPSR_KERNEL + +@@ -178,5 +190,5 @@ ASM_FUNC(jump_kernel) + + .data + .align 3 +-flag_no_el3: ++flag_keep_el: + .long 0 +diff --git a/arch/aarch64/psci.S b/arch/aarch64/psci.S +index 8bd224b..7b8919a 100644 +--- a/arch/aarch64/psci.S ++++ b/arch/aarch64/psci.S +@@ -79,7 +79,7 @@ smc_exit: + ldp x18, x19, [sp], #16 + eret + +-ASM_FUNC(start_el3) ++ASM_FUNC(start_el_max) + ldr x0, =vector + bl setup_vector + +@@ -89,10 +89,11 @@ ASM_FUNC(start_el3) + b psci_first_spin + + /* +- * This PSCI implementation requires EL3. Without EL3 we'll only boot the +- * primary cpu, all others will be trapped in an infinite loop. ++ * This PSCI implementation requires the highest EL(EL3 or Armv8-R EL2). ++ * Without the highest EL, we'll only boot the primary cpu, all othersr ++ * will be trapped in an infinite loop. + */ +-ASM_FUNC(start_no_el3) ++ASM_FUNC(start_keep_el) + cpuid x0, x1 + bl find_logical_id + cbz x0, psci_first_spin +diff --git a/arch/aarch64/spin.S b/arch/aarch64/spin.S +index 1ea1c0b..bfb1d47 100644 +--- a/arch/aarch64/spin.S ++++ b/arch/aarch64/spin.S +@@ -12,8 +12,8 @@ + + .text + +-ASM_FUNC(start_el3) +-ASM_FUNC(start_no_el3) ++ASM_FUNC(start_el_max) ++ASM_FUNC(start_keep_el) + cpuid x0, x1 + bl find_logical_id + diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0002-aarch64-Prepare-for-EL1-booting.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0002-aarch64-Prepare-for-EL1-booting.patch new file mode 100644 index 0000000..46447b8 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0002-aarch64-Prepare-for-EL1-booting.patch @@ -0,0 +1,48 @@ +From 26f9b5354c2de9cc052531096ff92b04c3a3846f Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 25 May 2021 07:25:00 +0100 +Subject: [PATCH] aarch64: Prepare for EL1 booting + +When booting from EL1, add a check and skip the init of +sctlr_el2 in jump_kernel + +Upstream-Status: Pending +Signed-off-by: Jaxson Han +Reviewed-by: Andre Przywara +--- + arch/aarch64/boot.S | 6 +++++- + arch/aarch64/include/asm/cpu.h | 1 + + 2 files changed, 6 insertions(+), 1 deletion(-) + +diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S +index 84e1646..b589744 100644 +--- a/arch/aarch64/boot.S ++++ b/arch/aarch64/boot.S +@@ -156,10 +156,14 @@ ASM_FUNC(jump_kernel) + ldr x0, =SCTLR_EL1_KERNEL + msr sctlr_el1, x0 + ++ mrs x0, CurrentEL ++ cmp x0, #CURRENTEL_EL2 ++ b.lt 1f ++ + ldr x0, =SCTLR_EL2_KERNEL + msr sctlr_el2, x0 + +- cpuid x0, x1 ++1: cpuid x0, x1 + bl find_logical_id + bl setup_stack // Reset stack pointer + +diff --git a/arch/aarch64/include/asm/cpu.h b/arch/aarch64/include/asm/cpu.h +index 63eb1c3..b1003f4 100644 +--- a/arch/aarch64/include/asm/cpu.h ++++ b/arch/aarch64/include/asm/cpu.h +@@ -11,6 +11,7 @@ + + #define MPIDR_ID_BITS 0xff00ffffff + ++#define CURRENTEL_EL2 (2 << 2) + #define CURRENTEL_EL3 (3 << 2) + + /* diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0002-arch64-Introduce-EL2-boot-code-for-v8-r64.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0002-arch64-Introduce-EL2-boot-code-for-v8-r64.patch deleted file mode 100644 index 5d039b2..0000000 --- a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0002-arch64-Introduce-EL2-boot-code-for-v8-r64.patch +++ /dev/null @@ -1,314 +0,0 @@ -From 81fcc5cc80c9c3c812d92000b9116f6a02ff7e6c Mon Sep 17 00:00:00 2001 -Message-Id: <81fcc5cc80c9c3c812d92000b9116f6a02ff7e6c.1616744115.git.diego.sueiro@arm.com> -In-Reply-To: <7b8c821c22929cd2d3532f937672fcf05dc7d5d0.1616744115.git.diego.sueiro@arm.com> -References: <7b8c821c22929cd2d3532f937672fcf05dc7d5d0.1616744115.git.diego.sueiro@arm.com> -From: Jaxson Han -Date: Thu, 25 Mar 2021 12:47:02 +0800 -Subject: [PATCH 2/2] arch64: Introduce EL2 boot code for v8-r64 - -The v8-r64 boots from EL2 mode. In order to boot linux, EL2 boot mode -is needed. Because there is no MMU supported for v8-r64 under EL2 mode, -bootwrapper needs to switch to EL1 mode when jumpping to the kernel. - -Some register in gic-v3.h need to be auto-detected. - -Issue-ID: SCM-2221 -Signed-off-by: Jaxson Han -Change-Id: I52ca3f045f1ab50f32945420144752f396d95193 - -Upstream-Status: Pending -Signed-off-by: Diego Sueiro ---- - arch/aarch64/boot.S | 76 +++++++++++++++++++++++++++---- - arch/aarch64/include/asm/cpu.h | 3 ++ - arch/aarch64/include/asm/gic-v3.h | 23 ++++++++-- - arch/aarch64/psci.S | 13 +++--- - arch/aarch64/spin.S | 8 ++-- - arch/aarch64/utils.S | 8 ++++ - 6 files changed, 110 insertions(+), 21 deletions(-) - -diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S -index e47cf59..5c3eb73 100644 ---- a/arch/aarch64/boot.S -+++ b/arch/aarch64/boot.S -@@ -22,20 +22,30 @@ _start: - bl setup_stack - - /* -- * EL3 initialisation -+ * Boot sequence -+ * If EL3, goto EL3 initialisation -+ * If EL2 && id_aa64mmfr0_el1.MSA == 0xf, do Armv8r initialisation -+ * Else no initialisation sequence - */ - mrs x0, CurrentEL - cmp x0, #CURRENTEL_EL3 -- b.eq 1f -+ beq el3_init -+ cmp x0, #CURRENTEL_EL2 -+ beq el2_init - -+no_el_max: - mov w0, #1 - ldr x1, =flag_no_el3 - str w0, [x1] - - bl setup_stack -- b start_no_el3 -+ b start_no_el_max - --1: mov x0, #0x30 // RES1 -+ /* -+ * EL3 initialisation -+ */ -+el3_init: -+ mov x0, #0x30 // RES1 - orr x0, x0, #(1 << 0) // Non-secure EL1 - orr x0, x0, #(1 << 8) // HVC enable - -@@ -93,14 +103,54 @@ _start: - mov x0, #ZCR_EL3_LEN_MASK // SVE: Enable full vector len - msr ZCR_EL3, x0 // for EL2. - --1: -+ mov w0, #SPSR_KERNEL -+ ldr x1, =spsr_to_elx -+ str w0, [x1] -+ b el_max_init -+ -+ /* -+ * EL2 Armv8r initialisation -+ */ -+el2_init: -+ /* Detect Armv8r */ -+ mrs x1, id_aa64mmfr0_el1 -+ ubfx x1, x1, #48, #4 // MSA -+ cmp x1, 0xf // 0xf means Armv8r -+ bne no_el_max -+ -+ mrs x0, midr_el1 -+ msr vpidr_el2, x0 -+ -+ mrs x0, mpidr_el1 -+ msr vmpidr_el2, x0 -+ -+ mov x0, #(1 << 31) // VTCR_MSA: VMSAv8-64 support -+ msr vtcr_el2, x0 -+ -+ /* Enable pointer authentication if present */ -+ mrs x1, id_aa64isar1_el1 -+ ldr x2, =(((0xff) << 24) | (0xff << 4)) -+ and x1, x1, x2 -+ cbz x1, 1f -+ -+ mrs x0, hcr_el2 -+ orr x0, x0, #(1 << 40) // AP key enable -+ orr x0, x0, #(1 << 41) // AP insn enable -+ msr hcr_el2, x0 -+ -+1: isb -+ mov w0, #SPSR_KERNEL_EL1 -+ ldr x1, =spsr_to_elx -+ str w0, [x1] -+ b el_max_init -+ -+el_max_init: - ldr x0, =CNTFRQ - msr cntfrq_el0, x0 - - bl gic_secure_init - -- b start_el3 -- -+ b start_el_max - err_invalid_id: - b . - -@@ -137,7 +187,7 @@ jump_kernel: - b.eq 1f - br x19 // No EL3 - --1: mov x4, #SPSR_KERNEL -+1: ldr w4, spsr_to_elx - - /* - * If bit 0 of the kernel address is set, we're entering in AArch32 -@@ -145,13 +195,23 @@ jump_kernel: - */ - bfi x4, x19, #5, #1 - -+ mrs x18, CurrentEL -+ cmp x18, #CURRENTEL_EL2 -+ b.eq 1f -+ - msr elr_el3, x19 - msr spsr_el3, x4 - eret - -+1: msr elr_el2, x19 -+ msr spsr_el2, x4 -+ eret -+ - .ltorg - - .data - .align 3 - flag_no_el3: - .long 0 -+spsr_to_elx: -+ .long 0 -diff --git a/arch/aarch64/include/asm/cpu.h b/arch/aarch64/include/asm/cpu.h -index ccb5397..2b3a0a4 100644 ---- a/arch/aarch64/include/asm/cpu.h -+++ b/arch/aarch64/include/asm/cpu.h -@@ -11,6 +11,7 @@ - - #define MPIDR_ID_BITS 0xff00ffffff - -+#define CURRENTEL_EL2 (2 << 2) - #define CURRENTEL_EL3 (3 << 2) - - /* -@@ -24,6 +25,7 @@ - #define SPSR_I (1 << 7) /* IRQ masked */ - #define SPSR_F (1 << 6) /* FIQ masked */ - #define SPSR_T (1 << 5) /* Thumb */ -+#define SPSR_EL1H (5 << 0) /* EL1 Handler mode */ - #define SPSR_EL2H (9 << 0) /* EL2 Handler mode */ - #define SPSR_HYP (0x1a << 0) /* M[3:0] = hyp, M[4] = AArch32 */ - -@@ -42,6 +44,7 @@ - #else - #define SCTLR_EL1_RESET SCTLR_EL1_RES1 - #define SPSR_KERNEL (SPSR_A | SPSR_D | SPSR_I | SPSR_F | SPSR_EL2H) -+#define SPSR_KERNEL_EL1 (SPSR_A | SPSR_D | SPSR_I | SPSR_F | SPSR_EL1H) - #endif - - #ifndef __ASSEMBLY__ -diff --git a/arch/aarch64/include/asm/gic-v3.h b/arch/aarch64/include/asm/gic-v3.h -index e743c02..f8ddb27 100644 ---- a/arch/aarch64/include/asm/gic-v3.h -+++ b/arch/aarch64/include/asm/gic-v3.h -@@ -15,21 +15,38 @@ - #define ICC_CTLR_EL3 "S3_6_C12_C12_4" - #define ICC_PMR_EL1 "S3_0_C4_C6_0" - -+static inline uint32_t current_el(void) -+{ -+ uint32_t val; -+ -+ asm volatile ("mrs %0, CurrentEL" : "=r" (val)); -+ return val; -+} -+ - static inline uint32_t gic_read_icc_sre(void) - { - uint32_t val; -- asm volatile ("mrs %0, " ICC_SRE_EL3 : "=r" (val)); -+ -+ if(current_el() == CURRENTEL_EL3) -+ asm volatile ("mrs %0, " ICC_SRE_EL3 : "=r" (val)); -+ else -+ asm volatile ("mrs %0, " ICC_SRE_EL2 : "=r" (val)); -+ - return val; - } - - static inline void gic_write_icc_sre(uint32_t val) - { -- asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val)); -+ if(current_el() == CURRENTEL_EL3) -+ asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val)); -+ else -+ asm volatile ("msr " ICC_SRE_EL2 ", %0" : : "r" (val)); - } - - static inline void gic_write_icc_ctlr(uint32_t val) - { -- asm volatile ("msr " ICC_CTLR_EL3 ", %0" : : "r" (val)); -+ if(current_el() == CURRENTEL_EL3) -+ asm volatile ("msr " ICC_CTLR_EL3 ", %0" : : "r" (val)); - } - - #endif -diff --git a/arch/aarch64/psci.S b/arch/aarch64/psci.S -index 01ebe7d..0681d5e 100644 ---- a/arch/aarch64/psci.S -+++ b/arch/aarch64/psci.S -@@ -45,8 +45,8 @@ vector: - - .text - -- .globl start_no_el3 -- .globl start_el3 -+ .globl start_no_el_max -+ .globl start_el_max - - err_exception: - b err_exception -@@ -101,7 +101,7 @@ smc_exit: - eret - - --start_el3: -+start_el_max: - ldr x0, =vector - bl setup_vector - -@@ -111,10 +111,11 @@ start_el3: - b psci_first_spin - - /* -- * This PSCI implementation requires EL3. Without EL3 we'll only boot the -- * primary cpu, all others will be trapped in an infinite loop. -+ * This PSCI implementation requires EL3 or AArch64-R EL2. Without EL max -+ * we'll only boot the primary cpu, all others will be trapped in an infinite -+ * loop. - */ --start_no_el3: -+start_no_el_max: - cpuid x0, x1 - bl find_logical_id - cbz x0, psci_first_spin -diff --git a/arch/aarch64/spin.S b/arch/aarch64/spin.S -index 72603cf..fa1d657 100644 ---- a/arch/aarch64/spin.S -+++ b/arch/aarch64/spin.S -@@ -11,11 +11,11 @@ - - .text - -- .globl start_no_el3 -- .globl start_el3 -+ .globl start_no_el_max -+ .globl start_el_max - --start_el3: --start_no_el3: -+start_el_max: -+start_no_el_max: - cpuid x0, x1 - bl find_logical_id - -diff --git a/arch/aarch64/utils.S b/arch/aarch64/utils.S -index ae22ea7..2a63fa7 100644 ---- a/arch/aarch64/utils.S -+++ b/arch/aarch64/utils.S -@@ -41,6 +41,14 @@ find_logical_id: - * x0: vector address - */ - setup_vector: -+ mrs x1, CurrentEL -+ cmp x1, #CURRENTEL_EL2 -+ b.eq 1f -+ - msr VBAR_EL3, x0 - isb - ret -+ -+1: msr VBAR_EL2, x0 -+ isb -+ ret --- -2.17.1 - diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0003-aarch64-Prepare-for-lower-EL-booting.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0003-aarch64-Prepare-for-lower-EL-booting.patch new file mode 100644 index 0000000..db81355 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0003-aarch64-Prepare-for-lower-EL-booting.patch @@ -0,0 +1,55 @@ +From ce628de7699dd6401ddf713efaa49872e2733619 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 25 May 2021 07:25:00 +0100 +Subject: [PATCH] aarch64: Prepare for lower EL booting + +Save SPSR_KERNEL into spsr_to_elx during el3_init. +The jump_kernel will load spsr_to_elx into spsr_el3. + +This change will make it easier to control whether drop to lower EL +before jumping to the kernel. + +Upstream-Status: Pending +Signed-off-by: Jaxson Han +Reviewed-by: Andre Przywara +--- + arch/aarch64/boot.S | 15 +++++++++++++-- + 1 file changed, 13 insertions(+), 2 deletions(-) + +diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S +index b589744..6b45afc 100644 +--- a/arch/aarch64/boot.S ++++ b/arch/aarch64/boot.S +@@ -130,7 +130,16 @@ el3_init: + mov x0, #ZCR_EL3_LEN_MASK // SVE: Enable full vector len + msr ZCR_EL3, x0 // for EL2. + +-1: ++ /* ++ * Save SPSR_KERNEL into spsr_to_elx. ++ * The jump_kernel will load spsr_to_elx into spsr_el3 ++ */ ++1: mov w0, #SPSR_KERNEL ++ ldr x1, =spsr_to_elx ++ str w0, [x1] ++ b el_max_init ++ ++el_max_init: + ldr x0, =COUNTER_FREQ + msr cntfrq_el0, x0 + +@@ -178,7 +187,7 @@ ASM_FUNC(jump_kernel) + b.eq 1f + br x19 // Keep current EL + +-1: mov x4, #SPSR_KERNEL ++1: ldr w4, spsr_to_elx + + /* + * If bit 0 of the kernel address is set, we're entering in AArch32 +@@ -196,3 +205,5 @@ ASM_FUNC(jump_kernel) + .align 3 + flag_keep_el: + .long 0 ++spsr_to_elx: ++ .long 0 diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0004-gic-v3-Prepare-for-gicv3-with-EL2.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0004-gic-v3-Prepare-for-gicv3-with-EL2.patch new file mode 100644 index 0000000..e10182e --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0004-gic-v3-Prepare-for-gicv3-with-EL2.patch @@ -0,0 +1,105 @@ +From 483d363bf825082b6db6de3c57d169e741861891 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 25 May 2021 07:25:00 +0100 +Subject: [PATCH] gic-v3: Prepare for gicv3 with EL2 + +This is a preparation for allowing boot-wrapper configuring the gicv3 +with EL2. + +When confiuring with EL2, since there is no ICC_CTLR_EL2, the +ICC_CTLR_EL3 cannot be replaced with ICC_CTLR_EL2 simply. +See [https://developer.arm.com/documentation/ihi0069/latest/]. + +As the caller, gic_secure_init expects the ICC_CTLR to be written, +we change the function into gic_init_icc_ctlr(). In the GIC spec, +the r/w bits in this register ([6:0]) either affect EL3 IRQ routing +(not applicable since no EL3), non-secure IRQ handling (not applicable +since only secure state in Armv8-R aarch64), or are aliased to +ICC_CTLR_EL1 bits. +So, based on this, the new gic_init_icc_ctlr() would be: +When currentEL is EL3, init ICC_CTLR_EL3 as before. +When currentEL is not EL3, init ICC_CTLR_EL1 with ICC_CTLR_EL1_RESET. + +Upstream-Status: Pending +Signed-off-by: Jaxson Han +Reviewed-by: Andre Przywara +--- + arch/aarch32/include/asm/gic-v3.h | 7 +++++++ + arch/aarch64/include/asm/gic-v3.h | 23 ++++++++++++++++++++--- + common/gic-v3.c | 2 +- + 3 files changed, 28 insertions(+), 4 deletions(-) + +diff --git a/arch/aarch32/include/asm/gic-v3.h b/arch/aarch32/include/asm/gic-v3.h +index 65f38de..11e7bc7 100644 +--- a/arch/aarch32/include/asm/gic-v3.h ++++ b/arch/aarch32/include/asm/gic-v3.h +@@ -9,6 +9,8 @@ + #ifndef __ASM_AARCH32_GICV3_H + #define __ASM_AARCH32_GICV3_H + ++#define ICC_CTLR_RESET (0UL) ++ + static inline void gic_write_icc_sre(uint32_t val) + { + asm volatile ("mcr p15, 6, %0, c12, c12, 5" : : "r" (val)); +@@ -19,4 +21,9 @@ static inline void gic_write_icc_ctlr(uint32_t val) + asm volatile ("mcr p15, 6, %0, c12, c12, 4" : : "r" (val)); + } + ++static inline void gic_init_icc_ctlr() ++{ ++ gic_write_icc_ctlr(ICC_CTLR_RESET); ++} ++ + #endif +diff --git a/arch/aarch64/include/asm/gic-v3.h b/arch/aarch64/include/asm/gic-v3.h +index 5b32380..090ab0b 100644 +--- a/arch/aarch64/include/asm/gic-v3.h ++++ b/arch/aarch64/include/asm/gic-v3.h +@@ -15,14 +15,31 @@ + #define ICC_CTLR_EL3 "S3_6_C12_C12_4" + #define ICC_PMR_EL1 "S3_0_C4_C6_0" + ++#define ICC_CTLR_EL3_RESET (0UL) ++#define ICC_CTLR_EL1_RESET (0UL) ++ ++static inline uint32_t current_el(void) ++{ ++ uint32_t val; ++ ++ asm volatile ("mrs %0, CurrentEL" : "=r" (val)); ++ return val; ++} ++ + static inline void gic_write_icc_sre(uint32_t val) + { +- asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val)); ++ if (current_el() == CURRENTEL_EL3) ++ asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val)); ++ else ++ asm volatile ("msr " ICC_SRE_EL2 ", %0" : : "r" (val)); + } + +-static inline void gic_write_icc_ctlr(uint32_t val) ++static inline void gic_init_icc_ctlr() + { +- asm volatile ("msr " ICC_CTLR_EL3 ", %0" : : "r" (val)); ++ if (current_el() == CURRENTEL_EL3) ++ asm volatile ("msr " ICC_CTLR_EL3 ", %0" : : "r" (ICC_CTLR_EL3_RESET)); ++ else ++ asm volatile ("msr " ICC_CTLR_EL1 ", %0" : : "r" (ICC_CTLR_EL1_RESET)); + } + + #endif +diff --git a/common/gic-v3.c b/common/gic-v3.c +index 6207007..a0fe564 100644 +--- a/common/gic-v3.c ++++ b/common/gic-v3.c +@@ -117,6 +117,6 @@ void gic_secure_init(void) + gic_write_icc_sre(ICC_SRE_Enable | ICC_SRE_DIB | ICC_SRE_DFB | ICC_SRE_SRE); + isb(); + +- gic_write_icc_ctlr(0); ++ gic_init_icc_ctlr(); + isb(); + } diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0005-aarch64-Prepare-for-booting-with-EL2.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0005-aarch64-Prepare-for-booting-with-EL2.patch new file mode 100644 index 0000000..3b6f78a --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0005-aarch64-Prepare-for-booting-with-EL2.patch @@ -0,0 +1,63 @@ +From be814863cdd5f61d9a16eec012d500550053c8c6 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 25 May 2021 07:25:00 +0100 +Subject: [PATCH] aarch64: Prepare for booting with EL2 + +Prepare for allowing boot-wrapper to be entered in EL2. +Detect current EL and set the corresponding EL registers. + +Upstream-Status: Pending +Signed-off-by: Jaxson Han +Reviewed-by: Andre Przywara +--- + arch/aarch64/boot.S | 8 ++++++++ + arch/aarch64/utils.S | 10 +++++++++- + 2 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S +index 6b45afc..908764a 100644 +--- a/arch/aarch64/boot.S ++++ b/arch/aarch64/boot.S +@@ -195,10 +195,18 @@ ASM_FUNC(jump_kernel) + */ + bfi x4, x19, #5, #1 + ++ mrs x5, CurrentEL ++ cmp x5, #CURRENTEL_EL2 ++ b.eq 1f ++ + msr elr_el3, x19 + msr spsr_el3, x4 + eret + ++1: msr elr_el2, x19 ++ msr spsr_el2, x4 ++ eret ++ + .ltorg + + .data +diff --git a/arch/aarch64/utils.S b/arch/aarch64/utils.S +index 85c7f8a..f02a249 100644 +--- a/arch/aarch64/utils.S ++++ b/arch/aarch64/utils.S +@@ -34,10 +34,18 @@ ASM_FUNC(find_logical_id) + ret + + /* +- * Setup EL3 vectors ++ * Setup EL3/EL2 vectors + * x0: vector address + */ + ASM_FUNC(setup_vector) ++ mrs x1, CurrentEL ++ cmp x1, #CURRENTEL_EL2 ++ b.eq 1f ++ + msr VBAR_EL3, x0 + isb + ret ++ ++1: msr VBAR_EL2, x0 ++ isb ++ ret diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0006-aarch64-Introduce-EL2-boot-code-for-Armv8-R-AArch64.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0006-aarch64-Introduce-EL2-boot-code-for-Armv8-R-AArch64.patch new file mode 100644 index 0000000..aaacc72 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0006-aarch64-Introduce-EL2-boot-code-for-Armv8-R-AArch64.patch @@ -0,0 +1,182 @@ +From 81df76f8d94cb6c31c01739b078a72bdb8497441 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 25 May 2021 07:25:00 +0100 +Subject: [PATCH] aarch64: Introduce EL2 boot code for Armv8-R AArch64 + +The Armv8-R AArch64 profile does not support the EL3 exception level. +The Armv8-R AArch64 profile allows for an (optional) VMSAv8-64 MMU +at EL1, which allows to run off-the-shelf Linux. However EL2 only +supports a PMSA, which is not supported by Linux, so we need to drop +into EL1 before entering the kernel. + +We add a new err_invalid_arch symbol as a dead loop. If we detect the +current Armv8-R aarch64 only supports with PMSA, meaning we cannot boot +Linux anymore, then we jump to err_invalid_arch. + +During Armv8-R aarch64 init, to make sure nothing unexpected traps into +EL2, we auto-detect and config FIEN and EnSCXT in HCR_EL2. + +The boot sequence is: +If CurrentEL == EL3, then goto EL3 initialisation and drop to lower EL + before entering the kernel. +If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA == 0xf (Armv8-R aarch64), + if id_aa64mmfr0_el1.MSA_frac == 0x2, + then goto Armv8-R AArch64 initialisation and drop to EL1 before + entering the kernel. + else, which means VMSA unsupported and cannot boot Linux, + goto err_invalid_arch (dead loop). +Else, no initialisation and keep the current EL before entering the + kernel. + +Upstream-Status: Pending +Signed-off-by: Jaxson Han +--- + arch/aarch64/boot.S | 92 +++++++++++++++++++++++++++++++++- + arch/aarch64/include/asm/cpu.h | 2 + + 2 files changed, 92 insertions(+), 2 deletions(-) + +diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S +index 908764a..def9192 100644 +--- a/arch/aarch64/boot.S ++++ b/arch/aarch64/boot.S +@@ -24,16 +24,24 @@ ASM_FUNC(_start) + * Boot sequence + * If CurrentEL == EL3, then goto EL3 initialisation and drop to + * lower EL before entering the kernel. ++ * If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA == 0xf, then ++ * If id_aa64mmfr0_el1.MSA_frac == 0x2, then goto ++ * Armv8-R AArch64 initialisation and drop to EL1 before ++ * entering the kernel. ++ * Else, which means VMSA unsupported and cannot boot Linux, ++ * goto err_invalid_arch (dead loop). + * Else, no initialisation and keep the current EL before + * entering the kernel. + */ + mrs x0, CurrentEL +- cmp x0, #CURRENTEL_EL3 +- b.eq el3_init ++ cmp x0, #CURRENTEL_EL2 ++ bgt el3_init ++ beq el2_init + + /* + * We stay in the current EL for entering the kernel + */ ++keep_el: + mov w0, #1 + ldr x1, =flag_keep_el + str w0, [x1] +@@ -139,6 +147,85 @@ el3_init: + str w0, [x1] + b el_max_init + ++ /* ++ * EL2 Armv8-R AArch64 initialisation ++ */ ++el2_init: ++ /* Detect Armv8-R AArch64 */ ++ mrs x1, id_aa64mmfr0_el1 ++ /* ++ * Check MSA, bits [51:48]: ++ * 0xf means Armv8-R AArch64. ++ * If not 0xf, proceed in Armv8-A EL2. ++ */ ++ ubfx x0, x1, #48, #4 // MSA ++ cmp x0, 0xf ++ bne keep_el ++ /* ++ * Check MSA_frac, bits [55:52]: ++ * 0x2 means EL1&0 translation regime also supports VMSAv8-64. ++ */ ++ ubfx x0, x1, #52, #4 // MSA_frac ++ cmp x0, 0x2 ++ /* ++ * If not 0x2, no VMSA, so cannot boot Linux and dead loop. ++ * Also, since the architecture guarantees that those CPUID ++ * fields never lose features when the value in a field ++ * increases, we use blt to cover it. ++ */ ++ blt err_invalid_arch ++ ++ mrs x0, midr_el1 ++ msr vpidr_el2, x0 ++ ++ mrs x0, mpidr_el1 ++ msr vmpidr_el2, x0 ++ ++ mov x0, #(1 << 31) // VTCR_MSA: VMSAv8-64 support ++ msr vtcr_el2, x0 ++ ++ /* Init HCR_EL2 */ ++ mov x0, #(1 << 31) // RES1: Armv8-R aarch64 only ++ ++ mrs x1, id_aa64pfr0_el1 ++ ubfx x2, x1, #56, 4 // ID_AA64PFR0_EL1.CSV2 ++ cmp x2, 0x2 ++ b.lt 1f ++ /* ++ * Disable trap when accessing SCTXNUM_EL0 or SCTXNUM_EL1 ++ * if FEAT_CSV2. ++ */ ++ orr x0, x0, #(1 << 53) // HCR_EL2.EnSCXT ++ ++1: ubfx x2, x1, #28, 4 // ID_AA64PFR0_EL1.RAS ++ cmp x2, 0x2 ++ b.lt 1f ++ /* Disable trap when accessing ERXPFGCDN_EL1 if FEAT_RASv1p1. */ ++ orr x0, x0, #(1 << 47) // HCR_EL2.FIEN ++ ++ /* Enable pointer authentication if present */ ++1: mrs x1, id_aa64isar1_el1 ++ /* ++ * If ID_AA64ISAR1_EL1.{GPI, GPA, API, APA} == {0000, 0000, 0000, 0000} ++ * then HCR_EL2.APK and HCR_EL2.API are RES 0. ++ * Else ++ * set HCR_EL2.APK and HCR_EL2.API. ++ */ ++ ldr x2, =(((0xff) << 24) | (0xff << 4)) ++ and x1, x1, x2 ++ cbz x1, 1f ++ ++ orr x0, x0, #(1 << 40) // HCR_EL2.APK ++ orr x0, x0, #(1 << 41) // HCR_EL2.API ++ ++1: msr hcr_el2, x0 ++ isb ++ ++ mov w0, #SPSR_KERNEL_EL1 ++ ldr x1, =spsr_to_elx ++ str w0, [x1] ++ // fall through ++ + el_max_init: + ldr x0, =COUNTER_FREQ + msr cntfrq_el0, x0 +@@ -148,6 +235,7 @@ el_max_init: + b start_el_max + + err_invalid_id: ++err_invalid_arch: + b . + + /* +diff --git a/arch/aarch64/include/asm/cpu.h b/arch/aarch64/include/asm/cpu.h +index b1003f4..91f803c 100644 +--- a/arch/aarch64/include/asm/cpu.h ++++ b/arch/aarch64/include/asm/cpu.h +@@ -25,6 +25,7 @@ + #define SPSR_I (1 << 7) /* IRQ masked */ + #define SPSR_F (1 << 6) /* FIQ masked */ + #define SPSR_T (1 << 5) /* Thumb */ ++#define SPSR_EL1H (5 << 0) /* EL1 Handler mode */ + #define SPSR_EL2H (9 << 0) /* EL2 Handler mode */ + #define SPSR_HYP (0x1a << 0) /* M[3:0] = hyp, M[4] = AArch32 */ + +@@ -43,6 +44,7 @@ + #else + #define SCTLR_EL1_KERNEL SCTLR_EL1_RES1 + #define SPSR_KERNEL (SPSR_A | SPSR_D | SPSR_I | SPSR_F | SPSR_EL2H) ++#define SPSR_KERNEL_EL1 (SPSR_A | SPSR_D | SPSR_I | SPSR_F | SPSR_EL1H) + #endif + + #ifndef __ASSEMBLY__ diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0003-Allow-enable-psci-to-choose-between-smc-and-hvc.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0007-Allow-enable-psci-to-choose-between-smc-and-hvc.patch similarity index 71% rename from meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0003-Allow-enable-psci-to-choose-between-smc-and-hvc.patch rename to meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0007-Allow-enable-psci-to-choose-between-smc-and-hvc.patch index fcd77b7..b130854 100644 --- a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0003-Allow-enable-psci-to-choose-between-smc-and-hvc.patch +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0007-Allow-enable-psci-to-choose-between-smc-and-hvc.patch @@ -1,4 +1,4 @@ -From 5120127e5f767b44a087c741a3438cef1e22ed50 Mon Sep 17 00:00:00 2001 +From f5a31b4f4ea8daaa0d337d5a2322ddb1912083fc Mon Sep 17 00:00:00 2001 From: Qi Feng Date: Wed, 26 May 2021 17:52:01 +0800 Subject: [PATCH] Allow --enable-psci to choose between smc and hvc @@ -28,38 +28,47 @@ To use hvc, use --enable-psci=hvc. [1]: https://developer.arm.com/documentation/ddi0600/latest/ Issue-Id: SCM-2654 +Upstream-Status: Pending Signed-off-by: Qi Feng Change-Id: Ib8afabdad2d98bc37371d165bbb6f1f9b88bfc87 Upstream-Status: Pending Signed-off-by: Huifeng Zhang --- - Makefile.am | 2 +- + Makefile.am | 10 +++++----- configure.ac | 14 +++++++++----- - 2 files changed, 10 insertions(+), 6 deletions(-) + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am -index ef6b793..a9ddd16 100644 +index f941b07..88a27de 100644 --- a/Makefile.am +++ b/Makefile.am -@@ -47,7 +47,7 @@ BOOTMETHOD := psci.o - OFILES += psci.o - PSCI_NODE := psci { \ - compatible = \"arm,psci\"; \ +@@ -50,11 +50,11 @@ endif + if PSCI + ARCH_OBJ += psci.o + COMMON_OBJ += psci.o +-PSCI_NODE := psci { \ +- compatible = \"arm,psci\"; \ - method = \"smc\"; \ -+ method = \"$(PSCI_METHOD)\"; \ - cpu_on = <$(PSCI_CPU_ON)>; \ - cpu_off = <$(PSCI_CPU_OFF)>; \ +- cpu_on = <$(PSCI_CPU_ON)>; \ +- cpu_off = <$(PSCI_CPU_OFF)>; \ ++PSCI_NODE := psci { \ ++ compatible = \"arm,psci\"; \ ++ method = \"$(PSCI_METHOD)\"; \ ++ cpu_on = <$(PSCI_CPU_ON)>; \ ++ cpu_off = <$(PSCI_CPU_OFF)>; \ }; + CPU_NODES := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/addpsci.pl $(KERNEL_DTB)) + else diff --git a/configure.ac b/configure.ac -index 6914eb4..9aab4a1 100644 +index 9e3b722..53e51be 100644 --- a/configure.ac +++ b/configure.ac @@ -83,13 +83,17 @@ AS_IF([test "x$X_IMAGE" != "x"], # Allow a user to pass --enable-psci AC_ARG_ENABLE([psci], - AS_HELP_STRING([--enable-psci], [enable the psci boot method]), -- [USE_PSCI=$enableval]) + AS_HELP_STRING([--disable-psci], [disable the psci boot method]), +- [USE_PSCI=$enableval], [USE_PSCI="yes"]) -AM_CONDITIONAL([PSCI], [test "x$USE_PSCI" = "xyes"]) -AS_IF([test "x$USE_PSCI" = "xyes"], [], [USE_PSCI=no]) - @@ -68,7 +77,7 @@ index 6914eb4..9aab4a1 100644 + yes|smc) USE_PSCI=smc ;; + hvc) USE_PSCI=hvc ;; + *) AC_MSG_ERROR([Bad value "${enableval}" for --enable-psci. Use "smc" or "hvc"]) ;; -+ esac]) ++ esac], [USE_PSCI="yes"]) +AM_CONDITIONAL([PSCI], [test "x$USE_PSCI" = "xyes" -o "x$USE_PSCI" = "xsmc" -o "x$USE_PSCI" = "xhvc"]) + +AS_IF([test "x$USE_PSCI" = "xno" -a "x$KERNEL_ES" = "x32"], @@ -78,6 +87,3 @@ index 6914eb4..9aab4a1 100644 # Allow a user to pass --with-initrd AC_ARG_WITH([initrd], --- -2.32.0 - diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0008-aarch64-Disable-CNTPCT_EL0-trap-for-v8-R64.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0008-aarch64-Disable-CNTPCT_EL0-trap-for-v8-R64.patch new file mode 100644 index 0000000..a14e54a --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0008-aarch64-Disable-CNTPCT_EL0-trap-for-v8-R64.patch @@ -0,0 +1,48 @@ +From 3f4614e02f0f8d2522510578da2752f8e3511bb3 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Mon, 25 Oct 2021 17:09:13 +0800 +Subject: [PATCH] aarch64: Disable CNTPCT_EL0 trap for v8-R64 + +To allow EL1 to access CNTPCT_EL0 without traping into EL2, we need to +set CNTHCTL_EL2.EL1PCTEN to 1. + +For v8-R64, the CNTHCTL_EL2 register follows the v8-A architecture. +However, as described in the v8-A architecture profile, the +CNTHCTL_EL2's bit assignments are different according to whether the +FEAT_VHE is implemented. + +Since v8-R64 does not support FEAT_VHE, we do not need to detect +FEAT_VHE. We can simply set CNTHCTL_EL2.EL1PCTEN to 1. + +Issue-ID: SCM-3508 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Jaxson Han +Change-Id: I4147e66341c8153312021e6f2ab67d0037246da1 +--- + arch/aarch64/boot.S | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S +index def9192..6dbd5cc 100644 +--- a/arch/aarch64/boot.S ++++ b/arch/aarch64/boot.S +@@ -219,6 +219,18 @@ el2_init: + orr x0, x0, #(1 << 41) // HCR_EL2.API + + 1: msr hcr_el2, x0 ++ ++ /* ++ * To disable trap when accessing CNTPCT_EL0, we need to set ++ * CNTHCTL_EL2.EL1PCTEN to 1. However, the CNTHCTL_EL2 bit assignments ++ * are different according to whether the FEAT_VHE is implemented. ++ * ++ * For Armv8-R AArch64, FEAT_VHE is not supported, so we do not need to ++ * detect FEAT_VHE(ID_AA64MMFR1_EL1.VH) and simply set ++ * CNTHCTL_EL2.EL1PCTEN to 1. ++ */ ++ mov x0, #1 // CNTHCTL_EL2.EL1PCTEN ++ msr cnthctl_el2, x0 + isb + + mov w0, #SPSR_KERNEL_EL1 diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0009-lds-Mark-the-mem-range.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0009-lds-Mark-the-mem-range.patch new file mode 100644 index 0000000..3d4fec8 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0009-lds-Mark-the-mem-range.patch @@ -0,0 +1,38 @@ +From 2851f0e6c1216894b9498d7b91256bb1ef49e544 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 2 Nov 2021 15:10:28 +0800 +Subject: [PATCH] lds: Mark the mem range + +Add firmware_start and firmware_end, so that we can use them to +calculate the mem range of boot-wrapper and then set the range to +/memreserve/ of dtb. + +Issue-ID: SCM-3815 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Jaxson Han +Change-Id: Idc5a2894e193c75381049a0f359b4b2a51c567ee +--- + model.lds.S | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/model.lds.S b/model.lds.S +index d4e7e13..ab98ddf 100644 +--- a/model.lds.S ++++ b/model.lds.S +@@ -64,6 +64,7 @@ SECTIONS + #endif + + .boot PHYS_OFFSET: { ++ PROVIDE(firmware_start = .); + *(.init) + *(.text*) + *(.data* .rodata* .bss* COMMON) +@@ -76,6 +77,7 @@ SECTIONS + mbox = .; + QUAD(0x0) + } ++ PROVIDE(firmware_end = .); + + ASSERT(etext <= (PHYS_OFFSET + TEXT_LIMIT), ".text overflow!") + } diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0010-common-Introduce-the-libfdt.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0010-common-Introduce-the-libfdt.patch new file mode 100644 index 0000000..e0496dc --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0010-common-Introduce-the-libfdt.patch @@ -0,0 +1,6044 @@ +From fadf04f44b679d85e55b2e5f220fecbebb52ad03 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 28 Dec 2021 17:02:17 +0800 +Subject: [PATCH] common: Introduce the libfdt + +We introduce libfdt (v1.6.1) [1] to boot-wrapper, so we can dynamically +add the firmware node. + +According to [2]: The libfdt is GPL/BSD dual-licensed which means it can +be used either under the terms of GPL, or under the terms of BSD. +We choose BSD because the boot-wrapper is under BSD. + +[1]: https://github.com/dgibson/dtc/tree/v1.6.1/libfdt +[2]: https://github.com/dgibson/dtc/blob/v1.6.1/README.license + +Issue-Id: SCM-3814 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Jaxson Han +Change-Id: Iec2f469053c8ac0ed38838c597b21a42bdf67b38 +--- + common/libfdt/README.license | 56 + + common/libfdt/fdt.c | 335 +++++ + common/libfdt/fdt_addresses.c | 101 ++ + common/libfdt/fdt_check.c | 93 ++ + common/libfdt/fdt_empty_tree.c | 38 + + common/libfdt/fdt_overlay.c | 882 +++++++++++++ + common/libfdt/fdt_ro.c | 859 +++++++++++++ + common/libfdt/fdt_rw.c | 500 +++++++ + common/libfdt/fdt_strerror.c | 59 + + common/libfdt/fdt_sw.c | 384 ++++++ + common/libfdt/fdt_wip.c | 94 ++ + common/libfdt/libfdt_internal.h | 192 +++ + include/fdt.h | 66 + + include/libfdt.h | 2147 +++++++++++++++++++++++++++++++ + include/libfdt_env.h | 95 ++ + 15 files changed, 5901 insertions(+) + create mode 100644 common/libfdt/README.license + create mode 100644 common/libfdt/fdt.c + create mode 100644 common/libfdt/fdt_addresses.c + create mode 100644 common/libfdt/fdt_check.c + create mode 100644 common/libfdt/fdt_empty_tree.c + create mode 100644 common/libfdt/fdt_overlay.c + create mode 100644 common/libfdt/fdt_ro.c + create mode 100644 common/libfdt/fdt_rw.c + create mode 100644 common/libfdt/fdt_strerror.c + create mode 100644 common/libfdt/fdt_sw.c + create mode 100644 common/libfdt/fdt_wip.c + create mode 100644 common/libfdt/libfdt_internal.h + create mode 100644 include/fdt.h + create mode 100644 include/libfdt.h + create mode 100644 include/libfdt_env.h + +diff --git a/common/libfdt/README.license b/common/libfdt/README.license +new file mode 100644 +index 0000000..102b004 +--- /dev/null ++++ b/common/libfdt/README.license +@@ -0,0 +1,56 @@ ++Licensing and contribution policy of dtc and libfdt ++=================================================== ++ ++This dtc package contains two pieces of software: dtc itself, and ++libfdt which comprises the files in the libfdt/ subdirectory. These ++two pieces of software, although closely related, are quite distinct. ++dtc does not incorporate or rely on libfdt for its operation, nor vice ++versa. It is important that these two pieces of software have ++different license conditions. ++ ++As SPDX license tags in each source file attest, dtc is licensed ++under the GNU GPL. The full text of the GPL can be found in the file ++entitled 'GPL' which should be included in this package. dtc code, ++therefore, may not be incorporated into works which do not have a GPL ++compatible license. ++ ++libfdt, however, is GPL/BSD dual-licensed. That is, it may be used ++either under the terms of the GPL, or under the terms of the 2-clause ++BSD license (aka the ISC license). The full terms of that license can ++be found are in the file entitled 'BSD-2-Clause'. This is, in ++practice, equivalent to being BSD licensed, since the terms of the BSD ++license are strictly more permissive than the GPL. ++ ++I made the decision to license libfdt in this way because I want to ++encourage widespread and correct usage of flattened device trees, ++including by proprietary or otherwise GPL-incompatible firmware or ++tools. Allowing libfdt to be used under the terms of the BSD license ++makes that it easier for vendors or authors of such software to do so. ++ ++This does mean that libfdt code could be "stolen" - say, included in a ++proprietary fimware and extended without contributing those extensions ++back to the libfdt mainline. While I hope that doesn't happen, I ++believe the goal of allowing libfdt to be widely used is more ++important than avoiding that. libfdt is quite small, and hardly ++rocket science; so the incentive for such impolite behaviour is small, ++and the inconvenience caused thereby is not dire. ++ ++Licenses such as the LGPL which would allow code to be used in non-GPL ++software, but also require contributions to be returned were ++considered. However, libfdt is designed to be used in firmwares and ++other environments with unusual technical constraints. It's difficult ++to anticipate all possible changes which might be needed to meld ++libfdt into such environments and so difficult to suitably word a ++license that puts the boundary between what is and isn't permitted in ++the intended place. Again, I judged encouraging widespread use of ++libfdt by keeping the license terms simple and familiar to be the more ++important goal. ++ ++**IMPORTANT** It's intended that all of libfdt as released remain ++permissively licensed this way. Therefore only contributions which ++are released under these terms can be merged into the libfdt mainline. ++ ++ ++David Gibson ++(principal original author of dtc and libfdt) ++2 November 2007 +diff --git a/common/libfdt/fdt.c b/common/libfdt/fdt.c +new file mode 100644 +index 0000000..9fe7cf4 +--- /dev/null ++++ b/common/libfdt/fdt.c +@@ -0,0 +1,335 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++/* ++ * Minimal sanity check for a read-only tree. fdt_ro_probe_() checks ++ * that the given buffer contains what appears to be a flattened ++ * device tree with sane information in its header. ++ */ ++int32_t fdt_ro_probe_(const void *fdt) ++{ ++ uint32_t totalsize = fdt_totalsize(fdt); ++ ++ if (can_assume(VALID_DTB)) ++ return totalsize; ++ ++ /* The device tree must be at an 8-byte aligned address */ ++ if ((uintptr_t)fdt & 7) ++ return -FDT_ERR_ALIGNMENT; ++ ++ if (fdt_magic(fdt) == FDT_MAGIC) { ++ /* Complete tree */ ++ if (!can_assume(LATEST)) { ++ if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) ++ return -FDT_ERR_BADVERSION; ++ if (fdt_last_comp_version(fdt) > ++ FDT_LAST_SUPPORTED_VERSION) ++ return -FDT_ERR_BADVERSION; ++ } ++ } else if (fdt_magic(fdt) == FDT_SW_MAGIC) { ++ /* Unfinished sequential-write blob */ ++ if (!can_assume(VALID_INPUT) && fdt_size_dt_struct(fdt) == 0) ++ return -FDT_ERR_BADSTATE; ++ } else { ++ return -FDT_ERR_BADMAGIC; ++ } ++ ++ if (totalsize < INT32_MAX) ++ return totalsize; ++ else ++ return -FDT_ERR_TRUNCATED; ++} ++ ++static int check_off_(uint32_t hdrsize, uint32_t totalsize, uint32_t off) ++{ ++ return (off >= hdrsize) && (off <= totalsize); ++} ++ ++static int check_block_(uint32_t hdrsize, uint32_t totalsize, ++ uint32_t base, uint32_t size) ++{ ++ if (!check_off_(hdrsize, totalsize, base)) ++ return 0; /* block start out of bounds */ ++ if ((base + size) < base) ++ return 0; /* overflow */ ++ if (!check_off_(hdrsize, totalsize, base + size)) ++ return 0; /* block end out of bounds */ ++ return 1; ++} ++ ++size_t fdt_header_size_(uint32_t version) ++{ ++ if (version <= 1) ++ return FDT_V1_SIZE; ++ else if (version <= 2) ++ return FDT_V2_SIZE; ++ else if (version <= 3) ++ return FDT_V3_SIZE; ++ else if (version <= 16) ++ return FDT_V16_SIZE; ++ else ++ return FDT_V17_SIZE; ++} ++ ++size_t fdt_header_size(const void *fdt) ++{ ++ return can_assume(LATEST) ? FDT_V17_SIZE : ++ fdt_header_size_(fdt_version(fdt)); ++} ++ ++int fdt_check_header(const void *fdt) ++{ ++ size_t hdrsize; ++ ++ /* The device tree must be at an 8-byte aligned address */ ++ if ((uintptr_t)fdt & 7) ++ return -FDT_ERR_ALIGNMENT; ++ ++ if (fdt_magic(fdt) != FDT_MAGIC) ++ return -FDT_ERR_BADMAGIC; ++ if (!can_assume(LATEST)) { ++ if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) ++ || (fdt_last_comp_version(fdt) > ++ FDT_LAST_SUPPORTED_VERSION)) ++ return -FDT_ERR_BADVERSION; ++ if (fdt_version(fdt) < fdt_last_comp_version(fdt)) ++ return -FDT_ERR_BADVERSION; ++ } ++ hdrsize = fdt_header_size(fdt); ++ if (!can_assume(VALID_DTB)) { ++ ++ if ((fdt_totalsize(fdt) < hdrsize) ++ || (fdt_totalsize(fdt) > INT_MAX)) ++ return -FDT_ERR_TRUNCATED; ++ ++ /* Bounds check memrsv block */ ++ if (!check_off_(hdrsize, fdt_totalsize(fdt), ++ fdt_off_mem_rsvmap(fdt))) ++ return -FDT_ERR_TRUNCATED; ++ } ++ ++ if (!can_assume(VALID_DTB)) { ++ /* Bounds check structure block */ ++ if (!can_assume(LATEST) && fdt_version(fdt) < 17) { ++ if (!check_off_(hdrsize, fdt_totalsize(fdt), ++ fdt_off_dt_struct(fdt))) ++ return -FDT_ERR_TRUNCATED; ++ } else { ++ if (!check_block_(hdrsize, fdt_totalsize(fdt), ++ fdt_off_dt_struct(fdt), ++ fdt_size_dt_struct(fdt))) ++ return -FDT_ERR_TRUNCATED; ++ } ++ ++ /* Bounds check strings block */ ++ if (!check_block_(hdrsize, fdt_totalsize(fdt), ++ fdt_off_dt_strings(fdt), ++ fdt_size_dt_strings(fdt))) ++ return -FDT_ERR_TRUNCATED; ++ } ++ ++ return 0; ++} ++ ++const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) ++{ ++ unsigned int uoffset = offset; ++ unsigned int absoffset = offset + fdt_off_dt_struct(fdt); ++ ++ if (offset < 0) ++ return NULL; ++ ++ if (!can_assume(VALID_INPUT)) ++ if ((absoffset < uoffset) ++ || ((absoffset + len) < absoffset) ++ || (absoffset + len) > fdt_totalsize(fdt)) ++ return NULL; ++ ++ if (can_assume(LATEST) || fdt_version(fdt) >= 0x11) ++ if (((uoffset + len) < uoffset) ++ || ((offset + len) > fdt_size_dt_struct(fdt))) ++ return NULL; ++ ++ return fdt_offset_ptr_(fdt, offset); ++} ++ ++uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) ++{ ++ const fdt32_t *tagp, *lenp; ++ uint32_t tag; ++ int offset = startoffset; ++ const char *p; ++ ++ *nextoffset = -FDT_ERR_TRUNCATED; ++ tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE); ++ if (!can_assume(VALID_DTB) && !tagp) ++ return FDT_END; /* premature end */ ++ tag = fdt32_to_cpu(*tagp); ++ offset += FDT_TAGSIZE; ++ ++ *nextoffset = -FDT_ERR_BADSTRUCTURE; ++ switch (tag) { ++ case FDT_BEGIN_NODE: ++ /* skip name */ ++ do { ++ p = fdt_offset_ptr(fdt, offset++, 1); ++ } while (p && (*p != '\0')); ++ if (!can_assume(VALID_DTB) && !p) ++ return FDT_END; /* premature end */ ++ break; ++ ++ case FDT_PROP: ++ lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp)); ++ if (!can_assume(VALID_DTB) && !lenp) ++ return FDT_END; /* premature end */ ++ /* skip-name offset, length and value */ ++ offset += sizeof(struct fdt_property) - FDT_TAGSIZE ++ + fdt32_to_cpu(*lenp); ++ if (!can_assume(LATEST) && ++ fdt_version(fdt) < 0x10 && fdt32_to_cpu(*lenp) >= 8 && ++ ((offset - fdt32_to_cpu(*lenp)) % 8) != 0) ++ offset += 4; ++ break; ++ ++ case FDT_END: ++ case FDT_END_NODE: ++ case FDT_NOP: ++ break; ++ ++ default: ++ return FDT_END; ++ } ++ ++ if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset)) ++ return FDT_END; /* premature end */ ++ ++ *nextoffset = FDT_TAGALIGN(offset); ++ return tag; ++} ++ ++int fdt_check_node_offset_(const void *fdt, int offset) ++{ ++ if (!can_assume(VALID_INPUT) ++ && ((offset < 0) || (offset % FDT_TAGSIZE))) ++ return -FDT_ERR_BADOFFSET; ++ ++ if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE) ++ return -FDT_ERR_BADOFFSET; ++ ++ return offset; ++} ++ ++int fdt_check_prop_offset_(const void *fdt, int offset) ++{ ++ if (!can_assume(VALID_INPUT) ++ && ((offset < 0) || (offset % FDT_TAGSIZE))) ++ return -FDT_ERR_BADOFFSET; ++ ++ if (fdt_next_tag(fdt, offset, &offset) != FDT_PROP) ++ return -FDT_ERR_BADOFFSET; ++ ++ return offset; ++} ++ ++int fdt_next_node(const void *fdt, int offset, int *depth) ++{ ++ int nextoffset = 0; ++ uint32_t tag; ++ ++ if (offset >= 0) ++ if ((nextoffset = fdt_check_node_offset_(fdt, offset)) < 0) ++ return nextoffset; ++ ++ do { ++ offset = nextoffset; ++ tag = fdt_next_tag(fdt, offset, &nextoffset); ++ ++ switch (tag) { ++ case FDT_PROP: ++ case FDT_NOP: ++ break; ++ ++ case FDT_BEGIN_NODE: ++ if (depth) ++ (*depth)++; ++ break; ++ ++ case FDT_END_NODE: ++ if (depth && ((--(*depth)) < 0)) ++ return nextoffset; ++ break; ++ ++ case FDT_END: ++ if ((nextoffset >= 0) ++ || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth)) ++ return -FDT_ERR_NOTFOUND; ++ else ++ return nextoffset; ++ } ++ } while (tag != FDT_BEGIN_NODE); ++ ++ return offset; ++} ++ ++int fdt_first_subnode(const void *fdt, int offset) ++{ ++ int depth = 0; ++ ++ offset = fdt_next_node(fdt, offset, &depth); ++ if (offset < 0 || depth != 1) ++ return -FDT_ERR_NOTFOUND; ++ ++ return offset; ++} ++ ++int fdt_next_subnode(const void *fdt, int offset) ++{ ++ int depth = 1; ++ ++ /* ++ * With respect to the parent, the depth of the next subnode will be ++ * the same as the last. ++ */ ++ do { ++ offset = fdt_next_node(fdt, offset, &depth); ++ if (offset < 0 || depth < 1) ++ return -FDT_ERR_NOTFOUND; ++ } while (depth > 1); ++ ++ return offset; ++} ++ ++const char *fdt_find_string_(const char *strtab, int tabsize, const char *s) ++{ ++ int len = strlen(s) + 1; ++ const char *last = strtab + tabsize - len; ++ const char *p; ++ ++ for (p = strtab; p <= last; p++) ++ if (memcmp(p, s, len) == 0) ++ return p; ++ return NULL; ++} ++ ++int fdt_move(const void *fdt, void *buf, int bufsize) ++{ ++ if (!can_assume(VALID_INPUT) && bufsize < 0) ++ return -FDT_ERR_NOSPACE; ++ ++ FDT_RO_PROBE(fdt); ++ ++ if (fdt_totalsize(fdt) > (unsigned int)bufsize) ++ return -FDT_ERR_NOSPACE; ++ ++ memmove(buf, fdt, fdt_totalsize(fdt)); ++ return 0; ++} +diff --git a/common/libfdt/fdt_addresses.c b/common/libfdt/fdt_addresses.c +new file mode 100644 +index 0000000..9a82cd0 +--- /dev/null ++++ b/common/libfdt/fdt_addresses.c +@@ -0,0 +1,101 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2014 David Gibson ++ * Copyright (C) 2018 embedded brains GmbH ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++static int fdt_cells(const void *fdt, int nodeoffset, const char *name) ++{ ++ const fdt32_t *c; ++ uint32_t val; ++ int len; ++ ++ c = fdt_getprop(fdt, nodeoffset, name, &len); ++ if (!c) ++ return len; ++ ++ if (len != sizeof(*c)) ++ return -FDT_ERR_BADNCELLS; ++ ++ val = fdt32_to_cpu(*c); ++ if (val > FDT_MAX_NCELLS) ++ return -FDT_ERR_BADNCELLS; ++ ++ return (int)val; ++} ++ ++int fdt_address_cells(const void *fdt, int nodeoffset) ++{ ++ int val; ++ ++ val = fdt_cells(fdt, nodeoffset, "#address-cells"); ++ if (val == 0) ++ return -FDT_ERR_BADNCELLS; ++ if (val == -FDT_ERR_NOTFOUND) ++ return 2; ++ return val; ++} ++ ++int fdt_size_cells(const void *fdt, int nodeoffset) ++{ ++ int val; ++ ++ val = fdt_cells(fdt, nodeoffset, "#size-cells"); ++ if (val == -FDT_ERR_NOTFOUND) ++ return 1; ++ return val; ++} ++ ++/* This function assumes that [address|size]_cells is 1 or 2 */ ++int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset, ++ const char *name, uint64_t addr, uint64_t size) ++{ ++ int addr_cells, size_cells, ret; ++ uint8_t data[sizeof(fdt64_t) * 2], *prop; ++ ++ ret = fdt_address_cells(fdt, parent); ++ if (ret < 0) ++ return ret; ++ addr_cells = ret; ++ ++ ret = fdt_size_cells(fdt, parent); ++ if (ret < 0) ++ return ret; ++ size_cells = ret; ++ ++ /* check validity of address */ ++ prop = data; ++ if (addr_cells == 1) { ++ if ((addr > UINT32_MAX) || ((UINT32_MAX + 1 - addr) < size)) ++ return -FDT_ERR_BADVALUE; ++ ++ fdt32_st(prop, (uint32_t)addr); ++ } else if (addr_cells == 2) { ++ fdt64_st(prop, addr); ++ } else { ++ return -FDT_ERR_BADNCELLS; ++ } ++ ++ /* check validity of size */ ++ prop += addr_cells * sizeof(fdt32_t); ++ if (size_cells == 1) { ++ if (size > UINT32_MAX) ++ return -FDT_ERR_BADVALUE; ++ ++ fdt32_st(prop, (uint32_t)size); ++ } else if (size_cells == 2) { ++ fdt64_st(prop, size); ++ } else { ++ return -FDT_ERR_BADNCELLS; ++ } ++ ++ return fdt_appendprop(fdt, nodeoffset, name, data, ++ (addr_cells + size_cells) * sizeof(fdt32_t)); ++} +diff --git a/common/libfdt/fdt_check.c b/common/libfdt/fdt_check.c +new file mode 100644 +index 0000000..fa410a8 +--- /dev/null ++++ b/common/libfdt/fdt_check.c +@@ -0,0 +1,93 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++int fdt_check_full(const void *fdt, size_t bufsize) ++{ ++ int err; ++ int num_memrsv; ++ int offset, nextoffset = 0; ++ uint32_t tag; ++ unsigned int depth = 0; ++ const void *prop; ++ const char *propname; ++ bool expect_end = false; ++ ++ if (bufsize < FDT_V1_SIZE) ++ return -FDT_ERR_TRUNCATED; ++ if (bufsize < fdt_header_size(fdt)) ++ return -FDT_ERR_TRUNCATED; ++ err = fdt_check_header(fdt); ++ if (err != 0) ++ return err; ++ if (bufsize < fdt_totalsize(fdt)) ++ return -FDT_ERR_TRUNCATED; ++ ++ num_memrsv = fdt_num_mem_rsv(fdt); ++ if (num_memrsv < 0) ++ return num_memrsv; ++ ++ while (1) { ++ offset = nextoffset; ++ tag = fdt_next_tag(fdt, offset, &nextoffset); ++ ++ if (nextoffset < 0) ++ return nextoffset; ++ ++ /* If we see two root nodes, something is wrong */ ++ if (expect_end && tag != FDT_END) ++ return -FDT_ERR_BADSTRUCTURE; ++ ++ switch (tag) { ++ case FDT_NOP: ++ break; ++ ++ case FDT_END: ++ if (depth != 0) ++ return -FDT_ERR_BADSTRUCTURE; ++ return 0; ++ ++ case FDT_BEGIN_NODE: ++ depth++; ++ if (depth > INT_MAX) ++ return -FDT_ERR_BADSTRUCTURE; ++ ++ /* The root node must have an empty name */ ++ if (depth == 1) { ++ const char *name; ++ int len; ++ ++ name = fdt_get_name(fdt, offset, &len); ++ if (*name || len) ++ return -FDT_ERR_BADSTRUCTURE; ++ } ++ break; ++ ++ case FDT_END_NODE: ++ if (depth == 0) ++ return -FDT_ERR_BADSTRUCTURE; ++ depth--; ++ if (depth == 0) ++ expect_end = true; ++ break; ++ ++ case FDT_PROP: ++ prop = fdt_getprop_by_offset(fdt, offset, &propname, ++ &err); ++ if (!prop) ++ return err; ++ break; ++ ++ default: ++ return -FDT_ERR_INTERNAL; ++ } ++ } ++} +diff --git a/common/libfdt/fdt_empty_tree.c b/common/libfdt/fdt_empty_tree.c +new file mode 100644 +index 0000000..49d54d4 +--- /dev/null ++++ b/common/libfdt/fdt_empty_tree.c +@@ -0,0 +1,38 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2012 David Gibson, IBM Corporation. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++int fdt_create_empty_tree(void *buf, int bufsize) ++{ ++ int err; ++ ++ err = fdt_create(buf, bufsize); ++ if (err) ++ return err; ++ ++ err = fdt_finish_reservemap(buf); ++ if (err) ++ return err; ++ ++ err = fdt_begin_node(buf, ""); ++ if (err) ++ return err; ++ ++ err = fdt_end_node(buf); ++ if (err) ++ return err; ++ ++ err = fdt_finish(buf); ++ if (err) ++ return err; ++ ++ return fdt_open_into(buf, buf, bufsize); ++} +diff --git a/common/libfdt/fdt_overlay.c b/common/libfdt/fdt_overlay.c +new file mode 100644 +index 0000000..d217e79 +--- /dev/null ++++ b/common/libfdt/fdt_overlay.c +@@ -0,0 +1,882 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2016 Free Electrons ++ * Copyright (C) 2016 NextThing Co. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++/** ++ * overlay_get_target_phandle - retrieves the target phandle of a fragment ++ * @fdto: pointer to the device tree overlay blob ++ * @fragment: node offset of the fragment in the overlay ++ * ++ * overlay_get_target_phandle() retrieves the target phandle of an ++ * overlay fragment when that fragment uses a phandle (target ++ * property) instead of a path (target-path property). ++ * ++ * returns: ++ * the phandle pointed by the target property ++ * 0, if the phandle was not found ++ * -1, if the phandle was malformed ++ */ ++static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) ++{ ++ const fdt32_t *val; ++ int len; ++ ++ val = fdt_getprop(fdto, fragment, "target", &len); ++ if (!val) ++ return 0; ++ ++ if ((len != sizeof(*val)) || (fdt32_to_cpu(*val) == (uint32_t)-1)) ++ return (uint32_t)-1; ++ ++ return fdt32_to_cpu(*val); ++} ++ ++/** ++ * overlay_get_target - retrieves the offset of a fragment's target ++ * @fdt: Base device tree blob ++ * @fdto: Device tree overlay blob ++ * @fragment: node offset of the fragment in the overlay ++ * @pathp: pointer which receives the path of the target (or NULL) ++ * ++ * overlay_get_target() retrieves the target offset in the base ++ * device tree of a fragment, no matter how the actual targeting is ++ * done (through a phandle or a path) ++ * ++ * returns: ++ * the targeted node offset in the base device tree ++ * Negative error code on error ++ */ ++static int overlay_get_target(const void *fdt, const void *fdto, ++ int fragment, char const **pathp) ++{ ++ uint32_t phandle; ++ const char *path = NULL; ++ int path_len = 0, ret; ++ ++ /* Try first to do a phandle based lookup */ ++ phandle = overlay_get_target_phandle(fdto, fragment); ++ if (phandle == (uint32_t)-1) ++ return -FDT_ERR_BADPHANDLE; ++ ++ /* no phandle, try path */ ++ if (!phandle) { ++ /* And then a path based lookup */ ++ path = fdt_getprop(fdto, fragment, "target-path", &path_len); ++ if (path) ++ ret = fdt_path_offset(fdt, path); ++ else ++ ret = path_len; ++ } else ++ ret = fdt_node_offset_by_phandle(fdt, phandle); ++ ++ /* ++ * If we haven't found either a target or a ++ * target-path property in a node that contains a ++ * __overlay__ subnode (we wouldn't be called ++ * otherwise), consider it a improperly written ++ * overlay ++ */ ++ if (ret < 0 && path_len == -FDT_ERR_NOTFOUND) ++ ret = -FDT_ERR_BADOVERLAY; ++ ++ /* return on error */ ++ if (ret < 0) ++ return ret; ++ ++ /* return pointer to path (if available) */ ++ if (pathp) ++ *pathp = path ? path : NULL; ++ ++ return ret; ++} ++ ++/** ++ * overlay_phandle_add_offset - Increases a phandle by an offset ++ * @fdt: Base device tree blob ++ * @node: Device tree overlay blob ++ * @name: Name of the property to modify (phandle or linux,phandle) ++ * @delta: offset to apply ++ * ++ * overlay_phandle_add_offset() increments a node phandle by a given ++ * offset. ++ * ++ * returns: ++ * 0 on success. ++ * Negative error code on error ++ */ ++static int overlay_phandle_add_offset(void *fdt, int node, ++ const char *name, uint32_t delta) ++{ ++ const fdt32_t *val; ++ uint32_t adj_val; ++ int len; ++ ++ val = fdt_getprop(fdt, node, name, &len); ++ if (!val) ++ return len; ++ ++ if (len != sizeof(*val)) ++ return -FDT_ERR_BADPHANDLE; ++ ++ adj_val = fdt32_to_cpu(*val); ++ if ((adj_val + delta) < adj_val) ++ return -FDT_ERR_NOPHANDLES; ++ ++ adj_val += delta; ++ if (adj_val == (uint32_t)-1) ++ return -FDT_ERR_NOPHANDLES; ++ ++ return fdt_setprop_inplace_u32(fdt, node, name, adj_val); ++} ++ ++/** ++ * overlay_adjust_node_phandles - Offsets the phandles of a node ++ * @fdto: Device tree overlay blob ++ * @node: Offset of the node we want to adjust ++ * @delta: Offset to shift the phandles of ++ * ++ * overlay_adjust_node_phandles() adds a constant to all the phandles ++ * of a given node. This is mainly use as part of the overlay ++ * application process, when we want to update all the overlay ++ * phandles to not conflict with the overlays of the base device tree. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_adjust_node_phandles(void *fdto, int node, ++ uint32_t delta) ++{ ++ int child; ++ int ret; ++ ++ ret = overlay_phandle_add_offset(fdto, node, "phandle", delta); ++ if (ret && ret != -FDT_ERR_NOTFOUND) ++ return ret; ++ ++ ret = overlay_phandle_add_offset(fdto, node, "linux,phandle", delta); ++ if (ret && ret != -FDT_ERR_NOTFOUND) ++ return ret; ++ ++ fdt_for_each_subnode(child, fdto, node) { ++ ret = overlay_adjust_node_phandles(fdto, child, delta); ++ if (ret) ++ return ret; ++ } ++ ++ return 0; ++} ++ ++/** ++ * overlay_adjust_local_phandles - Adjust the phandles of a whole overlay ++ * @fdto: Device tree overlay blob ++ * @delta: Offset to shift the phandles of ++ * ++ * overlay_adjust_local_phandles() adds a constant to all the ++ * phandles of an overlay. This is mainly use as part of the overlay ++ * application process, when we want to update all the overlay ++ * phandles to not conflict with the overlays of the base device tree. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_adjust_local_phandles(void *fdto, uint32_t delta) ++{ ++ /* ++ * Start adjusting the phandles from the overlay root ++ */ ++ return overlay_adjust_node_phandles(fdto, 0, delta); ++} ++ ++/** ++ * overlay_update_local_node_references - Adjust the overlay references ++ * @fdto: Device tree overlay blob ++ * @tree_node: Node offset of the node to operate on ++ * @fixup_node: Node offset of the matching local fixups node ++ * @delta: Offset to shift the phandles of ++ * ++ * overlay_update_local_nodes_references() update the phandles ++ * pointing to a node within the device tree overlay by adding a ++ * constant delta. ++ * ++ * This is mainly used as part of a device tree application process, ++ * where you want the device tree overlays phandles to not conflict ++ * with the ones from the base device tree before merging them. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_update_local_node_references(void *fdto, ++ int tree_node, ++ int fixup_node, ++ uint32_t delta) ++{ ++ int fixup_prop; ++ int fixup_child; ++ int ret; ++ ++ fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) { ++ const fdt32_t *fixup_val; ++ const char *tree_val; ++ const char *name; ++ int fixup_len; ++ int tree_len; ++ int i; ++ ++ fixup_val = fdt_getprop_by_offset(fdto, fixup_prop, ++ &name, &fixup_len); ++ if (!fixup_val) ++ return fixup_len; ++ ++ if (fixup_len % sizeof(uint32_t)) ++ return -FDT_ERR_BADOVERLAY; ++ fixup_len /= sizeof(uint32_t); ++ ++ tree_val = fdt_getprop(fdto, tree_node, name, &tree_len); ++ if (!tree_val) { ++ if (tree_len == -FDT_ERR_NOTFOUND) ++ return -FDT_ERR_BADOVERLAY; ++ ++ return tree_len; ++ } ++ ++ for (i = 0; i < fixup_len; i++) { ++ fdt32_t adj_val; ++ uint32_t poffset; ++ ++ poffset = fdt32_to_cpu(fixup_val[i]); ++ ++ /* ++ * phandles to fixup can be unaligned. ++ * ++ * Use a memcpy for the architectures that do ++ * not support unaligned accesses. ++ */ ++ memcpy(&adj_val, tree_val + poffset, sizeof(adj_val)); ++ ++ adj_val = cpu_to_fdt32(fdt32_to_cpu(adj_val) + delta); ++ ++ ret = fdt_setprop_inplace_namelen_partial(fdto, ++ tree_node, ++ name, ++ strlen(name), ++ poffset, ++ &adj_val, ++ sizeof(adj_val)); ++ if (ret == -FDT_ERR_NOSPACE) ++ return -FDT_ERR_BADOVERLAY; ++ ++ if (ret) ++ return ret; ++ } ++ } ++ ++ fdt_for_each_subnode(fixup_child, fdto, fixup_node) { ++ const char *fixup_child_name = fdt_get_name(fdto, fixup_child, ++ NULL); ++ int tree_child; ++ ++ tree_child = fdt_subnode_offset(fdto, tree_node, ++ fixup_child_name); ++ if (tree_child == -FDT_ERR_NOTFOUND) ++ return -FDT_ERR_BADOVERLAY; ++ if (tree_child < 0) ++ return tree_child; ++ ++ ret = overlay_update_local_node_references(fdto, ++ tree_child, ++ fixup_child, ++ delta); ++ if (ret) ++ return ret; ++ } ++ ++ return 0; ++} ++ ++/** ++ * overlay_update_local_references - Adjust the overlay references ++ * @fdto: Device tree overlay blob ++ * @delta: Offset to shift the phandles of ++ * ++ * overlay_update_local_references() update all the phandles pointing ++ * to a node within the device tree overlay by adding a constant ++ * delta to not conflict with the base overlay. ++ * ++ * This is mainly used as part of a device tree application process, ++ * where you want the device tree overlays phandles to not conflict ++ * with the ones from the base device tree before merging them. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_update_local_references(void *fdto, uint32_t delta) ++{ ++ int fixups; ++ ++ fixups = fdt_path_offset(fdto, "/__local_fixups__"); ++ if (fixups < 0) { ++ /* There's no local phandles to adjust, bail out */ ++ if (fixups == -FDT_ERR_NOTFOUND) ++ return 0; ++ ++ return fixups; ++ } ++ ++ /* ++ * Update our local references from the root of the tree ++ */ ++ return overlay_update_local_node_references(fdto, 0, fixups, ++ delta); ++} ++ ++/** ++ * overlay_fixup_one_phandle - Set an overlay phandle to the base one ++ * @fdt: Base Device Tree blob ++ * @fdto: Device tree overlay blob ++ * @symbols_off: Node offset of the symbols node in the base device tree ++ * @path: Path to a node holding a phandle in the overlay ++ * @path_len: number of path characters to consider ++ * @name: Name of the property holding the phandle reference in the overlay ++ * @name_len: number of name characters to consider ++ * @poffset: Offset within the overlay property where the phandle is stored ++ * @label: Label of the node referenced by the phandle ++ * ++ * overlay_fixup_one_phandle() resolves an overlay phandle pointing to ++ * a node in the base device tree. ++ * ++ * This is part of the device tree overlay application process, when ++ * you want all the phandles in the overlay to point to the actual ++ * base dt nodes. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_fixup_one_phandle(void *fdt, void *fdto, ++ int symbols_off, ++ const char *path, uint32_t path_len, ++ const char *name, uint32_t name_len, ++ int poffset, const char *label) ++{ ++ const char *symbol_path; ++ uint32_t phandle; ++ fdt32_t phandle_prop; ++ int symbol_off, fixup_off; ++ int prop_len; ++ ++ if (symbols_off < 0) ++ return symbols_off; ++ ++ symbol_path = fdt_getprop(fdt, symbols_off, label, ++ &prop_len); ++ if (!symbol_path) ++ return prop_len; ++ ++ symbol_off = fdt_path_offset(fdt, symbol_path); ++ if (symbol_off < 0) ++ return symbol_off; ++ ++ phandle = fdt_get_phandle(fdt, symbol_off); ++ if (!phandle) ++ return -FDT_ERR_NOTFOUND; ++ ++ fixup_off = fdt_path_offset_namelen(fdto, path, path_len); ++ if (fixup_off == -FDT_ERR_NOTFOUND) ++ return -FDT_ERR_BADOVERLAY; ++ if (fixup_off < 0) ++ return fixup_off; ++ ++ phandle_prop = cpu_to_fdt32(phandle); ++ return fdt_setprop_inplace_namelen_partial(fdto, fixup_off, ++ name, name_len, poffset, ++ &phandle_prop, ++ sizeof(phandle_prop)); ++}; ++ ++/** ++ * overlay_fixup_phandle - Set an overlay phandle to the base one ++ * @fdt: Base Device Tree blob ++ * @fdto: Device tree overlay blob ++ * @symbols_off: Node offset of the symbols node in the base device tree ++ * @property: Property offset in the overlay holding the list of fixups ++ * ++ * overlay_fixup_phandle() resolves all the overlay phandles pointed ++ * to in a __fixups__ property, and updates them to match the phandles ++ * in use in the base device tree. ++ * ++ * This is part of the device tree overlay application process, when ++ * you want all the phandles in the overlay to point to the actual ++ * base dt nodes. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off, ++ int property) ++{ ++ const char *value; ++ const char *label; ++ int len; ++ ++ value = fdt_getprop_by_offset(fdto, property, ++ &label, &len); ++ if (!value) { ++ if (len == -FDT_ERR_NOTFOUND) ++ return -FDT_ERR_INTERNAL; ++ ++ return len; ++ } ++ ++ do { ++ const char *path, *name, *fixup_end; ++ const char *fixup_str = value; ++ uint32_t path_len, name_len; ++ uint32_t fixup_len; ++ char *sep, *endptr; ++ int poffset, ret; ++ ++ fixup_end = memchr(value, '\0', len); ++ if (!fixup_end) ++ return -FDT_ERR_BADOVERLAY; ++ fixup_len = fixup_end - fixup_str; ++ ++ len -= fixup_len + 1; ++ value += fixup_len + 1; ++ ++ path = fixup_str; ++ sep = memchr(fixup_str, ':', fixup_len); ++ if (!sep || *sep != ':') ++ return -FDT_ERR_BADOVERLAY; ++ ++ path_len = sep - path; ++ if (path_len == (fixup_len - 1)) ++ return -FDT_ERR_BADOVERLAY; ++ ++ fixup_len -= path_len + 1; ++ name = sep + 1; ++ sep = memchr(name, ':', fixup_len); ++ if (!sep || *sep != ':') ++ return -FDT_ERR_BADOVERLAY; ++ ++ name_len = sep - name; ++ if (!name_len) ++ return -FDT_ERR_BADOVERLAY; ++ ++ poffset = strtoul(sep + 1, &endptr, 10); ++ if ((*endptr != '\0') || (endptr <= (sep + 1))) ++ return -FDT_ERR_BADOVERLAY; ++ ++ ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off, ++ path, path_len, name, name_len, ++ poffset, label); ++ if (ret) ++ return ret; ++ } while (len > 0); ++ ++ return 0; ++} ++ ++/** ++ * overlay_fixup_phandles - Resolve the overlay phandles to the base ++ * device tree ++ * @fdt: Base Device Tree blob ++ * @fdto: Device tree overlay blob ++ * ++ * overlay_fixup_phandles() resolves all the overlay phandles pointing ++ * to nodes in the base device tree. ++ * ++ * This is one of the steps of the device tree overlay application ++ * process, when you want all the phandles in the overlay to point to ++ * the actual base dt nodes. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_fixup_phandles(void *fdt, void *fdto) ++{ ++ int fixups_off, symbols_off; ++ int property; ++ ++ /* We can have overlays without any fixups */ ++ fixups_off = fdt_path_offset(fdto, "/__fixups__"); ++ if (fixups_off == -FDT_ERR_NOTFOUND) ++ return 0; /* nothing to do */ ++ if (fixups_off < 0) ++ return fixups_off; ++ ++ /* And base DTs without symbols */ ++ symbols_off = fdt_path_offset(fdt, "/__symbols__"); ++ if ((symbols_off < 0 && (symbols_off != -FDT_ERR_NOTFOUND))) ++ return symbols_off; ++ ++ fdt_for_each_property_offset(property, fdto, fixups_off) { ++ int ret; ++ ++ ret = overlay_fixup_phandle(fdt, fdto, symbols_off, property); ++ if (ret) ++ return ret; ++ } ++ ++ return 0; ++} ++ ++/** ++ * overlay_apply_node - Merges a node into the base device tree ++ * @fdt: Base Device Tree blob ++ * @target: Node offset in the base device tree to apply the fragment to ++ * @fdto: Device tree overlay blob ++ * @node: Node offset in the overlay holding the changes to merge ++ * ++ * overlay_apply_node() merges a node into a target base device tree ++ * node pointed. ++ * ++ * This is part of the final step in the device tree overlay ++ * application process, when all the phandles have been adjusted and ++ * resolved and you just have to merge overlay into the base device ++ * tree. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_apply_node(void *fdt, int target, ++ void *fdto, int node) ++{ ++ int property; ++ int subnode; ++ ++ fdt_for_each_property_offset(property, fdto, node) { ++ const char *name; ++ const void *prop; ++ int prop_len; ++ int ret; ++ ++ prop = fdt_getprop_by_offset(fdto, property, &name, ++ &prop_len); ++ if (prop_len == -FDT_ERR_NOTFOUND) ++ return -FDT_ERR_INTERNAL; ++ if (prop_len < 0) ++ return prop_len; ++ ++ ret = fdt_setprop(fdt, target, name, prop, prop_len); ++ if (ret) ++ return ret; ++ } ++ ++ fdt_for_each_subnode(subnode, fdto, node) { ++ const char *name = fdt_get_name(fdto, subnode, NULL); ++ int nnode; ++ int ret; ++ ++ nnode = fdt_add_subnode(fdt, target, name); ++ if (nnode == -FDT_ERR_EXISTS) { ++ nnode = fdt_subnode_offset(fdt, target, name); ++ if (nnode == -FDT_ERR_NOTFOUND) ++ return -FDT_ERR_INTERNAL; ++ } ++ ++ if (nnode < 0) ++ return nnode; ++ ++ ret = overlay_apply_node(fdt, nnode, fdto, subnode); ++ if (ret) ++ return ret; ++ } ++ ++ return 0; ++} ++ ++/** ++ * overlay_merge - Merge an overlay into its base device tree ++ * @fdt: Base Device Tree blob ++ * @fdto: Device tree overlay blob ++ * ++ * overlay_merge() merges an overlay into its base device tree. ++ * ++ * This is the next to last step in the device tree overlay application ++ * process, when all the phandles have been adjusted and resolved and ++ * you just have to merge overlay into the base device tree. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_merge(void *fdt, void *fdto) ++{ ++ int fragment; ++ ++ fdt_for_each_subnode(fragment, fdto, 0) { ++ int overlay; ++ int target; ++ int ret; ++ ++ /* ++ * Each fragments will have an __overlay__ node. If ++ * they don't, it's not supposed to be merged ++ */ ++ overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); ++ if (overlay == -FDT_ERR_NOTFOUND) ++ continue; ++ ++ if (overlay < 0) ++ return overlay; ++ ++ target = overlay_get_target(fdt, fdto, fragment, NULL); ++ if (target < 0) ++ return target; ++ ++ ret = overlay_apply_node(fdt, target, fdto, overlay); ++ if (ret) ++ return ret; ++ } ++ ++ return 0; ++} ++ ++static int get_path_len(const void *fdt, int nodeoffset) ++{ ++ int len = 0, namelen; ++ const char *name; ++ ++ FDT_RO_PROBE(fdt); ++ ++ for (;;) { ++ name = fdt_get_name(fdt, nodeoffset, &namelen); ++ if (!name) ++ return namelen; ++ ++ /* root? we're done */ ++ if (namelen == 0) ++ break; ++ ++ nodeoffset = fdt_parent_offset(fdt, nodeoffset); ++ if (nodeoffset < 0) ++ return nodeoffset; ++ len += namelen + 1; ++ } ++ ++ /* in case of root pretend it's "/" */ ++ if (len == 0) ++ len++; ++ return len; ++} ++ ++/** ++ * overlay_symbol_update - Update the symbols of base tree after a merge ++ * @fdt: Base Device Tree blob ++ * @fdto: Device tree overlay blob ++ * ++ * overlay_symbol_update() updates the symbols of the base tree with the ++ * symbols of the applied overlay ++ * ++ * This is the last step in the device tree overlay application ++ * process, allowing the reference of overlay symbols by subsequent ++ * overlay operations. ++ * ++ * returns: ++ * 0 on success ++ * Negative error code on failure ++ */ ++static int overlay_symbol_update(void *fdt, void *fdto) ++{ ++ int root_sym, ov_sym, prop, path_len, fragment, target; ++ int len, frag_name_len, ret, rel_path_len; ++ const char *s, *e; ++ const char *path; ++ const char *name; ++ const char *frag_name; ++ const char *rel_path; ++ const char *target_path; ++ char *buf; ++ void *p; ++ ++ ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__"); ++ ++ /* if no overlay symbols exist no problem */ ++ if (ov_sym < 0) ++ return 0; ++ ++ root_sym = fdt_subnode_offset(fdt, 0, "__symbols__"); ++ ++ /* it no root symbols exist we should create them */ ++ if (root_sym == -FDT_ERR_NOTFOUND) ++ root_sym = fdt_add_subnode(fdt, 0, "__symbols__"); ++ ++ /* any error is fatal now */ ++ if (root_sym < 0) ++ return root_sym; ++ ++ /* iterate over each overlay symbol */ ++ fdt_for_each_property_offset(prop, fdto, ov_sym) { ++ path = fdt_getprop_by_offset(fdto, prop, &name, &path_len); ++ if (!path) ++ return path_len; ++ ++ /* verify it's a string property (terminated by a single \0) */ ++ if (path_len < 1 || memchr(path, '\0', path_len) != &path[path_len - 1]) ++ return -FDT_ERR_BADVALUE; ++ ++ /* keep end marker to avoid strlen() */ ++ e = path + path_len; ++ ++ if (*path != '/') ++ return -FDT_ERR_BADVALUE; ++ ++ /* get fragment name first */ ++ s = strchr(path + 1, '/'); ++ if (!s) { ++ /* Symbol refers to something that won't end ++ * up in the target tree */ ++ continue; ++ } ++ ++ frag_name = path + 1; ++ frag_name_len = s - path - 1; ++ ++ /* verify format; safe since "s" lies in \0 terminated prop */ ++ len = sizeof("/__overlay__/") - 1; ++ if ((e - s) > len && (memcmp(s, "/__overlay__/", len) == 0)) { ++ /* //__overlay__/ */ ++ rel_path = s + len; ++ rel_path_len = e - rel_path - 1; ++ } else if ((e - s) == len ++ && (memcmp(s, "/__overlay__", len - 1) == 0)) { ++ /* //__overlay__ */ ++ rel_path = ""; ++ rel_path_len = 0; ++ } else { ++ /* Symbol refers to something that won't end ++ * up in the target tree */ ++ continue; ++ } ++ ++ /* find the fragment index in which the symbol lies */ ++ ret = fdt_subnode_offset_namelen(fdto, 0, frag_name, ++ frag_name_len); ++ /* not found? */ ++ if (ret < 0) ++ return -FDT_ERR_BADOVERLAY; ++ fragment = ret; ++ ++ /* an __overlay__ subnode must exist */ ++ ret = fdt_subnode_offset(fdto, fragment, "__overlay__"); ++ if (ret < 0) ++ return -FDT_ERR_BADOVERLAY; ++ ++ /* get the target of the fragment */ ++ ret = overlay_get_target(fdt, fdto, fragment, &target_path); ++ if (ret < 0) ++ return ret; ++ target = ret; ++ ++ /* if we have a target path use */ ++ if (!target_path) { ++ ret = get_path_len(fdt, target); ++ if (ret < 0) ++ return ret; ++ len = ret; ++ } else { ++ len = strlen(target_path); ++ } ++ ++ ret = fdt_setprop_placeholder(fdt, root_sym, name, ++ len + (len > 1) + rel_path_len + 1, &p); ++ if (ret < 0) ++ return ret; ++ ++ if (!target_path) { ++ /* again in case setprop_placeholder changed it */ ++ ret = overlay_get_target(fdt, fdto, fragment, &target_path); ++ if (ret < 0) ++ return ret; ++ target = ret; ++ } ++ ++ buf = p; ++ if (len > 1) { /* target is not root */ ++ if (!target_path) { ++ ret = fdt_get_path(fdt, target, buf, len + 1); ++ if (ret < 0) ++ return ret; ++ } else ++ memcpy(buf, target_path, len + 1); ++ ++ } else ++ len--; ++ ++ buf[len] = '/'; ++ memcpy(buf + len + 1, rel_path, rel_path_len); ++ buf[len + 1 + rel_path_len] = '\0'; ++ } ++ ++ return 0; ++} ++ ++int fdt_overlay_apply(void *fdt, void *fdto) ++{ ++ uint32_t delta; ++ int ret; ++ ++ FDT_RO_PROBE(fdt); ++ FDT_RO_PROBE(fdto); ++ ++ ret = fdt_find_max_phandle(fdt, &delta); ++ if (ret) ++ goto err; ++ ++ ret = overlay_adjust_local_phandles(fdto, delta); ++ if (ret) ++ goto err; ++ ++ ret = overlay_update_local_references(fdto, delta); ++ if (ret) ++ goto err; ++ ++ ret = overlay_fixup_phandles(fdt, fdto); ++ if (ret) ++ goto err; ++ ++ ret = overlay_merge(fdt, fdto); ++ if (ret) ++ goto err; ++ ++ ret = overlay_symbol_update(fdt, fdto); ++ if (ret) ++ goto err; ++ ++ /* ++ * The overlay has been damaged, erase its magic. ++ */ ++ fdt_set_magic(fdto, ~0); ++ ++ return 0; ++ ++err: ++ /* ++ * The overlay might have been damaged, erase its magic. ++ */ ++ fdt_set_magic(fdto, ~0); ++ ++ /* ++ * The base device tree might have been damaged, erase its ++ * magic. ++ */ ++ fdt_set_magic(fdt, ~0); ++ ++ return ret; ++} +diff --git a/common/libfdt/fdt_ro.c b/common/libfdt/fdt_ro.c +new file mode 100644 +index 0000000..17584da +--- /dev/null ++++ b/common/libfdt/fdt_ro.c +@@ -0,0 +1,859 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++static int fdt_nodename_eq_(const void *fdt, int offset, ++ const char *s, int len) ++{ ++ int olen; ++ const char *p = fdt_get_name(fdt, offset, &olen); ++ ++ if (!p || olen < len) ++ /* short match */ ++ return 0; ++ ++ if (memcmp(p, s, len) != 0) ++ return 0; ++ ++ if (p[len] == '\0') ++ return 1; ++ else if (!memchr(s, '@', len) && (p[len] == '@')) ++ return 1; ++ else ++ return 0; ++} ++ ++const char *fdt_get_string(const void *fdt, int stroffset, int *lenp) ++{ ++ int32_t totalsize; ++ uint32_t absoffset; ++ size_t len; ++ int err; ++ const char *s, *n; ++ ++ if (can_assume(VALID_INPUT)) { ++ s = (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset; ++ ++ if (lenp) ++ *lenp = strlen(s); ++ return s; ++ } ++ totalsize = fdt_ro_probe_(fdt); ++ err = totalsize; ++ if (totalsize < 0) ++ goto fail; ++ ++ err = -FDT_ERR_BADOFFSET; ++ absoffset = stroffset + fdt_off_dt_strings(fdt); ++ if (absoffset >= (unsigned)totalsize) ++ goto fail; ++ len = totalsize - absoffset; ++ ++ if (fdt_magic(fdt) == FDT_MAGIC) { ++ if (stroffset < 0) ++ goto fail; ++ if (can_assume(LATEST) || fdt_version(fdt) >= 17) { ++ if ((unsigned)stroffset >= fdt_size_dt_strings(fdt)) ++ goto fail; ++ if ((fdt_size_dt_strings(fdt) - stroffset) < len) ++ len = fdt_size_dt_strings(fdt) - stroffset; ++ } ++ } else if (fdt_magic(fdt) == FDT_SW_MAGIC) { ++ unsigned int sw_stroffset = -stroffset; ++ ++ if ((stroffset >= 0) || ++ (sw_stroffset > fdt_size_dt_strings(fdt))) ++ goto fail; ++ if (sw_stroffset < len) ++ len = sw_stroffset; ++ } else { ++ err = -FDT_ERR_INTERNAL; ++ goto fail; ++ } ++ ++ s = (const char *)fdt + absoffset; ++ n = memchr(s, '\0', len); ++ if (!n) { ++ /* missing terminating NULL */ ++ err = -FDT_ERR_TRUNCATED; ++ goto fail; ++ } ++ ++ if (lenp) ++ *lenp = n - s; ++ return s; ++ ++fail: ++ if (lenp) ++ *lenp = err; ++ return NULL; ++} ++ ++const char *fdt_string(const void *fdt, int stroffset) ++{ ++ return fdt_get_string(fdt, stroffset, NULL); ++} ++ ++static int fdt_string_eq_(const void *fdt, int stroffset, ++ const char *s, int len) ++{ ++ int slen; ++ const char *p = fdt_get_string(fdt, stroffset, &slen); ++ ++ return p && (slen == len) && (memcmp(p, s, len) == 0); ++} ++ ++int fdt_find_max_phandle(const void *fdt, uint32_t *phandle) ++{ ++ uint32_t max = 0; ++ int offset = -1; ++ ++ while (true) { ++ uint32_t value; ++ ++ offset = fdt_next_node(fdt, offset, NULL); ++ if (offset < 0) { ++ if (offset == -FDT_ERR_NOTFOUND) ++ break; ++ ++ return offset; ++ } ++ ++ value = fdt_get_phandle(fdt, offset); ++ ++ if (value > max) ++ max = value; ++ } ++ ++ if (phandle) ++ *phandle = max; ++ ++ return 0; ++} ++ ++int fdt_generate_phandle(const void *fdt, uint32_t *phandle) ++{ ++ uint32_t max; ++ int err; ++ ++ err = fdt_find_max_phandle(fdt, &max); ++ if (err < 0) ++ return err; ++ ++ if (max == FDT_MAX_PHANDLE) ++ return -FDT_ERR_NOPHANDLES; ++ ++ if (phandle) ++ *phandle = max + 1; ++ ++ return 0; ++} ++ ++static const struct fdt_reserve_entry *fdt_mem_rsv(const void *fdt, int n) ++{ ++ unsigned int offset = n * sizeof(struct fdt_reserve_entry); ++ unsigned int absoffset = fdt_off_mem_rsvmap(fdt) + offset; ++ ++ if (!can_assume(VALID_INPUT)) { ++ if (absoffset < fdt_off_mem_rsvmap(fdt)) ++ return NULL; ++ if (absoffset > fdt_totalsize(fdt) - ++ sizeof(struct fdt_reserve_entry)) ++ return NULL; ++ } ++ return fdt_mem_rsv_(fdt, n); ++} ++ ++int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size) ++{ ++ const struct fdt_reserve_entry *re; ++ ++ FDT_RO_PROBE(fdt); ++ re = fdt_mem_rsv(fdt, n); ++ if (!can_assume(VALID_INPUT) && !re) ++ return -FDT_ERR_BADOFFSET; ++ ++ *address = fdt64_ld_(&re->address); ++ *size = fdt64_ld_(&re->size); ++ return 0; ++} ++ ++int fdt_num_mem_rsv(const void *fdt) ++{ ++ int i; ++ const struct fdt_reserve_entry *re; ++ ++ for (i = 0; (re = fdt_mem_rsv(fdt, i)) != NULL; i++) { ++ if (fdt64_ld_(&re->size) == 0) ++ return i; ++ } ++ return -FDT_ERR_TRUNCATED; ++} ++ ++static int nextprop_(const void *fdt, int offset) ++{ ++ uint32_t tag; ++ int nextoffset; ++ ++ do { ++ tag = fdt_next_tag(fdt, offset, &nextoffset); ++ ++ switch (tag) { ++ case FDT_END: ++ if (nextoffset >= 0) ++ return -FDT_ERR_BADSTRUCTURE; ++ else ++ return nextoffset; ++ ++ case FDT_PROP: ++ return offset; ++ } ++ offset = nextoffset; ++ } while (tag == FDT_NOP); ++ ++ return -FDT_ERR_NOTFOUND; ++} ++ ++int fdt_subnode_offset_namelen(const void *fdt, int offset, ++ const char *name, int namelen) ++{ ++ int depth; ++ ++ FDT_RO_PROBE(fdt); ++ ++ for (depth = 0; ++ (offset >= 0) && (depth >= 0); ++ offset = fdt_next_node(fdt, offset, &depth)) ++ if ((depth == 1) ++ && fdt_nodename_eq_(fdt, offset, name, namelen)) ++ return offset; ++ ++ if (depth < 0) ++ return -FDT_ERR_NOTFOUND; ++ return offset; /* error */ ++} ++ ++int fdt_subnode_offset(const void *fdt, int parentoffset, ++ const char *name) ++{ ++ return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name)); ++} ++ ++int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen) ++{ ++ const char *end = path + namelen; ++ const char *p = path; ++ int offset = 0; ++ ++ FDT_RO_PROBE(fdt); ++ ++ /* see if we have an alias */ ++ if (*path != '/') { ++ const char *q = memchr(path, '/', end - p); ++ ++ if (!q) ++ q = end; ++ ++ p = fdt_get_alias_namelen(fdt, p, q - p); ++ if (!p) ++ return -FDT_ERR_BADPATH; ++ offset = fdt_path_offset(fdt, p); ++ ++ p = q; ++ } ++ ++ while (p < end) { ++ const char *q; ++ ++ while (*p == '/') { ++ p++; ++ if (p == end) ++ return offset; ++ } ++ q = memchr(p, '/', end - p); ++ if (! q) ++ q = end; ++ ++ offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p); ++ if (offset < 0) ++ return offset; ++ ++ p = q; ++ } ++ ++ return offset; ++} ++ ++int fdt_path_offset(const void *fdt, const char *path) ++{ ++ return fdt_path_offset_namelen(fdt, path, strlen(path)); ++} ++ ++const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) ++{ ++ const struct fdt_node_header *nh = fdt_offset_ptr_(fdt, nodeoffset); ++ const char *nameptr; ++ int err; ++ ++ if (((err = fdt_ro_probe_(fdt)) < 0) ++ || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0)) ++ goto fail; ++ ++ nameptr = nh->name; ++ ++ if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) { ++ /* ++ * For old FDT versions, match the naming conventions of V16: ++ * give only the leaf name (after all /). The actual tree ++ * contents are loosely checked. ++ */ ++ const char *leaf; ++ leaf = strrchr(nameptr, '/'); ++ if (leaf == NULL) { ++ err = -FDT_ERR_BADSTRUCTURE; ++ goto fail; ++ } ++ nameptr = leaf+1; ++ } ++ ++ if (len) ++ *len = strlen(nameptr); ++ ++ return nameptr; ++ ++ fail: ++ if (len) ++ *len = err; ++ return NULL; ++} ++ ++int fdt_first_property_offset(const void *fdt, int nodeoffset) ++{ ++ int offset; ++ ++ if ((offset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) ++ return offset; ++ ++ return nextprop_(fdt, offset); ++} ++ ++int fdt_next_property_offset(const void *fdt, int offset) ++{ ++ if ((offset = fdt_check_prop_offset_(fdt, offset)) < 0) ++ return offset; ++ ++ return nextprop_(fdt, offset); ++} ++ ++static const struct fdt_property *fdt_get_property_by_offset_(const void *fdt, ++ int offset, ++ int *lenp) ++{ ++ int err; ++ const struct fdt_property *prop; ++ ++ if (!can_assume(VALID_INPUT) && ++ (err = fdt_check_prop_offset_(fdt, offset)) < 0) { ++ if (lenp) ++ *lenp = err; ++ return NULL; ++ } ++ ++ prop = fdt_offset_ptr_(fdt, offset); ++ ++ if (lenp) ++ *lenp = fdt32_ld_(&prop->len); ++ ++ return prop; ++} ++ ++const struct fdt_property *fdt_get_property_by_offset(const void *fdt, ++ int offset, ++ int *lenp) ++{ ++ /* Prior to version 16, properties may need realignment ++ * and this API does not work. fdt_getprop_*() will, however. */ ++ ++ if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) { ++ if (lenp) ++ *lenp = -FDT_ERR_BADVERSION; ++ return NULL; ++ } ++ ++ return fdt_get_property_by_offset_(fdt, offset, lenp); ++} ++ ++static const struct fdt_property *fdt_get_property_namelen_(const void *fdt, ++ int offset, ++ const char *name, ++ int namelen, ++ int *lenp, ++ int *poffset) ++{ ++ for (offset = fdt_first_property_offset(fdt, offset); ++ (offset >= 0); ++ (offset = fdt_next_property_offset(fdt, offset))) { ++ const struct fdt_property *prop; ++ ++ prop = fdt_get_property_by_offset_(fdt, offset, lenp); ++ if (!can_assume(LIBFDT_FLAWLESS) && !prop) { ++ offset = -FDT_ERR_INTERNAL; ++ break; ++ } ++ if (fdt_string_eq_(fdt, fdt32_ld_(&prop->nameoff), ++ name, namelen)) { ++ if (poffset) ++ *poffset = offset; ++ return prop; ++ } ++ } ++ ++ if (lenp) ++ *lenp = offset; ++ return NULL; ++} ++ ++ ++const struct fdt_property *fdt_get_property_namelen(const void *fdt, ++ int offset, ++ const char *name, ++ int namelen, int *lenp) ++{ ++ /* Prior to version 16, properties may need realignment ++ * and this API does not work. fdt_getprop_*() will, however. */ ++ if (!can_assume(LATEST) && fdt_version(fdt) < 0x10) { ++ if (lenp) ++ *lenp = -FDT_ERR_BADVERSION; ++ return NULL; ++ } ++ ++ return fdt_get_property_namelen_(fdt, offset, name, namelen, lenp, ++ NULL); ++} ++ ++ ++const struct fdt_property *fdt_get_property(const void *fdt, ++ int nodeoffset, ++ const char *name, int *lenp) ++{ ++ return fdt_get_property_namelen(fdt, nodeoffset, name, ++ strlen(name), lenp); ++} ++ ++const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, ++ const char *name, int namelen, int *lenp) ++{ ++ int poffset; ++ const struct fdt_property *prop; ++ ++ prop = fdt_get_property_namelen_(fdt, nodeoffset, name, namelen, lenp, ++ &poffset); ++ if (!prop) ++ return NULL; ++ ++ /* Handle realignment */ ++ if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 && ++ (poffset + sizeof(*prop)) % 8 && fdt32_ld_(&prop->len) >= 8) ++ return prop->data + 4; ++ return prop->data; ++} ++ ++const void *fdt_getprop_by_offset(const void *fdt, int offset, ++ const char **namep, int *lenp) ++{ ++ const struct fdt_property *prop; ++ ++ prop = fdt_get_property_by_offset_(fdt, offset, lenp); ++ if (!prop) ++ return NULL; ++ if (namep) { ++ const char *name; ++ int namelen; ++ ++ if (!can_assume(VALID_INPUT)) { ++ name = fdt_get_string(fdt, fdt32_ld_(&prop->nameoff), ++ &namelen); ++ if (!name) { ++ if (lenp) ++ *lenp = namelen; ++ return NULL; ++ } ++ *namep = name; ++ } else { ++ *namep = fdt_string(fdt, fdt32_ld_(&prop->nameoff)); ++ } ++ } ++ ++ /* Handle realignment */ ++ if (!can_assume(LATEST) && fdt_version(fdt) < 0x10 && ++ (offset + sizeof(*prop)) % 8 && fdt32_ld_(&prop->len) >= 8) ++ return prop->data + 4; ++ return prop->data; ++} ++ ++const void *fdt_getprop(const void *fdt, int nodeoffset, ++ const char *name, int *lenp) ++{ ++ return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp); ++} ++ ++uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) ++{ ++ const fdt32_t *php; ++ int len; ++ ++ /* FIXME: This is a bit sub-optimal, since we potentially scan ++ * over all the properties twice. */ ++ php = fdt_getprop(fdt, nodeoffset, "phandle", &len); ++ if (!php || (len != sizeof(*php))) { ++ php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len); ++ if (!php || (len != sizeof(*php))) ++ return 0; ++ } ++ ++ return fdt32_ld_(php); ++} ++ ++const char *fdt_get_alias_namelen(const void *fdt, ++ const char *name, int namelen) ++{ ++ int aliasoffset; ++ ++ aliasoffset = fdt_path_offset(fdt, "/aliases"); ++ if (aliasoffset < 0) ++ return NULL; ++ ++ return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL); ++} ++ ++const char *fdt_get_alias(const void *fdt, const char *name) ++{ ++ return fdt_get_alias_namelen(fdt, name, strlen(name)); ++} ++ ++int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) ++{ ++ int pdepth = 0, p = 0; ++ int offset, depth, namelen; ++ const char *name; ++ ++ FDT_RO_PROBE(fdt); ++ ++ if (buflen < 2) ++ return -FDT_ERR_NOSPACE; ++ ++ for (offset = 0, depth = 0; ++ (offset >= 0) && (offset <= nodeoffset); ++ offset = fdt_next_node(fdt, offset, &depth)) { ++ while (pdepth > depth) { ++ do { ++ p--; ++ } while (buf[p-1] != '/'); ++ pdepth--; ++ } ++ ++ if (pdepth >= depth) { ++ name = fdt_get_name(fdt, offset, &namelen); ++ if (!name) ++ return namelen; ++ if ((p + namelen + 1) <= buflen) { ++ memcpy(buf + p, name, namelen); ++ p += namelen; ++ buf[p++] = '/'; ++ pdepth++; ++ } ++ } ++ ++ if (offset == nodeoffset) { ++ if (pdepth < (depth + 1)) ++ return -FDT_ERR_NOSPACE; ++ ++ if (p > 1) /* special case so that root path is "/", not "" */ ++ p--; ++ buf[p] = '\0'; ++ return 0; ++ } ++ } ++ ++ if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) ++ return -FDT_ERR_BADOFFSET; ++ else if (offset == -FDT_ERR_BADOFFSET) ++ return -FDT_ERR_BADSTRUCTURE; ++ ++ return offset; /* error from fdt_next_node() */ ++} ++ ++int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, ++ int supernodedepth, int *nodedepth) ++{ ++ int offset, depth; ++ int supernodeoffset = -FDT_ERR_INTERNAL; ++ ++ FDT_RO_PROBE(fdt); ++ ++ if (supernodedepth < 0) ++ return -FDT_ERR_NOTFOUND; ++ ++ for (offset = 0, depth = 0; ++ (offset >= 0) && (offset <= nodeoffset); ++ offset = fdt_next_node(fdt, offset, &depth)) { ++ if (depth == supernodedepth) ++ supernodeoffset = offset; ++ ++ if (offset == nodeoffset) { ++ if (nodedepth) ++ *nodedepth = depth; ++ ++ if (supernodedepth > depth) ++ return -FDT_ERR_NOTFOUND; ++ else ++ return supernodeoffset; ++ } ++ } ++ ++ if (!can_assume(VALID_INPUT)) { ++ if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) ++ return -FDT_ERR_BADOFFSET; ++ else if (offset == -FDT_ERR_BADOFFSET) ++ return -FDT_ERR_BADSTRUCTURE; ++ } ++ ++ return offset; /* error from fdt_next_node() */ ++} ++ ++int fdt_node_depth(const void *fdt, int nodeoffset) ++{ ++ int nodedepth; ++ int err; ++ ++ err = fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, &nodedepth); ++ if (err) ++ return (can_assume(LIBFDT_FLAWLESS) || err < 0) ? err : ++ -FDT_ERR_INTERNAL; ++ return nodedepth; ++} ++ ++int fdt_parent_offset(const void *fdt, int nodeoffset) ++{ ++ int nodedepth = fdt_node_depth(fdt, nodeoffset); ++ ++ if (nodedepth < 0) ++ return nodedepth; ++ return fdt_supernode_atdepth_offset(fdt, nodeoffset, ++ nodedepth - 1, NULL); ++} ++ ++int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, ++ const char *propname, ++ const void *propval, int proplen) ++{ ++ int offset; ++ const void *val; ++ int len; ++ ++ FDT_RO_PROBE(fdt); ++ ++ /* FIXME: The algorithm here is pretty horrible: we scan each ++ * property of a node in fdt_getprop(), then if that didn't ++ * find what we want, we scan over them again making our way ++ * to the next node. Still it's the easiest to implement ++ * approach; performance can come later. */ ++ for (offset = fdt_next_node(fdt, startoffset, NULL); ++ offset >= 0; ++ offset = fdt_next_node(fdt, offset, NULL)) { ++ val = fdt_getprop(fdt, offset, propname, &len); ++ if (val && (len == proplen) ++ && (memcmp(val, propval, len) == 0)) ++ return offset; ++ } ++ ++ return offset; /* error from fdt_next_node() */ ++} ++ ++int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle) ++{ ++ int offset; ++ ++ if ((phandle == 0) || (phandle == ~0U)) ++ return -FDT_ERR_BADPHANDLE; ++ ++ FDT_RO_PROBE(fdt); ++ ++ /* FIXME: The algorithm here is pretty horrible: we ++ * potentially scan each property of a node in ++ * fdt_get_phandle(), then if that didn't find what ++ * we want, we scan over them again making our way to the next ++ * node. Still it's the easiest to implement approach; ++ * performance can come later. */ ++ for (offset = fdt_next_node(fdt, -1, NULL); ++ offset >= 0; ++ offset = fdt_next_node(fdt, offset, NULL)) { ++ if (fdt_get_phandle(fdt, offset) == phandle) ++ return offset; ++ } ++ ++ return offset; /* error from fdt_next_node() */ ++} ++ ++int fdt_stringlist_contains(const char *strlist, int listlen, const char *str) ++{ ++ int len = strlen(str); ++ const char *p; ++ ++ while (listlen >= len) { ++ if (memcmp(str, strlist, len+1) == 0) ++ return 1; ++ p = memchr(strlist, '\0', listlen); ++ if (!p) ++ return 0; /* malformed strlist.. */ ++ listlen -= (p-strlist) + 1; ++ strlist = p + 1; ++ } ++ return 0; ++} ++ ++int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property) ++{ ++ const char *list, *end; ++ int length, count = 0; ++ ++ list = fdt_getprop(fdt, nodeoffset, property, &length); ++ if (!list) ++ return length; ++ ++ end = list + length; ++ ++ while (list < end) { ++ length = strnlen(list, end - list) + 1; ++ ++ /* Abort if the last string isn't properly NUL-terminated. */ ++ if (list + length > end) ++ return -FDT_ERR_BADVALUE; ++ ++ list += length; ++ count++; ++ } ++ ++ return count; ++} ++ ++int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, ++ const char *string) ++{ ++ int length, len, idx = 0; ++ const char *list, *end; ++ ++ list = fdt_getprop(fdt, nodeoffset, property, &length); ++ if (!list) ++ return length; ++ ++ len = strlen(string) + 1; ++ end = list + length; ++ ++ while (list < end) { ++ length = strnlen(list, end - list) + 1; ++ ++ /* Abort if the last string isn't properly NUL-terminated. */ ++ if (list + length > end) ++ return -FDT_ERR_BADVALUE; ++ ++ if (length == len && memcmp(list, string, length) == 0) ++ return idx; ++ ++ list += length; ++ idx++; ++ } ++ ++ return -FDT_ERR_NOTFOUND; ++} ++ ++const char *fdt_stringlist_get(const void *fdt, int nodeoffset, ++ const char *property, int idx, ++ int *lenp) ++{ ++ const char *list, *end; ++ int length; ++ ++ list = fdt_getprop(fdt, nodeoffset, property, &length); ++ if (!list) { ++ if (lenp) ++ *lenp = length; ++ ++ return NULL; ++ } ++ ++ end = list + length; ++ ++ while (list < end) { ++ length = strnlen(list, end - list) + 1; ++ ++ /* Abort if the last string isn't properly NUL-terminated. */ ++ if (list + length > end) { ++ if (lenp) ++ *lenp = -FDT_ERR_BADVALUE; ++ ++ return NULL; ++ } ++ ++ if (idx == 0) { ++ if (lenp) ++ *lenp = length - 1; ++ ++ return list; ++ } ++ ++ list += length; ++ idx--; ++ } ++ ++ if (lenp) ++ *lenp = -FDT_ERR_NOTFOUND; ++ ++ return NULL; ++} ++ ++int fdt_node_check_compatible(const void *fdt, int nodeoffset, ++ const char *compatible) ++{ ++ const void *prop; ++ int len; ++ ++ prop = fdt_getprop(fdt, nodeoffset, "compatible", &len); ++ if (!prop) ++ return len; ++ ++ return !fdt_stringlist_contains(prop, len, compatible); ++} ++ ++int fdt_node_offset_by_compatible(const void *fdt, int startoffset, ++ const char *compatible) ++{ ++ int offset, err; ++ ++ FDT_RO_PROBE(fdt); ++ ++ /* FIXME: The algorithm here is pretty horrible: we scan each ++ * property of a node in fdt_node_check_compatible(), then if ++ * that didn't find what we want, we scan over them again ++ * making our way to the next node. Still it's the easiest to ++ * implement approach; performance can come later. */ ++ for (offset = fdt_next_node(fdt, startoffset, NULL); ++ offset >= 0; ++ offset = fdt_next_node(fdt, offset, NULL)) { ++ err = fdt_node_check_compatible(fdt, offset, compatible); ++ if ((err < 0) && (err != -FDT_ERR_NOTFOUND)) ++ return err; ++ else if (err == 0) ++ return offset; ++ } ++ ++ return offset; /* error from fdt_next_node() */ ++} +diff --git a/common/libfdt/fdt_rw.c b/common/libfdt/fdt_rw.c +new file mode 100644 +index 0000000..3621d36 +--- /dev/null ++++ b/common/libfdt/fdt_rw.c +@@ -0,0 +1,500 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++static int fdt_blocks_misordered_(const void *fdt, ++ int mem_rsv_size, int struct_size) ++{ ++ return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8)) ++ || (fdt_off_dt_struct(fdt) < ++ (fdt_off_mem_rsvmap(fdt) + mem_rsv_size)) ++ || (fdt_off_dt_strings(fdt) < ++ (fdt_off_dt_struct(fdt) + struct_size)) ++ || (fdt_totalsize(fdt) < ++ (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt))); ++} ++ ++static int fdt_rw_probe_(void *fdt) ++{ ++ if (can_assume(VALID_DTB)) ++ return 0; ++ FDT_RO_PROBE(fdt); ++ ++ if (!can_assume(LATEST) && fdt_version(fdt) < 17) ++ return -FDT_ERR_BADVERSION; ++ if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry), ++ fdt_size_dt_struct(fdt))) ++ return -FDT_ERR_BADLAYOUT; ++ if (!can_assume(LATEST) && fdt_version(fdt) > 17) ++ fdt_set_version(fdt, 17); ++ ++ return 0; ++} ++ ++#define FDT_RW_PROBE(fdt) \ ++ { \ ++ int err_; \ ++ if ((err_ = fdt_rw_probe_(fdt)) != 0) \ ++ return err_; \ ++ } ++ ++static inline unsigned int fdt_data_size_(void *fdt) ++{ ++ return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); ++} ++ ++static int fdt_splice_(void *fdt, void *splicepoint, int oldlen, int newlen) ++{ ++ char *p = splicepoint; ++ unsigned int dsize = fdt_data_size_(fdt); ++ size_t soff = p - (char *)fdt; ++ ++ if ((oldlen < 0) || (soff + oldlen < soff) || (soff + oldlen > dsize)) ++ return -FDT_ERR_BADOFFSET; ++ if ((p < (char *)fdt) || (dsize + newlen < (unsigned)oldlen)) ++ return -FDT_ERR_BADOFFSET; ++ if (dsize - oldlen + newlen > fdt_totalsize(fdt)) ++ return -FDT_ERR_NOSPACE; ++ memmove(p + newlen, p + oldlen, ((char *)fdt + dsize) - (p + oldlen)); ++ return 0; ++} ++ ++static int fdt_splice_mem_rsv_(void *fdt, struct fdt_reserve_entry *p, ++ int oldn, int newn) ++{ ++ int delta = (newn - oldn) * sizeof(*p); ++ int err; ++ err = fdt_splice_(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); ++ if (err) ++ return err; ++ fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta); ++ fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); ++ return 0; ++} ++ ++static int fdt_splice_struct_(void *fdt, void *p, ++ int oldlen, int newlen) ++{ ++ int delta = newlen - oldlen; ++ int err; ++ ++ if ((err = fdt_splice_(fdt, p, oldlen, newlen))) ++ return err; ++ ++ fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta); ++ fdt_set_off_dt_strings(fdt, fdt_off_dt_strings(fdt) + delta); ++ return 0; ++} ++ ++/* Must only be used to roll back in case of error */ ++static void fdt_del_last_string_(void *fdt, const char *s) ++{ ++ int newlen = strlen(s) + 1; ++ ++ fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) - newlen); ++} ++ ++static int fdt_splice_string_(void *fdt, int newlen) ++{ ++ void *p = (char *)fdt ++ + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); ++ int err; ++ ++ if ((err = fdt_splice_(fdt, p, 0, newlen))) ++ return err; ++ ++ fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen); ++ return 0; ++} ++ ++/** ++ * fdt_find_add_string_() - Find or allocate a string ++ * ++ * @fdt: pointer to the device tree to check/adjust ++ * @s: string to find/add ++ * @allocated: Set to 0 if the string was found, 1 if not found and so ++ * allocated. Ignored if can_assume(NO_ROLLBACK) ++ * @return offset of string in the string table (whether found or added) ++ */ ++static int fdt_find_add_string_(void *fdt, const char *s, int *allocated) ++{ ++ char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); ++ const char *p; ++ char *new; ++ int len = strlen(s) + 1; ++ int err; ++ ++ if (!can_assume(NO_ROLLBACK)) ++ *allocated = 0; ++ ++ p = fdt_find_string_(strtab, fdt_size_dt_strings(fdt), s); ++ if (p) ++ /* found it */ ++ return (p - strtab); ++ ++ new = strtab + fdt_size_dt_strings(fdt); ++ err = fdt_splice_string_(fdt, len); ++ if (err) ++ return err; ++ ++ if (!can_assume(NO_ROLLBACK)) ++ *allocated = 1; ++ ++ memcpy(new, s, len); ++ return (new - strtab); ++} ++ ++int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size) ++{ ++ struct fdt_reserve_entry *re; ++ int err; ++ ++ FDT_RW_PROBE(fdt); ++ ++ re = fdt_mem_rsv_w_(fdt, fdt_num_mem_rsv(fdt)); ++ err = fdt_splice_mem_rsv_(fdt, re, 0, 1); ++ if (err) ++ return err; ++ ++ re->address = cpu_to_fdt64(address); ++ re->size = cpu_to_fdt64(size); ++ return 0; ++} ++ ++int fdt_del_mem_rsv(void *fdt, int n) ++{ ++ struct fdt_reserve_entry *re = fdt_mem_rsv_w_(fdt, n); ++ ++ FDT_RW_PROBE(fdt); ++ ++ if (n >= fdt_num_mem_rsv(fdt)) ++ return -FDT_ERR_NOTFOUND; ++ ++ return fdt_splice_mem_rsv_(fdt, re, 1, 0); ++} ++ ++static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name, ++ int len, struct fdt_property **prop) ++{ ++ int oldlen; ++ int err; ++ ++ *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); ++ if (!*prop) ++ return oldlen; ++ ++ if ((err = fdt_splice_struct_(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), ++ FDT_TAGALIGN(len)))) ++ return err; ++ ++ (*prop)->len = cpu_to_fdt32(len); ++ return 0; ++} ++ ++static int fdt_add_property_(void *fdt, int nodeoffset, const char *name, ++ int len, struct fdt_property **prop) ++{ ++ int proplen; ++ int nextoffset; ++ int namestroff; ++ int err; ++ int allocated; ++ ++ if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) ++ return nextoffset; ++ ++ namestroff = fdt_find_add_string_(fdt, name, &allocated); ++ if (namestroff < 0) ++ return namestroff; ++ ++ *prop = fdt_offset_ptr_w_(fdt, nextoffset); ++ proplen = sizeof(**prop) + FDT_TAGALIGN(len); ++ ++ err = fdt_splice_struct_(fdt, *prop, 0, proplen); ++ if (err) { ++ /* Delete the string if we failed to add it */ ++ if (!can_assume(NO_ROLLBACK) && allocated) ++ fdt_del_last_string_(fdt, name); ++ return err; ++ } ++ ++ (*prop)->tag = cpu_to_fdt32(FDT_PROP); ++ (*prop)->nameoff = cpu_to_fdt32(namestroff); ++ (*prop)->len = cpu_to_fdt32(len); ++ return 0; ++} ++ ++int fdt_set_name(void *fdt, int nodeoffset, const char *name) ++{ ++ char *namep; ++ int oldlen, newlen; ++ int err; ++ ++ FDT_RW_PROBE(fdt); ++ ++ namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen); ++ if (!namep) ++ return oldlen; ++ ++ newlen = strlen(name); ++ ++ err = fdt_splice_struct_(fdt, namep, FDT_TAGALIGN(oldlen+1), ++ FDT_TAGALIGN(newlen+1)); ++ if (err) ++ return err; ++ ++ memcpy(namep, name, newlen+1); ++ return 0; ++} ++ ++int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, ++ int len, void **prop_data) ++{ ++ struct fdt_property *prop; ++ int err; ++ ++ FDT_RW_PROBE(fdt); ++ ++ err = fdt_resize_property_(fdt, nodeoffset, name, len, &prop); ++ if (err == -FDT_ERR_NOTFOUND) ++ err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); ++ if (err) ++ return err; ++ ++ *prop_data = prop->data; ++ return 0; ++} ++ ++int fdt_setprop(void *fdt, int nodeoffset, const char *name, ++ const void *val, int len) ++{ ++ void *prop_data; ++ int err; ++ ++ err = fdt_setprop_placeholder(fdt, nodeoffset, name, len, &prop_data); ++ if (err) ++ return err; ++ ++ if (len) ++ memcpy(prop_data, val, len); ++ return 0; ++} ++ ++int fdt_appendprop(void *fdt, int nodeoffset, const char *name, ++ const void *val, int len) ++{ ++ struct fdt_property *prop; ++ int err, oldlen, newlen; ++ ++ FDT_RW_PROBE(fdt); ++ ++ prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); ++ if (prop) { ++ newlen = len + oldlen; ++ err = fdt_splice_struct_(fdt, prop->data, ++ FDT_TAGALIGN(oldlen), ++ FDT_TAGALIGN(newlen)); ++ if (err) ++ return err; ++ prop->len = cpu_to_fdt32(newlen); ++ memcpy(prop->data + oldlen, val, len); ++ } else { ++ err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); ++ if (err) ++ return err; ++ memcpy(prop->data, val, len); ++ } ++ return 0; ++} ++ ++int fdt_delprop(void *fdt, int nodeoffset, const char *name) ++{ ++ struct fdt_property *prop; ++ int len, proplen; ++ ++ FDT_RW_PROBE(fdt); ++ ++ prop = fdt_get_property_w(fdt, nodeoffset, name, &len); ++ if (!prop) ++ return len; ++ ++ proplen = sizeof(*prop) + FDT_TAGALIGN(len); ++ return fdt_splice_struct_(fdt, prop, proplen, 0); ++} ++ ++int fdt_add_subnode_namelen(void *fdt, int parentoffset, ++ const char *name, int namelen) ++{ ++ struct fdt_node_header *nh; ++ int offset, nextoffset; ++ int nodelen; ++ int err; ++ uint32_t tag; ++ fdt32_t *endtag; ++ ++ FDT_RW_PROBE(fdt); ++ ++ offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen); ++ if (offset >= 0) ++ return -FDT_ERR_EXISTS; ++ else if (offset != -FDT_ERR_NOTFOUND) ++ return offset; ++ ++ /* Try to place the new node after the parent's properties */ ++ tag = fdt_next_tag(fdt, parentoffset, &nextoffset); ++ /* the fdt_subnode_offset_namelen() should ensure this never hits */ ++ if (!can_assume(LIBFDT_FLAWLESS) && (tag != FDT_BEGIN_NODE)) ++ return -FDT_ERR_INTERNAL; ++ do { ++ offset = nextoffset; ++ tag = fdt_next_tag(fdt, offset, &nextoffset); ++ } while ((tag == FDT_PROP) || (tag == FDT_NOP)); ++ ++ nh = fdt_offset_ptr_w_(fdt, offset); ++ nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE; ++ ++ err = fdt_splice_struct_(fdt, nh, 0, nodelen); ++ if (err) ++ return err; ++ ++ nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); ++ memset(nh->name, 0, FDT_TAGALIGN(namelen+1)); ++ memcpy(nh->name, name, namelen); ++ endtag = (fdt32_t *)((char *)nh + nodelen - FDT_TAGSIZE); ++ *endtag = cpu_to_fdt32(FDT_END_NODE); ++ ++ return offset; ++} ++ ++int fdt_add_subnode(void *fdt, int parentoffset, const char *name) ++{ ++ return fdt_add_subnode_namelen(fdt, parentoffset, name, strlen(name)); ++} ++ ++int fdt_del_node(void *fdt, int nodeoffset) ++{ ++ int endoffset; ++ ++ FDT_RW_PROBE(fdt); ++ ++ endoffset = fdt_node_end_offset_(fdt, nodeoffset); ++ if (endoffset < 0) ++ return endoffset; ++ ++ return fdt_splice_struct_(fdt, fdt_offset_ptr_w_(fdt, nodeoffset), ++ endoffset - nodeoffset, 0); ++} ++ ++static void fdt_packblocks_(const char *old, char *new, ++ int mem_rsv_size, ++ int struct_size, ++ int strings_size) ++{ ++ int mem_rsv_off, struct_off, strings_off; ++ ++ mem_rsv_off = FDT_ALIGN(sizeof(struct fdt_header), 8); ++ struct_off = mem_rsv_off + mem_rsv_size; ++ strings_off = struct_off + struct_size; ++ ++ memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size); ++ fdt_set_off_mem_rsvmap(new, mem_rsv_off); ++ ++ memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size); ++ fdt_set_off_dt_struct(new, struct_off); ++ fdt_set_size_dt_struct(new, struct_size); ++ ++ memmove(new + strings_off, old + fdt_off_dt_strings(old), strings_size); ++ fdt_set_off_dt_strings(new, strings_off); ++ fdt_set_size_dt_strings(new, fdt_size_dt_strings(old)); ++} ++ ++int fdt_open_into(const void *fdt, void *buf, int bufsize) ++{ ++ int err; ++ int mem_rsv_size, struct_size; ++ int newsize; ++ const char *fdtstart = fdt; ++ const char *fdtend = fdtstart + fdt_totalsize(fdt); ++ char *tmp; ++ ++ FDT_RO_PROBE(fdt); ++ ++ mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) ++ * sizeof(struct fdt_reserve_entry); ++ ++ if (can_assume(LATEST) || fdt_version(fdt) >= 17) { ++ struct_size = fdt_size_dt_struct(fdt); ++ } else if (fdt_version(fdt) == 16) { ++ struct_size = 0; ++ while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END) ++ ; ++ if (struct_size < 0) ++ return struct_size; ++ } else { ++ return -FDT_ERR_BADVERSION; ++ } ++ ++ if (can_assume(LIBFDT_ORDER) || ++ !fdt_blocks_misordered_(fdt, mem_rsv_size, struct_size)) { ++ /* no further work necessary */ ++ err = fdt_move(fdt, buf, bufsize); ++ if (err) ++ return err; ++ fdt_set_version(buf, 17); ++ fdt_set_size_dt_struct(buf, struct_size); ++ fdt_set_totalsize(buf, bufsize); ++ return 0; ++ } ++ ++ /* Need to reorder */ ++ newsize = FDT_ALIGN(sizeof(struct fdt_header), 8) + mem_rsv_size ++ + struct_size + fdt_size_dt_strings(fdt); ++ ++ if (bufsize < newsize) ++ return -FDT_ERR_NOSPACE; ++ ++ /* First attempt to build converted tree at beginning of buffer */ ++ tmp = buf; ++ /* But if that overlaps with the old tree... */ ++ if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) { ++ /* Try right after the old tree instead */ ++ tmp = (char *)(uintptr_t)fdtend; ++ if ((tmp + newsize) > ((char *)buf + bufsize)) ++ return -FDT_ERR_NOSPACE; ++ } ++ ++ fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size, ++ fdt_size_dt_strings(fdt)); ++ memmove(buf, tmp, newsize); ++ ++ fdt_set_magic(buf, FDT_MAGIC); ++ fdt_set_totalsize(buf, bufsize); ++ fdt_set_version(buf, 17); ++ fdt_set_last_comp_version(buf, 16); ++ fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt)); ++ ++ return 0; ++} ++ ++int fdt_pack(void *fdt) ++{ ++ int mem_rsv_size; ++ ++ FDT_RW_PROBE(fdt); ++ ++ mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) ++ * sizeof(struct fdt_reserve_entry); ++ fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt), ++ fdt_size_dt_strings(fdt)); ++ fdt_set_totalsize(fdt, fdt_data_size_(fdt)); ++ ++ return 0; ++} +diff --git a/common/libfdt/fdt_strerror.c b/common/libfdt/fdt_strerror.c +new file mode 100644 +index 0000000..b435693 +--- /dev/null ++++ b/common/libfdt/fdt_strerror.c +@@ -0,0 +1,59 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++struct fdt_errtabent { ++ const char *str; ++}; ++ ++#define FDT_ERRTABENT(val) \ ++ [(val)] = { .str = #val, } ++ ++static struct fdt_errtabent fdt_errtable[] = { ++ FDT_ERRTABENT(FDT_ERR_NOTFOUND), ++ FDT_ERRTABENT(FDT_ERR_EXISTS), ++ FDT_ERRTABENT(FDT_ERR_NOSPACE), ++ ++ FDT_ERRTABENT(FDT_ERR_BADOFFSET), ++ FDT_ERRTABENT(FDT_ERR_BADPATH), ++ FDT_ERRTABENT(FDT_ERR_BADPHANDLE), ++ FDT_ERRTABENT(FDT_ERR_BADSTATE), ++ ++ FDT_ERRTABENT(FDT_ERR_TRUNCATED), ++ FDT_ERRTABENT(FDT_ERR_BADMAGIC), ++ FDT_ERRTABENT(FDT_ERR_BADVERSION), ++ FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), ++ FDT_ERRTABENT(FDT_ERR_BADLAYOUT), ++ FDT_ERRTABENT(FDT_ERR_INTERNAL), ++ FDT_ERRTABENT(FDT_ERR_BADNCELLS), ++ FDT_ERRTABENT(FDT_ERR_BADVALUE), ++ FDT_ERRTABENT(FDT_ERR_BADOVERLAY), ++ FDT_ERRTABENT(FDT_ERR_NOPHANDLES), ++ FDT_ERRTABENT(FDT_ERR_BADFLAGS), ++}; ++#define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))) ++ ++const char *fdt_strerror(int errval) ++{ ++ if (errval > 0) ++ return ""; ++ else if (errval == 0) ++ return ""; ++ else if (-errval < FDT_ERRTABSIZE) { ++ const char *s = fdt_errtable[-errval].str; ++ ++ if (s) ++ return s; ++ } ++ ++ return ""; ++} +diff --git a/common/libfdt/fdt_sw.c b/common/libfdt/fdt_sw.c +new file mode 100644 +index 0000000..4c569ee +--- /dev/null ++++ b/common/libfdt/fdt_sw.c +@@ -0,0 +1,384 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++static int fdt_sw_probe_(void *fdt) ++{ ++ if (!can_assume(VALID_INPUT)) { ++ if (fdt_magic(fdt) == FDT_MAGIC) ++ return -FDT_ERR_BADSTATE; ++ else if (fdt_magic(fdt) != FDT_SW_MAGIC) ++ return -FDT_ERR_BADMAGIC; ++ } ++ ++ return 0; ++} ++ ++#define FDT_SW_PROBE(fdt) \ ++ { \ ++ int err; \ ++ if ((err = fdt_sw_probe_(fdt)) != 0) \ ++ return err; \ ++ } ++ ++/* 'memrsv' state: Initial state after fdt_create() ++ * ++ * Allowed functions: ++ * fdt_add_reservemap_entry() ++ * fdt_finish_reservemap() [moves to 'struct' state] ++ */ ++static int fdt_sw_probe_memrsv_(void *fdt) ++{ ++ int err = fdt_sw_probe_(fdt); ++ if (err) ++ return err; ++ ++ if (!can_assume(VALID_INPUT) && fdt_off_dt_strings(fdt) != 0) ++ return -FDT_ERR_BADSTATE; ++ return 0; ++} ++ ++#define FDT_SW_PROBE_MEMRSV(fdt) \ ++ { \ ++ int err; \ ++ if ((err = fdt_sw_probe_memrsv_(fdt)) != 0) \ ++ return err; \ ++ } ++ ++/* 'struct' state: Enter this state after fdt_finish_reservemap() ++ * ++ * Allowed functions: ++ * fdt_begin_node() ++ * fdt_end_node() ++ * fdt_property*() ++ * fdt_finish() [moves to 'complete' state] ++ */ ++static int fdt_sw_probe_struct_(void *fdt) ++{ ++ int err = fdt_sw_probe_(fdt); ++ if (err) ++ return err; ++ ++ if (!can_assume(VALID_INPUT) && ++ fdt_off_dt_strings(fdt) != fdt_totalsize(fdt)) ++ return -FDT_ERR_BADSTATE; ++ return 0; ++} ++ ++#define FDT_SW_PROBE_STRUCT(fdt) \ ++ { \ ++ int err; \ ++ if ((err = fdt_sw_probe_struct_(fdt)) != 0) \ ++ return err; \ ++ } ++ ++static inline uint32_t sw_flags(void *fdt) ++{ ++ /* assert: (fdt_magic(fdt) == FDT_SW_MAGIC) */ ++ return fdt_last_comp_version(fdt); ++} ++ ++/* 'complete' state: Enter this state after fdt_finish() ++ * ++ * Allowed functions: none ++ */ ++ ++static void *fdt_grab_space_(void *fdt, size_t len) ++{ ++ unsigned int offset = fdt_size_dt_struct(fdt); ++ unsigned int spaceleft; ++ ++ spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt) ++ - fdt_size_dt_strings(fdt); ++ ++ if ((offset + len < offset) || (offset + len > spaceleft)) ++ return NULL; ++ ++ fdt_set_size_dt_struct(fdt, offset + len); ++ return fdt_offset_ptr_w_(fdt, offset); ++} ++ ++int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags) ++{ ++ const int hdrsize = FDT_ALIGN(sizeof(struct fdt_header), ++ sizeof(struct fdt_reserve_entry)); ++ void *fdt = buf; ++ ++ if (bufsize < hdrsize) ++ return -FDT_ERR_NOSPACE; ++ ++ if (flags & ~FDT_CREATE_FLAGS_ALL) ++ return -FDT_ERR_BADFLAGS; ++ ++ memset(buf, 0, bufsize); ++ ++ /* ++ * magic and last_comp_version keep intermediate state during the fdt ++ * creation process, which is replaced with the proper FDT format by ++ * fdt_finish(). ++ * ++ * flags should be accessed with sw_flags(). ++ */ ++ fdt_set_magic(fdt, FDT_SW_MAGIC); ++ fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION); ++ fdt_set_last_comp_version(fdt, flags); ++ ++ fdt_set_totalsize(fdt, bufsize); ++ ++ fdt_set_off_mem_rsvmap(fdt, hdrsize); ++ fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt)); ++ fdt_set_off_dt_strings(fdt, 0); ++ ++ return 0; ++} ++ ++int fdt_create(void *buf, int bufsize) ++{ ++ return fdt_create_with_flags(buf, bufsize, 0); ++} ++ ++int fdt_resize(void *fdt, void *buf, int bufsize) ++{ ++ size_t headsize, tailsize; ++ char *oldtail, *newtail; ++ ++ FDT_SW_PROBE(fdt); ++ ++ if (bufsize < 0) ++ return -FDT_ERR_NOSPACE; ++ ++ headsize = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); ++ tailsize = fdt_size_dt_strings(fdt); ++ ++ if (!can_assume(VALID_DTB) && ++ headsize + tailsize > fdt_totalsize(fdt)) ++ return -FDT_ERR_INTERNAL; ++ ++ if ((headsize + tailsize) > (unsigned)bufsize) ++ return -FDT_ERR_NOSPACE; ++ ++ oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize; ++ newtail = (char *)buf + bufsize - tailsize; ++ ++ /* Two cases to avoid clobbering data if the old and new ++ * buffers partially overlap */ ++ if (buf <= fdt) { ++ memmove(buf, fdt, headsize); ++ memmove(newtail, oldtail, tailsize); ++ } else { ++ memmove(newtail, oldtail, tailsize); ++ memmove(buf, fdt, headsize); ++ } ++ ++ fdt_set_totalsize(buf, bufsize); ++ if (fdt_off_dt_strings(buf)) ++ fdt_set_off_dt_strings(buf, bufsize); ++ ++ return 0; ++} ++ ++int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) ++{ ++ struct fdt_reserve_entry *re; ++ int offset; ++ ++ FDT_SW_PROBE_MEMRSV(fdt); ++ ++ offset = fdt_off_dt_struct(fdt); ++ if ((offset + sizeof(*re)) > fdt_totalsize(fdt)) ++ return -FDT_ERR_NOSPACE; ++ ++ re = (struct fdt_reserve_entry *)((char *)fdt + offset); ++ re->address = cpu_to_fdt64(addr); ++ re->size = cpu_to_fdt64(size); ++ ++ fdt_set_off_dt_struct(fdt, offset + sizeof(*re)); ++ ++ return 0; ++} ++ ++int fdt_finish_reservemap(void *fdt) ++{ ++ int err = fdt_add_reservemap_entry(fdt, 0, 0); ++ ++ if (err) ++ return err; ++ ++ fdt_set_off_dt_strings(fdt, fdt_totalsize(fdt)); ++ return 0; ++} ++ ++int fdt_begin_node(void *fdt, const char *name) ++{ ++ struct fdt_node_header *nh; ++ int namelen; ++ ++ FDT_SW_PROBE_STRUCT(fdt); ++ ++ namelen = strlen(name) + 1; ++ nh = fdt_grab_space_(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen)); ++ if (! nh) ++ return -FDT_ERR_NOSPACE; ++ ++ nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); ++ memcpy(nh->name, name, namelen); ++ return 0; ++} ++ ++int fdt_end_node(void *fdt) ++{ ++ fdt32_t *en; ++ ++ FDT_SW_PROBE_STRUCT(fdt); ++ ++ en = fdt_grab_space_(fdt, FDT_TAGSIZE); ++ if (! en) ++ return -FDT_ERR_NOSPACE; ++ ++ *en = cpu_to_fdt32(FDT_END_NODE); ++ return 0; ++} ++ ++static int fdt_add_string_(void *fdt, const char *s) ++{ ++ char *strtab = (char *)fdt + fdt_totalsize(fdt); ++ unsigned int strtabsize = fdt_size_dt_strings(fdt); ++ unsigned int len = strlen(s) + 1; ++ unsigned int struct_top, offset; ++ ++ offset = strtabsize + len; ++ struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); ++ if (fdt_totalsize(fdt) - offset < struct_top) ++ return 0; /* no more room :( */ ++ ++ memcpy(strtab - offset, s, len); ++ fdt_set_size_dt_strings(fdt, strtabsize + len); ++ return -offset; ++} ++ ++/* Must only be used to roll back in case of error */ ++static void fdt_del_last_string_(void *fdt, const char *s) ++{ ++ int strtabsize = fdt_size_dt_strings(fdt); ++ int len = strlen(s) + 1; ++ ++ fdt_set_size_dt_strings(fdt, strtabsize - len); ++} ++ ++static int fdt_find_add_string_(void *fdt, const char *s, int *allocated) ++{ ++ char *strtab = (char *)fdt + fdt_totalsize(fdt); ++ int strtabsize = fdt_size_dt_strings(fdt); ++ const char *p; ++ ++ *allocated = 0; ++ ++ p = fdt_find_string_(strtab - strtabsize, strtabsize, s); ++ if (p) ++ return p - strtab; ++ ++ *allocated = 1; ++ ++ return fdt_add_string_(fdt, s); ++} ++ ++int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp) ++{ ++ struct fdt_property *prop; ++ int nameoff; ++ int allocated; ++ ++ FDT_SW_PROBE_STRUCT(fdt); ++ ++ /* String de-duplication can be slow, _NO_NAME_DEDUP skips it */ ++ if (sw_flags(fdt) & FDT_CREATE_FLAG_NO_NAME_DEDUP) { ++ allocated = 1; ++ nameoff = fdt_add_string_(fdt, name); ++ } else { ++ nameoff = fdt_find_add_string_(fdt, name, &allocated); ++ } ++ if (nameoff == 0) ++ return -FDT_ERR_NOSPACE; ++ ++ prop = fdt_grab_space_(fdt, sizeof(*prop) + FDT_TAGALIGN(len)); ++ if (! prop) { ++ if (allocated) ++ fdt_del_last_string_(fdt, name); ++ return -FDT_ERR_NOSPACE; ++ } ++ ++ prop->tag = cpu_to_fdt32(FDT_PROP); ++ prop->nameoff = cpu_to_fdt32(nameoff); ++ prop->len = cpu_to_fdt32(len); ++ *valp = prop->data; ++ return 0; ++} ++ ++int fdt_property(void *fdt, const char *name, const void *val, int len) ++{ ++ void *ptr; ++ int ret; ++ ++ ret = fdt_property_placeholder(fdt, name, len, &ptr); ++ if (ret) ++ return ret; ++ memcpy(ptr, val, len); ++ return 0; ++} ++ ++int fdt_finish(void *fdt) ++{ ++ char *p = (char *)fdt; ++ fdt32_t *end; ++ int oldstroffset, newstroffset; ++ uint32_t tag; ++ int offset, nextoffset; ++ ++ FDT_SW_PROBE_STRUCT(fdt); ++ ++ /* Add terminator */ ++ end = fdt_grab_space_(fdt, sizeof(*end)); ++ if (! end) ++ return -FDT_ERR_NOSPACE; ++ *end = cpu_to_fdt32(FDT_END); ++ ++ /* Relocate the string table */ ++ oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt); ++ newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); ++ memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt)); ++ fdt_set_off_dt_strings(fdt, newstroffset); ++ ++ /* Walk the structure, correcting string offsets */ ++ offset = 0; ++ while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) { ++ if (tag == FDT_PROP) { ++ struct fdt_property *prop = ++ fdt_offset_ptr_w_(fdt, offset); ++ int nameoff; ++ ++ nameoff = fdt32_to_cpu(prop->nameoff); ++ nameoff += fdt_size_dt_strings(fdt); ++ prop->nameoff = cpu_to_fdt32(nameoff); ++ } ++ offset = nextoffset; ++ } ++ if (nextoffset < 0) ++ return nextoffset; ++ ++ /* Finally, adjust the header */ ++ fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt)); ++ ++ /* And fix up fields that were keeping intermediate state. */ ++ fdt_set_last_comp_version(fdt, FDT_LAST_COMPATIBLE_VERSION); ++ fdt_set_magic(fdt, FDT_MAGIC); ++ ++ return 0; ++} +diff --git a/common/libfdt/fdt_wip.c b/common/libfdt/fdt_wip.c +new file mode 100644 +index 0000000..c2d7566 +--- /dev/null ++++ b/common/libfdt/fdt_wip.c +@@ -0,0 +1,94 @@ ++// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ */ ++#include "libfdt_env.h" ++ ++#include ++#include ++ ++#include "libfdt_internal.h" ++ ++int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, ++ const char *name, int namelen, ++ uint32_t idx, const void *val, ++ int len) ++{ ++ void *propval; ++ int proplen; ++ ++ propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen, ++ &proplen); ++ if (!propval) ++ return proplen; ++ ++ if ((unsigned)proplen < (len + idx)) ++ return -FDT_ERR_NOSPACE; ++ ++ memcpy((char *)propval + idx, val, len); ++ return 0; ++} ++ ++int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, ++ const void *val, int len) ++{ ++ const void *propval; ++ int proplen; ++ ++ propval = fdt_getprop(fdt, nodeoffset, name, &proplen); ++ if (!propval) ++ return proplen; ++ ++ if (proplen != len) ++ return -FDT_ERR_NOSPACE; ++ ++ return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name, ++ strlen(name), 0, ++ val, len); ++} ++ ++static void fdt_nop_region_(void *start, int len) ++{ ++ fdt32_t *p; ++ ++ for (p = start; (char *)p < ((char *)start + len); p++) ++ *p = cpu_to_fdt32(FDT_NOP); ++} ++ ++int fdt_nop_property(void *fdt, int nodeoffset, const char *name) ++{ ++ struct fdt_property *prop; ++ int len; ++ ++ prop = fdt_get_property_w(fdt, nodeoffset, name, &len); ++ if (!prop) ++ return len; ++ ++ fdt_nop_region_(prop, len + sizeof(*prop)); ++ ++ return 0; ++} ++ ++int fdt_node_end_offset_(void *fdt, int offset) ++{ ++ int depth = 0; ++ ++ while ((offset >= 0) && (depth >= 0)) ++ offset = fdt_next_node(fdt, offset, &depth); ++ ++ return offset; ++} ++ ++int fdt_nop_node(void *fdt, int nodeoffset) ++{ ++ int endoffset; ++ ++ endoffset = fdt_node_end_offset_(fdt, nodeoffset); ++ if (endoffset < 0) ++ return endoffset; ++ ++ fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0), ++ endoffset - nodeoffset); ++ return 0; ++} +diff --git a/common/libfdt/libfdt_internal.h b/common/libfdt/libfdt_internal.h +new file mode 100644 +index 0000000..16bda19 +--- /dev/null ++++ b/common/libfdt/libfdt_internal.h +@@ -0,0 +1,192 @@ ++/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ ++#ifndef LIBFDT_INTERNAL_H ++#define LIBFDT_INTERNAL_H ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ */ ++#include ++ ++#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) ++#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) ++ ++int32_t fdt_ro_probe_(const void *fdt); ++#define FDT_RO_PROBE(fdt) \ ++ { \ ++ int32_t totalsize_; \ ++ if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ ++ return totalsize_; \ ++ } ++ ++int fdt_check_node_offset_(const void *fdt, int offset); ++int fdt_check_prop_offset_(const void *fdt, int offset); ++const char *fdt_find_string_(const char *strtab, int tabsize, const char *s); ++int fdt_node_end_offset_(void *fdt, int nodeoffset); ++ ++static inline const void *fdt_offset_ptr_(const void *fdt, int offset) ++{ ++ return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; ++} ++ ++static inline void *fdt_offset_ptr_w_(void *fdt, int offset) ++{ ++ return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset); ++} ++ ++static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n) ++{ ++ const struct fdt_reserve_entry *rsv_table = ++ (const struct fdt_reserve_entry *) ++ ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); ++ ++ return rsv_table + n; ++} ++static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n) ++{ ++ return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n); ++} ++ ++/* ++ * Internal helpers to access tructural elements of the device tree ++ * blob (rather than for exaple reading integers from within property ++ * values). We assume that we are either given a naturally aligned ++ * address for the platform or if we are not, we are on a platform ++ * where unaligned memory reads will be handled in a graceful manner. ++ * If not the external helpers fdtXX_ld() from libfdt.h can be used ++ * instead. ++ */ ++static inline uint32_t fdt32_ld_(const fdt32_t *p) ++{ ++ return fdt32_to_cpu(*p); ++} ++ ++static inline uint64_t fdt64_ld_(const fdt64_t *p) ++{ ++ return fdt64_to_cpu(*p); ++} ++ ++#define FDT_SW_MAGIC (~FDT_MAGIC) ++ ++/**********************************************************************/ ++/* Checking controls */ ++/**********************************************************************/ ++ ++#ifndef FDT_ASSUME_MASK ++#define FDT_ASSUME_MASK 0 ++#endif ++ ++/* ++ * Defines assumptions which can be enabled. Each of these can be enabled ++ * individually. For maximum safety, don't enable any assumptions! ++ * ++ * For minimal code size and no safety, use ASSUME_PERFECT at your own risk. ++ * You should have another method of validating the device tree, such as a ++ * signature or hash check before using libfdt. ++ * ++ * For situations where security is not a concern it may be safe to enable ++ * ASSUME_SANE. ++ */ ++enum { ++ /* ++ * This does essentially no checks. Only the latest device-tree ++ * version is correctly handled. Inconsistencies or errors in the device ++ * tree may cause undefined behaviour or crashes. Invalid parameters ++ * passed to libfdt may do the same. ++ * ++ * If an error occurs when modifying the tree it may leave the tree in ++ * an intermediate (but valid) state. As an example, adding a property ++ * where there is insufficient space may result in the property name ++ * being added to the string table even though the property itself is ++ * not added to the struct section. ++ * ++ * Only use this if you have a fully validated device tree with ++ * the latest supported version and wish to minimise code size. ++ */ ++ ASSUME_PERFECT = 0xff, ++ ++ /* ++ * This assumes that the device tree is sane. i.e. header metadata ++ * and basic hierarchy are correct. ++ * ++ * With this assumption enabled, normal device trees produced by libfdt ++ * and the compiler should be handled safely. Malicious device trees and ++ * complete garbage may cause libfdt to behave badly or crash. Truncated ++ * device trees (e.g. those only partially loaded) can also cause ++ * problems. ++ * ++ * Note: Only checks that relate exclusively to the device tree itself ++ * (not the parameters passed to libfdt) are disabled by this ++ * assumption. This includes checking headers, tags and the like. ++ */ ++ ASSUME_VALID_DTB = 1 << 0, ++ ++ /* ++ * This builds on ASSUME_VALID_DTB and further assumes that libfdt ++ * functions are called with valid parameters, i.e. not trigger ++ * FDT_ERR_BADOFFSET or offsets that are out of bounds. It disables any ++ * extensive checking of parameters and the device tree, making various ++ * assumptions about correctness. ++ * ++ * It doesn't make sense to enable this assumption unless ++ * ASSUME_VALID_DTB is also enabled. ++ */ ++ ASSUME_VALID_INPUT = 1 << 1, ++ ++ /* ++ * This disables checks for device-tree version and removes all code ++ * which handles older versions. ++ * ++ * Only enable this if you know you have a device tree with the latest ++ * version. ++ */ ++ ASSUME_LATEST = 1 << 2, ++ ++ /* ++ * This assumes that it is OK for a failed addition to the device tree, ++ * due to lack of space or some other problem, to skip any rollback ++ * steps (such as dropping the property name from the string table). ++ * This is safe to enable in most circumstances, even though it may ++ * leave the tree in a sub-optimal state. ++ */ ++ ASSUME_NO_ROLLBACK = 1 << 3, ++ ++ /* ++ * This assumes that the device tree components appear in a 'convenient' ++ * order, i.e. the memory reservation block first, then the structure ++ * block and finally the string block. ++ * ++ * This order is not specified by the device-tree specification, ++ * but is expected by libfdt. The device-tree compiler always created ++ * device trees with this order. ++ * ++ * This assumption disables a check in fdt_open_into() and removes the ++ * ability to fix the problem there. This is safe if you know that the ++ * device tree is correctly ordered. See fdt_blocks_misordered_(). ++ */ ++ ASSUME_LIBFDT_ORDER = 1 << 4, ++ ++ /* ++ * This assumes that libfdt itself does not have any internal bugs. It ++ * drops certain checks that should never be needed unless libfdt has an ++ * undiscovered bug. ++ * ++ * This can generally be considered safe to enable. ++ */ ++ ASSUME_LIBFDT_FLAWLESS = 1 << 5, ++}; ++ ++/** ++ * can_assume_() - check if a particular assumption is enabled ++ * ++ * @mask: Mask to check (ASSUME_...) ++ * @return true if that assumption is enabled, else false ++ */ ++static inline bool can_assume_(int mask) ++{ ++ return FDT_ASSUME_MASK & mask; ++} ++ ++/** helper macros for checking assumptions */ ++#define can_assume(_assume) can_assume_(ASSUME_ ## _assume) ++ ++#endif /* LIBFDT_INTERNAL_H */ +diff --git a/include/fdt.h b/include/fdt.h +new file mode 100644 +index 0000000..f2e6880 +--- /dev/null ++++ b/include/fdt.h +@@ -0,0 +1,66 @@ ++/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ ++#ifndef FDT_H ++#define FDT_H ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ * Copyright 2012 Kim Phillips, Freescale Semiconductor. ++ */ ++ ++#ifndef __ASSEMBLY__ ++ ++struct fdt_header { ++ fdt32_t magic; /* magic word FDT_MAGIC */ ++ fdt32_t totalsize; /* total size of DT block */ ++ fdt32_t off_dt_struct; /* offset to structure */ ++ fdt32_t off_dt_strings; /* offset to strings */ ++ fdt32_t off_mem_rsvmap; /* offset to memory reserve map */ ++ fdt32_t version; /* format version */ ++ fdt32_t last_comp_version; /* last compatible version */ ++ ++ /* version 2 fields below */ ++ fdt32_t boot_cpuid_phys; /* Which physical CPU id we're ++ booting on */ ++ /* version 3 fields below */ ++ fdt32_t size_dt_strings; /* size of the strings block */ ++ ++ /* version 17 fields below */ ++ fdt32_t size_dt_struct; /* size of the structure block */ ++}; ++ ++struct fdt_reserve_entry { ++ fdt64_t address; ++ fdt64_t size; ++}; ++ ++struct fdt_node_header { ++ fdt32_t tag; ++ char name[0]; ++}; ++ ++struct fdt_property { ++ fdt32_t tag; ++ fdt32_t len; ++ fdt32_t nameoff; ++ char data[0]; ++}; ++ ++#endif /* !__ASSEMBLY */ ++ ++#define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ ++#define FDT_TAGSIZE sizeof(fdt32_t) ++ ++#define FDT_BEGIN_NODE 0x1 /* Start node: full name */ ++#define FDT_END_NODE 0x2 /* End node */ ++#define FDT_PROP 0x3 /* Property: name off, ++ size, content */ ++#define FDT_NOP 0x4 /* nop */ ++#define FDT_END 0x9 ++ ++#define FDT_V1_SIZE (7*sizeof(fdt32_t)) ++#define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t)) ++#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t)) ++#define FDT_V16_SIZE FDT_V3_SIZE ++#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) ++ ++#endif /* FDT_H */ +diff --git a/include/libfdt.h b/include/libfdt.h +new file mode 100644 +index 0000000..a7f432c +--- /dev/null ++++ b/include/libfdt.h +@@ -0,0 +1,2147 @@ ++/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ ++#ifndef LIBFDT_H ++#define LIBFDT_H ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ */ ++ ++#include ++#include ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++#define FDT_FIRST_SUPPORTED_VERSION 0x02 ++#define FDT_LAST_COMPATIBLE_VERSION 0x10 ++#define FDT_LAST_SUPPORTED_VERSION 0x11 ++ ++/* Error codes: informative error codes */ ++#define FDT_ERR_NOTFOUND 1 ++ /* FDT_ERR_NOTFOUND: The requested node or property does not exist */ ++#define FDT_ERR_EXISTS 2 ++ /* FDT_ERR_EXISTS: Attempted to create a node or property which ++ * already exists */ ++#define FDT_ERR_NOSPACE 3 ++ /* FDT_ERR_NOSPACE: Operation needed to expand the device ++ * tree, but its buffer did not have sufficient space to ++ * contain the expanded tree. Use fdt_open_into() to move the ++ * device tree to a buffer with more space. */ ++ ++/* Error codes: codes for bad parameters */ ++#define FDT_ERR_BADOFFSET 4 ++ /* FDT_ERR_BADOFFSET: Function was passed a structure block ++ * offset which is out-of-bounds, or which points to an ++ * unsuitable part of the structure for the operation. */ ++#define FDT_ERR_BADPATH 5 ++ /* FDT_ERR_BADPATH: Function was passed a badly formatted path ++ * (e.g. missing a leading / for a function which requires an ++ * absolute path) */ ++#define FDT_ERR_BADPHANDLE 6 ++ /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle. ++ * This can be caused either by an invalid phandle property ++ * length, or the phandle value was either 0 or -1, which are ++ * not permitted. */ ++#define FDT_ERR_BADSTATE 7 ++ /* FDT_ERR_BADSTATE: Function was passed an incomplete device ++ * tree created by the sequential-write functions, which is ++ * not sufficiently complete for the requested operation. */ ++ ++/* Error codes: codes for bad device tree blobs */ ++#define FDT_ERR_TRUNCATED 8 ++ /* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly ++ * terminated (overflows, goes outside allowed bounds, or ++ * isn't properly terminated). */ ++#define FDT_ERR_BADMAGIC 9 ++ /* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a ++ * device tree at all - it is missing the flattened device ++ * tree magic number. */ ++#define FDT_ERR_BADVERSION 10 ++ /* FDT_ERR_BADVERSION: Given device tree has a version which ++ * can't be handled by the requested operation. For ++ * read-write functions, this may mean that fdt_open_into() is ++ * required to convert the tree to the expected version. */ ++#define FDT_ERR_BADSTRUCTURE 11 ++ /* FDT_ERR_BADSTRUCTURE: Given device tree has a corrupt ++ * structure block or other serious error (e.g. misnested ++ * nodes, or subnodes preceding properties). */ ++#define FDT_ERR_BADLAYOUT 12 ++ /* FDT_ERR_BADLAYOUT: For read-write functions, the given ++ * device tree has it's sub-blocks in an order that the ++ * function can't handle (memory reserve map, then structure, ++ * then strings). Use fdt_open_into() to reorganize the tree ++ * into a form suitable for the read-write operations. */ ++ ++/* "Can't happen" error indicating a bug in libfdt */ ++#define FDT_ERR_INTERNAL 13 ++ /* FDT_ERR_INTERNAL: libfdt has failed an internal assertion. ++ * Should never be returned, if it is, it indicates a bug in ++ * libfdt itself. */ ++ ++/* Errors in device tree content */ ++#define FDT_ERR_BADNCELLS 14 ++ /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells ++ * or similar property with a bad format or value */ ++ ++#define FDT_ERR_BADVALUE 15 ++ /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected ++ * value. For example: a property expected to contain a string list ++ * is not NUL-terminated within the length of its value. */ ++ ++#define FDT_ERR_BADOVERLAY 16 ++ /* FDT_ERR_BADOVERLAY: The device tree overlay, while ++ * correctly structured, cannot be applied due to some ++ * unexpected or missing value, property or node. */ ++ ++#define FDT_ERR_NOPHANDLES 17 ++ /* FDT_ERR_NOPHANDLES: The device tree doesn't have any ++ * phandle available anymore without causing an overflow */ ++ ++#define FDT_ERR_BADFLAGS 18 ++ /* FDT_ERR_BADFLAGS: The function was passed a flags field that ++ * contains invalid flags or an invalid combination of flags. */ ++ ++#define FDT_ERR_ALIGNMENT 19 ++ /* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte ++ * aligned. */ ++ ++#define FDT_ERR_MAX 19 ++ ++/* constants */ ++#define FDT_MAX_PHANDLE 0xfffffffe ++ /* Valid values for phandles range from 1 to 2^32-2. */ ++ ++/**********************************************************************/ ++/* Low-level functions (you probably don't need these) */ ++/**********************************************************************/ ++ ++#ifndef SWIG /* This function is not useful in Python */ ++const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); ++#endif ++static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) ++{ ++ return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); ++} ++ ++uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); ++ ++/* ++ * External helpers to access words from a device tree blob. They're built ++ * to work even with unaligned pointers on platforms (such as ARMv5) that don't ++ * like unaligned loads and stores. ++ */ ++static inline uint16_t fdt16_ld(const fdt16_t *p) ++{ ++ const uint8_t *bp = (const uint8_t *)p; ++ ++ return ((uint16_t)bp[0] << 8) | bp[1]; ++} ++ ++static inline uint32_t fdt32_ld(const fdt32_t *p) ++{ ++ const uint8_t *bp = (const uint8_t *)p; ++ ++ return ((uint32_t)bp[0] << 24) ++ | ((uint32_t)bp[1] << 16) ++ | ((uint32_t)bp[2] << 8) ++ | bp[3]; ++} ++ ++static inline void fdt32_st(void *property, uint32_t value) ++{ ++ uint8_t *bp = (uint8_t *)property; ++ ++ bp[0] = value >> 24; ++ bp[1] = (value >> 16) & 0xff; ++ bp[2] = (value >> 8) & 0xff; ++ bp[3] = value & 0xff; ++} ++ ++static inline uint64_t fdt64_ld(const fdt64_t *p) ++{ ++ const uint8_t *bp = (const uint8_t *)p; ++ ++ return ((uint64_t)bp[0] << 56) ++ | ((uint64_t)bp[1] << 48) ++ | ((uint64_t)bp[2] << 40) ++ | ((uint64_t)bp[3] << 32) ++ | ((uint64_t)bp[4] << 24) ++ | ((uint64_t)bp[5] << 16) ++ | ((uint64_t)bp[6] << 8) ++ | bp[7]; ++} ++ ++static inline void fdt64_st(void *property, uint64_t value) ++{ ++ uint8_t *bp = (uint8_t *)property; ++ ++ bp[0] = value >> 56; ++ bp[1] = (value >> 48) & 0xff; ++ bp[2] = (value >> 40) & 0xff; ++ bp[3] = (value >> 32) & 0xff; ++ bp[4] = (value >> 24) & 0xff; ++ bp[5] = (value >> 16) & 0xff; ++ bp[6] = (value >> 8) & 0xff; ++ bp[7] = value & 0xff; ++} ++ ++/**********************************************************************/ ++/* Traversal functions */ ++/**********************************************************************/ ++ ++int fdt_next_node(const void *fdt, int offset, int *depth); ++ ++/** ++ * fdt_first_subnode() - get offset of first direct subnode ++ * @fdt: FDT blob ++ * @offset: Offset of node to check ++ * ++ * Return: offset of first subnode, or -FDT_ERR_NOTFOUND if there is none ++ */ ++int fdt_first_subnode(const void *fdt, int offset); ++ ++/** ++ * fdt_next_subnode() - get offset of next direct subnode ++ * @fdt: FDT blob ++ * @offset: Offset of previous subnode ++ * ++ * After first calling fdt_first_subnode(), call this function repeatedly to ++ * get direct subnodes of a parent node. ++ * ++ * Return: offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more ++ * subnodes ++ */ ++int fdt_next_subnode(const void *fdt, int offset); ++ ++/** ++ * fdt_for_each_subnode - iterate over all subnodes of a parent ++ * ++ * @node: child node (int, lvalue) ++ * @fdt: FDT blob (const void *) ++ * @parent: parent node (int) ++ * ++ * This is actually a wrapper around a for loop and would be used like so: ++ * ++ * fdt_for_each_subnode(node, fdt, parent) { ++ * Use node ++ * ... ++ * } ++ * ++ * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) { ++ * Error handling ++ * } ++ * ++ * Note that this is implemented as a macro and @node is used as ++ * iterator in the loop. The parent variable be constant or even a ++ * literal. ++ */ ++#define fdt_for_each_subnode(node, fdt, parent) \ ++ for (node = fdt_first_subnode(fdt, parent); \ ++ node >= 0; \ ++ node = fdt_next_subnode(fdt, node)) ++ ++/**********************************************************************/ ++/* General functions */ ++/**********************************************************************/ ++#define fdt_get_header(fdt, field) \ ++ (fdt32_ld(&((const struct fdt_header *)(fdt))->field)) ++#define fdt_magic(fdt) (fdt_get_header(fdt, magic)) ++#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize)) ++#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct)) ++#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings)) ++#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap)) ++#define fdt_version(fdt) (fdt_get_header(fdt, version)) ++#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version)) ++#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys)) ++#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) ++#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) ++ ++#define fdt_set_hdr_(name) \ ++ static inline void fdt_set_##name(void *fdt, uint32_t val) \ ++ { \ ++ struct fdt_header *fdth = (struct fdt_header *)fdt; \ ++ fdth->name = cpu_to_fdt32(val); \ ++ } ++fdt_set_hdr_(magic); ++fdt_set_hdr_(totalsize); ++fdt_set_hdr_(off_dt_struct); ++fdt_set_hdr_(off_dt_strings); ++fdt_set_hdr_(off_mem_rsvmap); ++fdt_set_hdr_(version); ++fdt_set_hdr_(last_comp_version); ++fdt_set_hdr_(boot_cpuid_phys); ++fdt_set_hdr_(size_dt_strings); ++fdt_set_hdr_(size_dt_struct); ++#undef fdt_set_hdr_ ++ ++/** ++ * fdt_header_size - return the size of the tree's header ++ * @fdt: pointer to a flattened device tree ++ * ++ * Return: size of DTB header in bytes ++ */ ++size_t fdt_header_size(const void *fdt); ++ ++/** ++ * fdt_header_size_ - internal function to get header size from a version number ++ * @version: devicetree version number ++ * ++ * Return: size of DTB header in bytes ++ */ ++size_t fdt_header_size_(uint32_t version); ++ ++/** ++ * fdt_check_header - sanity check a device tree header ++ * @fdt: pointer to data which might be a flattened device tree ++ * ++ * fdt_check_header() checks that the given buffer contains what ++ * appears to be a flattened device tree, and that the header contains ++ * valid information (to the extent that can be determined from the ++ * header alone). ++ * ++ * returns: ++ * 0, if the buffer appears to contain a valid device tree ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_TRUNCATED, standard meanings, as above ++ */ ++int fdt_check_header(const void *fdt); ++ ++/** ++ * fdt_move - move a device tree around in memory ++ * @fdt: pointer to the device tree to move ++ * @buf: pointer to memory where the device is to be moved ++ * @bufsize: size of the memory space at buf ++ * ++ * fdt_move() relocates, if possible, the device tree blob located at ++ * fdt to the buffer at buf of size bufsize. The buffer may overlap ++ * with the existing device tree blob at fdt. Therefore, ++ * fdt_move(fdt, fdt, fdt_totalsize(fdt)) ++ * should always succeed. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, bufsize is insufficient to contain the device tree ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, standard meanings ++ */ ++int fdt_move(const void *fdt, void *buf, int bufsize); ++ ++/**********************************************************************/ ++/* Read-only functions */ ++/**********************************************************************/ ++ ++int fdt_check_full(const void *fdt, size_t bufsize); ++ ++/** ++ * fdt_get_string - retrieve a string from the strings block of a device tree ++ * @fdt: pointer to the device tree blob ++ * @stroffset: offset of the string within the strings block (native endian) ++ * @lenp: optional pointer to return the string's length ++ * ++ * fdt_get_string() retrieves a pointer to a single string from the ++ * strings block of the device tree blob at fdt, and optionally also ++ * returns the string's length in *lenp. ++ * ++ * returns: ++ * a pointer to the string, on success ++ * NULL, if stroffset is out of bounds, or doesn't point to a valid string ++ */ ++const char *fdt_get_string(const void *fdt, int stroffset, int *lenp); ++ ++/** ++ * fdt_string - retrieve a string from the strings block of a device tree ++ * @fdt: pointer to the device tree blob ++ * @stroffset: offset of the string within the strings block (native endian) ++ * ++ * fdt_string() retrieves a pointer to a single string from the ++ * strings block of the device tree blob at fdt. ++ * ++ * returns: ++ * a pointer to the string, on success ++ * NULL, if stroffset is out of bounds, or doesn't point to a valid string ++ */ ++const char *fdt_string(const void *fdt, int stroffset); ++ ++/** ++ * fdt_find_max_phandle - find and return the highest phandle in a tree ++ * @fdt: pointer to the device tree blob ++ * @phandle: return location for the highest phandle value found in the tree ++ * ++ * fdt_find_max_phandle() finds the highest phandle value in the given device ++ * tree. The value returned in @phandle is only valid if the function returns ++ * success. ++ * ++ * returns: ++ * 0 on success or a negative error code on failure ++ */ ++int fdt_find_max_phandle(const void *fdt, uint32_t *phandle); ++ ++/** ++ * fdt_get_max_phandle - retrieves the highest phandle in a tree ++ * @fdt: pointer to the device tree blob ++ * ++ * fdt_get_max_phandle retrieves the highest phandle in the given ++ * device tree. This will ignore badly formatted phandles, or phandles ++ * with a value of 0 or -1. ++ * ++ * This function is deprecated in favour of fdt_find_max_phandle(). ++ * ++ * returns: ++ * the highest phandle on success ++ * 0, if no phandle was found in the device tree ++ * -1, if an error occurred ++ */ ++static inline uint32_t fdt_get_max_phandle(const void *fdt) ++{ ++ uint32_t phandle; ++ int err; ++ ++ err = fdt_find_max_phandle(fdt, &phandle); ++ if (err < 0) ++ return (uint32_t)-1; ++ ++ return phandle; ++} ++ ++/** ++ * fdt_generate_phandle - return a new, unused phandle for a device tree blob ++ * @fdt: pointer to the device tree blob ++ * @phandle: return location for the new phandle ++ * ++ * Walks the device tree blob and looks for the highest phandle value. On ++ * success, the new, unused phandle value (one higher than the previously ++ * highest phandle value in the device tree blob) will be returned in the ++ * @phandle parameter. ++ * ++ * Return: 0 on success or a negative error-code on failure ++ */ ++int fdt_generate_phandle(const void *fdt, uint32_t *phandle); ++ ++/** ++ * fdt_num_mem_rsv - retrieve the number of memory reserve map entries ++ * @fdt: pointer to the device tree blob ++ * ++ * Returns the number of entries in the device tree blob's memory ++ * reservation map. This does not include the terminating 0,0 entry ++ * or any other (0,0) entries reserved for expansion. ++ * ++ * returns: ++ * the number of entries ++ */ ++int fdt_num_mem_rsv(const void *fdt); ++ ++/** ++ * fdt_get_mem_rsv - retrieve one memory reserve map entry ++ * @fdt: pointer to the device tree blob ++ * @n: index of reserve map entry ++ * @address: pointer to 64-bit variable to hold the start address ++ * @size: pointer to 64-bit variable to hold the size of the entry ++ * ++ * On success, @address and @size will contain the address and size of ++ * the n-th reserve map entry from the device tree blob, in ++ * native-endian format. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, standard meanings ++ */ ++int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size); ++ ++/** ++ * fdt_subnode_offset_namelen - find a subnode based on substring ++ * @fdt: pointer to the device tree blob ++ * @parentoffset: structure block offset of a node ++ * @name: name of the subnode to locate ++ * @namelen: number of characters of name to consider ++ * ++ * Identical to fdt_subnode_offset(), but only examine the first ++ * namelen characters of name for matching the subnode name. This is ++ * useful for finding subnodes based on a portion of a larger string, ++ * such as a full path. ++ * ++ * Return: offset of the subnode or -FDT_ERR_NOTFOUND if name not found. ++ */ ++#ifndef SWIG /* Not available in Python */ ++int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, ++ const char *name, int namelen); ++#endif ++/** ++ * fdt_subnode_offset - find a subnode of a given node ++ * @fdt: pointer to the device tree blob ++ * @parentoffset: structure block offset of a node ++ * @name: name of the subnode to locate ++ * ++ * fdt_subnode_offset() finds a subnode of the node at structure block ++ * offset parentoffset with the given name. name may include a unit ++ * address, in which case fdt_subnode_offset() will find the subnode ++ * with that unit address, or the unit address may be omitted, in ++ * which case fdt_subnode_offset() will find an arbitrary subnode ++ * whose name excluding unit address matches the given name. ++ * ++ * returns: ++ * structure block offset of the requested subnode (>=0), on success ++ * -FDT_ERR_NOTFOUND, if the requested subnode does not exist ++ * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE ++ * tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings. ++ */ ++int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); ++ ++/** ++ * fdt_path_offset_namelen - find a tree node by its full path ++ * @fdt: pointer to the device tree blob ++ * @path: full path of the node to locate ++ * @namelen: number of characters of path to consider ++ * ++ * Identical to fdt_path_offset(), but only consider the first namelen ++ * characters of path as the path name. ++ * ++ * Return: offset of the node or negative libfdt error value otherwise ++ */ ++#ifndef SWIG /* Not available in Python */ ++int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen); ++#endif ++ ++/** ++ * fdt_path_offset - find a tree node by its full path ++ * @fdt: pointer to the device tree blob ++ * @path: full path of the node to locate ++ * ++ * fdt_path_offset() finds a node of a given path in the device tree. ++ * Each path component may omit the unit address portion, but the ++ * results of this are undefined if any such path component is ++ * ambiguous (that is if there are multiple nodes at the relevant ++ * level matching the given component, differentiated only by unit ++ * address). ++ * ++ * returns: ++ * structure block offset of the node with the requested path (>=0), on ++ * success ++ * -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid ++ * -FDT_ERR_NOTFOUND, if the requested node does not exist ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings. ++ */ ++int fdt_path_offset(const void *fdt, const char *path); ++ ++/** ++ * fdt_get_name - retrieve the name of a given node ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: structure block offset of the starting node ++ * @lenp: pointer to an integer variable (will be overwritten) or NULL ++ * ++ * fdt_get_name() retrieves the name (including unit address) of the ++ * device tree node at structure block offset nodeoffset. If lenp is ++ * non-NULL, the length of this name is also returned, in the integer ++ * pointed to by lenp. ++ * ++ * returns: ++ * pointer to the node's name, on success ++ * If lenp is non-NULL, *lenp contains the length of that name ++ * (>=0) ++ * NULL, on error ++ * if lenp is non-NULL *lenp contains an error code (<0): ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE ++ * tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, standard meanings ++ */ ++const char *fdt_get_name(const void *fdt, int nodeoffset, int *lenp); ++ ++/** ++ * fdt_first_property_offset - find the offset of a node's first property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: structure block offset of a node ++ * ++ * fdt_first_property_offset() finds the first property of the node at ++ * the given structure block offset. ++ * ++ * returns: ++ * structure block offset of the property (>=0), on success ++ * -FDT_ERR_NOTFOUND, if the requested node has no properties ++ * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings. ++ */ ++int fdt_first_property_offset(const void *fdt, int nodeoffset); ++ ++/** ++ * fdt_next_property_offset - step through a node's properties ++ * @fdt: pointer to the device tree blob ++ * @offset: structure block offset of a property ++ * ++ * fdt_next_property_offset() finds the property immediately after the ++ * one at the given structure block offset. This will be a property ++ * of the same node as the given property. ++ * ++ * returns: ++ * structure block offset of the next property (>=0), on success ++ * -FDT_ERR_NOTFOUND, if the given property is the last in its node ++ * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings. ++ */ ++int fdt_next_property_offset(const void *fdt, int offset); ++ ++/** ++ * fdt_for_each_property_offset - iterate over all properties of a node ++ * ++ * @property: property offset (int, lvalue) ++ * @fdt: FDT blob (const void *) ++ * @node: node offset (int) ++ * ++ * This is actually a wrapper around a for loop and would be used like so: ++ * ++ * fdt_for_each_property_offset(property, fdt, node) { ++ * Use property ++ * ... ++ * } ++ * ++ * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) { ++ * Error handling ++ * } ++ * ++ * Note that this is implemented as a macro and property is used as ++ * iterator in the loop. The node variable can be constant or even a ++ * literal. ++ */ ++#define fdt_for_each_property_offset(property, fdt, node) \ ++ for (property = fdt_first_property_offset(fdt, node); \ ++ property >= 0; \ ++ property = fdt_next_property_offset(fdt, property)) ++ ++/** ++ * fdt_get_property_by_offset - retrieve the property at a given offset ++ * @fdt: pointer to the device tree blob ++ * @offset: offset of the property to retrieve ++ * @lenp: pointer to an integer variable (will be overwritten) or NULL ++ * ++ * fdt_get_property_by_offset() retrieves a pointer to the ++ * fdt_property structure within the device tree blob at the given ++ * offset. If lenp is non-NULL, the length of the property value is ++ * also returned, in the integer pointed to by lenp. ++ * ++ * Note that this code only works on device tree versions >= 16. fdt_getprop() ++ * works on all versions. ++ * ++ * returns: ++ * pointer to the structure representing the property ++ * if lenp is non-NULL, *lenp contains the length of the property ++ * value (>=0) ++ * NULL, on error ++ * if lenp is non-NULL, *lenp contains an error code (<0): ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++const struct fdt_property *fdt_get_property_by_offset(const void *fdt, ++ int offset, ++ int *lenp); ++ ++/** ++ * fdt_get_property_namelen - find a property based on substring ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to find ++ * @name: name of the property to find ++ * @namelen: number of characters of name to consider ++ * @lenp: pointer to an integer variable (will be overwritten) or NULL ++ * ++ * Identical to fdt_get_property(), but only examine the first namelen ++ * characters of name for matching the property name. ++ * ++ * Return: pointer to the structure representing the property, or NULL ++ * if not found ++ */ ++#ifndef SWIG /* Not available in Python */ ++const struct fdt_property *fdt_get_property_namelen(const void *fdt, ++ int nodeoffset, ++ const char *name, ++ int namelen, int *lenp); ++#endif ++ ++/** ++ * fdt_get_property - find a given property in a given node ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to find ++ * @name: name of the property to find ++ * @lenp: pointer to an integer variable (will be overwritten) or NULL ++ * ++ * fdt_get_property() retrieves a pointer to the fdt_property ++ * structure within the device tree blob corresponding to the property ++ * named 'name' of the node at offset nodeoffset. If lenp is ++ * non-NULL, the length of the property value is also returned, in the ++ * integer pointed to by lenp. ++ * ++ * returns: ++ * pointer to the structure representing the property ++ * if lenp is non-NULL, *lenp contains the length of the property ++ * value (>=0) ++ * NULL, on error ++ * if lenp is non-NULL, *lenp contains an error code (<0): ++ * -FDT_ERR_NOTFOUND, node does not have named property ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE ++ * tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++const struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset, ++ const char *name, int *lenp); ++static inline struct fdt_property *fdt_get_property_w(void *fdt, int nodeoffset, ++ const char *name, ++ int *lenp) ++{ ++ return (struct fdt_property *)(uintptr_t) ++ fdt_get_property(fdt, nodeoffset, name, lenp); ++} ++ ++/** ++ * fdt_getprop_by_offset - retrieve the value of a property at a given offset ++ * @fdt: pointer to the device tree blob ++ * @offset: offset of the property to read ++ * @namep: pointer to a string variable (will be overwritten) or NULL ++ * @lenp: pointer to an integer variable (will be overwritten) or NULL ++ * ++ * fdt_getprop_by_offset() retrieves a pointer to the value of the ++ * property at structure block offset 'offset' (this will be a pointer ++ * to within the device blob itself, not a copy of the value). If ++ * lenp is non-NULL, the length of the property value is also ++ * returned, in the integer pointed to by lenp. If namep is non-NULL, ++ * the property's namne will also be returned in the char * pointed to ++ * by namep (this will be a pointer to within the device tree's string ++ * block, not a new copy of the name). ++ * ++ * returns: ++ * pointer to the property's value ++ * if lenp is non-NULL, *lenp contains the length of the property ++ * value (>=0) ++ * if namep is non-NULL *namep contiains a pointer to the property ++ * name. ++ * NULL, on error ++ * if lenp is non-NULL, *lenp contains an error code (<0): ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_PROP tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++#ifndef SWIG /* This function is not useful in Python */ ++const void *fdt_getprop_by_offset(const void *fdt, int offset, ++ const char **namep, int *lenp); ++#endif ++ ++/** ++ * fdt_getprop_namelen - get property value based on substring ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to find ++ * @name: name of the property to find ++ * @namelen: number of characters of name to consider ++ * @lenp: pointer to an integer variable (will be overwritten) or NULL ++ * ++ * Identical to fdt_getprop(), but only examine the first namelen ++ * characters of name for matching the property name. ++ * ++ * Return: pointer to the property's value or NULL on error ++ */ ++#ifndef SWIG /* Not available in Python */ ++const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, ++ const char *name, int namelen, int *lenp); ++static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset, ++ const char *name, int namelen, ++ int *lenp) ++{ ++ return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name, ++ namelen, lenp); ++} ++#endif ++ ++/** ++ * fdt_getprop - retrieve the value of a given property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to find ++ * @name: name of the property to find ++ * @lenp: pointer to an integer variable (will be overwritten) or NULL ++ * ++ * fdt_getprop() retrieves a pointer to the value of the property ++ * named @name of the node at offset @nodeoffset (this will be a ++ * pointer to within the device blob itself, not a copy of the value). ++ * If @lenp is non-NULL, the length of the property value is also ++ * returned, in the integer pointed to by @lenp. ++ * ++ * returns: ++ * pointer to the property's value ++ * if lenp is non-NULL, *lenp contains the length of the property ++ * value (>=0) ++ * NULL, on error ++ * if lenp is non-NULL, *lenp contains an error code (<0): ++ * -FDT_ERR_NOTFOUND, node does not have named property ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE ++ * tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++const void *fdt_getprop(const void *fdt, int nodeoffset, ++ const char *name, int *lenp); ++static inline void *fdt_getprop_w(void *fdt, int nodeoffset, ++ const char *name, int *lenp) ++{ ++ return (void *)(uintptr_t)fdt_getprop(fdt, nodeoffset, name, lenp); ++} ++ ++/** ++ * fdt_get_phandle - retrieve the phandle of a given node ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: structure block offset of the node ++ * ++ * fdt_get_phandle() retrieves the phandle of the device tree node at ++ * structure block offset nodeoffset. ++ * ++ * returns: ++ * the phandle of the node at nodeoffset, on success (!= 0, != -1) ++ * 0, if the node has no phandle, or another error occurs ++ */ ++uint32_t fdt_get_phandle(const void *fdt, int nodeoffset); ++ ++/** ++ * fdt_get_alias_namelen - get alias based on substring ++ * @fdt: pointer to the device tree blob ++ * @name: name of the alias th look up ++ * @namelen: number of characters of name to consider ++ * ++ * Identical to fdt_get_alias(), but only examine the first @namelen ++ * characters of @name for matching the alias name. ++ * ++ * Return: a pointer to the expansion of the alias named @name, if it exists, ++ * NULL otherwise ++ */ ++#ifndef SWIG /* Not available in Python */ ++const char *fdt_get_alias_namelen(const void *fdt, ++ const char *name, int namelen); ++#endif ++ ++/** ++ * fdt_get_alias - retrieve the path referenced by a given alias ++ * @fdt: pointer to the device tree blob ++ * @name: name of the alias th look up ++ * ++ * fdt_get_alias() retrieves the value of a given alias. That is, the ++ * value of the property named @name in the node /aliases. ++ * ++ * returns: ++ * a pointer to the expansion of the alias named 'name', if it exists ++ * NULL, if the given alias or the /aliases node does not exist ++ */ ++const char *fdt_get_alias(const void *fdt, const char *name); ++ ++/** ++ * fdt_get_path - determine the full path of a node ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose path to find ++ * @buf: character buffer to contain the returned path (will be overwritten) ++ * @buflen: size of the character buffer at buf ++ * ++ * fdt_get_path() computes the full path of the node at offset ++ * nodeoffset, and records that path in the buffer at buf. ++ * ++ * NOTE: This function is expensive, as it must scan the device tree ++ * structure from the start to nodeoffset. ++ * ++ * returns: ++ * 0, on success ++ * buf contains the absolute path of the node at ++ * nodeoffset, as a NUL-terminated string. ++ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag ++ * -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1) ++ * characters and will not fit in the given buffer. ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, standard meanings ++ */ ++int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen); ++ ++/** ++ * fdt_supernode_atdepth_offset - find a specific ancestor of a node ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose parent to find ++ * @supernodedepth: depth of the ancestor to find ++ * @nodedepth: pointer to an integer variable (will be overwritten) or NULL ++ * ++ * fdt_supernode_atdepth_offset() finds an ancestor of the given node ++ * at a specific depth from the root (where the root itself has depth ++ * 0, its immediate subnodes depth 1 and so forth). So ++ * fdt_supernode_atdepth_offset(fdt, nodeoffset, 0, NULL); ++ * will always return 0, the offset of the root node. If the node at ++ * nodeoffset has depth D, then: ++ * fdt_supernode_atdepth_offset(fdt, nodeoffset, D, NULL); ++ * will return nodeoffset itself. ++ * ++ * NOTE: This function is expensive, as it must scan the device tree ++ * structure from the start to nodeoffset. ++ * ++ * returns: ++ * structure block offset of the node at node offset's ancestor ++ * of depth supernodedepth (>=0), on success ++ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag ++ * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of ++ * nodeoffset ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, standard meanings ++ */ ++int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, ++ int supernodedepth, int *nodedepth); ++ ++/** ++ * fdt_node_depth - find the depth of a given node ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose parent to find ++ * ++ * fdt_node_depth() finds the depth of a given node. The root node ++ * has depth 0, its immediate subnodes depth 1 and so forth. ++ * ++ * NOTE: This function is expensive, as it must scan the device tree ++ * structure from the start to nodeoffset. ++ * ++ * returns: ++ * depth of the node at nodeoffset (>=0), on success ++ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, standard meanings ++ */ ++int fdt_node_depth(const void *fdt, int nodeoffset); ++ ++/** ++ * fdt_parent_offset - find the parent of a given node ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose parent to find ++ * ++ * fdt_parent_offset() locates the parent node of a given node (that ++ * is, it finds the offset of the node which contains the node at ++ * nodeoffset as a subnode). ++ * ++ * NOTE: This function is expensive, as it must scan the device tree ++ * structure from the start to nodeoffset, *twice*. ++ * ++ * returns: ++ * structure block offset of the parent of the node at nodeoffset ++ * (>=0), on success ++ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, standard meanings ++ */ ++int fdt_parent_offset(const void *fdt, int nodeoffset); ++ ++/** ++ * fdt_node_offset_by_prop_value - find nodes with a given property value ++ * @fdt: pointer to the device tree blob ++ * @startoffset: only find nodes after this offset ++ * @propname: property name to check ++ * @propval: property value to search for ++ * @proplen: length of the value in propval ++ * ++ * fdt_node_offset_by_prop_value() returns the offset of the first ++ * node after startoffset, which has a property named propname whose ++ * value is of length proplen and has value equal to propval; or if ++ * startoffset is -1, the very first such node in the tree. ++ * ++ * To iterate through all nodes matching the criterion, the following ++ * idiom can be used: ++ * offset = fdt_node_offset_by_prop_value(fdt, -1, propname, ++ * propval, proplen); ++ * while (offset != -FDT_ERR_NOTFOUND) { ++ * // other code here ++ * offset = fdt_node_offset_by_prop_value(fdt, offset, propname, ++ * propval, proplen); ++ * } ++ * ++ * Note the -1 in the first call to the function, if 0 is used here ++ * instead, the function will never locate the root node, even if it ++ * matches the criterion. ++ * ++ * returns: ++ * structure block offset of the located node (>= 0, >startoffset), ++ * on success ++ * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the ++ * tree after startoffset ++ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, standard meanings ++ */ ++int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, ++ const char *propname, ++ const void *propval, int proplen); ++ ++/** ++ * fdt_node_offset_by_phandle - find the node with a given phandle ++ * @fdt: pointer to the device tree blob ++ * @phandle: phandle value ++ * ++ * fdt_node_offset_by_phandle() returns the offset of the node ++ * which has the given phandle value. If there is more than one node ++ * in the tree with the given phandle (an invalid tree), results are ++ * undefined. ++ * ++ * returns: ++ * structure block offset of the located node (>= 0), on success ++ * -FDT_ERR_NOTFOUND, no node with that phandle exists ++ * -FDT_ERR_BADPHANDLE, given phandle value was invalid (0 or -1) ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, standard meanings ++ */ ++int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle); ++ ++/** ++ * fdt_node_check_compatible - check a node's compatible property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of a tree node ++ * @compatible: string to match against ++ * ++ * fdt_node_check_compatible() returns 0 if the given node contains a ++ * @compatible property with the given string as one of its elements, ++ * it returns non-zero otherwise, or on error. ++ * ++ * returns: ++ * 0, if the node has a 'compatible' property listing the given string ++ * 1, if the node has a 'compatible' property, but it does not list ++ * the given string ++ * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property ++ * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, standard meanings ++ */ ++int fdt_node_check_compatible(const void *fdt, int nodeoffset, ++ const char *compatible); ++ ++/** ++ * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value ++ * @fdt: pointer to the device tree blob ++ * @startoffset: only find nodes after this offset ++ * @compatible: 'compatible' string to match against ++ * ++ * fdt_node_offset_by_compatible() returns the offset of the first ++ * node after startoffset, which has a 'compatible' property which ++ * lists the given compatible string; or if startoffset is -1, the ++ * very first such node in the tree. ++ * ++ * To iterate through all nodes matching the criterion, the following ++ * idiom can be used: ++ * offset = fdt_node_offset_by_compatible(fdt, -1, compatible); ++ * while (offset != -FDT_ERR_NOTFOUND) { ++ * // other code here ++ * offset = fdt_node_offset_by_compatible(fdt, offset, compatible); ++ * } ++ * ++ * Note the -1 in the first call to the function, if 0 is used here ++ * instead, the function will never locate the root node, even if it ++ * matches the criterion. ++ * ++ * returns: ++ * structure block offset of the located node (>= 0, >startoffset), ++ * on success ++ * -FDT_ERR_NOTFOUND, no node matching the criterion exists in the ++ * tree after startoffset ++ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, standard meanings ++ */ ++int fdt_node_offset_by_compatible(const void *fdt, int startoffset, ++ const char *compatible); ++ ++/** ++ * fdt_stringlist_contains - check a string list property for a string ++ * @strlist: Property containing a list of strings to check ++ * @listlen: Length of property ++ * @str: String to search for ++ * ++ * This is a utility function provided for convenience. The list contains ++ * one or more strings, each terminated by \0, as is found in a device tree ++ * "compatible" property. ++ * ++ * Return: 1 if the string is found in the list, 0 not found, or invalid list ++ */ ++int fdt_stringlist_contains(const char *strlist, int listlen, const char *str); ++ ++/** ++ * fdt_stringlist_count - count the number of strings in a string list ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of a tree node ++ * @property: name of the property containing the string list ++ * ++ * Return: ++ * the number of strings in the given property ++ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated ++ * -FDT_ERR_NOTFOUND if the property does not exist ++ */ ++int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property); ++ ++/** ++ * fdt_stringlist_search - find a string in a string list and return its index ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of a tree node ++ * @property: name of the property containing the string list ++ * @string: string to look up in the string list ++ * ++ * Note that it is possible for this function to succeed on property values ++ * that are not NUL-terminated. That's because the function will stop after ++ * finding the first occurrence of @string. This can for example happen with ++ * small-valued cell properties, such as #address-cells, when searching for ++ * the empty string. ++ * ++ * return: ++ * the index of the string in the list of strings ++ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated ++ * -FDT_ERR_NOTFOUND if the property does not exist or does not contain ++ * the given string ++ */ ++int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, ++ const char *string); ++ ++/** ++ * fdt_stringlist_get() - obtain the string at a given index in a string list ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of a tree node ++ * @property: name of the property containing the string list ++ * @index: index of the string to return ++ * @lenp: return location for the string length or an error code on failure ++ * ++ * Note that this will successfully extract strings from properties with ++ * non-NUL-terminated values. For example on small-valued cell properties ++ * this function will return the empty string. ++ * ++ * If non-NULL, the length of the string (on success) or a negative error-code ++ * (on failure) will be stored in the integer pointer to by lenp. ++ * ++ * Return: ++ * A pointer to the string at the given index in the string list or NULL on ++ * failure. On success the length of the string will be stored in the memory ++ * location pointed to by the lenp parameter, if non-NULL. On failure one of ++ * the following negative error codes will be returned in the lenp parameter ++ * (if non-NULL): ++ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated ++ * -FDT_ERR_NOTFOUND if the property does not exist ++ */ ++const char *fdt_stringlist_get(const void *fdt, int nodeoffset, ++ const char *property, int index, ++ int *lenp); ++ ++/**********************************************************************/ ++/* Read-only functions (addressing related) */ ++/**********************************************************************/ ++ ++/** ++ * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells ++ * ++ * This is the maximum value for #address-cells, #size-cells and ++ * similar properties that will be processed by libfdt. IEE1275 ++ * requires that OF implementations handle values up to 4. ++ * Implementations may support larger values, but in practice higher ++ * values aren't used. ++ */ ++#define FDT_MAX_NCELLS 4 ++ ++/** ++ * fdt_address_cells - retrieve address size for a bus represented in the tree ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node to find the address size for ++ * ++ * When the node has a valid #address-cells property, returns its value. ++ * ++ * returns: ++ * 0 <= n < FDT_MAX_NCELLS, on success ++ * 2, if the node has no #address-cells property ++ * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid ++ * #address-cells property ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_address_cells(const void *fdt, int nodeoffset); ++ ++/** ++ * fdt_size_cells - retrieve address range size for a bus represented in the ++ * tree ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node to find the address range size for ++ * ++ * When the node has a valid #size-cells property, returns its value. ++ * ++ * returns: ++ * 0 <= n < FDT_MAX_NCELLS, on success ++ * 1, if the node has no #size-cells property ++ * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid ++ * #size-cells property ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_size_cells(const void *fdt, int nodeoffset); ++ ++ ++/**********************************************************************/ ++/* Write-in-place functions */ ++/**********************************************************************/ ++ ++/** ++ * fdt_setprop_inplace_namelen_partial - change a property's value, ++ * but not its size ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @namelen: number of characters of name to consider ++ * @idx: index of the property to change in the array ++ * @val: pointer to data to replace the property value with ++ * @len: length of the property value ++ * ++ * Identical to fdt_setprop_inplace(), but modifies the given property ++ * starting from the given index, and using only the first characters ++ * of the name. It is useful when you want to manipulate only one value of ++ * an array and you have a string that doesn't end with \0. ++ * ++ * Return: 0 on success, negative libfdt error value otherwise ++ */ ++#ifndef SWIG /* Not available in Python */ ++int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, ++ const char *name, int namelen, ++ uint32_t idx, const void *val, ++ int len); ++#endif ++ ++/** ++ * fdt_setprop_inplace - change a property's value, but not its size ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: pointer to data to replace the property value with ++ * @len: length of the property value ++ * ++ * fdt_setprop_inplace() replaces the value of a given property with ++ * the data in val, of length len. This function cannot change the ++ * size of a property, and so will only work if len is equal to the ++ * current length of the property. ++ * ++ * This function will alter only the bytes in the blob which contain ++ * the given property value, and will not alter or move any other part ++ * of the tree. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, if len is not equal to the property's current length ++ * -FDT_ERR_NOTFOUND, node does not have the named property ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++#ifndef SWIG /* Not available in Python */ ++int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, ++ const void *val, int len); ++#endif ++ ++/** ++ * fdt_setprop_inplace_u32 - change the value of a 32-bit integer property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: 32-bit integer value to replace the property with ++ * ++ * fdt_setprop_inplace_u32() replaces the value of a given property ++ * with the 32-bit integer value in val, converting val to big-endian ++ * if necessary. This function cannot change the size of a property, ++ * and so will only work if the property already exists and has length ++ * 4. ++ * ++ * This function will alter only the bytes in the blob which contain ++ * the given property value, and will not alter or move any other part ++ * of the tree. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, if the property's length is not equal to 4 ++ * -FDT_ERR_NOTFOUND, node does not have the named property ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset, ++ const char *name, uint32_t val) ++{ ++ fdt32_t tmp = cpu_to_fdt32(val); ++ return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); ++} ++ ++/** ++ * fdt_setprop_inplace_u64 - change the value of a 64-bit integer property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: 64-bit integer value to replace the property with ++ * ++ * fdt_setprop_inplace_u64() replaces the value of a given property ++ * with the 64-bit integer value in val, converting val to big-endian ++ * if necessary. This function cannot change the size of a property, ++ * and so will only work if the property already exists and has length ++ * 8. ++ * ++ * This function will alter only the bytes in the blob which contain ++ * the given property value, and will not alter or move any other part ++ * of the tree. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, if the property's length is not equal to 8 ++ * -FDT_ERR_NOTFOUND, node does not have the named property ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset, ++ const char *name, uint64_t val) ++{ ++ fdt64_t tmp = cpu_to_fdt64(val); ++ return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp)); ++} ++ ++/** ++ * fdt_setprop_inplace_cell - change the value of a single-cell property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node containing the property ++ * @name: name of the property to change the value of ++ * @val: new value of the 32-bit cell ++ * ++ * This is an alternative name for fdt_setprop_inplace_u32() ++ * Return: 0 on success, negative libfdt error number otherwise. ++ */ ++static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset, ++ const char *name, uint32_t val) ++{ ++ return fdt_setprop_inplace_u32(fdt, nodeoffset, name, val); ++} ++ ++/** ++ * fdt_nop_property - replace a property with nop tags ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to nop ++ * @name: name of the property to nop ++ * ++ * fdt_nop_property() will replace a given property's representation ++ * in the blob with FDT_NOP tags, effectively removing it from the ++ * tree. ++ * ++ * This function will alter only the bytes in the blob which contain ++ * the property, and will not alter or move any other part of the ++ * tree. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOTFOUND, node does not have the named property ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_nop_property(void *fdt, int nodeoffset, const char *name); ++ ++/** ++ * fdt_nop_node - replace a node (subtree) with nop tags ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node to nop ++ * ++ * fdt_nop_node() will replace a given node's representation in the ++ * blob, including all its subnodes, if any, with FDT_NOP tags, ++ * effectively removing it from the tree. ++ * ++ * This function will alter only the bytes in the blob which contain ++ * the node and its properties and subnodes, and will not alter or ++ * move any other part of the tree. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_nop_node(void *fdt, int nodeoffset); ++ ++/**********************************************************************/ ++/* Sequential write functions */ ++/**********************************************************************/ ++ ++/* fdt_create_with_flags flags */ ++#define FDT_CREATE_FLAG_NO_NAME_DEDUP 0x1 ++ /* FDT_CREATE_FLAG_NO_NAME_DEDUP: Do not try to de-duplicate property ++ * names in the fdt. This can result in faster creation times, but ++ * a larger fdt. */ ++ ++#define FDT_CREATE_FLAGS_ALL (FDT_CREATE_FLAG_NO_NAME_DEDUP) ++ ++/** ++ * fdt_create_with_flags - begin creation of a new fdt ++ * @buf: pointer to memory allocated where fdt will be created ++ * @bufsize: size of the memory space at fdt ++ * @flags: a valid combination of FDT_CREATE_FLAG_ flags, or 0. ++ * ++ * fdt_create_with_flags() begins the process of creating a new fdt with ++ * the sequential write interface. ++ * ++ * fdt creation process must end with fdt_finished() to produce a valid fdt. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt ++ * -FDT_ERR_BADFLAGS, flags is not valid ++ */ ++int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags); ++ ++/** ++ * fdt_create - begin creation of a new fdt ++ * @buf: pointer to memory allocated where fdt will be created ++ * @bufsize: size of the memory space at fdt ++ * ++ * fdt_create() is equivalent to fdt_create_with_flags() with flags=0. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, bufsize is insufficient for a minimal fdt ++ */ ++int fdt_create(void *buf, int bufsize); ++ ++int fdt_resize(void *fdt, void *buf, int bufsize); ++int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size); ++int fdt_finish_reservemap(void *fdt); ++int fdt_begin_node(void *fdt, const char *name); ++int fdt_property(void *fdt, const char *name, const void *val, int len); ++static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val) ++{ ++ fdt32_t tmp = cpu_to_fdt32(val); ++ return fdt_property(fdt, name, &tmp, sizeof(tmp)); ++} ++static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) ++{ ++ fdt64_t tmp = cpu_to_fdt64(val); ++ return fdt_property(fdt, name, &tmp, sizeof(tmp)); ++} ++ ++#ifndef SWIG /* Not available in Python */ ++static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) ++{ ++ return fdt_property_u32(fdt, name, val); ++} ++#endif ++ ++/** ++ * fdt_property_placeholder - add a new property and return a ptr to its value ++ * ++ * @fdt: pointer to the device tree blob ++ * @name: name of property to add ++ * @len: length of property value in bytes ++ * @valp: returns a pointer to where where the value should be placed ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_NOSPACE, standard meanings ++ */ ++int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp); ++ ++#define fdt_property_string(fdt, name, str) \ ++ fdt_property(fdt, name, str, strlen(str)+1) ++int fdt_end_node(void *fdt); ++int fdt_finish(void *fdt); ++ ++/**********************************************************************/ ++/* Read-write functions */ ++/**********************************************************************/ ++ ++int fdt_create_empty_tree(void *buf, int bufsize); ++int fdt_open_into(const void *fdt, void *buf, int bufsize); ++int fdt_pack(void *fdt); ++ ++/** ++ * fdt_add_mem_rsv - add one memory reserve map entry ++ * @fdt: pointer to the device tree blob ++ * @address: 64-bit start address of the reserve map entry ++ * @size: 64-bit size of the reserved region ++ * ++ * Adds a reserve map entry to the given blob reserving a region at ++ * address address of length size. ++ * ++ * This function will insert data into the reserve map and will ++ * therefore change the indexes of some entries in the table. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new reservation entry ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size); ++ ++/** ++ * fdt_del_mem_rsv - remove a memory reserve map entry ++ * @fdt: pointer to the device tree blob ++ * @n: entry to remove ++ * ++ * fdt_del_mem_rsv() removes the n-th memory reserve map entry from ++ * the blob. ++ * ++ * This function will delete data from the reservation table and will ++ * therefore change the indexes of some entries in the table. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there ++ * are less than n+1 reserve map entries) ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_del_mem_rsv(void *fdt, int n); ++ ++/** ++ * fdt_set_name - change the name of a given node ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: structure block offset of a node ++ * @name: name to give the node ++ * ++ * fdt_set_name() replaces the name (including unit address, if any) ++ * of the given node with the given string. NOTE: this function can't ++ * efficiently check if the new name is unique amongst the given ++ * node's siblings; results are undefined if this function is invoked ++ * with a name equal to one of the given node's siblings. ++ * ++ * This function may insert or delete data from the blob, and will ++ * therefore change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob ++ * to contain the new name ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, standard meanings ++ */ ++int fdt_set_name(void *fdt, int nodeoffset, const char *name); ++ ++/** ++ * fdt_setprop - create or change a property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: pointer to data to set the property value to ++ * @len: length of the property value ++ * ++ * fdt_setprop() sets the value of the named property in the given ++ * node to the given value and length, creating the property if it ++ * does not already exist. ++ * ++ * This function may insert or delete data from the blob, and will ++ * therefore change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_setprop(void *fdt, int nodeoffset, const char *name, ++ const void *val, int len); ++ ++/** ++ * fdt_setprop_placeholder - allocate space for a property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @len: length of the property value ++ * @prop_data: return pointer to property data ++ * ++ * fdt_setprop_placeholer() allocates the named property in the given node. ++ * If the property exists it is resized. In either case a pointer to the ++ * property data is returned. ++ * ++ * This function may insert or delete data from the blob, and will ++ * therefore change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, ++ int len, void **prop_data); ++ ++/** ++ * fdt_setprop_u32 - set a property to a 32-bit integer ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: 32-bit integer value for the property (native endian) ++ * ++ * fdt_setprop_u32() sets the value of the named property in the given ++ * node to the given 32-bit integer value (converting to big-endian if ++ * necessary), or creates a new property with that value if it does ++ * not already exist. ++ * ++ * This function may insert or delete data from the blob, and will ++ * therefore change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name, ++ uint32_t val) ++{ ++ fdt32_t tmp = cpu_to_fdt32(val); ++ return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); ++} ++ ++/** ++ * fdt_setprop_u64 - set a property to a 64-bit integer ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: 64-bit integer value for the property (native endian) ++ * ++ * fdt_setprop_u64() sets the value of the named property in the given ++ * node to the given 64-bit integer value (converting to big-endian if ++ * necessary), or creates a new property with that value if it does ++ * not already exist. ++ * ++ * This function may insert or delete data from the blob, and will ++ * therefore change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name, ++ uint64_t val) ++{ ++ fdt64_t tmp = cpu_to_fdt64(val); ++ return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); ++} ++ ++/** ++ * fdt_setprop_cell - set a property to a single cell value ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: 32-bit integer value for the property (native endian) ++ * ++ * This is an alternative name for fdt_setprop_u32() ++ * ++ * Return: 0 on success, negative libfdt error value otherwise. ++ */ ++static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name, ++ uint32_t val) ++{ ++ return fdt_setprop_u32(fdt, nodeoffset, name, val); ++} ++ ++/** ++ * fdt_setprop_string - set a property to a string value ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @str: string value for the property ++ * ++ * fdt_setprop_string() sets the value of the named property in the ++ * given node to the given string value (using the length of the ++ * string to determine the new length of the property), or creates a ++ * new property with that value if it does not already exist. ++ * ++ * This function may insert or delete data from the blob, and will ++ * therefore change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++#define fdt_setprop_string(fdt, nodeoffset, name, str) \ ++ fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) ++ ++ ++/** ++ * fdt_setprop_empty - set a property to an empty value ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * ++ * fdt_setprop_empty() sets the value of the named property in the ++ * given node to an empty (zero length) value, or creates a new empty ++ * property if it does not already exist. ++ * ++ * This function may insert or delete data from the blob, and will ++ * therefore change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++#define fdt_setprop_empty(fdt, nodeoffset, name) \ ++ fdt_setprop((fdt), (nodeoffset), (name), NULL, 0) ++ ++/** ++ * fdt_appendprop - append to or create a property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to append to ++ * @val: pointer to data to append to the property value ++ * @len: length of the data to append to the property value ++ * ++ * fdt_appendprop() appends the value to the named property in the ++ * given node, creating the property if it does not already exist. ++ * ++ * This function may insert data into the blob, and will therefore ++ * change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_appendprop(void *fdt, int nodeoffset, const char *name, ++ const void *val, int len); ++ ++/** ++ * fdt_appendprop_u32 - append a 32-bit integer value to a property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: 32-bit integer value to append to the property (native endian) ++ * ++ * fdt_appendprop_u32() appends the given 32-bit integer value ++ * (converting to big-endian if necessary) to the value of the named ++ * property in the given node, or creates a new property with that ++ * value if it does not already exist. ++ * ++ * This function may insert data into the blob, and will therefore ++ * change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++static inline int fdt_appendprop_u32(void *fdt, int nodeoffset, ++ const char *name, uint32_t val) ++{ ++ fdt32_t tmp = cpu_to_fdt32(val); ++ return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); ++} ++ ++/** ++ * fdt_appendprop_u64 - append a 64-bit integer value to a property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: 64-bit integer value to append to the property (native endian) ++ * ++ * fdt_appendprop_u64() appends the given 64-bit integer value ++ * (converting to big-endian if necessary) to the value of the named ++ * property in the given node, or creates a new property with that ++ * value if it does not already exist. ++ * ++ * This function may insert data into the blob, and will therefore ++ * change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++static inline int fdt_appendprop_u64(void *fdt, int nodeoffset, ++ const char *name, uint64_t val) ++{ ++ fdt64_t tmp = cpu_to_fdt64(val); ++ return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp)); ++} ++ ++/** ++ * fdt_appendprop_cell - append a single cell value to a property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @val: 32-bit integer value to append to the property (native endian) ++ * ++ * This is an alternative name for fdt_appendprop_u32() ++ * ++ * Return: 0 on success, negative libfdt error value otherwise. ++ */ ++static inline int fdt_appendprop_cell(void *fdt, int nodeoffset, ++ const char *name, uint32_t val) ++{ ++ return fdt_appendprop_u32(fdt, nodeoffset, name, val); ++} ++ ++/** ++ * fdt_appendprop_string - append a string to a property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to change ++ * @name: name of the property to change ++ * @str: string value to append to the property ++ * ++ * fdt_appendprop_string() appends the given string to the value of ++ * the named property in the given node, or creates a new property ++ * with that value if it does not already exist. ++ * ++ * This function may insert data into the blob, and will therefore ++ * change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain the new property value ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++#define fdt_appendprop_string(fdt, nodeoffset, name, str) \ ++ fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) ++ ++/** ++ * fdt_appendprop_addrrange - append a address range property ++ * @fdt: pointer to the device tree blob ++ * @parent: offset of the parent node ++ * @nodeoffset: offset of the node to add a property at ++ * @name: name of property ++ * @addr: start address of a given range ++ * @size: size of a given range ++ * ++ * fdt_appendprop_addrrange() appends an address range value (start ++ * address and size) to the value of the named property in the given ++ * node, or creates a new property with that value if it does not ++ * already exist. ++ * If "name" is not specified, a default "reg" is used. ++ * Cell sizes are determined by parent's #address-cells and #size-cells. ++ * ++ * This function may insert data into the blob, and will therefore ++ * change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid ++ * #address-cells property ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size ++ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to ++ * contain a new property ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset, ++ const char *name, uint64_t addr, uint64_t size); ++ ++/** ++ * fdt_delprop - delete a property ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node whose property to nop ++ * @name: name of the property to nop ++ * ++ * fdt_del_property() will delete the given property. ++ * ++ * This function will delete data from the blob, and will therefore ++ * change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOTFOUND, node does not have the named property ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_delprop(void *fdt, int nodeoffset, const char *name); ++ ++/** ++ * fdt_add_subnode_namelen - creates a new node based on substring ++ * @fdt: pointer to the device tree blob ++ * @parentoffset: structure block offset of a node ++ * @name: name of the subnode to create ++ * @namelen: number of characters of name to consider ++ * ++ * Identical to fdt_add_subnode(), but use only the first @namelen ++ * characters of @name as the name of the new node. This is useful for ++ * creating subnodes based on a portion of a larger string, such as a ++ * full path. ++ * ++ * Return: structure block offset of the created subnode (>=0), ++ * negative libfdt error value otherwise ++ */ ++#ifndef SWIG /* Not available in Python */ ++int fdt_add_subnode_namelen(void *fdt, int parentoffset, ++ const char *name, int namelen); ++#endif ++ ++/** ++ * fdt_add_subnode - creates a new node ++ * @fdt: pointer to the device tree blob ++ * @parentoffset: structure block offset of a node ++ * @name: name of the subnode to locate ++ * ++ * fdt_add_subnode() creates a new node as a subnode of the node at ++ * structure block offset parentoffset, with the given name (which ++ * should include the unit address, if any). ++ * ++ * This function will insert data into the blob, and will therefore ++ * change the offsets of some existing nodes. ++ * ++ * returns: ++ * structure block offset of the created nodeequested subnode (>=0), on ++ * success ++ * -FDT_ERR_NOTFOUND, if the requested subnode does not exist ++ * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE ++ * tag ++ * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of ++ * the given name ++ * -FDT_ERR_NOSPACE, if there is insufficient free space in the ++ * blob to contain the new node ++ * -FDT_ERR_NOSPACE ++ * -FDT_ERR_BADLAYOUT ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings. ++ */ ++int fdt_add_subnode(void *fdt, int parentoffset, const char *name); ++ ++/** ++ * fdt_del_node - delete a node (subtree) ++ * @fdt: pointer to the device tree blob ++ * @nodeoffset: offset of the node to nop ++ * ++ * fdt_del_node() will remove the given node, including all its ++ * subnodes if any, from the blob. ++ * ++ * This function will delete data from the blob, and will therefore ++ * change the offsets of some existing nodes. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_del_node(void *fdt, int nodeoffset); ++ ++/** ++ * fdt_overlay_apply - Applies a DT overlay on a base DT ++ * @fdt: pointer to the base device tree blob ++ * @fdto: pointer to the device tree overlay blob ++ * ++ * fdt_overlay_apply() will apply the given device tree overlay on the ++ * given base device tree. ++ * ++ * Expect the base device tree to be modified, even if the function ++ * returns an error. ++ * ++ * returns: ++ * 0, on success ++ * -FDT_ERR_NOSPACE, there's not enough space in the base device tree ++ * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or ++ * properties in the base DT ++ * -FDT_ERR_BADPHANDLE, ++ * -FDT_ERR_BADOVERLAY, ++ * -FDT_ERR_NOPHANDLES, ++ * -FDT_ERR_INTERNAL, ++ * -FDT_ERR_BADLAYOUT, ++ * -FDT_ERR_BADMAGIC, ++ * -FDT_ERR_BADOFFSET, ++ * -FDT_ERR_BADPATH, ++ * -FDT_ERR_BADVERSION, ++ * -FDT_ERR_BADSTRUCTURE, ++ * -FDT_ERR_BADSTATE, ++ * -FDT_ERR_TRUNCATED, standard meanings ++ */ ++int fdt_overlay_apply(void *fdt, void *fdto); ++ ++/** ++ * fdt_overlay_target_offset - retrieves the offset of a fragment's target ++ * @fdt: Base device tree blob ++ * @fdto: Device tree overlay blob ++ * @fragment_offset: node offset of the fragment in the overlay ++ * @pathp: pointer which receives the path of the target (or NULL) ++ * ++ * fdt_overlay_target_offset() retrieves the target offset in the base ++ * device tree of a fragment, no matter how the actual targeting is ++ * done (through a phandle or a path) ++ * ++ * returns: ++ * the targeted node offset in the base device tree ++ * Negative error code on error ++ */ ++int fdt_overlay_target_offset(const void *fdt, const void *fdto, ++ int fragment_offset, char const **pathp); ++ ++/**********************************************************************/ ++/* Debugging / informational functions */ ++/**********************************************************************/ ++ ++const char *fdt_strerror(int errval); ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#endif /* LIBFDT_H */ +diff --git a/include/libfdt_env.h b/include/libfdt_env.h +new file mode 100644 +index 0000000..51b31d1 +--- /dev/null ++++ b/include/libfdt_env.h +@@ -0,0 +1,95 @@ ++/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ ++#ifndef LIBFDT_ENV_H ++#define LIBFDT_ENV_H ++/* ++ * libfdt - Flat Device Tree manipulation ++ * Copyright (C) 2006 David Gibson, IBM Corporation. ++ * Copyright 2012 Kim Phillips, Freescale Semiconductor. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef __CHECKER__ ++#define FDT_FORCE __attribute__((force)) ++#define FDT_BITWISE __attribute__((bitwise)) ++#else ++#define FDT_FORCE ++#define FDT_BITWISE ++#endif ++ ++typedef uint16_t FDT_BITWISE fdt16_t; ++typedef uint32_t FDT_BITWISE fdt32_t; ++typedef uint64_t FDT_BITWISE fdt64_t; ++ ++#define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n]) ++#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1)) ++#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \ ++ (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3)) ++#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \ ++ (EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \ ++ (EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \ ++ (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7)) ++ ++static inline uint16_t fdt16_to_cpu(fdt16_t x) ++{ ++ return (FDT_FORCE uint16_t)CPU_TO_FDT16(x); ++} ++static inline fdt16_t cpu_to_fdt16(uint16_t x) ++{ ++ return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x); ++} ++ ++static inline uint32_t fdt32_to_cpu(fdt32_t x) ++{ ++ return (FDT_FORCE uint32_t)CPU_TO_FDT32(x); ++} ++static inline fdt32_t cpu_to_fdt32(uint32_t x) ++{ ++ return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x); ++} ++ ++static inline uint64_t fdt64_to_cpu(fdt64_t x) ++{ ++ return (FDT_FORCE uint64_t)CPU_TO_FDT64(x); ++} ++static inline fdt64_t cpu_to_fdt64(uint64_t x) ++{ ++ return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x); ++} ++#undef CPU_TO_FDT64 ++#undef CPU_TO_FDT32 ++#undef CPU_TO_FDT16 ++#undef EXTRACT_BYTE ++ ++#ifdef __APPLE__ ++#include ++ ++/* strnlen() is not available on Mac OS < 10.7 */ ++# if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < \ ++ MAC_OS_X_VERSION_10_7) ++ ++#define strnlen fdt_strnlen ++ ++/* ++ * fdt_strnlen: returns the length of a string or max_count - which ever is ++ * smallest. ++ * Input 1 string: the string whose size is to be determined ++ * Input 2 max_count: the maximum value returned by this function ++ * Output: length of the string or max_count (the smallest of the two) ++ */ ++static inline size_t fdt_strnlen(const char *string, size_t max_count) ++{ ++ const char *p = memchr(string, 0, max_count); ++ return p ? p - string : max_count; ++} ++ ++#endif /* !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < ++ MAC_OS_X_VERSION_10_7) */ ++ ++#endif /* __APPLE__ */ ++ ++#endif /* LIBFDT_ENV_H */ diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0011-common-Add-essential-libc-functions.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0011-common-Add-essential-libc-functions.patch new file mode 100644 index 0000000..aa05a72 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0011-common-Add-essential-libc-functions.patch @@ -0,0 +1,101 @@ +From 0f2c7ca446063be6b193fbf870d38c0af19e15c5 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 28 Dec 2021 17:28:25 +0800 +Subject: [PATCH] common: Add essential libc functions + +The libfdt uses some of the libc functions, e.g. memcmp, memmove, +strlen .etc. Add them in lib.c. + +The code is copied from TF-A (v2.5) [1] project, which is under the +terms of BSD license. It is the same with boot-wrapper. + +[1]: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git + +Issue-Id: SCM-3814 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Jaxson Han +Change-Id: If3b55b00afa8694c7522df989a41e0b38eda1d38 +--- + common/lib.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 70 insertions(+), 1 deletion(-) + +diff --git a/common/lib.c b/common/lib.c +index fcf5f69..0be1c4a 100644 +--- a/common/lib.c ++++ b/common/lib.c +@@ -32,4 +32,73 @@ void *memset(void *s, int c, size_t n) + return s; + } + +-/* TODO: memmove and memcmp could also be called */ ++int memcmp(const void *s1, const void *s2, size_t len) ++{ ++ const unsigned char *s = s1; ++ const unsigned char *d = s2; ++ unsigned char sc; ++ unsigned char dc; ++ ++ while (len--) { ++ sc = *s++; ++ dc = *d++; ++ if (sc - dc) ++ return (sc - dc); ++ } ++ ++ return 0; ++} ++ ++void *memmove(void *dst, const void *src, size_t len) ++{ ++ if ((size_t)dst - (size_t)src >= len) { ++ /* destination not in source data, so can safely use memcpy */ ++ return memcpy(dst, src, len); ++ } else { ++ /* copy backwards... */ ++ const char *end = dst; ++ const char *s = (const char *)src + len; ++ char *d = (char *)dst + len; ++ while (d != end) ++ *--d = *--s; ++ } ++ return dst; ++} ++ ++void *memchr(const void *src, int c, size_t len) ++{ ++ const unsigned char *s = src; ++ ++ while (len--) { ++ if (*s == (unsigned char)c) ++ return (void *) s; ++ s++; ++ } ++ ++ return NULL; ++} ++ ++char *strrchr(const char *p, int ch) ++{ ++ char *save; ++ char c; ++ ++ c = ch; ++ for (save = NULL;; ++p) { ++ if (*p == c) ++ save = (char *)p; ++ if (*p == '\0') ++ return (save); ++ } ++ /* NOTREACHED */ ++} ++ ++size_t strlen(const char *s) ++{ ++ const char *cursor = s; ++ ++ while (*cursor) ++ cursor++; ++ ++ return cursor - s; ++} diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0012-Makefile-Add-the-libfdt-to-the-Makefile-system.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0012-Makefile-Add-the-libfdt-to-the-Makefile-system.patch new file mode 100644 index 0000000..eeddaac --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0012-Makefile-Add-the-libfdt-to-the-Makefile-system.patch @@ -0,0 +1,61 @@ +From de5d2b6c200ae5dd8113751e58bf7cf5844eec5a Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 28 Dec 2021 17:42:48 +0800 +Subject: [PATCH] Makefile: Add the libfdt to the Makefile system + +Add the libfdt into Makefile system. The libfdt uses const value and +thus gcc will enable the stack guard. The stack guard will fail the +compile. Add -fno-stack-protector to fix it. + +Issue-Id: SCM-3814 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Jaxson Han +Change-Id: I472bc28cdc5cde3b22461a4b7d7a3752ae382b4b +--- + Makefile.am | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/Makefile.am b/Makefile.am +index 88a27de..5e8668a 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -36,6 +36,9 @@ PSCI_CPU_OFF := 0x84000002 + COMMON_SRC := common/ + COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o + ++LIBFDT_SRC := common/libfdt/ ++LIBFDT_OBJS := fdt.o fdt_ro.o fdt_rw.o ++ + ARCH_OBJ := boot.o stack.o utils.o + + if BOOTWRAPPER_32 +@@ -125,11 +128,12 @@ CHOSEN_NODE := chosen { \ + CPPFLAGS += $(INITRD_FLAGS) + CFLAGS += -I$(top_srcdir)/include/ -I$(top_srcdir)/$(ARCH_SRC)/include/ + CFLAGS += -Wall -fomit-frame-pointer ++CFLAGS += -fno-stack-protector + CFLAGS += -ffunction-sections -fdata-sections + CFLAGS += -fno-pic -fno-pie + LDFLAGS += --gc-sections + +-OBJ := $(addprefix $(ARCH_SRC),$(ARCH_OBJ)) $(addprefix $(COMMON_SRC),$(COMMON_OBJ)) ++OBJ := $(addprefix $(ARCH_SRC),$(ARCH_OBJ)) $(addprefix $(COMMON_SRC),$(COMMON_OBJ)) $(addprefix $(LIBFDT_SRC),$(LIBFDT_OBJS)) + + # Don't lookup all prerequisites in $(top_srcdir), only the source files. When + # building outside the source tree $(ARCH_SRC) needs to be created. +@@ -150,10 +154,13 @@ $(ARCH_SRC): + $(COMMON_SRC): + $(MKDIR_P) $@ + ++$(LIBFDT_SRC): ++ $(MKDIR_P) $@ ++ + %.o: %.S Makefile | $(ARCH_SRC) + $(CC) $(CPPFLAGS) -D__ASSEMBLY__ $(CFLAGS) $(DEFINES) -c -o $@ $< + +-%.o: %.c Makefile | $(COMMON_SRC) ++%.o: %.c Makefile | $(COMMON_SRC) $(LIBFDT_SRC) + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c -o $@ $< + + model.lds: $(LD_SCRIPT) Makefile diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0013-platform-Add-print_hex-func.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0013-platform-Add-print_hex-func.patch new file mode 100644 index 0000000..7d643ff --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0013-platform-Add-print_hex-func.patch @@ -0,0 +1,67 @@ +From 5b8cb5192dbd0332e027e8999c3afe4433983291 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Wed, 29 Dec 2021 10:50:21 +0800 +Subject: [PATCH] platform: Add print_hex func + +Refine the print functions, and add a new print_hex func to print hex +numbers. + +Issue-Id: SCM-3814 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Jaxson Han +Change-Id: Ic960345d9ef0b41d81d30c4a4dbd9c31139907c4 +--- + common/platform.c | 33 +++++++++++++++++++++++++-------- + 1 file changed, 25 insertions(+), 8 deletions(-) + +diff --git a/common/platform.c b/common/platform.c +index d11f568..8269392 100644 +--- a/common/platform.c ++++ b/common/platform.c +@@ -30,20 +30,37 @@ + #define V2M_SYS(reg) ((void *)SYSREGS_BASE + V2M_SYS_##reg) + #endif + +-static void print_string(const char *str) ++static void print_char(const char c) + { + uint32_t flags; ++ do { ++ flags = raw_readl(PL011(UARTFR)); ++ } while (flags & PL011_UARTFR_FIFO_FULL); + ++ raw_writel(c, PL011(UARTDR)); ++ ++ do { ++ flags = raw_readl(PL011(UARTFR)); ++ } while (flags & PL011_UARTFR_BUSY); ++} ++ ++void print_string(const char *str) ++{ + while (*str) { +- do +- flags = raw_readl(PL011(UARTFR)); +- while (flags & PL011_UARTFR_FIFO_FULL); ++ print_char(*str++); ++ } ++} + +- raw_writel(*str++, PL011(UARTDR)); ++#define HEX_CHARS_PER_INT (2 * sizeof(int)) ++ ++void print_hex(unsigned int val) ++{ + +- do +- flags = raw_readl(PL011(UARTFR)); +- while (flags & PL011_UARTFR_BUSY); ++ const char hex_chars[16] = "0123456789abcdef"; ++ int i; ++ for (i = HEX_CHARS_PER_INT - 1; i >= 0; i--) { ++ int v = (val >> (4 * i)) & 0xf; ++ print_char(hex_chars[v]); + } + } + diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0014-common-Add-mem-usage-to-memreserve.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0014-common-Add-mem-usage-to-memreserve.patch new file mode 100644 index 0000000..f5263d2 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0014-common-Add-mem-usage-to-memreserve.patch @@ -0,0 +1,96 @@ +From b447242cd2457bec20d47fe6a8a5758d97a3bde3 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Wed, 19 Jan 2022 16:19:02 +0800 +Subject: [PATCH] common: Add mem usage to /memreserve/ + +Set /memreserve/ to prevent next boot stages from overrding PSCI +services with libfdt. + +Issue-Id: SCM-3815 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Jaxson Han +Change-Id: I2ea80cdf736a910fa2c3deb622e21d50f04be960 +--- + Makefile.am | 2 +- + common/boot.c | 1 + + common/device_tree.c | 34 ++++++++++++++++++++++++++++++++++ + include/boot.h | 1 + + 4 files changed, 37 insertions(+), 1 deletion(-) + create mode 100644 common/device_tree.c + +diff --git a/Makefile.am b/Makefile.am +index 5e8668a..734de92 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -34,7 +34,7 @@ endif + PSCI_CPU_OFF := 0x84000002 + + COMMON_SRC := common/ +-COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o ++COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o device_tree.o + + LIBFDT_SRC := common/libfdt/ + LIBFDT_OBJS := fdt.o fdt_ro.o fdt_rw.o +diff --git a/common/boot.c b/common/boot.c +index c74d34c..ee2bea0 100644 +--- a/common/boot.c ++++ b/common/boot.c +@@ -63,6 +63,7 @@ void __noreturn first_spin(unsigned int cpu, unsigned long *mbox, + { + if (cpu == 0) { + init_platform(); ++ dt_add_memreserve(); + + *mbox = (unsigned long)&entrypoint; + sevl(); +diff --git a/common/device_tree.c b/common/device_tree.c +new file mode 100644 +index 0000000..4d0876c +--- /dev/null ++++ b/common/device_tree.c +@@ -0,0 +1,34 @@ ++/* ++ * device_tree.c - Basic device tree node handler ++ * ++ * Copyright (C) 2021 ARM Limited. All rights reserved. ++ * ++ * Use of this source code is governed by a BSD-style license that can be ++ * found in the LICENSE.txt file. ++ */ ++#include ++ ++extern unsigned long dtb; ++extern char firmware_start[], firmware_end[]; ++ ++extern void print_string(const char *str); ++ ++static void *blob; ++ ++ ++void dt_add_memreserve(void) ++{ ++ int ret; ++ ++ blob = (void*)&dtb; ++ print_string("Add /memreserve/\n\r"); ++ ++ fdt_open_into(blob, blob, fdt_totalsize(blob) + ++ sizeof(struct fdt_reserve_entry)); ++ ret = fdt_add_mem_rsv(blob, (uint64_t)firmware_start, ++ (uint64_t)(firmware_end - firmware_start)); ++ ++ if(ret < 0) { ++ print_string("reserve mem add err\n\r"); ++ } ++} +diff --git a/include/boot.h b/include/boot.h +index d75e013..c3e2ec1 100644 +--- a/include/boot.h ++++ b/include/boot.h +@@ -16,4 +16,5 @@ void __noreturn spin(unsigned long *mbox, unsigned long invalid, int is_entry); + void __noreturn first_spin(unsigned int cpu, unsigned long *mbox, + unsigned long invalid_addr); + ++void dt_add_memreserve(void); + #endif diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0015-boot-Add-the-enable-keep-el-compile-option.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0015-boot-Add-the-enable-keep-el-compile-option.patch new file mode 100644 index 0000000..6c708e9 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0015-boot-Add-the-enable-keep-el-compile-option.patch @@ -0,0 +1,102 @@ +From 8271c21bcff260295203214b7b8c87cdb8236453 Mon Sep 17 00:00:00 2001 +From: Jaxson Han +Date: Tue, 4 Jan 2022 17:01:55 +0800 +Subject: [PATCH] boot: Add the --enable-keep-el compile option + +Add --enable-keep-el compile option to enable boot-wrapper booting next +stage at EL2. +The Armv8R AArch64 boots at EL2. If the next stage requires EL2 booting, +the boot-wrapper should not drop to EL1. +Currently, this option only works for Armv8R AArch64. Also, to work with +Linux PSCI, this option will cause secondary cores booting at EL1. + +Issue-Id: SCM-3813 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Jaxson Han +Change-Id: I3ba9c87cf0b59d163ca433f74c9e3a46e5ca2c63 +--- + Makefile.am | 4 ++++ + arch/aarch64/boot.S | 6 +++++- + common/psci.c | 6 ++++++ + configure.ac | 5 +++++ + 4 files changed, 20 insertions(+), 1 deletion(-) + +diff --git a/Makefile.am b/Makefile.am +index 734de92..054becd 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -33,6 +33,10 @@ PSCI_CPU_ON := 0xc4000003 + endif + PSCI_CPU_OFF := 0x84000002 + ++if KEEP_EL ++DEFINES += -DKEEP_EL ++endif ++ + COMMON_SRC := common/ + COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o device_tree.o + +diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S +index 6dbd5cc..157c097 100644 +--- a/arch/aarch64/boot.S ++++ b/arch/aarch64/boot.S +@@ -233,7 +233,11 @@ el2_init: + msr cnthctl_el2, x0 + isb + ++#ifdef KEEP_EL ++ mov w0, #SPSR_KERNEL ++#else + mov w0, #SPSR_KERNEL_EL1 ++#endif + ldr x1, =spsr_to_elx + str w0, [x1] + // fall through +@@ -313,5 +317,5 @@ ASM_FUNC(jump_kernel) + .align 3 + flag_keep_el: + .long 0 +-spsr_to_elx: ++ASM_DATA(spsr_to_elx) + .long 0 +diff --git a/common/psci.c b/common/psci.c +index a0e8700..945780b 100644 +--- a/common/psci.c ++++ b/common/psci.c +@@ -18,6 +18,8 @@ + #error "No MPIDRs provided" + #endif + ++extern unsigned int spsr_to_elx; ++ + static unsigned long branch_table[NR_CPUS]; + + bakery_ticket_t branch_table_lock[NR_CPUS]; +@@ -44,6 +46,10 @@ static int psci_cpu_on(unsigned long target_mpidr, unsigned long address) + ret = psci_store_address(cpu, address); + bakery_unlock(branch_table_lock, this_cpu); + ++#ifdef KEEP_EL ++ spsr_to_elx = SPSR_KERNEL_EL1; ++#endif ++ + return ret; + } + +diff --git a/configure.ac b/configure.ac +index 53e51be..0e07db3 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -25,6 +25,11 @@ AS_IF([test "x$BOOTWRAPPER_ES" = x32 -a "x$KERNEL_ES" != x32], + [AC_MSG_ERROR([a 32-bit boot-wrapper cannot launch a 64-bit kernel])] + ) + ++AC_ARG_ENABLE([keep-el], ++ AC_HELP_STRING([--enable-keep-el], [keep exception level when start kernel]), ++ [KEEP_EL=yes], [KEEP_EL=no]) ++AM_CONDITIONAL([KEEP_EL], [test "x$KEEP_EL" = xyes]) ++ + # Allow a user to pass --with-kernel-dir + AC_ARG_WITH([kernel-dir], + AS_HELP_STRING([--with-kernel-dir], [specify the root Linux kernel build directory (required)]), diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0016-Makefile-Change-COUNTER_FREQ-to-100-MHz.patch b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0016-Makefile-Change-COUNTER_FREQ-to-100-MHz.patch new file mode 100644 index 0000000..a6b16e4 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/files/fvp-baser-aemv8r64/0016-Makefile-Change-COUNTER_FREQ-to-100-MHz.patch @@ -0,0 +1,34 @@ +From dd3e3f414d0e6ed1643c2e2ccac676b7fc1dc7a9 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Tue, 1 Feb 2022 11:28:46 +0000 +Subject: [PATCH] Makefile: Change COUNTER_FREQ to 100 MHz + +Older Arm Fast Models (AEM < RevC) had a base frequency of 24 MHz. but +the RevC base models use 100 MHz. There is not a robust method of +determining the configured base frequency at runtime, so update +COUNTER_FREQ to be 100 MHz. + +Issue-Id: SCM-3871 +Upstream-Status: Pending +Signed-off-by: Peter Hoyes +Change-Id: Ia9ad0f8ee488d1a887791f1fa1d8f3bf9c5887fd +--- + Makefile.am | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile.am b/Makefile.am +index 40bc5d6..b48173c 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -13,7 +13,7 @@ SCRIPT_DIR := $(top_srcdir)/scripts + PHYS_OFFSET := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findmem.pl $(KERNEL_DTB)) + UART_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,pl011') + SYSREGS_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,vexpress-sysreg' 2> /dev/null) +-COUNTER_FREQ := 24000000 ++COUNTER_FREQ := 100000000 + + CPU_IDS := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findcpuids.pl $(KERNEL_DTB)) + NR_CPUS := $(shell echo $(CPU_IDS) | tr ',' ' ' | wc -w) +-- +2.25.1 + From patchwork Thu Feb 24 11:22:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 4216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA363C43219 for ; Thu, 24 Feb 2022 11:24:03 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.9085.1645701842498711355 for ; Thu, 24 Feb 2022 03:24:02 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 23081106F; Thu, 24 Feb 2022 03:24:02 -0800 (PST) Received: from e125920.cambridge.arm.com (unknown [10.1.199.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 87A3E3F70D; Thu, 24 Feb 2022 03:24:01 -0800 (PST) From: Peter Hoyes To: meta-arm@lists.yoctoproject.org Cc: diego.sueiro@arm.com, Peter Hoyes Subject: [PATCH honister 4/8] arm-bsp/u-boot: Add U-Boot for fvp-baser-aemv8r64 Date: Thu, 24 Feb 2022 11:22:40 +0000 Message-Id: <20220224112244.1521611-5-peter.hoyes@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224112244.1521611-1-peter.hoyes@arm.com> References: <20220224112244.1521611-1-peter.hoyes@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 24 Feb 2022 11:24:03 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/meta-arm/message/3052 From: Peter Hoyes This patch introduces U-Boot into the fvp-baser-aemv8r64 boot flow, providing EFI services. The fvp-baser-aemv8r64 does not have an EL3, so the system starts at S-EL2. For now, U-Boot is running at S-EL2, alongside boot-wrapper. Enable the --enable-keep-el option in boot-wrapper-aarch64 so that it boots the next stage (U-Boot) at S-EL2. Additionally, tell boot-wrapper-aarch64 to bundle U-Boot instead of the kernel. Linux only supports booting from S-EL1 on the fvp-baser-aemv8r64, so U-Boot is configured with CONFIG_SWITCH_TO_EL1, so that booti or bootefi switch to S-EL1 before booting the EFI payload (unless an enviornment variable - armv8_switch_to_el1 - is set to 'n'). Add patches to U-Boot, which: * Backports 53b40e8d54fcdb834e10e6538084517524b8401b, to disable pointer authentication traps. * Add board support for the fvp-baser-aemv8r64 (with a memory map which is inverted from the fvp-base). * Enable the configuration of U-Boot using the device tree passed from boot-wrapper-aarch64. * Enable virtio-net. * Disable setting the exception vectors at S-EL2 so that the PSCI vectors pass through to Linux. * Set up system registers at S-EL2 for Linux. * Configure the S-EL2 MPU for the EFI services. * Allows bootefi to switch to EL1 before booting Linux. Issue-Id: SCM-3871 Signed-off-by: Peter Hoyes Change-Id: I229d14b0717df412c1fe33772230ca779f79b32d --- .../conf/machine/fvp-baser-aemv8r64.conf | 6 +- ...oot-wrapper-aarch64-fvp-baser-aemv8r64.inc | 5 +- ...pointer-authentication-traps-for-EL1.patch | 126 ++++++++ ...ation-for-the-Arm-VExpress64-board-c.patch | 109 +++++++ ...tor-header-file-to-make-it-easier-to.patch | 173 +++++++++++ ...Clean-up-BASE_FVP-boot-configuration.patch | 99 +++++++ ...e-OF_CONTROL-and-OF_BOARD-for-VExpre.patch | 106 +++++++ ...s64-Enable-VIRTIO_NET-network-driver.patch | 62 ++++ ...v8-Add-ARMv8-MPU-configuration-logic.patch | 259 +++++++++++++++++ ...bling-exception-vectors-on-non-SPL-b.patch | 98 +++++++ ...mv8-ARMV8_SWITCH_TO_EL1-improvements.patch | 163 +++++++++++ ...ling-HVC-configurable-when-switching.patch | 73 +++++ ...press64-Do-not-set-COUNTER_FREQUENCY.patch | 37 +++ ...Add-BASER_FVP-vexpress-board-variant.patch | 275 ++++++++++++++++++ .../recipes-bsp/u-boot/u-boot_%.bbappend | 18 ++ 15 files changed, 1607 insertions(+), 2 deletions(-) create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0001-armv8-Disable-pointer-authentication-traps-for-EL1.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0002-doc-Add-documentation-for-the-Arm-VExpress64-board-c.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0003-vexpress64-Refactor-header-file-to-make-it-easier-to.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0004-vexpress64-Clean-up-BASE_FVP-boot-configuration.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0005-vexpress64-Enable-OF_CONTROL-and-OF_BOARD-for-VExpre.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0006-vexpress64-Enable-VIRTIO_NET-network-driver.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0007-armv8-Add-ARMv8-MPU-configuration-logic.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0008-armv8-Allow-disabling-exception-vectors-on-non-SPL-b.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0009-armv8-ARMV8_SWITCH_TO_EL1-improvements.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0010-armv8-Make-disabling-HVC-configurable-when-switching.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0011-vexpress64-Do-not-set-COUNTER_FREQUENCY.patch create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0012-vexpress64-Add-BASER_FVP-vexpress-board-variant.patch diff --git a/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf b/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf index 2d63be5..c190e4c 100644 --- a/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf +++ b/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf @@ -15,10 +15,14 @@ PREFERRED_VERSION_linux-yocto-rt ?= "5.14%" KERNEL_IMAGETYPE = "Image" KERNEL_DEVICETREE = "arm/fvp-baser-aemv8r64.dtb" +UBOOT_MACHINE ?= "vexpress_aemv8r_defconfig" + SERIAL_CONSOLES = "115200;ttyAMA0" IMAGE_FSTYPES += "wic" -WKS_FILE ?= "fvp-base.wks" +WKS_FILE ?= "efi-disk.wks.in" +EFI_PROVIDER ?= "grub-efi" +MACHINE_FEATURES:append = " efi" # As this is a virtual target that will not be used in the real world there is # no need for real SSH keys. Disable rng-tools (which takes too long to diff --git a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64-fvp-baser-aemv8r64.inc b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64-fvp-baser-aemv8r64.inc index 628571f..6bc7385 100644 --- a/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64-fvp-baser-aemv8r64.inc +++ b/meta-arm-bsp/recipes-bsp/boot-wrapper-aarch64/boot-wrapper-aarch64-fvp-baser-aemv8r64.inc @@ -23,6 +23,9 @@ SRC_URI:append = " \ BOOT_WRAPPER_AARCH64_CMDLINE = "\ earlycon console=ttyAMA0 loglevel=8 rootfstype=ext4 root=/dev/vda1 rw" -EXTRA_OECONF += "--enable-psci=hvc" +EXTRA_OECONF += "--enable-psci=hvc --enable-keep-el" TUNE_CCARGS = "" + +BOOT_WRAPPER_AARCH64_KERNEL = "u-boot.bin" +do_deploy[depends] += "u-boot:do_deploy" diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0001-armv8-Disable-pointer-authentication-traps-for-EL1.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0001-armv8-Disable-pointer-authentication-traps-for-EL1.patch new file mode 100644 index 0000000..fd2b6ae --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0001-armv8-Disable-pointer-authentication-traps-for-EL1.patch @@ -0,0 +1,126 @@ +From 0b1b542cbc1d159e57eef0656133bb233451d23d Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Thu, 19 Aug 2021 16:53:09 +0100 +Subject: [PATCH 01/12] armv8: Disable pointer authentication traps for EL1 + +The use of ARMv8.3 pointer authentication (PAuth) is governed by fields +in HCR_EL2, which trigger a 'trap to EL2' if not enabled. The reset +value of these fields is 'architecturally unknown' so we must ensure +that the fields are enabled (to disable the traps) if we are entering +the kernel at EL1. + +The APK field disables PAuth instruction traps and the API field +disables PAuth register traps + +Add code to disable the traps in armv8_switch_to_el1_m. Prior to doing +so, it checks fields in the ID_AA64ISAR1_EL1 register to ensure pointer +authentication is supported by the hardware. + +The runtime checks require a second temporary register, so add this to +the EL1 transition macro signature and update 2 call sites. + +Issue-Id: SCM-2443 +Signed-off-by: Peter Hoyes +Upstream-Status: Backport [https://source.denx.de/u-boot/u-boot/-/commit/53b40e8d54fcdb834e10e6538084517524b8401b] +Change-Id: I12159c327a2cca006b973a08fe414f73314e7eb1 +--- + arch/arm/cpu/armv8/fsl-layerscape/spintable.S | 2 +- + arch/arm/cpu/armv8/transition.S | 2 +- + arch/arm/include/asm/macro.h | 11 ++++++++-- + arch/arm/include/asm/system.h | 21 +++++++++++++++++++ + 4 files changed, 32 insertions(+), 4 deletions(-) + +diff --git a/arch/arm/cpu/armv8/fsl-layerscape/spintable.S b/arch/arm/cpu/armv8/fsl-layerscape/spintable.S +index 363ded03e6..d6bd188459 100644 +--- a/arch/arm/cpu/armv8/fsl-layerscape/spintable.S ++++ b/arch/arm/cpu/armv8/fsl-layerscape/spintable.S +@@ -93,7 +93,7 @@ __secondary_boot_func: + 4: + #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + switch_el x7, _dead_loop, 0f, _dead_loop +-0: armv8_switch_to_el1_m x4, x6, x7 ++0: armv8_switch_to_el1_m x4, x6, x7, x9 + #else + switch_el x7, 0f, _dead_loop, _dead_loop + 0: armv8_switch_to_el2_m x4, x6, x7 +diff --git a/arch/arm/cpu/armv8/transition.S b/arch/arm/cpu/armv8/transition.S +index a31af4ffc8..9dbdff3a4f 100644 +--- a/arch/arm/cpu/armv8/transition.S ++++ b/arch/arm/cpu/armv8/transition.S +@@ -40,7 +40,7 @@ ENTRY(armv8_switch_to_el1) + * now, jump to the address saved in x4. + */ + br x4 +-1: armv8_switch_to_el1_m x4, x5, x6 ++1: armv8_switch_to_el1_m x4, x5, x6, x7 + ENDPROC(armv8_switch_to_el1) + .popsection + +diff --git a/arch/arm/include/asm/macro.h b/arch/arm/include/asm/macro.h +index bb33b4bc89..5ee72d0e78 100644 +--- a/arch/arm/include/asm/macro.h ++++ b/arch/arm/include/asm/macro.h +@@ -238,7 +238,7 @@ lr .req x30 + * For loading 64-bit OS, x0 is physical address to the FDT blob. + * They will be passed to the guest. + */ +-.macro armv8_switch_to_el1_m, ep, flag, tmp ++.macro armv8_switch_to_el1_m, ep, flag, tmp, tmp2 + /* Initialize Generic Timers */ + mrs \tmp, cnthctl_el2 + /* Enable EL1 access to timers */ +@@ -288,7 +288,14 @@ lr .req x30 + b.eq 1f + + /* Initialize HCR_EL2 */ +- ldr \tmp, =(HCR_EL2_RW_AARCH64 | HCR_EL2_HCD_DIS) ++ /* Only disable PAuth traps if PAuth is supported */ ++ mrs \tmp, id_aa64isar1_el1 ++ ldr \tmp2, =(ID_AA64ISAR1_EL1_GPI | ID_AA64ISAR1_EL1_GPA | \ ++ ID_AA64ISAR1_EL1_API | ID_AA64ISAR1_EL1_APA) ++ tst \tmp, \tmp2 ++ mov \tmp2, #(HCR_EL2_RW_AARCH64 | HCR_EL2_HCD_DIS) ++ orr \tmp, \tmp2, #(HCR_EL2_APK | HCR_EL2_API) ++ csel \tmp, \tmp2, \tmp, eq + msr hcr_el2, \tmp + + /* Return to the EL1_SP1 mode from EL2 */ +diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h +index 11fceec4d2..77aa18909e 100644 +--- a/arch/arm/include/asm/system.h ++++ b/arch/arm/include/asm/system.h +@@ -75,10 +75,31 @@ + /* + * HCR_EL2 bits definitions + */ ++#define HCR_EL2_API (1 << 41) /* Trap pointer authentication ++ instructions */ ++#define HCR_EL2_APK (1 << 40) /* Trap pointer authentication ++ key access */ + #define HCR_EL2_RW_AARCH64 (1 << 31) /* EL1 is AArch64 */ + #define HCR_EL2_RW_AARCH32 (0 << 31) /* Lower levels are AArch32 */ + #define HCR_EL2_HCD_DIS (1 << 29) /* Hypervisor Call disabled */ + ++/* ++ * ID_AA64ISAR1_EL1 bits definitions ++ */ ++#define ID_AA64ISAR1_EL1_GPI (0xF << 28) /* Implementation-defined generic ++ code auth algorithm */ ++#define ID_AA64ISAR1_EL1_GPA (0xF << 24) /* QARMA generic code auth ++ algorithm */ ++#define ID_AA64ISAR1_EL1_API (0xF << 8) /* Implementation-defined address ++ auth algorithm */ ++#define ID_AA64ISAR1_EL1_APA (0xF << 4) /* QARMA address auth algorithm */ ++ ++/* ++ * ID_AA64PFR0_EL1 bits definitions ++ */ ++#define ID_AA64PFR0_EL1_EL3 (0xF << 12) /* EL3 implemented */ ++#define ID_AA64PFR0_EL1_EL2 (0xF << 8) /* EL2 implemented */ ++ + /* + * CPACR_EL1 bits definitions + */ +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0002-doc-Add-documentation-for-the-Arm-VExpress64-board-c.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0002-doc-Add-documentation-for-the-Arm-VExpress64-board-c.patch new file mode 100644 index 0000000..66f915a --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0002-doc-Add-documentation-for-the-Arm-VExpress64-board-c.patch @@ -0,0 +1,109 @@ +From b76b9a4388f921359046c3d59748b06a2ffa99ce Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Tue, 19 Oct 2021 15:47:21 +0100 +Subject: [PATCH 02/12] doc: Add documentation for the Arm VExpress64 board + configs + +Create a new documentation section for Arm Ltd boards with a sub-page +for the VExpress64 boards (FVP-A and Juno). + +Issue-Id: SCM-3533 +Upstream-Status: Backport [https://source.denx.de/u-boot/u-boot/-/commit/6c2f16b3c95a0bb7f5d6f65512dceb0dc75ac00a] +Signed-off-by: Peter Hoyes +Change-Id: I9e6244e9c4949c0a60acb32216fb71e933af40ed +--- + doc/board/armltd/index.rst | 9 ++++++ + doc/board/armltd/vexpress64.rst | 51 +++++++++++++++++++++++++++++++++ + doc/board/index.rst | 1 + + 3 files changed, 61 insertions(+) + create mode 100644 doc/board/armltd/index.rst + create mode 100644 doc/board/armltd/vexpress64.rst + +diff --git a/doc/board/armltd/index.rst b/doc/board/armltd/index.rst +new file mode 100644 +index 0000000000..b6786c114f +--- /dev/null ++++ b/doc/board/armltd/index.rst +@@ -0,0 +1,9 @@ ++.. SPDX-License-Identifier: GPL-2.0+ ++ ++Arm Ltd ++============= ++ ++.. toctree:: ++ :maxdepth: 2 ++ ++ vexpress64.rst +diff --git a/doc/board/armltd/vexpress64.rst b/doc/board/armltd/vexpress64.rst +new file mode 100644 +index 0000000000..b98b096544 +--- /dev/null ++++ b/doc/board/armltd/vexpress64.rst +@@ -0,0 +1,51 @@ ++.. SPDX-License-Identifier: GPL-2.0+ ++ ++Arm Versatile Express ++===================== ++ ++The vexpress_* board configuration supports the following platforms: ++ ++ * FVP_Base_RevC-2xAEMvA ++ * Juno development board ++ ++Fixed Virtual Platforms ++----------------------- ++ ++The Fixed Virtual Platforms (FVP) are complete simulations of an Arm system, ++including processor, memory and peripherals. They are set out in a "programmer's ++view", which gives a comprehensive model on which to build and test software. ++ ++The supported FVPs are available free of charge and can be downloaded from the ++Arm developer site [1]_ (user registration might be required). ++ ++Supported features: ++ ++ * GICv3 ++ * Generic timer ++ * PL011 UART ++ ++The default configuration assumes that U-Boot is bootstrapped using a suitable ++bootloader, such as Trusted Firmware-A [4]_. The u-boot binary can be passed ++into the TF-A build: ``make PLAT= all fip BL33=u-boot.bin`` ++ ++The FVPs can be debugged using Arm Development Studio [2]_. ++ ++Juno ++---- ++ ++Juno is an Arm development board with the following features: ++ ++ * Arm Cortex-A72/A57 and Arm Cortex-A53 in a "big.LITTLE" configuration ++ * A PCIe Gen2.0 bus with 4 lanes ++ * 8GB of DRAM ++ * GICv2 ++ ++More details can be found in the board documentation [3]_. ++ ++References ++---------- ++ ++.. [1] https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms ++.. [2] https://developer.arm.com/tools-and-software/embedded/arm-development-studio ++.. [3] https://developer.arm.com/tools-and-software/development-boards/juno-development-board ++.. [4] https://trustedfirmware-a.readthedocs.io/ +\ No newline at end of file +diff --git a/doc/board/index.rst b/doc/board/index.rst +index 747511f7dd..5c08de16b0 100644 +--- a/doc/board/index.rst ++++ b/doc/board/index.rst +@@ -10,6 +10,7 @@ Board-specific doc + advantech/index + AndesTech/index + amlogic/index ++ armltd/index + atmel/index + congatec/index + coreboot/index +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0003-vexpress64-Refactor-header-file-to-make-it-easier-to.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0003-vexpress64-Refactor-header-file-to-make-it-easier-to.patch new file mode 100644 index 0000000..b7a6a57 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0003-vexpress64-Refactor-header-file-to-make-it-easier-to.patch @@ -0,0 +1,173 @@ +From 14bd61e78264812edea18c442db99bb83c5f93c0 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Tue, 19 Oct 2021 15:39:52 +0100 +Subject: [PATCH 03/12] vexpress64: Refactor header file to make it easier to + add new FVPs + +Rename from vexpress_aemv8a.h -> vepxress_aemv8.h as new FVPs may not be +v8-A. No change in behavior. + +This is towards future work to enable support for the FVP_BaseR. + +Issue-Id: SCM-3537 +Upstream-Status: Backport [https://source.denx.de/u-boot/u-boot/-/commit/17fe55fd6fe9d32270380f574b33ff0bc15bb47e] +Signed-off-by: Peter Hoyes +Change-Id: Ie992e69d1b51c6f8939b1bea22e35658e96df6c6 +--- + board/armltd/vexpress64/Kconfig | 2 +- + doc/README.semihosting | 2 +- + .../{vexpress_aemv8a.h => vexpress_aemv8.h} | 48 ++++++++++--------- + 3 files changed, 27 insertions(+), 25 deletions(-) + rename include/configs/{vexpress_aemv8a.h => vexpress_aemv8.h} (88%) + +diff --git a/board/armltd/vexpress64/Kconfig b/board/armltd/vexpress64/Kconfig +index 1d13f542e6..4aab3f092e 100644 +--- a/board/armltd/vexpress64/Kconfig ++++ b/board/armltd/vexpress64/Kconfig +@@ -7,7 +7,7 @@ config SYS_VENDOR + default "armltd" + + config SYS_CONFIG_NAME +- default "vexpress_aemv8a" ++ default "vexpress_aemv8" + + config JUNO_DTB_PART + string "NOR flash partition holding DTB" +diff --git a/doc/README.semihosting b/doc/README.semihosting +index c019999bed..f382d0131e 100644 +--- a/doc/README.semihosting ++++ b/doc/README.semihosting +@@ -25,7 +25,7 @@ or turning on CONFIG_BASE_FVP for the more full featured model. + Rather than create a new armv8 board similar to armltd/vexpress64, add + semihosting calls to the existing one, enabled with CONFIG_SEMIHOSTING + and CONFIG_BASE_FVP both set. Also reuse the existing board config file +-vexpress_aemv8a.h but differentiate the two models by the presence or ++vexpress_aemv8.h but differentiate the two models by the presence or + absence of CONFIG_BASE_FVP. This change is tested and works on both the + Foundation and Base fastmodel simulators. + +diff --git a/include/configs/vexpress_aemv8a.h b/include/configs/vexpress_aemv8.h +similarity index 88% +rename from include/configs/vexpress_aemv8a.h +rename to include/configs/vexpress_aemv8.h +index 7318fb6c58..38141fe023 100644 +--- a/include/configs/vexpress_aemv8a.h ++++ b/include/configs/vexpress_aemv8.h +@@ -4,36 +4,37 @@ + * configurations. + */ + +-#ifndef __VEXPRESS_AEMV8A_H +-#define __VEXPRESS_AEMV8A_H ++#ifndef __VEXPRESS_AEMV8_H ++#define __VEXPRESS_AEMV8_H + + #define CONFIG_REMAKE_ELF + + /* Link Definitions */ +-#ifdef CONFIG_TARGET_VEXPRESS64_BASE_FVP ++#ifdef CONFIG_TARGET_VEXPRESS64_JUNO ++#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x7fff0) ++#else + /* ATF loads u-boot here for BASE_FVP model */ + #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x03f00000) +-#elif CONFIG_TARGET_VEXPRESS64_JUNO +-#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x7fff0) + #endif + + #define CONFIG_SYS_BOOTM_LEN (64 << 20) /* Increase max gunzip size */ + + /* CS register bases for the original memory map. */ +-#define V2M_PA_CS0 0x00000000 +-#define V2M_PA_CS1 0x14000000 +-#define V2M_PA_CS2 0x18000000 +-#define V2M_PA_CS3 0x1c000000 +-#define V2M_PA_CS4 0x0c000000 +-#define V2M_PA_CS5 0x10000000 ++#define V2M_BASE 0x80000000 ++#define V2M_PA_BASE 0x00000000 ++ ++#define V2M_PA_CS0 (V2M_PA_BASE + 0x00000000) ++#define V2M_PA_CS1 (V2M_PA_BASE + 0x14000000) ++#define V2M_PA_CS2 (V2M_PA_BASE + 0x18000000) ++#define V2M_PA_CS3 (V2M_PA_BASE + 0x1c000000) ++#define V2M_PA_CS4 (V2M_PA_BASE + 0x0c000000) ++#define V2M_PA_CS5 (V2M_PA_BASE + 0x10000000) + + #define V2M_PERIPH_OFFSET(x) (x << 16) + #define V2M_SYSREGS (V2M_PA_CS3 + V2M_PERIPH_OFFSET(1)) + #define V2M_SYSCTL (V2M_PA_CS3 + V2M_PERIPH_OFFSET(2)) + #define V2M_SERIAL_BUS_PCI (V2M_PA_CS3 + V2M_PERIPH_OFFSET(3)) + +-#define V2M_BASE 0x80000000 +- + /* Common peripherals relative to CS7. */ + #define V2M_AACI (V2M_PA_CS3 + V2M_PERIPH_OFFSET(4)) + #define V2M_MMCI (V2M_PA_CS3 + V2M_PERIPH_OFFSET(5)) +@@ -72,16 +73,16 @@ + + /* Generic Interrupt Controller Definitions */ + #ifdef CONFIG_GICV3 +-#define GICD_BASE (0x2f000000) +-#define GICR_BASE (0x2f100000) ++#define GICD_BASE (V2M_PA_BASE + 0x2f000000) ++#define GICR_BASE (V2M_PA_BASE + 0x2f100000) + #else + +-#ifdef CONFIG_TARGET_VEXPRESS64_BASE_FVP +-#define GICD_BASE (0x2f000000) +-#define GICC_BASE (0x2c000000) +-#elif CONFIG_TARGET_VEXPRESS64_JUNO ++#ifdef CONFIG_TARGET_VEXPRESS64_JUNO + #define GICD_BASE (0x2C010000) + #define GICC_BASE (0x2C02f000) ++#else ++#define GICD_BASE (V2M_PA_BASE + 0x2f000000) ++#define GICC_BASE (V2M_PA_BASE + 0x2c000000) + #endif + #endif /* !CONFIG_GICV3 */ + +@@ -91,7 +92,7 @@ + #ifndef CONFIG_TARGET_VEXPRESS64_JUNO + /* The Vexpress64 simulators use SMSC91C111 */ + #define CONFIG_SMC91111 1 +-#define CONFIG_SMC91111_BASE (0x01A000000) ++#define CONFIG_SMC91111_BASE (V2M_PA_BASE + 0x01A000000) + #endif + + /* PL011 Serial Configuration */ +@@ -117,7 +118,7 @@ + #ifdef CONFIG_TARGET_VEXPRESS64_JUNO + #define PHYS_SDRAM_2 (0x880000000) + #define PHYS_SDRAM_2_SIZE 0x180000000 +-#elif CONFIG_TARGET_VEXPRESS64_BASE_FVP && CONFIG_NR_DRAM_BANKS == 2 ++#elif CONFIG_NR_DRAM_BANKS == 2 + #define PHYS_SDRAM_2 (0x880000000) + #define PHYS_SDRAM_2_SIZE 0x80000000 + #endif +@@ -194,6 +195,7 @@ + " booti $kernel_addr - $fdt_addr; " \ + "fi" + #endif ++ + #endif + + /* Monitor Command Prompt */ +@@ -207,7 +209,7 @@ + /* Store environment at top of flash in the same location as blank.img */ + /* in the Juno firmware. */ + #else +-#define CONFIG_SYS_FLASH_BASE 0x0C000000 ++#define CONFIG_SYS_FLASH_BASE (V2M_PA_BASE + 0x0C000000) + /* 256 x 256KiB sectors */ + #define CONFIG_SYS_MAX_FLASH_SECT 256 + /* Store environment at top of flash */ +@@ -224,4 +226,4 @@ + #define CONFIG_SYS_FLASH_EMPTY_INFO /* flinfo indicates empty blocks */ + #define FLASH_MAX_SECTOR_SIZE 0x00040000 + +-#endif /* __VEXPRESS_AEMV8A_H */ ++#endif /* __VEXPRESS_AEMV8_H */ +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0004-vexpress64-Clean-up-BASE_FVP-boot-configuration.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0004-vexpress64-Clean-up-BASE_FVP-boot-configuration.patch new file mode 100644 index 0000000..9e1f6f7 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0004-vexpress64-Clean-up-BASE_FVP-boot-configuration.patch @@ -0,0 +1,99 @@ +From 3615110f3f478a6b3551fa9f9dc54317e6718e7d Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Tue, 19 Oct 2021 16:34:25 +0100 +Subject: [PATCH 04/12] vexpress64: Clean up BASE_FVP boot configuration + +Move env var address values to #defines so they can be reused elsewhere. + +Rename env var names to those recommended in the README. + +Fix issue where fdt is called with invalid arguments when booting +without a ramdisk. + +Issue-Id: SCM-3537 +Upstream-Status: Backport [https://source.denx.de/u-boot/u-boot/-/commit/90f262a6951f530ec60bf78a681b117f625cbe3f] +Signed-off-by: Peter Hoyes +Change-Id: I2cd9a1245860302857b6ad6d738b8f7fc4d4d038 +--- + include/configs/vexpress_aemv8.h | 50 ++++++++++++++++++++------------ + 1 file changed, 31 insertions(+), 19 deletions(-) + +diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h +index 38141fe023..9223eb2207 100644 +--- a/include/configs/vexpress_aemv8.h ++++ b/include/configs/vexpress_aemv8.h +@@ -7,6 +7,8 @@ + #ifndef __VEXPRESS_AEMV8_H + #define __VEXPRESS_AEMV8_H + ++#include ++ + #define CONFIG_REMAKE_ELF + + /* Link Definitions */ +@@ -166,33 +168,43 @@ + + + #elif CONFIG_TARGET_VEXPRESS64_BASE_FVP ++ ++#define VEXPRESS_KERNEL_ADDR 0x80080000 ++#define VEXPRESS_FDT_ADDR 0x8fc00000 ++#define VEXPRESS_BOOT_ADDR 0x8fd00000 ++#define VEXPRESS_RAMDISK_ADDR 0x8fe00000 ++ + #define CONFIG_EXTRA_ENV_SETTINGS \ + "kernel_name=Image\0" \ +- "kernel_addr=0x80080000\0" \ +- "initrd_name=ramdisk.img\0" \ +- "initrd_addr=0x88000000\0" \ +- "fdtfile=devtree.dtb\0" \ +- "fdt_addr=0x83000000\0" \ +- "boot_name=boot.img\0" \ +- "boot_addr=0x8007f800\0" ++ "kernel_addr_r=" __stringify(VEXPRESS_KERNEL_ADDR) "\0" \ ++ "ramdisk_name=ramdisk.img\0" \ ++ "ramdisk_addr_r=" __stringify(VEXPRESS_RAMDISK_ADDR) "\0" \ ++ "fdtfile=devtree.dtb\0" \ ++ "fdt_addr_r=" __stringify(VEXPRESS_FDT_ADDR) "\0" \ ++ "boot_name=boot.img\0" \ ++ "boot_addr_r=" __stringify(VEXPRESS_BOOT_ADDR) "\0" + + #ifndef CONFIG_BOOTCOMMAND +-#define CONFIG_BOOTCOMMAND "if smhload ${boot_name} ${boot_addr}; then " \ ++#define CONFIG_BOOTCOMMAND "if smhload ${boot_name} ${boot_addr_r}; then " \ + " set bootargs; " \ +- " abootimg addr ${boot_addr}; " \ +- " abootimg get dtb --index=0 fdt_addr; " \ +- " bootm ${boot_addr} ${boot_addr} " \ +- " ${fdt_addr}; " \ ++ " abootimg addr ${boot_addr_r}; " \ ++ " abootimg get dtb --index=0 fdt_addr_r; " \ ++ " bootm ${boot_addr_r} ${boot_addr_r} " \ ++ " ${fdt_addr_r}; " \ + "else; " \ + " set fdt_high 0xffffffffffffffff; " \ + " set initrd_high 0xffffffffffffffff; " \ +- " smhload ${kernel_name} ${kernel_addr}; " \ +- " smhload ${fdtfile} ${fdt_addr}; " \ +- " smhload ${initrd_name} ${initrd_addr} "\ +- " initrd_end; " \ +- " fdt addr ${fdt_addr}; fdt resize; " \ +- " fdt chosen ${initrd_addr} ${initrd_end}; " \ +- " booti $kernel_addr - $fdt_addr; " \ ++ " smhload ${kernel_name} ${kernel_addr_r}; " \ ++ " smhload ${fdtfile} ${fdt_addr_r}; " \ ++ " smhload ${ramdisk_name} ${ramdisk_addr_r} "\ ++ " ramdisk_end; " \ ++ " fdt addr ${fdt_addr_r}; fdt resize; " \ ++ " if test -n ${ramdisk_end}; then "\ ++ " fdt chosen ${ramdisk_addr_r} ${ramdisk_end}; " \ ++ " else; " \ ++ " fdt chosen; " \ ++ " fi; " \ ++ " booti $kernel_addr_r - $fdt_addr_r; " \ + "fi" + #endif + +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0005-vexpress64-Enable-OF_CONTROL-and-OF_BOARD-for-VExpre.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0005-vexpress64-Enable-OF_CONTROL-and-OF_BOARD-for-VExpre.patch new file mode 100644 index 0000000..c13e22b --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0005-vexpress64-Enable-OF_CONTROL-and-OF_BOARD-for-VExpre.patch @@ -0,0 +1,106 @@ +From 72fe643b81755a4935c789b2f4f0132ed7eaf8e1 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Mon, 4 Oct 2021 14:03:35 +0100 +Subject: [PATCH 05/12] vexpress64: Enable OF_CONTROL and OF_BOARD for + VExpress64 + +Capture x0 in lowlevel_init.S as potential fdt address. Modify +board_fdt_blob_setup to use fdt address from either vexpress_aemv8.h +or lowlevel_init.S. + +Issue-Id: SCM-3534 +Upstream-Status: Backport [https://source.denx.de/u-boot/u-boot/-/commit/2661397464e47d45cd25bbc5e6b9de7594b3268d] +Signed-off-by: Peter Hoyes +Change-Id: If60e2fbcbda23613f591752ddfabe66fb44623c5 +--- + board/armltd/vexpress64/Makefile | 5 +++++ + board/armltd/vexpress64/lowlevel_init.S | 12 ++++++++++++ + board/armltd/vexpress64/vexpress64.c | 24 ++++++++++++++++++++++++ + 3 files changed, 41 insertions(+) + create mode 100644 board/armltd/vexpress64/lowlevel_init.S + +diff --git a/board/armltd/vexpress64/Makefile b/board/armltd/vexpress64/Makefile +index 868dc4f629..5703e75967 100644 +--- a/board/armltd/vexpress64/Makefile ++++ b/board/armltd/vexpress64/Makefile +@@ -5,3 +5,8 @@ + + obj-y := vexpress64.o + obj-$(CONFIG_TARGET_VEXPRESS64_JUNO) += pcie.o ++ifdef CONFIG_OF_BOARD ++ifndef CONFIG_TARGET_VEXPRESS64_JUNO ++obj-y += lowlevel_init.o ++endif ++endif +diff --git a/board/armltd/vexpress64/lowlevel_init.S b/board/armltd/vexpress64/lowlevel_init.S +new file mode 100644 +index 0000000000..3dcfb85d0e +--- /dev/null ++++ b/board/armltd/vexpress64/lowlevel_init.S +@@ -0,0 +1,12 @@ ++/* SPDX-License-Identifier: GPL-2.0 */ ++/* ++ * (C) Copyright 2021 Arm Limited ++ */ ++ ++.global save_boot_params ++save_boot_params: ++ ++ adr x8, prior_stage_fdt_address ++ str x0, [x8] ++ ++ b save_boot_params_ret +diff --git a/board/armltd/vexpress64/vexpress64.c b/board/armltd/vexpress64/vexpress64.c +index 2e4260286b..b8408e35e5 100644 +--- a/board/armltd/vexpress64/vexpress64.c ++++ b/board/armltd/vexpress64/vexpress64.c +@@ -85,7 +85,15 @@ int dram_init_banksize(void) + return 0; + } + ++/* Assigned in lowlevel_init.S ++ * Push the variable into the .data section so that it ++ * does not get cleared later. ++ */ ++unsigned long __section(".data") prior_stage_fdt_address; ++ + #ifdef CONFIG_OF_BOARD ++ ++#ifdef CONFIG_TARGET_VEXPRESS64_JUNO + #define JUNO_FLASH_SEC_SIZE (256 * 1024) + static phys_addr_t find_dtb_in_nor_flash(const char *partname) + { +@@ -131,14 +139,30 @@ static phys_addr_t find_dtb_in_nor_flash(const char *partname) + return ~0; + } + ++#endif ++ + void *board_fdt_blob_setup(void) + { ++#ifdef CONFIG_TARGET_VEXPRESS64_JUNO + phys_addr_t fdt_rom_addr = find_dtb_in_nor_flash(CONFIG_JUNO_DTB_PART); + + if (fdt_rom_addr == ~0UL) + return NULL; + + return (void *)fdt_rom_addr; ++#endif ++ ++#ifdef VEXPRESS_FDT_ADDR ++ if (fdt_magic(VEXPRESS_FDT_ADDR) == FDT_MAGIC) { ++ return (void *)VEXPRESS_FDT_ADDR; ++ } ++#endif ++ ++ if (fdt_magic(prior_stage_fdt_address) == FDT_MAGIC) { ++ return (void *)prior_stage_fdt_address; ++ } ++ ++ return NULL; + } + #endif + +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0006-vexpress64-Enable-VIRTIO_NET-network-driver.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0006-vexpress64-Enable-VIRTIO_NET-network-driver.patch new file mode 100644 index 0000000..12cef01 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0006-vexpress64-Enable-VIRTIO_NET-network-driver.patch @@ -0,0 +1,62 @@ +From 814420f327e1933594b88c1f4d53ef6ac16d9faa Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Mon, 11 Oct 2021 11:57:26 +0100 +Subject: [PATCH 06/12] vexpress64: Enable VIRTIO_NET network driver + +The SMSC driver is using the old driver model. + +Init the virtio system in vexpress64.c so that the network device is +discovered. + +Issue-Id: SCM-3534 +Upstream-Status: Backport [https://source.denx.de/u-boot/u-boot/-/commit/439581dca4c786dbbdd2d6be024e0b907a3b0c80] +Signed-off-by: Peter Hoyes +Change-Id: I1b7d9eb142bf02dd88e99bcd7e44789a154885dd +--- + board/armltd/vexpress64/vexpress64.c | 7 +++++++ + include/configs/vexpress_aemv8.h | 4 ++-- + 2 files changed, 9 insertions(+), 2 deletions(-) + +diff --git a/board/armltd/vexpress64/vexpress64.c b/board/armltd/vexpress64/vexpress64.c +index b8408e35e5..821f9cfc3b 100644 +--- a/board/armltd/vexpress64/vexpress64.c ++++ b/board/armltd/vexpress64/vexpress64.c +@@ -18,6 +18,10 @@ + #include + #include "pcie.h" + #include ++#ifdef CONFIG_VIRTIO_NET ++#include ++#include ++#endif + + DECLARE_GLOBAL_DATA_PTR; + +@@ -64,6 +68,9 @@ __weak void vexpress64_pcie_init(void) + int board_init(void) + { + vexpress64_pcie_init(); ++#ifdef CONFIG_VIRTIO_NET ++ virtio_init(); ++#endif + return 0; + } + +diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h +index 9223eb2207..68422237dd 100644 +--- a/include/configs/vexpress_aemv8.h ++++ b/include/configs/vexpress_aemv8.h +@@ -91,8 +91,8 @@ + /* Size of malloc() pool */ + #define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + (8 << 20)) + +-#ifndef CONFIG_TARGET_VEXPRESS64_JUNO +-/* The Vexpress64 simulators use SMSC91C111 */ ++#if defined(CONFIG_TARGET_VEXPRESS64_BASE_FVP) && !defined(CONFIG_DM_ETH) ++/* The Vexpress64 BASE_FVP simulator uses SMSC91C111 */ + #define CONFIG_SMC91111 1 + #define CONFIG_SMC91111_BASE (V2M_PA_BASE + 0x01A000000) + #endif +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0007-armv8-Add-ARMv8-MPU-configuration-logic.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0007-armv8-Add-ARMv8-MPU-configuration-logic.patch new file mode 100644 index 0000000..cbe4b16 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0007-armv8-Add-ARMv8-MPU-configuration-logic.patch @@ -0,0 +1,259 @@ +From f8dfb0973b9972a3e65f2efa48fac0b3bb009b29 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Wed, 26 May 2021 17:41:10 +0100 +Subject: [PATCH 07/12] armv8: Add ARMv8 MPU configuration logic + +Detect whether an MMU is present at the current exception level. If +not, initialize the MPU instead of the MMU during init, and clear the +MPU regions before transition to Linux. + +The MSA in use at EL1&0 may be configurable but can only by determined +by inspecting VTCR_EL2 at EL2, so assume that there is an MMU for +backwards compatibility. + +Provide a default (blank) MPU memory map, which can be overridden by +board configurations. + +Issue-Id: SCM-2443 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Peter Hoyes +Change-Id: I0ee3879f9d7f03fe940664b3551c68eeaa458d17 +--- + arch/arm/cpu/armv8/cache_v8.c | 101 ++++++++++++++++++++++++++++++- + arch/arm/include/asm/armv8/mpu.h | 59 ++++++++++++++++++ + arch/arm/include/asm/system.h | 19 ++++++ + 3 files changed, 176 insertions(+), 3 deletions(-) + create mode 100644 arch/arm/include/asm/armv8/mpu.h + +diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c +index 15cecb5e0b..2a49966e8f 100644 +--- a/arch/arm/cpu/armv8/cache_v8.c ++++ b/arch/arm/cpu/armv8/cache_v8.c +@@ -15,6 +15,7 @@ + #include + #include + #include ++#include + + DECLARE_GLOBAL_DATA_PTR; + +@@ -365,6 +366,91 @@ __weak u64 get_page_table_size(void) + return size; + } + ++static void mpu_clear_regions(void) ++{ ++ int i; ++ ++ for (i = 0; mpu_mem_map[i].end || mpu_mem_map[i].attrs; i++) { ++ setup_el2_mpu_region(i, 0, 0); ++ } ++} ++ ++static struct mpu_region default_mpu_mem_map[] = {{0,}}; ++__weak struct mpu_region *mpu_mem_map = default_mpu_mem_map; ++ ++static void mpu_setup(void) ++{ ++ int i; ++ ++ if (current_el() != 2) { ++ panic("MPU configuration is only supported at EL2"); ++ } ++ ++ set_sctlr(get_sctlr() & ~(CR_M | CR_WXN)); ++ ++ asm volatile("msr MAIR_EL2, %0" : : "r" MEMORY_ATTRIBUTES); ++ ++ for (i = 0; mpu_mem_map[i].end || mpu_mem_map[i].attrs; i++) { ++ setup_el2_mpu_region(i, ++ PRBAR_ADDRESS(mpu_mem_map[i].start) ++ | PRBAR_OUTER_SH | PRBAR_AP_RW_ANY, ++ PRLAR_ADDRESS(mpu_mem_map[i].end) ++ | mpu_mem_map[i].attrs | PRLAR_EN_BIT ++ ); ++ } ++ ++ set_sctlr(get_sctlr() | CR_M); ++} ++ ++static bool el_has_mmu(void) ++{ ++ if (current_el() < 2) { ++ // We have no way of knowing, so assuming we have an MMU ++ return true; ++ } ++ ++ uint64_t id_aa64mmfr0; ++ asm volatile("mrs %0, id_aa64mmfr0_el1" ++ : "=r" (id_aa64mmfr0) : : "cc"); ++ uint64_t msa = id_aa64mmfr0 & ID_AA64MMFR0_EL1_MSA_MASK; ++ uint64_t msa_frac = id_aa64mmfr0 & ID_AA64MMFR0_EL1_MSA_FRAC_MASK; ++ ++ switch (msa) { ++ case ID_AA64MMFR0_EL1_MSA_VMSA: ++ /* ++ * VMSA supported in all translation regimes. ++ * No support for PMSA. ++ */ ++ return true; ++ case ID_AA64MMFR0_EL1_MSA_USE_FRAC: ++ /* See MSA_frac for the supported MSAs. */ ++ switch (msa_frac) { ++ case ID_AA64MMFR0_EL1_MSA_FRAC_NO_PMSA: ++ /* ++ * PMSA not supported in any translation ++ * regime. ++ */ ++ return true; ++ case ID_AA64MMFR0_EL1_MSA_FRAC_VMSA: ++ /* ++ * PMSA supported in all translation ++ * regimes. No support for VMSA. ++ */ ++ case ID_AA64MMFR0_EL1_MSA_FRAC_PMSA: ++ /* ++ * PMSA supported in all translation ++ * regimes. ++ */ ++ return false; ++ default: ++ panic("Unsupported id_aa64mmfr0_el1 " \ ++ "MSA_frac value"); ++ } ++ default: ++ panic("Unsupported id_aa64mmfr0_el1 MSA value"); ++ } ++} ++ + void setup_pgtables(void) + { + int i; +@@ -479,8 +565,13 @@ void dcache_enable(void) + /* The data cache is not active unless the mmu is enabled */ + if (!(get_sctlr() & CR_M)) { + invalidate_dcache_all(); +- __asm_invalidate_tlb_all(); +- mmu_setup(); ++ ++ if (el_has_mmu()) { ++ __asm_invalidate_tlb_all(); ++ mmu_setup(); ++ } else { ++ mpu_setup(); ++ } + } + + set_sctlr(get_sctlr() | CR_C); +@@ -499,7 +590,11 @@ void dcache_disable(void) + set_sctlr(sctlr & ~(CR_C|CR_M)); + + flush_dcache_all(); +- __asm_invalidate_tlb_all(); ++ ++ if (el_has_mmu()) ++ __asm_invalidate_tlb_all(); ++ else ++ mpu_clear_regions(); + } + + int dcache_status(void) +diff --git a/arch/arm/include/asm/armv8/mpu.h b/arch/arm/include/asm/armv8/mpu.h +new file mode 100644 +index 0000000000..8de627cafd +--- /dev/null ++++ b/arch/arm/include/asm/armv8/mpu.h +@@ -0,0 +1,59 @@ ++/* ++ * SPDX-License-Identifier: GPL-2.0+ ++ * ++ * (C) Copyright 2021 Arm Limited ++ */ ++ ++#ifndef _ASM_ARMV8_MPU_H_ ++#define _ASM_ARMV8_MPU_H_ ++ ++#include ++#include ++ ++#define PRSELR_EL2 S3_4_c6_c2_1 ++#define PRBAR_EL2 S3_4_c6_c8_0 ++#define PRLAR_EL2 S3_4_c6_c8_1 ++#define MPUIR_EL2 S3_4_c0_c0_4 ++ ++#define PRBAR_ADDRESS(addr) ((addr) & ~(0x3fULL)) ++ ++/* Access permissions */ ++#define PRBAR_AP(val) (((val) & 0x3) << 2) ++#define PRBAR_AP_RW_HYP PRBAR_AP(0x0) ++#define PRBAR_AP_RW_ANY PRBAR_AP(0x1) ++#define PRBAR_AP_RO_HYP PRBAR_AP(0x2) ++#define PRBAR_AP_RO_ANY PRBAR_AP(0x3) ++ ++/* Shareability */ ++#define PRBAR_SH(val) (((val) & 0x3) << 4) ++#define PRBAR_NON_SH PRBAR_SH(0x0) ++#define PRBAR_OUTER_SH PRBAR_SH(0x2) ++#define PRBAR_INNER_SH PRBAR_SH(0x3) ++ ++/* Memory attribute (MAIR idx) */ ++#define PRLAR_ATTRIDX(val) (((val) & 0x7) << 1) ++#define PRLAR_EN_BIT (0x1) ++#define PRLAR_ADDRESS(addr) ((addr) & ~(0x3fULL)) ++ ++#ifndef __ASSEMBLY__ ++ ++static inline void setup_el2_mpu_region(uint8_t region, uint64_t base, uint64_t limit) ++{ ++ asm volatile("msr " __stringify(PRSELR_EL2) ", %0" : : "r" (region)); ++ asm volatile("msr " __stringify(PRBAR_EL2) ", %0" : : "r" (base)); ++ asm volatile("msr " __stringify(PRLAR_EL2) ", %0" : : "r" (limit)); ++ ++ asm volatile("isb"); ++} ++ ++#endif ++ ++struct mpu_region { ++ u64 start; ++ u64 end; ++ u64 attrs; ++}; ++ ++extern struct mpu_region *mpu_mem_map; ++ ++#endif /* _ASM_ARMV8_MPU_H_ */ +diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h +index 77aa18909e..deb3158943 100644 +--- a/arch/arm/include/asm/system.h ++++ b/arch/arm/include/asm/system.h +@@ -94,6 +94,25 @@ + auth algorithm */ + #define ID_AA64ISAR1_EL1_APA (0xF << 4) /* QARMA address auth algorithm */ + ++/* ++ * ID_AA64MMFR0_EL1 bits definitions ++ */ ++#define ID_AA64MMFR0_EL1_MSA_FRAC_MASK (0xFUL << 52) /* Memory system ++ architecture ++ frac */ ++#define ID_AA64MMFR0_EL1_MSA_FRAC_VMSA (0x2UL << 52) /* EL1&0 supports ++ VMSA */ ++#define ID_AA64MMFR0_EL1_MSA_FRAC_PMSA (0x1UL << 52) /* EL1&0 only ++ supports PMSA*/ ++#define ID_AA64MMFR0_EL1_MSA_FRAC_NO_PMSA (0x0UL << 52) /* No PMSA ++ support */ ++#define ID_AA64MMFR0_EL1_MSA_MASK (0xFUL << 48) /* Memory system ++ architecture */ ++#define ID_AA64MMFR0_EL1_MSA_USE_FRAC (0xFUL << 48) /* Use MSA_FRAC */ ++#define ID_AA64MMFR0_EL1_MSA_VMSA (0x0UL << 48) /* Memory system ++ architecture ++ is VMSA */ ++ + /* + * ID_AA64PFR0_EL1 bits definitions + */ +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0008-armv8-Allow-disabling-exception-vectors-on-non-SPL-b.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0008-armv8-Allow-disabling-exception-vectors-on-non-SPL-b.patch new file mode 100644 index 0000000..1f1fac8 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0008-armv8-Allow-disabling-exception-vectors-on-non-SPL-b.patch @@ -0,0 +1,98 @@ +From 377b3d6d79e26e85dabf0fe0726ac179e9229523 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Fri, 10 Dec 2021 11:41:19 +0000 +Subject: [PATCH 08/12] armv8: Allow disabling exception vectors on non-SPL + builds + +On the BASER_FVP, U-Boot shares EL2 with another bootloader, so we do +not wish to overide the exception vector, but we are also not using an +SPL build. + +Therefore, add ARMV8_EXCEPTION_VECTORS, which disables exception vectors +in a similar way to ARMV8_SPL_EXCEPTION_VECTORS. + +Rename ARMV8_SPL_EXCEPTION_VECTORS -> SPL_ARMV8_EXCEPTION_VECTORS so +that both config flags be be targeted using CONFIG_IS_ENABLED. + +Issue-Id: SCM-3728 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Peter Hoyes +Change-Id: I0cf0fc6d7ef4d45791411cf1f67c65e198cc8b2b +--- + arch/arm/cpu/armv8/Kconfig | 11 ++++++++--- + arch/arm/cpu/armv8/Makefile | 6 ++---- + arch/arm/cpu/armv8/start.S | 4 ++-- + 3 files changed, 12 insertions(+), 9 deletions(-) + +diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig +index b7a10a8e34..77dae1f84a 100644 +--- a/arch/arm/cpu/armv8/Kconfig ++++ b/arch/arm/cpu/armv8/Kconfig +@@ -1,9 +1,8 @@ + if ARM64 + +-config ARMV8_SPL_EXCEPTION_VECTORS ++config ARMV8_EXCEPTION_VECTORS + bool "Install crash dump exception vectors" +- depends on SPL +- default n ++ default y + help + The default exception vector table is only used for the crash + dump, but still takes quite a lot of space in the image size. +@@ -11,6 +10,12 @@ config ARMV8_SPL_EXCEPTION_VECTORS + Say N here if you are running out of code space in the image + and want to save some space at the cost of less debugging info. + ++config SPL_ARMV8_EXCEPTION_VECTORS ++ bool "Install crash dump exception vectors in the SPL" ++ depends on SPL ++ help ++ Same as ARMV8_EXCEPTION_VECTORS, but for SPL builds ++ + config ARMV8_MULTIENTRY + bool "Enable multiple CPUs to enter into U-Boot" + +diff --git a/arch/arm/cpu/armv8/Makefile b/arch/arm/cpu/armv8/Makefile +index d85ddde430..be2a4b126c 100644 +--- a/arch/arm/cpu/armv8/Makefile ++++ b/arch/arm/cpu/armv8/Makefile +@@ -13,10 +13,8 @@ ifndef CONFIG_$(SPL_)SYS_DCACHE_OFF + obj-y += cache_v8.o + obj-y += cache.o + endif +-ifdef CONFIG_SPL_BUILD +-obj-$(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) += exceptions.o +-else +-obj-y += exceptions.o ++obj-$(CONFIG_$(SPL_)ARMV8_EXCEPTION_VECTORS) += exceptions.o ++ifndef CONFIG_SPL_BUILD + obj-y += exception_level.o + endif + obj-y += tlb.o +diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S +index 662449156b..2389e4773a 100644 +--- a/arch/arm/cpu/armv8/start.S ++++ b/arch/arm/cpu/armv8/start.S +@@ -108,7 +108,7 @@ pie_fixup_done: + bl reset_sctrl + #endif + +-#if defined(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) || !defined(CONFIG_SPL_BUILD) ++#if CONFIG_IS_ENABLED(ARMV8_EXCEPTION_VECTORS) + .macro set_vbar, regname, reg + msr \regname, \reg + .endm +@@ -382,7 +382,7 @@ ENDPROC(smp_kick_all_cpus) + /*-----------------------------------------------------------------------*/ + + ENTRY(c_runtime_cpu_setup) +-#if defined(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) || !defined(CONFIG_SPL_BUILD) ++#if CONFIG_IS_ENABLED(ARMV8_EXCEPTION_VECTORS) + /* Relocate vBAR */ + adr x0, vectors + switch_el x1, 3f, 2f, 1f +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0009-armv8-ARMV8_SWITCH_TO_EL1-improvements.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0009-armv8-ARMV8_SWITCH_TO_EL1-improvements.patch new file mode 100644 index 0000000..9bf3e5a --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0009-armv8-ARMV8_SWITCH_TO_EL1-improvements.patch @@ -0,0 +1,163 @@ +From 5facc2d1389074475f90a0713cefe0e3f69379d8 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Wed, 14 Jul 2021 12:44:27 +0100 +Subject: [PATCH 09/12] armv8: ARMV8_SWITCH_TO_EL1 improvements + +Convert CONFIG_ARMV8_SWITCH_TO_EL1 to a Kconfig variable. + +Add support for switching to EL1 to bootefi. + +Add the environment variable armv8_switch_to_el1 to allow configuring +whether to switch to EL1 at runtime. This overrides the compile-time +option. + +Issue-Id: SCM-3728 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Peter Hoyes +Change-Id: If98478148d6d8d1f732acac5439276700614815f +--- + arch/arm/cpu/armv8/Kconfig | 8 +++++++ + arch/arm/cpu/armv8/exception_level.c | 21 ++++++++++++++-- + arch/arm/lib/bootm.c | 36 ++++++++++++++++------------ + scripts/config_whitelist.txt | 1 - + 4 files changed, 48 insertions(+), 18 deletions(-) + +diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig +index 77dae1f84a..e994c261a1 100644 +--- a/arch/arm/cpu/armv8/Kconfig ++++ b/arch/arm/cpu/armv8/Kconfig +@@ -179,4 +179,12 @@ config ARMV8_SECURE_BASE + + endif + ++config ARMV8_SWITCH_TO_EL1 ++ bool "Switch to EL1 before booting the operating system" ++ default n ++ help ++ Switch to EL1 before booting the operating system, if for example the ++ operating system does not support booting at EL2, or you wish to prevent ++ any hypervisors from running. Supported for bootm, booti and bootefi. ++ + endif +diff --git a/arch/arm/cpu/armv8/exception_level.c b/arch/arm/cpu/armv8/exception_level.c +index b11936548f..4aad1550f4 100644 +--- a/arch/arm/cpu/armv8/exception_level.c ++++ b/arch/arm/cpu/armv8/exception_level.c +@@ -40,19 +40,36 @@ static void entry_non_secure(struct jmp_buf_data *non_secure_jmp) + * trusted firmware being one embodiment). The operating system shall be + * started at exception level EL2. So here we check the exception level + * and switch it if necessary. ++ * ++ * If armv8_switch_to_el1 (config or env var) is enabled, also switch to EL1 ++ * before booting the operating system. + */ + void switch_to_non_secure_mode(void) + { + struct jmp_buf_data non_secure_jmp; + + /* On AArch64 we need to make sure we call our payload in < EL3 */ +- if (current_el() == 3) { ++ ++ int switch_to_el1 = env_get_yesno("armv8_switch_to_el1"); ++#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 ++ if (switch_to_el1 == -1) { ++ switch_to_el1 = 1; ++ } ++#endif ++ ++ if (current_el() > 2) { + if (setjmp(&non_secure_jmp)) + return; + dcache_disable(); /* flush cache before switch to EL2 */ +- + /* Move into EL2 and keep running there */ + armv8_switch_to_el2((uintptr_t)&non_secure_jmp, 0, 0, 0, + (uintptr_t)entry_non_secure, ES_TO_AARCH64); ++ } else if (switch_to_el1 == 1 && current_el() > 1) { ++ if (setjmp(&non_secure_jmp)) ++ return; ++ dcache_disable(); /* flush cache before switch to EL1 */ ++ /* Move into EL1 and keep running there */ ++ armv8_switch_to_el1((uintptr_t)&non_secure_jmp, 0, 0, 0, ++ (uintptr_t)entry_non_secure, ES_TO_AARCH64); + } + } +diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c +index f60ee3a7e6..a87dd37664 100644 +--- a/arch/arm/lib/bootm.c ++++ b/arch/arm/lib/bootm.c +@@ -317,7 +317,6 @@ __weak void update_os_arch_secondary_cores(uint8_t os_arch) + { + } + +-#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + static void switch_to_el1(void) + { + if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && +@@ -332,7 +331,6 @@ static void switch_to_el1(void) + ES_TO_AARCH64); + } + #endif +-#endif + + /* Subcommand: GO */ + static void boot_jump_linux(bootm_headers_t *images, int flag) +@@ -359,21 +357,29 @@ static void boot_jump_linux(bootm_headers_t *images, int flag) + + update_os_arch_secondary_cores(images->os.arch); + ++ int armv8_switch_to_el1 = env_get_yesno("armv8_switch_to_el1"); + #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 +- armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, +- (u64)switch_to_el1, ES_TO_AARCH64); +-#else +- if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && +- (images->os.arch == IH_ARCH_ARM)) +- armv8_switch_to_el2(0, (u64)gd->bd->bi_arch_number, +- (u64)images->ft_addr, 0, +- (u64)images->ep, +- ES_TO_AARCH32); +- else +- armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, +- images->ep, +- ES_TO_AARCH64); ++ if (armv8_switch_to_el1 == -1) { ++ armv8_switch_to_el1 = 1; ++ } + #endif ++ if (armv8_switch_to_el1 == 1) { ++ armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, ++ (u64)switch_to_el1, ES_TO_AARCH64); ++ } else { ++ if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && ++ (images->os.arch == IH_ARCH_ARM)) ++ armv8_switch_to_el2(0, ++ (u64)gd->bd->bi_arch_number, ++ (u64)images->ft_addr, 0, ++ (u64)images->ep, ++ ES_TO_AARCH32); ++ else ++ armv8_switch_to_el2((u64)images->ft_addr, ++ 0, 0, 0, ++ images->ep, ++ ES_TO_AARCH64); ++ } + } + #else + unsigned long machid = gd->bd->bi_arch_number; +diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt +index 3dbcc042a8..60455d12e3 100644 +--- a/scripts/config_whitelist.txt ++++ b/scripts/config_whitelist.txt +@@ -46,7 +46,6 @@ CONFIG_ARMADA168 + CONFIG_ARMV7_SECURE_BASE + CONFIG_ARMV7_SECURE_MAX_SIZE + CONFIG_ARMV7_SECURE_RESERVE_SIZE +-CONFIG_ARMV8_SWITCH_TO_EL1 + CONFIG_ARM_ARCH_CP15_ERRATA + CONFIG_ARM_GIC_BASE_ADDRESS + CONFIG_ARM_PL180_MMCI_BASE +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0010-armv8-Make-disabling-HVC-configurable-when-switching.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0010-armv8-Make-disabling-HVC-configurable-when-switching.patch new file mode 100644 index 0000000..5ce4485 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0010-armv8-Make-disabling-HVC-configurable-when-switching.patch @@ -0,0 +1,73 @@ +From 8360c16a9261a90944ef922733ae5b56e8eed5a6 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Fri, 10 Dec 2021 16:37:26 +0000 +Subject: [PATCH 10/12] armv8: Make disabling HVC configurable when switching + to EL1 + +On the BASER_FVP there is no EL3, so HVC is used to provide PSCI +services. Therefore we cannot disable hypercalls. + +Create CONFIG_ARMV8_DISABLE_HVC (dependent on CONFIG_ARMV8_TO_EL1) to +control whether to disable HVC exceptions in HCR_EL2->HCD + +Issue-Id: SCM-3728 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Peter Hoyes +Change-Id: I463d82f1db8a3cafcab40a9c0c208753569cc300 +--- + arch/arm/cpu/armv8/Kconfig | 9 +++++++++ + arch/arm/include/asm/macro.h | 10 ++++++++-- + 2 files changed, 17 insertions(+), 2 deletions(-) + +diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig +index e994c261a1..cd49529346 100644 +--- a/arch/arm/cpu/armv8/Kconfig ++++ b/arch/arm/cpu/armv8/Kconfig +@@ -187,4 +187,13 @@ config ARMV8_SWITCH_TO_EL1 + operating system does not support booting at EL2, or you wish to prevent + any hypervisors from running. Supported for bootm, booti and bootefi. + ++config ARMV8_DISABLE_HVC ++ bool "Disable HVC calls before switching to EL1" ++ depends on ARMV8_SWITCH_TO_EL1 ++ default y ++ help ++ If switching to EL1 before loading the operating system, disable taking ++ hypercalls back to EL2. May be disabled if, for example, PSCI services are ++ running at EL2. ++ + endif +diff --git a/arch/arm/include/asm/macro.h b/arch/arm/include/asm/macro.h +index 5ee72d0e78..d6b5d7d7f3 100644 +--- a/arch/arm/include/asm/macro.h ++++ b/arch/arm/include/asm/macro.h +@@ -293,9 +293,12 @@ lr .req x30 + ldr \tmp2, =(ID_AA64ISAR1_EL1_GPI | ID_AA64ISAR1_EL1_GPA | \ + ID_AA64ISAR1_EL1_API | ID_AA64ISAR1_EL1_APA) + tst \tmp, \tmp2 +- mov \tmp2, #(HCR_EL2_RW_AARCH64 | HCR_EL2_HCD_DIS) ++ mov \tmp2, #(HCR_EL2_RW_AARCH64) + orr \tmp, \tmp2, #(HCR_EL2_APK | HCR_EL2_API) + csel \tmp, \tmp2, \tmp, eq ++#ifdef CONFIG_ARMV8_DISABLE_HVC ++ orr \tmp, \tmp, #(HCR_EL2_HCD_DIS) ++#endif + msr hcr_el2, \tmp + + /* Return to the EL1_SP1 mode from EL2 */ +@@ -308,7 +311,10 @@ lr .req x30 + + 1: + /* Initialize HCR_EL2 */ +- ldr \tmp, =(HCR_EL2_RW_AARCH32 | HCR_EL2_HCD_DIS) ++ ldr \tmp, =(HCR_EL2_RW_AARCH32) ++#ifdef CONFIG_ARMV8_DISABLE_HVC ++ orr \tmp, \tmp, #(HCR_EL2_HCD_DIS) ++#endif + msr hcr_el2, \tmp + + /* Return to AArch32 Supervisor mode from EL2 */ +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0011-vexpress64-Do-not-set-COUNTER_FREQUENCY.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0011-vexpress64-Do-not-set-COUNTER_FREQUENCY.patch new file mode 100644 index 0000000..0f4f0a4 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0011-vexpress64-Do-not-set-COUNTER_FREQUENCY.patch @@ -0,0 +1,37 @@ +From 3362e6910fe3f4d431b4034299f1b8d79a45e693 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Fri, 10 Dec 2021 15:09:09 +0000 +Subject: [PATCH 11/12] vexpress64: Do not set COUNTER_FREQUENCY + +VExpress boards normally run as a second-stage bootloader so should not +need to modify CNTFRQ_EL0. On the BASER_FVP, U-Boot can modify it if +running at EL2, but shouldn't because it might be different from the +value being used by the first-stage bootloader (which might be +providing PSCI services). + +Issue-Id: SCM-3728 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Peter Hoyes +Change-Id: I137473d721e58e4c348b9641f5b9778178d3bb65 +--- + include/configs/vexpress_aemv8.h | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h +index 68422237dd..567a6dbf36 100644 +--- a/include/configs/vexpress_aemv8.h ++++ b/include/configs/vexpress_aemv8.h +@@ -70,9 +70,6 @@ + #define V2M_SYS_CFGCTRL (V2M_SYSREGS + 0x0a4) + #define V2M_SYS_CFGSTAT (V2M_SYSREGS + 0x0a8) + +-/* Generic Timer Definitions */ +-#define COUNTER_FREQUENCY 24000000 /* 24MHz */ +- + /* Generic Interrupt Controller Definitions */ + #ifdef CONFIG_GICV3 + #define GICD_BASE (V2M_PA_BASE + 0x2f000000) +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0012-vexpress64-Add-BASER_FVP-vexpress-board-variant.patch b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0012-vexpress64-Add-BASER_FVP-vexpress-board-variant.patch new file mode 100644 index 0000000..787e79b --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot/fvp-baser-aemv8r64/0012-vexpress64-Add-BASER_FVP-vexpress-board-variant.patch @@ -0,0 +1,275 @@ +From fdc36eaf590bfadfa184ccf589076e0b3420b859 Mon Sep 17 00:00:00 2001 +From: Peter Hoyes +Date: Mon, 24 May 2021 11:47:53 +0100 +Subject: [PATCH 12/12] vexpress64: Add BASER_FVP vexpress board variant + +The BASER_FVP board variant is implemented on top of the BASE_FVP board +config (which, in turn, is based on the Juno Versatile Express board +config). They all share a similar memory map - for BASER_FVP the map is +inverted from the BASE_FVP +(https://developer.arm.com/documentation/100964/1114/Base-Platform/Base---memory/BaseR-Platform-memory-map) + + * Create new TARGET_VEXPRESS64_BASER_FVP target, which uses the same + board config as BASE_FVP and JUNO + * Implement inverted memory map in vexpress_aemv8.h + * Create vexpress_aemv8r defconfig + * Provide MPU and MMU memory maps for the BASER_FVP + * Provide default value for LNX_KRNL_IMG_TEXT_OFFSET_BASE + * Update vexpress64 documentation + +Issue-Id: SCM-3728 +Upstream-Status: Inappropriate [other] + Temporary patch +Signed-off-by: Peter Hoyes +Change-Id: Id173e52afad473abcf3f61c6bf374fc31f17edd3 +--- + arch/arm/Kconfig | 8 +++++ + board/armltd/vexpress64/Kconfig | 6 +++- + board/armltd/vexpress64/MAINTAINERS | 7 ++++ + board/armltd/vexpress64/vexpress64.c | 52 ++++++++++++++++++++++++++++ + configs/vexpress_aemv8r_defconfig | 27 +++++++++++++++ + doc/board/armltd/vexpress64.rst | 1 + + include/configs/vexpress_aemv8.h | 42 ++++++++++++++++++++++ + 7 files changed, 142 insertions(+), 1 deletion(-) + create mode 100644 configs/vexpress_aemv8r_defconfig + +diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig +index 0448787b8b..7bf39264e3 100644 +--- a/arch/arm/Kconfig ++++ b/arch/arm/Kconfig +@@ -1157,6 +1157,14 @@ config TARGET_VEXPRESS64_BASE_FVP + select PL01X_SERIAL + select SEMIHOSTING + ++config TARGET_VEXPRESS64_BASER_FVP ++ bool "Support Versatile Express ARMv8r64 FVP BASE model" ++ select ARM64 ++ select DM ++ select DM_SERIAL ++ select PL01X_SERIAL ++ select LINUX_KERNEL_IMAGE_HEADER ++ + config TARGET_VEXPRESS64_JUNO + bool "Support Versatile Express Juno Development Platform" + select ARM64 +diff --git a/board/armltd/vexpress64/Kconfig b/board/armltd/vexpress64/Kconfig +index 4aab3f092e..e824173fe1 100644 +--- a/board/armltd/vexpress64/Kconfig ++++ b/board/armltd/vexpress64/Kconfig +@@ -1,4 +1,5 @@ +-if TARGET_VEXPRESS64_BASE_FVP || TARGET_VEXPRESS64_JUNO ++if TARGET_VEXPRESS64_BASE_FVP || TARGET_VEXPRESS64_JUNO || \ ++ TARGET_VEXPRESS64_BASER_FVP + + config SYS_BOARD + default "vexpress64" +@@ -16,4 +17,7 @@ config JUNO_DTB_PART + The ARM partition name in the NOR flash memory holding the + device tree blob to configure U-Boot. + ++config LNX_KRNL_IMG_TEXT_OFFSET_BASE ++ default 0x0 ++ + endif +diff --git a/board/armltd/vexpress64/MAINTAINERS b/board/armltd/vexpress64/MAINTAINERS +index 0ba044d7ff..e89d9711b8 100644 +--- a/board/armltd/vexpress64/MAINTAINERS ++++ b/board/armltd/vexpress64/MAINTAINERS +@@ -14,3 +14,10 @@ JUNO DEVELOPMENT PLATFORM BOARD + M: Linus Walleij + S: Maintained + F: configs/vexpress_aemv8a_juno_defconfig ++ ++VEXPRESS_AEMV8R BOARD ++M: Diego Sueiro ++M: Peter Hoyes ++R: Andre Przywara ++S: Maintained ++F: configs/vexpress_aemv8r_defconfig +diff --git a/board/armltd/vexpress64/vexpress64.c b/board/armltd/vexpress64/vexpress64.c +index 821f9cfc3b..07c76609ab 100644 +--- a/board/armltd/vexpress64/vexpress64.c ++++ b/board/armltd/vexpress64/vexpress64.c +@@ -18,6 +18,7 @@ + #include + #include "pcie.h" + #include ++#include + #ifdef CONFIG_VIRTIO_NET + #include + #include +@@ -36,6 +37,56 @@ U_BOOT_DRVINFO(vexpress_serials) = { + .plat = &serial_plat, + }; + ++#ifdef CONFIG_TARGET_VEXPRESS64_BASER_FVP ++ ++static struct mpu_region vexpress64_aemv8r_mem_map[] = { ++ { ++ .start = 0x0UL, ++ .end = 0x7fffffffUL, ++ .attrs = PRLAR_ATTRIDX(MT_NORMAL) ++ }, { ++ .start = 0x80000000UL, ++ .end = 0xffffffffUL, ++ .attrs = PRLAR_ATTRIDX(MT_DEVICE_NGNRNE) ++ }, { ++ .start = 0x100000000UL, ++ .end = 0xffffffffffUL, ++ .attrs = PRLAR_ATTRIDX(MT_NORMAL) ++ }, { ++ /* List terminator */ ++ 0, ++ } ++}; ++ ++struct mpu_region *mpu_mem_map = vexpress64_aemv8r_mem_map; ++ ++static struct mm_region vexpress64_mem_map[] = { ++ { ++ .virt = 0x0UL, ++ .phys = 0x0UL, ++ .size = 0x80000000UL, ++ .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | ++ PTE_BLOCK_INNER_SHARE ++ }, { ++ .virt = 0x80000000UL, ++ .phys = 0x80000000UL, ++ .size = 0x80000000UL, ++ .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | ++ PTE_BLOCK_NON_SHARE | ++ PTE_BLOCK_PXN | PTE_BLOCK_UXN ++ }, ++ { ++ .virt = 0x100000000UL, ++ .phys = 0x100000000UL, ++ .size = 0xff00000000UL, ++ .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | ++ PTE_BLOCK_INNER_SHARE ++ }, { ++ /* List terminator */ ++ 0, ++ } ++}; ++#else + static struct mm_region vexpress64_mem_map[] = { + { + .virt = 0x0UL, +@@ -55,6 +106,7 @@ static struct mm_region vexpress64_mem_map[] = { + 0, + } + }; ++#endif + + struct mm_region *mem_map = vexpress64_mem_map; + +diff --git a/configs/vexpress_aemv8r_defconfig b/configs/vexpress_aemv8r_defconfig +new file mode 100644 +index 0000000000..37c393b66f +--- /dev/null ++++ b/configs/vexpress_aemv8r_defconfig +@@ -0,0 +1,27 @@ ++CONFIG_ARM=y ++CONFIG_TARGET_VEXPRESS64_BASER_FVP=y ++CONFIG_SYS_TEXT_BASE=0x00080000 ++CONFIG_POSITION_INDEPENDENT=y ++CONFIG_SYS_LOAD_ADDR=0x10000000 ++CONFIG_SYS_MALLOC_F_LEN=0x2000 ++CONFIG_NR_DRAM_BANKS=2 ++CONFIG_ENV_SIZE=0x40000 ++CONFIG_ENV_SECT_SIZE=0x40000 ++CONFIG_IDENT_STRING=" vexpress_aemv8r64" ++CONFIG_DISTRO_DEFAULTS=y ++CONFIG_BOOTDELAY=3 ++CONFIG_USE_BOOTARGS=y ++CONFIG_BOOTARGS="console=ttyAMA0 earlycon=pl011,0x9c090000 rootfstype=ext4 root=/dev/vda2 rw rootwait" ++# CONFIG_USE_BOOTCOMMAND is not set ++# CONFIG_DISPLAY_CPUINFO is not set ++CONFIG_SYS_PROMPT="VExpress64# " ++CONFIG_DM_ETH=y ++CONFIG_OF_CONTROL=y ++CONFIG_OF_BOARD=y ++CONFIG_VIRTIO_MMIO=y ++CONFIG_VIRTIO_BLK=y ++CONFIG_VIRTIO_NET=y ++CONFIG_ARMV8_SWITCH_TO_EL1=y ++CONFIG_ARMV8_DISABLE_HVC=n ++CONFIG_ARMV8_EXCEPTION_VECTORS=n ++CONFIG_ARCH_FIXUP_FDT_MEMORY=n +diff --git a/doc/board/armltd/vexpress64.rst b/doc/board/armltd/vexpress64.rst +index b98b096544..b8efbc1565 100644 +--- a/doc/board/armltd/vexpress64.rst ++++ b/doc/board/armltd/vexpress64.rst +@@ -6,6 +6,7 @@ Arm Versatile Express + The vexpress_* board configuration supports the following platforms: + + * FVP_Base_RevC-2xAEMvA ++ * FVP_BaseR_AEMv8R + * Juno development board + + Fixed Virtual Platforms +diff --git a/include/configs/vexpress_aemv8.h b/include/configs/vexpress_aemv8.h +index 567a6dbf36..d0173735db 100644 +--- a/include/configs/vexpress_aemv8.h ++++ b/include/configs/vexpress_aemv8.h +@@ -22,8 +22,13 @@ + #define CONFIG_SYS_BOOTM_LEN (64 << 20) /* Increase max gunzip size */ + + /* CS register bases for the original memory map. */ ++#ifdef CONFIG_TARGET_VEXPRESS64_BASER_FVP ++#define V2M_BASE 0x00000000 ++#define V2M_PA_BASE 0x80000000 ++#else + #define V2M_BASE 0x80000000 + #define V2M_PA_BASE 0x00000000 ++#endif + + #define V2M_PA_CS0 (V2M_PA_BASE + 0x00000000) + #define V2M_PA_CS1 (V2M_PA_BASE + 0x14000000) +@@ -205,6 +210,43 @@ + "fi" + #endif + ++#elif CONFIG_TARGET_VEXPRESS64_BASER_FVP ++ ++#define BOOTENV_DEV_MEM(devtypeu, devtypel, instance) \ ++ "bootcmd_mem= " \ ++ "source ${scriptaddr}; " \ ++ "if test $? -eq 1; then " \ ++ " env import -t ${scriptaddr}; " \ ++ " if test -n $uenvcmd; then " \ ++ " echo Running uenvcmd ...; " \ ++ " run uenvcmd; " \ ++ " fi; " \ ++ "fi\0" ++#define BOOTENV_DEV_NAME_MEM(devtypeu, devtypel, instance) "mem " ++ ++#define BOOT_TARGET_DEVICES(func) \ ++ func(MEM, mem, na) \ ++ func(VIRTIO, virtio, 0) \ ++ func(PXE, pxe, na) \ ++ func(DHCP, dhcp, na) ++ ++#include ++ ++#define VEXPRESS_KERNEL_ADDR 0x00200000 ++#define VEXPRESS_PXEFILE_ADDR 0x0fb00000 ++#define VEXPRESS_FDT_ADDR 0x0fc00000 ++#define VEXPRESS_SCRIPT_ADDR 0x0fd00000 ++#define VEXPRESS_RAMDISK_ADDR 0x0fe00000 ++ ++#define CONFIG_EXTRA_ENV_SETTINGS \ ++ "kernel_addr_r=" __stringify(VEXPRESS_KERNEL_ADDR) "\0" \ ++ "pxefile_addr_r=" __stringify(VEXPRESS_PXEFILE_ADDR) "\0" \ ++ "fdt_addr_r=" __stringify(VEXPRESS_FDT_ADDR) "\0" \ ++ "fdtfile=board.dtb\0" \ ++ "scriptaddr=" __stringify(VEXPRESS_SCRIPT_ADDR) "\0" \ ++ "ramdisk_addr_r=" __stringify(VEXPRESS_RAMDISK_ADDR) "\0" \ ++ BOOTENV ++ + #endif + + /* Monitor Command Prompt */ +-- +2.25.1 + diff --git a/meta-arm-bsp/recipes-bsp/u-boot/u-boot_%.bbappend b/meta-arm-bsp/recipes-bsp/u-boot/u-boot_%.bbappend index 88cf595..2eef58c 100644 --- a/meta-arm-bsp/recipes-bsp/u-boot/u-boot_%.bbappend +++ b/meta-arm-bsp/recipes-bsp/u-boot/u-boot_%.bbappend @@ -75,3 +75,21 @@ SRC_URI:append:fvp-base = " file://bootargs.cfg" # FVP BASE ARM32 # SRC_URI:append:fvp-base-arm32 = " file://0001-Add-vexpress_aemv8a_aarch32-variant.patch" + +# +# FVP BASER +# +SRC_URI:append:fvp-baser-aemv8r64 = " \ + file://0001-armv8-Disable-pointer-authentication-traps-for-EL1.patch \ + file://0002-doc-Add-documentation-for-the-Arm-VExpress64-board-c.patch \ + file://0003-vexpress64-Refactor-header-file-to-make-it-easier-to.patch \ + file://0004-vexpress64-Clean-up-BASE_FVP-boot-configuration.patch \ + file://0005-vexpress64-Enable-OF_CONTROL-and-OF_BOARD-for-VExpre.patch \ + file://0006-vexpress64-Enable-VIRTIO_NET-network-driver.patch \ + file://0007-armv8-Add-ARMv8-MPU-configuration-logic.patch \ + file://0008-armv8-Allow-disabling-exception-vectors-on-non-SPL-b.patch \ + file://0009-armv8-ARMV8_SWITCH_TO_EL1-improvements.patch \ + file://0010-armv8-Make-disabling-HVC-configurable-when-switching.patch \ + file://0011-vexpress64-Do-not-set-COUNTER_FREQUENCY.patch \ + file://0012-vexpress64-Add-BASER_FVP-vexpress-board-variant.patch \ + " From patchwork Thu Feb 24 11:22:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 4215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC339C433EF for ; Thu, 24 Feb 2022 11:24:05 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.9082.1645701845102314905 for ; Thu, 24 Feb 2022 03:24:05 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B6DE7106F; Thu, 24 Feb 2022 03:24:04 -0800 (PST) Received: from e125920.cambridge.arm.com (unknown [10.1.199.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2D30C3F70D; Thu, 24 Feb 2022 03:24:04 -0800 (PST) From: Peter Hoyes To: meta-arm@lists.yoctoproject.org Cc: diego.sueiro@arm.com, Peter Hoyes Subject: [PATCH honister 5/8] arm-bsp/kernel: Use 4 Gb of RAM in fvp-baser-aemv8r64 Date: Thu, 24 Feb 2022 11:22:41 +0000 Message-Id: <20220224112244.1521611-6-peter.hoyes@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224112244.1521611-1-peter.hoyes@arm.com> References: <20220224112244.1521611-1-peter.hoyes@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 24 Feb 2022 11:24:05 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/meta-arm/message/3053 From: Peter Hoyes The FVP default configuration has bp.dram_size=4, which is sufficient for development and testing purposes, so remove the FVP_CONFIG override and set to 4 Gb in the device tree. Issue-Id: SCM-3871 Signed-off-by: Peter Hoyes Change-Id: I4a96062c9e94d36f5459f33c86aab4d4885bab43 --- meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf | 1 - .../linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf b/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf index c190e4c..cfbc73d 100644 --- a/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf +++ b/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf @@ -39,7 +39,6 @@ FVP_CONSOLE ?= "terminal_0" FVP_CONFIG[bp.virtioblockdevice.image_path] ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.wic" FVP_CONFIG[bp.dram_metadata.init_value] ?= "0" FVP_CONFIG[bp.dram_metadata.is_enabled] ?= "true" -FVP_CONFIG[bp.dram_size] ?= "8" FVP_CONFIG[bp.exclusive_monitor.monitor_access_level] ?= "1" FVP_CONFIG[bp.pl011_uart0.unbuffered_output] ?= "1" FVP_CONFIG[bp.pl011_uart0.untimed_fifos] ?= "true" diff --git a/meta-arm-bsp/recipes-kernel/linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts b/meta-arm-bsp/recipes-kernel/linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts index 4d6640a..a5078f2 100644 --- a/meta-arm-bsp/recipes-kernel/linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts +++ b/meta-arm-bsp/recipes-kernel/linux/files/fvp-baser-aemv8r64/fvp-baser-aemv8r64.dts @@ -13,7 +13,7 @@ #size-cells = <0x2>; device_type = "memory"; reg = <0x0 0x0 0x0 0x80000000>, - <0x00000008 0x80000000 0x1 0x80000000>; + <0x00000008 0x80000000 0x0 0x80000000>; }; cpus { From patchwork Thu Feb 24 11:22:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 4217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7A8EC433EF for ; Thu, 24 Feb 2022 11:24:07 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.8984.1645701847360174866 for ; Thu, 24 Feb 2022 03:24:07 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0331F106F; Thu, 24 Feb 2022 03:24:07 -0800 (PST) Received: from e125920.cambridge.arm.com (unknown [10.1.199.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6CC4A3F70D; Thu, 24 Feb 2022 03:24:06 -0800 (PST) From: Peter Hoyes To: meta-arm@lists.yoctoproject.org Cc: diego.sueiro@arm.com, Peter Hoyes Subject: [PATCH honister 6/8] arm-bsp/conf: Use real-time clock for fvp-baser-aemv8r64 Date: Thu, 24 Feb 2022 11:22:42 +0000 Message-Id: <20220224112244.1521611-7-peter.hoyes@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224112244.1521611-1-peter.hoyes@arm.com> References: <20220224112244.1521611-1-peter.hoyes@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 24 Feb 2022 11:24:07 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/meta-arm/message/3054 From: Peter Hoyes Enable the bp.refcounter.use_real_time option, so that the CNTPCT_EL0 increments in real-time instead of simulator time. Issue-Id: SCM-3871 Signed-off-by: Peter Hoyes Change-Id: I197d6de4a7316e5299aee34e64e149cbd3d515a9 --- meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf b/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf index cfbc73d..444f83f 100644 --- a/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf +++ b/meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf @@ -61,4 +61,5 @@ FVP_CONFIG[gic_distributor.has-two-security-states] ?= "0" FVP_CONFIG[pctl.startup] ?= "0.0.0.*" FVP_CONFIG[bp.virtio_net.enabled] ?= "1" FVP_CONFIG[bp.virtio_net.hostbridge.userNetworking] ?= "1" -FVP_CONFIG[bp.vis.rate_limit-enable] ?= "0" \ No newline at end of file +FVP_CONFIG[bp.vis.rate_limit-enable] ?= "0" +FVP_CONFIG[bp.refcounter.use_real_time] ?= "1" From patchwork Thu Feb 24 11:22:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 4218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3D8FC433F5 for ; Thu, 24 Feb 2022 11:24:09 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.9097.1645701848779957501 for ; Thu, 24 Feb 2022 03:24:09 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6A0E51476; Thu, 24 Feb 2022 03:24:08 -0800 (PST) Received: from e125920.cambridge.arm.com (unknown [10.1.199.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D46EB3F70D; Thu, 24 Feb 2022 03:24:07 -0800 (PST) From: Peter Hoyes To: meta-arm@lists.yoctoproject.org Cc: diego.sueiro@arm.com, Peter Hoyes Subject: [PATCH honister 7/8] arm-bsp/docs: Update fvp-baser-aemv8r64 docs Date: Thu, 24 Feb 2022 11:22:43 +0000 Message-Id: <20220224112244.1521611-8-peter.hoyes@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224112244.1521611-1-peter.hoyes@arm.com> References: <20220224112244.1521611-1-peter.hoyes@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 24 Feb 2022 11:24:09 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/meta-arm/message/3055 From: Peter Hoyes Document U-Boot addition, add new architecture section and update the change log. Issue-Id: SCM-3871 Signed-off-by: Peter Hoyes Change-Id: Ie0e1ff35ade634f2b523c14bb058c9d775802632 --- .../documentation/fvp-baser-aemv8r64.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/meta-arm-bsp/documentation/fvp-baser-aemv8r64.md b/meta-arm-bsp/documentation/fvp-baser-aemv8r64.md index fdf5038..70256e0 100644 --- a/meta-arm-bsp/documentation/fvp-baser-aemv8r64.md +++ b/meta-arm-bsp/documentation/fvp-baser-aemv8r64.md @@ -28,12 +28,65 @@ where either a standard or Real-Time Linux kernel (PREEMPT\_RT) can be built and run: - boot-wrapper-aarch64: provides PSCI support + - U-Boot: v2021.07 - provides UEFI services - Linux kernel: linux-yocto-5.14 - Linux kernel with PREEMPT\_RT support: linux-yocto-rt-5.14 Note that the Real-Time Linux kernel (PREEMPT\_RT) does not use the real-time architectural extensions of the Armv8-R feature set. +High-Level Architecture +----------------------- + +The diagram below shows the current boot flow: + + +---------------------------------------------------------------+ + | Linux kernel | + +---------------------------------------------------------------+ + /|\ /|\ + | | + | UEFI services | + | PSCI services | + \|/ | + +----------------+ | S-EL1 + ----| U-Boot |------------------------------|----------- + +----------------+ | S-EL2 + /|\ | + | | + | | + | | + +--------------------------------------------------\|/----------+ + | +----------------+ +----------------+ | + | boot-wrapper-aarch64 | Device tree | | PSCI handler | | + | +----------------+ +----------------+ | + +---------------------------------------------------------------+ + + +The firmware binary (generated as `linux-system.axf`) includes +boot-wrapper-aarch64, the flattened device tree and U-Boot. U-Boot is configured +to automatically detect a virtio block device and boot the UEFI payload at the +path `/efi/boot/bootaa64.efi`. Using the standard build, the first partition +contains a Grub image at this path, which boots the Linux kernel at `/Image` on +the same partition. The second partition of the image contains the Linux root +file system. + +There is no EL3 or non-secure world in the Armv8-R AArch64 architecture, so the +reset vector starts boot-wrapper-aarch64 at S-EL2. Boot-wrapper-aarch64 is +compiled with the `--enable-keep-el` flag, which causes it to boot U-Boot at +S-EL2 too. U-Boot is compiled with the `CONFIG_ARMV8_SWITCH_TO_EL1` flag, which +causes it to switch to S-EL1 before booting Linux. + +The bundled device tree is passed to U-Boot via register x0. U-Boot passes the +same device tree to Linux via the UEFI system table. + +Power state management is provided by PSCI services in boot-wrapper-aarch64. +Linux accesses the PSCI handler via HVC calls to S-EL2. U-Boot has been patched +to prevent it from overriding the exception vector at S-EL2. The PSCI handler +memory region is added to a `/memreserve/` node in the device tree. + +Please note that the final firmware architecture for the fvp-baser-aemv8r64 is +not yet stabilized. The patches in this layer are provided for development and +evaluation purposes only, and should not be used in production firmware. Quick start: Howto Build and Run -------------------------------- @@ -167,6 +220,12 @@ Known Issues and Limitations Change Log ---------- +- Added U-Boot v2021.07 for UEFI support. +- Updated boot-wrapper-aarch64 revision and added support for booting U-Boot. +- Included boot-wrapper-aarch64 PSCI services in /memreserve/ region. +- Fixed the counter frequency initialization in boot-wrapper-aarch64. +- Configured the FVP to use the default RAM size of 4 Gb +- Fixed PL011 and SP805 register sizes in the device tree. - Added virtio_net User Networking mode by default and removed instructions about tap networking setup. - Updated Linux kernel version from 5.10 to 5.14 for both standard and From patchwork Thu Feb 24 11:22:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hoyes X-Patchwork-Id: 4219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A81B0C433EF for ; Thu, 24 Feb 2022 11:24:10 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.8985.1645701850249991651 for ; Thu, 24 Feb 2022 03:24:10 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: peter.hoyes@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DC947106F; Thu, 24 Feb 2022 03:24:09 -0800 (PST) Received: from e125920.cambridge.arm.com (unknown [10.1.199.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5221F3F70D; Thu, 24 Feb 2022 03:24:09 -0800 (PST) From: Peter Hoyes To: meta-arm@lists.yoctoproject.org Cc: diego.sueiro@arm.com, Peter Hoyes Subject: [PATCH honister 8/8] arm-bsp/docs: Minor fvp-baser-aemv8r64 updates Date: Thu, 24 Feb 2022 11:22:44 +0000 Message-Id: <20220224112244.1521611-9-peter.hoyes@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224112244.1521611-1-peter.hoyes@arm.com> References: <20220224112244.1521611-1-peter.hoyes@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 24 Feb 2022 11:24:10 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/meta-arm/message/3056 From: Peter Hoyes * Add clarification on how to mount p9 device * Remove instruction to use ctrl + c to stop FVP * Add cache_state_modelled to Known Issues Issue-Id: SCM-3871 Signed-off-by: Peter Hoyes Change-Id: I122c5ae5b3ceee1d106205d93a006f75bdbfa2bf --- .../documentation/fvp-baser-aemv8r64.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/meta-arm-bsp/documentation/fvp-baser-aemv8r64.md b/meta-arm-bsp/documentation/fvp-baser-aemv8r64.md index 70256e0..98ede27 100644 --- a/meta-arm-bsp/documentation/fvp-baser-aemv8r64.md +++ b/meta-arm-bsp/documentation/fvp-baser-aemv8r64.md @@ -171,18 +171,11 @@ To run an image after the build is done with the Real-Time Linux kernel **Note:** The terminal console login is `root` without password. -To finish the fvp emulation, you need to close the telnet session and stop the -runfvp script: - -1. To close the telnet session: +To finish the fvp emulation, you need to close the telnet session: - Escape to telnet console with ``ctrl+]``. - Run ``quit`` to close the session. -2. To stop the runfvp: - - - Type ``ctrl+c`` and wait for kas process to finish. - ### File sharing between host and fvp It is possible to share a directory between the host machine and the fvp using the virtio P9 device component included in the kernel. To do so, create a @@ -195,6 +188,14 @@ launching the model: --parameter 'bp.virtiop9device.root_path=/path/to/host-mount-dir' +e.g. for the standard Linux kernel: + + kas shell --keep-config-unchanged \ + meta-arm/kas/fvp-baser-aemv8r64-bsp.yml \ + --command "../layers/meta-arm/scripts/runfvp \ + --console --parameter + 'bp.virtiop9device.root_path=/path/to/host-mount-dir'" + Once you are logged into the fvp, the host directory can be mounted in a directory on the model using the following command: @@ -216,6 +217,8 @@ Known Issues and Limitations - Only PSCI CPU\_ON and CPU\_OFF functions are supported - Linux kernel does not support booting from secure EL2 on Armv8-R AArch64 - Linux KVM does not support Armv8-R AArch64 +- Enabling the FVP parameter `cache_state_modelled` is incompatible with virtio + devices Change Log ----------