Re: [U-Boot] [PATCH v2 7/8] board: Add new slimbootloader board

2019-07-08 Thread Bin Meng
Hi Aiden,

On Tue, Jul 9, 2019 at 8:02 AM Park, Aiden  wrote:
>
> Hi Bin,
>
> > -Original Message-
> > From: Park, Aiden
> > Sent: Monday, July 8, 2019 9:48 AM
> > To: Bin Meng 
> > Cc: U-Boot Mailing List ; Simon Glass
> > 
> > Subject: RE: [PATCH v2 7/8] board: Add new slimbootloader board
> >
> > Hi Bin,
> >
> > > -Original Message-
> > > From: Bin Meng [mailto:bmeng...@gmail.com]
> > > Sent: Tuesday, July 2, 2019 7:14 AM
> > > To: Park, Aiden 
> > > Cc: U-Boot Mailing List ; Simon Glass
> > > 
> > > Subject: Re: [PATCH v2 7/8] board: Add new slimbootloader board
> > >
> > > Hi Aiden,
> > >
> > > On Wed, Jun 26, 2019 at 7:21 AM Park, Aiden 
> > wrote:
> > > >
> > > > - Add new board/slimbootloader directory with minimum codes
> > > > - Add slimbootloader configuration files
> > > > - Add README in board/slimbootloader/slimbootloader/
> > > >
> > > > Signed-off-by: Aiden Park 
> > > > ---
> > > >  arch/x86/Kconfig  |  4 ++
> > > >  board/slimbootloader/Kconfig  | 25 
> > > >  board/slimbootloader/slimbootloader/Kconfig   | 51 +++
> > > >  board/slimbootloader/slimbootloader/Makefile  |  5 ++
> > > >  board/slimbootloader/slimbootloader/README| 58
> > > +
> > > >  .../slimbootloader/slimbootloader.c   | 17 +
> > > >  board/slimbootloader/slimbootloader/start.S   |  9 +++
> > > >  configs/slimbootloader_defconfig  | 64 +++
> > > >  include/configs/slimbootloader.h  | 54 
> > > >  9 files changed, 287 insertions(+)
> > > >  create mode 100644 board/slimbootloader/Kconfig  create mode 100644
> > > > board/slimbootloader/slimbootloader/Kconfig
> > > >  create mode 100644 board/slimbootloader/slimbootloader/Makefile
> > > >  create mode 100644 board/slimbootloader/slimbootloader/README
> > > >  create mode 100644
> > > > board/slimbootloader/slimbootloader/slimbootloader.c
> > > >  create mode 100644 board/slimbootloader/slimbootloader/start.S
> > > >  create mode 100644 configs/slimbootloader_defconfig  create mode
> > > > 100644 include/configs/slimbootloader.h
> > > >
> > > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index
> > > > 1612246dfc..3d57466a63 100644
> > > > --- a/arch/x86/Kconfig
> > > > +++ b/arch/x86/Kconfig
> > > > @@ -77,6 +77,9 @@ config VENDOR_GOOGLE  config VENDOR_INTEL
> > > > bool "Intel"
> > > >
> > > > +config VENDOR_SLIMBOOTLOADER
> > > > +   bool "slimbootloader"
> > >
> > > I think this should be "Intel".
> > Okay. Let me use VENDOR_INTEL.
> > >
> > > > +
> > > >  endchoice
> > > >
> > > >  # subarchitectures-specific options below @@ -104,6 +107,7 @@
> > > > source "board/efi/Kconfig"
> > > >  source "board/emulation/Kconfig"
> > > >  source "board/google/Kconfig"
> > > >  source "board/intel/Kconfig"
> > > > +source "board/slimbootloader/Kconfig"
> > >
> > > So it becomes a "board" in board/intel directory.
> > Okay. Let me use intel.
> > >
> > > >
> > > >  # platform-specific options below
> > > >  source "arch/x86/cpu/baytrail/Kconfig"
> > > > diff --git a/board/slimbootloader/Kconfig
> > > > b/board/slimbootloader/Kconfig new file mode 100644 index
> > > > 00..33c6fdf0aa
> > > > --- /dev/null
> > > > +++ b/board/slimbootloader/Kconfig
> > > > @@ -0,0 +1,25 @@
> > > > +# SPDX-License-Identifier: GPL-2.0+ # # Copyright (C) 2019 Intel
> > > > +Corporation 
> > > > +
> > > > +if VENDOR_SLIMBOOTLOADER
> > > > +
> > > > +choice
> > > > +   prompt "Select a board"
> > > > +   optional
> > > > +
> > > > +config TARGET_SLIMBOOTLOADER
> > > > +   bool "slimbootloader"
> > > > +   help
> > > > + This target is used for running U-Boot on top of Slim 
> > > > Bootloader
> > > > + boot firmware as a payload. Slim Bootloader does memory
> > > initialization
> > > > + and silicon initialization, and it passes necessary 
> > > > information in
> > > > + HOB(Hand Off Block) to a payload. The payload is responsible 
> > > > for OS
> > > > + load from media and booting OS.
> > > > + Refer to board/slimbootloader/slimbootloader/README for
> > > > + the
> > > details.
> > > > +
> > > > +endchoice
> > > > +
> > > > +source "board/slimbootloader/slimbootloader/Kconfig"
> > > > +
> > > > +endif
> > > > diff --git a/board/slimbootloader/slimbootloader/Kconfig
> > > > b/board/slimbootloader/slimbootloader/Kconfig
> > > > new file mode 100644
> > > > index 00..7262f2bf1b
> > > > --- /dev/null
> > > > +++ b/board/slimbootloader/slimbootloader/Kconfig
> > > > @@ -0,0 +1,51 @@
> > > > +# SPDX-License-Identifier: GPL-2.0+ # # Copyright (C) 2019 Intel
> > > > +Corporation 
> > > > +
> > > > +if TARGET_SLIMBOOTLOADER
> > > > +
> > > > +config SYS_BOARD
> > > > +   default "slimbootloader"
> > > > +
> > > > +config SYS_VENDOR
> > > > +   default "slimbootloader"
> > > > +
> > > > +config SYS_SOC
> > > > +   default "slimbootloader"
> > > 

[U-Boot] [PATCH v6 3/5] arm64: dts: ti: k3-am65: add mcu cpsw node

2019-07-08 Thread Keerthy
From: Grygorii Strashko 

Add mcu cpsw and its components along with scm_conf node
to have ethernet functional.

Signed-off-by: Grygorii Strashko 
Signed-off-by: Keerthy 
Reviewed-by: Tom Rini 
Acked-by: Joe Hershberger 
---

Changes in v6:

  * Added Joe's Ack.

 arch/arm/dts/k3-am65.dtsi|   2 +
 arch/arm/dts/k3-am654-base-board-u-boot.dtsi | 111 +++
 2 files changed, 113 insertions(+)

diff --git a/arch/arm/dts/k3-am65.dtsi b/arch/arm/dts/k3-am65.dtsi
index 3d4bf369d0..9d1ed49753 100644
--- a/arch/arm/dts/k3-am65.dtsi
+++ b/arch/arm/dts/k3-am65.dtsi
@@ -64,6 +64,7 @@
 /* MCUSS Range */
 <0x00 0x2838 0x00 0x2838 0x00 0x0388>,
 <0x00 0x4020 0x00 0x4020 0x00 0x00900100>,
+<0x00 0x40f0 0x00 0x40f0 0x00 0x0002>,
 <0x00 0x4204 0x00 0x4204 0x00 0x03ac2400>,
 <0x00 0x4510 0x00 0x4510 0x00 0x00c24000>,
 <0x00 0x4600 0x00 0x4600 0x00 0x0020>,
@@ -75,6 +76,7 @@
#size-cells = <2>;
ranges = <0x00 0x2838 0x00 0x2838 0x00 
0x0388>, /* MCU NAVSS*/
 <0x00 0x4020 0x00 0x4020 0x00 
0x00900100>, /* First peripheral window */
+<0x00 0x40f0 0x00 0x40f0 0x00 
0x0002>, /* CTRL_MMR0 */
 <0x00 0x4204 0x00 0x4204 0x00 
0x03ac2400>, /* WKUP */
 <0x00 0x4510 0x00 0x4510 0x00 
0x00c24000>, /* MMRs, remaining NAVSS */
 <0x00 0x4600 0x00 0x4600 0x00 
0x0020>, /* CPSW */
diff --git a/arch/arm/dts/k3-am654-base-board-u-boot.dtsi 
b/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
index f5c8253831..18b611990f 100644
--- a/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
@@ -13,6 +13,7 @@
 
aliases {
serial2 = _uart0;
+   ethernet0 = _port1;
};
 };
 
@@ -110,6 +111,116 @@
dma-coherent;
};
};
+
+   mcu_conf: scm_conf@40f0 {
+   compatible = "syscon";
+   reg = <0x0 0x40f0 0x0 0x2>;
+   };
+
+   mcu_cpsw: cpsw_nuss@04600 {
+   compatible = "ti,am654-cpsw-nuss";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   reg = <0x0 0x4600 0x0 0x20>;
+   reg-names = "cpsw_nuss";
+   ranges;
+   dma-coherent;
+   clocks = <_clks 5 10>;
+   clock-names = "fck";
+   power-domains = <_pds 5>;
+   ti,psil-base = <0x7000>;
+
+   dmas = <_udmap _cpsw 0 UDMA_DIR_TX>,
+  <_udmap _cpsw 1 UDMA_DIR_TX>,
+  <_udmap _cpsw 2 UDMA_DIR_TX>,
+  <_udmap _cpsw 3 UDMA_DIR_TX>,
+  <_udmap _cpsw 4 UDMA_DIR_TX>,
+  <_udmap _cpsw 5 UDMA_DIR_TX>,
+  <_udmap _cpsw 6 UDMA_DIR_TX>,
+  <_udmap _cpsw 7 UDMA_DIR_TX>,
+  <_udmap _cpsw 0 UDMA_DIR_RX>;
+   dma-names = "tx0", "tx1", "tx2", "tx3",
+   "tx4", "tx5", "tx6", "tx7",
+   "rx";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   host: host@0 {
+   reg = <0>;
+   ti,label = "host";
+   };
+
+   cpsw_port1: port@1 {
+   reg = <1>;
+   ti,mac-only;
+   ti,label = "port1";
+   ti,syscon-efuse = <_conf 0x200>;
+   };
+   };
+
+   davinci_mdio: mdio {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   bus_freq = <100>;
+   };
+
+   ti,psil-config0 {
+   linux,udma-mode = ;
+   statictr-type = ;
+   ti,needs-epib;
+   ti,psd-size = <16>;
+   };
+
+   ti,psil-config1 {
+   linux,udma-mode = ;
+   statictr-type = ;
+   ti,needs-epib;
+   ti,psd-size = <16>;
+   };
+
+   ti,psil-config2 {
+   linux,udma-mode = ;
+   statictr-type = ;
+   ti,needs-epib;
+   ti,psd-size = <16>;
+   };
+
+   ti,psil-config3 {
+   

[U-Boot] [PATCH v6 4/5] arm64: dts: k3-am654-base-board: add mcu cpsw nuss pinmux and phy defs

2019-07-08 Thread Keerthy
From: Grygorii Strashko 

Add mcu cpsw nuss pinmux and phy defs required by cpsw.

Signed-off-by: Grygorii Strashko 
Signed-off-by: Keerthy 
Reviewed-by: Tom Rini 
Acked-by: Joe Hershberger 
---

Changes in v6:

  * Added Joe's Ack.

 arch/arm/dts/k3-am654-base-board-u-boot.dtsi | 59 
 1 file changed, 59 insertions(+)

diff --git a/arch/arm/dts/k3-am654-base-board-u-boot.dtsi 
b/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
index 18b611990f..844a5cd96a 100644
--- a/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 
 / {
chosen {
@@ -300,6 +301,32 @@
u-boot,dm-spl;
 };
 
+_pmx0 {
+   mcu_cpsw_pins_default: mcu_cpsw_pins_default {
+   pinctrl-single,pins = <
+   AM65X_WKUP_IOPAD(0x0058, PIN_OUTPUT, 0) /* (N4) 
MCU_RGMII1_TX_CTL */
+   AM65X_WKUP_IOPAD(0x005c, PIN_INPUT, 0) /* (N5) 
MCU_RGMII1_RX_CTL */
+   AM65X_WKUP_IOPAD(0x0060, PIN_OUTPUT, 0) /* (M2) 
MCU_RGMII1_TD3 */
+   AM65X_WKUP_IOPAD(0x0064, PIN_OUTPUT, 0) /* (M3) 
MCU_RGMII1_TD2 */
+   AM65X_WKUP_IOPAD(0x0068, PIN_OUTPUT, 0) /* (M4) 
MCU_RGMII1_TD1 */
+   AM65X_WKUP_IOPAD(0x006c, PIN_OUTPUT, 0) /* (M5) 
MCU_RGMII1_TD0 */
+   AM65X_WKUP_IOPAD(0x0078, PIN_INPUT, 0) /* (L2) 
MCU_RGMII1_RD3 */
+   AM65X_WKUP_IOPAD(0x007c, PIN_INPUT, 0) /* (L5) 
MCU_RGMII1_RD2 */
+   AM65X_WKUP_IOPAD(0x0080, PIN_INPUT, 0) /* (M6) 
MCU_RGMII1_RD1 */
+   AM65X_WKUP_IOPAD(0x0084, PIN_INPUT, 0) /* (L6) 
MCU_RGMII1_RD0 */
+   AM65X_WKUP_IOPAD(0x0070, PIN_INPUT, 0) /* (N1) 
MCU_RGMII1_TXC */
+   AM65X_WKUP_IOPAD(0x0074, PIN_INPUT, 0) /* (M1) 
MCU_RGMII1_RXC */
+   >;
+   };
+
+   mcu_mdio_pins_default: mcu_mdio1_pins_default {
+   pinctrl-single,pins = <
+   AM65X_WKUP_IOPAD(0x008c, PIN_OUTPUT, 0) /* (L1) 
MCU_MDIO0_MDC */
+   AM65X_WKUP_IOPAD(0x0088, PIN_INPUT, 0) /* (L4) 
MCU_MDIO0_MDIO */
+   >;
+   };
+};
+
 _uart0 {
u-boot,dm-spl;
pinctrl-names = "default";
@@ -323,3 +350,35 @@
pinctrl-0 = <_mmc1_pins_default>;
sdhci-caps-mask = <0x7 0x0>;
 };
+
+_cpsw {
+   pinctrl-names = "default";
+   pinctrl-0 = <_cpsw_pins_default _mdio_pins_default>;
+};
+
+_mdio {
+   phy0: ethernet-phy@0 {
+   reg = <0>;
+   /* TODO: phy reset: 
TCA9555RTWR(i2c:0x21)[p04].GPIO_MCU_RGMII_RSTN */
+   ti,rx-internal-delay = ;
+   ti,tx-internal-delay = ;
+   ti,fifo-depth = ;
+   };
+};
+
+_port1 {
+   phy-mode = "rgmii-id";
+   phy-handle = <>;
+};
+
+_cpsw {
+   reg = <0x0 0x4600 0x0 0x20>,
+ <0x0 0x40f00200 0x0 0x2>;
+   reg-names = "cpsw_nuss", "mac_efuse";
+
+   cpsw-phy-sel@40f04040 {
+   compatible = "ti,am654-cpsw-phy-sel";
+   reg= <0x0 0x40f04040 0x0 0x4>;
+   reg-names = "gmii-sel";
+   };
+};
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 5/5] configs: am65x_evm_a53: enable networking

2019-07-08 Thread Keerthy
From: Grygorii Strashko 

Enable TI K3 AM65x CPSW NUSS driver.

Signed-off-by: Grygorii Strashko 
Signed-off-by: Keerthy 
Reviewed-by: Tom Rini 
Acked-by: Joe Hershberger 
---

Changes in v6:

  * Removed unused HEXDUMP config.
  * Added Joe's Ack.

 configs/am65x_evm_a53_defconfig | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
index 41cf0100fa..b940af3f56 100644
--- a/configs/am65x_evm_a53_defconfig
+++ b/configs/am65x_evm_a53_defconfig
@@ -44,6 +44,7 @@ CONFIG_SPL_MULTI_DTB_FIT_NO_COMPRESSION=y
 CONFIG_ENV_IS_IN_FAT=y
 CONFIG_ENV_FAT_INTERFACE="mmc"
 CONFIG_ENV_FAT_DEVICE_AND_PART="1:1"
+CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_DM=y
 CONFIG_SPL_DM=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
@@ -58,6 +59,11 @@ CONFIG_K3_SEC_PROXY=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_K3_ARASAN=y
+CONFIG_PHY_TI=y
+CONFIG_PHY_FIXED=y
+CONFIG_DM_ETH=y
+CONFIG_TI_AM65_CPSW_NUSS=y
+CONFIG_PHY=y
 CONFIG_PINCTRL=y
 # CONFIG_PINCTRL_GENERIC is not set
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 2/5] net: ethernet: ti: Introduce am654 gigabit eth switch subsystem driver

2019-07-08 Thread Keerthy
Add new driver for the TI AM65x SoC Gigabit Ethernet Switch subsystem (CPSW
NUSS). It has two ports and provides Ethernet packet communication for the
device and can be configured as an Ethernet switch. CPSW NUSS features: the
Reduced Gigabit Media Independent Interface (RGMII), Reduced Media
Independent Interface (RMII), and the Management Data Input/Output (MDIO)
interface for physical layer device (PHY) management. The TI AM65x SoC has
integrated two-port Gigabit Ethernet Switch subsystem into device MCU
domain named MCU_CPSW0. One Ethernet port (port 1) with selectable RGMII
and RMII interfaces and an internal Communications Port Programming
Interface (CPPI) port (Host port 0).

Host Port 0 CPPI Packet Streaming Interface interface supports 8 TX
channels and on RX channels operating by TI am654 NAVSS Unified DMA
Peripheral Root Complex (UDMA-P) controller.

Signed-off-by: Grygorii Strashko 
Signed-off-by: Keerthy 
---

Changes in v6:

  * Removed redundant #ifdef on DM_ETH
  * Corrected a typo in dev_err.

 drivers/net/ti/Kconfig  |   8 +
 drivers/net/ti/Makefile |   1 +
 drivers/net/ti/am65-cpsw-nuss.c | 792 
 3 files changed, 801 insertions(+)
 create mode 100644 drivers/net/ti/am65-cpsw-nuss.c

diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index 82bc9f5d03..ecf642de10 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -18,3 +18,11 @@ config DRIVER_TI_KEYSTONE_NET
bool "TI Keystone 2 Ethernet"
help
   This driver supports the TI Keystone 2 Ethernet subsystem
+
+config TI_AM65_CPSW_NUSS
+   bool "TI K3 AM65x MCU CPSW Nuss Ethernet controller driver"
+   depends on ARCH_K3
+   select PHYLIB
+   help
+ This driver supports TI K3 MCU CPSW Nuss Ethernet controller
+ in Texas Instruments K3 AM65x SoCs.
diff --git a/drivers/net/ti/Makefile b/drivers/net/ti/Makefile
index ee3e4eb5d6..8d3808bb4b 100644
--- a/drivers/net/ti/Makefile
+++ b/drivers/net/ti/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o cpsw-common.o cpsw_mdio.o
 obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
 obj-$(CONFIG_DRIVER_TI_KEYSTONE_NET) += keystone_net.o cpsw_mdio.o
+obj-$(CONFIG_TI_AM65_CPSW_NUSS) += am65-cpsw-nuss.o cpsw_mdio.o
diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
new file mode 100644
index 00..e11fbdeed3
--- /dev/null
+++ b/drivers/net/ti/am65-cpsw-nuss.c
@@ -0,0 +1,792 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments K3 AM65 Ethernet Switch SubSystem Driver
+ *
+ * Copyright (C) 2019, Texas Instruments, Incorporated
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "cpsw_mdio.h"
+
+#define AM65_CPSW_CPSWNU_MAX_PORTS 2
+
+#define AM65_CPSW_SS_BASE  0x0
+#define AM65_CPSW_SGMII_BASE   0x100
+#define AM65_CPSW_MDIO_BASE0xf00
+#define AM65_CPSW_XGMII_BASE   0x2100
+#define AM65_CPSW_CPSW_NU_BASE 0x2
+#define AM65_CPSW_CPSW_NU_ALE_BASE 0x1e000
+
+#define AM65_CPSW_CPSW_NU_PORTS_OFFSET 0x1000
+#define AM65_CPSW_CPSW_NU_PORT_MACSL_OFFSET0x330
+
+#define AM65_CPSW_MDIO_BUS_FREQ_DEF 100
+
+#define AM65_CPSW_CTL_REG  0x4
+#define AM65_CPSW_STAT_PORT_EN_REG 0x14
+#define AM65_CPSW_PTYPE_REG0x18
+
+#define AM65_CPSW_CTL_REG_P0_ENABLEBIT(2)
+#define AM65_CPSW_CTL_REG_P0_TX_CRC_REMOVE BIT(13)
+#define AM65_CPSW_CTL_REG_P0_RX_PADBIT(14)
+
+#define AM65_CPSW_P0_FLOW_ID_REG   0x8
+#define AM65_CPSW_PN_RX_MAXLEN_REG 0x24
+#define AM65_CPSW_PN_REG_SA_L  0x308
+#define AM65_CPSW_PN_REG_SA_H  0x30c
+
+#define AM65_CPSW_ALE_CTL_REG  0x8
+#define AM65_CPSW_ALE_CTL_REG_ENABLE   BIT(31)
+#define AM65_CPSW_ALE_CTL_REG_RESET_TBLBIT(30)
+#define AM65_CPSW_ALE_CTL_REG_BYPASS   BIT(4)
+#define AM65_CPSW_ALE_PN_CTL_REG(x)(0x40 + (x) * 4)
+#define AM65_CPSW_ALE_PN_CTL_REG_MODE_FORWARD  0x3
+#define AM65_CPSW_ALE_PN_CTL_REG_MAC_ONLY  BIT(11)
+
+#define AM65_CPSW_MACSL_CTL_REG0x0
+#define AM65_CPSW_MACSL_CTL_REG_IFCTL_ABIT(15)
+#define AM65_CPSW_MACSL_CTL_REG_GIGBIT(7)
+#define AM65_CPSW_MACSL_CTL_REG_GMII_ENBIT(5)
+#define AM65_CPSW_MACSL_CTL_REG_LOOPBACK   BIT(1)
+#define AM65_CPSW_MACSL_CTL_REG_FULL_DUPLEXBIT(0)
+#define AM65_CPSW_MACSL_RESET_REG  0x8
+#define AM65_CPSW_MACSL_RESET_REG_RESETBIT(0)
+#define AM65_CPSW_MACSL_STATUS_REG 0x4
+#define AM65_CPSW_MACSL_RESET_REG_PN_IDLE  BIT(31)
+#define AM65_CPSW_MACSL_RESET_REG_PN_E_IDLEBIT(30)
+#define AM65_CPSW_MACSL_RESET_REG_PN_P_IDLEBIT(29)
+#define AM65_CPSW_MACSL_RESET_REG_PN_TX_IDLE   BIT(28)
+#define 

[U-Boot] [PATCH v6 0/5] net: ethernet: ti: Introduce am654 gigabit eth switch subsystem driver

2019-07-08 Thread Keerthy
Add new driver for the TI AM65x SoC Gigabit Ethernet Switch subsystem (CPSW
NUSS). It has two ports and provides Ethernet packet communication for the
device and can be configured as an Ethernet switch. CPSW NUSS features: the
Reduced Gigabit Media Independent Interface (RGMII), Reduced Media
Independent Interface (RMII), and the Management Data Input/Output (MDIO)
interface for physical layer device (PHY) management. The TI AM65x SoC has
integrated two-port Gigabit Ethernet Switch subsystem into device MCU
domain named MCU_CPSW0. One Ethernet port (port 1) with selectable RGMII
and RMII interfaces and an internal Communications Port Programming
Interface (CPPI) port (Host port 0).

Host Port 0 CPPI Packet Streaming Interface interface supports 8 TX
channels and on RX channels operating by TI am654 NAVSS Unified DMA
Peripheral Root Complex (UDMA-P) controller.

Tested for tftp and booting to kernel on am654-evm.

Changes in v6:

  * Fixed comments from Joe on the driver patch.
  * Added Joe's Ack to the remaining patches.
  * Removed Hexdump config.

Changes in v5:
  * Rebased to latest which meant adapting to pinmux macro change.

Changes in v4:

  * Patch1 caused dra7 config build warnings corrected them.

Grygorii Strashko (3):
  arm64: dts: ti: k3-am65: add mcu cpsw node
  arm64: dts: k3-am654-base-board: add mcu cpsw nuss pinmux and phy defs
  configs: am65x_evm_a53: enable networking

Keerthy (2):
  driver: net: ti: cpsw-mdio: use phys_addr_t for mdio_base addr
  net: ethernet: ti: Introduce am654 gigabit eth switch  subsystem
driver

 arch/arm/dts/k3-am65.dtsi|   2 +
 arch/arm/dts/k3-am654-base-board-u-boot.dtsi | 170 
 configs/am65x_evm_a53_defconfig  |   6 +
 drivers/net/ti/Kconfig   |   8 +
 drivers/net/ti/Makefile  |   1 +
 drivers/net/ti/am65-cpsw-nuss.c  | 792 +++
 drivers/net/ti/cpsw_mdio.c   |   4 +-
 drivers/net/ti/cpsw_mdio.h   |   2 +-
 8 files changed, 982 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/ti/am65-cpsw-nuss.c

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 1/5] driver: net: ti: cpsw-mdio: use phys_addr_t for mdio_base addr

2019-07-08 Thread Keerthy
Use phys_addr_t for mdio_base address to avoid build
warnings on arm64 and dra7. Cast it to uintprt_t before
assigning to regs.

Signed-off-by: Grygorii Strashko 
Signed-off-by: Keerthy 
Reviewed-by: Tom Rini 
Acked-by: Joe Hershberger 
---

Changes in v6:

  * Added Joe's Ack.

 drivers/net/ti/cpsw_mdio.c | 4 ++--
 drivers/net/ti/cpsw_mdio.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ti/cpsw_mdio.c b/drivers/net/ti/cpsw_mdio.c
index 70f547e6d7..6e8f652011 100644
--- a/drivers/net/ti/cpsw_mdio.c
+++ b/drivers/net/ti/cpsw_mdio.c
@@ -125,7 +125,7 @@ u32 cpsw_mdio_get_alive(struct mii_dev *bus)
return val & GENMASK(15, 0);
 }
 
