Re: [PATCH v2 00/21] sunxi: Introduce H616 support

2021-01-23 Thread Andre Przywara
On Mon, 11 Jan 2021 21:11:32 +0100
Jernej Skrabec  wrote:

Hi,

Jernej: many thanks for your work on this and your persistence!

Jaehoon, Samuel: thanks for the diligent review, that's much
appreciated and very helpful!

> This series introduces H616 support. Later patches add also OrangePi
> Zero2 support but since H616 DT is not merged into Linux yet, I don't
> expect them to land yet.
> 
> Most patches are ready to land, except those which depends on non-upstreamed
> DT yet.

So I put those patches (on top of other pending patches) in the sunxi
master branch, and plan to send a pull request early next week, after
doing some more tests. I took the preliminary DTs, I don't see the
point of waiting for Linux mainline acceptance at this stage of
development. Since this is a new SoC and board, we can update still
after the merge window.

Beside adding all the review tags, I also did minor changes that were
not worth the churn of a respin:
- patch 07/21: extend the comment
- patch 08/21: fix a rebase bug
- patch 12/21: use SUN50I_GEN_H6 instead of MACH_SUN50I_H6
- patch 13/21: drop from this version
- patch 15/21: drop for good, now redundant due to change in 12/21
- patch 16/21: use different base address as suggested by Samuel
- patch 17/21: drop from this version
- patch 18/21: update DT, drop EMAC compatible change
- patch 19/21: add -r-pinctrl name as well
- patch 20/21: fix compilation due to mainline change
- patch 21/21: update .dts, drop Ethernet support

So I dropped the Ethernet support for now, since this relies on some
yet unreviewed EMAC driver changes. Ideally we can still merge them
next week, shall we agree on them.

Jernej, please have a look at those changes and shout if you are not
happy with them! Otherwise I will push them, and we have till April to
iron out any leftover bugs.

https://gitlab.denx.de/u-boot/custodians/u-boot-sunxi/-/commits/master/

Cheers,
Andre

> 
> This series is based on u-boot-sunxi repo.
> 
> Please take a look.
> 
> Best regards,
> Jernej
> 
> Changes from v1:
> - collected tags
> - replaced AXP805 magic value with macro
> - fixed H6 build (missing symbols after refactoring)
> - removed premature SPI boot support
> - add missing peripherals to prcm map
> - reworked mmc sector calculation
> - fixed comment in clock function
> - used IS_ENABLED ternary instead of #if #else #endif
> - renamed DRAM struct field to more meaningful name
> - fixed missing space in Kconfig for DRAM symbol
> - removed unused macro from sunxi-u-boot.dtsi
> - removed padding definition for H616
> - added FEL support for H616
> - picked patches 1-2 from 
> https://patchwork.ozlabs.org/project/uboot/list/?series=223600
> - added mmc support for H616
> 
> Andre Przywara (4):
>   sunxi: support loading with SPL > 32KB
>   mmc: sunxi: Refactor mod clock register offset
>   net: sun8i-emac: Always clear syscon EPHY register
>   net: sun8i-emac: Determine pinmux based on SoC, not EMAC type
> 
> Jernej Skrabec (17):
>   sunxi: Add support for AXP305 PMIC
>   sunxi: Introduce common symbol for H6 like SoCs
>   mmc: sunxi: Replace H6 ifdefs with H6 gen macro
>   i2c: mvtwsi: sunxi: update macro
>   sunxi: prcm: Add memory map for H6 like SoCs
>   sunxi: Add support for I2C on H6 like SoCs
>   sunxi: introduce support for H616 clocks
>   sunxi: add support for H616 uart0
>   sunxi: add support for R_I2C on H616
>   sunxi: Add H616 DRAM support
>   sunxi: Add support for H616 SoC
>   mmc: sunxi: Add H616 clock offset
>   sunxi: Add H616 FEL support
>   arm: sunxi: add initial H616 DTSI and headers
>   sunxi: gpio: introduce compatible for H616
>   clk: sunxi: Add support for H616 clocks
>   sunxi: Add support for OrangePi Zero2
> 
>  arch/arm/cpu/armv8/fel_utils.S|5 +-
>  arch/arm/dts/Makefile |2 +
>  arch/arm/dts/sun50i-h616-orangepi-zero2.dts   |  240 
>  arch/arm/dts/sun50i-h616.dtsi |  716 
>  arch/arm/dts/sunxi-u-boot.dtsi|8 +
>  arch/arm/include/asm/arch-sunxi/boot0.h   |2 +-
>  arch/arm/include/asm/arch-sunxi/clock.h   |2 +-
>  .../include/asm/arch-sunxi/clock_sun50i_h6.h  |   19 +-
>  arch/arm/include/asm/arch-sunxi/cpu.h |2 +-
>  .../include/asm/arch-sunxi/cpu_sun50i_h6.h|7 +
>  arch/arm/include/asm/arch-sunxi/dram.h|2 +
>  .../include/asm/arch-sunxi/dram_sun50i_h616.h |  159 +++
>  arch/arm/include/asm/arch-sunxi/gpio.h|2 +
>  arch/arm/include/asm/arch-sunxi/mmc.h |2 +-
>  arch/arm/include/asm/arch-sunxi/prcm.h|  249 +---
>  arch/arm/include/asm/arch-sunxi/prcm_sun50i.h |   47 +
>  arch/arm/include/asm/arch-sunxi/prcm_sun6i.h  |  247 
>  arch/arm/include/asm/arch-sunxi/timer.h   |2 +-
>  arch/arm/mach-sunxi/Kconfig   |   75 +-
>  arch/arm/mach-sunxi/Makefile  |4 +-
>  arch/arm/mach-sunxi/board.c   |   24 +-
>  arch/arm/mach-sunxi/clock_sun50i_h6.c  

Re: [PATCH v2 21/21] sunxi: Add support for OrangePi Zero2

2021-01-23 Thread Andre Przywara
On Mon, 11 Jan 2021 21:11:53 +0100
Jernej Skrabec  wrote:

> OrangePi Zero2 is SBC based on Allwinner H616 with 1 GiB of RAM, SD card
> support, gigabit ethernet, micro HDMI, WIFI, Bluetooth and 1 USB 2.0
> port. It also has two GPIO headers which allows further peripherals to
> be used.
> 
> Device Tree file is taken from initial OrangePi Zero2 Linux submission
> and it's not yet merged.

Looks alright, the same story here with the DT. I updated to v3, with
the prospect of updating this later in the cycle when needed.

I dropped the Ethernet support from the defconfig for now, as I moved
the EMAC driver fixes out of this initial series. Ideally we can still
get them merged next week.

> 
> Signed-off-by: Jernej Skrabec 

Reviewed-by: Andre Przywara 

Cheers,
Andre

