[PATCH v5 14/14] MAINTAINERS: MediaTek: add USB related files

2020-04-09 Thread Chunfeng Yun
Add dt-binding files of xhci-mtk and phys, C files of
phys.

Signed-off-by: Chunfeng Yun 
---
v5: new patch
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 37ff21a037..4fe3bf949e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -243,9 +243,12 @@ S: Maintained
 F: arch/arm/mach-mediatek/
 F: arch/arm/include/asm/arch-mediatek/
 F: board/mediatek/
+F: doc/device-tree-bindings/phy/phy-mtk-*
+F: doc/device-tree-bindings/usb/mediatek,*
 F: doc/README.mediatek
 F: drivers/clk/mediatek/
 F: drivers/mmc/mtk-sd.c
+F: drivers/phy/phy-mtk-*
 F: drivers/pinctrl/mediatek/
 F: drivers/power/domain/mtk-power-domain.c
 F: drivers/ram/mediatek/
-- 
2.25.1


[PATCH v5 11/14] arm: dts: mt7629: add usb related nodes

2020-04-09 Thread Chunfeng Yun
Add usb, phy and clock nodes

Signed-off-by: Chunfeng Yun 
---
v3~v5: no changes

v2:
1. remove fixed clock clk20m
---
 arch/arm/dts/mt7629-rfb.dts |  8 
 arch/arm/dts/mt7629.dtsi| 41 +
 2 files changed, 49 insertions(+)

diff --git a/arch/arm/dts/mt7629-rfb.dts b/arch/arm/dts/mt7629-rfb.dts
index 687fe1c029..bf84f76344 100644
--- a/arch/arm/dts/mt7629-rfb.dts
+++ b/arch/arm/dts/mt7629-rfb.dts
@@ -82,6 +82,14 @@
status = "okay";
 };
 
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_pins>;
diff --git a/arch/arm/dts/mt7629.dtsi b/arch/arm/dts/mt7629.dtsi
index a33a74a556..d1c99c5d6a 100644
--- a/arch/arm/dts/mt7629.dtsi
+++ b/arch/arm/dts/mt7629.dtsi
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "skeleton.dtsi"
 
 / {
@@ -222,6 +223,46 @@
#size-cells = <0>;
};
 
+   ssusbsys: ssusbsys@1a00 {
+   compatible = "mediatek,mt7629-ssusbsys", "syscon";
+   reg = <0x1a00 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   xhci: usb@1a0c {
+   compatible = "mediatek,mt7629-xhci", "mediatek,mtk-xhci";
+   reg = <0x1a0c 0x1000>, <0x1a0c3e00 0x0100>;
+   reg-names = "mac", "ippc";
+   power-domains = < MT7629_POWER_DOMAIN_HIF1>;
+   clocks = < CLK_SSUSB_SYS_EN>,
+< CLK_SSUSB_REF_EN>,
+< CLK_SSUSB_MCU_EN>,
+< CLK_SSUSB_DMA_EN>;
+   clock-names = "sys_ck", "ref_ck", "mcu_ck", "dma_ck";
+   phys = < PHY_TYPE_USB2>, < PHY_TYPE_USB3>;
+   status = "disabled";
+   };
+
+   u3phy: usb-phy@1a0c4000 {
+   compatible = "mediatek,mt7629-tphy", "mediatek,generic-tphy-v2";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0 0x1a0c4000 0x1000>;
+   status = "disabled";
+
+   u2port0: usb-phy@0 {
+   reg = <0x0 0x0700>;
+   #phy-cells = <1>;
+   clocks = < CLK_SSUSB_U2_PHY_EN>;
+   clock-names = "ref";
+   };
+
+   u3port0: usb-phy@700 {
+   reg = <0x0700 0x0700>;
+   #phy-cells = <1>;
+   };
+   };
+
ethsys: syscon@1b00 {
compatible = "mediatek,mt7629-ethsys", "syscon";
reg = <0x1b00 0x1000>;
-- 
2.25.1


[PATCH v5 10/14] xhci: mediatek: Add support for MTK xHCI host controller

2020-04-09 Thread Chunfeng Yun
This patch is used to support the on-chip xHCI controller on
MediaTek SoCs, currently control/bulk/interrupt transfers are
supported.

Signed-off-by: Chunfeng Yun 
---
v5:
1. print error number suggested by Marek
2. support interrupt transfer

v4:
1. use phy_bulk API

v3:
1. use macro approach to access registers suggested by Marek

v2:
1. use clk_bulk to get clocks suggested by Marek
2. use clrsetbits_le32() etc suggeseted by Marek
---
 drivers/usb/host/Kconfig|   6 +
 drivers/usb/host/Makefile   |   1 +
 drivers/usb/host/xhci-mtk.c | 296 
 drivers/usb/host/xhci.c |  10 ++
 include/usb/xhci.h  |   3 +
 5 files changed, 316 insertions(+)
 create mode 100644 drivers/usb/host/xhci-mtk.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 0987ff25b1..931af268f4 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -30,6 +30,12 @@ config USB_XHCI_DWC3_OF_SIMPLE
  Support USB2/3 functionality in simple SoC integrations with
  USB controller based on the DesignWare USB3 IP Core.
 
+config USB_XHCI_MTK
+   bool "Support for MediaTek on-chip xHCI USB controller"
+   depends on ARCH_MEDIATEK
+   help
+ Enables support for the on-chip xHCI controller on MediaTek SoCs.
+
 config USB_XHCI_MVEBU
bool "MVEBU USB 3.0 support"
default y
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 7feeff679c..104821f188 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_USB_XHCI_DWC3_OF_SIMPLE) += dwc3-of-simple.o
 obj-$(CONFIG_USB_XHCI_ROCKCHIP) += xhci-rockchip.o
 obj-$(CONFIG_USB_XHCI_EXYNOS) += xhci-exynos5.o
 obj-$(CONFIG_USB_XHCI_FSL) += xhci-fsl.o
+obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o
 obj-$(CONFIG_USB_XHCI_MVEBU) += xhci-mvebu.o
 obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
new file mode 100644
index 00..93293ca180
--- /dev/null
+++ b/drivers/usb/host/xhci-mtk.c
@@ -0,0 +1,296 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 MediaTek, Inc.
+ * Authors: Chunfeng Yun 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* IPPC (IP Port Control) registers */
+#define IPPC_IP_PW_CTRL0   0x00
+#define CTRL0_IP_SW_RSTBIT(0)
+
+#define IPPC_IP_PW_CTRL1   0x04
+#define CTRL1_IP_HOST_PDN  BIT(0)
+
+#define IPPC_IP_PW_STS10x10
+#define STS1_IP_SLEEP_STS  BIT(30)
+#define STS1_U3_MAC_RSTBIT(16)
+#define STS1_XHCI_RST  BIT(11)
+#define STS1_SYS125_RSTBIT(10)
+#define STS1_REF_RST   BIT(8)
+#define STS1_SYSPLL_STABLE BIT(0)
+
+#define IPPC_IP_XHCI_CAP   0x24
+#define CAP_U3_PORT_NUM(p) ((p) & 0xff)
+#define CAP_U2_PORT_NUM(p) (((p) >> 8) & 0xff)
+
+#define IPPC_U3_CTRL_0P0x30
+#define CTRL_U3_PORT_HOST_SEL  BIT(2)
+#define CTRL_U3_PORT_PDN   BIT(1)
+#define CTRL_U3_PORT_DIS   BIT(0)
+
+#define IPPC_U2_CTRL_0P0x50
+#define CTRL_U2_PORT_HOST_SEL  BIT(2)
+#define CTRL_U2_PORT_PDN   BIT(1)
+#define CTRL_U2_PORT_DIS   BIT(0)
+
+#define IPPC_U3_CTRL(p)(IPPC_U3_CTRL_0P + ((p) * 0x08))
+#define IPPC_U2_CTRL(p)(IPPC_U2_CTRL_0P + ((p) * 0x08))
+
+struct mtk_xhci {
+   struct xhci_ctrl ctrl;  /* Needs to come first in this struct! */
+   struct xhci_hccr *hcd;
+   void __iomem *ippc;
+   struct udevice *dev;
+   struct udevice *vusb33_supply;
+   struct udevice *vbus_supply;
+   struct clk_bulk clks;
+   struct phy_bulk phys;
+   int num_u2ports;
+   int num_u3ports;
+};
+
+static int xhci_mtk_host_enable(struct mtk_xhci *mtk)
+{
+   u32 value;
+   u32 check_val;
+   int ret;
+   int i;
+
+   /* power on host ip */
+   clrbits_le32(mtk->ippc + IPPC_IP_PW_CTRL1, CTRL1_IP_HOST_PDN);
+
+   /* power on and enable all u3 ports */
+   for (i = 0; i < mtk->num_u3ports; i++) {
+   clrsetbits_le32(mtk->ippc + IPPC_U3_CTRL(i),
+   CTRL_U3_PORT_PDN | CTRL_U3_PORT_DIS,
+   CTRL_U3_PORT_HOST_SEL);
+   }
+
+   /* power on and enable all u2 ports */
+   for (i = 0; i < mtk->num_u2ports; i++) {
+   clrsetbits_le32(mtk->ippc + IPPC_U2_CTRL(i),
+   CTRL_U2_PORT_PDN | CTRL_U2_PORT_DIS,
+   CTRL_U2_PORT_HOST_SEL);
+   }
+
+   /*
+* wait for clocks to be stable, and clock domains reset to
+* be inactive after power on and 

[PATCH v5 12/14] dt-bindings: phy-mtk-tphy: add properties of address mapping and clocks

2020-04-09 Thread Chunfeng Yun
1. add the address mapping related properties;
2. make "ref" clock optional, and add optional clock "da_ref";
3. add the banks layout of TPHY V1 and V2;

Signed-off-by: Chunfeng Yun 
---
v2~v5: no changes
---
 doc/device-tree-bindings/phy/phy-mtk-tphy.txt | 78 ---
 1 file changed, 68 insertions(+), 10 deletions(-)

diff --git a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt 
b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
index 037c5a4be5..8cd23d8c0b 100644
--- a/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
+++ b/doc/device-tree-bindings/phy/phy-mtk-tphy.txt
@@ -7,10 +7,17 @@ controllers on MediaTek SoCs, such as, USB2.0, USB3.0, PCIe, 
and SATA.
 Required properties (controller (parent) node):
  - compatible  : should be one of
  "mediatek,generic-tphy-v1"
- - clocks  : (deprecated, use port's clocks instead) a list of phandle +
- clock-specifier pairs, one for each entry in clock-names
- - clock-names : (deprecated, use port's one instead) must contain
- "u3phya_ref": for reference clock of usb3.0 analog phy.
+ "mediatek,generic-tphy-v2"
+
+- #address-cells:  the number of cells used to represent physical
+   base addresses.
+- #size-cells: the number of cells used to represent the size of an address.
+- ranges:  the address mapping relationship to the parent, defined with
+   - empty value: if optional 'reg' is used.
+   - non-empty value: if optional 'reg' is not used. should set
+   the child's base address to 0, the physical address
+   within parent's address space, and the length of
+   the address map.
 
 Required nodes : a sub-node is required for each port the controller
  provides. Address range information including the usual
@@ -27,12 +34,6 @@ Optional properties (controller (parent) node):
 
 Required properties (port (child) node):
 - reg  : address and length of the register set for the port.
-- clocks   : a list of phandle + clock-specifier pairs, one for each
- entry in clock-names
-- clock-names  : must contain
- "ref": 48M reference clock for HighSpeed analog phy; and 26M
-   reference clock for SuperSpeed analog phy, sometimes is
-   24M, 25M or 27M, depended on platform.
 - #phy-cells   : should be 1 (See second example)
  cell after port phandle is phy type from:
- PHY_TYPE_USB2
@@ -40,6 +41,17 @@ Required properties (port (child) node):
- PHY_TYPE_PCIE
- PHY_TYPE_SATA
 
+Optional properties (port (child) node):
+- clocks   : a list of phandle + clock-specifier pairs, one for each
+ entry in clock-names
+- clock-names  : may contain
+ "ref": 48M reference clock for HighSpeed (digital) phy; and 
26M
+   reference clock for SuperSpeed (digital) phy, sometimes 
is
+   24M, 25M or 27M, depended on platform.
+ "da_ref": the reference clock of analog phy, used if the 
clocks
+   of analog and digital phys are separated, otherwise uses
+   "ref" clock only if needed.
+
 Example:
 
u3phy2: usb-phy@1a244000 {
@@ -84,3 +96,49 @@ usb30: usb@1127 {
phy-names = "usb2-0", "usb3-0";
...
 };
+
+Layout differences of banks between TPHY V1 and V2
+-
+IP V1:
+portoffsetbank
+shared  0xSPLLC
+0x0100FMREG
+u2 port00x0800U2PHY_COM
+u3 port00x0900U3PHYD
+0x0a00U3PHYD_BANK2
+0x0b00U3PHYA
+0x0c00U3PHYA_DA
+u2 port10x1000U2PHY_COM
+u3 port10x1100U3PHYD
+0x1200U3PHYD_BANK2
+0x1300U3PHYA
+0x1400U3PHYA_DA
+u2 port20x1800U2PHY_COM
+...
+
+IP V2:
+portoffsetbank
+u2 port00xMISC
+0x0100FMREG
+0x0300U2PHY_COM
+u3 port00x0700SPLLC
+0x0800CHIP
+0x0900U3PHYD
+0x0a00U3PHYD_BANK2
+0x0b00U3PHYA
+0x0c00U3PHYA_DA
+u2 port10x1000MISC
+0x1100FMREG
+0x1300U2PHY_COM
+u3 port10x1700SPLLC
+0x1800CHIP
+0x1900U3PHYD
+0x1a00U3PHYD_BANK2
+0x1b00U3PHYA
+0x1c00U3PHYA_DA
+u2 port20x2000MISC
+...
+
+SPLLC shared by u3 ports and FMREG shared by u2 ports on
+TPHY V1 are put back into each port; a new bank MISC for
+u2 ports and CHIP for u3 ports are added on TPHY V2.
-- 
2.25.1


[PATCH v5 08/14] phy: phy-mtk-tphy: add support new version

2020-04-09 Thread Chunfeng Yun
The new version removes all shared banks between multi-phys

Signed-off-by: Chunfeng Yun 
---
v2~v5: no changes
---
 drivers/phy/phy-mtk-tphy.c | 68 +++---
 1 file changed, 63 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 71bc706c6e..20167fe7cb 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -28,6 +28,17 @@
 #define SSUSB_SIFSLV_V1_U3PHYD 0x000
 #define SSUSB_SIFSLV_V1_U3PHYA 0x200
 
+/* version V2 sub-banks offset base address */
+/* u2 phy banks */
+#define SSUSB_SIFSLV_V2_MISC   0x000
+#define SSUSB_SIFSLV_V2_U2FREQ 0x100
+#define SSUSB_SIFSLV_V2_U2PHY_COM  0x300
+/* u3/pcie/sata phy banks */
+#define SSUSB_SIFSLV_V2_SPLLC  0x000
+#define SSUSB_SIFSLV_V2_CHIP   0x100
+#define SSUSB_SIFSLV_V2_U3PHYD 0x200
+#define SSUSB_SIFSLV_V2_U3PHYA 0x400
+
 #define U3P_USBPHYACR0 0x000
 #define PA0_RG_U2PLL_FORCE_ON  BIT(15)
 #define PA0_RG_USB20_INTR_EN   BIT(5)
@@ -162,6 +173,11 @@
 #define XC3_RG_U3_XTAL_RX_PWD  BIT(9)
 #define XC3_RG_U3_FRC_XTAL_RX_PWD  BIT(8)
 
+enum mtk_phy_version {
+   MTK_TPHY_V1 = 1,
+   MTK_TPHY_V2,
+};
+
 struct u2phy_banks {
void __iomem *misc;
void __iomem *fmreg;
@@ -192,6 +208,7 @@ struct mtk_phy_instance {
 struct mtk_tphy {
struct udevice *dev;
void __iomem *sif_base;
+   enum mtk_phy_version version;
struct mtk_phy_instance **phys;
int nphys;
 };
@@ -304,6 +321,9 @@ static void pcie_phy_instance_init(struct mtk_tphy *tphy,
 {
struct u3phy_banks *u3_banks = >u3_banks;
 
+   if (tphy->version != MTK_TPHY_V1)
+   return;
+
clrsetbits_le32(u3_banks->phya + U3P_U3_PHYA_DA_REG0,
P3A_RG_XTAL_EXT_PE1H | P3A_RG_XTAL_EXT_PE2H,
P3A_RG_XTAL_EXT_PE1H_VAL(0x2) |
@@ -398,6 +418,31 @@ static void phy_v1_banks_init(struct mtk_tphy *tphy,
}
 }
 
+static void phy_v2_banks_init(struct mtk_tphy *tphy,
+ struct mtk_phy_instance *instance)
+{
+   struct u2phy_banks *u2_banks = >u2_banks;
+   struct u3phy_banks *u3_banks = >u3_banks;
+
+   switch (instance->type) {
+   case PHY_TYPE_USB2:
+   u2_banks->misc = instance->port_base + SSUSB_SIFSLV_V2_MISC;
+   u2_banks->fmreg = instance->port_base + SSUSB_SIFSLV_V2_U2FREQ;
+   u2_banks->com = instance->port_base + SSUSB_SIFSLV_V2_U2PHY_COM;
+   break;
+   case PHY_TYPE_USB3:
+   case PHY_TYPE_PCIE:
+   u3_banks->spllc = instance->port_base + SSUSB_SIFSLV_V2_SPLLC;
+   u3_banks->chip = instance->port_base + SSUSB_SIFSLV_V2_CHIP;
+   u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V2_U3PHYD;
+   u3_banks->phya = instance->port_base + SSUSB_SIFSLV_V2_U3PHYA;
+   break;
+   default:
+   dev_err(tphy->dev, "incompatible PHY type\n");
+   return;
+   }
+}
+
 static int mtk_phy_init(struct phy *phy)
 {
struct mtk_tphy *tphy = dev_get_priv(phy->dev);
@@ -500,7 +545,14 @@ static int mtk_phy_xlate(struct phy *phy,
return -EINVAL;
}
 
-   phy_v1_banks_init(tphy, instance);
+   if (tphy->version == MTK_TPHY_V1) {
+   phy_v1_banks_init(tphy, instance);
+   } else if (tphy->version == MTK_TPHY_V2) {
+   phy_v2_banks_init(tphy, instance);
+   } else {
+   dev_err(phy->dev, "phy version is not supported\n");
+   return -EINVAL;
+   }
 
return 0;
 }
@@ -527,9 +579,14 @@ static int mtk_tphy_probe(struct udevice *dev)
return -ENOMEM;
 
tphy->dev = dev;
-   tphy->sif_base = dev_read_addr_ptr(dev);
-   if (!tphy->sif_base)
-   return -ENOENT;
+   tphy->version = dev_get_driver_data(dev);
+
+   /* v1 has shared banks */
+   if (tphy->version == MTK_TPHY_V1) {
+   tphy->sif_base = dev_read_addr_ptr(dev);
+   if (!tphy->sif_base)
+   return -ENOENT;
+   }
 
dev_for_each_subnode(subnode, dev) {
struct mtk_phy_instance *instance;
@@ -560,7 +617,8 @@ static int mtk_tphy_probe(struct udevice *dev)
 }
 
 static const struct udevice_id mtk_tphy_id_table[] = {
-   { .compatible = "mediatek,generic-tphy-v1", },
+   { .compatible = "mediatek,generic-tphy-v1", .data = MTK_TPHY_V1, },
+   { .compatible = "mediatek,generic-tphy-v2", .data = MTK_TPHY_V2, },
{ }
 };
 
-- 
2.25.1


[PATCH v5 13/14] dt-bindings: usb: mtk-xhci: Add binding for MediaTek xHCI host controller

2020-04-09 Thread Chunfeng Yun
Add dt-binding for MediaTek xHCI host controller

Signed-off-by: Chunfeng Yun 
---
v2~v5: no changes
---
 .../usb/mediatek,mtk-xhci.txt | 40 +++
 1 file changed, 40 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt

diff --git a/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt 
b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
new file mode 100644
index 00..0447468a2d
--- /dev/null
+++ b/doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
@@ -0,0 +1,40 @@
+MediaTek xHCI
+
+The device node for USB3 host controller on MediaTek SoCs.
+
+Required properties:
+ - compatible : should be "mediatek,mtk-xhci"
+ - reg : specifies physical base address and size of the registers
+ - reg-names: should be "mac" for xHCI MAC and "ippc" for IP port control
+ - power-domains : a phandle to USB power domain node to control USB's
+   MTCMOS
+ - vusb33-supply : regulator of USB avdd3.3v
+
+ - clocks : a list of phandle + clock-specifier pairs, one for each
+   entry in clock-names
+ - clock-names : must contain
+   "sys_ck": controller clock used by normal mode,
+   the following ones are optional:
+   "ref_ck": reference clock used by low power mode etc,
+   "mcu_ck": mcu_bus clock for register access,
+   "dma_ck": dma_bus clock for data transfer by DMA,
+   "xhci_ck": controller clock
+
+ - phys : list of all the USB PHYs on this HCD
+ - phy-names: name specifier for the USB PHY
+
+Optional properties:
+ - vbus-supply : reference to the VBUS regulator;
+
+Example:
+xhci: usb@1a0c {
+   compatible = "mediatek,mt7629-xhci", "mediatek,mtk-xhci";
+   reg = <0x1a0c 0x1000>, <0x1a0c3e00 0x0100>;
+   reg-names = "mac", "ippc";
+   power-domains = < MT7629_POWER_DOMAIN_HIF1>;
+   clocks = < CLK_SSUSB_SYS_EN>, < CLK_SSUSB_REF_EN>,
+< CLK_SSUSB_MCU_EN>, < CLK_SSUSB_DMA_EN>;
+   clock-names = "sys_ck", "ref_ck", "mcu_ck", "dma_ck";
+   phys = < PHY_TYPE_USB2>, < PHY_TYPE_USB3>;
+   status = "disabled";
+};
-- 
2.25.1


[PATCH v5 09/14] phy: phy-mtk-tphy: add a new reference clock

2020-04-09 Thread Chunfeng Yun
Usually the digital and analog phys use the same reference clock,
but some platforms have two separate reference clocks for each of
them, so add another optional clock to support them.
In order to keep the clock names consistent with PHY IP's, change
the da_ref for analog phy and ref clock for digital phy.

Signed-off-by: Chunfeng Yun 
---
v2~v5: no changes
---
 drivers/phy/phy-mtk-tphy.c | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 20167fe7cb..81525a48b7 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -199,8 +199,8 @@ struct mtk_phy_instance {
struct u3phy_banks u3_banks;
};
 
-   /* reference clock of anolog phy */
-   struct clk ref_clk;
+   struct clk ref_clk; /* reference clock of (digital) phy */
+   struct clk da_ref_clk;  /* reference clock of analog phy */
u32 index;
u32 type;
 };
@@ -450,8 +450,17 @@ static int mtk_phy_init(struct phy *phy)
int ret;
 
ret = clk_enable(>ref_clk);
-   if (ret)
+   if (ret < 0) {
+   dev_err(tphy->dev, "failed to enable ref_clk\n");
return ret;
+   }
+
+   ret = clk_enable(>da_ref_clk);
+   if (ret < 0) {
+   dev_err(tphy->dev, "failed to enable da_ref_clk %d\n", ret);
+   clk_disable(>ref_clk);
+   return ret;
+   }
 
switch (instance->type) {
case PHY_TYPE_USB2:
@@ -502,6 +511,7 @@ static int mtk_phy_exit(struct phy *phy)
struct mtk_tphy *tphy = dev_get_priv(phy->dev);
struct mtk_phy_instance *instance = tphy->phys[phy->id];
 
+   clk_disable(>da_ref_clk);
clk_disable(>ref_clk);
 
return 0;
@@ -611,6 +621,11 @@ static int mtk_tphy_probe(struct udevice *dev)
 >ref_clk);
if (err)
return err;
+
+   err = clk_get_optional_nodev(subnode, "da_ref",
+>da_ref_clk);
+   if (err)
+   return err;
}
 
return 0;
-- 
2.25.1


[PATCH v5 03/14] phy: Add get/enable/disable for a bulk of phys

2020-04-09 Thread Chunfeng Yun
This patch adds a "bulk" API to the phy API in order to
get/enable/disable a group of phys associated with a device.

The bulk API will avoid adding a copy of the same code to
manage a group of phys in drivers.

Signed-off-by: Chunfeng Yun 
---
v5: no changes

v4: new patch
---
 drivers/phy/phy-uclass.c | 80 
 include/generic-phy.h| 66 +
 2 files changed, 146 insertions(+)

diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
index e201a90c8c..62580520ad 100644
--- a/drivers/phy/phy-uclass.c
+++ b/drivers/phy/phy-uclass.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 static inline struct phy_ops *phy_dev_ops(struct udevice *dev)
@@ -161,6 +162,85 @@ int generic_phy_power_off(struct phy *phy)
return ops->power_off ? ops->power_off(phy) : 0;
 }
 
+int generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk)
+{
+   int i, ret, count;
+
+   bulk->count = 0;
+
+   /* Return if no phy declared */
+   if (!dev_read_prop(dev, "phys", NULL))
+   return 0;
+
+   count = dev_count_phandle_with_args(dev, "phys", "#phy-cells");
+   if (count < 1)
+   return count;
+
+   bulk->phys = devm_kcalloc(dev, count, sizeof(struct phy), GFP_KERNEL);
+   if (!bulk->phys)
+   return -ENOMEM;
+
+   for (i = 0; i < count; i++) {
+   ret = generic_phy_get_by_index(dev, i, >phys[i]);
+   if (ret) {
+   pr_err("Failed to get PHY%d for %s\n", i, dev->name);
+   return ret;
+   }
+   bulk->count++;
+   }
+
+   return 0;
+}
+
+int generic_phy_enable_bulk(struct phy_bulk *bulk)
+{
+   struct phy *phys = bulk->phys;
+   int count = bulk->count;
+   int i, ret;
+
+   for (i = 0; i < count; i++) {
+   ret = generic_phy_init([i]);
+   if (ret) {
+   pr_err("Can't init PHY%d\n", i);
+   goto phys_init_err;
+   }
+   }
+
+   for (i = 0; i < count; i++) {
+   ret = generic_phy_power_on([i]);
+   if (ret) {
+   pr_err("Can't power PHY%d\n", i);
+   goto phys_poweron_err;
+   }
+   }
+
+   return 0;
+
+phys_poweron_err:
+   for (; i > 0; i--)
+   generic_phy_power_off([i - 1]);
+
+   i = count;
+phys_init_err:
+   for (; i > 0; i--)
+   generic_phy_exit([i - 1]);
+
+   return ret;
+}
+
+int generic_phy_disable_bulk(struct phy_bulk *bulk)
+{
+   struct phy *phys = bulk->phys;
+   int i, ret = 0;
+
+   for (i = 0; i < bulk->count; i++) {
+   ret |= generic_phy_power_off([i]);
+   ret |= generic_phy_exit([i]);
+   }
+
+   return ret;
+}
+
 UCLASS_DRIVER(phy) = {
.id = UCLASS_PHY,
.name   = "phy",
diff --git a/include/generic-phy.h b/include/generic-phy.h
index 95caf58341..55395a50eb 100644
--- a/include/generic-phy.h
+++ b/include/generic-phy.h
@@ -122,6 +122,23 @@ struct phy_ops {
int (*power_off)(struct phy *phy);
 };
 
+/**
+ * struct phy_bulk - A handle to (allowing control of) a bulk of phys.
+ *
+ * Consumers provide storage for the phy bulk. The content of the structure is
+ * managed solely by the phy API. A phy bulk struct is initialized
+ * by "get"ing the phy bulk struct.
+ * The phy bulk struct is passed to all other bulk phy APIs to apply
+ * the API to all the phy in the bulk struct.
+ *
+ * @phys: An array of phy handles.
+ * @count: The number of phy handles in the phys array.
+ */
+struct phy_bulk {
+   struct phy *phys;
+   unsigned int count;
+};
+
 #ifdef CONFIG_PHY
 
 /**
@@ -221,6 +238,39 @@ int generic_phy_get_by_index(struct udevice *user, int 
index,
 int generic_phy_get_by_name(struct udevice *user, const char *phy_name,
struct phy *phy);
 
+/**
+ * generic_phy_get_bulk - Get all phys of a device.
+ *
+ * This looks up and gets all phys of the consumer device; each device is
+ * assumed to have n phys associated with it somehow, and this function finds
+ * and gets all of them in a separate structure.
+ *
+ * @dev:   The consumer device.
+ * @bulk   A pointer to a phy bulk struct to initialize.
+ * @return 0 if OK, or a negative error code.
+ */
+int generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk);
+
+/**
+ * generic_phy_enable_bulk() - Enable (init and power on) all phys in a phy
+ * bulk struct.
+ *
+ * @bulk:  A phy bulk struct that was previously successfully requested
+ * by generic_phy_get_bulk().
+ * @return 0 if OK, or negative error code.
+ */
+int generic_phy_enable_bulk(struct phy_bulk *bulk);
+
+/**
+ * generic_phy_disable_bulk() - Enable (power off and exit) all phys in a phy
+ * bulk struct.
+ *
+ * @bulk:  A phy 

[PATCH v5 07/14] phy: phy-mtk-tphy: add support USB phys

2020-04-09 Thread Chunfeng Yun
Support USB2 and USB3 PHY with shared banks when support multi-phys

Signed-off-by: Chunfeng Yun 
---
v3~v5: no changes

v2:
1. get the count of phys by dev_get_child_count()
---
 drivers/phy/phy-mtk-tphy.c | 227 +++--
 1 file changed, 218 insertions(+), 9 deletions(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index bd089b7a43..71bc706c6e 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -20,11 +20,66 @@
 /* version V1 sub-banks offset base address */
 /* banks shared by multiple phys */
 #define SSUSB_SIFSLV_V1_SPLLC  0x000   /* shared by u3 phys */
+#define SSUSB_SIFSLV_V1_U2FREQ 0x100   /* shared by u2 phys */
 #define SSUSB_SIFSLV_V1_CHIP   0x300   /* shared by u3 phys */
+/* u2 phy bank */
+#define SSUSB_SIFSLV_V1_U2PHY_COM  0x000
 /* u3/pcie/sata phy banks */
 #define SSUSB_SIFSLV_V1_U3PHYD 0x000
 #define SSUSB_SIFSLV_V1_U3PHYA 0x200
 
+#define U3P_USBPHYACR0 0x000
+#define PA0_RG_U2PLL_FORCE_ON  BIT(15)
+#define PA0_RG_USB20_INTR_EN   BIT(5)
+
+#define U3P_USBPHYACR5 0x014
+#define PA5_RG_U2_HSTX_SRCAL_ENBIT(15)
+#define PA5_RG_U2_HSTX_SRCTRL  GENMASK(14, 12)
+#define PA5_RG_U2_HSTX_SRCTRL_VAL(x)   ((0x7 & (x)) << 12)
+#define PA5_RG_U2_HS_100U_U3_ENBIT(11)
+
+#define U3P_USBPHYACR6 0x018
+#define PA6_RG_U2_BC11_SW_EN   BIT(23)
+#define PA6_RG_U2_OTG_VBUSCMP_EN   BIT(20)
+#define PA6_RG_U2_SQTH GENMASK(3, 0)
+#define PA6_RG_U2_SQTH_VAL(x)  (0xf & (x))
+
+#define U3P_U2PHYACR4  0x020
+#define P2C_RG_USB20_GPIO_CTL  BIT(9)
+#define P2C_USB20_GPIO_MODEBIT(8)
+#define P2C_U2_GPIO_CTR_MSK\
+   (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE)
+
+#define U3P_U2PHYDTM0  0x068
+#define P2C_FORCE_UART_EN  BIT(26)
+#define P2C_FORCE_DATAIN   BIT(23)
+#define P2C_FORCE_DM_PULLDOWN  BIT(21)
+#define P2C_FORCE_DP_PULLDOWN  BIT(20)
+#define P2C_FORCE_XCVRSEL  BIT(19)
+#define P2C_FORCE_SUSPENDM BIT(18)
+#define P2C_FORCE_TERMSEL  BIT(17)
+#define P2C_RG_DATAIN  GENMASK(13, 10)
+#define P2C_RG_DATAIN_VAL(x)   ((0xf & (x)) << 10)
+#define P2C_RG_DMPULLDOWN  BIT(7)
+#define P2C_RG_DPPULLDOWN  BIT(6)
+#define P2C_RG_XCVRSEL GENMASK(5, 4)
+#define P2C_RG_XCVRSEL_VAL(x)  ((0x3 & (x)) << 4)
+#define P2C_RG_SUSPENDMBIT(3)
+#define P2C_RG_TERMSEL BIT(2)
+#define P2C_DTM0_PART_MASK \
+   (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \
+   P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \
+   P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \
+   P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL)
+
+#define U3P_U2PHYDTM1  0x06C
+#define P2C_RG_UART_EN BIT(16)
+#define P2C_FORCE_IDDIGBIT(9)
+#define P2C_RG_VBUSVALID   BIT(5)
+#define P2C_RG_SESSEND BIT(4)
+#define P2C_RG_AVALID  BIT(2)
+#define P2C_RG_IDDIG   BIT(1)
+
 #define U3P_U3_CHIP_GPIO_CTLD  0x0c
 #define P3C_REG_IP_SW_RST  BIT(31)
 #define P3C_MCU_BUS_CK_GATE_EN BIT(30)
@@ -42,6 +97,14 @@
 #define P3A_RG_CLKDRV_AMP  GENMASK(31, 29)
 #define P3A_RG_CLKDRV_AMP_VAL(x)   ((0x7 & (x)) << 29)
 
+#define U3P_U3_PHYA_REG6   0x018
+#define P3A_RG_TX_EIDLE_CM GENMASK(31, 28)
+#define P3A_RG_TX_EIDLE_CM_VAL(x)  ((0xf & (x)) << 28)
+
+#define U3P_U3_PHYA_REG9   0x024
+#define P3A_RG_RX_DAC_MUX  GENMASK(5, 1)
+#define P3A_RG_RX_DAC_MUX_VAL(x)   ((0x1f & (x)) << 1)
+
 #define U3P_U3_PHYA_DA_REG00x100
 #define P3A_RG_XTAL_EXT_PE2H   GENMASK(17, 16)
 #define P3A_RG_XTAL_EXT_PE2H_VAL(x)((0x3 & (x)) << 16)
@@ -77,6 +140,16 @@
 #define P3A_RG_PLL_DELTA_PE2H  GENMASK(15, 0)
 #define P3A_RG_PLL_DELTA_PE2H_VAL(x)   (0x & (x))
 
+#define U3P_U3_PHYD_LFPS1  0x00c
+#define P3D_RG_FWAKE_THGENMASK(21, 16)
+#define P3D_RG_FWAKE_TH_VAL(x) ((0x3f & (x)) << 16)
+
+#define U3P_U3_PHYD_CDR1   0x05c
+#define P3D_RG_CDR_BIR_LTD1GENMASK(28, 24)
+#define P3D_RG_CDR_BIR_LTD1_VAL(x) ((0x1f & (x)) << 24)
+#define P3D_RG_CDR_BIR_LTD0GENMASK(12, 8)
+#define P3D_RG_CDR_BIR_LTD0_VAL(x) ((0x1f & (x)) << 8)
+
 #define U3P_U3_PHYD_RXDET1 0x128
 #define P3D_RG_RXDET_STB2_SET  GENMASK(17, 9)
 #define P3D_RG_RXDET_STB2_SET_VAL(x)   ((0x1ff & (x)) << 9)
@@ -85,6 +158,16 @@
 #define P3D_RG_RXDET_STB2_SET_P3   GENMASK(8, 0)
 #define P3D_RG_RXDET_STB2_SET_P3_VAL(x)(0x1ff & (x))
 
+#define U3P_SPLLC_XTALCTL3  

[PATCH v5 02/14] test: dm: add test item for ofnode_get_child_count()

2020-04-09 Thread Chunfeng Yun
Add a test item for ofnode_get_child_count()

Signed-off-by: Chunfeng Yun 
Reviewed-by: Simon Glass 
---
v4~v5: no changes

v3:
1. squash dts patch into this one suggested by Simon
2. add reviewed-by Simon

v2:
a new patch to test ofnode_get_child_count() suggested by Simon
---
 arch/sandbox/dts/test.dts | 18 ++
 test/dm/ofnode.c  | 21 +
 2 files changed, 39 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 4a277934a7..09e69a9d33 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -202,6 +202,24 @@
compatible = "denx,u-boot-fdt-test1";
};
 
+   i-test {
+   compatible = "mediatek,u-boot-fdt-test";
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   subnode0 {
+   reg = <0>;
+   };
+
+   subnode1 {
+   reg = <1>;
+   };
+
+   subnode2 {
+   reg = <2>;
+   };
+   };
+
devres-test {
compatible = "denx,u-boot-devres-test";
};
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 1c49eaf38b..07d5c7d7a6 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -113,3 +113,24 @@ static int dm_test_ofnode_read_chosen(struct 
unit_test_state *uts)
return 0;
 }
 DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_get_child_count(struct unit_test_state *uts)
+{
+   ofnode node, child_node;
+   u32 val;
+
+   node = ofnode_path("/i-test");
+   ut_assert(ofnode_valid(node));
+
+   val = ofnode_get_child_count(node);
+   ut_asserteq(3, val);
+
+   child_node = ofnode_first_subnode(node);
+   ut_assert(ofnode_valid(child_node));
+   val = ofnode_get_child_count(child_node);
+   ut_asserteq(0, val);
+
+   return 0;
+}
+DM_TEST(dm_test_ofnode_get_child_count,
+   DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.25.1


[PATCH v5 00/14] Add support for MediaTek xHCI host controller

2020-04-09 Thread Chunfeng Yun
The series of patches are used to support xHCI host controller on
MediaTek SoCs which has a glue layer IPPC (IP Port Control), and
add USB function on T-PHY including T-PHY V1 and V2;
Finally add USB related nodes for MT7629 platform.

The files of xhci-mtk.* and phy-mtk-tphy.* are ported from
Linux Kenrel 5.6-rc1

v5 changes:
1. print error number suggested by Marek
2. support interrupt transfer
3. update MAINTAINER about MediaTek

v4 changes:
1. add phy_bulk API
2. use phy_bulk in xhci-mtk driver, also include dwc3/dwc2 drivers

v3 changes:
1. provide non/inline edev_get_child_count() suggested by Simon
2. squash [PATCH v2 02/10] into [PATCH v2 03/10] suggested by Simon
3. use macros to access IPPC registers suggested by Marek

v2 changes:
1. move ofnode_get_child_count() into ofnode.c suggested by Simon
2. add a test item for ofnode_get_child_count() suggested by Simon
3. use clk_bulk to get clocks suggested by Marek
4. use clrsetbits_le32() etc suggeseted by Marek
5. get the count of phys by dev_get_child_count()
6. drop reference to fixed clock clk20m

Chunfeng Yun (14):
  dm: core: Add function to get child count of ofnode or device
  test: dm: add test item for ofnode_get_child_count()
  phy: Add get/enable/disable for a bulk of phys
  test: dm: phy: add a test item for the phy_bulk API
  usb: dwc3: use the phy bulk API to get phys
  usb: dwc2_udc_otg: use the phy bulk API to get phys
  phy: phy-mtk-tphy: add support USB phys
  phy: phy-mtk-tphy: add support new version
  phy: phy-mtk-tphy: add a new reference clock
  xhci: mediatek: Add support for MTK xHCI host controller
  arm: dts: mt7629: add usb related nodes
  dt-bindings: phy-mtk-tphy: add properties of address mapping and
clocks
  dt-bindings: usb: mtk-xhci: Add binding for MediaTek xHCI host
controller
  MAINTAINERS: MediaTek: add USB related files

 MAINTAINERS   |   3 +
 arch/arm/dts/mt7629-rfb.dts   |   8 +
 arch/arm/dts/mt7629.dtsi  |  41 +++
 arch/sandbox/dts/test.dts |  29 ++
 doc/device-tree-bindings/phy/phy-mtk-tphy.txt |  78 -
 .../usb/mediatek,mtk-xhci.txt |  40 +++
 drivers/core/ofnode.c |  11 +
 drivers/core/read.c   |   5 +
 drivers/phy/phy-mtk-tphy.c| 316 +-
 drivers/phy/phy-uclass.c  |  80 +
 drivers/usb/dwc3/core.c   |  83 +
 drivers/usb/dwc3/dwc3-generic.c   |   7 +-
 drivers/usb/gadget/dwc2_udc_otg.c |  90 +
 drivers/usb/host/Kconfig  |   6 +
 drivers/usb/host/Makefile |   1 +
 drivers/usb/host/xhci-mtk.c   | 296 
 drivers/usb/host/xhci.c   |  10 +
 include/dm/ofnode.h   |   8 +
 include/dm/read.h |  13 +
 include/dwc3-uboot.h  |  11 +-
 include/generic-phy.h |  66 
 include/usb/xhci.h|   3 +
 test/dm/ofnode.c  |  21 ++
 test/dm/phy.c |  29 ++
 24 files changed, 1066 insertions(+), 189 deletions(-)
 create mode 100644 doc/device-tree-bindings/usb/mediatek,mtk-xhci.txt
 create mode 100644 drivers/usb/host/xhci-mtk.c

-- 
2.25.1


[PATCH v5 06/14] usb: dwc2_udc_otg: use the phy bulk API to get phys

2020-04-09 Thread Chunfeng Yun
Use the phy bulk API to get a group of phys

Signed-off-by: Chunfeng Yun 
---
v5: no changes

v4: new patch
---
 drivers/usb/gadget/dwc2_udc_otg.c | 90 +--
 1 file changed, 12 insertions(+), 78 deletions(-)

diff --git a/drivers/usb/gadget/dwc2_udc_otg.c 
b/drivers/usb/gadget/dwc2_udc_otg.c
index 496abf38e7..c3d2575571 100644
--- a/drivers/usb/gadget/dwc2_udc_otg.c
+++ b/drivers/usb/gadget/dwc2_udc_otg.c
@@ -943,8 +943,7 @@ int usb_gadget_handle_interrupts(int index)
 struct dwc2_priv_data {
struct clk_bulk clks;
struct reset_ctl_bulk   resets;
-   struct phy *phys;
-   int num_phys;
+   struct phy_bulk phys;
struct udevice *usb33d_supply;
 };
 
@@ -953,87 +952,22 @@ int dm_usb_gadget_handle_interrupts(struct udevice *dev)
return dwc2_udc_handle_interrupt();
 }
 
-int dwc2_phy_setup(struct udevice *dev, struct phy **array, int *num_phys)
+static int dwc2_phy_setup(struct udevice *dev, struct phy_bulk *phys)
 {
-   int i, ret, count;
-   struct phy *usb_phys;
-
-   /* Return if no phy declared */
-   if (!dev_read_prop(dev, "phys", NULL))
-   return 0;
-
-   count = dev_count_phandle_with_args(dev, "phys", "#phy-cells");
-   if (count <= 0)
-   return count;
-
-   usb_phys = devm_kcalloc(dev, count, sizeof(struct phy),
-   GFP_KERNEL);
-   if (!usb_phys)
-   return -ENOMEM;
-
-   for (i = 0; i < count; i++) {
-   ret = generic_phy_get_by_index(dev, i, _phys[i]);
-   if (ret && ret != -ENOENT) {
-   dev_err(dev, "Failed to get USB PHY%d for %s\n",
-   i, dev->name);
-   return ret;
-   }
-   }
-
-   for (i = 0; i < count; i++) {
-   ret = generic_phy_init(_phys[i]);
-   if (ret) {
-   dev_err(dev, "Can't init USB PHY%d for %s\n",
-   i, dev->name);
-   goto phys_init_err;
-   }
-   }
+   int ret;
 
-   for (i = 0; i < count; i++) {
-   ret = generic_phy_power_on(_phys[i]);
-   if (ret) {
-   dev_err(dev, "Can't power USB PHY%d for %s\n",
-   i, dev->name);
-   goto phys_poweron_err;
-   }
+   ret = generic_phy_get_bulk(dev, phys);
+   if (ret) {
+   dev_err(dev, "Failed to get phys\n");
+   return ret;
}
 
-   *array = usb_phys;
-   *num_phys =  count;
-
-   return 0;
-
-phys_poweron_err:
-   for (i = count - 1; i >= 0; i--)
-   generic_phy_power_off(_phys[i]);
-
-   for (i = 0; i < count; i++)
-   generic_phy_exit(_phys[i]);
-
-   return ret;
-
-phys_init_err:
-   for (; i >= 0; i--)
-   generic_phy_exit(_phys[i]);
-
-   return ret;
+   return generic_phy_enable_bulk(phys);
 }
 
-void dwc2_phy_shutdown(struct udevice *dev, struct phy *usb_phys, int num_phys)
+static void dwc2_phy_shutdown(struct udevice *dev, struct phy_bulk *phys)
 {
-   int i, ret;
-
-   for (i = 0; i < num_phys; i++) {
-   if (!generic_phy_valid(_phys[i]))
-   continue;
-
-   ret = generic_phy_power_off(_phys[i]);
-   ret |= generic_phy_exit(_phys[i]);
-   if (ret) {
-   dev_err(dev, "Can't shutdown USB PHY%d for %s\n",
-   i, dev->name);
-   }
-   }
+   generic_phy_disable_bulk(phys);
 }
 
 static int dwc2_udc_otg_ofdata_to_platdata(struct udevice *dev)
@@ -1159,7 +1093,7 @@ static int dwc2_udc_otg_probe(struct udevice *dev)
if (ret)
return ret;
 
-   ret = dwc2_phy_setup(dev, >phys, >num_phys);
+   ret = dwc2_phy_setup(dev, >phys);
if (ret)
return ret;
 
@@ -1209,7 +1143,7 @@ static int dwc2_udc_otg_remove(struct udevice *dev)
 
clk_release_bulk(>clks);
 
-   dwc2_phy_shutdown(dev, priv->phys, priv->num_phys);
+   dwc2_phy_shutdown(dev, >phys);
 
return dm_scan_fdt_dev(dev);
 }
-- 
2.25.1


[PATCH v5 01/14] dm: core: Add function to get child count of ofnode or device

2020-04-09 Thread Chunfeng Yun
This patch add function used to get the child count of
a ofnode or a device

Signed-off-by: Chunfeng Yun 
---
v4~v5: no changes

v3:
1. add non/inline function dev_get_child_count() instead of macro suggested 
by Simon

v2:
1. move ofnode_get_child_count() into ofnode.c suggested by Simon
2. add a new macro dev_get_child_count()
---
 drivers/core/ofnode.c | 11 +++
 drivers/core/read.c   |  5 +
 include/dm/ofnode.h   |  8 
 include/dm/read.h | 13 +
 4 files changed, 37 insertions(+)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 96a5dd20bd..6f4eb422a4 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -453,6 +453,17 @@ ofnode ofnode_get_chosen_node(const char *name)
return ofnode_path(prop);
 }
 
+int ofnode_get_child_count(ofnode parent)
+{
+   ofnode child;
+   int num = 0;
+
+   ofnode_for_each_subnode(child, parent)
+   num++;
+
+   return num;
+}
+
 static int decode_timing_property(ofnode node, const char *name,
  struct timing_entry *result)
 {
diff --git a/drivers/core/read.c b/drivers/core/read.c
index 1f999b1b31..046381f3a8 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -323,3 +323,8 @@ fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
 
return addr;
 }
+
+int dev_get_child_count(const struct udevice *dev)
+{
+   return ofnode_get_child_count(dev_ofnode(dev));
+}
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index b5a50e8849..0d521dbcf1 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -793,6 +793,14 @@ ofnode ofnode_by_prop_value(ofnode from, const char 
*propname,
 ofnode_valid(node); \
 node = ofnode_next_subnode(node))
 
+/**
+ * ofnode_get_child_count() - get the child count of a ofnode
+ *
+ * @node: valid node to get its child count
+ * @return the number of subnodes
+ */
+int ofnode_get_child_count(ofnode parent);
+
 /**
  * ofnode_translate_address() - Translate a device-tree address
  *
diff --git a/include/dm/read.h b/include/dm/read.h
index da8c7f25e7..38cf76d07a 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -607,6 +607,14 @@ u64 dev_translate_dma_address(const struct udevice *dev,
  */
 int dev_read_alias_highest_id(const char *stem);
 
+/**
+ * dev_get_child_count() - get the child count of a device
+ *
+ * @dev: device to use for interation (struct udevice *)
+ * @return the count of child subnode
+ */
+int dev_get_child_count(const struct udevice *dev);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 
 static inline int dev_read_u32(const struct udevice *dev,
@@ -885,6 +893,11 @@ static inline int dev_read_alias_highest_id(const char 
*stem)
return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
 }
 
+static inline int dev_get_child_count(const struct udevice *dev)
+{
+   return ofnode_get_child_count(dev_ofnode(dev));
+}
+
 #endif /* CONFIG_DM_DEV_READ_INLINE */
 
 /**
-- 
2.25.1


[PATCH v5 04/14] test: dm: phy: add a test item for the phy_bulk API

2020-04-09 Thread Chunfeng Yun
Add a test item for the phy_bulk API

Signed-off-by: Chunfeng Yun 
---
v5: no changes

v4: new patch
---
 arch/sandbox/dts/test.dts | 11 +++
 test/dm/phy.c | 29 +
 2 files changed, 40 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 09e69a9d33..58f5309e4d 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -143,12 +143,23 @@
broken;
};
 
+   phy_provider2: gen_phy@2 {
+   compatible = "sandbox,phy";
+   #phy-cells = <0>;
+   };
+
gen_phy_user: gen_phy_user {
compatible = "simple-bus";
phys = <_provider0 0>, <_provider0 1>, <_provider1>;
phy-names = "phy1", "phy2", "phy3";
};
 
+   gen_phy_user1: gen_phy_user1 {
+   compatible = "simple-bus";
+   phys = <_provider0 0>, <_provider2>;
+   phy-names = "phy1", "phy2";
+   };
+
some-bus {
#address-cells = <1>;
#size-cells = <0>;
diff --git a/test/dm/phy.c b/test/dm/phy.c
index 21d92194b9..11d648c72f 100644
--- a/test/dm/phy.c
+++ b/test/dm/phy.c
@@ -110,3 +110,32 @@ static int dm_test_phy_ops(struct unit_test_state *uts)
return 0;
 }
 DM_TEST(dm_test_phy_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_phy_bulk(struct unit_test_state *uts)
+{
+   struct phy_bulk phys;
+   struct udevice *parent;
+
+   /* test normal operations */
+   ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
+ "gen_phy_user1", ));
+
+   ut_assertok(generic_phy_get_bulk(parent, ));
+   ut_asserteq(2, phys.count);
+
+   ut_asserteq(0, generic_phy_enable_bulk());
+   ut_asserteq(0, generic_phy_disable_bulk());
+
+   /* has a known problem phy */
+   ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
+ "gen_phy_user", ));
+
+   ut_assertok(generic_phy_get_bulk(parent, ));
+   ut_asserteq(3, phys.count);
+
+   ut_asserteq(-EIO, generic_phy_enable_bulk());
+   ut_asserteq(-EIO, generic_phy_disable_bulk());
+
+   return 0;
+}
+DM_TEST(dm_test_phy_bulk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.25.1


[PATCH v5 05/14] usb: dwc3: use the phy bulk API to get phys

2020-04-09 Thread Chunfeng Yun
Get a group of phys by the phy bulk API

Signed-off-by: Chunfeng Yun 
---
v5: no changes

v4: new patch
---
 drivers/usb/dwc3/core.c | 83 -
 drivers/usb/dwc3/dwc3-generic.c |  7 ++-
 include/dwc3-uboot.h| 11 ++---
 3 files changed, 17 insertions(+), 84 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 4ec3f6df6a..908cca12b9 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -838,87 +838,22 @@ MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
 
 #if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB)
-int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys)
+int dwc3_setup_phy(struct udevice *dev, struct phy_bulk *phys)
 {
-   int i, ret, count;
-   struct phy *usb_phys;
-
-   /* Return if no phy declared */
-   if (!dev_read_prop(dev, "phys", NULL))
-   return 0;
-   count = dev_count_phandle_with_args(dev, "phys", "#phy-cells");
-   if (count <= 0)
-   return count;
-
-   usb_phys = devm_kcalloc(dev, count, sizeof(struct phy),
-   GFP_KERNEL);
-   if (!usb_phys)
-   return -ENOMEM;
-
-   for (i = 0; i < count; i++) {
-   ret = generic_phy_get_by_index(dev, i, _phys[i]);
-   if (ret && ret != -ENOENT) {
-   pr_err("Failed to get USB PHY%d for %s\n",
-  i, dev->name);
-   return ret;
-   }
-   }
-
-   for (i = 0; i < count; i++) {
-   ret = generic_phy_init(_phys[i]);
-   if (ret) {
-   pr_err("Can't init USB PHY%d for %s\n",
-  i, dev->name);
-   goto phys_init_err;
-   }
-   }
+   int ret;
 
-   for (i = 0; i < count; i++) {
-   ret = generic_phy_power_on(_phys[i]);
-   if (ret) {
-   pr_err("Can't power USB PHY%d for %s\n",
-  i, dev->name);
-   goto phys_poweron_err;
-   }
+   ret = generic_phy_get_bulk(dev, phys);
+   if (ret) {
+   dev_err(dev, "Failed to get phys\n");
+   return ret;
}
 
-   *array = usb_phys;
-   *num_phys =  count;
-   return 0;
-
-phys_poweron_err:
-   for (i = count - 1; i >= 0; i--)
-   generic_phy_power_off(_phys[i]);
-
-   for (i = 0; i < count; i++)
-   generic_phy_exit(_phys[i]);
-
-   return ret;
-
-phys_init_err:
-   for (; i >= 0; i--)
-   generic_phy_exit(_phys[i]);
-
-   return ret;
+   return generic_phy_enable_bulk(phys);
 }
 
-int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys)
+int dwc3_shutdown_phy(struct udevice *dev, struct phy_bulk *phys)
 {
-   int i, ret;
-
-   for (i = 0; i < num_phys; i++) {
-   if (!generic_phy_valid(_phys[i]))
-   continue;
-
-   ret = generic_phy_power_off(_phys[i]);
-   ret |= generic_phy_exit(_phys[i]);
-   if (ret) {
-   pr_err("Can't shutdown USB PHY%d for %s\n",
-  i, dev->name);
-   }
-   }
-
-   return 0;
+   return generic_phy_disable_bulk(phys);
 }
 #endif
 
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
index 3e116b2c5c..523189a5ff 100644
--- a/drivers/usb/dwc3/dwc3-generic.c
+++ b/drivers/usb/dwc3/dwc3-generic.c
@@ -33,8 +33,7 @@ struct dwc3_generic_plat {
 struct dwc3_generic_priv {
void *base;
struct dwc3 dwc3;
-   struct phy *phys;
-   int num_phys;
+   struct phy_bulk phys;
 };
 
 struct dwc3_generic_host_priv {
@@ -56,7 +55,7 @@ static int dwc3_generic_probe(struct udevice *dev,
dwc3_of_parse(dwc3);
 #endif
 
-   rc = dwc3_setup_phy(dev, >phys, >num_phys);
+   rc = dwc3_setup_phy(dev, >phys);
if (rc)
return rc;
 
@@ -79,7 +78,7 @@ static int dwc3_generic_remove(struct udevice *dev,
struct dwc3 *dwc3 = >dwc3;
 
dwc3_remove(dwc3);
-   dwc3_shutdown_phy(dev, priv->phys, priv->num_phys);
+   dwc3_shutdown_phy(dev, >phys);
unmap_physmem(dwc3->regs, MAP_NOCACHE);
 
return 0;
diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h
index 3c9e204cf0..ce835fd1b2 100644
--- a/include/dwc3-uboot.h
+++ b/include/dwc3-uboot.h
@@ -9,6 +9,7 @@
 #ifndef __DWC3_UBOOT_H_
 #define __DWC3_UBOOT_H_
 
+#include 
 #include 
 #include 
 
@@ -43,17 +44,15 @@ void dwc3_uboot_handle_interrupt(int index);
 
 struct phy;
 #if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB)
-int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys);
-int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys);
+int 

Re: Calling i2c set speed twice for i2c_mux_bus

2020-04-09 Thread Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which
has dts in mainline where i2c1 has i2c mux with some channels.
In DT clock-frequency = <40>; is specified and it is read in
i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means
that post probe is called for it too. And because clock-frequency
property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?


No :-(

The question is, is this a bug?

Should a i2c bus behind a mux not be able to set his own speed?

But may as a feature (or bugfix?) if "clock-frequency" is not there,
use the speed of the parent bus...?


Simon: I think that make sense to use some flags to skip calling
post_probe in this case. Or any suggestion how to fix it would be great.

Thanks,
Michal



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


Re: [PATCH v5 6/6] dm: mmc: Update mmc_get_mmc_dev() to use const *

2020-04-09 Thread Jaehoon Chung
On 4/8/20 11:33 PM, Simon Glass wrote:
> This function does not modify the device to change it to use const *, so
> that callers with a const udevice * can call it without a cast.
> 
> Signed-off-by: Simon Glass 

Reviewed-by: Jaehoon Chung 

Best Regards,
Jaehoon Chung

> ---
> 
> Changes in v5: None
> Changes in v4: None
> 
>  drivers/mmc/mmc-uclass.c | 2 +-
>  include/mmc.h| 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
> index c75892a72c1..88fc7d79f8e 100644
> --- a/drivers/mmc/mmc-uclass.c
> +++ b/drivers/mmc/mmc-uclass.c
> @@ -223,7 +223,7 @@ int mmc_of_parse(struct udevice *dev, struct mmc_config 
> *cfg)
>   return 0;
>  }
>  
> -struct mmc *mmc_get_mmc_dev(struct udevice *dev)
> +struct mmc *mmc_get_mmc_dev(const struct udevice *dev)
>  {
>   struct mmc_uclass_priv *upriv;
>  
> diff --git a/include/mmc.h b/include/mmc.h
> index e83c22423bf..0f9184b9714 100644
> --- a/include/mmc.h
> +++ b/include/mmc.h
> @@ -374,7 +374,7 @@ struct mmc_uclass_priv {
>   * @dev: Device
>   * @return associated mmc struct pointer if available, else NULL
>   */
> -struct mmc *mmc_get_mmc_dev(struct udevice *dev);
> +struct mmc *mmc_get_mmc_dev(const struct udevice *dev);
>  
>  /* End of driver model support */
>  
> 



Re: [RFC PATCH v2 05/13] mmc: add nexell driver

2020-04-09 Thread Jaehoon Chung
Hi,

On 4/10/20 2:33 AM, Stefan B. wrote:
> Hi,
> 
> see below my answers to your questions.
> 
> Regards
> Stefan Bosch
> 
> 
> Hi,
> 
> thanks a lot for your reply. As you already guessed I have ported the 
> outdated U-Boot from FriendlyARM, see:
> https://protect2.fireeye.com/url?k=00de144b-5d1421fc-00df9f04-0cc47a3003e8-6dd6a1886465f918=1=https%3A%2F%2Fgithub.com%2Ffriendlyarm%2Fu-boot%2Ftree%2Fnanopi2-v2016.01
> 
> The original MMC-driver has been nexell_dw_mmc.c, so I renamed it to 
> nexell_dw_mmc_dm.c after changing to DM.
> 
> I will have a closer look at your suggestions and give you feedback ASAP.

I don't know that you had received reviews about other patches.
If you want to apply new chip, then i think you need to implement drivers based 
on DM. 

> 
> 
> Regards
> Stefan Bosch
> 
> 
> Am 02.04.20 um 13:03 schrieb Jaehoon Chung:
>> Hi,
>>
>> On 3/28/20 6:43 PM, Stefan Bosch wrote:
>>> Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
>>> - mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).
>>
>> It doesn't need to add postfix as _dm.
>>
> Ok, I have renamed it to nexell_dw_mmc.c.
> 
>>>
>>> Signed-off-by: Stefan Bosch 
>>> ---
>>>
>>> Changes in v2:
>>> - commit "i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)" splitted
>>>    into separate commits for gpio, i2c, mmc, pwm.
>>>
>>>   drivers/mmc/Kconfig    |   6 +
>>>   drivers/mmc/Makefile   |   1 +
>>>   drivers/mmc/nexell_dw_mmc_dm.c | 350 
>>> +
>>>   3 files changed, 357 insertions(+)
>>>   create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c
>>>
>>> diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
>>> index 2f0eedc..bb8e7c0 100644
>>> --- a/drivers/mmc/Kconfig
>>> +++ b/drivers/mmc/Kconfig
>>> @@ -253,6 +253,12 @@ config MMC_DW_SNPS
>>>     This selects support for Synopsys DesignWare Memory Card Interface 
>>> driver
>>>     extensions used in various Synopsys ARC devboards.
>>>   +config NEXELL_DWMMC
>>> +    bool "Nexell SD/MMC controller support"
>>> +    depends on ARCH_NEXELL
>>> +    depends on MMC_DW
>>> +    default y
>>
>> Not depends on DM_MMC?
>>
> You are right, I have inserted "depends on DM_MMC". I missed this when 
> changing to DM.
> 
>>> +
>>>   config MMC_MESON_GX
>>>   bool "Meson GX EMMC controller support"
>>>   depends on DM_MMC && BLK && ARCH_MESON
>>> diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
>>> index 9c1f8e5..a7b5a7b 100644
>>> --- a/drivers/mmc/Makefile
>>> +++ b/drivers/mmc/Makefile
>>> @@ -43,6 +43,7 @@ obj-$(CONFIG_SH_MMCIF) += sh_mmcif.o
>>>   obj-$(CONFIG_SH_SDHI) += sh_sdhi.o
>>>   obj-$(CONFIG_STM32_SDMMC2) += stm32_sdmmc2.o
>>>   obj-$(CONFIG_JZ47XX_MMC) += jz_mmc.o
>>> +obj-$(CONFIG_NEXELL_DWMMC) += nexell_dw_mmc_dm.o
>>>     # SDHCI
>>>   obj-$(CONFIG_MMC_SDHCI)    += sdhci.o
>>> diff --git a/drivers/mmc/nexell_dw_mmc_dm.c b/drivers/mmc/nexell_dw_mmc_dm.c
>>> new file mode 100644
>>> index 000..b06b60d
>>> --- /dev/null
>>> +++ b/drivers/mmc/nexell_dw_mmc_dm.c
>>> @@ -0,0 +1,350 @@
>>> +// SPDX-License-Identifier: GPL-2.0+
>>> +/*
>>> + * (C) Copyright 2016 Nexell
>>> + * Youngbok, Park 
>>> + *
>>> + * (C) Copyright 2019 Stefan Bosch 
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#define DWMCI_CLKSEL    0x09C
>>> +#define DWMCI_SHIFT_0    0x0
>>> +#define DWMCI_SHIFT_1    0x1
>>> +#define DWMCI_SHIFT_2    0x2
>>> +#define DWMCI_SHIFT_3    0x3
>>> +#define DWMCI_SET_SAMPLE_CLK(x)    (x)
>>> +#define DWMCI_SET_DRV_CLK(x)    ((x) << 16)
>>> +#define DWMCI_SET_DIV_RATIO(x)    ((x) << 24)
>>> +#define DWMCI_CLKCTRL    0x114
>>> +#define NX_MMC_CLK_DELAY(x, y, a, b)    x) & 0xFF) << 0) |\
>>> +    (((y) & 0x03) << 16) |\
>>> +    (((a) & 0xFF) << 8)  |\
>>> +    (((b) & 0x03) << 24))
>>> +
>>> +struct nexell_mmc_plat {
>>> +    struct mmc_config cfg;
>>> +    struct mmc mmc;
>>> +};
>>> +
>>> +struct nexell_dwmmc_priv {
>>> +    struct clk *clk;
>>> +    struct dwmci_host host;
>>> +    int fifo_size;
>>> +    bool fifo_mode;
>>> +    int frequency;
>>> +    u32 min_freq;
>>> +    u32 max_freq;
>>> +    int d_delay;
>>> +    int d_shift;
>>> +    int s_delay;
>>> +    int s_shift;
>>> +
>>> +};
>>> +
>>> +struct clk *clk_get(const char *id);
>>> +
>>> +static void set_pin_stat(int index, int bit, int value)
>>> +{
>>> +#if !defined(CONFIG_SPL_BUILD)
>>> +    nx_gpio_set_pad_function(index, bit, value);
>>> +#else
>>> +#if defined(CONFIG_ARCH_S5P4418) ||    \
>>> +    defined(CONFIG_ARCH_S5P6818)
>>> +
>>> +    unsigned long base[5] = {
>>> +    PHY_BASEADDR_GPIOA, PHY_BASEADDR_GPIOB,
>>> +    PHY_BASEADDR_GPIOC, PHY_BASEADDR_GPIOD,
>>> +    PHY_BASEADDR_GPIOE,
>>> +    };
>>
>> I don't understand why gpio pin is set in mmc driver?
>> If nexell soc 

Re: [PATCH] usb: Keep async schedule running only across mass storage xfers

2020-04-09 Thread Tom Rini
On Mon, Apr 06, 2020 at 02:29:44PM +0200, Marek Vasut wrote:

> Rather than keeping the asynchronous schedule running always, keep it
> running only across USB mass storage transfers for now, as it seems
> that keeping it running all the time interferes with certain control
> transfers during device enumeration.
> 
> Note that running the async schedule all the time should not be an
> issue, especially on EHCI HCD, as that one implements most of the
> transfers using async schedule.
> 
> Note that we have usb_disable_asynch(), which however is utterly broken.
> The usb_disable_asynch() blocks the USB core from doing async transfers
> by setting a global flag. The async schedule should however be disabled
> per USB controller. Moreover, setting a global flag does not prevent the
> controller from using the async schedule, which e.g. the EHCI HCD does.
> 
> This patch implements additional callback to the controller, which
> permits it to lock the async schedule and keep it running across
> multiple transfers. Once the schedule is unlocked, it must also be
> disabled. This thus prevents the async schedule from running outside
> of the USB mass storage transfers.
> 
> Signed-off-by: Marek Vasut 
> Cc: Lukasz Majewski 
> Cc: Tom Rini 
> Tested-by: Tom Rini  [omap3_beagle, previously failing]

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] board: add InnoComm i.MX8MM WB15EVK

2020-04-09 Thread Matt Porter
Add support for the InnoComm i.MX8MM WB15EVK board
(https://www.innocomm.com/product_inner.aspx?num=2233).

The following functionality is supported:
- eMMC
- MMC/SD
- GPIO
- I2C
- Ethernet

Signed-off-by: Matt Porter 
---
 arch/arm/dts/Makefile |1 +
 arch/arm/dts/imx8mm-wb15evk-u-boot.dtsi   |  120 ++
 arch/arm/dts/imx8mm-wb15evk.dts   |  390 
 arch/arm/mach-imx/imx8m/Kconfig   |7 +
 board/innocomm/imx8mm_wb15evk/Kconfig |   16 +
 board/innocomm/imx8mm_wb15evk/MAINTAINERS |6 +
 board/innocomm/imx8mm_wb15evk/Makefile|   14 +
 board/innocomm/imx8mm_wb15evk/README.rst  |   46 +
 .../innocomm/imx8mm_wb15evk/imx8mm_wb15evk.c  |   35 +
 .../imx8mm_wb15evk/lpddr4_timing-2400mts.c| 1849 +
 board/innocomm/imx8mm_wb15evk/lpddr4_timing.c | 1849 +
 board/innocomm/imx8mm_wb15evk/spl.c   |  173 ++
 configs/imx8mm_wb15evk_defconfig  |   83 +
 include/configs/imx8mm_wb15evk.h  |  156 ++
 14 files changed, 4745 insertions(+)
 create mode 100644 arch/arm/dts/imx8mm-wb15evk-u-boot.dtsi
 create mode 100644 arch/arm/dts/imx8mm-wb15evk.dts
 create mode 100644 board/innocomm/imx8mm_wb15evk/Kconfig
 create mode 100644 board/innocomm/imx8mm_wb15evk/MAINTAINERS
 create mode 100644 board/innocomm/imx8mm_wb15evk/Makefile
 create mode 100644 board/innocomm/imx8mm_wb15evk/README.rst
 create mode 100644 board/innocomm/imx8mm_wb15evk/imx8mm_wb15evk.c
 create mode 100644 board/innocomm/imx8mm_wb15evk/lpddr4_timing-2400mts.c
 create mode 100644 board/innocomm/imx8mm_wb15evk/lpddr4_timing.c
 create mode 100644 board/innocomm/imx8mm_wb15evk/spl.c
 create mode 100644 configs/imx8mm_wb15evk_defconfig
 create mode 100644 include/configs/imx8mm_wb15evk.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 820ee9733a..128c118ac3 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -721,6 +721,7 @@ dtb-$(CONFIG_ARCH_IMX8) += \
 dtb-$(CONFIG_ARCH_IMX8M) += \
imx8mm-evk.dtb \
imx8mm-verdin.dtb \
+   imx8mm-wb15evk.dtb \
imx8mn-ddr4-evk.dtb \
imx8mq-evk.dtb \
imx8mp-evk.dtb
diff --git a/arch/arm/dts/imx8mm-wb15evk-u-boot.dtsi 
b/arch/arm/dts/imx8mm-wb15evk-u-boot.dtsi
new file mode 100644
index 00..67dce571e5
--- /dev/null
+++ b/arch/arm/dts/imx8mm-wb15evk-u-boot.dtsi
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ * Copyright 2020 Konsulko Group
+ */
+
+&{/soc@0} {
+   u-boot,dm-pre-reloc;
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+   u-boot,dm-pre-reloc;
+   /delete-property/ assigned-clocks;
+   /delete-property/ assigned-clock-parents;
+   /delete-property/ assigned-clock-rates;
+};
+
+_24m {
+   u-boot,dm-spl;
+   u-boot,dm-pre-reloc;
+};
+
+ {
+   u-boot,dm-spl;
+   u-boot,dm-pre-reloc;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+_reg_usdhc2_vmmc {
+   u-boot,dm-spl;
+};
+
+_uart2 {
+   u-boot,dm-spl;
+};
+
+_usdhc2_gpio {
+   u-boot,dm-spl;
+};
+
+_usdhc2 {
+   u-boot,dm-spl;
+};
+
+_usdhc3 {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+&{/soc@0/bus@3080/i2c@30a2/pmic@4b} {
+   u-boot,dm-spl;
+};
+
+&{/soc@0/bus@3080/i2c@30a2/pmic@4b/regulators} {
+   u-boot,dm-spl;
+};
+
+_i2c1 {
+   u-boot,dm-spl;
+};
+
+_pmic {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
diff --git a/arch/arm/dts/imx8mm-wb15evk.dts b/arch/arm/dts/imx8mm-wb15evk.dts
new file mode 100644
index 00..38e49ea11b
--- /dev/null
+++ b/arch/arm/dts/imx8mm-wb15evk.dts
@@ -0,0 +1,390 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright 2019 NXP
+ */
+
+/dts-v1/;
+
+#include 
+#include "imx8mm.dtsi"
+
+/ {
+   model = "InnoComm i.MX8MM WB15EVK";
+   compatible = "fsl,imx8mm-wb15evk", "fsl,imx8mm";
+
+   chosen {
+   stdout-path = 
+   };
+
+   reg_usdhc2_vmmc: regulator-usdhc2 {
+   compatible = "regulator-fixed";
+   pinctrl-names = "default";
+   pinctrl-0 = <_reg_usdhc2_vmmc>;
+   regulator-name = "VSD_3V3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   gpio = < 19 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   };
+};
+
+_0 {
+   cpu-supply = <_reg>;
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_fec1>;
+   phy-mode = "rgmii-id";
+   phy-handle = <>;
+   phy-reset-gpios = < 9 

Re: iMX8MM USB support?

2020-04-09 Thread Tim Harvey
On Thu, Apr 9, 2020 at 3:02 AM Schrempf Frieder
 wrote:
>
> On 08.04.20 17:31, Tim Harvey wrote:
> [...]
> >>
> >> In my case I'm loading a FIT image, so things are a bit different.
> >> Where are you loading the image to?
> >>
> >> I have the following line in mx8mm_usb_sdp_spl.conf to load my FIT image
> >> to DDR and jump to it:
> >>
> >> /path/to/image/u-boot.itb:load 0x4020, jump_direct 0x4020
> >>
> >
> > Frieder,
> >
> > I was trying to load u-boot.img
> >
> > The SPL boots fine:
> > U-Boot SPL 2020.01-00029-g5ad7797 (Apr 08 2020 - 08:16:53 -0700)
> > read error from device: 9310b8 register: x!Normal Boot
> > Trying to boot from USB SDP
> > SDP: initialize...
> > SDP: handle requests..
> >
> > But when I 'imx_usb u-boot.img' it complains there is no header on
> > u-boot.img. I enabled FIT generation and attempted to 'imx_usb
> > u-boot.itb' but imx_usb still complains about no header found.
> >
> > My mx8mm_usb_sdp_spl.conf loooks like this:
> > mx8mm_spl_sdp
> > #hid/bulk,[old_header,]max packet size, {ram start, ram size}(repeat
> > valid ram areas)
> > #In SPL, we typically load u-boot.img which has a U-boot header...
> > hid,1024,0x91,0x4000,1G,0x0090,0x4
> >
> > #0x6 - 0x8400 = 0x57c00, +0x3000=5ac00 (FIT image)
> > ../u-boot-imx6/u-boot.bin:load 0x4020
> > ../u-boot-imx6/bl31-iMX8MM.bin:load 0x0092,jump 0x92
> >
> > What does your mx8mm_usb_sdp_spl.conf look like? I must admit I don't
> > really understand how these are configured.
>
> It looks just like yours except that I have a single instruction as
> already stated above:
>
> /path/to/image/u-boot.itb:load 0x4020, jump_direct 0x4020
>
> and I'm loading the FIT image by running './imx_usb' without arguments.
>
> As imx_usb_loader can't parse FIT image headers, I use 'jump_direct' to
> jump to the raw image entry point and let SPL parse the FIT. I think in
> that case imx_usb_loader shouldn't complain about a missing header.

Frieder,

Ok, I finally understand. Using 'imx_usb ' which is what I was
doing is not the same as loading it via the conf file and was why it
was looking for a header.

So now that I'm using the imx_usb.conf files fully instead It's
loading u-boot.itb and jumping but unfortunately I'm still not quite
there.

Here's what I'm seeing:

U-Boot SPL 2020.01-00029-g6529a03-dirty (Apr 09 2020 - 13:02:21 -0700)
Normal Boot
Trying to boot from USB SDP
SDP: initialize...
SDP: handle requests...
Downloading file of size 584020 to 0x4020... done
Jumping to header at 0x4020
Header Tag is not an IMX image

Is the 'Header Tag' message normal? From adding some debugging it
appears to matching the dts name in my board_fit_config_name_match and
parsing the FIT image, loading the ATF and jumping but then I get
nothing. What would I expect at this point and do you have any
troubleshooting tips?

Thanks,

Tim


[PULL] MIPS fixes for v2020.04

2020-04-09 Thread Daniel Schwierzeck
Hi Tom,

actually I've prepared this pull reuqest some weeks ago but was quite busy
since then to finally send it. This is just small stuff whcih can't break
anything. It would be great if you could sqeeze it in the release, thanks.

Gitlab: https://gitlab.denx.de/u-boot/custodians/u-boot-mips/pipelines/2695
Travis CI: 
https://travis-ci.org/github/danielschwierzeck/u-boot/builds/673086037


The following changes since commit dfd5321becc54d7ce9fd564aaaba70a2132c058e:

  Merge tag 'u-boot-imx-20200408' of 
https://gitlab.denx.de/u-boot/custodians/u-boot-imx (2020-04-08 12:06:39 -0400)

are available in the Git repository at:

  git://git.denx.de/u-boot-mips.git tags/mips-fixes-for-2020.04

for you to fetch changes up to fb9acad30562177287d8cffec19e5dfa6f072de7:

  mips: cmd: go: Flush cache before jumping to app/image (2020-04-09 19:00:00 
+0200)


- doc: fix code examples in qemu-mips.rst
- mips: vcoreiii: fix memtest and cache coherency issues
- cmd/go: fix cache coherency issues on MIPS


Alex Nemirovsky (2):
  MIPS: allow override of flush_dcache_range()
  MIPS: allow override of get_tbclk()

Heinrich Schuchardt (1):
  doc: board: qemu-mips.rst: fix code examples

Lars Povlsen (2):
  mips: vcoreiii: Ajust CONFIG_SYS_MEMTEST_END
  mips: vcoreiii: Fix cache coherency issues

Stefan Roese (1):
  mips: cmd: go: Flush cache before jumping to app/image

 arch/mips/cpu/time.c   |   2 +-
 arch/mips/lib/Makefile |   1 +
 arch/mips/lib/boot.c   |  23 +++
 arch/mips/lib/cache.c  |   2 +-
 arch/mips/mach-mscc/cpu.c  |   9 +
 arch/mips/mach-mscc/dram.c |  14 +-
 arch/mips/mach-mscc/include/mach/ddr.h |   4 
 arch/mips/mach-mscc/lowlevel_init.S|  17 -
 doc/board/emulation/qemu-mips.rst  | 108 

 include/configs/vcoreiii.h |   3 ++-
 10 files changed, 114 insertions(+), 69 deletions(-)
 create mode 100644 arch/mips/lib/boot.c


[PATCH v2 27/28] buildman: Update the TODO items

2020-04-09 Thread Simon Glass
A few of these have been done. Drop those and add some new ideas.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add patch to udpate TODO items

 tools/buildman/README | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/tools/buildman/README b/tools/buildman/README
index fe76d4ce0eb..cb565b551f8 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -1232,12 +1232,16 @@ Some options you might like are:
 TODO
 
 
-This has mostly be written in my spare time as a response to my difficulties
-in testing large series of patches. Apart from tidying up there is quite a
-bit of scope for improvement. Things like better error diffs and easier
-access to log files. Also it would be nice if buildman could 'hunt' for
-problems, perhaps by building a few boards for each arch, or checking
-commits for changed files and building only boards which use those files.
+Many improvements have been made over the years. There is still quite a bit of
+scope for more though, e.g.:
+
+- easier access to log files
+- 'hunting' for problems, perhaps by building a few boards for each arch, or
+  checking commits for changed files and building only boards which use those
+  files
+- using the same git repo for all threads instead of cloning it. Currently
+  it uses about 500MB per thread, so on a 64-thread machine this is 32GB for
+  the build.
 
 
 Credits
@@ -1253,3 +1257,4 @@ s...@chromium.org
 Halloween 2012
 Updated 12-12-12
 Updated 23-02-13
+Updated 09-04-20
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 26/28] buildman: Add an option to ignore migration warnings

2020-04-09 Thread Simon Glass
These are becoming more common now. They cause boards to show warnings
which can be mistaking for compiler warnings.

Add a buildman option to ignore them. This option works only with the
summary option (-s). It does not affect the build process.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to ignore migration warnings

 tools/buildman/README |   2 +-
 tools/buildman/builder.py |  12 +++-
 tools/buildman/cmdline.py |   5 +-
 tools/buildman/control.py |   3 +-
 tools/buildman/test.py| 120 --
 5 files changed, 107 insertions(+), 35 deletions(-)

diff --git a/tools/buildman/README b/tools/buildman/README
index 0663ec33a5b..fe76d4ce0eb 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -1125,7 +1125,7 @@ warnings will produce success (since 129 is changed to 0).
 If there are both warnings and errors, errors win, so buildman returns 128.
 
 The -y option is provided (for use with -s) to ignore the bountiful device-tree
-warnings.
+warnings. Similarly, -Y tells buildman to ignore the migration warnings.
 
 
 How to change from MAKEALL
diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 45569aa1f81..30ebe1d820a 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -306,6 +306,8 @@ class Builder:
 self._re_warning = re.compile('(.*):(\d*):(\d*): warning: .*')
 self._re_dtb_warning = re.compile('(.*): Warning .*')
 self._re_note = re.compile('(.*):(\d*):(\d*): note: this is the 
location of the previous.*')
+self._re_migration_warning = re.compile(r'^={21} WARNING 
={22}\n.*\n=+\n',
+re.MULTILINE | re.DOTALL)
 
 self.queue = queue.Queue()
 self.out_queue = queue.Queue()
@@ -338,7 +340,8 @@ class Builder:
 def SetDisplayOptions(self, show_errors=False, show_sizes=False,
   show_detail=False, show_bloat=False,
   list_error_boards=False, show_config=False,
-  show_environment=False, filter_dtb_warnings=False):
+  show_environment=False, filter_dtb_warnings=False,
+  filter_migration_warnings=False):
 """Setup display options for the builder.
 
 Args:
@@ -351,6 +354,8 @@ class Builder:
 show_environment: Show environment deltas
 filter_dtb_warnings: Filter out any warnings from the device-tree
 compiler
+filter_migration_warnings: Filter out any warnings about migrating
+a board to driver model
 """
 self._show_errors = show_errors
 self._show_sizes = show_sizes
@@ -360,6 +365,7 @@ class Builder:
 self._show_config = show_config
 self._show_environment = show_environment
 self._filter_dtb_warnings = filter_dtb_warnings
+self._filter_migration_warnings = filter_migration_warnings
 
 def _AddTimestamp(self):
 """Add a new timestamp to the list and record the build period.
@@ -559,6 +565,10 @@ class Builder:
 New list with only interesting lines included
 """
 out_lines = []
+if self._filter_migration_warnings:
+text = '\n'.join(lines)
+text = self._re_migration_warning.sub('', text)
+lines = text.splitlines()
 for line in lines:
 if self.re_make_err.search(line):
 continue
diff --git a/tools/buildman/cmdline.py b/tools/buildman/cmdline.py
index 8510c077f74..1377b9d2bec 100644
--- a/tools/buildman/cmdline.py
+++ b/tools/buildman/cmdline.py
@@ -116,7 +116,10 @@ def ParseArgs():
   help='Specify a list of boards to exclude, separated by comma')
 parser.add_option('-y', '--filter-dtb-warnings', action='store_true',
   default=False,
-   help='Filter out device-tree-compiler warnings from output')
+  help='Filter out device-tree-compiler warnings from output')
+parser.add_option('-Y', '--filter-migration-warnings', action='store_true',
+  default=False,
+  help='Filter out migration warnings from output')
 
 parser.usage += """ [list of target/arch/cpu/board/vendor/soc to build]
 
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 45d9ab73ceb..07f47a54454 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -353,7 +353,8 @@ def DoBuildman(options, args, toolchains=None, 
make_func=None, boards=None,
 builder.SetDisplayOptions(
 options.show_errors, options.show_sizes, options.show_detail,
 options.show_bloat, options.list_error_boards, options.show_config,
-options.show_environment, options.filter_dtb_warnings)
+options.show_environment, options.filter_dtb_warnings,
+options.filter_migration_warnings)
 if options.summary:
 

[PATCH v2 24/28] buildman: Make -I the default

2020-04-09 Thread Simon Glass
At present buildman defaults to running 'mrproper' on every thread before
it starts building commits for each board. This can add a delay of about 5
seconds to the start of the process, since the tools and other invariants
must be rebuilt.

In particular, a build without '-b', to build current source, runs much
slower without -I, since any existing build is removed, thus losing the
possibility of an incremental build.

Partly this behaviour was to avoid strange build-system problems caused by
running 'make defconfig' for one board and then one with a different
architecture. But these problems were fixed quite a while ago.

The -I option (which disabled mrproper) was introduced four years ago and
does not seem to cause any problems with builds.

So make -I the default and deprecate the option. To allow use of
'mrproper', add a new -m flag.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/README   | 13 ++---
 tools/buildman/builder.py   |  7 +++
 tools/buildman/builderthread.py |  6 +++---
 tools/buildman/cmdline.py   |  5 -
 tools/buildman/control.py   |  6 +-
 tools/buildman/func_test.py | 28 
 6 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/tools/buildman/README b/tools/buildman/README
index ca0d1f64460..f299b0c2972 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -958,12 +958,11 @@ will build commits in us-buildman that are not in 
upstream/master.
 Building Faster
 ===
 
-By default, buildman executes 'make mrproper' prior to building the first
-commit for each board. This causes everything to be built from scratch. If you
-trust the build system's incremental build capabilities, you can pass the -I
-flag to skip the 'make mproper' invocation, which will reduce the amount of
-work 'make' does, and hence speed up the build. This flag will speed up any
-buildman invocation, since it reduces the amount of work done on any build.
+By default, buildman doesn't execute 'make mrproper' prior to building the
+first commit for each board. This reduces the amount of work 'make' does, and
+hence speeds up the build. To force use of 'make mrproper', use -the -m flag.
+This flag will slow down any buildman invocation, since it increases the amount
+of work done on any build.
 
 One possible application of buildman is as part of a continual edit, build,
 edit, build, ... cycle; repeatedly applying buildman to the same change or
@@ -994,7 +993,7 @@ Combining all of these options together yields the 
command-line shown below.
 This will provide the quickest possible feedback regarding the current content
 of the source tree, thus allowing rapid tested evolution of the code.
 
-SOURCE_DATE_EPOCH=0 ./tools/buildman/buildman -I -P tegra
+SOURCE_DATE_EPOCH=0 ./tools/buildman/buildman -P tegra
 
 
 Checking configuration
diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 6819e5b40da..597a03ffb08 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -231,7 +231,7 @@ class Builder:
 def __init__(self, toolchains, base_dir, git_dir, num_threads, num_jobs,
  gnu_make='make', checkout=True, show_unknown=True, step=1,
  no_subdirs=False, full_path=False, verbose_build=False,
- incremental=False, per_board_out_dir=False,
+ mrproper=False, per_board_out_dir=False,
  config_only=False, squash_config_y=False,
  warnings_as_errors=False, work_in_output=False):
 """Create a new Builder object
@@ -252,8 +252,7 @@ class Builder:
 full_path: Return the full path in CROSS_COMPILE and don't set
 PATH
 verbose_build: Run build with V=1 and don't use 'make -s'
-incremental: Always perform incremental builds; don't run make
-mrproper when configuring
+mrproper: Always run 'make mrproper' when configuring
 per_board_out_dir: Build in a separate persistent directory per
 board rather than a thread-specific directory
 config_only: Only configure each build, don't build it
@@ -311,7 +310,7 @@ class Builder:
 self.queue = queue.Queue()
 self.out_queue = queue.Queue()
 for i in range(self.num_threads):
-t = builderthread.BuilderThread(self, i, incremental,
+t = builderthread.BuilderThread(self, i, mrproper,
 per_board_out_dir)
 t.setDaemon(True)
 t.start()
diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py
index 7561f399428..fc6e1ab25da 100644
--- a/tools/buildman/builderthread.py
+++ b/tools/buildman/builderthread.py
@@ -90,12 +90,12 @@ class BuilderThread(threading.Thread):
 thread_num: Our thread number (0-n-1), used to decide on a
 temporary directory
 """
-def __init__(self, builder, 

[PATCH v2 25/28] buildman: Add an option to ignore device-tree warnings

2020-04-09 Thread Simon Glass
Unfortunately the plague of device-tree warnings has not lifted. These
warnings infiltrate almost every build, adding noise and confusion.

Add a buildman option to ignore them. This option works only with the
summary option (-s). It does not affect the build process.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop use of temporary 'line' variable

 tools/buildman/README |  3 +++
 tools/buildman/builder.py | 27 +--
 tools/buildman/cmdline.py |  3 +++
 tools/buildman/control.py | 11 +--
 tools/buildman/test.py| 31 ---
 5 files changed, 52 insertions(+), 23 deletions(-)

diff --git a/tools/buildman/README b/tools/buildman/README
index f299b0c2972..0663ec33a5b 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -1124,6 +1124,9 @@ warnings will produce success (since 129 is changed to 0).
 
 If there are both warnings and errors, errors win, so buildman returns 128.
 
+The -y option is provided (for use with -s) to ignore the bountiful device-tree
+warnings.
+
 
 How to change from MAKEALL
 ==
diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 597a03ffb08..45569aa1f81 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -338,16 +338,19 @@ class Builder:
 def SetDisplayOptions(self, show_errors=False, show_sizes=False,
   show_detail=False, show_bloat=False,
   list_error_boards=False, show_config=False,
-  show_environment=False):
+  show_environment=False, filter_dtb_warnings=False):
 """Setup display options for the builder.
 
-show_errors: True to show summarised error/warning info
-show_sizes: Show size deltas
-show_detail: Show size delta detail for each board if show_sizes
-show_bloat: Show detail for each function
-list_error_boards: Show the boards which caused each error/warning
-show_config: Show config deltas
-show_environment: Show environment deltas
+Args:
+show_errors: True to show summarised error/warning info
+show_sizes: Show size deltas
+show_detail: Show size delta detail for each board if show_sizes
+show_bloat: Show detail for each function
+list_error_boards: Show the boards which caused each error/warning
+show_config: Show config deltas
+show_environment: Show environment deltas
+filter_dtb_warnings: Filter out any warnings from the device-tree
+compiler
 """
 self._show_errors = show_errors
 self._show_sizes = show_sizes
@@ -356,6 +359,7 @@ class Builder:
 self._list_error_boards = list_error_boards
 self._show_config = show_config
 self._show_environment = show_environment
+self._filter_dtb_warnings = filter_dtb_warnings
 
 def _AddTimestamp(self):
 """Add a new timestamp to the list and record the build period.
@@ -556,8 +560,11 @@ class Builder:
 """
 out_lines = []
 for line in lines:
-if not self.re_make_err.search(line):
-out_lines.append(line)
+if self.re_make_err.search(line):
+continue
+if self._filter_dtb_warnings and self._re_dtb_warning.search(line):
+continue
+out_lines.append(line)
 return out_lines
 
 def ReadFuncSizes(self, fname, fd):
diff --git a/tools/buildman/cmdline.py b/tools/buildman/cmdline.py
index 0178c6e8845..8510c077f74 100644
--- a/tools/buildman/cmdline.py
+++ b/tools/buildman/cmdline.py
@@ -114,6 +114,9 @@ def ParseArgs():
 parser.add_option('-x', '--exclude', dest='exclude',
   type='string', action='append',
   help='Specify a list of boards to exclude, separated by comma')
+parser.add_option('-y', '--filter-dtb-warnings', action='store_true',
+  default=False,
+   help='Filter out device-tree-compiler warnings from output')
 
 parser.usage += """ [list of target/arch/cpu/board/vendor/soc to build]
 
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 384e62dbc56..45d9ab73ceb 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -345,16 +345,15 @@ def DoBuildman(options, args, toolchains=None, 
make_func=None, boards=None,
 commits = None
 
 Print(GetActionSummary(options.summary, commits, board_selected,
-options))
+   options))
 
 # We can't show function sizes without board details at present
 if options.show_bloat:
 options.show_detail = True
-builder.SetDisplayOptions(options.show_errors, options.show_sizes,
-  options.show_detail, options.show_bloat,
-  

[PATCH v2 28/28] buildman: Change the exit codes

2020-04-09 Thread Simon Glass
The current exit codes of 128 and 129 are useful in that they do not
conflict with those returned by tools, but they are not actually valid.
It seems better to pick some codes which work with 'bit bisect run'.

Update them to 100 (for errors) and 101 (for warnings).

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to change the exit codes

 tools/buildman/README | 12 ++--
 tools/buildman/control.py |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/buildman/README b/tools/buildman/README
index cb565b551f8..f3a0dc7288d 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -1114,15 +1114,15 @@ with -E, e.g. the migration warnings:
 When doing builds, Buildman's return code will reflect the overall result:
 
 0 (success) No errors or warnings found
-128 Errors found
-129 Warnings found (only if no -W)
+100 Errors found
+101 Warnings found (only if no -W)
 
-You can use -W to tell Buildman to return 0 (success) instead of 129 when
+You can use -W to tell Buildman to return 0 (success) instead of 101 when
 warnings are found. Note that it can be useful to combine -E and -W. This means
-that all compiler warnings will produce failures (code 128) and all other
-warnings will produce success (since 129 is changed to 0).
+that all compiler warnings will produce failures (code 100) and all other
+warnings will produce success (since 101 is changed to 0).
 
-If there are both warnings and errors, errors win, so buildman returns 128.
+If there are both warnings and errors, errors win, so buildman returns 100.
 
 The -y option is provided (for use with -s) to ignore the bountiful device-tree
 warnings. Similarly, -Y tells buildman to ignore the migration warnings.
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index 07f47a54454..30c030fd16e 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -361,7 +361,7 @@ def DoBuildman(options, args, toolchains=None, 
make_func=None, boards=None,
 fail, warned = builder.BuildBoards(commits, board_selected,
 options.keep_outputs, options.verbose)
 if fail:
-return 128
+return 100
 elif warned and not options.ignore_warnings:
-return 129
+return 101
 return 0
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 22/28] buildman: Add the abbreviation for --boards

2020-04-09 Thread Simon Glass
This option may be frequency used, so mention that it can be abbreviated
to --bo

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/README | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/buildman/README b/tools/buildman/README
index 86f5dfe501f..9bf4383f9f7 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -151,9 +151,9 @@ You can also use -x to specifically exclude some boards. 
For example:
 means to build all arm boards except nvidia, freescale and anything ending
 with 'ball'.
 
-For building specific boards you can use the --boards option, which takes a
-comma-separated list of board target names and be used multiple times on
-the command line:
+For building specific boards you can use the --boards (or --bo) option, which
+takes a comma-separated list of board target names and be used multiple times
+on the command line:
 
   buildman --boards sandbox,snow --boards
 
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 23/28] buildman: Update workflow documentation with more detail

2020-04-09 Thread Simon Glass
Make a few additions and change some wording in the workflow
documentation.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/README | 53 +--
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/tools/buildman/README b/tools/buildman/README
index 9bf4383f9f7..ca0d1f64460 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -501,6 +501,8 @@ If it can't detect the upstream branch, try checking out 
the branch, and
 doing something like 'git branch --set-upstream-to upstream/master'
 or something similar. Buildman will try to guess a suitable upstream branch
 if it can't find one (you will see a message like" Guessing upstream as ...).
+You can also use the -c option to manually specify the number of commits to
+build.
 
 As an example:
 
@@ -551,12 +553,13 @@ Buildman will set up some working directories, and get 
started. After a
 minute or so it will settle down to a steady pace, with a display like this:
 
 Building 18 commits for 1059 boards (4 threads, 1 job per thread)
-  528   36  124 /19062  1:13:30  : SIMPC8313_SP
+  528   36  124 /19062-18374  1:13:30  : SIMPC8313_SP
 
 This means that it is building 19062 board/commit combinations. So far it
 has managed to successfully build 528. Another 36 have built with warnings,
-and 124 more didn't build at all. Buildman expects to complete the process
-in around an hour and a quarter. Use this time to buy a faster computer.
+and 124 more didn't build at all. It has 18374 builds left to complete.
+Buildman expects to complete the process in around an hour and a quarter.
+Use this time to buy a faster computer.
 
 
 To find out how the build went, ask for a summary with -s. You can do this
@@ -588,32 +591,32 @@ $ ./tools/buildman/buildman -b lcd9b -s
 
 This shows which commits have succeeded and which have failed. In this case
 the build is still in progress so many boards are not built yet (use -u to
-see which ones). But still we can see a few failures. The galaxy5200_LOWBOOT
+see which ones). But already we can see a few failures. The galaxy5200_LOWBOOT
 never builds correctly. This could be a problem with our toolchain, or it
 could be a bug in the upstream. The good news is that we probably don't need
 to blame our commits. The bad news is that our commits are not tested on that
 board.
 
-Commit 12 broke lubbock. That's what the '+ lubbock' means. The failure
-is never fixed by a later commit, or you would see lubbock again, in green,
-without the +.
+Commit 12 broke lubbock. That's what the '+ lubbock', in red, means. The
+failure is never fixed by a later commit, or you would see lubbock again, in
+green, without the +.
 
 To see the actual error:
 
-$ ./tools/buildman/buildman -b  -se lubbock
+$ ./tools/buildman/buildman -b  -se
 ...
 12: lcd: Add support for flushing LCD fb from dcache after update
arm:   + lubbock
 +common/libcommon.o: In function `lcd_sync':
-+/u-boot/lcd9b/.bm-work/00/common/lcd.c:120: undefined reference to 
`flush_dcache_range'
++common/lcd.c:120: undefined reference to `flush_dcache_range'
 +arm-none-linux-gnueabi-ld: BFD (Sourcery G++ Lite 2010q1-202) 
2.19.51.20090709 assertion fail 
/scratch/julian/2010q1-release-linux-lite/obj/binutils-src-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu/bfd/elf32-arm.c:12572
-+make: *** [/u-boot/lcd9b/.bm-work/00/build/u-boot] Error 139
++make: *** [build/u-boot] Error 139
 13: tegra: Align LCD frame buffer to section boundary
 14: tegra: Support control of cache settings for LCD
 15: tegra: fdt: Add LCD definitions for Seaboard
 16: lcd: Add CONFIG_CONSOLE_SCROLL_LINES option to speed console
--/u-boot/lcd9b/.bm-work/00/common/lcd.c:120: undefined reference to 
`flush_dcache_range'
-+/u-boot/lcd9b/.bm-work/00/common/lcd.c:125: undefined reference to 
`flush_dcache_range'
+-common/lcd.c:120: undefined reference to `flush_dcache_range'
++common/lcd.c:125: undefined reference to `flush_dcache_range'
 17: tegra: Enable display/lcd support on Seaboard
 18: wip
 
@@ -621,6 +624,21 @@ So the problem is in lcd.c, due to missing cache 
operations. This information
 should be enough to work out what that commit is doing to break these
 boards. (In this case pxa did not have cache operations defined).
 
+Note that if there were other boards with errors, the above command would
+show their errors also. Each line is shown only once. So if lubbock and snow
+produce the same error, we just see:
+
+12: lcd: Add support for flushing LCD fb from dcache after update
+   arm:   + lubbock snow
++common/libcommon.o: In function `lcd_sync':
++common/lcd.c:120: undefined reference to `flush_dcache_range'
++arm-none-linux-gnueabi-ld: BFD (Sourcery G++ Lite 2010q1-202) 
2.19.51.20090709 assertion fail 
/scratch/julian/2010q1-release-linux-lite/obj/binutils-src-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu/bfd/elf32-arm.c:12572
++make: *** [build/u-boot] Error 139
+
+But if you did want to see just the 

[PATCH v2 21/28] buildman: Update the 'theory of operation' a little

2020-04-09 Thread Simon Glass
Make a few updates to this important section of the documentation, to
make things clearer.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/README | 69 ---
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/tools/buildman/README b/tools/buildman/README
index 4cf01141574..86f5dfe501f 100644
--- a/tools/buildman/README
+++ b/tools/buildman/README
@@ -51,23 +51,25 @@ Theory of Operation
 
 Buildman is a builder. It is not make, although it runs make. It does not
 produce any useful output on the terminal while building, except for
-progress information (except with -v, see below). All the output (errors,
-warnings and binaries if you ask for them) is stored in output
-directories, which you can look at while the build is progressing, or when
-it is finished.
+progress information (but see -v below). All the output (errors, warnings and
+binaries if you ask for them) is stored in output directories, which you can
+look at from a separate 'buildman -s' instance while the build is progressing,
+or when it is finished.
 
 Buildman is designed to build entire git branches, i.e. muliple commits. It
-can be run repeatedly on the same branch. In this case it will automatically
-rebuild commits which have changed (and remove its old results for that
-commit). It is possible to build a branch for one board, then later build it
-for another board. If you want buildman to re-build a commit it has already
-built (e.g. because of a toolchain update), use the -f flag.
+can be run repeatedly on the same branch after making changes to commits on
+that branch. In this case it will automatically rebuild commits which have
+changed (and remove its old results for that commit). It is possible to build
+a branch for one board, then later build it for another board. This adds to
+the output, so now you have results for two boards. If you want buildman to
+re-build a commit it has already built (e.g. because of a toolchain update),
+use the -f flag.
 
 Buildman produces a concise summary of which boards succeeded and failed.
 It shows which commit introduced which board failure using a simple
-red/green colour coding. Full error information can be requested, in which
-case it is de-duped and displayed against the commit that introduced the
-error. An example workflow is below.
+red/green colour coding (with yellow/cyan for warnings). Full error
+information can be requested, in which case it is de-duped and displayed
+against the commit that introduced the error. An example workflow is below.
 
 Buildman stores image size information and can report changes in image size
 from commit to commit. An example of this is below.
@@ -75,16 +77,20 @@ from commit to commit. An example of this is below.
 Buildman starts multiple threads, and each thread builds for one board at
 a time. A thread starts at the first commit, configures the source for your
 board and builds it. Then it checks out the next commit and does an
-incremental build. Eventually the thread reaches the last commit and stops.
-If errors or warnings are found along the way, the thread will reconfigure
-after every commit, and your build will be very slow. This is because a
-file that produces just a warning would not normally be rebuilt in an
-incremental build.
+incremental build (i.e. not using 'make xxx_defconfig' unless you use -C).
+Eventually the thread reaches the last commit and stops. If a commit causes
+an error or warning, buildman will try it again after reconfiguring (but see
+-Q). Thus some commits may be built twice, with the first result silently
+discarded. Lots of errors and warnings will causes lots of reconfigures and 
your
+build will be very slow. This is because a file that produces just a warning
+would not normally be rebuilt in an incremental build. Once a thread finishes
+building all the commits for a board, it starts on the commits for another
+board.
 
 Buildman works in an entirely separate place from your U-Boot repository.
 It creates a separate working directory for each thread, and puts the
 output files in the working directory, organised by commit name and board
-name, in a two-level hierarchy.
+name, in a two-level hierarchy (but see -P).
 
 Buildman is invoked in your U-Boot directory, the one with the .git
 directory. It clones this repository into a copy for each thread, and the
@@ -92,20 +98,23 @@ threads do not affect the state of your git repository. Any 
checkouts done
 by the thread affect only the working directory for that thread.
 
 Buildman automatically selects the correct tool chain for each board. You
-must supply suitable tool chains, but buildman takes care of selecting the
-right one.
+must supply suitable tool chains (see --fetch-arch), but buildman takes care
+of selecting the right one.
 
 Buildman generally builds a branch (with the -b flag), and in this case
-builds the upstream commit as well, for comparison. It cannot build
-individual 

[PATCH v2 20/28] buildman: Show a summary of the build result

2020-04-09 Thread Simon Glass
When buildman finishes it leaves the last summary line visible, which
shows the number of successful builds, builds with warnings and builds
with errors.

It is useful also to see how many builds were done in total along with
the time taken. Show these on a separate line before buildman finishes.

Signed-off-by: Simon Glass 

---

Changes in v2: None

 tools/buildman/builder.py | 17 +
 tools/buildman/test.py|  6 +++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 73753eb4bc9..6819e5b40da 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -192,6 +192,7 @@ class Builder:
 _next_delay_update: Next time we plan to display a progress update
 (datatime)
 _show_unknown: Show unknown boards (those not built) in summary
+_start_time: Start time for the build
 _timestamps: List of timestamps for the completion of the last
 last _timestamp_count builds. Each is a datetime object.
 _timestamp_count: Number of timestamps to keep in our list.
@@ -281,6 +282,7 @@ class Builder:
 self._build_period_us = None
 self._complete_delay = None
 self._next_delay_update = datetime.now()
+self._start_time = datetime.now()
 self.force_config_on_failure = True
 self.force_build_failures = False
 self.force_reconfig = False
@@ -1642,4 +1644,19 @@ class Builder:
 # Wait until we have processed all output
 self.out_queue.join()
 Print()
+
+msg = 'Completed: %d total built' % self.count
+if self.already_done:
+   msg += ' (%d previously' % self.already_done
+   if self.already_done != self.count:
+   msg += ', %d newly' % (self.count - self.already_done)
+   msg += ')'
+duration = datetime.now() - self._start_time
+if duration > timedelta(microseconds=100):
+if duration.microseconds >= 50:
+duration = duration + timedelta(seconds=1)
+duration = duration - timedelta(microseconds=duration.microseconds)
+msg += ', duration %s' % duration
+Print(msg)
+
 return (self.fail, self.warned)
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index a495df03036..fb861e16a1b 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -205,9 +205,9 @@ class TestBuild(unittest.TestCase):
 if line.text.strip():
 count += 1
 
-# We should get two starting messages, then an update for every commit
-# built.
-self.assertEqual(count, len(commits) * len(boards) + 2)
+# We should get two starting messages, an update for every commit built
+# and a summary message
+self.assertEqual(count, len(commits) * len(boards) + 3)
 build.SetDisplayOptions(**kwdisplay_args);
 build.ShowSummary(self.commits, board_selected)
 if echo_lines:
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 17/28] buildman: Drop unused output code

2020-04-09 Thread Simon Glass
The commit counter is a hangover from when buildman processed each board
for a commit. Now buildman processes each commit for a board, so this
output is never triggered.

Delete it.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 5 -
 1 file changed, 5 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index ccf46ac5f67..ae8eee16e35 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -450,11 +450,6 @@ class Builder:
 self._AddTimestamp()
 if self._complete_delay:
 name += '%s  : ' % self._complete_delay
-# When building all boards for a commit, we can print a commit
-# progress message.
-if result and result.commit_upto is None:
-name += 'commit %2d/%-3d' % (self.commit_upto + 1,
-self.commit_count)
 
 name += target
 terminal.PrintClear()
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 18/28] buildman: Show the number of builds remaining

2020-04-09 Thread Simon Glass
It is nice to see the actual number of builds remaining to complete. Add
this in the progress message, using a different colour.

Drop the unnecessary 'name' variable while we are here.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index ae8eee16e35..b9caf6cf9c1 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -444,16 +444,21 @@ class Builder:
 line += self.col.Color(self.col.YELLOW, '%5d' % self.warned)
 line += self.col.Color(self.col.RED, '%5d' % self.fail)
 
-name = ' /%-5d  ' % self.count
+line += ' /%-5d  ' % self.count
+remaining = self.count - self.upto
+if remaining:
+line += self.col.Color(self.col.MAGENTA, ' -%-5d  ' % remaining)
+else:
+line += ' ' * 8
 
 # Add our current completion time estimate
 self._AddTimestamp()
 if self._complete_delay:
-name += '%s  : ' % self._complete_delay
+line += '%s  : ' % self._complete_delay
 
-name += target
+line += target
 terminal.PrintClear()
-Print(line + name, newline=False)
+Print(line, newline=False)
 
 def _GetOutputDir(self, commit_upto):
 """Get the name of the output directory for a commit number
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 19/28] buildman: Limit the length of progress messages

2020-04-09 Thread Simon Glass
If a progress message is longer than the terminal line it will scroll the
terminal. Limit the messages to the terminal width.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index b9caf6cf9c1..73753eb4bc9 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -458,7 +458,7 @@ class Builder:
 
 line += target
 terminal.PrintClear()
-Print(line, newline=False)
+Print(line, newline=False, limit_to_line=True)
 
 def _GetOutputDir(self, commit_upto):
 """Get the name of the output directory for a commit number
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 15/28] buildman: Drop the line-clearing code in Builder

2020-04-09 Thread Simon Glass
The new feature in terminal can be used by buildman. Update the Builder
class accordingly.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 28 +++-
 1 file changed, 3 insertions(+), 25 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index e895ab73d8d..60e854bb49a 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -162,8 +162,6 @@ class Builder:
 force_build_failures: If a previously-built build (i.e. built on
 a previous run of buildman) is marked as failed, rebuild it.
 git_dir: Git directory containing source repository
-last_line_len: Length of the last line we printed (used for erasing
-it with new progress information)
 num_jobs: Number of jobs to run at once (passed to make as -j)
 num_threads: Number of builder threads to run
 out_queue: Queue of results to process
@@ -317,7 +315,6 @@ class Builder:
 t.start()
 self.threads.append(t)
 
-self.last_line_len = 0
 t = builderthread.ResultThread(self)
 t.setDaemon(True)
 t.start()
@@ -388,22 +385,6 @@ class Builder:
 self._timestamps.popleft()
 count -= 1
 
-def ClearLine(self, length):
-"""Clear any characters on the current line
-
-Make way for a new line of length 'length', by outputting enough
-spaces to clear out the old line. Then remember the new length for
-next time.
-
-Args:
-length: Length of new line, in characters
-"""
-if length < self.last_line_len:
-Print(' ' * (self.last_line_len - length), newline=False)
-Print('\r', newline=False)
-self.last_line_len = length
-sys.stdout.flush()
-
 def SelectCommit(self, commit, checkout=True):
 """Checkout the selected commit for this build
 """
@@ -449,8 +430,7 @@ class Builder:
 if result.already_done:
 self.already_done += 1
 if self._verbose:
-Print('\r', newline=False)
-self.ClearLine(0)
+terminal.PrintClear()
 boards_selected = {target : result.brd}
 self.ResetResultSummary(boards_selected)
 self.ProduceResultSummary(result.commit_upto, self.commits,
@@ -477,9 +457,8 @@ class Builder:
 self.commit_count)
 
 name += target
+terminal.PrintClear()
 Print(line + name, newline=False)
-length = 16 + len(name)
-self.ClearLine(length)
 
 def _GetOutputDir(self, commit_upto):
 """Get the name of the output directory for a commit number
@@ -1559,7 +1538,7 @@ class Builder:
 Print('\rCloning repo for thread %d' % thread_num,
   newline=False)
 gitutil.Clone(src_dir, thread_dir)
-Print('\r%s\r' % (' ' * 30), newline=False)
+terminal.PrintClear()
 
 def _PrepareWorkingSpace(self, max_threads, setup_git):
 """Prepare the working directory for use.
@@ -1660,5 +1639,4 @@ class Builder:
 # Wait until we have processed all output
 self.out_queue.join()
 Print()
-self.ClearLine(0)
 return (self.fail, self.warned)
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 16/28] buildman: Show a message when fetching a repo

2020-04-09 Thread Simon Glass
Fetching updated versions of a repo can take time. At present buildman
gives no indication that it is doing this.

Add a message to explain the delay.

Tidy up a few other messages while we are here.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 60e854bb49a..ccf46ac5f67 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -1533,7 +1533,10 @@ class Builder:
 if setup_git and self.git_dir:
 src_dir = os.path.abspath(self.git_dir)
 if os.path.exists(git_dir):
+Print('\rFetching repo for thread %d' % thread_num,
+  newline=False)
 gitutil.Fetch(git_dir, thread_dir)
+terminal.PrintClear()
 else:
 Print('\rCloning repo for thread %d' % thread_num,
   newline=False)
@@ -1591,7 +1594,7 @@ class Builder:
   newline=False)
 for dirname in to_remove:
 shutil.rmtree(dirname)
-Print('done')
+terminal.PrintClear()
 
 def BuildBoards(self, commits, board_selected, keep_outputs, verbose):
 """Build all commits for a list of boards
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 11/28] buildman: Use spaces in the board list

2020-04-09 Thread Simon Glass
At present the board names shown with -l are separated by commas. This
makes it hard to double-click to select a particular board. Also it is not
possible to select all boards and paste them as arguments to a subsequent
buildman run, since buildman requires spaces to separate the list on the
command line, not commas.

Change the output format to use spaces instead of commas.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to use spaces in the board list

 tools/buildman/builder.py | 2 +-
 tools/buildman/test.py| 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 7cbb1a6f628..e895ab73d8d 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -1253,7 +1253,7 @@ class Builder:
 for line in err_lines:
 boards = ''
 names = [board.target for board in line.boards]
-board_str = ','.join(names) if names else ''
+board_str = ' '.join(names) if names else ''
 if board_str:
 out = self.col.Color(colour, line.char + '(')
 out += self.col.Color(self.col.MAGENTA, board_str,
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index a64372dee36..a495df03036 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -249,9 +249,9 @@ class TestBuild(unittest.TestCase):
 new_lines.append(expect)
 return '\n'.join(new_lines)
 
-boards1234 = 'board1,board2,board3,board4' if list_error_boards else ''
-boards234 = 'board2,board3,board4' if list_error_boards else ''
-boards34 = 'board3,board4' if list_error_boards else ''
+boards1234 = 'board1 board2 board3 board4' if list_error_boards else ''
+boards234 = 'board2 board3 board4' if list_error_boards else ''
+boards34 = 'board3 board4' if list_error_boards else ''
 boards4 = 'board4' if list_error_boards else ''
 
 # Upstream commit: no errors
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 14/28] patman: Support limiting output to a single line

2020-04-09 Thread Simon Glass
When outputing a progress line we don't want it to go past the end of the
current terminal line, or it will not be possible to erase it. Add an
option to Print() which allows limiting the output to the terminal width.

Since ANSI sequences do not take up space on the terminal, these are
removed.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/patman/terminal.py | 58 +++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/tools/patman/terminal.py b/tools/patman/terminal.py
index c7693eb57ad..5c9e3eea20c 100644
--- a/tools/patman/terminal.py
+++ b/tools/patman/terminal.py
@@ -11,6 +11,7 @@ from __future__ import print_function
 
 import os
 import re
+import shutil
 import sys
 
 # Selection of when we want our output to be colored
@@ -47,6 +48,9 @@ class PrintLine:
 def CalcAsciiLen(text):
 """Calculate the length of a string, ignoring any ANSI sequences
 
+When displayed on a terminal, ANSI sequences don't take any space, so we
+need to ignore them when calculating the length of a string.
+
 Args:
 text: Text to check
 
@@ -70,8 +74,57 @@ def CalcAsciiLen(text):
 result = ansi_escape.sub('', text)
 return len(result)
 
+def TrimAsciiLen(text, size):
+"""Trim a string containing ANSI sequences to the given ASCII length
+
+The string is trimmed with ANSI sequences being ignored for the length
+calculation.
+
+>>> col = Color(COLOR_ALWAYS)
+>>> text = col.Color(Color.RED, 'abc')
+>>> len(text)
+14
+>>> CalcAsciiLen(TrimAsciiLen(text, 4))
+3
+>>> CalcAsciiLen(TrimAsciiLen(text, 2))
+2
+>>> text += 'def'
+>>> CalcAsciiLen(TrimAsciiLen(text, 4))
+4
+>>> text += col.Color(Color.RED, 'ghi')
+>>> CalcAsciiLen(TrimAsciiLen(text, 7))
+7
+"""
+if CalcAsciiLen(text) < size:
+return text
+pos = 0
+out = ''
+left = size
+
+# Work through each ANSI sequence in turn
+for m in ansi_escape.finditer(text):
+# Find the text before the sequence and add it to our string, making
+# sure it doesn't overflow
+before = text[pos:m.start()]
+toadd = before[:left]
+out += toadd
+
+# Figure out how much non-ANSI space we have left
+left -= len(toadd)
+
+# Add the ANSI sequence and move to the position immediately after it
+out += m.group()
+pos = m.start() + len(m.group())
+
+# Deal with text after the last ANSI sequence
+after = text[pos:]
+toadd = after[:left]
+out += toadd
+
+return out
+
 
-def Print(text='', newline=True, colour=None):
+def Print(text='', newline=True, colour=None, limit_to_line=False):
 """Handle a line of output to the terminal.
 
 In test mode this is recorded in a list. Otherwise it is output to the
@@ -94,6 +147,9 @@ def Print(text='', newline=True, colour=None):
 print(text)
 last_print_len = None
 else:
+if limit_to_line:
+cols = shutil.get_terminal_size().columns
+text = TrimAsciiLen(text, cols)
 print(text, end='', flush=True)
 last_print_len = CalcAsciiLen(text)
 
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 13/28] patman: Support erasing a previously unfinished text line

2020-04-09 Thread Simon Glass
When printing progress it is useful to print a message and leave the
cursor at the end of the line until the operation is finished. When it is
finished, the line needs to be erased so a new line can start in its place.

Add a function to handle clearing a line previously written by
terminal.Print()

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/patman/patman.py   |  2 +-
 tools/patman/terminal.py | 47 
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/tools/patman/patman.py b/tools/patman/patman.py
index cf53e532ddf..7f4ac9aef48 100755
--- a/tools/patman/patman.py
+++ b/tools/patman/patman.py
@@ -93,7 +93,7 @@ elif options.test:
 suite = unittest.TestLoader().loadTestsFromTestCase(module)
 suite.run(result)
 
-for module in ['gitutil', 'settings']:
+for module in ['gitutil', 'settings', 'terminal']:
 suite = doctest.DocTestSuite(module)
 suite.run(result)
 
diff --git a/tools/patman/terminal.py b/tools/patman/terminal.py
index 6541fa8f410..c7693eb57ad 100644
--- a/tools/patman/terminal.py
+++ b/tools/patman/terminal.py
@@ -10,6 +10,7 @@ This module handles terminal interaction including ANSI color 
codes.
 from __future__ import print_function
 
 import os
+import re
 import sys
 
 # Selection of when we want our output to be colored
@@ -19,6 +20,13 @@ COLOR_IF_TERMINAL, COLOR_ALWAYS, COLOR_NEVER = range(3)
 print_test_mode = False
 print_test_list = []
 
+# The length of the last line printed without a newline
+last_print_len = None
+
+# credit:
+# 
stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python
+ansi_escape = re.compile(r'\x1b(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
+
 class PrintLine:
 """A line of text output
 
@@ -36,6 +44,33 @@ class PrintLine:
 return 'newline=%s, colour=%s, text=%s' % (self.newline, self.colour,
 self.text)
 
+def CalcAsciiLen(text):
+"""Calculate the length of a string, ignoring any ANSI sequences
+
+Args:
+text: Text to check
+
+Returns:
+Length of text, after skipping ANSI sequences
+
+>>> col = Color(COLOR_ALWAYS)
+>>> text = col.Color(Color.RED, 'abc')
+>>> len(text)
+14
+>>> CalcAsciiLen(text)
+3
+>>>
+>>> text += 'def'
+>>> CalcAsciiLen(text)
+6
+>>> text += col.Color(Color.RED, 'abc')
+>>> CalcAsciiLen(text)
+9
+"""
+result = ansi_escape.sub('', text)
+return len(result)
+
+
 def Print(text='', newline=True, colour=None):
 """Handle a line of output to the terminal.
 
@@ -47,6 +82,8 @@ def Print(text='', newline=True, colour=None):
 newline: True to add a new line at the end of the text
 colour: Colour to use for the text
 """
+global last_print_len
+
 if print_test_mode:
 print_test_list.append(PrintLine(text, newline, colour))
 else:
@@ -55,8 +92,18 @@ def Print(text='', newline=True, colour=None):
 text = col.Color(colour, text)
 if newline:
 print(text)
+last_print_len = None
 else:
 print(text, end='', flush=True)
+last_print_len = CalcAsciiLen(text)
+
+def PrintClear():
+"""Clear a previously line that was printed with no newline"""
+global last_print_len
+
+if last_print_len:
+print('\r%s\r' % (' '* last_print_len), end='', flush=True)
+last_print_len = None
 
 def SetPrintTestMode():
 """Go into test mode, where all printing is recorded"""
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 12/28] patman: Update flushing Print() for Python 3

2020-04-09 Thread Simon Glass
This does not seem to work on Python 3. Update the code to use the
built-in support.

Signed-off-by: Simon Glass 
---

Changes in v2: None

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

diff --git a/tools/patman/terminal.py b/tools/patman/terminal.py
index 7a3b658b00e..6541fa8f410 100644
--- a/tools/patman/terminal.py
+++ b/tools/patman/terminal.py
@@ -53,11 +53,10 @@ def Print(text='', newline=True, colour=None):
 if colour:
 col = Color()
 text = col.Color(colour, text)
-print(text, end='')
 if newline:
-print()
+print(text)
 else:
-sys.stdout.flush()
+print(text, end='', flush=True)
 
 def SetPrintTestMode():
 """Go into test mode, where all printing is recorded"""
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 07/28] buildman: Test the output with --list-error-boards

2020-04-09 Thread Simon Glass
Add a test to cover this flag, which adds the name of each board to each
error/warning line.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Move the 'boards' variables to the start of _CheckOutput()

 tools/buildman/test.py | 46 +-
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index 1377035fbb4..b1435b45c03 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -214,13 +214,15 @@ class TestBuild(unittest.TestCase):
 terminal.EchoPrintTestLines()
 return iter(terminal.GetPrintTestLines())
 
-def _CheckOutput(self, lines):
+def _CheckOutput(self, lines, list_error_boards):
 """Check for expected output from the build summary
 
 Args:
 lines: Iterator containing the lines returned from the summary
+list_error_boards: Adjust the check for output produced with the
+   --list-error-boards flag
 """
-def add_line_prefix(prefix, error_str):
+def add_line_prefix(prefix, boards, error_str):
 """Add a prefix to each line of a string
 
 The training \n in error_str is removed before processing
@@ -232,10 +234,17 @@ class TestBuild(unittest.TestCase):
 Returns:
 New string where each line has the prefix added
 """
+if boards:
+boards = '(%s) ' % boards
 lines = error_str.strip().splitlines()
-new_lines = [prefix + line for line in lines]
+new_lines = [prefix + boards + line for line in lines]
 return '\n'.join(new_lines)
 
+boards1234 = 'board1,board2,board3,board4' if list_error_boards else ''
+boards234 = 'board2,board3,board4' if list_error_boards else ''
+boards34 = 'board3,board4' if list_error_boards else ''
+boards4 = 'board4' if list_error_boards else ''
+
 # Upstream commit: no errors
 self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
 
@@ -253,7 +262,8 @@ class TestBuild(unittest.TestCase):
 # Second commit: The warnings should be listed
 line = next(lines)
 
-self.assertEqual(line.text, add_line_prefix('w+', errors[0]))
+self.assertEqual(line.text,
+ add_line_prefix('w+', boards1234, errors[0]))
 self.assertEqual(line.colour, col.MAGENTA)
 
 # Third commit: Still fails
@@ -266,7 +276,7 @@ class TestBuild(unittest.TestCase):
 
 # Expect a compiler error
 line = next(lines)
-self.assertEqual(line.text, add_line_prefix('+', errors[1]))
+self.assertEqual(line.text, add_line_prefix('+', boards234, errors[1]))
 self.assertEqual(line.colour, col.RED)
 
 # Fourth commit: Compile errors are fixed, just have warning for board3
@@ -284,11 +294,11 @@ class TestBuild(unittest.TestCase):
 
 # Compile error fixed
 line = next(lines)
-self.assertEqual(line.text, add_line_prefix('-', errors[1]))
+self.assertEqual(line.text, add_line_prefix('-', boards234, errors[1]))
 self.assertEqual(line.colour, col.GREEN)
 
 line = next(lines)
-self.assertEqual(line.text, add_line_prefix('w+', errors[2]))
+self.assertEqual(line.text, add_line_prefix('w+', boards34, errors[2]))
 self.assertEqual(line.colour, col.MAGENTA)
 
 # Fifth commit
@@ -302,11 +312,11 @@ class TestBuild(unittest.TestCase):
 expect = [expect[0]] + expect[2:]
 expect = '\n'.join(expect)
 line = next(lines)
-self.assertEqual(line.text, add_line_prefix('+', expect))
+self.assertEqual(line.text, add_line_prefix('+', boards4, expect))
 self.assertEqual(line.colour, col.RED)
 
 line = next(lines)
-self.assertEqual(line.text, add_line_prefix('w-', errors[2]))
+self.assertEqual(line.text, add_line_prefix('w-', boards34, errors[2]))
 self.assertEqual(line.colour, col.CYAN)
 
 # Sixth commit
@@ -319,11 +329,11 @@ class TestBuild(unittest.TestCase):
 expect = [expect[0]] + expect[2:]
 expect = '\n'.join(expect)
 line = next(lines)
-self.assertEqual(line.text, add_line_prefix('-', expect))
+self.assertEqual(line.text, add_line_prefix('-', boards4, expect))
 self.assertEqual(line.colour, col.GREEN)
 
 line = next(lines)
-self.assertEqual(line.text, add_line_prefix('w-', errors[0]))
+self.assertEqual(line.text, add_line_prefix('w-', boards4, errors[0]))
 self.assertEqual(line.colour, col.CYAN)
 
 # Seventh commit
@@ -335,14 +345,14 @@ class TestBuild(unittest.TestCase):
 expect = expect_str[3:8] + [expect_str[-1]]
 expect = '\n'.join(expect)
 line = next(lines)
-self.assertEqual(line.text, add_line_prefix('+', expect))
+self.assertEqual(line.text, 

[PATCH v2 09/28] buildman: Use an object to hold error lines

2020-04-09 Thread Simon Glass
At present the string for each error line is created in _CalcErrorDelta()
and used to create the summary output. This is inflexible since all the
information (error/warning character, error line, list of boards with that
error line) is munged together in a string.

Create an object to hold this information and only convert it to a string
when printing the actual output.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 69 +--
 1 file changed, 52 insertions(+), 17 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 01d8bf46e45..238b711dec4 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -24,7 +24,6 @@ import terminal
 from terminal import Print
 import toolchain
 
-
 """
 Theory of Operation
 
@@ -91,6 +90,15 @@ u-boot/ source directory
 .git/   repository
 """
 
+"""Holds information about a particular error line we are outputing
+
+   char: Character representation: '+': error, '-': fixed error, 'w+': warning,
+   'w-' = fixed warning
+   boards: List of Board objects which have line in the error/warning output
+   errline: The text of the error line
+"""
+ErrLine = collections.namedtuple('ErrLine', 'char,boards,errline')
+
 # Possible build outcomes
 OUTCOME_OK, OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN = list(range(4))
 
@@ -1128,32 +1136,52 @@ class Builder:
 
 Args:
 line: Error line to search for
+line_boards: boards to search, each a Board
 Return:
-String containing a list of boards with that error line, or
-'' if the user has not requested such a list
+List of boards with that error line, or [] if the user has not
+requested such a list
 """
+boards = []
+board_set = set()
 if self._list_error_boards:
-names = []
 for board in line_boards[line]:
-if not board.target in names:
-names.append(board.target)
-names_str = '(%s) ' % ','.join(names)
-else:
-names_str = ''
-return names_str
+if not board in board_set:
+boards.append(board)
+board_set.add(board)
+return boards
 
 def _CalcErrorDelta(base_lines, base_line_boards, lines, line_boards,
 char):
+"""Calculate the required output based on changes in errors
+
+Args:
+base_lines: List of errors/warnings for previous commit
+base_line_boards: Dict keyed by error line, containing a list
+of the Board objects with that error in the previous commit
+lines: List of errors/warning for this commit, each a str
+line_boards: Dict keyed by error line, containing a list
+of the Board objects with that error in this commit
+char: Character representing error ('') or warning ('w'). The
+broken ('+') or fixed ('-') characters are added in this
+function
+
+Returns:
+Tuple
+List of ErrLine objects for 'better' lines
+List of ErrLine objects for 'worse' lines
+"""
 better_lines = []
 worse_lines = []
 for line in lines:
 if line not in base_lines:
-worse_lines.append(char + '+' +
-_BoardList(line, line_boards) + line)
+errline = ErrLine(char + '+', _BoardList(line, 
line_boards),
+  line)
+worse_lines.append(errline)
 for line in base_lines:
 if line not in lines:
-better_lines.append(char + '-' +
-_BoardList(line, base_line_boards) + line)
+errline = ErrLine(char + '-',
+  _BoardList(line, base_line_boards), line)
+better_lines.append(errline)
 return better_lines, worse_lines
 
 def _CalcConfig(delta, name, config):
@@ -1215,12 +1243,19 @@ class Builder:
 Also increments self._error_lines if err_lines not empty
 
 Args:
-err_lines: List of strings, each an error or warning line,
-possibly including a list of boards with that error/warning
+err_lines: List of ErrLine objects, each an error or warning
+line, possibly including a list of boards with that
+error/warning
 colour: Colour to use for output
 """
 if err_lines:
-

[PATCH v2 10/28] buildman: Show the list of boards in magenta

2020-04-09 Thread Simon Glass
It is quite hard to see the list of board for each error line since the
colour is the same as the actual error line. Show the board list in
magenta so that it is easier to distinguish them.

There is no point in checking the colour of the overall line, since there
are now multiple colours. So drop those tests.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 15 ++---
 tools/buildman/test.py| 70 ++-
 2 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 238b711dec4..7cbb1a6f628 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -1249,13 +1249,20 @@ class Builder:
 colour: Colour to use for output
 """
 if err_lines:
-out = []
+out_list = []
 for line in err_lines:
 boards = ''
 names = [board.target for board in line.boards]
-boards = '(%s) ' % ','.join(names) if names else ''
-out.append('%s%s%s' % (line.char, boards, line.errline))
-Print('\n'.join(out), colour=colour)
+board_str = ','.join(names) if names else ''
+if board_str:
+out = self.col.Color(colour, line.char + '(')
+out += self.col.Color(self.col.MAGENTA, board_str,
+  bright=False)
+out += self.col.Color(colour, ') %s' % line.errline)
+else:
+out = self.col.Color(colour, line.char + line.errline)
+out_list.append(out)
+Print('\n'.join(out_list))
 self._error_lines += 1
 
 
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index c494a158be6..a64372dee36 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -222,7 +222,7 @@ class TestBuild(unittest.TestCase):
 list_error_boards: Adjust the check for output produced with the
--list-error-boards flag
 """
-def add_line_prefix(prefix, boards, error_str):
+def add_line_prefix(prefix, boards, error_str, colour):
 """Add a prefix to each line of a string
 
 The training \n in error_str is removed before processing
@@ -230,14 +230,23 @@ class TestBuild(unittest.TestCase):
 Args:
 prefix: String prefix to add
 error_str: Error string containing the lines
+colour: Expected colour for the line. Note that the board list,
+if present, always appears in magenta
 
 Returns:
 New string where each line has the prefix added
 """
-if boards:
-boards = '(%s) ' % boards
 lines = error_str.strip().splitlines()
-new_lines = [prefix + boards + line for line in lines]
+new_lines = []
+for line in lines:
+if boards:
+expect = self._col.Color(colour, prefix + '(')
+expect += self._col.Color(self._col.MAGENTA, boards,
+  bright=False)
+expect += self._col.Color(colour, ') %s' % line)
+else:
+expect = self._col.Color(colour, prefix + line)
+new_lines.append(expect)
 return '\n'.join(new_lines)
 
 boards1234 = 'board1,board2,board3,board4' if list_error_boards else ''
@@ -260,11 +269,8 @@ class TestBuild(unittest.TestCase):
outcome=OUTCOME_WARN)
 
 # Second commit: The warnings should be listed
-line = next(lines)
-
-self.assertEqual(line.text,
- add_line_prefix('w+', boards1234, errors[0]))
-self.assertEqual(line.colour, col.YELLOW)
+self.assertEqual(next(lines).text,
+add_line_prefix('w+', boards1234, errors[0], col.YELLOW))
 
 # Third commit: Still fails
 self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
@@ -275,9 +281,8 @@ class TestBuild(unittest.TestCase):
 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
 
 # Expect a compiler error
-line = next(lines)
-self.assertEqual(line.text, add_line_prefix('+', boards234, errors[1]))
-self.assertEqual(line.colour, col.RED)
+self.assertEqual(next(lines).text,
+ add_line_prefix('+', boards234, errors[1], col.RED))
 
 # Fourth commit: Compile errors are fixed, just have warning for board3
 self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
@@ -293,13 +298,11 @@ class TestBuild(unittest.TestCase):
outcome=OUTCOME_WARN)
 
 # 

[PATCH v2 06/28] buildman: Add a test helper for creating a line prefix

2020-04-09 Thread Simon Glass
The split/join code is repeated in a lot of places. Add a function to
handle this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/test.py | 51 +-
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index c9c7a05ca61..1377035fbb4 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -220,6 +220,22 @@ class TestBuild(unittest.TestCase):
 Args:
 lines: Iterator containing the lines returned from the summary
 """
+def add_line_prefix(prefix, error_str):
+"""Add a prefix to each line of a string
+
+The training \n in error_str is removed before processing
+
+Args:
+prefix: String prefix to add
+error_str: Error string containing the lines
+
+Returns:
+New string where each line has the prefix added
+"""
+lines = error_str.strip().splitlines()
+new_lines = [prefix + line for line in lines]
+return '\n'.join(new_lines)
+
 # Upstream commit: no errors
 self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
 
@@ -236,8 +252,8 @@ class TestBuild(unittest.TestCase):
 
 # Second commit: The warnings should be listed
 line = next(lines)
-self.assertEqual(line.text, 'w+%s' %
-errors[0].rstrip().replace('\n', '\nw+'))
+
+self.assertEqual(line.text, add_line_prefix('w+', errors[0]))
 self.assertEqual(line.colour, col.MAGENTA)
 
 # Third commit: Still fails
@@ -250,8 +266,7 @@ class TestBuild(unittest.TestCase):
 
 # Expect a compiler error
 line = next(lines)
-self.assertEqual(line.text, '+%s' %
-errors[1].rstrip().replace('\n', '\n+'))
+self.assertEqual(line.text, add_line_prefix('+', errors[1]))
 self.assertEqual(line.colour, col.RED)
 
 # Fourth commit: Compile errors are fixed, just have warning for board3
@@ -269,13 +284,11 @@ class TestBuild(unittest.TestCase):
 
 # Compile error fixed
 line = next(lines)
-self.assertEqual(line.text, '-%s' %
-errors[1].rstrip().replace('\n', '\n-'))
+self.assertEqual(line.text, add_line_prefix('-', errors[1]))
 self.assertEqual(line.colour, col.GREEN)
 
 line = next(lines)
-self.assertEqual(line.text, 'w+%s' %
-errors[2].rstrip().replace('\n', '\nw+'))
+self.assertEqual(line.text, add_line_prefix('w+', errors[2]))
 self.assertEqual(line.colour, col.MAGENTA)
 
 # Fifth commit
@@ -287,14 +300,13 @@ class TestBuild(unittest.TestCase):
 # The second line of errors[3] is a duplicate, so buildman will drop it
 expect = errors[3].rstrip().split('\n')
 expect = [expect[0]] + expect[2:]
+expect = '\n'.join(expect)
 line = next(lines)
-self.assertEqual(line.text, '+%s' %
-'\n'.join(expect).replace('\n', '\n+'))
+self.assertEqual(line.text, add_line_prefix('+', expect))
 self.assertEqual(line.colour, col.RED)
 
 line = next(lines)
-self.assertEqual(line.text, 'w-%s' %
-errors[2].rstrip().replace('\n', '\nw-'))
+self.assertEqual(line.text, add_line_prefix('w-', errors[2]))
 self.assertEqual(line.colour, col.CYAN)
 
 # Sixth commit
@@ -305,14 +317,13 @@ class TestBuild(unittest.TestCase):
 # The second line of errors[3] is a duplicate, so buildman will drop it
 expect = errors[3].rstrip().split('\n')
 expect = [expect[0]] + expect[2:]
+expect = '\n'.join(expect)
 line = next(lines)
-self.assertEqual(line.text, '-%s' %
-'\n'.join(expect).replace('\n', '\n-'))
+self.assertEqual(line.text, add_line_prefix('-', expect))
 self.assertEqual(line.colour, col.GREEN)
 
 line = next(lines)
-self.assertEqual(line.text, 'w-%s' %
-errors[0].rstrip().replace('\n', '\nw-'))
+self.assertEqual(line.text, add_line_prefix('w-', errors[0]))
 self.assertEqual(line.colour, col.CYAN)
 
 # Seventh commit
@@ -322,16 +333,16 @@ class TestBuild(unittest.TestCase):
 # Pick out the correct error lines
 expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
 expect = expect_str[3:8] + [expect_str[-1]]
+expect = '\n'.join(expect)
 line = next(lines)
-self.assertEqual(line.text, '+%s' %
-'\n'.join(expect).replace('\n', '\n+'))
+self.assertEqual(line.text, add_line_prefix('+', expect))
 self.assertEqual(line.colour, col.RED)
 
 # Now the warnings lines
 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
+expect = '\n'.join(expect)
 line = next(lines)
-   

[PATCH v2 03/28] buildman: Use an iterator to check test output

2020-04-09 Thread Simon Glass
Rather than using the absolute array index, use an interator to work
through the expected output lines. This is easier to follow.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/test.py | 94 +++---
 1 file changed, 52 insertions(+), 42 deletions(-)

diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index 8e2b07fb438..84dd608127e 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -204,41 +204,44 @@ class TestBuild(unittest.TestCase):
 build.SetDisplayOptions(show_errors=True);
 build.ShowSummary(self.commits, board_selected)
 #terminal.EchoPrintTestLines()
-lines = terminal.GetPrintTestLines()
+lines = iter(terminal.GetPrintTestLines())
 
 # Upstream commit: no errors
-self.assertEqual(lines[0].text, '01: %s' % commits[0][1])
+self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
 
 # Second commit: all archs should fail with warnings
-self.assertEqual(lines[1].text, '02: %s' % commits[1][1])
+self.assertEqual(next(lines).text, '02: %s' % commits[1][1])
 
 col = terminal.Color()
-self.assertSummary(lines[2].text, 'arm', 'w+', ['board1'],
-   outcome=OUTCOME_WARN)
-self.assertSummary(lines[3].text, 'powerpc', 'w+', ['board2', 
'board3'],
+self.assertSummary(next(lines).text, 'arm', 'w+', ['board1'],
outcome=OUTCOME_WARN)
-self.assertSummary(lines[4].text, 'sandbox', 'w+', ['board4'],
+self.assertSummary(next(lines).text, 'powerpc', 'w+',
+   ['board2', 'board3'], outcome=OUTCOME_WARN)
+self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
outcome=OUTCOME_WARN)
 
 # Second commit: The warnings should be listed
-self.assertEqual(lines[5].text, 'w+%s' %
+line = next(lines)
+self.assertEqual(line.text, 'w+%s' %
 errors[0].rstrip().replace('\n', '\nw+'))
-self.assertEqual(lines[5].colour, col.MAGENTA)
+self.assertEqual(line.colour, col.MAGENTA)
 
 # Third commit: Still fails
-self.assertEqual(lines[6].text, '03: %s' % commits[2][1])
-self.assertSummary(lines[7].text, 'arm', '', ['board1'],
+self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
+self.assertSummary(next(lines).text, 'arm', '', ['board1'],
outcome=OUTCOME_OK)
-self.assertSummary(lines[8].text, 'powerpc', '+', ['board2', 'board3'])
-self.assertSummary(lines[9].text, 'sandbox', '+', ['board4'])
+self.assertSummary(next(lines).text, 'powerpc', '+',
+   ['board2', 'board3'])
+self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
 
 # Expect a compiler error
-self.assertEqual(lines[10].text, '+%s' %
+line = next(lines)
+self.assertEqual(line.text, '+%s' %
 errors[1].rstrip().replace('\n', '\n+'))
-self.assertEqual(lines[10].colour, col.RED)
+self.assertEqual(line.colour, col.RED)
 
 # Fourth commit: Compile errors are fixed, just have warning for board3
-self.assertEqual(lines[11].text, '04: %s' % commits[3][1])
+self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
 expect = '%10s: ' % 'powerpc'
 expect += ' ' + col.Color(col.GREEN, '')
 expect += '  '
@@ -246,70 +249,77 @@ class TestBuild(unittest.TestCase):
 expect += ' ' + col.Color(col.YELLOW, 'w+')
 expect += '  '
 expect += col.Color(col.YELLOW, ' %s' % 'board3')
-self.assertEqual(lines[12].text, expect)
-self.assertSummary(lines[13].text, 'sandbox', 'w+', ['board4'],
+self.assertEqual(next(lines).text, expect)
+self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
outcome=OUTCOME_WARN)
 
 # Compile error fixed
-self.assertEqual(lines[14].text, '-%s' %
+line = next(lines)
+self.assertEqual(line.text, '-%s' %
 errors[1].rstrip().replace('\n', '\n-'))
-self.assertEqual(lines[14].colour, col.GREEN)
+self.assertEqual(line.colour, col.GREEN)
 
-self.assertEqual(lines[15].text, 'w+%s' %
+line = next(lines)
+self.assertEqual(line.text, 'w+%s' %
 errors[2].rstrip().replace('\n', '\nw+'))
-self.assertEqual(lines[15].colour, col.MAGENTA)
+self.assertEqual(line.colour, col.MAGENTA)
 
 # Fifth commit
-self.assertEqual(lines[16].text, '05: %s' % commits[4][1])
-self.assertSummary(lines[17].text, 'powerpc', '', ['board3'],
+self.assertEqual(next(lines).text, '05: %s' % commits[4][1])
+self.assertSummary(next(lines).text, 'powerpc', '', ['board3'],

[PATCH v2 05/28] buildman: Split out testOutput() into separate functions

2020-04-09 Thread Simon Glass
We want to add a few more tests similar to testOutput(). Split its logic
into a function which runs buildman to get the output and another which
checks the output. This will make it easier to reuse the code.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/test.py | 34 --
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index b2f7e1edf76..c9c7a05ca61 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -178,10 +178,17 @@ class TestBuild(unittest.TestCase):
 expect += col.Color(expected_colour, ' %s' % board)
 self.assertEqual(text, expect)
 
-def testOutput(self):
-"""Test basic builder operation and output
+def _SetupTest(self, echo_lines=False, **kwdisplay_args):
+"""Set up the test by running a build and summary
 
-This does a line-by-line verification of the summary output.
+Args:
+echo_lines: True to echo lines to the terminal to aid test
+development
+kwdisplay_args: Dict of arguemnts to pass to
+Builder.SetDisplayOptions()
+
+Returns:
+Iterator containing the output lines, each a PrintLine() object
 """
 build = builder.Builder(self.toolchains, self.base_dir, None, 1, 2,
 checkout=False, show_unknown=False)
@@ -201,11 +208,18 @@ class TestBuild(unittest.TestCase):
 # We should get two starting messages, then an update for every commit
 # built.
 self.assertEqual(count, len(commits) * len(boards) + 2)
-build.SetDisplayOptions(show_errors=True);
+build.SetDisplayOptions(**kwdisplay_args);
 build.ShowSummary(self.commits, board_selected)
-#terminal.EchoPrintTestLines()
-lines = iter(terminal.GetPrintTestLines())
+if echo_lines:
+terminal.EchoPrintTestLines()
+return iter(terminal.GetPrintTestLines())
+
+def _CheckOutput(self, lines):
+"""Check for expected output from the build summary
 
+Args:
+lines: Iterator containing the lines returned from the summary
+"""
 # Upstream commit: no errors
 self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
 
@@ -320,6 +334,14 @@ class TestBuild(unittest.TestCase):
 '\n'.join(expect).replace('\n', '\nw+'))
 self.assertEqual(line.colour, col.MAGENTA)
 
+def testOutput(self):
+"""Test basic builder operation and output
+
+This does a line-by-line verification of the summary output.
+"""
+lines = self._SetupTest(show_errors=True)
+self._CheckOutput(lines)
+
 def _testGit(self):
 """Test basic builder operation by building a branch"""
 options = Options()
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 02/28] buildman: Add test coverage for error/warning colour

2020-04-09 Thread Simon Glass
Buildman should output the right colours for each error/warning line. Some
of these checks are missing. Add them.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/test.py | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index 2aaedf44ac7..8e2b07fb438 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -235,6 +235,7 @@ class TestBuild(unittest.TestCase):
 # Expect a compiler error
 self.assertEqual(lines[10].text, '+%s' %
 errors[1].rstrip().replace('\n', '\n+'))
+self.assertEqual(lines[10].colour, col.RED)
 
 # Fourth commit: Compile errors are fixed, just have warning for board3
 self.assertEqual(lines[11].text, '04: %s' % commits[3][1])
@@ -269,9 +270,11 @@ class TestBuild(unittest.TestCase):
 expect = [expect[0]] + expect[2:]
 self.assertEqual(lines[19].text, '+%s' %
 '\n'.join(expect).replace('\n', '\n+'))
+self.assertEqual(lines[19].colour, col.RED)
 
 self.assertEqual(lines[20].text, 'w-%s' %
 errors[2].rstrip().replace('\n', '\nw-'))
+self.assertEqual(lines[20].colour, col.CYAN)
 
 # Sixth commit
 self.assertEqual(lines[21].text, '06: %s' % commits[5][1])
@@ -283,9 +286,11 @@ class TestBuild(unittest.TestCase):
 expect = [expect[0]] + expect[2:]
 self.assertEqual(lines[23].text, '-%s' %
 '\n'.join(expect).replace('\n', '\n-'))
+self.assertEqual(lines[23].colour, col.GREEN)
 
 self.assertEqual(lines[24].text, 'w-%s' %
 errors[0].rstrip().replace('\n', '\nw-'))
+self.assertEqual(lines[24].colour, col.CYAN)
 
 # Seventh commit
 self.assertEqual(lines[25].text, '07: %s' % commits[6][1])
@@ -296,11 +301,13 @@ class TestBuild(unittest.TestCase):
 expect = expect_str[3:8] + [expect_str[-1]]
 self.assertEqual(lines[27].text, '+%s' %
 '\n'.join(expect).replace('\n', '\n+'))
+self.assertEqual(lines[27].colour, col.RED)
 
 # Now the warnings lines
 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
 self.assertEqual(lines[28].text, 'w+%s' %
 '\n'.join(expect).replace('\n', '\nw+'))
+self.assertEqual(lines[28].colour, col.MAGENTA)
 
 self.assertEqual(len(lines), 29)
 shutil.rmtree(base_dir)
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 08/28] buildman: Use yellow consistently for warning lines

2020-04-09 Thread Simon Glass
At present warnings are shown in yellow in the summary (-s) but magenta in
the detail listing (-e). Use yellow in both.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 2 +-
 tools/buildman/test.py| 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 621147696ed..01d8bf46e45 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -1279,7 +1279,7 @@ class Builder:
 _OutputErrLines(better_err, colour=self.col.GREEN)
 _OutputErrLines(worse_err, colour=self.col.RED)
 _OutputErrLines(better_warn, colour=self.col.CYAN)
-_OutputErrLines(worse_warn, colour=self.col.MAGENTA)
+_OutputErrLines(worse_warn, colour=self.col.YELLOW)
 
 if show_sizes:
 self.PrintSizeSummary(board_selected, board_dict, show_detail,
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index b1435b45c03..c494a158be6 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -264,7 +264,7 @@ class TestBuild(unittest.TestCase):
 
 self.assertEqual(line.text,
  add_line_prefix('w+', boards1234, errors[0]))
-self.assertEqual(line.colour, col.MAGENTA)
+self.assertEqual(line.colour, col.YELLOW)
 
 # Third commit: Still fails
 self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
@@ -299,7 +299,7 @@ class TestBuild(unittest.TestCase):
 
 line = next(lines)
 self.assertEqual(line.text, add_line_prefix('w+', boards34, errors[2]))
-self.assertEqual(line.colour, col.MAGENTA)
+self.assertEqual(line.colour, col.YELLOW)
 
 # Fifth commit
 self.assertEqual(next(lines).text, '05: %s' % commits[4][1])
@@ -353,7 +353,7 @@ class TestBuild(unittest.TestCase):
 expect = '\n'.join(expect)
 line = next(lines)
 self.assertEqual(line.text, add_line_prefix('w+', boards4, expect))
-self.assertEqual(line.colour, col.MAGENTA)
+self.assertEqual(line.colour, col.YELLOW)
 
 def testOutput(self):
 """Test basic builder operation and output
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 04/28] buildman: Create temp directory in test setup

2020-04-09 Thread Simon Glass
Rather than having a few tests handle this themselves, create the
temporary directory in the setUp() method and remove it in tearDown().
This will make it easier to add more tests.

Only testOutput and testGit() actually need it, but it doesn't add to the
test time noticeably to do this for all tests in this file.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/test.py | 26 ++
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index 84dd608127e..b2f7e1edf76 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -143,9 +143,14 @@ class TestBuild(unittest.TestCase):
 terminal.SetPrintTestMode()
 self._col = terminal.Color()
 
-def Make(self, commit, brd, stage, *args, **kwargs):
-global base_dir
+self.base_dir = tempfile.mkdtemp()
+if not os.path.isdir(self.base_dir):
+os.mkdir(self.base_dir)
+
+def tearDown(self):
+shutil.rmtree(self.base_dir)
 
+def Make(self, commit, brd, stage, *args, **kwargs):
 result = command.CommandResult()
 boardnum = int(brd.target[-1])
 result.return_code = 0
@@ -156,7 +161,7 @@ class TestBuild(unittest.TestCase):
 boardnum == 4 and commit.sequence == 6):
 result.return_code = commit.return_code
 result.stderr = (''.join(commit.error_list)
-% {'basedir' : base_dir + '/.bm-work/00/'})
+% {'basedir' : self.base_dir + '/.bm-work/00/'})
 
 result.combined = result.stdout + result.stderr
 return result
@@ -178,12 +183,7 @@ class TestBuild(unittest.TestCase):
 
 This does a line-by-line verification of the summary output.
 """
-global base_dir
-
-base_dir = tempfile.mkdtemp()
-if not os.path.isdir(base_dir):
-os.mkdir(base_dir)
-build = builder.Builder(self.toolchains, base_dir, None, 1, 2,
+build = builder.Builder(self.toolchains, self.base_dir, None, 1, 2,
 checkout=False, show_unknown=False)
 build.do_make = self.Make
 board_selected = self.boards.GetSelectedDict()
@@ -320,19 +320,14 @@ class TestBuild(unittest.TestCase):
 '\n'.join(expect).replace('\n', '\nw+'))
 self.assertEqual(line.colour, col.MAGENTA)
 
-shutil.rmtree(base_dir)
-
 def _testGit(self):
 """Test basic builder operation by building a branch"""
-base_dir = tempfile.mkdtemp()
-if not os.path.isdir(base_dir):
-os.mkdir(base_dir)
 options = Options()
 options.git = os.getcwd()
 options.summary = False
 options.jobs = None
 options.dry_run = False
-#options.git = os.path.join(base_dir, 'repo')
+#options.git = os.path.join(self.base_dir, 'repo')
 options.branch = 'test-buildman'
 options.force_build = False
 options.list_tool_chains = False
@@ -345,7 +340,6 @@ class TestBuild(unittest.TestCase):
 options.keep_outputs = False
 args = ['tegra20']
 control.DoBuildman(options, args)
-shutil.rmtree(base_dir)
 
 def testBoardSingle(self):
 """Test single board selection"""
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 01/28] buildman: Refactor error-line output int a function

2020-04-09 Thread Simon Glass
Reduce the amount of repeated code by creating an _OutputErrLines()
function to hold this code.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/buildman/builder.py | 32 +++-
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 70c55c588a7..621147696ed 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -1209,6 +1209,20 @@ class Builder:
 col = self.col.YELLOW
 Print('   ' + line, newline=True, colour=col)
 
+def _OutputErrLines(err_lines, colour):
+"""Output the line of error/warning lines, if not empty
+
+Also increments self._error_lines if err_lines not empty
+
+Args:
+err_lines: List of strings, each an error or warning line,
+possibly including a list of boards with that error/warning
+colour: Colour to use for output
+"""
+if err_lines:
+Print('\n'.join(err_lines), colour=colour)
+self._error_lines += 1
+
 
 ok_boards = []  # List of boards fixed since last commit
 warn_boards = []# List of boards with warnings since last commit
@@ -1239,7 +1253,7 @@ class Builder:
 else:
 new_boards.append(target)
 
-# Get a list of errors that have appeared, and disappeared
+# Get a list of errors and warnings that have appeared, and disappeared
 better_err, worse_err = _CalcErrorDelta(self._base_err_lines,
 self._base_err_line_boards, err_lines, err_line_boards, '')
 better_warn, worse_warn = _CalcErrorDelta(self._base_warn_lines,
@@ -1262,18 +1276,10 @@ class Builder:
 for arch, target_list in arch_list.items():
 Print('%10s: %s' % (arch, target_list))
 self._error_lines += 1
-if better_err:
-Print('\n'.join(better_err), colour=self.col.GREEN)
-self._error_lines += 1
-if worse_err:
-Print('\n'.join(worse_err), colour=self.col.RED)
-self._error_lines += 1
-if better_warn:
-Print('\n'.join(better_warn), colour=self.col.CYAN)
-self._error_lines += 1
-if worse_warn:
-Print('\n'.join(worse_warn), colour=self.col.MAGENTA)
-self._error_lines += 1
+_OutputErrLines(better_err, colour=self.col.GREEN)
+_OutputErrLines(worse_err, colour=self.col.RED)
+_OutputErrLines(better_warn, colour=self.col.CYAN)
+_OutputErrLines(worse_warn, colour=self.col.MAGENTA)
 
 if show_sizes:
 self.PrintSizeSummary(board_selected, board_dict, show_detail,
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 00/28] buildman: Improve summary output

2020-04-09 Thread Simon Glass
This series makes the output produced by buildman a little more useful and
easier to read:

- when using -l to see which errors relate to which board, it shows the
   boards in a different colour so they can be distinguished from the
   errors
- uses yellow consistently for warning lines
- shows the number of remaining builds
- shows a summary when the build completes, including the time taken
- adds a few messages to indicate what is happening while starting up

It also refactors a few tests a little to make them easier to follow,
makes -I the default and improves the documentation a little.

Finally it changes the exit codes to something acceptable to git bisect.

Changes in v2:
- Move the 'boards' variables to the start of _CheckOutput()
- Add new patch to use spaces in the board list
- Drop use of temporary 'line' variable
- Add new patch to ignore migration warnings
- Add patch to udpate TODO items
- Add new patch to change the exit codes

Simon Glass (28):
  buildman: Refactor error-line output int a function
  buildman: Add test coverage for error/warning colour
  buildman: Use an iterator to check test output
  buildman: Create temp directory in test setup
  buildman: Split out testOutput() into separate functions
  buildman: Add a test helper for creating a line prefix
  buildman: Test the output with --list-error-boards
  buildman: Use yellow consistently for warning lines
  buildman: Use an object to hold error lines
  buildman: Show the list of boards in magenta
  buildman: Use spaces in the board list
  patman: Update flushing Print() for Python 3
  patman: Support erasing a previously unfinished text line
  patman: Support limiting output to a single line
  buildman: Drop the line-clearing code in Builder
  buildman: Show a message when fetching a repo
  buildman: Drop unused output code
  buildman: Show the number of builds remaining
  buildman: Limit the length of progress messages
  buildman: Show a summary of the build result
  buildman: Update the 'theory of operation' a little
  buildman: Add the abbreviation for --boards
  buildman: Update workflow documentation with more detail
  buildman: Make -I the default
  buildman: Add an option to ignore device-tree warnings
  buildman: Add an option to ignore migration warnings
  buildman: Update the TODO items
  buildman: Change the exit codes

 tools/buildman/README   | 171 +++---
 tools/buildman/builder.py   | 216 ++
 tools/buildman/builderthread.py |   6 +-
 tools/buildman/cmdline.py   |  11 +-
 tools/buildman/control.py   |  22 ++-
 tools/buildman/func_test.py |  28 ++-
 tools/buildman/test.py  | 305 +++-
 tools/patman/patman.py  |   2 +-
 tools/patman/terminal.py| 110 +++-
 9 files changed, 614 insertions(+), 257 deletions(-)

-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 17/22] common: Drop linux/bug.h from common header

2020-04-09 Thread Simon Glass
Move this uncommon header out of the common header.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/arm/mach-bcm283x/include/mach/timer.h   | 1 +
 arch/arm/mach-imx/cmd_nandbcb.c  | 1 +
 arch/arm/mach-tegra/ivc.c| 1 +
 arch/arm/mach-uniphier/boot-device/boot-device.c | 1 +
 arch/mips/lib/cache.c| 1 +
 board/armltd/integrator/pci.c| 1 +
 board/sifive/fu540/fu540.c   | 1 +
 cmd/jffs2.c  | 1 +
 common/iotrace.c | 1 +
 drivers/clk/clk-divider.c| 1 +
 drivers/clk/clk-hsdk-cgu.c   | 1 +
 drivers/clk/clk-uclass.c | 1 +
 drivers/clk/clk_pic32.c  | 1 +
 drivers/clk/uniphier/clk-uniphier-core.c | 1 +
 drivers/core/of_access.c | 1 +
 drivers/core/of_addr.c   | 1 +
 drivers/ddr/fsl/ddr4_dimm_params.c   | 1 +
 drivers/gpio/adi_gpio2.c | 1 +
 drivers/gpio/sh_pfc.c| 1 +
 drivers/mmc/bcm2835_sdhost.c | 1 +
 drivers/mmc/sdhci-cadence.c  | 1 +
 drivers/mtd/mtdconcat.c  | 1 +
 drivers/mtd/mtdcore.c| 1 +
 drivers/mtd/mtdpart.c| 1 +
 drivers/mtd/nand/raw/atmel_nand.c| 1 +
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 1 +
 drivers/mtd/nand/raw/lpc32xx_nand_slc.c  | 1 +
 drivers/mtd/nand/raw/nand_base.c | 1 +
 drivers/mtd/nand/raw/nand_bbt.c  | 1 +
 drivers/mtd/nand/raw/pxa3xx_nand.c   | 1 +
 drivers/mtd/nand/raw/tegra_nand.c| 1 +
 drivers/mtd/nand/spi/core.c  | 1 +
 drivers/mtd/nand/spi/macronix.c  | 1 +
 drivers/mtd/ubi/attach.c | 1 +
 drivers/mtd/ubi/fastmap.c| 1 +
 drivers/mtd/ubi/vtbl.c   | 1 +
 drivers/mtd/ubispl/ubispl.c  | 1 +
 drivers/net/ep93xx_eth.c | 1 +
 drivers/net/fsl-mc/dpio/qbman_portal.c   | 1 +
 drivers/net/fsl-mc/dpio/qbman_private.h  | 1 +
 drivers/net/fsl-mc/dpio/qbman_sys.h  | 1 +
 drivers/net/fsl_enetc.c  | 1 +
 drivers/net/ldpaa_eth/ldpaa_eth.c| 1 +
 drivers/net/mvneta.c | 1 +
 drivers/net/mvpp2.c  | 1 +
 drivers/pinctrl/pinctrl-sti.c| 1 +
 drivers/pinctrl/renesas/pfc.c| 1 +
 drivers/pinctrl/renesas/sh_pfc.h | 1 +
 drivers/pinctrl/uniphier/pinctrl-uniphier-core.c | 1 +
 drivers/pinctrl/uniphier/pinctrl-uniphier.h  | 1 +
 drivers/smem/msm_smem.c  | 1 +
 drivers/spi/renesas_rpc_spi.c| 1 +
 drivers/usb/cdns3/core.c | 1 +
 drivers/usb/dwc3/core.c  | 1 +
 drivers/usb/dwc3/ep0.c   | 1 +
 drivers/usb/gadget/at91_udc.c| 1 +
 drivers/usb/gadget/composite.c   | 1 +
 drivers/usb/gadget/dwc2_udc_otg.c| 1 +
 drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c   | 1 +
 drivers/usb/gadget/f_mass_storage.c  | 1 +
 drivers/usb/gadget/pxa25x_udc.c  | 1 +
 drivers/usb/host/xhci-mem.c  | 1 +
 drivers/usb/host/xhci-ring.c | 1 +
 drivers/usb/host/xhci.c  | 1 +
 drivers/usb/musb-new/am35x.c | 1 +
 drivers/usb/musb-new/musb_core.c | 1 +
 drivers/usb/musb-new/musb_gadget.c   | 1 +
 drivers/usb/musb-new/musb_host.c | 1 +
 drivers/video/atmel_hlcdfb.c | 1 +
 drivers/virtio/virtio-uclass.c   | 1 +
 drivers/virtio/virtio_mmio.c | 1 +
 drivers/virtio/virtio_pci_legacy.c   | 1 +
 drivers/virtio/virtio_pci_modern.c   | 1 +
 drivers/virtio/virtio_ring.c | 1 +
 drivers/virtio/virtio_sandbox.c  | 1 +
 env/env.c| 1 +
 fs/ubifs/tnc.c   | 1 +
 fs/yaffs2/yaffs_mtdif2.c | 1 +
 fs/yaffs2/yportenv.h | 1 +
 include/common.h | 1 -
 include/linux/soc/ti/cppi5.h | 1 +
 include/virtio.h | 1 +
 lib/crypto/asymmetric_type.c | 1 +
 lib/crypto/public_key.c  | 1 +
 net/eth_legacy.c | 1 +
 85 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-bcm283x/include/mach/timer.h 

[PATCH v2 21/22] Use __ASSEMBLY__ as the assembly macros

2020-04-09 Thread Simon Glass
Some places use __ASSEMBLER__ instead which does not work since the
Makefile does not define it. Fix them.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to fix occurances of __ASSEMBLER__

 arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h | 2 +-
 arch/arm/include/asm/arch-mx27/regs-rtc.h  | 2 +-
 arch/arm/include/asm/arch-mx5/imx-regs.h   | 2 +-
 arch/arm/include/asm/arch-mx6/imx-regs.h   | 2 +-
 arch/arm/include/asm/arch-mx7/imx-regs.h   | 2 +-
 arch/arm/include/asm/arch-s32v234/imx-regs.h   | 2 +-
 arch/arm/include/asm/arch-vf610/imx-regs.h | 2 +-
 arch/arm/mach-socfpga/include/mach/clock_manager.h | 2 +-
 arch/arm/mach-socfpga/include/mach/clock_manager_arria10.h | 4 ++--
 arch/arm/mach-socfpga/include/mach/clock_manager_gen5.h| 4 ++--
 arch/arm/mach-socfpga/include/mach/sdram_arria10.h | 2 +-
 arch/arm/mach-stm32mp/include/mach/stm32.h | 2 +-
 arch/x86/include/asm/mtrr.h| 2 +-
 arch/x86/include/asm/sipi.h| 4 ++--
 include/atf_common.h   | 2 +-
 include/elf.h  | 4 ++--
 16 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h 
b/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h
index 299201b1570..5d8a2d49a1d 100644
--- a/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h
+++ b/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h
@@ -584,5 +584,5 @@ struct ccsr_serdes {
u8 res5[0x19fc - 0xa00];
 };
 
-#endif /*__ASSEMBLY__*/
+#endif /*__ASSEMBLY__ */
 #endif /* __ARCH_FSL_LSCH3_IMMAP_H_ */
diff --git a/arch/arm/include/asm/arch-mx27/regs-rtc.h 
b/arch/arm/include/asm/arch-mx27/regs-rtc.h
index d373ab15839..8434f4c1cb1 100644
--- a/arch/arm/include/asm/arch-mx27/regs-rtc.h
+++ b/arch/arm/include/asm/arch-mx27/regs-rtc.h
@@ -21,6 +21,6 @@ struct rtc_regs {
u32 dayr;
u32 dayalarm;
 };
-#endif /* __ASSEMBLY__*/
+#endif /* __ASSEMBLY__ */
 
 #endif /* __MX28_REGS_RTC_H__ */
diff --git a/arch/arm/include/asm/arch-mx5/imx-regs.h 
b/arch/arm/include/asm/arch-mx5/imx-regs.h
index fbb6e599b6d..3d1cc683228 100644
--- a/arch/arm/include/asm/arch-mx5/imx-regs.h
+++ b/arch/arm/include/asm/arch-mx5/imx-regs.h
@@ -557,6 +557,6 @@ struct pwm_regs {
u32 cnr;
 };
 
-#endif /* __ASSEMBLER__*/
+#endif /* __ASSEMBLY__ */
 
 #endif /* __ASM_ARCH_MX5_IMX_REGS_H__ */
diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h 
b/arch/arm/include/asm/arch-mx6/imx-regs.h
index 4f01b20aedf..5b41a7a4b8b 100644
--- a/arch/arm/include/asm/arch-mx6/imx-regs.h
+++ b/arch/arm/include/asm/arch-mx6/imx-regs.h
@@ -1003,5 +1003,5 @@ struct pwm_regs {
  */
 #defineis_boot_from_usb(void) (!(readl(USB_PHY0_BASE_ADDR) & (1<<20)))
 
-#endif /* __ASSEMBLER__*/
+#endif /* __ASSEMBLY__ */
 #endif /* __ASM_ARCH_MX6_IMX_REGS_H__ */
diff --git a/arch/arm/include/asm/arch-mx7/imx-regs.h 
b/arch/arm/include/asm/arch-mx7/imx-regs.h
index 63365140072..7b23abbc7eb 100644
--- a/arch/arm/include/asm/arch-mx7/imx-regs.h
+++ b/arch/arm/include/asm/arch-mx7/imx-regs.h
@@ -1223,5 +1223,5 @@ struct bootrom_sw_info {
u32 reserved_3[3];
 };
 
-#endif /* __ASSEMBLER__*/
+#endif /* __ASSEMBLY__ */
 #endif /* __ASM_ARCH_MX7_IMX_REGS_H__ */
diff --git a/arch/arm/include/asm/arch-s32v234/imx-regs.h 
b/arch/arm/include/asm/arch-s32v234/imx-regs.h
index 9a779cce965..1472a43f1bc 100644
--- a/arch/arm/include/asm/arch-s32v234/imx-regs.h
+++ b/arch/arm/include/asm/arch-s32v234/imx-regs.h
@@ -323,6 +323,6 @@ struct mscm_ir {
u32 ipcie[4];   /* Interconnect Parity Checking Injection 
Enable Register   */
 };
 
-#endif /* __ASSEMBLER__ */
+#endif /* __ASSEMBLY__ */
 
 #endif /* __ASM_ARCH_IMX_REGS_H__ */
diff --git a/arch/arm/include/asm/arch-vf610/imx-regs.h 
b/arch/arm/include/asm/arch-vf610/imx-regs.h
index ae0a187c4db..03def8e3c54 100644
--- a/arch/arm/include/asm/arch-vf610/imx-regs.h
+++ b/arch/arm/include/asm/arch-vf610/imx-regs.h
@@ -474,6 +474,6 @@ struct mscm {
u32 cpxcfg3;
 };
 
-#endif /* __ASSEMBLER__*/
+#endif /* __ASSEMBLY__ */
 
 #endif /* __ASM_ARCH_IMX_REGS_H__ */
diff --git a/arch/arm/mach-socfpga/include/mach/clock_manager.h 
b/arch/arm/mach-socfpga/include/mach/clock_manager.h
index c6830582a5a..1f734bcd65e 100644
--- a/arch/arm/mach-socfpga/include/mach/clock_manager.h
+++ b/arch/arm/mach-socfpga/include/mach/clock_manager.h
@@ -8,7 +8,7 @@
 
 phys_addr_t socfpga_get_clkmgr_addr(void);
 
-#ifndef __ASSEMBLER__
+#ifndef __ASSEMBLY__
 void cm_wait_for_lock(u32 mask);
 int cm_wait_for_fsm(void);
 void cm_print_clock_quick_summary(void);
diff --git a/arch/arm/mach-socfpga/include/mach/clock_manager_arria10.h 
b/arch/arm/mach-socfpga/include/mach/clock_manager_arria10.h
index 

Re: [PATCH] Series-to: u-boot Cover-letter: Fix Typo error in Makefile

2020-04-09 Thread Sicris Rey Embay
On Thu, Apr 9, 2020 at 8:49 PM Heinrich Schuchardt  wrote:
>
> On 2020-04-08 17:39, Sicris wrote:
> > This patch fixes the typo error in Makefile where
> > -I$(srctree)/arch/$(ARCH)/thumb1/include is not picked up
> > in the compiler flag when compiling for thumb2.
> > END
> >
> > Signed-off-by: Sicris 
> > ---
> >
> >  Makefile | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 8de5ff6d94..503b30392d 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -704,7 +704,7 @@ UBOOTINCLUDE:= \
> >   -Iinclude \
> >   $(if $(KBUILD_SRC), -I$(srctree)/include) \
> >   $(if $(CONFIG_$(SPL_)SYS_THUMB_BUILD), \
> > - $(if $(CONFIG_HAS_THUMB2),, \
> > + $(if $(CONFIG_HAS_THUMB2), \
> >   -I$(srctree)/arch/$(ARCH)/thumb1/include),) \
>
> This patch relates to
> https://stackoverflow.com/questions/61097841/error-selected-processor-does-not-support-requested-special-purpose-register
>
> The original problem was using the wrong compiler as discussed on
> Stackoverflow.

Sorry, I was not very clear on the problem that I've encountered.

I tried the M-profile as suggested in the stackoverflow comment from
Frant.  However, I still get the same error
with CONFIG_CMD_UBI=y.

{standard input}:757: Error: selected processor does not support
requested special purpose register – msr cpsr_c,r3

This is due to the assembly inline function local_irq_save() /
local_irq_restore.  On closer inspection,
the wrong header for local_irq_save / local_irq_restore was picked up
by the compiler.

Wrong Header: /arch/arm/include/asm/proc-armv/system.h
(Closest i can find) Correct Header:
/arch/arm/thumb1/include/asm/proc-armv/system.h

>
> Compiling stm32f769-disco_defconfig works fine using the Debian Bullseye
> package gcc-arm-linux-gnueabi without this patch.

Can you help me check if this compiles using Debian Bullseye with
CONFIG_CMD_UBI=y?
>
> The current logic is:
> If it is thumb and not thumb2, include the thumb1 directory.
> If it is thumb and thumb2, do not include the thumb1 directory.
>
> You are inverting the logic with your patch:
>
> If it is thumb and thumb2, include the thumb1 directory.
> If it is thumb and not thumb2, do not include the thumb1 directory.
>
> This does not make much sense to me.
>

Does this suggestion make sense?

$(if $(CONFIG_HAS_THUMB2), \
-I$(srctree)/arch/$(ARCH)/thumb2/include),
-I$(srctree)/arch/$(ARCH)/thumb1/include),) \

with thumb2/include contains the same thumb1/include contents.

> For understanding the if-statement I found the following Makefile useful:
>
> 
> all:
> $(if ,,echo 1)
> $(if ,echo 2)
> $(if 1,,echo 3)
> $(if 1,echo 4)
> ---
>
> The output contains 1 and 4.
>
> Best regards
>
> Heinrich
>
>
> >   -I$(srctree)/arch/$(ARCH)/include \
> >   -include $(srctree)/include/linux/kconfig.h
> >
>

cheers,
Sicris Rey


[PATCH v2 18/22] common: Drop linux/stringify.h from common header

2020-04-09 Thread Simon Glass
Move this uncommon header out of the common header.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/arm/cpu/armv7/bcm235xx/clk-core.h | 1 +
 arch/arm/cpu/armv7/bcm281xx/clk-core.h | 1 +
 board/Arcturus/ucp1020/cmd_arc.c   | 1 +
 board/gardena/smart-gateway-mt7688/board.c | 1 +
 board/gdsys/common/osd.c   | 1 +
 cmd/fastboot.c | 1 +
 drivers/clk/rockchip/clk_rk3036.c  | 1 +
 drivers/clk/rockchip/clk_rk3188.c  | 1 +
 drivers/clk/rockchip/clk_rk322x.c  | 1 +
 drivers/clk/rockchip/clk_rk3288.c  | 1 +
 drivers/clk/rockchip/clk_rk3368.c  | 1 +
 drivers/clk/rockchip/clk_rv1108.c  | 1 +
 fs/ubifs/super.c   | 1 +
 include/common.h   | 1 -
 include/config_fsl_chain_trust.h   | 2 ++
 include/configs/B4860QDS.h | 2 ++
 include/configs/C29XPCIE.h | 2 ++
 include/configs/M52277EVB.h| 2 ++
 include/configs/M5253DEMO.h| 2 ++
 include/configs/M5373EVB.h | 2 ++
 include/configs/M54418TWR.h| 2 ++
 include/configs/M54451EVB.h| 2 ++
 include/configs/M54455EVB.h| 2 ++
 include/configs/MPC8308RDB.h   | 2 ++
 include/configs/MPC8313ERDB_NAND.h | 2 ++
 include/configs/MPC8313ERDB_NOR.h  | 1 +
 include/configs/MPC8323ERDB.h  | 2 ++
 include/configs/MPC8349ITX.h   | 1 +
 include/configs/MPC837XERDB.h  | 2 ++
 include/configs/MPC8536DS.h| 2 ++
 include/configs/MPC8544DS.h| 1 +
 include/configs/MPC8548CDS.h   | 1 +
 include/configs/MPC8572DS.h| 2 ++
 include/configs/MPC8610HPCD.h  | 2 ++
 include/configs/MPC8641HPCN.h  | 2 ++
 include/configs/P1010RDB.h | 2 ++
 include/configs/P1022DS.h  | 2 ++
 include/configs/P1023RDB.h | 2 ++
 include/configs/P2041RDB.h | 1 +
 include/configs/T102xQDS.h | 2 ++
 include/configs/T102xRDB.h | 2 ++
 include/configs/T1040QDS.h | 2 ++
 include/configs/T104xRDB.h | 2 ++
 include/configs/T208xQDS.h | 2 ++
 include/configs/T208xRDB.h | 2 ++
 include/configs/T4240QDS.h | 2 ++
 include/configs/T4240RDB.h | 2 ++
 include/configs/UCP1020.h  | 2 ++
 include/configs/apalis_imx6.h  | 2 ++
 include/configs/apf27.h| 2 ++
 include/configs/at91sam9263ek.h| 3 +++
 include/configs/bcmstb.h   | 1 +
 include/configs/brppt1.h   | 1 +
 include/configs/brsmarc1.h | 1 +
 include/configs/brxre1.h   | 1 +
 include/configs/cgtqmx6eval.h  | 2 ++
 include/configs/clearfog.h | 2 ++
 include/configs/colibri-imx8x.h| 1 +
 include/configs/colibri_imx6.h | 2 ++
 include/configs/controlcenterd.h   | 2 ++
 include/configs/corenet_ds.h   | 2 ++
 include/configs/cyrus.h| 2 ++
 include/configs/dart_6ul.h | 1 +
 include/configs/el6x_common.h  | 2 ++
 include/configs/exynos-common.h| 1 +
 include/configs/helios4.h  | 1 +
 include/configs/hrcon.h| 2 ++
 include/configs/ids8313.h  | 2 ++
 include/configs/imx6-engicam.h | 1 +
 include/configs/imx8mm_evk.h   | 1 +
 include/configs/imx8mn_evk.h   | 1 +
 include/configs/imx8mp_evk.h   | 1 +
 include/configs/imx8mq_evk.h   | 1 +
 include/configs/imx8qm_mek.h   | 1 +
 include/configs/imx8qm_rom7720.h   | 2 ++
 include/configs/imx8qxp_mek.h  | 1 +
 include/configs/km/keymile-common.h| 2 ++
 include/configs/km/km-mpc83xx.h| 1 +
 include/configs/km/km_arm.h| 1 +
 include/configs/liteboard.h| 1 +
 include/configs/mpc8308_p1m.h  | 2 ++
 include/configs/mv-common.h| 2 ++
 include/configs/mx6_common.h   | 2 ++
 include/configs/mx6cuboxi.h| 2 ++
 include/configs/mx6sabre_common.h  | 2 ++
 include/configs/mx6sllevk.h| 1 +
 include/configs/mx6sxsabresd.h | 2 ++
 include/configs/mx6ul_14x14_evk.h  | 1 +
 include/configs/mx6ullevk.h| 1 +
 include/configs/mx7_common.h   | 1 +
 include/configs/nitrogen6x.h   | 1 +
 include/configs/p1_p2_rdb_pc.h | 2 ++
 include/configs/p1_twr.h   | 2 ++
 include/configs/pcl063_ull.h   | 1 +
 include/configs/pcm052.h   | 1 +
 include/configs/pico-imx6ul.h  | 1 +
 include/configs/pico-imx7d.h   

[PATCH v2 19/22] Fix some checkpatch warnings in calls to udelay()

2020-04-09 Thread Simon Glass
Fix up some incorrect code style in calls to functions in the linux/time.h
header, mostly udelay().

Signed-off-by: Simon Glass 

---

Changes in v2:
- Split out code-style changes for time functions into a new patch

 arch/arm/cpu/sa1100/timer.c   |  2 +-
 board/sbc8641d/sbc8641d.c |  8 
 cmd/mem.c |  4 ++--
 drivers/ata/sata_sil3114.c| 16 
 drivers/fpga/stratixII.c  |  6 +++---
 drivers/net/ax88180.c | 10 +-
 drivers/net/eepro100.c| 18 +-
 drivers/net/lan91c96.c| 10 +-
 drivers/net/rtl8139.c |  6 +++---
 drivers/net/smc9.c| 22 +++---
 drivers/qe/uec_phy.c  |  6 +++---
 drivers/rtc/ds1306.c  | 26 +-
 drivers/video/mb862xx.c   |  6 +++---
 examples/standalone/smc9_eeprom.c |  6 +++---
 lib/time.c|  2 +-
 15 files changed, 74 insertions(+), 74 deletions(-)

diff --git a/arch/arm/cpu/sa1100/timer.c b/arch/arm/cpu/sa1100/timer.c
index 8e20c96bcda..f2cbee5dca7 100644
--- a/arch/arm/cpu/sa1100/timer.c
+++ b/arch/arm/cpu/sa1100/timer.c
@@ -23,7 +23,7 @@ ulong get_timer (ulong base)
return get_timer_masked ();
 }
 
-void __udelay (unsigned long usec)
+void __udelay(unsigned long usec)
 {
ulong tmo;
ulong endtime;
diff --git a/board/sbc8641d/sbc8641d.c b/board/sbc8641d/sbc8641d.c
index 2346564c7d0..91867d4f3d2 100644
--- a/board/sbc8641d/sbc8641d.c
+++ b/board/sbc8641d/sbc8641d.c
@@ -123,12 +123,12 @@ long int fixed_sdram (void)
 
asm ("sync;isync");
 
-   udelay (500);
+   udelay(500);
 
ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1B;
asm ("sync; isync");
 
-   udelay (500);
+   udelay(500);
ddr = >im_ddr2;
 
ddr->cs0_bnds = CONFIG_SYS_DDR2_CS0_BNDS;
@@ -154,12 +154,12 @@ long int fixed_sdram (void)
 
asm ("sync;isync");
 
-   udelay (500);
+   udelay(500);
 
ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1B;
asm ("sync; isync");
 
-   udelay (500);
+   udelay(500);
 #endif
return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
 }
diff --git a/cmd/mem.c b/cmd/mem.c
index 13641de63c9..0a5aa8b47cb 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -189,7 +189,7 @@ static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int 
argc,
 
/* delay for  ms... */
for (i=0; i ms... */
for (i=0; i= 2ms" before checking status.
@@ -121,7 +121,7 @@ static void sata_identify (int num, int dev)
cmd = ATA_CMD_ID_ATA;   /*Device Identify Command */
writeb (cmd, port[num].ioaddr.command_addr);
readb (port[num].ioaddr.altstatus_addr);
-   udelay (10);
+   udelay(10);
 
status = sata_busy_wait ([num].ioaddr, ATA_BUSY, 1000, 0);
if (status & ATA_ERR) {
@@ -194,7 +194,7 @@ static void set_Feature_cmd (int num, int dev)
writeb (ATA_DEVICE_OBS, port[num].ioaddr.device_addr);
writeb (ATA_CMD_SET_FEATURES, port[num].ioaddr.command_addr);
 
-   udelay (50);
+   udelay(50);
msleep (150);
 
status = sata_busy_wait ([num].ioaddr, ATA_BUSY, 5000, 0);
@@ -392,7 +392,7 @@ static u8 wait_for_irq (int num, unsigned int max)
if (readl (port) & VND_TF_CNST_INTST) {
break;
}
-   udelay (1000);
+   udelay(1000);
max--;
} while ((max > 0));
 
@@ -408,7 +408,7 @@ static u8 sata_busy_wait (struct sata_ioports *ioaddr, int 
bits,
if (!((status = sata_chk_status (ioaddr, usealtstatus)) & 
bits)) {
break;
}
-   udelay (1000);
+   udelay(1000);
max--;
} while ((status & bits) && (max > 0));
 
@@ -429,7 +429,7 @@ static void msleep (int count)
int i;
 
for (i = 0; i < count; i++)
-   udelay (1000);
+   udelay(1000);
 }
 
 /* Read up to 255 sectors
@@ -616,7 +616,7 @@ ulong sata_write (int device, ulong block, lbaint_t blkcnt, 
const void *buff)
 
output_data ([num].ioaddr, buffer, ATA_SECTOR_WORDS);
readb (port[num].ioaddr.altstatus_addr);
-   udelay (50);
+   udelay(50);
 
++n;
++blknr;
diff --git a/drivers/fpga/stratixII.c b/drivers/fpga/stratixII.c
index 12d8dd19bf6..4edbfe4ba87 100644
--- a/drivers/fpga/stratixII.c
+++ b/drivers/fpga/stratixII.c
@@ -116,9 +116,9 @@ int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, 
size_t bsize,
 
/* 2. Strat burn cycle by deasserting config for t_CFG and waiting 
t_CF2CK after reaserted */
fns->config (0, 1, cookie);
-   udelay (5); /* nCONFIG low pulse width 2usec */
+   udelay(5);  /* nCONFIG 

[PATCH v2 10/22] common: Drop image.h from common header

2020-04-09 Thread Simon Glass
Move this uncommon header out of the common header.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/arc/lib/bootm.c | 2 ++
 arch/arm/cpu/armv8/fsl-layerscape/ls1028_ids.c   | 1 +
 arch/arm/cpu/armv8/fsl-layerscape/mp.c   | 1 +
 arch/arm/cpu/armv8/fsl-layerscape/spl.c  | 1 +
 arch/arm/cpu/armv8/sec_firmware.c| 2 ++
 arch/arm/lib/bootm.c | 1 +
 arch/arm/lib/image.c | 1 +
 arch/arm/lib/zimage.c| 1 +
 arch/arm/mach-imx/misc.c | 1 +
 arch/arm/mach-k3/common.c| 1 +
 arch/arm/mach-k3/security.c  | 1 +
 arch/arm/mach-k3/sysfw-loader.c  | 1 +
 arch/arm/mach-keystone/mon.c | 1 +
 arch/arm/mach-rockchip/misc.c| 1 +
 arch/arm/mach-rockchip/rk3399/rk3399.c   | 1 +
 arch/arm/mach-rockchip/spl.c | 1 +
 arch/arm/mach-sunxi/spl_spi_sunxi.c  | 1 +
 arch/arm/mach-zynq/spl.c | 1 +
 arch/arm/mach-zynqmp/spl.c   | 1 +
 arch/m68k/lib/bootm.c| 1 +
 arch/microblaze/lib/bootm.c  | 1 +
 arch/mips/lib/bootm.c| 1 +
 arch/mips/mach-jz47xx/jz4780/jz4780.c| 1 +
 arch/nds32/include/asm/u-boot-nds32.h| 2 ++
 arch/nios2/lib/bootm.c   | 1 +
 arch/powerpc/include/asm/fsl_i2c.h   | 1 +
 arch/powerpc/lib/bootm.c | 1 +
 arch/riscv/lib/image.c   | 1 +
 arch/sandbox/lib/bootm.c | 1 +
 arch/sh/lib/bootm.c  | 1 +
 arch/x86/cpu/apollolake/spl.c| 1 +
 arch/x86/lib/spl.c   | 1 +
 arch/x86/lib/tpl.c   | 1 +
 board/AndesTech/ax25-ae350/ax25-ae350.c  | 1 +
 board/Arcturus/ucp1020/ucp1020.c | 1 +
 board/advantech/imx8qm_rom7720_a1/spl.c  | 1 +
 board/aristainetos/aristainetos.c| 1 +
 board/dhelectronics/dh_imx6/dh_imx6.c| 1 +
 board/emulation/qemu-riscv/qemu-riscv.c  | 1 +
 board/engicam/common/spl.c   | 1 +
 board/freescale/b4860qds/b4860qds.c  | 1 +
 board/freescale/bsc9131rdb/bsc9131rdb.c  | 1 +
 board/freescale/bsc9132qds/bsc9132qds.c  | 1 +
 board/freescale/c29xpcie/c29xpcie.c  | 1 +
 board/freescale/corenet_ds/corenet_ds.c  | 1 +
 board/freescale/corenet_ds/eth_p4080.c   | 1 +
 board/freescale/imx8mm_evk/spl.c | 1 +
 board/freescale/imx8mn_evk/spl.c | 1 +
 board/freescale/imx8mp_evk/spl.c | 1 +
 board/freescale/imx8mq_evk/spl.c | 1 +
 board/freescale/imx8qm_mek/spl.c | 1 +
 board/freescale/imx8qxp_mek/spl.c| 1 +
 board/freescale/ls1046afrwy/eth.c| 1 +
 board/freescale/ls1046ardb/eth.c | 1 +
 board/freescale/lx2160a/eth_lx2160aqds.c | 2 ++
 board/freescale/lx2160a/eth_lx2160ardb.c | 1 +
 board/freescale/mpc8572ds/mpc8572ds.c| 1 +
 board/freescale/mx6sabreauto/mx6sabreauto.c  | 1 +
 board/freescale/mx6sabresd/mx6sabresd.c  | 1 +
 board/freescale/p1010rdb/p1010rdb.c  | 1 +
 board/freescale/p1022ds/p1022ds.c| 1 +
 board/freescale/p1023rdb/p1023rdb.c  | 1 +
 board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c  | 1 +
 board/freescale/p1_twr/p1_twr.c  | 1 +
 board/freescale/p2041rdb/p2041rdb.c  | 1 +
 board/freescale/t102xqds/eth_t102xqds.c  | 1 +
 board/freescale/t102xqds/t102xqds.c  | 1 +
 board/freescale/t102xrdb/eth_t102xrdb.c  | 1 +
 board/freescale/t102xrdb/t102xrdb.c  | 1 +
 board/freescale/t1040qds/eth.c   | 1 +
 board/freescale/t1040qds/t1040qds.c  | 1 +
 board/freescale/t104xrdb/t104xrdb.c  | 1 +
 board/freescale/t208xqds/eth_t208xqds.c  | 2 ++
 board/freescale/t208xqds/t208xqds.c  | 1 +
 board/freescale/t208xrdb/eth_t208xrdb.c  | 1 +
 board/freescale/t208xrdb/t208xrdb.c  | 1 +
 board/freescale/t4qds/eth.c  | 2 ++
 board/freescale/t4qds/t4240emu.c | 1 +
 board/freescale/t4qds/t4240qds.c | 1 +
 board/freescale/t4rdb/eth.c  | 1 +
 board/freescale/t4rdb/t4240rdb.c | 1 +
 board/gateworks/gw_ventana/gw_ventana.c  | 1 +
 board/gdsys/p1022/controlcenterd.c   | 1 +
 board/ge/bx50v3/bx50v3.c | 1 +
 board/highbank/highbank.c| 1 +
 board/keymile/kmp204x/kmp204x.c  | 1 +
 board/liebherr/display5/display5.c   | 1 +
 

[PATCH v2 15/22] common: Drop asm/ptrace.h from common header

2020-04-09 Thread Simon Glass
Move this uncommon header out of the common header.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/arm/cpu/arm1136/mx35/timer.c   | 1 +
 arch/arm/cpu/arm926ejs/mx25/timer.c | 1 +
 arch/arm/cpu/arm926ejs/mx27/timer.c | 1 +
 arch/arm/cpu/arm926ejs/spear/spl.c  | 1 +
 arch/arm/cpu/arm926ejs/spear/timer.c| 1 +
 arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 1 +
 arch/arm/cpu/armv8/sec_firmware.c   | 1 +
 arch/arm/lib/interrupts.c   | 1 +
 arch/arm/lib/interrupts_64.c| 1 +
 arch/arm/mach-imx/sip.c | 1 +
 arch/arm/mach-meson/board-common.c  | 1 +
 arch/arm/mach-meson/sm.c| 1 +
 arch/arm/mach-mvebu/arm64-common.c  | 1 +
 arch/m68k/lib/interrupts.c  | 1 +
 arch/m68k/lib/traps.c   | 1 +
 arch/mips/lib/traps.c   | 1 +
 arch/powerpc/cpu/mpc83xx/interrupts.c   | 1 +
 arch/powerpc/cpu/mpc83xx/traps.c| 1 +
 arch/powerpc/cpu/mpc85xx/interrupts.c   | 1 +
 arch/powerpc/cpu/mpc85xx/traps.c| 1 +
 arch/powerpc/cpu/mpc86xx/interrupts.c   | 1 +
 arch/powerpc/cpu/mpc86xx/traps.c| 1 +
 arch/powerpc/cpu/mpc8xx/interrupts.c| 1 +
 arch/powerpc/cpu/mpc8xx/traps.c | 1 +
 arch/powerpc/lib/interrupts.c   | 1 +
 arch/powerpc/lib/kgdb.c | 1 +
 arch/x86/cpu/i386/interrupt.c   | 1 +
 arch/xtensa/cpu/exceptions.c| 1 +
 board/cavium/thunderx/atf.c | 1 +
 board/xilinx/zynqmp/zynqmp.c| 1 +
 cmd/bedbug.c| 1 +
 common/bedbug.c | 1 +
 common/kgdb.c   | 1 +
 common/kgdb_stubs.c | 1 +
 drivers/clk/clk_versal.c| 1 +
 drivers/firmware/firmware-zynqmp.c  | 1 +
 drivers/timer/mpc83xx_timer.c   | 1 +
 include/common.h| 1 -
 38 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/arch/arm/cpu/arm1136/mx35/timer.c 
b/arch/arm/cpu/arm1136/mx35/timer.c
index cb351ecf769..f2541c398d8 100644
--- a/arch/arm/cpu/arm1136/mx35/timer.c
+++ b/arch/arm/cpu/arm1136/mx35/timer.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* General purpose timers bitfields */
 #define GPTCR_SWR   (1<<15)/* Software reset */
diff --git a/arch/arm/cpu/arm926ejs/mx25/timer.c 
b/arch/arm/cpu/arm926ejs/mx25/timer.c
index 7e2698b6055..4b726d5c73f 100644
--- a/arch/arm/cpu/arm926ejs/mx25/timer.c
+++ b/arch/arm/cpu/arm926ejs/mx25/timer.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* nothing really to do with interrupts, just starts up a counter. */
 /* The 32KHz 32-bit timer overruns in 134217 seconds */
diff --git a/arch/arm/cpu/arm926ejs/mx27/timer.c 
b/arch/arm/cpu/arm926ejs/mx27/timer.c
index 193588ea10b..d6e1e09f93e 100644
--- a/arch/arm/cpu/arm926ejs/mx27/timer.c
+++ b/arch/arm/cpu/arm926ejs/mx27/timer.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* General purpose timers bitfields */
 #define GPTCR_SWR  (1 << 15)   /* Software reset   */
diff --git a/arch/arm/cpu/arm926ejs/spear/spl.c 
b/arch/arm/cpu/arm926ejs/spear/spl.c
index 7b14ba05b46..08b98a2d068 100644
--- a/arch/arm/cpu/arm926ejs/spear/spl.c
+++ b/arch/arm/cpu/arm926ejs/spear/spl.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/arm926ejs/spear/timer.c 
b/arch/arm/cpu/arm926ejs/spear/timer.c
index 9db1c74b369..6803c349e84 100644
--- a/arch/arm/cpu/arm926ejs/spear/timer.c
+++ b/arch/arm/cpu/arm926ejs/spear/timer.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define GPT_RESOLUTION (CONFIG_SPEAR_HZ_CLOCK / CONFIG_SPEAR_HZ)
 #define READ_TIMER()   (readl(_regs_p->count) & GPT_FREE_RUNNING)
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c 
b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
index febb3857f2b..7bab283c399 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/armv8/sec_firmware.c 
b/arch/arm/cpu/armv8/sec_firmware.c
index 789f9ca5667..bfc0fac3eff 100644
--- a/arch/arm/cpu/armv8/sec_firmware.c
+++ b/arch/arm/cpu/armv8/sec_firmware.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/lib/interrupts.c b/arch/arm/lib/interrupts.c
index 6dbf03b00cd..885233e0824 100644
--- a/arch/arm/lib/interrupts.c
+++ b/arch/arm/lib/interrupts.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/arm/lib/interrupts_64.c b/arch/arm/lib/interrupts_64.c
index dffdf57aa20..bc062dfc9f4 100644
--- a/arch/arm/lib/interrupts_64.c
+++ b/arch/arm/lib/interrupts_64.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-imx/sip.c 

[PATCH v2 13/22] Fix some checkpatch warnings in calls to debug()

2020-04-09 Thread Simon Glass
Fix up some incorrect code style in calls to functions in the log.h
header, mostly debug().

Signed-off-by: Simon Glass 

---

Changes in v2:
- Split out code-style changes for log functions into a new patch

 arch/powerpc/lib/bootm.c| 10 +-
 board/freescale/mpc8568mds/mpc8568mds.c |  2 +-
 board/sbc8641d/sbc8641d.c   |  2 +-
 cmd/flash.c | 19 +--
 cmd/source.c| 10 +-
 common/flash.c  |  6 +++---
 drivers/rtc/m41t11.c| 12 ++--
 7 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c
index 59062ca654e..a9bcb6614fc 100644
--- a/arch/powerpc/lib/bootm.c
+++ b/arch/powerpc/lib/bootm.c
@@ -53,8 +53,8 @@ static void boot_jump_linux(bootm_headers_t *images)
 
kernel = (void (*)(bd_t *, ulong, ulong, ulong,
   ulong, ulong, ulong))images->ep;
-   debug ("## Transferring control to Linux (at address %08lx) ...\n",
-   (ulong)kernel);
+   debug("## Transferring control to Linux (at address %08lx) ...\n",
+ (ulong)kernel);
 
bootstage_mark(BOOTSTAGE_ID_RUN_OS);
 
@@ -81,7 +81,7 @@ static void boot_jump_linux(bootm_headers_t *images)
 *   r8: 0
 *   r9: 0
 */
-   debug ("   Booting using OF flat tree...\n");
+   debug("   Booting using OF flat tree...\n");
WATCHDOG_RESET ();
(*kernel) ((bd_t *)of_flat_tree, 0, 0, EPAPR_MAGIC,
   env_get_bootm_mapsize(), 0, 0);
@@ -105,7 +105,7 @@ static void boot_jump_linux(bootm_headers_t *images)
ulong initrd_end = images->initrd_end;
bd_t *kbd = images->kbd;
 
-   debug ("   Booting using board info...\n");
+   debug("   Booting using board info...\n");
WATCHDOG_RESET ();
(*kernel) (kbd, initrd_start, initrd_end,
   cmd_start, cmd_end, 0, 0);
@@ -149,7 +149,7 @@ void arch_lmb_reserve(struct lmb *lmb)
 * pointer.
 */
sp = get_sp();
-   debug ("## Current stack ends at 0x%08lx\n", sp);
+   debug("## Current stack ends at 0x%08lx\n", sp);
 
/* adjust sp by 4K to be safe */
sp -= 4096;
diff --git a/board/freescale/mpc8568mds/mpc8568mds.c 
b/board/freescale/mpc8568mds/mpc8568mds.c
index da974956640..3e804c85c4a 100644
--- a/board/freescale/mpc8568mds/mpc8568mds.c
+++ b/board/freescale/mpc8568mds/mpc8568mds.c
@@ -303,7 +303,7 @@ void pci_init_board(void)
porpllsr = in_be32(>porpllsr);
io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
 
-   debug ("   pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
+   debug("   %s: devdisr=%x, io_sel=%x\n", __func__, devdisr, io_sel);
 
pci_speed = 6000;
pci_32 = 1;
diff --git a/board/sbc8641d/sbc8641d.c b/board/sbc8641d/sbc8641d.c
index d053eaeec34..4163fd2ccf2 100644
--- a/board/sbc8641d/sbc8641d.c
+++ b/board/sbc8641d/sbc8641d.c
@@ -49,7 +49,7 @@ int dram_init(void)
dram_size = fixed_sdram ();
 #endif
 
-   debug ("DDR: ");
+   debug("DDR: ");
gd->ram_size = dram_size;
 
return 0;
diff --git a/cmd/flash.c b/cmd/flash.c
index 452b040dbca..77979e44129 100644
--- a/cmd/flash.c
+++ b/cmd/flash.c
@@ -411,13 +411,12 @@ int flash_sect_erase(ulong addr_first, ulong addr_last)
 ++bank, ++info) {
if (s_first[bank]>=0) {
erased += s_last[bank] - s_first[bank] + 1;
-   debug ("Erase Flash from 0x%08lx to 0x%08lx "
-   "in Bank # %ld ",
-   info->start[s_first[bank]],
-   (s_last[bank] == info->sector_count) ?
-   info->start[0] + info->size - 1:
-   info->start[s_last[bank]+1] - 1,
-   bank+1);
+   debug("Erase Flash from 0x%08lx to 0x%08lx in 
Bank # %ld ",
+ info->start[s_first[bank]],
+ (s_last[bank] == info->sector_count) ?
+ info->start[0] + info->size - 1 :
+ info->start[s_last[bank] + 1] - 1,
+ bank + 1);
rcode = flash_erase(info, s_first[bank],
s_last[bank]);
}
@@ -612,9 +611,9 @@ int flash_sect_protect(int p, ulong addr_first, ulong 
addr_last)
}
 
if (s_first[bank]>=0 && 

[PATCH v2 16/22] common: Drop asm_offsets.h from common header

2020-04-09 Thread Simon Glass
Move this uncommon header out of the common header.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/powerpc/cpu/mpc83xx/cpu_init.c   | 1 +
 arch/powerpc/cpu/mpc83xx/spl_minimal.c| 1 +
 arch/powerpc/cpu/mpc85xx/commproc.c   | 1 +
 arch/powerpc/cpu/mpc85xx/cpu_init_early.c | 1 +
 arch/powerpc/cpu/mpc86xx/cpu_init.c   | 1 +
 include/common.h  | 1 -
 lib/asm-offsets.c | 1 +
 7 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/cpu/mpc83xx/cpu_init.c 
b/arch/powerpc/cpu/mpc83xx/cpu_init.c
index af8facad534..4defe984774 100644
--- a/arch/powerpc/cpu/mpc83xx/cpu_init.c
+++ b/arch/powerpc/cpu/mpc83xx/cpu_init.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc83xx/spl_minimal.c 
b/arch/powerpc/cpu/mpc83xx/spl_minimal.c
index 34c81872591..2c61f2b81db 100644
--- a/arch/powerpc/cpu/mpc83xx/spl_minimal.c
+++ b/arch/powerpc/cpu/mpc83xx/spl_minimal.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc85xx/commproc.c 
b/arch/powerpc/cpu/mpc85xx/commproc.c
index 37e706238b6..95215a0b829 100644
--- a/arch/powerpc/cpu/mpc85xx/commproc.c
+++ b/arch/powerpc/cpu/mpc85xx/commproc.c
@@ -22,6 +22,7 @@
  * currently no deallocator for this memory.
  */
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/powerpc/cpu/mpc85xx/cpu_init_early.c 
b/arch/powerpc/cpu/mpc85xx/cpu_init_early.c
index 40cb24dd54a..c519e8bd4b0 100644
--- a/arch/powerpc/cpu/mpc85xx/cpu_init_early.c
+++ b/arch/powerpc/cpu/mpc85xx/cpu_init_early.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc86xx/cpu_init.c 
b/arch/powerpc/cpu/mpc86xx/cpu_init.c
index 34752a34af5..a17091d2ff8 100644
--- a/arch/powerpc/cpu/mpc86xx/cpu_init.c
+++ b/arch/powerpc/cpu/mpc86xx/cpu_init.c
@@ -9,6 +9,7 @@
  * cpu_init.c - low level cpu init
  */
 
+#include 
 #include 
 #include 
 #include 
diff --git a/include/common.h b/include/common.h
index 395d1d39018..976046e6202 100644
--- a/include/common.h
+++ b/include/common.h
@@ -16,7 +16,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index 26175132f32..b17651ed63d 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -12,6 +12,7 @@
  */
 
 #include 
+#include 
 
 #include 
 
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 04/22] arm: Don't include common.h in header files

2020-04-09 Thread Simon Glass
It is bad practice to include common.h in other header files since it can
bring in any number of superfluous definitions. It implies that some C
files don't include it and thus may be missing CONFIG options that are set
up by that file. The C files should include these themselves.

Update some header files in arch/arm to drop this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/arm/cpu/armv8/fwcall.c|  1 +
 arch/arm/include/asm/arch-am33xx/clk_synthesizer.h |  2 --
 arch/arm/include/asm/arch-am33xx/mux.h |  1 -
 arch/arm/include/asm/arch-am33xx/mux_am33xx.h  |  1 -
 arch/arm/include/asm/arch-am33xx/mux_am43xx.h  |  1 -
 arch/arm/include/asm/arch-am33xx/mux_ti816x.h  |  1 -
 arch/arm/include/asm/arch-fsl-layerscape/clock.h   |  2 --
 arch/arm/include/asm/arch-lpc32xx/dma.h|  2 --
 arch/arm/include/asm/arch-lpc32xx/i2c.h|  1 -
 arch/arm/include/asm/arch-ls102xa/clock.h  |  2 --
 arch/arm/include/asm/arch-mx25/clock.h |  2 --
 arch/arm/include/asm/arch-mx31/clock.h |  2 --
 arch/arm/include/asm/arch-mx35/clock.h |  2 --
 arch/arm/include/asm/arch-mx5/clock.h  |  2 --
 arch/arm/include/asm/arch-mx6/clock.h  |  7 +--
 arch/arm/include/asm/arch-mx7/clock.h  |  1 -
 arch/arm/include/asm/arch-mx7ulp/clock.h   |  1 -
 arch/arm/include/asm/arch-mx7ulp/pcc.h |  1 -
 arch/arm/include/asm/arch-mx7ulp/scg.h |  2 --
 arch/arm/include/asm/arch-omap4/clock.h|  1 -
 arch/arm/include/asm/arch-omap5/clock.h|  1 -
 arch/arm/include/asm/arch-omap5/dra7xx_iodelay.h   |  1 -
 arch/arm/include/asm/arch-rk3308/cru_rk3308.h  |  2 --
 arch/arm/include/asm/arch-rk3308/grf_rk3308.h  |  2 --
 arch/arm/include/asm/arch-rockchip/cru_px30.h  |  2 --
 arch/arm/include/asm/arch-rockchip/cru_rk3036.h|  2 --
 arch/arm/include/asm/arch-rockchip/cru_rk3128.h|  2 --
 arch/arm/include/asm/arch-rockchip/cru_rk322x.h|  2 --
 arch/arm/include/asm/arch-rockchip/cru_rk3328.h|  2 --
 arch/arm/include/asm/arch-rockchip/cru_rk3368.h|  3 ---
 arch/arm/include/asm/arch-rockchip/cru_rk3399.h|  2 --
 arch/arm/include/asm/arch-rockchip/cru_rv1108.h|  2 --
 arch/arm/include/asm/arch-rockchip/grf_px30.h  |  2 --
 arch/arm/include/asm/arch-rockchip/grf_rk3036.h|  2 --
 arch/arm/include/asm/arch-rockchip/grf_rk3128.h|  2 --
 arch/arm/include/asm/arch-rockchip/grf_rk322x.h|  2 --
 arch/arm/include/asm/arch-rockchip/grf_rk3368.h|  2 --
 arch/arm/include/asm/arch-rockchip/grf_rv1108.h|  2 --
 arch/arm/include/asm/arch-rockchip/sdram_rk3036.h  |  2 --
 arch/arm/include/asm/arch-rockchip/sdram_rk322x.h  |  2 --
 arch/arm/include/asm/arch-s32v234/clock.h  |  2 --
 arch/arm/include/asm/arch-sunxi/rsb.h  |  1 -
 arch/arm/include/asm/arch-tegra/ivc.h  |  2 --
 arch/arm/include/asm/arch-tegra/tegra_mmc.h|  1 -
 arch/arm/include/asm/arch-vf610/clock.h|  2 --
 arch/arm/include/asm/dma-mapping.h |  2 +-
 arch/arm/include/asm/emif.h|  1 -
 arch/arm/include/asm/mach-imx/iomux-v3.h   |  2 +-
 arch/arm/include/asm/mach-imx/sys_proto.h  |  6 --
 arch/arm/include/asm/omap_common.h | 10 ++
 arch/arm/include/asm/omap_sec_common.h |  2 --
 arch/arm/include/asm/psci.h|  4 
 arch/arm/include/asm/system.h  |  3 ++-
 arch/arm/mach-imx/ddrmc-vf610.c|  1 +
 arch/arm/mach-imx/mx7ulp/soc.c |  2 ++
 arch/arm/mach-imx/sata.c   |  1 +
 arch/arm/mach-omap2/am33xx/ddr.c   |  1 +
 arch/arm/mach-omap2/omap4/sdram_elpida.c   |  1 +
 arch/arm/mach-omap2/omap5/sdram.c  |  1 +
 arch/arm/mach-rockchip/rk3036/rk3036.c |  2 ++
 board/compulab/cm_t54/mux.c|  1 +
 board/el/el6x/el6x.c   |  1 +
 board/embest/mx6boards/mx6boards.c |  1 +
 board/gateworks/gw_ventana/common.c|  1 +
 board/grinn/liteboard/board.c  |  1 +
 board/overo/spl.c  |  2 ++
 board/sks-kinkel/sksimx6/sksimx6.c |  1 +
 board/solidrun/mx6cuboxi/mx6cuboxi.c   |  1 +
 board/technexion/pico-imx6/spl.c   |  1 +
 board/technexion/pico-imx7d/spl.c  |  1 +
 board/udoo/udoo_spl.c  |  1 +
 board/wandboard/spl.c  |  1 +
 board/wandboard/wandboard.c|  1 +
 drivers/mtd/nand/raw/denali.c  |  2 ++
 drivers/mtd/nand/raw/denali_dt.c   |  2 ++
 drivers/usb/eth/lan7x.h|  7 +++
 include/linux/compat.h |  

[PATCH v2 09/22] common: Drop bootstage.h from common header

2020-04-09 Thread Simon Glass
Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/arc/lib/bootm.c| 3 ++-
 arch/arm/cpu/armv8/generic_timer.c  | 1 +
 arch/arm/lib/bootm.c| 1 +
 arch/m68k/lib/bootm.c   | 1 +
 arch/microblaze/lib/bootm.c | 1 +
 arch/mips/lib/bootm.c   | 1 +
 arch/nds32/lib/bootm.c  | 1 +
 arch/powerpc/lib/bootm.c| 1 +
 arch/riscv/lib/bootm.c  | 1 +
 arch/sandbox/cpu/cpu.c  | 1 +
 arch/sandbox/lib/bootm.c| 1 +
 arch/x86/cpu/apollolake/fsp_s.c | 1 +
 arch/x86/cpu/apollolake/spl.c   | 1 +
 arch/x86/cpu/coreboot/timestamp.c   | 1 +
 arch/x86/cpu/cpu.c  | 1 +
 arch/x86/lib/bootm.c| 1 +
 arch/x86/lib/fsp2/fsp_init.c| 1 +
 arch/x86/lib/fsp2/fsp_meminit.c | 1 +
 arch/x86/lib/fsp2/fsp_silicon_init.c| 1 +
 arch/xtensa/lib/bootm.c | 1 +
 board/Seagate/dockstar/dockstar.c   | 1 +
 board/Seagate/goflexhome/goflexhome.c   | 1 +
 board/armltd/integrator/integrator.c| 1 +
 board/armltd/vexpress/vexpress_common.c | 1 +
 board/bosch/shc/board.c | 1 +
 board/buffalo/lsxl/lsxl.c   | 1 +
 board/gdsys/p1022/controlcenterd-id.c   | 1 +
 board/st/stv0991/stv0991.c  | 1 +
 board/technexion/tao3530/tao3530.c  | 1 +
 board/ti/beagle/beagle.c| 1 +
 cmd/bootstage.c | 1 +
 cmd/disk.c  | 1 +
 cmd/nand.c  | 1 +
 cmd/net.c   | 1 +
 cmd/usb.c   | 1 +
 common/board_f.c| 1 +
 common/board_r.c| 1 +
 common/bootm_os.c   | 1 +
 common/bootstage.c  | 1 +
 common/cli.c| 1 +
 common/image.c  | 1 +
 common/init/board_init.c| 1 +
 common/main.c   | 1 +
 common/spl/spl.c| 1 +
 drivers/pci/pci_rom.c   | 1 +
 drivers/scsi/scsi.c | 1 +
 drivers/spi/ich.c   | 1 +
 drivers/timer/cadence-ttc.c | 1 +
 drivers/timer/rockchip_timer.c  | 1 +
 drivers/timer/tsc_timer.c   | 1 +
 drivers/video/broadwell_igd.c   | 1 +
 drivers/video/tegra124/display.c| 1 +
 env/common.c| 1 +
 include/common.h| 1 -
 lib/time.c  | 1 +
 net/bootp.c | 1 +
 net/eth-uclass.c| 1 +
 net/eth_common.c| 1 +
 net/eth_legacy.c| 1 +
 net/net.c   | 1 +
 post/post.c | 1 +
 61 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c
index d38c18ef8f4..1b08ffe2857 100644
--- a/arch/arc/lib/bootm.c
+++ b/arch/arc/lib/bootm.c
@@ -3,9 +3,10 @@
  * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
  */
 
+#include 
+#include 
 #include 
 #include 
-#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
diff --git a/arch/arm/cpu/armv8/generic_timer.c 
b/arch/arm/cpu/armv8/generic_timer.c
index 46e63294fef..6fe3ede387b 100644
--- a/arch/arm/cpu/armv8/generic_timer.c
+++ b/arch/arm/cpu/armv8/generic_timer.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 3e387e49e70..37fc727601c 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -12,6 +12,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c
index 19445b3fc7a..fb1170d00d7 100644
--- a/arch/m68k/lib/bootm.c
+++ b/arch/m68k/lib/bootm.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c
index 87d2d6ee70d..f7303b790fc 100644
--- a/arch/microblaze/lib/bootm.c
+++ b/arch/microblaze/lib/bootm.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c
index 8c0d7672f24..9be9d18ac85 100644
--- a/arch/mips/lib/bootm.c
+++ b/arch/mips/lib/bootm.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/nds32/lib/bootm.c b/arch/nds32/lib/bootm.c
index 1003bc87b9d..b17368647d3 100644
--- a/arch/nds32/lib/bootm.c
+++ b/arch/nds32/lib/bootm.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c
index 390e8c0673c..1cef75c4bef 100644
--- a/arch/powerpc/lib/bootm.c
+++ b/arch/powerpc/lib/bootm.c
@@ -8,6 

[PATCH v2 08/22] bootstage: Use BOOTSTAGE instead of BOOTSTATE

2020-04-09 Thread Simon Glass
Some of the enum members are wrong. Fix them.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/x86/lib/fsp2/fsp_meminit.c  |  4 ++--
 arch/x86/lib/fsp2/fsp_silicon_init.c |  4 ++--
 common/board_f.c |  4 ++--
 common/board_r.c |  4 ++--
 common/spl/spl.c |  4 ++--
 include/bootstage.h  | 10 +-
 6 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/arch/x86/lib/fsp2/fsp_meminit.c b/arch/x86/lib/fsp2/fsp_meminit.c
index bf30c479899..300be8b093f 100644
--- a/arch/x86/lib/fsp2/fsp_meminit.c
+++ b/arch/x86/lib/fsp2/fsp_meminit.c
@@ -79,10 +79,10 @@ int fsp_memory_init(bool s3wake, bool use_spi_flash)
return log_msg_ret("Could not setup config", ret);
 
debug("SDRAM init...");
-   bootstage_start(BOOTSTATE_ID_ACCUM_FSP_M, "fsp-m");
+   bootstage_start(BOOTSTAGE_ID_ACCUM_FSP_M, "fsp-m");
func = (fsp_memory_init_func)(hdr->img_base + hdr->fsp_mem_init);
ret = func(, );
-   bootstage_accum(BOOTSTATE_ID_ACCUM_FSP_M);
+   bootstage_accum(BOOTSTAGE_ID_ACCUM_FSP_M);
if (ret)
return log_msg_ret("SDRAM init fail\n", ret);
 
diff --git a/arch/x86/lib/fsp2/fsp_silicon_init.c 
b/arch/x86/lib/fsp2/fsp_silicon_init.c
index d7ce43e1eb2..66a3cb39f18 100644
--- a/arch/x86/lib/fsp2/fsp_silicon_init.c
+++ b/arch/x86/lib/fsp2/fsp_silicon_init.c
@@ -42,10 +42,10 @@ int fsp_silicon_init(bool s3wake, bool use_spi_flash)
if (ret)
return log_msg_ret("Could not setup config", ret);
log_debug("Silicon init...");
-   bootstage_start(BOOTSTATE_ID_ACCUM_FSP_S, "fsp-s");
+   bootstage_start(BOOTSTAGE_ID_ACCUM_FSP_S, "fsp-s");
func = (fsp_silicon_init_func)(hdr->img_base + hdr->fsp_silicon_init);
ret = func();
-   bootstage_accum(BOOTSTATE_ID_ACCUM_FSP_S);
+   bootstage_accum(BOOTSTAGE_ID_ACCUM_FSP_S);
if (ret)
return log_msg_ret("Silicon init fail\n", ret);
log_debug("done\n");
diff --git a/common/board_f.c b/common/board_f.c
index c59400269a6..c32a77a95b8 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -837,9 +837,9 @@ static int initf_dm(void)
 #if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
int ret;
 
-   bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
+   bootstage_start(BOOTSTAGE_ID_ACCUM_DM_F, "dm_f");
ret = dm_init_and_scan(true);
-   bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
+   bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F);
if (ret)
return ret;
 #endif
diff --git a/common/board_r.c b/common/board_r.c
index 95319a2b50d..46806fe8611 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -313,9 +313,9 @@ static int initr_dm(void)
 #ifdef CONFIG_TIMER
gd->timer = NULL;
 #endif
-   bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r");
+   bootstage_start(BOOTSTAGE_ID_ACCUM_DM_R, "dm_r");
ret = dm_init_and_scan(false);
-   bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R);
+   bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_R);
if (ret)
return ret;
 
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 932e6ab98ac..0526cd7718d 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -455,11 +455,11 @@ static int spl_common_init(bool setup_malloc)
}
}
if (CONFIG_IS_ENABLED(DM)) {
-   bootstage_start(BOOTSTATE_ID_ACCUM_DM_SPL,
+   bootstage_start(BOOTSTAGE_ID_ACCUM_DM_SPL,
spl_phase() == PHASE_TPL ? "dm tpl" : "dm_spl");
/* With CONFIG_SPL_OF_PLATDATA, bring in all devices */
ret = dm_init_and_scan(!CONFIG_IS_ENABLED(OF_PLATDATA));
-   bootstage_accum(BOOTSTATE_ID_ACCUM_DM_SPL);
+   bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_SPL);
if (ret) {
debug("dm_init_and_scan() returned error %d\n", ret);
return ret;
diff --git a/include/bootstage.h b/include/bootstage.h
index 82f0307ef1e..f507271375f 100644
--- a/include/bootstage.h
+++ b/include/bootstage.h
@@ -199,11 +199,11 @@ enum bootstage_id {
BOOTSTAGE_ID_ACCUM_DECOMP,
BOOTSTAGE_ID_ACCUM_OF_LIVE,
BOOTSTAGE_ID_FPGA_INIT,
-   BOOTSTATE_ID_ACCUM_DM_SPL,
-   BOOTSTATE_ID_ACCUM_DM_F,
-   BOOTSTATE_ID_ACCUM_DM_R,
-   BOOTSTATE_ID_ACCUM_FSP_M,
-   BOOTSTATE_ID_ACCUM_FSP_S,
+   BOOTSTAGE_ID_ACCUM_DM_SPL,
+   BOOTSTAGE_ID_ACCUM_DM_F,
+   BOOTSTAGE_ID_ACCUM_DM_R,
+   BOOTSTAGE_ID_ACCUM_FSP_M,
+   BOOTSTAGE_ID_ACCUM_FSP_S,
BOOTSTAGE_ID_ACCUM_MMAP_SPI,
 
/* a few spare for the user, from here */
-- 
2.26.0.110.g2183baf09c-goog



[PATCH v2 02/22] flash: Tidy up coding style for flash functions

2020-04-09 Thread Simon Glass
Some functions use the wrong code style and generate checkpatch errors.
Fix these.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Split out code-style changes for flash functions into a new patch

 arch/arm/mach-at91/arm926ejs/eflash.c |  8 
 board/cobra5272/flash.c   | 16 
 board/socrates/socrates.c | 27 ++-
 cmd/flash.c   | 22 --
 common/flash.c| 10 +-
 include/flash.h   | 24 
 6 files changed, 55 insertions(+), 52 deletions(-)

diff --git a/arch/arm/mach-at91/arm926ejs/eflash.c 
b/arch/arm/mach-at91/arm926ejs/eflash.c
index 7b61fa72260..cfd6490d9dd 100644
--- a/arch/arm/mach-at91/arm926ejs/eflash.c
+++ b/arch/arm/mach-at91/arm926ejs/eflash.c
@@ -58,7 +58,7 @@
 flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
 static u32 pagesize;
 
-unsigned long flash_init (void)
+unsigned long flash_init(void)
 {
at91_eefc_t *eefc = (at91_eefc_t *) ATMEL_BASE_EEFC;
at91_dbu_t *dbu = (at91_dbu_t *) ATMEL_BASE_DBGU;
@@ -127,7 +127,7 @@ unsigned long flash_init (void)
return size;
 }
 
-void flash_print_info (flash_info_t *info)
+void flash_print_info(flash_info_t *info)
 {
int i;
 
@@ -202,7 +202,7 @@ static u32 erase_write_page (u32 pagenum)
& (AT91_EEFC_FSR_FCMDE | AT91_EEFC_FSR_FLOCKE);
 }
 
-int flash_erase (flash_info_t *info, int s_first, int s_last)
+int flash_erase(flash_info_t *info, int s_first, int s_last)
 {
debug("erase first=%d last=%d\n", s_first, s_last);
puts("this flash does not need and support erasing!\n");
@@ -215,7 +215,7 @@ int flash_erase (flash_info_t *info, int s_first, int 
s_last)
  * 1 - write timeout
  */
 
-int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
+int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 {
u32 pagenum;
u32 *src32, *dst32;
diff --git a/board/cobra5272/flash.c b/board/cobra5272/flash.c
index 1d3c5acddf8..e601ed8e720 100644
--- a/board/cobra5272/flash.c
+++ b/board/cobra5272/flash.c
@@ -14,7 +14,7 @@
 
 flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
 
-void flash_print_info (flash_info_t * info)
+void flash_print_info(flash_info_t *info)
 {
int i;
 
@@ -55,7 +55,7 @@ Done:
 }
 
 
-unsigned long flash_init (void)
+unsigned long flash_init(void)
 {
int i, j;
ulong size = 0;
@@ -98,9 +98,9 @@ unsigned long flash_init (void)
size += flash_info[i].size;
}
 
-   flash_protect (FLAG_PROTECT_SET,
-  CONFIG_SYS_FLASH_BASE,
-  CONFIG_SYS_FLASH_BASE + 0x3, _info[0]);
+   flash_protect(FLAG_PROTECT_SET,
+ CONFIG_SYS_FLASH_BASE,
+ CONFIG_SYS_FLASH_BASE + 0x3, _info[0]);
 
return size;
 }
@@ -127,7 +127,7 @@ unsigned long flash_init (void)
 #define TMO   4
 
 
-int flash_erase (flash_info_t * info, int s_first, int s_last)
+int flash_erase(flash_info_t *info, int s_first, int s_last)
 {
ulong result;
int iflag, cflag, prot, sect;
@@ -244,7 +244,7 @@ int flash_erase (flash_info_t * info, int s_first, int 
s_last)
return rc;
 }
 
-static int write_word (flash_info_t * info, ulong dest, ulong data)
+static int write_word(flash_info_t *info, ulong dest, ulong data)
 {
volatile u16 *addr = (volatile u16 *) dest;
ulong result;
@@ -311,7 +311,7 @@ static int write_word (flash_info_t * info, ulong dest, 
ulong data)
 }
 
 
-int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
+int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 {
ulong wp, data;
int rc;
diff --git a/board/socrates/socrates.c b/board/socrates/socrates.c
index b0ddee7906a..bd214acc808 100644
--- a/board/socrates/socrates.c
+++ b/board/socrates/socrates.c
@@ -105,25 +105,26 @@ int misc_init_r (void)
/*
 * Re-do flash protection upon new addresses
 */
-   flash_protect (FLAG_PROTECT_CLEAR,
-  gd->bd->bi_flashstart, 0x,
-  _info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
+   flash_protect(FLAG_PROTECT_CLEAR,
+ gd->bd->bi_flashstart, 0x,
+ _info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
 
/* Monitor protection ON by default */
-   flash_protect (FLAG_PROTECT_SET,
-  CONFIG_SYS_MONITOR_BASE, CONFIG_SYS_MONITOR_BASE 
+ monitor_flash_len - 1,
-  _info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
+   flash_protect(FLAG_PROTECT_SET,
+ CONFIG_SYS_MONITOR_BASE, CONFIG_SYS_MONITOR_BASE +
+ monitor_flash_len - 1,
+ 

[PATCH v2 07/22] common: Drop part.h from common header

2020-04-09 Thread Simon Glass
Move this uncommon header out of the common header.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 api/api_storage.c| 1 +
 arch/arm/mach-omap2/utils.c  | 1 +
 arch/arm/mach-snapdragon/dram.c  | 1 +
 arch/x86/include/asm/fsp/fsp_api.h   | 2 ++
 arch/x86/include/asm/fsp/fsp_fv.h| 2 ++
 board/xilinx/zynq/bootimg.c  | 1 +
 cmd/ab_select.c  | 2 ++
 cmd/bcb.c| 1 +
 cmd/gpt.c| 2 ++
 cmd/mmc.c| 2 ++
 cmd/nvme.c   | 1 +
 cmd/sata.c   | 1 +
 cmd/scsi.c   | 1 +
 cmd/unzip.c  | 1 +
 cmd/usb.c| 1 +
 cmd/usb_mass_storage.c   | 3 ++-
 cmd/virtio.c | 1 +
 common/android_ab.c  | 4 +++-
 common/spl/spl_ext.c | 1 +
 common/spl/spl_mmc.c | 1 +
 common/usb_storage.c | 1 +
 disk/part.c  | 1 +
 disk/part_amiga.c| 1 +
 disk/part_dos.c  | 2 ++
 disk/part_efi.c  | 4 +++-
 disk/part_iso.c  | 2 ++
 disk/part_mac.c  | 1 +
 drivers/ata/ahci.c   | 1 +
 drivers/ata/dwc_ahsata.c | 2 ++
 drivers/ata/fsl_sata.c   | 1 +
 drivers/ata/sata.c   | 2 ++
 drivers/ata/sata_mv.c| 1 +
 drivers/ata/sata_sandbox.c   | 1 +
 drivers/ata/sata_sil3114.c   | 2 ++
 drivers/block/blk-uclass.c   | 1 +
 drivers/block/blk_legacy.c   | 2 ++
 drivers/block/blkcache.c | 2 +-
 drivers/block/ide.c  | 2 ++
 drivers/dfu/dfu_mmc.c| 1 +
 drivers/fastboot/fb_getvar.c | 1 +
 drivers/fastboot/fb_nand.c   | 1 +
 drivers/misc/fsl_ifc.c   | 1 +
 drivers/mmc/mmc.c| 1 +
 drivers/mmc/mmc_write.c  | 1 +
 drivers/mmc/sh_sdhi.c| 1 +
 drivers/mtd/nand/raw/fsl_ifc_spl.c   | 1 +
 drivers/net/fm/eth.c | 1 +
 drivers/nvme/nvme-uclass.c   | 1 +
 drivers/nvme/nvme.c  | 1 +
 drivers/scsi/scsi.c  | 2 ++
 drivers/usb/gadget/ether.c   | 1 +
 drivers/usb/gadget/f_rockusb.c   | 1 +
 drivers/video/atmel_hlcdfb.c | 1 +
 drivers/video/atmel_lcdfb.c  | 1 +
 drivers/video/imx/mxc_ipuv3_fb.c | 1 +
 drivers/video/meson/meson_vpu.c  | 1 +
 drivers/video/mvebu_lcd.c| 1 +
 drivers/video/sunxi/sunxi_de2.c  | 1 +
 drivers/video/tegra.c| 1 +
 drivers/video/tegra124/display.c | 1 +
 drivers/virtio/virtio_blk.c  | 1 +
 env/ext4.c   | 1 +
 env/fat.c| 6 +++---
 fs/btrfs/dev.c   | 1 +
 fs/btrfs/super.c | 4 +++-
 fs/ext4/ext4_common.c| 2 ++
 fs/ext4/ext4_journal.c   | 1 +
 fs/ext4/ext4_write.c | 2 ++
 fs/ext4/ext4fs.c | 2 ++
 fs/fs.c  | 1 +
 fs/fs_internal.c | 1 +
 fs/sandbox/sandboxfs.c   | 1 +
 fs/ubifs/ubifs.c | 1 +
 include/android_ab.h | 3 ++-
 include/btrfs.h  | 3 +++
 include/common.h | 1 -
 include/efi_loader.h | 2 ++
 include/ext4fs.h | 2 ++
 include/fat.h| 2 ++
 include/fb_mmc.h | 3 +++
 include/fs.h | 2 ++
 include/fsl_ifc.h| 1 +
 include/gzip.h   | 2 ++
 include/initcall.h   | 4 
 include/reiserfs.h   | 3 +++
 include/sandboxfs.h  | 3 +++
 include/spl.h| 1 +
 include/ubifs_uboot.h| 3 +++
 lib/efi_driver/efi_block_device.c| 2 ++
 lib/efi_loader/efi_device_path_to_text.c | 1 +
 lib/efi_loader/efi_file.c| 1 +
 lib/gunzip.c | 1 +
 lib/image-sparse.c   | 1 +
 test/dm/blk.c| 1 +
 test/dm/mmc.c| 1 +
 test/dm/usb.c| 1 +
 96 files changed, 140 insertions(+), 10 deletions(-)

diff --git a/api/api_storage.c b/api/api_storage.c
index 7ae03ac2306..a0dacad1a55 100644
--- a/api/api_storage.c
+++ b/api/api_storage.c
@@ -8,6 +8,7 @@
 #include 
 #include 

[PATCH v2 06/22] part: Drop disk_partition_t typedef

2020-04-09 Thread Simon Glass
We should not be using typedefs and these make it harder to use
forward declarations (to reduce header file inclusions). Drop the typedef.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/arm/mach-omap2/utils.c  |  2 +-
 arch/x86/cpu/quark/quark.c   |  1 +
 cmd/ab_select.c  |  2 +-
 cmd/bcb.c|  4 ++--
 cmd/disk.c   |  2 +-
 cmd/fat.c|  4 ++--
 cmd/gpt.c| 17 +++---
 cmd/part.c   |  6 ++---
 cmd/read.c   |  2 +-
 cmd/reiser.c |  4 ++--
 cmd/usb_mass_storage.c   |  2 +-
 cmd/zfs.c|  4 ++--
 common/android_ab.c  |  6 ++---
 common/spl/spl_ext.c |  4 ++--
 common/spl/spl_mmc.c |  2 +-
 disk/part.c  | 17 +++---
 disk/part_amiga.c|  2 +-
 disk/part_dos.c  |  4 ++--
 disk/part_efi.c  |  8 +++
 disk/part_iso.c  |  8 +++
 disk/part_mac.c  |  2 +-
 drivers/dfu/dfu_mmc.c|  2 +-
 drivers/fastboot/fb_getvar.c |  4 ++--
 drivers/fastboot/fb_mmc.c| 20 
 env/ext4.c   |  4 ++--
 env/fat.c|  4 ++--
 env/mmc.c|  2 +-
 fs/btrfs/btrfs.c |  3 ++-
 fs/btrfs/btrfs.h |  2 +-
 fs/btrfs/dev.c   |  2 +-
 fs/ext4/dev.c|  4 ++--
 fs/ext4/ext4fs.c |  2 +-
 fs/fat/fat.c |  6 ++---
 fs/fs.c  |  6 ++---
 fs/fs_internal.c |  2 +-
 fs/reiserfs/dev.c|  4 ++--
 fs/sandbox/sandboxfs.c   |  2 +-
 fs/ubifs/ubifs.c |  2 +-
 fs/zfs/dev.c |  4 ++--
 include/android_ab.h |  2 +-
 include/avb_verify.h |  2 +-
 include/btrfs.h  |  3 ++-
 include/ext4fs.h |  4 ++--
 include/fat.h|  2 +-
 include/fb_mmc.h |  5 ++--
 include/fs_internal.h|  2 +-
 include/part.h   | 40 +---
 include/reiserfs.h   |  2 +-
 include/sandboxfs.h  |  2 +-
 include/ubifs_uboot.h|  2 +-
 include/zfs_common.h |  2 +-
 lib/efi_loader/efi_device_path.c |  4 ++--
 lib/efi_loader/efi_disk.c|  2 +-
 lib/efi_loader/efi_file.c|  2 +-
 54 files changed, 131 insertions(+), 123 deletions(-)

diff --git a/arch/arm/mach-omap2/utils.c b/arch/arm/mach-omap2/utils.c
index 0d5ca20e8e8..6e519d8c910 100644
--- a/arch/arm/mach-omap2/utils.c
+++ b/arch/arm/mach-omap2/utils.c
@@ -90,7 +90,7 @@ static u32 omap_mmc_get_part_size(const char *part)
 {
int res;
struct blk_desc *dev_desc;
-   disk_partition_t info;
+   struct disk_partition info;
u64 sz = 0;
 
dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
diff --git a/arch/x86/cpu/quark/quark.c b/arch/x86/cpu/quark/quark.c
index d6611eea5dc..46c6d00eb4d 100644
--- a/arch/x86/cpu/quark/quark.c
+++ b/arch/x86/cpu/quark/quark.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/cmd/ab_select.c b/cmd/ab_select.c
index 7c8f2ee8eb3..d0d957d4f9d 100644
--- a/cmd/ab_select.c
+++ b/cmd/ab_select.c
@@ -11,7 +11,7 @@ static int do_ab_select(cmd_tbl_t *cmdtp, int flag, int argc,
 {
int ret;
struct blk_desc *dev_desc;
-   disk_partition_t part_info;
+   struct disk_partition part_info;
char slot[2];
 
if (argc != 4)
diff --git a/cmd/bcb.c b/cmd/bcb.c
index 9626f2c69e3..62f9a44e38a 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -112,7 +112,7 @@ static int do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc,
   char * const argv[])
 {
struct blk_desc *desc;
-   disk_partition_t info;
+   struct disk_partition info;
u64 cnt;
char *endp;
int part, ret;
@@ -252,7 +252,7 @@ static int do_bcb_store(cmd_tbl_t *cmdtp, int flag, int 
argc,
char * const argv[])
 {
struct blk_desc *desc;
-   disk_partition_t info;
+   struct disk_partition info;
u64 cnt;
int ret;
 
diff --git a/cmd/disk.c b/cmd/disk.c
index 15973b7d132..9e008a38890 100644
--- a/cmd/disk.c
+++ b/cmd/disk.c
@@ -16,7 +16,7 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int 
argc,
int part;
ulong addr = CONFIG_SYS_LOAD_ADDR;
ulong cnt;
-   disk_partition_t info;
+   struct disk_partition info;
 #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
image_header_t *hdr;
 #endif
diff --git a/cmd/fat.c b/cmd/fat.c
index 2392907be2f..a88a49c1171 100644
--- a/cmd/fat.c
+++ b/cmd/fat.c
@@ -70,7 +70,7 @@ static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int 

[PATCH v2 03/22] common: Drop flash.h from common header

2020-04-09 Thread Simon Glass
Move this uncommon header out of the common header.

Fix up some style problems in flash.h while we are here.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 arch/arm/mach-at91/arm926ejs/eflash.c  | 1 +
 board/AndesTech/adp-ae3xx/adp-ae3xx.c  | 1 +
 board/AndesTech/adp-ag101p/adp-ag101p.c| 1 +
 board/AndesTech/ax25-ae350/ax25-ae350.c| 1 +
 board/Arcturus/ucp1020/cmd_arc.c   | 1 +
 board/atmel/at91sam9263ek/at91sam9263ek.c  | 1 +
 board/buffalo/lsxl/lsxl.c  | 1 +
 board/cobra5272/flash.c| 2 ++
 board/freescale/common/fsl_validate.c  | 1 +
 board/freescale/m5253demo/flash.c  | 1 +
 board/freescale/mpc8568mds/bcsr.c  | 1 +
 board/freescale/mpc8568mds/mpc8568mds.c| 1 +
 board/freescale/mpc8569mds/bcsr.c  | 1 +
 board/freescale/mpc8569mds/mpc8569mds.c| 1 +
 board/gardena/smart-gateway-mt7688/board.c | 1 +
 board/gdsys/mpc8308/hrcon.c| 1 +
 board/gdsys/mpc8308/strider.c  | 1 +
 board/renesas/sh7752evb/sh7752evb.c| 1 +
 board/renesas/sh7753evb/sh7753evb.c| 1 +
 board/renesas/sh7757lcr/sh7757lcr.c| 1 +
 board/siemens/taurus/taurus.c  | 1 +
 board/socrates/socrates.c  | 1 +
 board/spear/x600/x600.c| 1 +
 cmd/armflash.c | 1 +
 cmd/cros_ec.c  | 1 +
 cmd/flash.c| 1 +
 cmd/jffs2.c| 1 +
 cmd/mvebu/bubt.c   | 1 +
 cmd/sf.c   | 1 +
 common/board_r.c   | 1 +
 common/flash.c | 1 +
 drivers/dfu/dfu_sf.c   | 1 +
 drivers/fastboot/fb_command.c  | 1 +
 drivers/fastboot/fb_mmc.c  | 1 +
 drivers/fastboot/fb_nand.c | 1 +
 drivers/misc/cros_ec.c | 1 +
 drivers/mtd/cfi_flash.c| 1 +
 drivers/mtd/jedec_flash.c  | 1 +
 drivers/mtd/spi/sf_dataflash.c | 1 +
 drivers/mtd/spi/sf_mtd.c   | 1 +
 drivers/mtd/stm32_flash.c  | 1 +
 env/sf.c   | 2 ++
 fs/cramfs/cramfs.c | 1 +
 fs/jffs2/jffs2_1pass.c | 1 +
 include/common.h   | 1 -
 45 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-at91/arm926ejs/eflash.c 
b/arch/arm/mach-at91/arm926ejs/eflash.c
index cfd6490d9dd..c875bfd89b7 100644
--- a/arch/arm/mach-at91/arm926ejs/eflash.c
+++ b/arch/arm/mach-at91/arm926ejs/eflash.c
@@ -43,6 +43,7 @@
  * do a read-modify-write for partially programmed pages
  */
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/AndesTech/adp-ae3xx/adp-ae3xx.c 
b/board/AndesTech/adp-ae3xx/adp-ae3xx.c
index a04415decaf..8eb40bf295c 100644
--- a/board/AndesTech/adp-ae3xx/adp-ae3xx.c
+++ b/board/AndesTech/adp-ae3xx/adp-ae3xx.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
 #include 
 #endif
diff --git a/board/AndesTech/adp-ag101p/adp-ag101p.c 
b/board/AndesTech/adp-ag101p/adp-ag101p.c
index faf39b4ba6a..d349b19648d 100644
--- a/board/AndesTech/adp-ag101p/adp-ag101p.c
+++ b/board/AndesTech/adp-ag101p/adp-ag101p.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
 #include 
diff --git a/board/AndesTech/ax25-ae350/ax25-ae350.c 
b/board/AndesTech/ax25-ae350/ax25-ae350.c
index f164073000c..de546dab174 100644
--- a/board/AndesTech/ax25-ae350/ax25-ae350.c
+++ b/board/AndesTech/ax25-ae350/ax25-ae350.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
 #include 
diff --git a/board/Arcturus/ucp1020/cmd_arc.c b/board/Arcturus/ucp1020/cmd_arc.c
index b50de63c5e0..2b4853f8f91 100644
--- a/board/Arcturus/ucp1020/cmd_arc.c
+++ b/board/Arcturus/ucp1020/cmd_arc.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/atmel/at91sam9263ek/at91sam9263ek.c 
b/board/atmel/at91sam9263ek/at91sam9263ek.c
index b811d931c44..be132bc185f 100644
--- a/board/atmel/at91sam9263ek/at91sam9263ek.c
+++ b/board/atmel/at91sam9263ek/at91sam9263ek.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/buffalo/lsxl/lsxl.c b/board/buffalo/lsxl/lsxl.c
index 95d3a5e1f57..aa641259ac6 100644
--- a/board/buffalo/lsxl/lsxl.c
+++ b/board/buffalo/lsxl/lsxl.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/cobra5272/flash.c b/board/cobra5272/flash.c
index e601ed8e720..5860cd0ac03 100644
--- a/board/cobra5272/flash.c
+++ b/board/cobra5272/flash.c
@@ -7,7 +7,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 
 

[PATCH v2 01/22] common: Drop uuid.h from common header

2020-04-09 Thread Simon Glass
Move this uncommon header out of the common header.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 cmd/gpt.c | 1 +
 cmd/nvedit_efi.c  | 1 +
 cmd/x86/hob.c | 1 +
 disk/part_efi.c   | 1 +
 fs/btrfs/btrfs.c  | 1 +
 fs/ext4/ext4fs.c  | 1 +
 include/common.h  | 1 -
 lib/efi_loader/efi_variable.c | 1 +
 lib/uuid.c| 1 +
 lib/vsprintf.c| 1 +
 net/bootp.c   | 1 +
 11 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index efaf1bcecb2..e05ef4355bc 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
index 8ea0da01283..3fdeec945c6 100644
--- a/cmd/nvedit_efi.c
+++ b/cmd/nvedit_efi.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /*
diff --git a/cmd/x86/hob.c b/cmd/x86/hob.c
index 3967a7ca5a7..29d9e3d5a27 100644
--- a/cmd/x86/hob.c
+++ b/cmd/x86/hob.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/disk/part_efi.c b/disk/part_efi.c
index b2e157d9c1e..2709aebd60e 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -9,6 +9,7 @@
  *   when CONFIG_SYS_64BIT_LBA is not defined, lbaint_t is 32 bits; this
  *   limits the maximum size of addressable storage to < 2 Terra Bytes
  */
+#include 
 #include 
 #include 
 #include 
diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c
index cb7e1827422..2e3985e3855 100644
--- a/fs/btrfs/btrfs.c
+++ b/fs/btrfs/btrfs.c
@@ -8,6 +8,7 @@
 #include "btrfs.h"
 #include 
 #include 
+#include 
 #include 
 
 struct btrfs_info btrfs_info;
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 966b427a974..96ca276839e 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -26,6 +26,7 @@
 #include "ext4_common.h"
 #include 
 #include 
+#include 
 
 int ext4fs_symlinknest;
 struct ext_filesystem ext_fs;
diff --git a/include/common.h b/include/common.h
index 0ef8505fc79..a8242cafc51 100644
--- a/include/common.h
+++ b/include/common.h
@@ -36,7 +36,6 @@
 #include/* global data used for startup functions */
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index fe2f2645913..81a678c2036 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define READ_ONLY BIT(31)
diff --git a/lib/uuid.c b/lib/uuid.c
index 3d3c7abcaea..db26911414a 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index b4edee29b0d..de9ef902b96 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/net/bootp.c b/net/bootp.c
index 505489140e8..c73a82e642c 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "bootp.h"
 #ifdef CONFIG_LED_STATUS
-- 
2.26.0.110.g2183baf09c-goog



Re: [RFC 1/7] mmc: fsl_esdhc_imx: add OF_PLATDATA support

2020-04-09 Thread Walter Lozano



On 9/4/20 16:50, Simon Glass wrote:

Hi Walter,

On Thu, 9 Apr 2020 at 13:44, Walter Lozano  wrote:

Hi Simon,

On 9/4/20 16:36, Simon Glass wrote:

Hi Walter,

On Thu, 9 Apr 2020 at 13:07, Walter Lozano  wrote:

Hi Simon,

On 8/4/20 00:14, Simon Glass wrote:

Hi Walter,

On Tue, 7 Apr 2020 at 14:05, Walter Lozano  wrote:

Hi Simon,

Thank you for taking the time to review this series.

On 6/4/20 00:42, Simon Glass wrote:

Hi Walter,

On Sun, 29 Mar 2020 at 21:32, Walter Lozano  wrote:

Signed-off-by: Walter Lozano
---
 drivers/mmc/fsl_esdhc_imx.c | 46 +
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
index 4900498e9b..761a4b46e9 100644
--- a/drivers/mmc/fsl_esdhc_imx.c
+++ b/drivers/mmc/fsl_esdhc_imx.c
@@ -29,6 +29,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 

 #if !CONFIG_IS_ENABLED(BLK)
 #include "mmc_private.h"
@@ -98,6 +100,11 @@ struct fsl_esdhc {
 };

 struct fsl_esdhc_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+   /* Put this first since driver model will copy the data here */
+   struct dtd_fsl_imx6q_usdhc dtplat;
+#endif
+
struct mmc_config cfg;
struct mmc mmc;
 };
@@ -1377,14 +1384,18 @@ static int fsl_esdhc_probe(struct udevice *dev)
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
struct fsl_esdhc_priv *priv = dev_get_priv(dev);
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
const void *fdt = gd->fdt_blob;
int node = dev_of_offset(dev);
+   fdt_addr_t addr;
+#else
+   struct dtd_fsl_imx6q_usdhc *dtplat = >dtplat;
+#endif
struct esdhc_soc_data *data =
(struct esdhc_soc_data *)dev_get_driver_data(dev);
 #if CONFIG_IS_ENABLED(DM_REGULATOR)
struct udevice *vqmmc_dev;
 #endif
-   fdt_addr_t addr;
unsigned int val;
struct mmc *mmc;
 #if !CONFIG_IS_ENABLED(BLK)
@@ -1392,14 +1403,23 @@ static int fsl_esdhc_probe(struct udevice *dev)
 #endif
int ret;

+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+   priv->esdhc_regs = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
+   val = plat->dtplat.bus_width;
+   if (val == 8)
+   priv->bus_width = 8;
+   else if (val == 4)
+   priv->bus_width = 4;
+   else
+   priv->bus_width = 1;
+   priv->non_removable = 1;
+#else
addr = dev_read_addr(dev);
if (addr == FDT_ADDR_T_NONE)
return -EINVAL;
priv->esdhc_regs = (struct fsl_esdhc *)addr;
priv->dev = dev;
priv->mode = -1;
-   if (data)
-   priv->flags = data->flags;

val = dev_read_u32_default(dev, "bus-width", -1);
if (val == 8)
@@ -1462,7 +1482,9 @@ static int fsl_esdhc_probe(struct udevice *dev)
priv->vs18_enable = 1;
}
 #endif
-
+#endif
+   if (data)
+   priv->flags = data->flags;
/*
 * TODO:
 * Because lack of clk driver, if SDHC clk is not enabled,
@@ -1513,9 +1535,11 @@ static int fsl_esdhc_probe(struct udevice *dev)
return ret;
}

+#if !CONFIG_IS_ENABLED(OF_PLATDATA)

Maybe can use if() for this one?

Thank you for the suggestion


ret = mmc_of_parse(dev, >cfg);
if (ret)
return ret;
+#endif

mmc = >mmc;
mmc->cfg = >cfg;
@@ -1648,4 +1672,18 @@ U_BOOT_DRIVER(fsl_esdhc) = {
.platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
.priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
 };
+
+#if CONFIG_IS_ENABLED(OF_PLATDATA)

Don't you already have a U_BOOT_DRIVER declaration?

You may need to change the name of your existing driver though (see
of-platdata docs).

So if it is because of that, please add a comment.

I have my doubts regarding this issue. As I see, this driver is used by
many different DT with different compatible strings, so I'm thinking in
trying to find a more generic approach. Would it be useful to have a
more elaborated solution searching for the compatible string when
matching drivers with device?

Yes I think so.

Actually searching for a string is not great anyway. I wonder if we
can use the linker-list idea in the previous email somehow?

I'm sure I' understand the idea you try to share with me. Sorry, I
understand that one limitation of the current implementation of
OF_PLATDATA is the fact that the U_BOOT_DRIVER name should match the one
used as first entry in DT. As in particular this driver has several
compatible

   { .compatible = "fsl,imx53-esdhc", },
   { .compatible = "fsl,imx6ul-usdhc", },
   { .compatible = "fsl,imx6sx-usdhc", },
   { .compatible = 

Re: [RFC] dm: uclass: add functions to get device by platdata

2020-04-09 Thread Walter Lozano



On 9/4/20 16:36, Simon Glass wrote:

HI Walter,

On Thu, 9 Apr 2020 at 12:57, Walter Lozano  wrote:

Hi Simon,

On 8/4/20 00:14, Simon Glass wrote:

Hi Walter,

On Tue, 7 Apr 2020 at 14:05, Walter Lozano  wrote:

Hi Simon,

On 6/4/20 00:43, Simon Glass wrote:

Hi Walter,

On Mon, 9 Mar 2020 at 12:27, Walter Lozano   wrote:

Hi Simon

On 6/3/20 17:32, Simon Glass wrote:

Hi Walter,

On Fri, 6 Mar 2020 at 09:10, Walter Lozano   wrote:

Hi Simon,

Thanks again for taking the time to check my comments.

On 6/3/20 10:17, Simon Glass wrote:

Hi Walter,

On Thu, 5 Mar 2020 at 06:54, Walter Lozano   wrote:

Hi Simon,

Thanks for taking the time to check for my comments

On 4/3/20 20:11, Simon Glass wrote:


Hi Walter,

On Wed, 4 Mar 2020 at 12:40, Walter Lozano   wrote:

When OF_PLATDATA is enabled DT information is parsed and platdata
structures are populated. In this context the links between DT nodes are
represented as pointers to platdata structures, and there is no clear way
to access to the device which owns the structure.

This patch implements a set of functions:

- device_find_by_platdata
- uclass_find_device_by_platdata

to access to the device.

Signed-off-by: Walter Lozano
---
   drivers/core/device.c| 19 +++
   drivers/core/uclass.c| 34 ++
   include/dm/device.h  |  2 ++
   include/dm/uclass-internal.h |  3 +++
   include/dm/uclass.h  |  2 ++
   5 files changed, 60 insertions(+)

This is interesting. Could you also add the motivation for this? It's
not clear to me who would call this function.

I have been reviewing the OF_PLATDATA support as an R project, in this 
context, in order to have
a better understanding on the possibilities and limitations I decided to add 
its support to iMX6,
more particularly to the MMC drivers. The link issue arises when I tried to 
setup the GPIO for
Card Detection, which is trivial when DT is available. However, when 
OF_PLATDATA is enabled
this seems, at least for me, not straightforward.

In order to overcome this limitation I think that having a set of functions to 
find/get devices
based on platdata could be useful. Of course, there might be a better 
approach/idea, so that is
the motivation for this RFC.

An example of the usage could be

#if CONFIG_IS_ENABLED(DM_GPIO)

  struct udevice *gpiodev;

  ret = uclass_get_device_by_platdata(UCLASS_GPIO, (void 
*)dtplat->cd_gpios->node, );

  if (ret)
  return ret;

  ret = gpio_dev_request_index(gpiodev, gpiodev->name, "cd-gpios",
   dtplat->cd_gpios->arg[0], 
GPIOD_IS_IN,
   dtplat->cd_gpios->arg[1], 
>cd_gpio);

  if (ret)
  return ret;

#endif

This is part of my current work, a series of patches to add OF_PLATDATA support 
as explained.

Does this make sense to you?

Not yet :-)

What is the context of this call? Typically dtplat is only available
in the driver that includes it.

Sorry for not being clear enough. I'm working in a patchset that needs
some clean up, that is the reason I didn't send it yet. I'll try to
clarify, but if you think it could be useful to share it, please let me
know.


What driver is the above code in? Is it for MMC that needs a GPIO to
function? I'll assume it is for now.

The driver on which I'm working in is drivers/mmc/fsl_esdhc_imx.c, I'm
adding support for OF_PLATDATA to it, and in this sense trying to get
the GPIOs used for CD to be requested.


Then the weird thing is that we are accessing the dtplat of another
device. It's a clever technique but I wonder if we can find another
way.

If you see drivers/mmc/rockchip_sdhci.c it has:

ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, );

So I wonder if we need gpio_dev_request_by_platdata()?

Thanks for pointing to this example, as I saw it before starting to work
on these functions and had some doubts. I'll use it in the next
paragraph to share my thoughts and the motivation of my work.

 From my understanding, clk_get_by_index_platdata in this context can
only get a UCLASS_CLK device with id == 0. Is this correct?

If it is so, this will only allow us to use this function if we know in
advance that the UCLASS_CLK device has index 0.

How can we get the correct UCLASS_CLK device in case of multiple instances?

We actually can't support that at present. I think we would need to
change the property to be an array, like:

   clocks = [
   [, CLK_ID_SPI],
   [, CLK_ID_I2C, 23],
 ]

which would need a fancier dtoc. Perhaps we should start by
upstreaming that tool.

In this case, are you suggesting to replace CLK_ID_SPI and CLK_ID_I2C
with a integer calculated by dtoc based on the clocks entries available?
If I understand correctly, what we need is to get the index parameter to
feed the function uclass_find_device. Is 

Re: [RFC 1/7] mmc: fsl_esdhc_imx: add OF_PLATDATA support

2020-04-09 Thread Simon Glass
Hi Walter,

On Thu, 9 Apr 2020 at 13:44, Walter Lozano  wrote:
>
> Hi Simon,
>
> On 9/4/20 16:36, Simon Glass wrote:
> > Hi Walter,
> >
> > On Thu, 9 Apr 2020 at 13:07, Walter Lozano  
> > wrote:
> >> Hi Simon,
> >>
> >> On 8/4/20 00:14, Simon Glass wrote:
> >>> Hi Walter,
> >>>
> >>> On Tue, 7 Apr 2020 at 14:05, Walter Lozano  
> >>> wrote:
>  Hi Simon,
> 
>  Thank you for taking the time to review this series.
> 
>  On 6/4/20 00:42, Simon Glass wrote:
> > Hi Walter,
> >
> > On Sun, 29 Mar 2020 at 21:32, Walter 
> > Lozano  wrote:
> >> Signed-off-by: Walter Lozano
> >> ---
> >> drivers/mmc/fsl_esdhc_imx.c | 46 
> >> +
> >> 1 file changed, 42 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
> >> index 4900498e9b..761a4b46e9 100644
> >> --- a/drivers/mmc/fsl_esdhc_imx.c
> >> +++ b/drivers/mmc/fsl_esdhc_imx.c
> >> @@ -29,6 +29,8 @@
> >> #include 
> >> #include 
> >> #include 
> >> +#include 
> >> +#include 
> >>
> >> #if !CONFIG_IS_ENABLED(BLK)
> >> #include "mmc_private.h"
> >> @@ -98,6 +100,11 @@ struct fsl_esdhc {
> >> };
> >>
> >> struct fsl_esdhc_plat {
> >> +#if CONFIG_IS_ENABLED(OF_PLATDATA)
> >> +   /* Put this first since driver model will copy the data here */
> >> +   struct dtd_fsl_imx6q_usdhc dtplat;
> >> +#endif
> >> +
> >>struct mmc_config cfg;
> >>struct mmc mmc;
> >> };
> >> @@ -1377,14 +1384,18 @@ static int fsl_esdhc_probe(struct udevice *dev)
> >>struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
> >>struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
> >>struct fsl_esdhc_priv *priv = dev_get_priv(dev);
> >> +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
> >>const void *fdt = gd->fdt_blob;
> >>int node = dev_of_offset(dev);
> >> +   fdt_addr_t addr;
> >> +#else
> >> +   struct dtd_fsl_imx6q_usdhc *dtplat = >dtplat;
> >> +#endif
> >>struct esdhc_soc_data *data =
> >>(struct esdhc_soc_data *)dev_get_driver_data(dev);
> >> #if CONFIG_IS_ENABLED(DM_REGULATOR)
> >>struct udevice *vqmmc_dev;
> >> #endif
> >> -   fdt_addr_t addr;
> >>unsigned int val;
> >>struct mmc *mmc;
> >> #if !CONFIG_IS_ENABLED(BLK)
> >> @@ -1392,14 +1403,23 @@ static int fsl_esdhc_probe(struct udevice *dev)
> >> #endif
> >>int ret;
> >>
> >> +#if CONFIG_IS_ENABLED(OF_PLATDATA)
> >> +   priv->esdhc_regs = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
> >> +   val = plat->dtplat.bus_width;
> >> +   if (val == 8)
> >> +   priv->bus_width = 8;
> >> +   else if (val == 4)
> >> +   priv->bus_width = 4;
> >> +   else
> >> +   priv->bus_width = 1;
> >> +   priv->non_removable = 1;
> >> +#else
> >>addr = dev_read_addr(dev);
> >>if (addr == FDT_ADDR_T_NONE)
> >>return -EINVAL;
> >>priv->esdhc_regs = (struct fsl_esdhc *)addr;
> >>priv->dev = dev;
> >>priv->mode = -1;
> >> -   if (data)
> >> -   priv->flags = data->flags;
> >>
> >>val = dev_read_u32_default(dev, "bus-width", -1);
> >>if (val == 8)
> >> @@ -1462,7 +1482,9 @@ static int fsl_esdhc_probe(struct udevice *dev)
> >>priv->vs18_enable = 1;
> >>}
> >> #endif
> >> -
> >> +#endif
> >> +   if (data)
> >> +   priv->flags = data->flags;
> >>/*
> >> * TODO:
> >> * Because lack of clk driver, if SDHC clk is not enabled,
> >> @@ -1513,9 +1535,11 @@ static int fsl_esdhc_probe(struct udevice *dev)
> >>return ret;
> >>}
> >>
> >> +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
> > Maybe can use if() for this one?
>  Thank you for the suggestion
> 
> >>ret = mmc_of_parse(dev, >cfg);
> >>if (ret)
> >>return ret;
> >> +#endif
> >>
> >>mmc = >mmc;
> >>mmc->cfg = >cfg;
> >> @@ -1648,4 +1672,18 @@ U_BOOT_DRIVER(fsl_esdhc) = {
> >>.platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
> >>.priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
> >> };
> >> +
> >> +#if CONFIG_IS_ENABLED(OF_PLATDATA)
> > Don't you already have a U_BOOT_DRIVER declaration?
> >
> > You may need to change the name of your 

Re: [RFC 1/7] mmc: fsl_esdhc_imx: add OF_PLATDATA support

2020-04-09 Thread Walter Lozano

Hi Simon,

On 9/4/20 16:36, Simon Glass wrote:

Hi Walter,

On Thu, 9 Apr 2020 at 13:07, Walter Lozano  wrote:

Hi Simon,

On 8/4/20 00:14, Simon Glass wrote:

Hi Walter,

On Tue, 7 Apr 2020 at 14:05, Walter Lozano  wrote:

Hi Simon,

Thank you for taking the time to review this series.

On 6/4/20 00:42, Simon Glass wrote:

Hi Walter,

On Sun, 29 Mar 2020 at 21:32, Walter Lozano  wrote:

Signed-off-by: Walter Lozano
---
drivers/mmc/fsl_esdhc_imx.c | 46 +
1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
index 4900498e9b..761a4b46e9 100644
--- a/drivers/mmc/fsl_esdhc_imx.c
+++ b/drivers/mmc/fsl_esdhc_imx.c
@@ -29,6 +29,8 @@
#include 
#include 
#include 
+#include 
+#include 

#if !CONFIG_IS_ENABLED(BLK)
#include "mmc_private.h"
@@ -98,6 +100,11 @@ struct fsl_esdhc {
};

struct fsl_esdhc_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+   /* Put this first since driver model will copy the data here */
+   struct dtd_fsl_imx6q_usdhc dtplat;
+#endif
+
   struct mmc_config cfg;
   struct mmc mmc;
};
@@ -1377,14 +1384,18 @@ static int fsl_esdhc_probe(struct udevice *dev)
   struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
   struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
   struct fsl_esdhc_priv *priv = dev_get_priv(dev);
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
   const void *fdt = gd->fdt_blob;
   int node = dev_of_offset(dev);
+   fdt_addr_t addr;
+#else
+   struct dtd_fsl_imx6q_usdhc *dtplat = >dtplat;
+#endif
   struct esdhc_soc_data *data =
   (struct esdhc_soc_data *)dev_get_driver_data(dev);
#if CONFIG_IS_ENABLED(DM_REGULATOR)
   struct udevice *vqmmc_dev;
#endif
-   fdt_addr_t addr;
   unsigned int val;
   struct mmc *mmc;
#if !CONFIG_IS_ENABLED(BLK)
@@ -1392,14 +1403,23 @@ static int fsl_esdhc_probe(struct udevice *dev)
#endif
   int ret;

+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+   priv->esdhc_regs = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
+   val = plat->dtplat.bus_width;
+   if (val == 8)
+   priv->bus_width = 8;
+   else if (val == 4)
+   priv->bus_width = 4;
+   else
+   priv->bus_width = 1;
+   priv->non_removable = 1;
+#else
   addr = dev_read_addr(dev);
   if (addr == FDT_ADDR_T_NONE)
   return -EINVAL;
   priv->esdhc_regs = (struct fsl_esdhc *)addr;
   priv->dev = dev;
   priv->mode = -1;
-   if (data)
-   priv->flags = data->flags;

   val = dev_read_u32_default(dev, "bus-width", -1);
   if (val == 8)
@@ -1462,7 +1482,9 @@ static int fsl_esdhc_probe(struct udevice *dev)
   priv->vs18_enable = 1;
   }
#endif
-
+#endif
+   if (data)
+   priv->flags = data->flags;
   /*
* TODO:
* Because lack of clk driver, if SDHC clk is not enabled,
@@ -1513,9 +1535,11 @@ static int fsl_esdhc_probe(struct udevice *dev)
   return ret;
   }

+#if !CONFIG_IS_ENABLED(OF_PLATDATA)

Maybe can use if() for this one?

Thank you for the suggestion


   ret = mmc_of_parse(dev, >cfg);
   if (ret)
   return ret;
+#endif

   mmc = >mmc;
   mmc->cfg = >cfg;
@@ -1648,4 +1672,18 @@ U_BOOT_DRIVER(fsl_esdhc) = {
   .platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
   .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
};
+
+#if CONFIG_IS_ENABLED(OF_PLATDATA)

Don't you already have a U_BOOT_DRIVER declaration?

You may need to change the name of your existing driver though (see
of-platdata docs).

So if it is because of that, please add a comment.

I have my doubts regarding this issue. As I see, this driver is used by
many different DT with different compatible strings, so I'm thinking in
trying to find a more generic approach. Would it be useful to have a
more elaborated solution searching for the compatible string when
matching drivers with device?

Yes I think so.

Actually searching for a string is not great anyway. I wonder if we
can use the linker-list idea in the previous email somehow?


I'm sure I' understand the idea you try to share with me. Sorry, I
understand that one limitation of the current implementation of
OF_PLATDATA is the fact that the U_BOOT_DRIVER name should match the one
used as first entry in DT. As in particular this driver has several
compatible

  { .compatible = "fsl,imx53-esdhc", },
  { .compatible = "fsl,imx6ul-usdhc", },
  { .compatible = "fsl,imx6sx-usdhc", },
  { .compatible = "fsl,imx6sl-usdhc", },
  { .compatible = "fsl,imx6q-usdhc", },
  { .compatible = "fsl,imx7d-usdhc", .data =
(ulong)_imx7d_data,},
  { 

Re: [RFC 1/7] mmc: fsl_esdhc_imx: add OF_PLATDATA support

2020-04-09 Thread Simon Glass
Hi Walter,

On Thu, 9 Apr 2020 at 13:07, Walter Lozano  wrote:
>
> Hi Simon,
>
> On 8/4/20 00:14, Simon Glass wrote:
> > Hi Walter,
> >
> > On Tue, 7 Apr 2020 at 14:05, Walter Lozano  
> > wrote:
> >> Hi Simon,
> >>
> >> Thank you for taking the time to review this series.
> >>
> >> On 6/4/20 00:42, Simon Glass wrote:
> >>> Hi Walter,
> >>>
> >>> On Sun, 29 Mar 2020 at 21:32, Walter Lozano  
> >>> wrote:
>  Signed-off-by: Walter Lozano
>  ---
> drivers/mmc/fsl_esdhc_imx.c | 46 +
> 1 file changed, 42 insertions(+), 4 deletions(-)
> 
>  diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
>  index 4900498e9b..761a4b46e9 100644
>  --- a/drivers/mmc/fsl_esdhc_imx.c
>  +++ b/drivers/mmc/fsl_esdhc_imx.c
>  @@ -29,6 +29,8 @@
> #include 
> #include 
> #include 
>  +#include 
>  +#include 
> 
> #if !CONFIG_IS_ENABLED(BLK)
> #include "mmc_private.h"
>  @@ -98,6 +100,11 @@ struct fsl_esdhc {
> };
> 
> struct fsl_esdhc_plat {
>  +#if CONFIG_IS_ENABLED(OF_PLATDATA)
>  +   /* Put this first since driver model will copy the data here */
>  +   struct dtd_fsl_imx6q_usdhc dtplat;
>  +#endif
>  +
>    struct mmc_config cfg;
>    struct mmc mmc;
> };
>  @@ -1377,14 +1384,18 @@ static int fsl_esdhc_probe(struct udevice *dev)
>    struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
>    struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
>    struct fsl_esdhc_priv *priv = dev_get_priv(dev);
>  +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
>    const void *fdt = gd->fdt_blob;
>    int node = dev_of_offset(dev);
>  +   fdt_addr_t addr;
>  +#else
>  +   struct dtd_fsl_imx6q_usdhc *dtplat = >dtplat;
>  +#endif
>    struct esdhc_soc_data *data =
>    (struct esdhc_soc_data *)dev_get_driver_data(dev);
> #if CONFIG_IS_ENABLED(DM_REGULATOR)
>    struct udevice *vqmmc_dev;
> #endif
>  -   fdt_addr_t addr;
>    unsigned int val;
>    struct mmc *mmc;
> #if !CONFIG_IS_ENABLED(BLK)
>  @@ -1392,14 +1403,23 @@ static int fsl_esdhc_probe(struct udevice *dev)
> #endif
>    int ret;
> 
>  +#if CONFIG_IS_ENABLED(OF_PLATDATA)
>  +   priv->esdhc_regs = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
>  +   val = plat->dtplat.bus_width;
>  +   if (val == 8)
>  +   priv->bus_width = 8;
>  +   else if (val == 4)
>  +   priv->bus_width = 4;
>  +   else
>  +   priv->bus_width = 1;
>  +   priv->non_removable = 1;
>  +#else
>    addr = dev_read_addr(dev);
>    if (addr == FDT_ADDR_T_NONE)
>    return -EINVAL;
>    priv->esdhc_regs = (struct fsl_esdhc *)addr;
>    priv->dev = dev;
>    priv->mode = -1;
>  -   if (data)
>  -   priv->flags = data->flags;
> 
>    val = dev_read_u32_default(dev, "bus-width", -1);
>    if (val == 8)
>  @@ -1462,7 +1482,9 @@ static int fsl_esdhc_probe(struct udevice *dev)
>    priv->vs18_enable = 1;
>    }
> #endif
>  -
>  +#endif
>  +   if (data)
>  +   priv->flags = data->flags;
>    /*
> * TODO:
> * Because lack of clk driver, if SDHC clk is not enabled,
>  @@ -1513,9 +1535,11 @@ static int fsl_esdhc_probe(struct udevice *dev)
>    return ret;
>    }
> 
>  +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
> >>> Maybe can use if() for this one?
> >> Thank you for the suggestion
> >>
>    ret = mmc_of_parse(dev, >cfg);
>    if (ret)
>    return ret;
>  +#endif
> 
>    mmc = >mmc;
>    mmc->cfg = >cfg;
>  @@ -1648,4 +1672,18 @@ U_BOOT_DRIVER(fsl_esdhc) = {
>    .platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
>    .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
> };
>  +
>  +#if CONFIG_IS_ENABLED(OF_PLATDATA)
> >>> Don't you already have a U_BOOT_DRIVER declaration?
> >>>
> >>> You may need to change the name of your existing driver though (see
> >>> of-platdata docs).
> >>>
> >>> So if it is because of that, please add a comment.
> >> I have my doubts regarding this issue. As I see, this driver is used by
> >> many different DT with different compatible strings, so I'm thinking in
> >> trying to find a more generic approach. Would it be useful to have a
> >> more elaborated solution searching for the compatible string when
> >> matching drivers with device?
> 

Re: [PATCH v6 12/29] dm: core: Add basic ACPI support

2020-04-09 Thread Simon Glass
On Thu, 9 Apr 2020 at 11:40, Andy Shevchenko
 wrote:
>
> On Thu, Apr 09, 2020 at 10:27:38AM -0600, Simon Glass wrote:
> > ACPI (Advanced Configuration and Power Interface) is a standard for
> > specifying information about a platform. It is a little like device
> > tree but the bindings are part of the specification and it supports an
> > interpreted bytecode language.
> >
> > Driver model does not use ACPI for U-Boot's configuration, but it is
> > convenient to have it support generation of ACPI tables for passing to
> > Linux, etc.
> >
> > As a starting point, add an optional set of ACPI operations to each
> > device. Initially only a single operation is available, to obtain the
> > ACPI name for the device. More operations are added later.
> >
> > Enable ACPI for sandbox to ensure build coverage and so that we can add
> > tests.
> >
>
> Both looks good to me now, thanks!
>
> > Reviewed-by: Bin Meng 
> > Reviewed-by: Wolfgang Wallner 
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v6:
> > - Use ACPI_NAME_LEN in acpi_copy_name since we add the nul anyway
> >
> > Changes in v5:
> > - Capitalise ACPI_OPS_PTR since it includes a comma
> >
> > Changes in v4: None
> > Changes in v3:
> > - Drop 'Intel' from 'Intel ACPI'
> > - Reword commit message to drop the bit about ACPI being complicated
> > - Compute ACPI_NAME_MAX from ACPI_NAME_LEN
> > - Rename acpi_return_name() to acpi_copy_name()
> > - Use strncpy() instead of strcpy() in acpi_copy_name()
> >
> > Changes in v2:
> > - Move LOGC_ACPI definition to this patch
> >
> >  configs/tools-only_defconfig |  1 +
> >  drivers/core/Kconfig |  9 +
> >  drivers/core/Makefile|  1 +
> >  drivers/core/acpi.c  | 33 
> >  include/dm/acpi.h| 73 
> >  include/dm/device.h  |  5 +++
> >  include/log.h|  2 +
> >  7 files changed, 124 insertions(+)
> >  create mode 100644 drivers/core/acpi.c
> >  create mode 100644 include/dm/acpi.h

Andy let me add your tag.

Reviewed-by: Andy Shevchenko 


Re: [RFC] dm: uclass: add functions to get device by platdata

2020-04-09 Thread Simon Glass
HI Walter,

On Thu, 9 Apr 2020 at 12:57, Walter Lozano  wrote:
>
> Hi Simon,
>
> On 8/4/20 00:14, Simon Glass wrote:
> > Hi Walter,
> >
> > On Tue, 7 Apr 2020 at 14:05, Walter Lozano  
> > wrote:
> >> Hi Simon,
> >>
> >> On 6/4/20 00:43, Simon Glass wrote:
> >>> Hi Walter,
> >>>
> >>> On Mon, 9 Mar 2020 at 12:27, Walter Lozano   
> >>> wrote:
>  Hi Simon
> 
>  On 6/3/20 17:32, Simon Glass wrote:
> > Hi Walter,
> >
> > On Fri, 6 Mar 2020 at 09:10, Walter Lozano 
> >   wrote:
> >> Hi Simon,
> >>
> >> Thanks again for taking the time to check my comments.
> >>
> >> On 6/3/20 10:17, Simon Glass wrote:
> >>> Hi Walter,
> >>>
> >>> On Thu, 5 Mar 2020 at 06:54, Walter 
> >>> Lozano   wrote:
>  Hi Simon,
> 
>  Thanks for taking the time to check for my comments
> 
>  On 4/3/20 20:11, Simon Glass wrote:
> 
> > Hi Walter,
> >
> > On Wed, 4 Mar 2020 at 12:40, Walter 
> > Lozano   wrote:
> >> When OF_PLATDATA is enabled DT information is parsed and platdata
> >> structures are populated. In this context the links between DT 
> >> nodes are
> >> represented as pointers to platdata structures, and there is no 
> >> clear way
> >> to access to the device which owns the structure.
> >>
> >> This patch implements a set of functions:
> >>
> >> - device_find_by_platdata
> >> - uclass_find_device_by_platdata
> >>
> >> to access to the device.
> >>
> >> Signed-off-by: Walter Lozano
> >> ---
> >>   drivers/core/device.c| 19 +++
> >>   drivers/core/uclass.c| 34 
> >> ++
> >>   include/dm/device.h  |  2 ++
> >>   include/dm/uclass-internal.h |  3 +++
> >>   include/dm/uclass.h  |  2 ++
> >>   5 files changed, 60 insertions(+)
> > This is interesting. Could you also add the motivation for this? 
> > It's
> > not clear to me who would call this function.
>  I have been reviewing the OF_PLATDATA support as an R project, in 
>  this context, in order to have
>  a better understanding on the possibilities and limitations I 
>  decided to add its support to iMX6,
>  more particularly to the MMC drivers. The link issue arises when I 
>  tried to setup the GPIO for
>  Card Detection, which is trivial when DT is available. However, when 
>  OF_PLATDATA is enabled
>  this seems, at least for me, not straightforward.
> 
>  In order to overcome this limitation I think that having a set of 
>  functions to find/get devices
>  based on platdata could be useful. Of course, there might be a 
>  better approach/idea, so that is
>  the motivation for this RFC.
> 
>  An example of the usage could be
> 
>  #if CONFIG_IS_ENABLED(DM_GPIO)
> 
>   struct udevice *gpiodev;
> 
>   ret = uclass_get_device_by_platdata(UCLASS_GPIO, (void 
>  *)dtplat->cd_gpios->node, );
> 
>   if (ret)
>   return ret;
> 
>   ret = gpio_dev_request_index(gpiodev, gpiodev->name, 
>  "cd-gpios",
>    dtplat->cd_gpios->arg[0], 
>  GPIOD_IS_IN,
>    dtplat->cd_gpios->arg[1], 
>  >cd_gpio);
> 
>   if (ret)
>   return ret;
> 
>  #endif
> 
>  This is part of my current work, a series of patches to add 
>  OF_PLATDATA support as explained.
> 
>  Does this make sense to you?
> >>> Not yet :-)
> >>>
> >>> What is the context of this call? Typically dtplat is only available
> >>> in the driver that includes it.
> >> Sorry for not being clear enough. I'm working in a patchset that needs
> >> some clean up, that is the reason I didn't send it yet. I'll try to
> >> clarify, but if you think it could be useful to share it, please let me
> >> know.
> >>
> >>> What driver is the above code in? Is it for MMC that needs a GPIO to
> >>> function? I'll assume it is for now.
> >> The driver on which I'm working in is drivers/mmc/fsl_esdhc_imx.c, I'm
> >> adding support for OF_PLATDATA to it, and in this sense trying to get
> >> the GPIOs used for CD to be requested.
> >>
> >>> Then the weird thing is that we are accessing the dtplat of another
> >>> device. It's a clever technique but I wonder if we can find another
> >>> way.
> >>>
> >>> If you see 

Re: [PATCH v6 10/29] pci: Adjust dm_pci_read_bar32() to return errors correctly

2020-04-09 Thread Simon Glass
On Thu, 9 Apr 2020 at 10:28, Simon Glass  wrote:
>
> At present if reading a BAR returns 0x then the value is masked
> and a different value is returned. This makes it harder to detect the
> problem when debugging.
>
> Update the function to avoid masking in this case.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Bin Meng 
> Reviewed-by: Wolfgang Wallner 
> ---
>
> Changes in v6:
> - Rework commit message to avoid mention of missing device
>
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
>
>  drivers/pci/pci-uclass.c | 9 -
>  1 file changed, 8 insertions(+), 1 deletion(-)

Andy let me add your tag based on your email on the other v6 patch.

Reviewed-by: Andy Shevchenko 


Re: [RFC 1/7] mmc: fsl_esdhc_imx: add OF_PLATDATA support

2020-04-09 Thread Walter Lozano

Hi Simon,

On 8/4/20 00:14, Simon Glass wrote:

Hi Walter,

On Tue, 7 Apr 2020 at 14:05, Walter Lozano  wrote:

Hi Simon,

Thank you for taking the time to review this series.

On 6/4/20 00:42, Simon Glass wrote:

Hi Walter,

On Sun, 29 Mar 2020 at 21:32, Walter Lozano  wrote:

Signed-off-by: Walter Lozano
---
   drivers/mmc/fsl_esdhc_imx.c | 46 +
   1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
index 4900498e9b..761a4b46e9 100644
--- a/drivers/mmc/fsl_esdhc_imx.c
+++ b/drivers/mmc/fsl_esdhc_imx.c
@@ -29,6 +29,8 @@
   #include 
   #include 
   #include 
+#include 
+#include 

   #if !CONFIG_IS_ENABLED(BLK)
   #include "mmc_private.h"
@@ -98,6 +100,11 @@ struct fsl_esdhc {
   };

   struct fsl_esdhc_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+   /* Put this first since driver model will copy the data here */
+   struct dtd_fsl_imx6q_usdhc dtplat;
+#endif
+
  struct mmc_config cfg;
  struct mmc mmc;
   };
@@ -1377,14 +1384,18 @@ static int fsl_esdhc_probe(struct udevice *dev)
  struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  struct fsl_esdhc_priv *priv = dev_get_priv(dev);
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
  const void *fdt = gd->fdt_blob;
  int node = dev_of_offset(dev);
+   fdt_addr_t addr;
+#else
+   struct dtd_fsl_imx6q_usdhc *dtplat = >dtplat;
+#endif
  struct esdhc_soc_data *data =
  (struct esdhc_soc_data *)dev_get_driver_data(dev);
   #if CONFIG_IS_ENABLED(DM_REGULATOR)
  struct udevice *vqmmc_dev;
   #endif
-   fdt_addr_t addr;
  unsigned int val;
  struct mmc *mmc;
   #if !CONFIG_IS_ENABLED(BLK)
@@ -1392,14 +1403,23 @@ static int fsl_esdhc_probe(struct udevice *dev)
   #endif
  int ret;

+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+   priv->esdhc_regs = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
+   val = plat->dtplat.bus_width;
+   if (val == 8)
+   priv->bus_width = 8;
+   else if (val == 4)
+   priv->bus_width = 4;
+   else
+   priv->bus_width = 1;
+   priv->non_removable = 1;
+#else
  addr = dev_read_addr(dev);
  if (addr == FDT_ADDR_T_NONE)
  return -EINVAL;
  priv->esdhc_regs = (struct fsl_esdhc *)addr;
  priv->dev = dev;
  priv->mode = -1;
-   if (data)
-   priv->flags = data->flags;

  val = dev_read_u32_default(dev, "bus-width", -1);
  if (val == 8)
@@ -1462,7 +1482,9 @@ static int fsl_esdhc_probe(struct udevice *dev)
  priv->vs18_enable = 1;
  }
   #endif
-
+#endif
+   if (data)
+   priv->flags = data->flags;
  /*
   * TODO:
   * Because lack of clk driver, if SDHC clk is not enabled,
@@ -1513,9 +1535,11 @@ static int fsl_esdhc_probe(struct udevice *dev)
  return ret;
  }

+#if !CONFIG_IS_ENABLED(OF_PLATDATA)

Maybe can use if() for this one?

Thank you for the suggestion


  ret = mmc_of_parse(dev, >cfg);
  if (ret)
  return ret;
+#endif

  mmc = >mmc;
  mmc->cfg = >cfg;
@@ -1648,4 +1672,18 @@ U_BOOT_DRIVER(fsl_esdhc) = {
  .platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
  .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
   };
+
+#if CONFIG_IS_ENABLED(OF_PLATDATA)

Don't you already have a U_BOOT_DRIVER declaration?

You may need to change the name of your existing driver though (see
of-platdata docs).

So if it is because of that, please add a comment.

I have my doubts regarding this issue. As I see, this driver is used by
many different DT with different compatible strings, so I'm thinking in
trying to find a more generic approach. Would it be useful to have a
more elaborated solution searching for the compatible string when
matching drivers with device?

Yes I think so.

Actually searching for a string is not great anyway. I wonder if we
can use the linker-list idea in the previous email somehow?



I'm sure I' understand the idea you try to share with me. Sorry, I 
understand that one limitation of the current implementation of 
OF_PLATDATA is the fact that the U_BOOT_DRIVER name should match the one 
used as first entry in DT. As in particular this driver has several 
compatible


    { .compatible = "fsl,imx53-esdhc", },
    { .compatible = "fsl,imx6ul-usdhc", },
    { .compatible = "fsl,imx6sx-usdhc", },
    { .compatible = "fsl,imx6sl-usdhc", },
    { .compatible = "fsl,imx6q-usdhc", },
    { .compatible = "fsl,imx7d-usdhc", .data = 
(ulong)_imx7d_data,},

    { .compatible = "fsl,imx7ulp-usdhc", },
    { .compatible = "fsl,imx8qm-usdhc", .data = 
(ulong)_imx8qm_data,},
    { .compatible = "fsl,imx8mm-usdhc", .data = 

Re: [RFC] dm: uclass: add functions to get device by platdata

2020-04-09 Thread Walter Lozano

Hi Simon,

On 8/4/20 00:14, Simon Glass wrote:

Hi Walter,

On Tue, 7 Apr 2020 at 14:05, Walter Lozano  wrote:

Hi Simon,

On 6/4/20 00:43, Simon Glass wrote:

Hi Walter,

On Mon, 9 Mar 2020 at 12:27, Walter Lozano   wrote:

Hi Simon

On 6/3/20 17:32, Simon Glass wrote:

Hi Walter,

On Fri, 6 Mar 2020 at 09:10, Walter Lozano   wrote:

Hi Simon,

Thanks again for taking the time to check my comments.

On 6/3/20 10:17, Simon Glass wrote:

Hi Walter,

On Thu, 5 Mar 2020 at 06:54, Walter Lozano   wrote:

Hi Simon,

Thanks for taking the time to check for my comments

On 4/3/20 20:11, Simon Glass wrote:


Hi Walter,

On Wed, 4 Mar 2020 at 12:40, Walter Lozano   wrote:

When OF_PLATDATA is enabled DT information is parsed and platdata
structures are populated. In this context the links between DT nodes are
represented as pointers to platdata structures, and there is no clear way
to access to the device which owns the structure.

This patch implements a set of functions:

- device_find_by_platdata
- uclass_find_device_by_platdata

to access to the device.

Signed-off-by: Walter Lozano
---
  drivers/core/device.c| 19 +++
  drivers/core/uclass.c| 34 ++
  include/dm/device.h  |  2 ++
  include/dm/uclass-internal.h |  3 +++
  include/dm/uclass.h  |  2 ++
  5 files changed, 60 insertions(+)

This is interesting. Could you also add the motivation for this? It's
not clear to me who would call this function.

I have been reviewing the OF_PLATDATA support as an R project, in this 
context, in order to have
a better understanding on the possibilities and limitations I decided to add 
its support to iMX6,
more particularly to the MMC drivers. The link issue arises when I tried to 
setup the GPIO for
Card Detection, which is trivial when DT is available. However, when 
OF_PLATDATA is enabled
this seems, at least for me, not straightforward.

In order to overcome this limitation I think that having a set of functions to 
find/get devices
based on platdata could be useful. Of course, there might be a better 
approach/idea, so that is
the motivation for this RFC.

An example of the usage could be

#if CONFIG_IS_ENABLED(DM_GPIO)

 struct udevice *gpiodev;

 ret = uclass_get_device_by_platdata(UCLASS_GPIO, (void 
*)dtplat->cd_gpios->node, );

 if (ret)
 return ret;

 ret = gpio_dev_request_index(gpiodev, gpiodev->name, "cd-gpios",
  dtplat->cd_gpios->arg[0], GPIOD_IS_IN,
  dtplat->cd_gpios->arg[1], 
>cd_gpio);

 if (ret)
 return ret;

#endif

This is part of my current work, a series of patches to add OF_PLATDATA support 
as explained.

Does this make sense to you?

Not yet :-)

What is the context of this call? Typically dtplat is only available
in the driver that includes it.

Sorry for not being clear enough. I'm working in a patchset that needs
some clean up, that is the reason I didn't send it yet. I'll try to
clarify, but if you think it could be useful to share it, please let me
know.


What driver is the above code in? Is it for MMC that needs a GPIO to
function? I'll assume it is for now.

The driver on which I'm working in is drivers/mmc/fsl_esdhc_imx.c, I'm
adding support for OF_PLATDATA to it, and in this sense trying to get
the GPIOs used for CD to be requested.


Then the weird thing is that we are accessing the dtplat of another
device. It's a clever technique but I wonder if we can find another
way.

If you see drivers/mmc/rockchip_sdhci.c it has:

ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, );

So I wonder if we need gpio_dev_request_by_platdata()?

Thanks for pointing to this example, as I saw it before starting to work
on these functions and had some doubts. I'll use it in the next
paragraph to share my thoughts and the motivation of my work.

From my understanding, clk_get_by_index_platdata in this context can
only get a UCLASS_CLK device with id == 0. Is this correct?

If it is so, this will only allow us to use this function if we know in
advance that the UCLASS_CLK device has index 0.

How can we get the correct UCLASS_CLK device in case of multiple instances?

We actually can't support that at present. I think we would need to
change the property to be an array, like:

  clocks = [
  [, CLK_ID_SPI],
  [, CLK_ID_I2C, 23],
]

which would need a fancier dtoc. Perhaps we should start by
upstreaming that tool.

In this case, are you suggesting to replace CLK_ID_SPI and CLK_ID_I2C
with a integer calculated by dtoc based on the clocks entries available?
If I understand correctly, what we need is to get the index parameter to
feed the function uclass_find_device. Is this correct?

No, I was thinking that it would be the same CLK_ID_SPI value from the binding.

We currently have (see the 

Re: [PATCH 20/26 v6] spl: spl_nor: Move legacy image loading into spl_legacy.c

2020-04-09 Thread Daniel Schwierzeck



Am 08.04.20 um 10:09 schrieb Stefan Roese:
> Move the legacy image loading into spl_legacy.c. This makes it easier
> to extend the legacy image handling with new features that other
> SPL loaders might use (e.g. spl_spi.c etc).
> 
> No functional change indended.
> 
> Signed-off-by: Stefan Roese 
> Cc: Weijie Gao 
> Cc: Simon Goldschmidt 
> ---
> Changes in v6:
> - New patch
> 
>  common/spl/spl_legacy.c | 17 +
>  common/spl/spl_nor.c| 34 +-
>  include/spl.h   | 14 ++
>  3 files changed, 48 insertions(+), 17 deletions(-)
> 
> diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
> index 772135193e..d0fc4b111e 100644
> --- a/common/spl/spl_legacy.c
> +++ b/common/spl/spl_legacy.c
> @@ -51,3 +51,20 @@ int spl_parse_legacy_header(struct spl_image_info 
> *spl_image,
>  
>   return 0;
>  }
> +
> +int spl_load_legacy_img(struct spl_image_info *spl_image,
> + const struct image_header *header,
> + uintptr_t dataptr, struct spl_load_info *info)
> +{
> + int ret;
> +
> + ret = spl_parse_image_header(spl_image, header);
> + if (ret)
> + return ret;
> +
> + dataptr = (uintptr_t)header + sizeof(struct image_header);

how should this work? You call this function with

spl_load_legacy_img(spl_image, , dataptr, );

so "header" points to the copy on the stack. "dataptr" already holds the
address of the SPL payload. If you overwrite "dataptr" now, it will
point to the stack area after the header copy.


> + info->read(info, dataptr, spl_image->size,
> +(void *)(unsigned long)spl_image->load_addr);
> +
> + return 0;
> +}
> diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c
> index cb8e06fe1f..d55165b772 100644
> --- a/common/spl/spl_nor.c
> +++ b/common/spl/spl_nor.c
> @@ -24,11 +24,8 @@ unsigned long __weak spl_nor_get_uboot_base(void)
>  static int spl_nor_load_image(struct spl_image_info *spl_image,
> struct spl_boot_device *bootdev)
>  {
> - int ret;
>   __maybe_unused const struct image_header *header;
>   __maybe_unused struct spl_load_info load;
> - struct image_header hdr;
> - uintptr_t dataptr;
>  
>   /*
>* Loading of the payload to SDRAM is done with skipping of
> @@ -45,6 +42,8 @@ static int spl_nor_load_image(struct spl_image_info 
> *spl_image,
>   header = (const struct image_header *)CONFIG_SYS_OS_BASE;
>  #ifdef CONFIG_SPL_LOAD_FIT
>   if (image_get_magic(header) == FDT_MAGIC) {
> + int ret;
> +
>   debug("Found FIT\n");
>   load.bl_len = 1;
>   load.read = spl_nor_load_read;
> @@ -63,6 +62,7 @@ static int spl_nor_load_image(struct spl_image_info 
> *spl_image,
>  #endif
>   if (image_get_os(header) == IH_OS_LINUX) {
>   /* happy - was a Linux */
> + int ret;
>  
>   ret = spl_parse_image_header(spl_image, header);
>   if (ret)
> @@ -95,11 +95,9 @@ static int spl_nor_load_image(struct spl_image_info 
> *spl_image,
>   debug("Found FIT format U-Boot\n");
>   load.bl_len = 1;
>   load.read = spl_nor_load_read;
> - ret = spl_load_simple_fit(spl_image, ,
> -   spl_nor_get_uboot_base(),
> -   (void *)header);
> -
> - return ret;
> + return spl_load_simple_fit(spl_image, ,
> +spl_nor_get_uboot_base(),
> +(void *)header);
>   }
>  #endif
>   if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
> @@ -109,17 +107,19 @@ static int spl_nor_load_image(struct spl_image_info 
> *spl_image,
> spl_nor_get_uboot_base());
>   }
>  
> - ret = spl_parse_image_header(spl_image,
> - (const struct image_header *)spl_nor_get_uboot_base());
> - if (ret)
> - return ret;
> + if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
> + struct image_header hdr;
> + uintptr_t dataptr;
>  
> - /* Payload image may not be aligned, so copy it for safety */
> - memcpy(, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
> - dataptr = spl_nor_get_uboot_base() + sizeof(struct image_header);
> + /* Payload image may not be aligned, so copy it for safety */
> + memcpy(, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
> + dataptr = spl_nor_get_uboot_base() + sizeof(hdr);
>  
> - memcpy((void *)(unsigned long)spl_image->load_addr,
> -(void *)dataptr, spl_image->size);
> + /* Legacy image handling */
> + load.bl_len = 1;
> + load.read = spl_nor_load_read;
> + return 

RE: [PATCH v2 1/2] arm: stm32mp: activate data cache in SPL and before relocation

2020-04-09 Thread Patrick DELAUNAY
Dear Marek,

> From: Marek Vasut 
> Sent: vendredi 3 avril 2020 23:32
> 
> On 4/3/20 11:25 AM, Patrick Delaunay wrote:
> [...]
> > diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
> > index 36a9205819..c22c1a9bbc 100644
> > --- a/arch/arm/mach-stm32mp/cpu.c
> > +++ b/arch/arm/mach-stm32mp/cpu.c
> > @@ -75,6 +75,12 @@
> >  #define PKG_SHIFT  27
> >  #define PKG_MASK   GENMASK(2, 0)
> >
> > +/*
> > + * early TLB into the .data section so that it not get cleared
> > + * with 16kB allignment (see TTBR0_BASE_ADDR_MASK)  */
> > +u8 early_tlb[PGTABLE_SIZE] __section(".data") __aligned(0x4000);
> 
> Can you early-malloc this one ?

I try to early maloc and it is failing because my code in arch_cpu_init() is 
executed before 
the early poll initialization done in spl_common_init () called by 
spl_early_init()
So it too late for my use case

And if I initialise the MMU and the cache after this function it is too late, as
dm_init_and_scan and fdt parsin is also called in spl_common_init()

> (why do you need this in __section("data") ?)

I try to use .bss and it is failing because the bss is resetted to 0 in SPL 
after board_init_f, and the MMU is cleared without notice.

In fact BBS is not available, board_init_f() can use only stack variables
and global_data (see README:258).

When I investigate the issue, I found CONFIG_SPL_EARLY_BSS
that explain this point :

config SPL_EARLY_BSS
depends on ARM && !ARM64
bool "Allows initializing BSS early before entering board_init_f"
help
  On some platform we have sufficient memory available early on to
  allow setting up and using a basic BSS prior to entering
  board_init_f. Activating this option will also de-activate the
  clearing of BSS during the SPL relocation process, thus allowing
  to carry state from board_init_f to board_init_r by way of BSS.

So it is s compromise between harcoded addred (end of SYSRAM)
or glabal variable in .data section

V2 patch with .data seems more elegant for me (it avoid assumption on
U-Boot size for preloc case).

And if you have size issue for SPL you can deactivate cache for SPL only
(CONFIG_SPL_SYS_DCACHE_OFF).

> [...]

Regards

Patrick


Re: [PATCH 22/26 v6] spl: spl_legacy: Add cache flush after reading U-Boot image

2020-04-09 Thread Simon Goldschmidt
Am 09.04.2020 um 09:43 schrieb Stefan Roese:
> On 09.04.20 09:29, Simon Goldschmidt wrote:
>> Am 08.04.2020 um 10:09 schrieb Stefan Roese:
>>> From: Weijie Gao 
>>>
>>> Flush the cache after reading of the U-Boot proper into SDRAM so that
>>> it can be started.
>>>
>>> This is needed on some platforms, e.g. MT76x8.
>>>
>>> Signed-off-by: Weijie Gao 
>>> Signed-off-by: Stefan Roese 
>>> Cc: Weijie Gao 
>>> Cc: Simon Goldschmidt 
>>> ---
>>> Changes in v6:
>>> - New patch
>>>
>>>   common/spl/spl_legacy.c | 4 
>>>   1 file changed, 4 insertions(+)
>>>
>>> diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
>>> index 2cd2a74a4c..e320206098 100644
>>> --- a/common/spl/spl_legacy.c
>>> +++ b/common/spl/spl_legacy.c
>>> @@ -4,6 +4,7 @@
>>>*/
>>>   
>>>   #include 
>>> +#include 
>>>   #include 
>>>   #include 
>>>   
>>> @@ -108,5 +109,8 @@ int spl_load_legacy_img(struct spl_image_info 
>>> *spl_image,
>>> return -EINVAL;
>>> }
>>>   
>>> +   /* Flush cache of loaded U-Boot image */
>>> +   flush_cache((unsigned long)spl_image->load_addr, spl_image->size);
>>> +
>>
>> I failed to find the mail, but haven't we discussed moving this cache
>> flush to your arch before starting a binary?
> 
> I don't remember such an agreement. But I don't object in general.

Ok, maybe I remember wrong then.

> 
>> I cannot see this being required or implemented for non-legacy images,
>> and it still seems wrong here.
> 
> Its pretty common when an OS image is loaded and booted, that the cache
> is flushed before running code from it.

Yes, of course. I can follow you there. I'm just curious why it's added
here and only for legacy images.

> 
> But I can rework this to add some empty weak function (I don't see an
> easy better way) to do this platform specific image handling before its
> booted. Or do you have a better idea on how to handle this?

I don't know. And I'm not totally opposed to this patch. I just think
it's a strange thing to do here. If you need it, I think it should be in
a more central place. Surely, you'd need it for non-legacy images, too?

I could imagine this being added to jump_to_image_no_args(). That way,
we would have the cache flush in a central place instead of stumbling
accross it again in the future (e.g. for non-legacy images). OTOH, I'm
not sure that would be free of side-effects...?

Regards,
Simon


> 
> Thanks,
> Stefan
> 



RE: [PATCH v2 2/2] arm: stm32mp: activate data cache on DDR in SPL

2020-04-09 Thread Patrick DELAUNAY
Dear Marek,

> From: Marek Vasut 
> Sent: vendredi 3 avril 2020 23:33
> 
> On 4/3/20 11:25 AM, Patrick Delaunay wrote:
> > Activate cache on DDR to improves the accesses to DDR used by SPL:
> > - CONFIG_SPL_BSS_START_ADDR
> > - CONFIG_SYS_SPL_MALLOC_START
> >
> > Cache is configured only when DDR is fully initialized, to avoid
> > speculative access and issue in get_ram_size().
> > Data cache is deactivated at the end of SPL, to flush the data cache
> > and the TLB.
> >
> > Signed-off-by: Patrick Delaunay 
> > ---
> >
> > Changes in v2:
> > - new
> >

[...]

> > +void spl_board_prepare_for_boot(void) {
> > +   dcache_disable();
> > +   debug("SPL bye\n");
> > +}
> > +
> > +void spl_board_prepare_for_boot_linux(void)
> > +{
> > +   dcache_disable();
> > +   debug("SPL bye\n");
> 
> Is the debug() statement really needed ? I think the common SPL code already
> has some.

Not needed, I will drop them in V3.

Patrick


RE: [PATCH 2/3] arm: caches: add DCACHE_DEFAULT_OPTION

2020-04-09 Thread Patrick DELAUNAY
Dear Marek,

> Sent: jeudi 9 avril 2020 12:21
> To: Patrick DELAUNAY ; u-boot@lists.denx.de
> 
> On 4/9/20 12:01 PM, Patrick DELAUNAY wrote:
> > Dear Marek,
> 
> Hi,
> 
> >> From: Uboot-stm32 
> >> On Behalf Of Patrick DELAUNAY
> >>
> >> Dear Marek,
> >>
> >>> From: Marek Vasut 
> >>> Sent: vendredi 3 avril 2020 23:29
> >>>
> >>> On 4/3/20 10:28 AM, Patrick Delaunay wrote:
>  Add the new flags DCACHE_DEFAULT_OPTION to define the default
>  option to use according the compilation flags
>  CONFIG_SYS_ARM_CACHE_WRITETHROUGH or
> >>> CONFIG_SYS_ARM_CACHE_WRITEALLOC.
> >>>
> >>> Can't you unify these macros into a single Kconfig "select"
> >>> statement instead , and then just select the matching cache configuration 
> >>> in
> Kconfig ?
> >>
> >> Yes I will try, with 2 steps
> >> - migrate existing CONFIG_SYS_ARM_CACHE_ in Kconfig
> >
> > First step done...
> > I will push it as a separate patchset I think.
> >
> >> - add new option CONFIG_SYS_ARM_CACHE_OPTION
> >
> > In fact it is to difficult to use select because each defines
> > DCACHE_XXX value can have several values
> >
> > they are build according CONFIG_ARM64 / LPAE
> >
> > But, I can't use this define in Kconfig
> >
> > I try :
> > option  ARM_OPTION
> > int "option"
> > default DCACHE_WRITETHROUGHT if
> CONFIG_SYS_ARM_CACHE_WRITETHROUGH
> > default DCACHE_ WRITEALLOC if CONFIG_SYS_ARM_CACHE_
> WRITEALLOC
> > default DCACHE_WRITEBACK if
> CONFIG_SYS_ARM_CACHE_WRITEBACK
> >
> > int and hex is invalid, and string can't be use with "".
> >
> > And I don't found way to build it automatically when option is activated.
> >
> > Any idea ?
> 
> Maybe you can have a select in the Kconfig to set some differently named 
> option,
> e.g.
> 
> DCACHE_MODE_WRITE{THROUGH,ALLOC,BACK}
> 
> and then an ifdef in some header file, e.g.
> 
> #ifdef CONFIG_DCACHE_MODE_WRITETHROUGH
> #define ARM_CACHE_MODE DCACHE_WRITETHROUGH ...
> 
> And then use ARM_CACHE_MODE where you need a value and
> CONFIG_DCACHE_MODE{...} where you need a config option check.
> 
> Does this work ?

I try with string and default (as select is allowed on for bolean or trisate),
And I failed :-<

I don't found a way to have the de-stringficate the KConfig option
to generated the correct define

config SYS_ARM_CACHE_POLICY
string "Name of the ARM data write cache policy"
default WRITEBACK if SYS_ARM_CACHE_WRITEBACK
default WRITETHROUGH if SYS_ARM_CACHE_WRITEBACK
default WRITEALLOC if SYS_ARM_CACHE_WRITEALLOC

#define DCACHE_DEFAULT_OPTION   DCACHE_ ## CONFIG_SYS_ARM_CACHE_POLICY

=> error: ‘DCACHE_CONFIG_SYS_ARM_CACHE_POLICY’ undeclared (first use in this 
function); did you mean ‘CONFIG_SYS_ARM_CACHE_POLICY’?

#define DCACHE_OPTION(s)DCACHE_ ## CONFIG_SYS_ARM_CACHE_POLICY

#define DCACHE_DEFAULT_OPTION   DCACHE_OPTION(CONFIG_SYS_ARM_CACHE_POLICY)

arch/arm/include/asm/system.h:488:26: error: ‘DCACHE_’ undeclared (first use in 
this function); did you mean ‘DCACHE_OFF’?
arch/arm/lib/cache-cp15.c:99:25: error: expected ‘)’ before string constant

The stringification is possible but not the inverse operation (remove the 
quote)...

In my .config, CONFIG_SYS_ARM_CACHE_POLICY="WRITEBACK"

Regards

Patrick




Re: [PATCH v6 12/29] dm: core: Add basic ACPI support

2020-04-09 Thread Andy Shevchenko
On Thu, Apr 09, 2020 at 10:27:38AM -0600, Simon Glass wrote:
> ACPI (Advanced Configuration and Power Interface) is a standard for
> specifying information about a platform. It is a little like device
> tree but the bindings are part of the specification and it supports an
> interpreted bytecode language.
> 
> Driver model does not use ACPI for U-Boot's configuration, but it is
> convenient to have it support generation of ACPI tables for passing to
> Linux, etc.
> 
> As a starting point, add an optional set of ACPI operations to each
> device. Initially only a single operation is available, to obtain the
> ACPI name for the device. More operations are added later.
> 
> Enable ACPI for sandbox to ensure build coverage and so that we can add
> tests.
> 

Both looks good to me now, thanks!

> Reviewed-by: Bin Meng 
> Reviewed-by: Wolfgang Wallner 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v6:
> - Use ACPI_NAME_LEN in acpi_copy_name since we add the nul anyway
> 
> Changes in v5:
> - Capitalise ACPI_OPS_PTR since it includes a comma
> 
> Changes in v4: None
> Changes in v3:
> - Drop 'Intel' from 'Intel ACPI'
> - Reword commit message to drop the bit about ACPI being complicated
> - Compute ACPI_NAME_MAX from ACPI_NAME_LEN
> - Rename acpi_return_name() to acpi_copy_name()
> - Use strncpy() instead of strcpy() in acpi_copy_name()
> 
> Changes in v2:
> - Move LOGC_ACPI definition to this patch
> 
>  configs/tools-only_defconfig |  1 +
>  drivers/core/Kconfig |  9 +
>  drivers/core/Makefile|  1 +
>  drivers/core/acpi.c  | 33 
>  include/dm/acpi.h| 73 
>  include/dm/device.h  |  5 +++
>  include/log.h|  2 +
>  7 files changed, 124 insertions(+)
>  create mode 100644 drivers/core/acpi.c
>  create mode 100644 include/dm/acpi.h
> 
> diff --git a/configs/tools-only_defconfig b/configs/tools-only_defconfig
> index 6ca50dc5fd3..2811b2cd37d 100644
> --- a/configs/tools-only_defconfig
> +++ b/configs/tools-only_defconfig
> @@ -26,3 +26,4 @@ CONFIG_SYSRESET=y
>  # CONFIG_VIRTIO_PCI is not set
>  # CONFIG_VIRTIO_SANDBOX is not set
>  # CONFIG_EFI_LOADER is not set
> +# CONFIG_ACPIGEN is not set
> diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig
> index 3b95b5387b9..a3b03993423 100644
> --- a/drivers/core/Kconfig
> +++ b/drivers/core/Kconfig
> @@ -261,4 +261,13 @@ config DM_DEV_READ_INLINE
>   bool
>   default y if !OF_LIVE
>  
> +config ACPIGEN
> + bool "Support ACPI table generation in driver model"
> + default y if SANDBOX || GENERATE_ACPI_TABLE
> + help
> +   This option enables generation of ACPI tables using driver-model
> +   devices. It adds a new operation struct to each driver, to support
> +   things like generating device-specific tables and returning the ACPI
> +   name of a device.
> +
>  endmenu
> diff --git a/drivers/core/Makefile b/drivers/core/Makefile
> index bce7467da1d..c707026a3a0 100644
> --- a/drivers/core/Makefile
> +++ b/drivers/core/Makefile
> @@ -3,6 +3,7 @@
>  # Copyright (c) 2013 Google, Inc
>  
>  obj-y+= device.o fdtaddr.o lists.o root.o uclass.o util.o
> +obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o
>  obj-$(CONFIG_DEVRES) += devres.o
>  obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE)+= device-remove.o
>  obj-$(CONFIG_$(SPL_)SIMPLE_BUS)  += simple-bus.o
> diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
> new file mode 100644
> index 000..ba50d688fef
> --- /dev/null
> +++ b/drivers/core/acpi.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Core driver model support for ACPI table generation
> + *
> + * Copyright 2019 Google LLC
> + * Written by Simon Glass 
> + */
> +
> +#define LOG_CATEOGRY LOGC_ACPI
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +int acpi_copy_name(char *out_name, const char *name)
> +{
> + strncpy(out_name, name, ACPI_NAME_LEN);
> + out_name[ACPI_NAME_LEN] = '\0';
> +
> + return 0;
> +}
> +
> +int acpi_get_name(const struct udevice *dev, char *out_name)
> +{
> + struct acpi_ops *aops;
> +
> + aops = device_get_acpi_ops(dev);
> + if (aops && aops->get_name)
> + return aops->get_name(dev, out_name);
> +
> + return -ENOSYS;
> +}
> diff --git a/include/dm/acpi.h b/include/dm/acpi.h
> new file mode 100644
> index 000..ba0813fa21c
> --- /dev/null
> +++ b/include/dm/acpi.h
> @@ -0,0 +1,73 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Core ACPI (Advanced Configuration and Power Interface) support
> + *
> + * Copyright 2019 Google LLC
> + * Written by Simon Glass 
> + */
> +
> +#ifndef __DM_ACPI_H__
> +#define __DM_ACPI_H__
> +
> +/* Allow operations to be optional for ACPI */
> +#if CONFIG_IS_ENABLED(ACPIGEN)
> +#define ACPI_OPS_PTR(_ptr)   .acpi_ops   = _ptr,
> +#else
> +#define ACPI_OPS_PTR(_ptr)
> +#endif
> +
> +/* Length of an ACPI name string, excluding nul terminator */
> +#define 

RE: [PATCH V3] ARM: dts: stm32: Add KS8851-16MLL ethernet on FMC2

2020-04-09 Thread Patrick DELAUNAY
Dear Marek,

> From: Marek Vasut 
> Sent: jeudi 9 avril 2020 13:27
> 
> On 4/1/20 3:30 PM, Patrick DELAUNAY wrote:
> > Hi Marek,
> 
> Hi,
> 
> [...]
> 
> >> + {
> >> +  /* These should bound to FMC2 bus driver, but we do not have one */
> >
> > As temporarily solution (waiting final solution and real FMC2 bus
> > driver) can you define a NO_OP in board device associated to existing
> > compatible = "st,stm32mp15-fmc2"
> 
> NO_OP ?

Sorry, UCLASS_NOP

After debate with Christophe, I agree that i sis other complicated
for temporarily solution. 
 
> >> +  pinctrl-0 = <_pins_b>;
> >> +  pinctrl-1 = <_sleep_pins_b>;
> >> +  pinctrl-names = "default", "sleep";
> >> +
> >> +  fmc_pins_b: fmc-0 {
> >> +  pins1 {
> > [...]
> >> +  };
> >> +  };
> >> +
> >> +  fmc_sleep_pins_b: fmc-sleep-0 {
> >> +  pins {
> > [...]
> >> +  };
> >> +  };
> >> +};
> >> +
> >>   {
> >>u-boot,dm-pre-reloc;
> >>  };
> >
> > For example
> >
> >  {
> > pinctrl-names = "default", "sleep";
> > pinctrl-0 = <& fmc_pins_b>;
> > pinctrl-1 = <& fmc_sleep_pins_b>;
> > status = "okay";
> > #address-cells = <1>;
> > #size-cells = <0>;
> > };
> >
> > static const struct udevice_id stm32_fmc2_bus_ids[] = {
> > {.compatible = "st,stm32mp15-fmc2},
> > { }
> > };
> >
> > U_BOOT_DRIVER(stm32_fmc2_bus) = {
> > .name   = "stm32mp15-fmc2-ids",
> > .id = UCLASS_NOP,
> > .of_match   = stm32_fmc2_bus_ids,
> > .bind   = stm32_fmc2_bus,
> > };
> 
> That looks like a hack, it would collide with the actual FMC2 driver and it 
> seems
> the FMC2 DT compatible string is not even stable yet (cfr the Linux patches). 
> So I
> am reluctant to do anything like depending on the FMC DT bindings thus far.

You are aligned with Christophe, he push me to accept your temporarily solution.

[...]
> > Use clk and reset driver model and DT, for example:
> >
> > struct clk clk;
> > struct reset_ctl reset;
> >
> > clk_get_by_index_nodev(ofnode, 0,  ;
> > clk_get_by_index_nodev(ofnode, 0,  );
> 
> This very much looks like I can just write the entire bus driver by now, 
> instead of
> just writing these few registers in a real simple way, until the bus driver 
> exists.
> 
> But since the bindings aren't stable, I am not very inclined to do that.

I am convinced now (thanks to Christophe) to keep it simple as it is a 
temporarily
solution.

Reviewed-by: Patrick Delaunay 

Thanks

Patrick

> 
> [...]


Re: [PATCH] imx: Fix imx8m FIT script issue

2020-04-09 Thread Tom Rini
On Thu, Apr 09, 2020 at 01:44:43AM -0700, Ye Li wrote:

> The FIT config node has reversed ATF and u-boot: ATF is set to 'firmware' but
> u-boot is set to 'loadables'.
> This script can work previously because spl fit driver wrongly appends fdt to
> all loadable images. With the issue fixed in commit 9d15d1d1c24f ("Revert
> "common: spl_fit: Default to IH_OS_U_BOOT if FIT_IMAGE_TINY enabled"") the
> u-boot in 'loadables' does not have fdt appended and fails to work.  So 
> correct
> the script by moving u-boot to 'firmware' and ATF to 'loadables'.
> 
> Signed-off-by: Ye Li 
> Reported-by: Matt Porter 
> Tested-by: Matt Porter 

Rewording the commit per Fabio's suggestion with a few other tweaks as I
read over the code to the above, and taking directly also at his
suggestion.

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [RFC PATCH v2 05/13] mmc: add nexell driver

2020-04-09 Thread Stefan B.

Hi,

see below my answers to your questions.

Regards
Stefan Bosch


Hi,

thanks a lot for your reply. As you already guessed I have ported the 
outdated U-Boot from FriendlyARM, see:

https://github.com/friendlyarm/u-boot/tree/nanopi2-v2016.01

The original MMC-driver has been nexell_dw_mmc.c, so I renamed it to 
nexell_dw_mmc_dm.c after changing to DM.


I will have a closer look at your suggestions and give you feedback ASAP.


Regards
Stefan Bosch


Am 02.04.20 um 13:03 schrieb Jaehoon Chung:

Hi,

On 3/28/20 6:43 PM, Stefan Bosch wrote:

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).


It doesn't need to add postfix as _dm.


Ok, I have renamed it to nexell_dw_mmc.c.



Signed-off-by: Stefan Bosch 
---

Changes in v2:
- commit "i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)" splitted
   into separate commits for gpio, i2c, mmc, pwm.

  drivers/mmc/Kconfig|   6 +
  drivers/mmc/Makefile   |   1 +
  drivers/mmc/nexell_dw_mmc_dm.c | 350 +
  3 files changed, 357 insertions(+)
  create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c

diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 2f0eedc..bb8e7c0 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -253,6 +253,12 @@ config MMC_DW_SNPS
  This selects support for Synopsys DesignWare Memory Card Interface 
driver
  extensions used in various Synopsys ARC devboards.
  
+config NEXELL_DWMMC

+   bool "Nexell SD/MMC controller support"
+   depends on ARCH_NEXELL
+   depends on MMC_DW
+   default y


Not depends on DM_MMC?

You are right, I have inserted "depends on DM_MMC". I missed this when 
changing to DM.



+
  config MMC_MESON_GX
bool "Meson GX EMMC controller support"
depends on DM_MMC && BLK && ARCH_MESON
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 9c1f8e5..a7b5a7b 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_SH_MMCIF) += sh_mmcif.o
  obj-$(CONFIG_SH_SDHI) += sh_sdhi.o
  obj-$(CONFIG_STM32_SDMMC2) += stm32_sdmmc2.o
  obj-$(CONFIG_JZ47XX_MMC) += jz_mmc.o
+obj-$(CONFIG_NEXELL_DWMMC) += nexell_dw_mmc_dm.o
  
  # SDHCI

  obj-$(CONFIG_MMC_SDHCI)   += sdhci.o
diff --git a/drivers/mmc/nexell_dw_mmc_dm.c b/drivers/mmc/nexell_dw_mmc_dm.c
new file mode 100644
index 000..b06b60d
--- /dev/null
+++ b/drivers/mmc/nexell_dw_mmc_dm.c
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * Youngbok, Park 
+ *
+ * (C) Copyright 2019 Stefan Bosch 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DWMCI_CLKSEL   0x09C
+#define DWMCI_SHIFT_0  0x0
+#define DWMCI_SHIFT_1  0x1
+#define DWMCI_SHIFT_2  0x2
+#define DWMCI_SHIFT_3  0x3
+#define DWMCI_SET_SAMPLE_CLK(x)(x)
+#define DWMCI_SET_DRV_CLK(x)   ((x) << 16)
+#define DWMCI_SET_DIV_RATIO(x) ((x) << 24)
+#define DWMCI_CLKCTRL  0x114
+#define NX_MMC_CLK_DELAY(x, y, a, b)   x) & 0xFF) << 0) |\
+   (((y) & 0x03) << 16) |\
+   (((a) & 0xFF) << 8)  |\
+   (((b) & 0x03) << 24))
+
+struct nexell_mmc_plat {
+   struct mmc_config cfg;
+   struct mmc mmc;
+};
+
+struct nexell_dwmmc_priv {
+   struct clk *clk;
+   struct dwmci_host host;
+   int fifo_size;
+   bool fifo_mode;
+   int frequency;
+   u32 min_freq;
+   u32 max_freq;
+   int d_delay;
+   int d_shift;
+   int s_delay;
+   int s_shift;
+
+};
+
+struct clk *clk_get(const char *id);
+
+static void set_pin_stat(int index, int bit, int value)
+{
+#if !defined(CONFIG_SPL_BUILD)
+   nx_gpio_set_pad_function(index, bit, value);
+#else
+#if defined(CONFIG_ARCH_S5P4418) ||\
+   defined(CONFIG_ARCH_S5P6818)
+
+   unsigned long base[5] = {
+   PHY_BASEADDR_GPIOA, PHY_BASEADDR_GPIOB,
+   PHY_BASEADDR_GPIOC, PHY_BASEADDR_GPIOD,
+   PHY_BASEADDR_GPIOE,
+   };


I don't understand why gpio pin is set in mmc driver?
If nexell soc will change the gpio map and function value, does it needs to add 
other gpio control?


+
+   dw_mmc_set_pin(base[index], bit, value);
+#endif
+#endif
+}
+
+static void nx_dw_mmc_set_pin(struct dwmci_host *host)
+{
+   debug("  %s(): dev_index == %d", __func__, host->dev_index);
+
+   switch (host->dev_index) {
+   case 0:
+   set_pin_stat(0, 29, 1);
+   set_pin_stat(0, 31, 1);
+   set_pin_stat(1, 1, 1);
+   set_pin_stat(1, 3, 1);
+   set_pin_stat(1, 5, 1);
+   set_pin_stat(1, 7, 1);
+   break;
+   case 1:
+   set_pin_stat(3, 22, 

Re: [PATCH] cmd: Add test and fix bugs for dm drivers

2020-04-09 Thread Tom Rini
On Mon, Apr 06, 2020 at 10:23:09AM -0400, Sean Anderson wrote:

> Add a test for the dm drivers command. Also fix a null pointer dereference
> revealed by said test.
> 
> Signed-off-by: Sean Anderson 
> Reviewed-by: Bin Meng 
> Tested-by: Bin Meng 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


RE: [PATCH] ARM: dts: stm32: Define FMC2 base address

2020-04-09 Thread Patrick DELAUNAY
Dear,

> From: Marek Vasut 
> Sent: jeudi 9 avril 2020 13:23
> 
> On 4/1/20 3:45 PM, Patrick DELAUNAY wrote:
> > Hi Marek,
> 
> Hi,
> 
> >> From: Marek Vasut 
> >> Sent: jeudi 26 mars 2020 16:57
> >>
> >> Define FMC2 base address, for use in board files, until there is an
> >> actual FMC2 bus driver.
> >>
> >> Signed-off-by: Marek Vasut 
> >> Cc: Patrick Delaunay 
> >> Cc: Patrice Chotard 
> >> ---
> >>  arch/arm/mach-stm32mp/include/mach/stm32.h | 1 +
> >>  1 file changed, 1 insertion(+)
> >>
> >> diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h
> >> b/arch/arm/mach- stm32mp/include/mach/stm32.h index
> >> f0636005e5..62d95d7f88 100644
> >> --- a/arch/arm/mach-stm32mp/include/mach/stm32.h
> >> +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h
> >> @@ -13,6 +13,7 @@
> >>  #define STM32_RCC_BASE0x5000
> >>  #define STM32_PWR_BASE0x50001000
> >>  #define STM32_DBGMCU_BASE 0x50081000
> >> +#define STM32_FMC2_BASE   0x58002000
> >
> > For me, the address should be defined in this file only for the few
> > addresses used before device tree avaibility: I want to avoid to have all 
> > the
> device defined here.
> >
> > But normally it is not the case for FMC2, even if I understand the current 
> > need,
> without FMC2 bus driver
> > I will take this patch only it is not possible to get FMC2 address from 
> > device
> tree.
> 
> I can parse this information from the DT, but what would be the benefit?
> Slower boot due to the need to traverse DT and more complex code?

I am convinced now (thanks to Christophe) because the correct FMC bus driver is 
not yet ready...

It will be clean-up later when no more used.

Reviewed-by: Patrick Delaunay 

Thanks

Patrick




Re: [PATCH] Series-to: u-boot Cover-letter: Fix Typo error in Makefile

2020-04-09 Thread Heinrich Schuchardt
On 2020-04-09 16:25, Sicris Rey Embay wrote:
> On Thu, Apr 9, 2020 at 8:49 PM Heinrich Schuchardt  wrote:
>>
>> On 2020-04-08 17:39, Sicris wrote:
>>> This patch fixes the typo error in Makefile where
>>> -I$(srctree)/arch/$(ARCH)/thumb1/include is not picked up
>>> in the compiler flag when compiling for thumb2.
>>> END
>>>
>>> Signed-off-by: Sicris 
>>> ---
>>>
>>>  Makefile | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/Makefile b/Makefile
>>> index 8de5ff6d94..503b30392d 100644
>>> --- a/Makefile
>>> +++ b/Makefile
>>> @@ -704,7 +704,7 @@ UBOOTINCLUDE:= \
>>>   -Iinclude \
>>>   $(if $(KBUILD_SRC), -I$(srctree)/include) \
>>>   $(if $(CONFIG_$(SPL_)SYS_THUMB_BUILD), \
>>> - $(if $(CONFIG_HAS_THUMB2),, \
>>> + $(if $(CONFIG_HAS_THUMB2), \
>>>   -I$(srctree)/arch/$(ARCH)/thumb1/include),) \
>>
>> This patch relates to
>> https://stackoverflow.com/questions/61097841/error-selected-processor-does-not-support-requested-special-purpose-register
>>
>> The original problem was using the wrong compiler as discussed on
>> Stackoverflow.
>
> Sorry, I was not very clear on the problem that I've encountered.
>
> I tried the M-profile as suggested in the stackoverflow comment from
> Frant.  However, I still get the same error
> with CONFIG_CMD_UBI=y.
>
> {standard input}:757: Error: selected processor does not support
> requested special purpose register – msr cpsr_c,r3
>
> This is due to the assembly inline function local_irq_save() /
> local_irq_restore.  On closer inspection,
> the wrong header for local_irq_save / local_irq_restore was picked up
> by the compiler.
>
> Wrong Header: /arch/arm/include/asm/proc-armv/system.h
> (Closest i can find) Correct Header:
> /arch/arm/thumb1/include/asm/proc-armv/system.h
>
>>
>> Compiling stm32f769-disco_defconfig works fine using the Debian Bullseye
>> package gcc-arm-linux-gnueabi without this patch.
>
> Can you help me check if this compiles using Debian Bullseye with
> CONFIG_CMD_UBI=y?

With this selected compiling fails.

{standard input}:965: Error: selected processor does not support
requested special purpose register -- `mrs r1,cpsr'

The CPSR register is not present on ARMv6-M and ARMv7-M processors.

So on these architectures arch/arm/include/asm/proc-armv/system.h has to
be replaced by arch/arm/thumb1/include/asm/proc-armv/system.h.

>>
>> The current logic is:
>> If it is thumb and not thumb2, include the thumb1 directory.
>> If it is thumb and thumb2, do not include the thumb1 directory.
>>
>> You are inverting the logic with your patch:
>>
>> If it is thumb and thumb2, include the thumb1 directory.
>> If it is thumb and not thumb2, do not include the thumb1 directory.
>>
>> This does not make much sense to me.
>>
>
> Does this suggestion make sense?
>
> $(if $(CONFIG_HAS_THUMB2), \
> -I$(srctree)/arch/$(ARCH)/thumb2/include),
> -I$(srctree)/arch/$(ARCH)/thumb1/include),) \

We do not want to use a special include on ARMv7-A even if building in
thumbs mode. So we should explicitly check the CPU architecture here.

If CONFIG_HAS_THUMB2 is undefined or CONFIG_CPU_V7M is defined,
we should use -I$(srctree)/arch/$(ARCH)/thumb1/include.

--- a/Makefile
+++ b/Makefile
@@ -701,13 +701,15 @@ KBUILD_CFLAGS += $(KCFLAGS)
 # Use UBOOTINCLUDE when you must reference the include/ directory.
 # Needed to be compatible with the O= option
-UBOOTINCLUDE:= \
-   -Iinclude \
-   $(if $(KBUILD_SRC), -I$(srctree)/include) \
-   $(if $(CONFIG_$(SPL_)SYS_THUMB_BUILD), \
-   $(if $(CONFIG_HAS_THUMB2),, \
-   -I$(srctree)/arch/$(ARCH)/thumb1/include),) \
-   -I$(srctree)/arch/$(ARCH)/include \
-   -include $(srctree)/include/linux/kconfig.h
+UBOOTINCLUDE:= \
+   -Iinclude \
+   $(if $(KBUILD_SRC), -I$(srctree)/include) \
+   $(if $(CONFIG_$(SPL_)SYS_THUMB_BUILD), \
+   $(if $(CONFIG_HAS_THUMB2), \
+   $(if $(CONFIG_CPU_V7M), \
+   -I$(srctree)/arch/arm/thumb1/include), \
+   -I$(srctree)/arch/arm/thumb1/include)) \
+   -I$(srctree)/arch/$(ARCH)/include \
+   -include $(srctree)/include/linux/kconfig.h

Best regards

Heinrich

>
> with thumb2/include contains the same thumb1/include contents.
>
>> For understanding the if-statement I found the following Makefile useful:
>>
>> 
>> all:
>> $(if ,,echo 1)
>> $(if ,echo 2)
>> $(if 1,,echo 3)
>> $(if 1,echo 4)
>> ---
>>
>> The output contains 1 and 4.
>>
>> Best regards
>>
>> Heinrich
>>
>>
>>>   -I$(srctree)/arch/$(ARCH)/include \
>>>   -include $(srctree)/include/linux/kconfig.h
>>>
>>
>
> cheers,
> Sicris Rey
>



Re: [PATCH v3] mips: cmd: go: Flush cache before jumping to app/image

2020-04-09 Thread Daniel Schwierzeck



Am 13.02.20 um 07:04 schrieb Stefan Roese:
> It has been noticed on MT7628/88 platforms, that booting the RAM image
> does not work reliably. Sometimes it works and sometimes not. Debugging
> showed that this "might" be a cache related issue as very strange
> errors occurred (e.g. output corrupted etc).
> 
> This patch adds a cache flush for the complete SDRAM area to the go cmd
> before jumping to the entry point for the MIPS architecture. The
> complete area is flushed as we don't know at this point, how big the
> area of the "application" really is.
> 
> Signed-off-by: Stefan Roese 
> Reviewed-by: Daniel Schwierzeck 
> Tested-by: Mauro Condarelli 
> Cc: Daniel Schwierzeck 
> Cc: Mauro Condarelli 
> Cc: Weijie Gao 
> ---
> v3:
> - Use gd->ram_top instead of gd->bd->bi_memsize for memory size
>   calculation as suggested by Daniel
>   
> v2:
> - Moved cache flush into weak do_go_exec() to make this changed
>   mips only
> 
>  arch/mips/lib/Makefile |  1 +
>  arch/mips/lib/boot.c   | 23 +++
>  2 files changed, 24 insertions(+)
>  create mode 100644 arch/mips/lib/boot.c
> 

applied to u-boot-mips/next, thanks.

-- 
- Daniel


RE: [PATCH 3/4] [RFC] ARM: dts: stm32: Rework DDR DT inclusion

2020-04-09 Thread Patrick DELAUNAY
Hi Marek,

> From: Marek Vasut 
> Sent: mercredi 8 avril 2020 15:54
> 
> On 4/8/20 12:09 PM, Patrick DELAUNAY wrote:
> > Hi,
> 
> Hi,
> 
> >> From: Marek Vasut 
> >> Sent: mardi 7 avril 2020 22:01
> >>
> >> On 4/7/20 3:00 PM, Patrick DELAUNAY wrote:
> >>> Dear Marek,
> >>
> >> Hi,
> >>

[...]

> >>>
> >>> And I want to propose, for DH board with several configuration
> >>>
> >>>   {
> >>>   config-1 {
> >>> #include "stm32mp15-ddr3-1x4Gb-1066-binG.dtsi"
> >>>   }
> >>>   config-2 {
> >>> #include "stm32mp15-ddr3-2x4Gb-1066-binG.dtsi"
> >>>   }
> >>> }
> >>>
> >>>
> >>> For ST board with only one configuration (don't change the device
> >>> tree, config at the same level)   { #include
> >>> "stm32mp15-ddr3-1x4Gb-1066-binG.dtsi"
> >>> }
> >>>
> >>>

[...]

> >>
> >> I would much rather prefer to avoid manually writing the config@
> >> parts, that should be handled by some macro magic instead. With my
> >> proposal, it is not necessary at all either.
> >

[]

> >
> > So the file generate by CubeMX don't change =  stm32mp15-ddr3-1x4Gb-1066-
> binG.dtsi and stm32mp15-ddr3-2x4Gb-1066-binG.dtsi.
> >
> > The ST board devicetree don't change: the DDR configuration is still
> > in ddr node (as in TF-A)
> >
> > For your board, the device tree
> > /arch/arm/dts/stm32mp15xx-dhcor-u-boot.dtsi
> >
> > [...]
> > #define DDR_MEM_CONFIG 2
> > #include "stm32mp15-ddr3-1x4Gb-1066-binG.dtsi"
> >
> > #define DDR_MEM_CONFIG 3
> > #include "stm32mp15-ddr3-2x4Gb-1066-binG.dtsi"
> > [...]
> >
> > And you can directly compare reg value of sub node with ddr3code.
> >
> > It is more acceptable ?
> 
> I wonder, can't we have some sort of macro where you would specify a 
> compatible
> string for the DDR config (on which you can match in your
> board_stm32mp1_ddr_config_name_match() and the dtsi file to be included, and
> the macro would generate the necessary entries in the  {} controller node 
> ?
> 
> E.g. like this:
> 
> #include "stm32mp15-ddr.dtsi"
> STM32MP15_DDR("vendor,board-1gib", stm32mp15-ddr3-2x4Gb-1066-binG.dtsi);
> STM32MP15_DDR("vendor,board-2gib", stm32mp15-ddr3-4x4Gb-1066-binG.dtsi);
> 
> and then in board_stm32mp1_ddr_config_name_match()
> {
>  if (!strcmp(..., "vendor,board-1gib"))
> return 0;
>  ...
> }

Yes, I agree, compatible is the better solution and the binding 

./doc/device-tree-bindings/memory-controllers/st,stm32mp1-ddr.txt becomes

ddr: ddr@0x5A003000{
compatible = "st,stm32mp1-ddr";
[...]

config-1 {
compatible = "vendor,board-1gib";

st,mem-name = "..."
[...]
st,phy-timing = <...>
}
config-2 {
compatible = "vendor,board-2gib";
st,mem-name = "..."
[...]
st,phy-timing = <...>
}
status = "okay";
}

And you match this configuration with compatible.

For the macro, it should be perfect, if it is not too complicate.

Because I afraid that "#include" in macro isn't allowed.

regards

Patrick



Re: [PATCH 22/26 v6] spl: spl_legacy: Add cache flush after reading U-Boot image

2020-04-09 Thread Daniel Schwierzeck



Am 09.04.20 um 09:43 schrieb Stefan Roese:
> On 09.04.20 09:29, Simon Goldschmidt wrote:
>> Am 08.04.2020 um 10:09 schrieb Stefan Roese:
>>> From: Weijie Gao 
>>>
>>> Flush the cache after reading of the U-Boot proper into SDRAM so that
>>> it can be started.
>>>
>>> This is needed on some platforms, e.g. MT76x8.
>>>
>>> Signed-off-by: Weijie Gao 
>>> Signed-off-by: Stefan Roese 
>>> Cc: Weijie Gao 
>>> Cc: Simon Goldschmidt 
>>> ---
>>> Changes in v6:
>>> - New patch
>>>
>>>   common/spl/spl_legacy.c | 4 
>>>   1 file changed, 4 insertions(+)
>>>
>>> diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
>>> index 2cd2a74a4c..e320206098 100644
>>> --- a/common/spl/spl_legacy.c
>>> +++ b/common/spl/spl_legacy.c
>>> @@ -4,6 +4,7 @@
>>>    */
>>>     #include 
>>> +#include 
>>>   #include 
>>>   #include 
>>>   @@ -108,5 +109,8 @@ int spl_load_legacy_img(struct spl_image_info
>>> *spl_image,
>>>   return -EINVAL;
>>>   }
>>>   +    /* Flush cache of loaded U-Boot image */
>>> +    flush_cache((unsigned long)spl_image->load_addr, spl_image->size);
>>> +
>>
>> I failed to find the mail, but haven't we discussed moving this cache
>> flush to your arch before starting a binary?
> 
> I don't remember such an agreement. But I don't object in general.
> 
>> I cannot see this being required or implemented for non-legacy images,
>> and it still seems wrong here.
> 
> Its pretty common when an OS image is loaded and booted, that the cache
> is flushed before running code from it.
> 
> But I can rework this to add some empty weak function (I don't see an
> easy better way) to do this platform specific image handling before its
> booted. Or do you have a better idea on how to handle this?
> 
> Thanks,
> Stefan

actually all MIPS platforms with non-coherent cache need that flush
before jumping to another U-Boot or OS. Thus currently random crashes
can occur on all MIPS boards with generic SPL not just mtmips.

But jump_to_image_no_args() in spl.c is already declared as weak, so we
should implement that unconditionally for MIPS similar to your patch for
do_go_exec(). It would be great if you could prepare a patch to replace
this one, thanks.

-- 
- Daniel


[PATCH v6 10/29] pci: Adjust dm_pci_read_bar32() to return errors correctly

2020-04-09 Thread Simon Glass
At present if reading a BAR returns 0x then the value is masked
and a different value is returned. This makes it harder to detect the
problem when debugging.

Update the function to avoid masking in this case.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
Reviewed-by: Wolfgang Wallner 
---

Changes in v6:
- Rework commit message to avoid mention of missing device

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/pci/pci-uclass.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 213381da6bd..7f46e901fb2 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -1213,7 +1213,14 @@ u32 dm_pci_read_bar32(const struct udevice *dev, int 
barnum)
 
bar = PCI_BASE_ADDRESS_0 + barnum * 4;
dm_pci_read_config32(dev, bar, );
-   if (addr & PCI_BASE_ADDRESS_SPACE_IO)
+
+   /*
+* If we get an invalid address, return this so that comparisons with
+* FDT_ADDR_T_NONE work correctly
+*/
+   if (addr == 0x)
+   return addr;
+   else if (addr & PCI_BASE_ADDRESS_SPACE_IO)
return addr & PCI_BASE_ADDRESS_IO_MASK;
else
return addr & PCI_BASE_ADDRESS_MEM_MASK;
-- 
2.26.0.292.g33ef6b2f38-goog



[PATCH v6 12/29] dm: core: Add basic ACPI support

2020-04-09 Thread Simon Glass
ACPI (Advanced Configuration and Power Interface) is a standard for
specifying information about a platform. It is a little like device
tree but the bindings are part of the specification and it supports an
interpreted bytecode language.

Driver model does not use ACPI for U-Boot's configuration, but it is
convenient to have it support generation of ACPI tables for passing to
Linux, etc.

As a starting point, add an optional set of ACPI operations to each
device. Initially only a single operation is available, to obtain the
ACPI name for the device. More operations are added later.

Enable ACPI for sandbox to ensure build coverage and so that we can add
tests.

Reviewed-by: Bin Meng 
Reviewed-by: Wolfgang Wallner 
Signed-off-by: Simon Glass 
---

Changes in v6:
- Use ACPI_NAME_LEN in acpi_copy_name since we add the nul anyway

Changes in v5:
- Capitalise ACPI_OPS_PTR since it includes a comma

Changes in v4: None
Changes in v3:
- Drop 'Intel' from 'Intel ACPI'
- Reword commit message to drop the bit about ACPI being complicated
- Compute ACPI_NAME_MAX from ACPI_NAME_LEN
- Rename acpi_return_name() to acpi_copy_name()
- Use strncpy() instead of strcpy() in acpi_copy_name()

Changes in v2:
- Move LOGC_ACPI definition to this patch

 configs/tools-only_defconfig |  1 +
 drivers/core/Kconfig |  9 +
 drivers/core/Makefile|  1 +
 drivers/core/acpi.c  | 33 
 include/dm/acpi.h| 73 
 include/dm/device.h  |  5 +++
 include/log.h|  2 +
 7 files changed, 124 insertions(+)
 create mode 100644 drivers/core/acpi.c
 create mode 100644 include/dm/acpi.h

diff --git a/configs/tools-only_defconfig b/configs/tools-only_defconfig
index 6ca50dc5fd3..2811b2cd37d 100644
--- a/configs/tools-only_defconfig
+++ b/configs/tools-only_defconfig
@@ -26,3 +26,4 @@ CONFIG_SYSRESET=y
 # CONFIG_VIRTIO_PCI is not set
 # CONFIG_VIRTIO_SANDBOX is not set
 # CONFIG_EFI_LOADER is not set
+# CONFIG_ACPIGEN is not set
diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig
index 3b95b5387b9..a3b03993423 100644
--- a/drivers/core/Kconfig
+++ b/drivers/core/Kconfig
@@ -261,4 +261,13 @@ config DM_DEV_READ_INLINE
bool
default y if !OF_LIVE
 
+config ACPIGEN
+   bool "Support ACPI table generation in driver model"
+   default y if SANDBOX || GENERATE_ACPI_TABLE
+   help
+ This option enables generation of ACPI tables using driver-model
+ devices. It adds a new operation struct to each driver, to support
+ things like generating device-specific tables and returning the ACPI
+ name of a device.
+
 endmenu
diff --git a/drivers/core/Makefile b/drivers/core/Makefile
index bce7467da1d..c707026a3a0 100644
--- a/drivers/core/Makefile
+++ b/drivers/core/Makefile
@@ -3,6 +3,7 @@
 # Copyright (c) 2013 Google, Inc
 
 obj-y  += device.o fdtaddr.o lists.o root.o uclass.o util.o
+obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o
 obj-$(CONFIG_DEVRES) += devres.o
 obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE)  += device-remove.o
 obj-$(CONFIG_$(SPL_)SIMPLE_BUS)+= simple-bus.o
diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
new file mode 100644
index 000..ba50d688fef
--- /dev/null
+++ b/drivers/core/acpi.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Core driver model support for ACPI table generation
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass 
+ */
+
+#define LOG_CATEOGRY   LOGC_ACPI
+
+#include 
+#include 
+#include 
+#include 
+
+int acpi_copy_name(char *out_name, const char *name)
+{
+   strncpy(out_name, name, ACPI_NAME_LEN);
+   out_name[ACPI_NAME_LEN] = '\0';
+
+   return 0;
+}
+
+int acpi_get_name(const struct udevice *dev, char *out_name)
+{
+   struct acpi_ops *aops;
+
+   aops = device_get_acpi_ops(dev);
+   if (aops && aops->get_name)
+   return aops->get_name(dev, out_name);
+
+   return -ENOSYS;
+}
diff --git a/include/dm/acpi.h b/include/dm/acpi.h
new file mode 100644
index 000..ba0813fa21c
--- /dev/null
+++ b/include/dm/acpi.h
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Core ACPI (Advanced Configuration and Power Interface) support
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass 
+ */
+
+#ifndef __DM_ACPI_H__
+#define __DM_ACPI_H__
+
+/* Allow operations to be optional for ACPI */
+#if CONFIG_IS_ENABLED(ACPIGEN)
+#define ACPI_OPS_PTR(_ptr) .acpi_ops   = _ptr,
+#else
+#define ACPI_OPS_PTR(_ptr)
+#endif
+
+/* Length of an ACPI name string, excluding nul terminator */
+#define ACPI_NAME_LEN  4
+
+/* Length of an ACPI name string including nul terminator */
+#define ACPI_NAME_MAX  (ACPI_NAME_LEN + 1)
+
+/**
+ * struct acpi_ops - ACPI operations supported by driver model
+ */
+struct acpi_ops {
+   /**
+* get_name() - Obtain the ACPI name of a device
+*
+* @dev: Device to check
+* @out_name: Place to put the name, 

Re: Calling i2c set speed twice for i2c_mux_bus

2020-04-09 Thread Simon Glass
Hi Michal,

On Thu, 9 Apr 2020 at 08:03, Michal Simek  wrote:
>
> Hi Heiko and Simon,
>
> I have find out one bug in i2c class. I am using zcu104 revC board which
> has dts in mainline where i2c1 has i2c mux with some channels.
> In DT clock-frequency = <40>; is specified and it is read in
> i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means
> that post probe is called for it too. And because clock-frequency
> property is not there default 100k is used.
>
> I think that is bug and should be fixed.
> Heiko: Are you aware about this issue?
>
> Simon: I think that make sense to use some flags to skip calling
> post_probe in this case. Or any suggestion how to fix it would be great.

Ick, hope not. Can you please point me to the board config and the device tree?

Regards,
Simon


Re: [PATCH 1/2] libfdt: Make fdt_cells function accessible

2020-04-09 Thread Simon Glass
Hi Matthias,

On Wed, 8 Apr 2020 at 03:35,  wrote:
>
> From: Matthias Brugger 
>
> For reading address-cells and size-cells, the libfdt only provides
> functions which do not return in case the node does not provide the
> property. For traversing the DT to find the parent node which provides
> this property we will need to know that.
>
> Make fdt_cells accessible from outside of libfdt so that we can detect
> not present size- and address-cells properties in a node.
>
> Signed-off-by: Matthias Brugger 
> ---
>
>  scripts/dtc/libfdt/fdt_addresses.c | 2 +-
>  scripts/dtc/libfdt/libfdt.h| 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)

Can you please send these patches upstream too?

Thanks,
Simon


Re: [PATCH 2/2] dm: core: Walk the tree to find address- and size-cells properties

2020-04-09 Thread Simon Glass
Hi Matthias,

On Wed, 8 Apr 2020 at 03:35,  wrote:
>
> From: Matthias Brugger 
>
> Walk the tree when reading size-cells or address-cells properties.
>
> Reported-by: Robin Randhawa 
> Signed-off-by: Matthias Brugger 
>
> ---
>
>  drivers/core/ofnode.c |  8 
>  include/dm/ofnode.h   | 36 
>  include/dm/read.h |  6 ++
>  3 files changed, 42 insertions(+), 8 deletions(-)
>

Please can you send these upstream? I think you'll need to add a test
when doing that, too.

Regards,
Simon


Re: [PATCH v5 10/29] pci: Adjust dm_pci_read_bar32() to return errors correctly

2020-04-09 Thread Simon Glass
Hi,

On Thu, 9 Apr 2020 at 03:39, Mark Kettenis  wrote:
>
> > From: Andy Shevchenko 
> > Date: Thu, 9 Apr 2020 12:06:11 +0300
> >
> > On Thu, Apr 9, 2020 at 2:00 AM Simon Glass  wrote:
> > >
> > > At present if reading a BAR returns 0x (e.g. the device is not
> > > present) then the value is masked and a different value is returned.
> > > This makes it harder to detect the problem when debugging.
> >
> > If you insisting on the code, you may need to reword the commit
> > message, at least by removing ambiguous "device not present", because
> > this is not how PCI spec defines situations when device is not
> > present.
>
> In addition to that:
>
> The 0x value is an artifact of how x86 systems handle aborted
> PCI transactions.  Other architectures will probably generate a fault
> of some sorts.  It looks like at least some of the pci drivers in
> u-boot emulate the x86 behaviour but I'm not sure all of them do.

This is not intended to be used to detect missing devices. It's just
that we should not be masking an obviously invalid value, to make it
look more valid. It is very confusing.

I'll update the comment message.

Regards,
Simon


Re: [PATCH v5 12/29] dm: core: Add basic ACPI support

2020-04-09 Thread Simon Glass
Hi Andy,

On Thu, 9 Apr 2020 at 03:02, Andy Shevchenko  wrote:
>
> On Thu, Apr 9, 2020 at 2:01 AM Simon Glass  wrote:
> >
> > ACPI (Advanced Configuration and Power Interface) is a standard for
> > specifying information about a platform. It is a little like device
> > tree but the bindings are part of the specification and it supports an
> > interpreted bytecode language.
> >
> > Driver model does not use ACPI for U-Boot's configuration, but it is
> > convenient to have it support generation of ACPI tables for passing to
> > Linux, etc.
> >
> > As a starting point, add an optional set of ACPI operations to each
> > device. Initially only a single operation is available, to obtain the
> > ACPI name for the device. More operations are added later.
> >
> > Enable ACPI for sandbox to ensure build coverage and so that we can add
> > tests.
>
> > +int acpi_copy_name(char *out_name, const char *name)
> > +{
> > +   strncpy(out_name, name, ACPI_NAME_MAX);
>
> _LEN.
>
> The idea as I tried to explain that name can have only 4 bytes at the
> end of the page. I dunno what U-Boot does if you access out of the
> boundaries to the page which is not mapped to MMU (in OSes it will be
> page fault). Does U-Boot map all pages to MMU?
>
> In any case, the code above has this subtle issue. We may live with
> it, but since it's a generic kinda function, better to be pedantic
> about it.

OK I will change it. The documentation is pretty clear on how to use
this function, but I suppose people might not read it.

Regards,
Simon


  1   2   >