-struct mii_dev *cpsw_mdio_init(const char *name, u32 mdio_base,
+struct mii_dev *cpsw_mdio_init(const char *name, phys_addr_t mdio_base,
   u32 bus_freq, int fck_freq)
 {
struct cpsw_mdio *cpsw_mdio;
@@ -144,7 +144,7 @@ struct mii_dev *cpsw_mdio_init(const char *name, u32 
mdio_base,
return NULL;
}
 
-   cpsw_mdio->regs = (struct cpsw_mdio_regs *)mdio_base;
+   cpsw_mdio->regs = (struct cpsw_mdio_regs *)(uintptr_t)mdio_base;
 
if (!bus_freq || !fck_freq)
cpsw_mdio->div = CPSW_MDIO_DIV_DEF;
diff --git a/drivers/net/ti/cpsw_mdio.h b/drivers/net/ti/cpsw_mdio.h
index 4a76d4e5c5..dbf4a2dcac 100644
--- a/drivers/net/ti/cpsw_mdio.h
+++ b/drivers/net/ti/cpsw_mdio.h
@@ -10,7 +10,7 @@
 
 struct cpsw_mdio;
 
-struct mii_dev *cpsw_mdio_init(const char *name, u32 mdio_base,
+struct mii_dev *cpsw_mdio_init(const char *name, phys_addr_t mdio_base,
   u32 bus_freq, int fck_freq);
 void cpsw_mdio_free(struct mii_dev *bus);
 u32 cpsw_mdio_get_alive(struct mii_dev *bus);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 5/5] configs: am65x_evm_a53: enable networking

2019-07-08 Thread Keerthy



On 09/07/19 4:27 AM, Joe Hershberger wrote:

On Thu, Jun 6, 2019 at 7:15 AM Keerthy  wrote:


From: Grygorii Strashko 

Enable TI K3 AM65x CPSW NUSS driver.

Signed-off-by: Grygorii Strashko 
Signed-off-by: Keerthy 
Reviewed-by: Tom Rini 


Question below, but...

Acked-by: Joe Hershberger 


---
  configs/am65x_evm_a53_defconfig | 7 +++
  1 file changed, 7 insertions(+)

diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
index 41cf0100fa..5d33b127b1 100644
--- a/configs/am65x_evm_a53_defconfig
+++ b/configs/am65x_evm_a53_defconfig
@@ -44,6 +44,7 @@ CONFIG_SPL_MULTI_DTB_FIT_NO_COMPRESSION=y
  CONFIG_ENV_IS_IN_FAT=y
  CONFIG_ENV_FAT_INTERFACE="mmc"
  CONFIG_ENV_FAT_DEVICE_AND_PART="1:1"
+CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_DM=y
  CONFIG_SPL_DM=y
  CONFIG_SPL_DM_SEQ_ALIAS=y
@@ -58,6 +59,11 @@ CONFIG_K3_SEC_PROXY=y
  CONFIG_DM_MMC=y
  CONFIG_MMC_SDHCI=y
  CONFIG_MMC_SDHCI_K3_ARASAN=y
+CONFIG_PHY_TI=y
+CONFIG_PHY_FIXED=y
+CONFIG_DM_ETH=y
+CONFIG_TI_AM65_CPSW_NUSS=y
+CONFIG_PHY=y
  CONFIG_PINCTRL=y
  # CONFIG_PINCTRL_GENERIC is not set
  CONFIG_SPL_PINCTRL=y
@@ -74,3 +80,4 @@ CONFIG_SOC_TI=y
  CONFIG_SYSRESET=y
  CONFIG_SPL_SYSRESET=y
  CONFIG_SYSRESET_TI_SCI=y
+CONFIG_HEXDUMP=y


Why is this needed?


Ah this was needed when some debug prints were enabled in prior 
versions. I will remove this in v6.


Thanks for the review.

Best Regards,
Keerthy




--
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/5] net: ethernet: ti: Introduce am654 gigabit eth switch subsystem driver

2019-07-08 Thread Keerthy



On 09/07/19 3:52 AM, Joe Hershberger wrote:

On Thu, Jun 6, 2019 at 7:14 AM Keerthy  wrote:


From: Grygorii Strashko 

Add new driver for the TI AM65x SoC Gigabit Ethernet Switch subsystem (CPSW
NUSS). It has two ports and provides Ethernet packet communication for the
device and can be configured as an Ethernet switch. CPSW NUSS features: the
Reduced Gigabit Media Independent Interface (RGMII), Reduced Media
Independent Interface (RMII), and the Management Data Input/Output (MDIO)
interface for physical layer device (PHY) management. The TI AM65x SoC has
integrated two-port Gigabit Ethernet Switch subsystem into device MCU
domain named MCU_CPSW0. One Ethernet port (port 1) with selectable RGMII
and RMII interfaces and an internal Communications Port Programming
Interface (CPPI) port (Host port 0).

Host Port 0 CPPI Packet Streaming Interface interface supports 8 TX
channels and on RX channels operating by TI am654 NAVSS Unified DMA
Peripheral Root Complex (UDMA-P) controller.

Signed-off-by: Grygorii Strashko 
Signed-off-by: Keerthy 
---
  drivers/net/ti/Kconfig  |   8 +
  drivers/net/ti/Makefile |   1 +
  drivers/net/ti/am65-cpsw-nuss.c | 794 
  3 files changed, 803 insertions(+)
  create mode 100644 drivers/net/ti/am65-cpsw-nuss.c

diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index 82bc9f5d03..ecf642de10 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -18,3 +18,11 @@ config DRIVER_TI_KEYSTONE_NET
 bool "TI Keystone 2 Ethernet"
 help
This driver supports the TI Keystone 2 Ethernet subsystem
+
+config TI_AM65_CPSW_NUSS
+   bool "TI K3 AM65x MCU CPSW Nuss Ethernet controller driver"
+   depends on ARCH_K3
+   select PHYLIB
+   help
+ This driver supports TI K3 MCU CPSW Nuss Ethernet controller
+ in Texas Instruments K3 AM65x SoCs.
diff --git a/drivers/net/ti/Makefile b/drivers/net/ti/Makefile
index ee3e4eb5d6..8d3808bb4b 100644
--- a/drivers/net/ti/Makefile
+++ b/drivers/net/ti/Makefile
@@ -5,3 +5,4 @@
  obj-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o cpsw-common.o cpsw_mdio.o
  obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
  obj-$(CONFIG_DRIVER_TI_KEYSTONE_NET) += keystone_net.o cpsw_mdio.o
+obj-$(CONFIG_TI_AM65_CPSW_NUSS) += am65-cpsw-nuss.o cpsw_mdio.o
diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
new file mode 100644
index 00..658cc34033
--- /dev/null
+++ b/drivers/net/ti/am65-cpsw-nuss.c


[ ... ]


+static const struct eth_ops am65_cpsw_ops = {
+   .start  = am65_cpsw_start,
+   .send   = am65_cpsw_send,
+   .recv   = am65_cpsw_recv,
+   .free_pkt   = am65_cpsw_free_pkt,
+   .stop   = am65_cpsw_stop,
+   .read_rom_hwaddr = am65_cpsw_read_rom_hwaddr,


I'm surprised that write_hwaddr is not included.


This driver is pretty much based on cpsw.c under drivers/net/ti.
I believe there is no mandate to write the hw mac address to specific IP 
register.





+};
+
+static int am65_cpsw_mdio_init(struct udevice *dev)
+{
+   struct am65_cpsw_priv *priv = dev_get_priv(dev);
+   struct am65_cpsw_common *cpsw_common = priv->cpsw_common;
+
+   if (!priv->has_phy || cpsw_common->bus)
+   return 0;
+
+   cpsw_common->bus = cpsw_mdio_init(dev->name,
+ cpsw_common->mdio_base,
+ cpsw_common->bus_freq,
+ clk_get_rate(_common->fclk));
+   if (!cpsw_common->bus)
+   return -EFAULT;
+
+   return 0;
+}
+
+static int am65_cpsw_phy_init(struct udevice *dev)
+{
+   struct am65_cpsw_priv *priv = dev_get_priv(dev);
+   struct am65_cpsw_common *cpsw_common = priv->cpsw_common;
+   struct eth_pdata *pdata = dev_get_platdata(dev);
+   struct phy_device *phydev;
+   u32 supported = PHY_GBIT_FEATURES;
+   int ret;
+
+   phydev = phy_connect(cpsw_common->bus,
+priv->phy_addr,
+priv->dev,
+pdata->phy_interface);
+
+   if (!phydev) {
+   dev_err(dev, "phy_connect() failed\n");
+   return -ENODEV;
+   }
+
+   phydev->supported &= supported;
+   if (pdata->max_speed) {
+   ret = phy_set_supported(phydev, pdata->max_speed);
+   if (ret)
+   return ret;
+   }
+   phydev->advertising = phydev->supported;
+
+#ifdef CONFIG_DM_ETH


Why is this needed? I would expect this to already be assumed.


Yes. This is redundant.




+   if (ofnode_valid(priv->phy_node))
+   phydev->node = priv->phy_node;
+#endif
+
+   priv->phydev = phydev;
+   ret = phy_config(phydev);
+   if (ret < 0)
+   pr_err("phy_config() failed: %d", ret);
+
+   return ret;
+}
+
+static int am65_cpsw_ofdata_parse_phy(struct udevice 

Re: [U-Boot] [PATCH] common: fdt_support: Add missing cpu_to_fdt32() to fdt_pci_dma_ranges()

2019-07-08 Thread Marek Vasut
On 7/9/19 2:49 AM, Marek Vasut wrote:
> The fdt_pci_dma_ranges() cannot work on e.g. ARM, since the DT entries
> endianness is not adjusted at all. Fix this.
> 
> Signed-off-by: Marek Vasut 
> Cc: Tom Rini 

+CC Simon

> ---
>  common/fdt_support.c | 25 ++---
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/common/fdt_support.c b/common/fdt_support.c
> index f31e9b0cc5..e0043e8da6 100644
> --- a/common/fdt_support.c
> +++ b/common/fdt_support.c
> @@ -671,30 +671,33 @@ int fdt_pci_dma_ranges(void *blob, int phb_off, struct 
> pci_controller *hose) {
>  
>   dma_range[0] = 0;
>   if (size >= 0x1ull)
> - dma_range[0] |= FDT_PCI_MEM64;
> + dma_range[0] |= cpu_to_fdt32(FDT_PCI_MEM64);
>   else
> - dma_range[0] |= FDT_PCI_MEM32;
> + dma_range[0] |= cpu_to_fdt32(FDT_PCI_MEM32);
>   if (hose->regions[r].flags & PCI_REGION_PREFETCH)
> - dma_range[0] |= FDT_PCI_PREFETCH;
> + dma_range[0] |= cpu_to_fdt32(FDT_PCI_PREFETCH);
>  #ifdef CONFIG_SYS_PCI_64BIT
> - dma_range[1] = bus_start >> 32;
> + dma_range[1] = cpu_to_fdt32(bus_start >> 32);
>  #else
>   dma_range[1] = 0;
>  #endif
> - dma_range[2] = bus_start & 0x;
> + dma_range[2] = cpu_to_fdt32(bus_start & 0x);
>  
>   if (addrcell == 2) {
> - dma_range[3] = phys_start >> 32;
> - dma_range[4] = phys_start & 0x;
> + dma_range[3] = cpu_to_fdt32(phys_start >> 32);
> + dma_range[4] = cpu_to_fdt32(phys_start & 0x);
>   } else {
> - dma_range[3] = phys_start & 0x;
> + dma_range[3] = cpu_to_fdt32(phys_start & 0x);
>   }
>  
>   if (sizecell == 2) {
> - dma_range[3 + addrcell + 0] = size >> 32;
> - dma_range[3 + addrcell + 1] = size & 0x;
> + dma_range[3 + addrcell + 0] =
> + cpu_to_fdt32(size >> 32);
> + dma_range[3 + addrcell + 1] =
> + cpu_to_fdt32(size & 0x);
>   } else {
> - dma_range[3 + addrcell + 0] = size & 0x;
> + dma_range[3 + addrcell + 0] =
> + cpu_to_fdt32(size & 0x);
>   }
>  
>   dma_range += (3 + addrcell + sizecell);
> 


-- 
Best regards,
Marek Vasut
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH V2] ARM: renesas: Update Gen3 PCIe dma-ranges before boot

2019-07-08 Thread Marek Vasut
Update "dma-ranges" DT property of all PCIe controllers in the system
with the up-to-date DRAM layout. This allows the PCIe controller take
full advantage of all the available DRAM.

Signed-off-by: Marek Vasut 
Cc: Nobuhiro Iwamatsu 
---
V2: - Drop support for older kernels
- Mark memory as prefetchable
---
 arch/arm/mach-rmobile/Kconfig  |  1 +
 board/renesas/rcar-common/common.c | 49 ++
 2 files changed, 50 insertions(+)

diff --git a/arch/arm/mach-rmobile/Kconfig b/arch/arm/mach-rmobile/Kconfig
index aafeb355ef..52ab891425 100644
--- a/arch/arm/mach-rmobile/Kconfig
+++ b/arch/arm/mach-rmobile/Kconfig
@@ -21,6 +21,7 @@ config RCAR_GEN3
imply CMD_GPT
imply CMD_UUID
imply CMD_MMC_SWRITE if MMC
+   imply OF_BOARD_SETUP if PCI
imply SUPPORT_EMMC_RPMB if MMC
imply SPL
imply SPL_BOARD_INIT
diff --git a/board/renesas/rcar-common/common.c 
b/board/renesas/rcar-common/common.c
index 292867e496..37f8a46d7e 100644
--- a/board/renesas/rcar-common/common.c
+++ b/board/renesas/rcar-common/common.c
@@ -8,6 +8,8 @@
  */
 
 #include 
+#include 
+#include 
 #include 
 
 #ifdef CONFIG_RCAR_GEN3
@@ -46,4 +48,51 @@ int dram_init_banksize(void)
 
return 0;
 }
+
+#if CONFIG_IS_ENABLED(OF_BOARD_SETUP) && CONFIG_IS_ENABLED(PCI)
+int ft_board_setup(void *blob, bd_t *bd)
+{
+   struct udevice *dev;
+   struct uclass *uc;
+   fdt_addr_t regs_addr;
+   int i, off, ret;
+
+   ret = uclass_get(UCLASS_PCI, );
+   if (ret)
+   return ret;
+
+   uclass_foreach_dev(dev, uc) {
+   struct pci_controller hose = { 0 };
+
+   for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+   if (hose.region_count == MAX_PCI_REGIONS) {
+   printf("maximum number of regions parsed, 
aborting\n");
+   break;
+   }
+
+   if (bd->bi_dram[i].size) {
+   
pci_set_region([hose.region_count++],
+  bd->bi_dram[i].start,
+  bd->bi_dram[i].start,
+  bd->bi_dram[i].size,
+  PCI_REGION_MEM |
+  PCI_REGION_PREFETCH |
+  PCI_REGION_SYS_MEMORY);
+   }
+   }
+
+   regs_addr = devfdt_get_addr_index(dev, 0);
+   off = fdt_node_offset_by_compat_reg(blob,
+   "renesas,pcie-rcar-gen3", regs_addr);
+   if (off < 0) {
+   printf("Failed to find PCIe node@%llx\n", regs_addr);
+   return off;
+   }
+
+   fdt_pci_dma_ranges(blob, off, );
+   }
+
+   return 0;
+}
+#endif
 #endif
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] common: fdt_support: Add missing cpu_to_fdt32() to fdt_pci_dma_ranges()

2019-07-08 Thread Marek Vasut
The fdt_pci_dma_ranges() cannot work on e.g. ARM, since the DT entries
endianness is not adjusted at all. Fix this.

Signed-off-by: Marek Vasut 
Cc: Tom Rini 
---
 common/fdt_support.c | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index f31e9b0cc5..e0043e8da6 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -671,30 +671,33 @@ int fdt_pci_dma_ranges(void *blob, int phb_off, struct 
pci_controller *hose) {
 
dma_range[0] = 0;
if (size >= 0x1ull)
-   dma_range[0] |= FDT_PCI_MEM64;
+   dma_range[0] |= cpu_to_fdt32(FDT_PCI_MEM64);
else
-   dma_range[0] |= FDT_PCI_MEM32;
+   dma_range[0] |= cpu_to_fdt32(FDT_PCI_MEM32);
if (hose->regions[r].flags & PCI_REGION_PREFETCH)
-   dma_range[0] |= FDT_PCI_PREFETCH;
+   dma_range[0] |= cpu_to_fdt32(FDT_PCI_PREFETCH);
 #ifdef CONFIG_SYS_PCI_64BIT
-   dma_range[1] = bus_start >> 32;
+   dma_range[1] = cpu_to_fdt32(bus_start >> 32);
 #else
dma_range[1] = 0;
 #endif
-   dma_range[2] = bus_start & 0x;
+   dma_range[2] = cpu_to_fdt32(bus_start & 0x);
 
if (addrcell == 2) {
-   dma_range[3] = phys_start >> 32;
-   dma_range[4] = phys_start & 0x;
+   dma_range[3] = cpu_to_fdt32(phys_start >> 32);
+   dma_range[4] = cpu_to_fdt32(phys_start & 0x);
} else {
-   dma_range[3] = phys_start & 0x;
+   dma_range[3] = cpu_to_fdt32(phys_start & 0x);
}
 
if (sizecell == 2) {
-   dma_range[3 + addrcell + 0] = size >> 32;
-   dma_range[3 + addrcell + 1] = size & 0x;
+   dma_range[3 + addrcell + 0] =
+   cpu_to_fdt32(size >> 32);
+   dma_range[3 + addrcell + 1] =
+   cpu_to_fdt32(size & 0x);
} else {
-   dma_range[3 + addrcell + 0] = size & 0x;
+   dma_range[3 + addrcell + 0] =
+   cpu_to_fdt32(size & 0x);
}
 
dma_range += (3 + addrcell + sizecell);
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] ARM: renesas: Update Gen3 PCIe dma-ranges before boot

2019-07-08 Thread Marek Vasut
Update "dma-ranges" DT property of all PCIe controllers in the system
with the up-to-date DRAM layout. This allows the PCIe controller take
full advantage of all the available DRAM, at least in theory.

This patch only populates up to two dma-ranges entry though, this is
because older versions of Linux kernel would fail to probe the PCIe
driver if there are more regions in the DT than the PCIe IP can use.

Signed-off-by: Marek Vasut 
Cc: Nobuhiro Iwamatsu 
---
 arch/arm/mach-rmobile/Kconfig  |  1 +
 board/renesas/rcar-common/common.c | 53 ++
 2 files changed, 54 insertions(+)

diff --git a/arch/arm/mach-rmobile/Kconfig b/arch/arm/mach-rmobile/Kconfig
index aafeb355ef..52ab891425 100644
--- a/arch/arm/mach-rmobile/Kconfig
+++ b/arch/arm/mach-rmobile/Kconfig
@@ -21,6 +21,7 @@ config RCAR_GEN3
imply CMD_GPT
imply CMD_UUID
imply CMD_MMC_SWRITE if MMC
+   imply OF_BOARD_SETUP if PCI
imply SUPPORT_EMMC_RPMB if MMC
imply SPL
imply SPL_BOARD_INIT
diff --git a/board/renesas/rcar-common/common.c 
b/board/renesas/rcar-common/common.c
index 292867e496..17127d4124 100644
--- a/board/renesas/rcar-common/common.c
+++ b/board/renesas/rcar-common/common.c
@@ -8,6 +8,8 @@
  */
 
 #include 
+#include 
+#include 
 #include 
 
 #ifdef CONFIG_RCAR_GEN3
@@ -46,4 +48,55 @@ int dram_init_banksize(void)
 
return 0;
 }
+
+#if CONFIG_IS_ENABLED(OF_BOARD_SETUP) && CONFIG_IS_ENABLED(PCI)
+int ft_board_setup(void *blob, bd_t *bd)
+{
+   struct udevice *dev;
+   struct uclass *uc;
+   fdt_addr_t regs_addr;
+   int i, off, ret;
+
+   ret = uclass_get(UCLASS_PCI, );
+   if (ret)
+   return ret;
+
+   uclass_foreach_dev(dev, uc) {
+   struct pci_controller hose = { 0 };
+
+   /*
+* Limit the number of memory regions to 2, which is the
+* maximum that older Linux kernel versions can handle
+* without aborting.
+*/
+   for (i = 0; i < min(CONFIG_NR_DRAM_BANKS, 2); i++) {
+   if (hose.region_count == MAX_PCI_REGIONS) {
+   printf("maximum number of regions parsed, 
aborting\n");
+   break;
+   }
+
+   if (bd->bi_dram[i].size) {
+   
pci_set_region([hose.region_count++],
+  bd->bi_dram[i].start,
+  bd->bi_dram[i].start,
+  bd->bi_dram[i].size,
+  PCI_REGION_MEM |
+  PCI_REGION_SYS_MEMORY);
+   }
+   }
+
+   regs_addr = devfdt_get_addr_index(dev, 0);
+   off = fdt_node_offset_by_compat_reg(blob,
+   "renesas,pcie-rcar-gen3", regs_addr);
+   if (off < 0) {
+   printf("Failed to find PCIe node@%llx\n", regs_addr);
+   return off;
+   }
+
+   fdt_pci_dma_ranges(blob, off, );
+   }
+
+   return 0;
+}
+#endif
 #endif
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 7/8] board: Add new slimbootloader board

2019-07-08 Thread Park, Aiden
Hi Bin,

> -Original Message-
> From: Park, Aiden
> Sent: Monday, July 8, 2019 9:48 AM
> To: Bin Meng 
> Cc: U-Boot Mailing List ; Simon Glass
> 
> Subject: RE: [PATCH v2 7/8] board: Add new slimbootloader board
> 
> Hi Bin,
> 
> > -Original Message-
> > From: Bin Meng [mailto:bmeng...@gmail.com]
> > Sent: Tuesday, July 2, 2019 7:14 AM
> > To: Park, Aiden 
> > Cc: U-Boot Mailing List ; Simon Glass
> > 
> > Subject: Re: [PATCH v2 7/8] board: Add new slimbootloader board
> >
> > Hi Aiden,
> >
> > On Wed, Jun 26, 2019 at 7:21 AM Park, Aiden 
> wrote:
> > >
> > > - Add new board/slimbootloader directory with minimum codes
> > > - Add slimbootloader configuration files
> > > - Add README in board/slimbootloader/slimbootloader/
> > >
> > > Signed-off-by: Aiden Park 
> > > ---
> > >  arch/x86/Kconfig  |  4 ++
> > >  board/slimbootloader/Kconfig  | 25 
> > >  board/slimbootloader/slimbootloader/Kconfig   | 51 +++
> > >  board/slimbootloader/slimbootloader/Makefile  |  5 ++
> > >  board/slimbootloader/slimbootloader/README| 58
> > +
> > >  .../slimbootloader/slimbootloader.c   | 17 +
> > >  board/slimbootloader/slimbootloader/start.S   |  9 +++
> > >  configs/slimbootloader_defconfig  | 64 +++
> > >  include/configs/slimbootloader.h  | 54 
> > >  9 files changed, 287 insertions(+)
> > >  create mode 100644 board/slimbootloader/Kconfig  create mode 100644
> > > board/slimbootloader/slimbootloader/Kconfig
> > >  create mode 100644 board/slimbootloader/slimbootloader/Makefile
> > >  create mode 100644 board/slimbootloader/slimbootloader/README
> > >  create mode 100644
> > > board/slimbootloader/slimbootloader/slimbootloader.c
> > >  create mode 100644 board/slimbootloader/slimbootloader/start.S
> > >  create mode 100644 configs/slimbootloader_defconfig  create mode
> > > 100644 include/configs/slimbootloader.h
> > >
> > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index
> > > 1612246dfc..3d57466a63 100644
> > > --- a/arch/x86/Kconfig
> > > +++ b/arch/x86/Kconfig
> > > @@ -77,6 +77,9 @@ config VENDOR_GOOGLE  config VENDOR_INTEL
> > > bool "Intel"
> > >
> > > +config VENDOR_SLIMBOOTLOADER
> > > +   bool "slimbootloader"
> >
> > I think this should be "Intel".
> Okay. Let me use VENDOR_INTEL.
> >
> > > +
> > >  endchoice
> > >
> > >  # subarchitectures-specific options below @@ -104,6 +107,7 @@
> > > source "board/efi/Kconfig"
> > >  source "board/emulation/Kconfig"
> > >  source "board/google/Kconfig"
> > >  source "board/intel/Kconfig"
> > > +source "board/slimbootloader/Kconfig"
> >
> > So it becomes a "board" in board/intel directory.
> Okay. Let me use intel.
> >
> > >
> > >  # platform-specific options below
> > >  source "arch/x86/cpu/baytrail/Kconfig"
> > > diff --git a/board/slimbootloader/Kconfig
> > > b/board/slimbootloader/Kconfig new file mode 100644 index
> > > 00..33c6fdf0aa
> > > --- /dev/null
> > > +++ b/board/slimbootloader/Kconfig
> > > @@ -0,0 +1,25 @@
> > > +# SPDX-License-Identifier: GPL-2.0+ # # Copyright (C) 2019 Intel
> > > +Corporation 
> > > +
> > > +if VENDOR_SLIMBOOTLOADER
> > > +
> > > +choice
> > > +   prompt "Select a board"
> > > +   optional
> > > +
> > > +config TARGET_SLIMBOOTLOADER
> > > +   bool "slimbootloader"
> > > +   help
> > > + This target is used for running U-Boot on top of Slim Bootloader
> > > + boot firmware as a payload. Slim Bootloader does memory
> > initialization
> > > + and silicon initialization, and it passes necessary information 
> > > in
> > > + HOB(Hand Off Block) to a payload. The payload is responsible 
> > > for OS
> > > + load from media and booting OS.
> > > + Refer to board/slimbootloader/slimbootloader/README for
> > > + the
> > details.
> > > +
> > > +endchoice
> > > +
> > > +source "board/slimbootloader/slimbootloader/Kconfig"
> > > +
> > > +endif
> > > diff --git a/board/slimbootloader/slimbootloader/Kconfig
> > > b/board/slimbootloader/slimbootloader/Kconfig
> > > new file mode 100644
> > > index 00..7262f2bf1b
> > > --- /dev/null
> > > +++ b/board/slimbootloader/slimbootloader/Kconfig
> > > @@ -0,0 +1,51 @@
> > > +# SPDX-License-Identifier: GPL-2.0+ # # Copyright (C) 2019 Intel
> > > +Corporation 
> > > +
> > > +if TARGET_SLIMBOOTLOADER
> > > +
> > > +config SYS_BOARD
> > > +   default "slimbootloader"
> > > +
> > > +config SYS_VENDOR
> > > +   default "slimbootloader"
> > > +
> > > +config SYS_SOC
> > > +   default "slimbootloader"
> > > +
> > > +config SYS_TEXT_BASE
> > > +   default 0x0010
> > > +
> > > +comment "slimbootloader-specific options"
> > > +
> > > +config SYS_CONFIG_NAME
> > > +   string "Board configuration file"
> > > +   default "slimbootloader"
> > > +   help
> > > + This option selects the board configuration file in 
> > > 

[U-Boot] [PATCH 4/5] ext4: gracefully fail on divide-by-0

2019-07-08 Thread Paul Emge
This patch checks for 0 in several ext4 headers and gracefully
fails instead of raising a divide-by-0 exception.

Signed-off-by: Paul Emge 
---
 fs/ext4/ext4_common.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 464c33d0d7..0d15e0c3cd 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -1571,8 +1571,12 @@ static int ext4fs_blockgroup
int log2blksz = get_fs()->dev_desc->log2blksz;
int desc_size = get_fs()->gdsize;
 
+   if (desc_size == 0)
+   return 0;
desc_per_blk = EXT2_BLOCK_SIZE(data) / desc_size;
 
+   if (desc_per_blk == 0)
+   return 0;
blkno = le32_to_cpu(data->sblock.first_data_block) + 1 +
group / desc_per_blk;
blkoff = (group % desc_per_blk) * desc_size;
@@ -1602,6 +1606,10 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, 
struct ext2_inode *inode)
 
/* It is easier to calculate if the first inode is 0. */
ino--;
+   if ( le32_to_cpu(sblock->inodes_per_group) == 0 || fs->inodesz == 0) {
+   free(blkgrp);
+   return 0;
+   }
status = ext4fs_blockgroup(data, ino / le32_to_cpu
   (sblock->inodes_per_group), blkgrp);
if (status == 0) {
@@ -1610,6 +1618,10 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, 
struct ext2_inode *inode)
}
 
inodes_per_block = EXT2_BLOCK_SIZE(data) / fs->inodesz;
+   if ( inodes_per_block == 0 ) {
+   free(blkgrp);
+   return 0;
+   }
blkno = ext4fs_bg_get_inode_table_id(blkgrp, fs) +
(ino % le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block;
blkoff = (ino % inodes_per_block) * fs->inodesz;
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 5/5] CVE-2019-13106: ext4: fix out-of-bounds memset

2019-07-08 Thread Paul Emge
In ext4fs_read_file in ext4fs.c, a memset can overwrite the bounds of
the destination memory region. This patch adds a check to disallow
this.

Signed-off-by: Paul Emge 
---
 fs/ext4/ext4fs.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index e2b740cac4..37b31d9f0f 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -61,6 +61,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
lbaint_t delayed_skipfirst = 0;
lbaint_t delayed_next = 0;
char *delayed_buf = NULL;
+   char *start_buf = buf;
short status;
struct ext_block_cache cache;
 
@@ -139,6 +140,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
}
} else {
int n;
+   int n_left;
if (previous_block_number != -1) {
/* spill */
status = ext4fs_devread(delayed_start,
@@ -153,8 +155,9 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
}
/* Zero no more than `len' bytes. */
n = blocksize - skipfirst;
-   if (n > len)
-   n = len;
+   n_left = len - ( buf - start_buf );
+   if (n > n_left)
+   n = n_left;
memset(buf, 0, n);
}
buf += blocksize - skipfirst;
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 3/5] CVE-2019-13104: ext4: check for underflow in ext4fs_read_file

2019-07-08 Thread Paul Emge
in ext4fs_read_file, it is possible for a broken/malicious file
system to cause a memcpy of a negative number of bytes, which
overflows all memory. This patch fixes the issue by checking for
a negative length.

Signed-off-by: Paul Emge 
---
 fs/ext4/ext4fs.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 85dc122f30..e2b740cac4 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -66,13 +66,15 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
 
ext_cache_init();
 
-   if (blocksize <= 0)
-   return -1;
-
/* Adjust len so it we can't read past the end of the file. */
if (len + pos > filesize)
len = (filesize - pos);
 
+   if (blocksize <= 0 || len <= 0) {
+   ext_cache_fini();
+   return -1;
+   }
+
blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
 
for (i = lldiv(pos, blocksize); i < blockcnt; i++) {
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/5] CVE-2019-13105: ext4: fix double-free in ext4_cache_read

2019-07-08 Thread Paul Emge
ext_cache_read doesn't null cache->buf, after freeing, which results
in a later function double-freeing it. This patch fixes
ext_cache_read to call ext_cache_fini instead of free.

Signed-off-by: Paul Emge 
---
 fs/ext4/ext4fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 26db677a1f..85dc122f30 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -286,7 +286,7 @@ int ext_cache_read(struct ext_block_cache *cache, lbaint_t 
block, int size)
if (!cache->buf)
return 0;
if (!ext4fs_devread(block, 0, size, cache->buf)) {
-   free(cache->buf);
+   ext_cache_fini(cache);
return 0;
}
cache->block = block;
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/5] CVE-2019-13103: disk: stop infinite recursion in DOS Partitions

2019-07-08 Thread Paul Emge
part_get_info_extended and print_partition_extended can recurse infinitely
while parsing a self-referential filesystem or one with a silly number of
extended partitions. This patch adds a limit to the number of recursive
partitions.

Signed-off-by: Paul Emge 
---
 disk/part_dos.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 936cee0d36..aae9d95906 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -23,6 +23,10 @@
 
 #define DOS_PART_DEFAULT_SECTOR 512
 
+/* should this be configurable? It looks like it's not very common at all
+ * to use large numbers of partitions */
+#define MAX_EXT_PARTS 256
+
 /* Convert char[4] in little endian format to the host format integer
  */
 static inline unsigned int le32_to_int(unsigned char *le32)
@@ -126,6 +130,13 @@ static void print_partition_extended(struct blk_desc 
*dev_desc,
dos_partition_t *pt;
int i;
 
+   /* set a maximum recursion level */
+   if (part_num > MAX_EXT_PARTS)
+   {
+   printf("** Nested DOS partitions detected, stopping **\n");
+   return;
+}
+
if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
printf ("** Can't read partition table on %d:" LBAFU " **\n",
dev_desc->devnum, ext_part_sector);
@@ -191,6 +202,13 @@ static int part_get_info_extended(struct blk_desc 
*dev_desc,
int i;
int dos_type;
 
+   /* set a maximum recursion level */
+   if (part_num > MAX_EXT_PARTS)
+   {
+   printf("** Nested DOS partitions detected, stopping **\n");
+   return -1;
+}
+
if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
printf ("** Can't read partition table on %d:" LBAFU " **\n",
dev_desc->devnum, ext_part_sector);
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 6/6] net: macb: apply sane DMA configuration

2019-07-08 Thread Joe Hershberger
On Tue, Jun 11, 2019 at 10:51 AM Ramon Fried  wrote:
>
> DMA configuration was heavily dependent on the HW
> defaults, add function to properly set the required
> fields, including the new dma_burst_length.
>
> Signed-off-by: Ramon Fried 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 5/6] net: macb: add dma_burst_length config

2019-07-08 Thread Joe Hershberger
On Tue, Jun 11, 2019 at 10:39 AM Ramon Fried  wrote:
>
> GEM support higher DMA burst writes/reads than the default (4).
> add configuration structure with dma burst length so it could be
> applied later to DMA configuration.
>
> Signed-off-by: Ramon Fried 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 4/6] net: macb: add support for SGMII phy interface

2019-07-08 Thread Joe Hershberger
On Tue, Jun 11, 2019 at 10:50 AM Ramon Fried  wrote:
>
> This patch adds support for the sgmii phy interface,
> available only to DM users, dictated by current driver
> design.
>
> Signed-off-by: Ramon Fried 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 3/6] net: macb: use bit access macro from header file

2019-07-08 Thread Joe Hershberger
On Tue, Jun 11, 2019 at 10:52 AM Ramon Fried  wrote:
>
> macb.h provides macros for reading/setting bitfields,
> in macb registers and descriptors. use that instead
> of redefining them in the source file.
>
> Signed-off-by: Ramon Fried 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/2] efi_loader: Return non-zero for error in efi_add_memory_map()

2019-07-08 Thread Bryan O'Donoghue
If we are trying to map address zero, as is the case on raspberrypi, then
we have no way of telling the difference between a valid
efi_add_memory_map() at zero and an overlapping error at zero.

Instead of returning zero, return EFI_NO_MAPPING on carve-out errors. In
include/efi.h we can see that EFI_SUCCESS is defined as 0, so it seems we
ought to return one of the available EFI error codes. EFI_NO_MAPPING seems
to make sense.

Fixes: 5d00995c361c ("efi_loader: Implement memory allocation and map")
Fixes: 74c16acce30b ("efi_loader: Don't allocate from memory holes")
Cc: Heinrich Schuchardt 
Cc: Alexander Graf 
Signed-off-by: Bryan O'Donoghue 
---
 lib/efi_loader/efi_memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 27379381e8..7d6aab255c 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -277,7 +277,7 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, 