> ---
>  arch/arm/dts/Makefile   |   2 +
>  arch/arm/dts/sun50i-h616-orangepi-zero2.dts | 240 
>  board/sunxi/MAINTAINERS |   5 +
>  configs/orangepi_zero2_defconfig|  15 ++
>  4 files changed, 262 insertions(+)
>  create mode 100644 arch/arm/dts/sun50i-h616-orangepi-zero2.dts
>  create mode 100644 configs/orangepi_zero2_defconfig
> 
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index 1a62e4c0708a..ed6150dca38d 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -609,6 +609,8 @@ dtb-$(CONFIG_MACH_SUN50I_H6) += \
>   sun50i-h6-orangepi-lite2.dtb \
>   sun50i-h6-orangepi-one-plus.dtb \
>   sun50i-h6-pine-h64.dtb
> +dtb-$(CONFIG_MACH_SUN50I_H616) += \
> + sun50i-h616-orangepi-zero2.dtb
>  dtb-$(CONFIG_MACH_SUN50I) += \
>   sun50i-a64-amarula-relic.dtb \
>   sun50i-a64-bananapi-m64.dtb \
> diff --git a/arch/arm/dts/sun50i-h616-orangepi-zero2.dts 
> b/arch/arm/dts/sun50i-h616-orangepi-zero2.dts
> new file mode 100644
> index ..2afc036059b4
> --- /dev/null
> +++ b/arch/arm/dts/sun50i-h616-orangepi-zero2.dts
> @@ -0,0 +1,240 @@
> +// SPDX-License-Identifier: (GPL-2.0+ or MIT)
> +/*
> + * Copyright (C) 2020 Arm Ltd.
> + */
> +
> +/dts-v1/;
> +
> +#include "sun50i-h616.dtsi"
> +
> +#include 
> +#include 
> +#include 
> +
> +/ {
> + model = "OrangePi Zero2";
> + compatible = "xunlong,orangepi-zero2", "allwinner,sun50i-h616";
> +
> + aliases {
> + ethernet0 = 
> + serial0 = 
> + };
> +
> + chosen {
> + stdout-path = "serial0:115200n8";
> + };
> +
> + leds {
> + compatible = "gpio-leds";
> +
> + power {
> + function = LED_FUNCTION_POWER;
> + color = ;
> + gpios = < 2 12 GPIO_ACTIVE_HIGH>; /* PC12 */
> + default-state = "on";
> + };
> +
> + status {
> + function = LED_FUNCTION_STATUS;
> + color = ;
> + gpios = < 2 13 GPIO_ACTIVE_HIGH>; /* PC13 */
> + };
> + };
> +
> + reg_vcc5v: vcc5v {
> + /* board wide 5V supply directly from the USB-C socket */
> + compatible = "regulator-fixed";
> + regulator-name = "vcc-5v";
> + regulator-min-microvolt = <500>;
> + regulator-max-microvolt = <500>;
> + regulator-always-on;
> + };
> +
> + reg_usb1_vbus: usb1-vbus {
> + compatible = "regulator-fixed";
> + regulator-name = "usb1-vbus";
> + regulator-min-microvolt = <500>;
> + regulator-max-microvolt = <500>;
> + vin-supply = <_vcc5v>;
> + enable-active-high;
> + gpio = < 2 16 GPIO_ACTIVE_HIGH>; /* PC16 */
> + status = "okay";
> + };
> +};
> +
> + {
> + status = "okay";
> +};
> +
> + {
> + status = "okay";
> +};
> +
> +/* USB 2 & 3 are on headers only. */
> +
> + {
> + pinctrl-names = "default";
> + pinctrl-0 = <_rgmii_pins>;
> + phy-mode = "rgmii";
> + phy-handle = <_rgmii_phy>;
> + phy-supply = <_dcdce>;
> + allwinner,rx-delay-ps = <3100>;
> + allwinner,tx-delay-ps = <700>;
> + status = "okay";
> +};
> +
> + {
> + ext_rgmii_phy: ethernet-phy@1 {
> + compatible = "ethernet-phy-ieee802.3-c22";
> + reg = <1>;
> + };
> +};
> +
> + {
> + vmmc-supply = <_dcdce>;
> + cd-gpios = < 5 6 GPIO_ACTIVE_LOW>;  /* PF6 */
> + bus-width = <4>;
> + status = "okay";
> +};
> +
> + {
> + status = "okay";
> +};
> +
> + {
> + status = "okay";
> +};
> +
> +_i2c {
> + status = "okay";
> +
> + axp305: pmic@36 {
> + compatible = "x-powers,axp305", "x-powers,axp805",
> +  "x-powers,axp806";
> + reg = <0x36>;
> +
> + x-powers,self-working-mode;
> + vina-supply = <_vcc5v>;
> + vinb-supply = <_vcc5v>;
> + vinc-supply = <_vcc5v>;
> + vind-supply = <_vcc5v>;
> + vine-supply = 

Re: [PATCH v2 20/21] clk: sunxi: Add support for H616 clocks

2021-01-23 Thread Andre Przywara
On Mon, 11 Jan 2021 21:11:52 +0100
Jernej Skrabec  wrote:

> This commit introduces DM H616 clock driver.
> 
> Reviewed-by: Andre Przywara 
> Signed-off-by: Jernej Skrabec 
> ---
>  drivers/clk/sunxi/Kconfig|   7 ++
>  drivers/clk/sunxi/Makefile   |   1 +
>  drivers/clk/sunxi/clk_h616.c | 120 +++
>  3 files changed, 128 insertions(+)
>  create mode 100644 drivers/clk/sunxi/clk_h616.c
> 
> diff --git a/drivers/clk/sunxi/Kconfig b/drivers/clk/sunxi/Kconfig
> index 5ff101b99305..bf084fa7a84a 100644
> --- a/drivers/clk/sunxi/Kconfig
> +++ b/drivers/clk/sunxi/Kconfig
> @@ -79,6 +79,13 @@ config CLK_SUN50I_H6
> This enables common clock driver support for platforms based
> on Allwinner H6 SoC.
>  
> +config CLK_SUN50I_H616
> + bool "Clock driver for Allwinner H616"
> + default MACH_SUN50I_H616
> + help
> +   This enables common clock driver support for platforms based
> +   on Allwinner H616 SoC.
> +
>  config CLK_SUN50I_A64
>   bool "Clock driver for Allwinner A64"
>   default MACH_SUN50I
> diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
> index 36fb2aeb56c5..0dfc0593fb1c 100644
> --- a/drivers/clk/sunxi/Makefile
> +++ b/drivers/clk/sunxi/Makefile
> @@ -16,4 +16,5 @@ obj-$(CONFIG_CLK_SUN8I_V3S) += clk_v3s.o
>  obj-$(CONFIG_CLK_SUN9I_A80) += clk_a80.o
>  obj-$(CONFIG_CLK_SUN8I_H3) += clk_h3.o
>  obj-$(CONFIG_CLK_SUN50I_H6) += clk_h6.o
> +obj-$(CONFIG_CLK_SUN50I_H616) += clk_h616.o
>  obj-$(CONFIG_CLK_SUN50I_A64) += clk_a64.o
> diff --git a/drivers/clk/sunxi/clk_h616.c b/drivers/clk/sunxi/clk_h616.c
> new file mode 100644
> index ..e2e3a5c78c95
> --- /dev/null
> +++ b/drivers/clk/sunxi/clk_h616.c
> @@ -0,0 +1,120 @@
> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> +/*
> + * Copyright (C) 2021 Jernej Skrabec 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static struct ccu_clk_gate h616_gates[] = {
> + [CLK_BUS_MMC0]  = GATE(0x84c, BIT(0)),
> + [CLK_BUS_MMC1]  = GATE(0x84c, BIT(1)),
> + [CLK_BUS_MMC2]  = GATE(0x84c, BIT(2)),
> +
> + [CLK_BUS_UART0] = GATE(0x90c, BIT(0)),
> + [CLK_BUS_UART1] = GATE(0x90c, BIT(1)),
> + [CLK_BUS_UART2] = GATE(0x90c, BIT(2)),
> + [CLK_BUS_UART3] = GATE(0x90c, BIT(3)),
> + [CLK_BUS_UART4] = GATE(0x90c, BIT(4)),
> + [CLK_BUS_UART5] = GATE(0x90c, BIT(5)),
> +
> + [CLK_SPI0]  = GATE(0x940, BIT(31)),
> + [CLK_SPI1]  = GATE(0x944, BIT(31)),
> +
> + [CLK_BUS_SPI0]  = GATE(0x96c, BIT(0)),
> + [CLK_BUS_SPI1]  = GATE(0x96c, BIT(1)),
> +
> + [CLK_BUS_EMAC0] = GATE(0x97c, BIT(0)),
> + [CLK_BUS_EMAC1] = GATE(0x97c, BIT(1)),
> +
> + [CLK_USB_PHY0]  = GATE(0xa70, BIT(29)),
> + [CLK_USB_OHCI0] = GATE(0xa70, BIT(31)),
> +
> + [CLK_USB_PHY1]  = GATE(0xa74, BIT(29)),
> + [CLK_USB_OHCI1] = GATE(0xa74, BIT(31)),
> +
> + [CLK_USB_PHY2]  = GATE(0xa78, BIT(29)),
> + [CLK_USB_OHCI2] = GATE(0xa78, BIT(31)),
> +
> + [CLK_USB_PHY3]  = GATE(0xa7c, BIT(29)),
> + [CLK_USB_OHCI3] = GATE(0xa7c, BIT(31)),
> +
> + [CLK_BUS_OHCI0] = GATE(0xa8c, BIT(0)),
> + [CLK_BUS_OHCI1] = GATE(0xa8c, BIT(1)),
> + [CLK_BUS_OHCI2] = GATE(0xa8c, BIT(2)),
> + [CLK_BUS_OHCI3] = GATE(0xa8c, BIT(3)),
> + [CLK_BUS_EHCI0] = GATE(0xa8c, BIT(4)),
> + [CLK_BUS_EHCI1] = GATE(0xa8c, BIT(5)),
> + [CLK_BUS_EHCI2] = GATE(0xa8c, BIT(6)),
> + [CLK_BUS_EHCI3] = GATE(0xa8c, BIT(7)),
> + [CLK_BUS_OTG]   = GATE(0xa8c, BIT(8)),
> +};
> +
> +static struct ccu_reset h616_resets[] = {
> + [RST_BUS_MMC0]  = RESET(0x84c, BIT(16)),
> + [RST_BUS_MMC1]  = RESET(0x84c, BIT(17)),
> + [RST_BUS_MMC2]  = RESET(0x84c, BIT(18)),
> +
> + [RST_BUS_UART0] = RESET(0x90c, BIT(16)),
> + [RST_BUS_UART1] = RESET(0x90c, BIT(17)),
> + [RST_BUS_UART2] = RESET(0x90c, BIT(18)),
> + [RST_BUS_UART3] = RESET(0x90c, BIT(19)),
> + [RST_BUS_UART4] = RESET(0x90c, BIT(20)),
> + [RST_BUS_UART5] = RESET(0x90c, BIT(21)),
> +
> + [RST_BUS_SPI0]  = RESET(0x96c, BIT(16)),
> + [RST_BUS_SPI1]  = RESET(0x96c, BIT(17)),
> +
> + [RST_BUS_EMAC0] = RESET(0x97c, BIT(16)),
> + [RST_BUS_EMAC1] = RESET(0x97c, BIT(17)),
> +
> + [RST_USB_PHY0]  = RESET(0xa70, BIT(30)),
> +
> + [RST_USB_PHY1]  = RESET(0xa74, BIT(30)),
> +
> + [RST_USB_PHY2]  = RESET(0xa78, BIT(30)),
> +
> + [RST_USB_PHY3]  = RESET(0xa7c, BIT(30)),
> +
> + [RST_BUS_OHCI0] = RESET(0xa8c, BIT(16)),
> + [RST_BUS_OHCI1] = RESET(0xa8c, BIT(17)),
> + 

Re: [PATCH v2 18/21] arm: sunxi: add initial H616 DTSI and headers

2021-01-23 Thread Andre Przywara
On Mon, 11 Jan 2021 21:11:50 +0100
Jernej Skrabec  wrote:

Hi,

> This commit introduces H616 DTSI file and dt-bindings headers needed for
> device tree files.
> 
> Files are taken from initial Linux H616 support submission with minor
> change - emac0 fallback has H6 compatible instead of A64, otherwise
> network doesn't work. H616 DTSI is not merged upstream yet.

So I updated to this the the v3 version, putting a link in the commit
message. Also I dropped the emac compatible change, this should be
covered by a U-Boot driver fix (which I will repost shortly).

Regarding the preliminary nature of the DT: This is probably the best we
can get now, so I don't want to block U-Boot support on the Linux DT
acceptance at this stage of development. U-Boot support is also crucial
for kernel development and testing, so this is somewhat of a chicken-egg
problem. We can update the U-Boot DTs at any time later.

> Signed-off-by: Jernej Skrabec 

Confirmed to be the version from the Linux patches, so:

Reviewed-by: Andre Przywara 

Cheers,
Andre

> ---
>  arch/arm/dts/sun50i-h616.dtsi   | 716 
>  include/dt-bindings/clock/sun50i-h616-ccu.h | 115 
>  include/dt-bindings/reset/sun50i-h616-ccu.h |  70 ++
>  3 files changed, 901 insertions(+)
>  create mode 100644 arch/arm/dts/sun50i-h616.dtsi
>  create mode 100644 include/dt-bindings/clock/sun50i-h616-ccu.h
>  create mode 100644 include/dt-bindings/reset/sun50i-h616-ccu.h
> 
> diff --git a/arch/arm/dts/sun50i-h616.dtsi b/arch/arm/dts/sun50i-h616.dtsi
> new file mode 100644
> index ..d416e9a3d3e6
> --- /dev/null
> +++ b/arch/arm/dts/sun50i-h616.dtsi
> @@ -0,0 +1,716 @@
> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> +// Copyright (C) 2020 Arm Ltd.
> +// based on the H6 dtsi, which is:
> +//   Copyright (C) 2017 Icenowy Zheng 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/ {
> + interrupt-parent = <>;
> + #address-cells = <2>;
> + #size-cells = <2>;
> +
> + cpus {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + cpu0: cpu@0 {
> + compatible = "arm,cortex-a53";
> + device_type = "cpu";
> + reg = <0>;
> + enable-method = "psci";
> + clocks = < CLK_CPUX>;
> + };
> +
> + cpu1: cpu@1 {
> + compatible = "arm,cortex-a53";
> + device_type = "cpu";
> + reg = <1>;
> + enable-method = "psci";
> + clocks = < CLK_CPUX>;
> + };
> +
> + cpu2: cpu@2 {
> + compatible = "arm,cortex-a53";
> + device_type = "cpu";
> + reg = <2>;
> + enable-method = "psci";
> + clocks = < CLK_CPUX>;
> + };
> +
> + cpu3: cpu@3 {
> + compatible = "arm,cortex-a53";
> + device_type = "cpu";
> + reg = <3>;
> + enable-method = "psci";
> + clocks = < CLK_CPUX>;
> + };
> + };
> +
> + reserved-memory {
> + #address-cells = <2>;
> + #size-cells = <2>;
> + ranges;
> +
> + /* 512KiB reserved for ARM Trusted Firmware (BL31) */
> + secmon_reserved: secmon@4000 {
> + reg = <0x0 0x4000 0x0 0x8>;
> + no-map;
> + };
> + };
> +
> + osc24M: osc24M_clk {
> + #clock-cells = <0>;
> + compatible = "fixed-clock";
> + clock-frequency = <2400>;
> + clock-output-names = "osc24M";
> + };
> +
> + pmu {
> + compatible = "arm,cortex-a53-pmu";
> + interrupts = ,
> +  ,
> +  ,
> +  ;
> + interrupt-affinity = <>, <>, <>, <>;
> + };
> +
> + psci {
> + compatible = "arm,psci-0.2";
> + method = "smc";
> + };
> +
> + timer {
> + compatible = "arm,armv8-timer";
> + arm,no-tick-in-suspend;
> + interrupts =  + (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>,
> +   + (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>,
> +   + (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>,
> +   + (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>;
> + };
> +
> + soc {
> + compatible = "simple-bus";
> + #address-cells = <1>;
> + #size-cells = <1>;
> + ranges = <0x0 0x0 0x0 0x4000>;
> +
> + syscon: syscon@300 {
> + compatible = 

Re: [PATCH 04/11] pinctrl: single: get register area size by device API

2021-01-23 Thread Simon Glass
Hi Dario,

On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> Use dev_read_addr_size to get size of the controller's register area.
>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 9 +++--
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pinctrl/pinctrl-single.c 
> b/drivers/pinctrl/pinctrl-single.c
> index cec00e289c..c80a42a193 100644
> --- a/drivers/pinctrl/pinctrl-single.c
> +++ b/drivers/pinctrl/pinctrl-single.c
> @@ -182,17 +182,14 @@ static int single_set_state(struct udevice *dev,
>  static int single_of_to_plat(struct udevice *dev)
>  {
> fdt_addr_t addr;
> -   u32 of_reg[2];
> -   int res;
> +   fdt_size_t size;
> struct single_pdata *pdata = dev_get_plat(dev);
>
> pdata->width =
> dev_read_u32_default(dev, "pinctrl-single,register-width", 0);
>
> -   res = dev_read_u32_array(dev, "reg", of_reg, 2);
> -   if (res)
> -   return res;
> -   pdata->offset = of_reg[1] - pdata->width / 8;
> +   dev_read_addr_size(dev, "reg", );

Please check return value.

> +   pdata->offset = size - pdata->width / BITS_PER_BYTE;
>
> addr = dev_read_addr(dev);
> if (addr == FDT_ADDR_T_NONE) {
> --
> 2.17.1
>

Regards,
Simon


Re: [RFC PATCH] arm: EFI: Disallow EFI bootmgr when providing PSCI

2021-01-23 Thread Simon Glass
On Fri, 22 Jan 2021 at 05:05, Andre Przywara  wrote:
>
> When "bootefi bootmgr" is run, it switches the CPU into non-secure
> state. This breaks platforms like 32-bit Allwinner boards that rely on
> running in secure state until late in the process, when they install
> the PSCI handler in secure memory and drop into non-secure state.
> They hang just before entering the kernel, after the "Starting the
> kernel" message.
>
> Commit f3866909e350 ("distro_bootcmd: call EFI bootmgr even without
> having /EFI/boot") changed the order of EFI probing, so the EFI bootmgr
> is now *always* run, resulting in the default distro boot commands now
> *always* failing, even in the total absence of any UEFI directories or
> boot files.
>
> So use the newly added build option to disable the EFI bootmgr, which
> makes those boards boot again using the distro boot commands.
> Explicitly calling "bootefi bootmgr" still breaks the boot, though.
>
> Signed-off-by: Andre Przywara 
> Reported-by: Jernej Skrabec 
> ---
> Hi,
>
> the above is the result of my analysis, happy to stand corrected in
> case I missed something. I know that this is not a proper solution,
> but it's an effective stop-gap measure to fix all those boards. It looks
> like a proper solution would either be:
> - Let the EFI bootmgr run in the current security state.
> - Install the PSCI handlers early in U-Boot.
>
> Both solutions sound rather involved, so probably require more time.
> But we need to fix this breakage now.
>
> Cheers,
> Andre
>
>  lib/efi_loader/Kconfig | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 


Re: [PATCH] cmd: misc: Fix return value for the sleep command

2021-01-23 Thread Simon Glass
On Fri, 22 Jan 2021 at 04:27, Marek Szyprowski  wrote:
>
> If sleeping has been interrupted, return CMD_RET_FAILURE instead of -1
> (CMD_RET_USAGE).
>
> Signed-off-by: Marek Szyprowski 
> ---
>  cmd/sleep.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH v3 01/20] mmc: sdhci: Add helper functions for UHS modes

2021-01-23 Thread Simon Glass
Hi Aswath,

On Thu, 21 Jan 2021 at 05:41, Aswath Govindraju  wrote:
>
> From: Faiz Abbas 
>
> Add a set_voltage() function which handles the switch from 3.3V to 1.8V
> for SD card UHS modes.
>
> Signed-off-by: Faiz Abbas 
> Signed-off-by: Aswath Govindraju 
> ---
>  drivers/mmc/sdhci.c | 80 +
>  include/sdhci.h |  1 +
>  2 files changed, 81 insertions(+)
>
> diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
> index 06289343124e..e7e3e22d1a7e 100644
> --- a/drivers/mmc/sdhci.c
> +++ b/drivers/mmc/sdhci.c
> @@ -20,6 +20,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  static void sdhci_reset(struct sdhci_host *host, u8 mask)
>  {
> @@ -509,6 +510,85 @@ void sdhci_set_uhs_timing(struct sdhci_host *host)
> sdhci_writew(host, reg, SDHCI_HOST_CONTROL2);
>  }
>
> +#if CONFIG_IS_ENABLED(MMC_IO_VOLTAGE)
> +static void sdhci_set_voltage(struct sdhci_host *host)
> +{
> +   struct mmc *mmc = (struct mmc *)host->mmc;
> +   u32 ctrl;
> +   int ret;
> +
> +   ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
> +
> +   switch (mmc->signal_voltage) {
> +   case MMC_SIGNAL_VOLTAGE_330:
> +#if CONFIG_IS_ENABLED(DM_REGULATOR)

Can you use if(), please? You should see a patman warning about this.

> +   if (mmc->vqmmc_supply) {
> +   ret = regulator_set_enable(mmc->vqmmc_supply, false);
> +   if (ret) {
> +   pr_err("failed to disable vqmmc-supply: 
> %d\n", ret);
> +   return;
> +   }
> +
> +   ret = regulator_set_value(mmc->vqmmc_supply, 330);
> +   if (ret) {
> +   pr_err("failed to set vqmmc-voltage to 3.3V: 
> %d\n", ret);
> +   return;
> +   }
> +
> +   ret = regulator_set_enable(mmc->vqmmc_supply, true);
> +   if (ret) {
> +   pr_err("failed to enable vqmmc-supply: %d\n", 
> ret);
> +   return;
> +   }
> +   }
> +#endif
> +   mdelay(5);
> +   if (IS_SD(mmc)) {
> +   ctrl &= ~SDHCI_CTRL_VDD_180;
> +   sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
> +   }
> +   break;
> +   case MMC_SIGNAL_VOLTAGE_180:
> +#if CONFIG_IS_ENABLED(DM_REGULATOR)
> +   if (mmc->vqmmc_supply) {
> +   regulator_set_enable(mmc->vqmmc_supply, false);
> +   if (ret) {
> +   pr_err("failed to disable vqmmc-supply: 
> %d\n", ret);
> +   return;
> +   }
> +
> +   regulator_set_value(mmc->vqmmc_supply, 180);
> +   if (ret) {
> +   pr_err("failed to set vqmmc-voltage to 1.8V: 
> %d\n", ret);
> +   return;
> +   }
> +
> +   regulator_set_enable(mmc->vqmmc_supply, true);
> +   if (ret) {
> +   pr_err("failed to enable vqmmc-supply: %d\n", 
> ret);
> +   return;
> +   }
> +   }
> +#endif
> +   if (IS_SD(mmc)) {
> +   ctrl |= SDHCI_CTRL_VDD_180;
> +   sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
> +   }
> +   break;
> +   default:
> +   /* No signal voltage switch required */
> +   return;
> +   }
> +}
> +#else
> +static void sdhci_set_voltage(struct sdhci_host *host) { }
> +#endif
> +void sdhci_set_control_reg(struct sdhci_host *host)
> +{
> +   sdhci_set_voltage(host);
> +   sdhci_set_uhs_timing(host);
> +}
> +
>  #ifdef CONFIG_DM_MMC
>  static int sdhci_set_ios(struct udevice *dev)
>  {
> diff --git a/include/sdhci.h b/include/sdhci.h
> index 3e5a64981857..0f820c6d2669 100644
> --- a/include/sdhci.h
> +++ b/include/sdhci.h
> @@ -491,6 +491,7 @@ void sdhci_set_uhs_timing(struct sdhci_host *host);
>  /* Export the operations to drivers */
>  int sdhci_probe(struct udevice *dev);
>  int sdhci_set_clock(struct mmc *mmc, unsigned int clock);
> +void sdhci_set_control_reg(struct sdhci_host *host);

This needs a comment. What does it do?

>  extern const struct dm_mmc_ops sdhci_ops;
>  #else
>  #endif
> --
> 2.17.1
>

Regards,
Simon


Re: [PATCH 02/11] pinctrl: single: fix the loop counter variable type

2021-01-23 Thread Simon Glass
On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> The patch changes the variable 'n' type from phys_addr_t to int.

s/The patch changes/Change/

>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pinctrl/pinctrl-sing

Reviewed-by: Simon Glass 


Re: [PATCH] test: unit test for echo command

2021-01-23 Thread Simon Glass
On Thu, 21 Jan 2021 at 10:48, Heinrich Schuchardt  wrote:
>
> Provide a unit test for the unit command
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  test/cmd/Makefile|  3 +++
>  test/cmd/test_echo.c | 57 
>  2 files changed, 60 insertions(+)
>  create mode 100644 test/cmd/test_echo.c

Reviewed-by: Simon Glass 


Re: [PATCH 2/7] global_data.h: Change ram_top type to phys_addr_t

2021-01-23 Thread Simon Glass
On Thu, 21 Jan 2021 at 08:00, Bin Meng  wrote:
>
> From: Bin Meng 
>
> It's possible to have ram_top above 4 GiB in a 32-bit system, hence
> we need to declare ram_top as `phys_addr_t`.
>
> Signed-off-by: Bin Meng 
> ---
>
>  include/asm-generic/global_data.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH] lib: rsa: rsa-verify: don't look for keys in the FIT image

2021-01-23 Thread Simon Glass
Hi ,

On Tue, 12 Jan 2021 at 11:19, Philippe Reynes
 wrote:
>
> In the function rsa_verify_hash, if the "main" key doesn't
> work, u-boot try others keys. But it searches those keys
> in the FIT image instead of the u-boot device tree.
>
> Signed-off-by: Philippe Reynes 
> ---
>  lib/rsa/rsa-verify.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c
> index 0ab0f629d0..e34d3293d1 100644
> --- a/lib/rsa/rsa-verify.c
> +++ b/lib/rsa/rsa-verify.c
> @@ -522,10 +522,10 @@ int rsa_verify_hash(struct image_sign_info *info,
> return ret;
>
> /* No luck, so try each of the keys in turn */
> -   for (ndepth = 0, noffset = fdt_next_node(info->fit, sig_node,
> +   for (ndepth = 0, noffset = fdt_next_node(blob, sig_node,
>  );
>  (noffset >= 0) && (ndepth > 0);
> -noffset = fdt_next_node(info->fit, noffset, )) {
> +noffset = fdt_next_node(blob, noffset, )) {
> if (ndepth == 1 && noffset != node) {
> ret = rsa_verify_with_keynode(info, hash,
>   sig, sig_len,

Reviewed-by: Simon Glass 

But I wonder how this is not caught by tests? Can you look into that
please? We are obviously missing a test case.


 - Simon


Re: [PATCH 1/1] doc: document echo command

2021-01-23 Thread Simon Glass
On Thu, 21 Jan 2021 at 10:55, Heinrich Schuchardt  wrote:
>
> Provide a man-page for the echo command.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  doc/usage/echo.rst  | 65 +
>  doc/usage/index.rst |  1 +
>  2 files changed, 66 insertions(+)
>  create mode 100644 doc/usage/echo.rst
>
Reviewed-by: Simon Glass 


Re: [PATCH 11/11] test: pinmux: add test for 'pinctrl-single' driver

2021-01-23 Thread Simon Glass
On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> The test adds two pinmux nodes to the device tree, one to test when a
> register changes only one pin's mux (pinctrl-single,pins), and the other
> to test when more than one pin's mux is changed (pinctrl-single,bits).
> This required replacing the controller's register access functions when
> the driver is used on sandbox.
>
> Signed-off-by: Dario Binacchi 
>
> ---
>
>  arch/sandbox/dts/test.dts| 65 +
>  configs/sandbox_defconfig|  1 +
>  drivers/pinctrl/pinctrl-single.c | 62 +++-
>  test/dm/pinmux.c | 81 ++--
>  4 files changed, 193 insertions(+), 16 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 05/11] pinctrl: single: check "register-width" DT property

2021-01-23 Thread Simon Glass
Hi Dario,

On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> In more recent versions of the Linux kernel the driver's probe function
> returns an error if the "pinctrl-single,register-width" DT property is
> missing. The lack of this information, in fact, does not allow to know
> whether to access the registers of the controller at 8, 16 or 32 bits.

"Update it to ..."

>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 10 +++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>

Reviewed-by: Simon Glass 

Consider updating the pinctrl tests for this.


Re: [PATCH 10/11] pinctrl: single: add get_pin_muxing operation

2021-01-23 Thread Simon Glass
Hi Dario,

On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> It allows to display the muxing of a given pin. Inspired by more recent
> versions of the Linux driver, in addition to the address and the value
> of the configuration register I added the pin function retrieved from
> the DT. In doing so, the information displayed does not depend on the
> platform, being a generic type driver, and it can be useful for debug
> purposes.
>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 220 +--
>  1 file changed, 211 insertions(+), 9 deletions(-)

Do we need an updated DT binding file?

Regards,
Simon


Re: [PATCH 08/11] pinctrl: single: add get_pins_count operation

2021-01-23 Thread Simon Glass
On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> It returns the number of selectable pins.
>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 22 ++
>  1 file changed, 22 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH 09/11] pinctrl: single: add get_pin_name operation

2021-01-23 Thread Simon Glass
On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> It returns the name of the requested pin.
>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 16 
>  1 file changed, 16 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH 07/11] pinctrl: single: use function pointer for register access

2021-01-23 Thread Simon Glass
Hi Dario,

On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> The patch allows you to call the read/write functions set during probing
> without having to check the type of access at runtime. It also adds
> functions for 8-bit registers access.
>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 98 
>  1 file changed, 73 insertions(+), 25 deletions(-)

I'm not really keen on this. A switch() statement is not expensive and
function pointers add indirection/confusion and use more space.

Regards,
Simon


Re: [PATCH 01/11] pinctrl: single: fix format of structure documentation

2021-01-23 Thread Simon Glass
On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> U-Boot adopted the kernel-doc annotation style.
>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 45 +---
>  1 file changed, 36 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 03/11] pinctrl: single: fix debug messages formatting

2021-01-23 Thread Simon Glass
Hi Dario,

On Sat, 23 Jan 2021 at 11:27, Dario Binacchi  wrote:
>
> The printf '%pa' format specifier appends the '0x' prefix to the
> displayed address. Furthermore, the offset variable is displayed with
> the '%x' format specifier instead of '%pa'.

Please start your commit message with the problem and then describe
what your patch does. It is unclear from this commit message why we
need this patch :-)
>
> Signed-off-by: Dario Binacchi 
> ---
>
>  drivers/pinctrl/pinctrl-single.c | 28 
>  1 file changed, 16 insertions(+), 12 deletions(-)

Regards,
Simon


Re: [PATCH 1/1] doc: describe loady command

2021-01-23 Thread Simon Glass
On Fri, 22 Jan 2021 at 11:20, Heinrich Schuchardt  wrote:
>
> Create a man-page for the loady command.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  doc/usage/index.rst |  1 +
>  doc/usage/loady.rst | 67 +
>  2 files changed, 68 insertions(+)
>  create mode 100644 doc/usage/loady.rst
>

Reviewed-by: Simon Glass 


Re: [PATCH 4/7] fdtdec: Cast prior_stage_fdt_address with uintptr_t

2021-01-23 Thread Simon Glass
On Thu, 21 Jan 2021 at 08:01, Bin Meng  wrote:
>
> From: Bin Meng 
>
> At present prior_stage_fdt_address is declared as phys_addr_t. On
> a 32-bit platform where phys_addr_t can be 64-bit, assigning its
> value to gd->fdt_blob which is a pointer, can cause warnings.
>
> Cast it to uintptr_t before the assignment.
>
> Signed-off-by: Bin Meng 
> ---
>
>  lib/fdtdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

The prior-stage stuff should be modified to use SPL_HANDOFF


Re: [PATCH] dm: replace auto_alloc_size with auto

2021-01-23 Thread Simon Glass
On Sat, 23 Jan 2021 at 11:49, Dario Binacchi  wrote:
>
> The auto_alloc_size members of struct driver has been renamed auto.
>
> Signed-off-by: Dario Binacchi 
> ---
>
>  include/dm/device.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH 2/2] console: Don't start/stop console if stdio device invalid

2021-01-23 Thread Simon Glass
On Wed, 20 Jan 2021 at 07:05, Nicolas Saenz Julienne
 wrote:
>
> Don't start/stop an stdio device that might have been already freed.
>
> Signed-off-by: Nicolas Saenz Julienne 
> Fixes: 70c2525c0d3c ("IOMUX: Stop dropped consoles")
> ---
>  common/console.c | 3 +++
>  1 file changed, 3 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH 1/2] stdio: Introduce stdio_valid()

2021-01-23 Thread Simon Glass
Hi Nicolas,

On Wed, 20 Jan 2021 at 07:05, Nicolas Saenz Julienne
 wrote:
>
> stdio_valid() will confirm that a struct stdio_dev pointer is indeed
> valid.
>
> Signed-off-by: Nicolas Saenz Julienne 
> ---
>  common/stdio.c  | 11 +++
>  include/stdio_dev.h |  1 +
>  2 files changed, 12 insertions(+)
>
> diff --git a/common/stdio.c b/common/stdio.c
> index abf9b1e915..69b7d2692d 100644
> --- a/common/stdio.c
> +++ b/common/stdio.c
> @@ -157,6 +157,17 @@ static int stdio_probe_device(const char *name, enum 
> uclass_id id,
> return 0;
>  }
>
> +bool stdio_valid(struct stdio_dev *dev)
> +{
> +   struct stdio_dev *sdev;
> +
> +   list_for_each_entry(sdev, , list)
> +   if (sdev == dev)
> +   return true;
> +
> +   return false;
> +}
> +
>  struct stdio_dev *stdio_get_by_name(const char *name)
>  {
> struct list_head *pos;
> diff --git a/include/stdio_dev.h b/include/stdio_dev.h
> index 48871a6a22..f341439b03 100644
> --- a/include/stdio_dev.h
> +++ b/include/stdio_dev.h
> @@ -97,6 +97,7 @@ int stdio_deregister_dev(struct stdio_dev *dev, int force);
>  struct list_head *stdio_get_list(void);
>  struct stdio_dev *stdio_get_by_name(const char *name);
>  struct stdio_dev *stdio_clone(struct stdio_dev *dev);
> +bool stdio_valid(struct stdio_dev *dev);

Please add a full function comment and explain what valid means.

>
>  int drv_lcd_init(void);
>  int drv_video_init(void);
> --
> 2.30.0
>

Regards,
Simon


Booting on PX30

2021-01-23 Thread Piotr Lobacz
Hi all,
In our company we have a board which was made for us by Liteon with PX30
chip on it. It boots with miniloader and uboot.img along with trust.img. The
problem is that i wanted to boot it up using TPL/SPL images and it doesn't
boot. With uboot source code which was given to us it prints for me just
these lines:

U-Boot TPL 2017.09-g05c644bda3-dirty (Jan 23 2021 - 00:13:09)
DDR V1.15 dll en dbg
D3,1024MB,333MHz
bw  col bk  row cs  dbw
32  10  8   15  1   16
OUT

The same is with the newest one

U-Boot TPL board init
DDR3, 333MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS=1 Die BW=16 Size=1024MB
out

And nothing else happens. Am i something missing? I'm sorry for a newbie
question, but i have not a big experience in this matter.

Thanks for any help you can provide.

Regards,
Peter



--
Sent from: http://u-boot.10912.n7.nabble.com/


Re: Sync include/linux/*.h from kernel

2021-01-23 Thread Tom Rini
On Fri, Jan 22, 2021 at 09:22:14AM +, Peng Fan (OSS) wrote:

> All,
> 
> Do we need to sync the header files under
> include/linux/*.h from Linux Kernel?
> 
> Seems many files are out of date and Linux
> Kernel changed a lot, such as linkage.h.

Yes, we need to sync various files more often.  In the case of
linkage.h, it's not part of kconfig/kbuild/et al, so it would be a
matter of copying the relevant files from say v5.10 or and fixing all of
the fall-out.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] net: fec: Get rid of FEC_ENET_ENABLE_[TR]XC_DELAY

2021-01-23 Thread Stefano Babic

Hi Marek,

On 23.01.21 20:57, Marek Vasut wrote:

On 1/23/21 8:54 PM, sba...@denx.de wrote:

The FEC_ENET_ENABLE_.XC_DELAY setting is only used by one system which
supports OF control, correctly set the rgmii-id PHY mode in the DT and
then determine whether or not to enable the FEC RXC/TXC internal delay
based on the PHY mode.


[...]


Applied to u-boot-imx, master, thanks !


Didn't this fail to build on mx25 ?


Yes, sorry, this is a false positive - patch has not been applied.

Regards,
Stefano


Re: [PATCH 3/4] usb: musb: Fix handling interrupts for EP0 and SET ADDRESS commmand

2021-01-23 Thread Pali Rohár
On Saturday 23 January 2021 22:23:10 Lukasz Majewski wrote:
> Hi Pali,
> 
> > On Saturday 23 January 2021 16:16:11 Lukasz Majewski wrote:
> > > Hi Pali,
> > >   
> > > > Interrupt for EP0 is indicated in intrtx register via first bit.
> > > > It is set for both RX and TX. First bit in intrrx register is
> > > > reserved and not set.
> > > > 
> > > > So remove calling musb_peri_ep0() function at every iteration of
> > > > udc_irq() and musb_peri_rx() and call it only from musb_peri_tx()
> > > > when correct interrupt bit in initrtx it set.
> > > > 
> > > > Address from SET ADDRESS command must be set to faddr register
> > > > only after acknowledging SERV_RXPKTRDY followed by received EP0
> > > > interrupt. So prior calling musb_peri_ep0_set_address() check for
> > > > EP0 interrupt instead of (incorrect) MUSB_INTR_SOF interrupt.
> > > > 
> > > > This patch fixes issue that host (computer) cannot register
> > > > U-Boot USB device and failing with errors:
> > > > 
> > > > usb 1-1: new full-speed USB device number 86 using xhci_hcd
> > > > usb 1-1: Device not responding to setup address.
> > > > usb 1-1: Device not responding to setup address.
> > > > usb 1-1: device not accepting address 86, error -71
> > > > 
> > > > U-Boot was writing address to faddr register too early and did not
> > > > wait for correct interrupt after which should update address.
> > > > 
> > > > Signed-off-by: Pali Rohár 
> > > > ---
> > > >  drivers/usb/musb/musb_udc.c | 12 
> > > >  1 file changed, 4 insertions(+), 8 deletions(-)
> > > > 
> > > > diff --git a/drivers/usb/musb/musb_udc.c
> > > > b/drivers/usb/musb/musb_udc.c index 7c74422623..50d8bc319c 100644
> > > > --- a/drivers/usb/musb/musb_udc.c
> > > > +++ b/drivers/usb/musb/musb_udc.c
> > > > @@ -707,9 +707,7 @@ static void musb_peri_rx(u16 intr)
> > > >  {
> > > > unsigned int ep;
> > > >  
> > > > -   /* Check for EP0 */
> > > > -   if (0x01 & intr)
> > > > -   musb_peri_ep0();
> > > > +   /* First bit is reserved and does not indicate interrupt
> > > > for EP0 */ 
> > > > for (ep = 1; ep < 16; ep++) {
> > > > if ((1 << ep) & intr)
> > > > @@ -721,9 +719,9 @@ static void musb_peri_tx(u16 intr)
> > > >  {
> > > > unsigned int ep;
> > > >  
> > > > -   /* Check for EP0 */
> > > > +   /* Check for EP0: first bit indicates interrupt for both
> > > > RX and TX */ if (0x01 & intr)
> > > > -   musb_peri_ep0_tx();
> > > > +   musb_peri_ep0();
> > > >  
> > > > for (ep = 1; ep < 16; ep++) {
> > > > if ((1 << ep) & intr)
> > > > @@ -750,8 +748,6 @@ void udc_irq(void)
> > > > musb_peri_resume();
> > > > }
> > > >  
> > > > -   musb_peri_ep0();
> > > > -
> > > > if (MUSB_INTR_RESET & intrusb) {
> > > > usbd_device_event_irq(udc_device,
> > > > DEVICE_RESET, 0); musb_peri_reset();
> > > > @@ -790,7 +786,7 @@ void udc_irq(void)
> > > > if (intrtx)
> > > > musb_peri_tx(intrtx);
> > > > } else {
> > > > -   if (MUSB_INTR_SOF & intrusb) {
> > > > +   if (readw(>intrtx) & 0x1) {
> > > > u8 faddr;
> > > > faddr = readb(>faddr);
> > > > /*  
> > > 
> > > Applying this patch causes error. Could you rebase your work on
> > > newest master (after onging PR is accepted).  
> > 
> > Hello! This patch series is rebased on top of the another patch series
> > "Nokia RX-51: Fix USB TTY console and enable it" as it depends on it.
> 
> I took this patch series as they were queued in patchwork.

I have wrote this information also into the cover letter of this patch
series that it depends on another set.

> > So I cannot rebase it on top of master as it would not work.
> > 
> > Nokia RX-51: Fix USB TTY console and enable it:
> > <20201129164618.5829-1-p...@kernel.org>
> > https://lists.denx.de/pipermail/u-boot/2020-November/433728.html
> 
> Those were delegated to Marek, and are not yet in his tree
> (-master/-next).
> 
> Ok. I will wait for them to be pulled.
> 
> > 
> > > Thanks in advance and sorry for delay.
> > > 
> > > 
> > > Best regards,
> > > 
> > > Lukasz Majewski
> > > 
> > > --
> > > 
> > > DENX Software Engineering GmbH,  Managing Director: Wolfgang
> > > Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell,
> > > Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> > > lu...@denx.de  
> > 
> > 
> 
> 
> 
> 
> Best regards,
> 
> Lukasz Majewski
> 
> --
> 
> DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de




Re: [PATCH 3/4] usb: musb: Fix handling interrupts for EP0 and SET ADDRESS commmand

2021-01-23 Thread Lukasz Majewski
Hi Pali,

> On Saturday 23 January 2021 16:16:11 Lukasz Majewski wrote:
> > Hi Pali,
> >   
> > > Interrupt for EP0 is indicated in intrtx register via first bit.
> > > It is set for both RX and TX. First bit in intrrx register is
> > > reserved and not set.
> > > 
> > > So remove calling musb_peri_ep0() function at every iteration of
> > > udc_irq() and musb_peri_rx() and call it only from musb_peri_tx()
> > > when correct interrupt bit in initrtx it set.
> > > 
> > > Address from SET ADDRESS command must be set to faddr register
> > > only after acknowledging SERV_RXPKTRDY followed by received EP0
> > > interrupt. So prior calling musb_peri_ep0_set_address() check for
> > > EP0 interrupt instead of (incorrect) MUSB_INTR_SOF interrupt.
> > > 
> > > This patch fixes issue that host (computer) cannot register
> > > U-Boot USB device and failing with errors:
> > > 
> > > usb 1-1: new full-speed USB device number 86 using xhci_hcd
> > > usb 1-1: Device not responding to setup address.
> > > usb 1-1: Device not responding to setup address.
> > > usb 1-1: device not accepting address 86, error -71
> > > 
> > > U-Boot was writing address to faddr register too early and did not
> > > wait for correct interrupt after which should update address.
> > > 
> > > Signed-off-by: Pali Rohár 
> > > ---
> > >  drivers/usb/musb/musb_udc.c | 12 
> > >  1 file changed, 4 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/drivers/usb/musb/musb_udc.c
> > > b/drivers/usb/musb/musb_udc.c index 7c74422623..50d8bc319c 100644
> > > --- a/drivers/usb/musb/musb_udc.c
> > > +++ b/drivers/usb/musb/musb_udc.c
> > > @@ -707,9 +707,7 @@ static void musb_peri_rx(u16 intr)
> > >  {
> > >   unsigned int ep;
> > >  
> > > - /* Check for EP0 */
> > > - if (0x01 & intr)
> > > - musb_peri_ep0();
> > > + /* First bit is reserved and does not indicate interrupt
> > > for EP0 */ 
> > >   for (ep = 1; ep < 16; ep++) {
> > >   if ((1 << ep) & intr)
> > > @@ -721,9 +719,9 @@ static void musb_peri_tx(u16 intr)
> > >  {
> > >   unsigned int ep;
> > >  
> > > - /* Check for EP0 */
> > > + /* Check for EP0: first bit indicates interrupt for both
> > > RX and TX */ if (0x01 & intr)
> > > - musb_peri_ep0_tx();
> > > + musb_peri_ep0();
> > >  
> > >   for (ep = 1; ep < 16; ep++) {
> > >   if ((1 << ep) & intr)
> > > @@ -750,8 +748,6 @@ void udc_irq(void)
> > >   musb_peri_resume();
> > >   }
> > >  
> > > - musb_peri_ep0();
> > > -
> > >   if (MUSB_INTR_RESET & intrusb) {
> > >   usbd_device_event_irq(udc_device,
> > > DEVICE_RESET, 0); musb_peri_reset();
> > > @@ -790,7 +786,7 @@ void udc_irq(void)
> > >   if (intrtx)
> > >   musb_peri_tx(intrtx);
> > >   } else {
> > > - if (MUSB_INTR_SOF & intrusb) {
> > > + if (readw(>intrtx) & 0x1) {
> > >   u8 faddr;
> > >   faddr = readb(>faddr);
> > >   /*  
> > 
> > Applying this patch causes error. Could you rebase your work on
> > newest master (after onging PR is accepted).  
> 
> Hello! This patch series is rebased on top of the another patch series
> "Nokia RX-51: Fix USB TTY console and enable it" as it depends on it.

I took this patch series as they were queued in patchwork.

> So I cannot rebase it on top of master as it would not work.
> 
> Nokia RX-51: Fix USB TTY console and enable it:
> <20201129164618.5829-1-p...@kernel.org>
> https://lists.denx.de/pipermail/u-boot/2020-November/433728.html

Those were delegated to Marek, and are not yet in his tree
(-master/-next).

Ok. I will wait for them to be pulled.

> 
> > Thanks in advance and sorry for delay.
> > 
> > 
> > Best regards,
> > 
> > Lukasz Majewski
> > 
> > --
> > 
> > DENX Software Engineering GmbH,  Managing Director: Wolfgang
> > Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell,
> > Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> > lu...@denx.de  
> 
> 




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpy7nJi1iO2G.pgp
Description: OpenPGP digital signature


[U-Boot] Question: PCIe enumeration of PEX switch

2021-01-23 Thread Ramakrishna Maladi (rmaladi)
Hi
  U-boot is unable to enumerate pericom PCIe switch and subsequent end point 
devices on our board (arm v8.2, 64-bit)
  When booted to linux, we see the same enumerated with endpoints
  Have any one come ever come across this issue and found a workaround to it?
  I hope we no need to have a special driver in u-boot for it?

U-boot
rommon> dm tree
Class Index  Probed  DriverName
---
pci_generi  25  [   ]   pci_generic_drv   |   |   `-- pci_15:0.0

PCIe debug logs

pci_auto_config_devices: done
pci_uclass_pre_probe, bus=25/pci@8e00, parent=soc@0
decode_regions: len=28, cells_per_record=7
decode_regions: region 0, pci_addr=0, addr=8860, size=10, 
space_code=1
- type=1, pos=0
decode_regions: region 1, pci_addr=100, addr=88200100, size=10, 
space_code=3
- type=0, pos=1
decode_regions: region 2, pci_addr=10, addr=8840, 
size=10, space_code=3
- type=8, pos=2
decode_regions: region 3, pci_addr=8e00, addr=8e00, 
size=10, space_code=3
- type=0, pos=3
pci_uclass_post_probe: probing bus 25
bdf 19 01.00.00: u1 0 (10)
01.00.00: u1 0 (87803010) 0
word 87803010
01.00.00: u1 0 (87803010) -> 12d8
bdf 19 01.00.00: u0 e (10)
01.00.00: u0 e (87803010)
pci_find_and_bind_driver: Searching for driver: vendor=12d8, device=8619
pci_find_and_bind_driver: No match found: bound generic driver instead
bdf 19 01.00.00: u2 100 (10)
01.00.00: u2 100 (87803010) 19ff00
long 878030100100
01.00.00: u2 100 (87803010) -> fb410003
bdf 19 01.00.00: u2 fb4 (10)
01.00.00: u2 fb4 (87803010) fb410003
long 878030100fb4
01.00.00: u2 fb4 (87803010) -> 13810001
bdf 19 01.00.00: u2 138 (10)
01.00.00: u2 138 (87803010) 13810001
long 878030100138
01.00.00: u2 138 (87803010) -> 14810004
bdf 19 01.00.00: u2 148 (10)
01.00.00: u2 148 (87803010) 14810004
long 878030100148
01.00.00: u2 148 (87803010) -> 27010002
bdf 19 01.00.00: u2 270 (10)
01.00.00: u2 270 (87803010) 27010002
long 878030100270
01.00.00: u2 270 (87803010) -> 9001001e
bdf 19 01.00.00: u2 900 (10)
01.00.00: u2 900 (87803010) 9001001e
long 878030100900
01.00.00: u2 900 (87803010) -> 10012
bdf 190100 01.00.01: u1 0 (101000)
01.00.01: u1 0 (878030101000) 12d8
word 878030101000
01.00.01: u1 0 (878030101000) -> 12d8
bdf 190100 01.00.01: u0 e (101000)
01.00.01: u0 e (878030101000) 81
byte 87803010100e
01.00.01: u0 e (878030101000) -> 80
pci_bind_bus_devices: bus 25/pci@8e00: found device 0, function 1
bdf 190100 01.00.01: u1 2 (101000)
01.00.01: u1 2 (878030101000) 8619
word 878030101002
01.00.01: u1 2 (878030101000) -> 8619
bdf 190100 01.00.01: u2 8 (101000)



pci_uclass_pre_probe, bus=57/pci_19:1f.0, parent=pci@8e00
pci_uclass_post_probe: probing bus 57
bdf 39 21.00.00: u1 0 (210)
21.00.00: u1 0 (87803210) 0
word 87803210
21.00.00: u1 0 (87803210) -> 
bdf 390800 21.01.00: u1 0 (2108000)
21.01.00: u1 0 (878032108000) 
word 878032108000
21.01.00: u1 0 (878032108000) -> 
bdf 391000 21.02.00: u1 0 (211)
21.02.00: u1 0 (87803211) 
word 87803211
21.02.00: u1 0 (87803211) -> 
bdf 391800 21.03.00: u1 0 (2118000)
21.03.00: u1 0 (878032118000) 
word 878032118000
21.03.00: u1 0 (878032118000) -> 
bdf 392000 21.04.00: u1 0 (212)
21.04.00: u1 0 (87803212) 
word 87803212
21.04.00: u1 0 (87803212) -> 
bdf 392800 21.05.00: u1 0 (2128000)
21.05.00: u1 0 (878032128000) 
word 878032128000
21.05.00: u1 0 (878032128000) -> 
bdf 393000 21.06.00: u1 0 (213)
21.06.00: u1 0 (87803213) 
word 87803213
21.06.00: u1 0 (87803213) -> 
bdf 393800 21.07.00: u1 0 (2138000)
21.07.00: u1 0 (878032138000) 
word 878032138000
21.07.00: u1 0 (878032138000) -> 
bdf 394000 21.08.00: u1 0 (214)
21.08.00: u1 0 (87803214) 
word 87803214
21.08.00: u1 0 (87803214) -> 
bdf 394800 21.09.00: u1 0 (2148000)
21.09.00: u1 0 (878032148000) 
word 878032148000
21.09.00: u1 0 (878032148000) -> 
bdf 395000 21.0a.00: u1 0 (215)
21.0a.00: u1 0 (87803215) 
word 87803215
21.0a.00: u1 0 (87803215) -> 
bdf 395800 21.0b.00: u1 0 (2158000)
21.0b.00: u1 0 (878032158000) 
word 878032158000
21.0b.00: u1 0 (878032158000) -> 
bdf 396000 21.0c.00: u1 0 (216)
21.0c.00: u1 0 (87803216) 
word 87803216
21.0c.00: u1 0 (87803216) -> 
bdf 396800 21.0d.00: u1 0 (2168000)
21.0d.00: u1 0 (878032168000) 
word 878032168000
21.0d.00: u1 0 (878032168000) -> 
bdf 397000 21.0e.00: u1 0 (217)
21.0e.00: u1 0 (87803217) 
word 87803217
21.0e.00: u1 0 (87803217) -> 
bdf 397800 21.0f.00: u1 0 (2178000)
21.0f.00: u1 0 (878032178000) 
word 878032178000
21.0f.00: u1 0 (878032178000) -> 
bdf 398000 21.10.00: u1 0 (218)

Re: [PATCH] net: fec: Get rid of FEC_ENET_ENABLE_[TR]XC_DELAY

2021-01-23 Thread Marek Vasut

On 1/23/21 8:54 PM, sba...@denx.de wrote:

The FEC_ENET_ENABLE_.XC_DELAY setting is only used by one system which
supports OF control, correctly set the rgmii-id PHY mode in the DT and
then determine whether or not to enable the FEC RXC/TXC internal delay
based on the PHY mode.


[...]


Applied to u-boot-imx, master, thanks !


Didn't this fail to build on mx25 ?


[GIT] Pull request: u-boot-dfu (23.01.2021)

2021-01-23 Thread Lukasz Majewski
Dear Marek,

Please find a set of DFU/Gadget related fixes and improvements. This is
a first batch of them as I was not able to prepare the PR earlier (and
yes I do apologize for the delay/lack of PRs sent earlier). More
patches will be pulled in following PRs.

This set is not causing any CI issues:
https://dev.azure.com/lukma633/U-Boot/_build/results?buildId=17=results

The following changes since commit
184aa6504143b452132e28cd3ebecc7b941cdfa1:

  Merge tag 'u-boot-rockchip-20210121' of
  https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip (2021-01-21
  07:39:47 -0500)

are available in the Git repository at:

  u-boot-denx-dfu/master 

for you to fetch changes up to 737465042a6f6a3c31699f183ad2574c5d2f6c96:

  usb: gadget: Do not export usbd_device_* arrays (2021-01-23 16:14:10
  +0100)


Andy Shevchenko (3):
  f_rockusb: Use NULL instead of 0 for pointers
  f_rockusb: Avoid use-after-free in the global pointer variable
  f_fastboot: Avoid use-after-free in the global pointer variable

Eugeniu Rosca (5):
  cmd: bcb: Extract '__bcb_load' from 'do_bcb_load' for internal
needs cmd: bcb: Extract '__bcb_set' from 'do_bcb_set' for internal needs
  cmd: bcb: Extract '__bcb_store' from 'do_bcb_store' for internal
needs cmd: bcb: Expose 'bcb_write_reboot_reason' to external callers
  cmd: bcb: Add support for processing const string literals in
bcb_set()

Guillermo Rodriguez (1):
  dfu: Fix handling of UBI partitions in MTD backend

Jaehoon Chung (1):
  dfu: add 'SKIP' entity

Marek Szyprowski (5):
  cmd: usb_mass_storage: show device interface name
  dfu: mmc: use the default MMC device if entity specifies it as -1
  dfu: add 'SCRIPT' entity
  dfu: add support for the dfu_alt_info reintialization from the
flashed script thor: add support for the dfu_alt_info reintialization
from the flashed script

Pali Rohár (1):
  usb: gadget: Do not export usbd_device_* arrays

Seung-Woo Kim (1):
  gadget: f_thor: fix wrong file size cast


Merge tag data/information:
https://gitlab.denx.de/u-boot/custodians/u-boot-dfu/-/tags/u-boot-dfu-23Jan2021

- dfu: Fix handling of UBI partitions in MTD backend
- gadget: f_thor: fix wrong file size cast
- Extend cmd: bcb
- Fixes for fastboot and rockchip gadgets
- dfu: Add SCRIPT and SKIP entities
- dfu/thor: Add `dfu_alt_info` reinitialization from flashed script
- u-boot: Reduce size of u-boot as usbd_device_* arrays are not exported

The repository on Gitlab (master branch):
https://gitlab.denx.de/u-boot/custodians/u-boot-dfu/-/commits/master


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpT3eE0_zXaG.pgp
Description: OpenPGP digital signature


[PATCH] dm: replace auto_alloc_size with auto

2021-01-23 Thread Dario Binacchi
The auto_alloc_size members of struct driver has been renamed auto.

Signed-off-by: Dario Binacchi 
---

 include/dm/device.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/dm/device.h b/include/dm/device.h
index f5b4cd6876..e665558444 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -111,7 +111,7 @@ enum {
  * probe method if the device has a device tree node.
  *
  * All three of plat, priv and uclass_priv can be allocated by the
- * driver, or you can use the auto_alloc_size members of struct driver and
+ * driver, or you can use the auto members of struct driver and
  * struct uclass_driver to have driver model do this automatically.
  *
  * @driver: The driver used by this device
-- 
2.17.1



[PATCH] Replace video_uc_platdata with video_uc_plat

2021-01-23 Thread Dario Binacchi
The video_uc_platdata structure no longer exists. It has been renamed
video_uc_plat.

Signed-off-by: Dario Binacchi 
---

 drivers/video/Kconfig  | 4 ++--
 drivers/video/nexell_display.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d782eb806a..bdacf67795 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -30,7 +30,7 @@ config VIDEO_PCI_DEFAULT_FB_SIZE
help
  Generally, video drivers request the amount of memory they need for
  the frame buffer when they are bound, by setting the size field in
- struct video_uc_platdata. That memory is then reserved for use after
+ struct video_uc_plat. That memory is then reserved for use after
  relocation. But PCI drivers cannot be bound before relocation unless
  they are mentioned in the devicetree.
 
@@ -51,7 +51,7 @@ config VIDEO_COPY
  U-Boot) and then copied to the hardware frame-buffer as needed.
 
  To use this, your video driver must set @copy_base in
- struct video_uc_platdata.
+ struct video_uc_plat.
 
 config BACKLIGHT_PWM
bool "Generic PWM based Backlight Driver"
diff --git a/drivers/video/nexell_display.c b/drivers/video/nexell_display.c
index b47bef3578..c7621ef49c 100644
--- a/drivers/video/nexell_display.c
+++ b/drivers/video/nexell_display.c
@@ -15,7 +15,7 @@
 #include 
 #include 
 #include 
-#include  /* For struct video_uc_platdata */
+#include  /* For struct video_uc_plat */
 #include 
 #include 
 #include 
-- 
2.17.1



[PATCH 1/1] efi_loader: correct block IO alignment check

2021-01-23 Thread Heinrich Schuchardt
If the field Media->IoAlign of the EFI block IO protocol is zero, no
alignment is required. Our code required 4 GiB alignment in this case.

Don't check buffer alignment if Media->IoAlign == 0.

Fixes: f59f0825e8b9 ("efi_loader: parameter checks BLOCK_IO_PROTOCOL")
Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_disk.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index c0804effde..d0aad0252a 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -142,8 +142,9 @@ static efi_status_t EFIAPI efi_disk_read_blocks(struct 
efi_block_io *this,
return EFI_MEDIA_CHANGED;
if (!this->media->media_present)
return EFI_NO_MEDIA;
-   /* media->io_align is a power of 2 */
-   if ((uintptr_t)buffer & (this->media->io_align - 1))
+   /* media->io_align is a power of 2 or 0 */
+   if (this->media->io_align &&
+   (uintptr_t)buffer & (this->media->io_align - 1))
return EFI_INVALID_PARAMETER;
if (lba * this->media->block_size + buffer_size >
this->media->last_block * this->media->block_size)
@@ -209,8 +210,9 @@ static efi_status_t EFIAPI efi_disk_write_blocks(struct 
efi_block_io *this,
return EFI_MEDIA_CHANGED;
if (!this->media->media_present)
return EFI_NO_MEDIA;
-   /* media->io_align is a power of 2 */
-   if ((uintptr_t)buffer & (this->media->io_align - 1))
+   /* media->io_align is a power of 2 or 0 */
+   if (this->media->io_align &&
+   (uintptr_t)buffer & (this->media->io_align - 1))
return EFI_INVALID_PARAMETER;
if (lba * this->media->block_size + buffer_size >
this->media->last_block * this->media->block_size)
--
2.29.2



[PATCH 11/11] test: pinmux: add test for 'pinctrl-single' driver

2021-01-23 Thread Dario Binacchi
The test adds two pinmux nodes to the device tree, one to test when a
register changes only one pin's mux (pinctrl-single,pins), and the other
to test when more than one pin's mux is changed (pinctrl-single,bits).
This required replacing the controller's register access functions when
the driver is used on sandbox.

Signed-off-by: Dario Binacchi 

---

 arch/sandbox/dts/test.dts| 65 +
 configs/sandbox_defconfig|  1 +
 drivers/pinctrl/pinctrl-single.c | 62 +++-
 test/dm/pinmux.c | 81 ++--
 4 files changed, 193 insertions(+), 16 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index f86cd0d3b2..e00a163641 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -513,6 +513,9 @@
reg = <0 1>;
compatible = "sandbox,i2c";
clock-frequency = <10>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_i2c0_pins>;
+
eeprom@2c {
reg = <0x2c>;
compatible = "i2c-eeprom";
@@ -592,6 +595,8 @@
lcd {
u-boot,dm-pre-reloc;
compatible = "sandbox,lcd-sdl";
+   pinctrl-names = "default";
+   pinctrl-0 = <_lcd_pins>;
xres = <1366>;
yres = <768>;
};
@@ -842,6 +847,8 @@
pwm: pwm {
compatible = "sandbox,pwm";
#pwm-cells = <2>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_pwm_pins>;
};
 
pwm2 {
@@ -913,6 +920,9 @@
reg = <0 1>;
compatible = "sandbox,spi";
cs-gpios = <0>, <0>, <_a 0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_spi0_pins>;
+
spi.bin@0 {
reg = <0>;
compatible = "spansion,m25p16", "jedec,spi-nor";
@@ -1002,6 +1012,8 @@
uart0: serial {
compatible = "sandbox,serial";
u-boot,dm-pre-reloc;
+   pinctrl-names = "default";
+   pinctrl-0 = <_uart0_pins>;
};
 
usb_0: usb@0 {
@@ -1268,6 +1280,59 @@
};
};
 
+   pinctrl-single-pins {
+   compatible = "pinctrl-single";
+   reg = <0x 0x238>;
+   #pinctrl-cells = <1>;
+   pinctrl-single,register-width = <32>;
+   pinctrl-single,function-mask = <0x7f>;
+
+   pinmux_pwm_pins: pinmux_pwm_pins {
+   pinctrl-single,pins = < 0x48 0x06 >;
+   };
+
+   pinmux_spi0_pins: pinmux_spi0_pins {
+   pinctrl-single,pins = <
+   0x190 0x0c
+   0x194 0x0c
+   0x198 0x23
+   0x19c 0x0c
+   >;
+   };
+
+   pinmux_uart0_pins: pinmux_uart0_pins {
+   pinctrl-single,pins = <
+   0x70 0x30
+   0x74 0x00
+   >;
+   };
+   };
+
+   pinctrl-single-bits {
+   compatible = "pinctrl-single";
+   reg = <0x 0x50>;
+   #pinctrl-cells = <2>;
+   pinctrl-single,bit-per-mux;
+   pinctrl-single,register-width = <32>;
+   pinctrl-single,function-mask = <0xf>;
+
+   pinmux_i2c0_pins: pinmux_i2c0_pins {
+   pinctrl-single,bits = <
+   0x10 0x2200 0xff00
+   >;
+   };
+
+   pinmux_lcd_pins: pinmux_lcd_pins {
+   pinctrl-single,bits = <
+   0x40 0x2200 0xff00
+   0x44 0x 0x
+   0x48 0x0022 0x00ff
+   0x48 0x0200 0x0f00
+   0x4c 0x0222 0x0fff
+   >;
+   };
+   };
+
hwspinlock@0 {
compatible = "sandbox,hwspinlock";
};
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 86dc603667..1c7d49f073 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -193,6 +193,7 @@ CONFIG_PHY_SANDBOX=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_PINCTRL_SANDBOX=y
+CONFIG_PINCTRL_SINGLE=y
 CONFIG_POWER_DOMAIN=y
 CONFIG_SANDBOX_POWER_DOMAIN=y
 CONFIG_DM_PMIC=y
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 8db0d9e3d1..0efffd48e7 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -53,12 +53,15 @@ struct single_func {
  * @write: function to write to a configuration 

[PATCH 10/11] pinctrl: single: add get_pin_muxing operation

2021-01-23 Thread Dario Binacchi
It allows to display the muxing of a given pin. Inspired by more recent
versions of the Linux driver, in addition to the address and the value
of the configuration register I added the pin function retrieved from
the DT. In doing so, the information displayed does not depend on the
platform, being a generic type driver, and it can be useful for debug
purposes.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 220 +--
 1 file changed, 211 insertions(+), 9 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 04e2b00f7e..8db0d9e3d1 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -1,14 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) EETS GmbH, 2017, Felix Brack 
+ * Copyright (C) 2021 Dario Binacchi 
  */
 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
+#include 
 
 /**
  * struct single_pdata - platform data
@@ -26,6 +30,20 @@ struct single_pdata {
bool bits_per_mux;
 };
 
+/**
+ * struct single_func - pinctrl function
+ * @node: list node
+ * @name: pinctrl function name
+ * @npins: number of entries in pins array
+ * @pins: pins array
+ */
+struct single_func {
+   struct list_head node;
+   const char *name;
+   unsigned int npins;
+   unsigned int *pins;
+};
+
 /**
  * struct single_priv - private data
  * @bits_per_pin: number of bits per pin
@@ -38,6 +56,7 @@ struct single_priv {
unsigned int bits_per_pin;
unsigned int npins;
char pin_name[PINNAME_SIZE];
+   struct list_head functions;
unsigned int (*read)(fdt_addr_t reg);
void (*write)(unsigned int val, fdt_addr_t reg);
 };
@@ -102,6 +121,121 @@ static void single_writel(unsigned int val, fdt_addr_t 
reg)
writel(val, reg);
 }
 
+/**
+ * single_get_pin_by_offset() - get a pin based on the register offset
+ * @dev: single driver instance
+ * @offset: register offset from the base
+ */
+static int single_get_pin_by_offset(struct udevice *dev, unsigned int offset)
+{
+   struct single_pdata *pdata = dev_get_plat(dev);
+   struct single_priv *priv = dev_get_priv(dev);
+
+   if (offset > pdata->offset) {
+   dev_err(dev, "mux offset out of range: 0x%x (0x%x)\n",
+   offset, pdata->offset);
+   return -EINVAL;
+   }
+
+   if (pdata->bits_per_mux)
+   return (offset * BITS_PER_BYTE) / priv->bits_per_pin;
+
+   return offset / (pdata->width / BITS_PER_BYTE);
+}
+
+static int single_get_offset_by_pin(struct udevice *dev, unsigned int pin)
+{
+   struct single_pdata *pdata = dev_get_plat(dev);
+   struct single_priv *priv = dev_get_priv(dev);
+   unsigned int mux_bytes;
+
+   if (pin >= priv->npins)
+   return -EINVAL;
+
+   mux_bytes = pdata->width / BITS_PER_BYTE;
+   if (pdata->bits_per_mux) {
+   int byte_num;
+
+   byte_num = (priv->bits_per_pin * pin) / BITS_PER_BYTE;
+   return (byte_num / mux_bytes) * mux_bytes;
+   }
+
+   return pin * mux_bytes;
+}
+
+static const char *single_get_pin_function(struct udevice *dev,
+  unsigned int pin)
+{
+   struct single_priv *priv = dev_get_priv(dev);
+   struct single_func *func;
+   int i;
+
+   list_for_each_entry(func, >functions, node) {
+   for (i = 0; i < func->npins; i++) {
+   if (pin == func->pins[i])
+   return func->name;
+
+   if (pin < func->pins[i])
+   break;
+   }
+   }
+
+   return NULL;
+}
+
+static int single_get_pin_muxing(struct udevice *dev, unsigned int pin,
+char *buf, int size)
+{
+   struct single_pdata *pdata = dev_get_plat(dev);
+   struct single_priv *priv = dev_get_priv(dev);
+   fdt_addr_t reg;
+   const char *fname;
+   unsigned int val;
+   int offset, pin_shift = 0;
+
+   offset = single_get_offset_by_pin(dev, pin);
+   if (offset < 0)
+   return offset;
+
+   reg = pdata->base + offset;
+   val = priv->read(reg);
+
+   if (pdata->bits_per_mux)
+   pin_shift = pin % (pdata->width / priv->bits_per_pin) *
+   priv->bits_per_pin;
+
+   val &= (pdata->mask << pin_shift);
+   fname = single_get_pin_function(dev, pin);
+   snprintf(buf, size, "%pa 0x%08x %s", , val,
+fname ? fname : "UNCLAIMED");
+   return 0;
+}
+
+static struct single_func *single_allocate_function(struct udevice *dev,
+   unsigned int group_pins)
+{
+   struct single_func *func;
+
+   func = devm_kmalloc(dev, sizeof(*func), GFP_KERNEL);
+   if (!func)
+   return ERR_PTR(-ENOMEM);
+
+   

[PATCH 08/11] pinctrl: single: add get_pins_count operation

2021-01-23 Thread Dario Binacchi
It returns the number of selectable pins.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index eb69e53096..21a3bbaaa7 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -28,10 +28,14 @@ struct single_pdata {
 
 /**
  * struct single_priv - private data
+ * @bits_per_pin: number of bits per pin
+ * @npins: number of selectable pins
  * @read: function to read from a configuration register
  * @write: function to write to a configuration register
  */
 struct single_priv {
+   unsigned int bits_per_pin;
+   unsigned int npins;
unsigned int (*read)(fdt_addr_t reg);
void (*write)(unsigned int val, fdt_addr_t reg);
 };
@@ -203,10 +207,27 @@ static int single_set_state(struct udevice *dev,
return len;
 }
 
+static int single_get_pins_count(struct udevice *dev)
+{
+   struct single_priv *priv = dev_get_priv(dev);
+
+   return priv->npins;
+}
+
 static int single_probe(struct udevice *dev)
 {
struct single_pdata *pdata = dev_get_plat(dev);
struct single_priv *priv = dev_get_priv(dev);
+   u32 size;
+
+   size = pdata->offset + pdata->width / BITS_PER_BYTE;
+   priv->npins = size / (pdata->width / BITS_PER_BYTE);
+   if (pdata->bits_per_mux) {
+   priv->bits_per_pin = fls(pdata->mask);
+   priv->npins *= (pdata->width / priv->bits_per_pin);
+   }
+
+   dev_dbg(dev, "%d pins\n", priv->npins);
 
switch (pdata->width) {
case 8:
@@ -264,6 +285,7 @@ static int single_of_to_plat(struct udevice *dev)
 }
 
 const struct pinctrl_ops single_pinctrl_ops = {
+   .get_pins_count = single_get_pins_count,
.set_state = single_set_state,
 };
 
-- 
2.17.1



[PATCH 09/11] pinctrl: single: add get_pin_name operation

2021-01-23 Thread Dario Binacchi
It returns the name of the requested pin.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 21a3bbaaa7..04e2b00f7e 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -30,12 +30,14 @@ struct single_pdata {
  * struct single_priv - private data
  * @bits_per_pin: number of bits per pin
  * @npins: number of selectable pins
+ * @pin_name: temporary buffer to store the pin name
  * @read: function to read from a configuration register
  * @write: function to write to a configuration register
  */
 struct single_priv {
unsigned int bits_per_pin;
unsigned int npins;
+   char pin_name[PINNAME_SIZE];
unsigned int (*read)(fdt_addr_t reg);
void (*write)(unsigned int val, fdt_addr_t reg);
 };
@@ -207,6 +209,19 @@ static int single_set_state(struct udevice *dev,
return len;
 }
 
+static const char *single_get_pin_name(struct udevice *dev,
+  unsigned int selector)
+{
+   struct single_priv *priv = dev_get_priv(dev);
+
+   if (selector >= priv->npins)
+   snprintf(priv->pin_name, PINNAME_SIZE, "Error");
+   else
+   snprintf(priv->pin_name, PINNAME_SIZE, "PIN%u", selector);
+
+   return priv->pin_name;
+}
+
 static int single_get_pins_count(struct udevice *dev)
 {
struct single_priv *priv = dev_get_priv(dev);
@@ -286,6 +301,7 @@ static int single_of_to_plat(struct udevice *dev)
 
 const struct pinctrl_ops single_pinctrl_ops = {
.get_pins_count = single_get_pins_count,
+   .get_pin_name = single_get_pin_name,
.set_state = single_set_state,
 };
 
-- 
2.17.1



[PATCH 07/11] pinctrl: single: use function pointer for register access

2021-01-23 Thread Dario Binacchi
The patch allows you to call the read/write functions set during probing
without having to check the type of access at runtime. It also adds
functions for 8-bit registers access.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 98 
 1 file changed, 73 insertions(+), 25 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 09bb883041..eb69e53096 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -26,6 +26,16 @@ struct single_pdata {
bool bits_per_mux;
 };
 
+/**
+ * struct single_priv - private data
+ * @read: function to read from a configuration register
+ * @write: function to write to a configuration register
+ */
+struct single_priv {
+   unsigned int (*read)(fdt_addr_t reg);
+   void (*write)(unsigned int val, fdt_addr_t reg);
+};
+
 /**
  * struct single_fdt_pin_cfg - pin configuration
  *
@@ -56,6 +66,36 @@ struct single_fdt_bits_cfg {
fdt32_t mask;
 };
 
+static unsigned int single_readb(fdt_addr_t reg)
+{
+   return readb(reg);
+}
+
+static unsigned int single_readw(fdt_addr_t reg)
+{
+   return readw(reg);
+}
+
+static unsigned int single_readl(fdt_addr_t reg)
+{
+   return readl(reg);
+}
+
+static void single_writeb(unsigned int val, fdt_addr_t reg)
+{
+   writeb(val, reg);
+}
+
+static void single_writew(unsigned int val, fdt_addr_t reg)
+{
+   writew(val, reg);
+}
+
+static void single_writel(unsigned int val, fdt_addr_t reg)
+{
+   writel(val, reg);
+}
+
 /**
  * single_configure_pins() - Configure pins based on FDT data
  *
@@ -75,6 +115,7 @@ static int single_configure_pins(struct udevice *dev,
 int size)
 {
struct single_pdata *pdata = dev_get_plat(dev);
+   struct single_priv *priv = dev_get_priv(dev);
int n, count = size / sizeof(struct single_fdt_pin_cfg);
phys_addr_t reg;
u32 offset, val;
@@ -93,19 +134,9 @@ static int single_configure_pins(struct udevice *dev,
 
reg = pdata->base + offset;
val = fdt32_to_cpu(pins->val) & pdata->mask;
-   switch (pdata->width) {
-   case 16:
-   writew((readw(reg) & ~pdata->mask) | val, reg);
-   break;
-   case 32:
-   writel((readl(reg) & ~pdata->mask) | val, reg);
-   break;
-   default:
-   dev_warn(dev, "unsupported register width %i\n",
-pdata->width);
-   continue;
-   }
+   priv->write((priv->read(reg) & ~pdata->mask) | val, reg);
dev_dbg(dev, "  reg/val %pa/0x%08x\n", , val);
+
}
return 0;
 }
@@ -115,6 +146,7 @@ static int single_configure_bits(struct udevice *dev,
 int size)
 {
struct single_pdata *pdata = dev_get_plat(dev);
+   struct single_priv *priv = dev_get_priv(dev);
int n, count = size / sizeof(struct single_fdt_bits_cfg);
phys_addr_t reg;
u32 offset, val, mask;
@@ -131,19 +163,7 @@ static int single_configure_bits(struct udevice *dev,
 
mask = fdt32_to_cpu(pins->mask);
val = fdt32_to_cpu(pins->val) & mask;
-
-   switch (pdata->width) {
-   case 16:
-   writew((readw(reg) & ~mask) | val, reg);
-   break;
-   case 32:
-   writel((readl(reg) & ~mask) | val, reg);
-   break;
-   default:
-   dev_warn(dev, "unsupported register width %i\n",
-pdata->width);
-   continue;
-   }
+   priv->write((priv->read(reg) & ~mask) | val, reg);
dev_dbg(dev, "  reg/val %pa/0x%08x\n", , val);
}
return 0;
@@ -183,6 +203,32 @@ static int single_set_state(struct udevice *dev,
return len;
 }
 
+static int single_probe(struct udevice *dev)
+{
+   struct single_pdata *pdata = dev_get_plat(dev);
+   struct single_priv *priv = dev_get_priv(dev);
+
+   switch (pdata->width) {
+   case 8:
+   priv->read = single_readb;
+   priv->write = single_writeb;
+   break;
+   case 16:
+   priv->read = single_readw;
+   priv->write = single_writew;
+   break;
+   case 32:
+   priv->read = single_readl;
+   priv->write = single_writel;
+   break;
+   default:
+   dev_err(dev, "wrong register width\n");
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 static int single_of_to_plat(struct udevice *dev)
 {
fdt_addr_t addr;
@@ -232,5 +278,7 @@ U_BOOT_DRIVER(single_pinctrl) = {
.of_match = single_pinctrl_match,
 

[PATCH 05/11] pinctrl: single: check "register-width" DT property

2021-01-23 Thread Dario Binacchi
In more recent versions of the Linux kernel the driver's probe function
returns an error if the "pinctrl-single,register-width" DT property is
missing. The lack of this information, in fact, does not allow to know
whether to access the registers of the controller at 8, 16 or 32 bits.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index c80a42a193..8fd3bf66de 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -22,7 +22,7 @@ struct single_pdata {
fdt_addr_t base;
int offset;
u32 mask;
-   int width;
+   u32 width;
bool bits_per_mux;
 };
 
@@ -184,9 +184,13 @@ static int single_of_to_plat(struct udevice *dev)
fdt_addr_t addr;
fdt_size_t size;
struct single_pdata *pdata = dev_get_plat(dev);
+   int ret;
 
-   pdata->width =
-   dev_read_u32_default(dev, "pinctrl-single,register-width", 0);
+   ret = dev_read_u32(dev, "pinctrl-single,register-width", >width);
+   if (ret) {
+   dev_err(dev, "missing register width\n");
+   return ret;
+   }
 
dev_read_addr_size(dev, "reg", );
pdata->offset = size - pdata->width / BITS_PER_BYTE;
-- 
2.17.1



[PATCH 06/11] pinctrl: single: change function mask default value

2021-01-23 Thread Dario Binacchi
The patch is inspired by more recent versions of the Linux driver.
Replacing the default value 0x of the function mask with 0 is
certainly more conservative in case the "pinctrl-single,function-mask"
DT property is missing.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 8fd3bf66de..09bb883041 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -79,6 +79,10 @@ static int single_configure_pins(struct udevice *dev,
phys_addr_t reg;
u32 offset, val;
 
+   /* If function mask is null, needn't enable it. */
+   if (!pdata->mask)
+   return 0;
+
for (n = 0; n < count; n++, pins++) {
offset = fdt32_to_cpu(pins->reg);
if (offset < 0 || offset > pdata->offset) {
@@ -202,8 +206,12 @@ static int single_of_to_plat(struct udevice *dev)
}
pdata->base = addr;
 
-   pdata->mask = dev_read_u32_default(dev, "pinctrl-single,function-mask",
-  0x);
+   ret = dev_read_u32(dev, "pinctrl-single,function-mask", >mask);
+   if (ret) {
+   pdata->mask = 0;
+   dev_warn(dev, "missing function register mask\n");
+   }
+
pdata->bits_per_mux = dev_read_bool(dev, "pinctrl-single,bit-per-mux");
 
return 0;
-- 
2.17.1



[PATCH 04/11] pinctrl: single: get register area size by device API

2021-01-23 Thread Dario Binacchi
Use dev_read_addr_size to get size of the controller's register area.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index cec00e289c..c80a42a193 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -182,17 +182,14 @@ static int single_set_state(struct udevice *dev,
 static int single_of_to_plat(struct udevice *dev)
 {
fdt_addr_t addr;
-   u32 of_reg[2];
-   int res;
+   fdt_size_t size;
struct single_pdata *pdata = dev_get_plat(dev);
 
pdata->width =
dev_read_u32_default(dev, "pinctrl-single,register-width", 0);
 
-   res = dev_read_u32_array(dev, "reg", of_reg, 2);
-   if (res)
-   return res;
-   pdata->offset = of_reg[1] - pdata->width / 8;
+   dev_read_addr_size(dev, "reg", );
+   pdata->offset = size - pdata->width / BITS_PER_BYTE;
 
addr = dev_read_addr(dev);
if (addr == FDT_ADDR_T_NONE) {
-- 
2.17.1



[PATCH 03/11] pinctrl: single: fix debug messages formatting

2021-01-23 Thread Dario Binacchi
The printf '%pa' format specifier appends the '0x' prefix to the
displayed address. Furthermore, the offset variable is displayed with
the '%x' format specifier instead of '%pa'.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 49ed15211d..cec00e289c 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -77,15 +77,17 @@ static int single_configure_pins(struct udevice *dev,
struct single_pdata *pdata = dev_get_plat(dev);
int n, count = size / sizeof(struct single_fdt_pin_cfg);
phys_addr_t reg;
-   u32 val;
+   u32 offset, val;
 
for (n = 0; n < count; n++, pins++) {
-   reg = fdt32_to_cpu(pins->reg);
-   if ((reg < 0) || (reg > pdata->offset)) {
-   dev_dbg(dev, "  invalid register offset 0x%pa\n", );
+   offset = fdt32_to_cpu(pins->reg);
+   if (offset < 0 || offset > pdata->offset) {
+   dev_dbg(dev, "  invalid register offset 0x%x\n",
+   offset);
continue;
}
-   reg += pdata->base;
+
+   reg = pdata->base + offset;
val = fdt32_to_cpu(pins->val) & pdata->mask;
switch (pdata->width) {
case 16:
@@ -99,7 +101,7 @@ static int single_configure_pins(struct udevice *dev,
 pdata->width);
continue;
}
-   dev_dbg(dev, "  reg/val 0x%pa/0x%08x\n", , val);
+   dev_dbg(dev, "  reg/val %pa/0x%08x\n", , val);
}
return 0;
 }
@@ -111,15 +113,17 @@ static int single_configure_bits(struct udevice *dev,
struct single_pdata *pdata = dev_get_plat(dev);
int n, count = size / sizeof(struct single_fdt_bits_cfg);
phys_addr_t reg;
-   u32 val, mask;
+   u32 offset, val, mask;
 
for (n = 0; n < count; n++, pins++) {
-   reg = fdt32_to_cpu(pins->reg);
-   if ((reg < 0) || (reg > pdata->offset)) {
-   dev_dbg(dev, "  invalid register offset 0x%pa\n", );
+   offset = fdt32_to_cpu(pins->reg);
+   if (offset < 0 || offset > pdata->offset) {
+   dev_dbg(dev, "  invalid register offset 0x%x\n",
+   offset);
continue;
}
-   reg += pdata->base;
+
+   reg = pdata->base + offset;
 
mask = fdt32_to_cpu(pins->mask);
val = fdt32_to_cpu(pins->val) & mask;
@@ -136,7 +140,7 @@ static int single_configure_bits(struct udevice *dev,
 pdata->width);
continue;
}
-   dev_dbg(dev, "  reg/val 0x%pa/0x%08x\n", , val);
+   dev_dbg(dev, "  reg/val %pa/0x%08x\n", , val);
}
return 0;
 }
-- 
2.17.1



[PATCH 02/11] pinctrl: single: fix the loop counter variable type

2021-01-23 Thread Dario Binacchi
The patch changes the variable 'n' type from phys_addr_t to int.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index c9a6c272bf..49ed15211d 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -75,8 +75,8 @@ static int single_configure_pins(struct udevice *dev,
 int size)
 {
struct single_pdata *pdata = dev_get_plat(dev);
-   int count = size / sizeof(struct single_fdt_pin_cfg);
-   phys_addr_t n, reg;
+   int n, count = size / sizeof(struct single_fdt_pin_cfg);
+   phys_addr_t reg;
u32 val;
 
for (n = 0; n < count; n++, pins++) {
@@ -109,8 +109,8 @@ static int single_configure_bits(struct udevice *dev,
 int size)
 {
struct single_pdata *pdata = dev_get_plat(dev);
-   int count = size / sizeof(struct single_fdt_bits_cfg);
-   phys_addr_t n, reg;
+   int n, count = size / sizeof(struct single_fdt_bits_cfg);
+   phys_addr_t reg;
u32 val, mask;
 
for (n = 0; n < count; n++, pins++) {
-- 
2.17.1



[PATCH 01/11] pinctrl: single: fix format of structure documentation

2021-01-23 Thread Dario Binacchi
U-Boot adopted the kernel-doc annotation style.

Signed-off-by: Dario Binacchi 
---

 drivers/pinctrl/pinctrl-single.c | 45 +---
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 20c3c82aa9..c9a6c272bf 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -10,23 +10,50 @@
 #include 
 #include 
 
+/**
+ * struct single_pdata - platform data
+ * @base: first configuration register
+ * @offset: index of last configuration register
+ * @mask: configuration-value mask bits
+ * @width: configuration register bit width
+ * @bits_per_mux: true if one register controls more than one pin
+ */
 struct single_pdata {
-   fdt_addr_t base;/* first configuration register */
-   int offset; /* index of last configuration register */
-   u32 mask;   /* configuration-value mask bits */
-   int width;  /* configuration register bit width */
+   fdt_addr_t base;
+   int offset;
+   u32 mask;
+   int width;
bool bits_per_mux;
 };
 
+/**
+ * struct single_fdt_pin_cfg - pin configuration
+ *
+ * This structure is used for the pin configuration parameters in case
+ * the register controls only one pin.
+ *
+ * @reg: configuration register offset
+ * @val: configuration register value
+ */
 struct single_fdt_pin_cfg {
-   fdt32_t reg;/* configuration register offset */
-   fdt32_t val;/* configuration register value */
+   fdt32_t reg;
+   fdt32_t val;
 };
 
+/**
+ * struct single_fdt_bits_cfg - pin configuration
+ *
+ * This structure is used for the pin configuration parameters in case
+ * the register controls more than one pin.
+ *
+ * @reg: configuration register offset
+ * @val: configuration register value
+ * @mask: configuration register mask
+ */
 struct single_fdt_bits_cfg {
-   fdt32_t reg;/* configuration register offset */
-   fdt32_t val;/* configuration register value */
-   fdt32_t mask;   /* configuration register mask */
+   fdt32_t reg;
+   fdt32_t val;
+   fdt32_t mask;
 };
 
 /**
-- 
2.17.1



[PATCH 00/11] Add support for pinmux status command on beaglebone

2021-01-23 Thread Dario Binacchi


The series was born from the need to check the pinmux setting of a
peripheral on a beaglebone board. I then ran the 'pinmux status -a'
command but it failed because some operations (get_pin_muxing,
get_pin_name and get_pins_count) were missing in the 'pinctrl-single'
driver.

The patch series can be cleanly applied to the HEAD of the master which
at the time of release points to e716c9022970dac9be15856a6651a07132463578
commit (Revert "doc: update Kernel documentation build system").


Dario Binacchi (11):
  pinctrl: single: fix format of structure documentation
  pinctrl: single: fix the loop counter variable type
  pinctrl: single: fix debug messages formatting
  pinctrl: single: get register area size by device API
  pinctrl: single: check "register-width" DT property
  pinctrl: single: change function mask default value
  pinctrl: single: use function pointer for register access
  pinctrl: single: add get_pins_count operation
  pinctrl: single: add get_pin_name operation
  pinctrl: single: add get_pin_muxing operation
  test: pinmux: add test for 'pinctrl-single' driver

 arch/sandbox/dts/test.dts|  65 
 configs/sandbox_defconfig|   1 +
 drivers/pinctrl/pinctrl-single.c | 488 +++
 test/dm/pinmux.c |  81 -
 4 files changed, 570 insertions(+), 65 deletions(-)

-- 
2.17.1



[PATCH 1/1] efi_selftest: test EFI_BLOCK_IO_PROTOCOL.Media->LastBlock

2021-01-23 Thread Heinrich Schuchardt
The field Media->LastBlock of the EFI_BLOCK_IO_PROTOCOL must be filled
with the index of the last logical block (LBA) for the block device that
our test driver provides.

After calling ConnectController() U-Boot exposes the block IO protocol for
the partition check that the value of Media->LastBlock equals the partition
size minus one.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_selftest/efi_selftest_block_device.c | 21 +++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/lib/efi_selftest/efi_selftest_block_device.c 
b/lib/efi_selftest/efi_selftest_block_device.c
index 5eb297d285..15f03751ac 100644
--- a/lib/efi_selftest/efi_selftest_block_device.c
+++ b/lib/efi_selftest/efi_selftest_block_device.c
@@ -194,7 +194,7 @@ static int setup(const efi_handle_t handle,
decompress();

block_io.media->block_size = 1 << LB_BLOCK_SIZE;
-   block_io.media->last_block = img.length >> LB_BLOCK_SIZE;
+   block_io.media->last_block = (img.length >> LB_BLOCK_SIZE) - 1;

ret = boottime->install_protocol_interface(
_handle, _io_protocol_guid,
@@ -301,6 +301,7 @@ static int execute(void)
efi_handle_t *handles;
efi_handle_t handle_partition = NULL;
struct efi_device_path *dp_partition;
+   struct efi_block_io *block_io_protocol;
struct efi_simple_file_system_protocol *file_system;
struct efi_file_handle *root, *file;
struct {
@@ -309,6 +310,7 @@ static int execute(void)
} system_info;
efi_uintn_t buf_size;
char buf[16] __aligned(ARCH_DMA_MINALIGN);
+   u32 part1_size;
u64 pos;

/* Connect controller to virtual disk */
@@ -353,6 +355,23 @@ static int execute(void)
return EFI_ST_FAILURE;
}

+   /* Open the block_io_protocol */
+   ret = boottime->open_protocol(handle_partition,
+ _io_protocol_guid,
+ (void **)_io_protocol, NULL, NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+   if (ret != EFI_SUCCESS) {
+   efi_st_error("Failed to open block IO protocol\n");
+   return EFI_ST_FAILURE;
+   }
+   /* Get size of first MBR partition */
+   memcpy(_size, image + 0x1ca, sizeof(u32));
+   if (block_io_protocol->media->last_block != part1_size - 1) {
+   efi_st_error("Last LBA of partition %x, expected %x\n",
+(unsigned int)block_io_protocol->media->last_block,
+part1_size - 1);
+   return EFI_ST_FAILURE;
+   }
/* Open the simple file system protocol */
ret = boottime->open_protocol(handle_partition,
  _simple_file_system_protocol,
--
2.29.2



Re: [PATCH v4 58/59] acpi: Add more documentation for struct acpi_gpio

2021-01-23 Thread Simon Glass
Hi Andy,

On Thu, 29 Oct 2020 at 06:22, Andy Shevchenko
 wrote:
>
> On Tue, Sep 22, 2020 at 12:45:43PM -0600, Simon Glass wrote:
> > Add some documentation provided by Andy Shevchenko to describe how to
> > use struct acpi_gpio.
>
> Thanks!
>
> I see Bin already applied this, perhaps follow up fix is needed. See below.
>
> ...
>
> > + * Note that GpioIo doesn't have any means of Active Low / High setting, 
> > so a
>
> GpioIo -> GpioIo()
>
> > + * _DSD must be provided to mitigate this.
>
> Plus the following:
>
> "This parameter does not make sense for GpioInt() since it has its own means
> to define it."
>
> > + * GpioIo doesn't properly communicate the initial state of the output pin,
>
> GpioIo -> GpioIo()
>
> > + * thus Linux assumes the simple rule:
> > + *
> > + * Pull Bias   Polarity  Requested...
> > + *
> > + * Implicitx AS IS (assumed firmware configured for us)
> > + * Explicitx (no _DSD)   as Pull Bias (Up == High, Down == Low),
> > + *   assuming non-active (Polarity = !Pull 
> > Bias)
> > + *
> > + * DownLow   as low, assuming active
>
> > + * DownHigh  as high, assuming non-active
>
> Should be read:
>
> " * DownHigh  as low, assuming non-active"
>
> > + * Up  Low   as high, assuming non-active
> > + * Up  High  as high, assuming active
> > + *
> > + * GpioIo() can be used as interrupt and in this case the IoRestriction 
> > mustn't
> > + * be OutputOnly.
> > + * It also requires active_low flag from _DSD in cases where it's
> > + * needed (better to always provide than rely on above assumption made on 
> > OS
> > + * level).
>

Thanks, I sent a patch for these.

Regards,
Simon


[PATCH] acpi: Tidy up documentation for struct acpi_gpio

2021-01-23 Thread Simon Glass
Some comments were provided after this patch was applied. Address them.

Signed-off-by: Simon Glass 
---

 include/acpi/acpi_device.h | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/acpi/acpi_device.h b/include/acpi/acpi_device.h
index ed4acd912a1..2c8846250b6 100644
--- a/include/acpi/acpi_device.h
+++ b/include/acpi/acpi_device.h
@@ -171,10 +171,11 @@ enum acpi_gpio_polarity {
  * @io_restrict: I/O restriction setting
  * @polarity: GPIO polarity
  *
- * Note that GpioIo doesn't have any means of Active Low / High setting, so a
- * _DSD must be provided to mitigate this.
+ * Note that GpioIo() doesn't have any means of Active Low / High setting, so a
+ * _DSD must be provided to mitigate this. This parameter does not make sense
+ * for GpioInt() since it has its own means to define it.
  *
- * GpioIo doesn't properly communicate the initial state of the output pin,
+ * GpioIo() doesn't properly communicate the initial state of the output pin,
  * thus Linux assumes the simple rule:
  *
  * Pull Bias   Polarity  Requested...
@@ -184,7 +185,7 @@ enum acpi_gpio_polarity {
  *   assuming non-active (Polarity = !Pull Bias)
  *
  * DownLow   as low, assuming active
- * DownHigh  as high, assuming non-active
+ * DownHigh  as low, assuming non-active
  * Up  Low   as high, assuming non-active
  * Up  High  as high, assuming active
  *
-- 
2.30.0.280.ga3ce27912f-goog



Re: [PATCH 1/1] doc: update Kernel documentation build system

2021-01-23 Thread Tom Rini
On Sat, Jan 23, 2021 at 12:46:23PM -0500, Tom Rini wrote:
> On Fri, Jan 01, 2021 at 01:21:11AM +0100, Heinrich Schuchardt wrote:
> 
> > Update the docomentation build system according to Linux v5.11-rc1.
> > 
> > With this patch we can build the HTML documentation using either of
> > Sphinx 2 and Sphinx 3.
> > 
> > Signed-off-by: Heinrich Schuchardt 
> > Reviewed-by: Simon Glass 
> 
> Applied to u-boot/master, thanks!

I've had to revert this.  While I caught and fixed up in a semi-logical
way one duplicate label problem, there's another now that I see, and
probably many more once I rework that one.  It's unclear as well how
best to handle these otherwise logical duplicate labels, such as "eMMC"
in doc/board/microchip/mpfs_icicle.rst for example.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/1] doc: move README.menu to HTML documentation

2021-01-23 Thread Tom Rini
On Mon, Jan 18, 2021 at 09:06:03PM +0100, Heinrich Schuchardt wrote:

> Convert README.menu to reStructured text and add it to the HTML
> documentation.
> 
> Signed-off-by: Heinrich Schuchardt 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 3/3] doc: move test/py/README.md to HTML documentation

2021-01-23 Thread Tom Rini
On Mon, Jan 18, 2021 at 08:24:03PM +0100, Heinrich Schuchardt wrote:

> Convert test/py/README.md to restructured text and add it to the generated
> HTML documentation.
> 
> Signed-off-by: Heinrich Schuchardt 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/3] doc: move test/README to HTML documentation

2021-01-23 Thread Tom Rini
On Mon, Jan 18, 2021 at 08:24:02PM +0100, Heinrich Schuchardt wrote:

> Move test/README to the 'Develop U-Boot' chapter of the HTML documentation.
> 
> Signed-off-by: Heinrich Schuchardt 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/3] doc: structure doc/develop/index.rst

2021-01-23 Thread Tom Rini
On Mon, Jan 18, 2021 at 08:24:01PM +0100, Heinrich Schuchardt wrote:

> Provide sub-chapters for 'Develop U-Boot'
> 
> Signed-off-by: Heinrich Schuchardt 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] doc: update help message

2021-01-23 Thread Tom Rini
On Thu, Jan 14, 2021 at 12:04:04PM +0100, Patrick Delaunay wrote:

> Update the help message used for 'make help':
> 
>   Documentation targets:
> Linux kernel internal documentation in different formats from ReST:
> =>
> U-Boot documentation in different formats from ReST:
> 
> Signed-off-by: Patrick Delaunay 
> Reviewed-by: Heinrich Schuchardt 
> Reviewed-by: Bin Meng 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/1] doc: update Kernel documentation build system

2021-01-23 Thread Tom Rini
On Fri, Jan 01, 2021 at 01:21:11AM +0100, Heinrich Schuchardt wrote:

> Update the docomentation build system according to Linux v5.11-rc1.
> 
> With this patch we can build the HTML documentation using either of
> Sphinx 2 and Sphinx 3.
> 
> Signed-off-by: Heinrich Schuchardt 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] doc: FIT image: Clarify format and simplify syntax

2021-01-23 Thread Tom Rini
On Tue, Dec 15, 2020 at 01:15:43PM -0600, Alexandru Gagniuc wrote:

> ** Introduction
> 
> There are currently four ways to load an OS image with u-boot
>   1. SPL -> u-boot -> bootm
>   2. SPL blue falcon mode
>   3. "Basic" FIT image (CONFIG_LOAD_FIT)
>   4. "Full-featured" FIT image (CONFIG_LOAD_FIT_FULL)
> 
> These four code paths were developed independently, and share very
> little code. (3) and (4), behave very differently, are littered with
> special cases. They even have different DTS syntax and properties.
> 
> The cause of this divergence is that the FIT format specification
> leaves a number of things open to interpretation. The purpose of this
> change is to enable the reduction of code size, duplication, and
> complexity by updating and streamlining the FIT format.
> 
> We are only marginally concerned with backwards compatibility, because
> we don't have inter-compatibility. For example, CONFIG_LOAD_FIT is
> able to load images that CONFIG_LOAD_FIT_FULL won't. This is a direct
> result of the incompatible syntax between the two implementations.
> 
> Ideally, these changes would enable "simple" FIT to be a subset of the
> "full" fit implementation, and share most code. These changes should
> also eliminate the need for falcon mode (although we are not
> advocating for the removal of falcon mode at this time).
> 
> ** Description of changes
> 
>  * The "configurations" node is now mandatory
> 
> Guessing how to load components based on their "os" and "type" invites
> confusion and superfluous heuristics. Instead, require each FIT image
> to be explicit on how components should be loaded.
> 
>  * Eliminate "ramdisk", "setup", "standalone", and "fpga" properties
> 
> Having too many special purpose properties requires special-casing
> FIT loading code. When a special property can be handled by another
> property, it is redundant.
>  - A "ramdisk" is identical to a loadable. Thus ramdisk images should
>be placed under "loadables".
>  - A "setup" node can be achieved by using a "kernel" or "firmware"
>property instead.
>  - "standalone" is used for u-boot nodes. The correct property to use
>in this case is "firmware".
>  - "fpga" is a loadable
> 
>  * Prioritize control between "firmware" and "kernel"
> 
> "firmware" and "kernel" are special nodes in that control is passed
> to the "entry-point" of the image. Both can be present, for example,
> an OP-TEE firmware with a linux kernel. When both are present,
> control is passed to the "firmware" image.
> 
> ** Further generalizations (not included herein)
> 
> The "firmware" and "kernel" properties could be generalized as a
> "next-boot-stage", or similar name. This "next" stage would be special
> in that it is both executable, and is the stage that is passed
> control. For example, "next-stage" could be an op-tee image, with
> linux as a loadable, or a u-boot image.
> 
> Signed-off-by: Alexandru Gagniuc 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 3/4] mkimage: Move padding commands outside of FIT_SIGNATURE

2021-01-23 Thread Tom Rini
On Tue, Dec 08, 2020 at 02:42:15PM +1030, Joel Stanley wrote:

> These commands were disabled when CONFIG_FIT_SIGNATURE is disabled, but
> they do not depend on crypto support so they can be unconditionally
> enabled.
> 
> Signed-off-by: Joel Stanley 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 2/4] image-fit: Fix FIT_CIPHER linking

2021-01-23 Thread Tom Rini
On Tue, Dec 08, 2020 at 02:42:14PM +1030, Joel Stanley wrote:

> When CONFIG_FIT_CIPHER=y and CONFIG_FIT_SIGNATURE=n is there is no
> implementation of image_get_host_blob for mkimage/dumpimage:
> 
>  /usr/bin/ld: tools/common/image-cipher.o: in function 
> `fit_image_decrypt_data':
>  image-cipher.c:(.text+0x9a): undefined reference to `image_get_host_blob'
> 
> Move the implementation to a common file so it can be shaed between
> image-cipher.c and image-fit-sig.c.
> 
> Signed-off-by: Joel Stanley 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 1/4] tools/Makefile: FIT_CIPHER requires libssl

2021-01-23 Thread Tom Rini
On Tue, Dec 08, 2020 at 02:42:13PM +1030, Joel Stanley wrote:

> If CONFIG_FIT_CIPHER is enabled without CONFIG_FIT_SIGNATURE then
> mkimage/dumpimage will fail to link:
> 
>  /usr/bin/ld: tools/common/image-cipher.o: in function 
> `fit_image_decrypt_data':
>  image-cipher.c:(.text+0x9a): undefined reference to `image_get_host_blob'
>  /usr/bin/ld: tools/common/image-cipher.o:(.data.rel+0x10): undefined 
> reference to `EVP_aes_128_cbc'
>  /usr/bin/ld: tools/common/image-cipher.o:(.data.rel+0x40): undefined 
> reference to `EVP_aes_192_cbc'
>  /usr/bin/ld: tools/common/image-cipher.o:(.data.rel+0x70): undefined 
> reference to `EVP_aes_256_cbc'
>  /usr/bin/ld: tools/lib/aes/aes-encrypt.o: in function `image_aes_encrypt':
>  aes-encrypt.c:(.text+0x22): undefined reference to `EVP_CIPHER_CTX_new'
>  /usr/bin/ld: aes-encrypt.c:(.text+0x6f): undefined reference to 
> `EVP_EncryptInit_ex'
>  /usr/bin/ld: aes-encrypt.c:(.text+0x8d): undefined reference to 
> `EVP_EncryptUpdate'
>  /usr/bin/ld: aes-encrypt.c:(.text+0xac): undefined reference to 
> `EVP_CIPHER_CTX_free'
>  /usr/bin/ld: aes-encrypt.c:(.text+0xf2): undefined reference to 
> `EVP_EncryptFinal_ex'
>  collect2: error: ld returned 1 exit status
> 
> Signed-off-by: Joel Stanley 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] tools: env: return error if ubi_update_start() fails

2021-01-23 Thread Tom Rini
On Mon, Nov 30, 2020 at 12:11:32PM +0100, Martin Hundebøll wrote:

> The UBI_IOCVOLUP ioctl can fail if exclusive access to the volume isn't
> obtained. If this happens, the flush operation doesn't return error,
> leaving the caller without knowledge of missing flush.
> 
> Fix this by forwarding the error (-1) from ubi_update_start().
> 
> Fixes: 34255b92e6e ("tools: env: Add support for direct read/write UBI 
> volumes")
> Signed-off-by: Martin Hundebøll 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] tools: image-host: add support for several sub-images

2021-01-23 Thread Tom Rini
On Tue, Nov 24, 2020 at 02:39:48PM +0100, Philippe Reynes wrote:

> The propoerty sign-images points to images in the configuration
> node. But thoses images may references severals "sub-images" (for
> example for images loadable). This commit adds the support of
> severals sub-images.
> 
> Signed-off-by: Philippe Reynes 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] tools: image-host: clean function fit_config_get_hash_list

2021-01-23 Thread Tom Rini
On Tue, Nov 24, 2020 at 02:39:47PM +0100, Philippe Reynes wrote:

> This commit creates a function fit_config_add_hash that will be
> used in the next commit to support several 'sub-images'.
> 
> Signed-off-by: Philippe Reynes 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: please pull u-boot-samsung master

2021-01-23 Thread Tom Rini
On Fri, Jan 22, 2021 at 04:45:30PM +0900, Minkyu Kang wrote:

> Dear Tom,
> 
> The following changes since commit ee6726be4f0dccb612f0193c62ca149164c8a5af:
> 
>   Merge tag 'ti-v2021.04-rc1' of
> https://gitlab.denx.de/u-boot/custodians/u-boot-ti (2021-01-12 09:32:48
> -0500)
> 
> are available in the Git repository at:
> 
>   g...@gitlab.denx.de:u-boot/custodians/u-boot-samsung.git
> 
> for you to fetch changes up to 0a80955fc6e03ebbe1f98c5fa3c89fb33f23c23e:
> 
>   mmc: exynos_dw_mmc: remove unused function (2021-01-13 13:49:38 +0900)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v2 8/8] bootm: Fix duplicate debugging in bootm_process_cmdline()

2021-01-23 Thread Simon Glass
These two returns use the same string so are not distinguishable with
LOG_ERROR_RETURN. Fix it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/bootm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 8298693900d..48a5b04cd7a 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -585,7 +585,7 @@ int bootm_process_cmdline(char *buf, int maxlen, int flags)
if (IS_ENABLED(CONFIG_BOOTARGS_SUBST) && (flags & BOOTM_CL_SUBST)) {
ret = process_subst(buf, maxlen);
if (ret)
-   return log_msg_ret("silent", ret);
+   return log_msg_ret("subst", ret);
}
 
return 0;
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v2 7/8] sandbox: Write out bloblist when existing

2021-01-23 Thread Simon Glass
Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/sandbox/cpu/state.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index 4ffaf163789..f63cfd38ee4 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -398,8 +399,12 @@ int state_uninit(void)
 {
int err;
 
+   log_info("Writing sandbox state\n");
state = _state;
 
+   /* Finish the bloblist, so that it is correct before writing memory */
+   bloblist_finish();
+
if (state->write_ram_buf) {
err = os_write_ram_buf(state->ram_buf_fname);
if (err) {
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v2 6/8] sandbox: Avoid using malloc() for system state

2021-01-23 Thread Simon Glass
This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not free, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop unnecessary check before calling os_free()
- Update the comment for os_free()
- Also free the RAM buffer
- Convert the rest of the allocations in os.c, etc.

 arch/sandbox/cpu/os.c| 24 
 arch/sandbox/cpu/spl.c   | 10 +++---
 arch/sandbox/cpu/start.c | 12 +++-
 arch/sandbox/cpu/state.c | 18 +-
 include/os.h |  3 ++-
 5 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 69ce6afdfac..5df11007c9d 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -150,7 +150,7 @@ int os_read_file(const char *fname, void **bufp, int *sizep)
printf("Cannot seek to start of file '%s'\n", fname);
goto err;
}
-   *bufp = malloc(size);
+   *bufp = os_malloc(size);
if (!*bufp) {
printf("Not enough memory to read file '%s'\n", fname);
ret = -ENOMEM;
@@ -378,8 +378,8 @@ int os_parse_args(struct sandbox_state *state, int argc, 
char *argv[])
state->argv = argv;
 
/* dynamically construct the arguments to the system getopt_long */
-   short_opts = malloc(sizeof(*short_opts) * num_options * 2 + 1);
-   long_opts = malloc(sizeof(*long_opts) * (num_options + 1));
+   short_opts = os_malloc(sizeof(*short_opts) * num_options * 2 + 1);
+   long_opts = os_malloc(sizeof(*long_opts) * (num_options + 1));
if (!short_opts || !long_opts)
return 1;
 
@@ -458,7 +458,7 @@ void os_dirent_free(struct os_dirent_node *node)
 
while (node) {
next = node->next;
-   free(node);
+   os_free(node);
node = next;
}
 }
@@ -483,7 +483,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node 
**headp)
/* Create a buffer upfront, with typically sufficient size */
dirlen = strlen(dirname) + 2;
len = dirlen + 256;
-   fname = malloc(len);
+   fname = os_malloc(len);
if (!fname) {
ret = -ENOMEM;
goto done;
@@ -496,7 +496,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node 
**headp)
ret = errno;
break;
}
-   next = malloc(sizeof(*node) + strlen(entry->d_name) + 1);
+   next = os_malloc(sizeof(*node) + strlen(entry->d_name) + 1);
if (!next) {
os_dirent_free(head);
ret = -ENOMEM;
@@ -505,10 +505,10 @@ int os_dirent_ls(const char *dirname, struct 
os_dirent_node **headp)
if (dirlen + strlen(entry->d_name) > len) {
len = dirlen + strlen(entry->d_name);
old_fname = fname;
-   fname = realloc(fname, len);
+   fname = os_realloc(fname, len);
if (!fname) {
-   free(old_fname);
-   free(next);
+   os_free(old_fname);
+   os_free(next);
os_dirent_free(head);
ret = -ENOMEM;
goto done;
@@ -542,7 +542,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node 
**headp)
 
 done:
closedir(dir);
-   free(fname);
+   os_free(fname);
return ret;
 }
 
@@ -659,7 +659,7 @@ static int add_args(char ***argvp, char *add_args[], int 
count)
for (argc = 0; (*argvp)[argc]; argc++)
;
 
-   argv = malloc((argc + count + 1) * sizeof(char *));
+   argv = os_malloc((argc + count + 1) * sizeof(char *));
if (!argv) {
printf("Out of memory for %d argv\n", count);
return -ENOMEM;
@@ -742,7 +742,7 @@ static int os_jump_to_file(const char *fname)
os_exit(2);
 
err = execv(fname, argv);
-   free(argv);
+   os_free(argv);
if (err) {
perror("Unable to run image");
printf("Image filename '%s'\n", fname);
diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 9a77da15619..197b98c9828 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -42,10 +42,14 @@ static int spl_board_load_image(struct spl_image_info 
*spl_image,
return ret;
}
 
-   /* Set 

[PATCH v2 5/8] sandbox: Add os_realloc()

2021-01-23 Thread Simon Glass
We provide os_malloc() and os_free() but not os_realloc(). Add this,
following the usual semantics. Also update os_malloc() to behave correctly
when passed a zero size.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to add os_realloc()

 arch/sandbox/cpu/os.c | 38 ++
 include/os.h  | 12 +++-
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 80996a91ce7..69ce6afdfac 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -269,6 +269,8 @@ void *os_malloc(size_t length)
int page_size = getpagesize();
struct os_mem_hdr *hdr;
 
+   if (!length)
+   return NULL;
/*
 * Use an address that is hopefully available to us so that pointers
 * to this memory are fairly obvious. If we end up with a different
@@ -295,6 +297,42 @@ void os_free(void *ptr)
}
 }
 
+/* These macros are from kernel.h but not accessible in this file */
+#define ALIGN(x, a)__ALIGN_MASK((x), (typeof(x))(a) - 1)
+#define __ALIGN_MASK(x, mask)  (((x) + (mask)) & ~(mask))
+
+void *os_realloc(void *ptr, size_t length)
+{
+   int page_size = getpagesize();
+   struct os_mem_hdr *hdr;
+   void *new_ptr;
+
+   /* Reallocating a NULL pointer is just an alloc */
+   if (!ptr)
+   return os_malloc(length);
+
+   /* Changing a length to 0 is just a free */
+   if (length) {
+   os_free(ptr);
+   return NULL;
+   }
+
+   /*
+* If the new size is the same number of pages as the old, nothing to
+* do. There isn't much point in shrinking things
+*/
+   hdr = ptr - page_size;
+   if (ALIGN(length, page_size) <= ALIGN(hdr->length, page_size))
+   return ptr;
+
+   /* We have to grow it, so allocate something new */
+   new_ptr = os_malloc(length);
+   memcpy(new_ptr, ptr, hdr->length);
+   os_free(ptr);
+
+   return new_ptr;
+}
+
 void os_usleep(unsigned long usec)
 {
usleep(usec);
diff --git a/include/os.h b/include/os.h
index 0913b47b3a8..b4c5dd727c4 100644
--- a/include/os.h
+++ b/include/os.h
@@ -114,7 +114,7 @@ void os_fd_restore(void);
  * os_malloc() - aquires some memory from the underlying os.
  *
  * @length:Number of bytes to be allocated
- * Return: Pointer to length bytes or NULL on error
+ * Return: Pointer to length bytes or NULL if @length is 0 or on error
  */
 void *os_malloc(size_t length);
 
@@ -127,6 +127,16 @@ void *os_malloc(size_t length);
  */
 void os_free(void *ptr);
 
+/**
+ * os_realloc() - reallocate memory
+ *
+ * This follows the semantics of realloc(), so can perform an os_malloc() or
+ * os_free() depending on @ptr and @length.
+ *
+ * Return: Pointer to reallocated memory or NULL if @length is 0
+ */
+void *os_realloc(void *ptr, size_t length);
+
 /**
  * os_usleep() - access to the usleep function of the os
  *
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v2 4/8] s5p4418_nanopi2: Drop dead code

2021-01-23 Thread Simon Glass
This code is still using the old command typedef. It was not noticed since
this file is not currently built. It is using a non-existent option in the
Makefile.

Drop this file since it is not needed for correct operation.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop the file instead of fixing it up

 arch/arm/mach-nexell/Makefile |   1 -
 arch/arm/mach-nexell/cmd_boot_linux.c | 144 --
 2 files changed, 145 deletions(-)
 delete mode 100644 arch/arm/mach-nexell/cmd_boot_linux.c

diff --git a/arch/arm/mach-nexell/Makefile b/arch/arm/mach-nexell/Makefile
index 10b3963ed10..dda16dbb8e6 100644
--- a/arch/arm/mach-nexell/Makefile
+++ b/arch/arm/mach-nexell/Makefile
@@ -10,4 +10,3 @@ obj-y += nx_gpio.o
 obj-y  += tieoff.o
 obj-$(CONFIG_ARCH_S5P4418) += reg-call.o
 obj-$(CONFIG_ARCH_S5P4418) += nx_sec_reg.o
-obj-$(CONFIG_CMD_BOOTL)+= cmd_boot_linux.o
diff --git a/arch/arm/mach-nexell/cmd_boot_linux.c 
b/arch/arm/mach-nexell/cmd_boot_linux.c
deleted file mode 100644
index f2dedfe1625..000
--- a/arch/arm/mach-nexell/cmd_boot_linux.c
+++ /dev/null
@@ -1,144 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * (C) Copyright 2016 nexell
- * jhkim 
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_CLI_FRAMEWORK)
-
-DECLARE_GLOBAL_DATA_PTR;
-
-static bootm_headers_t linux_images;
-
-static void boot_go_set_os(cmd_tbl_t *cmdtp, int flag, int argc,
-  char * const argv[],
-  bootm_headers_t *images)
-{
-   char * const img_addr = argv[0];
-
-   images->os.type = IH_TYPE_KERNEL;
-   images->os.comp = IH_COMP_NONE;
-   images->os.os = IH_OS_LINUX;
-   images->os.load = simple_strtoul(img_addr, NULL, 16);
-   images->ep = images->os.load;
-#if defined(CONFIG_ARM)
-   images->os.arch = IH_ARCH_ARM;
-#elif defined(CONFIG_ARM64)
-   images->os.arch = IH_ARCH_ARM64;
-#else
-   #error "Not support architecture ..."
-#endif
-   if (!IS_ENABLED(CONFIG_OF_LIBFDT) && !IS_ENABLED(CONFIG_SPL_BUILD)) {
-   /* set DTB address for linux kernel */
-   if (argc > 2) {
-   unsigned long ft_addr;
-
-   ft_addr = simple_strtol(argv[2], NULL, 16);
-   images->ft_addr = (char *)ft_addr;
-
-   /*
-* if not defined IMAGE_ENABLE_OF_LIBFDT,
-* must be set to fdt address
-*/
-   if (!IMAGE_ENABLE_OF_LIBFDT)
-   gd->bd->bi_boot_params = ft_addr;
-
-   debug("## set ft:%08lx and boot params:%08lx [control 
of:%s]"
- "...\n", ft_addr, gd->bd->bi_boot_params,
- IMAGE_ENABLE_OF_LIBFDT ? "on" : "off");
-   }
-   }
-}
-
-#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
-static void boot_start_lmb(bootm_headers_t *images)
-{
-   ulong   mem_start;
-   phys_size_t mem_size;
-
-   lmb_init(>lmb);
-
-   mem_start = getenv_bootm_low();
-   mem_size = getenv_bootm_size();
-
-   lmb_add(>lmb, (phys_addr_t)mem_start, mem_size);
-
-   arch_lmb_reserve(>lmb);
-   board_lmb_reserve(>lmb);
-}
-#else
-#define lmb_reserve(lmb, base, size)
-static inline void boot_start_lmb(bootm_headers_t *images) { }
-#endif
-
-int do_boot_linux(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-   boot_os_fn *boot_fn;
-   bootm_headers_t *images = _images;
-   int flags;
-   int ret;
-
-   boot_start_lmb(images);
-
-   flags  = BOOTM_STATE_START;
-
-   argc--; argv++;
-   boot_go_set_os(cmdtp, flag, argc, argv, images);
-
-   if (IS_ENABLED(CONFIG_OF_LIBFDT)) {
-   /* find flattened device tree */
-   ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, images,
-  >ft_addr, >ft_len);
-   if (ret) {
-   puts("Could not find a valid device tree\n");
-   return 1;
-   }
-   set_working_fdt_addr((ulong)images->ft_addr);
-   }
-
-   if (!IS_ENABLED(CONFIG_OF_LIBFDT))
-   flags |= BOOTM_STATE_OS_GO;
-
-   boot_fn = do_bootm_linux;
-   ret = boot_fn(flags, argc, argv, images);
-
-   if (ret == BOOTM_ERR_UNIMPLEMENTED)
-   show_boot_progress(BOOTSTAGE_ID_DECOMP_UNIMPL);
-   else if (ret == BOOTM_ERR_RESET)
-   do_reset(cmdtp, flag, argc, argv);
-
-   return ret;
-}
-
-U_BOOT_CMD(bootl, CONFIG_SYS_MAXARGS, 1, do_boot_linux,
-  "boot linux image from memory",
-  "[addr [arg ...]]\n- boot linux image stored in memory\n"
-  "\tuse a '-' for the DTB address\n"
-);
-#endif
-
-#if 

[PATCH v2 2/8] binman: Indicate how to make binman verbose

2021-01-23 Thread Simon Glass
Add notes about how to make binman produce verbose logging when building.

Add a comment on how to do this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile| 1 +
 tools/binman/README | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index c2b7046ce3b..66f441f23aa 100644
--- a/Makefile
+++ b/Makefile
@@ -1326,6 +1326,7 @@ u-boot.ldr:   u-boot
 # binman
 # ---
 # Use 'make BINMAN_DEBUG=1' to enable debugging
+# Use 'make BINMAN_VERBOSE=3' to set vebosity level
 default_dt := $(if $(DEVICE_TREE),$(DEVICE_TREE),$(CONFIG_DEFAULT_DEVICE_TREE))
 quiet_cmd_binman = BINMAN  $@
 cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
diff --git a/tools/binman/README b/tools/binman/README
index a00c9026163..45f0a0c2cd3 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -637,7 +637,8 @@ Logging
 
 Binman normally operates silently unless there is an error, in which case it
 just displays the error. The -D/--debug option can be used to create a full
-backtrace when errors occur.
+backtrace when errors occur. You can use BINMAN_DEBUG=1 when building to select
+this.
 
 Internally binman logs some output while it is running. This can be displayed
 by increasing the -v/--verbosity from the default of 1:
@@ -649,6 +650,7 @@ by increasing the -v/--verbosity from the default of 1:
4: detailed information about each operation
5: debug (all output)
 
+You can use BINMAN_VERBOSE=5 (for example) when building to select this.
 
 Hashing Entries
 ---
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v2 3/8] doc: Add a note about how to produce 'md' output using hexdump

2021-01-23 Thread Simon Glass
Comparing a hex dump on the U-Boot command line with the contents of a
file on the host system is fairly easy and convenient to do manually if
it is small. But the format used hexdump by default differs from that
shown by U-Boot. Add a note about how to make them the same.

(For large dumps, writing the data to the network with tftpput, or to a
USB stick with ext4save is easiest.)

Signed-off-by: Simon Glass 
---

(no changes since v1)

 README | 4 
 1 file changed, 4 insertions(+)

diff --git a/README b/README
index afa33dc7f30..582bfb00348 100644
--- a/README
+++ b/README
@@ -3274,6 +3274,10 @@ TODO.
 
 For now: just type "help ".
 
+Note that the format of 'md' can be emulated from linux with:
+
+   hexdump -v -e '"%08.8_ax: " 16/1 "%02x " "   "' -e '16/1 "%_p" "\n" ' fname
+
 
 Environment Variables:
 ==
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v2 1/8] spl: Drop duplicate 'Jumping to U-Boot' message

2021-01-23 Thread Simon Glass
This is printed twice but we only need one message, since there is very
little processing in between them. Drop the first one.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/spl/spl.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 12b00e2a407..7fe0812799f 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -693,7 +693,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 #endif
switch (spl_image.os) {
case IH_OS_U_BOOT:
-   debug("Jumping to U-Boot\n");
break;
 #if CONFIG_IS_ENABLED(ATF)
case IH_OS_ARM_TRUSTED_FIRMWARE:
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v2 0/8] Various minor fixes

2021-01-23 Thread Simon Glass
This series collects a few minor fixes and improvements that have been
hanging around in a branch for a while.

Changes in v2:
- Drop the file instead of fixing it up
- Add new patch to add os_realloc()
- Drop unnecessary check before calling os_free()
- Update the comment for os_free()
- Also free the RAM buffer
- Convert the rest of the allocations in os.c, etc.

Simon Glass (8):
  spl: Drop duplicate 'Jumping to U-Boot' message
  binman: Indicate how to make binman verbose
  doc: Add a note about how to produce 'md' output using hexdump
  s5p4418_nanopi2: Drop dead code
  sandbox: Add os_realloc()
  sandbox: Avoid using malloc() for system state
  sandbox: Write out bloblist when existing
  bootm: Fix duplicate debugging in bootm_process_cmdline()

 Makefile  |   1 +
 README|   4 +
 arch/arm/mach-nexell/Makefile |   1 -
 arch/arm/mach-nexell/cmd_boot_linux.c | 144 --
 arch/sandbox/cpu/os.c |  62 ---
 arch/sandbox/cpu/spl.c|  10 +-
 arch/sandbox/cpu/start.c  |  12 ++-
 arch/sandbox/cpu/state.c  |  23 ++--
 common/bootm.c|   2 +-
 common/spl/spl.c  |   1 -
 include/os.h  |  15 ++-
 tools/binman/README   |   4 +-
 12 files changed, 100 insertions(+), 179 deletions(-)
 delete mode 100644 arch/arm/mach-nexell/cmd_boot_linux.c

-- 
2.30.0.280.ga3ce27912f-goog



Re: [PATCH 5/5] x86: coral: Enable CONFIG_BOOTARGS_SUBST

2021-01-23 Thread Simon Glass
Enable this option so that the boot-script substitutions of %U works as
expected. With this, it can boot into Chrome OS.

Signed-off-by: Simon Glass 
---

 configs/chromebook_coral_defconfig | 1 +
 1 file changed, 1 insertion(+)

Applied to u-boot-dm, thanks!


Re: [PATCH 01/10] dtoc: binman: Drop Python 2 code

2021-01-23 Thread Simon Glass
Drop a few more Python 2 relics that are no-longer needed.

Signed-off-by: Simon Glass 
---

 tools/binman/fmap_util.py | 4 ++--
 tools/dtoc/fdt.py | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 02/10] patman: Correct lz4 compression parameters

2021-01-23 Thread Simon Glass
At present on large files, lz4 uses a larger block size (e.g. 256KB) than
the 64KB supported by the U-Boot decompression implementation. Also it is
optimised for maximum compression speed, producing larger output than we
would like.

Update the parameters to correct these problems.

Signed-off-by: Simon Glass 
---

 tools/patman/tools.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 08/10] binman: Allow vblock to include devicetree blobs

2021-01-23 Thread Simon Glass
At present if a devicetree blob is included in a vblock it does not deal
with updates. This is because the vblock is created once at the start and
does not have a method to update itself later, after all the entry
contents are finalised.

Fix this by adjusting how the vblock is created.

Also simplify Image.ProcessEntryContents() since it effectively duplicates
the code in Section.ProcessContents().

Signed-off-by: Simon Glass 
---

 tools/binman/etype/blob.py   |  4 ++
 tools/binman/etype/vblock.py | 15 +++-
 tools/binman/ftest.py| 49 +++-
 tools/binman/image.py|  7 +---
 tools/binman/test/189_vblock_content.dts | 31 +++
 5 files changed, 96 insertions(+), 10 deletions(-)
 create mode 100644 tools/binman/test/189_vblock_content.dts

Applied to u-boot-dm, thanks!


Re: [PATCH 10/10] binman: Allow for skip_at_start when reading entries

2021-01-23 Thread Simon Glass
The offset of an entry needs to be adjusted by its skip-at-start value.
This is currently missing when reading entry data. Fix it.

Signed-off-by: Simon Glass 
---

 tools/binman/etype/section.py | 10 ++
 tools/binman/ftest.py | 19 +++
 tools/binman/test/191_read_image_skip.dts | 23 +++
 3 files changed, 48 insertions(+), 4 deletions(-)
 create mode 100644 tools/binman/test/191_read_image_skip.dts

Applied to u-boot-dm, thanks!


Re: [PATCH 09/10] binman: Support alignment of files

2021-01-23 Thread Simon Glass
When packing files it is sometimes useful to align the start of each file,
e.g. if the flash driver can only access 32-bit-aligned data. Provides a
new property to support this.

Signed-off-by: Simon Glass 
---

 tools/binman/etype/files.py   |  4 
 tools/binman/ftest.py |  8 
 tools/binman/state.py | 10 ++
 tools/binman/test/084_files.dts   |  2 +-
 tools/binman/test/190_files_align.dts | 12 
 tools/dtoc/fdt.py | 12 
 tools/dtoc/test_fdt.py|  6 ++
 7 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/test/190_files_align.dts

Applied to u-boot-dm, thanks!


Re: [PATCH 1/1] sandbox: fix sandbox_cmdline_cb_test_fdt()

2021-01-23 Thread Simon Glass
On Fri, 25 Dec 2020 at 08:04, Heinrich Schuchardt  wrote:
>
> fmt does not foresee any parameter.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  arch/sandbox/cpu/start.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 1/1] x86: typo segement

2021-01-23 Thread Simon Glass
On Tue, Dec 22, 2020 at 2:53 PM Heinrich Schuchardt  wrote:
>
> %s/segement/segment/
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  arch/x86/cpu/i386/cpu.c | 2 +-
>  arch/x86/cpu/start.S| 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng 

Applied to u-boot-dm, thanks!


Re: [PATCH 2/5] tpm: cr50: Add a better description and more debug

2021-01-23 Thread Simon Glass
Update the TPM description to include the interrupt mechanicm since this
is useful to know. Also add a warning if the TPM cannot be found and a
debug line if it succeeds.

Signed-off-by: Simon Glass 
---

 drivers/tpm/cr50_i2c.c | 22 ++
 1 file changed, 18 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 4/5] x86: coral: Update an unused pin to reduce power

2021-01-23 Thread Simon Glass
GPIO_25 is not used on coral, so set it up in deep sleep.

Signed-off-by: Simon Glass 
---

 arch/x86/dts/chromebook_coral.dts | 1 +
 1 file changed, 1 insertion(+)

Applied to u-boot-dm, thanks!


Re: [PATCH] doc/sandbox: improve formatting of command line options

2021-01-23 Thread Simon Glass
On Wed, 30 Dec 2020 at 10:10, Heinrich Schuchardt  wrote:
>
> Show the command line options in bold.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  doc/arch/sandbox.rst | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)
>

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 3/5] tpm: cr50: Rename driver to work with of-platdata

2021-01-23 Thread Simon Glass
Update the driver name to match the compatible string, so it can work
with of-platdata.

Signed-off-by: Simon Glass 
---

 drivers/tpm/cr50_i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 1/5] tpm: cr50: Check for valid locality

2021-01-23 Thread Simon Glass
When the Cr50 starts up it doesn't have a valid locality. The driver sets
it to -1 to indicate that. Tracking this allows cr50_i2c_cleanup() to
avoid releasing a locality that was not claimed.

However the helper functions that generate the flags use a u8 type which
cannot support -1, so they return a locality of 0xff.

Fix this by updating the type. With this, 'tpm startup TPM2_SU_CLEAR'
works as expected.

Signed-off-by: Simon Glass 
---

 drivers/tpm/cr50_i2c.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 03/10] binman: Update the TODO list

2021-01-23 Thread Simon Glass
Two of the items have been completed and I thought of another one. Update
the list.

Signed-off-by: Simon Glass 
---

 tools/binman/README | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 06/10] binman: Support finding symbols in sub-sections

2021-01-23 Thread Simon Glass
At present binman only supports resolving symbols in the same section as
the binary that uses it. This is quite limited because we often need to
group entries into different sections.

Enhance the algorithm to search the entire image for symbols.

Signed-off-by: Simon Glass 
---

 tools/binman/elf.py   |  3 +-
 tools/binman/elf_test.py  |  4 ++-
 tools/binman/etype/section.py | 41 +---
 tools/binman/ftest.py | 15 +
 tools/binman/image.py | 45 +++
 tools/binman/test/187_symbols_sub.dts | 22 +
 6 files changed, 123 insertions(+), 7 deletions(-)
 create mode 100644 tools/binman/test/187_symbols_sub.dts

Applied to u-boot-dm, thanks!


Re: [PATCH 05/10] binman: Fix a few file comments

2021-01-23 Thread Simon Glass
Two files have the wrong comment at the top of them. Fix this.

Signed-off-by: Simon Glass 
---

 tools/binman/etype/u_boot_spl_bss_pad.py | 1 -
 tools/binman/etype/u_boot_spl_nodtb.py   | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 04/10] binman: Show the size when writing entries

2021-01-23 Thread Simon Glass
Update the log output to show the size, since this is useful information.

Signed-off-by: Simon Glass 
---

 tools/binman/control.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 07/10] binman: Support reading an image with entry args

2021-01-23 Thread Simon Glass
Normally when an entry is created, any entry arguments it has are required
to be provided, so it can actually generate its contents correctly.

However when an existing image is read, Entry objects are created for each
of the entries in the image. This happens as part of the process of
reading the image into binman.

In this case we don't need the entry arguments, since we do not intend to
regenerate the entries, or at least not unless requested. So there is no
sense in reporting an error for missing entry arguments.

Add a new property for the Image to handle this case. Update the error
reporting to be conditional on this property.

Signed-off-by: Simon Glass 
---

 tools/binman/entry.py|  3 +--
 tools/binman/etype/section.py| 15 +++
 tools/binman/ftest.py| 19 +++
 tools/binman/image.py| 10 --
 tools/binman/test/188_image_entryarg.dts | 21 +
 5 files changed, 64 insertions(+), 4 deletions(-)
 create mode 100644 tools/binman/test/188_image_entryarg.dts

Applied to u-boot-dm, thanks!


[PATCH v3 11/11] tpm: Allow disabling platform hierarchy with TPM2

2021-01-23 Thread Simon Glass
With TPM2 we don't actually lock the TPM once verified boot is finished.
Instead we disable the platform hierarchy which serves the same purpose.
Add an implementation of this so we can safely boot into the kernel.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add definition of TPM2_RC_NV_DEFINED return code

 include/tpm-v2.h | 13 +
 lib/tpm-v2.c | 35 +++
 2 files changed, 48 insertions(+)

diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 1ca1e7e2011..e18c8b1ccca 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -235,6 +235,7 @@ enum tpm2_handles {
 enum tpm2_command_codes {
TPM2_CC_STARTUP = 0x0144,
TPM2_CC_SELF_TEST   = 0x0143,
+   TPM2_CC_HIER_CONTROL= 0x0121,
TPM2_CC_CLEAR   = 0x0126,
TPM2_CC_CLEARCONTROL= 0x0127,
TPM2_CC_HIERCHANGEAUTH  = 0x0129,
@@ -272,6 +273,7 @@ enum tpm2_return_codes {
TPM2_RC_COMMAND_CODE= TPM2_RC_VER1 + 0x0043,
TPM2_RC_AUTHSIZE= TPM2_RC_VER1 + 0x0044,
TPM2_RC_AUTH_CONTEXT= TPM2_RC_VER1 + 0x0045,
+   TPM2_RC_NV_DEFINED  = TPM2_RC_VER1 + 0x004c,
TPM2_RC_NEEDS_TEST  = TPM2_RC_VER1 + 0x0053,
TPM2_RC_WARN= 0x0900,
TPM2_RC_TESTING = TPM2_RC_WARN + 0x000A,
@@ -582,4 +584,15 @@ u32 tpm2_get_random(struct udevice *dev, void *data, u32 
count);
  */
 u32 tpm2_write_lock(struct udevice *dev, u32 index);
 
+/**
+ * Disable access to any platform data
+ *
+ * This can be called to close off access to the firmware data in the data,
+ * before calling the kernel.
+ *
+ * @devTPM device
+ * @return code of the operation
+ */
+u32 tpm2_disable_platform_hierarchy(struct udevice *dev);
+
 #endif /* __TPM_V2_H */
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 35f3917aeb5..1b32661979d 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -625,3 +625,38 @@ u32 tpm2_write_lock(struct udevice *dev, u32 index)
 
return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
+
+u32 tpm2_disable_platform_hierarchy(struct udevice *dev)
+{
+   struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
+   tpm_u32(10 + 4 + 13 + 5),   /* Length */
+   tpm_u32(TPM2_CC_HIER_CONTROL),  /* Command code */
+
+   /* 4 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
+
+   /* session header 9 bytes */
+   tpm_u32(9), /* Header size */
+   tpm_u32(TPM2_RS_PW),/* Password authorisation */
+   tpm_u16(0), /* nonce_size */
+   0,  /* session_attrs */
+   tpm_u16(0), /* auth_size */
+
+   /* payload 5 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Hierarchy to disable */
+   0,  /* 0=disable */
+   };
+   int ret;
+
+   ret = tpm_sendrecv_command(dev, command_v2, NULL, NULL);
+   log_info("ret=%s, %x\n", dev->name, ret);
+   if (ret)
+   return ret;
+
+   priv->plat_hier_disabled = true;
+
+   return 0;
+}
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v3 10/11] tpm: Add TPM2 support for write_lock

2021-01-23 Thread Simon Glass
Implement this API function for TPM2.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/tpm-v2.h | 12 
 lib/tpm-v2.c | 23 +++
 lib/tpm_api.c|  2 +-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 6a400771af1..1ca1e7e2011 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -241,6 +241,7 @@ enum tpm2_command_codes {
TPM2_CC_NV_DEFINE_SPACE = 0x012a,
TPM2_CC_PCR_SETAUTHPOL  = 0x012C,
TPM2_CC_NV_WRITE= 0x0137,
+   TPM2_CC_NV_WRITELOCK= 0x0138,
TPM2_CC_DAM_RESET   = 0x0139,
TPM2_CC_DAM_PARAMETERS  = 0x013A,
TPM2_CC_NV_READ = 0x014E,
@@ -570,4 +571,15 @@ u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char 
*pw,
  */
 u32 tpm2_get_random(struct udevice *dev, void *data, u32 count);
 
+/**
+ * Lock data in the TPM
+ *
+ * Once locked the data cannot be written until after a reboot
+ *
+ * @devTPM device
+ * @index  Index of data to lock
+ * @return code of the operation
+ */
+u32 tpm2_write_lock(struct udevice *dev, u32 index);
+
 #endif /* __TPM_V2_H */
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 7bf43264ab0..35f3917aeb5 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -602,3 +602,26 @@ u32 tpm2_get_random(struct udevice *dev, void *data, u32 
count)
 
return 0;
 }
+
+u32 tpm2_write_lock(struct udevice *dev, u32 index)
+{
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
+   tpm_u32(10 + 8 + 13), /* Length */
+   tpm_u32(TPM2_CC_NV_WRITELOCK), /* Command code */
+
+   /* handles 8 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
+   tpm_u32(HR_NV_INDEX + index),   /* Password authorisation */
+
+   /* session header 9 bytes */
+   tpm_u32(9), /* Header size */
+   tpm_u32(TPM2_RS_PW),/* Password authorisation */
+   tpm_u16(0), /* nonce_size */
+   0,  /* session_attrs */
+   tpm_u16(0), /* auth_size */
+   };
+
+   return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
+}
diff --git a/lib/tpm_api.c b/lib/tpm_api.c
index 687fc8bc7ee..4c662640a92 100644
--- a/lib/tpm_api.c
+++ b/lib/tpm_api.c
@@ -144,7 +144,7 @@ u32 tpm_write_lock(struct udevice *dev, u32 index)
if (is_tpm1(dev))
return -ENOSYS;
else if (is_tpm2(dev))
-   return -ENOSYS;
+   return tpm2_write_lock(dev, index);
else
return -ENOSYS;
 }
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v3 05/11] tpm: Switch TPMv1 over to use the new API

2021-01-23 Thread Simon Glass
Take over the plain 'tpm_...' functions for use by the new TPM API. Rename
all the TPMv1 functions so they are called from the API.

Update the TPMv1 functions so that they are called from the API. Change
existing users to use the tpm1_ prefix so they don't need to go through
the API, which might introduce uncertainty.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 board/gdsys/a38x/controlcenterdc.c|   4 +-
 board/gdsys/a38x/hre.c|  28 +++
 board/gdsys/a38x/keyprogram.c |   8 +-
 board/gdsys/mpc8308/gazerbeam.c   |   4 +-
 board/gdsys/p1022/controlcenterd-id.c |  36 
 cmd/tpm-v1.c  |  25 +++---
 cmd/tpm_test.c|  40 +
 include/tpm-v1.h  |  76 -
 lib/Makefile  |   1 +
 lib/tpm-v1.c  | 115 --
 10 files changed, 168 insertions(+), 169 deletions(-)

diff --git a/board/gdsys/a38x/controlcenterdc.c 
b/board/gdsys/a38x/controlcenterdc.c
index a2287f9deb1..187ac8c4f9f 100644
--- a/board/gdsys/a38x/controlcenterdc.c
+++ b/board/gdsys/a38x/controlcenterdc.c
@@ -286,8 +286,8 @@ int last_stage_init(void)
ccdc_eth_init();
 #endif
ret = get_tpm();
-   if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
-   tpm_continue_self_test(tpm)) {
+   if (ret || tpm_init(tpm) || tpm1_startup(tpm, TPM_ST_CLEAR) ||
+   tpm1_continue_self_test(tpm)) {
return 1;
}
 
diff --git a/board/gdsys/a38x/hre.c b/board/gdsys/a38x/hre.c
index 699241b3e62..de5411a6b93 100644
--- a/board/gdsys/a38x/hre.c
+++ b/board/gdsys/a38x/hre.c
@@ -107,8 +107,8 @@ static int get_tpm_nv_size(struct udevice *tpm, uint32_t 
index, uint32_t *size)
uint8_t *ptr;
uint16_t v16;
 
-   err = tpm_get_capability(tpm, TPM_CAP_NV_INDEX, index,
-info, sizeof(info));
+   err = tpm1_get_capability(tpm, TPM_CAP_NV_INDEX, index, info,
+ sizeof(info));
if (err) {
printf("tpm_get_capability(CAP_NV_INDEX, %08x) failed: %u\n",
   index, err);
@@ -150,8 +150,8 @@ static int find_key(struct udevice *tpm, const uint8_t 
auth[20],
unsigned int i;
 
/* fetch list of already loaded keys in the TPM */
-   err = tpm_get_capability(tpm, TPM_CAP_HANDLE, TPM_RT_KEY, buf,
-sizeof(buf));
+   err = tpm1_get_capability(tpm, TPM_CAP_HANDLE, TPM_RT_KEY, buf,
+ sizeof(buf));
if (err)
return -1;
key_count = get_unaligned_be16(buf);
@@ -162,8 +162,8 @@ static int find_key(struct udevice *tpm, const uint8_t 
auth[20],
/* now search a(/ the) key which we can access with the given auth */
for (i = 0; i < key_count; ++i) {
buf_len = sizeof(buf);
-   err = tpm_get_pub_key_oiap(tpm, key_handles[i], auth, buf,
-  _len);
+   err = tpm1_get_pub_key_oiap(tpm, key_handles[i], auth, buf,
+   _len);
if (err && err != TPM_AUTHFAIL)
return -1;
if (err)
@@ -192,8 +192,8 @@ static int read_common_data(struct udevice *tpm)
if (get_tpm_nv_size(tpm, NV_COMMON_DATA_INDEX, ) ||
size < NV_COMMON_DATA_MIN_SIZE)
return 1;
-   err = tpm_nv_read_value(tpm, NV_COMMON_DATA_INDEX,
-   buf, min(sizeof(buf), size));
+   err = tpm1_nv_read_value(tpm, NV_COMMON_DATA_INDEX, buf,
+min(sizeof(buf), size));
if (err) {
printf("tpm_nv_read_value() failed: %u\n", err);
return 1;
@@ -270,8 +270,8 @@ static struct h_reg *access_hreg(struct udevice *tpm, 
uint8_t spec,
if (mode & HREG_RD) {
if (!result->valid) {
if (IS_PCR_HREG(spec)) {
-   hre_tpm_err = tpm_pcr_read(tpm, HREG_IDX(spec),
-   result->digest, 20);
+   hre_tpm_err = tpm1_pcr_read(tpm, HREG_IDX(spec),
+   result->digest, 20);
result->valid = (hre_tpm_err == TPM_SUCCESS);
} else if (IS_FIX_HREG(spec)) {
switch (HREG_IDX(spec)) {
@@ -357,8 +357,8 @@ static int hre_op_loadkey(struct udevice *tpm, struct h_reg 
*src_reg,
return -1;
if (find_key(tpm, src_reg->digest, dst_reg->digest, _handle))
return -1;
-   hre_tpm_err = tpm_load_key2_oiap(tpm, parent_handle, key, key_size,
-src_reg->digest, _handle);
+   hre_tpm_err = tpm1_load_key2_oiap(tpm, 

[PATCH v3 09/11] tpm: Add TPM2 support for read/write values

2021-01-23 Thread Simon Glass
Implement this API function for TPM2.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/tpm-common.h |  3 ++
 include/tpm-v2.h | 38 
 lib/tpm-v2.c | 84 
 lib/tpm_api.c|  4 +--
 4 files changed, 127 insertions(+), 2 deletions(-)

diff --git a/include/tpm-common.h b/include/tpm-common.h
index e29b10b1766..080183779b3 100644
--- a/include/tpm-common.h
+++ b/include/tpm-common.h
@@ -53,6 +53,8 @@ enum tpm_version {
  * @buf:   Buffer used during the exchanges with the chip
  * @pcr_count: Number of PCR per bank
  * @pcr_select_min:Minimum size in bytes of the pcrSelect array
+ * @plat_hier_disabled:Platform hierarchy has been disabled (TPM is 
locked
+ * down until next reboot)
  */
 struct tpm_chip_priv {
enum tpm_version version;
@@ -64,6 +66,7 @@ struct tpm_chip_priv {
/* TPM v2 specific data */
uint pcr_count;
uint pcr_select_min;
+   bool plat_hier_disabled;
 };
 
 /**
diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 2766dc72a65..6a400771af1 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -240,6 +240,7 @@ enum tpm2_command_codes {
TPM2_CC_HIERCHANGEAUTH  = 0x0129,
TPM2_CC_NV_DEFINE_SPACE = 0x012a,
TPM2_CC_PCR_SETAUTHPOL  = 0x012C,
+   TPM2_CC_NV_WRITE= 0x0137,
TPM2_CC_DAM_RESET   = 0x0139,
TPM2_CC_DAM_PARAMETERS  = 0x013A,
TPM2_CC_NV_READ = 0x014E,
@@ -354,6 +355,20 @@ enum {
TPM_MAX_BUF_SIZE= 1260,
 };
 
+enum {
+   /* Secure storage for firmware settings */
+   TPM_HT_PCR = 0,
+   TPM_HT_NV_INDEX,
+   TPM_HT_HMAC_SESSION,
+   TPM_HT_POLICY_SESSION,
+
+   HR_SHIFT= 24,
+   HR_PCR  = TPM_HT_PCR << HR_SHIFT,
+   HR_HMAC_SESSION = TPM_HT_HMAC_SESSION << HR_SHIFT,
+   HR_POLICY_SESSION   = TPM_HT_POLICY_SESSION << HR_SHIFT,
+   HR_NV_INDEX = TPM_HT_NV_INDEX << HR_SHIFT,
+};
+
 /**
  * Issue a TPM2_Startup command.
  *
@@ -418,6 +433,29 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 
space_index,
 u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
const u8 *digest, u32 digest_len);
 
+/**
+ * Read data from the secure storage
+ *
+ * @devTPM device
+ * @index  Index of data to read
+ * @data   Place to put data
+ * @count  Number of bytes of data
+ * @return code of the operation
+ */
+u32 tpm2_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count);
+
+/**
+ * Write data to the secure storage
+ *
+ * @devTPM device
+ * @index  Index of data to write
+ * @data   Data to write
+ * @count  Number of bytes of data
+ * @return code of the operation
+ */
+u32 tpm2_nv_write_value(struct udevice *dev, u32 index, const void *data,
+   u32 count);
+
 /**
  * Issue a TPM2_PCR_Read command.
  *
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index aea1dfb6ba0..7bf43264ab0 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -170,6 +170,90 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 
algorithm,
return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
+u32 tpm2_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count)
+{
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
+   tpm_u32(10 + 8 + 4 + 9 + 4),/* Length */
+   tpm_u32(TPM2_CC_NV_READ),   /* Command code */
+
+   /* handles 8 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
+   tpm_u32(HR_NV_INDEX + index),   /* Password authorisation */
+
+   /* AUTH_SESSION */
+   tpm_u32(9), /* Authorization size */
+   tpm_u32(TPM2_RS_PW),/* Session handle */
+   tpm_u16(0), /* Size of  */
+   /*  (if any) */
+   0,  /* Attributes: Cont/Excl/Rst */
+   tpm_u16(0), /* Size of  */
+   /*  (if any) */
+
+   tpm_u16(count), /* Number of bytes */
+   tpm_u16(0), /* Offset */
+   };
+   size_t response_len = COMMAND_BUFFER_SIZE;
+   u8 response[COMMAND_BUFFER_SIZE];
+   int ret;
+   u16 tag;
+   u32 size, code;
+
+   ret = tpm_sendrecv_command(dev, command_v2, response, _len);
+   if (ret)
+   return log_msg_ret("read", ret);
+   if (unpack_byte_string(response, response_len, "wdds",
+  0, , 2, , 6, ,
+  16, data, count))
+   return 

[PATCH v3 08/11] tpm: Add an implementation of define_space

2021-01-23 Thread Simon Glass
Add support for this so that the TPM can be set up for use with
Chromium OS verified boot.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add a comment to the offset and fix up the value

 include/tpm-v2.h | 18 ++
 lib/tpm-v2.c | 48 
 2 files changed, 66 insertions(+)

diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index fab6b86ca2f..2766dc72a65 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -238,6 +238,7 @@ enum tpm2_command_codes {
TPM2_CC_CLEAR   = 0x0126,
TPM2_CC_CLEARCONTROL= 0x0127,
TPM2_CC_HIERCHANGEAUTH  = 0x0129,
+   TPM2_CC_NV_DEFINE_SPACE = 0x012a,
TPM2_CC_PCR_SETAUTHPOL  = 0x012C,
TPM2_CC_DAM_RESET   = 0x0139,
TPM2_CC_DAM_PARAMETERS  = 0x013A,
@@ -386,6 +387,23 @@ u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no 
full_test);
 u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
   const ssize_t pw_sz);
 
+/**
+ * Issue a TPM_NV_DefineSpace command
+ *
+ * This allows a space to be defined with given attributes and policy
+ *
+ * @devTPM device
+ * @space_indexindex of the area
+ * @space_size size of area in bytes
+ * @nv_attributes  TPM_NV_ATTRIBUTES of the area
+ * @nv_policy  policy to use
+ * @nv_policy_size size of the policy
+ * @return return code of the operation
+ */
+u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index,
+size_t space_size, u32 nv_attributes,
+const u8 *nv_policy, size_t nv_policy_size);
+
 /**
  * Issue a TPM2_PCR_Extend command.
  *
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index c4e869ec5b5..aea1dfb6ba0 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -81,6 +81,54 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char 
*pw,
return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
+u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index,
+size_t space_size, u32 nv_attributes,
+const u8 *nv_policy, size_t nv_policy_size)
+{
+   /*
+* Calculate the offset of the nv_policy piece by adding each of the
+* chunks below.
+*/
+   uint offset = 10 + 8 + 13 + 14;
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
+   tpm_u32(offset + nv_policy_size),/* Length */
+   tpm_u32(TPM2_CC_NV_DEFINE_SPACE),/* Command code */
+
+   /* handles 8 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
+
+   /* session header 13 bytes */
+   tpm_u32(9), /* Header size */
+   tpm_u32(TPM2_RS_PW),/* Password authorisation */
+   tpm_u16(0), /* nonce_size */
+   0,  /* session_attrs */
+   tpm_u16(0), /* auth_size */
+
+   /* message 14 bytes + policy */
+   tpm_u16(12 + nv_policy_size),   /* size */
+   tpm_u32(space_index),
+   tpm_u16(TPM2_ALG_SHA256),
+   tpm_u32(nv_attributes),
+   tpm_u16(nv_policy_size),
+   /* nv_policy */
+   };
+   int ret;
+
+   /*
+* Fill the command structure starting from the first buffer:
+* - the password (if any)
+*/
+   ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
+  offset, nv_policy, nv_policy_size);
+   offset += nv_policy_size;
+   if (ret)
+   return TPM_LIB_ERROR;
+
+   return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
+}
+
 u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
const u8 *digest, u32 digest_len)
 {
-- 
2.30.0.280.ga3ce27912f-goog



[PATCH v3 07/11] tpm: Reduce duplication in a few functions

2021-01-23 Thread Simon Glass
Update tpm2_clear() and tpm2_pcr_extend() so that the command size
is not repeated twice. Add a small comment to the latter.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add comments for the offset value

 lib/tpm-v2.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 1f3deb06e48..c4e869ec5b5 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -47,9 +47,11 @@ u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no 
full_test)
 u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
   const ssize_t pw_sz)
 {
+   /* Length of the message header, up to start of password */
+   uint offset = 27;
u8 command_v2[COMMAND_BUFFER_SIZE] = {
tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
-   tpm_u32(27 + pw_sz),/* Length */
+   tpm_u32(offset + pw_sz),/* Length */
tpm_u32(TPM2_CC_CLEAR), /* Command code */
 
/* HANDLE */
@@ -64,7 +66,6 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char 
*pw,
tpm_u16(pw_sz), /* Size of  */
/* STRING(pw)   (if any) */
};
-   unsigned int offset = 27;
int ret;
 
/*
@@ -83,9 +84,11 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char 
*pw,
 u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
const u8 *digest, u32 digest_len)
 {
+   /* Length of the message header, up to start of digest */
+   uint offset = 33;
u8 command_v2[COMMAND_BUFFER_SIZE] = {
tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
-   tpm_u32(33 + digest_len),   /* Length */
+   tpm_u32(offset + digest_len),   /* Length */
tpm_u32(TPM2_CC_PCR_EXTEND),/* Command code */
 
/* HANDLE */
@@ -99,11 +102,12 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 
algorithm,
0,  /* Attributes: Cont/Excl/Rst */
tpm_u16(0), /* Size of  */
/*  (if any) */
+
+   /* hashes */
tpm_u32(1), /* Count (number of hashes) */
tpm_u16(algorithm), /* Algorithm of the hash */
/* STRING(digest)  Digest */
};
-   unsigned int offset = 33;
int ret;
 
/*
@@ -112,7 +116,6 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 
algorithm,
 */
ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
   offset, digest, digest_len);
-   offset += digest_len;
if (ret)
return TPM_LIB_ERROR;
 
-- 
2.30.0.280.ga3ce27912f-goog



  1   2   >