[PATCH 10/15] ram: k3-j721e: lpddr4_ctl_regs: Fix checkpatch issue for types

2021-05-03 Thread Dave Gerlach
Use Linux style u32 instead of uint32_t.

Signed-off-by: Dave Gerlach 
---
 drivers/ram/k3-j721e/lpddr4_ctl_regs.h | 3028 
 1 file changed, 1514 insertions(+), 1514 deletions(-)

diff --git a/drivers/ram/k3-j721e/lpddr4_ctl_regs.h 
b/drivers/ram/k3-j721e/lpddr4_ctl_regs.h
index 213e56948870..34e6698906ff 100644
--- a/drivers/ram/k3-j721e/lpddr4_ctl_regs.h
+++ b/drivers/ram/k3-j721e/lpddr4_ctl_regs.h
@@ -20,1527 +20,1527 @@
 #include "lpddr4_phy_core_macros.h"
 
 typedef struct __attribute__((packed)) lpddr4_ctlregs_s {
-   volatile uint32_t DENALI_CTL_0;
-   volatile uint32_t DENALI_CTL_1;
-   volatile uint32_t DENALI_CTL_2;
-   volatile uint32_t DENALI_CTL_3;
-   volatile uint32_t DENALI_CTL_4;
-   volatile uint32_t DENALI_CTL_5;
-   volatile uint32_t DENALI_CTL_6;
-   volatile uint32_t DENALI_CTL_7;
-   volatile uint32_t DENALI_CTL_8;
-   volatile uint32_t DENALI_CTL_9;
-   volatile uint32_t DENALI_CTL_10;
-   volatile uint32_t DENALI_CTL_11;
-   volatile uint32_t DENALI_CTL_12;
-   volatile uint32_t DENALI_CTL_13;
-   volatile uint32_t DENALI_CTL_14;
-   volatile uint32_t DENALI_CTL_15;
-   volatile uint32_t DENALI_CTL_16;
-   volatile uint32_t DENALI_CTL_17;
-   volatile uint32_t DENALI_CTL_18;
-   volatile uint32_t DENALI_CTL_19;
-   volatile uint32_t DENALI_CTL_20;
-   volatile uint32_t DENALI_CTL_21;
-   volatile uint32_t DENALI_CTL_22;
-   volatile uint32_t DENALI_CTL_23;
-   volatile uint32_t DENALI_CTL_24;
-   volatile uint32_t DENALI_CTL_25;
-   volatile uint32_t DENALI_CTL_26;
-   volatile uint32_t DENALI_CTL_27;
-   volatile uint32_t DENALI_CTL_28;
-   volatile uint32_t DENALI_CTL_29;
-   volatile uint32_t DENALI_CTL_30;
-   volatile uint32_t DENALI_CTL_31;
-   volatile uint32_t DENALI_CTL_32;
-   volatile uint32_t DENALI_CTL_33;
-   volatile uint32_t DENALI_CTL_34;
-   volatile uint32_t DENALI_CTL_35;
-   volatile uint32_t DENALI_CTL_36;
-   volatile uint32_t DENALI_CTL_37;
-   volatile uint32_t DENALI_CTL_38;
-   volatile uint32_t DENALI_CTL_39;
-   volatile uint32_t DENALI_CTL_40;
-   volatile uint32_t DENALI_CTL_41;
-   volatile uint32_t DENALI_CTL_42;
-   volatile uint32_t DENALI_CTL_43;
-   volatile uint32_t DENALI_CTL_44;
-   volatile uint32_t DENALI_CTL_45;
-   volatile uint32_t DENALI_CTL_46;
-   volatile uint32_t DENALI_CTL_47;
-   volatile uint32_t DENALI_CTL_48;
-   volatile uint32_t DENALI_CTL_49;
-   volatile uint32_t DENALI_CTL_50;
-   volatile uint32_t DENALI_CTL_51;
-   volatile uint32_t DENALI_CTL_52;
-   volatile uint32_t DENALI_CTL_53;
-   volatile uint32_t DENALI_CTL_54;
-   volatile uint32_t DENALI_CTL_55;
-   volatile uint32_t DENALI_CTL_56;
-   volatile uint32_t DENALI_CTL_57;
-   volatile uint32_t DENALI_CTL_58;
-   volatile uint32_t DENALI_CTL_59;
-   volatile uint32_t DENALI_CTL_60;
-   volatile uint32_t DENALI_CTL_61;
-   volatile uint32_t DENALI_CTL_62;
-   volatile uint32_t DENALI_CTL_63;
-   volatile uint32_t DENALI_CTL_64;
-   volatile uint32_t DENALI_CTL_65;
-   volatile uint32_t DENALI_CTL_66;
-   volatile uint32_t DENALI_CTL_67;
-   volatile uint32_t DENALI_CTL_68;
-   volatile uint32_t DENALI_CTL_69;
-   volatile uint32_t DENALI_CTL_70;
-   volatile uint32_t DENALI_CTL_71;
-   volatile uint32_t DENALI_CTL_72;
-   volatile uint32_t DENALI_CTL_73;
-   volatile uint32_t DENALI_CTL_74;
-   volatile uint32_t DENALI_CTL_75;
-   volatile uint32_t DENALI_CTL_76;
-   volatile uint32_t DENALI_CTL_77;
-   volatile uint32_t DENALI_CTL_78;
-   volatile uint32_t DENALI_CTL_79;
-   volatile uint32_t DENALI_CTL_80;
-   volatile uint32_t DENALI_CTL_81;
-   volatile uint32_t DENALI_CTL_82;
-   volatile uint32_t DENALI_CTL_83;
-   volatile uint32_t DENALI_CTL_84;
-   volatile uint32_t DENALI_CTL_85;
-   volatile uint32_t DENALI_CTL_86;
-   volatile uint32_t DENALI_CTL_87;
-   volatile uint32_t DENALI_CTL_88;
-   volatile uint32_t DENALI_CTL_89;
-   volatile uint32_t DENALI_CTL_90;
-   volatile uint32_t DENALI_CTL_91;
-   volatile uint32_t DENALI_CTL_92;
-   volatile uint32_t DENALI_CTL_93;
-   volatile uint32_t DENALI_CTL_94;
-   volatile uint32_t DENALI_CTL_95;
-   volatile uint32_t DENALI_CTL_96;
-   volatile uint32_t DENALI_CTL_97;
-   volatile uint32_t DENALI_CTL_98;
-   volatile uint32_t DENALI_CTL_99;
-   volatile uint32_t DENALI_CTL_100;
-   volatile uint32_t DENALI_CTL_101;
-   volatile uint32_t DENALI_CTL_102;
-   volatile uint32_t DENALI_CTL_103;
-   volatile uint32_t DENALI_CTL_104;
-   volatile uint32_t DENALI_CTL_105;
-   volatile uint32_t DENALI_CTL_106;
-   volatile uint32_t DENALI_CTL_107;
-   volatile 

[PATCH 12/15] ram: k3-ddrss: Introduce top-level CONFIG_K3_DDRSS

2021-05-03 Thread Dave Gerlach
Create a new CONFIG_K3_DDRSS option to select the common parts of the
k3-ddrss driver. Also introduce a choice that depends on the top level
option to select CONFIG_K3_J721E_DDRSS for j721e support, and update
corresponding Kconfig as required.

Signed-off-by: Dave Gerlach 
---
 board/ti/j721e/Kconfig |  4 ++--
 drivers/ram/Kconfig| 11 ++-
 drivers/ram/Makefile   |  2 +-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/board/ti/j721e/Kconfig b/board/ti/j721e/Kconfig
index 2cbe2b2481ac..c28752a658b3 100644
--- a/board/ti/j721e/Kconfig
+++ b/board/ti/j721e/Kconfig
@@ -23,7 +23,7 @@ config TARGET_J721E_R5_EVM
select K3_LOAD_SYSFW
select RAM
select SPL_RAM
-   select K3_J721E_DDRSS
+   select K3_DDRSS
imply SYS_K3_SPL_ATF
imply TI_I2C_BOARD_DETECT
 
@@ -43,7 +43,7 @@ config TARGET_J7200_R5_EVM
select K3_LOAD_SYSFW
select RAM
select SPL_RAM
-   select K3_J721E_DDRSS
+   select K3_DDRSS
imply SYS_K3_SPL_ATF
imply TI_I2C_BOARD_DETECT
 
diff --git a/drivers/ram/Kconfig b/drivers/ram/Kconfig
index a270e13b2651..4e4e7a9632a6 100644
--- a/drivers/ram/Kconfig
+++ b/drivers/ram/Kconfig
@@ -54,9 +54,16 @@ config K3_AM654_DDRSS
  config add support for the initialization of the external
  SDRAM devices connected to DDR subsystem.
 
+config K3_DDRSS
+   bool "Enable K3 DDRSS support"
+   depends on RAM
+
+choice
+   depends on K3_DDRSS
+   prompt "K3 DDRSS Arch Support"
+
 config K3_J721E_DDRSS
bool "Enable J721E DDRSS support"
-   depends on RAM
help
  The J721E DDR subsystem comprises DDR controller, DDR PHY and
  wrapper logic to integrate these blocks in the device. The DDR
@@ -65,6 +72,8 @@ config K3_J721E_DDRSS
  Enabling this config adds support for the DDR memory controller
  on J721E family of SoCs.
 
+endchoice
+
 config IMXRT_SDRAM
bool "Enable i.MXRT SDRAM support"
depends on RAM
diff --git a/drivers/ram/Makefile b/drivers/ram/Makefile
index 1806a160f51c..5a39611349d2 100644
--- a/drivers/ram/Makefile
+++ b/drivers/ram/Makefile
@@ -15,7 +15,7 @@ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
 obj-$(CONFIG_K3_AM654_DDRSS) += k3-am654-ddrss.o
 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
 obj-$(CONFIG_ARCH_ASPEED) += aspeed/
-obj-$(CONFIG_K3_J721E_DDRSS) += k3-ddrss/
+obj-$(CONFIG_K3_DDRSS) += k3-ddrss/
 
 obj-$(CONFIG_IMXRT_SDRAM) += imxrt_sdram.o
 
-- 
2.28.0



[PATCH 15/15] ram: k3-ddrss: Enable vtt regulator if present

2021-05-03 Thread Dave Gerlach
From: Lokesh Vutla 

Attempt to get and enable a vtt regulator if one is provided from the
dts. If we do not find one, continue as not all platforms have this.

Signed-off-by: Nishanth Menon 
Signed-off-by: Lokesh Vutla 
Signed-off-by: Dave Gerlach 
---
 drivers/ram/k3-ddrss/k3-ddrss.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/ram/k3-ddrss/k3-ddrss.c b/drivers/ram/k3-ddrss/k3-ddrss.c
index a10551491713..89d2eaec3d1a 100644
--- a/drivers/ram/k3-ddrss/k3-ddrss.c
+++ b/drivers/ram/k3-ddrss/k3-ddrss.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "lpddr4_obj_if.h"
 #include "lpddr4_if.h"
@@ -40,6 +41,7 @@ struct k3_ddrss_desc {
u32 ddr_freq1;
u32 ddr_freq2;
u32 ddr_fhs_cnt;
+   struct udevice *vtt_supply;
 };
 
 static lpddr4_obj *driverdt;
@@ -192,6 +194,18 @@ static int k3_ddrss_power_on(struct k3_ddrss_desc *ddrss)
return ret;
}
 
+   ret = device_get_supply_regulator(ddrss->dev, "vtt-supply",
+   >vtt_supply);
+   if (ret) {
+   dev_dbg(ddrss->dev, "vtt-supply not found.\n");
+   } else {
+   ret = regulator_set_value(ddrss->vtt_supply, 330);
+   if (ret)
+   return ret;
+   dev_dbg(ddrss->dev, "VTT regulator enabled, volt = %d\n",
+   regulator_get_value(ddrss->vtt_supply));
+   }
+
return 0;
 }
 
-- 
2.28.0



[PATCH 01/15] dt-bindings: memory-controller: Add K3 AM64 DDRSS compatible

2021-05-03 Thread Dave Gerlach
Update the k3-ddrss DT binding document to include compatible
for k3,am64-ddrss.

Signed-off-by: Dave Gerlach 
---
 doc/device-tree-bindings/memory-controller/k3-j721e-ddrss.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/doc/device-tree-bindings/memory-controller/k3-j721e-ddrss.txt 
b/doc/device-tree-bindings/memory-controller/k3-j721e-ddrss.txt
index 873a0e7ae7c8..c4cf26eaa4cf 100644
--- a/doc/device-tree-bindings/memory-controller/k3-j721e-ddrss.txt
+++ b/doc/device-tree-bindings/memory-controller/k3-j721e-ddrss.txt
@@ -9,7 +9,8 @@ DDRSS device node:
 ==
 Required properties:
 
-- compatible:  Shall be: "ti,j721e-ddrss"
+- compatible:  Shall be: "ti,j721e-ddrss" for j721e, j7200
+ "ti,am64-ddrss" for am642
 - reg-namescfg - Map the controller configuration region
ctrl_mmr_lp4 - Map LP4 register region in ctrl mmr
 - reg: Contains the register map per reg-names.
-- 
2.28.0



[PATCH 00/15] ram: k3-ddrss: Convert k3-j721e to common driver with k3-am64 support

2021-05-03 Thread Dave Gerlach
This patch series updates the existing k3-j721e driver to a common driver
to support both j721e and the new am642 SoC. It renames drivers/ram/k3-j721e
to drivers/ram/k3-ddrss and then introduces a refactored common driver with
the existing j721e support moved to files named with 32bit and am64 support
introduced in files named with 16bit.

Additionally, a bunch of indentation issues are cleaned up in several header
files as this allows better consistency between the old and new macros, and one
header had a large number of checkpatch issues that I could easily clean up in
one patch. I split these to individual patches to keep sizes down in the larger,
later patches that introduce actual functionality.

Regards,
Dave

Dave Gerlach (14):
  dt-bindings: memory-controller: Add K3 AM64 DDRSS compatible
  ram: k3-j721e: lpddr4_address_slice_0_macros: Fix indentation issues
  ram: k3-j721e: lpddr4_data_slice_0_macros: Fix indentation issues
  ram: k3-j721e: lpddr4_data_slice_1_macros: Fix indentation issues
  ram: k3-j721e: lpddr4_data_slice_2_macros: Fix indentation issues
  ram: k3-j721e: lpddr4_data_slice_3_macros: Fix indentation issues
  ram: k3-j721e: lpddr4_ddr_controller_macros: Fix indentation issues
  ram: k3-j721e: lpddr4_phy_core_macros: Fix indentation issues
  ram: k3-j721e: lpddr4_pi_macros: Fix indentation issues
  ram: k3-j721e: lpddr4_ctl_regs: Fix checkpatch issue for types
  ram: k3-j721e: Rename to k3-ddrss
  ram: k3-ddrss: Introduce top-level CONFIG_K3_DDRSS
  ram: k3-ddrss: Introduce common driver with J7 SoC support
  ram: k3-ddrss: Introduce support for AM642 SoCs

Lokesh Vutla (1):
  ram: k3-ddrss: Enable vtt regulator if present

 board/ti/j721e/Kconfig|4 +-
 .../memory-controller/k3-j721e-ddrss.txt  |3 +-
 drivers/ram/Kconfig   |   24 +-
 drivers/ram/Makefile  |2 +-
 drivers/ram/k3-ddrss/16bit/lpddr4_16bit_if.h  |  108 +
 .../ram/k3-ddrss/16bit/lpddr4_16bit_obj_if.h  |   14 +
 .../k3-ddrss/16bit/lpddr4_16bit_structs_if.h  |   15 +
 .../16bit/lpddr4_address_slice_0_macros.h |  624 ++
 .../16bit/lpddr4_address_slice_1_macros.h |  624 ++
 .../16bit/lpddr4_address_slice_2_macros.h |  624 ++
 drivers/ram/k3-ddrss/16bit/lpddr4_ctl_regs.h  | 1306 +++
 .../k3-ddrss/16bit/lpddr4_ctl_regs_rw_masks.h |   23 +
 .../16bit/lpddr4_data_slice_0_macros.h| 2036 +
 .../16bit/lpddr4_data_slice_1_macros.h| 2036 +
 .../16bit/lpddr4_ddr_controller_macros.h  | 6436 ++
 .../k3-ddrss/16bit/lpddr4_phy_core_macros.h   | 1838 
 drivers/ram/k3-ddrss/16bit/lpddr4_pi_macros.h | 5784 
 drivers/ram/k3-ddrss/32bit/lpddr4_32bit_if.h  |   91 +
 .../ram/k3-ddrss/32bit/lpddr4_32bit_obj_if.h  |   14 +
 .../k3-ddrss/32bit/lpddr4_32bit_structs_if.h  |   15 +
 .../32bit}/lpddr4_address_slice_0_macros.h|  343 +-
 drivers/ram/k3-ddrss/32bit/lpddr4_ctl_regs.h  | 1545 
 .../k3-ddrss/32bit/lpddr4_ctl_regs_rw_masks.h |   23 +
 .../32bit}/lpddr4_data_slice_0_macros.h   | 1443 ++-
 .../32bit}/lpddr4_data_slice_1_macros.h   | 1363 ++-
 .../32bit}/lpddr4_data_slice_2_macros.h   | 1363 ++-
 .../32bit}/lpddr4_data_slice_3_macros.h   | 1363 ++-
 .../32bit/lpddr4_ddr_controller_macros.h  | 7793 +
 .../32bit}/lpddr4_phy_core_macros.h   | 1397 ++-
 drivers/ram/k3-ddrss/32bit/lpddr4_pi_macros.h | 5397 
 drivers/ram/k3-ddrss/Makefile |   17 +
 drivers/ram/k3-ddrss/cdn_errno.h  |  140 +
 drivers/ram/k3-ddrss/cdn_inttypes.h   |   14 +
 drivers/ram/k3-ddrss/cdn_stdint.h |   14 +
 drivers/ram/k3-ddrss/cdn_stdtypes.h   |   19 +
 drivers/ram/k3-ddrss/cps_drv_lpddr4.h |  102 +
 .../k3-j721e-ddrss.c => k3-ddrss/k3-ddrss.c}  |  244 +-
 drivers/ram/k3-ddrss/lpddr4.c | 1079 +++
 drivers/ram/k3-ddrss/lpddr4.h |   73 +
 drivers/ram/k3-ddrss/lpddr4_16bit.c   |  396 +
 drivers/ram/k3-ddrss/lpddr4_16bit.h   |   33 +
 .../k3-ddrss/lpddr4_16bit_ctl_regs_rw_masks.c | 1309 +++
 drivers/ram/k3-ddrss/lpddr4_16bit_sanity.h|  257 +
 drivers/ram/k3-ddrss/lpddr4_32bit.c   |  302 +
 drivers/ram/k3-ddrss/lpddr4_32bit.h   |   30 +
 .../k3-ddrss/lpddr4_32bit_ctl_regs_rw_masks.c | 1548 
 drivers/ram/k3-ddrss/lpddr4_32bit_sanity.h|  223 +
 drivers/ram/k3-ddrss/lpddr4_if.h  |  144 +
 drivers/ram/k3-ddrss/lpddr4_obj_if.c  |   51 +
 drivers/ram/k3-ddrss/lpddr4_obj_if.h  |   86 +
 .../{k3-j721e => k3-ddrss}/lpddr4_private.h   |0
 drivers/ram/k3-ddrss/lpddr4_sanity.h  |  445 +
 drivers/ram/k3-ddrss/lpddr4_structs_if.h  |   51 +
 drivers/ram/k3-j721e/Makefile |8 -
 drivers/ram/k3-j721e/cps_drv_lpddr4.h |  119 -
 drivers/ram/k3-j721e/lpddr4.c | 2105 -
 drivers/ram/k3-j721e/lpddr4_ctl_regs.h| 1546 
 

[PATCH 02/15] ram: k3-j721e: lpddr4_address_slice_0_macros: Fix indentation issues

2021-05-03 Thread Dave Gerlach
Fix the indentation for certain macros to be consistent with the other
macros in the file, as the existing indentation does not make sense in
many places.

Signed-off-by: Dave Gerlach 
---
 .../k3-j721e/lpddr4_address_slice_0_macros.h  | 334 +-
 1 file changed, 167 insertions(+), 167 deletions(-)

diff --git a/drivers/ram/k3-j721e/lpddr4_address_slice_0_macros.h 
b/drivers/ram/k3-j721e/lpddr4_address_slice_0_macros.h
index bc8059efd15c..6fc9b0f74a84 100644
--- a/drivers/ram/k3-j721e/lpddr4_address_slice_0_macros.h
+++ b/drivers/ram/k3-j721e/lpddr4_address_slice_0_macros.h
@@ -10,8 +10,8 @@
 #ifndef REG_LPDDR4_ADDRESS_SLICE_0_MACROS_H_
 #define REG_LPDDR4_ADDRESS_SLICE_0_MACROS_H_
 
-#define LPDDR4__DENALI_PHY_1024_READ_MASK  
0x000107FFU
-#define LPDDR4__DENALI_PHY_1024_WRITE_MASK 
   0x000107FFU
+#define LPDDR4__DENALI_PHY_1024_READ_MASK
0x000107FFU
+#define LPDDR4__DENALI_PHY_1024_WRITE_MASK   
0x000107FFU
 #define LPDDR4__DENALI_PHY_1024__PHY_ADR_CLK_WR_BYPASS_SLAVE_DELAY_0_MASK 
0x07FFU
 #define LPDDR4__DENALI_PHY_1024__PHY_ADR_CLK_WR_BYPASS_SLAVE_DELAY_0_SHIFT
0U
 #define LPDDR4__DENALI_PHY_1024__PHY_ADR_CLK_WR_BYPASS_SLAVE_DELAY_0_WIDTH   
11U
@@ -32,16 +32,16 @@
 #define LPDDR4__SC_PHY_ADR_MANUAL_CLEAR_0__REG DENALI_PHY_1024
 #define LPDDR4__SC_PHY_ADR_MANUAL_CLEAR_0__FLD 
LPDDR4__DENALI_PHY_1024__SC_PHY_ADR_MANUAL_CLEAR_0
 
-#define LPDDR4__DENALI_PHY_1025_READ_MASK  
0xU
-#define LPDDR4__DENALI_PHY_1025_WRITE_MASK 
   0xU
+#define LPDDR4__DENALI_PHY_1025_READ_MASK
0xU
+#define LPDDR4__DENALI_PHY_1025_WRITE_MASK   
0xU
 #define LPDDR4__DENALI_PHY_1025__PHY_ADR_LPBK_RESULT_OBS_0_MASK  
0xU
 #define LPDDR4__DENALI_PHY_1025__PHY_ADR_LPBK_RESULT_OBS_0_SHIFT  
0U
 #define LPDDR4__DENALI_PHY_1025__PHY_ADR_LPBK_RESULT_OBS_0_WIDTH 
32U
 #define LPDDR4__PHY_ADR_LPBK_RESULT_OBS_0__REG DENALI_PHY_1025
 #define LPDDR4__PHY_ADR_LPBK_RESULT_OBS_0__FLD 
LPDDR4__DENALI_PHY_1025__PHY_ADR_LPBK_RESULT_OBS_0
 
-#define LPDDR4__DENALI_PHY_1026_READ_MASK  
0x0FFFU
-#define LPDDR4__DENALI_PHY_1026_WRITE_MASK 
   0x0FFFU
+#define LPDDR4__DENALI_PHY_1026_READ_MASK
0x0FFFU
+#define LPDDR4__DENALI_PHY_1026_WRITE_MASK   
0x0FFFU
 #define LPDDR4__DENALI_PHY_1026__PHY_ADR_LPBK_ERROR_COUNT_OBS_0_MASK 
0xU
 #define LPDDR4__DENALI_PHY_1026__PHY_ADR_LPBK_ERROR_COUNT_OBS_0_SHIFT 
0U
 #define LPDDR4__DENALI_PHY_1026__PHY_ADR_LPBK_ERROR_COUNT_OBS_0_WIDTH
16U
@@ -60,8 +60,8 @@
 #define LPDDR4__PHY_ADR_MASTER_DLY_LOCK_OBS_SELECT_0__REG DENALI_PHY_1026
 #define LPDDR4__PHY_ADR_MASTER_DLY_LOCK_OBS_SELECT_0__FLD 
LPDDR4__DENALI_PHY_1026__PHY_ADR_MASTER_DLY_LOCK_OBS_SELECT_0
 
-#define LPDDR4__DENALI_PHY_1027_READ_MASK  
0xFF7F07FFU
-#define LPDDR4__DENALI_PHY_1027_WRITE_MASK 
   0xFF7F07FFU
+#define LPDDR4__DENALI_PHY_1027_READ_MASK
0xFF7F07FFU
+#define LPDDR4__DENALI_PHY_1027_WRITE_MASK   
0xFF7F07FFU
 #define LPDDR4__DENALI_PHY_1027__PHY_ADR_MASTER_DLY_LOCK_OBS_0_MASK  
0x07FFU
 #define LPDDR4__DENALI_PHY_1027__PHY_ADR_MASTER_DLY_LOCK_OBS_0_SHIFT  
0U
 #define LPDDR4__DENALI_PHY_1027__PHY_ADR_MASTER_DLY_LOCK_OBS_0_WIDTH 
11U
@@ -80,8 +80,8 @@
 #define LPDDR4__PHY_ADR_ADDER_SLV_DLY_ENC_OBS_0__REG DENALI_PHY_1027
 #define LPDDR4__PHY_ADR_ADDER_SLV_DLY_ENC_OBS_0__FLD 
LPDDR4__DENALI_PHY_1027__PHY_ADR_ADDER_SLV_DLY_ENC_OBS_0
 
-#define LPDDR4__DENALI_PHY_1028_READ_MASK  
0x01000707U
-#define LPDDR4__DENALI_PHY_1028_WRITE_MASK 
   0x01000707U
+#define LPDDR4__DENALI_PHY_1028_READ_MASK
0x01000707U
+#define LPDDR4__DENALI_PHY_1028_WRITE_MASK   
0x01000707U
 #define LPDDR4__DENALI_PHY_1028__PHY_ADR_SLAVE_LOOP_CNT_UPDATE_0_MASK 
0x0007U
 #define LPDDR4__DENALI_PHY_1028__PHY_ADR_SLAVE_LOOP_CNT_UPDATE_0_SHIFT
0U
 #define LPDDR4__DENALI_PHY_1028__PHY_ADR_SLAVE_LOOP_CNT_UPDATE_0_WIDTH
3U
@@ -103,18 +103,18 @@
 #define LPDDR4__SC_PHY_ADR_SNAP_OBS_REGS_0__FLD 
LPDDR4__DENALI_PHY_1028__SC_PHY_ADR_SNAP_OBS_REGS_0
 
 #define LPDDR4__DENALI_PHY_1028__PHY_ADR_TSEL_ENABLE_0_MASK  
0x0100U
-#define LPDDR4__DENALI_PHY_1028__PHY_ADR_TSEL_ENABLE_0_SHIFT   
 24U
-#define LPDDR4__DENALI_PHY_1028__PHY_ADR_TSEL_ENABLE_0_WIDTH   
  1U
-#define LPDDR4__DENALI_PHY_1028__PHY_ADR_TSEL_ENABLE_0_WOCLR 

[PATCH 11/15] ram: k3-j721e: Rename to k3-ddrss

2021-05-03 Thread Dave Gerlach
Rename the k3-j721e folder under drivers/ram to k3-ddrss in preparation
of introducing additional support for other platforms to the same
driver.

Signed-off-by: Dave Gerlach 
---
 drivers/ram/Makefile| 2 +-
 drivers/ram/{k3-j721e => k3-ddrss}/Makefile | 0
 drivers/ram/{k3-j721e => k3-ddrss}/cps_drv_lpddr4.h | 0
 drivers/ram/{k3-j721e => k3-ddrss}/k3-j721e-ddrss.c | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4.c | 0
 .../ram/{k3-j721e => k3-ddrss}/lpddr4_address_slice_0_macros.h  | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_ctl_regs.h| 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_data_slice_0_macros.h | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_data_slice_1_macros.h | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_data_slice_2_macros.h | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_data_slice_3_macros.h | 0
 .../ram/{k3-j721e => k3-ddrss}/lpddr4_ddr_controller_macros.h   | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_if.h  | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_obj_if.c  | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_obj_if.h  | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_phy_core_macros.h | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_pi_macros.h   | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_private.h | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_sanity.h  | 0
 drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_structs_if.h  | 0
 20 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/ram/{k3-j721e => k3-ddrss}/Makefile (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/cps_drv_lpddr4.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/k3-j721e-ddrss.c (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4.c (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_address_slice_0_macros.h 
(100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_ctl_regs.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_data_slice_0_macros.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_data_slice_1_macros.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_data_slice_2_macros.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_data_slice_3_macros.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_ddr_controller_macros.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_if.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_obj_if.c (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_obj_if.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_phy_core_macros.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_pi_macros.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_private.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_sanity.h (100%)
 rename drivers/ram/{k3-j721e => k3-ddrss}/lpddr4_structs_if.h (100%)

diff --git a/drivers/ram/Makefile b/drivers/ram/Makefile
index 209a78c06f52..1806a160f51c 100644
--- a/drivers/ram/Makefile
+++ b/drivers/ram/Makefile
@@ -15,7 +15,7 @@ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
 obj-$(CONFIG_K3_AM654_DDRSS) += k3-am654-ddrss.o
 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
 obj-$(CONFIG_ARCH_ASPEED) += aspeed/
-obj-$(CONFIG_K3_J721E_DDRSS) += k3-j721e/
+obj-$(CONFIG_K3_J721E_DDRSS) += k3-ddrss/
 
 obj-$(CONFIG_IMXRT_SDRAM) += imxrt_sdram.o
 
diff --git a/drivers/ram/k3-j721e/Makefile b/drivers/ram/k3-ddrss/Makefile
similarity index 100%
rename from drivers/ram/k3-j721e/Makefile
rename to drivers/ram/k3-ddrss/Makefile
diff --git a/drivers/ram/k3-j721e/cps_drv_lpddr4.h 
b/drivers/ram/k3-ddrss/cps_drv_lpddr4.h
similarity index 100%
rename from drivers/ram/k3-j721e/cps_drv_lpddr4.h
rename to drivers/ram/k3-ddrss/cps_drv_lpddr4.h
diff --git a/drivers/ram/k3-j721e/k3-j721e-ddrss.c 
b/drivers/ram/k3-ddrss/k3-j721e-ddrss.c
similarity index 100%
rename from drivers/ram/k3-j721e/k3-j721e-ddrss.c
rename to drivers/ram/k3-ddrss/k3-j721e-ddrss.c
diff --git a/drivers/ram/k3-j721e/lpddr4.c b/drivers/ram/k3-ddrss/lpddr4.c
similarity index 100%
rename from drivers/ram/k3-j721e/lpddr4.c
rename to drivers/ram/k3-ddrss/lpddr4.c
diff --git a/drivers/ram/k3-j721e/lpddr4_address_slice_0_macros.h 
b/drivers/ram/k3-ddrss/lpddr4_address_slice_0_macros.h
similarity index 100%
rename from drivers/ram/k3-j721e/lpddr4_address_slice_0_macros.h
rename to drivers/ram/k3-ddrss/lpddr4_address_slice_0_macros.h
diff --git a/drivers/ram/k3-j721e/lpddr4_ctl_regs.h 
b/drivers/ram/k3-ddrss/lpddr4_ctl_regs.h
similarity index 100%
rename from drivers/ram/k3-j721e/lpddr4_ctl_regs.h
rename to drivers/ram/k3-ddrss/lpddr4_ctl_regs.h
diff --git a/drivers/ram/k3-j721e/lpddr4_data_slice_0_macros.h 
b/drivers/ram/k3-ddrss/lpddr4_data_slice_0_macros.h
similarity index 100%
rename from drivers/ram/k3-j721e/lpddr4_data_slice_0_macros.h
rename to drivers/ram/k3-ddrss/lpddr4_data_slice_0_macros.h
diff --git 

Re: [PATCH v7 4/8] drivers: pci: add pcie support for fu740

2021-05-03 Thread Green Wan
On Mon, May 3, 2021 at 9:08 PM Neil Armstrong  wrote:
>
> On 22/04/2021 11:11, Green Wan wrote:
> > Add pcie driver for SiFive fu740, the driver depends on
> > fu740 gpio, clk and reset driver to do init. Force running at Gen1
> > for better capatible enumeration.
> >
> > Several devices are tested:
> > a) M.2 NVMe SSD
> > b) USB-to-PCI adapter
> > c) Ethernet adapter (E1000 compatible)
> >
> > Signed-off-by: Green Wan 
> > ---
> >  drivers/pci/Kconfig  |  10 +
> >  drivers/pci/Makefile |   1 +
> >  drivers/pci/pcie_dw_sifive.c | 508 +++
> >  3 files changed, 519 insertions(+)
> >  create mode 100644 drivers/pci/pcie_dw_sifive.c
> >
> > diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
> > index cdcdd8f456..b11dd5c02d 100644
> > --- a/drivers/pci/Kconfig
> > +++ b/drivers/pci/Kconfig
> > @@ -97,6 +97,16 @@ config PCIE_DW_MVEBU
> > Armada-8K SoCs. The PCIe controller on Armada-8K is based on
> > DesignWare hardware.
> >
> > +config PCIE_DW_SIFIVE
> > + bool "Enable SiFive FU740 PCIe"
> > + depends on CLK_SIFIVE_PRCI
> > + depends on RESET_SIFIVE
> > + depends on SIFIVE_GPIO
> > + select PCIE_DW_COMMON
> > + help
> > +   Say Y here if you want to enable PCIe controller support on
> > +   FU740.
> > +
> >  config PCIE_FSL
> >   bool "FSL PowerPC PCIe support"
> >   depends on DM_PCI
> > diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
> > index 96d61821fe..7351f8027d 100644
> > --- a/drivers/pci/Makefile
> > +++ b/drivers/pci/Makefile
> > @@ -53,3 +53,4 @@ obj-$(CONFIG_PCIE_DW_ROCKCHIP) += pcie_dw_rockchip.o
> >  obj-$(CONFIG_PCIE_DW_MESON) += pcie_dw_meson.o
> >  obj-$(CONFIG_PCI_BRCMSTB) += pcie_brcmstb.o
> >  obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
> > +obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
> > diff --git a/drivers/pci/pcie_dw_sifive.c b/drivers/pci/pcie_dw_sifive.c
> > new file mode 100644
> > index 00..599eb0ece2
> > --- /dev/null
> > +++ b/drivers/pci/pcie_dw_sifive.c
> > @@ -0,0 +1,508 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * SiFive FU740 DesignWare PCIe Controller
> > + *
> > + * Copyright (C) 2020-2021 SiFive, Inc.
> > + *
> > + * Based in early part on the i.MX6 PCIe host controller shim which is:
> > + *
> > + * Copyright (C) 2013 Kosagi
> > + *   http://www.kosagi.com
> > + *
> > + * Based on driver from author: Alan Mikhak 
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "pcie_dw_common.h"
> > +
> > +struct pcie_sifive {
> > + /* Must be first member of the struct */
> > + struct pcie_dw dw;
> > +
> > + /* private control regs */
> > + void __iomem *priv_base;
> > +
> > + /* reset, power, clock resources */
> > + int sys_int_pin;
> > + struct gpio_desc pwren_gpio;
> > + struct gpio_desc reset_gpio;
> > + struct clk aux_ck;
> > + struct reset_ctl reset;
> > +};
> > +
> > +enum pcie_sifive_devtype {
> > + SV_PCIE_UNKNOWN_TYPE = 0,
> > + SV_PCIE_ENDPOINT_TYPE = 1,
> > + SV_PCIE_HOST_TYPE = 3
> > +};
> > +
> > +#define ASSERTION_DELAY  100
> > +#define PCIE_PERST_ASSERT0x0
> > +#define PCIE_PERST_DEASSERT  0x1
> > +#define PCIE_PHY_RESET   0x1
> > +#define PCIE_PHY_RESET_DEASSERT  0x0
> > +#define GPIO_LOW 0x0
> > +#define GPIO_HIGH0x1
> > +#define PCIE_PHY_SEL 0x1
> > +
> > +#define sv_info(sv, fmt, arg...) printf(fmt, ## arg)
> > +#define sv_warn(sv, fmt, arg...) printf(fmt, ## arg)
> > +#define sv_debug(sv, fmt, arg...)debug(fmt, ## arg)
> > +#define sv_err(sv, fmt, arg...)  printf(fmt, ## arg)
> > +
> > +/* Doorbell Interface */
> > +#define DBI_OFFSET   0x0
> > +#define DBI_SIZE 0x1000
> > +
> > +#define PL_OFFSET0x700
> > +
> > +#define PHY_DEBUG_R0 (PL_OFFSET + 0x28)
> > +
> > +#define PHY_DEBUG_R1 (PL_OFFSET + 0x2c)
> > +#define PHY_DEBUG_R1_LINK_UP (0x1 << 4)
> > +#define PHY_DEBUG_R1_LINK_IN_TRAINING(0x1 << 29)
> > +
> > +#define PCIE_MISC_CONTROL_1  0x8bc
> > +#define DBI_RO_WR_EN BIT(0)
> > +
> > +/* pcie reset */
> > +#define PCIEX8MGMT_PERST_N   0x0
> > +
> > +/* LTSSM */
> > +#define PCIEX8MGMT_APP_LTSSM_ENABLE  0x10
> > +#define LTSSM_ENABLE_BIT BIT(0)
> > +
> > +/* phy reset */
> > +#define PCIEX8MGMT_APP_HOLD_PHY_RST  0x18
> > +
> > +/* device type */
> > +#define PCIEX8MGMT_DEVICE_TYPE   0x708
> > +#define DEVICE_TYPE_EP   0x0
> > +#define DEVICE_TYPE_RC   0x4
> > +
> > +/* phy control registers*/
> > +#define PCIEX8MGMT_PHY0_CR_PARA_ADDR 0x860
> > +#define 

Re: [PATCH 04/49] btrfs: Use U-Boot API for decompression

2021-05-03 Thread Marek Behun
On Mon,  3 May 2021 17:10:51 -0600
Simon Glass  wrote:

> Use the common function to avoid code duplication.
> 
> Signed-off-by: Simon Glass 

Is this tested? Why only zstd?

marek


[PATCH 00/49] image: Reduce #ifdefs and ad-hoc defines in image code

2021-05-03 Thread Simon Glass
Much of the image-handling code predates the introduction of Kconfig and
has quite a few #ifdefs in it. It also uses its own IMAGE_... defines to
help reduce the #ifdefs, which is unnecessary now that we can use
IS_ENABLED() et al.

The image code is also where quite a bit of code is shared with the host
tools. At present this uses a lot of checks of USE_HOSTCC.

This series introduces 'host' Kconfig options and a way to use
CONFIG_IS_ENABLED() to check them. This works in a similar way to SPL, so

   CONFIG_IS_ENABLED(FIT)

will evaluate to true on the host build (USE_HOSTCC) if CONFIG_HOST_FIT is
enabled. This allows quite a bit of clean-up of the image.h header file
and many of the image C files.

The 'host' Kconfig options should help to solve a more general problem in
that we mostly want the host tools to build with all features enabled, no
matter which features the 'target' build actually uses. This is a pain to
arrange at present, but with 'host' Kconfigs, we can just define them all
to y.

There are cases where the host tools do not have features which are
present on the target, for example environment and physical addressing.
To help with this, some of the core image code is split out into
image-board.c and image-host.c files.

Even with these changes, some #ifdefs remain (101 down to 42 in
common/image*). But the code is somewhat easier to follow and there are
fewer build paths.

In service of the above, this series includes a patch to add an API function
for zstd, so the code can be dropped from bootm.c

It also introduces a function to handle manual relocation.

Changes in v2:
- Add new abuf_init_set() function

Simon Glass (49):
  Add support for an owned buffer
  compiler: Add a comment to host_build()
  zstd: Create a function for use from U-Boot
  btrfs: Use U-Boot API for decompression
  image: Avoid switch default in image_decomp()
  image: Update zstd to avoid reporting error twice
  gzip: Avoid use of u64
  image: Update image_decomp() to avoid ifdefs
  image: Split board code out into its own file
  image: Fix up checkpatch warnings in image-board.c
  image: Split host code out into its own file
  image: Create a function to do manual relocation
  image: Avoid #ifdefs for manual relocation
  image: Remove ifdefs around image_setup_linux() el at
  image: Add Kconfig options for FIT in the host build
  kconfig: Add host support to CONFIG_IS_ENABLED()
  image: Shorten FIT_ENABLE_SHAxxx_SUPPORT
  image: Rename SPL_SHAxxx_SUPPORT to SPL_FIT_SHAxxx
  hash: Use Kconfig to enable hashing in host tools
  hash: Drop some #ifdefs in hash.c
  image: Drop IMAGE_ENABLE_FIT
  image: Drop IMAGE_ENABLE_OF_LIBFDT
  image: Use Kconfig to enable CONFIG_FIT_VERBOSE on host
  image: Rename CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
  image: Use Kconfig to enable FIT_RSASSA_PSS on host
  Kconfig: Rename SPL_CRC32_SUPPORT to SPL_CRC32
  image: Drop IMAGE_ENABLE_CRC32
  Kconfig: Rename SPL_MD5_SUPPORT to SPL_MD5
  image: Drop IMAGE_ENABLE_MD5
  image: Drop IMAGE_ENABLE_SHA1
  image: Drop IMAGE_ENABLE_SHAxxx
  image: Drop IMAGE_BOOT_GET_CMDLINE
  image: Drop IMAGE_OF_BOARD_SETUP
  image: Drop IMAGE_OF_SYSTEM_SETUP
  image: Drop IMAGE_ENABLE_IGNORE
  image: Drop IMAGE_ENABLE_SIGN/VERIFY defines
  image: Drop IMAGE_ENABLE_BEST_MATCH
  image: Drop IMAGE_ENABLE_EN/DECRYPT defines
  image: Tidy up fit_unsupported_reset()
  image: Drop unnecessary #ifdefs from image.h
  image: Drop #ifdefs for fit_print_contents()
  image: Drop most #ifdefs in image-board.c
  image: Reduce variable scope in boot_get_ramdisk()
  image: Split up boot_get_ramdisk()
  image: Remove #ifdefs from select_ramdisk()
  image: Remove some #ifdefs from image-fit and image-fit-sig
  image: Reduce variable scope in boot_get_fdt()
  image: Split up boot_get_fdt()
  image: Remove #ifdefs from select_fdt()

 arch/arc/lib/bootm.c  |2 +-
 arch/arm/lib/bootm.c  |4 +-
 arch/arm/mach-imx/hab.c   |2 +-
 arch/microblaze/lib/bootm.c   |2 +-
 arch/nds32/lib/bootm.c|4 +-
 arch/riscv/lib/bootm.c|4 +-
 board/synopsys/hsdk/hsdk.c|2 +-
 common/Kconfig.boot   |   18 +-
 common/Makefile   |2 +-
 common/bootm.c|   30 +-
 common/bootm_os.c |8 +
 common/hash.c |   96 +-
 common/image-board.c  |  958 +
 common/image-cipher.c |6 +-
 common/image-fdt.c|  275 ++---
 common/image-fit-sig.c|7 +-
 common/image-fit.c|   42 +-
 common/image-host.c   |   27 +
 common/image-sig.c|   57 +-
 common/image.c| 1179 ++---
 common/spl/Kconfig|   27 +-
 configs/axm_defconfig 

cramfs: unsupported filesystem features - ERROR

2021-05-03 Thread Marko Stanisic
I have created an emmc.img in Buildroot 2020.11 and flashed an emmc 
modul with that image.


The emmc.img file has two partitions with cramfs filesystem.(but i only 
have to load one) I tried to load the cramfs partition from the emmc 
into the RAM with the *cramfsls* - command and Iam very sure that i 
correctly loaded the cramfs partition with *mmc read* into the RAM.


I checked the RAM content with md.b - command and compared the first 
512byte visually with the hexdump of the rootfs.cramfs image (created by 
the genimage tool - called by buildroot).


But the problem ist that I get that weird error message *cramfs: 
unsupported filesystem features* in u-boot 2016.03 and i have no idea 
why. Normal gzip compression was used and XIP was turned off in the 
buildroot menuconfig.


Has anyone an idea, about the error message?

Note: I defined the "cramfsaddr" environment variable with an address 
location in the ram. That should be set to define an RAM address 
location inside the RAM to laod the cramfs partition.




[PATCH 26/49] Kconfig: Rename SPL_CRC32_SUPPORT to SPL_CRC32

2021-05-03 Thread Simon Glass
Drop the _SUPPORT suffix so we can use CONFIG_IS_ENABLED() with this
option.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/spl/Kconfig| 4 ++--
 configs/axm_defconfig | 2 +-
 configs/chromebit_mickey_defconfig| 2 +-
 configs/chromebook_jerry_defconfig| 2 +-
 configs/chromebook_minnie_defconfig   | 2 +-
 configs/chromebook_speedy_defconfig   | 2 +-
 configs/evb-px30_defconfig| 2 +-
 configs/firefly-px30_defconfig| 2 +-
 configs/imxrt1020-evk_defconfig   | 2 +-
 configs/imxrt1050-evk_defconfig   | 2 +-
 configs/odroid-go2_defconfig  | 2 +-
 configs/px30-core-ctouch2-px30_defconfig  | 2 +-
 configs/px30-core-edimm2.2-px30_defconfig | 2 +-
 configs/socfpga_agilex_atf_defconfig  | 2 +-
 configs/socfpga_agilex_vab_defconfig  | 2 +-
 configs/socfpga_stratix10_atf_defconfig   | 2 +-
 configs/taurus_defconfig  | 2 +-
 include/image.h   | 2 +-
 18 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index d94b9892175..0329d93b29e 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -204,7 +204,7 @@ config SPL_LEGACY_IMAGE_SUPPORT
 config SPL_LEGACY_IMAGE_CRC_CHECK
bool "Check CRC of Legacy images"
depends on SPL_LEGACY_IMAGE_SUPPORT
-   select SPL_CRC32_SUPPORT
+   select SPL_CRC32
help
  Enable this to check the CRC of Legacy images. While this increases
  reliability, it affects both code size and boot duration.
@@ -407,7 +407,7 @@ config SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION
  the eMMC EXT_CSC_PART_CONFIG selection should be overridden in SPL
  by user defined partition number.
 
-config SPL_CRC32_SUPPORT
+config SPL_CRC32
bool "Support CRC32"
default y if SPL_LEGACY_IMAGE_SUPPORT
help
diff --git a/configs/axm_defconfig b/configs/axm_defconfig
index 0bfd7548b09..4e776fd6953 100644
--- a/configs/axm_defconfig
+++ b/configs/axm_defconfig
@@ -32,7 +32,7 @@ CONFIG_BOOTCOMMAND="run flash_self"
 CONFIG_BOARD_EARLY_INIT_F=y
 # CONFIG_SPL_LEGACY_IMAGE_SUPPORT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
-CONFIG_SPL_CRC32_SUPPORT=y
+CONFIG_SPL_CRC32=y
 CONFIG_SPL_NAND_SUPPORT=y
 CONFIG_SPL_NAND_DRIVERS=y
 CONFIG_SPL_NAND_ECC=y
diff --git a/configs/chromebit_mickey_defconfig 
b/configs/chromebit_mickey_defconfig
index c09b63b9462..2b664e118cf 100644
--- a/configs/chromebit_mickey_defconfig
+++ b/configs/chromebit_mickey_defconfig
@@ -25,7 +25,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 # CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR is not set
-# CONFIG_SPL_CRC32_SUPPORT is not set
+# CONFIG_SPL_CRC32 is not set
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
diff --git a/configs/chromebook_jerry_defconfig 
b/configs/chromebook_jerry_defconfig
index 692b630174d..a757d259f58 100644
--- a/configs/chromebook_jerry_defconfig
+++ b/configs/chromebook_jerry_defconfig
@@ -26,7 +26,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 # CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR is not set
-# CONFIG_SPL_CRC32_SUPPORT is not set
+# CONFIG_SPL_CRC32 is not set
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
diff --git a/configs/chromebook_minnie_defconfig 
b/configs/chromebook_minnie_defconfig
index ae55842e3bf..353aa01ea9e 100644
--- a/configs/chromebook_minnie_defconfig
+++ b/configs/chromebook_minnie_defconfig
@@ -26,7 +26,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 # CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR is not set
-# CONFIG_SPL_CRC32_SUPPORT is not set
+# CONFIG_SPL_CRC32 is not set
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
diff --git a/configs/chromebook_speedy_defconfig 
b/configs/chromebook_speedy_defconfig
index 4b460ee6a9e..c5be5597b10 100644
--- a/configs/chromebook_speedy_defconfig
+++ b/configs/chromebook_speedy_defconfig
@@ -26,7 +26,7 @@ CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 # CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR is not set
-# CONFIG_SPL_CRC32_SUPPORT is not set
+# CONFIG_SPL_CRC32 is not set
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
diff --git a/configs/evb-px30_defconfig b/configs/evb-px30_defconfig
index d2fdfef2938..55e2702a172 100644
--- a/configs/evb-px30_defconfig
+++ b/configs/evb-px30_defconfig
@@ -29,7 +29,7 @@ CONFIG_SPL_BOOTROM_SUPPORT=y
 # CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
 CONFIG_SPL_STACK_R=y
 # CONFIG_TPL_BANNER_PRINT is not set
-CONFIG_SPL_CRC32_SUPPORT=y
+CONFIG_SPL_CRC32=y
 CONFIG_SPL_ATF=y
 # CONFIG_TPL_FRAMEWORK is not set
 # CONFIG_CMD_BOOTD is not set
diff --git a/configs/firefly-px30_defconfig b/configs/firefly-px30_defconfig
index 6487615fe08..978a3604053 100644
--- 

[PATCH 27/49] image: Drop IMAGE_ENABLE_CRC32

2021-05-03 Thread Simon Glass
Add a host Kconfig for CRC32. With this we can use CONFIG_IS_ENABLED(CRC32)
directly in the host build, so drop the unnecessary indirection.

Add a few more conditions to SPL_CRC32 to avoid build failures as well as
TPL_CRC32. Also update hash.c to make crc32 optional.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/hash.c  | 13 -
 common/image-fit.c |  2 +-
 common/spl/Kconfig | 13 -
 include/image.h|  8 
 lib/Kconfig|  5 +
 lib/Makefile   |  4 +---
 tools/Kconfig  |  5 +
 7 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/common/hash.c b/common/hash.c
index 1ccc62f162d..67e81e6150d 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -178,7 +178,7 @@ static int hash_finish_crc16_ccitt(struct hash_algo *algo, 
void *ctx,
return 0;
 }
 
-static int hash_init_crc32(struct hash_algo *algo, void **ctxp)
+static int __maybe_unused hash_init_crc32(struct hash_algo *algo, void **ctxp)
 {
uint32_t *ctx = malloc(sizeof(uint32_t));
*ctx = 0;
@@ -186,15 +186,16 @@ static int hash_init_crc32(struct hash_algo *algo, void 
**ctxp)
return 0;
 }
 
-static int hash_update_crc32(struct hash_algo *algo, void *ctx,
-const void *buf, unsigned int size, int is_last)
+static int __maybe_unused hash_update_crc32(struct hash_algo *algo, void *ctx,
+   const void *buf, unsigned int size,
+   int is_last)
 {
*((uint32_t *)ctx) = crc32(*((uint32_t *)ctx), buf, size);
return 0;
 }
 
-static int hash_finish_crc32(struct hash_algo *algo, void *ctx, void *dest_buf,
-int size)
+static int __maybe_unused hash_finish_crc32(struct hash_algo *algo, void *ctx,
+   void *dest_buf, int size)
 {
if (size < algo->digest_size)
return -1;
@@ -303,6 +304,7 @@ static struct hash_algo hash_algo[] = {
.hash_update= hash_update_crc16_ccitt,
.hash_finish= hash_finish_crc16_ccitt,
},
+#if CONFIG_IS_ENABLED(CRC32)
{
.name   = "crc32",
.digest_size= 4,
@@ -312,6 +314,7 @@ static struct hash_algo hash_algo[] = {
.hash_update= hash_update_crc32,
.hash_finish= hash_finish_crc32,
},
+#endif
 };
 
 /* Try to minimize code size for boards that don't want much hashing */
diff --git a/common/image-fit.c b/common/image-fit.c
index a16e2dd54a5..1ce46a5c72d 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1213,7 +1213,7 @@ int fit_set_timestamp(void *fit, int noffset, time_t 
timestamp)
 int calculate_hash(const void *data, int data_len, const char *algo,
uint8_t *value, int *value_len)
 {
-   if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) {
+   if (CONFIG_IS_ENABLED(CRC32) && strcmp(algo, "crc32") == 0) {
*((uint32_t *)value) = crc32_wd(0, data, data_len,
CHUNKSZ_CRC32);
*((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value));
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 0329d93b29e..636a7319274 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -409,7 +409,8 @@ config SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION
 
 config SPL_CRC32
bool "Support CRC32"
-   default y if SPL_LEGACY_IMAGE_SUPPORT
+   default y if SPL_LEGACY_IMAGE_SUPPORT || SPL_EFI_PARTITION
+   default y if SPL_ENV_SUPPORT || TPL_BLOBLIST
help
  Enable this to support CRC32 in uImages or FIT images within SPL.
  This is a 32-bit checksum value that can be used to verify images.
@@ -1467,6 +1468,16 @@ config TPL_BOOTROM_SUPPORT
  BOOT_DEVICE_BOOTROM (or fall-through to the next boot device in the
  boot device list, if not implemented for a given board)
 
+config TPL_CRC32
+   bool "Support CRC32 in TPL"
+   default y if TPL_ENV_SUPPORT || TPL_BLOBLIST
+   help
+ Enable this to support CRC32 in uImages or FIT images within SPL.
+ This is a 32-bit checksum value that can be used to verify images.
+ For FIT images, this is the least secure type of checksum, suitable
+ for detected accidental image corruption. For secure applications you
+ should consider SHA1 or SHA256.
+
 config TPL_DRIVERS_MISC_SUPPORT
bool "Support misc drivers in TPL"
help
diff --git a/include/image.h b/include/image.h
index 5aedc1bb23b..e68c2cbf621 100644
--- a/include/image.h
+++ b/include/image.h
@@ -47,9 +47,6 @@ struct fdt_region;
 #include 
 #include 
 # ifdef CONFIG_SPL_BUILD
-#  ifdef CONFIG_SPL_CRC32
-#   define IMAGE_ENABLE_CRC32  1
-#  endif
 #  ifdef CONFIG_SPL_MD5_SUPPORT
 #   define IMAGE_ENABLE_MD51
 #  endif
@@ -57,15 +54,10 @@ struct fdt_region;
 #   

[PATCH 11/49] image: Split host code out into its own file

2021-05-03 Thread Simon Glass
To avoid having #ifdefs in a few functions which are completely different
in the board and host code, create a new image-host.c file.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-board.c | 17 +
 common/image-host.c  | 27 +++
 common/image.c   | 38 +-
 tools/Makefile   |  1 +
 4 files changed, 46 insertions(+), 37 deletions(-)
 create mode 100644 common/image-host.c

diff --git a/common/image-board.c b/common/image-board.c
index 5d3eafb5245..b46062c86b9 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -925,3 +926,19 @@ int image_setup_linux(bootm_headers_t *images)
return 0;
 }
 #endif /* CONFIG_LMB */
+
+void genimg_print_size(uint32_t size)
+{
+   printf("%d Bytes = ", size);
+   print_size(size, "\n");
+}
+
+void genimg_print_time(time_t timestamp)
+{
+   struct rtc_time tm;
+
+   rtc_to_tm(timestamp, );
+   printf("%4d-%02d-%02d  %2d:%02d:%02d UTC\n",
+  tm.tm_year, tm.tm_mon, tm.tm_mday,
+  tm.tm_hour, tm.tm_min, tm.tm_sec);
+}
diff --git a/common/image-host.c b/common/image-host.c
new file mode 100644
index 000..20a9521948b
--- /dev/null
+++ b/common/image-host.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Image code used by host tools (and not boards)
+ *
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2006
+ * Wolfgang Denk, DENX Software Engineering, w...@denx.de.
+ */
+
+#include 
+
+void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
+{
+   memmove(to, from, len);
+}
+
+void genimg_print_size(uint32_t size)
+{
+   printf("%d Bytes = %.2f KiB = %.2f MiB\n", size, (double)size / 1.024e3,
+  (double)size / 1.048576e6);
+}
+
+void genimg_print_time(time_t timestamp)
+{
+   printf("%s", ctime());
+}
diff --git a/common/image.c b/common/image.c
index e9658e3ab1b..0ef8f30fcfa 100644
--- a/common/image.c
+++ b/common/image.c
@@ -18,8 +18,6 @@
 #include 
 #endif
 
-#include 
-
 #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT
 #include 
 #include 
@@ -60,6 +58,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -526,41 +525,6 @@ int image_decomp(int comp, ulong load, ulong image_start, 
int type,
return 0;
 }
 
-#ifdef USE_HOSTCC
-void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
-{
-   memmove(to, from, len);
-}
-#endif /* !USE_HOSTCC */
-
-void genimg_print_size(uint32_t size)
-{
-#ifndef USE_HOSTCC
-   printf("%d Bytes = ", size);
-   print_size(size, "\n");
-#else
-   printf("%d Bytes = %.2f KiB = %.2f MiB\n",
-   size, (double)size / 1.024e3,
-   (double)size / 1.048576e6);
-#endif
-}
-
-#if IMAGE_ENABLE_TIMESTAMP
-void genimg_print_time(time_t timestamp)
-{
-#ifndef USE_HOSTCC
-   struct rtc_time tm;
-
-   rtc_to_tm(timestamp, );
-   printf("%4d-%02d-%02d  %2d:%02d:%02d UTC\n",
-   tm.tm_year, tm.tm_mon, tm.tm_mday,
-   tm.tm_hour, tm.tm_min, tm.tm_sec);
-#else
-   printf("%s", ctime());
-#endif
-}
-#endif
-
 const table_entry_t *get_table_entry(const table_entry_t *table, int id)
 {
for (; table->id >= 0; ++table) {
diff --git a/tools/Makefile b/tools/Makefile
index d020c55d664..2b4bc547abd 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -94,6 +94,7 @@ dumpimage-mkimage-objs := aisimage.o \
lib/fdtdec_common.o \
lib/fdtdec.o \
common/image.o \
+   common/image-host.o \
imagetool.o \
imximage.o \
imx8image.o \
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 17/49] image: Shorten FIT_ENABLE_SHAxxx_SUPPORT

2021-05-03 Thread Simon Glass
The ENABLE part of this name is redundant, since all boolean Kconfig
options serve to enable something. The SUPPORT part is also redundant
since Kconfigs can be assumed to enable support for something. Together
they just serve to make these options overly long and inconsistent
with other options.

Rename FIT_ENABLE_SHAxxx_SUPPORT to FIT_SHAxxx

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/Kconfig.boot  |  6 +++---
 configs/mt8516_pumpkin_defconfig |  2 +-
 include/image.h  | 12 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/common/Kconfig.boot b/common/Kconfig.boot
index 5a18d62d780..af3325a7ce2 100644
--- a/common/Kconfig.boot
+++ b/common/Kconfig.boot
@@ -35,7 +35,7 @@ config FIT_EXTERNAL_OFFSET
  could be put in the hole between data payload and fit image
  header, such as CSF data on i.MX platform.
 
-config FIT_ENABLE_SHA256_SUPPORT
+config FIT_SHA256
bool "Support SHA256 checksum of FIT image contents"
default y
select SHA256
@@ -44,7 +44,7 @@ config FIT_ENABLE_SHA256_SUPPORT
  SHA256 checksum is a 256-bit (32-byte) hash value used to check that
  the image contents have not been corrupted.
 
-config FIT_ENABLE_SHA384_SUPPORT
+config FIT_SHA384
bool "Support SHA384 checksum of FIT image contents"
default n
select SHA384
@@ -54,7 +54,7 @@ config FIT_ENABLE_SHA384_SUPPORT
  the image contents have not been corrupted. Use this for the highest
  security.
 
-config FIT_ENABLE_SHA512_SUPPORT
+config FIT_SHA512
bool "Support SHA512 checksum of FIT image contents"
default n
select SHA512
diff --git a/configs/mt8516_pumpkin_defconfig b/configs/mt8516_pumpkin_defconfig
index 5270ec28cbd..d330c03db3c 100644
--- a/configs/mt8516_pumpkin_defconfig
+++ b/configs/mt8516_pumpkin_defconfig
@@ -13,7 +13,7 @@ CONFIG_DEBUG_UART_CLOCK=2600
 CONFIG_DEFAULT_DEVICE_TREE="mt8516-pumpkin"
 CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
-# CONFIG_FIT_ENABLE_SHA256_SUPPORT is not set
+# CONFIG_FIT_SHA256 is not set
 # CONFIG_ARCH_FIXUP_FDT_MEMORY is not set
 CONFIG_DEFAULT_FDT_FILE="mt8516-pumpkin"
 # CONFIG_DISPLAY_BOARDINFO is not set
diff --git a/include/image.h b/include/image.h
index 459685d4d43..9319a779b93 100644
--- a/include/image.h
+++ b/include/image.h
@@ -31,9 +31,9 @@ struct fdt_region;
 #define IMAGE_ENABLE_OF_LIBFDT 1
 #define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */
 #define CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT 1
-#define CONFIG_FIT_ENABLE_SHA256_SUPPORT
-#define CONFIG_FIT_ENABLE_SHA384_SUPPORT
-#define CONFIG_FIT_ENABLE_SHA512_SUPPORT
+#define CONFIG_FIT_SHA256
+#define CONFIG_FIT_SHA384
+#define CONFIG_FIT_SHA512
 #define CONFIG_SHA1
 #define CONFIG_SHA256
 #define CONFIG_SHA384
@@ -89,21 +89,21 @@ struct fdt_region;
 #define IMAGE_ENABLE_SHA1  0
 #endif
 
-#if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \
+#if defined(CONFIG_FIT_SHA256) || \
defined(CONFIG_SPL_SHA256_SUPPORT)
 #define IMAGE_ENABLE_SHA2561
 #else
 #define IMAGE_ENABLE_SHA2560
 #endif
 
-#if defined(CONFIG_FIT_ENABLE_SHA384_SUPPORT) || \
+#if defined(CONFIG_FIT_SHA384) || \
defined(CONFIG_SPL_SHA384_SUPPORT)
 #define IMAGE_ENABLE_SHA3841
 #else
 #define IMAGE_ENABLE_SHA3840
 #endif
 
-#if defined(CONFIG_FIT_ENABLE_SHA512_SUPPORT) || \
+#if defined(CONFIG_FIT_SHA512) || \
defined(CONFIG_SPL_SHA512_SUPPORT)
 #define IMAGE_ENABLE_SHA5121
 #else
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 09/49] image: Split board code out into its own file

2021-05-03 Thread Simon Glass
To avoid a large #ifdef in the image.c file, move the affected code into
a separate file.

Avoid any style fix-ups for easier review. Those are in the next patch.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/Makefile  |   2 +-
 common/image-board.c | 925 +++
 common/image.c   | 925 +--
 3 files changed, 928 insertions(+), 924 deletions(-)
 create mode 100644 common/image-board.c

diff --git a/common/Makefile b/common/Makefile
index 829ea5fb426..b71b0496022 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -104,7 +104,7 @@ obj-y += malloc_simple.o
 endif
 endif
 
-obj-y += image.o
+obj-y += image.o image-board.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
diff --git a/common/image-board.c b/common/image-board.c
new file mode 100644
index 000..0c4e32e14e4
--- /dev/null
+++ b/common/image-board.c
@@ -0,0 +1,925 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Image code used by boards (and not host tools)
+ *
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2006
+ * Wolfgang Denk, DENX Software Engineering, w...@denx.de.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifndef CONFIG_SYS_BARGSIZE
+#define CONFIG_SYS_BARGSIZE 512
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
+/**
+ * image_get_ramdisk - get and verify ramdisk image
+ * @rd_addr: ramdisk image start address
+ * @arch: expected ramdisk architecture
+ * @verify: checksum verification flag
+ *
+ * image_get_ramdisk() returns a pointer to the verified ramdisk image
+ * header. Routine receives image start address and expected architecture
+ * flag. Verification done covers data and header integrity and os/type/arch
+ * fields checking.
+ *
+ * returns:
+ * pointer to a ramdisk image header, if image was found and valid
+ * otherwise, return NULL
+ */
+static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
+   int verify)
+{
+   const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
+
+   if (!image_check_magic(rd_hdr)) {
+   puts("Bad Magic Number\n");
+   bootstage_error(BOOTSTAGE_ID_RD_MAGIC);
+   return NULL;
+   }
+
+   if (!image_check_hcrc(rd_hdr)) {
+   puts("Bad Header Checksum\n");
+   bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
+   return NULL;
+   }
+
+   bootstage_mark(BOOTSTAGE_ID_RD_MAGIC);
+   image_print_contents(rd_hdr);
+
+   if (verify) {
+   puts("   Verifying Checksum ... ");
+   if (!image_check_dcrc(rd_hdr)) {
+   puts("Bad Data CRC\n");
+   bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM);
+   return NULL;
+   }
+   puts("OK\n");
+   }
+
+   bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
+
+   if (!image_check_os(rd_hdr, IH_OS_LINUX) ||
+   !image_check_arch(rd_hdr, arch) ||
+   !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) {
+   printf("No Linux %s Ramdisk Image\n",
+   genimg_get_arch_name(arch));
+   bootstage_error(BOOTSTAGE_ID_RAMDISK);
+   return NULL;
+   }
+
+   return rd_hdr;
+}
+#endif
+
+/*/
+/* Shared dual-format routines */
+/*/
+ulong image_load_addr = CONFIG_SYS_LOAD_ADDR;  /* Default Load Address */
+ulong image_save_addr; /* Default Save Address */
+ulong image_save_size; /* Default Save Size (in bytes) */
+
+static int on_loadaddr(const char *name, const char *value, enum env_op op,
+   int flags)
+{
+   switch (op) {
+   case env_op_create:
+   case env_op_overwrite:
+   image_load_addr = simple_strtoul(value, NULL, 16);
+   break;
+   default:
+   break;
+   }
+
+   return 0;
+}
+U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);
+
+ulong env_get_bootm_low(void)
+{
+   char *s = env_get("bootm_low");
+   if (s) {
+   ulong tmp = simple_strtoul(s, NULL, 16);
+   return tmp;
+   }
+
+#if defined(CONFIG_SYS_SDRAM_BASE)
+   return CONFIG_SYS_SDRAM_BASE;
+#elif defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)
+   return gd->bd->bi_dram[0].start;
+#else
+   return 0;
+#endif
+}
+
+phys_size_t env_get_bootm_size(void)
+{
+   phys_size_t tmp, size;
+   phys_addr_t start;
+   char *s = env_get("bootm_size");
+   if (s) {
+   tmp = (phys_size_t)simple_strtoull(s, NULL, 

[PATCH 39/49] image: Tidy up fit_unsupported_reset()

2021-05-03 Thread Simon Glass
This function is only used in one place and does not need to use the
preprocessor. Move it to the C file and convert it to a normal function.

Drop fit_unsupported() since it is not used.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/bootm_os.c |  8 
 include/image.h   | 13 -
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/common/bootm_os.c b/common/bootm_os.c
index 0b6325db660..70fad4efb55 100644
--- a/common/bootm_os.c
+++ b/common/bootm_os.c
@@ -58,6 +58,14 @@ static void copy_args(char *dest, int argc, char *const 
argv[], char delim)
 }
 #endif
 
+static void __maybe_unused fit_unsupported_reset(const char *msg)
+{
+   if (CONFIG_IS_ENABLED(FIT_VERBOSE)) {
+   printf("! FIT images not supported for '%s' - must reset board 
to recover!\n",
+  msg);
+   }
+}
+
 #ifdef CONFIG_BOOTM_NETBSD
 static int do_bootm_netbsd(int flag, int argc, char *const argv[],
   bootm_headers_t *images)
diff --git a/include/image.h b/include/image.h
index 9adbda8ab70..d7e0c829841 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1412,19 +1412,6 @@ int fit_image_cipher_get_algo(const void *fit, int 
noffset, char **algo);
 
 struct cipher_algo *image_get_cipher_algo(const char *full_name);
 
-#if CONFIG_IS_ENABLED(FIT_VERBOSE)
-#define fit_unsupported(msg)   printf("! %s:%d " \
-   "FIT images not supported for '%s'\n", \
-   __FILE__, __LINE__, (msg))
-
-#define fit_unsupported_reset(msg) printf("! %s:%d " \
-   "FIT images not supported for '%s' " \
-   "- must reset board to recover!\n", \
-   __FILE__, __LINE__, (msg))
-#else
-#define fit_unsupported(msg)
-#define fit_unsupported_reset(msg)
-#endif /* FIT_VERBOSE */
 #endif /* CONFIG_FIT */
 
 #if !defined(USE_HOSTCC)
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 41/49] image: Drop #ifdefs for fit_print_contents()

2021-05-03 Thread Simon Glass
Use a simple return to drop the unwanted code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fit.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 3ee306143b3..f8aa61fc99d 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -165,7 +165,6 @@ int fit_get_subimage_count(const void *fit, int 
images_noffset)
return count;
 }
 
-#if CONFIG_IS_ENABLED(FIT_PRINT)
 /**
  * fit_image_print_data() - prints out the hash node details
  * @fit: pointer to the FIT format image header
@@ -375,6 +374,9 @@ void fit_print_contents(const void *fit)
const char *p;
time_t timestamp;
 
+   if (!CONFIG_IS_ENABLED(FIT_PRINT))
+   return;
+
/* Indent string is defined in header image.h */
p = IMAGE_INDENT_STRING;
 
@@ -477,6 +479,9 @@ void fit_image_print(const void *fit, int image_noffset, 
const char *p)
int ndepth;
int ret;
 
+   if (!CONFIG_IS_ENABLED(FIT_PRINT))
+   return;
+
/* Mandatory properties */
ret = fit_get_desc(fit, image_noffset, );
printf("%s  Description:  ", p);
@@ -570,10 +575,6 @@ void fit_image_print(const void *fit, int image_noffset, 
const char *p)
}
}
 }
-#else
-void fit_print_contents(const void *fit) { }
-void fit_image_print(const void *fit, int image_noffset, const char *p) { }
-#endif /* CONFIG_IS_ENABLED(FIT_PRINT) */
 
 /**
  * fit_get_desc - get node description property
-- 
2.31.1.527.g47e6f16901-goog



Re: [PATCH 04/49] btrfs: Use U-Boot API for decompression

2021-05-03 Thread Qu Wenruo




On 2021/5/4 上午7:10, Simon Glass wrote:

Use the common function to avoid code duplication.

Signed-off-by: Simon Glass 


Acked-by: Qu Wenruo 

Thanks,
Qu

---

(no changes since v1)

  fs/btrfs/compression.c | 51 +-
  1 file changed, 5 insertions(+), 46 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 23efefa1997..7adfbb04a7c 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -6,6 +6,7 @@
   */

  #include "btrfs.h"
+#include 
  #include 
  #include 
  #include 
@@ -136,54 +137,12 @@ static u32 decompress_zlib(const u8 *_cbuf, u32 clen, u8 
*dbuf, u32 dlen)

  static u32 decompress_zstd(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
  {
-   ZSTD_DStream *dstream;
-   ZSTD_inBuffer in_buf;
-   ZSTD_outBuffer out_buf;
-   void *workspace;
-   size_t wsize;
-   u32 res = -1;
-
-   wsize = ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT);
-   workspace = malloc(wsize);
-   if (!workspace) {
-   debug("%s: cannot allocate workspace of size %zu\n", __func__,
- wsize);
-   return -1;
-   }
-
-   dstream = ZSTD_initDStream(ZSTD_BTRFS_MAX_INPUT, workspace, wsize);
-   if (!dstream) {
-   printf("%s: ZSTD_initDStream failed\n", __func__);
-   goto err_free;
-   }
+   struct abuf in, out;

-   in_buf.src = cbuf;
-   in_buf.pos = 0;
-   in_buf.size = clen;
+   abuf_init_set(, (u8 *)cbuf, clen);
+   abuf_init_set(, dbuf, dlen);

-   out_buf.dst = dbuf;
-   out_buf.pos = 0;
-   out_buf.size = dlen;
-
-   while (1) {
-   size_t ret;
-
-   ret = ZSTD_decompressStream(dstream, _buf, _buf);
-   if (ZSTD_isError(ret)) {
-   printf("%s: ZSTD_decompressStream error %d\n", __func__,
-  ZSTD_getErrorCode(ret));
-   goto err_free;
-   }
-
-   if (in_buf.pos >= clen || !ret)
-   break;
-   }
-
-   res = out_buf.pos;
-
-err_free:
-   free(workspace);
-   return res;
+   return zstd_decompress(, );
  }

  u32 btrfs_decompress(u8 type, const char *c, u32 clen, char *d, u32 dlen)



[PATCH 32/49] image: Drop IMAGE_BOOT_GET_CMDLINE

2021-05-03 Thread Simon Glass
This is not needed with Kconfig, since we can use IS_ENABLED() easily
enough. Update the only place where this is used and drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-board.c | 2 +-
 include/image.h  | 6 --
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/common/image-board.c b/common/image-board.c
index 0b9809c3f6b..1a3b0bc7efc 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -898,7 +898,7 @@ int image_setup_linux(bootm_headers_t *images)
if (CONFIG_IS_ENABLED(OF_LIBFDT))
boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
 
-   if (IMAGE_BOOT_GET_CMDLINE) {
+   if (IS_ENABLED(CONFIG_SYS_BOOT_GET_CMDLINE)) {
ret = boot_get_cmdline(lmb, >cmdline_start,
   >cmdline_end);
if (ret) {
diff --git a/include/image.h b/include/image.h
index f4b8dd7dd0f..122fc25e1b4 100644
--- a/include/image.h
+++ b/include/image.h
@@ -49,12 +49,6 @@ struct fdt_region;
 
 #endif /* FIT */
 
-#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
-# define IMAGE_BOOT_GET_CMDLINE1
-#else
-# define IMAGE_BOOT_GET_CMDLINE0
-#endif
-
 #ifdef CONFIG_OF_BOARD_SETUP
 # define IMAGE_OF_BOARD_SETUP  1
 #else
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 49/49] image: Remove #ifdefs from select_fdt()

2021-05-03 Thread Simon Glass
Use boolean variables to deal with the strange #ifdef logic of this
function, so we can remove the #ifdefs. Also drop one from its caller,
boot_get_fdt()

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fdt.c | 201 ++---
 1 file changed, 100 insertions(+), 101 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index c17c23e1295..8afd6ed94a6 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -39,7 +39,6 @@ static void fdt_error(const char *msg)
puts(" - must RESET the board to recover.\n");
 }
 
-#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
 static const image_header_t *image_get_fdt(ulong fdt_addr)
 {
const image_header_t *fdt_hdr = map_sysmem(fdt_addr, 0);
@@ -72,7 +71,6 @@ static const image_header_t *image_get_fdt(ulong fdt_addr)
}
return fdt_hdr;
 }
-#endif
 
 static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr,
uint64_t size)
@@ -258,46 +256,49 @@ error:
 static int select_fdt(bootm_headers_t *images, const char *select, u8 arch,
  ulong *fdt_addrp)
 {
-   const char *buf;
-   ulong fdt_addr;
-
-#if CONFIG_IS_ENABLED(FIT)
const char *fit_uname_config = images->fit_uname_cfg;
const char *fit_uname_fdt = NULL;
-   ulong default_addr;
int fdt_noffset;
+   const char *buf;
+   bool processed;
+   ulong fdt_addr = 0;
 
if (select) {
-   /*
-* If the FDT blob comes from the FIT image and the
-* FIT image address is omitted in the command line
-* argument, try to use ramdisk or os FIT image
-* address or default load address.
-*/
-   if (images->fit_uname_rd)
-   default_addr = (ulong)images->fit_hdr_rd;
-   else if (images->fit_uname_os)
-   default_addr = (ulong)images->fit_hdr_os;
-   else
-   default_addr = image_load_addr;
-
-   if (fit_parse_conf(select, default_addr, _addr,
-  _uname_config)) {
-   debug("*  fdt: config '%s' from image at 0x%08lx\n",
- fit_uname_config, fdt_addr);
-   } else if (fit_parse_subimage(select, default_addr, _addr,
-  _uname_fdt)) {
-   debug("*  fdt: subimage '%s' from image at 0x%08lx\n",
- fit_uname_fdt, fdt_addr);
-   } else
-#endif
-   {
+   ulong default_addr;
+   bool done = true;
+
+   if (CONFIG_IS_ENABLED(FIT)) {
+   /*
+* If the FDT blob comes from the FIT image and the
+* FIT image address is omitted in the command line
+* argument, try to use ramdisk or os FIT image
+* address or default load address.
+*/
+   if (images->fit_uname_rd)
+   default_addr = (ulong)images->fit_hdr_rd;
+   else if (images->fit_uname_os)
+   default_addr = (ulong)images->fit_hdr_os;
+   else
+   default_addr = image_load_addr;
+
+   if (fit_parse_conf(select, default_addr, _addr,
+  _uname_config)) {
+   debug("*  fdt: config '%s' from image at 
0x%08lx\n",
+ fit_uname_config, fdt_addr);
+   } else if (fit_parse_subimage(select, default_addr, 
_addr,
+  _uname_fdt)) {
+   debug("*  fdt: subimage '%s' from image at 
0x%08lx\n",
+ fit_uname_fdt, fdt_addr);
+   } else {
+   done = false;
+   }
+   }
+   if (!done) {
fdt_addr = simple_strtoul(select, NULL, 16);
debug("*  fdt: cmdline image address = 0x%08lx\n",
  fdt_addr);
}
-#if CONFIG_IS_ENABLED(FIT)
-   } else {
+   } else if (CONFIG_IS_ENABLED(FIT)) {
/* use FIT configuration provided in first bootm
 * command argument
 */
@@ -309,7 +310,6 @@ static int select_fdt(bootm_headers_t *images, const char 
*select, u8 arch,
else if (fdt_noffset < 0)
return fdt_noffset;
}
-#endif
debug("## Checking for 'FDT'/'FDT Image' at %08lx\n",
  fdt_addr);
 
@@ -319,90 +319,90 @@ static int select_fdt(bootm_headers_t *images, const char 
*select, u8 arch,
 * check image 

[PATCH 30/49] image: Drop IMAGE_ENABLE_SHA1

2021-05-03 Thread Simon Glass
We already have a host Kconfig for SHA1. Use CONFIG_IS_ENABLED(SHA1)
directly in the code shared with the host build, so we can drop the
unnecessary indirection.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fit.c |  2 +-
 include/image.h| 11 ---
 2 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 19a2d3c91df..96794074b63 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1218,7 +1218,7 @@ int calculate_hash(const void *data, int data_len, const 
char *algo,
CHUNKSZ_CRC32);
*((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value));
*value_len = 4;
-   } else if (IMAGE_ENABLE_SHA1 && strcmp(algo, "sha1") == 0) {
+   } else if (CONFIG_IS_ENABLED(SHA1) && strcmp(algo, "sha1") == 0) {
sha1_csum_wd((unsigned char *)data, data_len,
 (unsigned char *)value, CHUNKSZ_SHA1);
*value_len = 20;
diff --git a/include/image.h b/include/image.h
index 9f665a597b0..f5ff77bf0ca 100644
--- a/include/image.h
+++ b/include/image.h
@@ -46,17 +46,6 @@ struct fdt_region;
 #include 
 #include 
 #include 
-# ifdef CONFIG_SPL_BUILD
-#  ifdef CONFIG_SPL_FIT_SHA1
-#   define IMAGE_ENABLE_SHA1   1
-#  endif
-# else
-#  define IMAGE_ENABLE_SHA11
-# endif
-
-#ifndef IMAGE_ENABLE_SHA1
-#define IMAGE_ENABLE_SHA1  0
-#endif
 
 #if defined(CONFIG_FIT_SHA256) || \
defined(CONFIG_SPL_FIT_SHA256)
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 37/49] image: Drop IMAGE_ENABLE_BEST_MATCH

2021-05-03 Thread Simon Glass
This is not needed with Kconfig, since we can use IS_ENABLED() easily
enough. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fit.c | 2 +-
 include/image.h| 5 -
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index e81a0858dc1..a0987fd52c8 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -2026,7 +2026,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
 * fit_conf_get_node() will try to find default config node
 */
bootstage_mark(bootstage_id + BOOTSTAGE_SUB_NO_UNIT_NAME);
-   if (IMAGE_ENABLE_BEST_MATCH && !fit_uname_config) {
+   if (IS_ENABLED(CONFIG_FIT_BEST_MATCH) && !fit_uname_config) {
cfg_noffset = fit_conf_find_compat(fit, gd_fdt_blob());
} else {
cfg_noffset = fit_conf_get_node(fit,
diff --git a/include/image.h b/include/image.h
index 12043abd049..b388684cbdc 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1157,11 +1157,6 @@ void image_set_host_blob(void *host_blob);
 # define gd_fdt_blob() (gd->fdt_blob)
 #endif
 
-#ifdef CONFIG_FIT_BEST_MATCH
-#define IMAGE_ENABLE_BEST_MATCH1
-#else
-#define IMAGE_ENABLE_BEST_MATCH0
-#endif
 #endif /* FIT */
 
 /*
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 46/49] image: Remove some #ifdefs from image-fit and image-fit-sig

2021-05-03 Thread Simon Glass
Drop the #ifdefs which are easy to remove without refactoring.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/Kconfig.boot| 10 ++
 common/image-fit-sig.c |  8 ++--
 common/image-fit.c |  7 ---
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/common/Kconfig.boot b/common/Kconfig.boot
index 03a6e6f214f..a31d9847124 100644
--- a/common/Kconfig.boot
+++ b/common/Kconfig.boot
@@ -191,6 +191,16 @@ config SPL_FIT_SIGNATURE
select SPL_IMAGE_SIGN_INFO
select SPL_FIT_FULL_CHECK
 
+config SPL_FIT_SIGNATURE_MAX_SIZE
+   hex "Max size of signed FIT structures in SPL"
+   depends on SPL_FIT_SIGNATURE
+   default 0x1000
+   help
+ This option sets a max size in bytes for verified FIT uImages.
+ A sane value of 256MB protects corrupted DTB structures from 
overlapping
+ device memory. Assure this size does not extend past expected storage
+ space.
+
 config SPL_LOAD_FIT
bool "Enable SPL loading U-Boot as a FIT (basic fitImage features)"
select SPL_FIT
diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
index 12a6745c642..22f89861048 100644
--- a/common/image-fit-sig.c
+++ b/common/image-fit-sig.c
@@ -49,10 +49,8 @@ struct image_region *fit_region_make_list(const void *fit,
 * Use malloc() except in SPL (to save code size). In SPL the caller
 * must allocate the array.
 */
-#ifndef CONFIG_SPL_BUILD
-   if (!region)
+   if (!IS_ENABLED(CONFIG_SPL_BUILD) && !region)
region = calloc(sizeof(*region), count);
-#endif
if (!region)
return NULL;
for (i = 0; i < count; i++) {
@@ -72,12 +70,10 @@ static int fit_image_setup_verify(struct image_sign_info 
*info,
char *algo_name;
const char *padding_name;
 
-#ifndef USE_HOSTCC
-   if (fdt_totalsize(fit) > CONFIG_FIT_SIGNATURE_MAX_SIZE) {
+   if (fdt_totalsize(fit) > CONFIG_VAL(FIT_SIGNATURE_MAX_SIZE)) {
*err_msgp = "Total size too large";
return 1;
}
-#endif
if (fit_image_hash_get_algo(fit, noffset, _name)) {
*err_msgp = "Can't get hash algo property";
return -1;
diff --git a/common/image-fit.c b/common/image-fit.c
index f8aa61fc99d..882e872144f 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1993,9 +1993,6 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
int type_ok, os_ok;
ulong load, load_end, data, len;
uint8_t os, comp;
-#ifndef USE_HOSTCC
-   uint8_t os_arch;
-#endif
const char *prop_name;
int ret;
 
@@ -2087,8 +2084,12 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
}
 
 #ifndef USE_HOSTCC
+   {
+   uint8_t os_arch;
+
fit_image_get_arch(fit, noffset, _arch);
images->os.arch = os_arch;
+   }
 #endif
 
bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL);
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 25/49] image: Use Kconfig to enable FIT_RSASSA_PSS on host

2021-05-03 Thread Simon Glass
Add a host Kconfig for FIT_RSASSA_PSS. With this we can use
CONFIG_IS_ENABLED(FIT_RSASSA_PSS) directly in the host build, so drop the
forcing of this in the image.h header.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-sig.c   | 4 ++--
 include/image.h  | 3 ---
 include/u-boot/rsa.h | 8 
 lib/rsa/rsa-sign.c   | 4 ++--
 lib/rsa/rsa-verify.c | 4 ++--
 tools/Kconfig| 5 +
 6 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/common/image-sig.c b/common/image-sig.c
index 31a4fd46061..bbc6bb3b1e3 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -100,12 +100,12 @@ struct padding_algo padding_algos[] = {
.name = "pkcs-1.5",
.verify = padding_pkcs_15_verify,
},
-#ifdef CONFIG_FIT_RSASSA_PSS
+#if CONFIG_IS_ENABLED(FIT_RSASSA_PSS)
{
.name = "pss",
.verify = padding_pss_verify,
}
-#endif /* CONFIG_FIT_RSASSA_PSS */
+#endif /* FIT_RSASSA_PSS */
 };
 
 struct checksum_algo *image_get_checksum_algo(const char *full_name)
diff --git a/include/image.h b/include/image.h
index 0356d03b2ce..3bb12ee3821 100644
--- a/include/image.h
+++ b/include/image.h
@@ -27,9 +27,6 @@ struct fdt_region;
 #include 
 #include 
 
-/* new uImage format support enabled on host */
-#define CONFIG_FIT_RSASSA_PSS 1
-
 #define IMAGE_ENABLE_IGNORE0
 #define IMAGE_INDENT_STRING""
 
diff --git a/include/u-boot/rsa.h b/include/u-boot/rsa.h
index bc564d56fa3..45fe3509093 100644
--- a/include/u-boot/rsa.h
+++ b/include/u-boot/rsa.h
@@ -119,11 +119,11 @@ int padding_pkcs_15_verify(struct image_sign_info *info,
   uint8_t *msg, int msg_len,
   const uint8_t *hash, int hash_len);
 
-#ifdef CONFIG_FIT_RSASSA_PSS
+#if CONFIG_IS_ENABLED(FIT_RSASSA_PSS)
 int padding_pss_verify(struct image_sign_info *info,
   uint8_t *msg, int msg_len,
   const uint8_t *hash, int hash_len);
-#endif /* CONFIG_FIT_RSASSA_PSS */
+#endif /* FIT_RSASSA_PSS */
 #else
 static inline int rsa_verify_hash(struct image_sign_info *info,
  const uint8_t *hash,
@@ -146,14 +146,14 @@ static inline int padding_pkcs_15_verify(struct 
image_sign_info *info,
return -ENXIO;
 }
 
-#ifdef CONFIG_FIT_RSASSA_PSS
+#if CONFIG_IS_ENABLED(FIT_RSASSA_PSS)
 static inline int padding_pss_verify(struct image_sign_info *info,
 uint8_t *msg, int msg_len,
 const uint8_t *hash, int hash_len)
 {
return -ENXIO;
 }
-#endif /* CONFIG_FIT_RSASSA_PSS */
+#endif /* FIT_RSASSA_PSS */
 #endif
 
 #define RSA_DEFAULT_PADDING_NAME   "pkcs-1.5"
diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
index f4ed11e74a4..5ae77621fc6 100644
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
@@ -442,7 +442,7 @@ static int rsa_sign_with_key(EVP_PKEY *pkey, struct 
padding_algo *padding_algo,
goto err_sign;
}
 
-#ifdef CONFIG_FIT_RSASSA_PSS
+#if CONFIG_IS_ENABLED(FIT_RSASSA_PSS)
if (padding_algo && !strcmp(padding_algo->name, "pss")) {
if (EVP_PKEY_CTX_set_rsa_padding(ckey,
 RSA_PKCS1_PSS_PADDING) <= 0) {
@@ -450,7 +450,7 @@ static int rsa_sign_with_key(EVP_PKEY *pkey, struct 
padding_algo *padding_algo,
goto err_sign;
}
}
-#endif /* CONFIG_FIT_RSASSA_PSS */
+#endif /* FIT_RSASSA_PSS */
 
for (i = 0; i < region_count; i++) {
if (!EVP_DigestSignUpdate(context, region[i].data,
diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c
index 1998c773fc7..b1abfa8eacc 100644
--- a/lib/rsa/rsa-verify.c
+++ b/lib/rsa/rsa-verify.c
@@ -95,7 +95,7 @@ int padding_pkcs_15_verify(struct image_sign_info *info,
return 0;
 }
 
-#ifdef CONFIG_FIT_RSASSA_PSS
+#if CONFIG_IS_ENABLED(FIT_RSASSA_PSS)
 static void u32_i2osp(uint32_t val, uint8_t *buf)
 {
buf[0] = (uint8_t)((val >> 24) & 0xff);
@@ -296,7 +296,7 @@ out:
 
return ret;
 }
-#endif
+#endif /* FIT_RSASSA_PSS */
 
 #if CONFIG_IS_ENABLED(FIT_SIGNATURE) || CONFIG_IS_ENABLED(RSA_VERIFY_WITH_PKEY)
 /**
diff --git a/tools/Kconfig b/tools/Kconfig
index 6d0f4565a80..8bd782cf5b9 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -24,6 +24,11 @@ config HOST_FIT_PRINT
help
  Print the content of the FIT verbosely in the host build
 
+config HOST_FIT_RSASSA_PSS
+   def_bool y
+   help
+ Support the rsassa-pss signature scheme in the host build
+
 config HOST_FIT_SHA1
def_bool y
help
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 18/49] image: Rename SPL_SHAxxx_SUPPORT to SPL_FIT_SHAxxx

2021-05-03 Thread Simon Glass
These option are named inconsistently with other SPL options, thus making
them incompatible with the CONFIG_IS_ENABLED() macro. Rename them.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/spl/Kconfig | 8 
 include/image.h| 8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index df5468f1ac2..d94b9892175 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -429,7 +429,7 @@ config SPL_MD5_SUPPORT
  applications where images may be changed maliciously, you should
  consider SHA256 or SHA384.
 
-config SPL_SHA1_SUPPORT
+config SPL_FIT_SHA1
bool "Support SHA1"
depends on SPL_FIT
select SHA1
@@ -441,7 +441,7 @@ config SPL_SHA1_SUPPORT
  due to the expanding computing power available to brute-force
  attacks. For more security, consider SHA256 or SHA384.
 
-config SPL_SHA256_SUPPORT
+config SPL_FIT_SHA256
bool "Support SHA256"
depends on SPL_FIT
select SHA256
@@ -450,7 +450,7 @@ config SPL_SHA256_SUPPORT
  checksum is a 256-bit (32-byte) hash value used to check that the
  image contents have not been corrupted.
 
-config SPL_SHA384_SUPPORT
+config SPL_FIT_SHA384
bool "Support SHA384"
depends on SPL_FIT
select SHA384
@@ -461,7 +461,7 @@ config SPL_SHA384_SUPPORT
  image contents have not been corrupted. Use this for the highest
  security.
 
-config SPL_SHA512_SUPPORT
+config SPL_FIT_SHA512
bool "Support SHA512"
depends on SPL_FIT
select SHA512
diff --git a/include/image.h b/include/image.h
index 9319a779b93..3284f36c97a 100644
--- a/include/image.h
+++ b/include/image.h
@@ -68,7 +68,7 @@ struct fdt_region;
 #  ifdef CONFIG_SPL_MD5_SUPPORT
 #   define IMAGE_ENABLE_MD51
 #  endif
-#  ifdef CONFIG_SPL_SHA1_SUPPORT
+#  ifdef CONFIG_SPL_FIT_SHA1
 #   define IMAGE_ENABLE_SHA1   1
 #  endif
 # else
@@ -90,21 +90,21 @@ struct fdt_region;
 #endif
 
 #if defined(CONFIG_FIT_SHA256) || \
-   defined(CONFIG_SPL_SHA256_SUPPORT)
+   defined(CONFIG_SPL_FIT_SHA256)
 #define IMAGE_ENABLE_SHA2561
 #else
 #define IMAGE_ENABLE_SHA2560
 #endif
 
 #if defined(CONFIG_FIT_SHA384) || \
-   defined(CONFIG_SPL_SHA384_SUPPORT)
+   defined(CONFIG_SPL_FIT_SHA384)
 #define IMAGE_ENABLE_SHA3841
 #else
 #define IMAGE_ENABLE_SHA3840
 #endif
 
 #if defined(CONFIG_FIT_SHA512) || \
-   defined(CONFIG_SPL_SHA512_SUPPORT)
+   defined(CONFIG_SPL_FIT_SHA512)
 #define IMAGE_ENABLE_SHA5121
 #else
 #define IMAGE_ENABLE_SHA5120
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 20/49] hash: Drop some #ifdefs in hash.c

2021-05-03 Thread Simon Glass
We can use the __maybe_unused attribute to avoid some of the #ifdefs in
this file. Update the functions accordingly.

Note: The actual hashing interface is still a mess, with four separate
combinations and lots of #ifdefs. This should really use a driver
approach, e.g. as is done with partition drivers.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/hash.c | 54 ---
 1 file changed, 25 insertions(+), 29 deletions(-)

diff --git a/common/hash.c b/common/hash.c
index 987d238c66c..1ccc62f162d 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -24,6 +24,7 @@
 #include 
 #else
 #include "mkimage.h"
+#include 
 #include 
 #include 
 #endif /* !USE_HOSTCC*/
@@ -42,8 +43,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static void reloc_update(void);
 
-#if CONFIG_IS_ENABLED(SHA1) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
-static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
+static int __maybe_unused hash_init_sha1(struct hash_algo *algo, void **ctxp)
 {
sha1_context *ctx = malloc(sizeof(sha1_context));
sha1_starts(ctx);
@@ -51,15 +51,16 @@ static int hash_init_sha1(struct hash_algo *algo, void 
**ctxp)
return 0;
 }
 
-static int hash_update_sha1(struct hash_algo *algo, void *ctx, const void *buf,
-   unsigned int size, int is_last)
+static int __maybe_unused hash_update_sha1(struct hash_algo *algo, void *ctx,
+  const void *buf, unsigned int size,
+  int is_last)
 {
sha1_update((sha1_context *)ctx, buf, size);
return 0;
 }
 
-static int hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf,
-   int size)
+static int __maybe_unused hash_finish_sha1(struct hash_algo *algo, void *ctx,
+  void *dest_buf, int size)
 {
if (size < algo->digest_size)
return -1;
@@ -68,10 +69,8 @@ static int hash_finish_sha1(struct hash_algo *algo, void 
*ctx, void *dest_buf,
free(ctx);
return 0;
 }
-#endif
 
-#if CONFIG_IS_ENABLED(SHA256) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
-static int hash_init_sha256(struct hash_algo *algo, void **ctxp)
+static int __maybe_unused hash_init_sha256(struct hash_algo *algo, void **ctxp)
 {
sha256_context *ctx = malloc(sizeof(sha256_context));
sha256_starts(ctx);
@@ -79,15 +78,16 @@ static int hash_init_sha256(struct hash_algo *algo, void 
**ctxp)
return 0;
 }
 
-static int hash_update_sha256(struct hash_algo *algo, void *ctx,
- const void *buf, unsigned int size, int is_last)
+static int __maybe_unused hash_update_sha256(struct hash_algo *algo, void *ctx,
+const void *buf, uint size,
+int is_last)
 {
sha256_update((sha256_context *)ctx, buf, size);
return 0;
 }
 
-static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void
- *dest_buf, int size)
+static int __maybe_unused hash_finish_sha256(struct hash_algo *algo, void *ctx,
+void *dest_buf, int size)
 {
if (size < algo->digest_size)
return -1;
@@ -96,10 +96,8 @@ static int hash_finish_sha256(struct hash_algo *algo, void 
*ctx, void
free(ctx);
return 0;
 }
-#endif
 
-#if CONFIG_IS_ENABLED(SHA384) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
-static int hash_init_sha384(struct hash_algo *algo, void **ctxp)
+static int __maybe_unused hash_init_sha384(struct hash_algo *algo, void **ctxp)
 {
sha512_context *ctx = malloc(sizeof(sha512_context));
sha384_starts(ctx);
@@ -107,15 +105,16 @@ static int hash_init_sha384(struct hash_algo *algo, void 
**ctxp)
return 0;
 }
 
-static int hash_update_sha384(struct hash_algo *algo, void *ctx,
- const void *buf, unsigned int size, int is_last)
+static int __maybe_unused hash_update_sha384(struct hash_algo *algo, void *ctx,
+const void *buf, uint size,
+int is_last)
 {
sha384_update((sha512_context *)ctx, buf, size);
return 0;
 }
 
-static int hash_finish_sha384(struct hash_algo *algo, void *ctx, void
- *dest_buf, int size)
+static int __maybe_unused hash_finish_sha384(struct hash_algo *algo, void *ctx,
+void *dest_buf, int size)
 {
if (size < algo->digest_size)
return -1;
@@ -124,10 +123,8 @@ static int hash_finish_sha384(struct hash_algo *algo, void 
*ctx, void
free(ctx);
return 0;
 }
-#endif
 
-#if CONFIG_IS_ENABLED(SHA512) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
-static int hash_init_sha512(struct hash_algo *algo, void **ctxp)
+static int __maybe_unused 

[PATCH 35/49] image: Drop IMAGE_ENABLE_IGNORE

2021-05-03 Thread Simon Glass
We can use the new host_build() function for this, so drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fit.c | 2 +-
 include/image.h| 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 070835b3a87..c13ff6bba24 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1262,7 +1262,7 @@ static int fit_image_check_hash(const void *fit, int 
noffset, const void *data,
}
printf("%s", algo);
 
-   if (IMAGE_ENABLE_IGNORE) {
+   if (!host_build()) {
fit_image_hash_get_ignore(fit, noffset, );
if (ignore) {
printf("-skipped ");
diff --git a/include/image.h b/include/image.h
index eb5ca8a32d3..64866c609f4 100644
--- a/include/image.h
+++ b/include/image.h
@@ -27,7 +27,6 @@ struct fdt_region;
 #include 
 #include 
 
-#define IMAGE_ENABLE_IGNORE0
 #define IMAGE_INDENT_STRING""
 
 #else
@@ -36,8 +35,6 @@ struct fdt_region;
 #include 
 #include 
 
-/* Take notice of the 'ignore' property for hashes */
-#define IMAGE_ENABLE_IGNORE1
 #define IMAGE_INDENT_STRING"   "
 
 #endif /* USE_HOSTCC */
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 19/49] hash: Use Kconfig to enable hashing in host tools

2021-05-03 Thread Simon Glass
At present when building host tools, we force CONFIG_SHA1 to be enabled
regardless of the board Kconfig setting. This is done in the image.h
header file.

Clean this up by adding new Kconfig options to enable hashing on the host,
relying on CONFIG_IS_ENABLED() to deal with the different builds.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/hash.c   | 37 +++--
 include/image.h |  4 
 tools/Kconfig   | 20 
 3 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/common/hash.c b/common/hash.c
index 10dff7ddb0e..987d238c66c 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -25,6 +25,7 @@
 #else
 #include "mkimage.h"
 #include 
+#include 
 #endif /* !USE_HOSTCC*/
 
 #include 
@@ -41,7 +42,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static void reloc_update(void);
 
-#if defined(CONFIG_SHA1) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA1) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
 static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
 {
sha1_context *ctx = malloc(sizeof(sha1_context));
@@ -69,7 +70,7 @@ static int hash_finish_sha1(struct hash_algo *algo, void 
*ctx, void *dest_buf,
 }
 #endif
 
-#if defined(CONFIG_SHA256) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA256) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
 static int hash_init_sha256(struct hash_algo *algo, void **ctxp)
 {
sha256_context *ctx = malloc(sizeof(sha256_context));
@@ -97,7 +98,7 @@ static int hash_finish_sha256(struct hash_algo *algo, void 
*ctx, void
 }
 #endif
 
-#if defined(CONFIG_SHA384) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA384) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
 static int hash_init_sha384(struct hash_algo *algo, void **ctxp)
 {
sha512_context *ctx = malloc(sizeof(sha512_context));
@@ -125,7 +126,7 @@ static int hash_finish_sha384(struct hash_algo *algo, void 
*ctx, void
 }
 #endif
 
-#if defined(CONFIG_SHA512) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
+#if CONFIG_IS_ENABLED(SHA512) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
 static int hash_init_sha512(struct hash_algo *algo, void **ctxp)
 {
sha512_context *ctx = malloc(sizeof(sha512_context));
@@ -213,17 +214,17 @@ static int hash_finish_crc32(struct hash_algo *algo, void 
*ctx, void *dest_buf,
  * Note that algorithm names must be in lower case.
  */
 static struct hash_algo hash_algo[] = {
-#ifdef CONFIG_SHA1
+#if CONFIG_IS_ENABLED(SHA1)
{
.name   = "sha1",
.digest_size= SHA1_SUM_LEN,
.chunk_size = CHUNKSZ_SHA1,
-#ifdef CONFIG_SHA_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_HW_ACCEL)
.hash_func_ws   = hw_sha1,
 #else
.hash_func_ws   = sha1_csum_wd,
 #endif
-#ifdef CONFIG_SHA_PROG_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
.hash_init  = hw_sha_init,
.hash_update= hw_sha_update,
.hash_finish= hw_sha_finish,
@@ -234,17 +235,17 @@ static struct hash_algo hash_algo[] = {
 #endif
},
 #endif
-#ifdef CONFIG_SHA256
+#if CONFIG_IS_ENABLED(SHA256)
{
.name   = "sha256",
.digest_size= SHA256_SUM_LEN,
.chunk_size = CHUNKSZ_SHA256,
-#ifdef CONFIG_SHA_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_HW_ACCEL)
.hash_func_ws   = hw_sha256,
 #else
.hash_func_ws   = sha256_csum_wd,
 #endif
-#ifdef CONFIG_SHA_PROG_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
.hash_init  = hw_sha_init,
.hash_update= hw_sha_update,
.hash_finish= hw_sha_finish,
@@ -255,17 +256,17 @@ static struct hash_algo hash_algo[] = {
 #endif
},
 #endif
-#ifdef CONFIG_SHA384
+#if CONFIG_IS_ENABLED(SHA384)
{
.name   = "sha384",
.digest_size= SHA384_SUM_LEN,
.chunk_size = CHUNKSZ_SHA384,
-#ifdef CONFIG_SHA_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_HW_ACCEL)
.hash_func_ws   = hw_sha384,
 #else
.hash_func_ws   = sha384_csum_wd,
 #endif
-#ifdef CONFIG_SHA_PROG_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
.hash_init  = hw_sha_init,
.hash_update= hw_sha_update,
.hash_finish= hw_sha_finish,
@@ -276,17 +277,17 @@ static struct hash_algo hash_algo[] = {
 #endif
},
 #endif
-#ifdef CONFIG_SHA512
+#if CONFIG_IS_ENABLED(SHA512)
{
.name   = "sha512",
.digest_size= SHA512_SUM_LEN,
.chunk_size = CHUNKSZ_SHA512,
-#ifdef CONFIG_SHA_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_HW_ACCEL)
.hash_func_ws   = hw_sha512,
 #else
.hash_func_ws   = sha512_csum_wd,
 #endif
-#ifdef CONFIG_SHA_PROG_HW_ACCEL
+#if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL)
.hash_init  = hw_sha_init,
   

[PATCH 29/49] image: Drop IMAGE_ENABLE_MD5

2021-05-03 Thread Simon Glass
Add a host Kconfig for MD5. With this we can use CONFIG_IS_ENABLED(MD5)
directly in the host build, so drop the unnecessary indirection.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fit.c | 2 +-
 include/image.h| 8 
 tools/Kconfig  | 5 +
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 1ce46a5c72d..19a2d3c91df 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1234,7 +1234,7 @@ int calculate_hash(const void *data, int data_len, const 
char *algo,
sha512_csum_wd((unsigned char *)data, data_len,
   (unsigned char *)value, CHUNKSZ_SHA512);
*value_len = SHA512_SUM_LEN;
-   } else if (IMAGE_ENABLE_MD5 && strcmp(algo, "md5") == 0) {
+   } else if (CONFIG_IS_ENABLED(MD5) && strcmp(algo, "md5") == 0) {
md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
*value_len = 16;
} else {
diff --git a/include/image.h b/include/image.h
index e1e4bf6806f..9f665a597b0 100644
--- a/include/image.h
+++ b/include/image.h
@@ -47,21 +47,13 @@ struct fdt_region;
 #include 
 #include 
 # ifdef CONFIG_SPL_BUILD
-#  ifdef CONFIG_SPL_MD5
-#   define IMAGE_ENABLE_MD51
-#  endif
 #  ifdef CONFIG_SPL_FIT_SHA1
 #   define IMAGE_ENABLE_SHA1   1
 #  endif
 # else
-#  define IMAGE_ENABLE_MD5 1
 #  define IMAGE_ENABLE_SHA11
 # endif
 
-#ifndef IMAGE_ENABLE_MD5
-#define IMAGE_ENABLE_MD5   0
-#endif
-
 #ifndef IMAGE_ENABLE_SHA1
 #define IMAGE_ENABLE_SHA1  0
 #endif
diff --git a/tools/Kconfig b/tools/Kconfig
index e27826fae9f..bbd6e8b9d79 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -69,6 +69,11 @@ config HOST_FIT_VERBOSE
help
  Support verbose FIT output in the host build
 
+config HOST_MD5
+   def_bool y
+   help
+ Enable MD5 support in the host build
+
 config HOST_OF_LIBFDT
def_bool y
help
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 23/49] image: Use Kconfig to enable CONFIG_FIT_VERBOSE on host

2021-05-03 Thread Simon Glass
Add a host Kconfig for FIT_VERBOSE. With this we can use
CONFIG_IS_ENABLED(FIT_VERBOSE) directly in the host build, so drop the
forcing of this in the image.h header.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/image.h | 5 ++---
 tools/Kconfig   | 5 +
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/image.h b/include/image.h
index bdf19a4cc04..b08ae2bb6c0 100644
--- a/include/image.h
+++ b/include/image.h
@@ -28,7 +28,6 @@ struct fdt_region;
 #include 
 
 /* new uImage format support enabled on host */
-#define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */
 #define CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT 1
 
 #define IMAGE_ENABLE_IGNORE0
@@ -1509,7 +1508,7 @@ int fit_image_cipher_get_algo(const void *fit, int 
noffset, char **algo);
 
 struct cipher_algo *image_get_cipher_algo(const char *full_name);
 
-#ifdef CONFIG_FIT_VERBOSE
+#if CONFIG_IS_ENABLED(FIT_VERBOSE)
 #define fit_unsupported(msg)   printf("! %s:%d " \
"FIT images not supported for '%s'\n", \
__FILE__, __LINE__, (msg))
@@ -1521,7 +1520,7 @@ struct cipher_algo *image_get_cipher_algo(const char 
*full_name);
 #else
 #define fit_unsupported(msg)
 #define fit_unsupported_reset(msg)
-#endif /* CONFIG_FIT_VERBOSE */
+#endif /* FIT_VERBOSE */
 #endif /* CONFIG_FIT */
 
 #if !defined(USE_HOSTCC)
diff --git a/tools/Kconfig b/tools/Kconfig
index c67dc04f5ed..6d0f4565a80 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -54,6 +54,11 @@ config HOST_FIT_SIGNATURE_MAX_SIZE
depends on HOST_FIT_SIGNATURE
default 0x1000
 
+config HOST_FIT_VERBOSE
+   def_bool y
+   help
+ Support verbose FIT output in the host build
+
 config HOST_OF_LIBFDT
def_bool y
help
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 14/49] image: Remove ifdefs around image_setup_linux() el at

2021-05-03 Thread Simon Glass
Drop some more ifdefs in image-board.c and also the FPGA part of bootm.c
which calls into it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/bootm.c   | 16 
 common/image-board.c | 11 +++
 2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index ea71522d0c9..fe17d1da9e5 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -296,15 +296,15 @@ int bootm_find_images(int flag, int argc, char *const 
argv[], ulong start,
 #endif
 
 #if IMAGE_ENABLE_FIT
-#if defined(CONFIG_FPGA)
-   /* find bitstreams */
-   ret = boot_get_fpga(argc, argv, , IH_ARCH_DEFAULT,
-   NULL, NULL);
-   if (ret) {
-   printf("FPGA image is corrupted or invalid\n");
-   return 1;
+   if (IS_ENABLED(CONFIG_FPGA)) {
+   /* find bitstreams */
+   ret = boot_get_fpga(argc, argv, , IH_ARCH_DEFAULT,
+   NULL, NULL);
+   if (ret) {
+   printf("FPGA image is corrupted or invalid\n");
+   return 1;
+   }
}
-#endif
 
/* find all of the loadables */
ret = boot_get_loadable(argc, argv, , IH_ARCH_DEFAULT,
diff --git a/common/image-board.c b/common/image-board.c
index b46062c86b9..0f41ede1e98 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -814,7 +814,6 @@ int boot_get_loadable(int argc, char *const argv[], 
bootm_headers_t *images,
 }
 #endif
 
-#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
 /**
  * boot_get_cmdline - allocate and initialize kernel cmdline
  * @lmb: pointer to lmb handle, will be used for memory mgmt
@@ -853,9 +852,7 @@ int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, 
ulong *cmd_end)
 
return 0;
 }
-#endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
 
-#ifdef CONFIG_SYS_BOOT_GET_KBD
 /**
  * boot_get_kbd - allocate and initialize kernel copy of board info
  * @lmb: pointer to lmb handle, will be used for memory mgmt
@@ -883,15 +880,14 @@ int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd)
 
debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
 
-#if defined(DEBUG) && defined(CONFIG_CMD_BDI)
-   do_bdinfo(NULL, 0, 0, NULL);
+#if defined(DEBUG)
+   if (IS_ENABLED(CONFIG_CMD_BDI)
+   do_bdinfo(NULL, 0, 0, NULL);
 #endif
 
return 0;
 }
-#endif /* CONFIG_SYS_BOOT_GET_KBD */
 
-#ifdef CONFIG_LMB
 int image_setup_linux(bootm_headers_t *images)
 {
ulong of_size = images->ft_len;
@@ -925,7 +921,6 @@ int image_setup_linux(bootm_headers_t *images)
 
return 0;
 }
-#endif /* CONFIG_LMB */
 
 void genimg_print_size(uint32_t size)
 {
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 44/49] image: Split up boot_get_ramdisk()

2021-05-03 Thread Simon Glass
This function is far too long. Before trying to remove #ifdefs, split out
the code that deals with selecting the ramdisk into a separate function.

Leave the code indented as it was for easier review. The next patch cleans
this up along with checkpatch violations.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-board.c | 147 +--
 1 file changed, 87 insertions(+), 60 deletions(-)

diff --git a/common/image-board.c b/common/image-board.c
index f0ef426d1c9..c32fff96ece 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -313,57 +313,21 @@ int genimg_has_config(bootm_headers_t *images)
 }
 
 /**
- * boot_get_ramdisk - main ramdisk handling routine
- * @argc: command argument count
- * @argv: command argument list
+ * select_ramdisk() - Select and locate the ramdisk to use
+ *
  * @images: pointer to the bootm images structure
+ * @select: name of ramdisk to select, or NULL for any
  * @arch: expected ramdisk architecture
- * @rd_start: pointer to a ulong variable, will hold ramdisk start address
- * @rd_end: pointer to a ulong variable, will hold ramdisk end
- *
- * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
- * Currently supported are the following ramdisk sources:
- *  - multicomponent kernel/ramdisk image,
- *  - commandline provided address of decicated ramdisk image.
- *
- * returns:
- * 0, if ramdisk image was found and valid, or skiped
- * rd_start and rd_end are set to ramdisk start/end addresses if
- * ramdisk image is found and valid
- *
- * 1, if ramdisk image is found but corrupted, or invalid
- * rd_start and rd_end are set to 0 if no ramdisk exists
+ * @rd_datap: pointer to a ulong variable, will hold ramdisk pointer
+ * @rd_lenp: pointer to a ulong variable, will hold ramdisk length
+ * @return 0 if OK, -ENOPKG if no ramdisk (but an error should not be 
reported),
+ * other -ve value on other error
  */
-int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
-u8 arch, ulong *rd_start, ulong *rd_end)
+static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch,
+ ulong *rd_datap, ulong *rd_lenp)
 {
-   ulong rd_data, rd_len;
-   void *buf;
-   const char *select = NULL;
-
-   *rd_start = 0;
-   *rd_end = 0;
-
-   if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) {
-   /* Look for an Android boot image */
-   buf = map_sysmem(images->os.start, 0);
-   if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID)
-   select = (argc == 0) ? env_get("loadaddr") : argv[0];
-   }
-
-   if (argc >= 2)
-   select = argv[1];
-
-   /*
-* Look for a '-' which indicates to ignore the
-* ramdisk argument
-*/
-   if (select && strcmp(select, "-") ==  0) {
-   debug("## Skipping init Ramdisk\n");
-   rd_len = 0;
-   rd_data = 0;
-   } else if (select || genimg_has_config(images)) {
-   ulong rd_addr, rd_load;
+   ulong rd_addr, rd_load;
+   char *buf;
 
 #if CONFIG_IS_ENABLED(FIT)
const char *fit_uname_config = images->fit_uname_cfg;
@@ -403,16 +367,16 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
} else {
/* use FIT configuration provided in first bootm
 * command argument. If the property is not defined,
-* quit silently.
+* quit silently (with -ENOPKG)
 */
rd_addr = map_to_sysmem(images->fit_hdr_os);
rd_noffset = fit_get_node_from_config(images,
  FIT_RAMDISK_PROP,
  rd_addr);
if (rd_noffset == -ENOENT)
-   return 0;
+   return -ENOPKG;
else if (rd_noffset < 0)
-   return 1;
+   return rd_noffset;
}
 #endif
 
@@ -435,10 +399,10 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
   images->verify);
 
if (!rd_hdr)
-   return 1;
+   return -ENOENT;
 
-   rd_data = image_get_data(rd_hdr);
-   rd_len = image_get_data_size(rd_hdr);
+   *rd_datap = image_get_data(rd_hdr);
+   *rd_lenp = image_get_data_size(rd_hdr);
rd_load = image_get_load(rd_hdr);
break;
}
@@ -451,9 +415,9 @@ int boot_get_ramdisk(int argc, 

[PATCH 22/49] image: Drop IMAGE_ENABLE_OF_LIBFDT

2021-05-03 Thread Simon Glass
Add a host Kconfig for OF_LIBFDT. With this we can use
CONFIG_IS_ENABLED(OF_LIBFDT) directly in the host build, so drop the
unnecessary indirection.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arc/lib/bootm.c| 2 +-
 arch/arm/lib/bootm.c| 4 ++--
 arch/microblaze/lib/bootm.c | 2 +-
 arch/nds32/lib/bootm.c  | 4 ++--
 arch/riscv/lib/bootm.c  | 4 ++--
 board/synopsys/hsdk/hsdk.c  | 2 +-
 common/bootm.c  | 4 ++--
 common/image-board.c| 8 
 common/image.c  | 2 +-
 include/image.h | 3 ---
 lib/lmb.c   | 2 +-
 tools/Kconfig   | 5 +
 12 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c
index 8a8d394a5f0..2e139611e59 100644
--- a/arch/arc/lib/bootm.c
+++ b/arch/arc/lib/bootm.c
@@ -93,7 +93,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
   "(fake run for tracing)" : "");
bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
 
-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
+   if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
r0 = 2;
r2 = (unsigned int)images->ft_addr;
} else {
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index f60ee3a7e6a..493c9e1df19 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -244,7 +244,7 @@ static void boot_prep_linux(bootm_headers_t *images)
 {
char *commandline = env_get("bootargs");
 
-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
+   if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
 #ifdef CONFIG_OF_LIBFDT
debug("using: FDT\n");
if (image_setup_linux(images)) {
@@ -401,7 +401,7 @@ static void boot_jump_linux(bootm_headers_t *images, int 
flag)
bootstage_mark(BOOTSTAGE_ID_RUN_OS);
announce_and_cleanup(fake);
 
-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
+   if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len)
r2 = (unsigned long)images->ft_addr;
else
r2 = gd->bd->bi_boot_params;
diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c
index 6695ac63c77..1e041fb5685 100644
--- a/arch/microblaze/lib/bootm.c
+++ b/arch/microblaze/lib/bootm.c
@@ -101,7 +101,7 @@ static void boot_jump_linux(bootm_headers_t *images, int 
flag)
 
 static void boot_prep_linux(bootm_headers_t *images)
 {
-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
+   if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
debug("using: FDT\n");
if (image_setup_linux(images)) {
printf("FDT creation failed! hanging...");
diff --git a/arch/nds32/lib/bootm.c b/arch/nds32/lib/bootm.c
index b3b8bc29037..394564a3f5b 100644
--- a/arch/nds32/lib/bootm.c
+++ b/arch/nds32/lib/bootm.c
@@ -73,7 +73,7 @@ int do_bootm_linux(int flag, int argc, char *argv[], 
bootm_headers_t *images)
debug("## Transferring control to Linux (at address %08lx) ...\n",
   (ulong)theKernel);
 
-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
+   if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
 #ifdef CONFIG_OF_LIBFDT
debug("using: FDT\n");
if (image_setup_linux(images)) {
@@ -118,7 +118,7 @@ int do_bootm_linux(int flag, int argc, char *argv[], 
bootm_headers_t *images)
 #endif
}
cleanup_before_linux();
-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
+   if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len)
theKernel(0, machid, (unsigned long)images->ft_addr);
else
theKernel(0, machid, bd->bi_boot_params);
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
index 8dd18205403..6c9e7eb6547 100644
--- a/arch/riscv/lib/bootm.c
+++ b/arch/riscv/lib/bootm.c
@@ -64,7 +64,7 @@ static void announce_and_cleanup(int fake)
 
 static void boot_prep_linux(bootm_headers_t *images)
 {
-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
+   if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
 #ifdef CONFIG_OF_LIBFDT
debug("using: FDT\n");
if (image_setup_linux(images)) {
@@ -96,7 +96,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
announce_and_cleanup(fake);
 
if (!fake) {
-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
+   if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
 #ifdef CONFIG_SMP
ret = smp_call_function(images->ep,
(ulong)images->ft_addr, 0, 0);
diff --git a/board/synopsys/hsdk/hsdk.c b/board/synopsys/hsdk/hsdk.c
index 892b94bb083..226fbba6296 100644
--- a/board/synopsys/hsdk/hsdk.c
+++ b/board/synopsys/hsdk/hsdk.c
@@ -871,7 +871,7 @@ int board_prep_linux(bootm_headers_t *images)
if (env_common.core_mask.val == ALL_CPU_MASK)
 

[PATCH 28/49] Kconfig: Rename SPL_MD5_SUPPORT to SPL_MD5

2021-05-03 Thread Simon Glass
Drop the _SUPPORT suffix so we can use CONFIG_IS_ENABLED() with this
option.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/spl/Kconfig | 2 +-
 include/image.h| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 636a7319274..56e5867c9cd 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -418,7 +418,7 @@ config SPL_CRC32
  for detected accidental image corruption. For secure applications you
  should consider SHA1 or SHA256.
 
-config SPL_MD5_SUPPORT
+config SPL_MD5
bool "Support MD5"
depends on SPL_FIT
help
diff --git a/include/image.h b/include/image.h
index e68c2cbf621..e1e4bf6806f 100644
--- a/include/image.h
+++ b/include/image.h
@@ -47,7 +47,7 @@ struct fdt_region;
 #include 
 #include 
 # ifdef CONFIG_SPL_BUILD
-#  ifdef CONFIG_SPL_MD5_SUPPORT
+#  ifdef CONFIG_SPL_MD5
 #   define IMAGE_ENABLE_MD51
 #  endif
 #  ifdef CONFIG_SPL_FIT_SHA1
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 33/49] image: Drop IMAGE_OF_BOARD_SETUP

2021-05-03 Thread Simon Glass
This is not needed with Kconfig, since we can use IS_ENABLED() easily
enough. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fdt.c | 4 ++--
 include/image.h| 6 --
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index d50e1ba3feb..c2d9710bfaa 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -575,7 +575,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
/* Append PStore configuration */
fdt_fixup_pstore(blob);
 #endif
-   if (IMAGE_OF_BOARD_SETUP) {
+   if (IS_ENABLED(CONFIG_OF_BOARD_SETUP)) {
const char *skip_board_fixup;
 
skip_board_fixup = env_get("skip_board_fixup");
@@ -622,7 +622,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
goto err;
 
 #if defined(CONFIG_SOC_KEYSTONE)
-   if (IMAGE_OF_BOARD_SETUP)
+   if (IS_ENABLED(CONFIG_OF_BOARD_SETUP))
ft_board_setup_ex(blob, gd->bd);
 #endif
 
diff --git a/include/image.h b/include/image.h
index 122fc25e1b4..deb690d168b 100644
--- a/include/image.h
+++ b/include/image.h
@@ -49,12 +49,6 @@ struct fdt_region;
 
 #endif /* FIT */
 
-#ifdef CONFIG_OF_BOARD_SETUP
-# define IMAGE_OF_BOARD_SETUP  1
-#else
-# define IMAGE_OF_BOARD_SETUP  0
-#endif
-
 #ifdef CONFIG_OF_SYSTEM_SETUP
 # define IMAGE_OF_SYSTEM_SETUP 1
 #else
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 13/49] image: Avoid #ifdefs for manual relocation

2021-05-03 Thread Simon Glass
Add a macro to handle manually relocating a pointer. Update the iamge code
to use this to avoid needing #ifdefs.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-sig.c | 43 ---
 include/relocate.h |  6 ++
 2 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/common/image-sig.c b/common/image-sig.c
index 0f8e592aba7..12310bfca1a 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -16,6 +16,7 @@
 DECLARE_GLOBAL_DATA_PTR;
 #endif /* !USE_HOSTCC*/
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -112,20 +113,22 @@ struct checksum_algo *image_get_checksum_algo(const char 
*full_name)
int i;
const char *name;
 
-#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
-   static bool done;
+   if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
+   static bool done;
 
-   if (!done) {
-   done = true;
-   for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
-   checksum_algos[i].name += gd->reloc_off;
+   if (!done) {
+   done = true;
+   for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
+   struct checksum_algo *algo = _algos[i];
+
+   MANUAL_RELOC(algo->name);
 #if IMAGE_ENABLE_SIGN
-   checksum_algos[i].calculate_sign += gd->reloc_off;
+   MANUAL_RELOC(algo->calculate_sign);
 #endif
-   checksum_algos[i].calculate += gd->reloc_off;
+   MANUAL_RELOC(algo->calculate);
+   }
}
}
-#endif
 
for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
name = checksum_algos[i].name;
@@ -143,19 +146,21 @@ struct crypto_algo *image_get_crypto_algo(const char 
*full_name)
int i;
const char *name;
 
-#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
-   static bool done;
+   if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
+   static bool done;
 
-   if (!done) {
-   done = true;
-   for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
-   crypto_algos[i].name += gd->reloc_off;
-   crypto_algos[i].sign += gd->reloc_off;
-   crypto_algos[i].add_verify_data += gd->reloc_off;
-   crypto_algos[i].verify += gd->reloc_off;
+   if (!done) {
+   done = true;
+   for (i = 0; i < ARRAY_SIZE(crypto_algos); i++) {
+   struct crypto_algo *algo = _algos[i];
+
+   MANUAL_RELOC(algo->name);
+   MANUAL_RELOC(algo->sign);
+   MANUAL_RELOC(algo->add_verify_data);
+   MANUAL_RELOC(algo->verify);
+   }
}
}
-#endif
 
/* Move name to after the comma */
name = strchr(full_name, ',');
diff --git a/include/relocate.h b/include/relocate.h
index c4fad336128..26682da955f 100644
--- a/include/relocate.h
+++ b/include/relocate.h
@@ -57,4 +57,10 @@ static inline void *manual_reloc(void *ptr)
return ptr;
 }
 
+#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
+#define MANUAL_RELOC(ptr)  (ptr) = manual_reloc(ptr)
+#else
+#define MANUAL_RELOC(ptr)  (void)(ptr)
+#endif
+
 #endif /* _RELOCATE_H_ */
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 43/49] image: Reduce variable scope in boot_get_ramdisk()

2021-05-03 Thread Simon Glass
Move the variables declarations to where they are needed, to reduce the
number of #ifdefs needed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-board.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/common/image-board.c b/common/image-board.c
index 0543c67d3bd..f0ef426d1c9 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -337,18 +337,8 @@ int genimg_has_config(bootm_headers_t *images)
 int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
 u8 arch, ulong *rd_start, ulong *rd_end)
 {
-   ulong rd_addr, rd_load;
ulong rd_data, rd_len;
-#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
-   const image_header_t *rd_hdr;
-#endif
void *buf;
-#if CONFIG_IS_ENABLED(FIT)
-   const char  *fit_uname_config = images->fit_uname_cfg;
-   const char  *fit_uname_ramdisk = NULL;
-   ulong   default_addr;
-   int rd_noffset;
-#endif
const char *select = NULL;
 
*rd_start = 0;
@@ -373,8 +363,15 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
rd_len = 0;
rd_data = 0;
} else if (select || genimg_has_config(images)) {
+   ulong rd_addr, rd_load;
+
 #if CONFIG_IS_ENABLED(FIT)
+   const char *fit_uname_config = images->fit_uname_cfg;
+   const char *fit_uname_ramdisk = NULL;
+   int rd_noffset;
+
if (select) {
+   ulong default_addr;
/*
 * If the init ramdisk comes from the FIT image and
 * the FIT image address is omitted in the command
@@ -427,7 +424,9 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
buf = map_sysmem(rd_addr, 0);
switch (genimg_get_format(buf)) {
 #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
-   case IMAGE_FORMAT_LEGACY:
+   case IMAGE_FORMAT_LEGACY: {
+   const image_header_t *rd_hdr;
+
printf("## Loading init Ramdisk from Legacy Image at 
%08lx ...\n",
   rd_addr);
 
@@ -442,6 +441,7 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
rd_len = image_get_data_size(rd_hdr);
rd_load = image_get_load(rd_hdr);
break;
+   }
 #endif
 #if CONFIG_IS_ENABLED(FIT)
case IMAGE_FORMAT_FIT:
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 21/49] image: Drop IMAGE_ENABLE_FIT

2021-05-03 Thread Simon Glass
Make use of the host Kconfig for FIT. With this we can use
CONFIG_IS_ENABLED(FIT) directly in the host build, so drop the unnecessary
indirection.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/mach-imx/hab.c |  2 +-
 common/bootm.c  | 10 +-
 common/image-board.c| 16 
 common/image.c  |  2 +-
 include/fdt_support.h   |  2 +-
 include/image.h | 22 +-
 tools/Kconfig   | 20 
 7 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c
index 00bd157d0e0..cf56f67 100644
--- a/arch/arm/mach-imx/hab.c
+++ b/arch/arm/mach-imx/hab.c
@@ -591,7 +591,7 @@ static ulong get_image_ivt_offset(ulong img_addr)
return (image_get_image_size((image_header_t *)img_addr)
+ 0x1000 - 1)  & ~(0x1000 - 1);
 #endif
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
case IMAGE_FORMAT_FIT:
return (fit_get_size(buf) + 0x1000 - 1)  & ~(0x1000 - 1);
 #endif
diff --git a/common/bootm.c b/common/bootm.c
index fe17d1da9e5..8d614fe140e 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -115,7 +115,7 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, 
int argc,
images.os.arch = image_get_arch(os_hdr);
break;
 #endif
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
case IMAGE_FORMAT_FIT:
if (fit_image_get_type(images.fit_hdr_os,
   images.fit_noffset_os,
@@ -187,7 +187,7 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, 
int argc,
/* Kernel entry point is the setup.bin */
} else if (images.legacy_hdr_valid) {
images.ep = image_get_ep(_hdr_os_copy);
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
} else if (images.fit_uname_os) {
int ret;
 
@@ -295,7 +295,7 @@ int bootm_find_images(int flag, int argc, char *const 
argv[], ulong start,
set_working_fdt_addr(map_to_sysmem(images.ft_addr));
 #endif
 
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
if (IS_ENABLED(CONFIG_FPGA)) {
/* find bitstreams */
ret = boot_get_fpga(argc, argv, , IH_ARCH_DEFAULT,
@@ -858,7 +858,7 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, 
int flag, int argc,
const void *buf;
const char  *fit_uname_config = NULL;
const char  *fit_uname_kernel = NULL;
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
int os_noffset;
 #endif
 
@@ -916,7 +916,7 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, 
int flag, int argc,
bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
break;
 #endif
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
case IMAGE_FORMAT_FIT:
os_noffset = fit_image_load(images, img_addr,
_uname_kernel, _uname_config,
diff --git a/common/image-board.c b/common/image-board.c
index 0f41ede1e98..05eeaaac8b0 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -282,7 +282,7 @@ int genimg_get_format(const void *img_addr)
if (image_check_magic(hdr))
return IMAGE_FORMAT_LEGACY;
 #endif
-#if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT
+#if CONFIG_IS_ENABLED(FIT) || IMAGE_ENABLE_OF_LIBFDT
if (fdt_check_header(img_addr) == 0)
return IMAGE_FORMAT_FIT;
 #endif
@@ -307,7 +307,7 @@ int genimg_get_format(const void *img_addr)
  */
 int genimg_has_config(bootm_headers_t *images)
 {
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
if (images->fit_uname_cfg)
return 1;
 #endif
@@ -348,7 +348,7 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
 #ifdef CONFIG_SUPPORT_RAW_INITRD
char *end;
 #endif
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
const char  *fit_uname_config = images->fit_uname_cfg;
const char  *fit_uname_ramdisk = NULL;
ulong   default_addr;
@@ -380,7 +380,7 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
rd_len = 0;
rd_data = 0;
} else if (select || genimg_has_config(images)) {
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
if (select) {
/*
 * If the init ramdisk comes from the FIT image and
@@ -409,7 +409,7 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
debug("*  ramdisk: cmdline image address = 
0x%08lx\n",
  rd_addr);
}
-#if IMAGE_ENABLE_FIT
+#if CONFIG_IS_ENABLED(FIT)
} else {
/* use FIT configuration provided in first bootm
 * command argument. If the property is 

[PATCH 34/49] image: Drop IMAGE_OF_SYSTEM_SETUP

2021-05-03 Thread Simon Glass
This is not needed with Kconfig, since we can use IS_ENABLED() easily
enough. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fdt.c | 2 +-
 include/image.h| 6 --
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index c2d9710bfaa..80bfa625ab2 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -590,7 +590,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
}
}
}
-   if (IMAGE_OF_SYSTEM_SETUP) {
+   if (IS_ENABLED(CONFIG_OF_SYSTEM_SETUP)) {
fdt_ret = ft_system_setup(blob, gd->bd);
if (fdt_ret) {
printf("ERROR: system-specific fdt fixup failed: %s\n",
diff --git a/include/image.h b/include/image.h
index deb690d168b..eb5ca8a32d3 100644
--- a/include/image.h
+++ b/include/image.h
@@ -49,12 +49,6 @@ struct fdt_region;
 
 #endif /* FIT */
 
-#ifdef CONFIG_OF_SYSTEM_SETUP
-# define IMAGE_OF_SYSTEM_SETUP 1
-#else
-# define IMAGE_OF_SYSTEM_SETUP 0
-#endif
-
 extern ulong image_load_addr;  /* Default Load Address */
 extern ulong image_save_addr;  /* Default Save Address */
 extern ulong image_save_size;  /* Default Save Size */
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 12/49] image: Create a function to do manual relocation

2021-05-03 Thread Simon Glass
Rather than adding an #ifdef and open-coding this calculation, add a
helper function to handle it. Use this in the image code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image.c | 33 +++--
 include/relocate.h | 24 +++-
 2 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/common/image.c b/common/image.c
index 0ef8f30fcfa..086ae609f29 100644
--- a/common/image.c
+++ b/common/image.c
@@ -63,6 +63,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -563,11 +564,7 @@ const char *genimg_get_cat_name(enum ih_category category, 
uint id)
entry = get_table_entry(table_info[category].table, id);
if (!entry)
return unknown_msg(category);
-#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
-   return entry->lname;
-#else
-   return entry->lname + gd->reloc_off;
-#endif
+   return manual_reloc(entry->lname);
 }
 
 /**
@@ -587,11 +584,7 @@ const char *genimg_get_cat_short_name(enum ih_category 
category, uint id)
entry = get_table_entry(table_info[category].table, id);
if (!entry)
return unknown_msg(category);
-#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
-   return entry->sname;
-#else
-   return entry->sname + gd->reloc_off;
-#endif
+   return manual_reloc(entry->sname);
 }
 
 int genimg_get_cat_count(enum ih_category category)
@@ -641,11 +634,7 @@ char *get_table_entry_name(const table_entry_t *table, 
char *msg, int id)
table = get_table_entry(table, id);
if (!table)
return msg;
-#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
-   return table->lname;
-#else
-   return table->lname + gd->reloc_off;
-#endif
+   return manual_reloc(table->lname);
 }
 
 const char *genimg_get_os_name(uint8_t os)
@@ -675,11 +664,7 @@ static const char *genimg_get_short_name(const 
table_entry_t *table, int val)
table = get_table_entry(table, val);
if (!table)
return "unknown";
-#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
-   return table->sname;
-#else
-   return table->sname + gd->reloc_off;
-#endif
+   return manual_reloc(table->sname);
 }
 
 const char *genimg_get_type_short_name(uint8_t type)
@@ -722,12 +707,8 @@ int get_table_entry_id(const table_entry_t *table,
const table_entry_t *t;
 
for (t = table; t->id >= 0; ++t) {
-#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
-   if (t->sname && strcasecmp(t->sname + gd->reloc_off, name) == 0)
-#else
-   if (t->sname && strcasecmp(t->sname, name) == 0)
-#endif
-   return (t->id);
+   if (t->sname && !strcasecmp(manual_reloc(t->sname), name))
+   return t->id;
}
debug("Invalid %s Type: %s\n", table_name, name);
 
diff --git a/include/relocate.h b/include/relocate.h
index 9ceeecdbe71..c4fad336128 100644
--- a/include/relocate.h
+++ b/include/relocate.h
@@ -7,7 +7,11 @@
 #ifndef _RELOCATE_H_
 #define _RELOCATE_H_
 
-#include 
+#ifndef USE_HOSTCC
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+#endif
 
 /**
  * copy_uboot_to_ram() - Copy U-Boot to its new relocated position
@@ -35,4 +39,22 @@ int clear_bss(void);
  */
 int do_elf_reloc_fixups(void);
 
+/**
+ * manual_reloc() - Manually relocate a pointer if needed
+ *
+ * This is a nop in almost all cases, except for the systems with a broken gcc
+ * which need to manually relocate some things.
+ *
+ * @ptr: Pointer to relocate
+ * @return new pointer value
+ */
+static inline void *manual_reloc(void *ptr)
+{
+#ifndef USE_HOSTCC
+   if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC))
+   return ptr + gd->reloc_off;
+#endif
+   return ptr;
+}
+
 #endif /* _RELOCATE_H_ */
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 10/49] image: Fix up checkpatch warnings in image-board.c

2021-05-03 Thread Simon Glass
Tidy up the warnings.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-board.c | 142 ++-
 1 file changed, 72 insertions(+), 70 deletions(-)

diff --git a/common/image-board.c b/common/image-board.c
index 0c4e32e14e4..5d3eafb5245 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -41,8 +41,8 @@ DECLARE_GLOBAL_DATA_PTR;
  * pointer to a ramdisk image header, if image was found and valid
  * otherwise, return NULL
  */
-static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
-   int verify)
+static const image_header_t *image_get_ramdisk(ulong rd_addr, u8 arch,
+  int verify)
 {
const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
 
@@ -77,7 +77,7 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, 
uint8_t arch,
!image_check_arch(rd_hdr, arch) ||
!image_check_type(rd_hdr, IH_TYPE_RAMDISK)) {
printf("No Linux %s Ramdisk Image\n",
-   genimg_get_arch_name(arch));
+  genimg_get_arch_name(arch));
bootstage_error(BOOTSTAGE_ID_RAMDISK);
return NULL;
}
@@ -94,7 +94,7 @@ ulong image_save_addr;/* Default Save 
Address */
 ulong image_save_size; /* Default Save Size (in bytes) */
 
 static int on_loadaddr(const char *name, const char *value, enum env_op op,
-   int flags)
+  int flags)
 {
switch (op) {
case env_op_create:
@@ -112,6 +112,7 @@ U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);
 ulong env_get_bootm_low(void)
 {
char *s = env_get("bootm_low");
+
if (s) {
ulong tmp = simple_strtoul(s, NULL, 16);
return tmp;
@@ -131,6 +132,7 @@ phys_size_t env_get_bootm_size(void)
phys_size_t tmp, size;
phys_addr_t start;
char *s = env_get("bootm_size");
+
if (s) {
tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
return tmp;
@@ -155,6 +157,7 @@ phys_size_t env_get_bootm_mapsize(void)
 {
phys_size_t tmp;
char *s = env_get("bootm_mapsize");
+
if (s) {
tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
return tmp;
@@ -179,6 +182,7 @@ void memmove_wd(void *to, void *from, size_t len, ulong 
chunksz)
}
while (len > 0) {
size_t tail = (len > chunksz) ? chunksz : len;
+
WATCHDOG_RESET();
if (to > from) {
to -= tail;
@@ -212,8 +216,8 @@ void memmove_wd(void *to, void *from, size_t len, ulong 
chunksz)
  * kernel start address
  */
 ulong genimg_get_kernel_addr_fit(char * const img_addr,
-const char **fit_uname_config,
-const char **fit_uname_kernel)
+const char **fit_uname_config,
+const char **fit_uname_kernel)
 {
ulong kernel_addr;
 
@@ -319,7 +323,7 @@ int genimg_has_config(bootm_headers_t *images)
  * @rd_end: pointer to a ulong variable, will hold ramdisk end
  *
  * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
- * Curently supported are the following ramdisk sources:
+ * Currently supported are the following ramdisk sources:
  *  - multicomponent kernel/ramdisk image,
  *  - commandline provided address of decicated ramdisk image.
  *
@@ -332,7 +336,7 @@ int genimg_has_config(bootm_headers_t *images)
  * rd_start and rd_end are set to 0 if no ramdisk exists
  */
 int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
-uint8_t arch, ulong *rd_start, ulong *rd_end)
+u8 arch, ulong *rd_start, ulong *rd_end)
 {
ulong rd_addr, rd_load;
ulong rd_data, rd_len;
@@ -372,7 +376,8 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
 */
if (select && strcmp(select, "-") ==  0) {
debug("## Skipping init Ramdisk\n");
-   rd_len = rd_data = 0;
+   rd_len = 0;
+   rd_data = 0;
} else if (select || genimg_has_config(images)) {
 #if IMAGE_ENABLE_FIT
if (select) {
@@ -389,21 +394,19 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
 
if (fit_parse_conf(select, default_addr,
   _addr, _uname_config)) {
-   debug("*  ramdisk: config '%s' from image at "
-   "0x%08lx\n",
-   fit_uname_config, rd_addr);
+   debug("*  ramdisk: config '%s' from image at 
0x%08lx\n",
+   

[PATCH 24/49] image: Rename CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT

2021-05-03 Thread Simon Glass
Drop the ENABLE and SUPPORT parts of this, which are redundant.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/Kconfig.boot | 2 +-
 common/image-sig.c  | 4 ++--
 configs/bcm963158_ram_defconfig | 2 +-
 configs/sandbox_defconfig   | 2 +-
 include/image.h | 2 +-
 include/u-boot/rsa.h| 8 
 lib/rsa/rsa-sign.c  | 4 ++--
 lib/rsa/rsa-verify.c| 2 +-
 8 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/common/Kconfig.boot b/common/Kconfig.boot
index af3325a7ce2..03a6e6f214f 100644
--- a/common/Kconfig.boot
+++ b/common/Kconfig.boot
@@ -103,7 +103,7 @@ config FIT_SIGNATURE_MAX_SIZE
  device memory. Assure this size does not extend past expected storage
  space.
 
-config FIT_ENABLE_RSASSA_PSS_SUPPORT
+config FIT_RSASSA_PSS
bool "Support rsassa-pss signature scheme of FIT image contents"
depends on FIT_SIGNATURE
default n
diff --git a/common/image-sig.c b/common/image-sig.c
index 12310bfca1a..31a4fd46061 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -100,12 +100,12 @@ struct padding_algo padding_algos[] = {
.name = "pkcs-1.5",
.verify = padding_pkcs_15_verify,
},
-#ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
+#ifdef CONFIG_FIT_RSASSA_PSS
{
.name = "pss",
.verify = padding_pss_verify,
}
-#endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
+#endif /* CONFIG_FIT_RSASSA_PSS */
 };
 
 struct checksum_algo *image_get_checksum_algo(const char *full_name)
diff --git a/configs/bcm963158_ram_defconfig b/configs/bcm963158_ram_defconfig
index 0be1e0981ab..ec006514d13 100644
--- a/configs/bcm963158_ram_defconfig
+++ b/configs/bcm963158_ram_defconfig
@@ -11,7 +11,7 @@ CONFIG_DEFAULT_DEVICE_TREE="bcm963158"
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
-CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT=y
+CONFIG_FIT_RSASSA_PSS=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_SUPPORT_RAW_INITRD=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 33446322a46..b4aa2dec7ec 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -10,7 +10,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
-CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT=y
+CONFIG_FIT_RSASSA_PSS=y
 CONFIG_FIT_CIPHER=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_BOOTSTAGE=y
diff --git a/include/image.h b/include/image.h
index b08ae2bb6c0..0356d03b2ce 100644
--- a/include/image.h
+++ b/include/image.h
@@ -28,7 +28,7 @@ struct fdt_region;
 #include 
 
 /* new uImage format support enabled on host */
-#define CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT 1
+#define CONFIG_FIT_RSASSA_PSS 1
 
 #define IMAGE_ENABLE_IGNORE0
 #define IMAGE_INDENT_STRING""
diff --git a/include/u-boot/rsa.h b/include/u-boot/rsa.h
index bed1c097c2c..bc564d56fa3 100644
--- a/include/u-boot/rsa.h
+++ b/include/u-boot/rsa.h
@@ -119,11 +119,11 @@ int padding_pkcs_15_verify(struct image_sign_info *info,
   uint8_t *msg, int msg_len,
   const uint8_t *hash, int hash_len);
 
-#ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
+#ifdef CONFIG_FIT_RSASSA_PSS
 int padding_pss_verify(struct image_sign_info *info,
   uint8_t *msg, int msg_len,
   const uint8_t *hash, int hash_len);
-#endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
+#endif /* CONFIG_FIT_RSASSA_PSS */
 #else
 static inline int rsa_verify_hash(struct image_sign_info *info,
  const uint8_t *hash,
@@ -146,14 +146,14 @@ static inline int padding_pkcs_15_verify(struct 
image_sign_info *info,
return -ENXIO;
 }
 
-#ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
+#ifdef CONFIG_FIT_RSASSA_PSS
 static inline int padding_pss_verify(struct image_sign_info *info,
 uint8_t *msg, int msg_len,
 const uint8_t *hash, int hash_len)
 {
return -ENXIO;
 }
-#endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
+#endif /* CONFIG_FIT_RSASSA_PSS */
 #endif
 
 #define RSA_DEFAULT_PADDING_NAME   "pkcs-1.5"
diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
index 5a1583b8f75..f4ed11e74a4 100644
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
@@ -442,7 +442,7 @@ static int rsa_sign_with_key(EVP_PKEY *pkey, struct 
padding_algo *padding_algo,
goto err_sign;
}
 
-#ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
+#ifdef CONFIG_FIT_RSASSA_PSS
if (padding_algo && !strcmp(padding_algo->name, "pss")) {
if (EVP_PKEY_CTX_set_rsa_padding(ckey,
 RSA_PKCS1_PSS_PADDING) <= 0) {
@@ -450,7 +450,7 @@ static int rsa_sign_with_key(EVP_PKEY *pkey, struct 
padding_algo *padding_algo,
goto err_sign;
}
}
-#endif /* 

[PATCH 16/49] kconfig: Add host support to CONFIG_IS_ENABLED()

2021-05-03 Thread Simon Glass
At present we must separately test for the host build for many options,
since we force them to be enabled. For example, CONFIG_FIT is always
enabled in the host tools, even if CONFIG_FIT is not enabled by the
board itself.

It would be more convenient if we could use, for example,
CONFIG_IS_ENABLED(FIT) and get CONFIG_HOST_FIT, when building for the
host. Add support for this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/linux/kconfig.h | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index d109ed3119e..6216b58625f 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -31,11 +31,14 @@
(config_enabled(option))
 
 /*
- * U-Boot add-on: Helper macros to reference to different macros
- * (CONFIG_ or CONFIG_SPL_ prefixed), depending on the build context.
+ * U-Boot add-on: Helper macros to reference to different macros (prefixed by
+ * CONFIG_, CONFIG_SPL_, CONFIG_TPL or CONFIG_HOST), depending on the build
+ * context.
  */
 
-#if defined(CONFIG_TPL_BUILD)
+#ifdef USE_HOSTCC
+#define _CONFIG_PREFIX HOST_
+#elif defined(CONFIG_TPL_BUILD)
 #define _CONFIG_PREFIX TPL_
 #elif defined(CONFIG_SPL_BUILD)
 #define _CONFIG_PREFIX SPL_
@@ -49,6 +52,7 @@
 
 /*
  * CONFIG_VAL(FOO) evaluates to the value of
+ *  CONFIG_HOST_FOO if USE_HOSTCC is undefined,
  *  CONFIG_FOO if CONFIG_SPL_BUILD is undefined,
  *  CONFIG_SPL_FOO if CONFIG_SPL_BUILD is defined.
  *  CONFIG_TPL_FOO if CONFIG_TPL_BUILD is defined.
@@ -76,18 +80,21 @@
 
 /*
  * CONFIG_IS_ENABLED(FOO) expands to
+ *  1 if USE_HOSTCC is defined and CONFIG_HOST_FOO is set to 'y',
  *  1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y',
  *  1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y',
  *  1 if CONFIG_TPL_BUILD is defined and CONFIG_TPL_FOO is set to 'y',
  *  0 otherwise.
  *
  * CONFIG_IS_ENABLED(FOO, (abc)) expands to
+ *  abc if USE_HOSTCC is defined and CONFIG_HOST_FOO is set to 'y',
  *  abc if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y',
  *  abc if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y',
  *  abc if CONFIG_TPL_BUILD is defined and CONFIG_TPL_FOO is set to 'y',
  *  nothing otherwise.
  *
  * CONFIG_IS_ENABLED(FOO, (abc), (def)) expands to
+ *  abc if USE_HOSTCC is defined and CONFIG_HOST_FOO is set to 'y',
  *  abc if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y',
  *  abc if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y',
  *  abc if CONFIG_TPL_BUILD is defined and CONFIG_TPL_FOO is set to 'y',
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 45/49] image: Remove #ifdefs from select_ramdisk()

2021-05-03 Thread Simon Glass
Use boolean variables to deal with the strange #ifdef logic of this
function, so we can remove the #ifdefs.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-board.c | 139 ++-
 1 file changed, 72 insertions(+), 67 deletions(-)

diff --git a/common/image-board.c b/common/image-board.c
index c32fff96ece..0c057e77951 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -26,7 +26,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
 /**
  * image_get_ramdisk - get and verify ramdisk image
  * @rd_addr: ramdisk image start address
@@ -85,7 +84,6 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, 
u8 arch,
 
return rd_hdr;
 }
-#endif
 
 /*/
 /* Shared dual-format routines */
@@ -326,16 +324,18 @@ int genimg_has_config(bootm_headers_t *images)
 static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch,
  ulong *rd_datap, ulong *rd_lenp)
 {
-   ulong rd_addr, rd_load;
+   ulong rd_addr = 0, rd_load;
char *buf;
+   const char *fit_uname_config = images->fit_uname_cfg;
+   const char *fit_uname_ramdisk = NULL;
+   bool processed;
+   int rd_noffset;
 
-#if CONFIG_IS_ENABLED(FIT)
-   const char *fit_uname_config = images->fit_uname_cfg;
-   const char *fit_uname_ramdisk = NULL;
-   int rd_noffset;
+   if (select) {
+   ulong default_addr;
+   bool done = true;
 
-   if (select) {
-   ulong default_addr;
+   if (CONFIG_IS_ENABLED(FIT)) {
/*
 * If the init ramdisk comes from the FIT image and
 * the FIT image address is omitted in the command
@@ -347,8 +347,8 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
else
default_addr = image_load_addr;
 
-   if (fit_parse_conf(select, default_addr,
-  _addr, _uname_config)) {
+   if (fit_parse_conf(select, default_addr, _addr,
+  _uname_config)) {
debug("*  ramdisk: config '%s' from image at 
0x%08lx\n",
  fit_uname_config, rd_addr);
} else if (fit_parse_subimage(select, default_addr,
@@ -356,61 +356,59 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
  _uname_ramdisk)) {
debug("*  ramdisk: subimage '%s' from image at 
0x%08lx\n",
  fit_uname_ramdisk, rd_addr);
-   } else
-#endif
-   {
-   rd_addr = simple_strtoul(select, NULL, 16);
-   debug("*  ramdisk: cmdline image address = 
0x%08lx\n",
- rd_addr);
+   } else {
+   done = false;
}
-#if CONFIG_IS_ENABLED(FIT)
-   } else {
-   /* use FIT configuration provided in first bootm
-* command argument. If the property is not defined,
-* quit silently (with -ENOPKG)
-*/
-   rd_addr = map_to_sysmem(images->fit_hdr_os);
-   rd_noffset = fit_get_node_from_config(images,
- FIT_RAMDISK_PROP,
- rd_addr);
-   if (rd_noffset == -ENOENT)
-   return -ENOPKG;
-   else if (rd_noffset < 0)
-   return rd_noffset;
}
-#endif
-
-   /*
-* Check if there is an initrd image at the
-* address provided in the second bootm argument
-* check image type, for FIT images get FIT node.
+   if (!done) {
+   rd_addr = simple_strtoul(select, NULL, 16);
+   debug("*  ramdisk: cmdline image address = 0x%08lx\n",
+ rd_addr);
+   }
+   } else if (CONFIG_IS_ENABLED(FIT)) {
+   /* use FIT configuration provided in first bootm
+* command argument. If the property is not defined,
+* quit silently (with -ENOPKG  )
 */
-   buf = map_sysmem(rd_addr, 0);
-   switch (genimg_get_format(buf)) {
-#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
-   case IMAGE_FORMAT_LEGACY: 

[PATCH 48/49] image: Split up boot_get_fdt()

2021-05-03 Thread Simon Glass
This function is far too long. Before trying to remove #ifdefs, split out
the code that deals with selecting the FDT into a separate function.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fdt.c | 319 -
 1 file changed, 173 insertions(+), 146 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index 524adbd1339..c17c23e1295 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -244,6 +244,173 @@ error:
return 1;
 }
 
+/**
+ * select_fdt() - Select and locate the FDT to use
+ *
+ * @images: pointer to the bootm images structure
+ * @select: name of FDT to select, or NULL for any
+ * @arch: expected FDT architecture
+ * @fdt_addrp: pointer to a ulong variable, will hold FDT pointer
+ * @return 0 if OK, -ENOPKG if no FDT (but an error should not be reported),
+ * other -ve value on other error
+ */
+
+static int select_fdt(bootm_headers_t *images, const char *select, u8 arch,
+ ulong *fdt_addrp)
+{
+   const char *buf;
+   ulong fdt_addr;
+
+#if CONFIG_IS_ENABLED(FIT)
+   const char *fit_uname_config = images->fit_uname_cfg;
+   const char *fit_uname_fdt = NULL;
+   ulong default_addr;
+   int fdt_noffset;
+
+   if (select) {
+   /*
+* If the FDT blob comes from the FIT image and the
+* FIT image address is omitted in the command line
+* argument, try to use ramdisk or os FIT image
+* address or default load address.
+*/
+   if (images->fit_uname_rd)
+   default_addr = (ulong)images->fit_hdr_rd;
+   else if (images->fit_uname_os)
+   default_addr = (ulong)images->fit_hdr_os;
+   else
+   default_addr = image_load_addr;
+
+   if (fit_parse_conf(select, default_addr, _addr,
+  _uname_config)) {
+   debug("*  fdt: config '%s' from image at 0x%08lx\n",
+ fit_uname_config, fdt_addr);
+   } else if (fit_parse_subimage(select, default_addr, _addr,
+  _uname_fdt)) {
+   debug("*  fdt: subimage '%s' from image at 0x%08lx\n",
+ fit_uname_fdt, fdt_addr);
+   } else
+#endif
+   {
+   fdt_addr = simple_strtoul(select, NULL, 16);
+   debug("*  fdt: cmdline image address = 0x%08lx\n",
+ fdt_addr);
+   }
+#if CONFIG_IS_ENABLED(FIT)
+   } else {
+   /* use FIT configuration provided in first bootm
+* command argument
+*/
+   fdt_addr = map_to_sysmem(images->fit_hdr_os);
+   fdt_noffset = fit_get_node_from_config(images, FIT_FDT_PROP,
+  fdt_addr);
+   if (fdt_noffset == -ENOENT)
+   return -ENOPKG;
+   else if (fdt_noffset < 0)
+   return fdt_noffset;
+   }
+#endif
+   debug("## Checking for 'FDT'/'FDT Image' at %08lx\n",
+ fdt_addr);
+
+   /*
+* Check if there is an FDT image at the
+* address provided in the second bootm argument
+* check image type, for FIT images get a FIT node.
+*/
+   buf = map_sysmem(fdt_addr, 0);
+   switch (genimg_get_format(buf)) {
+#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
+   case IMAGE_FORMAT_LEGACY: {
+   const image_header_t *fdt_hdr;
+   ulong load, load_end;
+   ulong image_start, image_data, image_end;
+
+   /* verify fdt_addr points to a valid image header */
+   printf("## Flattened Device Tree from Legacy Image at %08lx\n",
+  fdt_addr);
+   fdt_hdr = image_get_fdt(fdt_addr);
+   if (!fdt_hdr)
+   return -ENOPKG;
+
+   /*
+* move image data to the load address,
+* make sure we don't overwrite initial image
+*/
+   image_start = (ulong)fdt_hdr;
+   image_data = (ulong)image_get_data(fdt_hdr);
+   image_end = image_get_image_end(fdt_hdr);
+
+   load = image_get_load(fdt_hdr);
+   load_end = load + image_get_data_size(fdt_hdr);
+
+   if (load == image_start ||
+   load == image_data) {
+   fdt_addr = load;
+   break;
+   }
+
+   if ((load < image_end) && (load_end > image_start)) {
+   fdt_error("fdt overwritten");
+   return -EFAULT;
+   }
+
+   debug("   Loading FDT from 0x%08lx to 0x%08lx\n",
+ image_data, load);
+
+  

[PATCH 36/49] image: Drop IMAGE_ENABLE_SIGN/VERIFY defines

2021-05-03 Thread Simon Glass
Add host Kconfigs for FIT_SIGN and RSA_VERIFY. With these we can use
CONFIG_IS_ENABLED() directly in the host build, so drop the unnecessary
indirections IMAGE_ENABLE_SIGN and HOST_RSA_VERIFY. Also drop
FIT_IMAGE_ENABLE_VERIFY which is not actually used.

Leave IMAGE_ENABLE_VERIFY_ECDSA along since this feature is incomplete
and needs to be integrated with RSA.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fit.c |  6 +++---
 common/image-sig.c | 10 +-
 include/image.h| 13 ++---
 include/u-boot/ecdsa.h |  2 +-
 include/u-boot/rsa.h   |  4 ++--
 tools/Kconfig  | 10 ++
 tools/image-host.c |  4 ++--
 7 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index c13ff6bba24..e81a0858dc1 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1301,7 +1301,7 @@ int fit_image_verify_with_data(const void *fit, int 
image_noffset,
int ret;
 
/* Verify all required signatures */
-   if (FIT_IMAGE_ENABLE_VERIFY &&
+   if (CONFIG_IS_ENABLED(RSA_VERIFY) &&
fit_image_verify_required_sigs(fit, image_noffset, data, size,
   gd_fdt_blob(), _all)) {
err_msg = "Unable to verify required signature";
@@ -1323,7 +1323,7 @@ int fit_image_verify_with_data(const void *fit, int 
image_noffset,
 _msg))
goto error;
puts("+ ");
-   } else if (FIT_IMAGE_ENABLE_VERIFY && verify_all &&
+   } else if (CONFIG_IS_ENABLED(RSA_VERIFY) && verify_all &&
!strncmp(name, FIT_SIG_NODENAME,
strlen(FIT_SIG_NODENAME))) {
ret = fit_image_check_sig(fit, noffset, data,
@@ -2045,7 +2045,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
if (image_type == IH_TYPE_KERNEL)
images->fit_uname_cfg = fit_base_uname_config;
 
-   if (FIT_IMAGE_ENABLE_VERIFY && images->verify) {
+   if (CONFIG_IS_ENABLED(RSA_VERIFY) && images->verify) {
puts("   Verifying Hash Integrity ... ");
if (fit_config_verify(fit, cfg_noffset)) {
puts("Bad Data Hash\n");
diff --git a/common/image-sig.c b/common/image-sig.c
index bbc6bb3b1e3..74ca96a39e9 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -29,7 +29,7 @@ struct checksum_algo checksum_algos[] = {
.checksum_len = SHA1_SUM_LEN,
.der_len = SHA1_DER_LEN,
.der_prefix = sha1_der_prefix,
-#if IMAGE_ENABLE_SIGN
+#if CONFIG_IS_ENABLED(FIT_SIGN)
.calculate_sign = EVP_sha1,
 #endif
.calculate = hash_calculate,
@@ -39,7 +39,7 @@ struct checksum_algo checksum_algos[] = {
.checksum_len = SHA256_SUM_LEN,
.der_len = SHA256_DER_LEN,
.der_prefix = sha256_der_prefix,
-#if IMAGE_ENABLE_SIGN
+#if CONFIG_IS_ENABLED(FIT_SIGN)
.calculate_sign = EVP_sha256,
 #endif
.calculate = hash_calculate,
@@ -50,7 +50,7 @@ struct checksum_algo checksum_algos[] = {
.checksum_len = SHA384_SUM_LEN,
.der_len = SHA384_DER_LEN,
.der_prefix = sha384_der_prefix,
-#if IMAGE_ENABLE_SIGN
+#if CONFIG_IS_ENABLED(FIT_SIGN)
.calculate_sign = EVP_sha384,
 #endif
.calculate = hash_calculate,
@@ -62,7 +62,7 @@ struct checksum_algo checksum_algos[] = {
.checksum_len = SHA512_SUM_LEN,
.der_len = SHA512_DER_LEN,
.der_prefix = sha512_der_prefix,
-#if IMAGE_ENABLE_SIGN
+#if CONFIG_IS_ENABLED(FIT_SIGN)
.calculate_sign = EVP_sha512,
 #endif
.calculate = hash_calculate,
@@ -122,7 +122,7 @@ struct checksum_algo *image_get_checksum_algo(const char 
*full_name)
struct checksum_algo *algo = _algos[i];
 
MANUAL_RELOC(algo->name);
-#if IMAGE_ENABLE_SIGN
+#if CONFIG_IS_ENABLED(FIT_SIGN)
MANUAL_RELOC(algo->calculate_sign);
 #endif
MANUAL_RELOC(algo->calculate);
diff --git a/include/image.h b/include/image.h
index 64866c609f4..12043abd049 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1139,22 +1139,13 @@ int calculate_hash(const void *data, int data_len, 
const char *algo,
  */
 #if defined(USE_HOSTCC)
 # if defined(CONFIG_FIT_SIGNATURE)
-#  define IMAGE_ENABLE_SIGN1
-#  define IMAGE_ENABLE_VERIFY  1
 #  define IMAGE_ENABLE_VERIFY_ECDSA1
-#  define FIT_IMAGE_ENABLE_VERIFY  1
 #  include 
 # else
-#  define IMAGE_ENABLE_SIGN0
-#  define IMAGE_ENABLE_VERIFY  0
 # define IMAGE_ENABLE_VERIFY_ECDSA 0
-#  define FIT_IMAGE_ENABLE_VERIFY 

[PATCH 31/49] image: Drop IMAGE_ENABLE_SHAxxx

2021-05-03 Thread Simon Glass
We already have a host Kconfig for these SHA options. Use
CONFIG_IS_ENABLED(SHAxxx) directly in the code shared with the host build,
so we can drop the unnecessary indirections.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fit.c |  6 +++---
 include/image.h| 21 -
 2 files changed, 3 insertions(+), 24 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 96794074b63..070835b3a87 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1222,15 +1222,15 @@ int calculate_hash(const void *data, int data_len, 
const char *algo,
sha1_csum_wd((unsigned char *)data, data_len,
 (unsigned char *)value, CHUNKSZ_SHA1);
*value_len = 20;
-   } else if (IMAGE_ENABLE_SHA256 && strcmp(algo, "sha256") == 0) {
+   } else if (CONFIG_IS_ENABLED(SHA256) && strcmp(algo, "sha256") == 0) {
sha256_csum_wd((unsigned char *)data, data_len,
   (unsigned char *)value, CHUNKSZ_SHA256);
*value_len = SHA256_SUM_LEN;
-   } else if (IMAGE_ENABLE_SHA384 && strcmp(algo, "sha384") == 0) {
+   } else if (CONFIG_IS_ENABLED(SHA384) && strcmp(algo, "sha384") == 0) {
sha384_csum_wd((unsigned char *)data, data_len,
   (unsigned char *)value, CHUNKSZ_SHA384);
*value_len = SHA384_SUM_LEN;
-   } else if (IMAGE_ENABLE_SHA512 && strcmp(algo, "sha512") == 0) {
+   } else if (CONFIG_IS_ENABLED(SHA512) && strcmp(algo, "sha512") == 0) {
sha512_csum_wd((unsigned char *)data, data_len,
   (unsigned char *)value, CHUNKSZ_SHA512);
*value_len = SHA512_SUM_LEN;
diff --git a/include/image.h b/include/image.h
index f5ff77bf0ca..f4b8dd7dd0f 100644
--- a/include/image.h
+++ b/include/image.h
@@ -47,27 +47,6 @@ struct fdt_region;
 #include 
 #include 
 
-#if defined(CONFIG_FIT_SHA256) || \
-   defined(CONFIG_SPL_FIT_SHA256)
-#define IMAGE_ENABLE_SHA2561
-#else
-#define IMAGE_ENABLE_SHA2560
-#endif
-
-#if defined(CONFIG_FIT_SHA384) || \
-   defined(CONFIG_SPL_FIT_SHA384)
-#define IMAGE_ENABLE_SHA3841
-#else
-#define IMAGE_ENABLE_SHA3840
-#endif
-
-#if defined(CONFIG_FIT_SHA512) || \
-   defined(CONFIG_SPL_FIT_SHA512)
-#define IMAGE_ENABLE_SHA5121
-#else
-#define IMAGE_ENABLE_SHA5120
-#endif
-
 #endif /* FIT */
 
 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 47/49] image: Reduce variable scope in boot_get_fdt()

2021-05-03 Thread Simon Glass
Move the variables declarations to where they are needed, to reduce the
number of #ifdefs needed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fdt.c | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index 80bfa625ab2..524adbd1339 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -269,21 +269,10 @@ error:
 int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
 bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
 {
-#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
-   const image_header_t *fdt_hdr;
-   ulong   load, load_end;
-   ulong   image_start, image_data, image_end;
-#endif
ulong   img_addr;
ulong   fdt_addr;
char*fdt_blob = NULL;
void*buf;
-#if CONFIG_IS_ENABLED(FIT)
-   const char  *fit_uname_config = images->fit_uname_cfg;
-   const char  *fit_uname_fdt = NULL;
-   ulong   default_addr;
-   int fdt_noffset;
-#endif
const char *select = NULL;
 
*of_flat_tree = NULL;
@@ -297,6 +286,11 @@ int boot_get_fdt(int flag, int argc, char *const argv[], 
uint8_t arch,
select = argv[2];
if (select || genimg_has_config(images)) {
 #if CONFIG_IS_ENABLED(FIT)
+   const char *fit_uname_config = images->fit_uname_cfg;
+   const char *fit_uname_fdt = NULL;
+   ulong default_addr;
+   int fdt_noffset;
+
if (select) {
/*
 * If the FDT blob comes from the FIT image and the
@@ -352,7 +346,11 @@ int boot_get_fdt(int flag, int argc, char *const argv[], 
uint8_t arch,
buf = map_sysmem(fdt_addr, 0);
switch (genimg_get_format(buf)) {
 #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
-   case IMAGE_FORMAT_LEGACY:
+   case IMAGE_FORMAT_LEGACY: {
+   const image_header_t *fdt_hdr;
+   ulong load, load_end;
+   ulong image_start, image_data, image_end;
+
/* verify fdt_addr points to a valid image header */
printf("## Flattened Device Tree from Legacy Image at 
%08lx\n",
   fdt_addr);
@@ -391,6 +389,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], 
uint8_t arch,
 
fdt_addr = load;
break;
+   }
 #endif
case IMAGE_FORMAT_FIT:
/*
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 42/49] image: Drop most #ifdefs in image-board.c

2021-05-03 Thread Simon Glass
Remove ifdefs in this file, so far as possible without too much
refactoring.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-board.c | 109 +++
 include/image.h  |   7 ++-
 2 files changed, 53 insertions(+), 63 deletions(-)

diff --git a/common/image-board.c b/common/image-board.c
index 1a3b0bc7efc..0543c67d3bd 100644
--- a/common/image-board.c
+++ b/common/image-board.c
@@ -227,16 +227,16 @@ ulong genimg_get_kernel_addr_fit(char * const img_addr,
kernel_addr = image_load_addr;
debug("*  kernel: default image load address = 0x%08lx\n",
  image_load_addr);
-#if CONFIG_IS_ENABLED(FIT)
-   } else if (fit_parse_conf(img_addr, image_load_addr, _addr,
+   } else if (CONFIG_IS_ENABLED(FIT) &&
+  fit_parse_conf(img_addr, image_load_addr, _addr,
  fit_uname_config)) {
debug("*  kernel: config '%s' from image at 0x%08lx\n",
  *fit_uname_config, kernel_addr);
-   } else if (fit_parse_subimage(img_addr, image_load_addr, _addr,
-fit_uname_kernel)) {
+   } else if (CONFIG_IS_ENABLED(FIT) &&
+  fit_parse_subimage(img_addr, image_load_addr, _addr,
+ fit_uname_kernel)) {
debug("*  kernel: subimage '%s' from image at 0x%08lx\n",
  *fit_uname_kernel, kernel_addr);
-#endif
} else {
kernel_addr = simple_strtoul(img_addr, NULL, 16);
debug("*  kernel: cmdline image address = 0x%08lx\n",
@@ -275,21 +275,20 @@ ulong genimg_get_kernel_addr(char * const img_addr)
  */
 int genimg_get_format(const void *img_addr)
 {
-#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
-   const image_header_t *hdr;
+   if (CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)) {
+   const image_header_t *hdr;
 
-   hdr = (const image_header_t *)img_addr;
-   if (image_check_magic(hdr))
-   return IMAGE_FORMAT_LEGACY;
-#endif
-#if CONFIG_IS_ENABLED(FIT) || CONFIG_IS_ENABLED(OF_LIBFDT)
-   if (fdt_check_header(img_addr) == 0)
-   return IMAGE_FORMAT_FIT;
-#endif
-#ifdef CONFIG_ANDROID_BOOT_IMAGE
-   if (android_image_check_header(img_addr) == 0)
+   hdr = (const image_header_t *)img_addr;
+   if (image_check_magic(hdr))
+   return IMAGE_FORMAT_LEGACY;
+   }
+   if (CONFIG_IS_ENABLED(FIT) || CONFIG_IS_ENABLED(OF_LIBFDT)) {
+   if (!fdt_check_header(img_addr))
+   return IMAGE_FORMAT_FIT;
+   }
+   if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE) &&
+   !android_image_check_header(img_addr))
return IMAGE_FORMAT_ANDROID;
-#endif
 
return IMAGE_FORMAT_INVALID;
 }
@@ -307,10 +306,9 @@ int genimg_get_format(const void *img_addr)
  */
 int genimg_has_config(bootm_headers_t *images)
 {
-#if CONFIG_IS_ENABLED(FIT)
-   if (images->fit_uname_cfg)
+   if (CONFIG_IS_ENABLED(FIT) && images->fit_uname_cfg)
return 1;
-#endif
+
return 0;
 }
 
@@ -345,9 +343,6 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
const image_header_t *rd_hdr;
 #endif
void *buf;
-#ifdef CONFIG_SUPPORT_RAW_INITRD
-   char *end;
-#endif
 #if CONFIG_IS_ENABLED(FIT)
const char  *fit_uname_config = images->fit_uname_cfg;
const char  *fit_uname_ramdisk = NULL;
@@ -359,14 +354,12 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
*rd_start = 0;
*rd_end = 0;
 
-#ifdef CONFIG_ANDROID_BOOT_IMAGE
-   /*
-* Look for an Android boot image.
-*/
-   buf = map_sysmem(images->os.start, 0);
-   if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID)
-   select = (argc == 0) ? env_get("loadaddr") : argv[0];
-#endif
+   if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) {
+   /* Look for an Android boot image */
+   buf = map_sysmem(images->os.start, 0);
+   if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID)
+   select = (argc == 0) ? env_get("loadaddr") : argv[0];
+   }
 
if (argc >= 2)
select = argv[1];
@@ -474,22 +467,20 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
break;
 #endif
default:
-#ifdef CONFIG_SUPPORT_RAW_INITRD
-   end = NULL;
-   if (select)
-   end = strchr(select, ':');
-   if (end) {
-   rd_len = simple_strtoul(++end, NULL, 16);
-   rd_data = rd_addr;
-   } else
-#endif
-   {
-   puts("Wrong Ramdisk Image 

[PATCH 15/49] image: Add Kconfig options for FIT in the host build

2021-05-03 Thread Simon Glass
In preparation for enabling CONFIG_IS_ENABLED() on the host build, add
some options to enable the various FIT options expected in these tools.
This will ensure that the code builds correctly when CONFIG_HOST_xxx
is distinct from CONFIG_xxx.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-fit-sig.c |  3 ++-
 common/image-fit.c |  4 ++--
 tools/Kconfig  | 25 +
 tools/Makefile | 18 +-
 4 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
index 55ddf1879ed..12a6745c642 100644
--- a/common/image-fit-sig.c
+++ b/common/image-fit-sig.c
@@ -72,11 +72,12 @@ static int fit_image_setup_verify(struct image_sign_info 
*info,
char *algo_name;
const char *padding_name;
 
+#ifndef USE_HOSTCC
if (fdt_totalsize(fit) > CONFIG_FIT_SIGNATURE_MAX_SIZE) {
*err_msgp = "Total size too large";
return 1;
}
-
+#endif
if (fit_image_hash_get_algo(fit, noffset, _name)) {
*err_msgp = "Can't get hash algo property";
return -1;
diff --git a/common/image-fit.c b/common/image-fit.c
index e614643fe39..a16e2dd54a5 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -165,7 +165,7 @@ int fit_get_subimage_count(const void *fit, int 
images_noffset)
return count;
 }
 
-#if CONFIG_IS_ENABLED(FIT_PRINT) || CONFIG_IS_ENABLED(SPL_FIT_PRINT)
+#if CONFIG_IS_ENABLED(FIT_PRINT)
 /**
  * fit_image_print_data() - prints out the hash node details
  * @fit: pointer to the FIT format image header
@@ -573,7 +573,7 @@ void fit_image_print(const void *fit, int image_noffset, 
const char *p)
 #else
 void fit_print_contents(const void *fit) { }
 void fit_image_print(const void *fit, int image_noffset, const char *p) { }
-#endif /* CONFIG_IS_ENABLED(FIR_PRINT) || CONFIG_IS_ENABLED(SPL_FIT_PRINT) */
+#endif /* CONFIG_IS_ENABLED(FIT_PRINT) */
 
 /**
  * fit_get_desc - get node description property
diff --git a/tools/Kconfig b/tools/Kconfig
index b2f5012240c..f00ab661135 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -9,4 +9,29 @@ config MKIMAGE_DTC_PATH
  some cases the system dtc may not support all required features
  and the path to a different version should be given here.
 
+config HOST_FIT
+   def_bool y
+   help
+ Enable FIT support in the host build.
+
+config HOST_FIT_FULL_CHECK
+   def_bool y
+   help
+ Do a full check of the FIT before using it in the host build
+
+config HOST_FIT_PRINT
+   def_bool y
+   help
+ Print the content of the FIT verbosely in the host build
+
+config HOST_FIT_SIGNATURE
+   def_bool y
+   help
+ Enable signature verification of FIT uImages in the host build
+
+config HOST_FIT_SIGNATURE_MAX_SIZE
+   hex
+   depends on HOST_FIT_SIGNATURE
+   default 0x1000
+
 endmenu
diff --git a/tools/Makefile b/tools/Makefile
index 2b4bc547abd..d143198f7c9 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -53,12 +53,12 @@ hostprogs-y += mkenvimage
 mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
 
 hostprogs-y += dumpimage mkimage
-hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info fit_check_sign
+hostprogs-$(CONFIG_HOST_FIT_SIGNATURE) += fit_info fit_check_sign
 
 hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST) += file2include
 
-FIT_OBJS-$(CONFIG_FIT) := fit_common.o fit_image.o image-host.o 
common/image-fit.o
-FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := common/image-sig.o 
common/image-fit-sig.o
+FIT_OBJS-$(CONFIG_HOST_FIT) := fit_common.o fit_image.o image-host.o 
common/image-fit.o
+FIT_SIG_OBJS-$(CONFIG_HOST_FIT_SIGNATURE) := common/image-sig.o 
common/image-fit-sig.o
 FIT_CIPHER_OBJS-$(CONFIG_FIT_CIPHER) := common/image-cipher.o
 
 # The following files are synced with upstream DTC.
@@ -66,17 +66,17 @@ FIT_CIPHER_OBJS-$(CONFIG_FIT_CIPHER) := 
common/image-cipher.o
 LIBFDT_OBJS := $(addprefix libfdt/, fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o 
\
fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o)
 
-RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
+RSA_OBJS-$(CONFIG_HOST_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
rsa-sign.o rsa-verify.o \
rsa-mod-exp.o)
 
-ECDSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/ecdsa/, 
ecdsa-libcrypto.o)
+ECDSA_OBJS-$(CONFIG_HOST_FIT_SIGNATURE) := $(addprefix lib/ecdsa/, 
ecdsa-libcrypto.o)
 
 AES_OBJS-$(CONFIG_FIT_CIPHER) := $(addprefix lib/aes/, \
aes-encrypt.o aes-decrypt.o)
 
 # Cryptographic helpers that depend on openssl/libcrypto
-LIBCRYPTO_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/, \
+LIBCRYPTO_OBJS-$(CONFIG_HOST_FIT_SIGNATURE) := $(addprefix lib/, \
fdt-libcrypto.o)
 
 ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rksd.o rkspi.o
@@ -137,13 +137,13 

[PATCH 40/49] image: Drop unnecessary #ifdefs from image.h

2021-05-03 Thread Simon Glass
This file has a lot of conditional code and much of it is unnecessary.
Clean this up to reduce the number of build combinations.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/image.h| 40 --
 include/u-boot/hash-checksum.h |  5 +++--
 lib/hash-checksum.c|  2 +-
 3 files changed, 8 insertions(+), 39 deletions(-)

diff --git a/include/image.h b/include/image.h
index d7e0c829841..a8b10a8fddb 100644
--- a/include/image.h
+++ b/include/image.h
@@ -39,12 +39,10 @@ struct fdt_region;
 
 #endif /* USE_HOSTCC */
 
-#if CONFIG_IS_ENABLED(FIT)
 #include 
 #include 
 #include 
-
-#endif /* FIT */
+#include 
 
 extern ulong image_load_addr;  /* Default Load Address */
 extern ulong image_save_addr;  /* Default Save Address */
@@ -504,8 +502,7 @@ int genimg_get_type_id(const char *name);
 int genimg_get_comp_id(const char *name);
 void genimg_print_size(uint32_t size);
 
-#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
-   defined(USE_HOSTCC)
+#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || 
defined(USE_HOSTCC)
 #define IMAGE_ENABLE_TIMESTAMP 1
 #else
 #define IMAGE_ENABLE_TIMESTAMP 0
@@ -523,12 +520,9 @@ enum fit_load_op {
 int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start,
   ulong *setup_len);
 
-#ifndef USE_HOSTCC
 /* Image format types, returned by _get_format() routine */
 #define IMAGE_FORMAT_INVALID   0x00
-#if defined(CONFIG_LEGACY_IMAGE_FORMAT)
 #define IMAGE_FORMAT_LEGACY0x01/* legacy image_header based format */
-#endif
 #define IMAGE_FORMAT_FIT   0x02/* new, libfdt based format */
 #define IMAGE_FORMAT_ANDROID   0x03/* Android boot image */
 
@@ -567,7 +561,6 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
  */
 int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images,
  uint8_t arch, const ulong *ld_start, ulong *const ld_len);
-#endif /* !USE_HOSTCC */
 
 int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
   ulong *setup_start, ulong *setup_len);
@@ -644,7 +637,6 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
  */
 int image_source_script(ulong addr, const char *fit_uname);
 
-#ifndef USE_HOSTCC
 /**
  * fit_get_node_from_config() - Look up an image a FIT by type
  *
@@ -684,10 +676,7 @@ int boot_relocate_fdt(struct lmb *lmb, char 
**of_flat_tree, ulong *of_size);
 int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
  ulong *initrd_start, ulong *initrd_end);
 int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
-#ifdef CONFIG_SYS_BOOT_GET_KBD
 int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd);
-#endif /* CONFIG_SYS_BOOT_GET_KBD */
-#endif /* !USE_HOSTCC */
 
 /***/
 /* Legacy format specific code (prefixed with image_) */
@@ -802,11 +791,9 @@ static inline int image_check_type(const image_header_t 
*hdr, uint8_t type)
 }
 static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
 {
-#ifndef USE_HOSTCC
/* Let's assume that sandbox can load any architecture */
-   if (IS_ENABLED(CONFIG_SANDBOX))
+   if (!host_build() && IS_ENABLED(CONFIG_SANDBOX))
return true;
-#endif
return (image_get_arch(hdr) == arch) ||
(image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64);
 }
@@ -954,7 +941,6 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong 
*size,
 
 #define FIT_MAX_HASH_LEN   HASH_MAX_DIGEST_SIZE
 
-#if CONFIG_IS_ENABLED(FIT)
 /* cmdline argument format parsing */
 int fit_parse_conf(const char *spec, ulong addr_curr,
ulong *addr, const char **conf_name);
@@ -1128,7 +1114,6 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
 
 int fit_check_ramdisk(const void *fit, int os_noffset,
uint8_t arch, int verify);
-#endif /* FIT */
 
 int calculate_hash(const void *data, int data_len, const char *algo,
uint8_t *value, int *value_len);
@@ -1148,7 +1133,6 @@ int calculate_hash(const void *data, int data_len, const 
char *algo,
 # define IMAGE_ENABLE_VERIFY_ECDSA 0
 #endif
 
-#if CONFIG_IS_ENABLED(FIT)
 #ifdef USE_HOSTCC
 void *image_get_host_blob(void);
 void image_set_host_blob(void *host_blob);
@@ -1157,8 +1141,6 @@ void image_set_host_blob(void *host_blob);
 # define gd_fdt_blob() (gd->fdt_blob)
 #endif
 
-#endif /* FIT */
-
 /*
  * Information passed to the signing routines
  *
@@ -1195,9 +1177,6 @@ struct image_region {
int size;
 };
 
-#if CONFIG_IS_ENABLED(RSA_VERIFY)
-# include 
-#endif
 struct checksum_algo {
const char *name;
const int checksum_len;
@@ -1207,7 +1186,7 @@ struct checksum_algo {
const EVP_MD *(*calculate_sign)(void);
 #endif
int (*calculate)(const char *name,
-

[PATCH 38/49] image: Drop IMAGE_ENABLE_EN/DECRYPT defines

2021-05-03 Thread Simon Glass
Add a host Kconfigs for IMAGE_ENABLE_ENCRYPT. With this we can use
CONFIG_IS_ENABLED() directly in the host build, so drop the unnecessary
indirections IMAGE_IMAGE_ENABLE_ENCRYPT and IMAGE_IMAGE_ENABLE_DECRYPT.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image-cipher.c |  6 +++---
 common/image-fit.c|  2 +-
 include/image.h   | 16 +++-
 include/u-boot/aes.h  |  8 
 tools/Kconfig | 11 +++
 tools/image-host.c|  2 +-
 6 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/common/image-cipher.c b/common/image-cipher.c
index b9061489396..453bab8c492 100644
--- a/common/image-cipher.c
+++ b/common/image-cipher.c
@@ -21,7 +21,7 @@ struct cipher_algo cipher_algos[] = {
.name = "aes128",
.key_len = AES128_KEY_LENGTH,
.iv_len  = AES_BLOCK_LENGTH,
-#if IMAGE_ENABLE_ENCRYPT
+#if CONFIG_IS_ENABLED(FIT_CIPHER_ENCRYPT)
.calculate_type = EVP_aes_128_cbc,
 #endif
.encrypt = image_aes_encrypt,
@@ -32,7 +32,7 @@ struct cipher_algo cipher_algos[] = {
.name = "aes192",
.key_len = AES192_KEY_LENGTH,
.iv_len  = AES_BLOCK_LENGTH,
-#if IMAGE_ENABLE_ENCRYPT
+#if CONFIG_IS_ENABLED(FIT_CIPHER_ENCRYPT)
.calculate_type = EVP_aes_192_cbc,
 #endif
.encrypt = image_aes_encrypt,
@@ -43,7 +43,7 @@ struct cipher_algo cipher_algos[] = {
.name = "aes256",
.key_len = AES256_KEY_LENGTH,
.iv_len  = AES_BLOCK_LENGTH,
-#if IMAGE_ENABLE_ENCRYPT
+#if CONFIG_IS_ENABLED(FIT_CIPHER_ENCRYPT)
.calculate_type = EVP_aes_256_cbc,
 #endif
.encrypt = image_aes_encrypt,
diff --git a/common/image-fit.c b/common/image-fit.c
index a0987fd52c8..3ee306143b3 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -2132,7 +2132,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
}
 
/* Decrypt data before uncompress/move */
-   if (IS_ENABLED(CONFIG_FIT_CIPHER) && IMAGE_ENABLE_DECRYPT) {
+   if (IS_ENABLED(CONFIG_FIT_CIPHER) && CONFIG_IS_ENABLED(FIT_CIPHER)) {
puts("   Decrypting Data ... ");
if (fit_image_uncipher(fit, noffset, , )) {
puts("Error\n");
diff --git a/include/image.h b/include/image.h
index b388684cbdc..9adbda8ab70 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1368,18 +1368,8 @@ static inline int fit_image_check_target_arch(const void 
*fdt, int node)
  * At present we only support ciphering on the host, and unciphering on the
  * device
  */
-#if defined(USE_HOSTCC)
-# if defined(CONFIG_FIT_CIPHER)
-#  define IMAGE_ENABLE_ENCRYPT 1
-#  define IMAGE_ENABLE_DECRYPT 1
-#  include 
-# else
-#  define IMAGE_ENABLE_ENCRYPT 0
-#  define IMAGE_ENABLE_DECRYPT 0
-# endif
-#else
-# define IMAGE_ENABLE_ENCRYPT  0
-# define IMAGE_ENABLE_DECRYPT  CONFIG_IS_ENABLED(FIT_CIPHER)
+#if CONFIG_IS_ENABLED(FIT_CIPHER_ENCRYPT)
+#include 
 #endif
 
 /* Information passed to the ciphering routines */
@@ -1402,7 +1392,7 @@ struct cipher_algo {
int key_len;/* Length of the key */
int iv_len; /* Length of the IV */
 
-#if IMAGE_ENABLE_ENCRYPT
+#if CONFIG_IS_ENABLED(FIT_CIPHER_ENCRYPT)
const EVP_CIPHER * (*calculate_type)(void);
 #endif
 
diff --git a/include/u-boot/aes.h b/include/u-boot/aes.h
index acbc50b9e6f..1c064610952 100644
--- a/include/u-boot/aes.h
+++ b/include/u-boot/aes.h
@@ -9,7 +9,7 @@
 #include 
 #include 
 
-#if IMAGE_ENABLE_ENCRYPT
+#if CONFIG_IS_ENABLED(FIT_CIPHER_ENCRYPT)
 int image_aes_encrypt(struct image_cipher_info *info,
  const unsigned char *data, int size,
  unsigned char **cipher, int *cipher_len);
@@ -28,9 +28,9 @@ int image_aes_add_cipher_data(struct image_cipher_info *info, 
void *keydest,
 {
return -ENXIO;
 }
-#endif /* IMAGE_ENABLE_ENCRYPT */
+#endif /* FIT_CIPHER_ENCRYPT */
 
-#if IMAGE_ENABLE_DECRYPT
+#if CONFIG_IS_ENABLED(FIT_CIPHER)
 int image_aes_decrypt(struct image_cipher_info *info,
  const void *cipher, size_t cipher_len,
  void **data, size_t *size);
@@ -41,6 +41,6 @@ int image_aes_decrypt(struct image_cipher_info *info,
 {
return -ENXIO;
 }
-#endif /* IMAGE_ENABLE_DECRYPT */
+#endif /* CONFIG_IS_ENABLED(FIT_CIPHER) */
 
 #endif
diff --git a/tools/Kconfig b/tools/Kconfig
index 13f923c7ac7..5dd33fcbc55 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -19,6 +19,17 @@ config HOST_FIT
help
  Enable FIT support in the host build.
 
+config HOST_FIT_CIPHER
+   def_bool y
+   help
+Enable ciphering data in a FIT in the host build
+
+config HOST_FIT_CIPHER_ENCRYPT
+   def_bool y
+   depends on FIT_CIPHER
+   help
+ Enables encryption in a FIT in the host build
+
 config HOST_FIT_FULL_CHECK
def_bool y
help

[PATCH 08/49] image: Update image_decomp() to avoid ifdefs

2021-05-03 Thread Simon Glass
Adjust this function so that preprocessor macros are not needed. With
this, the host build uses more of the same header files as the target
build.

Rather than definining CONFIG_SYS_MALLOC_LEN, add a CONSERVE_MEMORY
define, since that is the purpose of the value.

This appears to have no impact on code size from a spot check of a few
boards (snow, firefly-rk3288, boston32r2el, m53menlo).

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image.c| 145 ++
 configs/sandbox_defconfig |   1 +
 2 files changed, 69 insertions(+), 77 deletions(-)

diff --git a/common/image.c b/common/image.c
index bd71bf7ec29..a41e8067b11 100644
--- a/common/image.c
+++ b/common/image.c
@@ -22,12 +22,9 @@
 #include 
 #endif
 
-#include 
 #include 
 
-#include 
 #include 
-#include 
 #include 
 
 #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT
@@ -43,13 +40,6 @@
 #include 
 #include 
 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #ifdef CONFIG_CMD_BDI
 extern int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc,
 char *const argv[]);
@@ -61,7 +51,15 @@ DECLARE_GLOBAL_DATA_PTR;
 static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
int verify);
 #endif
+
+/* Set this if we have less than 4 MB of malloc() space */
+#if CONFIG_SYS_MALLOC_LEN < (4096 * 1024)
+#define CONSERVE_MEMORYtrue
 #else
+#define CONSERVE_MEMORYfalse
+#endif
+
+#else /* USE_HOSTCC */
 #include "mkimage.h"
 #include 
 #include 
@@ -70,10 +68,23 @@ static const image_header_t *image_get_ramdisk(ulong 
rd_addr, uint8_t arch,
 #ifndef __maybe_unused
 # define __maybe_unused/* unimplemented */
 #endif
+
+#define CONSERVE_MEMORYfalse
+
 #endif /* !USE_HOSTCC*/
 
-#include 
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 #ifndef CONFIG_SYS_BARGSIZE
 #define CONFIG_SYS_BARGSIZE 512
@@ -464,83 +475,63 @@ int image_decomp(int comp, ulong load, ulong image_start, 
int type,
else
ret = -ENOSPC;
break;
-#ifndef USE_HOSTCC
-#if CONFIG_IS_ENABLED(GZIP)
-   case IH_COMP_GZIP: {
-   ret = gunzip(load_buf, unc_len, image_buf, _len);
+   case IH_COMP_GZIP:
+   if (!host_build() && CONFIG_IS_ENABLED(GZIP))
+   ret = gunzip(load_buf, unc_len, image_buf, _len);
break;
-   }
-#endif /* CONFIG_GZIP */
-#endif
-#ifndef USE_HOSTCC
-#if CONFIG_IS_ENABLED(BZIP2)
-   case IH_COMP_BZIP2: {
-   uint size = unc_len;
+   case IH_COMP_BZIP2:
+   if (!host_build() && CONFIG_IS_ENABLED(BZIP2)) {
+   uint size = unc_len;
 
-   /*
-* If we've got less than 4 MB of malloc() space,
-* use slower decompression algorithm which requires
-* at most 2300 KB of memory.
-*/
-   ret = BZ2_bzBuffToBuffDecompress(load_buf, ,
-   image_buf, image_len,
-   CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
-   image_len = size;
+   /*
+* If we've got less than 4 MB of malloc() space,
+* use slower decompression algorithm which requires
+* at most 2300 KB of memory.
+*/
+   ret = BZ2_bzBuffToBuffDecompress(load_buf, ,
+   image_buf, image_len, CONSERVE_MEMORY, 0);
+   image_len = size;
+   }
break;
-   }
-#endif /* CONFIG_BZIP2 */
-#endif
-#ifndef USE_HOSTCC
-#if CONFIG_IS_ENABLED(LZMA)
-   case IH_COMP_LZMA: {
-   SizeT lzma_len = unc_len;
+   case IH_COMP_LZMA:
+   if (!host_build() && CONFIG_IS_ENABLED(LZMA)) {
+   SizeT lzma_len = unc_len;
 
-   ret = lzmaBuffToBuffDecompress(load_buf, _len,
-  image_buf, image_len);
-   image_len = lzma_len;
+   ret = lzmaBuffToBuffDecompress(load_buf, _len,
+  image_buf, image_len);
+   image_len = lzma_len;
+   }
break;
-   }
-#endif /* CONFIG_LZMA */
-#endif
-#ifndef USE_HOSTCC
-#if CONFIG_IS_ENABLED(LZO)
-   case IH_COMP_LZO: {
-   size_t size = unc_len;
+   case IH_COMP_LZO:
+   if (!host_build() && CONFIG_IS_ENABLED(LZO)) {
+   size_t size = unc_len;
 
-   ret = lzop_decompress(image_buf, image_len, load_buf, );
-   image_len = size;
+   ret = lzop_decompress(image_buf, image_len, load_buf, 
);
+ 

[PATCH 07/49] gzip: Avoid use of u64

2021-05-03 Thread Simon Glass
The gzip API uses the u64 type in it, which is not available in the host
build. This makes it impossible to include the header file.

We could make this type available, but it seems unnecessary. Limiting the
compression size to that of the 'unsigned long' type seems good enough. On
32-bit machines the limit then becomes 4GB, which likely exceeds available
RAM anyway, therefore it should be sufficient. On 64-bit machines this is
effectively u64 anyway.

Update the header file and implementation to use 'ulong' instead of 'u64'.

Add a definition of u32 for the cases that seem to need exactly that
length. This should be safe enough.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/compiler.h |  3 +++
 include/gzip.h |  8 
 lib/gunzip.c   | 28 ++--
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/include/compiler.h b/include/compiler.h
index ec0d600e71a..f111c735984 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -68,6 +68,9 @@ typedef uint32_t __u32;
 typedef unsigned int uint;
 typedef unsigned long ulong;
 
+/* Define these on the host so we can build some target code */
+typedef __u32 u32;
+
 #define uswap_16(x) \
x) & 0xff00) >> 8) | \
 (((x) & 0x00ff) << 8))
diff --git a/include/gzip.h b/include/gzip.h
index 783acbb60d2..cb4db3d70fe 100644
--- a/include/gzip.h
+++ b/include/gzip.h
@@ -54,11 +54,11 @@ int zunzip(void *dst, int dstlen, unsigned char *src, 
unsigned long *lenp,
  * gzwrite_progress_finish called at end of loop to
  * indicate success (retcode=0) or failure
  */
-void gzwrite_progress_init(u64 expected_size);
+void gzwrite_progress_init(ulong expected_size);
 
-void gzwrite_progress(int iteration, u64 bytes_written, u64 total_bytes);
+void gzwrite_progress(int iteration, ulong bytes_written, ulong total_bytes);
 
-void gzwrite_progress_finish(int retcode, u64 totalwritten, u64 totalsize,
+void gzwrite_progress_finish(int retcode, ulong totalwritten, ulong totalsize,
 u32 expected_crc, u32 calculated_crc);
 
 /**
@@ -74,7 +74,7 @@ void gzwrite_progress_finish(int retcode, u64 totalwritten, 
u64 totalsize,
  * @return 0 if OK, -1 on error
  */
 int gzwrite(unsigned char *src, int len, struct blk_desc *dev, ulong 
szwritebuf,
-   u64 startoffs, u64 szexpected);
+   ulong startoffs, ulong szexpected);
 
 /**
  * gzip()- Compress data into a buffer using the gzip algorithm
diff --git a/lib/gunzip.c b/lib/gunzip.c
index bee3b9261f3..a8e498d98d8 100644
--- a/lib/gunzip.c
+++ b/lib/gunzip.c
@@ -84,32 +84,32 @@ int gunzip(void *dst, int dstlen, unsigned char *src, 
unsigned long *lenp)
 
 #ifdef CONFIG_CMD_UNZIP
 __weak
-void gzwrite_progress_init(u64 expectedsize)
+void gzwrite_progress_init(ulong expectedsize)
 {
putc('\n');
 }
 
 __weak
 void gzwrite_progress(int iteration,
-u64 bytes_written,
-u64 total_bytes)
+ulong bytes_written,
+ulong total_bytes)
 {
if (0 == (iteration & 3))
-   printf("%llu/%llu\r", bytes_written, total_bytes);
+   printf("%lu/%lu\r", bytes_written, total_bytes);
 }
 
 __weak
 void gzwrite_progress_finish(int returnval,
-u64 bytes_written,
-u64 total_bytes,
+ulong bytes_written,
+ulong total_bytes,
 u32 expected_crc,
 u32 calculated_crc)
 {
if (0 == returnval) {
-   printf("\n\t%llu bytes, crc 0x%08x\n",
+   printf("\n\t%lu bytes, crc 0x%08x\n",
   total_bytes, calculated_crc);
} else {
-   printf("\n\tuncompressed %llu of %llu\n"
+   printf("\n\tuncompressed %lu of %lu\n"
   "\tcrcs == 0x%08x/0x%08x\n",
   bytes_written, total_bytes,
   expected_crc, calculated_crc);
@@ -119,15 +119,15 @@ void gzwrite_progress_finish(int returnval,
 int gzwrite(unsigned char *src, int len,
struct blk_desc *dev,
unsigned long szwritebuf,
-   u64 startoffs,
-   u64 szexpected)
+   ulong startoffs,
+   ulong szexpected)
 {
int i, flags;
z_stream s;
int r = 0;
unsigned char *writebuf;
unsigned crc = 0;
-   u64 totalfilled = 0;
+   ulong totalfilled = 0;
lbaint_t blksperbuf, outblock;
u32 expected_crc;
u32 payload_size;
@@ -142,7 +142,7 @@ int gzwrite(unsigned char *src, int len,
}
 
if (startoffs & (dev->blksz-1)) {
-   printf("%s: start offset %llu not a multiple of %lu\n",
+   printf("%s: start offset %lu not a multiple of %lu\n",
   __func__, startoffs, dev->blksz);
return -1;
}
@@ -182,12 

[PATCH 06/49] image: Update zstd to avoid reporting error twice

2021-05-03 Thread Simon Glass
The zstd implementation prints the error in image_decomp() which is
incorrect and does not match other algorithms. Drop this and let the
caller report the error.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/common/image.c b/common/image.c
index 6c38211efce..bd71bf7ec29 100644
--- a/common/image.c
+++ b/common/image.c
@@ -532,12 +532,10 @@ int image_decomp(int comp, ulong load, ulong image_start, 
int type,
abuf_init_set(, image_buf, image_len);
abuf_init_set(, load_buf, unc_len);
ret = zstd_decompress(, );
-   if (ret < 0) {
-   printf("ZSTD decompression failed\n");
-   return ret;
+   if (ret >= 0) {
+   image_len = ret;
+   ret = 0;
}
-
-   image_len = ret;
break;
}
 #endif /* CONFIG_ZSTD */
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 05/49] image: Avoid switch default in image_decomp()

2021-05-03 Thread Simon Glass
At present this function is full of preprocessor macros. Adjust it to
check for an unsupported algorithm after the switch(). This will allow
us to drop the macros.

Fix up the return-value path and an extra blank line while we are here.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/common/image.c b/common/image.c
index 062e08886fd..6c38211efce 100644
--- a/common/image.c
+++ b/common/image.c
@@ -444,7 +444,7 @@ int image_decomp(int comp, ulong load, ulong image_start, 
int type,
 void *load_buf, void *image_buf, ulong image_len,
 uint unc_len, ulong *load_end)
 {
-   int ret = 0;
+   int ret = -ENOSYS;
 
*load_end = load;
print_decomp_msg(comp, type, load == image_start);
@@ -456,6 +456,7 @@ int image_decomp(int comp, ulong load, ulong image_start, 
int type,
 */
switch (comp) {
case IH_COMP_NONE:
+   ret = 0;
if (load == image_start)
break;
if (image_len <= unc_len)
@@ -537,22 +538,23 @@ int image_decomp(int comp, ulong load, ulong image_start, 
int type,
}
 
image_len = ret;
-
break;
}
 #endif /* CONFIG_ZSTD */
 #endif
-   default:
+   }
+   if (ret == -ENOSYS) {
printf("Unimplemented compression type %d\n", comp);
-   return -ENOSYS;
+   return ret;
}
+   if (ret)
+   return ret;
 
*load_end = load + image_len;
 
-   return ret;
+   return 0;
 }
 
-
 #ifndef USE_HOSTCC
 #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
 /**
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 03/49] zstd: Create a function for use from U-Boot

2021-05-03 Thread Simon Glass
The existing zstd API requires the same sequence of calls to perform its
task. Create a helper for U-Boot, to avoid code duplication, as is done
with other compression algorithms. Make use of of this from the image
code.

Note that the zstd code lacks a test in test/compression.c and this should
be added by the maintainer.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/image.c   | 50 +++---
 include/linux/zstd.h | 11 
 lib/zstd/Makefile|  2 +-
 lib/zstd/zstd.c  | 64 
 4 files changed, 85 insertions(+), 42 deletions(-)
 create mode 100644 lib/zstd/zstd.c

diff --git a/common/image.c b/common/image.c
index 51854aae5dd..062e08886fd 100644
--- a/common/image.c
+++ b/common/image.c
@@ -22,6 +22,7 @@
 #include 
 #endif
 
+#include 
 #include 
 
 #include 
@@ -525,50 +526,17 @@ int image_decomp(int comp, ulong load, ulong image_start, 
int type,
 #ifndef USE_HOSTCC
 #if CONFIG_IS_ENABLED(ZSTD)
case IH_COMP_ZSTD: {
-   size_t size = unc_len;
-   ZSTD_DStream *dstream;
-   ZSTD_inBuffer in_buf;
-   ZSTD_outBuffer out_buf;
-   void *workspace;
-   size_t wsize;
-
-   wsize = ZSTD_DStreamWorkspaceBound(image_len);
-   workspace = malloc(wsize);
-   if (!workspace) {
-   debug("%s: cannot allocate workspace of size %zu\n", 
__func__,
- wsize);
-   return -1;
-   }
-
-   dstream = ZSTD_initDStream(image_len, workspace, wsize);
-   if (!dstream) {
-   printf("%s: ZSTD_initDStream failed\n", __func__);
-   return ZSTD_getErrorCode(ret);
-   }
-
-   in_buf.src = image_buf;
-   in_buf.pos = 0;
-   in_buf.size = image_len;
+   struct abuf in, out;
 
-   out_buf.dst = load_buf;
-   out_buf.pos = 0;
-   out_buf.size = size;
-
-   while (1) {
-   size_t ret;
-
-   ret = ZSTD_decompressStream(dstream, _buf, _buf);
-   if (ZSTD_isError(ret)) {
-   printf("%s: ZSTD_decompressStream error %d\n", 
__func__,
-  ZSTD_getErrorCode(ret));
-   return ZSTD_getErrorCode(ret);
-   }
-
-   if (in_buf.pos >= image_len || !ret)
-   break;
+   abuf_init_set(, image_buf, image_len);
+   abuf_init_set(, load_buf, unc_len);
+   ret = zstd_decompress(, );
+   if (ret < 0) {
+   printf("ZSTD decompression failed\n");
+   return ret;
}
 
-   image_len = out_buf.pos;
+   image_len = ret;
 
break;
}
diff --git a/include/linux/zstd.h b/include/linux/zstd.h
index 724f69350e0..35ba4c90aa4 100644
--- a/include/linux/zstd.h
+++ b/include/linux/zstd.h
@@ -1144,4 +1144,15 @@ size_t ZSTD_decompressBlock(ZSTD_DCtx *dctx, void *dst, 
size_t dstCapacity,
 size_t ZSTD_insertBlock(ZSTD_DCtx *dctx, const void *blockStart,
size_t blockSize);
 
+struct abuf;
+
+/**
+ * zstd_decompress() - Decompress Zstandard data
+ *
+ * @in: Input buffer to decompress
+ * @out: Output buffer to hold the results (must be large enough)
+ * @return size of the decompressed data, or -ve on error
+ */
+int zstd_decompress(struct abuf *in, struct abuf *out);
+
 #endif  /* ZSTD_H */
diff --git a/lib/zstd/Makefile b/lib/zstd/Makefile
index 33c1df48ec8..12170892923 100644
--- a/lib/zstd/Makefile
+++ b/lib/zstd/Makefile
@@ -1,4 +1,4 @@
 obj-y += zstd_decompress.o
 
 zstd_decompress-y := huf_decompress.o decompress.o \
-entropy_common.o fse_decompress.o zstd_common.o
+entropy_common.o fse_decompress.o zstd_common.o zstd.o
diff --git a/lib/zstd/zstd.c b/lib/zstd/zstd.c
new file mode 100644
index 000..bf9cd19cfa3
--- /dev/null
+++ b/lib/zstd/zstd.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 Google LLC
+ */
+
+#define LOG_CATEGORY   LOGC_BOOT
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int zstd_decompress(struct abuf *in, struct abuf *out)
+{
+   ZSTD_DStream *dstream;
+   ZSTD_inBuffer in_buf;
+   ZSTD_outBuffer out_buf;
+   void *workspace;
+   size_t wsize;
+   int ret;
+
+   wsize = ZSTD_DStreamWorkspaceBound(abuf_size(in));
+   workspace = malloc(wsize);
+   if (!workspace) {
+   debug("%s: cannot allocate workspace of size %zu\n", __func__,
+   wsize);
+   return -ENOMEM;
+   }
+
+   dstream = ZSTD_initDStream(abuf_size(in), workspace, wsize);
+   if 

[PATCH 04/49] btrfs: Use U-Boot API for decompression

2021-05-03 Thread Simon Glass
Use the common function to avoid code duplication.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 fs/btrfs/compression.c | 51 +-
 1 file changed, 5 insertions(+), 46 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 23efefa1997..7adfbb04a7c 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -6,6 +6,7 @@
  */
 
 #include "btrfs.h"
+#include 
 #include 
 #include 
 #include 
@@ -136,54 +137,12 @@ static u32 decompress_zlib(const u8 *_cbuf, u32 clen, u8 
*dbuf, u32 dlen)
 
 static u32 decompress_zstd(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
 {
-   ZSTD_DStream *dstream;
-   ZSTD_inBuffer in_buf;
-   ZSTD_outBuffer out_buf;
-   void *workspace;
-   size_t wsize;
-   u32 res = -1;
-
-   wsize = ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT);
-   workspace = malloc(wsize);
-   if (!workspace) {
-   debug("%s: cannot allocate workspace of size %zu\n", __func__,
- wsize);
-   return -1;
-   }
-
-   dstream = ZSTD_initDStream(ZSTD_BTRFS_MAX_INPUT, workspace, wsize);
-   if (!dstream) {
-   printf("%s: ZSTD_initDStream failed\n", __func__);
-   goto err_free;
-   }
+   struct abuf in, out;
 
-   in_buf.src = cbuf;
-   in_buf.pos = 0;
-   in_buf.size = clen;
+   abuf_init_set(, (u8 *)cbuf, clen);
+   abuf_init_set(, dbuf, dlen);
 
-   out_buf.dst = dbuf;
-   out_buf.pos = 0;
-   out_buf.size = dlen;
-
-   while (1) {
-   size_t ret;
-
-   ret = ZSTD_decompressStream(dstream, _buf, _buf);
-   if (ZSTD_isError(ret)) {
-   printf("%s: ZSTD_decompressStream error %d\n", __func__,
-  ZSTD_getErrorCode(ret));
-   goto err_free;
-   }
-
-   if (in_buf.pos >= clen || !ret)
-   break;
-   }
-
-   res = out_buf.pos;
-
-err_free:
-   free(workspace);
-   return res;
+   return zstd_decompress(, );
 }
 
 u32 btrfs_decompress(u8 type, const char *c, u32 clen, char *d, u32 dlen)
-- 
2.31.1.527.g47e6f16901-goog



[PATCH 01/49] Add support for an owned buffer

2021-05-03 Thread Simon Glass
When passing a data buffer back from a function, it is not always clear
who owns the buffer, i.e. who is responsible for freeing the memory used.
An example of this is where multiple files are decompressed from the
firmware image, using a temporary buffer for reading (since the
compressed data has to live somewhere) and producing a temporary or
permanent buffer with the resuilts.

Where the firmware image can be memory-mapped, as on x86, the compressed
data does not need to be buffered, but the complexity of having a buffer
which is either allocated or not, makes the code hard to understand.

Introduce a new 'abuf' which supports simple buffer operations:

- encapsulating a buffer and its size
- either allocated with malloc() or not
- able to be reliably freed if necessary
- able to be converted to an allocated buffer if needed

This simple API makes it easier to deal with allocated and memory-mapped
buffers.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new abuf_init_set() function

 include/abuf.h| 148 ++
 lib/Makefile  |   1 +
 lib/abuf.c| 103 
 test/lib/Makefile |   1 +
 test/lib/abuf.c   | 303 ++
 5 files changed, 556 insertions(+)
 create mode 100644 include/abuf.h
 create mode 100644 lib/abuf.c
 create mode 100644 test/lib/abuf.c

diff --git a/include/abuf.h b/include/abuf.h
new file mode 100644
index 000..3b8f78348dd
--- /dev/null
+++ b/include/abuf.h
@@ -0,0 +1,148 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Handles a buffer that can be allocated and freed
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass 
+ */
+
+#ifndef __ABUF_H
+#define __ABUF_H
+
+#include 
+
+/**
+ * struct abuf - buffer that can be allocated and freed
+ *
+ * This is useful for a block of data which may be allocated with malloc(), or
+ * not, so that it needs to be freed correctly when finished with.
+ *
+ * For now it has a very simple purpose.
+ *
+ * Using memset() to zero all fields is guaranteed to be equivalent to
+ * abuf_init().
+ *
+ * @data: Pointer to data
+ * @size: Size of data in bytes
+ * @alloced: true if allocated with malloc(), so must be freed after use
+ */
+struct abuf {
+   void *data;
+   size_t size;
+   bool alloced;
+};
+
+static inline void *abuf_data(struct abuf *abuf)
+{
+   return abuf->data;
+}
+
+static inline size_t abuf_size(struct abuf *abuf)
+{
+   return abuf->size;
+}
+
+/**
+ * abuf_set() - set the (unallocated) data in a buffer
+ *
+ * This simply makes the abuf point to the supplied data, which must be live
+ * for the lifetime of the abuf. It is not alloced.
+ *
+ * Any existing data in the abuf is freed and the alloced member is set to
+ * false.
+ *
+ * @abuf: abuf to adjust
+ * @data: New contents of abuf
+ * @size: New size of abuf
+ */
+void abuf_set(struct abuf *abuf, void *data, size_t size);
+
+/**
+ * abuf_map_sysmem() - calls map_sysmem() to set up an abuf
+ *
+ * This is equivalent to abuf_set(abuf, map_sysmem(addr, size), size)
+ *
+ * Any existing data in the abuf is freed and the alloced member is set to
+ * false.
+ *
+ * @abuf: abuf to adjust
+ * @addr: Address to set the abuf to
+ * @size: New size of abuf
+ */
+void abuf_map_sysmem(struct abuf *abuf, ulong addr, size_t size);
+
+/**
+ * abuf_realloc() - Change the size of a buffer
+ *
+ * This uses realloc() to change the size of the buffer, with the same 
semantics
+ * as that function. If the abuf is not currently alloced, then it will alloc
+ * it if the size needs to increase (i.e. set the alloced member to true)
+ *
+ * @abuf: abuf to adjust
+ * @new_size: new size in bytes.
+ * if 0, the abuf is freed
+ * if greater than the current size, the abuf is extended and the new
+ *space is not inited. The alloced member is set to true
+ * if less than the current size, the abuf is contracted and the data at
+ *the end is lost. If @new_size is 0, this sets the alloced member to
+ *false
+ * @return true if OK, false if out of memory
+ */
+bool abuf_realloc(struct abuf *abuf, size_t new_size);
+
+/**
+ * abuf_uninit_move() - Return the allocated contents and uninit the abuf
+ *
+ * This returns the abuf data to the caller, allocating it if necessary, so 
that
+ * the caller receives data that it can be sure will hang around. The caller is
+ * responsible for freeing the data.
+ *
+ * If the abuf has allocated data, it is returned. If the abuf has data but it
+ * is not allocated, then it is first allocated, then returned.
+ *
+ * If the abuf size is 0, this returns NULL
+ *
+ * The abuf is uninited as part of this, except if the allocation fails, in
+ * which NULL is returned and the abuf remains untouched.
+ *
+ * The abuf must be inited before this can be called.
+ *
+ * @abuf: abuf to uninit
+ * @sizep: if non-NULL, returns the size of the returned data
+ * @return data contents, allocated with malloc(), or NULL if the data could 

[PATCH 02/49] compiler: Add a comment to host_build()

2021-05-03 Thread Simon Glass
This function should have a comment explaining what it does. Add one.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/compiler.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/compiler.h b/include/compiler.h
index 27b9843497a..ec0d600e71a 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -151,6 +151,11 @@ typedef unsigned long int uintptr_t;
 #define MEM_SUPPORT_64BIT_DATA 0
 #endif
 
+/**
+ * host_build() - check if we are building for the host
+ *
+ * @return true if building for the hose, false if for a target
+ */
 static inline bool host_build(void) {
 #ifdef USE_HOSTCC
return true;
-- 
2.31.1.527.g47e6f16901-goog



[PATCH v8 15/15] mtd: spi-nor-tiny: Add fixups for Cypress s25hl-t/s25hs-t

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

Fixes mode clocks for SPINOR_OP_READ_FAST_4B in tiny.

Signed-off-by: Takahiro Kuwano 
---
Changes in v8:
  - No change

Changes in v7:
  - No change

Changes in v6:
  - Remove spansion_quad_enable_volatile() per comment in

https://patchwork.ozlabs.org/project/uboot/patch/a5c3cf1353d9a621379e2fcfefc51fb44c9680c5.1611729896.git.takahiro.kuw...@infineon.com/

Changes in v5:
  - Add a comment about Flash models and respective IDs

 drivers/mtd/spi/spi-nor-tiny.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-tiny.c b/drivers/mtd/spi/spi-nor-tiny.c
index 5cc2b7d996..aa2df75c60 100644
--- a/drivers/mtd/spi/spi-nor-tiny.c
+++ b/drivers/mtd/spi/spi-nor-tiny.c
@@ -583,6 +583,12 @@ static int spi_nor_init_params(struct spi_nor *nor,
spi_nor_set_read_settings(>reads[SNOR_CMD_READ_FAST],
  0, 8, SPINOR_OP_READ_FAST,
  SNOR_PROTO_1_1_1);
+#ifdef CONFIG_SPI_FLASH_SPANSION
+   if (JEDEC_MFR(info) == SNOR_MFR_CYPRESS &&
+   (info->id[1] == 0x2a || info->id[1] == 0x2b))
+   /* 0x2a: S25HL (QSPI, 3.3V), 0x2b: S25HS (QSPI, 1.8V) */
+   params->reads[SNOR_CMD_READ_FAST].num_mode_clocks = 8;
+#endif
}
 
if (info->flags & SPI_NOR_QUAD_READ) {
-- 
2.25.1



[PATCH v8 14/15] mtd: spi-nor-core: Add fixups for Cypress s25hl-t/s25hs-t

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

The nor->ready() and spansion_sr_ready() introduced earlier in this
series are used for multi-die package parts.

The nor->quad_enable() sets the volatile QE bit on each die.

The nor->erase() is hooked if the device is not configured to uniform
sectors, assuming it has 32 x 4KB sectors overlaid on bottom address.
Other configurations, top and split, are not supported at this point.
Will submit additional patches to support it as needed.

The post_bfpt/sfdp() fixes the params wrongly advertised in SFDP.

Signed-off-by: Takahiro Kuwano 
---
Changes in v8:
  - No change

Changes in v7:
  - Fix return type of s25hx_t_erase_non_uniform() to 'int'

Changes in v6:
  - Remove mtd.writesize fixup
  - Check if uniform sector is selected in multi-die package parts
  - Fix some other minor issues

Changes in v5:
  - Add s25hx_t_erase_non_uniform()
  - Change mtd.writesize and mtd.flags in s25hx_t_setup()
  - Fix page size and erase size issues in s25hx_t_post_bfpt_fixup()

 drivers/mtd/spi/spi-nor-core.c | 142 +
 include/linux/mtd/spi-nor.h|   3 +
 2 files changed, 145 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index c2b26cc2fd..2b48404c04 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -2678,8 +2678,150 @@ static int spi_nor_init(struct spi_nor *nor)
return 0;
 }
 
+#ifdef CONFIG_SPI_FLASH_SPANSION
+static int s25hx_t_mdp_ready(struct spi_nor *nor)
+{
+   u32 addr;
+   int ret;
+
+   for (addr = 0; addr < nor->mtd.size; addr += SZ_128M) {
+   ret = spansion_sr_ready(nor, addr, 0);
+   if (!ret)
+   return ret;
+   }
+
+   return 1;
+}
+
+static int s25hx_t_quad_enable(struct spi_nor *nor)
+{
+   u32 addr;
+   int ret;
+
+   for (addr = 0; addr < nor->mtd.size; addr += SZ_128M) {
+   ret = spansion_quad_enable_volatile(nor, addr, 0);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
+static int s25hx_t_erase_non_uniform(struct spi_nor *nor, loff_t addr)
+{
+   /* Support 32 x 4KB sectors at bottom */
+   return spansion_erase_non_uniform(nor, addr, SPINOR_OP_BE_4K_4B, 0,
+ SZ_128K);
+}
+
+static int s25hx_t_setup(struct spi_nor *nor, const struct flash_info *info,
+const struct spi_nor_flash_parameter *params,
+const struct spi_nor_hwcaps *hwcaps)
+{
+   int ret;
+   u8 cfr3v;
+
+#ifdef CONFIG_SPI_FLASH_BAR
+   return -ENOTSUPP; /* Bank Address Register is not supported */
+#endif
+   /*
+* Read CFR3V to check if uniform sector is selected. If not, assign an
+* erase hook that supports non-uniform erase.
+*/
+   ret = spansion_read_any_reg(nor, SPINOR_REG_ADDR_CFR3V, 0, );
+   if (ret)
+   return ret;
+   if (!(cfr3v & CFR3V_UNHYSA))
+   nor->erase = s25hx_t_erase_non_uniform;
+
+   /*
+* For the multi-die package parts, the ready() hook is needed to check
+* all dies' status via read any register.
+*/
+   if (nor->mtd.size > SZ_128M)
+   nor->ready = s25hx_t_mdp_ready;
+
+   return spi_nor_default_setup(nor, info, params, hwcaps);
+}
+
+static void s25hx_t_default_init(struct spi_nor *nor)
+{
+   nor->setup = s25hx_t_setup;
+}
+
+static int s25hx_t_post_bfpt_fixup(struct spi_nor *nor,
+  const struct sfdp_parameter_header *header,
+  const struct sfdp_bfpt *bfpt,
+  struct spi_nor_flash_parameter *params)
+{
+   int ret;
+   u32 addr;
+   u8 cfr3v;
+
+   /* erase size in case it is set to 4K from BFPT */
+   nor->erase_opcode = SPINOR_OP_SE_4B;
+   nor->mtd.erasesize = nor->info->sector_size;
+
+   ret = set_4byte(nor, nor->info, 1);
+   if (ret)
+   return ret;
+   nor->addr_width = 4;
+
+   /*
+* The page_size is set to 512B from BFPT, but it actually depends on
+* the configuration register. Look up the CFR3V and determine the
+* page_size. For multi-die package parts, use 512B only when the all
+* dies are configured to 512B buffer.
+*/
+   for (addr = 0; addr < params->size; addr += SZ_128M) {
+   ret = spansion_read_any_reg(nor, addr + SPINOR_REG_ADDR_CFR3V,
+   0, );
+   if (ret)
+   return ret;
+
+   if (!(cfr3v & CFR3V_PGMBUF)) {
+   params->page_size = 256;
+   return 0;
+   }
+   }
+   params->page_size = 512;
+
+   return 0;
+}
+
+static void s25hx_t_post_sfdp_fixup(struct spi_nor *nor,
+   struct spi_nor_flash_parameter 

[PATCH v8 13/15] mtd: spi-nor-core: Add Cypress manufacturer ID in set_4byte

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

Cypress chips support SPINOR_OP_EN4B(B7h) to enable 4-byte addressing mode.

Cypress chips support B8h to disable 4-byte addressing mode instead of
SPINOR_OP_EX4B(E9h).

This patch defines new opcode and updates set_4byte() to support
enable/disable 4-byte addressing mode for Cypress chips.

Signed-off-by: Takahiro Kuwano 
---
Changes in v8:
  - No change
  
Changes in v7:
  - No change
  
Changes in v6:
  - Define SPINOR_OP_EX4B_CYPRESS and use it

 drivers/mtd/spi/spi-nor-core.c | 3 +++
 include/linux/mtd/spi-nor.h| 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 0e013e0c61..c2b26cc2fd 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -516,6 +516,9 @@ static int set_4byte(struct spi_nor *nor, const struct 
flash_info *info,
}
 
return status;
+   case SNOR_MFR_CYPRESS:
+   cmd = enable ? SPINOR_OP_EN4B : SPINOR_OP_EX4B_CYPRESS;
+   return nor->write_reg(nor, cmd, NULL, 0);
default:
/* Spansion style */
nor->cmd_buf[0] = enable << 7;
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 8a187eaf26..0b295c3eec 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -121,6 +121,7 @@
 #define SPINOR_OP_BRWR 0x17/* Bank register write */
 #define SPINOR_OP_BRRD 0x16/* Bank register read */
 #define SPINOR_OP_CLSR 0x30/* Clear status register 1 */
+#define SPINOR_OP_EX4B_CYPRESS 0xB8/* Exit 4-byte mode */
 #define SPINOR_OP_RDAR 0x65/* Read any register */
 #define SPINOR_OP_WRAR 0x71/* Write any register */
 #define SPINOR_REG_ADDR_STR1V  0x0080
-- 
2.25.1



[PATCH v8 12/15] mtd: spi-nor-core: Read status by Read Any Register

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

The spansion_sr_ready() reads status register 1 by Read Any Register
commnad. This function is called from Flash specific hook with die address
and dummy cycles to support multi-die package parts from Spansion/Cypress.

Signed-off-by: Takahiro Kuwano 
Reviewed-by: Pratyush Yadav 
---
Changes in v8:
  - No change
  
Changes in v7:
  - No change
  
Changes in v6:
  - No change

Changes in v5:
  - New in v5, separated from another patch

 drivers/mtd/spi/spi-nor-core.c | 29 +
 include/linux/mtd/spi-nor.h|  1 +
 2 files changed, 30 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 8a2c5d949a..0e013e0c61 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -523,6 +523,35 @@ static int set_4byte(struct spi_nor *nor, const struct 
flash_info *info,
}
 }
 
+#ifdef CONFIG_SPI_FLASH_SPANSION
+/*
+ * Read status register 1 by using Read Any Register command to support multi
+ * die package parts.
+ */
+static int spansion_sr_ready(struct spi_nor *nor, u32 addr_base, u8 dummy)
+{
+   u32 reg_addr = addr_base + SPINOR_REG_ADDR_STR1V;
+   u8 sr;
+   int ret;
+
+   ret = spansion_read_any_reg(nor, reg_addr, dummy, );
+   if (ret < 0)
+   return ret;
+
+   if (sr & (SR_E_ERR | SR_P_ERR)) {
+   if (sr & SR_E_ERR)
+   dev_dbg(nor->dev, "Erase Error occurred\n");
+   else
+   dev_dbg(nor->dev, "Programming Error occurred\n");
+
+   nor->write_reg(nor, SPINOR_OP_CLSR, NULL, 0);
+   return -EIO;
+   }
+
+   return !(sr & SR_WIP);
+}
+#endif
+
 static int spi_nor_sr_ready(struct spi_nor *nor)
 {
int sr = read_sr(nor);
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 2236e36e28..8a187eaf26 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -123,6 +123,7 @@
 #define SPINOR_OP_CLSR 0x30/* Clear status register 1 */
 #define SPINOR_OP_RDAR 0x65/* Read any register */
 #define SPINOR_OP_WRAR 0x71/* Write any register */
+#define SPINOR_REG_ADDR_STR1V  0x0080
 #define SPINOR_REG_ADDR_CFR1V  0x0082
 
 /* Used for Micron flashes only. */
-- 
2.25.1



[PATCH v8 11/15] mtd: spi-nor-core: Add the ->ready() hook

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

For dual/quad die package devices from Spansion/Cypress, the device's
status needs to be checked by reading status registers in all dies, by
using Read Any Register command. To support this, a Flash specific hook
that can overwrite the legacy status check is needed.

Signed-off-by: Takahiro Kuwano 
Reviewed-by: Pratyush Yadav 
---
Changes in v8:
  - No change
  
Changes in v7:
  - No change
  
Changes in v6:
  - Rebase and fix commit description
  
Changes in v5:
  - Move spansion_sr_ready() to different patch
  - Move original code in spi_nor_ready() to newly created
spi_nor_default_ready()

 drivers/mtd/spi/spi-nor-core.c | 10 +-
 include/linux/mtd/spi-nor.h|  2 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index ac8ebfc4f0..8a2c5d949a 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -567,7 +567,7 @@ static int spi_nor_fsr_ready(struct spi_nor *nor)
return fsr & FSR_READY;
 }
 
-static int spi_nor_ready(struct spi_nor *nor)
+static int spi_nor_default_ready(struct spi_nor *nor)
 {
int sr, fsr;
 
@@ -580,6 +580,14 @@ static int spi_nor_ready(struct spi_nor *nor)
return sr && fsr;
 }
 
+static int spi_nor_ready(struct spi_nor *nor)
+{
+   if (nor->ready)
+   return nor->ready(nor);
+
+   return spi_nor_default_ready(nor);
+}
+
 /*
  * Service routine to read status register until ready, or timeout occurs.
  * Returns non-zero if error.
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index de4472da5c..2236e36e28 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -437,6 +437,7 @@ struct spi_flash {
  * @flash_is_locked:   [FLASH-SPECIFIC] check if a region of the SPI NOR is
  * completely locked
  * @quad_enable:   [FLASH-SPECIFIC] enables SPI NOR quad mode
+ * @ready: [FLASH-SPECIFIC] check if the flash is ready
  * @priv:  the private data
  */
 struct spi_nor {
@@ -482,6 +483,7 @@ struct spi_nor {
int (*flash_unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
int (*flash_is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len);
int (*quad_enable)(struct spi_nor *nor);
+   int (*ready)(struct spi_nor *nor);
 
void *priv;
 /* Compatibility for spi_flash, remove once sf layer is merged with mtd */
-- 
2.25.1



[PATCH v8 09/15] mtd: spi-nor-core: Add support for Read/Write Any Register

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

Some of Spansion/Cypress chips support Read/Write Any Register commands.
These commands are mainly used to write volatile registers and access to
the registers in second and subsequent die for multi-die package parts.

The Read Any Register instruction (65h) is followed by register address
and dummy cycles, then the selected register byte is returned.

The Write Any Register instruction (71h) is followed by register address
and register byte to write.

Signed-off-by: Takahiro Kuwano 
Reviewed-by: Pratyush Yadav 
---
Changes in v8:
  - No change
  
Changes in v7:
  - No change
  
Changes in v6:
  - No change

Changes in v5:
  - Remove unused defines from spi-nor.h

 drivers/mtd/spi/spi-nor-core.c | 25 +
 include/linux/mtd/spi-nor.h|  2 ++
 2 files changed, 27 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 1b84e389ad..36c1756576 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -212,6 +212,31 @@ static int spi_nor_write_reg(struct spi_nor *nor, u8 
opcode, u8 *buf, int len)
return spi_nor_read_write_reg(nor, , buf);
 }
 
+#ifdef CONFIG_SPI_FLASH_SPANSION
+static int spansion_read_any_reg(struct spi_nor *nor, u32 addr, u8 dummy,
+u8 *val)
+{
+   struct spi_mem_op op =
+   SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDAR, 1),
+  SPI_MEM_OP_ADDR(nor->addr_width, addr, 1),
+  SPI_MEM_OP_DUMMY(dummy / 8, 1),
+  SPI_MEM_OP_DATA_IN(1, NULL, 1));
+
+   return spi_nor_read_write_reg(nor, , val);
+}
+
+static int spansion_write_any_reg(struct spi_nor *nor, u32 addr, u8 val)
+{
+   struct spi_mem_op op =
+   SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRAR, 1),
+  SPI_MEM_OP_ADDR(nor->addr_width, addr, 1),
+  SPI_MEM_OP_NO_DUMMY,
+  SPI_MEM_OP_DATA_OUT(1, NULL, 1));
+
+   return spi_nor_read_write_reg(nor, , );
+}
+#endif
+
 static ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len,
 u_char *buf)
 {
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 47ce8f5f25..a9b389f2af 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -121,6 +121,8 @@
 #define SPINOR_OP_BRWR 0x17/* Bank register write */
 #define SPINOR_OP_BRRD 0x16/* Bank register read */
 #define SPINOR_OP_CLSR 0x30/* Clear status register 1 */
+#define SPINOR_OP_RDAR 0x65/* Read any register */
+#define SPINOR_OP_WRAR 0x71/* Write any register */
 
 /* Used for Micron flashes only. */
 #define SPINOR_OP_RD_EVCR  0x65/* Read EVCR register */
-- 
2.25.1



[PATCH v8 10/15] mtd: spi-nor-core: Add support for volatile QE bit

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

Some of Spansion/Cypress chips support volatile version of configuration
registers and it is recommended to update volatile registers in the field
application due to a risk of the non-volatile registers corruption by
power interrupt. This patch adds a function to set Quad Enable bit in CFR1
volatile.

Signed-off-by: Takahiro Kuwano 
---
Changes in v8:
  - Define spansion_quad_enable_volatile() under CONFIG_SPI_FLASH_SPANSION
  
Changes in v7:
  - No change
  
Changes in v6:
  - No change

Changes in v5:
  - Fix register address calculation, 'base | offset' -> 'base + offset'

 drivers/mtd/spi/spi-nor-core.c | 55 ++
 include/linux/mtd/spi-nor.h|  1 +
 2 files changed, 56 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 36c1756576..ac8ebfc4f0 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -1561,6 +1561,61 @@ static int macronix_quad_enable(struct spi_nor *nor)
 }
 #endif
 
+#ifdef CONFIG_SPI_FLASH_SPANSION
+/**
+ * spansion_quad_enable_volatile() - enable Quad I/O mode in volatile register.
+ * @nor:   pointer to a 'struct spi_nor'
+ * @addr_base: base address of register (can be >0 in multi-die parts)
+ * @dummy: number of dummy cycles for register read
+ *
+ * It is recommended to update volatile registers in the field application due
+ * to a risk of the non-volatile registers corruption by power interrupt. This
+ * function sets Quad Enable bit in CFR1 volatile.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int spansion_quad_enable_volatile(struct spi_nor *nor, u32 addr_base,
+u8 dummy)
+{
+   u32 addr = addr_base + SPINOR_REG_ADDR_CFR1V;
+
+   u8 cr;
+   int ret;
+
+   /* Check current Quad Enable bit value. */
+   ret = spansion_read_any_reg(nor, addr, dummy, );
+   if (ret < 0) {
+   dev_dbg(nor->dev,
+   "error while reading configuration register\n");
+   return -EINVAL;
+   }
+
+   if (cr & CR_QUAD_EN_SPAN)
+   return 0;
+
+   cr |= CR_QUAD_EN_SPAN;
+
+   write_enable(nor);
+
+   ret = spansion_write_any_reg(nor, addr, cr);
+
+   if (ret < 0) {
+   dev_dbg(nor->dev,
+   "error while writing configuration register\n");
+   return -EINVAL;
+   }
+
+   /* Read back and check it. */
+   ret = spansion_read_any_reg(nor, addr, dummy, );
+   if (ret || !(cr & CR_QUAD_EN_SPAN)) {
+   dev_dbg(nor->dev, "Spansion Quad bit not set\n");
+   return -EINVAL;
+   }
+
+   return 0;
+}
+#endif
+
 #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
 /*
  * Write status Register and configuration register with 2 bytes
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index a9b389f2af..de4472da5c 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -123,6 +123,7 @@
 #define SPINOR_OP_CLSR 0x30/* Clear status register 1 */
 #define SPINOR_OP_RDAR 0x65/* Read any register */
 #define SPINOR_OP_WRAR 0x71/* Write any register */
+#define SPINOR_REG_ADDR_CFR1V  0x0082
 
 /* Used for Micron flashes only. */
 #define SPINOR_OP_RD_EVCR  0x65/* Read EVCR register */
-- 
2.25.1



[PATCH v8 08/15] mtd: spi-nor-ids: Add Cypress s25hl-t/s25hs-t

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

The S25HL-T/S25HS-T family is the Cypress Semper Flash with Quad SPI.

https://www.cypress.com/file/424146/download (256Mb/512Mb/1Gb, single die)
https://www.cypress.com/file/499246/download (2Gb/4Gb, dual/quad die)

The full version can be found in the following links (registration
required).
https://community.cypress.com/t5/Semper-Flash-Access-Program/Datasheet-Semper-Flash-with-Quad-SPI/ta-p/260789?attachment-id=19522
https://community.cypress.com/t5/Semper-Flash-Access-Program/Datasheet-2Gb-MCP-Semper-Flash-with-Quad-SPI/ta-p/260823?attachment-id=29503

S25HL/HS-T (Semper Flash with Quad SPI) Family has user-configurable
sector architecture. By default, the 512Mb and 1Gb, single-die package
parts are configured to non-uniform that 4KB sectors overlaid on bottom
address. To support this, an erase hook makes overlaid sectors appear as
uniform sectors. The 2Gb, dual-die package parts are configured to uniform
by default.

Tested on Xilinx Zynq-7000 FPGA board.

Signed-off-by: Takahiro Kuwano 
Reviewed-by: Pratyush Yadav 
---
Changes in v8:
  - No change
  
Changes in v7:
  - No change
  
Changes in v6:
  - Remove USE_CLSR flag from S25HL02GT and S25HS02GT
  - Remove comment block and update commit description

Changes in v5:
  - Remove 256Mb and 4Gb parts

 drivers/mtd/spi/spi-nor-ids.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-ids.c b/drivers/mtd/spi/spi-nor-ids.c
index 2b57797954..d6f1b7d8a3 100644
--- a/drivers/mtd/spi/spi-nor-ids.c
+++ b/drivers/mtd/spi/spi-nor-ids.c
@@ -222,6 +222,22 @@ const struct flash_info spi_nor_ids[] = {
{ INFO("s25fl208k",  0x014014,  0,  64 * 1024,  16, SECT_4K | 
SPI_NOR_DUAL_READ) },
{ INFO("s25fl064l",  0x016017,  0,  64 * 1024, 128, SECT_4K | 
SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
{ INFO("s25fl128l",  0x016018,  0,  64 * 1024, 256, SECT_4K | 
SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+   { INFO6("s25hl512t",  0x342a1a, 0x0f0390, 256 * 1024, 256,
+   SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES |
+   USE_CLSR) },
+   { INFO6("s25hl01gt",  0x342a1b, 0x0f0390, 256 * 1024, 512,
+   SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES |
+   USE_CLSR) },
+   { INFO6("s25hl02gt",  0x342a1c, 0x0f0090, 256 * 1024, 1024,
+   SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+   { INFO6("s25hs512t",  0x342b1a, 0x0f0390, 256 * 1024, 256,
+   SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES |
+   USE_CLSR) },
+   { INFO6("s25hs01gt",  0x342b1b, 0x0f0390, 256 * 1024, 512,
+   SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES |
+   USE_CLSR) },
+   { INFO6("s25hs02gt",  0x342b1c, 0x0f0090, 256 * 1024, 1024,
+   SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
 #endif
 #ifdef CONFIG_SPI_FLASH_SST/* SST */
/* SST -- large erase sizes are "overlays", "sectors" are 4K */
-- 
2.25.1



[PATCH v8 07/15] mtd: spi-nor: Add Cypress manufacturer ID

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

This patch adds Cypress manufacturer ID (34h) definition.

Signed-off-by: Takahiro Kuwano 
Reviewed-by: Pratyush Yadav 
---
 include/linux/mtd/spi-nor.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index b2e9e0895b..47ce8f5f25 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -27,6 +27,7 @@
 #define SNOR_MFR_SPANSION  CFI_MFR_AMD
 #define SNOR_MFR_SST   CFI_MFR_SST
 #define SNOR_MFR_WINBOND   0xef /* Also used by some Spansion */
+#define SNOR_MFR_CYPRESS   0x34
 
 /*
  * Note on opcode nomenclature: some opcodes have a format like
-- 
2.25.1



[PATCH v8 06/15] mtd: spi-nor-core: Add non-uniform erase for Spansion/Cypress

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

Some of Spansion/Cypress chips have overlaid 4KB sectors at top and/or
bottom, depending on the device configuration, while U-Boot supports
uniform sector layout only.

The spansion_erase_non_uniform()  erases overlaid 4KB sectors,
non-overlaid portion of normal sector, and remaining normal sectors, by
selecting correct erase command and size based on the address to erase
and size of overlaid portion in parameters. Since different Spansion
flashes can use different opcode for erasing the 4K sectors, the opcode
must be passed in as a parameter based on the flash being used.

Signed-off-by: Takahiro Kuwano 
Signed-off-by: Pratyush Yadav 
[p.ya...@ti.com: Refactor the function to be compatible with nor->erase,
make 4K opcode customizable, call spi_nor_setup_op() before executing
the op.]
[takahiro.kuw...@infineon.com: Remove spi_nor_setup_op() and initialize
op.cmd.buswidth and op.addr.buswidth by 1]
---

Once Pratyush's patch [0] is accepted, I will rebase this series.

[0] 
https://patchwork.ozlabs.org/project/uboot/patch/20210401193133.18129-27-p.ya...@ti.com/

 drivers/mtd/spi/spi-nor-core.c | 59 ++
 1 file changed, 59 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 829ad36903..1b84e389ad 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -739,6 +739,65 @@ erase_err:
return ret;
 }
 
+#ifdef CONFIG_SPI_FLASH_SPANSION
+/**
+ * spansion_erase_non_uniform() - erase non-uniform sectors for 
Spansion/Cypress
+ *chips
+ * @nor:   pointer to a 'struct spi_nor'
+ * @addr:  address of the sector to erase
+ * @opcode_4k: opcode for 4K sector erase
+ * @ovlsz_top: size of overlaid portion at the top address
+ * @ovlsz_btm: size of overlaid portion at the bottom address
+ *
+ * Erase an address range on the nor chip that can contain 4KB sectors overlaid
+ * on top and/or bottom. The appropriate erase opcode and size are chosen by
+ * address to erase and size of overlaid portion.
+ *
+ * Return: number of bytes erased on success, -errno otherwise.
+ */
+static int spansion_erase_non_uniform(struct spi_nor *nor, u32 addr,
+ u8 opcode_4k, u32 ovlsz_top,
+ u32 ovlsz_btm)
+{
+   struct spi_mem_op op =
+   SPI_MEM_OP(SPI_MEM_OP_CMD(nor->erase_opcode, 1),
+  SPI_MEM_OP_ADDR(nor->addr_width, addr, 1),
+  SPI_MEM_OP_NO_DUMMY,
+  SPI_MEM_OP_NO_DATA);
+   struct mtd_info *mtd = >mtd;
+   u32 erasesize;
+   int ret;
+
+   /* 4KB sectors */
+   if (op.addr.val < ovlsz_btm ||
+   op.addr.val >= mtd->size - ovlsz_top) {
+   op.cmd.opcode = opcode_4k;
+   erasesize = SZ_4K;
+
+   /* Non-overlaid portion in the normal sector at the bottom */
+   } else if (op.addr.val == ovlsz_btm) {
+   op.cmd.opcode = nor->erase_opcode;
+   erasesize = mtd->erasesize - ovlsz_btm;
+
+   /* Non-overlaid portion in the normal sector at the top */
+   } else if (op.addr.val == mtd->size - mtd->erasesize) {
+   op.cmd.opcode = nor->erase_opcode;
+   erasesize = mtd->erasesize - ovlsz_top;
+
+   /* Normal sectors */
+   } else {
+   op.cmd.opcode = nor->erase_opcode;
+   erasesize = mtd->erasesize;
+   }
+
+   ret = spi_mem_exec_op(nor->spi, );
+   if (ret)
+   return ret;
+
+   return erasesize;
+}
+#endif
+
 #if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
 /* Write status register and ensure bits in mask match written values */
 static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask)
-- 
2.25.1



[PATCH v8 05/15] mtd: spi-nor-core: allow truncated erases

2021-05-03 Thread tkuw584924
From: Pratyush Yadav 

On devices with non-uniform sector sizes like Spansion S25 or S28 family
of flashes the sector under erase does not necessarily have to be
mtd->erasesize bytes long. For example, on S28 flashes the first 128 KiB
region is composed of 32 4 KiB sectors, then a 128 KiB sector, and then
256 KiB sectors till the end.

Let the flash-specific erase functions erase less than the requested
length in case of the 4 or 128 KiB sectors and report the number of
bytes erased back to the calling function.

Signed-off-by: Pratyush Yadav 
[takahiro.kuw...@infineon.com: base on master to exclude Octal/DTR
related changes]
Signed-off-by: Takahiro Kuwano 
---

Pratyush's original patch [0] depends on the other changes in his
series. Once his patch is accepted, I will rebase this series.

[0] 
https://patchwork.ozlabs.org/project/uboot/patch/20210401193133.18129-26-p.ya...@ti.com/

 drivers/mtd/spi/spi-nor-core.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 9f31e6b92a..829ad36903 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -660,7 +660,8 @@ static int read_bar(struct spi_nor *nor, const struct 
flash_info *info)
 #endif
 
 /*
- * Initiate the erasure of a single sector
+ * Initiate the erasure of a single sector. Returns the number of bytes erased
+ * on success, a negative error code on error.
  */
 static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
 {
@@ -669,6 +670,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 
addr)
   SPI_MEM_OP_ADDR(nor->addr_width, addr, 1),
   SPI_MEM_OP_NO_DUMMY,
   SPI_MEM_OP_NO_DATA);
+   int ret;
 
if (nor->erase)
return nor->erase(nor, addr);
@@ -677,7 +679,11 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 
addr)
 * Default implementation, if driver doesn't have a specialized HW
 * control
 */
-   return spi_mem_exec_op(nor->spi, );
+   ret = spi_mem_exec_op(nor->spi, );
+   if (ret)
+   return ret;
+
+   return nor->mtd.erasesize;
 }
 
 /*
@@ -713,11 +719,11 @@ static int spi_nor_erase(struct mtd_info *mtd, struct 
erase_info *instr)
write_enable(nor);
 
ret = spi_nor_erase_sector(nor, addr);
-   if (ret)
+   if (ret < 0)
goto erase_err;
 
-   addr += mtd->erasesize;
-   len -= mtd->erasesize;
+   addr += ret;
+   len -= ret;
 
ret = spi_nor_wait_till_ready(nor);
if (ret)
-- 
2.25.1



[PATCH v8 04/15] mtd: spi-nor-core: Introduce flash-specific fixup hooks

2021-05-03 Thread tkuw584924
From: Pratyush Yadav 

Sometimes the information in a flash's SFDP tables is wrong. Sometimes
some information just can't be expressed in the SFDP table. So,
introduce the fixup hooks to allow tailoring settings for a specific
flash.

Three hooks are added: default_init, post_sfdp, and post_bfpt. These
allow tweaking the flash settings at different point in the probe
sequence. Since the hooks reside in nor->info, set that value just
before the call to spi_nor_init_params().

The hooks and at what points they are executed mimics Linux's spi-nor
framework. One major difference is that Linux puts the struct
spi_nor_fixups in nor->info. This is not possible in U-Boot because the
spi-nor-ids list is shared between spi-nor-core.c and spi-nor-tiny.c.
Since spi-nor-tiny shouldn't have those fixup hooks populated, add a
separate function that lets flashes populate their fixup hooks.

Signed-off-by: Pratyush Yadav 
---

Taken from Pratyush's series:
https://patchwork.ozlabs.org/project/uboot/list/?series=237040=*

 drivers/mtd/spi/spi-nor-core.c | 78 --
 include/linux/mtd/spi-nor.h|  2 +
 2 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index eb58e9ea09..9f31e6b92a 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -152,6 +152,31 @@ struct sfdp_bfpt {
u32 dwords[BFPT_DWORD_MAX];
 };
 
+/**
+ * struct spi_nor_fixups - SPI NOR fixup hooks
+ * @default_init: called after default flash parameters init. Used to tweak
+ *flash parameters when information provided by the flash_info
+ *table is incomplete or wrong.
+ * @post_bfpt: called after the BFPT table has been parsed
+ * @post_sfdp: called after SFDP has been parsed (is also called for SPI NORs
+ * that do not support RDSFDP). Typically used to tweak various
+ * parameters that could not be extracted by other means (i.e.
+ * when information provided by the SFDP/flash_info tables are
+ * incomplete or wrong).
+ *
+ * Those hooks can be used to tweak the SPI NOR configuration when the SFDP
+ * table is broken or not available.
+ */
+struct spi_nor_fixups {
+   void (*default_init)(struct spi_nor *nor);
+   int (*post_bfpt)(struct spi_nor *nor,
+const struct sfdp_parameter_header *bfpt_header,
+const struct sfdp_bfpt *bfpt,
+struct spi_nor_flash_parameter *params);
+   void (*post_sfdp)(struct spi_nor *nor,
+ struct spi_nor_flash_parameter *params);
+};
+
 static int spi_nor_read_write_reg(struct spi_nor *nor, struct spi_mem_op
*op, void *buf)
 {
@@ -1751,6 +1776,18 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = 
{
 
 static int spi_nor_hwcaps_read2cmd(u32 hwcaps);
 
+static int
+spi_nor_post_bfpt_fixups(struct spi_nor *nor,
+const struct sfdp_parameter_header *bfpt_header,
+const struct sfdp_bfpt *bfpt,
+struct spi_nor_flash_parameter *params)
+{
+   if (nor->fixups && nor->fixups->post_bfpt)
+   return nor->fixups->post_bfpt(nor, bfpt_header, bfpt, params);
+
+   return 0;
+}
+
 /**
  * spi_nor_parse_bfpt() - read and parse the Basic Flash Parameter Table.
  * @nor:   pointer to a 'struct spi_nor'
@@ -1889,7 +1926,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 
/* Stop here if not JESD216 rev A or later. */
if (bfpt_header->length < BFPT_DWORD_MAX)
-   return 0;
+   return spi_nor_post_bfpt_fixups(nor, bfpt_header, ,
+   params);
 
/* Page size: this field specifies 'N' so the page size = 2^N bytes. */
params->page_size = bfpt.dwords[BFPT_DWORD(11)];
@@ -1922,7 +1960,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
return -EINVAL;
}
 
-   return 0;
+   return spi_nor_post_bfpt_fixups(nor, bfpt_header, , params);
 }
 
 /**
@@ -2085,6 +2123,29 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,
 }
 #endif /* SPI_FLASH_SFDP_SUPPORT */
 
+/**
+ * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings
+ * after SFDP has been parsed (is also called for SPI NORs that do not
+ * support RDSFDP).
+ * @nor:   pointer to a 'struct spi_nor'
+ *
+ * Typically used to tweak various parameters that could not be extracted by
+ * other means (i.e. when information provided by the SFDP/flash_info tables
+ * are incomplete or wrong).
+ */
+static void spi_nor_post_sfdp_fixups(struct spi_nor *nor,
+struct spi_nor_flash_parameter *params)
+{
+   if (nor->fixups && nor->fixups->post_sfdp)
+   nor->fixups->post_sfdp(nor, params);
+}
+
+static void spi_nor_default_init_fixups(struct spi_nor *nor)

[PATCH v8 03/15] mtd: spi-nor-core: Move SFDP related declarations to top

2021-05-03 Thread tkuw584924
From: Pratyush Yadav 

These structures will be used in a later commit inside another structure
definition. Also take the declarations out of the ifdef since they won't
affect the final binary anyway and will be used in a later commit.

Signed-off-by: Pratyush Yadav 
---

Taken from Pratyush's series:
https://patchwork.ozlabs.org/project/uboot/list/?series=237040=*

 drivers/mtd/spi/spi-nor-core.c | 224 -
 1 file changed, 112 insertions(+), 112 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index bda00fa76e..eb58e9ea09 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -40,6 +40,118 @@
 
 #define DEFAULT_READY_WAIT_JIFFIES (40UL * HZ)
 
+struct sfdp_parameter_header {
+   u8  id_lsb;
+   u8  minor;
+   u8  major;
+   u8  length; /* in double words */
+   u8  parameter_table_pointer[3]; /* byte address */
+   u8  id_msb;
+};
+
+#define SFDP_PARAM_HEADER_ID(p)(((p)->id_msb << 8) | (p)->id_lsb)
+#define SFDP_PARAM_HEADER_PTP(p) \
+   (((p)->parameter_table_pointer[2] << 16) | \
+((p)->parameter_table_pointer[1] <<  8) | \
+((p)->parameter_table_pointer[0] <<  0))
+
+#define SFDP_BFPT_ID   0xff00  /* Basic Flash Parameter Table */
+#define SFDP_SECTOR_MAP_ID 0xff81  /* Sector Map Table */
+#define SFDP_SST_ID0x01bf  /* Manufacturer specific Table */
+
+#define SFDP_SIGNATURE 0x50444653U
+#define SFDP_JESD216_MAJOR 1
+#define SFDP_JESD216_MINOR 0
+#define SFDP_JESD216A_MINOR5
+#define SFDP_JESD216B_MINOR6
+
+struct sfdp_header {
+   u32 signature; /* Ox50444653U <=> "SFDP" */
+   u8  minor;
+   u8  major;
+   u8  nph; /* 0-base number of parameter headers */
+   u8  unused;
+
+   /* Basic Flash Parameter Table. */
+   struct sfdp_parameter_headerbfpt_header;
+};
+
+/* Basic Flash Parameter Table */
+
+/*
+ * JESD216 rev B defines a Basic Flash Parameter Table of 16 DWORDs.
+ * They are indexed from 1 but C arrays are indexed from 0.
+ */
+#define BFPT_DWORD(i)  ((i) - 1)
+#define BFPT_DWORD_MAX 16
+
+/* The first version of JESB216 defined only 9 DWORDs. */
+#define BFPT_DWORD_MAX_JESD216 9
+
+/* 1st DWORD. */
+#define BFPT_DWORD1_FAST_READ_1_1_2BIT(16)
+#define BFPT_DWORD1_ADDRESS_BYTES_MASK GENMASK(18, 17)
+#define BFPT_DWORD1_ADDRESS_BYTES_3_ONLY   (0x0UL << 17)
+#define BFPT_DWORD1_ADDRESS_BYTES_3_OR_4   (0x1UL << 17)
+#define BFPT_DWORD1_ADDRESS_BYTES_4_ONLY   (0x2UL << 17)
+#define BFPT_DWORD1_DTRBIT(19)
+#define BFPT_DWORD1_FAST_READ_1_2_2BIT(20)
+#define BFPT_DWORD1_FAST_READ_1_4_4BIT(21)
+#define BFPT_DWORD1_FAST_READ_1_1_4BIT(22)
+
+/* 5th DWORD. */
+#define BFPT_DWORD5_FAST_READ_2_2_2BIT(0)
+#define BFPT_DWORD5_FAST_READ_4_4_4BIT(4)
+
+/* 11th DWORD. */
+#define BFPT_DWORD11_PAGE_SIZE_SHIFT   4
+#define BFPT_DWORD11_PAGE_SIZE_MASKGENMASK(7, 4)
+
+/* 15th DWORD. */
+
+/*
+ * (from JESD216 rev B)
+ * Quad Enable Requirements (QER):
+ * - 000b: Device does not have a QE bit. Device detects 1-1-4 and 1-4-4
+ * reads based on instruction. DQ3/HOLD# functions are hold during
+ * instruction phase.
+ * - 001b: QE is bit 1 of status register 2. It is set via Write Status with
+ * two data bytes where bit 1 of the second byte is one.
+ * [...]
+ * Writing only one byte to the status register has the side-effect of
+ * clearing status register 2, including the QE bit. The 100b code is
+ * used if writing one byte to the status register does not modify
+ * status register 2.
+ * - 010b: QE is bit 6 of status register 1. It is set via Write Status with
+ * one data byte where bit 6 is one.
+ * [...]
+ * - 011b: QE is bit 7 of status register 2. It is set via Write status
+ * register 2 instruction 3Eh with one data byte where bit 7 is one.
+ * [...]
+ * The status register 2 is read using instruction 3Fh.
+ * - 100b: QE is bit 1 of status register 2. It is set via Write Status with
+ * two data bytes where bit 1 of the second byte is one.
+ * [...]
+ * In contrast to the 001b code, writing one byte to the status
+ * register does not modify status register 2.
+ * - 101b: QE is bit 1 of status register 2. Status register 1 is read using
+ * Read Status instruction 05h. Status register2 is read using
+ * instruction 35h. QE is set via Writ Status instruction 01h with
+ * two data bytes where bit 1 of the second byte is one.
+ * [...]
+ */
+#define BFPT_DWORD15_QER_MASK  GENMASK(22, 

[PATCH v8 02/15] mtd: spi-nor-core: Add a ->setup() hook

2021-05-03 Thread tkuw584924
From: Pratyush Yadav 

nor->setup() can be used by flashes to configure settings in case they
have any peculiarities that can't be easily expressed by the generic
spi-nor framework. This includes things like different opcodes, dummy
cycles, page size, uniform/non-uniform sector sizes, etc.

Move related declarations to avoid forward declarations.

Inspired by the Linux kernel's setup() hook.

Signed-off-by: Pratyush Yadav 
---

Taken from Pratyush's series:
https://patchwork.ozlabs.org/project/uboot/list/?series=237040=*

 drivers/mtd/spi/spi-nor-core.c |  84 +++
 drivers/mtd/spi/spi-nor-tiny.c |  22 
 include/linux/mtd/spi-nor.h| 192 ++---
 3 files changed, 147 insertions(+), 151 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index e0efebc355..bda00fa76e 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -1451,71 +1451,6 @@ static int spansion_no_read_cr_quad_enable(struct 
spi_nor *nor)
 #endif /* CONFIG_SPI_FLASH_SFDP_SUPPORT */
 #endif /* CONFIG_SPI_FLASH_SPANSION */
 
-struct spi_nor_read_command {
-   u8  num_mode_clocks;
-   u8  num_wait_states;
-   u8  opcode;
-   enum spi_nor_protocol   proto;
-};
-
-struct spi_nor_pp_command {
-   u8  opcode;
-   enum spi_nor_protocol   proto;
-};
-
-enum spi_nor_read_command_index {
-   SNOR_CMD_READ,
-   SNOR_CMD_READ_FAST,
-   SNOR_CMD_READ_1_1_1_DTR,
-
-   /* Dual SPI */
-   SNOR_CMD_READ_1_1_2,
-   SNOR_CMD_READ_1_2_2,
-   SNOR_CMD_READ_2_2_2,
-   SNOR_CMD_READ_1_2_2_DTR,
-
-   /* Quad SPI */
-   SNOR_CMD_READ_1_1_4,
-   SNOR_CMD_READ_1_4_4,
-   SNOR_CMD_READ_4_4_4,
-   SNOR_CMD_READ_1_4_4_DTR,
-
-   /* Octo SPI */
-   SNOR_CMD_READ_1_1_8,
-   SNOR_CMD_READ_1_8_8,
-   SNOR_CMD_READ_8_8_8,
-   SNOR_CMD_READ_1_8_8_DTR,
-
-   SNOR_CMD_READ_MAX
-};
-
-enum spi_nor_pp_command_index {
-   SNOR_CMD_PP,
-
-   /* Quad SPI */
-   SNOR_CMD_PP_1_1_4,
-   SNOR_CMD_PP_1_4_4,
-   SNOR_CMD_PP_4_4_4,
-
-   /* Octo SPI */
-   SNOR_CMD_PP_1_1_8,
-   SNOR_CMD_PP_1_8_8,
-   SNOR_CMD_PP_8_8_8,
-
-   SNOR_CMD_PP_MAX
-};
-
-struct spi_nor_flash_parameter {
-   u64 size;
-   u32 page_size;
-
-   struct spi_nor_hwcaps   hwcaps;
-   struct spi_nor_read_command reads[SNOR_CMD_READ_MAX];
-   struct spi_nor_pp_command   page_programs[SNOR_CMD_PP_MAX];
-
-   int (*quad_enable)(struct spi_nor *nor);
-};
-
 static void
 spi_nor_set_read_settings(struct spi_nor_read_command *read,
  u8 num_mode_clocks,
@@ -2377,9 +2312,10 @@ static int spi_nor_select_erase(struct spi_nor *nor,
return 0;
 }
 
-static int spi_nor_setup(struct spi_nor *nor, const struct flash_info *info,
-const struct spi_nor_flash_parameter *params,
-const struct spi_nor_hwcaps *hwcaps)
+static int spi_nor_default_setup(struct spi_nor *nor,
+const struct flash_info *info,
+const struct spi_nor_flash_parameter *params,
+const struct spi_nor_hwcaps *hwcaps)
 {
u32 ignored_mask, shared_mask;
bool enable_quad_io;
@@ -2438,6 +2374,16 @@ static int spi_nor_setup(struct spi_nor *nor, const 
struct flash_info *info,
return 0;
 }
 
+static int spi_nor_setup(struct spi_nor *nor, const struct flash_info *info,
+const struct spi_nor_flash_parameter *params,
+const struct spi_nor_hwcaps *hwcaps)
+{
+   if (!nor->setup)
+   return 0;
+
+   return nor->setup(nor, info, params, hwcaps);
+}
+
 static int spi_nor_init(struct spi_nor *nor)
 {
int err;
@@ -2504,6 +2450,8 @@ int spi_nor_scan(struct spi_nor *nor)
nor->read_reg = spi_nor_read_reg;
nor->write_reg = spi_nor_write_reg;
 
+   nor->setup = spi_nor_default_setup;
+
if (spi->mode & SPI_RX_OCTAL) {
hwcaps.mask |= SNOR_HWCAPS_READ_1_1_8;
 
diff --git a/drivers/mtd/spi/spi-nor-tiny.c b/drivers/mtd/spi/spi-nor-tiny.c
index 07c8c7b82b..5cc2b7d996 100644
--- a/drivers/mtd/spi/spi-nor-tiny.c
+++ b/drivers/mtd/spi/spi-nor-tiny.c
@@ -555,28 +555,6 @@ static int spansion_read_cr_quad_enable(struct spi_nor 
*nor)
 }
 #endif /* CONFIG_SPI_FLASH_SPANSION */
 
-struct spi_nor_read_command {
-   u8  num_mode_clocks;
-   u8  num_wait_states;
-   u8  opcode;
-   enum spi_nor_protocol   proto;
-};
-
-enum spi_nor_read_command_index {
-   SNOR_CMD_READ,
-   SNOR_CMD_READ_FAST,
-
-   /* Quad SPI */
-   SNOR_CMD_READ_1_1_4,
-
-   SNOR_CMD_READ_MAX
-};
-
-struct 

[PATCH v8 01/15] arm: mvebu: x530: Use tiny SPI NOR

2021-05-03 Thread tkuw584924
From: Pratyush Yadav 

The SPI NOR core will get new functions in following commits. This has
presented a significant challenge of keeping the SPL size in check on
the x530 platform.

On a previous iteration of the series, adding a set of compile-time
switches got the build working. But rebasing on the latest master breaks
the build again. We are fighting a losing battle here. Every addition to
either the SPI NOR core in the future, or any other core part of U-Boot
will potentially lead to the SPL size going beyond the limit and the
build failing.

To combat this we will have to keep adding more and more compile-time
switches, increasing the complexity of the code in the process. This is
not sustainable. So use tiny SPI NOR instead. It is designed with
size-limited SPL binaries in mind, and will afford us more breathing
room.

To enable tiny SPI NOR, CONFIG_SPI_FLASH_BAR has to be disabled.

Signed-off-by: Pratyush Yadav 
[takahiro.kuw...@infineon.com: Make commit description suitable for
this series]
Signed-off-by: Takahiro Kuwano 
---
 configs/x530_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/x530_defconfig b/configs/x530_defconfig
index 890c94b5c1..0570dbe9ea 100644
--- a/configs/x530_defconfig
+++ b/configs/x530_defconfig
@@ -62,7 +62,6 @@ CONFIG_SYS_NAND_USE_FLASH_BBT=y
 CONFIG_NAND_PXA3XX=y
 CONFIG_SF_DEFAULT_BUS=1
 CONFIG_SF_DEFAULT_SPEED=5000
-CONFIG_SPI_FLASH_BAR=y
 CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_SST=y
-- 
2.25.1



[PATCH v8 00/15] mtd: spi-nor: Add support for Cypress s25hl-t/s25hs-t

2021-05-03 Thread tkuw584924
From: Takahiro Kuwano 

The S25HL-T/S25HS-T family is the Cypress Semper Flash with Quad SPI.

The summary datasheets can be found in the following links.
https://www.cypress.com/file/424146/download (256Mb/512Mb/1Gb, single die)
https://www.cypress.com/file/499246/download (2Gb/4Gb, dual/quad die)

The full version can be found in the following links (registration
required).
https://community.cypress.com/t5/Semper-Flash-Access-Program/Datasheet-Semper-Flash-with-Quad-SPI/ta-p/260789?attachment-id=19522
https://community.cypress.com/t5/Semper-Flash-Access-Program/Datasheet-2Gb-MCP-Semper-Flash-with-Quad-SPI/ta-p/260823?attachment-id=29503

Tested on Xilinx Zynq-7000 FPGA board.

Changes since v8:
  - Took another patch from Pratyush's series 
  - Define spansion_quad_enable_volatile() under CONFIG_SPI_FLASH_SPANSION

Changes since v7:
  - Fixed return type of s25hx_t_erase_non_uniform() to 'int'
  
Changes since v6:
  - Took some patches from Pratyush's series
  - Removed USE_CLSR flag from S25HL02GT and S25HS02GT
  - Defined SPINOR_OP_EX4B_CYPRESS and use it
  - Removed mtd.writesize fixup
  - Added uniform sector check for multi-die package parts
  - Remove spansion_quad_enable_volatile() from tiny
  - Fixed some other minor issues

Changes since v5:
  - Removed 256Mb and 4Gb parts support
  - Fixed register offset issue in spansion_quad_enable_volatile()
  - Added spi_nor_default_ready() and moved existing code into it
  - Separated spansion_sr_read() to new patch
  - Renamed spansion_overlaid_erase() to spansion_non_uniform_erase() and
changed the implementation to issue the proper erase command based on
the address
  - Added s25hx_t_erase_non_uniform()
  - Changed mtd.writesize and mtd.flags in s25hx_t_setup()
  - Fixed page size and erase size issues in s25hx_t_post_bfpt_fixup()

Changes since v4:
  - Added Read/Write Any Register support
  - Added the ->ready() hook to support multi-die package parts
  - Added S25HL02GT/S25HL04GT/S25HS02GT/S25HS04GT support
  
Changes since v3:
  - Split into multiple patches

Changes since v2:
  - Fixed typo in comment for spansion_overlaid_erase()
  - Fixed expressions for addr and len check in spansion_overlaid_erase()
  - Added device ID check to make the changes effective for S25 only
  - Added nor->setup() and fixup hooks based on the following patches

https://patchwork.ozlabs.org/project/uboot/patch/20200904153500.3569-7-p.ya...@ti.com/

https://patchwork.ozlabs.org/project/uboot/patch/20200904153500.3569-8-p.ya...@ti.com/

https://patchwork.ozlabs.org/project/uboot/patch/20200904153500.3569-9-p.ya...@ti.com/

Pratyush Yadav (5):
  arm: mvebu: x530: Use tiny SPI NOR
  mtd: spi-nor-core: Add a ->setup() hook
  mtd: spi-nor-core: Move SFDP related declarations to top
  mtd: spi-nor-core: Introduce flash-specific fixup hooks
  mtd: spi-nor-core: allow truncated erases

Takahiro Kuwano (10):
  mtd: spi-nor-core: Add non-uniform erase for Spansion/Cypress
  mtd: spi-nor: Add Cypress manufacturer ID
  mtd: spi-nor-ids: Add Cypress s25hl-t/s25hs-t
  mtd: spi-nor-core: Add support for Read/Write Any Register
  mtd: spi-nor-core: Add support for volatile QE bit
  mtd: spi-nor-core: Add the ->ready() hook
  mtd: spi-nor-core: Read status by Read Any Register
  mtd: spi-nor-core: Add Cypress manufacturer ID in set_4byte
  mtd: spi-nor-core: Add fixups for Cypress s25hl-t/s25hs-t
  mtd: spi-nor-tiny: Add fixups for Cypress s25hl-t/s25hs-t

 configs/x530_defconfig |   1 -
 drivers/mtd/spi/spi-nor-core.c | 725 -
 drivers/mtd/spi/spi-nor-ids.c  |  16 +
 drivers/mtd/spi/spi-nor-tiny.c |  28 +-
 include/linux/mtd/spi-nor.h| 205 +++---
 5 files changed, 702 insertions(+), 273 deletions(-)

-- 
2.25.1



[RFC 7/7] TEST: Move to gcc-11.0 prerelease and LLVM-11

2021-05-03 Thread Tom Rini
- gcc-11.0 proper is coming soon to kernel.org, use this snapshot for
  now to see what fails.
- grub-2.04 does not build with gcc-11.0 due to -Werror, grub-2.06-rc1
  fails on riscv32-linux as seen here:
  https://www.mail-archive.com/grub-devel@gnu.org/msg30736.html

Cc: Heinrich Schuchardt 
Signed-off-by: Tom Rini 
---
 .azure-pipelines.yml|  3 +-
 .gitlab-ci.yml  |  3 +-
 tools/docker/Dockerfile | 74 +
 3 files changed, 32 insertions(+), 48 deletions(-)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 59e99b8894c5..28e4d53ece71 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -2,7 +2,7 @@ variables:
   windows_vm: vs2017-win2016
   ubuntu_vm: ubuntu-18.04
   macos_vm: macOS-10.15
-  ci_runner_image: trini/u-boot-gitlab-ci-runner:bionic-20200807-02Sep2020
+  ci_runner_image: trini/u-boot-gitlab-ci-runner:bionic-20210416-29Apr2021
   # Add '-u 0' options for Azure pipelines, otherwise we get "permission
   # denied" error when it tries to "useradd -m -u 1001 vsts_azpcontainer",
   # since our $(ci_runner_image) user is not root.
@@ -312,7 +312,6 @@ jobs:
   cp ~/grub_x86.efi ${UBOOT_TRAVIS_BUILD_DIR}/
   cp ~/grub_x64.efi ${UBOOT_TRAVIS_BUILD_DIR}/
   cp /opt/grub/grubriscv64.efi 
${UBOOT_TRAVIS_BUILD_DIR}/grub_riscv64.efi
-  cp /opt/grub/grubriscv32.efi 
${UBOOT_TRAVIS_BUILD_DIR}/grub_riscv32.efi
   cp /opt/grub/grubaa64.efi ${UBOOT_TRAVIS_BUILD_DIR}/grub_arm64.efi
   cp /opt/grub/grubarm.efi ${UBOOT_TRAVIS_BUILD_DIR}/grub_arm.efi
   virtualenv -p /usr/bin/python3 /tmp/venv
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bff487404f30..02dc8449ecf9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,7 +2,7 @@
 
 # Grab our configured image.  The source for this is found at:
 # https://source.denx.de/u-boot/gitlab-ci-runner
-image: trini/u-boot-gitlab-ci-runner:bionic-20200807-02Sep2020
+image: trini/u-boot-gitlab-ci-runner:bionic-20210416-29Apr2021
 
 # We run some tests in different order, to catch some failures quicker.
 stages:
@@ -38,7 +38,6 @@ stages:
 - cp ~/grub_x86.efi $UBOOT_TRAVIS_BUILD_DIR/
 - cp ~/grub_x64.efi $UBOOT_TRAVIS_BUILD_DIR/
 - cp /opt/grub/grubriscv64.efi $UBOOT_TRAVIS_BUILD_DIR/grub_riscv64.efi
-- cp /opt/grub/grubriscv32.efi $UBOOT_TRAVIS_BUILD_DIR/grub_riscv32.efi
 - cp /opt/grub/grubaa64.efi $UBOOT_TRAVIS_BUILD_DIR/grub_arm64.efi
 - cp /opt/grub/grubarm.efi $UBOOT_TRAVIS_BUILD_DIR/grub_arm.efi
 - virtualenv -p /usr/bin/python3 /tmp/venv
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index d2f0074ee8a6..fb3155b7a28d 100644
--- a/tools/docker/Dockerfile
+++ b/tools/docker/Dockerfile
@@ -2,7 +2,7 @@
 # This Dockerfile is used to build an image containing basic stuff to be used
 # to build U-Boot and run our test suites.
 
-FROM ubuntu:bionic-20200807
+FROM ubuntu:bionic-20210416
 MAINTAINER Tom Rini 
 LABEL Description=" This image is for building U-Boot inside a container"
 
@@ -12,20 +12,20 @@ ENV DEBIAN_FRONTEND=noninteractive
 # Add LLVM repository
 RUN apt-get update && apt-get install -y gnupg2 wget xz-utils && rm -rf 
/var/lib/apt/lists/*
 RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
-RUN echo deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main | tee 
/etc/apt/sources.list.d/llvm.list
+RUN echo deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main | tee 
/etc/apt/sources.list.d/llvm.list
 
 # Manually install the kernel.org "Crosstool" based toolchains for gcc-7.3
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-aarch64-linux.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-arm-linux-gnueabi.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-i386-linux.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-m68k-linux.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-mips-linux.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-microblaze-linux.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-nios2-linux.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-powerpc-linux.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/9.2.0/x86_64-gcc-9.2.0-nolibc-riscv32-linux.tar.xz
 | tar -C /opt -xJ
-RUN wget -O - 

[RFC 6/7] bootstage: Eliminate when not enabled

2021-05-03 Thread Tom Rini
When we do not have bootstage enabled, rather than include an empty
dummy function, we just don't reference it.  This saves us space in some
tight builds.  This also shows a few cases where show_boot_progress was
incorrectly guarded before.

Cc: Simon Glass 
Signed-off-by: Tom Rini 
---
Moving to gcc-11 causes at least one well maintained and used board to
now run out of space, and this saves us 400 bytes in SPL.
---
 arch/x86/cpu/cpu.c| 2 ++
 board/Seagate/dockstar/dockstar.c | 2 ++
 board/Seagate/goflexhome/goflexhome.c | 2 ++
 board/bosch/shc/board.c   | 6 +++---
 board/buffalo/lsxl/lsxl.c | 2 +-
 board/k+p/kp_imx53/kp_imx53.c | 2 ++
 board/st/stv0991/stv0991.c| 2 +-
 common/init/board_init.c  | 2 ++
 common/spl/spl.c  | 2 ++
 include/bootstage.h   | 4 +++-
 10 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index 9c4edfcbfdaa..01dece5769c8 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -178,10 +178,12 @@ int default_print_cpuinfo(void)
return 0;
 }
 
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
 void show_boot_progress(int val)
 {
outb(val, POST_PORT);
 }
+#endif
 
 #if !defined(CONFIG_SYS_COREBOOT) && !defined(CONFIG_EFI_STUB)
 /*
diff --git a/board/Seagate/dockstar/dockstar.c 
b/board/Seagate/dockstar/dockstar.c
index 380e37be5502..fb6919315804 100644
--- a/board/Seagate/dockstar/dockstar.c
+++ b/board/Seagate/dockstar/dockstar.c
@@ -140,6 +140,7 @@ void reset_phy(void)
 }
 #endif /* CONFIG_RESET_PHY_R */
 
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
 #define GREEN_LED  (1 << 14)
 #define ORANGE_LED (1 << 15)
 #define BOTH_LEDS  (GREEN_LED | ORANGE_LED)
@@ -169,3 +170,4 @@ void show_boot_progress(int val)
break;
}
 }
+#endif
diff --git a/board/Seagate/goflexhome/goflexhome.c 
b/board/Seagate/goflexhome/goflexhome.c
index 4c19fa7195e8..af8cab7bdc73 100644
--- a/board/Seagate/goflexhome/goflexhome.c
+++ b/board/Seagate/goflexhome/goflexhome.c
@@ -142,6 +142,7 @@ void reset_phy(void)
 }
 #endif /* CONFIG_RESET_PHY_R */
 
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
 #define GREEN_LED  (1 << 14)
 #define ORANGE_LED (1 << 15)
 #define BOTH_LEDS  (GREEN_LED | ORANGE_LED)
@@ -175,3 +176,4 @@ void show_boot_progress(int val)
break;
}
 }
+#endif
diff --git a/board/bosch/shc/board.c b/board/bosch/shc/board.c
index e89378188728..01d9ce4f71f9 100644
--- a/board/bosch/shc/board.c
+++ b/board/bosch/shc/board.c
@@ -188,7 +188,7 @@ static void __maybe_unused leds_set_booting(void)
 /*
  * Function to set the LEDs in the state "Bootloader error"
  */
-static void leds_set_failure(int state)
+static void __maybe_unused leds_set_failure(int state)
 {
 #if defined(CONFIG_B_SAMPLE)
/* Turn all blue and green LEDs off */
@@ -479,7 +479,7 @@ int board_eth_init(struct bd_info *bis)
 }
 #endif
 
-#ifdef CONFIG_SHOW_BOOT_PROGRESS
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
 static void bosch_check_reset_pin(void)
 {
if (readl(GPIO1_BASE + OMAP_GPIO_IRQSTATUS_SET_0) & RESET_MASK) {
@@ -525,9 +525,9 @@ void show_boot_progress(int val)
break;
}
 }
+#endif
 
 void arch_preboot_os(void)
 {
leds_set_finish();
 }
-#endif
diff --git a/board/buffalo/lsxl/lsxl.c b/board/buffalo/lsxl/lsxl.c
index 34be601fdde6..738b6bc25cea 100644
--- a/board/buffalo/lsxl/lsxl.c
+++ b/board/buffalo/lsxl/lsxl.c
@@ -271,7 +271,7 @@ int misc_init_r(void)
 }
 #endif
 
-#ifdef CONFIG_SHOW_BOOT_PROGRESS
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
 void show_boot_progress(int progress)
 {
if (progress > 0)
diff --git a/board/k+p/kp_imx53/kp_imx53.c b/board/k+p/kp_imx53/kp_imx53.c
index cc8118b4ad4f..7c3a695cb258 100644
--- a/board/k+p/kp_imx53/kp_imx53.c
+++ b/board/k+p/kp_imx53/kp_imx53.c
@@ -155,6 +155,7 @@ int board_late_init(void)
return ret;
 }
 
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
 #define GPIO_DR 0x0
 #define GPIO_GDIR 0x4
 #define GPIO_ALT1 0x1
@@ -203,3 +204,4 @@ void show_boot_progress(int status)
gpio_direction_output(LED_RED, 1);
}
 }
+#endif
diff --git a/board/st/stv0991/stv0991.c b/board/st/stv0991/stv0991.c
index 3b0de82db283..57ca9f659c16 100644
--- a/board/st/stv0991/stv0991.c
+++ b/board/st/stv0991/stv0991.c
@@ -37,7 +37,7 @@ U_BOOT_DRVINFO(stv09911_serials) = {
 };
 #endif
 
-#ifdef CONFIG_SHOW_BOOT_PROGRESS
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
 void show_boot_progress(int progress)
 {
printf("%i\n", progress);
diff --git a/common/init/board_init.c b/common/init/board_init.c
index 3f183ee11326..0965b96fa3ad 100644
--- a/common/init/board_init.c
+++ b/common/init/board_init.c
@@ -166,7 +166,9 @@ void board_init_f_init_reserve(ulong base)
board_init_f_init_stack_protection();
 }
 
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
 /*
  * Board-specific Platform code can reimplement show_boot_progress () if needed
  */
 __weak void 

[RFC 5/7] Makefile: Disable gcc-10.0 warnings

2021-05-03 Thread Tom Rini
Based on 5c45de21a2223, 44720996e2d79 and 5a76021c2eff7 in Linux

Signed-off-by: Tom Rini 
---
 Makefile | 4 
 1 file changed, 4 insertions(+)

diff --git a/Makefile b/Makefile
index 404977efa527..aaa9a0495e69 100644
--- a/Makefile
+++ b/Makefile
@@ -687,6 +687,10 @@ KBUILD_CFLAGS += $(call 
cc-option,-fno-delete-null-pointer-checks)
 # disable stringop warnings in gcc 8+
 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
 
+KBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds)
+KBUILD_CFLAGS += $(call cc-disable-warning, array-bounds)
+KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
+
 # Enabled with W=2, disabled by default as noisy
 KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
 
-- 
2.17.1



[RFC 3/7] eb_cpu5282: Declare diplay_width / display_height as externs

2021-05-03 Thread Tom Rini
The board code here references the display_width / display_height
variables set in the video driver, declare these as externs as gcc-11
will notice and lead to a multiple definition error.

Signed-off-by: Tom Rini 
---
 board/BuS/eb_cpu5282/eb_cpu5282.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/board/BuS/eb_cpu5282/eb_cpu5282.c 
b/board/BuS/eb_cpu5282/eb_cpu5282.c
index 153ed0e963b0..144a08922b10 100644
--- a/board/BuS/eb_cpu5282/eb_cpu5282.c
+++ b/board/BuS/eb_cpu5282/eb_cpu5282.c
@@ -22,8 +22,8 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 #if IS_ENABLED(CONFIG_VIDEO_VCXK)
-unsigned long display_width;
-unsigned long display_height;
+extern unsigned long display_width;
+extern unsigned long display_height;
 #endif
 
 /*---*/
-- 
2.17.1



[RFC 4/7] pinctrl: mscc: Fix multiple definition error

2021-05-03 Thread Tom Rini
With gcc-11 we get a multiple errors here as the declarations for
mscc_pinctrl_ops and mscc_gpio_ops are missing an extern.

CC: Gregory CLEMENT 
Cc: Lars Povlsen 
Cc: Horatiu Vultur 
Signed-off-by: Tom Rini 
---
 drivers/pinctrl/mscc/mscc-common.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/mscc/mscc-common.h 
b/drivers/pinctrl/mscc/mscc-common.h
index 3c5c1faf840f..49c84a9f410b 100644
--- a/drivers/pinctrl/mscc/mscc-common.h
+++ b/drivers/pinctrl/mscc/mscc-common.h
@@ -61,6 +61,6 @@ int mscc_pinctrl_probe(struct udevice *dev, int num_func,
   const struct mscc_pin_data *mscc_pins, int num_pins,
   char * const *function_names,
   const unsigned long *mscc_gpios);
-const struct pinctrl_ops mscc_pinctrl_ops;
+extern const struct pinctrl_ops mscc_pinctrl_ops;
 
-const struct dm_gpio_ops mscc_gpio_ops;
+extern const struct dm_gpio_ops mscc_gpio_ops;
-- 
2.17.1



[RFC 2/7] freescale: Drop unnecessary cpld_data_t non-typedef

2021-05-03 Thread Tom Rini
In some board cpld.h files the definition of the cpld_data struct
not-quite makes a typedef for cpld_data_t.  This problem is caught with
gcc-11 as a multiple definition error.  As there are no users of this
non-typedef, fix this by not declaring it one to begin with.

Cc: Priyanka Jain 
Cc: Shengzhou Liu 
Signed-off-by: Tom Rini 
---
 board/freescale/t102xrdb/cpld.h | 2 +-
 board/freescale/t104xrdb/cpld.h | 3 +--
 board/freescale/t208xrdb/cpld.h | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/board/freescale/t102xrdb/cpld.h b/board/freescale/t102xrdb/cpld.h
index c05f536806fb..bd40cc319a89 100644
--- a/board/freescale/t102xrdb/cpld.h
+++ b/board/freescale/t102xrdb/cpld.h
@@ -21,7 +21,7 @@ struct cpld_data {
u8 boot_override;   /* 0x18 - Boot override register */
u8 boot_config1;/* 0x19 - Boot config override register*/
u8 boot_config2;/* 0x1A - Boot config override register*/
-} cpld_data_t;
+};
 
 
 /* Pointer to the CPLD register set */
diff --git a/board/freescale/t104xrdb/cpld.h b/board/freescale/t104xrdb/cpld.h
index a816aef10a42..769883f9461f 100644
--- a/board/freescale/t104xrdb/cpld.h
+++ b/board/freescale/t104xrdb/cpld.h
@@ -30,8 +30,7 @@ struct cpld_data {
u8 boot_override;   /* 0x18 - Boot override register */
u8 boot_config1;/* 0x19 - Boot config override register*/
u8 boot_config2;/* 0x1A - Boot config override register*/
-} cpld_data_t;
-
+};
 
 /* Pointer to the CPLD register set */
 
diff --git a/board/freescale/t208xrdb/cpld.h b/board/freescale/t208xrdb/cpld.h
index bd6c203742e3..a623b1811faf 100644
--- a/board/freescale/t208xrdb/cpld.h
+++ b/board/freescale/t208xrdb/cpld.h
@@ -21,7 +21,7 @@ struct cpld_data {
u8 boot_or; /* 0x16 - Boot config override register */
u8 boot_cfg1;   /* 0x17 - Boot configuration register 1 */
u8 boot_cfg2;   /* 0x18 - Boot configuration register 2 */
-} cpld_data_t;
+};
 
 u8 cpld_read(unsigned int reg);
 void cpld_write(unsigned int reg, u8 value);
-- 
2.17.1



[RFC 1/7] ARM: mvebu: a38x: Correct mismatched bound warnings

2021-05-03 Thread Tom Rini
With gcc-11 we see:
drivers/ddr/marvell/a38x/ddr3_debug.c:672:47: error: argument 2 of type 
'u32[5]' {aka 'unsigned int[5]'} with mismatched bound 
[-Werror=array-parameter=]
  672 | int ddr3_tip_read_adll_value(u32 dev_num, u32 
pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM],
  |   
^~~
In file included from drivers/ddr/marvell/a38x/ddr3_training_ip_engine.h:10,
 from drivers/ddr/marvell/a38x/ddr3_init.h:17,
 from drivers/ddr/marvell/a38x/ddr3_debug.c:6:
drivers/ddr/marvell/a38x/ddr3_training_ip_flow.h:116:47: note: previously 
declared as 'u32[]' {aka 'unsigned int[]'}

And similar warnings.  Correct these by updating the prototype.  Remove
the prototype for ddr3_tip_read_pup_value as it is unused.

Signed-off-by: Tom Rini 
---
 drivers/ddr/marvell/a38x/ddr3_training_ip_flow.h | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/ddr/marvell/a38x/ddr3_training_ip_flow.h 
b/drivers/ddr/marvell/a38x/ddr3_training_ip_flow.h
index ab152cb455e9..55832a55405b 100644
--- a/drivers/ddr/marvell/a38x/ddr3_training_ip_flow.h
+++ b/drivers/ddr/marvell/a38x/ddr3_training_ip_flow.h
@@ -8,6 +8,7 @@
 
 #include "ddr3_training_ip.h"
 #include "ddr3_training_ip_db.h"
+#include "mv_ddr_plat.h"
 
 #define KILLER_PATTERN_LENGTH  32
 #define EXT_ACCESS_BURST_LENGTH8
@@ -112,9 +113,12 @@ int ddr3_tip_configure_odpg(u32 dev_num, enum 
hws_access_type access_type,
 int ddr3_tip_write_mrs_cmd(u32 dev_num, u32 *cs_mask_arr, enum mr_number 
mr_num, u32 data, u32 mask);
 int ddr3_tip_write_cs_result(u32 dev_num, u32 offset);
 int ddr3_tip_reset_fifo_ptr(u32 dev_num);
-int ddr3_tip_read_pup_value(u32 dev_num, u32 pup_values[], int reg_addr, u32 
mask);
-int ddr3_tip_read_adll_value(u32 dev_num, u32 pup_values[], u32 reg_addr, u32 
mask);
-int ddr3_tip_write_adll_value(u32 dev_num, u32 pup_values[], u32 reg_addr);
+int ddr3_tip_read_adll_value(u32 dev_num,
+u32 pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM],
+u32 reg_addr, u32 mask);
+int ddr3_tip_write_adll_value(u32 dev_num,
+ u32 pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM],
+ u32 reg_addr);
 int ddr3_tip_tune_training_params(u32 dev_num, struct tune_train_params 
*params);
 
 #endif /* _DDR3_TRAINING_IP_FLOW_H_ */
-- 
2.17.1



[RFC 0/7] Update CI to using GCC 11.0 / LLVM-11

2021-05-03 Thread Tom Rini
Hey all,

This series does most of the work required to move to using GCC-11.0 to
build in CI.  The first thing is I realized I forgot to update buildman
to know to where to fetch gcc-11 from, but I'll take care of that later.
Next, this ends up using the last gcc-11 snapshot as the gcc-11.0
prebuilds aren't quite up on kernel.org, but will be soon.

The real issues here and I'd like some feedback on, and need some help
with are:
- grub + riscv32 + gcc-11 doesn't build, and this seems known but not
  addressed yet.  I don't know what we want to do here as it's for
  running some tests.
- I cannot get x86 to build.  With this series the failures are:
  https://source.denx.de/u-boot/u-boot/-/jobs/263745
  But I can't find a good way to address that multiple definition error
  of _X86EMU_env that doesn't break some other platform.  At heart,
  Chromebooks enable the emulation and we have both chromebook_link and
  chromebook_link64 as builds, so we have both X86_64 and !X86_64
  builds.  I don't know the best way to deal with this, but I also
  wonder if the bios_emulation code doesn't need a rather large cleaning
  perhaps?

-- 
Tom




Re: [PATCH v1 08/10] net: mvpp2: fix missing switch case break

2021-05-03 Thread Ramon Fried
On Mon, May 3, 2021 at 9:13 AM Stefan Roese  wrote:
>
> Hi Ramon,
>
> On 30.04.21 16:18, Ramon Fried wrote:
> > On Fri, Apr 30, 2021 at 7:40 AM Stefan Roese  wrote:
> >>
> >> On 29.04.21 22:24, Ramon Fried wrote:
> >>> On Tue, Apr 27, 2021 at 4:28 PM Stefan Roese  wrote:
> 
>  From: Ben Peled 
> 
>  Signed-off-by: Ben Peled 
>  Reviewed-by: Stefan Chulski 
>  Reviewed-by: Kostya Porotchkin 
>  Tested-by: sa_ip-sw-jenkins 
> >>> Please remove this, Jenkins is not a person.
> >>
> >> I've left these lines in because most of these patches are plain
> >> cherry-picked from the Marvell SDK.
> >>
> >> Should I resubmit this patch only or the complete patchset? Or could you
> >> perhaps remove this line while collecting the patches for a pull
> >> request?
> > Please submit the patchset again.
>
> Done. I just now noticed, that I forgot to add your RB tags. Should I
> send v3 with the RB tags?
No, that's fine.


Re: [PATCH v2 10/10] net: mvpp2: add explicit sgmii-2500 support

2021-05-03 Thread Ramon Fried
On Mon, May 3, 2021 at 9:09 AM Stefan Roese  wrote:
>
> From: Marcin Wojtas 
>
> Until now the mvpp2 driver used an extra 'phy-speed'
> DT property in order to differentiate between the
> SGMII and SGMII @2.5GHz. As there is a dedicated
> PHY_INTERFACE_MODE_SGMII_2500 flag to mark the latter
> start using it and drop the custom flag.
>
> Signed-off-by: Marcin Wojtas 
> Reviewed-by: Stefan Chulski 
> Reviewed-by: Nadav Haklai 
> Tested-by: Nadav Haklai 
>
> Signed-off-by: Stefan Roese 
> ---
>
> Changes in v2:
> - Removed all non-personal tags (Jenkins etc)
>
>  drivers/net/mvpp2.c | 28 
>  1 file changed, 12 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
> index c5bfe41281d6..4c0a7b0a9f5c 100644
> --- a/drivers/net/mvpp2.c
> +++ b/drivers/net/mvpp2.c
> @@ -976,8 +976,6 @@ struct mvpp2_port {
> unsigned int duplex;
> unsigned int speed;
>
> -   unsigned int phy_speed; /* SGMII 1Gbps vs 2.5Gbps */
> -
> struct mvpp2_bm_pool *pool_long;
> struct mvpp2_bm_pool *pool_short;
>
> @@ -2875,6 +2873,7 @@ static void mvpp2_port_mii_set(struct mvpp2_port *port)
>
> switch (port->phy_interface) {
> case PHY_INTERFACE_MODE_SGMII:
> +   case PHY_INTERFACE_MODE_SGMII_2500:
> val |= MVPP2_GMAC_INBAND_AN_MASK;
> break;
> case PHY_INTERFACE_MODE_1000BASEX:
> @@ -2942,6 +2941,7 @@ static void mvpp2_port_loopback_set(struct mvpp2_port 
> *port)
> val &= ~MVPP2_GMAC_GMII_LB_EN_MASK;
>
> if (port->phy_interface == PHY_INTERFACE_MODE_SGMII ||
> +   port->phy_interface == PHY_INTERFACE_MODE_SGMII_2500 ||
> port->phy_interface == PHY_INTERFACE_MODE_1000BASEX ||
> port->phy_interface == PHY_INTERFACE_MODE_2500BASEX)
> val |= MVPP2_GMAC_PCS_LB_EN_MASK;
> @@ -3239,12 +3239,11 @@ static int gop_gmac_mode_cfg(struct mvpp2_port *port)
> /* Set TX FIFO thresholds */
> switch (port->phy_interface) {
> case PHY_INTERFACE_MODE_SGMII:
> -   if (port->phy_speed == 2500)
> -   gop_gmac_sgmii2_5_cfg(port);
> -   else
> -   gop_gmac_sgmii_cfg(port);
> +   gop_gmac_sgmii_cfg(port);
> +   break;
> +   case PHY_INTERFACE_MODE_SGMII_2500:
> +   gop_gmac_sgmii2_5_cfg(port);
> break;
> -
> case PHY_INTERFACE_MODE_1000BASEX:
> gop_gmac_1000basex_cfg(port);
> break;
> @@ -3425,6 +3424,7 @@ static int gop_port_init(struct mvpp2_port *port)
> break;
>
> case PHY_INTERFACE_MODE_SGMII:
> +   case PHY_INTERFACE_MODE_SGMII_2500:
> case PHY_INTERFACE_MODE_1000BASEX:
> case PHY_INTERFACE_MODE_2500BASEX:
> /* configure PCS */
> @@ -3484,6 +3484,7 @@ static void gop_port_enable(struct mvpp2_port *port, 
> int enable)
> case PHY_INTERFACE_MODE_RGMII:
> case PHY_INTERFACE_MODE_RGMII_ID:
> case PHY_INTERFACE_MODE_SGMII:
> +   case PHY_INTERFACE_MODE_SGMII_2500:
> case PHY_INTERFACE_MODE_1000BASEX:
> case PHY_INTERFACE_MODE_2500BASEX:
> if (enable)
> @@ -3520,6 +3521,7 @@ static u32 mvpp2_netc_cfg_create(int gop_id, 
> phy_interface_t phy_type)
>
> if (gop_id == 2) {
> if (phy_type == PHY_INTERFACE_MODE_SGMII ||
> +   phy_type == PHY_INTERFACE_MODE_SGMII_2500 ||
> phy_type == PHY_INTERFACE_MODE_1000BASEX ||
> phy_type == PHY_INTERFACE_MODE_2500BASEX)
> val |= MV_NETC_GE_MAC2_SGMII;
> @@ -3530,6 +3532,7 @@ static u32 mvpp2_netc_cfg_create(int gop_id, 
> phy_interface_t phy_type)
>
> if (gop_id == 3) {
> if (phy_type == PHY_INTERFACE_MODE_SGMII ||
> +   phy_type == PHY_INTERFACE_MODE_SGMII_2500 ||
> phy_type == PHY_INTERFACE_MODE_1000BASEX ||
> phy_type == PHY_INTERFACE_MODE_2500BASEX)
> val |= MV_NETC_GE_MAC3_SGMII;
> @@ -4528,6 +4531,7 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
> case PHY_INTERFACE_MODE_RGMII:
> case PHY_INTERFACE_MODE_RGMII_ID:
> case PHY_INTERFACE_MODE_SGMII:
> +   case PHY_INTERFACE_MODE_SGMII_2500:
> case PHY_INTERFACE_MODE_1000BASEX:
> case PHY_INTERFACE_MODE_2500BASEX:
> mvpp2_gmac_max_rx_size_set(port);
> @@ -4838,15 +4842,6 @@ static int phy_info_parse(struct udevice *dev, struct 
> mvpp2_port *port)
>  >phy_tx_disable_gpio, GPIOD_IS_OUT);
>  #endif
>
> -   /*
> -* ToDo:
> -* Not sure if this DT property "phy-speed" will get accepted, so
> -* this might change later
> -*/
> -   /* Get phy-speed for SGMII 2.5Gbps vs 1Gbps setup */
> -   port->phy_speed = 

Re: [PATCH v2 08/10] net: mvpp2: fix missing switch case break

2021-05-03 Thread Ramon Fried
On Mon, May 3, 2021 at 9:09 AM Stefan Roese  wrote:
>
> From: Ben Peled 
>
> Signed-off-by: Ben Peled 
> Reviewed-by: Stefan Chulski 
> Reviewed-by: Kostya Porotchkin 
> Signed-off-by: Stefan Roese 
> ---
>
> (no changes since v1)
>
>  drivers/net/mvpp2.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
> index 61a0ea0894a7..3d920e85ffef 100644
> --- a/drivers/net/mvpp2.c
> +++ b/drivers/net/mvpp2.c
> @@ -3247,9 +3247,11 @@ static int gop_gmac_mode_cfg(struct mvpp2_port *port)
>
> case PHY_INTERFACE_MODE_1000BASEX:
> gop_gmac_1000basex_cfg(port);
> +   break;
>
> case PHY_INTERFACE_MODE_2500BASEX:
> gop_gmac_2500basex_cfg(port);
> +   break;
>
> case PHY_INTERFACE_MODE_RGMII:
> case PHY_INTERFACE_MODE_RGMII_ID:
> --
> 2.31.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH v2 07/10] net: mvpp2: remove unused define MVPP22_SMI_PHY_ADDR_REG

2021-05-03 Thread Ramon Fried
On Mon, May 3, 2021 at 9:09 AM Stefan Roese  wrote:
>
> From: Ben Peled 
>
> Signed-off-by: Ben Peled 
> Reviewed-by: Stefan Chulski 
> Reviewed-by: Kostya Porotchkin 
> Signed-off-by: Stefan Roese 
> ---
>
> (no changes since v1)
>
>  drivers/net/mvpp2.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
> index 879289452b15..61a0ea0894a7 100644
> --- a/drivers/net/mvpp2.c
> +++ b/drivers/net/mvpp2.c
> @@ -490,9 +490,6 @@ do {  
>   \
>  #define MVPP22_SMI_MISC_CFG_REG(MVPP22_SMI + 0x04)
>  #define  MVPP22_SMI_POLLING_EN BIT(10)
>
> -#define MVPP22_SMI_PHY_ADDR_REG(port)  (MVPP22_SMI + 0x04 + \
> -(0x4 * (port)))
> -
>  #define MVPP2_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
>
>  /* Descriptor ring Macros */
> --
> 2.31.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH v2 04/10] net: mvpp2: remove redundant SMI address configuration

2021-05-03 Thread Ramon Fried
On Mon, May 3, 2021 at 9:08 AM Stefan Roese  wrote:
>
> From: Marcin Wojtas 
>
> Because the mvpp2 driver now relies on the PHYLIB and
> the external MDIO driver, configuring low level
> SMI bus settings is redundant.
>
> Signed-off-by: Marcin Wojtas 
> Reviewed-by: Kostya Porotchkin 
> Reviewed-by: Stefan Chulski 
> Signed-off-by: Stefan Roese 
> ---
>
> (no changes since v1)
>
>  drivers/net/mvpp2.c | 12 
>  1 file changed, 12 deletions(-)
>
> diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
> index 847007d5b487..2043bdf10aa4 100644
> --- a/drivers/net/mvpp2.c
> +++ b/drivers/net/mvpp2.c
> @@ -5292,14 +5292,6 @@ static int mvpp2_write_hwaddr(struct udevice *dev)
> return mvpp2_prs_update_mac_da(port, port->dev_addr);
>  }
>
> -static int mvpp22_smi_phy_addr_cfg(struct mvpp2_port *port)
> -{
> -   writel(port->phyaddr, port->priv->iface_base +
> -  MVPP22_SMI_PHY_ADDR_REG(port->gop_id));
> -
> -   return 0;
> -}
> -
>  static int mvpp2_base_probe(struct udevice *dev)
>  {
> struct mvpp2 *priv = dev_get_priv(dev);
> @@ -5422,10 +5414,6 @@ static int mvpp2_probe(struct udevice *dev)
> port->base = priv->iface_base + MVPP22_PORT_BASE +
> port->gop_id * MVPP22_PORT_OFFSET;
>
> -   /* Set phy address of the port */
> -   if (port->phyaddr < PHY_MAX_ADDR)
> -   mvpp22_smi_phy_addr_cfg(port);
> -
> /* GoP Init */
> gop_port_init(port);
> }
> --
> 2.31.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH v2 03/10] net: mvpp2: add 1000BaseX and 2500BaseX ppv2 support

2021-05-03 Thread Ramon Fried
On Mon, May 3, 2021 at 9:08 AM Stefan Roese  wrote:
>
> From: Stefan Chulski 
>
> Signed-off-by: Stefan Chulski 
> Signed-off-by: Stefan Roese 
> ---
>
> (no changes since v1)
>
>  drivers/net/mvpp2.c | 117 ++--
>  1 file changed, 112 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
> index 015f5329de74..847007d5b487 100644
> --- a/drivers/net/mvpp2.c
> +++ b/drivers/net/mvpp2.c
> @@ -2880,6 +2880,10 @@ static void mvpp2_port_mii_set(struct mvpp2_port *port)
> case PHY_INTERFACE_MODE_SGMII:
> val |= MVPP2_GMAC_INBAND_AN_MASK;
> break;
> +   case PHY_INTERFACE_MODE_1000BASEX:
> +   case PHY_INTERFACE_MODE_2500BASEX:
> +   val &= ~MVPP2_GMAC_INBAND_AN_MASK;
> +   break;
> case PHY_INTERFACE_MODE_RGMII:
> case PHY_INTERFACE_MODE_RGMII_ID:
> val |= MVPP2_GMAC_PORT_RGMII_MASK;
> @@ -2940,7 +2944,9 @@ static void mvpp2_port_loopback_set(struct mvpp2_port 
> *port)
> else
> val &= ~MVPP2_GMAC_GMII_LB_EN_MASK;
>
> -   if (port->phy_interface == PHY_INTERFACE_MODE_SGMII)
> +   if (port->phy_interface == PHY_INTERFACE_MODE_SGMII ||
> +   port->phy_interface == PHY_INTERFACE_MODE_1000BASEX ||
> +   port->phy_interface == PHY_INTERFACE_MODE_2500BASEX)
> val |= MVPP2_GMAC_PCS_LB_EN_MASK;
> else
> val &= ~MVPP2_GMAC_PCS_LB_EN_MASK;
> @@ -3051,10 +3057,10 @@ static void gop_gmac_sgmii2_5_cfg(struct mvpp2_port 
> *port)
>
> val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
> /*
> -* Configure GIG MAC to 1000Base-X mode connected to a fiber
> +* Configure GIG MAC to SGMII mode connected to a fiber
>  * transceiver
>  */
> -   val |= MVPP2_GMAC_PORT_TYPE_MASK;
> +   val &= ~MVPP2_GMAC_PORT_TYPE_MASK;
> writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
>
> /* configure AN 0x9268 */
> @@ -3106,6 +3112,89 @@ static void gop_gmac_sgmii_cfg(struct mvpp2_port *port)
> writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
>  }
>
> +static void gop_gmac_2500basex_cfg(struct mvpp2_port *port)
> +{
> +   u32 val, thresh;
> +
> +   /*
> +* Configure minimal level of the Tx FIFO before the lower part
> +* starts to read a packet
> +*/
> +   thresh = MVPP2_SGMII2_5_TX_FIFO_MIN_TH;
> +   val = readl(port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG);
> +   val &= ~MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK;
> +   val |= MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(thresh);
> +   writel(val, port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG);
> +
> +   /* Disable bypass of sync module */
> +   val = readl(port->base + MVPP2_GMAC_CTRL_4_REG);
> +   val |= MVPP2_GMAC_CTRL4_SYNC_BYPASS_MASK;
> +   /* configure DP clock select according to mode */
> +   val |= MVPP2_GMAC_CTRL4_DP_CLK_SEL_MASK;
> +   /* configure QSGMII bypass according to mode */
> +   val |= MVPP2_GMAC_CTRL4_QSGMII_BYPASS_ACTIVE_MASK;
> +   writel(val, port->base + MVPP2_GMAC_CTRL_4_REG);
> +
> +   val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
> +   /*
> +* Configure GIG MAC to 2500Base-X mode connected to a fiber
> +* transceiver
> +*/
> +   val |= MVPP2_GMAC_PORT_TYPE_MASK;
> +   writel(val, port->base + MVPP2_GMAC_CTRL_0_REG);
> +
> +   /* In 2500BaseX mode, we can't negotiate speed
> +* and we do not want InBand autoneg
> +* bypass enabled (link interrupt storm risk
> +* otherwise).
> +*/
> +   val = MVPP2_GMAC_EN_PCS_AN |
> +   MVPP2_GMAC_CONFIG_GMII_SPEED  |
> +   MVPP2_GMAC_CONFIG_FULL_DUPLEX |
> +   MVPP2_GMAC_CHOOSE_SAMPLE_TX_CONFIG;
> +   writel(val, port->base + MVPP2_GMAC_AUTONEG_CONFIG);
> +}
> +
> +static void gop_gmac_1000basex_cfg(struct mvpp2_port *port)
> +{
> +   u32 val, thresh;
> +
> +   /*
> +* Configure minimal level of the Tx FIFO before the lower part
> +* starts to read a packet
> +*/
> +   thresh = MVPP2_SGMII_TX_FIFO_MIN_TH;
> +   val = readl(port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG);
> +   val &= ~MVPP2_GMAC_TX_FIFO_MIN_TH_ALL_MASK;
> +   val |= MVPP2_GMAC_TX_FIFO_MIN_TH_MASK(thresh);
> +   writel(val, port->base + MVPP2_GMAC_PORT_FIFO_CFG_1_REG);
> +
> +   /* Disable bypass of sync module */
> +   val = readl(port->base + MVPP2_GMAC_CTRL_4_REG);
> +   val |= MVPP2_GMAC_CTRL4_SYNC_BYPASS_MASK;
> +   /* configure DP clock select according to mode */
> +   val &= ~MVPP2_GMAC_CTRL4_DP_CLK_SEL_MASK;
> +   /* configure QSGMII bypass according to mode */
> +   val |= MVPP2_GMAC_CTRL4_QSGMII_BYPASS_ACTIVE_MASK;
> +   writel(val, port->base + MVPP2_GMAC_CTRL_4_REG);
> +
> +   val = readl(port->base + MVPP2_GMAC_CTRL_0_REG);
> +   /* configure GIG 

Re: [PATCH 03/16] ARM: dts: imxrt1020: add alias to osc

2021-05-03 Thread Giulio Benetti


> Il giorno 3 mag 2021, alle ore 20:21, Fabio Estevam  ha 
> scritto:
> 
> On Mon, May 3, 2021 at 2:52 PM Giulio Benetti
>  wrote:
> 
>> Ok, is it ok if it even repeats the first line? Because I don’t know what 
>> write more than that.
> 
> Yes, that would be fine.

Ok thank you. This was a doubt I always had.

Giulio


Re: [PATCH 03/16] ARM: dts: imxrt1020: add alias to osc

2021-05-03 Thread Fabio Estevam
On Mon, May 3, 2021 at 2:52 PM Giulio Benetti
 wrote:

> Ok, is it ok if it even repeats the first line? Because I don’t know what 
> write more than that.

Yes, that would be fine.


[PATCH] imx: ventana: enable dm support for PCI and FEC ethernet

2021-05-03 Thread Tim Harvey
Enable driver model support for FEC ethernet which allows us to remove
the iomux and board_eth_init function. Replace the toggling of the ethernet
phy reset with dt configuration.

Enable driver model support for PCI which allows us to remove the
eth1000_initialize() call. Additionally enable PCI_INIT_R to scan for
PCI devices on init such as the e1000 that is present on the GW552x.

Convert board_pci_fixup to use dm callback and remove pcidisable env
variable which is not supported for DM_PCI and thus leave PCI always
enabled during init.

Signed-off-by: Tim Harvey 
---
v2: rebase
---
 arch/arm/dts/imx6qdl-gw51xx.dtsi|  2 +
 arch/arm/dts/imx6qdl-gw52xx.dtsi|  2 +
 arch/arm/dts/imx6qdl-gw53xx.dtsi|  3 +
 arch/arm/dts/imx6qdl-gw54xx.dtsi|  3 +
 arch/arm/dts/imx6qdl-gw560x.dtsi|  2 +
 arch/arm/dts/imx6qdl-gw5903.dtsi|  3 +
 arch/arm/dts/imx6qdl-gw5904.dtsi|  3 +
 arch/arm/dts/imx6qdl-gw5907.dtsi|  2 +
 arch/arm/dts/imx6qdl-gw5910.dtsi|  3 +
 arch/arm/dts/imx6qdl-gw5912.dtsi|  4 +
 arch/arm/dts/imx6qdl-gw5913.dtsi|  3 +
 board/gateworks/gw_ventana/common.h |  1 -
 board/gateworks/gw_ventana/gw_ventana.c | 99 -
 configs/gwventana_emmc_defconfig|  5 ++
 configs/gwventana_gw5904_defconfig  |  5 ++
 configs/gwventana_nand_defconfig|  5 ++
 include/configs/gw_ventana.h| 10 ---
 17 files changed, 61 insertions(+), 94 deletions(-)

diff --git a/arch/arm/dts/imx6qdl-gw51xx.dtsi b/arch/arm/dts/imx6qdl-gw51xx.dtsi
index 2a21c6731e..7e28463084 100644
--- a/arch/arm/dts/imx6qdl-gw51xx.dtsi
+++ b/arch/arm/dts/imx6qdl-gw51xx.dtsi
@@ -129,6 +129,8 @@
pinctrl-0 = <_enet>;
phy-mode = "rgmii-id";
phy-reset-gpios = < 30 GPIO_ACTIVE_LOW>;
+   phy-reset-duration = <10>;
+   phy-reset-post-delay = <100>;
status = "okay";
 };
 
diff --git a/arch/arm/dts/imx6qdl-gw52xx.dtsi b/arch/arm/dts/imx6qdl-gw52xx.dtsi
index 6eedf8d40d..f1d9ba1fac 100644
--- a/arch/arm/dts/imx6qdl-gw52xx.dtsi
+++ b/arch/arm/dts/imx6qdl-gw52xx.dtsi
@@ -195,6 +195,8 @@
pinctrl-0 = <_enet>;
phy-mode = "rgmii-id";
phy-reset-gpios = < 30 GPIO_ACTIVE_LOW>;
+   phy-reset-duration = <10>;
+   phy-reset-post-delay = <100>;
status = "okay";
 };
 
diff --git a/arch/arm/dts/imx6qdl-gw53xx.dtsi b/arch/arm/dts/imx6qdl-gw53xx.dtsi
index 9deec7e352..172a45ba17 100644
--- a/arch/arm/dts/imx6qdl-gw53xx.dtsi
+++ b/arch/arm/dts/imx6qdl-gw53xx.dtsi
@@ -188,6 +188,8 @@
pinctrl-0 = <_enet>;
phy-mode = "rgmii-id";
phy-reset-gpios = < 30 GPIO_ACTIVE_LOW>;
+   phy-reset-duration = <10>;
+   phy-reset-post-delay = <100>;
status = "okay";
 };
 
@@ -597,6 +599,7 @@
MX6QDL_PAD_ENET_MDIO__ENET_MDIO 0x1b0b0
MX6QDL_PAD_ENET_MDC__ENET_MDC   0x1b0b0
MX6QDL_PAD_GPIO_16__ENET_REF_CLK0x4001b0a8
+   MX6QDL_PAD_ENET_TXD0__GPIO1_IO300x1b0b0
>;
};
 
diff --git a/arch/arm/dts/imx6qdl-gw54xx.dtsi b/arch/arm/dts/imx6qdl-gw54xx.dtsi
index a30ba4848e..e09fad6068 100644
--- a/arch/arm/dts/imx6qdl-gw54xx.dtsi
+++ b/arch/arm/dts/imx6qdl-gw54xx.dtsi
@@ -225,6 +225,8 @@
pinctrl-0 = <_enet>;
phy-mode = "rgmii-id";
phy-reset-gpios = < 30 GPIO_ACTIVE_LOW>;
+   phy-reset-duration = <10>;
+   phy-reset-post-delay = <100>;
status = "okay";
 };
 
@@ -675,6 +677,7 @@
MX6QDL_PAD_ENET_MDIO__ENET_MDIO 0x1b0b0
MX6QDL_PAD_ENET_MDC__ENET_MDC   0x1b0b0
MX6QDL_PAD_GPIO_16__ENET_REF_CLK0x4001b0a8
+   MX6QDL_PAD_ENET_TXD0__GPIO1_IO300x1b0b0
>;
};
 
diff --git a/arch/arm/dts/imx6qdl-gw560x.dtsi b/arch/arm/dts/imx6qdl-gw560x.dtsi
index 0786b0d546..bfe65fd3c0 100644
--- a/arch/arm/dts/imx6qdl-gw560x.dtsi
+++ b/arch/arm/dts/imx6qdl-gw560x.dtsi
@@ -279,6 +279,8 @@
pinctrl-0 = <_enet>;
phy-mode = "rgmii-id";
phy-reset-gpios = < 30 GPIO_ACTIVE_LOW>;
+   phy-reset-duration = <10>;
+   phy-reset-post-delay = <100>;
status = "okay";
 };
 
diff --git a/arch/arm/dts/imx6qdl-gw5903.dtsi b/arch/arm/dts/imx6qdl-gw5903.dtsi
index 78f9ec90b7..6ebf6aef2f 100644
--- a/arch/arm/dts/imx6qdl-gw5903.dtsi
+++ b/arch/arm/dts/imx6qdl-gw5903.dtsi
@@ -223,6 +223,9 @@
pinctrl-names = "default";
pinctrl-0 = <_enet>;
phy-mode = "rgmii-id";
+   phy-reset-gpios = < 30 GPIO_ACTIVE_LOW>;
+   phy-reset-duration = <10>;
+   phy-reset-post-delay = <100>;
status = "okay";
 };
 
diff --git a/arch/arm/dts/imx6qdl-gw5904.dtsi b/arch/arm/dts/imx6qdl-gw5904.dtsi
index 5b7bd56932..9adbd728dc 100644
--- a/arch/arm/dts/imx6qdl-gw5904.dtsi
+++ b/arch/arm/dts/imx6qdl-gw5904.dtsi
@@ -200,6 +200,9 @@
   

am335x: Unable to boot u-boot image from mmc1

2021-05-03 Thread 粘博閎
Hi all,

I try to build u-boot by config of am335x_evm_test_defconfig on branch
master and burn to sd card on beaglebone black.

When I boot the device, the print the string "Trying to boot from MMC1".

But I build u-boot by config of am335x_evm_test_defconfig on branch
v2019.04 and boot normally.

Thanks. Regards.


Re: [PATCH 03/16] ARM: dts: imxrt1020: add alias to osc

2021-05-03 Thread Giulio Benetti
Hi Gabio,

> Il giorno 3 mag 2021, alle ore 16:01, Fabio Estevam  ha 
> scritto:
> 
> Hi Giulio,
> 
>> On Wed, Apr 7, 2021 at 4:03 PM Giulio Benetti
>>  wrote:
>> 
>> Signed-off-by: Giulio Benetti 
>> ---
>> arch/arm/dts/imxrt1020.dtsi | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/arch/arm/dts/imxrt1020.dtsi b/arch/arm/dts/imxrt1020.dtsi
>> index 97f3cec9f3..0a3a3b451a 100644
>> --- a/arch/arm/dts/imxrt1020.dtsi
>> +++ b/arch/arm/dts/imxrt1020.dtsi
>> @@ -36,7 +36,7 @@
>>clock-frequency = <0>;
>>};
>> 
>> -   osc {
>> +   osc: osc {
> 
> Nit: what you are adding here is a "node label", not an "alias".
Thank you, you’re right.
> 
> It would be nice to always add a commit log, even if it is a short one.

Ok, is it ok if it even repeats the first line? Because I don’t know what write 
more than that.

Best regards
Giulio Benetti


Re: [PATCH] ARM: stm32: Add additional ID register check for KSZ8851 presence

2021-05-03 Thread Patrice CHOTARD
Hi Marek

On 5/3/21 1:31 PM, Marek Vasut wrote:
> Currently the code sets eth1addr only if /ethernet1 alias exists in DT,
> the node pointed to by the alias has "micrel,ks8851-mll" compatible
> string, and the KSZ8851 CCR register read indicates programmed EEPROM
> is not connected.
> 
> This is not sufficient to detect cases where the DT still contains the
> KSZ8851 nodes, but the chip itself is not present. Extend the detection
> to handle these cases.
> 
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> ---
>  board/dhelectronics/dh_stm32mp1/board.c | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/board/dhelectronics/dh_stm32mp1/board.c 
> b/board/dhelectronics/dh_stm32mp1/board.c
> index 49b12c4c042..ac1af718d4a 100644
> --- a/board/dhelectronics/dh_stm32mp1/board.c
> +++ b/board/dhelectronics/dh_stm32mp1/board.c
> @@ -86,6 +86,8 @@ DECLARE_GLOBAL_DATA_PTR;
>  #define KS_CCR_EEPROMBIT(9)
>  #define KS_BE0   BIT(12)
>  #define KS_BE1   BIT(13)
> +#define KS_CIDER 0xC0
> +#define CIDER_ID 0x8870
>  
>  int setup_mac_address(void)
>  {
> @@ -123,11 +125,18 @@ int setup_mac_address(void)
>* is present. If EEPROM is present, it must contain valid
>* MAC address.
>*/
> - u32 reg, ccr;
> + u32 reg, cider, ccr;
>   reg = fdt_get_base_address(gd->fdt_blob, off);
>   if (!reg)
>   goto out_set_ethaddr;
>  
> + writew(KS_BE0 | KS_BE1 | KS_CIDER, reg + 2);
> + cider = readw(reg);
> + if ((cider & 0xfff0) != CIDER_ID) {
> + skip_eth1 = true;
> + goto out_set_ethaddr;
> + }
> +
>   writew(KS_BE0 | KS_BE1 | KS_CCR, reg + 2);
>   ccr = readw(reg);
>   if (ccr & KS_CCR_EEPROM) {
> 

Reviewed-by: Patrice Chotard 

Thanks
Patrice


Re: [PATCH] ARM: stm32: Enable UNZIP on DHSOM by default

2021-05-03 Thread Patrice CHOTARD
Hi Marek

On 5/3/21 1:31 PM, Marek Vasut wrote:
> The CMD_UNZIP provides the 'gzwrite' command, which is convenient
> for writing e.g. gz-compressed images to eMMC from U-Boot.
> 
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> ---
>  configs/stm32mp15_dhcom_basic_defconfig | 1 +
>  configs/stm32mp15_dhcor_basic_defconfig | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/configs/stm32mp15_dhcom_basic_defconfig 
> b/configs/stm32mp15_dhcom_basic_defconfig
> index e36d34d001e..df702547081 100644
> --- a/configs/stm32mp15_dhcom_basic_defconfig
> +++ b/configs/stm32mp15_dhcom_basic_defconfig
> @@ -36,6 +36,7 @@ CONFIG_SYS_PROMPT="STM32MP> "
>  CONFIG_CMD_EEPROM=y
>  CONFIG_CMD_MEMINFO=y
>  CONFIG_CMD_MEMTEST=y
> +CONFIG_CMD_UNZIP=y
>  CONFIG_CMD_ADC=y
>  CONFIG_CMD_CLK=y
>  CONFIG_CMD_DFU=y
> diff --git a/configs/stm32mp15_dhcor_basic_defconfig 
> b/configs/stm32mp15_dhcor_basic_defconfig
> index 4794b1a14d5..4508d4158af 100644
> --- a/configs/stm32mp15_dhcor_basic_defconfig
> +++ b/configs/stm32mp15_dhcor_basic_defconfig
> @@ -34,6 +34,7 @@ CONFIG_SYS_PROMPT="STM32MP> "
>  CONFIG_CMD_EEPROM=y
>  CONFIG_CMD_MEMINFO=y
>  CONFIG_CMD_MEMTEST=y
> +CONFIG_CMD_UNZIP=y
>  CONFIG_CMD_ADC=y
>  CONFIG_CMD_CLK=y
>  CONFIG_CMD_DFU=y
> 
Reviewed-by: Patrice Chotard 

Thanks
Patrice


Re: [PATCH 03/16] ARM: dts: imxrt1020: add alias to osc

2021-05-03 Thread Fabio Estevam
Hi Giulio,

On Wed, Apr 7, 2021 at 4:03 PM Giulio Benetti
 wrote:
>
> Signed-off-by: Giulio Benetti 
> ---
>  arch/arm/dts/imxrt1020.dtsi | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/dts/imxrt1020.dtsi b/arch/arm/dts/imxrt1020.dtsi
> index 97f3cec9f3..0a3a3b451a 100644
> --- a/arch/arm/dts/imxrt1020.dtsi
> +++ b/arch/arm/dts/imxrt1020.dtsi
> @@ -36,7 +36,7 @@
> clock-frequency = <0>;
> };
>
> -   osc {
> +   osc: osc {

Nit: what you are adding here is a "node label", not an "alias".

It would be nice to always add a commit log, even if it is a short one.


Re: [Uboot-stm32] [PATCH 1/2] cmd: pinmux: update result of do_status

2021-05-03 Thread Patrick DELAUNAY

Hi Simon,

On 4/29/21 6:10 PM, Simon Glass wrote:

Hi Patrick,

On Tue, 20 Apr 2021 at 03:21, Patrice CHOTARD  wrote:

Hi Patrick

-Original Message-
From: Uboot-stm32  On Behalf 
Of Patrick DELAUNAY
Sent: mercredi 28 octobre 2020 11:07
To: u-boot@lists.denx.de
Cc: U-Boot STM32 ; Simon Glass 
; Patrick DELAUNAY ; Sean Anderson 

Subject: [Uboot-stm32] [PATCH 1/2] cmd: pinmux: update result of do_status

Update the result of do_status and alway returns a CMD_RET_ value (-ENOSYS was 
a possible result of show_pinmux).

This patch also adds pincontrol name in error messages (dev->name) and treats 
correctly the status sub command when pin-controller device is not selected.

Signed-off-by: Patrick Delaunay 
---

  cmd/pinmux.c | 44 +++-
  test/py/tests/test_pinmux.py |  4 ++--
  2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/cmd/pinmux.c b/cmd/pinmux.c index 9942b15419..af04c95a46 100644
--- a/cmd/pinmux.c
+++ b/cmd/pinmux.c
@@ -41,7 +41,7 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc,
 return CMD_RET_SUCCESS;
  }

-static int show_pinmux(struct udevice *dev)

I think it is better to return the error code and let the caller
ignore it, If we later want to report the error code, we can.



ok even if this static is only a help of do_status I will continue to 
return the result.




+static void show_pinmux(struct udevice *dev)
  {
 char pin_name[PINNAME_SIZE];
 char pin_mux[PINMUX_SIZE];
@@ -51,54 +51,56 @@ static int show_pinmux(struct udevice *dev)

 pins_count = pinctrl_get_pins_count(dev);

-   if (pins_count == -ENOSYS) {
-   printf("Ops get_pins_count not supported\n");
-   return pins_count;
+   if (pins_count < 0) {

Why change this to < 0 ?

I believe that -ENOSYS is the only valid error. We should update the
get_pins_count() API function to indicate that.


I think that any value < 0 was allowed ...

/**
* pinctrl_get_pins_count() - Display pin-controller pins number
* @dev:Pinctrl device to use
*
* This allows to know the number of pins owned by a given pin-controller
*
* Return: Number of pins if OK, or negative error code on failure
*/
intpinctrl_get_pins_count(structudevice*dev);
with
intpinctrl_get_pins_count(structudevice*dev)
{ struct pinctrl_ops *ops = pinctrl_get_ops(dev); if 
(!ops->get_pins_count) return -ENOSYS;

returnops->get_pins_count(dev);
}
But after check you are right: the ops don't allow negative value for error
/**
* @get_pins_count:Get the number of selectable pins
*
* @dev:Pinctrl device to use
*
* This function is necessary to parse the "pins" property in DTS.
*
* @Return:
* number of selectable named pins available in this driver
*/
int(*get_pins_count)(structudevice*dev);
I will update the API doc and this check.

+   printf("Ops get_pins_count not supported by %s\n", dev->name);
+   return;
 }

  (...)

  static int do_list(struct cmd_tbl *cmdtp, int flag, int argc, diff --git 
a/test/py/tests/test_pinmux.py b/test/py/tests/test_pinmux.py index 
0cbbae000c..b3ae2ab024 100644
--- a/test/py/tests/test_pinmux.py
+++ b/test/py/tests/test_pinmux.py
@@ -13,9 +13,9 @@ def test_pinmux_usage_1(u_boot_console):
  @pytest.mark.buildconfigspec('cmd_pinmux')
  def test_pinmux_usage_2(u_boot_console):
  """Test that 'pinmux status' executed without previous "pinmux dev"
-command displays pinmux usage."""
+command displays error message."""
  output = u_boot_console.run_command('pinmux status')
-assert 'Usage:' in output
+assert 'pin-controller device not selected' in output

  @pytest.mark.buildconfigspec('cmd_pinmux')
  @pytest.mark.boardspec('sandbox')

Reviewed-by: Patrice Chotard 

Thanks
Patrice

Regards,
Simon
___
Uboot-stm32 mailing list
uboot-st...@st-md-mailman.stormreply.com
https://st-md-mailman.stormreply.com/mailman/listinfo/uboot-stm32


Regards

Patrick



  1   2   >