int memory_type,
 * The user requested to only have RAM overlaps,
 * but we hit a non-RAM region. Error out.
 */
-   return 0;
+   return EFI_NO_MAPPING;
case EFI_CARVE_NO_OVERLAP:
/* Just ignore this list entry */
break;
@@ -307,7 +307,7 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, 
int memory_type,
 * The payload wanted to have RAM overlaps, but we overlapped
 * with an unallocated region. Error out.
 */
-   return 0;
+   return EFI_NO_MAPPING;
}
 
/* Add our new map */
-- 
2.22.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 0/2] efi_loader: Fix inconsistencies in efi_add_memory_map usage

2019-07-08 Thread Bryan O'Donoghue
These two patches fix some inconsistent usage around efi_add_memory_map().

The first patch fixes the case where there is a mapping for an address
starting at 0 as is the case on RPI3. We should not print an error for
this. efi_add_memory_map(start = 0, ...) succeeds but
efi_carve_out_dt_rsv() does not properly parse the result code.

The second patch fixes the result code returned by efi_add_memory_map() in
two instances. Returing zero is the same as returning EFI_SUCCESS, we
should return one of the error codes from include/efi.h only, not zero to
indicate failure.

Bryan O'Donoghue (2):
  efi_loader: Check the result of efi_add_memory_map against input addr
  efi_loader: Return non-zero for error in efi_add_memory_map()

 cmd/bootefi.c   | 4 ++--
 lib/efi_loader/efi_memory.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

-- 
2.22.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/2] efi_loader: Check the result of efi_add_memory_map against input addr

2019-07-08 Thread Bryan O'Donoghue
We should check the result of efi_add_memory_map() against the first input
parameter, not against zero.

In efi_carve_out_dt_rsv() add_efi_memory_map() gets passed addr = 0. The
function succeeds but the parsing routine interprets zero as an error.

Fix that now by comparing the result code of add_efi_memory_map() to the
first input parameter as other users of add_efi_memory_map() already do.

Removes this error on raspberrypi 3 boot: "FDT memrsv map 0: Failed to add
to map".

Fixes: 416e07e2cfcf ("efi: Drop error return in efi_carve_out_dt_rsv()")
Cc: Heinrich Schuchardt 
Cc: Alexander Graf 
Signed-off-by: Bryan O'Donoghue 
---
 cmd/bootefi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index c19256e00d..0b404ccbd1 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -169,8 +169,8 @@ static void efi_carve_out_dt_rsv(void *fdt)
 
pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK));
addr &= ~EFI_PAGE_MASK;
-   if (!efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE,
-   false))
+   if (efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE,
+  false) != addr)
printf("FDT memrsv map %d: Failed to add to map\n", i);
}
 }
-- 
2.22.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 2/6] net: macb: add support for faster clk rates

2019-07-08 Thread Joe Hershberger
On Tue, Jun 11, 2019 at 10:40 AM Ramon Fried  wrote:
>
> add support for clock rates higher than 2.4Mhz
>
> Signed-off-by: Ramon Fried 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/6] net: macb: sync header definitions as taken from Linux

2019-07-08 Thread Joe Hershberger
On Tue, Jun 11, 2019 at 10:51 AM Ramon Fried  wrote:
>
> Few registers and bits were added by Cadence and
> they were not updated in the headers.
> Take the latest definitions as defined in Linux
> header (5.1) that also includes some comments
> about existing registers.
>
> One register was improperly named (UR), fix that.
>
> Signed-off-by: Ramon Fried 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3] net: phy: cortina: Use block layer to read from mmc

2019-07-08 Thread Joe Hershberger
On Tue, Jun 11, 2019 at 1:27 AM Yinbo Zhu  wrote:
>
> This patch is to use block layer to read from mmc in cortina
>
> Signed-off-by: Yinbo Zhu 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [RESEND Patch] net: mscc: refactor mscc_miim

2019-07-08 Thread Joe Hershberger
On Sun, Jun 9, 2019 at 8:28 AM Horatiu Vultur
 wrote:
>
> Because all MSCC SoC use the same MDIO bus, put the implementation in
> one common file(mscc_miim) and make all the other MSCC network drivers to
> use these functions.
>
> Signed-off-by: Horatiu Vultur 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 2/2] net: macb: Add support for 1000-baseX

2019-07-08 Thread Joe Hershberger
On Fri, Jun 7, 2019 at 8:48 AM Radu Pirea  wrote:
>
> Macb can be used with Xilinx PCS/PMA PHY in fpga which is a 1000-baseX
> phy(lpa 0x41e0). This patch adds checks for LPA_1000XFULL and
> LPA_1000XHALF bits.
>
> Signed-off-by: Radu Pirea 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/2] net: macb: Fixed reading MII_LPA register

2019-07-08 Thread Joe Hershberger
On Fri, Jun 7, 2019 at 8:48 AM Radu Pirea  wrote:
>
> If macb is gem and is gigabit capable, lpa value is not read from
> the right register(MII_LPA) and is read from MII_STAT1000. This patch
> fixes reading of the lpa value.
>
> Signed-off-by: Radu Pirea 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 5/5] configs: am65x_evm_a53: enable networking

2019-07-08 Thread Joe Hershberger
On Thu, Jun 6, 2019 at 7:15 AM Keerthy  wrote:
>
> From: Grygorii Strashko 
>
> Enable TI K3 AM65x CPSW NUSS driver.
>
> Signed-off-by: Grygorii Strashko 
> Signed-off-by: Keerthy 
> Reviewed-by: Tom Rini 

Question below, but...

Acked-by: Joe Hershberger 

> ---
>  configs/am65x_evm_a53_defconfig | 7 +++
>  1 file changed, 7 insertions(+)
>
> diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
> index 41cf0100fa..5d33b127b1 100644
> --- a/configs/am65x_evm_a53_defconfig
> +++ b/configs/am65x_evm_a53_defconfig
> @@ -44,6 +44,7 @@ CONFIG_SPL_MULTI_DTB_FIT_NO_COMPRESSION=y
>  CONFIG_ENV_IS_IN_FAT=y
>  CONFIG_ENV_FAT_INTERFACE="mmc"
>  CONFIG_ENV_FAT_DEVICE_AND_PART="1:1"
> +CONFIG_NET_RANDOM_ETHADDR=y
>  CONFIG_DM=y
>  CONFIG_SPL_DM=y
>  CONFIG_SPL_DM_SEQ_ALIAS=y
> @@ -58,6 +59,11 @@ CONFIG_K3_SEC_PROXY=y
>  CONFIG_DM_MMC=y
>  CONFIG_MMC_SDHCI=y
>  CONFIG_MMC_SDHCI_K3_ARASAN=y
> +CONFIG_PHY_TI=y
> +CONFIG_PHY_FIXED=y
> +CONFIG_DM_ETH=y
> +CONFIG_TI_AM65_CPSW_NUSS=y
> +CONFIG_PHY=y
>  CONFIG_PINCTRL=y
>  # CONFIG_PINCTRL_GENERIC is not set
>  CONFIG_SPL_PINCTRL=y
> @@ -74,3 +80,4 @@ CONFIG_SOC_TI=y
>  CONFIG_SYSRESET=y
>  CONFIG_SPL_SYSRESET=y
>  CONFIG_SYSRESET_TI_SCI=y
> +CONFIG_HEXDUMP=y

Why is this needed?

> --
> 2.17.1
>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 4/5] arm64: dts: k3-am654-base-board: add mcu cpsw nuss pinmux and phy defs

2019-07-08 Thread Joe Hershberger
On Thu, Jun 6, 2019 at 7:15 AM Keerthy  wrote:
>
> From: Grygorii Strashko 
>
> Add mcu cpsw nuss pinmux and phy defs required by cpsw.
>
> Signed-off-by: Grygorii Strashko 
> Signed-off-by: Keerthy 
> Reviewed-by: Tom Rini 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 3/5] arm64: dts: ti: k3-am65: add mcu cpsw node

2019-07-08 Thread Joe Hershberger
On Thu, Jun 6, 2019 at 7:15 AM Keerthy  wrote:
>
> From: Grygorii Strashko 
>
> Add mcu cpsw and its components along with scm_conf node
> to have ethernet functional.
>
> Signed-off-by: Grygorii Strashko 
> Signed-off-by: Keerthy 
> Reviewed-by: Tom Rini 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 2/5] net: ethernet: ti: Introduce am654 gigabit eth switch subsystem driver

2019-07-08 Thread Joe Hershberger
On Thu, Jun 6, 2019 at 7:14 AM Keerthy  wrote:
>
> From: Grygorii Strashko 
>
> Add new driver for the TI AM65x SoC Gigabit Ethernet Switch subsystem (CPSW
> NUSS). It has two ports and provides Ethernet packet communication for the
> device and can be configured as an Ethernet switch. CPSW NUSS features: the
> Reduced Gigabit Media Independent Interface (RGMII), Reduced Media
> Independent Interface (RMII), and the Management Data Input/Output (MDIO)
> interface for physical layer device (PHY) management. The TI AM65x SoC has
> integrated two-port Gigabit Ethernet Switch subsystem into device MCU
> domain named MCU_CPSW0. One Ethernet port (port 1) with selectable RGMII
> and RMII interfaces and an internal Communications Port Programming
> Interface (CPPI) port (Host port 0).
>
> Host Port 0 CPPI Packet Streaming Interface interface supports 8 TX
> channels and on RX channels operating by TI am654 NAVSS Unified DMA
> Peripheral Root Complex (UDMA-P) controller.
>
> Signed-off-by: Grygorii Strashko 
> Signed-off-by: Keerthy 
> ---
>  drivers/net/ti/Kconfig  |   8 +
>  drivers/net/ti/Makefile |   1 +
>  drivers/net/ti/am65-cpsw-nuss.c | 794 
>  3 files changed, 803 insertions(+)
>  create mode 100644 drivers/net/ti/am65-cpsw-nuss.c
>
> diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
> index 82bc9f5d03..ecf642de10 100644
> --- a/drivers/net/ti/Kconfig
> +++ b/drivers/net/ti/Kconfig
> @@ -18,3 +18,11 @@ config DRIVER_TI_KEYSTONE_NET
> bool "TI Keystone 2 Ethernet"
> help
>This driver supports the TI Keystone 2 Ethernet subsystem
> +
> +config TI_AM65_CPSW_NUSS
> +   bool "TI K3 AM65x MCU CPSW Nuss Ethernet controller driver"
> +   depends on ARCH_K3
> +   select PHYLIB
> +   help
> + This driver supports TI K3 MCU CPSW Nuss Ethernet controller
> + in Texas Instruments K3 AM65x SoCs.
> diff --git a/drivers/net/ti/Makefile b/drivers/net/ti/Makefile
> index ee3e4eb5d6..8d3808bb4b 100644
> --- a/drivers/net/ti/Makefile
> +++ b/drivers/net/ti/Makefile
> @@ -5,3 +5,4 @@
>  obj-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o cpsw-common.o cpsw_mdio.o
>  obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
>  obj-$(CONFIG_DRIVER_TI_KEYSTONE_NET) += keystone_net.o cpsw_mdio.o
> +obj-$(CONFIG_TI_AM65_CPSW_NUSS) += am65-cpsw-nuss.o cpsw_mdio.o
> diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
> new file mode 100644
> index 00..658cc34033
> --- /dev/null
> +++ b/drivers/net/ti/am65-cpsw-nuss.c

[ ... ]

> +static const struct eth_ops am65_cpsw_ops = {
> +   .start  = am65_cpsw_start,
> +   .send   = am65_cpsw_send,
> +   .recv   = am65_cpsw_recv,
> +   .free_pkt   = am65_cpsw_free_pkt,
> +   .stop   = am65_cpsw_stop,
> +   .read_rom_hwaddr = am65_cpsw_read_rom_hwaddr,

I'm surprised that write_hwaddr is not included.

> +};
> +
> +static int am65_cpsw_mdio_init(struct udevice *dev)
> +{
> +   struct am65_cpsw_priv *priv = dev_get_priv(dev);
> +   struct am65_cpsw_common *cpsw_common = priv->cpsw_common;
> +
> +   if (!priv->has_phy || cpsw_common->bus)
> +   return 0;
> +
> +   cpsw_common->bus = cpsw_mdio_init(dev->name,
> + cpsw_common->mdio_base,
> + cpsw_common->bus_freq,
> + clk_get_rate(_common->fclk));
> +   if (!cpsw_common->bus)
> +   return -EFAULT;
> +
> +   return 0;
> +}
> +
> +static int am65_cpsw_phy_init(struct udevice *dev)
> +{
> +   struct am65_cpsw_priv *priv = dev_get_priv(dev);
> +   struct am65_cpsw_common *cpsw_common = priv->cpsw_common;
> +   struct eth_pdata *pdata = dev_get_platdata(dev);
> +   struct phy_device *phydev;
> +   u32 supported = PHY_GBIT_FEATURES;
> +   int ret;
> +
> +   phydev = phy_connect(cpsw_common->bus,
> +priv->phy_addr,
> +priv->dev,
> +pdata->phy_interface);
> +
> +   if (!phydev) {
> +   dev_err(dev, "phy_connect() failed\n");
> +   return -ENODEV;
> +   }
> +
> +   phydev->supported &= supported;
> +   if (pdata->max_speed) {
> +   ret = phy_set_supported(phydev, pdata->max_speed);
> +   if (ret)
> +   return ret;
> +   }
> +   phydev->advertising = phydev->supported;
> +
> +#ifdef CONFIG_DM_ETH

Why is this needed? I would expect this to already be assumed.

> +   if (ofnode_valid(priv->phy_node))
> +   phydev->node = priv->phy_node;
> +#endif
> +
> +   priv->phydev = phydev;
> +   ret = phy_config(phydev);
> +   if (ret < 0)
> +   pr_err("phy_config() failed: %d", ret);
> +
> +   return ret;
> +}
> +
> +static int am65_cpsw_ofdata_parse_phy(struct udevice 

Re: [U-Boot] [EXT] Re: [PATCH 1/2 v3] net: introduce MDIO DM class for MDIO devices

2019-07-08 Thread Alex Marginean

On 7/9/2019 12:40 AM, Joe Hershberger wrote:

On Fri, Jun 14, 2019 at 1:26 PM Alex Marginean  wrote:


Hi Nevo,

On 6/14/2019 7:55 PM, Nevo Hed wrote:

Hi Alex

In another thread (https://lists.denx.de/pipermail/u-boot/2019-June/371933.html)
I asked Ken (before learning of their cut-backs) if I should take a
stab at re-integrating his work
where Joe also pointed out the impending acceptance of your work.

I'm not sure where we left off here in this thread and wondering if
you are working on that or not.  Ive been staring at this for a bit
and ready to take a stab at it if you are not.


I am planning to add helpers to MDIO uclass, along the lines Ken sent
initially, on top of the current patch.  It looks like the helpers would
fit just fine.  I didn't get to do it yet though.


I'm intending to take this as is... I assume that fits with your plan for this.


Thanks Joe, it does fit with the plan so far.
Nevo and I started a conversation on the side on a respin of the Marvell
MDIO driver, I'll send that out when it's ready too.

Alex



Thanks,
-Joe



One difference between the two DM MDIO implementations is the way MDIO
ops work, the patch I sent abstracts away the legacy mii_bus from DM
MDIO driver.  I would keep that as it, which means a bit more rework on
the marvell driver.  I didn't look into this in detail yet.
I think I can send a version of the helpers in [1] in about a week,
maybe more, right now I'm trying to get MDIO MUX DM support out for
review plus some updates for the NXP platform I'm working on.  I can
take a stab at porting the marvell driver too, but I can't test it.
If you want to put some time into this right now feel free to do it :)



if easier - i'm `nhed73` on the #u-boot irc channel

Thanks
---Nevo


I can join if you want to discuss details, let me know.

Thanks!
Alex




On Tue, Jun 11, 2019 at 8:04 AM Alexandru Marginean
 wrote:


Hi Ken,

On 6/11/2019 12:44 PM, Ken Ma wrote:

Hi Alex

Thanks a lot for your information!

I think our patches have no essential difference.
The 2 patches have only small implementation difference:
In my patch, mii bus ops functions(read/write/reset...) need to be
implemented while in your patch mdio bus functions need to be
implemented and then mii bus ops functions will call mdio bus ops
functions. > I had planned to reuse those existed mii ops functions such as
smc911x_miiphy_read/ smc911x_miiphy_write/ sun8i_mdio_read/
sun8i_mdio_write... then it is easy for turning old mdio driver to
DM. >
Now I am not working on u-boot, so I am sorry that I will not do the pulling 
work.

Yours,
Ken


OK, I think I get what you wanted to do.  Either way it's not too
difficult to convert existing MDIOs to DM, but they have to start using
struct udevice.  That's similar to what was done on DM_ETH and others.

The helpers mapping eth/phy/mdio make sense and could be useful, that's
something I'll try to look into.

Thank you!
Alex




-Original Message-
From: Alex Marginean 
Sent: Tuesday, June 11, 2019 9:18 AM
To: joe.hershber...@ni.com; Ken Ma 
Cc: u-boot ; Joseph Hershberger 

Subject: [EXT] Re: [U-Boot] [PATCH 1/2 v3] net: introduce MDIO DM class for 
MDIO devices

External Email

--
+Ken,

Hi Joe,

On 6/10/2019 11:25 PM, Joe Hershberger wrote:

On Mon, Jun 3, 2019 at 11:11 AM Alex Marginean  wrote:


Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
stand-alone devices.  Useful in particular for systems that support
DM_ETH and have a stand-alone MDIO hardware block shared by multiple
Ethernet interfaces.

Signed-off-by: Alex Marginean 
---

Changes in v2:
- fixed several comments using wrong API names
- dropped dm_ from names of internal functions that don't use 
udevice *
- fixed UCLASS driver name
- added missing mdio_unregister in dm_mdio_pre_remove
- added a comment on why spaces in names aren't ok
- added a comment on how static mdio_read/_write/_reset functions
are used
Changes in v3:
- none



Not sure if you already noticed this [1] or not, but there may be
something there that you want to incorporate or maybe not.

Cheers,
-Joe

[1] - https://patchwork.ozlabs.org/patch/939726/



I didn't notice it, thanks for pointing it out!
Apart from the obvious overlap of adding UCLASS_MDIO and code like _post_probe 
they seem to deal with different needs.

Ken, can you please take a look at the patch I sent?  It has a wrapper over 
phy_connect, but provides no helpers on how the caller would get the PHY ADDR.  
Do you want to try pulling the API you add on top of the patch I sent, or do 
you want me to try?  It looks like it would work with minimal effort.

Thank you!
Alex



___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

___
U-Boot mailing list

Re: [U-Boot] [ANN] U-Boot v2019.07 released

2019-07-08 Thread Tom Rini
On Mon, Jul 08, 2019 at 10:50:12PM +0100, Peter Robinson wrote:
> Hi Tom,
> 
> > So it is release day and once again we've had a few important fixes come
> > in over the last few days.  But I still feel comfortable doing the
> > release today.  Our next release is v2019.10 and I am hopeful this cycle
> > of fixes coming in at the end will happen, rather than seeing problems
> > discovered after release.
> >
> > After the last release we had seen DM conversion deadlines pass, and
> > then in some cases we've seen some more conversion progress and in
> > others we're still working on it, and in still other cases we've just
> > removed features to see if people are in fact using the hardware still.
> > With v2019.07 we've now gone past the deadline for some block devices
> > and PCI and SPI flash, so I expect things to be moving to requiring
> > CONFIG_DEPRECATED now.
> >
> > So with that, the merge window is open and we're looking at doing the
> > v2019.07 release on July 8th, 2019.
> 
> I'm guessing that date is a copy paste error?

Indeed, oops.  v2019.10 on October 7th, 2019.  Thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 1/5] driver: net: ti: cpsw-mdio: use phys_addr_t for mdio_base addr

2019-07-08 Thread Joe Hershberger
On Thu, Jun 6, 2019 at 7:13 AM Keerthy  wrote:
>
> Use phys_addr_t for mdio_base address to avoid build
> warnings on arm64 and dra7. Cast it to uintprt_t before
> assigning to regs.
>
> Signed-off-by: Grygorii Strashko 
> Signed-off-by: Keerthy 
> Reviewed-by: Tom Rini 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [ANN] U-Boot v2019.07 released

2019-07-08 Thread Peter Robinson
Hi Tom,

> So it is release day and once again we've had a few important fixes come
> in over the last few days.  But I still feel comfortable doing the
> release today.  Our next release is v2019.10 and I am hopeful this cycle
> of fixes coming in at the end will happen, rather than seeing problems
> discovered after release.
>
> After the last release we had seen DM conversion deadlines pass, and
> then in some cases we've seen some more conversion progress and in
> others we're still working on it, and in still other cases we've just
> removed features to see if people are in fact using the hardware still.
> With v2019.07 we've now gone past the deadline for some block devices
> and PCI and SPI flash, so I expect things to be moving to requiring
> CONFIG_DEPRECATED now.
>
> So with that, the merge window is open and we're looking at doing the
> v2019.07 release on July 8th, 2019.

I'm guessing that date is a copy paste error?

Peter
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 0/5] net: ethernet: ti: Introduce am654 gigabit eth switch subsystem driver

2019-07-08 Thread Joe Hershberger
On Tue, Jul 2, 2019 at 12:07 AM Keerthy  wrote:
>
>
>
> On 06/06/19 5:43 PM, Keerthy wrote:
> > Add new driver for the TI AM65x SoC Gigabit Ethernet Switch subsystem (CPSW
> > NUSS). It has two ports and provides Ethernet packet communication for the
> > device and can be configured as an Ethernet switch. CPSW NUSS features: the
> > Reduced Gigabit Media Independent Interface (RGMII), Reduced Media
> > Independent Interface (RMII), and the Management Data Input/Output (MDIO)
> > interface for physical layer device (PHY) management. The TI AM65x SoC has
> > integrated two-port Gigabit Ethernet Switch subsystem into device MCU
> > domain named MCU_CPSW0. One Ethernet port (port 1) with selectable RGMII
> > and RMII interfaces and an internal Communications Port Programming
> > Interface (CPPI) port (Host port 0).
> >
> > Host Port 0 CPPI Packet Streaming Interface interface supports 8 TX
> > channels and on RX channels operating by TI am654 NAVSS Unified DMA
> > Peripheral Root Complex (UDMA-P) controller.
> >
> > Tested for tftp and booting to kernel on am654-evm.
>
> Tom,
>
> Please pull this series. If there are no further comments.

This is next on my list to review.

Thanks,
-Joe

> - Keerthy
>
> >
> > Changes in v5:
> >* Rebased to latest which meant adapting to pinmux macro change.
> >
> > Changes in v4:
> >
> >* Patch1 caused dra7 config build warnings corrected them.
> >
> >
> > Grygorii Strashko (4):
> >net: ethernet: ti: Introduce am654 gigabit eth switch subsystem driver
> >arm64: dts: ti: k3-am65: add mcu cpsw node
> >arm64: dts: k3-am654-base-board: add mcu cpsw nuss pinmux and phy defs
> >configs: am65x_evm_a53: enable networking
> >
> > Keerthy (1):
> >driver: net: ti: cpsw-mdio: use phys_addr_t for mdio_base addr
> >
> >   arch/arm/dts/k3-am65.dtsi|   2 +
> >   arch/arm/dts/k3-am654-base-board-u-boot.dtsi | 170 
> >   configs/am65x_evm_a53_defconfig  |   7 +
> >   drivers/net/ti/Kconfig   |   8 +
> >   drivers/net/ti/Makefile  |   1 +
> >   drivers/net/ti/am65-cpsw-nuss.c  | 794 +++
> >   drivers/net/ti/cpsw_mdio.c   |   4 +-
> >   drivers/net/ti/cpsw_mdio.h   |   2 +-
> >   8 files changed, 985 insertions(+), 3 deletions(-)
> >   create mode 100644 drivers/net/ti/am65-cpsw-nuss.c
> >
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [EXT] Re: [PATCH 1/2 v3] net: introduce MDIO DM class for MDIO devices

2019-07-08 Thread Joe Hershberger
On Fri, Jun 14, 2019 at 1:26 PM Alex Marginean  wrote:
>
> Hi Nevo,
>
> On 6/14/2019 7:55 PM, Nevo Hed wrote:
> > Hi Alex
> >
> > In another thread 
> > (https://lists.denx.de/pipermail/u-boot/2019-June/371933.html)
> > I asked Ken (before learning of their cut-backs) if I should take a
> > stab at re-integrating his work
> > where Joe also pointed out the impending acceptance of your work.
> >
> > I'm not sure where we left off here in this thread and wondering if
> > you are working on that or not.  Ive been staring at this for a bit
> > and ready to take a stab at it if you are not.
>
> I am planning to add helpers to MDIO uclass, along the lines Ken sent
> initially, on top of the current patch.  It looks like the helpers would
> fit just fine.  I didn't get to do it yet though.

I'm intending to take this as is... I assume that fits with your plan for this.

Thanks,
-Joe

>
> One difference between the two DM MDIO implementations is the way MDIO
> ops work, the patch I sent abstracts away the legacy mii_bus from DM
> MDIO driver.  I would keep that as it, which means a bit more rework on
> the marvell driver.  I didn't look into this in detail yet.
> I think I can send a version of the helpers in [1] in about a week,
> maybe more, right now I'm trying to get MDIO MUX DM support out for
> review plus some updates for the NXP platform I'm working on.  I can
> take a stab at porting the marvell driver too, but I can't test it.
> If you want to put some time into this right now feel free to do it :)
>
> >
> > if easier - i'm `nhed73` on the #u-boot irc channel
> >
> > Thanks
> >---Nevo
>
> I can join if you want to discuss details, let me know.
>
> Thanks!
> Alex
>
>
> >
> > On Tue, Jun 11, 2019 at 8:04 AM Alexandru Marginean
> >  wrote:
> >>
> >> Hi Ken,
> >>
> >> On 6/11/2019 12:44 PM, Ken Ma wrote:
> >>> Hi Alex
> >>>
> >>> Thanks a lot for your information!
> >>>
> >>> I think our patches have no essential difference.
> >>> The 2 patches have only small implementation difference:
> >>> In my patch, mii bus ops functions(read/write/reset...) need to be
> >>> implemented while in your patch mdio bus functions need to be
> >>> implemented and then mii bus ops functions will call mdio bus ops
> >>> functions. > I had planned to reuse those existed mii ops functions such 
> >>> as
> >>> smc911x_miiphy_read/ smc911x_miiphy_write/ sun8i_mdio_read/
> >>> sun8i_mdio_write... then it is easy for turning old mdio driver to
> >>> DM. >
> >>> Now I am not working on u-boot, so I am sorry that I will not do the 
> >>> pulling work.
> >>>
> >>> Yours,
> >>> Ken
> >>
> >> OK, I think I get what you wanted to do.  Either way it's not too
> >> difficult to convert existing MDIOs to DM, but they have to start using
> >> struct udevice.  That's similar to what was done on DM_ETH and others.
> >>
> >> The helpers mapping eth/phy/mdio make sense and could be useful, that's
> >> something I'll try to look into.
> >>
> >> Thank you!
> >> Alex
> >>
> >>
> >>>
> >>> -Original Message-
> >>> From: Alex Marginean 
> >>> Sent: Tuesday, June 11, 2019 9:18 AM
> >>> To: joe.hershber...@ni.com; Ken Ma 
> >>> Cc: u-boot ; Joseph Hershberger 
> >>> 
> >>> Subject: [EXT] Re: [U-Boot] [PATCH 1/2 v3] net: introduce MDIO DM class 
> >>> for MDIO devices
> >>>
> >>> External Email
> >>>
> >>> --
> >>> +Ken,
> >>>
> >>> Hi Joe,
> >>>
> >>> On 6/10/2019 11:25 PM, Joe Hershberger wrote:
>  On Mon, Jun 3, 2019 at 11:11 AM Alex Marginean  
>  wrote:
> >
> > Adds UCLASS_MDIO DM class supporting MDIO buses that are probed as
> > stand-alone devices.  Useful in particular for systems that support
> > DM_ETH and have a stand-alone MDIO hardware block shared by multiple
> > Ethernet interfaces.
> >
> > Signed-off-by: Alex Marginean 
> > ---
> >
> > Changes in v2:
> >- fixed several comments using wrong API names
> >- dropped dm_ from names of internal functions that don't 
> > use udevice *
> >- fixed UCLASS driver name
> >- added missing mdio_unregister in dm_mdio_pre_remove
> >- added a comment on why spaces in names aren't ok
> >- added a comment on how static mdio_read/_write/_reset 
> > functions
> >are used
> > Changes in v3:
> >- none
> 
> 
>  Not sure if you already noticed this [1] or not, but there may be
>  something there that you want to incorporate or maybe not.
> 
>  Cheers,
>  -Joe
> 
>  [1] - https://patchwork.ozlabs.org/patch/939726/
> 
> >>>
> >>> I didn't notice it, thanks for pointing it out!
> >>> Apart from the obvious overlap of adding UCLASS_MDIO and code like 
> >>> _post_probe they seem to deal with different needs.
> >>>
> >>> Ken, can you please take a look at the patch I sent?  It has a wrapper 
> >>> over 

Re: [U-Boot] [PATCH] net: mscc: serval: Remove delay when serdes is configured

2019-07-08 Thread Joe Hershberger
On Thu, May 23, 2019 at 2:48 PM Horatiu Vultur
 wrote:
>
> When serdes configuration was written in hardware there was a delay
> of 100ms to be sure that configuration was written. But the delay is not
> needed because already the function serdes_write it is checking that the
> operation finished.
>
> Therefore remove the mdelay. This improves the speed of configuring the
> network driver.
>
> Signed-off-by: Horatiu Vultur 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [u-boot 2/2] drivers/fsl-mc: Support DPSPARSER object and apply spb command

2019-07-08 Thread Joe Hershberger
On Wed, May 15, 2019 at 4:10 AM Florinel Iordache
 wrote:
>
> Add support for DPSPARSER object (create/destroy, open/close, apply spb)
> required to configure Soft Parser by using MC. Also add uboot command to
> apply a Soft Parser Blob by using a command like: fsl_mc apply spb
> 
>
> Signed-off-by: Florinel Iordache 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 31/31] binman: Add a test for nested and aligned sections

2019-07-08 Thread Simon Glass
Current test coverage is likely sufficient for the logic used to place
sections in the image. However it seems useful to add a test specifically
for nested sections, since these could have some unusual interactions.

Add a new test for this and aligned sections. This test failed before the
refactor to drop the bsection.py file (Section class), but passes now.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add patches to enhance the 'ls' command to filter which entries are shown
- Add patches to implement the 'extract' command

 tools/binman/ftest.py| 67 +++-
 tools/binman/test/131_pack_align_section.dts | 28 
 2 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/test/131_pack_align_section.dts

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 709fa0adc3f..6a40d1fdbb4 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -586,7 +586,7 @@ class TestFunctional(unittest.TestCase):
 
 def testSimpleDebug(self):
 """Test a simple binman run with debugging enabled"""
-data = self._DoTestFile('005_simple.dts', debug=True)
+self._DoTestFile('005_simple.dts', debug=True)
 
 def testDual(self):
 """Test that we can handle creating two images
@@ -2654,6 +2654,71 @@ class TestFunctional(unittest.TestCase):
 self.assertIn('Must specify exactly one entry path to write with -o',
   str(e.exception))
 
+def testPackAlignSection(self):
+"""Test that sections can have alignment"""
+self._DoReadFile('131_pack_align_section.dts')
+
+self.assertIn('image', control.images)
+image = control.images['image']
+entries = image.GetEntries()
+self.assertEqual(3, len(entries))
+
+# First u-boot
+self.assertIn('u-boot', entries)
+entry = entries['u-boot']
+self.assertEqual(0, entry.offset)
+self.assertEqual(0, entry.image_pos)
+self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
+self.assertEqual(len(U_BOOT_DATA), entry.size)
+
+# Section0
+self.assertIn('section0', entries)
+section0 = entries['section0']
+self.assertEqual(0x10, section0.offset)
+self.assertEqual(0x10, section0.image_pos)
+self.assertEqual(len(U_BOOT_DATA), section0.size)
+
+# Second u-boot
+section_entries = section0.GetEntries()
+self.assertIn('u-boot', section_entries)
+entry = section_entries['u-boot']
+self.assertEqual(0, entry.offset)
+self.assertEqual(0x10, entry.image_pos)
+self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
+self.assertEqual(len(U_BOOT_DATA), entry.size)
+
+# Section1
+self.assertIn('section1', entries)
+section1 = entries['section1']
+self.assertEqual(0x14, section1.offset)
+self.assertEqual(0x14, section1.image_pos)
+self.assertEqual(0x20, section1.size)
+
+# Second u-boot
+section_entries = section1.GetEntries()
+self.assertIn('u-boot', section_entries)
+entry = section_entries['u-boot']
+self.assertEqual(0, entry.offset)
+self.assertEqual(0x14, entry.image_pos)
+self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
+self.assertEqual(len(U_BOOT_DATA), entry.size)
+
+# Section2
+self.assertIn('section2', section_entries)
+section2 = section_entries['section2']
+self.assertEqual(0x4, section2.offset)
+self.assertEqual(0x18, section2.image_pos)
+self.assertEqual(4, section2.size)
+
+# Third u-boot
+section_entries = section2.GetEntries()
+self.assertIn('u-boot', section_entries)
+entry = section_entries['u-boot']
+self.assertEqual(0, entry.offset)
+self.assertEqual(0x18, entry.image_pos)
+self.assertEqual(len(U_BOOT_DATA), entry.contents_size)
+self.assertEqual(len(U_BOOT_DATA), entry.size)
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/tools/binman/test/131_pack_align_section.dts 
b/tools/binman/test/131_pack_align_section.dts
new file mode 100644
index 000..44478855b09
--- /dev/null
+++ b/tools/binman/test/131_pack_align_section.dts
@@ -0,0 +1,28 @@
+/dts-v1/;
+
+/ {
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   binman {
+   u-boot {
+   };
+   section0 {
+   type = "section";
+   align = <0x10>;
+   u-boot {
+   };
+   };
+   section1 {
+   type = "section";
+   align-size = <0x20>;
+   u-boot {
+   };
+   section2 {
+   type = "section";
+   u-boot {
+   

[U-Boot] [PATCH v2 21/31] binman: Allow listing the entries in an image

2019-07-08 Thread Simon Glass
It is useful to be able to summarise all the entries in an image, e.g. to
display this to this user. Add a new ListEntries() method to Entry, and
set up a way to call it through the Image class.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add the Entry object to EntryInfo as well
- Change Image.ListEntries() to BuildEntryList() since signature differs

 tools/binman/bsection.py   |  9 
 tools/binman/entry.py  | 36 
 tools/binman/etype/cbfs.py |  7 +++-
 tools/binman/etype/section.py  |  4 ++
 tools/binman/ftest.py  | 76 ++
 tools/binman/image.py  | 10 +
 tools/binman/test/127_list.dts | 33 +++
 7 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/test/127_list.dts

diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
index 9047e55a34a..082f424241c 100644
--- a/tools/binman/bsection.py
+++ b/tools/binman/bsection.py
@@ -10,6 +10,7 @@ from __future__ import print_function
 from collections import OrderedDict
 import sys
 
+from entry import Entry
 import fdt_util
 import re
 import state
@@ -512,3 +513,11 @@ class Section(object):
 image size is dynamic and its sections have not yet been packed
 """
 return self._image._size
+
+def ListEntries(self, entries, indent):
+"""Override this method to list all files in the section"""
+Entry.AddEntryInfo(entries, indent, self._name, 'section', self._size,
+   self._image_pos, None, self._offset,
+   self._parent_section)
+for entry in self._entries.values():
+entry.ListEntries(entries, indent + 1)
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index e38cb71c596..ee63d183532 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -33,6 +33,10 @@ our_path = os.path.dirname(os.path.realpath(__file__))
 # device-tree properties.
 EntryArg = namedtuple('EntryArg', ['name', 'datatype'])
 
+# Information about an entry for use when displaying summaries
+EntryInfo = namedtuple('EntryInfo', ['indent', 'name', 'etype', 'size',
+ 'image_pos', 'uncomp_size', 'offset',
+ 'entry'])
 
 class Entry(object):
 """An Entry in the section
@@ -617,3 +621,35 @@ features to produce new behaviours.
 if not self.HasSibling(name):
 return False
 return self.section.GetEntries()[name].image_pos
+
+@staticmethod
+def AddEntryInfo(entries, indent, name, etype, size, image_pos,
+ uncomp_size, offset, entry):
+"""Add a new entry to the entries list
+
+Args:
+entries: List (of EntryInfo objects) to add to
+indent: Current indent level to add to list
+name: Entry name (string)
+etype: Entry type (string)
+size: Entry size in bytes (int)
+image_pos: Position within image in bytes (int)
+uncomp_size: Uncompressed size if the entry uses compression, else
+None
+offset: Entry offset within parent in bytes (int)
+entry: Entry object
+"""
+entries.append(EntryInfo(indent, name, etype, size, image_pos,
+ uncomp_size, offset, entry))
+
+def ListEntries(self, entries, indent):
+"""Add files in this entry to the list of entries
+
+This can be overridden by subclasses which need different behaviour.
+
+Args:
+entries: List (of EntryInfo objects) to add to
+indent: Current indent level to add to list
+"""
+self.AddEntryInfo(entries, indent, self.name, self.etype, self.size,
+  self.image_pos, self.uncomp_size, self.offset, self)
diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index 175ecae1584..953d6f4868d 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -195,7 +195,6 @@ class Entry_cbfs(Entry):
 entry._type)
 if cfile:
 entry._cbfs_file = cfile
-entry.size = cfile.data_len
 data = cbfs.get_data()
 self.SetContents(data)
 return True
@@ -249,3 +248,9 @@ class Entry_cbfs(Entry):
 state.SetInt(entry._node, 'image-pos', entry.image_pos)
 if entry.uncomp_size is not None:
 state.SetInt(entry._node, 'uncomp-size', entry.uncomp_size)
+
+def ListEntries(self, entries, indent):
+"""Override this method to list all files in the section"""
+Entry.ListEntries(self, entries, indent)
+for entry in self._cbfs_entries.values():
+entry.ListEntries(entries, indent + 1)
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 23bf22113d4..178e89352e5 100644
--- a/tools/binman/etype/section.py

[U-Boot] [PATCH v2 19/31] binman: Support FDT update for CBFS

2019-07-08 Thread Simon Glass
It is useful to add the CBFS file information (offset, size, etc.) into
the FDT so that the layout is complete. Add support for this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/etype/cbfs.py| 49 +--
 tools/binman/ftest.py | 25 ++
 tools/binman/test/125_cbfs_update.dts | 21 
 3 files changed, 92 insertions(+), 3 deletions(-)
 create mode 100644 tools/binman/test/125_cbfs_update.dts

diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index 49baa6a4f63..a46bb98a033 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -11,6 +11,7 @@ import cbfs_util
 from cbfs_util import CbfsWriter
 from entry import Entry
 import fdt_util
+import state
 
 class Entry_cbfs(Entry):
 """Entry containing a Coreboot Filesystem (CBFS)
@@ -181,11 +182,17 @@ class Entry_cbfs(Entry):
 if not entry.ObtainContents():
 return False
 data = entry.GetData()
+cfile = None
 if entry._type == 'raw':
-cbfs.add_file_raw(entry._cbfs_name, data, entry._cbfs_offset,
-  entry._cbfs_compress)
+cfile = cbfs.add_file_raw(entry._cbfs_name, data,
+  entry._cbfs_offset,
+  entry._cbfs_compress)
 elif entry._type == 'stage':
-cbfs.add_file_stage(entry._cbfs_name, data, entry._cbfs_offset)
+cfile = cbfs.add_file_stage(entry._cbfs_name, data,
+entry._cbfs_offset)
+if cfile:
+entry._cbfs_file = cfile
+entry.size = cfile.data_len
 data = cbfs.get_data()
 self.SetContents(data)
 return True
@@ -203,3 +210,39 @@ class Entry_cbfs(Entry):
 self.Raise("Invalid compression in '%s': '%s'" %
(node.name, compress))
 self._cbfs_entries[entry._cbfs_name] = entry
+
+def SetImagePos(self, image_pos):
+"""Override this function to set all the entry properties from CBFS
+
+We can only do this once image_pos is known
+
+Args:
+image_pos: Position of this entry in the image
+"""
+Entry.SetImagePos(self, image_pos)
+
+# Now update the entries with info from the CBFS entries
+for entry in self._cbfs_entries.values():
+cfile = entry._cbfs_file
+entry.size = cfile.data_len
+entry.offset = cfile.calced_cbfs_offset
+entry.image_pos = self.image_pos + entry.offset
+if entry._cbfs_compress:
+entry.uncomp_size = cfile.memlen
+
+def AddMissingProperties(self):
+Entry.AddMissingProperties(self)
+for entry in self._cbfs_entries.values():
+entry.AddMissingProperties()
+if entry._cbfs_compress:
+state.AddZeroProp(entry._node, 'uncomp-size')
+
+def SetCalculatedProperties(self):
+"""Set the value of device-tree properties calculated by binman"""
+Entry.SetCalculatedProperties(self)
+for entry in self._cbfs_entries.values():
+state.SetInt(entry._node, 'offset', entry.offset)
+state.SetInt(entry._node, 'size', entry.size)
+state.SetInt(entry._node, 'image-pos', entry.image_pos)
+if entry.uncomp_size is not None:
+state.SetInt(entry._node, 'uncomp-size', entry.uncomp_size)
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 89e732fca31..999d8884aca 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -2160,6 +2160,31 @@ class TestFunctional(unittest.TestCase):
 }
 self.assertEqual(expected, props)
 
+def testCbfsUpdateFdt(self):
+"""Test that we can update the device tree with CBFS offset/size 
info"""
+self._CheckLz4()
+data, _, _, out_dtb_fname = self._DoReadFileDtb('125_cbfs_update.dts',
+update_dtb=True)
+dtb = fdt.Fdt(out_dtb_fname)
+dtb.Scan()
+props = self._GetPropTree(dtb, ['offset', 'size', 'image-pos',
+'uncomp-size'])
+del props['cbfs/u-boot:size']
+self.assertEqual({
+'offset': 0,
+'size': len(data),
+'image-pos': 0,
+'cbfs:offset': 0,
+'cbfs:size': len(data),
+'cbfs:image-pos': 0,
+'cbfs/u-boot:offset': 0x38,
+'cbfs/u-boot:uncomp-size': len(U_BOOT_DATA),
+'cbfs/u-boot:image-pos': 0x38,
+'cbfs/u-boot-dtb:offset': 0xb8,
+'cbfs/u-boot-dtb:size': len(U_BOOT_DATA),
+'cbfs/u-boot-dtb:image-pos': 0xb8,
+}, props)
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git 

[U-Boot] [PATCH v2 25/31] binman: Convert Image to a subclass of Entry

2019-07-08 Thread Simon Glass
When support for sections (and thus hierarchical images) was added to
binman, the decision was made to create a new Section class which could
be used by both Image and an Entry_section class. The decision between
using inheritance and composition was tricky to make, but in the end it
was decided that Image was different enough from Entry that it made sense
to put the implementation of sections in an entirely separate class. It
also has the advantage that core Image code does have to rely on an entry
class in the etype directory.

This work was mostly completed in commit:

   8f1da50ccc "binman: Refactor much of the image code into 'section'

As a result of this, the Section class has its own version of things like
offset and size and these must be kept in sync with the parent
Entry_section class in some cases.

In the last year it has become apparent that the cost of keeping things in
sync is larger than expected, since more and more code wants to access
these properties.

An alternative approach, previously considered and rejected, now seems
better.

Adjust Image to be a subclass of Entry_section. Move the code from Section
(in bsection.py) to Entry_section and delete Section. Update all tests
accordingly.

This requires substantial changes to Image. Overall the changes reduce
code size by about 240 lines. While much of that is just boilerplate from
Section, there are quite a few functions in Entry_section which now do not
need to be overiden from Entry. This suggests the change is beneficial
even without further functionality being added.

A side benefit is that the properties of sections are now consistent with
other entries. This fixes a problem in testListCmd() where some properties
are missing for sections.

Unfortunately this is a very large commit since it is not feasible to do
the migration piecemeal. Given the substantial tests available and the
100% code coverage of binman, we should be able to do this safely.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README.entries   |  21 +-
 tools/binman/bsection.py  | 523 --
 tools/binman/entry.py |   8 +-
 tools/binman/etype/files.py   |   3 +-
 tools/binman/etype/fmap.py|   2 +-
 tools/binman/etype/section.py | 431 +---
 tools/binman/ftest.py |  29 +-
 tools/binman/image.py | 129 +++--
 tools/binman/image_test.py|  18 +-
 9 files changed, 462 insertions(+), 702 deletions(-)
 delete mode 100644 tools/binman/bsection.py

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 598d8278a70..7ce88ee5da8 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -521,16 +521,21 @@ Entry: section: Entry that contains other entries
 -
 
 Properties / Entry arguments: (see binman README for more information)
-- size: Size of section in bytes
-- align-size: Align size to a particular power of two
-- pad-before: Add padding before the entry
-- pad-after: Add padding after the entry
-- pad-byte: Pad byte to use when padding
-- sort-by-offset: Reorder the entries by offset
-- end-at-4gb: Used to build an x86 ROM which ends at 4GB (2^32)
-- name-prefix: Adds a prefix to the name of every entry in the section
+pad-byte: Pad byte to use when padding
+sort-by-offset: True if entries should be sorted by offset, False if
+they must be in-order in the device tree description
+end-at-4gb: Used to build an x86 ROM which ends at 4GB (2^32)
+skip-at-start: Number of bytes before the first entry starts. These
+effectively adjust the starting offset of entries. For example,
+if this is 16, then the first entry would start at 16. An entry
+with offset = 20 would in fact be written at offset 4 in the image
+file, since the first 16 bytes are skipped when writing.
+name-prefix: Adds a prefix to the name of every entry in the section
 when writing out the map
 
+Since a section is also an entry, it inherits all the properies of entries
+too.
+
 A section is an entry which can contain other entries, thus allowing
 hierarchical images to be created. See 'Sections and hierarchical images'
 in the binman README for more information.
diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
deleted file mode 100644
index 082f424241c..000
--- a/tools/binman/bsection.py
+++ /dev/null
@@ -1,523 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-# Copyright (c) 2018 Google, Inc
-# Written by Simon Glass 
-#
-# Base class for sections (collections of entries)
-#
-
-from __future__ import print_function
-
-from collections import OrderedDict
-import sys
-
-from entry import Entry
-import fdt_util
-import re
-import state
-import tools
-
-class Section(object):
-"""A section which contains multiple entries
-
-A section represents a collection of entries. There must be one 

[U-Boot] [PATCH v2 24/31] binman: Support reading an image into an Image object

2019-07-08 Thread Simon Glass
It is possible to read an Image, locate its FDT map and then read it into
the binman data structures. This allows full access to the entries that
were written to the image. Add support for this.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Move 129_list_fdtmap.dts into the next commit
- Rename 128_decode_image_no_hdr.dts to 129_decode_image_nohdr.dts
- Update Image for LocateFdtmap() returning the position of the header
- Update test to use _DoReadFileRealDtb() helper

 tools/binman/entry.py|  5 +++
 tools/binman/ftest.py| 39 ++--
 tools/binman/image.py| 38 +++
 tools/binman/test/129_decode_image_nohdr.dts | 33 +
 4 files changed, 111 insertions(+), 4 deletions(-)
 create mode 100644 tools/binman/test/129_decode_image_nohdr.dts

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index ee63d183532..6c74f2a2175 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -162,6 +162,11 @@ class Entry(object):
 self.orig_offset = self.offset
 self.orig_size = self.size
 
+# These should not be set in input files, but are set in an FDT map,
+# which is also read by this code.
+self.image_pos = fdt_util.GetInt(self._node, 'image-pos')
+self.uncomp_size = fdt_util.GetInt(self._node, 'uncomp-size')
+
 self.align = fdt_util.GetInt(self._node, 'align')
 if tools.NotPowerOfTwo(self.align):
 raise ValueError("Node '%s': Alignment %s must be a power of two" %
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index ce66e3a2f20..f3a8e64ad13 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -30,6 +30,7 @@ import fdt_util
 import fmap_util
 import test_util
 import gzip
+from image import Image
 import state
 import tools
 import tout
@@ -2286,8 +2287,7 @@ class TestFunctional(unittest.TestCase):
 def testFindImageHeader(self):
 """Test locating a image header"""
 self._CheckLz4()
-data = self._DoReadFileDtb('128_decode_image.dts', use_real_dtb=True,
-   update_dtb=True)[0]
+data = self.data = self._DoReadFileRealDtb('128_decode_image.dts')
 image = control.images['image']
 entries = image.GetEntries()
 entry = entries['fdtmap']
@@ -2296,8 +2296,7 @@ class TestFunctional(unittest.TestCase):
 
 def testFindImageHeaderStart(self):
 """Test locating a image header located at the start of an image"""
-data = self._DoReadFileDtb('117_fdtmap_hdr_start.dts',
-   use_real_dtb=True, update_dtb=True)[0]
+data = self.data = self._DoReadFileRealDtb('117_fdtmap_hdr_start.dts')
 image = control.images['image']
 entries = image.GetEntries()
 entry = entries['fdtmap']
@@ -2309,6 +2308,38 @@ class TestFunctional(unittest.TestCase):
 data = self._DoReadFile('005_simple.dts')
 self.assertEqual(None, image_header.LocateHeaderOffset(data))
 
+def testReadImage(self):
+"""Test reading an image and accessing its FDT map"""
+self._CheckLz4()
+data = self.data = self._DoReadFileRealDtb('128_decode_image.dts')
+image_fname = tools.GetOutputFilename('image.bin')
+orig_image = control.images['image']
+image = Image.FromFile(image_fname)
+self.assertEqual(orig_image.GetEntries().keys(),
+ image.GetEntries().keys())
+
+orig_entry = orig_image.GetEntries()['fdtmap']
+entry = image.GetEntries()['fdtmap']
+self.assertEquals(orig_entry.offset, entry.offset)
+self.assertEquals(orig_entry.size, entry.size)
+self.assertEquals(orig_entry.image_pos, entry.image_pos)
+
+def testReadImageNoHeader(self):
+"""Test accessing an image's FDT map without an image header"""
+self._CheckLz4()
+data = self._DoReadFileRealDtb('129_decode_image_nohdr.dts')
+image_fname = tools.GetOutputFilename('image.bin')
+image = Image.FromFile(image_fname)
+self.assertTrue(isinstance(image, Image))
+self.assertEqual('image', image._name)
+
+def testReadImageFail(self):
+"""Test failing to read an image image's FDT map"""
+self._DoReadFile('005_simple.dts')
+image_fname = tools.GetOutputFilename('image.bin')
+with self.assertRaises(ValueError) as e:
+image = Image.FromFile(image_fname)
+self.assertIn("Cannot find FDT map in image", str(e.exception))
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/tools/binman/image.py b/tools/binman/image.py
index 6f4bd5d37b2..f890350a8d0 100644
--- a/tools/binman/image.py
+++ b/tools/binman/image.py
@@ -12,6 +12,9 @@ from operator import attrgetter
 import re
 import sys
 
+from etype import fdtmap
+from etype 

[U-Boot] [PATCH v2 26/31] binman: Support listing an image

2019-07-08 Thread Simon Glass
Add support for listing the entries in an image. This relies on the image
having an FDT map.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Adjust the test to not rely on lz4 compression version
- Allow listing subsets of the image
- Change list command from 'list' to 'ls'
- Deal with travis's old lz4 version by skipping tests as necessary
- Move patch 'Add a comment about CBFS test structure' to earlier series
- Move patch 'Allow cbfstool to be optional with tests' to earlier series
- Update output from 'list' command
- Update test to use _DoReadFileRealDtb() helper

 tools/binman/README   |  44 +++-
 tools/binman/cmdline.py   |   6 ++
 tools/binman/control.py   |  35 ++
 tools/binman/ftest.py |  82 ++
 tools/binman/image.py | 150 ++
 tools/binman/test/130_list_fdtmap.dts |  36 +++
 6 files changed, 352 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/test/130_list_fdtmap.dts

diff --git a/tools/binman/README b/tools/binman/README
index 9860633792f..146e0fd470a 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -490,6 +490,49 @@ see README.entries. This is generated from the source code 
using:
binman entry-docs >tools/binman/README.entries
 
 
+Listing images
+--
+
+It is possible to list the entries in an existing firmware image created by
+binman, provided that there is an 'fdtmap' entry in the image. For example:
+
+$ binman ls -i image.bin
+Name  Image-pos  Size  Entry-typeOffset  Uncomp-size
+--
+main-section  c00  section0
+  u-boot  0 4  u-boot 0
+  section 5fc  section4
+cbfs100   400  cbfs   0
+  u-boot138 4  u-boot38
+  u-boot-dtb180   108  u-boot-dtb80  3b5
+u-boot-dtb  500   1ff  u-boot-dtb   400  3b5
+  fdtmap6fc   381  fdtmap   6fc
+  image-header  bf8 8  image-header bf8
+
+This shows the hierarchy of the image, the position, size and type of each
+entry, the offset of each entry within its parent and the uncompressed size if
+the entry is compressed.
+
+It is also possible to list just some files in an image, e.g.
+
+$ binman ls -i image.bin section/cbfs
+Name  Image-pos  Size  Entry-type  Offset  Uncomp-size
+
+cbfs100   400  cbfs 0
+  u-boot138 4  u-boot  38
+  u-boot-dtb180   108  u-boot-dtb  80  3b5
+
+or with wildcards:
+
+$ binman ls -i image.bin "*cb*" "*head*"
+Name  Image-pos  Size  Entry-typeOffset  Uncomp-size
+--
+cbfs100   400  cbfs   0
+  u-boot138 4  u-boot38
+  u-boot-dtb180   108  u-boot-dtb80  3b5
+  image-header  bf8 8  image-header bf8
+
+
 Hashing Entries
 ---
 
@@ -825,7 +868,6 @@ Some ideas:
 - Add an option to decode an image into the constituent binaries
 - Support building an image for a board (-b) more completely, with a
   configurable build directory
-- Support listing files in images
 - Support logging of binman's operations, with different levels of verbosity
 - Support updating binaries in an image (with no size change / repacking)
 - Support updating binaries in an image (with repacking)
diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py
index a002105fc77..508232eabb5 100644
--- a/tools/binman/cmdline.py
+++ b/tools/binman/cmdline.py
@@ -65,6 +65,12 @@ controlled by a description in the board device tree.'''
 entry_parser = subparsers.add_parser('entry-docs',
 help='Write out entry documentation (see README.entries)')
 
+list_parser = subparsers.add_parser('ls', help='List files in an image')
+list_parser.add_argument('-i', '--image', type=str, required=True,
+ help='Image filename to list')
+list_parser.add_argument('paths', type=str, nargs='*',
+ help='Paths within file to list (wildcard)')
+
 test_parser = subparsers.add_parser('test', help='Run tests')
 test_parser.add_argument('-P', '--processes', type=int,
 help='set number of processes to use for running tests')
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 35faf115062..813c8b1bf9e 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -67,6 +67,37 @@ def WriteEntryDocs(modules, test_missing=None):
 

[U-Boot] [PATCH v2 20/31] binman: Detect bad CBFS file types

2019-07-08 Thread Simon Glass
Detect when an unknown or unsupported file type is specified and report
an error.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/etype/cbfs.py  |  3 +++
 tools/binman/ftest.py   |  6 ++
 tools/binman/test/126_cbfs_bad_type.dts | 17 +
 3 files changed, 26 insertions(+)
 create mode 100644 tools/binman/test/126_cbfs_bad_type.dts

diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index a46bb98a033..175ecae1584 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -190,6 +190,9 @@ class Entry_cbfs(Entry):
 elif entry._type == 'stage':
 cfile = cbfs.add_file_stage(entry._cbfs_name, data,
 entry._cbfs_offset)
+else:
+entry.Raise("Unknown cbfs-type '%s' (use 'raw', 'stage')" %
+entry._type)
 if cfile:
 entry._cbfs_file = cfile
 entry.size = cfile.data_len
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 999d8884aca..21bea6c9d13 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -2185,6 +2185,12 @@ class TestFunctional(unittest.TestCase):
 'cbfs/u-boot-dtb:image-pos': 0xb8,
 }, props)
 
+def testCbfsBadType(self):
+"""Test an image header with a no specified location is detected"""
+with self.assertRaises(ValueError) as e:
+self._DoReadFile('126_cbfs_bad_type.dts')
+self.assertIn("Unknown cbfs-type 'badtype'", str(e.exception))
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/tools/binman/test/126_cbfs_bad_type.dts 
b/tools/binman/test/126_cbfs_bad_type.dts
new file mode 100644
index 000..2cd6fc6d52d
--- /dev/null
+++ b/tools/binman/test/126_cbfs_bad_type.dts
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   binman {
+   cbfs {
+   size = <0x100>;
+   u-boot {
+   cbfs-type = "badtype";
+   };
+   };
+   };
+};
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 16/31] binman: Allow device-tree entries to be compressed

2019-07-08 Thread Simon Glass
At present the logic skips the blob class' handling of compression, so
this is not supported with device tree entries. Fix this.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Update test to use _DoReadFileRealDtb() helper

 tools/binman/etype/blob.py | 25 +
 tools/binman/etype/blob_dtb.py |  8 
 tools/binman/ftest.py  | 18 ++
 tools/binman/test/124_compress_dtb.dts | 14 ++
 4 files changed, 53 insertions(+), 12 deletions(-)
 create mode 100644 tools/binman/test/124_compress_dtb.dts

diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index ec94568ac0a..a4ff0efcebc 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -41,17 +41,26 @@ class Entry_blob(Entry):
 self.ReadBlobContents()
 return True
 
-def ReadBlobContents(self):
-# We assume the data is small enough to fit into memory. If this
-# is used for large filesystem image that might not be true.
-# In that case, Image.BuildImage() could be adjusted to use a
-# new Entry method which can read in chunks. Then we could copy
-# the data in chunks and avoid reading it all at once. For now
-# this seems like an unnecessary complication.
-indata = tools.ReadFile(self._pathname)
+def CompressData(self, indata):
 if self.compress != 'none':
 self.uncomp_size = len(indata)
 data = tools.Compress(indata, self.compress)
+return data
+
+def ReadBlobContents(self):
+"""Read blob contents into memory
+
+This function compresses the data before storing if needed.
+
+We assume the data is small enough to fit into memory. If this
+is used for large filesystem image that might not be true.
+In that case, Image.BuildImage() could be adjusted to use a
+new Entry method which can read in chunks. Then we could copy
+the data in chunks and avoid reading it all at once. For now
+this seems like an unnecessary complication.
+"""
+indata = tools.ReadFile(self._pathname)
+data = self.CompressData(indata)
 self.SetContents(data)
 return True
 
diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py
index 09d5d727138..88ed55d8865 100644
--- a/tools/binman/etype/blob_dtb.py
+++ b/tools/binman/etype/blob_dtb.py
@@ -23,11 +23,11 @@ class Entry_blob_dtb(Entry_blob):
 def ObtainContents(self):
 """Get the device-tree from the list held by the 'state' module"""
 self._filename = self.GetDefaultFilename()
-self._pathname, data = state.GetFdtContents(self._filename)
-self.SetContents(data)
-return True
+self._pathname, _ = state.GetFdtContents(self._filename)
+return Entry_blob.ReadBlobContents(self)
 
 def ProcessContents(self):
 """Re-read the DTB contents so that we get any calculated properties"""
-_, data = state.GetFdtContents(self._filename)
+_, indata = state.GetFdtContents(self._filename)
+data = self.CompressData(indata)
 return self.ProcessContentsUpdate(data)
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index aae8dbc1b33..89e732fca31 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -2142,6 +2142,24 @@ class TestFunctional(unittest.TestCase):
 self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)])
 self.assertEqual(b'aa', data[-2:])
 
+def testCompressDtb(self):
+"""Test that compress of device-tree files is supported"""
+self._CheckLz4()
+data = self.data = self._DoReadFileRealDtb('124_compress_dtb.dts')
+self.assertEqual(U_BOOT_DATA, data[:len(U_BOOT_DATA)])
+comp_data = data[len(U_BOOT_DATA):]
+orig = self._decompress(comp_data)
+dtb = fdt.Fdt.FromData(orig)
+dtb.Scan()
+props = self._GetPropTree(dtb, ['size', 'uncomp-size'])
+expected = {
+'u-boot:size': len(U_BOOT_DATA),
+'u-boot-dtb:uncomp-size': len(orig),
+'u-boot-dtb:size': len(comp_data),
+'size': len(data),
+}
+self.assertEqual(expected, props)
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/tools/binman/test/124_compress_dtb.dts 
b/tools/binman/test/124_compress_dtb.dts
new file mode 100644
index 000..46bfd8b265f
--- /dev/null
+++ b/tools/binman/test/124_compress_dtb.dts
@@ -0,0 +1,14 @@
+/dts-v1/;
+
+/ {
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   binman {
+   u-boot {
+   };
+   u-boot-dtb {
+   compress = "lz4";
+   };
+   };
+};
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 07/31] binman: Convert to use ArgumentParser

2019-07-08 Thread Simon Glass
This class is the new way to handle arguments in Python. Convert binman
over to use it. At the same time, introduce commands so that we can
separate out the different parts of binman functionality.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Don't allow global arguments after the command
- Fix up arguments in main Makefile
- Pass verbosity to tests via the setup_test_args() method
- Put --toolpath in the right place in functional tests

 .travis.yml   |  2 +-
 Makefile  |  4 +-
 test/run  |  4 +-
 tools/binman/README   |  8 ++--
 tools/binman/binman.py| 47 +++---
 tools/binman/cmdline.py   | 82 +--
 tools/binman/control.py   | 51 
 tools/binman/ftest.py | 66 +--
 tools/patman/test_util.py |  5 ++-
 9 files changed, 133 insertions(+), 136 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 70d89d3e233..2f604152090 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -147,7 +147,7 @@ script:
if [[ -n "${TEST_PY_TOOLS}" ]]; then
  PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt"
  PATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}"
- ./tools/binman/binman --toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools -t &&
+ ./tools/binman/binman --toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools test &&
  ./tools/patman/patman --test &&
  ./tools/buildman/buildman -t &&
  PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt"
diff --git a/Makefile b/Makefile
index f3857ab6a9b..ee0d3c90029 100644
--- a/Makefile
+++ b/Makefile
@@ -1196,9 +1196,9 @@ u-boot.ldr:   u-boot
 # ---
 # Use 'make BINMAN_DEBUG=1' to enable debugging
 quiet_cmd_binman = BINMAN  $@
-cmd_binman = $(srctree)/tools/binman/binman -u -d u-boot.dtb -O . -m \
+cmd_binman = $(srctree)/tools/binman/binman build -u -d u-boot.dtb -O . -m \
-I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
-   $(if $(BINMAN_DEBUG),-D) $(BINMAN_$(@F)) $<
+   $(if $(BINMAN_DEBUG),-D) $(BINMAN_$(@F))
 
 OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
 
diff --git a/test/run b/test/run
index b97647eba6f..d635622c106 100755
--- a/test/run
+++ b/test/run
@@ -40,7 +40,7 @@ export PYTHONPATH=${DTC_DIR}/pylibfdt
 export DTC=${DTC_DIR}/dtc
 TOOLS_DIR=build-sandbox_spl/tools
 
-run_test "binman" ./tools/binman/binman -t --toolpath ${TOOLS_DIR}
+run_test "binman" ./tools/binman/binman --toolpath ${TOOLS_DIR} test
 run_test "patman" ./tools/patman/patman --test
 
 [ "$1" == "quick" ] && skip=--skip-net-tests
@@ -52,7 +52,7 @@ run_test "dtoc" ./tools/dtoc/dtoc -t
 # To enable Python test coverage on Debian-type distributions (e.g. Ubuntu):
 #   $ sudo apt-get install python-pytest python-coverage
 export PATH=$PATH:${TOOLS_DIR}
-run_test "binman code coverage" ./tools/binman/binman -T --toolpath 
${TOOLS_DIR}
+run_test "binman code coverage" ./tools/binman/binman test -T
 run_test "dtoc code coverage" ./tools/dtoc/dtoc -T
 run_test "fdt code coverage" ./tools/dtoc/test_fdt -T
 
diff --git a/tools/binman/README b/tools/binman/README
index ef62d1f1ec7..fe734c1e5f7 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -187,7 +187,7 @@ First install prerequisites, e.g.
 
 Type:
 
-   binman -b 
+   binman build -b 
 
 to build an image for a board. The board name is the same name used when
 configuring U-Boot (e.g. for sandbox_defconfig the board name is 'sandbox').
@@ -195,7 +195,7 @@ Binman assumes that the input files for the build are in 
../b/.
 
 Or you can specify this explicitly:
 
-   binman -I 
+   binman build -I 
 
 where  is the build directory containing the output of the U-Boot
 build.
@@ -483,7 +483,7 @@ Entry Documentation
 For details on the various entry types supported by binman and how to use them,
 see README.entries. This is generated from the source code using:
 
-   binman -E >tools/binman/README.entries
+   binman entry-docs >tools/binman/README.entries
 
 
 Hashing Entries
@@ -715,7 +715,7 @@ Code coverage
 -
 
 Binman is a critical tool and is designed to be very testable. Entry
-implementations target 100% test coverage. Run 'binman -T' to check this.
+implementations target 100% test coverage. Run 'binman test -T' to check this.
 
 To enable Python test coverage on Debian-type distributions (e.g. Ubuntu):
 
diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index 613aad5c451..8bd5868df26 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -20,14 +20,15 @@ import sys
 import traceback
 import unittest
 
-# Bring in the patman and dtoc libraries
+# Bring in the patman and dtoc libraries (but don't override the first path
+# in PYTHONPATH)
 our_path = os.path.dirname(os.path.realpath(__file__))
 for dirname in ['../patman', '../dtoc', '..', '../concurrencytest']:
-

[U-Boot] [PATCH v2 11/31] binman: Fix up ProcessUpdateContents error and comments

2019-07-08 Thread Simon Glass
This function raises an exception with its arguments around the wrong way
so the message is incorrect. Fix this as well as a few minor comment
problems.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/entry.py | 8 
 tools/binman/ftest.py | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index a04e149d96c..b19a3b026f2 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -237,25 +237,25 @@ class Entry(object):
 This sets both the data and content_size properties
 
 Args:
-data: Data to set to the contents (string)
+data: Data to set to the contents (bytes)
 """
 self.data = data
 self.contents_size = len(self.data)
 
 def ProcessContentsUpdate(self, data):
-"""Update the contens of an entry, after the size is fixed
+"""Update the contents of an entry, after the size is fixed
 
 This checks that the new data is the same size as the old.
 
 Args:
-data: Data to set to the contents (string)
+data: Data to set to the contents (bytes)
 
 Raises:
 ValueError if the new data size is not the same as the old
 """
 if len(data) != self.contents_size:
 self.Raise('Cannot update entry size from %d to %d' %
-   (len(data), self.contents_size))
+   (self.contents_size, len(data)))
 self.SetContents(data)
 
 def ObtainContents(self):
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index c675299e1da..1c917345f2a 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1223,7 +1223,7 @@ class TestFunctional(unittest.TestCase):
 with self.assertRaises(ValueError) as e:
 self._DoReadFile('059_change_size.dts', True)
 self.assertIn("Node '/binman/_testing': Cannot update entry size from "
-  '2 to 1', str(e.exception))
+  '1 to 2', str(e.exception))
 
 def testUpdateFdt(self):
 """Test that we can update the device tree with offset/size info"""
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 22/31] binman: Support locating an FDT map

2019-07-08 Thread Simon Glass
Add support for locating an image's Fdt map which is used to determine
the contents and structure of the image.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Adjust LocateFdtmap() to return the position of the header
- Update commit subject to more accurately describe this patch
- Update test to use _DoReadFileRealDtb() helper

 tools/binman/etype/fdtmap.py   | 25 --
 tools/binman/ftest.py  | 15 +++
 tools/binman/test/128_decode_image.dts | 36 ++
 3 files changed, 74 insertions(+), 2 deletions(-)
 create mode 100644 tools/binman/test/128_decode_image.dts

diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py
index bfd7962be3a..08505264984 100644
--- a/tools/binman/etype/fdtmap.py
+++ b/tools/binman/etype/fdtmap.py
@@ -15,7 +15,26 @@ from fdt import Fdt
 import state
 import tools
 
-FDTMAP_MAGIC = b'_FDTMAP_'
+FDTMAP_MAGIC   = b'_FDTMAP_'
+FDTMAP_HDR_LEN = 16
+
+def LocateFdtmap(data):
+"""Search an image for an fdt map
+
+Args:
+data: Data to search
+
+Returns:
+Position of fdt map in data, or None if not found. Note that the
+position returned is of the FDT header, i.e. before the FDT data
+"""
+hdr_pos = data.find(FDTMAP_MAGIC)
+size = len(data)
+if hdr_pos:
+hdr = data[hdr_pos:hdr_pos + FDTMAP_HDR_LEN]
+if len(hdr) == FDTMAP_HDR_LEN:
+return hdr_pos
+return None
 
 class Entry_fdtmap(Entry):
 """An entry which contains an FDT map
@@ -24,7 +43,9 @@ class Entry_fdtmap(Entry):
 None
 
 An FDT map is just a header followed by an FDT containing a list of all the
-entries in the image.
+entries in the image. The root node corresponds to the image node in the
+original FDT, and an image-name property indicates the image name in that
+original tree.
 
 The header is the string _FDTMAP_ followed by 8 unused bytes.
 
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index de459b2b3b6..d800ba1e9d8 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -24,6 +24,7 @@ import command
 import control
 import elf
 import fdt
+from etype import fdtmap
 import fdt_util
 import fmap_util
 import test_util
@@ -2267,6 +2268,20 @@ class TestFunctional(unittest.TestCase):
 self.assertEqual(len(data), 0x100 + section_size)
 self.assertEqual(section_size, 0x400 + dtb_size)
 
+def testFindFdtmap(self):
+"""Test locating an FDT map in an image"""
+self._CheckLz4()
+data = self.data = self._DoReadFileRealDtb('128_decode_image.dts')
+image = control.images['image']
+entries = image.GetEntries()
+entry = entries['fdtmap']
+self.assertEqual(entry.image_pos, fdtmap.LocateFdtmap(data))
+
+def testFindFdtmapMissing(self):
+"""Test failing to locate an FDP map"""
+data = self._DoReadFile('005_simple.dts')
+self.assertEqual(None, fdtmap.LocateFdtmap(data))
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/tools/binman/test/128_decode_image.dts 
b/tools/binman/test/128_decode_image.dts
new file mode 100644
index 000..449fccc41df
--- /dev/null
+++ b/tools/binman/test/128_decode_image.dts
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   binman {
+   size = <0xc00>;
+   u-boot {
+   };
+   section {
+   align = <0x100>;
+   cbfs {
+   size = <0x400>;
+   u-boot {
+   cbfs-type = "raw";
+   };
+   u-boot-dtb {
+   cbfs-type = "raw";
+   cbfs-compress = "lzma";
+   cbfs-offset = <0x80>;
+   };
+   };
+   u-boot-dtb {
+   compress = "lz4";
+   };
+   };
+   fdtmap {
+   };
+   image-header {
+   location = "end";
+   };
+   };
+};
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 30/31] binman: Add an 'extract' command

2019-07-08 Thread Simon Glass
It is useful to be able to extract all binaries from the image, or a
subset of them. Add a new 'extract' command to handle this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README |  25 +-
 tools/binman/cmdline.py |  13 +++
 tools/binman/control.py |  60 +
 tools/binman/ftest.py   | 189 
 4 files changed, 286 insertions(+), 1 deletion(-)

diff --git a/tools/binman/README b/tools/binman/README
index 1655a9d50df..756c6a0010e 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -533,6 +533,30 @@ or with wildcards:
   image-header  bf8 8  image-header bf8
 
 
+Extracting files from images
+
+
+You can extract files from an existing firmware image created by binman,
+provided that there is an 'fdtmap' entry in the image. For example:
+
+$ binman extract -i image.bin section/cbfs/u-boot
+
+which will write the uncompressed contents of that entry to the file 'u-boot' 
in
+the current directory. You can also extract to a particular file, in this case
+u-boot.bin:
+
+$ binman extract -i image.bin section/cbfs/u-boot -f u-boot.bin
+
+It is possible to extract all files into a destination directory, which will
+put files in subdirectories matching the entry hierarchy:
+
+$ binman extract -i image.bin -O outdir
+
+or just a selection:
+
+$ binman extract -i image.bin "*u-boot*" -O outdir
+
+
 Logging
 ---
 
@@ -883,7 +907,6 @@ Some ideas:
 - Use of-platdata to make the information available to code that is unable
   to use device tree (such as a very small SPL image)
 - Allow easy building of images by specifying just the board name
-- Add an option to decode an image into the constituent binaries
 - Support building an image for a board (-b) more completely, with a
   configurable build directory
 - Support updating binaries in an image (with no size change / repacking)
diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py
index 508232eabb5..a43aec649ed 100644
--- a/tools/binman/cmdline.py
+++ b/tools/binman/cmdline.py
@@ -71,6 +71,19 @@ controlled by a description in the board device tree.'''
 list_parser.add_argument('paths', type=str, nargs='*',
  help='Paths within file to list (wildcard)')
 
+extract_parser = subparsers.add_parser('extract',
+   help='Extract files from an image')
+extract_parser.add_argument('-i', '--image', type=str, required=True,
+help='Image filename to extract')
+extract_parser.add_argument('-f', '--filename', type=str,
+help='Output filename to write to')
+extract_parser.add_argument('-O', '--outdir', type=str, default='',
+help='Path to directory to use for output files')
+extract_parser.add_argument('paths', type=str, nargs='*',
+help='Paths within file to extract (wildcard)')
+extract_parser.add_argument('-U', '--uncompressed', action='store_true',
+help='Output raw uncompressed data for compressed entries')
+
 test_parser = subparsers.add_parser('test', help='Run tests')
 test_parser.add_argument('-P', '--processes', type=int,
 help='set number of processes to use for running tests')
diff --git a/tools/binman/control.py b/tools/binman/control.py
index b244e7a0cd0..dc898be6179 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -118,6 +118,57 @@ def ReadEntry(image_fname, entry_path, decomp=True):
 return entry.ReadData(decomp)
 
 
+def ExtractEntries(image_fname, output_fname, outdir, entry_paths,
+   decomp=True):
+"""Extract the data from one or more entries and write it to files
+
+Args:
+image_fname: Image filename to process
+output_fname: Single output filename to use if extracting one file, 
None
+otherwise
+outdir: Output directory to use (for any number of files), else None
+entry_paths: List of entry paths to extract
+decomp: True to compress the entry data
+
+Returns:
+List of EntryInfo records that were written
+"""
+image = Image.FromFile(image_fname)
+
+# Output an entry to a single file, as a special case
+if output_fname:
+if not entry_paths:
+raise ValueError('Must specify an entry path to write with -o')
+if len(entry_paths) != 1:
+raise ValueError('Must specify exactly one entry path to write 
with -o')
+entry = image.FindEntryPath(entry_paths[0])
+data = entry.ReadData(decomp)
+tools.WriteFile(output_fname, data)
+tout.Notice("Wrote %#x bytes to file '%s'" % (len(data), output_fname))
+return
+
+# Otherwise we will output to a path given by the entry path of each entry.
+# This means that entries will appear in subdirectories if they are part of
+# a sub-section.

[U-Boot] [PATCH v2 12/31] binman: Call ProcessUpdateContents() consistently

2019-07-08 Thread Simon Glass
SetContents() should only be called to set the contents of an entry from
within the ObtainContents() call, since it has no guard against increasing
the size of the contents, thus triggering incorrect operation.

Change all such calls to use ProcessUpdateContents() instead.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/etype/blob_dtb.py | 2 +-
 tools/binman/etype/fdtmap.py   | 2 +-
 tools/binman/etype/fmap.py | 2 +-
 tools/binman/etype/image_header.py | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py
index cc5b4a3f760..d80c3d7e006 100644
--- a/tools/binman/etype/blob_dtb.py
+++ b/tools/binman/etype/blob_dtb.py
@@ -30,4 +30,4 @@ class Entry_blob_dtb(Entry_blob):
 def ProcessContents(self):
 """Re-read the DTB contents so that we get any calculated properties"""
 _, data = state.GetFdtContents(self._filename)
-self.SetContents(data)
+self.ProcessContentsUpdate(data)
diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py
index cdeb491ebdc..ddac148b9ba 100644
--- a/tools/binman/etype/fdtmap.py
+++ b/tools/binman/etype/fdtmap.py
@@ -106,4 +106,4 @@ class Entry_fdtmap(Entry):
 This is necessary since new data may have been written back to it 
during
 processing, e.g. the image-pos properties.
 """
-self.SetContents(self._GetFdtmap())
+self.ProcessContentsUpdate(self._GetFdtmap())
diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py
index e6b5c5c74c0..45d6db18a31 100644
--- a/tools/binman/etype/fmap.py
+++ b/tools/binman/etype/fmap.py
@@ -62,4 +62,4 @@ class Entry_fmap(Entry):
 return True
 
 def ProcessContents(self):
-self.SetContents(self._GetFmap())
+self.ProcessContentsUpdate(self._GetFmap())
diff --git a/tools/binman/etype/image_header.py 
b/tools/binman/etype/image_header.py
index 9bc84ec01d4..d6de58ce4b7 100644
--- a/tools/binman/etype/image_header.py
+++ b/tools/binman/etype/image_header.py
@@ -73,4 +73,4 @@ class Entry_image_header(Entry):
 This is necessary since image_pos is not available when 
ObtainContents()
 is called, since by then the entries have not been packed in the image.
 """
-self.SetContents(self._GetHeader())
+self.ProcessContentsUpdate(self._GetHeader())
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 28/31] binman: Allow reading an entry from an image

2019-07-08 Thread Simon Glass
It is useful to be able to extract entry contents from an image to see
what is inside. Add a simple function to read the contents of an entry,
decompressing it by default.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/control.py| 20 ++
 tools/binman/entry.py  | 21 +++
 tools/binman/etype/blob.py | 13 
 tools/binman/ftest.py  | 42 ++
 tools/binman/image.py  |  4 +++-
 5 files changed, 99 insertions(+), 1 deletion(-)

diff --git a/tools/binman/control.py b/tools/binman/control.py
index 813c8b1bf9e..b244e7a0cd0 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -98,6 +98,26 @@ def ListEntries(image_fname, entry_paths):
 out += txt
 print(out.rstrip())
 
+
+def ReadEntry(image_fname, entry_path, decomp=True):
+"""Extract an entry from an image
+
+This extracts the data from a particular entry in an image
+
+Args:
+image_fname: Image filename to process
+entry_path: Path to entry to extract
+decomp: True to return uncompressed data, if the data is compress
+False to return the raw data
+
+Returns:
+data extracted from the entry
+"""
+image = Image.FromFile(image_fname)
+entry = image.FindEntryPath(entry_path)
+return entry.ReadData(decomp)
+
+
 def Binman(args):
 """The main control code for binman
 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 33d3f1e4d42..1c382f3b852 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -659,3 +659,24 @@ features to produce new behaviours.
 """
 self.AddEntryInfo(entries, indent, self.name, self.etype, self.size,
   self.image_pos, self.uncomp_size, self.offset, self)
+
+def ReadData(self, decomp=True):
+"""Read the data for an entry from the image
+
+This is used when the image has been read in and we want to extract the
+data for a particular entry from that image.
+
+Args:
+decomp: True to decompress any compressed data before returning it;
+False to return the raw, uncompressed data
+
+Returns:
+Entry data (bytes)
+"""
+# Use True here so that we get an uncompressed section to work from,
+# although compressed sections are currently not supported
+data = self.section.ReadData(True)
+tout.Info('%s: Reading data from offset %#x-%#x, size %#x (avail %#x)' 
%
+  (self.GetPath(), self.offset, self.offset + self.size,
+   self.size, len(data)))
+return data[self.offset:self.offset + self.size]
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index a4ff0efcebc..00cad33718c 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -9,6 +9,7 @@ from entry import Entry
 import fdt_util
 import state
 import tools
+import tout
 
 class Entry_blob(Entry):
 """Entry containing an arbitrary binary blob
@@ -66,3 +67,15 @@ class Entry_blob(Entry):
 
 def GetDefaultFilename(self):
 return self._filename
+
+def ReadData(self, decomp=True):
+indata = Entry.ReadData(self, decomp)
+if decomp:
+data = tools.Decompress(indata, self.compress)
+if self.uncomp_size:
+tout.Info("%s: Decompressing data size %#x with algo '%s' to 
data size %#x" %
+  (self.GetPath(), len(indata), self.compress,
+   len(data)))
+else:
+data = indata
+return data
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index ad828041f30..c11dd1b85ab 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -69,6 +69,8 @@ FILES_DATA= (b"sorry I'm late\nOh, don't bother 
apologising, I'm " +
 COMPRESS_DATA = b'compress xx data'
 REFCODE_DATA  = b'refcode'
 
+EXTRACT_DTB_SIZE = 0x3c9
+
 
 class TestFunctional(unittest.TestCase):
 """Functional tests for binman
@@ -2423,6 +2425,46 @@ class TestFunctional(unittest.TestCase):
 """Test listing the files in a sub-entry of a section"""
 self._RunListCmd(['section/cbfs'], ['cbfs', 'u-boot', 'u-boot-dtb'])
 
+def _RunExtractCmd(self, entry_name, decomp=True):
+"""Extract an entry from an image
+
+Args:
+entry_name: Entry name to extract
+decomp: True to decompress the data if compressed, False to leave
+it in its raw uncompressed format
+
+Returns:
+data from entry
+"""
+self._CheckLz4()
+self._DoReadFileRealDtb('130_list_fdtmap.dts')
+image_fname = tools.GetOutputFilename('image.bin')
+return control.ReadEntry(image_fname, entry_name, decomp)
+
+def testExtractSimple(self):
+"""Test extracting a single file"""
+

[U-Boot] [PATCH v2 23/31] binman: Support locating an image header

2019-07-08 Thread Simon Glass
Add support for locating an image header in an image.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/etype/image_header.py | 23 +++
 tools/binman/ftest.py  | 27 +++
 2 files changed, 50 insertions(+)

diff --git a/tools/binman/etype/image_header.py 
b/tools/binman/etype/image_header.py
index b1c4f8a07e9..8f9c5aa5d9e 100644
--- a/tools/binman/etype/image_header.py
+++ b/tools/binman/etype/image_header.py
@@ -15,6 +15,29 @@ from entry import Entry
 import fdt_util
 
 IMAGE_HEADER_MAGIC = b'BinM'
+IMAGE_HEADER_LEN   = 8
+
+def LocateHeaderOffset(data):
+"""Search an image for an image header
+
+Args:
+data: Data to search
+
+Returns:
+Offset of image header in the image, or None if not found
+"""
+hdr_pos = data.find(IMAGE_HEADER_MAGIC)
+if hdr_pos != -1:
+size = len(data)
+hdr = data[hdr_pos:hdr_pos + IMAGE_HEADER_LEN]
+if len(hdr) == IMAGE_HEADER_LEN:
+offset = struct.unpack('https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 06/31] binman: Add an image header

2019-07-08 Thread Simon Glass
It is useful to be able to quickly locate the FDT map in the image. An
easy way to do this is with a pointer at the start or end of the image.

Add an 'image header' entry, which places a magic number followed by a
pointer to the FDT map. This can be located at the start or end of the
image, or at a chosen location.

As part of this, update GetSiblingImagePos() to detect missing siblings.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Update test to use _DoReadFileRealDtb() helper

 tools/binman/README  |  5 +-
 tools/binman/README.entries  | 19 +
 tools/binman/entry.py| 11 +++
 tools/binman/etype/image_header.py   | 76 
 tools/binman/ftest.py| 47 +++-
 tools/binman/test/116_fdtmap_hdr.dts | 17 +
 tools/binman/test/117_fdtmap_hdr_start.dts   | 19 +
 tools/binman/test/118_fdtmap_hdr_pos.dts | 19 +
 tools/binman/test/119_fdtmap_hdr_missing.dts | 16 +
 tools/binman/test/120_hdr_no_location.dts| 16 +
 10 files changed, 242 insertions(+), 3 deletions(-)
 create mode 100644 tools/binman/etype/image_header.py
 create mode 100644 tools/binman/test/116_fdtmap_hdr.dts
 create mode 100644 tools/binman/test/117_fdtmap_hdr_start.dts
 create mode 100644 tools/binman/test/118_fdtmap_hdr_pos.dts
 create mode 100644 tools/binman/test/119_fdtmap_hdr_missing.dts
 create mode 100644 tools/binman/test/120_hdr_no_location.dts

diff --git a/tools/binman/README b/tools/binman/README
index 8a5f3320dcb..ef62d1f1ec7 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -640,7 +640,9 @@ of each entry.
 
 Alternatively, an FDT map entry can be used to add a special FDT containing
 just the information about the image. This is preceded by a magic string so can
-be located anywhere in the image.
+be located anywhere in the image. An image header (typically at the start or 
end
+of the image) can be used to point to the FDT map. See fdtmap and image-header
+entries for more information.
 
 
 Compression
@@ -817,7 +819,6 @@ Some ideas:
 - Add an option to decode an image into the constituent binaries
 - Support building an image for a board (-b) more completely, with a
   configurable build directory
-- Support putting the FDT in an image with a suitable magic number
 - Support listing files in images
 - Support logging of binman's operations, with different levels of verbosity
 - Support updating binaries in an image (with no size change / repacking)
diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 7014d36f5ff..598d8278a70 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -331,6 +331,25 @@ README.chromium for how to obtain the required keys and 
tools.
 
 
 
+Entry: image-header: An entry which contains a pointer to the FDT map
+-
+
+Properties / Entry arguments:
+location: Location of header ("start" or "end" of image). This is
+optional. If omitted then the entry must have an offset property.
+
+This adds an 8-byte entry to the start or end of the image, pointing to the
+location of the FDT map. The format is a magic number followed by an offset
+from the start or end of the image, in twos-compliment format.
+
+This entry must be in the top-level part of the image.
+
+NOTE: If the location is at the start/end, you will probably need to specify
+sort-by-offset for the image, unless you actually put the image header
+first/last in the entry list.
+
+
+
 Entry: intel-cmc: Entry containing an Intel Chipset Micro Code (CMC) file
 -
 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 7356c49c626..e1cd0d3a882 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -561,3 +561,14 @@ features to produce new behaviours.
 else False
 """
 return name in self.section.GetEntries()
+
+def GetSiblingImagePos(self, name):
+"""Return the image position of the given sibling
+
+Returns:
+Image position of sibling, or None if the sibling has no position,
+or False if there is no such sibling
+"""
+if not self.HasSibling(name):
+return False
+return self.section.GetEntries()[name].image_pos
diff --git a/tools/binman/etype/image_header.py 
b/tools/binman/etype/image_header.py
new file mode 100644
index 000..9bc84ec01d4
--- /dev/null
+++ b/tools/binman/etype/image_header.py
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2018 Google, Inc
+# Written by Simon Glass 
+
+"""Entry-type module for an image header which points to the FDT map
+
+This creates an 8-byte entry with a magic number and the offset of the FDT map
+(which is another entry in the image), relative to the start or end of the
+image.
+"""
+
+import 

[U-Boot] [PATCH v2 29/31] binman: Support reading from CBFS entries

2019-07-08 Thread Simon Glass
CBFS is a bit like a section but with a custom format. Provide the list of
entries and the compression type to binman so that it can extract the data
from the CBFS, just like any other part of the image.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/cbfs_util.py  | 14 ++
 tools/binman/etype/cbfs.py |  7 +++
 2 files changed, 21 insertions(+)

diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
index 4691be4aee2..45e16da0aaa 100644
--- a/tools/binman/cbfs_util.py
+++ b/tools/binman/cbfs_util.py
@@ -142,6 +142,20 @@ def find_compress(find_name):
 return compress
 return None
 
+def compress_name(compress):
+"""Look up the name of a compression algorithm
+
+Args:
+compress: Compression algorithm number to find (COMPRESS_...)
+
+Returns:
+Compression algorithm name (string)
+
+Raises:
+KeyError if the algorithm number is invalid
+"""
+return COMPRESS_NAMES[compress]
+
 def align_int(val, align):
 """Align a value up to the given alignment
 
diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index 953d6f4868d..edf2189fd26 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -238,6 +238,10 @@ class Entry_cbfs(Entry):
 entry.AddMissingProperties()
 if entry._cbfs_compress:
 state.AddZeroProp(entry._node, 'uncomp-size')
+# Store the 'compress' property, since we don't look at
+# 'cbfs-compress' in Entry.ReadData()
+state.AddString(entry._node, 'compress',
+cbfs_util.compress_name(entry._cbfs_compress))
 
 def SetCalculatedProperties(self):
 """Set the value of device-tree properties calculated by binman"""
@@ -254,3 +258,6 @@ class Entry_cbfs(Entry):
 Entry.ListEntries(self, entries, indent)
 for entry in self._cbfs_entries.values():
 entry.ListEntries(entries, indent + 1)
+
+def GetEntries(self):
+return self._cbfs_entries
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 18/31] binman: Use the cbfs memlen field only for uncompressed length

2019-07-08 Thread Simon Glass
The purpose of this badly named field is a bit ambiguous. Adjust the code
to use it only to store the uncompressed length of a file, leaving it set
to None if there is no compression used. This makes it easy to see if the
value in this field is relevant / useful.

Also set data_len for compressed fields, since it should be the length of
the compressed data, not the uncompressed data.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/cbfs_util.py | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
index 530629a5c96..4691be4aee2 100644
--- a/tools/binman/cbfs_util.py
+++ b/tools/binman/cbfs_util.py
@@ -197,7 +197,8 @@ class CbfsFile(object):
 data_len: Length of (possibly compressed) data in bytes
 ftype: File type (TYPE_...)
 compression: Compression type (COMPRESS_...)
-memlen: Length of data in memory (typically the uncompressed length)
+memlen: Length of data in memory, i.e. the uncompressed length, None if
+no compression algortihm is selected
 load: Load address in memory if known, else None
 entry: Entry address in memory if known, else None. This is where
 execution starts after the file is loaded
@@ -213,11 +214,11 @@ class CbfsFile(object):
 self.data = data
 self.ftype = ftype
 self.compress = compress
-self.memlen = len(data)
+self.memlen = None
 self.load = None
 self.entry = None
 self.base_address = None
-self.data_len = 0
+self.data_len = len(data)
 self.erase_byte = None
 self.size = None
 
@@ -349,9 +350,11 @@ class CbfsFile(object):
 data = tools.Compress(orig_data, 'lz4')
 elif self.compress == COMPRESS_LZMA:
 data = tools.Compress(orig_data, 'lzma')
+self.memlen = len(orig_data)
+self.data_len = len(data)
 attr = struct.pack(ATTR_COMPRESSION_FORMAT,
FILE_ATTR_TAG_COMPRESSION, ATTR_COMPRESSION_LEN,
-   self.compress, len(orig_data))
+   self.compress, self.memlen)
 elif self.ftype == TYPE_EMPTY:
 data = tools.GetBytes(self.erase_byte, self.size)
 else:
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 14/31] binman: Add a control for post-pack entry expansion

2019-07-08 Thread Simon Glass
We plan to support changing the size of entries after they have been
packed. For now it will always be enabled. But to aid testing of both
cases (in the event that we want to add a command-line flag, for example),
add a setting to control it.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/state.py | 24 
 1 file changed, 24 insertions(+)

diff --git a/tools/binman/state.py b/tools/binman/state.py
index 3ccd7855d47..382bda32219 100644
--- a/tools/binman/state.py
+++ b/tools/binman/state.py
@@ -31,6 +31,11 @@ fdt_subset = set()
 # The DTB which contains the full image information
 main_dtb = None
 
+# Allow entries to expand after they have been packed. This is detected and
+# forces a re-pack. If not allowed, any attempted expansion causes an error in
+# Entry.ProcessContentsUpdate()
+allow_entry_expansion = True
+
 def GetFdt(fname):
 """Get the Fdt object for a particular device-tree filename
 
@@ -250,3 +255,22 @@ def CheckSetHashValue(node, get_data_func):
 data = m.digest()
 for n in GetUpdateNodes(hash_node):
 n.SetData('value', data)
+
+def SetAllowEntryExpansion(allow):
+"""Set whether post-pack expansion of entries is allowed
+
+Args:
+   allow: True to allow expansion, False to raise an exception
+"""
+global allow_entry_expansion
+
+allow_entry_expansion = allow
+
+def AllowEntryExpansion():
+"""Check whether post-pack expansion of entries is allowed
+
+Returns:
+True if expansion should be allowed, False if an exception should be
+raised
+"""
+return allow_entry_expansion
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 15/31] binman: Allow entries to expand after packing

2019-07-08 Thread Simon Glass
Add support for detecting entries that change size after they have already
been packed, and re-running packing when it happens.

This removes the limitation that entry size cannot change after
PackEntries() is called.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Avoid dual assignment in ResetForPack()
- Show a message when a section's size changes
- Use 3 packing passes instead of two, and add a comment
- Use bytearray for Python 3

 tools/binman/README   |  3 +-
 tools/binman/bsection.py  | 12 +
 tools/binman/control.py   | 51 +--
 tools/binman/entry.py | 21 +++-
 tools/binman/etype/_testing.py| 11 +++-
 tools/binman/etype/section.py |  5 ++
 tools/binman/etype/u_boot_with_ucode_ptr.py   |  2 +-
 tools/binman/ftest.py | 33 ++--
 tools/binman/image.py |  8 +++
 tools/binman/test/121_entry_expand.dts| 20 
 tools/binman/test/122_entry_expand_twice.dts  | 21 
 .../binman/test/123_entry_expand_section.dts  | 22 
 12 files changed, 184 insertions(+), 25 deletions(-)
 create mode 100644 tools/binman/test/121_entry_expand.dts
 create mode 100644 tools/binman/test/122_entry_expand_twice.dts
 create mode 100644 tools/binman/test/123_entry_expand_section.dts

diff --git a/tools/binman/README b/tools/binman/README
index abbf809b823..9860633792f 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -566,7 +566,8 @@ tree. This sets the correct 'offset' and 'size' vaues, for 
example.
 The default implementatoin does nothing. This can be overriden to adjust the
 contents of an entry in some way. For example, it would be possible to create
 an entry containing a hash of the contents of some other entries. At this
-stage the offset and size of entries should not be adjusted.
+stage the offset and size of entries should not be adjusted unless absolutely
+necessary, since it requires a repack (going back to PackEntries()).
 
 10. WriteSymbols() - write the value of symbols into the U-Boot SPL binary.
 See 'Access to binman entry offsets at run time' below for a description of
diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
index f49a6e93bc7..9047e55a34a 100644
--- a/tools/binman/bsection.py
+++ b/tools/binman/bsection.py
@@ -45,6 +45,8 @@ class Section(object):
 _name_prefix: Prefix to add to the name of all entries within this
 section
 _entries: OrderedDict() of entries
+_orig_offset: Original offset value read from node
+_orig_size: Original size value read from node
 """
 def __init__(self, name, parent_section, node, image, test=False):
 global entry
@@ -76,6 +78,8 @@ class Section(object):
 """Read properties from the section node"""
 self._offset = fdt_util.GetInt(self._node, 'offset')
 self._size = fdt_util.GetInt(self._node, 'size')
+self._orig_offset = self._offset
+self._orig_size = self._size
 self._align_size = fdt_util.GetInt(self._node, 'align-size')
 if tools.NotPowerOfTwo(self._align_size):
 self._Raise("Alignment size %s must be a power of two" %
@@ -257,6 +261,13 @@ class Section(object):
 for name, info in offset_dict.items():
 self._SetEntryOffsetSize(name, *info)
 
+def ResetForPack(self):
+"""Reset offset/size fields so that packing can be done again"""
+self._offset = self._orig_offset
+self._size = self._orig_size
+for entry in self._entries.values():
+entry.ResetForPack()
+
 def PackEntries(self):
 """Pack all entries into the section"""
 offset = self._skip_at_start
@@ -325,6 +336,7 @@ class Section(object):
 for entry in self._entries.values():
 if not entry.ProcessContents():
 sizes_ok = False
+print("Entry '%s' size change" % self._node.path)
 return sizes_ok
 
 def WriteSymbols(self):
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 9022cf76e99..35faf115062 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -170,21 +170,42 @@ def Binman(args):
 # completed and written, but that does not seem important.
 image.GetEntryContents()
 image.GetEntryOffsets()
-try:
-image.PackEntries()
-image.CheckSize()
-image.CheckEntries()
-except Exception as e:
-if args.map:
-fname = image.WriteMap()
-print("Wrote map file '%s' to show errors"  % fname)
-raise
-image.SetImagePos()
-if args.update_fdt:
-image.SetCalculatedProperties()
-for 

[U-Boot] [PATCH v2 27/31] binman: Allow for logging information to be displayed

2019-07-08 Thread Simon Glass
Binman generally operates silently but in some cases it is useful to see
what Binman is actually doing at each step. Enable some logging output
with different logging levels selectable via the -v flag.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README   | 19 ++-
 tools/binman/entry.py |  3 ++-
 tools/binman/image.py |  3 ++-
 tools/patman/tout.py  | 10 +-
 4 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/tools/binman/README b/tools/binman/README
index 146e0fd470a..1655a9d50df 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -533,6 +533,24 @@ or with wildcards:
   image-header  bf8 8  image-header bf8
 
 
+Logging
+---
+
+Binman normally operates silently unless there is an error, in which case it
+just displays the error. The -D/--debug option can be used to create a full
+backtrace when errors occur.
+
+Internally binman logs some output while it is running. This can be displayed
+by increasing the -v/--verbosity from the default of 1:
+
+   0: silent
+   1: warnings only
+   2: notices (important messages)
+   3: info about major operations
+   4: detailed information about each operation
+   5: debug (all output)
+
+
 Hashing Entries
 ---
 
@@ -868,7 +886,6 @@ Some ideas:
 - Add an option to decode an image into the constituent binaries
 - Support building an image for a board (-b) more completely, with a
   configurable build directory
-- Support logging of binman's operations, with different levels of verbosity
 - Support updating binaries in an image (with no size change / repacking)
 - Support updating binaries in an image (with repacking)
 - Support adding FITs to an image
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index c45a2fdb4b0..33d3f1e4d42 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -23,6 +23,7 @@ import sys
 import fdt_util
 import state
 import tools
+import tout
 
 modules = {}
 
@@ -272,7 +273,7 @@ class Entry(object):
 new_size = len(data)
 if state.AllowEntryExpansion():
 if new_size > self.contents_size:
-print("Entry '%s' size change from %#x to %#x" % (
+tout.Debug("Entry '%s' size change from %#x to %#x" % (
 self._node.path, self.contents_size, new_size))
 # self.data will indicate the new size needed
 size_ok = False
diff --git a/tools/binman/image.py b/tools/binman/image.py
index 2c5668e2a96..bbb5e23c3b2 100644
--- a/tools/binman/image.py
+++ b/tools/binman/image.py
@@ -20,6 +20,7 @@ from etype import section
 import fdt
 import fdt_util
 import tools
+import tout
 
 class Image(section.Entry_section):
 """A Image, representing an output from binman
@@ -107,7 +108,7 @@ class Image(section.Entry_section):
 for entry in self._entries.values():
 if not entry.ProcessContents():
 sizes_ok = False
-print("Entry '%s' size change" % self._node.path)
+tout.Debug("Entry '%s' size change" % self._node.path)
 return sizes_ok
 
 def WriteSymbols(self):
diff --git a/tools/patman/tout.py b/tools/patman/tout.py
index 4957c7ae1df..15acce28cb9 100644
--- a/tools/patman/tout.py
+++ b/tools/patman/tout.py
@@ -131,13 +131,21 @@ def Info(msg):
 """
 _Output(3, msg)
 
+def Detail(msg):
+"""Display a detailed message
+
+Args:
+msg; Message to display.
+"""
+_Output(4, msg)
+
 def Debug(msg):
 """Display a debug message
 
 Args:
 msg; Message to display.
 """
-_Output(4, msg)
+_Output(5, msg)
 
 def UserOutput(msg):
 """Display a message regardless of the current output level.
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 17/31] binman: Provide the actual data address for cbfs files

2019-07-08 Thread Simon Glass
At present a file with no explicit CBFS offset is placed in the next
available location but there is no way to find out where it ended up.
Update and rename the get_data() function to provide this information.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/cbfs_util.py | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
index 1cdbcb2339e..530629a5c96 100644
--- a/tools/binman/cbfs_util.py
+++ b/tools/binman/cbfs_util.py
@@ -185,7 +185,8 @@ class CbfsFile(object):
 """Class to represent a single CBFS file
 
 This is used to hold the information about a file, including its contents.
-Use the get_data() method to obtain the raw output for writing to CBFS.
+Use the get_data_and_offset() method to obtain the raw output for writing 
to
+CBFS.
 
 Properties:
 name: Name of file
@@ -319,12 +320,15 @@ class CbfsFile(object):
 raise ValueError('Unknown file type %#x\n' % self.ftype)
 return hdr_len
 
-def get_data(self, offset=None, pad_byte=None):
-"""Obtain the contents of the file, in CBFS format
+def get_data_and_offset(self, offset=None, pad_byte=None):
+"""Obtain the contents of the file, in CBFS format and the offset of
+the data within the file
 
 Returns:
-bytes representing the contents of this file, packed and aligned
-for directly inserting into the final CBFS output
+tuple:
+bytes representing the contents of this file, packed and 
aligned
+for directly inserting into the final CBFS output
+offset to the file data from the start of the returned data.
 """
 name = _pack_string(self.name)
 hdr_len = len(name) + FILE_HEADER_LEN
@@ -368,8 +372,10 @@ class CbfsFile(object):
  (self.name, self.cbfs_offset, offset))
 pad = tools.GetBytes(pad_byte, pad_len)
 hdr_len += pad_len
-self.offset = len(content) + len(data)
-hdr = struct.pack(FILE_HEADER_FORMAT, FILE_MAGIC, self.offset,
+
+# This is the offset of the start of the file's data,
+size = len(content) + len(data)
+hdr = struct.pack(FILE_HEADER_FORMAT, FILE_MAGIC, size,
   self.ftype, attr_pos, hdr_len)
 
 # Do a sanity check of the get_header_len() function, to ensure that it
@@ -381,7 +387,7 @@ class CbfsFile(object):
 # happen. It probably indicates that get_header_len() is broken.
 raise ValueError("Internal error: CBFS file '%s': Expected headers 
of %#x bytes, got %#d" %
  (self.name, expected_len, actual_len))
-return hdr + name + attr + pad + content + data
+return hdr + name + attr + pad + content + data, hdr_len
 
 
 class CbfsWriter(object):
@@ -392,7 +398,7 @@ class CbfsWriter(object):
 cbw = CbfsWriter(size)
 cbw.add_file_raw('u-boot', tools.ReadFile('u-boot.bin'))
 ...
-data = cbw.get_data()
+data, cbfs_offset = cbw.get_data_and_offset()
 
 Attributes:
 _master_name: Name of the file containing the master header
@@ -475,7 +481,7 @@ class CbfsWriter(object):
 todo = align_int_down(offset - upto, self._align)
 if todo:
 cbf = CbfsFile.empty(todo, self._erase_byte)
-fd.write(cbf.get_data())
+fd.write(cbf.get_data_and_offset()[0])
 self._skip_to(fd, offset)
 
 def _align_to(self, fd, align):
@@ -579,8 +585,11 @@ class CbfsWriter(object):
 offset = cbf.calc_start_offset()
 if offset is not None:
 self._pad_to(fd, align_int_down(offset, self._align))
-fd.write(cbf.get_data(fd.tell(), self._erase_byte))
+pos = fd.tell()
+data, data_offset = cbf.get_data_and_offset(pos, self._erase_byte)
+fd.write(data)
 self._align_to(fd, self._align)
+cbf.calced_cbfs_offset = pos + data_offset
 if not self._hdr_at_start:
 self._write_header(fd, add_fileheader=self._add_fileheader)
 
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 09/31] binman: Drop an unused arg in Entry.Lookup()

2019-07-08 Thread Simon Glass
The first argument is not used. Remove it.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/entry.py | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 82ed5f0..00bb1d190a9 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -85,11 +85,10 @@ class Entry(object):
 self.ReadNode()
 
 @staticmethod
-def Lookup(section, node_path, etype):
+def Lookup(node_path, etype):
 """Look up the entry class for a node.
 
 Args:
-section:   Section object containing this node
 node_node: Path name of Node object containing information about
the entry to create (used for errors)
 etype:   Entry type to use
@@ -140,7 +139,7 @@ class Entry(object):
 """
 if not etype:
 etype = fdt_util.GetString(node, 'type', node.name)
-obj = Entry.Lookup(section, node.path, etype)
+obj = Entry.Lookup(node.path, etype)
 
 # Call its constructor to get the object we want.
 return obj(section, etype, node)
@@ -514,7 +513,7 @@ features to produce new behaviours.
 modules.remove('_testing')
 missing = []
 for name in modules:
-module = Entry.Lookup(name, name, name)
+module = Entry.Lookup(name, name)
 docs = getattr(module, '__doc__')
 if test_missing == name:
 docs = None
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 08/31] binman: Move compression into the Entry base class

2019-07-08 Thread Simon Glass
Compression is currently available only with blobs. However we want to
report the compression algorithm and uncompressed size for all entries,
so that other entry types can support compression. This will help with
the forthcoming 'list' feature which lists entries in the image.

Move the compression properties into the base class. Also fix up the docs
which had the wrong property name.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README| 11 ---
 tools/binman/entry.py  |  9 +
 tools/binman/etype/blob.py | 19 ---
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/tools/binman/README b/tools/binman/README
index fe734c1e5f7..abbf809b823 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -339,6 +339,10 @@ expand-size:
limited by the size of the image/section and the position of the next
entry.
 
+compress:
+   Sets the compression algortihm to use (for blobs only). See the entry
+   documentation for details.
+
 The attributes supported for images and sections are described below. Several
 are similar to those for entries.
 
@@ -649,15 +653,16 @@ Compression
 ---
 
 Binman support compression for 'blob' entries (those of type 'blob' and
-derivatives). To enable this for an entry, add a 'compression' property:
+derivatives). To enable this for an entry, add a 'compress' property:
 
 blob {
 filename = "datafile";
-compression = "lz4";
+compress = "lz4";
 };
 
 The entry will then contain the compressed data, using the 'lz4' compression
-algorithm. Currently this is the only one that is supported.
+algorithm. Currently this is the only one that is supported. The uncompressed
+size is written to the node in an 'uncomp-size' property, if -u is used.
 
 
 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index e1cd0d3a882..82ed5f0 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -51,6 +51,8 @@ class Entry(object):
 offset: Offset of entry within the section, None if not known yet (in
 which case it will be calculated by Pack())
 size: Entry size in bytes, None if not known
+uncomp_size: Size of uncompressed data in bytes, if the entry is
+compressed, else None
 contents_size: Size of contents in bytes, 0 by default
 align: Entry start offset alignment, or None
 align_size: Entry size alignment, or None
@@ -58,6 +60,7 @@ class Entry(object):
 pad_before: Number of pad bytes before the contents, 0 if none
 pad_after: Number of pad bytes after the contents, 0 if none
 data: Contents of entry (string of bytes)
+compress: Compression algoithm used (e.g. 'lz4'), 'none' if none
 """
 def __init__(self, section, etype, node, read_node=True, name_prefix=''):
 self.section = section
@@ -66,6 +69,7 @@ class Entry(object):
 self.name = node and (name_prefix + node.name) or 'none'
 self.offset = None
 self.size = None
+self.uncomp_size = None
 self.data = None
 self.contents_size = 0
 self.align = None
@@ -76,6 +80,7 @@ class Entry(object):
 self.offset_unset = False
 self.image_pos = None
 self._expand_size = False
+self.compress = 'none'
 if read_node:
 self.ReadNode()
 
@@ -188,6 +193,8 @@ class Entry(object):
 for prop in ['offset', 'size', 'image-pos']:
 if not prop in self._node.props:
 state.AddZeroProp(self._node, prop)
+if self.compress != 'none':
+state.AddZeroProp(self._node, 'uncomp-size')
 err = state.CheckAddHashProp(self._node)
 if err:
 self.Raise(err)
@@ -198,6 +205,8 @@ class Entry(object):
 state.SetInt(self._node, 'size', self.size)
 state.SetInt(self._node, 'image-pos',
self.image_pos - self.section.GetRootSkipAtStart())
+if self.uncomp_size is not None:
+state.SetInt(self._node, 'uncomp-size', self.uncomp_size)
 state.CheckSetHashValue(self._node, self.GetData)
 
 def ProcessFdt(self, fdt):
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index a91e7847009..ec94568ac0a 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -33,8 +33,7 @@ class Entry_blob(Entry):
 def __init__(self, section, etype, node):
 Entry.__init__(self, section, etype, node)
 self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
-self._compress = fdt_util.GetString(self._node, 'compress', 'none')
-self._uncompressed_size = None
+self.compress = fdt_util.GetString(self._node, 'compress', 'none')
 
 def ObtainContents(self):
 self._filename = self.GetDefaultFilename()
@@ -50,21 +49,11 @@ class Entry_blob(Entry):
 # the data in chunks and avoid reading 

[U-Boot] [PATCH v2 10/31] binman: Allow easy importing of entry modules

2019-07-08 Thread Simon Glass
At present entry modules can only be accessed using Entry.Lookup() or
Entry.Create(). Most of the time this is fine, but sometimes a module
needs to provide constants or helper functions useful to other modules.
It is easier in this case to use 'import'.

Add an __init__ file to permit this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/entry.py  | 2 ++
 tools/binman/etype/__init__.py | 0
 tools/patman/test_util.py  | 1 +
 3 files changed, 3 insertions(+)
 create mode 100644 tools/binman/etype/__init__.py

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 00bb1d190a9..a04e149d96c 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -513,6 +513,8 @@ features to produce new behaviours.
 modules.remove('_testing')
 missing = []
 for name in modules:
+if name.startswith('__'):
+continue
 module = Entry.Lookup(name, name)
 docs = getattr(module, '__doc__')
 if test_missing == name:
diff --git a/tools/binman/etype/__init__.py b/tools/binman/etype/__init__.py
new file mode 100644
index 000..e69de29bb2d
diff --git a/tools/patman/test_util.py b/tools/patman/test_util.py
index 40098159c08..09f258c26b4 100644
--- a/tools/patman/test_util.py
+++ b/tools/patman/test_util.py
@@ -58,6 +58,7 @@ def RunTestCoverage(prog, filter_fname, exclude_list, 
build_dir, required=None):
 test_set = set([os.path.splitext(os.path.basename(line.split()[0]))[0]
 for line in lines if '/etype/' in line])
 missing_list = required
+missing_list.discard('__init__')
 missing_list.difference_update(test_set)
 if missing_list:
 print('Missing tests for %s' % (', '.join(missing_list)))
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 13/31] binman: Add a return value to ProcessContentsUpdate()

2019-07-08 Thread Simon Glass
At present if this function tries to update the contents such that the
size changes, it raises an error. We plan to add the ability to change
the size of entries after packing is completed, since in some cases it is
not possible to determine the size in advance.

An example of this is with a compressed device tree, where the values
of the device tree change in SetCalculatedProperties() or
ProcessEntryContents(). While the device tree itself does not change size,
since placeholders for any new properties have already bee added by
AddMissingProperties(), we cannot predict the size of the device tree
after compression. If a value changes from 0 to 0x1234 (say), then the
compressed device tree may expand.

As a first step towards supporting this, make ProcessContentsUpdate()
return a value indicating whether the content size is OK. For now this is
always True (since otherwise binman raises an error), but later patches
will adjust this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/bsection.py|  8 +++-
 tools/binman/entry.py   | 22 +++--
 tools/binman/etype/_testing.py  |  5 +++--
 tools/binman/etype/blob_dtb.py  |  2 +-
 tools/binman/etype/fdtmap.py|  2 +-
 tools/binman/etype/fmap.py  |  2 +-
 tools/binman/etype/image_header.py  |  2 +-
 tools/binman/etype/section.py   |  5 +++--
 tools/binman/etype/u_boot_with_ucode_ptr.py |  6 +++---
 tools/binman/image.py   |  5 -
 10 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
index 3e3d369d5e4..f49a6e93bc7 100644
--- a/tools/binman/bsection.py
+++ b/tools/binman/bsection.py
@@ -317,9 +317,15 @@ class Section(object):
 """Call the ProcessContents() method for each entry
 
 This is intended to adjust the contents as needed by the entry type.
+
+Returns:
+True if no entries needed to change their size
 """
+sizes_ok = True
 for entry in self._entries.values():
-entry.ProcessContents()
+if not entry.ProcessContents():
+sizes_ok = False
+return sizes_ok
 
 def WriteSymbols(self):
 """Write symbol values into binary files for access at run time"""
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index b19a3b026f2..7db1402b84f 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -245,7 +245,8 @@ class Entry(object):
 def ProcessContentsUpdate(self, data):
 """Update the contents of an entry, after the size is fixed
 
-This checks that the new data is the same size as the old.
+This checks that the new data is the same size as the old. If the size
+has changed, this triggers a re-run of the packing algorithm.
 
 Args:
 data: Data to set to the contents (bytes)
@@ -253,10 +254,12 @@ class Entry(object):
 Raises:
 ValueError if the new data size is not the same as the old
 """
+size_ok = True
 if len(data) != self.contents_size:
 self.Raise('Cannot update entry size from %d to %d' %
(self.contents_size, len(data)))
 self.SetContents(data)
+return size_ok
 
 def ObtainContents(self):
 """Figure out the contents of an entry.
@@ -401,7 +404,22 @@ class Entry(object):
 self.image_pos = image_pos + self.offset
 
 def ProcessContents(self):
-pass
+"""Do any post-packing updates of entry contents
+
+This function should call ProcessContentsUpdate() to update the entry
+contents, if necessary, returning its return value here.
+
+Args:
+data: Data to set to the contents (bytes)
+
+Returns:
+True if the new data size is OK, False if expansion is needed
+
+Raises:
+ValueError if the new data size is not the same as the old and
+state.AllowEntryExpansion() is False
+"""
+return True
 
 def WriteSymbols(self, section):
 """Write symbol values into binary files for access at run time
diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py
index ac62d2e2005..2204362281c 100644
--- a/tools/binman/etype/_testing.py
+++ b/tools/binman/etype/_testing.py
@@ -88,9 +88,10 @@ class Entry__testing(Entry):
 
 def ProcessContents(self):
 if self.bad_update_contents:
-# Request to update the conents with something larger, to cause a
+# Request to update the contents with something larger, to cause a
 # failure.
-self.ProcessContentsUpdate('aa')
+return self.ProcessContentsUpdate('aa')
+return True
 
 def ProcessFdt(self, fdt):
 """Force reprocessing the first time"""
diff --git 

[U-Boot] [PATCH v2 05/31] binman: Add an FDT map

2019-07-08 Thread Simon Glass
An FDT map is an entry which holds a full description of the image
entries, in FDT format. It can be discovered using the magic string at
its start. Tools can locate and read this entry to find out what entries
are in the image and where each entry is located.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README  |   5 +-
 tools/binman/README.entries  |  38 +++
 tools/binman/etype/fdtmap.py | 109 +++
 tools/binman/ftest.py|  52 +--
 tools/binman/state.py|   2 +-
 tools/binman/test/115_fdtmap.dts |  13 
 6 files changed, 211 insertions(+), 8 deletions(-)
 create mode 100644 tools/binman/etype/fdtmap.py
 create mode 100644 tools/binman/test/115_fdtmap.dts

diff --git a/tools/binman/README b/tools/binman/README
index b067d3b78cf..8a5f3320dcb 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -638,6 +638,10 @@ the image definition, binman calculates the final values 
and writes these to
 the device tree. These can be used by U-Boot at run-time to find the location
 of each entry.
 
+Alternatively, an FDT map entry can be used to add a special FDT containing
+just the information about the image. This is preceded by a magic string so can
+be located anywhere in the image.
+
 
 Compression
 ---
@@ -814,7 +818,6 @@ Some ideas:
 - Support building an image for a board (-b) more completely, with a
   configurable build directory
 - Support putting the FDT in an image with a suitable magic number
-- Support adding a pointer to the FDT map
 - Support listing files in images
 - Support logging of binman's operations, with different levels of verbosity
 - Support updating binaries in an image (with no size change / repacking)
diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 3241befc7f4..7014d36f5ff 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -223,6 +223,44 @@ updating the EC on startup via software sync.
 
 
 
+Entry: fdtmap: An entry which contains an FDT map
+-
+
+Properties / Entry arguments:
+None
+
+An FDT map is just a header followed by an FDT containing a list of all the
+entries in the image.
+
+The header is the string _FDTMAP_ followed by 8 unused bytes.
+
+When used, this entry will be populated with an FDT map which reflects the
+entries in the current image. Hierarchy is preserved, and all offsets and
+sizes are included.
+
+Note that the -u option must be provided to ensure that binman updates the
+FDT with the position of each entry.
+
+Example output for a simple image with U-Boot and an FDT map:
+
+/ {
+size = <0x0112>;
+image-pos = <0x>;
+offset = <0x>;
+u-boot {
+size = <0x0004>;
+image-pos = <0x>;
+offset = <0x>;
+};
+fdtmap {
+size = <0x010e>;
+image-pos = <0x0004>;
+offset = <0x0004>;
+};
+};
+
+
+
 Entry: files: Entry containing a set of files
 -
 
diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py
new file mode 100644
index 000..cdeb491ebdc
--- /dev/null
+++ b/tools/binman/etype/fdtmap.py
@@ -0,0 +1,109 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2018 Google, Inc
+# Written by Simon Glass 
+
+"""# Entry-type module for a full map of the firmware image
+
+This handles putting an FDT into the image with just the information about the
+image.
+"""
+
+import libfdt
+
+from entry import Entry
+from fdt import Fdt
+import state
+import tools
+
+FDTMAP_MAGIC = b'_FDTMAP_'
+
+class Entry_fdtmap(Entry):
+"""An entry which contains an FDT map
+
+Properties / Entry arguments:
+None
+
+An FDT map is just a header followed by an FDT containing a list of all the
+entries in the image.
+
+The header is the string _FDTMAP_ followed by 8 unused bytes.
+
+When used, this entry will be populated with an FDT map which reflects the
+entries in the current image. Hierarchy is preserved, and all offsets and
+sizes are included.
+
+Note that the -u option must be provided to ensure that binman updates the
+FDT with the position of each entry.
+
+Example output for a simple image with U-Boot and an FDT map:
+
+/ {
+size = <0x0112>;
+image-pos = <0x>;
+offset = <0x>;
+u-boot {
+size = <0x0004>;
+image-pos = <0x>;
+offset = <0x>;
+};
+fdtmap {
+size = <0x010e>;
+image-pos = <0x0004>;
+offset = <0x0004>;
+};
+};
+"""
+def __init__(self, section, etype, node):
+Entry.__init__(self, section, etype, node)
+
+def _GetFdtmap(self):
+"""Build an FDT map from the entries in the current image
+
+

[U-Boot] [PATCH v2 03/31] binman: Update help for new features

2019-07-08 Thread Simon Glass
A few new features have been added. This has rendered part of the README
obsolete. Update it.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/binman/README b/tools/binman/README
index 1851a4e536d..b067d3b78cf 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -36,10 +36,9 @@ suitable padding and alignment. It provides a way to process 
binaries before
 they are included, by adding a Python plug-in. The device tree is available
 to U-Boot at run-time so that the images can be interpreted.
 
-Binman does not yet update the device tree with the final location of
-everything when it is done. A simple C structure could be generated for
-constrained environments like SPL (using dtoc) but this is also not
-implemented.
+Binman can update the device tree with the final location of everything when it
+is done. Entry positions can be provided to U-Boot SPL as run-time symbols,
+avoiding device-tree code overhead.
 
 Binman can also support incorporating filesystems in the image if required.
 For example x86 platforms may use CBFS in some cases.
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 04/31] binman: Add a convenience functions for real-DTB tests

2019-07-08 Thread Simon Glass
Quite a few tests will use a real device tree and need it updated with the
binman metadata. Add a helper function for this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/ftest.py | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 5bde8aa30a1..ed125670e2c 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -380,6 +380,17 @@ class TestFunctional(unittest.TestCase):
 if reset_dtbs and use_real_dtb:
 self._ResetDtbs()
 
+def _DoReadFileRealDtb(self, fname):
+"""Run binman with a real .dtb file and return the resulting data
+
+Args:
+fname: DT source filename to use (e.g. 082_fdt_update_all.dts)
+
+Returns:
+Resulting image contents
+"""
+return self._DoReadFileDtb(fname, use_real_dtb=True, 
update_dtb=True)[0]
+
 def _DoReadFile(self, fname, use_real_dtb=False):
 """Helper function which discards the device-tree binary
 
@@ -1547,8 +1558,7 @@ class TestFunctional(unittest.TestCase):
 
 def testUpdateFdtAll(self):
 """Test that all device trees are updated with offset/size info"""
-data, _, _, _ = self._DoReadFileDtb('082_fdt_update_all.dts',
-use_real_dtb=True, update_dtb=True)
+data = self._DoReadFileRealDtb('082_fdt_update_all.dts')
 
 base_expected = {
 'section:image-pos': 0,
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 02/31] binman: Update future features

2019-07-08 Thread Simon Glass
A few features have been completed and a few items are added.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/binman/README b/tools/binman/README
index 2f4c7fec21e..1851a4e536d 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -811,13 +811,17 @@ Some ideas:
 - Use of-platdata to make the information available to code that is unable
   to use device tree (such as a very small SPL image)
 - Allow easy building of images by specifying just the board name
-- Produce a full Python binding for libfdt (for upstream). This is nearing
-completion but some work remains
 - Add an option to decode an image into the constituent binaries
 - Support building an image for a board (-b) more completely, with a
   configurable build directory
-- Consider making binman work with buildman, although if it is used in the
-  Makefile, this will be automatic
+- Support putting the FDT in an image with a suitable magic number
+- Support adding a pointer to the FDT map
+- Support listing files in images
+- Support logging of binman's operations, with different levels of verbosity
+- Support updating binaries in an image (with no size change / repacking)
+- Support updating binaries in an image (with repacking)
+- Support adding FITs to an image
+- Support for ARM Trusted Firmware (ATF)
 
 --
 Simon Glass 
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 01/31] binman: Simplify the entry test

2019-07-08 Thread Simon Glass
The current test for the 'entry' module is a bit convoluted since it has
to import the module multiple times. It also relies on ordering, in that
test1EntryNoImportLib() must run before test2EntryImportLib() if they are
running in the same Python process.

This is unreliable since neither the ordering of tests nor the process
that they run in is defined.

Fix this by always reloading the entry in these two tests. Also add a
check that the expected value of have_importlib is obtained.

This corrects a code-coverage problem in the 'entry' module on some
systems.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/entry_test.py | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index b30a7beecc8..b6ad3edb8dc 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -9,12 +9,11 @@ import os
 import sys
 import unittest
 
+import entry
 import fdt
 import fdt_util
 import tools
 
-entry = None
-
 class TestEntry(unittest.TestCase):
 def setUp(self):
 tools.PrepareOutputDir(None)
@@ -29,16 +28,7 @@ class TestEntry(unittest.TestCase):
 dtb = fdt.FdtScan(fname)
 return dtb.GetNode('/binman/u-boot')
 
-def test1EntryNoImportLib(self):
-"""Test that we can import Entry subclassess successfully"""
-
-sys.modules['importlib'] = None
-global entry
-import entry
-entry.Entry.Create(None, self.GetNode(), 'u-boot')
-
-def test2EntryImportLib(self):
-del sys.modules['importlib']
+def _ReloadEntry(self):
 global entry
 if entry:
 if sys.version_info[0] >= 3:
@@ -48,8 +38,21 @@ class TestEntry(unittest.TestCase):
 reload(entry)
 else:
 import entry
+
+def test1EntryNoImportLib(self):
+"""Test that we can import Entry subclassess successfully"""
+sys.modules['importlib'] = None
+global entry
+self._ReloadEntry()
+entry.Entry.Create(None, self.GetNode(), 'u-boot')
+self.assertFalse(entry.have_importlib)
+
+def test2EntryImportLib(self):
+del sys.modules['importlib']
+global entry
+self._ReloadEntry()
 entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
-del entry
+self.assertTrue(entry.have_importlib)
 
 def testEntryContents(self):
 """Test the Entry bass class"""
@@ -59,7 +62,6 @@ class TestEntry(unittest.TestCase):
 
 def testUnknownEntry(self):
 """Test that unknown entry types are detected"""
-import entry
 Node = collections.namedtuple('Node', ['name', 'path'])
 node = Node('invalid-name', 'invalid-path')
 with self.assertRaises(ValueError) as e:
@@ -69,7 +71,6 @@ class TestEntry(unittest.TestCase):
 
 def testUniqueName(self):
 """Test Entry.GetUniqueName"""
-import entry
 Node = collections.namedtuple('Node', ['name', 'parent'])
 base_node = Node('root', None)
 base_entry = entry.Entry(None, None, base_node, read_node=False)
@@ -80,7 +81,6 @@ class TestEntry(unittest.TestCase):
 
 def testGetDefaultFilename(self):
 """Trivial test for this base class function"""
-import entry
 base_entry = entry.Entry(None, None, None, read_node=False)
 self.assertIsNone(base_entry.GetDefaultFilename())
 
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 00/31] binman: Allow reading of images to list contents

2019-07-08 Thread Simon Glass
This series adds features to allow binman to read its own images. Using
an 'FDT map' inside the image (basically a cut-down copy of the input
config with some pieces added) it can reverse-engineer the image and
figure out what is where.

Uses of this feature are

- a new 'ls' command, which allows listing the entries in an image
- a new 'extract' command, which allows entry contents to be extracted and
written to one or more files

Other improvements along the way include:
- Support for FDT map
- Support for an image header, which points to the FDT map
- Ability to deal with entries which change size after packing
- Additional error checking and FDT features for CBFS
- Convert from OptionParser to ArgumentParser
- Refactor to reduce code differences between entries and sections

Future work will allow reading files from the image, but I've decided to
put that in the next series.

Changes in v2:
- Add patches to enhance the 'ls' command to filter which entries are shown
- Add patches to implement the 'extract' command
- Add the Entry object to EntryInfo as well
- Adjust LocateFdtmap() to return the position of the header
- Adjust the test to not rely on lz4 compression version
- Allow listing subsets of the image
- Avoid dual assignment in ResetForPack()
- Change Image.ListEntries() to BuildEntryList() since signature differs
- Change list command from 'list' to 'ls'
- Deal with travis's old lz4 version by skipping tests as necessary
- Don't allow global arguments after the command
- Fix up arguments in main Makefile
- Move 129_list_fdtmap.dts into the next commit
- Move patch 'Add a comment about CBFS test structure' to earlier series
- Move patch 'Allow cbfstool to be optional with tests' to earlier series
- Pass verbosity to tests via the setup_test_args() method
- Put --toolpath in the right place in functional tests
- Rename 128_decode_image_no_hdr.dts to 129_decode_image_nohdr.dts
- Show a message when a section's size changes
- Update Image for LocateFdtmap() returning the position of the header
- Update commit subject to more accurately describe this patch
- Update output from 'list' command
- Update test to use _DoReadFileRealDtb() helper
- Use 3 packing passes instead of two, and add a comment
- Use bytearray for Python 3

Simon Glass (31):
  binman: Simplify the entry test
  binman: Update future features
  binman: Update help for new features
  binman: Add a convenience functions for real-DTB tests
  binman: Add an FDT map
  binman: Add an image header
  binman: Convert to use ArgumentParser
  binman: Move compression into the Entry base class
  binman: Drop an unused arg in Entry.Lookup()
  binman: Allow easy importing of entry modules
  binman: Fix up ProcessUpdateContents error and comments
  binman: Call ProcessUpdateContents() consistently
  binman: Add a return value to ProcessContentsUpdate()
  binman: Add a control for post-pack entry expansion
  binman: Allow entries to expand after packing
  binman: Allow device-tree entries to be compressed
  binman: Provide the actual data address for cbfs files
  binman: Use the cbfs memlen field only for uncompressed length
  binman: Support FDT update for CBFS
  binman: Detect bad CBFS file types
  binman: Allow listing the entries in an image
  binman: Support locating an FDT map
  binman: Support locating an image header
  binman: Support reading an image into an Image object
  binman: Convert Image to a subclass of Entry
  binman: Support listing an image
  binman: Allow for logging information to be displayed
  binman: Allow reading an entry from an image
  binman: Support reading from CBFS entries
  binman: Add an 'extract' command
  binman: Add a test for nested and aligned sections

 .travis.yml   |   2 +-
 Makefile  |   4 +-
 test/run  |   4 +-
 tools/binman/README   | 129 ++-
 tools/binman/README.entries   |  78 +-
 tools/binman/binman.py|  47 +-
 tools/binman/bsection.py  | 496 ---
 tools/binman/cbfs_util.py |  56 +-
 tools/binman/cmdline.py   | 101 ++-
 tools/binman/control.py   | 213 -
 tools/binman/entry.py | 149 +++-
 tools/binman/entry_test.py|  32 +-
 tools/binman/etype/__init__.py|   0
 tools/binman/etype/_testing.py|  14 +-
 tools/binman/etype/blob.py|  51 +-
 tools/binman/etype/blob_dtb.py|  10 +-
 tools/binman/etype/cbfs.py|  64 +-
 tools/binman/etype/fdtmap.py  | 130 +++
 tools/binman/etype/files.py   |   3 +-
 tools/binman/etype/fmap.py|   4 +-
 tools/binman/etype/image_header.py|  99 +++
 tools/binman/etype/section.py | 439 +-
 

Re: [U-Boot] [u-boot 1/2] drivers/fsl-mc: Create Kconfig file to manage driver specific configs better

2019-07-08 Thread Joe Hershberger
On Wed, May 15, 2019 at 4:09 AM Florinel Iordache
 wrote:
>
> Create drivers/net/fsl-mc/Kconfig and move fsl-mc specific configs
> from arch/arm/cpu/armv8/fsl-layerscape/Kconfig to this new Kconfig
>
> Signed-off-by: Florinel Iordache 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] net: phy: ti: Fix clock output DT property

2019-07-08 Thread Joseph Hershberger
> -Original Message-
> From: Trent Piepho 
> Sent: Friday, May 10, 2019 12:49 PM
> To: u-boot@lists.denx.de
> Cc: Trent Piepho ; Joseph Hershberger
> ; Janine Hagemann
> ; Grygorii Strashko 
> Subject: [EXTERNAL] [PATCH] net: phy: ti: Fix clock output DT property
> 
> The code block reading the DT property for the clock output control was
> before the phy's DT node pointer was set, so it could never work.  Move it
> after the node pointer is set.
> 
> Also store the unsigned 32-bit property into an unsigned value, not a signed
> value, as the former will cause a problem if value overflows.
> For instance, if one were to add 0x as a code to mean the clock output
> should be turned off.
> 
> Cc: Joe Hershberger 
> Cc: Janine Hagemann 
> Cc: Grygorii Strashko 
> Signed-off-by: Trent Piepho 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] net: phy: ti: Use default values for tx/rx delay and fifo size

2019-07-08 Thread Joseph Hershberger
> -Original Message-
> From: Trent Piepho 
> Sent: Thursday, May 09, 2019 2:42 PM
> To: u-boot@lists.denx.de
> Cc: Trent Piepho ; Joseph Hershberger
> ; Janine Hagemann
> ; Grygorii Strashko 
> Subject: [EXTERNAL] [PATCH] net: phy: ti: Use default values for tx/rx delay
> and fifo size
> 
> When not using DM_ETH, these PHY settings are programmed with default
> values hardcoded into the driver.  When using DM_ETH, they should come
> from the device tree.  However, if the device tree does not have the
> properties, the driver will silent use -1.  Which is entirely out of range,
> programs nonsense into the PHY's registers, and does not work.
> 
> Change this to use the same defaults as non-DM_ETH if the device tree is
> lacking the properties.
> 
> As an alternative, the kernel driver for the phy will display an error message
> and fail if the device tree is lacking.
> 
> Cc: Joe Hershberger 
> Cc: Janine Hagemann 
> Cc: Grygorii Strashko 
> Signed-off-by: Trent Piepho 

Acked-by: Joe Hershberger 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 19/37] binman: Don't assume there is an ME region

2019-07-08 Thread Simon Glass
At present having a descriptor means that there is an ME (Intel
Management Engine) entry as well. The descriptor provides the ME location
and assumes that it is present.

For some SoCs this is not true. Before providing the location of a
potentially non-existent entry, check if it is present.

Update the comment in the ME entry also.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README.entries|  2 ++
 tools/binman/entry.py  |  9 +
 tools/binman/etype/intel_descriptor.py | 10 +++---
 tools/binman/etype/intel_me.py |  2 ++
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 357946d6305..702fc9fda08 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -206,6 +206,8 @@ does not directly execute code in the ME binary.
 
 A typical filename is 'me.bin'.
 
+The position of this entry is generally set by the intel-descriptor entry.
+
 See README.x86 for information about x86 binary blobs.
 
 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index e8d0adec1e9..7ead997e0fd 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -544,3 +544,12 @@ features to produce new behaviours.
 # the data grows. This should not fail, but check it to be sure.
 if not self.ObtainContents():
 self.Raise('Cannot obtain contents when expanding entry')
+
+def HasSibling(self, name):
+"""Check if there is a sibling of a given name
+
+Returns:
+True if there is an entry with this name in the the same section,
+else False
+"""
+return name in self.section.GetEntries()
diff --git a/tools/binman/etype/intel_descriptor.py 
b/tools/binman/etype/intel_descriptor.py
index 661063457ed..65ba2391e69 100644
--- a/tools/binman/etype/intel_descriptor.py
+++ b/tools/binman/etype/intel_descriptor.py
@@ -60,6 +60,10 @@ class Entry_intel_descriptor(Entry_blob):
 for i in range(MAX_REGIONS):
 self._regions.append(Region(self.data, frba, i))
 
-# Set the offset for ME only, for now, since the others are not used
-return {'intel-me': [self._regions[REGION_ME].base,
- self._regions[REGION_ME].size]}
+# Set the offset for ME (Management Engine) only, for now, since the
+# others are not used
+info = {}
+if self.HasSibling('intel-me'):
+info['intel-me'] = [self._regions[REGION_ME].base,
+self._regions[REGION_ME].size]
+return info
diff --git a/tools/binman/etype/intel_me.py b/tools/binman/etype/intel_me.py
index 247c5b33866..c932ec52225 100644
--- a/tools/binman/etype/intel_me.py
+++ b/tools/binman/etype/intel_me.py
@@ -22,6 +22,8 @@ class Entry_intel_me(Entry_blob):
 
 A typical filename is 'me.bin'.
 
+The position of this entry is generally set by the intel-descriptor entry.
+
 See README.x86 for information about x86 binary blobs.
 """
 def __init__(self, section, etype, node):
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 32/37] patman: Add a function to write ifwitool

2019-07-08 Thread Simon Glass
This tool has quite a few arguments and options, so put the functionality
in a function so that we call it from one place and hopefully get it
right.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/patman/tools.py | 33 +
 1 file changed, 33 insertions(+)

diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 69d03d38608..e945b54fa28 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -3,6 +3,8 @@
 # Copyright (c) 2016 Google, Inc
 #
 
+from __future__ import print_function
+
 import command
 import glob
 import os
@@ -440,3 +442,34 @@ def Decompress(indata, algo):
 else:
 raise ValueError("Unknown algorithm '%s'" % algo)
 return data
+
+CMD_CREATE, CMD_DELETE, CMD_ADD, CMD_REPLACE, CMD_EXTRACT = range(5)
+
+IFWITOOL_CMDS = {
+CMD_CREATE: 'create',
+CMD_DELETE: 'delete',
+CMD_ADD: 'add',
+CMD_REPLACE: 'replace',
+CMD_EXTRACT: 'extract',
+}
+
+def RunIfwiTool(ifwi_file, cmd, fname=None, subpart=None, entry_name=None):
+"""Run ifwitool with the given arguments:
+
+Args:
+ifwi_file: IFWI file to operation on
+cmd: Command to execute (CMD_...)
+fname: Filename of file to add/replace/extract/create (None for
+CMD_DELETE)
+subpart: Name of sub-partition to operation on (None for CMD_CREATE)
+entry_name: Name of directory entry to operate on, or None if none
+"""
+args = ['ifwitool', ifwi_file]
+args.append(IFWITOOL_CMDS[cmd])
+if fname:
+args += ['-f', fname]
+if subpart:
+args += ['-n', subpart]
+if entry_name:
+args += ['-d', '-e', entry_name]
+Run(*args)
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [ANN] U-Boot v2019.07 released

2019-07-08 Thread Tom Rini
Hey all,

So it is release day and once again we've had a few important fixes come
in over the last few days.  But I still feel comfortable doing the
release today.  Our next release is v2019.10 and I am hopeful this cycle
of fixes coming in at the end will happen, rather than seeing problems
discovered after release.

After the last release we had seen DM conversion deadlines pass, and
then in some cases we've seen some more conversion progress and in
others we're still working on it, and in still other cases we've just
removed features to see if people are in fact using the hardware still.
With v2019.07 we've now gone past the deadline for some block devices
and PCI and SPI flash, so I expect things to be moving to requiring
CONFIG_DEPRECATED now.

So with that, the merge window is open and we're looking at doing the
v2019.07 release on July 8th, 2019.

Please note that there may be a problem with getting the release tarball
if you get it via http/https.  We are aware of the issue and it is being
looked into now.

Thanks all!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 28/37] binman: Fix up the _DoTestFile() function -u argument

2019-07-08 Thread Simon Glass
This should be -u, not -up, since we don't need to preserve the output
directory in this case.

Signed-off-by: Simon Glass 
---

Changes in v2: None

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

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 9cec5f42fa3..b1780854cfe 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -208,7 +208,7 @@ class TestFunctional(unittest.TestCase):
 if map:
 args.append('-m')
 if update_dtb:
-args.append('-up')
+args.append('-u')
 if not use_real_dtb:
 args.append('--fake-dtb')
 if verbosity is not None:
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 37/37] binman: Add support for fixed-offset files in CBFS

2019-07-08 Thread Simon Glass
A feature of CBFS is that it allows files to be positioned at particular
offset (as with binman in general). This is useful to support
execute-in-place (XIP) code, since this may not be relocatable.

Add a new cbfs-offset property to control this.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Skip use of cbfstool in tests if it is not available

 tools/binman/README.entries   |  38 
 tools/binman/cbfs_util.py | 125 +-
 tools/binman/cbfs_util_test.py|  82 +++--
 tools/binman/etype/cbfs.py|  16 +++-
 tools/binman/ftest.py |  23 +
 tools/binman/test/114_cbfs_offset.dts |  26 ++
 6 files changed, 276 insertions(+), 34 deletions(-)
 create mode 100644 tools/binman/test/114_cbfs_offset.dts

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 2e6aea1e84c..3241befc7f4 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -100,6 +100,7 @@ with the second subnode below:
 filename = "u-boot.dtb";
 cbfs-type = "raw";
 cbfs-compress = "lz4";
+cbfs-offset = <0x10>;
 };
 };
 
@@ -158,6 +159,15 @@ cbfs-type:
 to add a flat binary with a load/start address, similar to the
 'add-flat-binary' option in cbfstool.
 
+cbfs-offset:
+This is the offset of the file's data within the CBFS. It is used to
+specify where the file should be placed in cases where a fixed position
+is needed. Typical uses are for code which is not relocatable and must
+execute in-place from a particular address. This works because SPI flash
+is generally mapped into memory on x86 devices. The file header is
+placed before this offset so that the data start lines up exactly with
+the chosen offset. If this property is not provided, then the file is
+placed in the next available spot.
 
 The current implementation supports only a subset of CBFS features. It does
 not support other file types (e.g. payload), adding multiple files (like the
@@ -334,6 +344,34 @@ See README.x86 for information about x86 binary blobs.
 
 
 
+Entry: intel-ifwi: Entry containing an Intel Integrated Firmware Image (IFWI) 
file
+--
+
+Properties / Entry arguments:
+- filename: Filename of file to read into entry. This is either the
+IFWI file itself, or a file that can be converted into one using a
+tool
+- convert-fit: If present this indicates that the ifwitool should be
+used to convert the provided file into a IFWI.
+
+This file contains code and data used by the SoC that is required to make
+it work. It includes U-Boot TPL, microcode, things related to the CSE
+(Converged Security Engine, the microcontroller that loads all the firmware)
+and other items beyond the wit of man.
+
+A typical filename is 'ifwi.bin' for an IFWI file, or 'fitimage.bin' for a
+file that will be converted to an IFWI.
+
+The position of this entry is generally set by the intel-descriptor entry.
+
+The contents of the IFWI are specified by the subnodes of the IFWI node.
+Each subnode describes an entry which is placed into the IFWFI with a given
+sub-partition (and optional entry name).
+
+See README.x86 for information about x86 binary blobs.
+
+
+
 Entry: intel-me: Entry containing an Intel Management Engine (ME) file
 --
 
diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
index ec4a2e5a8c6..1cdbcb2339e 100644
--- a/tools/binman/cbfs_util.py
+++ b/tools/binman/cbfs_util.py
@@ -12,7 +12,7 @@ it is necessary to rely on the C structures and source code 
(mostly cbfstool)
 to fully understand it.
 
 Currently supported: raw and stage types with compression, padding empty areas
-with empty files
+with empty files, fixed-offset files
 """
 
 from __future__ import print_function
@@ -190,6 +190,8 @@ class CbfsFile(object):
 Properties:
 name: Name of file
 offset: Offset of file data from start of file header
+cbfs_offset: Offset of file data in bytes from start of CBFS, or None 
to
+place this file anyway
 data: Contents of file, uncompressed
 data_len: Length of (possibly compressed) data in bytes
 ftype: File type (TYPE_...)
@@ -203,9 +205,10 @@ class CbfsFile(object):
 contents (used for empty files)
 size: Size of the file in bytes (used for empty files)
 """
-def __init__(self, name, ftype, data, compress=COMPRESS_NONE):
+def __init__(self, name, ftype, data, cbfs_offset, compress=COMPRESS_NONE):
 self.name = name
 self.offset = None
+self.cbfs_offset = cbfs_offset
 self.data = data
 self.ftype = ftype
 self.compress = 

[U-Boot] [PATCH v2 08/37] patman: Add a way to set the search path for tools

2019-07-08 Thread Simon Glass
Sometimes tools can be located by looking in other locations. Add a way to
direct the search.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/patman/tools.py | 42 +-
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 8e9f22afe8a..0b3049f91f4 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -24,6 +24,8 @@ chroot_path = None
 # Search paths to use for Filename(), used to find files
 search_paths = []
 
+tool_search_paths = []
+
 # Tools and the packages that contain them, on debian
 packages = {
 'lz4': 'liblz4-tool',
@@ -154,26 +156,56 @@ def Align(pos, align):
 def NotPowerOfTwo(num):
 return num and (num & (num - 1))
 
-def PathHasFile(fname):
+def SetToolPaths(toolpaths):
+"""Set the path to search for tools
+
+Args:
+toolpaths: List of paths to search for tools executed by Run()
+"""
+global tool_search_paths
+
+tool_search_paths = toolpaths
+
+def PathHasFile(path_spec, fname):
 """Check if a given filename is in the PATH
 
 Args:
+path_spec: Value of PATH variable to check
 fname: Filename to check
 
 Returns:
 True if found, False if not
 """
-for dir in os.environ['PATH'].split(':'):
+for dir in path_spec.split(':'):
 if os.path.exists(os.path.join(dir, fname)):
 return True
 return False
 
 def Run(name, *args, **kwargs):
+"""Run a tool with some arguments
+
+This runs a 'tool', which is a program used by binman to process files and
+perhaps produce some output. Tools can be located on the PATH or in a
+search path.
+
+Args:
+name: Command name to run
+args: Arguments to the tool
+kwargs: Options to pass to command.run()
+
+Returns:
+CommandResult object
+"""
 try:
-return command.Run(name, *args, cwd=outdir, capture=True, **kwargs)
+env = None
+if tool_search_paths:
+env = dict(os.environ)
+env['PATH'] = ':'.join(tool_search_paths) + ':' + env['PATH']
+return command.Run(name, *args, capture=True,
+   capture_stderr=True, env=env, **kwargs)
 except:
-if not PathHasFile(name):
-msg = "Plesae install tool '%s'" % name
+if env and not PathHasFile(env['PATH'], name):
+msg = "Please install tool '%s'" % name
 package = packages.get(name)
 if package:
  msg += " (e.g. from package '%s')" % package
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 36/37] binman: Pad empty areas of the CBFS with files

2019-07-08 Thread Simon Glass
When there is lots of open space in a CBFS it is normally padded with
'empty' files so that sequentially scanning the CBFS can skip from one to
the next without a break.

Add support for this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/cbfs_util.py  | 68 --
 tools/binman/cbfs_util_test.py | 23 +++-
 2 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
index 197cff89509..ec4a2e5a8c6 100644
--- a/tools/binman/cbfs_util.py
+++ b/tools/binman/cbfs_util.py
@@ -11,7 +11,8 @@ The format is somewhat defined by documentation in the 
coreboot tree although
 it is necessary to rely on the C structures and source code (mostly cbfstool)
 to fully understand it.
 
-Currently supported: raw and stage types with compression
+Currently supported: raw and stage types with compression, padding empty areas
+with empty files
 """
 
 from __future__ import print_function
@@ -102,6 +103,7 @@ ARCH_NAMES = {
 TYPE_CBFSHEADER = 0x02   # Master header, HEADER_FORMAT
 TYPE_STAGE  = 0x10   # Stage, holding an executable, see STAGE_FORMAT
 TYPE_RAW= 0x50   # Raw file, possibly compressed
+TYPE_EMPTY  = 0x # Empty data
 
 # Compression types
 COMPRESS_NONE, COMPRESS_LZMA, COMPRESS_LZ4 = range(3)
@@ -152,6 +154,19 @@ def align_int(val, align):
 """
 return int((val + align - 1) / align) * align
 
+def align_int_down(val, align):
+"""Align a value down to the given alignment
+
+Args:
+val: Integer value to align
+align: Integer alignment value (e.g. 4 to align to 4-byte boundary)
+
+Returns:
+integer value aligned to the required boundary, rounding down if
+necessary
+"""
+return int(val / align) * align
+
 def _pack_string(instr):
 """Pack a string to the required aligned size by adding padding
 
@@ -184,6 +199,9 @@ class CbfsFile(object):
 entry: Entry address in memory if known, else None. This is where
 execution starts after the file is loaded
 base_address: Base address to use for 'stage' files
+erase_byte: Erase byte to use for padding between the file header and
+contents (used for empty files)
+size: Size of the file in bytes (used for empty files)
 """
 def __init__(self, name, ftype, data, compress=COMPRESS_NONE):
 self.name = name
@@ -196,6 +214,8 @@ class CbfsFile(object):
 self.entry = None
 self.base_address = None
 self.data_len = 0
+self.erase_byte = None
+self.size = None
 
 def decompress(self):
 """Handle decompressing data if necessary"""
@@ -242,6 +262,24 @@ class CbfsFile(object):
 """
 return CbfsFile(name, TYPE_RAW, data, compress)
 
+@classmethod
+def empty(cls, space_to_use, erase_byte):
+"""Create a new empty file of a given size
+
+Args:
+space_to_use:: Size of available space, which must be at least as
+large as the alignment size for this CBFS
+erase_byte: Byte to use for contents of file (repeated through the
+whole file)
+
+Returns:
+CbfsFile object containing the file information
+"""
+cfile = CbfsFile('', TYPE_EMPTY, b'')
+cfile.size = space_to_use - FILE_HEADER_LEN - FILENAME_ALIGN
+cfile.erase_byte = erase_byte
+return cfile
+
 def get_data(self):
 """Obtain the contents of the file, in CBFS format
 
@@ -270,6 +308,8 @@ class CbfsFile(object):
 attr = struct.pack(ATTR_COMPRESSION_FORMAT,
FILE_ATTR_TAG_COMPRESSION, ATTR_COMPRESSION_LEN,
self.compress, len(orig_data))
+elif self.ftype == TYPE_EMPTY:
+data = tools.GetBytes(self.erase_byte, self.size)
 else:
 raise ValueError('Unknown type %#x when writing\n' % self.ftype)
 if attr:
@@ -357,6 +397,24 @@ class CbfsWriter(object):
  (offset, fd.tell()))
 fd.write(tools.GetBytes(self._erase_byte, offset - fd.tell()))
 
+def _pad_to(self, fd, offset):
+"""Write out pad bytes and/or an empty file until a given offset
+
+Args:
+fd: File objext to write to
+offset: Offset to write to
+"""
+self._align_to(fd, self._align)
+upto = fd.tell()
+if upto > offset:
+raise ValueError('No space for data before pad offset %#x (current 
offset %#x)' %
+ (offset, upto))
+todo = align_int_down(offset - upto, self._align)
+if todo:
+cbf = CbfsFile.empty(todo, self._erase_byte)
+fd.write(cbf.get_data())
+self._skip_to(fd, offset)
+
 def _align_to(self, fd, align):
 """Write out pad bytes until a given alignment is 

[U-Boot] [PATCH v2 22/37] patman: Add functions to compress and decompress data

2019-07-08 Thread Simon Glass
Add utility functions to compress and decompress using lz4 and lzma
algorithms. In the latter case these use the legacy lzma support favoured
by coreboot's CBFS.

No tests are provided as these functions will be tested by the CBFS
tests in a separate patch.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README   |  3 +-
 tools/patman/tools.py | 66 +++
 2 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/tools/binman/README b/tools/binman/README
index 0ff30ef6fd9..7eda244bbe2 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -183,7 +183,8 @@ Running binman
 
 First install prerequisites, e.g.
 
-   sudo apt-get install python-pyelftools python3-pyelftools
+   sudo apt-get install python-pyelftools python3-pyelftools lzma-alone \
+   liblz4-tool
 
 Type:
 
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 0b3049f91f4..69d03d38608 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -374,3 +374,69 @@ def ToBytes(string):
 if sys.version_info[0] >= 3:
 return string.encode('utf-8')
 return string
+
+def Compress(indata, algo):
+"""Compress some data using a given algorithm
+
+Note that for lzma this uses an old version of the algorithm, not that
+provided by xz.
+
+This requires 'lz4' and 'lzma_alone' tools. It also requires an output
+directory to be previously set up, by calling PrepareOutputDir().
+
+Args:
+indata: Input data to compress
+algo: Algorithm to use ('none', 'gzip', 'lz4' or 'lzma')
+
+Returns:
+Compressed data
+"""
+if algo == 'none':
+return indata
+fname = GetOutputFilename('%s.comp.tmp' % algo)
+WriteFile(fname, indata)
+if algo == 'lz4':
+data = Run('lz4', '--no-frame-crc', '-c', fname, binary=True)
+# cbfstool uses a very old version of lzma
+elif algo == 'lzma':
+outfname = GetOutputFilename('%s.comp.otmp' % algo)
+Run('lzma_alone', 'e', fname, outfname, '-lc1', '-lp0', '-pb0', '-d8')
+data = ReadFile(outfname)
+elif algo == 'gzip':
+data = Run('gzip', '-c', fname, binary=True)
+else:
+raise ValueError("Unknown algorithm '%s'" % algo)
+return data
+
+def Decompress(indata, algo):
+"""Decompress some data using a given algorithm
+
+Note that for lzma this uses an old version of the algorithm, not that
+provided by xz.
+
+This requires 'lz4' and 'lzma_alone' tools. It also requires an output
+directory to be previously set up, by calling PrepareOutputDir().
+
+Args:
+indata: Input data to decompress
+algo: Algorithm to use ('none', 'gzip', 'lz4' or 'lzma')
+
+Returns:
+Compressed data
+"""
+if algo == 'none':
+return indata
+fname = GetOutputFilename('%s.decomp.tmp' % algo)
+with open(fname, 'wb') as fd:
+fd.write(indata)
+if algo == 'lz4':
+data = Run('lz4', '-dc', fname, binary=True)
+elif algo == 'lzma':
+outfname = GetOutputFilename('%s.decomp.otmp' % algo)
+Run('lzma_alone', 'd', fname, outfname)
+data = ReadFile(outfname)
+elif algo == 'gzip':
+data = Run('gzip', '-cd', fname, binary=True)
+else:
+raise ValueError("Unknown algorithm '%s'" % algo)
+return data
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PULL] u-boot-mips

2019-07-08 Thread Tom Rini
On Fri, Jul 05, 2019 at 05:29:43PM +0200, Daniel Schwierzeck wrote:

> Hi Tom,
> 
> please pull a fix for network instability on MT7688 Gardena Smart Gateway.
> This should go into 2019.07, thanks.
> 
> 
> The following changes since commit 1f83431f0053f6fb20c511c391ffc687433848cf:
> 
>   board: amlogic: add mailing-list to MAINTAINERS (2019-07-04 11:36:52 -0400)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-mips.git tags/mips-fixes-for-2019.07
> 
> for you to fetch changes up to 9814fb272f59fc07c0856a6e034e34b361cade18:
> 
>   mips: mt76xx: Implement new d-cache fix in last_stage_init() (2019-07-05 
> 17:12:27 +0200)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 30/37] binman: Allow preserving test directories

2019-07-08 Thread Simon Glass
Sometimes when debugging tests it is useful to keep the input and output
directories so they can be examined later. Add an option for this and
update the binman tests to support it. This affects both the test class
and the tearDown() function called after each test.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README |  8 
 tools/binman/binman.py  | 16 +---
 tools/binman/cmdline.py |  4 
 tools/binman/ftest.py   | 28 +---
 4 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/tools/binman/README b/tools/binman/README
index 7eda244bbe2..2f4c7fec21e 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -731,6 +731,14 @@ Use '-P 1' to disable this. It is automatically disabled 
when code coverage is
 being used (-T) since they are incompatible.
 
 
+Debugging tests
+---
+
+Sometimes when debugging tests it is useful to keep the input and output
+directories so they can be examined later. Use -X or --test-preserve-dirs for
+this.
+
+
 Advanced Features / Technical docs
 --
 
diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index 7c1dcfb65fc..9878eb86d4f 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -46,15 +46,20 @@ except:
 import control
 import test_util
 
-def RunTests(debug, verbosity, processes, args):
+def RunTests(debug, verbosity, processes, test_preserve_dirs, args):
 """Run the functional tests and any embedded doctests
 
 Args:
 debug: True to enable debugging, which shows a full stack trace on 
error
 verbosity: Verbosity level to use
+test_preserve_dirs: True to preserve the input directory used by tests
+so that it can be examined afterwards (only useful for debugging
+tests). If a single test is selected (in args[0]) it also preserves
+the output directory for this test. Both directories are displayed
+on the command line.
+processes: Number of processes to use to run tests (None=same as #CPUs)
 args: List of positional args provided to binman. This can hold a test
 name to execute (as in 'binman -t testSections', for example)
-processes: Number of processes to use to run tests (None=same as #CPUs)
 """
 import elf_test
 import entry_test
@@ -82,6 +87,11 @@ def RunTests(debug, verbosity, processes, args):
 loader = unittest.TestLoader()
 for module in (entry_test.TestEntry, ftest.TestFunctional, 
fdt_test.TestFdt,
elf_test.TestElf, image_test.TestImage):
+# Test the test module about our arguments, if it is interested
+if hasattr(module, 'setup_test_args'):
+setup_test_args = getattr(module, 'setup_test_args')
+setup_test_args(preserve_indir=test_preserve_dirs,
+preserve_outdirs=test_preserve_dirs and test_name is not None)
 if test_name:
 try:
 suite.addTests(loader.loadTestsFromName(test_name, module))
@@ -157,7 +167,7 @@ def RunBinman(options, args):
 
 if options.test:
 ret_code = RunTests(options.debug, options.verbosity, 
options.processes,
-args[1:])
+options.test_preserve_dirs, args[1:])
 
 elif options.test_coverage:
 RunTestCoverage()
diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py
index 39b835666ea..91e007e4e03 100644
--- a/tools/binman/cmdline.py
+++ b/tools/binman/cmdline.py
@@ -59,6 +59,10 @@ def ParseArgs(argv):
 parser.add_option('-v', '--verbosity', default=1,
 type='int', help='Control verbosity: 0=silent, 1=progress, 3=full, '
 '4=debug')
+parser.add_option('-X', '--test-preserve-dirs', action='store_true',
+help='Preserve and display test-created input directories; also '
+ 'preserve the output directory if a single test is run (pass test 
'
+ 'name at the end of the command line')
 
 parser.usage += """
 
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index f5e0b9b9742..256d4a1c5d8 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -6,6 +6,8 @@
 #
 #python -m unittest func_test.TestFunctional.testHelp
 
+from __future__ import print_function
+
 import hashlib
 from optparse import OptionParser
 import os
@@ -134,10 +136,27 @@ class TestFunctional(unittest.TestCase):
 @classmethod
 def tearDownClass(self):
 """Remove the temporary input directory and its contents"""
-if self._indir:
-shutil.rmtree(self._indir)
+if self.preserve_indir:
+print('Preserving input dir: %s' % self._indir)
+else:
+if self._indir:
+shutil.rmtree(self._indir)
 self._indir = None
 
+@classmethod
+def setup_test_args(cls, preserve_indir=False, preserve_outdirs=False):
+"""Accept arguments 

[U-Boot] [PATCH v2 23/37] binman: Use the tools.Decompress method

2019-07-08 Thread Simon Glass
Update the compression test to use the tools module to decompress the
output data.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/ftest.py | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index c74e12d13c8..6ff871b3c16 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -59,7 +59,7 @@ BMPBLK_DATA   = b'bmp'
 VBLOCK_DATA   = b'vblk'
 FILES_DATA= (b"sorry I'm late\nOh, don't bother apologising, I'm " 
+
  b"sorry you're alive\n")
-COMPRESS_DATA = b'data to compress'
+COMPRESS_DATA = b'compress xx data'
 REFCODE_DATA  = b'refcode'
 
 
@@ -1560,16 +1560,7 @@ class TestFunctional(unittest.TestCase):
 self._ResetDtbs()
 
 def _decompress(self, data):
-out = os.path.join(self._indir, 'lz4.tmp')
-with open(out, 'wb') as fd:
-fd.write(data)
-return tools.Run('lz4', '-dc', out, binary=True)
-'''
-try:
-orig = lz4.frame.decompress(data)
-except AttributeError:
-orig = lz4.decompress(data)
-'''
+return tools.Decompress(data, 'lz4')
 
 def testCompress(self):
 """Test compression of blobs"""
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 34/37] binman: Add support for CBFS entries

2019-07-08 Thread Simon Glass
Add support for putting CBFSs (Coreboot Filesystems) in an image. This
allows binman to produce firmware images used by coreboot to boot.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Skip use of cbfstool in tests if it is not available

 tools/binman/README.entries | 142 ++
 tools/binman/control.py |   2 +
 tools/binman/etype/cbfs.py  | 193 
 tools/binman/ftest.py   | 110 +++
 tools/binman/test/102_cbfs_raw.dts  |  20 ++
 tools/binman/test/103_cbfs_raw_ppc.dts  |  21 +++
 tools/binman/test/104_cbfs_stage.dts|  19 ++
 tools/binman/test/105_cbfs_raw_compress.dts |  26 +++
 tools/binman/test/106_cbfs_bad_arch.dts |  15 ++
 tools/binman/test/107_cbfs_no_size.dts  |  13 ++
 tools/binman/test/108_cbfs_no_contents.dts  |  17 ++
 tools/binman/test/109_cbfs_bad_compress.dts |  18 ++
 tools/binman/test/110_cbfs_name.dts |  24 +++
 13 files changed, 620 insertions(+)
 create mode 100644 tools/binman/etype/cbfs.py
 create mode 100644 tools/binman/test/102_cbfs_raw.dts
 create mode 100644 tools/binman/test/103_cbfs_raw_ppc.dts
 create mode 100644 tools/binman/test/104_cbfs_stage.dts
 create mode 100644 tools/binman/test/105_cbfs_raw_compress.dts
 create mode 100644 tools/binman/test/106_cbfs_bad_arch.dts
 create mode 100644 tools/binman/test/107_cbfs_no_size.dts
 create mode 100644 tools/binman/test/108_cbfs_no_contents.dts
 create mode 100644 tools/binman/test/109_cbfs_bad_compress.dts
 create mode 100644 tools/binman/test/110_cbfs_name.dts

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 9a316763ace..2e6aea1e84c 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -60,6 +60,148 @@ See cros_ec_rw for an example of this.
 
 
 
+Entry: cbfs: Entry containing a Coreboot Filesystem (CBFS)
+--
+
+A CBFS provides a way to group files into a group. It has a simple directory
+structure and allows the position of individual files to be set, since it is
+designed to support execute-in-place in an x86 SPI-flash device. Where XIP
+is not used, it supports compression and storing ELF files.
+
+CBFS is used by coreboot as its way of orgnanising SPI-flash contents.
+
+The contents of the CBFS are defined by subnodes of the cbfs entry, e.g.:
+
+cbfs {
+size = <0x10>;
+u-boot {
+cbfs-type = "raw";
+};
+u-boot-dtb {
+cbfs-type = "raw";
+};
+};
+
+This creates a CBFS 1MB in size two files in it: u-boot.bin and u-boot.dtb.
+Note that the size is required since binman does not support calculating it.
+The contents of each entry is just what binman would normally provide if it
+were not a CBFS node. A blob type can be used to import arbitrary files as
+with the second subnode below:
+
+cbfs {
+size = <0x10>;
+u-boot {
+cbfs-name = "BOOT";
+cbfs-type = "raw";
+};
+
+dtb {
+type = "blob";
+filename = "u-boot.dtb";
+cbfs-type = "raw";
+cbfs-compress = "lz4";
+};
+};
+
+This creates a CBFS 1MB in size with u-boot.bin (named "BOOT") and
+u-boot.dtb (named "dtb") and compressed with the lz4 algorithm.
+
+
+Properties supported in the top-level CBFS node:
+
+cbfs-arch:
+Defaults to "x86", but you can specify the architecture if needed.
+
+
+Properties supported in the CBFS entry subnodes:
+
+cbfs-name:
+This is the name of the file created in CBFS. It defaults to the entry
+name (which is the node name), but you can override it with this
+property.
+
+cbfs-type:
+This is the CBFS file type. The following are supported:
+
+raw:
+This is a 'raw' file, although compression is supported. It can be
+used to store any file in CBFS.
+
+stage:
+This is an ELF file that has been loaded (i.e. mapped to memory), so
+appears in the CBFS as a flat binary. The input file must be an ELF
+image, for example this puts "u-boot" (the ELF image) into a 'stage'
+entry:
+
+cbfs {
+size = <0x10>;
+u-boot-elf {
+cbfs-name = "BOOT";
+cbfs-type = "stage";
+};
+};
+
+You can use your own ELF file with something like:
+
+cbfs {
+size = <0x10>;
+something {
+type = "blob";
+filename = "cbfs-stage.elf";
+cbfs-type = "stage";
+};
+};
+
+As mentioned, the file is converted to a flat binary, so it is
+equivalent to adding "u-boot.bin", for example, but with the load and
+start addresses specified by the 

[U-Boot] [PATCH v2 10/37] binman: Add missing comments to bsection

2019-07-08 Thread Simon Glass
Some functions lack comments in this file. Add comments to cover this
functionality.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/bsection.py | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
index a3026718794..e0e3707db41 100644
--- a/tools/binman/bsection.py
+++ b/tools/binman/bsection.py
@@ -452,13 +452,36 @@ class Section(object):
 source_entry.Raise("Cannot find entry for node '%s'" % node.name)
 
 def ExpandSize(self, size):
+"""Change the size of an entry
+
+Args:
+size: New size for entry
+"""
 if size != self._size:
 self._size = size
 
 def GetRootSkipAtStart(self):
+"""Get the skip-at-start value for the top-level section
+
+This is used to find out the starting offset for root section that
+contains this section. If this is a top-level section then it returns
+the skip-at-start offset for this section.
+
+This is used to get the absolute position of section within the image.
+
+Returns:
+Integer skip-at-start value for the root section containing this
+section
+"""
 if self._parent_section:
 return self._parent_section.GetRootSkipAtStart()
 return self._skip_at_start
 
 def GetImageSize(self):
+"""Get the size of the image containing this section
+
+Returns:
+Image size as an integer number of bytes, which may be None if the
+image size is dynamic and its sections have not yet been packed
+"""
 return self._image._size
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 27/37] binman: Support ELF files for TPL

2019-07-08 Thread Simon Glass
We currenty support using the ELF file in U-Boot proper and SPL, but not
TPL. Add this as it is useful both with sandbox and for CBFS to allow
adding TPL as a 'stage'.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README.entries  | 11 +++
 tools/binman/etype/u_boot_tpl_elf.py | 24 
 tools/binman/ftest.py|  2 ++
 tools/binman/test/096_elf.dts|  2 ++
 4 files changed, 39 insertions(+)
 create mode 100644 tools/binman/etype/u_boot_tpl_elf.py

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index c26addcfe64..9a316763ace 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -574,6 +574,17 @@ process.
 
 
 
+Entry: u-boot-tpl-elf: U-Boot TPL ELF image
+---
+
+Properties / Entry arguments:
+- filename: Filename of TPL u-boot (default 'tpl/u-boot-tpl')
+
+This is the U-Boot TPL ELF image. It does not include a device tree but can
+be relocated to any address for execution.
+
+
+
 Entry: u-boot-tpl-with-ucode-ptr: U-Boot TPL with embedded microcode pointer
 
 
diff --git a/tools/binman/etype/u_boot_tpl_elf.py 
b/tools/binman/etype/u_boot_tpl_elf.py
new file mode 100644
index 000..9cc1cc2c450
--- /dev/null
+++ b/tools/binman/etype/u_boot_tpl_elf.py
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2018 Google, Inc
+# Written by Simon Glass 
+#
+# Entry-type module for U-Boot TPL ELF image
+#
+
+from entry import Entry
+from blob import Entry_blob
+
+class Entry_u_boot_tpl_elf(Entry_blob):
+"""U-Boot TPL ELF image
+
+Properties / Entry arguments:
+- filename: Filename of TPL u-boot (default 'tpl/u-boot-tpl')
+
+This is the U-Boot TPL ELF image. It does not include a device tree but can
+be relocated to any address for execution.
+"""
+def __init__(self, section, etype, node):
+Entry_blob.__init__(self, section, etype, node)
+
+def GetDefaultFilename(self):
+return 'tpl/u-boot-tpl'
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 6ff871b3c16..9cec5f42fa3 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1745,6 +1745,8 @@ class TestFunctional(unittest.TestCase):
 def testElf(self):
 """Basic test of ELF entries"""
 self._SetupSplElf()
+with open(self.TestFile('bss_data'), 'rb') as fd:
+TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read())
 with open(self.TestFile('bss_data'), 'rb') as fd:
 TestFunctional._MakeInputFile('-boot', fd.read())
 data = self._DoReadFile('096_elf.dts')
diff --git a/tools/binman/test/096_elf.dts b/tools/binman/test/096_elf.dts
index df3440c3194..8e3f3f15ef0 100644
--- a/tools/binman/test/096_elf.dts
+++ b/tools/binman/test/096_elf.dts
@@ -10,5 +10,7 @@
};
u-boot-spl-elf {
};
+   u-boot-tpl-elf {
+   };
};
 };
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 29/37] binman: Allow verbosity control when running tests

2019-07-08 Thread Simon Glass
At present the -v flag is ignored with tests, so that (for example) -v2
does not have any effect. Update binman to pass this flag through to tests
so that they work just like running binman normally, except in a few
special cases where we are actually testing behaviour with different
levels of verbosity.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/binman.py |  8 ++--
 tools/binman/ftest.py  | 17 -
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index bab98826dc6..7c1dcfb65fc 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -46,11 +46,12 @@ except:
 import control
 import test_util
 
-def RunTests(debug, processes, args):
+def RunTests(debug, verbosity, processes, args):
 """Run the functional tests and any embedded doctests
 
 Args:
 debug: True to enable debugging, which shows a full stack trace on 
error
+verbosity: Verbosity level to use
 args: List of positional args provided to binman. This can hold a test
 name to execute (as in 'binman -t testSections', for example)
 processes: Number of processes to use to run tests (None=same as #CPUs)
@@ -71,6 +72,8 @@ def RunTests(debug, processes, args):
 sys.argv = [sys.argv[0]]
 if debug:
 sys.argv.append('-D')
+if verbosity:
+sys.argv.append('-v%d' % verbosity)
 
 # Run the entry tests first ,since these need to be the first to import the
 # 'entry' module.
@@ -153,7 +156,8 @@ def RunBinman(options, args):
 sys.tracebacklimit = 0
 
 if options.test:
-ret_code = RunTests(options.debug, options.processes, args[1:])
+ret_code = RunTests(options.debug, options.verbosity, 
options.processes,
+args[1:])
 
 elif options.test_coverage:
 RunTestCoverage()
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index b1780854cfe..f5e0b9b9742 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -153,6 +153,19 @@ class TestFunctional(unittest.TestCase):
 TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', 
U_BOOT_SPL_DTB_DATA)
 TestFunctional._MakeInputFile('tpl/u-boot-tpl.dtb', 
U_BOOT_TPL_DTB_DATA)
 
+def _GetVerbosity(self):
+"""Check if verbosity should be enabled
+
+Returns:
+list containing either:
+- Verbosity flag (e.g. '-v2') if it is present on the cmd line
+- nothing if the flag is not present
+"""
+for arg in sys.argv[1:]:
+if arg.startswith('-v'):
+return [arg]
+return []
+
 def _RunBinman(self, *args, **kwargs):
 """Run binman using the command line
 
@@ -213,6 +226,8 @@ class TestFunctional(unittest.TestCase):
 args.append('--fake-dtb')
 if verbosity is not None:
 args.append('-v%d' % verbosity)
+else:
+args += self._GetVerbosity()
 if entry_args:
 for arg, value in entry_args.items():
 args.append('-a%s=%s' % (arg, value))
@@ -1471,7 +1486,7 @@ class TestFunctional(unittest.TestCase):
 expected = 'Skipping images: image1'
 
 # We should only get the expected message in verbose mode
-for verbosity in (None, 2):
+for verbosity in (0, 2):
 with test_util.capture_sys_output() as (stdout, stderr):
 retcode = self._DoTestFile('006_dual_image.dts',
verbosity=verbosity,
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 33/37] binman: Add a utility library for coreboot CBFS

2019-07-08 Thread Simon Glass
Coreboot uses a simple flash-based filesystem called Coreboot Filesystem
(CBFS) to organise files used during boot. This allows files to be named
and their position in the flash to be set. It has special features for
dealing with x86 devices which typically memory-map their SPI flash to the
top of 32-bit address space and need a 'boot block' ending there.

Create a library to help create and read CBFS files. This includes a
writer class, a reader class and associated other helpers. Only a subset
of features are currently supported.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Install lzma tool in travis
- Skip use of cbfstool in tests if it is not available

 .travis.yml|   1 +
 tools/binman/binman.py |   4 +-
 tools/binman/cbfs_util.py  | 720 +
 tools/binman/cbfs_util_test.py | 540 +
 4 files changed, 1264 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/cbfs_util.py
 create mode 100755 tools/binman/cbfs_util_test.py

diff --git a/.travis.yml b/.travis.yml
index c883198abbf..70d89d3e233 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,6 +32,7 @@ addons:
 - device-tree-compiler
 - lzop
 - liblz4-tool
+- lzma-alone
 - libisl15
 - clang-7
 - srecord
diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index 52c03f68c6d..613aad5c451 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -62,6 +62,7 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, 
args, toolpath):
 name to execute (as in 'binman -t testSections', for example)
 toolpath: List of paths to use for tools
 """
+import cbfs_util_test
 import elf_test
 import entry_test
 import fdt_test
@@ -90,7 +91,8 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, 
args, toolpath):
 suite = unittest.TestSuite()
 loader = unittest.TestLoader()
 for module in (entry_test.TestEntry, ftest.TestFunctional, 
fdt_test.TestFdt,
-   elf_test.TestElf, image_test.TestImage):
+   elf_test.TestElf, image_test.TestImage,
+   cbfs_util_test.TestCbfs):
 # Test the test module about our arguments, if it is interested
 if hasattr(module, 'setup_test_args'):
 setup_test_args = getattr(module, 'setup_test_args')
diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py
new file mode 100644
index 000..197cff89509
--- /dev/null
+++ b/tools/binman/cbfs_util.py
@@ -0,0 +1,720 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2019 Google LLC
+# Written by Simon Glass 
+
+"""Support for coreboot's CBFS format
+
+CBFS supports a header followed by a number of files, generally targeted at SPI
+flash.
+
+The format is somewhat defined by documentation in the coreboot tree although
+it is necessary to rely on the C structures and source code (mostly cbfstool)
+to fully understand it.
+
+Currently supported: raw and stage types with compression
+"""
+
+from __future__ import print_function
+
+from collections import OrderedDict
+import io
+import struct
+import sys
+
+import command
+import elf
+import tools
+
+# Set to True to enable printing output while working
+DEBUG = False
+
+# Set to True to enable output from running cbfstool for debugging
+VERBOSE = False
+
+# The master header, at the start of the CBFS
+HEADER_FORMAT  = '>'
+HEADER_LEN = 0x20
+HEADER_MAGIC   = 0x4f524243
+HEADER_VERSION1= 0x31313131
+HEADER_VERSION2= 0x31313132
+
+# The file header, at the start of each file in the CBFS
+FILE_HEADER_FORMAT = b'>8s'
+FILE_HEADER_LEN= 0x18
+FILE_MAGIC = b'LARCHIVE'
+FILENAME_ALIGN = 16  # Filename lengths are aligned to this
+
+# A stage header containing information about 'stage' files
+# Yes this is correct: this header is in litte-endian format
+STAGE_FORMAT   = ' offset:
+raise ValueError('No space for data before offset %#x (current 
offset %#x)' %
+ (offset, fd.tell()))
+fd.write(tools.GetBytes(self._erase_byte, offset - fd.tell()))
+
+def _align_to(self, fd, align):
+"""Write out pad bytes until a given alignment is reached
+
+This only aligns if the resulting output would not reach the end of the
+CBFS, since we want to leave the last 4 bytes for the master-header
+pointer.
+
+Args:
+fd: File objext to write to
+align: Alignment to require (e.g. 4 means pad to next 4-byte
+boundary)
+"""
+offset = align_int(fd.tell(), align)
+if offset < self._size:
+self._skip_to(fd, offset)
+
+def add_file_stage(self, name, data):
+"""Add a new stage file to the CBFS
+
+Args:
+name: String file name to put in CBFS (does not need to correspond
+ 

[U-Boot] [PATCH v2 35/37] binman: Add support for Intel IFWI entries

2019-07-08 Thread Simon Glass
An Integrated Firmware Image is used to hold various binaries used for
booting with Apollolake and some later devices. Add support for this.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/etype/intel_descriptor.py|   6 +-
 tools/binman/etype/intel_ifwi.py  | 100 ++
 tools/binman/ftest.py |  55 ++
 tools/binman/test/111_x86-rom-ifwi.dts|  29 +
 tools/binman/test/112_x86-rom-ifwi-nodesc.dts |  28 +
 tools/binman/test/113_x86-rom-ifwi-nodata.dts |  29 +
 tools/binman/test/fitimage.bin.gz | Bin 0 -> 8418 bytes
 tools/binman/test/ifwi.bin.gz | Bin 0 -> 1884 bytes
 8 files changed, 245 insertions(+), 2 deletions(-)
 create mode 100644 tools/binman/etype/intel_ifwi.py
 create mode 100644 tools/binman/test/111_x86-rom-ifwi.dts
 create mode 100644 tools/binman/test/112_x86-rom-ifwi-nodesc.dts
 create mode 100644 tools/binman/test/113_x86-rom-ifwi-nodata.dts
 create mode 100644 tools/binman/test/fitimage.bin.gz
 create mode 100644 tools/binman/test/ifwi.bin.gz

diff --git a/tools/binman/etype/intel_descriptor.py 
b/tools/binman/etype/intel_descriptor.py
index 65ba2391e69..adea578080c 100644
--- a/tools/binman/etype/intel_descriptor.py
+++ b/tools/binman/etype/intel_descriptor.py
@@ -60,10 +60,12 @@ class Entry_intel_descriptor(Entry_blob):
 for i in range(MAX_REGIONS):
 self._regions.append(Region(self.data, frba, i))
 
-# Set the offset for ME (Management Engine) only, for now, since the
-# others are not used
+# Set the offset for ME (Management Engine) and IFWI (Integrated
+# Firmware Image), for now, since the others are not used.
 info = {}
 if self.HasSibling('intel-me'):
 info['intel-me'] = [self._regions[REGION_ME].base,
 self._regions[REGION_ME].size]
+if self.HasSibling('intel-ifwi'):
+info['intel-ifwi'] = [self._regions[REGION_BIOS].base, None]
 return info
diff --git a/tools/binman/etype/intel_ifwi.py b/tools/binman/etype/intel_ifwi.py
new file mode 100644
index 000..8c79b2dd291
--- /dev/null
+++ b/tools/binman/etype/intel_ifwi.py
@@ -0,0 +1,100 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2016 Google, Inc
+# Written by Simon Glass 
+#
+# Entry-type module for Intel Management Engine binary blob
+#
+
+from collections import OrderedDict
+
+from entry import Entry
+from blob import Entry_blob
+import fdt_util
+import tools
+
+class Entry_intel_ifwi(Entry_blob):
+"""Entry containing an Intel Integrated Firmware Image (IFWI) file
+
+Properties / Entry arguments:
+- filename: Filename of file to read into entry. This is either the
+IFWI file itself, or a file that can be converted into one using a
+tool
+- convert-fit: If present this indicates that the ifwitool should be
+used to convert the provided file into a IFWI.
+
+This file contains code and data used by the SoC that is required to make
+it work. It includes U-Boot TPL, microcode, things related to the CSE
+(Converged Security Engine, the microcontroller that loads all the 
firmware)
+and other items beyond the wit of man.
+
+A typical filename is 'ifwi.bin' for an IFWI file, or 'fitimage.bin' for a
+file that will be converted to an IFWI.
+
+The position of this entry is generally set by the intel-descriptor entry.
+
+The contents of the IFWI are specified by the subnodes of the IFWI node.
+Each subnode describes an entry which is placed into the IFWFI with a given
+sub-partition (and optional entry name).
+
+See README.x86 for information about x86 binary blobs.
+"""
+def __init__(self, section, etype, node):
+Entry_blob.__init__(self, section, etype, node)
+self._convert_fit = fdt_util.GetBool(self._node, 'convert-fit')
+self._ifwi_entries = OrderedDict()
+self._ReadSubnodes()
+
+def ObtainContents(self):
+"""Get the contects for the IFWI
+
+Unfortunately we cannot create anything from scratch here, as Intel has
+tools which create precursor binaries with lots of data and settings,
+and these are not incorporated into binman.
+
+The first step is to get a file in the IFWI format. This is either
+supplied directly or is extracted from a fitimage using the 'create'
+subcommand.
+
+After that we delete the OBBP sub-partition and add each of the files
+that we want in the IFWI file, one for each sub-entry of the IWFI node.
+"""
+self._pathname = tools.GetInputFilename(self._filename)
+
+# Create the IFWI file if needed
+if self._convert_fit:
+inname = self._pathname
+outname = tools.GetOutputFilename('ifwi.bin')
+tools.RunIfwiTool(inname, tools.CMD_CREATE, outname)
+  

[U-Boot] [PATCH v2 26/37] binman: Correct comment in u_boot_spl_elf

2019-07-08 Thread Simon Glass
This comment mentions the wrong default filename. Fix it.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/README.entries  | 2 +-
 tools/binman/etype/u_boot_spl_elf.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 9cbdbbaadef..c26addcfe64 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -496,7 +496,7 @@ Entry: u-boot-spl-elf: U-Boot SPL ELF image
 ---
 
 Properties / Entry arguments:
-- filename: Filename of SPL u-boot (default 'spl/u-boot')
+- filename: Filename of SPL u-boot (default 'spl/u-boot-spl')
 
 This is the U-Boot SPL ELF image. It does not include a device tree but can
 be relocated to any address for execution.
diff --git a/tools/binman/etype/u_boot_spl_elf.py 
b/tools/binman/etype/u_boot_spl_elf.py
index da328ae15e1..24ee77237ed 100644
--- a/tools/binman/etype/u_boot_spl_elf.py
+++ b/tools/binman/etype/u_boot_spl_elf.py
@@ -12,7 +12,7 @@ class Entry_u_boot_spl_elf(Entry_blob):
 """U-Boot SPL ELF image
 
 Properties / Entry arguments:
-- filename: Filename of SPL u-boot (default 'spl/u-boot')
+- filename: Filename of SPL u-boot (default 'spl/u-boot-spl')
 
 This is the U-Boot SPL ELF image. It does not include a device tree but can
 be relocated to any address for execution.
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 24/37] binman: Drop unnecessary debug handling

2019-07-08 Thread Simon Glass
The -D option enables debug mode, but we only need to add -D to the
command line once. Drop the duplicate code. Also drop the comment about
enabling debugging since this can be done with -D.

Signed-off-by: Simon Glass 

---

Changes in v2: None

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

diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index 05aeaecd8f3..bab98826dc6 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -71,8 +71,6 @@ def RunTests(debug, processes, args):
 sys.argv = [sys.argv[0]]
 if debug:
 sys.argv.append('-D')
-if debug:
-sys.argv.append('-D')
 
 # Run the entry tests first ,since these need to be the first to import the
 # 'entry' module.
@@ -151,9 +149,6 @@ def RunBinman(options, args):
 """
 ret_code = 0
 
-# For testing: This enables full exception traces.
-#options.debug = True
-
 if not options.debug:
 sys.tracebacklimit = 0
 
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 13/37] binman: Use a better error for missing Intel descriptor

2019-07-08 Thread Simon Glass
FD is a bit confusing so write this out in full. Also avoid splitting the
string so that people can grep for the error message more easily.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/etype/intel_descriptor.py | 2 +-
 tools/binman/ftest.py  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/binman/etype/intel_descriptor.py 
b/tools/binman/etype/intel_descriptor.py
index 6acbbd8b7a5..9deb8dcf42c 100644
--- a/tools/binman/etype/intel_descriptor.py
+++ b/tools/binman/etype/intel_descriptor.py
@@ -51,7 +51,7 @@ class Entry_intel_descriptor(Entry_blob):
 def GetOffsets(self):
 offset = self.data.find(FD_SIGNATURE)
 if offset == -1:
-self.Raise('Cannot find FD signature')
+self.Raise('Cannot find Intel Flash Descriptor (FD) signature')
 flvalsig, flmap0, flmap1, flmap2 = struct.unpack('> 16) & 0xff) << 4
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 46f669e73b4..8577adb5380 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -806,8 +806,8 @@ class TestFunctional(unittest.TestCase):
 TestFunctional._MakeInputFile('descriptor.bin', b'')
 with self.assertRaises(ValueError) as e:
 self._DoTestFile('031_x86-rom-me.dts')
-self.assertIn("Node '/binman/intel-descriptor': Cannot find FD "
-  "signature", str(e.exception))
+self.assertIn("Node '/binman/intel-descriptor': Cannot find Intel 
Flash Descriptor (FD) signature",
+  str(e.exception))
 
 def testPackX86RomBadDesc(self):
 """Test that the Intel requires a descriptor entry"""
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 17/37] binman: Ensure that coverage has access to site packages

2019-07-08 Thread Simon Glass
Code coverage tests fail on binman due to dist-packages being dropped from
the python path on Ubuntu 16.04. Add them in so that we can find the
elffile module, which is required by binman.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 tools/binman/binman.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index 9f8c5c99b79..05aeaecd8f3 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -11,9 +11,11 @@
 
 from __future__ import print_function
 
+from distutils.sysconfig import get_python_lib
 import glob
 import multiprocessing
 import os
+import site
 import sys
 import traceback
 import unittest
@@ -28,6 +30,12 @@ sys.path.insert(0, 'scripts/dtc/pylibfdt')
 sys.path.insert(0, os.path.join(our_path,
 '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
 
+# When running under python-coverage on Ubuntu 16.04, the dist-packages
+# directories are dropped from the python path. Add them in so that we can find
+# the elffile module. We could use site.getsitepackages() here but 
unfortunately
+# that is not available in a virtualenv.
+sys.path.append(get_python_lib())
+
 import cmdline
 import command
 use_concurrent = True
-- 
2.22.0.410.gd8fdbe21b5-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


  1   2   >