Re: [PATCH] tools: mksunxiboot: Use sunxi_image header directly

2021-10-14 Thread Samuel Holland
On 10/13/21 7:19 PM, Andre Przywara wrote:
> On Tue, 12 Oct 2021 19:35:41 -0500
> Samuel Holland  wrote:
> 
>> When adding eGON support to mkimage, the struct boot_file_head
>> definition was moved to its own header. This is the only thing
>> mksunxiboot needed out of asm/arch/spl.h. Clean up the relative
>> include by switching to new header.
>>
>> Signed-off-by: Samuel Holland 
> 
> Reviewed-by: Andre Przywara 
> 
>> ---
>> We switched from using mksunxiboot to mkimage in January, so maybe
>> it is about time to consider dropping this tool?
> 
> Well, is there a reason to remove it? Otherwise I don't see a problem
> to keep it around for a while, 9 months is not a terribly long time for
> some people.

No, there's not a particular reason. I was reminded that this file still
exists because I tried refactoring some things to isolate SPL code, and
I broke it. Now that it's fixed, leaving it is not too much trouble.

Regards,
Samuel


[RFC PATCH 1/1] tools: mkimage: Add Allwinner TOC1 support

2021-10-14 Thread Samuel Holland
TOC1 is an container format used by Allwinner's boot0 that can hold
multiple images. It supports encryption and signatures, but that
functionality is not implemented, only the basic "non-secure" subset.

A config file is used to provide the list of data files to include. Its
path is passed as the argument to "-d". It contains sections of the
following form:

  [name]
  file = /path/to/file
  addr = 0x12345678

Specific well-known names, such as "dtb", "opensbi", and "u-boot", are
used by the bootloader to distinguish the items inside the image.

Signed-off-by: Samuel Holland 
---

 common/image.c|   1 +
 include/image.h   |   1 +
 include/sunxi_image.h |  26 
 tools/Makefile|   1 +
 tools/sunxi_toc1.c| 318 ++
 5 files changed, 347 insertions(+)
 create mode 100644 tools/sunxi_toc1.c

diff --git a/common/image.c b/common/image.c
index d15b47ebbe..a2b925c0c5 100644
--- a/common/image.c
+++ b/common/image.c
@@ -186,6 +186,7 @@ static const table_entry_t uimage_type[] = {
{   IH_TYPE_COPRO, "copro", "Coprocessor Image"},
{   IH_TYPE_SUNXI_EGON, "sunxi_egon",  "Allwinner eGON Boot Image" 
},
{   IH_TYPE_SUNXI_TOC0, "sunxi_toc0",  "Allwinner TOC0 Boot Image" 
},
+   {   IH_TYPE_SUNXI_TOC1, "sunxi_toc1",  "Allwinner TOC1 Boot Image" 
},
{   -1, "",   "",   },
 };
 
diff --git a/include/image.h b/include/image.h
index 1547246ec8..eb165f34da 100644
--- a/include/image.h
+++ b/include/image.h
@@ -228,6 +228,7 @@ enum {
IH_TYPE_COPRO,  /* Coprocessor Image for remoteproc*/
IH_TYPE_SUNXI_EGON, /* Allwinner eGON Boot Image */
IH_TYPE_SUNXI_TOC0, /* Allwinner TOC0 Boot Image */
+   IH_TYPE_SUNXI_TOC1, /* Allwinner TOC1 Boot Image */
 
IH_TYPE_COUNT,  /* Number of image types */
 };
diff --git a/include/sunxi_image.h b/include/sunxi_image.h
index 379ca9196e..98f381bbe6 100644
--- a/include/sunxi_image.h
+++ b/include/sunxi_image.h
@@ -116,4 +116,30 @@ struct __packed toc0_item_info {
 #define TOC0_ITEM_INFO_NAME_KEY0x00010303
 #define TOC0_ITEM_INFO_END "IIE;"
 
+struct __packed toc1_main_info {
+   uint8_t name[16];
+   __le32  magic;
+   __le32  checksum;
+   __le32  serial;
+   __le32  status;
+   __le32  num_items;
+   __le32  length;
+   __le32  major_version;
+   __le32  minor_version;
+   __le32  reserved[3];
+   uint8_t end[4];
+};
+
+struct __packed toc1_item_info {
+   uint8_t name[64];
+   __le32  offset;
+   __le32  length;
+   __le32  encryption;
+   __le32  type;
+   __le32  load_addr;
+   __le32  index;
+   __le32  reserved[69];
+   uint8_t end[4];
+};
+
 #endif
diff --git a/tools/Makefile b/tools/Makefile
index e2aeb097aa..8b42f3ff6f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -132,6 +132,7 @@ dumpimage-mkimage-objs := aisimage.o \
$(ROCKCHIP_OBS) \
socfpgaimage.o \
sunxi_egon.o \
+   sunxi_toc1.o \
lib/crc16.o \
lib/hash-checksum.o \
lib/sha1.o \
diff --git a/tools/sunxi_toc1.c b/tools/sunxi_toc1.c
new file mode 100644
index 00..7dd3f5d52a
--- /dev/null
+++ b/tools/sunxi_toc1.c
@@ -0,0 +1,318 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018 Arm Ltd.
+ * (C) Copyright 2020-2021 Samuel Holland 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "imagetool.h"
+#include "mkimage.h"
+
+#define SECTOR_SIZE512
+
+struct item_desc {
+   const char  *name;
+   const char  *file;
+   unsigned long   addr;
+   longlength;
+};
+
+static uint32_t toc1_header_length(uint32_t num_items)
+{
+   return ALIGN(sizeof(struct toc1_main_info) +
+sizeof(struct toc1_item_info) * num_items, SECTOR_SIZE);
+}
+
+static int toc1_parse_cfg(const char *file, struct item_desc **desc,
+ uint32_t *main_length, uint32_t *num_items)
+{
+   struct item_desc *descs = NULL;
+   int ret = EXIT_FAILURE;
+   FILE *cfg, *fp = NULL;
+   uint32_t ndescs = 0;
+   char *line = NULL;
+   size_t len = 0;
+
+   *desc = NULL;
+   *main_length = 0;
+   *num_items = 0;
+
+   cfg = fopen(file, "r");
+   if (!cfg)
+   return ret;
+
+   while (getline(, , cfg) > 0) {
+   char *end, *s;
+
+   if (line[0] == '[') {
+   s = line + 1;
+   end = strchr(s, ']');
+   if (!end || end[1] != '\n')
+   goto err;
+   end[0] = '\0';
+
+   ndescs++;
+ 

[RFC PATCH 0/1] tools: mkimage: Add Allwinner TOC1 support

2021-10-14 Thread Samuel Holland
The SPL port for the Allwinner D1 RISC-V SoC will probably take a while
longer than porting U-Boot proper, as none of the relevant drivers are
set up for DM in SPL. In the meantime, we are using[1][2] a fork[3] of
Allwinner's boot0 loader, which they also call "spl" in their BSP. boot0
uses this TOC1 image format.

The vendor tools for generating TOC1 images require a binary config file
generated by their FEX compiler. Instead of trying to support that, I
made up a simple human-readable config file format. I didn't see any
existing platform-agnostic parser for multi-image containers in mkimage.

I am sending this as RFC because it is only of temporary/limited use.
It only works with one specific fork of boot0 which was modified to
"behave" (the the original vendor version monkey-patches a custom header
inside the U-Boot image during boot). So it will be obsolete once U-Boot
SPL is ported. And it is Yet Another Image Format. On the other hand, it
does work, and it is currently being used.

[1]: https://linux-sunxi.org/Allwinner_Nezha#U-Boot
[2]: https://fedoraproject.org/wiki/Architectures/RISC-V/Allwinner
[3]: https://github.com/smaeul/sun20i_d1_spl


Samuel Holland (1):
  tools: mkimage: Add Allwinner TOC1 support

 common/image.c|   1 +
 include/image.h   |   1 +
 include/sunxi_image.h |  26 
 tools/Makefile|   1 +
 tools/sunxi_toc1.c| 318 ++
 5 files changed, 347 insertions(+)
 create mode 100644 tools/sunxi_toc1.c

-- 
2.32.0



[PATCH v3 2/4] tools: mkimage: Add Allwinner TOC0 support

2021-10-14 Thread Samuel Holland
Most Allwinner sunxi SoCs have separate boot ROMs in non-secure and
secure mode. The "non-secure" or "normal" boot ROM (NBROM) uses the
existing sunxi_egon image type. The secure boot ROM (SBROM) uses a
completely different image type, known as TOC0.

A TOC0 image is composed of a header and two or more items. One item
is the firmware binary. The others form a chain linking the firmware
signature to the root-of-trust public key (ROTPK), which has its hash
burned in the SoC's eFuses. Signatures are made using RSA-2048 + SHA256.

The pseudo-ASN.1 structure is manually assembled; this is done to work
around bugs/quirks in the boot ROM, which vary between SoCs. This TOC0
implementation has been verified to work with the A50, A64, H5, H6,
and H616 SBROMs, and it may work with other SoCs.

Signed-off-by: Samuel Holland 
---

Changes in v3:
 - Removed TOOLS_LIBCRYPTO selection for sunxi, since most boards
   do not need it
 - Added __packed to all new "ABI" structs
 - Added entry to MAINTAINERS for sunxi tools

Changes in v2:
 - Moved certificate and key item structures out of sunxi_image.h
 - Renamed "main" and "item" variables for clarity
 - Improved error messages, and added a hint about key generation
 - Added a comment explaining the purpose of the various key files
 - Mentioned testing this code on A50 in the commit message

 MAINTAINERS   |   1 +
 common/image.c|   1 +
 include/image.h   |   1 +
 include/sunxi_image.h |  37 ++
 tools/Makefile|   3 +-
 tools/sunxi_toc0.c| 907 ++
 6 files changed, 949 insertions(+), 1 deletion(-)
 create mode 100644 tools/sunxi_toc0.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 71f468c00a..0d62829f51 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -475,6 +475,7 @@ F:  board/sunxi/
 F: drivers/clk/sunxi/
 F: drivers/phy/allwinner/
 F: drivers/video/sunxi/
+F: tools/sunxi*
 
 ARM TEGRA
 M: Tom Warren 
diff --git a/common/image.c b/common/image.c
index 3fa60b5827..d15b47ebbe 100644
--- a/common/image.c
+++ b/common/image.c
@@ -185,6 +185,7 @@ static const table_entry_t uimage_type[] = {
{   IH_TYPE_MTKIMAGE,   "mtk_image",   "MediaTek BootROM loadable 
Image" },
{   IH_TYPE_COPRO, "copro", "Coprocessor Image"},
{   IH_TYPE_SUNXI_EGON, "sunxi_egon",  "Allwinner eGON Boot Image" 
},
+   {   IH_TYPE_SUNXI_TOC0, "sunxi_toc0",  "Allwinner TOC0 Boot Image" 
},
{   -1, "",   "",   },
 };
 
diff --git a/include/image.h b/include/image.h
index 34d13ada84..1547246ec8 100644
--- a/include/image.h
+++ b/include/image.h
@@ -227,6 +227,7 @@ enum {
IH_TYPE_IMX8IMAGE,  /* Freescale IMX8Boot Image */
IH_TYPE_COPRO,  /* Coprocessor Image for remoteproc*/
IH_TYPE_SUNXI_EGON, /* Allwinner eGON Boot Image */
+   IH_TYPE_SUNXI_TOC0, /* Allwinner TOC0 Boot Image */
 
IH_TYPE_COUNT,  /* Number of image types */
 };
diff --git a/include/sunxi_image.h b/include/sunxi_image.h
index 5b2055c0af..379ca9196e 100644
--- a/include/sunxi_image.h
+++ b/include/sunxi_image.h
@@ -9,9 +9,13 @@
  *
  * Shared between mkimage and the SPL.
  */
+
 #ifndefSUNXI_IMAGE_H
 #defineSUNXI_IMAGE_H
 
+#include 
+#include 
+
 #define BOOT0_MAGIC"eGON.BT0"
 #define BROM_STAMP_VALUE   0x5f0a6c39
 #define SPL_SIGNATURE  "SPL" /* marks "sunxi" SPL header */
@@ -79,4 +83,37 @@ struct boot_file_head {
 /* Compile time check to assure proper alignment of structure */
 typedef char boot_file_head_not_multiple_of_32[1 - 2*(sizeof(struct 
boot_file_head) % 32)];
 
+struct __packed toc0_main_info {
+   uint8_t name[8];
+   __le32  magic;
+   __le32  checksum;
+   __le32  serial;
+   __le32  status;
+   __le32  num_items;
+   __le32  length;
+   uint8_t platform[4];
+   uint8_t reserved[8];
+   uint8_t end[4];
+};
+
+#define TOC0_MAIN_INFO_NAME"TOC0.GLH"
+#define TOC0_MAIN_INFO_MAGIC   0x89119800
+#define TOC0_MAIN_INFO_END "MIE;"
+
+struct __packed toc0_item_info {
+   __le32  name;
+   __le32  offset;
+   __le32  length;
+   __le32  status;
+   __le32  type;
+   __le32  load_addr;
+   uint8_t reserved[4];
+   uint8_t end[4];
+};
+
+#define TOC0_ITEM_INFO_NAME_CERT   0x00010101
+#define TOC0_ITEM_INFO_NAME_FIRMWARE   0x00010202
+#define TOC0_ITEM_INFO_NAME_KEY0x00010303
+#define TOC0_ITEM_INFO_END "IIE;"
+
 #endif
diff --git a/tools/Makefile b/tools/Makefile
index a9b3d982d8..e2aeb097aa 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -98,7 +98,8 @@ AES_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := $(addprefix lib/aes/, \
 LIBCRYPTO_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := \
lib/fdt-libcrypto.o \
kwbimage.o \
-   mxsimage.o

[PATCH v3 4/4] sunxi: Support building a SPL as a TOC0 image

2021-10-14 Thread Samuel Holland
Now that mkimage can generate TOC0 images, and the SPL can interpret
them, hook up the build infrastructure so the user can choose which
image type to build. Since the absolute load address is stored in the
TOC0 header, that information must be passed to mkimage.

Signed-off-by: Samuel Holland 
---

(no changes since v2)

Changes in v2:
 - Rebase on top of Icenowy's RISC-V support series
 - Rename Kconfig symbols to include the full image type name

 arch/arm/mach-sunxi/Kconfig |  2 ++
 board/sunxi/Kconfig | 24 
 scripts/Makefile.spl|  5 -
 3 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 board/sunxi/Kconfig

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 2c18cf02d1..879efb9f61 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -1050,6 +1050,8 @@ config BLUETOOTH_DT_DEVICE_FIXUP
  The used address is "bdaddr" if set, and "ethaddr" with the LSB
  flipped elsewise.
 
+source "board/sunxi/Kconfig"
+
 endif
 
 config CHIP_DIP_SCAN
diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig
new file mode 100644
index 00..084a8b0c6c
--- /dev/null
+++ b/board/sunxi/Kconfig
@@ -0,0 +1,24 @@
+choice
+   prompt "SPL Image Type"
+   default SPL_IMAGE_TYPE_SUNXI_EGON
+
+config SPL_IMAGE_TYPE_SUNXI_EGON
+   bool "eGON (normal)"
+   help
+ Select this option to embed the SPL binary in an eGON.BT0 image,
+ which is compatible with the normal boot ROM (NBROM).
+
+ This is usually the correct option to choose.
+
+config SPL_IMAGE_TYPE_SUNXI_TOC0
+   bool "TOC0 (secure)"
+   help
+ Select this option to embed the SPL binary in a TOC0 image,
+ which is compatible with the secure boot ROM (SBROM).
+
+endchoice
+
+config SPL_IMAGE_TYPE
+   string
+   default "sunxi_egon" if SPL_IMAGE_TYPE_SUNXI_EGON
+   default "sunxi_toc0" if SPL_IMAGE_TYPE_SUNXI_TOC0
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 4cc23799db..635fa14cb9 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -411,7 +411,10 @@ endif
 $(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
$(call if_changed,mkimage)
 
-MKIMAGEFLAGS_sunxi-spl.bin = -A $(ARCH) -T sunxi_egon \
+MKIMAGEFLAGS_sunxi-spl.bin = \
+   -A $(ARCH) \
+   -T $(CONFIG_SPL_IMAGE_TYPE) \
+   -a $(CONFIG_SPL_TEXT_BASE) \
-n $(CONFIG_DEFAULT_DEVICE_TREE)
 
 OBJCOPYFLAGS_u-boot-spl-dtb.hex := -I binary -O ihex 
--change-address=$(CONFIG_SPL_TEXT_BASE)
-- 
2.32.0



[PATCH v3 3/4] sunxi: Support SPL in both eGON and TOC0 images

2021-10-14 Thread Samuel Holland
SPL uses the image header to detect the boot device and to find the
offset of the next U-Boot stage. Since this information is stored
differently in the eGON and TOC0 image headers, add code to find the
correct value based on the image type currently in use.

Signed-off-by: Samuel Holland 
---

Changes in v3:
 - Fixed offset of magic passed to memcmp
 - Refactored functions to not return pointers (fixes ambiguous NULL)

Changes in v2:
 - Moved SPL header signature checks out of sunxi_image.h
 - Refactored SPL header signature checks to use fewer casts

 arch/arm/include/asm/arch-sunxi/spl.h |  2 --
 arch/arm/mach-sunxi/board.c   | 34 ++-
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/arch/arm/include/asm/arch-sunxi/spl.h 
b/arch/arm/include/asm/arch-sunxi/spl.h
index 58cdf806d9..157b11e489 100644
--- a/arch/arm/include/asm/arch-sunxi/spl.h
+++ b/arch/arm/include/asm/arch-sunxi/spl.h
@@ -19,8 +19,6 @@
 #define SUNXI_BOOTED_FROM_MMC0_HIGH0x10
 #define SUNXI_BOOTED_FROM_MMC2_HIGH0x12
 
-#define is_boot0_magic(addr)   (memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0)
-
 uint32_t sunxi_get_boot_device(void);
 
 #endif
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index b4ba2a72c4..b2cd64bb3f 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -243,12 +243,28 @@ void s_init(void)
 
 #define SUNXI_INVALID_BOOT_SOURCE  -1
 
+static int sunxi_egon_valid(struct boot_file_head *egon_head)
+{
+   return !memcmp(egon_head->magic, BOOT0_MAGIC, 8); /* eGON.BT0 */
+}
+
+static int sunxi_toc0_valid(struct toc0_main_info *toc0_info)
+{
+   return !memcmp(toc0_info->name, TOC0_MAIN_INFO_NAME, 8); /* TOC0.GLH */
+}
+
 static int sunxi_get_boot_source(void)
 {
-   if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */
-   return SUNXI_INVALID_BOOT_SOURCE;
+   struct boot_file_head *egon_head = (void *)SPL_ADDR;
+   struct toc0_main_info *toc0_info = (void *)SPL_ADDR;
+
+   if (sunxi_egon_valid(egon_head))
+   return readb(_head->boot_media);
+   if (sunxi_toc0_valid(toc0_info))
+   return readb(_info->platform[0]);
 
-   return readb(SPL_ADDR + 0x28);
+   /* Not a valid image, so we must have been booted via FEL. */
+   return SUNXI_INVALID_BOOT_SOURCE;
 }
 
 /* The sunxi internal brom will try to loader external bootloader
@@ -296,10 +312,16 @@ uint32_t sunxi_get_boot_device(void)
 #ifdef CONFIG_SPL_BUILD
 static u32 sunxi_get_spl_size(void)
 {
-   if (!is_boot0_magic(SPL_ADDR + 4)) /* eGON.BT0 */
-   return 0;
+   struct boot_file_head *egon_head = (void *)SPL_ADDR;
+   struct toc0_main_info *toc0_info = (void *)SPL_ADDR;
 
-   return readl(SPL_ADDR + 0x10);
+   if (sunxi_egon_valid(egon_head))
+   return readl(_head->length);
+   if (sunxi_toc0_valid(toc0_info))
+   return readl(_info->length);
+
+   /* Not a valid image, so use the default U-Boot offset. */
+   return 0;
 }
 
 /*
-- 
2.32.0



[PATCH v3 1/4] tools: Separate image types which depend on OpenSSL

2021-10-14 Thread Samuel Holland
Some image types (kwbimage and mxsimage) always depend on OpenSSL, so
they can only be included in mkimage when TOOLS_LIBCRYPTO is selected.
Use Makefile logic to conditionally link the files.

When building for platforms which use those image types, automatically
select TOOLS_LIBCRYPTO, since it is required for the build to complete.

Signed-off-by: Samuel Holland 
---

Changes in v3:
 - Selected TOOLS_LIBCRYPTO on all platforms that use kwbimage (as best
   as I can tell, using the suggestions from Pali Rohár)

Changes in v2:
 - Refactored the first patch on top of TOOLS_LIBCRYPTO

 arch/arm/Kconfig  |  3 +++
 arch/arm/mach-imx/mxs/Kconfig |  2 ++
 scripts/config_whitelist.txt  |  1 -
 tools/Makefile| 19 +--
 tools/mxsimage.c  |  3 ---
 5 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d8c041a877..380ad4f670 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -566,6 +566,7 @@ config ARCH_KIRKWOOD
select BOARD_EARLY_INIT_F
select CPU_ARM926EJS
select GPIO_EXTRA_HEADER
+   select TOOLS_LIBCRYPTO
 
 config ARCH_MVEBU
bool "Marvell MVEBU family (Armada XP/375/38x/3700/7K/8K)"
@@ -580,12 +581,14 @@ config ARCH_MVEBU
select OF_CONTROL
select OF_SEPARATE
select SPI
+   select TOOLS_LIBCRYPTO
imply CMD_DM
 
 config ARCH_ORION5X
bool "Marvell Orion"
select CPU_ARM926EJS
select GPIO_EXTRA_HEADER
+   select TOOLS_LIBCRYPTO
 
 config TARGET_STV0991
bool "Support stv0991"
diff --git a/arch/arm/mach-imx/mxs/Kconfig b/arch/arm/mach-imx/mxs/Kconfig
index b2026a3758..6f138d25e9 100644
--- a/arch/arm/mach-imx/mxs/Kconfig
+++ b/arch/arm/mach-imx/mxs/Kconfig
@@ -3,6 +3,7 @@ if ARCH_MX23
 config MX23
bool
default y
+   select TOOLS_LIBCRYPTO
 
 choice
prompt "MX23 board select"
@@ -34,6 +35,7 @@ if ARCH_MX28
 config MX28
bool
default y
+   select TOOLS_LIBCRYPTO
 
 choice
prompt "MX28 board select"
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
index 3a6865dc70..bea6b6f83b 100644
--- a/scripts/config_whitelist.txt
+++ b/scripts/config_whitelist.txt
@@ -838,7 +838,6 @@ CONFIG_MXC_UART_BASE
 CONFIG_MXC_USB_FLAGS
 CONFIG_MXC_USB_PORT
 CONFIG_MXC_USB_PORTSC
-CONFIG_MXS
 CONFIG_MXS_AUART
 CONFIG_MXS_AUART_BASE
 CONFIG_MXS_OCOTP
diff --git a/tools/Makefile b/tools/Makefile
index 999fd46531..a9b3d982d8 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -94,9 +94,11 @@ ECDSA_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := $(addprefix 
lib/ecdsa/, ecdsa-libcrypto.
 AES_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := $(addprefix lib/aes/, \
aes-encrypt.o aes-decrypt.o)
 
-# Cryptographic helpers that depend on openssl/libcrypto
-LIBCRYPTO_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := $(addprefix lib/, \
-   fdt-libcrypto.o)
+# Cryptographic helpers and image types that depend on openssl/libcrypto
+LIBCRYPTO_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := \
+   lib/fdt-libcrypto.o \
+   kwbimage.o \
+   mxsimage.o
 
 ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rksd.o rkspi.o
 
@@ -118,10 +120,8 @@ dumpimage-mkimage-objs := aisimage.o \
imximage.o \
imx8image.o \
imx8mimage.o \
-   kwbimage.o \
lib/md5.o \
lpc32xximage.o \
-   mxsimage.o \
omapimage.o \
os_support.o \
pblimage.o \
@@ -156,22 +156,13 @@ fit_info-objs   := $(dumpimage-mkimage-objs) fit_info.o
 fit_check_sign-objs   := $(dumpimage-mkimage-objs) fit_check_sign.o
 file2include-objs := file2include.o
 
-ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_TOOLS_LIBCRYPTO),)
-# Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
-# the mxsimage support within tools/mxsimage.c .
-HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
-endif
-
 ifdef CONFIG_TOOLS_LIBCRYPTO
 # This affects include/image.h, but including the board config file
 # is tricky, so manually define this options here.
 HOST_EXTRACFLAGS   += -DCONFIG_FIT_SIGNATURE
 HOST_EXTRACFLAGS   += -DCONFIG_FIT_SIGNATURE_MAX_SIZE=0x
 HOST_EXTRACFLAGS   += -DCONFIG_FIT_CIPHER
-endif
 
-# MXSImage needs LibSSL
-ifneq 
($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_TOOLS_LIBCRYPTO),)
 HOSTCFLAGS_kwbimage.o += \
$(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "")
 HOSTLDLIBS_mkimage += \
diff --git a/tools/mxsimage.c b/tools/mxsimage.c
index 002f4b525a..2bfbb421eb 100644
--- a/tools/mxsimage.c
+++ b/tools/mxsimage.c
@@ -5,8 +5,6 @@
  * Copyright (C) 2012-2013 Marek Vasut 
  */
 
-#ifdef CONFIG_MXS
-
 #include 
 #include 
 #include 
@@ -2363,4 +2361,3 @@ 

[PATCH v3 0/4] sunxi: TOC0 image type support

2021-10-14 Thread Samuel Holland
This series adds support for the TOC0 image format used by the Allwinner
secure boot ROM (SBROM). This series has been tested on the following
SoCs/boards, with the eFuse burnt to enable secure mode:
 - A50: Ainol Q88 Tablet
 - A64: Pine A64 Plus
 - H5: Orange Pi Zero Plus
 - H6: Pine H64 Model B
 - H616: Orange Pi Zero 2

This time I also tested it on boards that are not switched to secure
mode (with A64, H3, and H5).

Due to both series changing Makefile.spl, the last patch depends on:
https://patchwork.ozlabs.org/project/uboot/list/?series=267136

Changes in v3:
 - Selected TOOLS_LIBCRYPTO on all platforms that use kwbimage (as best
   as I can tell, using the suggestions from Pali Rohár)
 - Removed TOOLS_LIBCRYPTO selection for sunxi, since most boards
   do not need it
 - Added __packed to all new "ABI" structs
 - Added entry to MAINTAINERS for sunxi tools
 - Fixed offset of magic passed to memcmp
 - Refactored functions to not return pointers (fixes ambiguous NULL)

Changes in v2:
 - Refactored the first patch on top of TOOLS_LIBCRYPTO
 - Moved certificate and key item structures out of sunxi_image.h
 - Renamed "main" and "item" variables for clarity
 - Improved error messages, and added a hint about key generation
 - Added a comment explaining the purpose of the various key files
 - Mentioned testing this code on A50 in the commit message
 - Moved SPL header signature checks out of sunxi_image.h
 - Refactored SPL header signature checks to use fewer casts
 - Rebase on top of Icenowy's RISC-V support series
 - Rename Kconfig symbols to include the full image type name

Samuel Holland (4):
  tools: Separate image types which depend on OpenSSL
  tools: mkimage: Add Allwinner TOC0 support
  sunxi: Support SPL in both eGON and TOC0 images
  sunxi: Support building a SPL as a TOC0 image

 MAINTAINERS   |   1 +
 arch/arm/Kconfig  |   3 +
 arch/arm/include/asm/arch-sunxi/spl.h |   2 -
 arch/arm/mach-imx/mxs/Kconfig |   2 +
 arch/arm/mach-sunxi/Kconfig   |   2 +
 arch/arm/mach-sunxi/board.c   |  34 +-
 board/sunxi/Kconfig   |  24 +
 common/image.c|   1 +
 include/image.h   |   1 +
 include/sunxi_image.h |  37 ++
 scripts/Makefile.spl  |   5 +-
 scripts/config_whitelist.txt  |   1 -
 tools/Makefile|  20 +-
 tools/mxsimage.c  |   3 -
 tools/sunxi_toc0.c| 907 ++
 15 files changed, 1016 insertions(+), 27 deletions(-)
 create mode 100644 board/sunxi/Kconfig
 create mode 100644 tools/sunxi_toc0.c

-- 
2.32.0



Re: External dts building

2021-10-14 Thread Giulio Benetti
Hi Simon,

> Il giorno 15 ott 2021, alle ore 02:53, Simon Glass  ha 
> scritto:
> 
> Hi Giulio,
> 
>> On Thu, 14 Oct 2021 at 15:12, Giulio Benetti
>>  wrote:
>> 
>> Hi Simon,
>> 
>> Il giorno 14 ott 2021, alle ore 22:43, Simon Glass  ha 
>> scritto:
>> 
>> Hi Giulio,
>> 
>> On Thu, 14 Oct 2021 at 13:23, Giulio Benetti
>>  wrote:
>> 
>> 
>> Hi Simon,
>> 
>> 
>> Il giorno 14 ott 2021, alle ore 20:24, Simon Glass  ha 
>> scritto:
>> 
>> 
>> Hi,
>> 
>> 
>> On Thu, 14 Oct 2021 at 07:46, Tom Rini  wrote:
>> 
>> 
>> On Thu, Oct 14, 2021 at 02:53:30AM +0200, Giulio Benetti wrote:
>> 
>> 
>> Hello All,
>> 
>> 
>> is there a way to pass a dts file without touching the 
>> arch/arm/boot/dts/Makefile?
>> 
>> 
>> On Buildroot we support the possibility to pass an external dts by copying 
>> it to the uboot sources to
>> 
>> be built but since uboot version 2020.01 it doesn’t work anymore.
>> 
>> 
>> So I’ve proposed a patch to prepend the dts file in the Makefile above, but 
>> this has drawbacks, like we reconfigure(it keeps adding files every time).
>> 
>> 
>> So I ask you, is there a more canonical way already to achieve this?
>> 
>> 
>> Not exactly, and it's something we're very much actively discussing
>> 
>> right now.
>> 
>> 
>> Are you using 'make DEVICE_TREE=xxx' ?
>> 
>> 
>> Yes but it doesn’t work if you don’t add an entry into arch/arm/dts/Makefile
>> 
>> Before version 2020.01 worked, but not after it.
>> 
>> 
>> What board are you building?
>> 
>> 
>> A20-OLinuXino-Lime_defconfig for but without CONFIG_DEFAULT_DEVICE_TREE 
>> undefined,
>> so if you try to pass DEVICE_TREE= pointing to an external .dts file copied 
>> to arch/arm/dts/ make doesn’t find the entry in Makefile and it can’t build 
>> it.
>> 
>> This is useful in build systems like Buildroot where you can provide an 
>> external defconfig as well as an external .dts file.
>> 
>> So here the solution I see is to create an entry in arch/arm/dts/Makefile on 
>> the top of the file afte copying the .dts file we want to build.
>> But on Buildroot they’ve pointed me to ask upstream(here) if there’s a more 
>> canonical way or to work together to achieve the goal:
>> 
>> https://patchwork.ozlabs.org/project/buildroot/patch/20210209201303.195093-1-giulio.bene...@benettiengineering.com/
> 
> How about not disabling CONFIG_DEFAULT_DEVICE_TREE ? That should work OK.

But if I’m not wrong the problem of the dts/Makefile remains. If .dts file is 
not assigned to dtb-y it won’t be built.

And in the case of Buildroot we have 2 ways to use external dts files:
1) patch uboot adding the dts and the entry in dts/Makefile
2) copy .dts file(let’s say located in ~/my-folder/my.dts) to 
arch/arm/dts/my.dts and prepend
the dtb-y += my.dts in arch/arm/dts/Makefile and here problem arises.
Because it can work once but we need to make it possible to have ‘make 
uboot-rebuild/reconfigure’
(Buildroot has such targets). This way is not easy at all to prepend the dtb-y 
at the top of the file without re-prepending it again and again.

It worked up to uboot < 2020.01, but I still haven’t bisected to see the 
“offending” commit.
Maybe I can try and find out why it behaves like that.

What about that?

Best regards
Giulio

> 
> Regards,
> Simon
> 
>> 
>> Sorry if this e-mail is html but I’m on mobile :-/
>> 
>> Best regards
>> Giulio Benetti
>> 
>> 
>> Regards,
>> Simon



Re: [PATCH] CI: Switch running the nokia_rx51 test with in-container toolchain

2021-10-14 Thread Simon Glass
On Thu, 14 Oct 2021 at 20:21, Tom Rini  wrote:
>
> Instead of fetching an arm toolchain to use, run the test with the one
> that's already in the container image.
>
> Signed-off-by: Tom Rini 
> ---
>  .azure-pipelines.yml | 3 +--
>  .gitlab-ci.yml   | 3 +--
>  2 files changed, 2 insertions(+), 4 deletions(-)

Works for me on gitlab!

Reviewed-by: Simon Glass 
Tested-by: Simon Glass 


>
> diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
> index 53f86f5184c5..d3352defef2e 100644
> --- a/.azure-pipelines.yml
> +++ b/.azure-pipelines.yml
> @@ -169,8 +169,7 @@ jobs:
>options: $(container_option)
>  steps:
>- script: |
> -  ./tools/buildman/buildman --fetch-arch arm
> -  export 
> PATH=~/.buildman-toolchains/gcc-9.2.0-nolibc/arm-linux-gnueabi/bin/:$PATH
> +  export PATH=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin:$PATH
>test/nokia_rx51_test.sh
>
>- job: test_py
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index 5a3e2f0ceb85..4aeca31e198b 100644
> --- a/.gitlab-ci.yml
> +++ b/.gitlab-ci.yml
> @@ -177,8 +177,7 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites:
>  Run tests for Nokia RX-51 (aka N900):
>stage: testsuites
>script:
> -- ./tools/buildman/buildman --fetch-arch arm;
> -  export 
> PATH=~/.buildman-toolchains/gcc-9.2.0-nolibc/arm-linux-gnueabi/bin/:$PATH;
> +- export PATH=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin:$PATH;
>test/nokia_rx51_test.sh
>
>  # Test sandbox with test.py
> --
> 2.25.1
>


Re: [PATCH 1/4] serial: samsung: add support for skip debug init in s5p

2021-10-14 Thread Minkyu Kang
Dear Dzmitry Sankouski,

On Wed, 13 Oct 2021 at 00:42, Dzmitry Sankouski 
wrote:

> Signed-off-by: Dzmitry Sankouski 
> Cc: Minkyu Kang 
> ---
>  drivers/serial/serial_s5p.c | 8 +---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c
> index 6d09952a5d..caa9a4e5c1 100644
> --- a/drivers/serial/serial_s5p.c
> +++ b/drivers/serial/serial_s5p.c
> @@ -221,10 +221,12 @@ U_BOOT_DRIVER(serial_s5p) = {
>
>  static inline void _debug_uart_init(void)
>  {
> -   struct s5p_uart *uart = (struct s5p_uart *)CONFIG_DEBUG_UART_BASE;
> +   if (IS_ENABLED(CONFIG_DEBUG_UART_SKIP_INIT)) {
> +   struct s5p_uart *uart = (struct s5p_uart
> *)CONFIG_DEBUG_UART_BASE;
>
> -   s5p_serial_init(uart);
> -   s5p_serial_baud(uart, CONFIG_DEBUG_UART_CLOCK, CONFIG_BAUDRATE);
> +   s5p_serial_init(uart);
> +   s5p_serial_baud(uart, CONFIG_DEBUG_UART_CLOCK,
> CONFIG_BAUDRATE);
> +   }
>  }
>
>
Please return if disabled.
It looks cleaner. less change, less depth.

-- 
Thanks,
Minkyu Kang.


[PATCH] CI: Switch running the nokia_rx51 test with in-container toolchain

2021-10-14 Thread Tom Rini
Instead of fetching an arm toolchain to use, run the test with the one
that's already in the container image.

Signed-off-by: Tom Rini 
---
 .azure-pipelines.yml | 3 +--
 .gitlab-ci.yml   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 53f86f5184c5..d3352defef2e 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -169,8 +169,7 @@ jobs:
   options: $(container_option)
 steps:
   - script: |
-  ./tools/buildman/buildman --fetch-arch arm
-  export 
PATH=~/.buildman-toolchains/gcc-9.2.0-nolibc/arm-linux-gnueabi/bin/:$PATH
+  export PATH=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin:$PATH
   test/nokia_rx51_test.sh
 
   - job: test_py
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5a3e2f0ceb85..4aeca31e198b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -177,8 +177,7 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites:
 Run tests for Nokia RX-51 (aka N900):
   stage: testsuites
   script:
-- ./tools/buildman/buildman --fetch-arch arm;
-  export 
PATH=~/.buildman-toolchains/gcc-9.2.0-nolibc/arm-linux-gnueabi/bin/:$PATH;
+- export PATH=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin:$PATH;
   test/nokia_rx51_test.sh
 
 # Test sandbox with test.py
-- 
2.25.1



Re: [PATCH] clk: introduce u-boot,ignore-clk-defaults

2021-10-14 Thread Simon Glass
Hi Peng, Sean,

On Thu, 14 Oct 2021 at 19:17, Peng Fan  wrote:
>
> > Subject: Re: [PATCH] clk: introduce u-boot,ignore-clk-defaults
> >
> >
> > On 10/13/21 5:37 AM, Peng Fan (OSS) wrote:
> > > From: Peng Fan 
> > >
> > > Current code has a force clk_set_defaults in multiple stages, U-Boot
> > > reuse the same device tree and Linux Kernel device tree, but we not
> > > register all the clks as Linux Kernel, so clk_set_defaults will fail
> > > and cause the clk provider registeration fail.
> > >
> > > So introduce a new property to ignore the default settings which could
> > > be used by any node that wanna ignore default settings.
> > >
> > > Signed-off-by: Peng Fan 
> > > ---
> > >   doc/device-tree-bindings/device.txt | 3 +++
> > >   drivers/clk/clk-uclass.c| 3 +++
> > >   2 files changed, 6 insertions(+)
> > >
> > > diff --git a/doc/device-tree-bindings/device.txt
> > > b/doc/device-tree-bindings/device.txt
> > > index 73ce2a3b5b..fe34ced268 100644
> > > --- a/doc/device-tree-bindings/device.txt
> > > +++ b/doc/device-tree-bindings/device.txt
> > > @@ -28,6 +28,9 @@ the acpi,compatible property.
> > >   Linux will only load the driver if the device can be detected (e.g. 
> > > on
> > I2C
> > >   bus). Note that this is an out-of-tree Linux feature.
> > >
> > > +Common device bindings that could be shared listed below:
> > > + - u-boot,ignore-clk-defaults : ignore the assigned-clock-parents
> > > +   and assigned-clock-rates for a device that has the property.
> > >
> > >   Example
> > >   ---
> > > diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index
> > > 493018b33e..6bf3179e7b 100644
> > > --- a/drivers/clk/clk-uclass.c
> > > +++ b/drivers/clk/clk-uclass.c
> > > @@ -376,6 +376,9 @@ int clk_set_defaults(struct udevice *dev, enum
> > clk_defaults_stage stage)
> > > if (!dev_has_ofnode(dev))
> > > return 0;
> > >
> > > +   if (ofnode_get_property(dev_ofnode(dev), "u-boot,ignore-clk-defaults",
> > NULL))
> > > +   return 0;
> > > +
> > > /*
> > >  * To avoid setting defaults twice, don't set them before relocation.
> > >  * However, still set them for SPL. And still set them if
> > > explicitly
> > >
> >
> > Why not just have the property ignore errors?
>
> I think the force err return was done by Simon?
>
> >
> > In the long term, it may be better to standardize that e.g. ENOENT means 
> > that
> > the clock doesn't exist. That way we can skip setting the defaults.
> > ENOSYS should probably be treated the same way (warn, but don't fail).
>
> I am not sure whether people expect force error for ENOENT/ENOSYS in U-Boot.
> For i.MX, I not expect force error.

Yes that is me, indeed. It's just that we should not silently ignore
errors. If we know the clock is optional, then the driver that knows
that can handle it. But if we start having things quietly fail,
debugging becomes a pain.

Regards,
Simon


[PATCH next v6 11/12] configs: aspeed: Make EXTRA_ENV_SETTINGS board specific

2021-10-14 Thread Chia-Wei Wang
Move CONFIG_EXTRA_ENV_SETTINGS to board-specific
configuration headers.

Signed-off-by: Chia-Wei Wang 
---
 include/configs/aspeed-common.h | 9 -
 include/configs/evb_ast2500.h   | 9 +
 include/configs/evb_ast2600.h   | 9 +
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/include/configs/aspeed-common.h b/include/configs/aspeed-common.h
index 5177bf20fa..96526e1a75 100644
--- a/include/configs/aspeed-common.h
+++ b/include/configs/aspeed-common.h
@@ -38,13 +38,4 @@
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
 
-/*
- * Miscellaneous configurable options
- */
-
-#define CONFIG_EXTRA_ENV_SETTINGS \
-   "verify=yes\0"  \
-   "spi_dma=yes\0" \
-   ""
-
 #endif /* __AST_COMMON_CONFIG_H */
diff --git a/include/configs/evb_ast2500.h b/include/configs/evb_ast2500.h
index dc032c1a41..a886fd941e 100644
--- a/include/configs/evb_ast2500.h
+++ b/include/configs/evb_ast2500.h
@@ -13,4 +13,13 @@
 
 #define CONFIG_SYS_UBOOT_BASE  CONFIG_SYS_TEXT_BASE
 
+/* Memory Info */
+#define CONFIG_SYS_LOAD_ADDR   0x8300
+
+/* Misc */
+#define CONFIG_EXTRA_ENV_SETTINGS \
+   "verify=yes\0"  \
+   "spi_dma=yes\0" \
+   ""
+
 #endif /* __CONFIG_H */
diff --git a/include/configs/evb_ast2600.h b/include/configs/evb_ast2600.h
index 177a52eb91..d2aceb6663 100644
--- a/include/configs/evb_ast2600.h
+++ b/include/configs/evb_ast2600.h
@@ -10,4 +10,13 @@
 
 #define CONFIG_SYS_UBOOT_BASE  CONFIG_SYS_TEXT_BASE
 
+/* Memory Info */
+#define CONFIG_SYS_LOAD_ADDR   0x8300
+
+/* Misc */
+#define CONFIG_EXTRA_ENV_SETTINGS \
+   "verify=yes\0"  \
+   "spi_dma=yes\0" \
+   ""
+
 #endif /* __CONFIG_H */
-- 
2.17.1



[PATCH next v6 04/12] crypto: aspeed: Add AST2600 HACE support

2021-10-14 Thread Chia-Wei Wang
From: Johnny Huang 

Hash and Crypto Engine (HACE) is designed to accelerate the
throughput of hash data digest, and symmetric-key encryption.

Signed-off-by: Johnny Huang 
Signed-off-by: Chia-Wei Wang 
---
 drivers/crypto/Kconfig  |   2 +
 drivers/crypto/Makefile |   1 +
 drivers/crypto/aspeed/Kconfig   |  10 +
 drivers/crypto/aspeed/Makefile  |   1 +
 drivers/crypto/aspeed/aspeed_hace.c | 381 
 drivers/crypto/hash/Kconfig |   8 +
 6 files changed, 403 insertions(+)
 create mode 100644 drivers/crypto/aspeed/Kconfig
 create mode 100644 drivers/crypto/aspeed/Makefile
 create mode 100644 drivers/crypto/aspeed/aspeed_hace.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 0082177c21..675081ecd3 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -4,4 +4,6 @@ source drivers/crypto/hash/Kconfig
 
 source drivers/crypto/fsl/Kconfig
 
+source drivers/crypto/aspeed/Kconfig
+
 endmenu
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index e8bae43e3f..6b762565a1 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_EXYNOS_ACE_SHA)+= ace_sha.o
 obj-y += rsa_mod_exp/
 obj-y += fsl/
 obj-y += hash/
+obj-y += aspeed/
diff --git a/drivers/crypto/aspeed/Kconfig b/drivers/crypto/aspeed/Kconfig
new file mode 100644
index 00..471c06f986
--- /dev/null
+++ b/drivers/crypto/aspeed/Kconfig
@@ -0,0 +1,10 @@
+config ASPEED_HACE
+   bool "ASPEED Hash and Crypto Engine"
+   depends on DM_HASH
+   help
+ Select this option to enable a driver for using the SHA engine in
+ the ASPEED BMC SoCs.
+
+ Enabling this allows the use of SHA operations in hardware without
+ requiring the SHA software implementations. It also improves 
performance
+ and saves code size.
diff --git a/drivers/crypto/aspeed/Makefile b/drivers/crypto/aspeed/Makefile
new file mode 100644
index 00..84e6bfe82a
--- /dev/null
+++ b/drivers/crypto/aspeed/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_ASPEED_HACE) += aspeed_hace.o
diff --git a/drivers/crypto/aspeed/aspeed_hace.c 
b/drivers/crypto/aspeed/aspeed_hace.c
new file mode 100644
index 00..1178cc6a76
--- /dev/null
+++ b/drivers/crypto/aspeed/aspeed_hace.c
@@ -0,0 +1,381 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2021 ASPEED Technology Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* register offsets*/
+#define HACE_STS   0x1C
+#define   HACE_HASH_DATA_OVF   BIT(23)
+#define   HACE_HASH_INTBIT(9)
+#define   HACE_HASH_BUSY   BIT(0)
+#define HACE_HASH_DATA 0x20
+#define HACE_HASH_DIGEST   0x24
+#define HACE_HASH_HMAC_KEY 0x28
+#define HACE_HASH_DATA_LEN 0x2C
+#define HACE_HASH_CMD  0x30
+#define   HACE_HASH_MODE_ACCUM BIT(8)
+#define   HACE_HASH_ALGO_SHA1  BIT(5)
+#define   HACE_HASH_ALGO_SHA256(BIT(6) | BIT(4))
+#define   HACE_HASH_ALGO_SHA384(BIT(10) | BIT(6) | BIT(5))
+#define   HACE_HASH_ALGO_SHA512(BIT(6) | BIT(5))
+#define   HACE_HASH_SHA_BE_EN  BIT(3)
+
+/* buffer size based on SHA-512 need*/
+#define HASH_BLOCK_BUFSZ   128
+#define HASH_DIGEST_BUFSZ  64
+
+struct aspeed_hace_ctx {
+   uint8_t digest[HASH_DIGEST_BUFSZ];
+
+   uint32_t cmd;
+   enum HASH_ALGO algo;
+
+   uint32_t blk_size;
+   uint32_t pad_size;
+   uint64_t total[2];
+
+   uint8_t buf[HASH_BLOCK_BUFSZ];
+   uint32_t buf_cnt;
+} __aligned((8));
+
+struct aspeed_hace {
+   phys_addr_t base;
+   struct clk clk;
+};
+
+static const uint32_t iv_sha1[8] = {
+   0x01234567, 0x89abcdef, 0xfedcba98, 0x76543210,
+   0xf0e1d2c3, 0, 0, 0
+};
+
+static const uint32_t iv_sha256[8] = {
+   0x67e6096a, 0x85ae67bb, 0x72f36e3c, 0x3af54fa5,
+   0x7f520e51, 0x8c68059b, 0xabd9831f, 0x19cde05bUL
+};
+
+static const uint32_t iv_sha384[16] = {
+   0x5d9dbbcb, 0xd89e05c1, 0x2a299a62, 0x07d57c36,
+   0x5a015991, 0x17dd7030, 0xd8ec2f15, 0x39590ef7,
+   0x67263367, 0x310bc0ff, 0x874ab48e, 0x11155868,
+   0x0d2e0cdb, 0xa78ff964, 0x1d48b547, 0xa44ffabeUL
+};
+
+static const uint32_t iv_sha512[16] = {
+   0x67e6096a, 0x08c9bcf3, 0x85ae67bb, 0x3ba7ca84,
+   0x72f36e3c, 0x2bf894fe, 0x3af54fa5, 0xf1361d5f,
+   0x7f520e51, 0xd182e6ad, 0x8c68059b, 0x1f6c3e2b,
+   0xabd9831f, 0x6bbd41fb, 0x19cde05b, 0x79217e13UL
+};
+
+static int aspeed_hace_wait_completion(uint32_t reg, uint32_t flag, int 
timeout_us)
+{
+   uint32_t val;
+
+   return readl_poll_timeout(reg, val, (val & flag) == flag, timeout_us);
+}
+
+static int aspeed_hace_process(struct udevice *dev, void *ctx, const void 
*ibuf, uint32_t ilen)
+{
+   struct aspeed_hace *hace = dev_get_priv(dev);
+   

[PATCH next v6 12/12] configs: ast2600: Boot kernel FIT in DRAM

2021-10-14 Thread Chia-Wei Wang
AST2600 leverages the FIT hash/signature verification to fulfill
secure boot trust chain. To improve the performance and save SW
code size for those crypto operations, the two HW crypto engine,
HACE and ACRY, are enabled.

However, both of the engines can only access to data stored in
DRAM space. Therefore, we need to move the FIT image into DRAM
before the booting.

This patch update the CONFIG_BOOTCOMMAND to execute the pre-defined
ENV variable which consists of FIT image copy to memory and booting.

Signed-off-by: Chia-Wei Wang 
---
 configs/evb-ast2600_defconfig | 2 +-
 include/configs/evb_ast2600.h | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/configs/evb-ast2600_defconfig b/configs/evb-ast2600_defconfig
index eba6940ec1..abb156f13e 100644
--- a/configs/evb-ast2600_defconfig
+++ b/configs/evb-ast2600_defconfig
@@ -27,7 +27,7 @@ CONFIG_SPL_LOAD_FIT_ADDRESS=0x1
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyS4,115200n8 root=/dev/ram rw"
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="bootm 2010"
+CONFIG_BOOTCOMMAND="run bootspi"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD=y
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC=y
diff --git a/include/configs/evb_ast2600.h b/include/configs/evb_ast2600.h
index d2aceb6663..83002db317 100644
--- a/include/configs/evb_ast2600.h
+++ b/include/configs/evb_ast2600.h
@@ -14,7 +14,14 @@
 #define CONFIG_SYS_LOAD_ADDR   0x8300
 
 /* Misc */
+#define STR_HELPER(s)  #s
+#define STR(s) STR_HELPER(s)
+
 #define CONFIG_EXTRA_ENV_SETTINGS \
+   "loadaddr=" STR(CONFIG_SYS_LOAD_ADDR) "\0" \
+   "bootspi=fdt addr 2010 && fdt header get fitsize totalsize && " \
+   "cp.b 2010 ${loadaddr} ${fitsize} && bootm; " \
+   "echo Error loading kernel FIT image\0" \
"verify=yes\0"  \
"spi_dma=yes\0" \
""
-- 
2.17.1



[PATCH next v6 07/12] crypto: aspeed: Add AST2600 ACRY support

2021-10-14 Thread Chia-Wei Wang
ACRY is deisnged to accerlerate ECC/RSA digital signature
generation and verification.

Signed-off-by: Chia-Wei Wang 
---
 drivers/crypto/aspeed/Kconfig   |  10 ++
 drivers/crypto/aspeed/Makefile  |   1 +
 drivers/crypto/aspeed/aspeed_acry.c | 182 
 lib/rsa/Kconfig |  10 +-
 4 files changed, 202 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/aspeed/aspeed_acry.c

diff --git a/drivers/crypto/aspeed/Kconfig b/drivers/crypto/aspeed/Kconfig
index 471c06f986..9bf317177a 100644
--- a/drivers/crypto/aspeed/Kconfig
+++ b/drivers/crypto/aspeed/Kconfig
@@ -8,3 +8,13 @@ config ASPEED_HACE
  Enabling this allows the use of SHA operations in hardware without
  requiring the SHA software implementations. It also improves 
performance
  and saves code size.
+
+config ASPEED_ACRY
+   bool "ASPEED RSA and ECC Engine"
+   depends on ASPEED_AST2600
+   help
+Select this option to enable a driver for using the RSA/ECC engine in
+the ASPEED BMC SoCs.
+
+Enabling this allows the use of RSA/ECC operations in hardware without 
requiring the
+software implementations. It also improves performance and saves code 
size.
diff --git a/drivers/crypto/aspeed/Makefile b/drivers/crypto/aspeed/Makefile
index 84e6bfe82a..58b55fc46e 100644
--- a/drivers/crypto/aspeed/Makefile
+++ b/drivers/crypto/aspeed/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_ASPEED_HACE) += aspeed_hace.o
+obj-$(CONFIG_ASPEED_ACRY) += aspeed_acry.o
diff --git a/drivers/crypto/aspeed/aspeed_acry.c 
b/drivers/crypto/aspeed/aspeed_acry.c
new file mode 100644
index 00..0b948f828a
--- /dev/null
+++ b/drivers/crypto/aspeed/aspeed_acry.c
@@ -0,0 +1,182 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2021 ASPEED Technology Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* ACRY register offsets */
+#define ACRY_CTRL1 0x00
+#define   ACRY_CTRL1_RSA_DMA   BIT(1)
+#define   ACRY_CTRL1_RSA_START BIT(0)
+#define ACRY_CTRL2 0x44
+#define ACRY_CTRL3 0x48
+#define   ACRY_CTRL3_SRAM_AHB_ACCESS   BIT(8)
+#define   ACRY_CTRL3_ECC_RSA_MODE_MASK GENMASK(5, 4)
+#define   ACRY_CTRL3_ECC_RSA_MODE_SHIFT4
+#define ACRY_DMA_DRAM_SADDR0x4c
+#define ACRY_DMA_DMEM_TADDR0x50
+#define   ACRY_DMA_DMEM_TADDR_LEN_MASK GENMASK(15, 0)
+#define   ACRY_DMA_DMEM_TADDR_LEN_SHIFT0
+#define ACRY_RSA_PARAM 0x58
+#define   ACRY_RSA_PARAM_EXP_MASK  GENMASK(31, 16)
+#define   ACRY_RSA_PARAM_EXP_SHIFT 16
+#define   ACRY_RSA_PARAM_MOD_MASK  GENMASK(15, 0)
+#define   ACRY_RSA_PARAM_MOD_SHIFT 0
+#define ACRY_RSA_INT_EN0x3f8
+#define   ACRY_RSA_INT_EN_RSA_READYBIT(2)
+#define   ACRY_RSA_INT_EN_RSA_CMPLTBIT(1)
+#define ACRY_RSA_INT_STS   0x3fc
+#define   ACRY_RSA_INT_STS_RSA_READY   BIT(2)
+#define   ACRY_RSA_INT_STS_RSA_CMPLT   BIT(1)
+
+/* misc. constant */
+#define ACRY_ECC_MODE  2
+#define ACRY_RSA_MODE  3
+#define ACRY_CTX_BUFSZ 0x600
+
+struct aspeed_acry {
+   phys_addr_t base;
+   phys_addr_t sram_base; /* internal sram */
+   struct clk clk;
+};
+
+static int aspeed_acry_mod_exp(struct udevice *dev, const uint8_t *sig, 
uint32_t sig_len,
+  struct key_prop *prop, uint8_t *out)
+{
+   int i, j;
+   u8 *ctx;
+   u8 *ptr;
+   u32 reg;
+   struct aspeed_acry *acry = dev_get_priv(dev);
+
+   ctx = memalign(16, ACRY_CTX_BUFSZ);
+   if (!ctx)
+   return -ENOMEM;
+
+   memset(ctx, 0, ACRY_CTX_BUFSZ);
+
+   ptr = (u8 *)prop->public_exponent;
+   for (i = prop->exp_len - 1, j = 0; i >= 0; --i) {
+   ctx[j] = ptr[i];
+   j++;
+   j = (j % 16) ? j : j + 32;
+   }
+
+   ptr = (u8 *)prop->modulus;
+   for (i = (prop->num_bits >> 3) - 1, j = 0; i >= 0; --i) {
+   ctx[j + 16] = ptr[i];
+   j++;
+   j = (j % 16) ? j : j + 32;
+   }
+
+   ptr = (u8 *)sig;
+   for (i = sig_len - 1, j = 0; i >= 0; --i) {
+   ctx[j + 32] = ptr[i];
+   j++;
+   j = (j % 16) ? j : j + 32;
+   }
+
+   writel((u32)ctx, acry->base + ACRY_DMA_DRAM_SADDR);
+
+   reg = (((prop->exp_len << 3) << ACRY_RSA_PARAM_EXP_SHIFT) & 
ACRY_RSA_PARAM_EXP_MASK) |
+ ((prop->num_bits << ACRY_RSA_PARAM_MOD_SHIFT) & 
ACRY_RSA_PARAM_MOD_MASK);
+   writel(reg, acry->base + ACRY_RSA_PARAM);
+
+   reg = (ACRY_CTX_BUFSZ << ACRY_DMA_DMEM_TADDR_LEN_SHIFT) & 
ACRY_DMA_DMEM_TADDR_LEN_MASK;
+   writel(reg, acry->base + ACRY_DMA_DMEM_TADDR);
+
+   reg = (ACRY_RSA_MODE << ACRY_CTRL3_ECC_RSA_MODE_SHIFT) & 
ACRY_CTRL3_ECC_RSA_MODE_MASK;
+   writel(reg, acry->base + ACRY_CTRL3);
+
+   writel(ACRY_CTRL1_RSA_DMA | ACRY_CTRL1_RSA_START, acry->base + 
ACRY_CTRL1);
+

[PATCH next v6 09/12] ast2600: spl: Locate load buffer in DRAM space

2021-10-14 Thread Chia-Wei Wang
Return CONFIG_SYS_LOAD_ADDR pointing to DRAM space for
spl_get_load_buffer() to allow generic SPL image loading
code (e.g. FIT and Ymodem) to store data in DRAM.

Signed-off-by: Chia-Wei Wang 
---
 arch/arm/mach-aspeed/ast2600/spl.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/arm/mach-aspeed/ast2600/spl.c 
b/arch/arm/mach-aspeed/ast2600/spl.c
index 0d8cb29678..6c49d6aede 100644
--- a/arch/arm/mach-aspeed/ast2600/spl.c
+++ b/arch/arm/mach-aspeed/ast2600/spl.c
@@ -28,14 +28,7 @@ u32 spl_boot_device(void)
 
 struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
 {
-   /*
-* When boot from SPI, AST2600 already remap 0x ~ 0x0fff
-* to BMC SPI memory space 0x2000 ~ 0x2fff. The next stage BL
-* has been located in SPI for XIP. In this case, the load buffer for
-* SPL image loading will be set to the remapped address of the next
-* BL instead of the DRAM space CONFIG_SYS_LOAD_ADDR
-*/
-   return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
+   return (struct image_header *)(CONFIG_SYS_LOAD_ADDR);
 }
 
 #ifdef CONFIG_SPL_OS_BOOT
-- 
2.17.1



[PATCH next v6 08/12] ARM: dts: ast2600: Add ACRY to device tree

2021-10-14 Thread Chia-Wei Wang
Add ACRY DTS node and enable it for AST2600 EVB.

Signed-off-by: Chia-Wei Wang 
---
 arch/arm/dts/ast2600-evb.dts | 5 +
 arch/arm/dts/ast2600.dtsi| 9 +
 2 files changed, 14 insertions(+)

diff --git a/arch/arm/dts/ast2600-evb.dts b/arch/arm/dts/ast2600-evb.dts
index adb80a30ef..05362d19bd 100644
--- a/arch/arm/dts/ast2600-evb.dts
+++ b/arch/arm/dts/ast2600-evb.dts
@@ -182,3 +182,8 @@
u-boot,dm-pre-reloc;
status = "okay";
 };
+
+ {
+   u-boot,dm-pre-reloc;
+   status = "okay";
+};
diff --git a/arch/arm/dts/ast2600.dtsi b/arch/arm/dts/ast2600.dtsi
index b8fe966c7d..31905fd208 100644
--- a/arch/arm/dts/ast2600.dtsi
+++ b/arch/arm/dts/ast2600.dtsi
@@ -195,6 +195,15 @@
status = "disabled";
};
 
+   acry: acry@1e6fa000 {
+   compatible = "aspeed,ast2600-acry";
+   reg = <0x1e6fa000 0x1000>,
+ <0x1e71 0x1>;
+   interrupts = ;
+   clocks = < ASPEED_CLK_GATE_RSACLK>;
+   status = "disabled";
+   };
+
edac: sdram@1e6e {
compatible = "aspeed,ast2600-sdram-edac";
reg = <0x1e6e 0x174>;
-- 
2.17.1



[PATCH next v6 10/12] configs: ast2600-evb: Enable SPL FIT support

2021-10-14 Thread Chia-Wei Wang
Enable SPL FIT image load and verification support.
The HW accelerated SHA is also available with the
newly added support of the HACE HW hash engine.

The SPL thumb build is also enabled to keep the binary
less than 64KB to fit into the Aspeed secure boot design.

Signed-off-by: Chia-Wei Wang 
---
 configs/evb-ast2600_defconfig | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/configs/evb-ast2600_defconfig b/configs/evb-ast2600_defconfig
index 56ab885d9b..eba6940ec1 100644
--- a/configs/evb-ast2600_defconfig
+++ b/configs/evb-ast2600_defconfig
@@ -1,7 +1,8 @@
 CONFIG_ARM=y
 CONFIG_SYS_DCACHE_OFF=y
+CONFIG_SPL_SYS_THUMB_BUILD=y
 CONFIG_ARCH_ASPEED=y
-CONFIG_SYS_TEXT_BASE=0x1
+CONFIG_SYS_TEXT_BASE=0x8000
 CONFIG_ASPEED_AST2600=y
 CONFIG_TARGET_EVB_AST2600=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
@@ -12,13 +13,17 @@ CONFIG_ENV_SIZE=0x1
 CONFIG_SYS_MALLOC_LEN=0x200
 CONFIG_DEFAULT_DEVICE_TREE="ast2600-evb"
 CONFIG_SPL_SERIAL=y
+CONFIG_SPL_STACK_R_ADDR=0x8300
 CONFIG_SPL_SIZE_LIMIT=0x1
 CONFIG_SPL=y
 # CONFIG_ARMV7_NONSEC is not set
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_LOAD_ADDR=0x8300
 CONFIG_FIT=y
-# CONFIG_LEGACY_IMAGE_FORMAT is not set
+CONFIG_SPL_FIT_SIGNATURE=y
+CONFIG_SPL_LOAD_FIT=y
+CONFIG_SPL_LOAD_FIT_ADDRESS=0x1
+# CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyS4,115200n8 root=/dev/ram rw"
 CONFIG_USE_BOOTCOMMAND=y
@@ -26,8 +31,10 @@ CONFIG_BOOTCOMMAND="bootm 2010"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD=y
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC=y
-# CONFIG_SPL_LEGACY_IMAGE_SUPPORT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_STACK_R=y
+CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x200
+CONFIG_SPL_FIT_IMAGE_TINY=y
 CONFIG_SPL_DM_RESET=y
 CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
@@ -47,6 +54,9 @@ CONFIG_REGMAP=y
 CONFIG_SPL_OF_TRANSLATE=y
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_DM_HASH=y
+CONFIG_HASH_ASPEED=y
+CONFIG_ASPEED_ACRY=y
 CONFIG_DM_I2C=y
 CONFIG_MISC=y
 CONFIG_SPL_MISC=y
@@ -65,5 +75,9 @@ CONFIG_SYS_NS16550=y
 CONFIG_SYSRESET=y
 CONFIG_SPL_SYSRESET=y
 CONFIG_WDT=y
+CONFIG_SHA512_ALGO=y
+CONFIG_SHA512=y
+CONFIG_SHA384=y
 CONFIG_HEXDUMP=y
 # CONFIG_EFI_LOADER is not set
+CONFIG_PHANDLE_CHECK_SEQ=y
-- 
2.17.1



[PATCH next v6 06/12] clk: ast2600: Add RSACLK control for ACRY

2021-10-14 Thread Chia-Wei Wang
Add RSACLK enable for ACRY, the HW RSA/ECC crypto engine
of ASPEED AST2600 SoCs.

As ACRY and HACE share the same reset control bit, we do not
perform the reset-hold-n-release operation during their clock
ungating process. Instead, only reset release is conducted to
prevent mutual interference.

Signed-off-by: Chia-Wei Wang 
---
 .../arm/include/asm/arch-aspeed/scu_ast2600.h |  1 +
 drivers/clk/aspeed/clk_ast2600.c  | 22 +--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h 
b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
index d7b500f656..7c5aab98b6 100644
--- a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
+++ b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
@@ -8,6 +8,7 @@
 #define SCU_UNLOCK_KEY 0x1688a8a8
 
 #define SCU_CLKGATE1_EMMC  BIT(27)
+#define SCU_CLKGATE1_ACRY  BIT(24)
 #define SCU_CLKGATE1_MAC2  BIT(21)
 #define SCU_CLKGATE1_MAC1  BIT(20)
 #define SCU_CLKGATE1_USB_HUB   BIT(14)
diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c
index 69128fd3c4..f6ebf824aa 100644
--- a/drivers/clk/aspeed/clk_ast2600.c
+++ b/drivers/clk/aspeed/clk_ast2600.c
@@ -1018,11 +1018,26 @@ static ulong ast2600_enable_haceclk(struct ast2600_scu 
*scu)
uint32_t reset_bit;
uint32_t clkgate_bit;
 
+   /* share the same reset control bit with ACRY */
reset_bit = BIT(ASPEED_RESET_HACE);
clkgate_bit = SCU_CLKGATE1_HACE;
 
-   writel(reset_bit, >modrst_ctrl1);
-   udelay(100);
+   writel(clkgate_bit, >clkgate_clr1);
+   mdelay(20);
+   writel(reset_bit, >modrst_clr1);
+
+   return 0;
+}
+
+static ulong ast2600_enable_rsaclk(struct ast2600_scu *scu)
+{
+   uint32_t reset_bit;
+   uint32_t clkgate_bit;
+
+   /* share the same reset control bit with HACE */
+   reset_bit = BIT(ASPEED_RESET_HACE);
+   clkgate_bit = SCU_CLKGATE1_ACRY;
+
writel(clkgate_bit, >clkgate_clr1);
mdelay(20);
writel(reset_bit, >modrst_clr1);
@@ -1071,6 +1086,9 @@ static int ast2600_clk_enable(struct clk *clk)
case ASPEED_CLK_GATE_YCLK:
ast2600_enable_haceclk(priv->scu);
break;
+   case ASPEED_CLK_GATE_RSACLK:
+   ast2600_enable_rsaclk(priv->scu);
+   break;
default:
pr_err("can't enable clk\n");
return -ENOENT;
-- 
2.17.1



[PATCH next v6 05/12] ARM: dts: ast2600: Add HACE to device tree

2021-10-14 Thread Chia-Wei Wang
From: Joel Stanley 

Add HACE DTS node and enable it for AST2600 EVB.

Signed-off-by: Joel Stanley 
Signed-off-by: Chia-Wei Wang 
---
 arch/arm/dts/ast2600-evb.dts | 5 +
 arch/arm/dts/ast2600.dtsi| 8 
 2 files changed, 13 insertions(+)

diff --git a/arch/arm/dts/ast2600-evb.dts b/arch/arm/dts/ast2600-evb.dts
index 2abd31341c..adb80a30ef 100644
--- a/arch/arm/dts/ast2600-evb.dts
+++ b/arch/arm/dts/ast2600-evb.dts
@@ -177,3 +177,8 @@
  0x08 0x04
  0x08 0x04>;
 };
+
+ {
+   u-boot,dm-pre-reloc;
+   status = "okay";
+};
diff --git a/arch/arm/dts/ast2600.dtsi b/arch/arm/dts/ast2600.dtsi
index f121f547e6..b8fe966c7d 100644
--- a/arch/arm/dts/ast2600.dtsi
+++ b/arch/arm/dts/ast2600.dtsi
@@ -187,6 +187,14 @@
};
};
 
+   hace: hace@1e6d {
+   compatible = "aspeed,ast2600-hace";
+   reg = <0x1e6d 0x200>;
+   interrupts = ;
+   clocks = < ASPEED_CLK_GATE_YCLK>;
+   status = "disabled";
+   };
+
edac: sdram@1e6e {
compatible = "aspeed,ast2600-sdram-edac";
reg = <0x1e6e 0x174>;
-- 
2.17.1



[PATCH next v6 00/12] aspeed: Support secure boot chain with FIT image verification

2021-10-14 Thread Chia-Wei Wang
This patch series intends to provide a secure boot chain from SPL to Linux 
kernel
based on the hash and signature verification of FIT image paradigm.

To improve the performance and save code size (SPL is limited to 64KB due to 
HW-RoT),
the drviers of two HW crypto engine HACE and ACRY are also added for AST26xx 
SoCs.

As HACE and ACRY can only access to DRAM space, additional configuration and
boot command are also updated according to move each FIT image before its 
booting.

In addition, the common code of FIT image hash algorithm lookup is also revised
to leverage the HW accelerated calculation.

v6:
 - fix parameter comment for v5 update

v5:
 - fix inconsistent parameter name due to parallel patch work

v4:
 - add new DM_HASH based driver for Aspeed HACE
 - remove SPL board init, which was originally used to probe non-DM HACE driver
 - fix typo of ARCY to ACRY
 - refactor defconfig based on the new Kconfig of U-Boot next branch

v3:
 - add SW work around for HACE HW DMA issue by resetting HACE
 - add reset control for HACE device tree node
 - sync all of the HACE error message to use debug()

v2:
 - update commit authors

Chia-Wei Wang (9):
  image: fit: Fix parameter name for hash algorithm
  aspeed: ast2600: Enlarge SRAM size
  clk: ast2600: Add RSACLK control for ACRY
  crypto: aspeed: Add AST2600 ACRY support
  ARM: dts: ast2600: Add ACRY to device tree
  ast2600: spl: Locate load buffer in DRAM space
  configs: ast2600-evb: Enable SPL FIT support
  configs: aspeed: Make EXTRA_ENV_SETTINGS board specific
  configs: ast2600: Boot kernel FIT in DRAM

Joel Stanley (2):
  clk: ast2600: Add YCLK control for HACE
  ARM: dts: ast2600: Add HACE to device tree

Johnny Huang (1):
  crypto: aspeed: Add AST2600 HACE support

 arch/arm/dts/ast2600-evb.dts  |  10 +
 arch/arm/dts/ast2600.dtsi |  17 +
 arch/arm/include/asm/arch-aspeed/platform.h   |   2 +-
 .../arm/include/asm/arch-aspeed/scu_ast2600.h |   6 +-
 arch/arm/mach-aspeed/ast2600/spl.c|   9 +-
 common/image-fit.c|   4 +-
 configs/evb-ast2600_defconfig |  22 +-
 drivers/clk/aspeed/clk_ast2600.c  |  38 ++
 drivers/crypto/Kconfig|   2 +
 drivers/crypto/Makefile   |   1 +
 drivers/crypto/aspeed/Kconfig |  20 +
 drivers/crypto/aspeed/Makefile|   2 +
 drivers/crypto/aspeed/aspeed_acry.c   | 182 +
 drivers/crypto/aspeed/aspeed_hace.c   | 381 ++
 drivers/crypto/hash/Kconfig   |   8 +
 include/configs/aspeed-common.h   |   9 -
 include/configs/evb_ast2500.h |   9 +
 include/configs/evb_ast2600.h |  16 +
 lib/rsa/Kconfig   |  10 +-
 19 files changed, 721 insertions(+), 27 deletions(-)
 create mode 100644 drivers/crypto/aspeed/Kconfig
 create mode 100644 drivers/crypto/aspeed/Makefile
 create mode 100644 drivers/crypto/aspeed/aspeed_acry.c
 create mode 100644 drivers/crypto/aspeed/aspeed_hace.c

-- 
2.17.1



[PATCH next v6 03/12] clk: ast2600: Add YCLK control for HACE

2021-10-14 Thread Chia-Wei Wang
From: Joel Stanley 

Add YCLK enable for HACE, the HW hash engine of
ASPEED AST2600 SoCs.

Signed-off-by: Joel Stanley 
Signed-off-by: Chia-Wei Wang 
---
 .../arm/include/asm/arch-aspeed/scu_ast2600.h |  5 +++--
 drivers/clk/aspeed/clk_ast2600.c  | 20 +++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h 
b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
index a205fb1f76..d7b500f656 100644
--- a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
+++ b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h
@@ -10,8 +10,9 @@
 #define SCU_CLKGATE1_EMMC  BIT(27)
 #define SCU_CLKGATE1_MAC2  BIT(21)
 #define SCU_CLKGATE1_MAC1  BIT(20)
-#define SCU_CLKGATE1_USB_HUB   BIT(14)
-#define SCU_CLKGATE1_USB_HOST2 BIT(7)
+#define SCU_CLKGATE1_USB_HUB   BIT(14)
+#define SCU_CLKGATE1_HACE  BIT(13)
+#define SCU_CLKGATE1_USB_HOST2 BIT(7)
 
 #define SCU_CLKGATE2_FSI   BIT(30)
 #define SCU_CLKGATE2_MAC4  BIT(21)
diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c
index 3a92739f5c..69128fd3c4 100644
--- a/drivers/clk/aspeed/clk_ast2600.c
+++ b/drivers/clk/aspeed/clk_ast2600.c
@@ -1013,6 +1013,23 @@ static ulong ast2600_enable_usbbhclk(struct ast2600_scu 
*scu)
return 0;
 }
 
+static ulong ast2600_enable_haceclk(struct ast2600_scu *scu)
+{
+   uint32_t reset_bit;
+   uint32_t clkgate_bit;
+
+   reset_bit = BIT(ASPEED_RESET_HACE);
+   clkgate_bit = SCU_CLKGATE1_HACE;
+
+   writel(reset_bit, >modrst_ctrl1);
+   udelay(100);
+   writel(clkgate_bit, >clkgate_clr1);
+   mdelay(20);
+   writel(reset_bit, >modrst_clr1);
+
+   return 0;
+}
+
 static int ast2600_clk_enable(struct clk *clk)
 {
struct ast2600_clk_priv *priv = dev_get_priv(clk->dev);
@@ -1051,6 +1068,9 @@ static int ast2600_clk_enable(struct clk *clk)
case ASPEED_CLK_GATE_USBPORT2CLK:
ast2600_enable_usbbhclk(priv->scu);
break;
+   case ASPEED_CLK_GATE_YCLK:
+   ast2600_enable_haceclk(priv->scu);
+   break;
default:
pr_err("can't enable clk\n");
return -ENOENT;
-- 
2.17.1



[PATCH next v6 01/12] image: fit: Fix parameter name for hash algorithm

2021-10-14 Thread Chia-Wei Wang
Fix inconsistent parameter naming of the hash algorithm.

Signed-off-by: Chia-Wei Wang 
Fixes: 92055e138f2 ("image: Drop if/elseif hash selection in calculate_hash()")
---
 common/image-fit.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 5a0a0cc200..a53a2b5d6f 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1201,7 +1201,7 @@ int fit_set_timestamp(void *fit, int noffset, time_t 
timestamp)
  * calculate_hash - calculate and return hash for provided input data
  * @data: pointer to the input data
  * @data_len: data length
- * @algo: requested hash algorithm
+ * @name: requested hash algorithm name
  * @value: pointer to the char, will hold hash value data (caller must
  * allocate enough free space)
  * value_len: length of the calculated hash
@@ -1229,7 +1229,7 @@ int calculate_hash(const void *data, int data_len, const 
char *name,
return -1;
}
 
-   hash_algo = hash_algo_lookup_by_name(algo);
+   hash_algo = hash_algo_lookup_by_name(name);
if (hash_algo == HASH_ALGO_INVALID) {
debug("Unsupported hash algorithm\n");
return -1;
-- 
2.17.1



[PATCH next v6 02/12] aspeed: ast2600: Enlarge SRAM size

2021-10-14 Thread Chia-Wei Wang
The AST2600 SRAM has been extended to 88KB since A1
chip revision. This patch updates the SRAM size to
offer more space for early stack/heap use.

Signed-off-by: Chia-Wei Wang 
---
 arch/arm/include/asm/arch-aspeed/platform.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/arch-aspeed/platform.h 
b/arch/arm/include/asm/arch-aspeed/platform.h
index d50ec5f8a9..589abd4a3f 100644
--- a/arch/arm/include/asm/arch-aspeed/platform.h
+++ b/arch/arm/include/asm/arch-aspeed/platform.h
@@ -17,7 +17,7 @@
 #define ASPEED_MAC_COUNT   4
 #define ASPEED_DRAM_BASE   0x8000
 #define ASPEED_SRAM_BASE   0x1000
-#define ASPEED_SRAM_SIZE   0x1
+#define ASPEED_SRAM_SIZE   0x16000
 #else
 #err "Unrecognized Aspeed platform."
 #endif
-- 
2.17.1



[PATCH v3 4/4] sunxi: specify architecture when generating SPL boot image

2021-10-14 Thread Samuel Holland
From: Icenowy Zheng 

As mkimage -T sunxi_egon now gains support for -A parameter, specify the
architecture when generating SPL boot image for sunxi.

Reviewed-by: Andre Przywara 
Signed-off-by: Icenowy Zheng 
Signed-off-by: Samuel Holland 
---

(no changes since v1)

 scripts/Makefile.spl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 6f26eb1fa1..4cc23799db 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -411,7 +411,7 @@ endif
 $(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
$(call if_changed,mkimage)
 
-MKIMAGEFLAGS_sunxi-spl.bin = -T sunxi_egon \
+MKIMAGEFLAGS_sunxi-spl.bin = -A $(ARCH) -T sunxi_egon \
-n $(CONFIG_DEFAULT_DEVICE_TREE)
 
 OBJCOPYFLAGS_u-boot-spl-dtb.hex := -I binary -O ihex 
--change-address=$(CONFIG_SPL_TEXT_BASE)
-- 
2.32.0



[PATCH v3 2/4] mkimage: sunxi_egon: refactor for multi-architecture support

2021-10-14 Thread Samuel Holland
From: Icenowy Zheng 

Refactor some functions in mkimage sunxi_egon type, in order to prepare
for adding support for more CPU architectures (e.g. RISC-V). In
addition, compatibility for operation w/o specified architecture is
kept, in this case the architecture is assumed as ARM.

Reviewed-by: Andre Przywara 
Signed-off-by: Icenowy Zheng 
Signed-off-by: Samuel Holland 
---

Changes in v3:
- Factor out an egon_get_arch() function as suggested by Andre

 tools/sunxi_egon.c | 50 +++---
 1 file changed, 43 insertions(+), 7 deletions(-)

diff --git a/tools/sunxi_egon.c b/tools/sunxi_egon.c
index a5299eb6a1..e1c945a12f 100644
--- a/tools/sunxi_egon.c
+++ b/tools/sunxi_egon.c
@@ -14,9 +14,28 @@
  */
 #define PAD_SIZE   8192
 
+static int egon_get_arch(struct image_tool_params *params)
+{
+   if (params->Aflag)
+   return params->arch;
+
+   /* For compatibility, assume ARM when no architecture specified */
+   return IH_ARCH_ARM;
+}
+
 static int egon_check_params(struct image_tool_params *params)
 {
-   /* We just need a binary image file. */
+   /*
+* Check whether the architecture is supported.
+*/
+   switch (egon_get_arch(params)) {
+   case IH_ARCH_ARM:
+   break;
+   default:
+   return EXIT_FAILURE;
+   }
+
+   /* We need a binary image file. */
return !params->dflag;
 }
 
@@ -26,9 +45,18 @@ static int egon_verify_header(unsigned char *ptr, int 
image_size,
const struct boot_file_head *header = (void *)ptr;
uint32_t length;
 
-   /* First 4 bytes must be an ARM branch instruction. */
-   if ((le32_to_cpu(header->b_instruction) & 0xff00) != 0xea00)
-   return EXIT_FAILURE;
+   /*
+* First 4 bytes must be a branch instruction of the corresponding
+* architecture.
+*/
+   switch (egon_get_arch(params)) {
+   case IH_ARCH_ARM:
+   if ((le32_to_cpu(header->b_instruction) & 0xff00) != 
0xea00)
+   return EXIT_FAILURE;
+   break;
+   default:
+   return EXIT_FAILURE; /* Unknown architecture */
+   }
 
if (memcmp(header->magic, BOOT0_MAGIC, sizeof(header->magic)))
return EXIT_FAILURE;
@@ -77,9 +105,17 @@ static void egon_set_header(void *buf, struct stat *sbuf, 
int infd,
uint32_t checksum = 0, value;
int i;
 
-   /* Generate an ARM branch instruction to jump over the header. */
-   value = 0xea00 | (sizeof(struct boot_file_head) / 4 - 2);
-   header->b_instruction = cpu_to_le32(value);
+   /*
+* Different architectures need different first instruction to
+* branch to the body.
+*/
+   switch (egon_get_arch(params)) {
+   case IH_ARCH_ARM:
+   /* Generate an ARM branch instruction to jump over the header. 
*/
+   value = 0xea00 | (sizeof(struct boot_file_head) / 4 - 2);
+   header->b_instruction = cpu_to_le32(value);
+   break;
+   }
 
memcpy(header->magic, BOOT0_MAGIC, sizeof(header->magic));
header->check_sum = cpu_to_le32(BROM_STAMP_VALUE);
-- 
2.32.0



[PATCH v3 3/4] mkimage: sunxi_egon: add support for riscv

2021-10-14 Thread Samuel Holland
From: Icenowy Zheng 

There's now a sun20i family in sunxi, which uses RISC-V CPU.

Add support for making eGON.BT0 image for RISC-V.

Reviewed-by: Andre Przywara 
Signed-off-by: Icenowy Zheng 
Signed-off-by: Samuel Holland 
---

(no changes since v1)

 tools/sunxi_egon.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/tools/sunxi_egon.c b/tools/sunxi_egon.c
index e1c945a12f..06e8d67ebc 100644
--- a/tools/sunxi_egon.c
+++ b/tools/sunxi_egon.c
@@ -30,6 +30,7 @@ static int egon_check_params(struct image_tool_params *params)
 */
switch (egon_get_arch(params)) {
case IH_ARCH_ARM:
+   case IH_ARCH_RISCV:
break;
default:
return EXIT_FAILURE;
@@ -54,6 +55,10 @@ static int egon_verify_header(unsigned char *ptr, int 
image_size,
if ((le32_to_cpu(header->b_instruction) & 0xff00) != 
0xea00)
return EXIT_FAILURE;
break;
+   case IH_ARCH_RISCV:
+   if ((le32_to_cpu(header->b_instruction) & 0x0fff) != 
0x006f)
+   return EXIT_FAILURE;
+   break;
default:
return EXIT_FAILURE; /* Unknown architecture */
}
@@ -115,6 +120,24 @@ static void egon_set_header(void *buf, struct stat *sbuf, 
int infd,
value = 0xea00 | (sizeof(struct boot_file_head) / 4 - 2);
header->b_instruction = cpu_to_le32(value);
break;
+   case IH_ARCH_RISCV:
+   /*
+* Generate a RISC-V JAL instruction with rd=x0
+* (pseudo instruction J, jump without side effects).
+*
+* The following weird bit operation maps imm[20]
+* to inst[31], imm[10:1] to inst[30:21],
+* imm[11] to inst[20], imm[19:12] to inst[19:12],
+* and imm[0] is dropped (because 1-byte RISC-V instruction
+* is not allowed).
+*/
+   value = 0x006f |
+   ((sizeof(struct boot_file_head) & 0x0010) << 11) |
+   ((sizeof(struct boot_file_head) & 0x07fe) << 20) |
+   ((sizeof(struct boot_file_head) & 0x0800) << 9) |
+   ((sizeof(struct boot_file_head) & 0x000ff000) << 0);
+   header->b_instruction = cpu_to_le32(value);
+   break;
}
 
memcpy(header->magic, BOOT0_MAGIC, sizeof(header->magic));
-- 
2.32.0



[PATCH v3 1/4] mkimage: add a flag to describe whether -A is specified

2021-10-14 Thread Samuel Holland
From: Icenowy Zheng 

The sunxi_egon type used to take no -A argument (because we assume sunxi
targets are all ARM). However, as Allwinner D1 appears as the first
RISC-V sunxi target, we need to support -A; in addition, as external
projects rely on U-Boot mkimage to generate sunxi eGON.BT0 header, we
need to keep compatibility with command line without -A.

As the default value of arch in mkimage is not proper (IH_ARCH_PPC
instead of IH_ARCH_INVALID), to keep more compatibility, add an Aflag
field to image parameters to describe whether an architecture is
explicitly specified.

Reviewed-by: Tom Rini 
Signed-off-by: Icenowy Zheng 
Signed-off-by: Samuel Holland 
---

(no changes since v1)

 tools/imagetool.h | 1 +
 tools/mkimage.c   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/tools/imagetool.h b/tools/imagetool.h
index e229a34ffc..5dc28312c2 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -51,6 +51,7 @@ struct image_tool_params {
int pflag;
int vflag;
int xflag;
+   int Aflag;
int skipcpy;
int os;
int arch;
diff --git a/tools/mkimage.c b/tools/mkimage.c
index fbe883ce36..cfd97b046c 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -171,6 +171,7 @@ static void process_args(int argc, char **argv)
show_valid_options(IH_ARCH);
usage("Invalid architecture");
}
+   params.Aflag = 1;
break;
case 'b':
if (add_content(IH_TYPE_FLATDT, optarg)) {
-- 
2.32.0



[PATCH v3 0/4] mkimage: sunxi_egon: add riscv support

2021-10-14 Thread Samuel Holland
This patchset updates mkimage -T sunxi_egon to be able to generate
an eGON.BT0 image for Allwinner RISC-V SoCs (e.g. D1).

In addition, to keep the compatibility, it will still consider the
architecture to be ARM when no architecture is specified.

This v3 is a minor update to Icenowy's patch series, which I have
also tested. Since the TOC0 patch series touches the same lines in
Makefile.spl, it depends on this series.

Changes in v3:
- Factor out an egon_get_arch() function as suggested by Andre

Icenowy Zheng (4):
  mkimage: add a flag to describe whether -A is specified
  mkimage: sunxi_egon: refactor for multi-architecture support
  mkimage: sunxi_egon: add support for riscv
  sunxi: specify architecture when generating SPL boot image

 scripts/Makefile.spl |  2 +-
 tools/imagetool.h|  1 +
 tools/mkimage.c  |  1 +
 tools/sunxi_egon.c   | 73 +++-
 4 files changed, 69 insertions(+), 8 deletions(-)

-- 
2.32.0



Re: [PATCH 1/1] cmd: simplify 'efidebug boot add' command

2021-10-14 Thread Heinrich Schuchardt

On 10/14/21 11:46 PM, Heinrich Schuchardt wrote:

We can determine the length of the device path in the boot option after it
is created. There is no need to keep track of the length while building
the device path.


As we are using end of total device path node as separator this does not
work.

Sorry for the noise.

Best regards

Heinrich



Signed-off-by: Heinrich Schuchardt 
---
  cmd/efidebug.c | 8 ++--
  1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 67ab06aefc..3398f56962 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -964,7 +964,6 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
struct efi_load_option lo;
void *data = NULL;
efi_uintn_t size;
-   efi_uintn_t fp_size = 0;
efi_status_t ret;
int r = CMD_RET_SUCCESS;

@@ -1008,8 +1007,6 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int 
flag,
r = CMD_RET_FAILURE;
goto out;
}
-   fp_size += efi_dp_size(file_path) +
-   sizeof(struct efi_device_path);
argc -= 5;
argv += 5;
} else if (!strcmp(argv[0], "-i")) {
@@ -1026,8 +1023,6 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int 
flag,
}
argc -= 3;
argv += 3;
-   fp_size += efi_dp_size(initrd_dp) +
-   sizeof(struct efi_device_path);
} else if (!strcmp(argv[0], "-s")) {
if (argc < 1 || lo.optional_data) {
r = CMD_RET_USAGE;
@@ -1056,7 +1051,8 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int 
flag,
}

lo.file_path = final_fp;
-   lo.file_path_length = fp_size;
+   lo.file_path_length = efi_dp_size(final_fp) +
+ sizeof(struct efi_device_path);

size = efi_serialize_load_option(, (u8 **));
if (!size) {
--
2.30.2





[PATCH 1/1] efi_loader: efi_dp_from_lo() should skip VenMedia node

2021-10-14 Thread Heinrich Schuchardt
The 'efidebug boot dump' command should not display the VenMedia() device
path node preceding the device path of the initial ram disk.

By letting efi_dp_from_lo() skip the VenMedia() device path node we can
simplify the coding.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_device_path.c |  2 +-
 lib/efi_loader/efi_helper.c  | 19 +--
 2 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index aaf1999d46..7f2aa239de 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -1287,7 +1287,7 @@ efi_device_path *efi_dp_from_lo(struct efi_load_option 
*lo,

vendor = (struct efi_device_path_vendor *)fp;
if (!guidcmp(>guid, guid))
-   return efi_dp_dup(fp);
+   return efi_dp_dup(efi_dp_next(fp));
}
log_debug("VenMedia(%pUl) not found in %ls\n", , lo->label);

diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index 485384b7ee..b80a6e07df 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -68,10 +68,8 @@ out:
  */
 struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid)
 {
-   struct efi_device_path *file_path = NULL;
-   struct efi_device_path *tmp = NULL;
struct efi_load_option lo;
-   void *var_value = NULL;
+   void *var_value;
efi_uintn_t size;
efi_status_t ret;
u16 var_name[16];
@@ -86,18 +84,11 @@ struct efi_device_path *efi_get_dp_from_boot(const 
efi_guid_t guid)

ret = efi_deserialize_load_option(, var_value, );
if (ret != EFI_SUCCESS)
-   goto out;
-
-   tmp = efi_dp_from_lo(, );
-   if (!tmp)
-   goto out;
+   goto err;

-   /* efi_dp_dup will just return NULL if efi_dp_next is NULL */
-   file_path = efi_dp_dup(efi_dp_next(tmp));
+   return efi_dp_from_lo(, );

-out:
-   efi_free_pool(tmp);
+err:
free(var_value);
-
-   return file_path;
+   return NULL;
 }
--
2.30.2



RE: [PATCH next v5 01/12] image: fit: Fix parameter name for hash algorithm

2021-10-14 Thread ChiaWei Wang
Hi Simon,

> From: Simon Glass 
> Sent: Thursday, October 14, 2021 11:10 PM
> 
> Hi Chia-Wei,
> 
> On Sun, 3 Oct 2021 at 19:54, Chia-Wei Wang
>  wrote:
> >
> > Fix inconsistent function parameter name of the hash algorithm.
> >
> > Signed-off-by: Chia-Wei Wang 
> > Fixes: 92055e138f2 ("image: Drop if/elseif hash selection in
> > calculate_hash()")
> > ---
> >  common/image-fit.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/common/image-fit.c b/common/image-fit.c index
> > 5a0a0cc200..9e8a1f36c1 100644
> > --- a/common/image-fit.c
> > +++ b/common/image-fit.c
> > @@ -1229,7 +1229,7 @@ int calculate_hash(const void *data, int data_len,
> const char *name,
> > return -1;
> > }
> >
> > -   hash_algo = hash_algo_lookup_by_name(algo);
> > +   hash_algo = hash_algo_lookup_by_name(name);
> > if (hash_algo == HASH_ALGO_INVALID) {
> > debug("Unsupported hash algorithm\n");
> > return -1;
> > --
> 
> Can you please fix the comment for this function as well?
> 
>  * @algo: requested hash algorithm
> 
> (should be @name)
> 

Sure. I missed the comment part.
Will send v6 to make them consistent ASAP.

Regards,
Chiawei


Re: [PATCH] buildman: Add gcc-11.1.0 to the directory list

2021-10-14 Thread Tom Rini
On Thu, Oct 14, 2021 at 07:25:24PM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Thu, 14 Oct 2021 at 19:12, Tom Rini  wrote:
> >
> > On Thu, Oct 14, 2021 at 07:05:33PM -0600, Simon Glass wrote:
> > > Hi Tom,
> > >
> > > On Tue, 5 Oct 2021 at 10:20, Tom Rini  wrote:
> > > >
> > > > While CI has been using gcc-11.1.0 for a long time, we have not updated
> > > > buildman to match.  Correct this omission.
> > > >
> > > > Signed-off-by: Tom Rini 
> > > > ---
> > > >  tools/buildman/toolchain.py | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
> > > > index fd137f7300e7..4e2471f3e370 100644
> > > > --- a/tools/buildman/toolchain.py
> > > > +++ b/tools/buildman/toolchain.py
> > > > @@ -498,7 +498,7 @@ class Toolchains:
> > > >  if arch == 'aarch64':
> > > >  arch = 'arm64'
> > > >  base = 'https://www.kernel.org/pub/tools/crosstool/files/bin'
> > > > -versions = ['9.2.0', '7.3.0', '6.4.0', '4.9.4']
> > > > +versions = ['11.1.0', '9.2.0', '7.3.0', '6.4.0', '4.9.4']
> > > >  links = []
> > > >  for version in versions:
> > > >  url = '%s/%s/%s/' % (base, arch, version)
> > > > --
> > > > 2.17.1
> > > >
> > >
> > > This seems to break that n900 build:
> > >
> > > https://source.denx.de/u-boot/custodians/u-boot-dm/-/jobs/336316
> >
> > *headdesk* the test hard-codes the toolchain version to add to PATH.
> 
> It might be a good oppty to put some of its downloads into the docker image?

Well, it's the CI files that had been hard-coding the path (I was a bit
quick before), and should instead be using the one that's already in the
image, yes.  So let me fire off something to fix that, and it just needs
to be in your tree before the other patch, to preserve bisectability.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] buildman: Add gcc-11.1.0 to the directory list

2021-10-14 Thread Simon Glass
Hi Tom,

On Thu, 14 Oct 2021 at 19:12, Tom Rini  wrote:
>
> On Thu, Oct 14, 2021 at 07:05:33PM -0600, Simon Glass wrote:
> > Hi Tom,
> >
> > On Tue, 5 Oct 2021 at 10:20, Tom Rini  wrote:
> > >
> > > While CI has been using gcc-11.1.0 for a long time, we have not updated
> > > buildman to match.  Correct this omission.
> > >
> > > Signed-off-by: Tom Rini 
> > > ---
> > >  tools/buildman/toolchain.py | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
> > > index fd137f7300e7..4e2471f3e370 100644
> > > --- a/tools/buildman/toolchain.py
> > > +++ b/tools/buildman/toolchain.py
> > > @@ -498,7 +498,7 @@ class Toolchains:
> > >  if arch == 'aarch64':
> > >  arch = 'arm64'
> > >  base = 'https://www.kernel.org/pub/tools/crosstool/files/bin'
> > > -versions = ['9.2.0', '7.3.0', '6.4.0', '4.9.4']
> > > +versions = ['11.1.0', '9.2.0', '7.3.0', '6.4.0', '4.9.4']
> > >  links = []
> > >  for version in versions:
> > >  url = '%s/%s/%s/' % (base, arch, version)
> > > --
> > > 2.17.1
> > >
> >
> > This seems to break that n900 build:
> >
> > https://source.denx.de/u-boot/custodians/u-boot-dm/-/jobs/336316
>
> *headdesk* the test hard-codes the toolchain version to add to PATH.

It might be a good oppty to put some of its downloads into the docker image?

Regards,
Simon


RE: [PATCH] clk: introduce u-boot,ignore-clk-defaults

2021-10-14 Thread Peng Fan
> Subject: Re: [PATCH] clk: introduce u-boot,ignore-clk-defaults
> 
> 
> On 10/13/21 5:37 AM, Peng Fan (OSS) wrote:
> > From: Peng Fan 
> >
> > Current code has a force clk_set_defaults in multiple stages, U-Boot
> > reuse the same device tree and Linux Kernel device tree, but we not
> > register all the clks as Linux Kernel, so clk_set_defaults will fail
> > and cause the clk provider registeration fail.
> >
> > So introduce a new property to ignore the default settings which could
> > be used by any node that wanna ignore default settings.
> >
> > Signed-off-by: Peng Fan 
> > ---
> >   doc/device-tree-bindings/device.txt | 3 +++
> >   drivers/clk/clk-uclass.c| 3 +++
> >   2 files changed, 6 insertions(+)
> >
> > diff --git a/doc/device-tree-bindings/device.txt
> > b/doc/device-tree-bindings/device.txt
> > index 73ce2a3b5b..fe34ced268 100644
> > --- a/doc/device-tree-bindings/device.txt
> > +++ b/doc/device-tree-bindings/device.txt
> > @@ -28,6 +28,9 @@ the acpi,compatible property.
> >   Linux will only load the driver if the device can be detected (e.g. on
> I2C
> >   bus). Note that this is an out-of-tree Linux feature.
> >
> > +Common device bindings that could be shared listed below:
> > + - u-boot,ignore-clk-defaults : ignore the assigned-clock-parents
> > +   and assigned-clock-rates for a device that has the property.
> >
> >   Example
> >   ---
> > diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index
> > 493018b33e..6bf3179e7b 100644
> > --- a/drivers/clk/clk-uclass.c
> > +++ b/drivers/clk/clk-uclass.c
> > @@ -376,6 +376,9 @@ int clk_set_defaults(struct udevice *dev, enum
> clk_defaults_stage stage)
> > if (!dev_has_ofnode(dev))
> > return 0;
> >
> > +   if (ofnode_get_property(dev_ofnode(dev), "u-boot,ignore-clk-defaults",
> NULL))
> > +   return 0;
> > +
> > /*
> >  * To avoid setting defaults twice, don't set them before relocation.
> >  * However, still set them for SPL. And still set them if
> > explicitly
> >
> 
> Why not just have the property ignore errors?

I think the force err return was done by Simon?

> 
> In the long term, it may be better to standardize that e.g. ENOENT means that
> the clock doesn't exist. That way we can skip setting the defaults.
> ENOSYS should probably be treated the same way (warn, but don't fail).

I am not sure whether people expect force error for ENOENT/ENOSYS in U-Boot.
For i.MX, I not expect force error.

Regards,
Peng.

> 
> --Sean


Re: [PATCH] buildman: Add gcc-11.1.0 to the directory list

2021-10-14 Thread Tom Rini
On Thu, Oct 14, 2021 at 07:05:33PM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Tue, 5 Oct 2021 at 10:20, Tom Rini  wrote:
> >
> > While CI has been using gcc-11.1.0 for a long time, we have not updated
> > buildman to match.  Correct this omission.
> >
> > Signed-off-by: Tom Rini 
> > ---
> >  tools/buildman/toolchain.py | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
> > index fd137f7300e7..4e2471f3e370 100644
> > --- a/tools/buildman/toolchain.py
> > +++ b/tools/buildman/toolchain.py
> > @@ -498,7 +498,7 @@ class Toolchains:
> >  if arch == 'aarch64':
> >  arch = 'arm64'
> >  base = 'https://www.kernel.org/pub/tools/crosstool/files/bin'
> > -versions = ['9.2.0', '7.3.0', '6.4.0', '4.9.4']
> > +versions = ['11.1.0', '9.2.0', '7.3.0', '6.4.0', '4.9.4']
> >  links = []
> >  for version in versions:
> >  url = '%s/%s/%s/' % (base, arch, version)
> > --
> > 2.17.1
> >
> 
> This seems to break that n900 build:
> 
> https://source.denx.de/u-boot/custodians/u-boot-dm/-/jobs/336316

*headdesk* the test hard-codes the toolchain version to add to PATH.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] clk: introduce u-boot,ignore-clk-defaults

2021-10-14 Thread Sean Anderson



On 10/13/21 5:37 AM, Peng Fan (OSS) wrote:

From: Peng Fan 

Current code has a force clk_set_defaults in multiple stages,
U-Boot reuse the same device tree and Linux Kernel device tree,
but we not register all the clks as Linux Kernel, so clk_set_defaults
will fail and cause the clk provider registeration fail.

So introduce a new property to ignore the default settings which could
be used by any node that wanna ignore default settings.

Signed-off-by: Peng Fan 
---
  doc/device-tree-bindings/device.txt | 3 +++
  drivers/clk/clk-uclass.c| 3 +++
  2 files changed, 6 insertions(+)

diff --git a/doc/device-tree-bindings/device.txt 
b/doc/device-tree-bindings/device.txt
index 73ce2a3b5b..fe34ced268 100644
--- a/doc/device-tree-bindings/device.txt
+++ b/doc/device-tree-bindings/device.txt
@@ -28,6 +28,9 @@ the acpi,compatible property.
  Linux will only load the driver if the device can be detected (e.g. on I2C
  bus). Note that this is an out-of-tree Linux feature.
  
+Common device bindings that could be shared listed below:

+ - u-boot,ignore-clk-defaults : ignore the assigned-clock-parents
+   and assigned-clock-rates for a device that has the property.
  
  Example

  ---
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 493018b33e..6bf3179e7b 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -376,6 +376,9 @@ int clk_set_defaults(struct udevice *dev, enum 
clk_defaults_stage stage)
if (!dev_has_ofnode(dev))
return 0;
  
+	if (ofnode_get_property(dev_ofnode(dev), "u-boot,ignore-clk-defaults", NULL))

+   return 0;
+
/*
 * To avoid setting defaults twice, don't set them before relocation.
 * However, still set them for SPL. And still set them if explicitly



Why not just have the property ignore errors?

In the long term, it may be better to standardize that e.g. ENOENT means
that the clock doesn't exist. That way we can skip setting the defaults.
ENOSYS should probably be treated the same way (warn, but don't fail).

--Sean


Re: [PATCH] buildman: Add gcc-11.1.0 to the directory list

2021-10-14 Thread Simon Glass
Hi Tom,

On Tue, 5 Oct 2021 at 10:20, Tom Rini  wrote:
>
> While CI has been using gcc-11.1.0 for a long time, we have not updated
> buildman to match.  Correct this omission.
>
> Signed-off-by: Tom Rini 
> ---
>  tools/buildman/toolchain.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
> index fd137f7300e7..4e2471f3e370 100644
> --- a/tools/buildman/toolchain.py
> +++ b/tools/buildman/toolchain.py
> @@ -498,7 +498,7 @@ class Toolchains:
>  if arch == 'aarch64':
>  arch = 'arm64'
>  base = 'https://www.kernel.org/pub/tools/crosstool/files/bin'
> -versions = ['9.2.0', '7.3.0', '6.4.0', '4.9.4']
> +versions = ['11.1.0', '9.2.0', '7.3.0', '6.4.0', '4.9.4']
>  links = []
>  for version in versions:
>  url = '%s/%s/%s/' % (base, arch, version)
> --
> 2.17.1
>

This seems to break that n900 build:

https://source.denx.de/u-boot/custodians/u-boot-dm/-/jobs/336316

Regards,
Simon


Re: External dts building

2021-10-14 Thread Simon Glass
Hi Giulio,

On Thu, 14 Oct 2021 at 15:12, Giulio Benetti
 wrote:
>
> Hi Simon,
>
> Il giorno 14 ott 2021, alle ore 22:43, Simon Glass  ha 
> scritto:
>
> Hi Giulio,
>
> On Thu, 14 Oct 2021 at 13:23, Giulio Benetti
>  wrote:
>
>
> Hi Simon,
>
>
> Il giorno 14 ott 2021, alle ore 20:24, Simon Glass  ha 
> scritto:
>
>
> Hi,
>
>
> On Thu, 14 Oct 2021 at 07:46, Tom Rini  wrote:
>
>
> On Thu, Oct 14, 2021 at 02:53:30AM +0200, Giulio Benetti wrote:
>
>
> Hello All,
>
>
> is there a way to pass a dts file without touching the 
> arch/arm/boot/dts/Makefile?
>
>
> On Buildroot we support the possibility to pass an external dts by copying it 
> to the uboot sources to
>
> be built but since uboot version 2020.01 it doesn’t work anymore.
>
>
> So I’ve proposed a patch to prepend the dts file in the Makefile above, but 
> this has drawbacks, like we reconfigure(it keeps adding files every time).
>
>
> So I ask you, is there a more canonical way already to achieve this?
>
>
> Not exactly, and it's something we're very much actively discussing
>
> right now.
>
>
> Are you using 'make DEVICE_TREE=xxx' ?
>
>
> Yes but it doesn’t work if you don’t add an entry into arch/arm/dts/Makefile
>
> Before version 2020.01 worked, but not after it.
>
>
> What board are you building?
>
>
> A20-OLinuXino-Lime_defconfig for but without CONFIG_DEFAULT_DEVICE_TREE 
> undefined,
> so if you try to pass DEVICE_TREE= pointing to an external .dts file copied 
> to arch/arm/dts/ make doesn’t find the entry in Makefile and it can’t build 
> it.
>
> This is useful in build systems like Buildroot where you can provide an 
> external defconfig as well as an external .dts file.
>
> So here the solution I see is to create an entry in arch/arm/dts/Makefile on 
> the top of the file afte copying the .dts file we want to build.
> But on Buildroot they’ve pointed me to ask upstream(here) if there’s a more 
> canonical way or to work together to achieve the goal:
>
> https://patchwork.ozlabs.org/project/buildroot/patch/20210209201303.195093-1-giulio.bene...@benettiengineering.com/

How about not disabling CONFIG_DEFAULT_DEVICE_TREE ? That should work OK.

Regards,
Simon

>
> Sorry if this e-mail is html but I’m on mobile :-/
>
> Best regards
> Giulio Benetti
>
>
> Regards,
> Simon


Re: [PATCH v4 03/11] efi_loader: capsule: add back efi_get_public_key_data()

2021-10-14 Thread Simon Glass
Hi Takahiro,

On Thu, 7 Oct 2021 at 00:25, AKASHI Takahiro  wrote:
>
> The commit 47a25e81d35c ("Revert "efi_capsule: Move signature from DTB to
> .rodata"") failed to revert the removal of efi_get_public_key_data().
>
> Add back this function and move it under lib/efi_loader so that other
> platforms can utilize it. It is now declared as a weak function so that
> it can be replaced with a platform-specific implementation.
>
> Fixes: 47a25e81d35c ("Revert "efi_capsule: Move signature from DTB to
> .rodata"")
> Signed-off-by: AKASHI Takahiro 
> ---
>  lib/efi_loader/efi_capsule.c | 36 
>  1 file changed, 36 insertions(+)
>
> diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
> index b75e4bcba1a9..44f5da61a9be 100644
> --- a/lib/efi_loader/efi_capsule.c
> +++ b/lib/efi_loader/efi_capsule.c
> @@ -11,15 +11,20 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include 
>  #include 
>  #include 
>
> +DECLARE_GLOBAL_DATA_PTR;
> +
>  const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
>  static const efi_guid_t efi_guid_firmware_management_capsule_id =
> EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
> @@ -251,6 +256,37 @@ out:
>  }
>
>  #if defined(CONFIG_EFI_CAPSULE_AUTHENTICATE)
> +int __weak efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)

I don't think this should be weak. What other way is there of handling
this and why would it be platform-specific?

> +{
> +   const void *fdt_blob = gd->fdt_blob;
> +   const void *blob;
> +   const char *cnode_name = "capsule-key";
> +   const char *snode_name = "signature";
> +   int sig_node;
> +   int len;
> +
> +   sig_node = fdt_subnode_offset(fdt_blob, 0, snode_name);
> +   if (sig_node < 0) {
> +   log_err("Unable to get signature node offset\n");
> +
> +   return -FDT_ERR_NOTFOUND;
> +   }
> +
> +   blob = fdt_getprop(fdt_blob, sig_node, cnode_name, );
> +
> +   if (!blob || len < 0) {
> +   log_err("Unable to get capsule-key value\n");
> +   *pkey = NULL;
> +   *pkey_len = 0;
> +
> +   return -FDT_ERR_NOTFOUND;
> +   }
> +
> +   *pkey = (void *)blob;
> +   *pkey_len = len;
> +
> +   return 0;
> +}
>
>  efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t 
> capsule_size,
>   void **image, efi_uintn_t *image_size)
> --
> 2.33.0
>

Regards,
Simon


Re: [PATCH v4 04/11] tools: add fdtsig.sh

2021-10-14 Thread Simon Glass
Hi Takahiro,

On Mon, 11 Oct 2021 at 19:42, AKASHI Takahiro
 wrote:
>
> Simon,
>
> On Mon, Oct 11, 2021 at 08:54:09AM -0600, Simon Glass wrote:
> > Hi Takahiro,
> >
> > On Thu, 7 Oct 2021 at 00:25, AKASHI Takahiro  
> > wrote:
> > >
> > > With this script, a public key is added to a device tree blob
> > > as the default efi_get_public_key_data() expects.
> > >
> > > Signed-off-by: AKASHI Takahiro 
> > > ---
> > >  MAINTAINERS |  1 +
> > >  tools/fdtsig.sh | 40 
> > >  2 files changed, 41 insertions(+)
> > >  create mode 100755 tools/fdtsig.sh
> >
> > Instead of an ad-hoc script with no tests,
>
> Basically I intended to provide fdtsig.sh as a *sample* script so that
> people may want to integrate the logic into their own build rule/systems.
> But I could use this script in my 'capsule authentication' test
> that is also added in patch#22.
>
> > could we use binman for
> > putting the image together and inserting it?
>
> First, as you can see, the script is quite simple and secondly,
> the purpose of binman, IIUC, is to help handle/manipulate U-Boot
> image binaries.
> So I'm not sure whether it is really useful to add such a feature to binman.

I'm not sure. The script seems very ad-hoc to me, for a feature that
Linaro is pushing so hard.

I don't see where the script is used in the tests or even mentioned in
the documentation. Am I missing something?

Regards,
Simon


Re: [PATCH v2 04/13] env: Change env_match() to static and remove from header

2021-10-14 Thread Simon Glass
On Thu, 14 Oct 2021 at 12:24, Simon Glass  wrote:
>
> Hi Marek,
>
> On Thu, 14 Oct 2021 at 10:06, Marek Behún  wrote:
> >
> > On Thu, 14 Oct 2021 09:11:08 -0600
> > Simon Glass  wrote:
> >
> > > Hi Marek,
> > >
> > > On Wed, 13 Oct 2021 at 09:46, Marek Behún  wrote:
> > > >
> > > > From: Marek Behún 
> > > >
> > > > This function was used by other parts of U-Boot in the past when
> > > > environment was read from underlying device one character at a time.
> > > >
> > > > This is not the case anymore.
> > > >
> > > > Signed-off-by: Marek Behún 
> > > > ---
> > > >  cmd/nvedit.c  | 30 +++---
> > > >  include/env.h | 11 ---
> > > >  2 files changed, 15 insertions(+), 26 deletions(-)
> > > >
> > > > diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> > > > index ddc715b4f9..742e0924af 100644
> > > > --- a/cmd/nvedit.c
> > > > +++ b/cmd/nvedit.c
> > > > @@ -706,6 +706,21 @@ char *from_env(const char *envvar)
> > > > return ret;
> > > >  }
> > > >
> > >
> > > Please can you add the function comment here? We don't want to lose
> > > it.
> >
> > Simon, the comment is invalid (the function does something
> > different from what the comment says) and the function is only used as a
> > helper by env_get_f(), which comes right after it. The function is
> > refactored and renamend in subsequent patches, and its purpose seems
> > obvious to me.
> >
> > Should I really leave the comment there?
>
> That's fine but it would be good to mention that in the commit message
> explicitly.
>
> Also you add matching_name_get_value(). Can you add a comment to that, then?
>
Reviewed-by: Simon Glass 


Re: [PATCH v2 1/7] iommu: Add IOMMU uclass

2021-10-14 Thread Simon Glass
Hi Mark,

On Thu, 14 Oct 2021 at 15:11, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Thu, 14 Oct 2021 14:55:19 -0600
> >
> > Hi Mark,
> >
> > On Thu, 14 Oct 2021 at 14:51, Mark Kettenis  wrote:
> > >
> > > > From: Simon Glass 
> > > > Date: Thu, 14 Oct 2021 14:20:21 -0600
> > > >
> > > > Hi Mark,
> > > >
> > > > On Thu, 14 Oct 2021 at 13:35, Mark Kettenis  
> > > > wrote:
> > > > >
> > > > > > From: Simon Glass 
> > > > > > Date: Mon, 11 Oct 2021 11:00:34 -0600
> > > > > >
> > > > > > Hi Mark,
> > > > > >
> > > > > > On Sun, 3 Oct 2021 at 12:31, Mark Kettenis  
> > > > > > wrote:
> > > > > > >
> > > > > > > This uclass is intended to manage IOMMUs on systems where the
> > > > > > > IOMMUs are not in bypass mode by default.  In that case U-Boot
> > > > > > > cannot ignore the IOMMUs if it wants to use devices that need
> > > > > > > to do DMA and sit behind such an IOMMU.
> > > > > > >
> > > > > > > This initial IOMMU uclass implementation does not implement and
> > > > > > > device ops and is intended for IOMMUs that have a bypass mode
> > > > > > > that does not require address translation.  Support for IOMMUs
> > > > > > > that do require address translation is planned and device ops
> > > > > > > will be defined when support for such IOMMUs will be added.
> > > > > > >
> > > > > > > Signed-off-by: Mark Kettenis 
> > > > > > > ---
> > > > > > >  drivers/Kconfig  |  2 ++
> > > > > > >  drivers/Makefile |  1 +
> > > > > > >  drivers/core/device.c|  8 +++
> > > > > > >  drivers/iommu/Kconfig| 13 +++
> > > > > > >  drivers/iommu/Makefile   |  3 +++
> > > > > > >  drivers/iommu/iommu-uclass.c | 45 
> > > > > > > 
> > > > > > >  include/dm/uclass-id.h   |  1 +
> > > > > > >  include/iommu.h  | 16 +
> > > > > > >  8 files changed, 89 insertions(+)
> > > > > > >  create mode 100644 drivers/iommu/Kconfig
> > > > > > >  create mode 100644 drivers/iommu/Makefile
> > > > > > >  create mode 100644 drivers/iommu/iommu-uclass.c
> > > > > > >  create mode 100644 include/iommu.h
> > > > > > >
> > > > > > > diff --git a/drivers/Kconfig b/drivers/Kconfig
> > > > > > > index 417d6f88c2..b26ca8cf70 100644
> > > > > > > --- a/drivers/Kconfig
> > > > > > > +++ b/drivers/Kconfig
> > > > > > > @@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig"
> > > > > > >
> > > > > > >  source "drivers/input/Kconfig"
> > > > > > >
> > > > > > > +source "drivers/iommu/Kconfig"
> > > > > > > +
> > > > > > >  source "drivers/led/Kconfig"
> > > > > > >
> > > > > > >  source "drivers/mailbox/Kconfig"
> > > > > > > diff --git a/drivers/Makefile b/drivers/Makefile
> > > > > > > index fd218c9056..166aeb9817 100644
> > > > > > > --- a/drivers/Makefile
> > > > > > > +++ b/drivers/Makefile
> > > > > > > @@ -109,6 +109,7 @@ obj-y += mtd/
> > > > > > >  obj-y += pwm/
> > > > > > >  obj-y += reset/
> > > > > > >  obj-y += input/
> > > > > > > +obj-y += iommu/
> > > > > > >  # SOC specific infrastructure drivers.
> > > > > > >  obj-y += smem/
> > > > > > >  obj-y += thermal/
> > > > > > > diff --git a/drivers/core/device.c b/drivers/core/device.c
> > > > > > > index 29668f6fb3..5f480ad443 100644
> > > > > > > --- a/drivers/core/device.c
> > > > > > > +++ b/drivers/core/device.c
> > > > > > > @@ -28,6 +28,7 @@
> > > > > > >  #include 
> > > > > > >  #include 
> > > > > > >  #include 
> > > > > > > +#include 
> > > > > > >  #include 
> > > > > > >  #include 
> > > > > > >  #include 
> > > > > > > @@ -543,6 +544,13 @@ int device_probe(struct udevice *dev)
> > > > > > > goto fail;
> > > > > > > }
> > > > > > >
> > > > > > > +   if (CONFIG_IS_ENABLED(IOMMU) && dev->parent &&
> > > > > > > +   (device_get_uclass_id(dev) != UCLASS_IOMMU)) {
> > > > > > > +   ret = dev_iommu_probe(dev);
> > > > > > > +   if (ret)
> > > > > > > +   goto fail;
> > > > > > > +   }
> > > > > > > +
> > > > > > > ret = device_get_dma_constraints(dev);
> > > > > > > if (ret)
> > > > > > > goto fail;
> > > > > > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> > > > > > > new file mode 100644
> > > > > > > index 00..8cb377560e
> > > > > > > --- /dev/null
> > > > > > > +++ b/drivers/iommu/Kconfig
> > > > > > > @@ -0,0 +1,13 @@
> > > > > > > +#
> > > > > > > +# IOMMU devices
> > > > > > > +#
> > > > > > > +
> > > > > > > +menu "IOMMU device drivers"
> > > > > > > +
> > > > > > > +config IOMMU
> > > > > > > +   bool "Enable Driver Model for IOMMU drivers"
> > > > > > > +   depends on DM
> > > > > > > +   help
> > > > > > > + Enable driver model for IOMMU devices.
> > > > > >
> > > > > > Need at least three lines. What is an IOMMU? How does it relate to
> > > > > > other devices?
> > > > >
> > > > > Not sure if I can describe what an IOMMU is in just a few lines, but
> > > > > I'll try.
> > > > >
> > > > 

Re: [PATCH v2 10/13] env: Use better name for variable in env_get_f()

2021-10-14 Thread Simon Glass
Hi Marek,

On Wed, 13 Oct 2021 at 09:46, Marek Behún  wrote:
>
> From: Marek Behún 
>
> The `nxt` variable actually points to the terminating null-byte of the
> current env var, and the next env var is at `nxt + 1`, not `nxt`. So a
> better name for this variable is `end`.
>
> Signed-off-by: Marek Behún 
> ---
>  cmd/nvedit.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> index 6eabd51209..08288fad10 100644
> --- a/cmd/nvedit.c
> +++ b/cmd/nvedit.c
> @@ -724,7 +724,7 @@ static const char *matching_name_get_value(const char *p, 
> const char *name)
>   */
>  int env_get_f(const char *name, char *buf, unsigned len)
>  {
> -   const char *env, *p, *nxt;
> +   const char *env, *p, *end;
>
> if (name == NULL || *name == '\0')
> return -1;
> @@ -734,12 +734,12 @@ int env_get_f(const char *name, char *buf, unsigned len)
> else
> env = (const char *)gd->env_addr;
>
> -   for (p = env; *p != '\0'; p = nxt + 1) {
> +   for (p = env; *p != '\0'; p = end + 1) {
> const char *value;
> int n;
>
> -   for (nxt = p; *nxt != '\0'; ++nxt)
> -   if (nxt - env >= CONFIG_ENV_SIZE)
> +   for (end = p; *end != '\0'; ++end)
> +   if (end - env >= CONFIG_ENV_SIZE)
> return -1;
>
> value = matching_name_get_value(p, name);
> --
> 2.32.0
>


Re: [PATCH v2 09/13] env: Use string pointer instead of indexes in env_get_f()

2021-10-14 Thread Simon Glass
Hi Marek,

On Wed, 13 Oct 2021 at 09:46, Marek Behún  wrote:
>
> From: Marek Behún 
>
> Since we no longer use env_get_char() to access n-th character of
> linearized environment data, but rather access the arrays themselves, we
> can convert the iteration to use string pointers instead of position
> indexes.
>
> Signed-off-by: Marek Behún 
> ---
>  cmd/nvedit.c | 34 +-
>  1 file changed, 17 insertions(+), 17 deletions(-)
>
> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> index 7c99a693ea..6eabd51209 100644
> --- a/cmd/nvedit.c
> +++ b/cmd/nvedit.c
> @@ -706,17 +706,17 @@ char *from_env(const char *envvar)
> return ret;
>  }
>
> -static int env_match(const char *env, const char *s1, int i2)
> +static const char *matching_name_get_value(const char *p, const char *name)

OK so this is the function where I would like a nice comment, please.

>  {
> -   while (*s1 == env[i2++] && *s1 != '\0')
> -   if (*s1++ == '=')
> -   return i2;
> +   while (*name == *p++ && *name != '\0')
> +   if (*name++ == '=')
> +   return p;
>
> -   /* We can look at env[i2-1] because i2 was incremented at least once. 
> */
> -   if (*s1 == '\0' && env[i2-1] == '=')
> -   return i2;
> +   /* We can look at p[-1] because p was incremented at least once. */
> +   if (*name == '\0' && p[-1] == '=')
> +   return p;
>
> -   return -1;
> +   return NULL;
>  }
>
>  /*
> @@ -724,8 +724,7 @@ static int env_match(const char *env, const char *s1, int 
> i2)
>   */
>  int env_get_f(const char *name, char *buf, unsigned len)
>  {
> -   const char *env;
> -   int i, nxt;
> +   const char *env, *p, *nxt;
>
> if (name == NULL || *name == '\0')
> return -1;
> @@ -735,20 +734,21 @@ int env_get_f(const char *name, char *buf, unsigned len)
> else
> env = (const char *)gd->env_addr;
>
> -   for (i = 0; env[i] != '\0'; i = nxt + 1) {
> -   int val, n;
> +   for (p = env; *p != '\0'; p = nxt + 1) {
> +   const char *value;
> +   int n;
>
> -   for (nxt = i; env[nxt] != '\0'; ++nxt)
> -   if (nxt >= CONFIG_ENV_SIZE)
> +   for (nxt = p; *nxt != '\0'; ++nxt)
> +   if (nxt - env >= CONFIG_ENV_SIZE)
> return -1;
>
> -   val = env_match(env, name, i);
> -   if (val < 0)
> +   value = matching_name_get_value(p, name);
> +   if (value == NULL)
> continue;
>
> /* found; copy out */
> for (n = 0; n < len; ++n, ++buf) {
> -   *buf = env[val++];
> +   *buf = *value++;
> if (*buf == '\0')
> return n;
> }
> --
> 2.32.0
>

Regards,
Simon


[PATCH 1/1] efi_loader: avoid multiple local copies of lf2_initrd_guid

2021-10-14 Thread Heinrich Schuchardt
Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt 
---
 cmd/efidebug.c   | 3 +--
 include/efi_load_initrd.h| 1 +
 lib/efi_loader/efi_helper.c  | 5 +
 lib/efi_loader/efi_load_initrd.c | 3 +--
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 33a5135ee1..a977ca9c72 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -1144,7 +1144,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void 
*data, size_t *size)
struct efi_device_path *initrd_path = NULL;
struct efi_load_option lo;
efi_status_t ret;
-   const efi_guid_t lf2_initrd_guid = EFI_INITRD_MEDIA_GUID;

ret = efi_deserialize_load_option(, data, size);
if (ret != EFI_SUCCESS) {
@@ -1165,7 +1164,7 @@ static void show_efi_boot_opt_data(u16 *varname16, void 
*data, size_t *size)

printf("  file_path: %pD\n", lo.file_path);

-   initrd_path = efi_dp_from_lo(, _initrd_guid);
+   initrd_path = efi_dp_from_lo(, _lf2_initrd_guid);
if (initrd_path) {
printf("  initrd_path: %pD\n", initrd_path);
efi_free_pool(initrd_path);
diff --git a/include/efi_load_initrd.h b/include/efi_load_initrd.h
index 478ae807c6..be5d5a7acb 100644
--- a/include/efi_load_initrd.h
+++ b/include/efi_load_initrd.h
@@ -16,6 +16,7 @@
 #define EFI_INITRD_MEDIA_GUID \
EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, \
 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
+extern const efi_guid_t efi_lf2_initrd_guid;

 struct efi_initrd_dp {
struct efi_device_path_vendor vendor;
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index 89833de222..485384b7ee 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -13,6 +13,11 @@
 #include 
 #include 

+#if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI_LOAD_FILE2_INITRD)
+/* GUID used by Linux to identify the LoadFile2 protocol with the initrd */
+const efi_guid_t efi_lf2_initrd_guid = EFI_INITRD_MEDIA_GUID;
+#endif
+
 /**
  * efi_create_current_boot_var() - Return Boot name were  is replaced 
by
  *the value of BootCurrent
diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c
index e2a8063023..c5e6652e66 100644
--- a/lib/efi_loader/efi_load_initrd.c
+++ b/lib/efi_loader/efi_load_initrd.c
@@ -52,7 +52,6 @@ static efi_handle_t efi_initrd_handle;
  */
 static efi_status_t get_initrd_fp(struct efi_device_path **initrd_fp)
 {
-   const efi_guid_t lf2_initrd_guid = EFI_INITRD_MEDIA_GUID;
struct efi_device_path *dp = NULL;

/*
@@ -65,7 +64,7 @@ static efi_status_t get_initrd_fp(struct efi_device_path 
**initrd_fp)
 * We can then use this specific return value and not install the
 * protocol, while allowing the boot to continue
 */
-   dp = efi_get_dp_from_boot(lf2_initrd_guid);
+   dp = efi_get_dp_from_boot(efi_lf2_initrd_guid);
if (!dp)
return EFI_INVALID_PARAMETER;

--
2.30.2



[PATCH 1/1] efi_loader: efi_dp_from_lo() unused parameter size

2021-10-14 Thread Heinrich Schuchardt
Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt 
---
 cmd/efidebug.c   | 3 +--
 include/efi_loader.h | 1 -
 lib/efi_loader/efi_device_path.c | 2 --
 lib/efi_loader/efi_helper.c  | 2 +-
 4 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 70a4658012..33a5135ee1 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -1144,7 +1144,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void 
*data, size_t *size)
struct efi_device_path *initrd_path = NULL;
struct efi_load_option lo;
efi_status_t ret;
-   efi_uintn_t initrd_dp_size;
const efi_guid_t lf2_initrd_guid = EFI_INITRD_MEDIA_GUID;

ret = efi_deserialize_load_option(, data, size);
@@ -1166,7 +1165,7 @@ static void show_efi_boot_opt_data(u16 *varname16, void 
*data, size_t *size)

printf("  file_path: %pD\n", lo.file_path);

-   initrd_path = efi_dp_from_lo(, _dp_size, _initrd_guid);
+   initrd_path = efi_dp_from_lo(, _initrd_guid);
if (initrd_path) {
printf("  initrd_path: %pD\n", initrd_path);
efi_free_pool(initrd_path);
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 6e806f9b0d..3e5ac38042 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -842,7 +842,6 @@ struct efi_load_option {
 };

 struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
-  efi_uintn_t *size,
   const efi_guid_t *guid);
 struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
  const struct efi_device_path *dp2);
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index c3139f8e64..aaf1999d46 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -1263,7 +1263,6 @@ ssize_t efi_dp_check_length(const struct efi_device_path 
*dp,
  *initrd location
  *
  * @lo:EFI_LOAD_OPTION containing a valid device path
- * @size:  size of the discovered device path
  * @guid:  guid to search for
  *
  * Return:
@@ -1272,7 +1271,6 @@ ssize_t efi_dp_check_length(const struct efi_device_path 
*dp,
  */
 struct
 efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
-   efi_uintn_t *size,
const efi_guid_t *guid)
 {
struct efi_device_path *fp = lo->file_path;
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index 4c5b7cd2e1..89833de222 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -83,7 +83,7 @@ struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t 
guid)
if (ret != EFI_SUCCESS)
goto out;

-   tmp = efi_dp_from_lo(, , );
+   tmp = efi_dp_from_lo(, );
if (!tmp)
goto out;

--
2.30.2



[PATCH 1/1] efi_loader: simplify show_efi_boot_opt_data()

2021-10-14 Thread Heinrich Schuchardt
Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt 
---
 cmd/efidebug.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 5235dbb7c1..70a4658012 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -1143,7 +1143,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void 
*data, size_t *size)
 {
struct efi_device_path *initrd_path = NULL;
struct efi_load_option lo;
-   u16 *dp_str;
efi_status_t ret;
efi_uintn_t initrd_dp_size;
const efi_guid_t lf2_initrd_guid = EFI_INITRD_MEDIA_GUID;
@@ -1165,15 +1164,11 @@ static void show_efi_boot_opt_data(u16 *varname16, void 
*data, size_t *size)
   lo.attributes);
printf("  label: %ls\n", lo.label);

-   dp_str = efi_dp_str(lo.file_path);
-   printf("  file_path: %ls\n", dp_str);
-   efi_free_pool(dp_str);
+   printf("  file_path: %pD\n", lo.file_path);

initrd_path = efi_dp_from_lo(, _dp_size, _initrd_guid);
if (initrd_path) {
-   dp_str = efi_dp_str(initrd_path);
-   printf("  initrd_path: %ls\n", dp_str);
-   efi_free_pool(dp_str);
+   printf("  initrd_path: %pD\n", initrd_path);
efi_free_pool(initrd_path);
}

--
2.30.2



Re: [PATCH] arm: spl: flush and disable cache before jumping to OPTEE

2021-10-14 Thread Tom Rini
On Sat, Sep 25, 2021 at 05:05:43PM +0300, Oleksandr Suvorov wrote:

> From: Ricardo Salveti 
> 
> Make sure to flush, disable caches and interrupts before jumpint to
> OPTEE. This fixes the SDP->SPL->OPTEE boot flow on iMX6Q and most
> likely on some other ARM SoCs.
> 
> Signed-off-by: Ricardo Salveti 
> Co-developed-by: Oleksandr Suvorov 
> Signed-off-by: Oleksandr Suvorov 
> ---
> 
>  arch/arm/lib/spl.c | 11 +++
>  common/spl/spl.c   | 11 +--
>  include/spl.h  |  9 +
>  3 files changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/lib/spl.c b/arch/arm/lib/spl.c
> index 8e2bdf3536..16e3cd557a 100644
> --- a/arch/arm/lib/spl.c
> +++ b/arch/arm/lib/spl.c
> @@ -77,3 +77,14 @@ void __noreturn jump_to_image_linux(struct spl_image_info 
> *spl_image)
>  }
>  #endif   /* CONFIG_ARM64 */
>  #endif
> +
> +#if CONFIG_IS_ENABLED(OPTEE)
> +void __noreturn jump_to_image_optee(struct spl_image_info *spl_image)
> +{
> + /* flush and turn off caches before jumping to OPTEE */
> + cleanup_before_linux();
> +
> + spl_optee_entry(NULL, NULL, spl_image->fdt_addr,
> + (void *)spl_image->entry_point);
> +}
> +#endif
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index d55d3c2848..f3fab3c4d9 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -171,6 +171,14 @@ __weak void spl_board_prepare_for_optee(void *fdt)
>  {
>  }
>  
> +#if CONFIG_IS_ENABLED(OPTEE)
> +__weak void __noreturn jump_to_image_optee(struct spl_image_info *spl_image)
> +{
> + spl_optee_entry(NULL, NULL, spl_image->fdt_addr,
> + (void *)spl_image->entry_point);
> +}
> +#endif
> +
>  __weak void spl_board_prepare_for_boot(void)
>  {
>   /* Nothing to do! */
> @@ -777,8 +785,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
>   case IH_OS_TEE:
>   debug("Jumping to U-Boot via OP-TEE\n");
>   spl_board_prepare_for_optee(spl_image.fdt_addr);
> - spl_optee_entry(NULL, NULL, spl_image.fdt_addr,
> - (void *)spl_image.entry_point);
> + jump_to_image_optee(_image);
>   break;
>  #endif
>  #if CONFIG_IS_ENABLED(OPENSBI)
> diff --git a/include/spl.h b/include/spl.h
> index afbf39bef4..8e7173d294 100644
> --- a/include/spl.h
> +++ b/include/spl.h
> @@ -460,6 +460,15 @@ int spl_board_boot_device(u32 boot_device);
>   */
>  void __noreturn jump_to_image_linux(struct spl_image_info *spl_image);
>  
> +/**
> + * jump_to_image_linux() - Jump to OP-TEE OS from SPL
> + *
> + * This jumps into OP-TEE OS using the information in @spl_image.
> + *
> + * @spl_image: Image description to set up
> + */
> +void __noreturn jump_to_image_optee(struct spl_image_info *spl_image);
> +
>  /**
>   * spl_start_uboot() - Check if SPL should start the kernel or U-Boot
>   *

At current, this causes evb-rk3229 and evb-rk3288 to fail to build.  A
trivial "test on OPTEE_IMAGE" instead leads to warnings about a
noreturnn function returning.  Please rebase on current master and
retest your use cases, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH 1/1] efi_loader: efi_dp_from_lo() don't copy GUID

2021-10-14 Thread Heinrich Schuchardt
Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt 
---
 cmd/efidebug.c   | 2 +-
 include/efi_loader.h | 3 ++-
 lib/efi_loader/efi_device_path.c | 5 +++--
 lib/efi_loader/efi_helper.c  | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 67ab06aefc..5235dbb7c1 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -1169,7 +1169,7 @@ static void show_efi_boot_opt_data(u16 *varname16, void 
*data, size_t *size)
printf("  file_path: %ls\n", dp_str);
efi_free_pool(dp_str);

-   initrd_path = efi_dp_from_lo(, _dp_size, lf2_initrd_guid);
+   initrd_path = efi_dp_from_lo(, _dp_size, _initrd_guid);
if (initrd_path) {
dp_str = efi_dp_str(initrd_path);
printf("  initrd_path: %ls\n", dp_str);
diff --git a/include/efi_loader.h b/include/efi_loader.h
index c440962fe5..8b57bb9b09 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -840,7 +840,8 @@ struct efi_load_option {
 };

 struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
-  efi_uintn_t *size, efi_guid_t guid);
+  efi_uintn_t *size,
+  const efi_guid_t *guid);
 struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
  const struct efi_device_path *dp2);
 efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data,
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index cbdb466da4..c3139f8e64 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -1272,7 +1272,8 @@ ssize_t efi_dp_check_length(const struct efi_device_path 
*dp,
  */
 struct
 efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
-   efi_uintn_t *size, efi_guid_t guid)
+   efi_uintn_t *size,
+   const efi_guid_t *guid)
 {
struct efi_device_path *fp = lo->file_path;
struct efi_device_path_vendor *vendor;
@@ -1287,7 +1288,7 @@ efi_device_path *efi_dp_from_lo(struct efi_load_option 
*lo,
continue;

vendor = (struct efi_device_path_vendor *)fp;
-   if (!guidcmp(>guid, ))
+   if (!guidcmp(>guid, guid))
return efi_dp_dup(fp);
}
log_debug("VenMedia(%pUl) not found in %ls\n", , lo->label);
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index d03a736461..4c5b7cd2e1 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -83,7 +83,7 @@ struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t 
guid)
if (ret != EFI_SUCCESS)
goto out;

-   tmp = efi_dp_from_lo(, , guid);
+   tmp = efi_dp_from_lo(, , );
if (!tmp)
goto out;

--
2.30.2



Re: [PATCH v3 7/7] doc: board: apple: Add Apple M1 documentation

2021-10-14 Thread François Ozog
Le jeu. 14 oct. 2021 à 22:44, Simon Glass  a écrit :

> Hi Mark,
>
> On Thu, 14 Oct 2021 at 14:09, Mark Kettenis 
> wrote:
> >
> > > From: Simon Glass 
> > > Date: Mon, 11 Oct 2021 11:01:20 -0600
> > >
> > > Hi Mark,
> > >
> > > On Mon, 11 Oct 2021 at 10:40, Mark Kettenis 
> wrote:
> > > >
> > > > Provide preliminary instructions on how to get U-Boot to run on
> > > > Apple Silicon Macs.
> > > >
> > >
> > > Please can you add a change log to this patch? Patman will do it for
> you.
> >
> > Sorry, I'm confused.  The changelog is on the cover letter.  This
> > particular patch did not change at all...
>
> OK perhaps that is why I am confused too...it is better to have the
> change log on each patch as well.
>
> Regards,
> Simon

hey guys , that’s really a cool thing !

>
> --
François-Frédéric Ozog | *Director Business Development*
T: +33.67221.6485
francois.o...@linaro.org | Skype: ffozog


[PATCH 1/1] cmd: simplify 'efidebug boot add' command

2021-10-14 Thread Heinrich Schuchardt
We can determine the length of the device path in the boot option after it
is created. There is no need to keep track of the length while building
the device path.

Signed-off-by: Heinrich Schuchardt 
---
 cmd/efidebug.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 67ab06aefc..3398f56962 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -964,7 +964,6 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
struct efi_load_option lo;
void *data = NULL;
efi_uintn_t size;
-   efi_uintn_t fp_size = 0;
efi_status_t ret;
int r = CMD_RET_SUCCESS;

@@ -1008,8 +1007,6 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int 
flag,
r = CMD_RET_FAILURE;
goto out;
}
-   fp_size += efi_dp_size(file_path) +
-   sizeof(struct efi_device_path);
argc -= 5;
argv += 5;
} else if (!strcmp(argv[0], "-i")) {
@@ -1026,8 +1023,6 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int 
flag,
}
argc -= 3;
argv += 3;
-   fp_size += efi_dp_size(initrd_dp) +
-   sizeof(struct efi_device_path);
} else if (!strcmp(argv[0], "-s")) {
if (argc < 1 || lo.optional_data) {
r = CMD_RET_USAGE;
@@ -1056,7 +1051,8 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int 
flag,
}

lo.file_path = final_fp;
-   lo.file_path_length = fp_size;
+   lo.file_path_length = efi_dp_size(final_fp) +
+ sizeof(struct efi_device_path);

size = efi_serialize_load_option(, (u8 **));
if (!size) {
--
2.30.2



Re: External dts building

2021-10-14 Thread Giulio Benetti

On 10/14/21 8:22 PM, Tom Rini wrote:

On Thu, Oct 14, 2021 at 08:08:37PM +0200, Giulio Benetti wrote:



Il giorno 14 ott 2021, alle ore 15:45, Tom Rini  ha scritto:

On Thu, Oct 14, 2021 at 02:53:30AM +0200, Giulio Benetti wrote:


Hello All,

is there a way to pass a dts file without touching the 
arch/arm/boot/dts/Makefile?

On Buildroot we support the possibility to pass an external dts by copying it 
to the uboot sources to
be built but since uboot version 2020.01 it doesn’t work anymore.

So I’ve proposed a patch to prepend the dts file in the Makefile above, but 
this has drawbacks, like we reconfigure(it keeps adding files every time).

So I ask you, is there a more canonical way already to achieve this?


Not exactly, and it's something we're very much actively discussing
right now.


Ok, thank you. Is there already a thread about this?


https://lore.kernel.org/u-boot/20211013010120.96851-1-...@chromium.org/
is the start of it.


Thank you

--
Giulio Benetti
Benetti Engineering sas


Re: External dts building

2021-10-14 Thread Giulio Benetti
Hi Simon,

> Il giorno 14 ott 2021, alle ore 22:43, Simon Glass  ha 
> scritto:
> 
> Hi Giulio,
> 
>> On Thu, 14 Oct 2021 at 13:23, Giulio Benetti
>>  wrote:
>> 
>> Hi Simon,
>> 
 Il giorno 14 ott 2021, alle ore 20:24, Simon Glass  ha 
 scritto:
>>> 
>>> Hi,
>>> 
 On Thu, 14 Oct 2021 at 07:46, Tom Rini  wrote:
 
> On Thu, Oct 14, 2021 at 02:53:30AM +0200, Giulio Benetti wrote:
> 
> Hello All,
> 
> is there a way to pass a dts file without touching the 
> arch/arm/boot/dts/Makefile?
> 
> On Buildroot we support the possibility to pass an external dts by 
> copying it to the uboot sources to
> be built but since uboot version 2020.01 it doesn’t work anymore.
> 
> So I’ve proposed a patch to prepend the dts file in the Makefile above, 
> but this has drawbacks, like we reconfigure(it keeps adding files every 
> time).
> 
> So I ask you, is there a more canonical way already to achieve this?
 
 Not exactly, and it's something we're very much actively discussing
 right now.
>>> 
>>> Are you using 'make DEVICE_TREE=xxx' ?
>> 
>> Yes but it doesn’t work if you don’t add an entry into arch/arm/dts/Makefile
>> Before version 2020.01 worked, but not after it.
> 
> What board are you building?

A20-OLinuXino-Lime_defconfig for but without CONFIG_DEFAULT_DEVICE_TREE 
undefined,
so if you try to pass DEVICE_TREE= pointing to an external .dts file copied to 
arch/arm/dts/ make doesn’t find the entry in Makefile and it can’t build it.

This is useful in build systems like Buildroot where you can provide an 
external defconfig as well as an external .dts file.

So here the solution I see is to create an entry in arch/arm/dts/Makefile on 
the top of the file afte copying the .dts file we want to build.
But on Buildroot they’ve pointed me to ask upstream(here) if there’s a more 
canonical way or to work together to achieve the goal:

https://patchwork.ozlabs.org/project/buildroot/patch/20210209201303.195093-1-giulio.bene...@benettiengineering.com/

Sorry if this e-mail is html but I’m on mobile :-/

Best regards
Giulio Benetti

> 
> Regards,
> Simon


Re: [PATCH v2 1/7] iommu: Add IOMMU uclass

2021-10-14 Thread Mark Kettenis
> From: Simon Glass 
> Date: Thu, 14 Oct 2021 14:55:19 -0600
> 
> Hi Mark,
> 
> On Thu, 14 Oct 2021 at 14:51, Mark Kettenis  wrote:
> >
> > > From: Simon Glass 
> > > Date: Thu, 14 Oct 2021 14:20:21 -0600
> > >
> > > Hi Mark,
> > >
> > > On Thu, 14 Oct 2021 at 13:35, Mark Kettenis  
> > > wrote:
> > > >
> > > > > From: Simon Glass 
> > > > > Date: Mon, 11 Oct 2021 11:00:34 -0600
> > > > >
> > > > > Hi Mark,
> > > > >
> > > > > On Sun, 3 Oct 2021 at 12:31, Mark Kettenis  
> > > > > wrote:
> > > > > >
> > > > > > This uclass is intended to manage IOMMUs on systems where the
> > > > > > IOMMUs are not in bypass mode by default.  In that case U-Boot
> > > > > > cannot ignore the IOMMUs if it wants to use devices that need
> > > > > > to do DMA and sit behind such an IOMMU.
> > > > > >
> > > > > > This initial IOMMU uclass implementation does not implement and
> > > > > > device ops and is intended for IOMMUs that have a bypass mode
> > > > > > that does not require address translation.  Support for IOMMUs
> > > > > > that do require address translation is planned and device ops
> > > > > > will be defined when support for such IOMMUs will be added.
> > > > > >
> > > > > > Signed-off-by: Mark Kettenis 
> > > > > > ---
> > > > > >  drivers/Kconfig  |  2 ++
> > > > > >  drivers/Makefile |  1 +
> > > > > >  drivers/core/device.c|  8 +++
> > > > > >  drivers/iommu/Kconfig| 13 +++
> > > > > >  drivers/iommu/Makefile   |  3 +++
> > > > > >  drivers/iommu/iommu-uclass.c | 45 
> > > > > > 
> > > > > >  include/dm/uclass-id.h   |  1 +
> > > > > >  include/iommu.h  | 16 +
> > > > > >  8 files changed, 89 insertions(+)
> > > > > >  create mode 100644 drivers/iommu/Kconfig
> > > > > >  create mode 100644 drivers/iommu/Makefile
> > > > > >  create mode 100644 drivers/iommu/iommu-uclass.c
> > > > > >  create mode 100644 include/iommu.h
> > > > > >
> > > > > > diff --git a/drivers/Kconfig b/drivers/Kconfig
> > > > > > index 417d6f88c2..b26ca8cf70 100644
> > > > > > --- a/drivers/Kconfig
> > > > > > +++ b/drivers/Kconfig
> > > > > > @@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig"
> > > > > >
> > > > > >  source "drivers/input/Kconfig"
> > > > > >
> > > > > > +source "drivers/iommu/Kconfig"
> > > > > > +
> > > > > >  source "drivers/led/Kconfig"
> > > > > >
> > > > > >  source "drivers/mailbox/Kconfig"
> > > > > > diff --git a/drivers/Makefile b/drivers/Makefile
> > > > > > index fd218c9056..166aeb9817 100644
> > > > > > --- a/drivers/Makefile
> > > > > > +++ b/drivers/Makefile
> > > > > > @@ -109,6 +109,7 @@ obj-y += mtd/
> > > > > >  obj-y += pwm/
> > > > > >  obj-y += reset/
> > > > > >  obj-y += input/
> > > > > > +obj-y += iommu/
> > > > > >  # SOC specific infrastructure drivers.
> > > > > >  obj-y += smem/
> > > > > >  obj-y += thermal/
> > > > > > diff --git a/drivers/core/device.c b/drivers/core/device.c
> > > > > > index 29668f6fb3..5f480ad443 100644
> > > > > > --- a/drivers/core/device.c
> > > > > > +++ b/drivers/core/device.c
> > > > > > @@ -28,6 +28,7 @@
> > > > > >  #include 
> > > > > >  #include 
> > > > > >  #include 
> > > > > > +#include 
> > > > > >  #include 
> > > > > >  #include 
> > > > > >  #include 
> > > > > > @@ -543,6 +544,13 @@ int device_probe(struct udevice *dev)
> > > > > > goto fail;
> > > > > > }
> > > > > >
> > > > > > +   if (CONFIG_IS_ENABLED(IOMMU) && dev->parent &&
> > > > > > +   (device_get_uclass_id(dev) != UCLASS_IOMMU)) {
> > > > > > +   ret = dev_iommu_probe(dev);
> > > > > > +   if (ret)
> > > > > > +   goto fail;
> > > > > > +   }
> > > > > > +
> > > > > > ret = device_get_dma_constraints(dev);
> > > > > > if (ret)
> > > > > > goto fail;
> > > > > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> > > > > > new file mode 100644
> > > > > > index 00..8cb377560e
> > > > > > --- /dev/null
> > > > > > +++ b/drivers/iommu/Kconfig
> > > > > > @@ -0,0 +1,13 @@
> > > > > > +#
> > > > > > +# IOMMU devices
> > > > > > +#
> > > > > > +
> > > > > > +menu "IOMMU device drivers"
> > > > > > +
> > > > > > +config IOMMU
> > > > > > +   bool "Enable Driver Model for IOMMU drivers"
> > > > > > +   depends on DM
> > > > > > +   help
> > > > > > + Enable driver model for IOMMU devices.
> > > > >
> > > > > Need at least three lines. What is an IOMMU? How does it relate to
> > > > > other devices?
> > > >
> > > > Not sure if I can describe what an IOMMU is in just a few lines, but
> > > > I'll try.
> > > >
> > > > > > +
> > > > > > +endmenu
> > > > > > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> > > > > > new file mode 100644
> > > > > > index 00..f1ceb10150
> > > > > > --- /dev/null
> > > > > > +++ b/drivers/iommu/Makefile
> > > > > > @@ -0,0 +1,3 @@
> > > > > > +# SPDX-License-Identifier: 

Re: [PATCH 00/16] fdt: Make OF_BOARD a boolean option

2021-10-14 Thread Simon Glass
Hi François,

On Thu, 14 Oct 2021 at 12:13, François Ozog  wrote:
>
>
>
> Le mer. 13 oct. 2021 à 20:06, Simon Glass  a écrit :
>>
>> Hi François,
>>
>> On Wed, 13 Oct 2021 at 11:35, François Ozog  wrote:
>> >
>> > Hi Simon
>> >
>> > Le mer. 13 oct. 2021 à 16:49, Simon Glass  a écrit :
>> >>
>> >> Hi Tom, Bin,François,
>> >>
>> >> On Tue, 12 Oct 2021 at 19:34, Tom Rini  wrote:
>> >> >
>> >> > On Wed, Oct 13, 2021 at 09:29:14AM +0800, Bin Meng wrote:
>> >> > > Hi Simon,
>> >> > >
>> >> > > On Wed, Oct 13, 2021 at 9:01 AM Simon Glass  wrote:
>> >> > > >
>> >> > > > With Ilias' efforts we have dropped OF_PRIOR_STAGE and OF_HOSTFILE 
>> >> > > > so
>> >> > > > there are only three ways to obtain a devicetree:
>> >> > > >
>> >> > > >- OF_SEPARATE - the normal way, where the devicetree is built and
>> >> > > >   appended to U-Boot
>> >> > > >- OF_EMBED - for development purposes, the devicetree is 
>> >> > > > embedded in
>> >> > > >   the ELF file (also used for EFI)
>> >> > > >- OF_BOARD - the board figures it out on its own
>> >> > > >
>> >> > > > The last one is currently set up so that no devicetree is needed at 
>> >> > > > all
>> >> > > > in the U-Boot tree. Most boards do provide one, but some don't. Some
>> >> > > > don't even provide instructions on how to boot on the board.
>> >> > > >
>> >> > > > The problems with this approach are documented at [1].
>> >> > > >
>> >> > > > In practice, OF_BOARD is not really distinct from OF_SEPARATE. Any 
>> >> > > > board
>> >> > > > can obtain its devicetree at runtime, even it is has a devicetree 
>> >> > > > built
>> >> > > > in U-Boot. This is because U-Boot may be a second-stage bootloader 
>> >> > > > and its
>> >> > > > caller may have a better idea about the hardware available in the 
>> >> > > > machine.
>> >> > > > This is the case with a few QEMU boards, for example.
>> >> > > >
>> >> > > > So it makes no sense to have OF_BOARD as a 'choice'. It should be an
>> >> > > > option, available with either OF_SEPARATE or OF_EMBED.
>> >> > > >
>> >> > > > This series makes this change, adding various missing devicetree 
>> >> > > > files
>> >> > > > (and placeholders) to make the build work.
>> >> > >
>> >> > > Adding device trees that are never used sounds like a hack to me.
>> >> > >
>> >> > > For QEMU, device tree is dynamically generated on the fly based on
>> >> > > command line parameters, and the device tree you put in this series
>> >> > > has various hardcoded  values which normally do not show up
>> >> > > in hand-written dts files.
>> >> > >
>> >> > > I am not sure I understand the whole point of this.
>> >> >
>> >> > I am also confused and do not like the idea of adding device trees for
>> >> > platforms that are capable of and can / do have a device tree to give us
>> >> > at run time.
>> >>
>> >> (I'll just reply to this one email, since the same points applies to
>> >> all replies I think)
>> >>
>> >> I have been thinking about this and discussing it with people for a
>> >> few months now. I've been signalling a change like this for over a
>> >> month now, on U-Boot contributor calls and in discussions with Linaro
>> >> people. I sent a patch (below) to try to explain things. I hope it is
>> >> not a surprise!
>> >>
>> >> The issue here is that we need a devicetree in-tree in U-Boot, to
>> >> avoid the mess that has been created by OF_PRIOR_STAGE, OF_BOARD,
>> >> BINMAN_STANDALONE_FDT and to a lesser extent, OF_HOSTFILE. Between
>> >> Ilias' series and this one we can get ourselves on a stronger footing.
>> >> There is just OF_SEPARATE, with OF_EMBED for debugging/ELF use.
>> >> For more context:
>> >>
>> >> http://patchwork.ozlabs.org/project/uboot/patch/20210919215111.3830278-3-...@chromium.org/
>> >>
>> >> BTW I did suggest to QEMU ARM that they support a way of adding the
>> >> u-boot.dtsi but there was not much interest there (in fact the
>> >> maintainer would prefer there was no special support even for booting
>> >> Linux directly!)
>> >
>> > i understand their point of view and agree with it.
>> >>
>> >> But in any case it doesn't really help U-Boot. I
>> >> think the path forward might be to run QEMU twice, once to get its
>> >> generated tree and once to give the 'merged' tree with the U-Boot
>> >> properties in it, if people want to use U-Boot features.
>> >>
>> >> I do strongly believe that OF_BOARD must be a run-time option, not a
>> >> build-time one. It creates all sorts of problems and obscurity which
>> >> have taken months to unpick. See the above patch for the rationale.
>> >>
>> >> To add to that rationale, OF_BOARD needs to be an option available to
>> >> any board. At some point in the future it may become a common way
>> >> things are done, e.g. TF-A calling U-Boot and providing a devicetree
>> >> to it. It doesn't make any sense to have people decide whether or not
>> >> to set OF_BOARD at build time, thus affecting how the image is put
>> >> together. We'll end up with different U-Boot build targets 

Re: [RFC 07/22] dm: blk: add UCLASS_PARTITION

2021-10-14 Thread Simon Glass
Hi Takahiro,

On Thu, 14 Oct 2021 at 02:03, AKASHI Takahiro
 wrote:
>
> Simon,
>
> On Wed, Oct 13, 2021 at 12:05:58PM -0600, Simon Glass wrote:
> > Hi Takahiro,
> >
> > On Tue, 12 Oct 2021 at 19:32, AKASHI Takahiro
> >  wrote:
> > >
> > > On Tue, Oct 12, 2021 at 11:14:17AM -0400, Tom Rini wrote:
> > > > On Mon, Oct 11, 2021 at 10:14:00AM -0600, Simon Glass wrote:
> > > > > Hi Heinrich,
> > > > >
> > > > > On Mon, 11 Oct 2021 at 09:02, Heinrich Schuchardt 
> > > > >  wrote:
> > > > > >
> > > > > >
> > > > > >
> > > > > > On 10/11/21 16:54, Simon Glass wrote:
> > > > > > > Hi Takahiro,
> > > > > > >
> > > > > > > On Sun, 10 Oct 2021 at 20:29, AKASHI Takahiro
> > > > > > >  wrote:
> > > > > > >>
> > > > > > >> Heinrich,
> > > > > > >>
> > > > > > >> On Fri, Oct 08, 2021 at 10:23:52AM +0200, Heinrich Schuchardt 
> > > > > > >> wrote:
> > > > > > >>>
> > > > > > >>>
> > > > > > >>> On 10/8/21 02:51, AKASHI Takahiro wrote:
> > > > > >  On Mon, Oct 04, 2021 at 12:27:59PM +0900, AKASHI Takahiro 
> > > > > >  wrote:
> > > > > > > On Fri, Oct 01, 2021 at 11:30:37AM +0200, Heinrich Schuchardt 
> > > > > > > wrote:
> > > > > > >>
> > > > > > >>
> > > > > > >> On 10/1/21 07:01, AKASHI Takahiro wrote:
> > > > > > >>> UCLASS_PARTITION device will be created as a child node of
> > > > > > >>> UCLASS_BLK device.
> > > > > > >>>
> > > > > > >>> Signed-off-by: AKASHI Takahiro 
> > > > > > >>> ---
> > > > > > >>> drivers/block/blk-uclass.c | 111 
> > > > > > >>> +
> > > > > > >>> include/blk.h  |   9 +++
> > > > > > >>> include/dm/uclass-id.h |   1 +
> > > > > > >>> 3 files changed, 121 insertions(+)
> > > > > > >>>
> > > > > > >>> diff --git a/drivers/block/blk-uclass.c 
> > > > > > >>> b/drivers/block/blk-uclass.c
> > > > > > >>> index 83682dcc181a..dd7f3c0fe31e 100644
> > > > > > >>> --- a/drivers/block/blk-uclass.c
> > > > > > >>> +++ b/drivers/block/blk-uclass.c
> > > > > > >>> @@ -12,6 +12,7 @@
> > > > > > >>> #include 
> > > > > > >>> #include 
> > > > > > >>> #include 
> > > > > > >>> +#include 
> > > > > > >>> #include 
> > > > > > >>> #include 
> > > > > > >>> #include 
> > > > > > >>> @@ -695,6 +696,44 @@ int blk_unbind_all(int if_type)
> > > > > > >>>return 0;
> > > > > > >>> }
> > > > > > >>>
> > > > > > >>> +int blk_create_partitions(struct udevice *parent)
> > > > > > >>> +{
> > > > > > >>> + int part, count;
> > > > > > >>> + struct blk_desc *desc = dev_get_uclass_plat(parent);
> > > > > > >>> + struct disk_partition info;
> > > > > > >>> + struct disk_part *part_data;
> > > > > > >>> + char devname[32];
> > > > > > >>> + struct udevice *dev;
> > > > > > >>> + int ret;
> > > > > > >>> +
> > > > > > >>> + if (!CONFIG_IS_ENABLED(PARTITIONS) ||
> > > > > > >>> + !CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE))
> > > > > > >>> + return 0;
> > > > > > >>> +
> > > > > > >>> + /* Add devices for each partition */
> > > > > > >>> + for (count = 0, part = 1; part <= 
> > > > > > >>> MAX_SEARCH_PARTITIONS; part++) {
> > > > > > >>> + if (part_get_info(desc, part, ))
> > > > > > >>> + continue;
> > > > > > >>> + snprintf(devname, sizeof(devname), "%s:%d", 
> > > > > > >>> parent->name,
> > > > > > >>> +  part);
> > > > > > >>> +
> > > > > > >>> + ret = device_bind_driver(parent, 
> > > > > > >>> "blk_partition",
> > > > > > >>> +  strdup(devname), 
> > > > > > >>> );
> > > > > > >>> + if (ret)
> > > > > > >>> + return ret;
> > > > > > >>> +
> > > > > > >>> + part_data = dev_get_uclass_plat(dev);
> > > > > > >>> + part_data->partnum = part;
> > > > > > >>> + part_data->gpt_part_info = info;
> > > > > > >>> + count++;
> > > > > > >>> +
> > > > > > >>> + device_probe(dev);
> > > > > > >>> + }
> > > > > > >>> + debug("%s: %d partitions found in %s\n", __func__, 
> > > > > > >>> count, parent->name);
> > > > > > >>> +
> > > > > > >>> + return 0;
> > > > > > >>> +}
> > > > > > >>> +
> > > > > > >>> static int blk_post_probe(struct udevice *dev)
> > > > > > >>> {
> > > > > > >>>if (IS_ENABLED(CONFIG_PARTITIONS) &&
> > > > > > >>> @@ -713,3 +752,75 @@ UCLASS_DRIVER(blk) = {
> > > > > > >>>.post_probe = blk_post_probe,
> > > > > > >>>.per_device_plat_auto   = sizeof(struct blk_desc),
> > > > > > >>> };
> > > > > > >>> +
> > > > > > >>> +static ulong blk_part_read(struct udevice *dev, 

Re: [PATCH v2 1/7] iommu: Add IOMMU uclass

2021-10-14 Thread Simon Glass
Hi Mark,

On Thu, 14 Oct 2021 at 14:51, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Thu, 14 Oct 2021 14:20:21 -0600
> >
> > Hi Mark,
> >
> > On Thu, 14 Oct 2021 at 13:35, Mark Kettenis  wrote:
> > >
> > > > From: Simon Glass 
> > > > Date: Mon, 11 Oct 2021 11:00:34 -0600
> > > >
> > > > Hi Mark,
> > > >
> > > > On Sun, 3 Oct 2021 at 12:31, Mark Kettenis  wrote:
> > > > >
> > > > > This uclass is intended to manage IOMMUs on systems where the
> > > > > IOMMUs are not in bypass mode by default.  In that case U-Boot
> > > > > cannot ignore the IOMMUs if it wants to use devices that need
> > > > > to do DMA and sit behind such an IOMMU.
> > > > >
> > > > > This initial IOMMU uclass implementation does not implement and
> > > > > device ops and is intended for IOMMUs that have a bypass mode
> > > > > that does not require address translation.  Support for IOMMUs
> > > > > that do require address translation is planned and device ops
> > > > > will be defined when support for such IOMMUs will be added.
> > > > >
> > > > > Signed-off-by: Mark Kettenis 
> > > > > ---
> > > > >  drivers/Kconfig  |  2 ++
> > > > >  drivers/Makefile |  1 +
> > > > >  drivers/core/device.c|  8 +++
> > > > >  drivers/iommu/Kconfig| 13 +++
> > > > >  drivers/iommu/Makefile   |  3 +++
> > > > >  drivers/iommu/iommu-uclass.c | 45 
> > > > > 
> > > > >  include/dm/uclass-id.h   |  1 +
> > > > >  include/iommu.h  | 16 +
> > > > >  8 files changed, 89 insertions(+)
> > > > >  create mode 100644 drivers/iommu/Kconfig
> > > > >  create mode 100644 drivers/iommu/Makefile
> > > > >  create mode 100644 drivers/iommu/iommu-uclass.c
> > > > >  create mode 100644 include/iommu.h
> > > > >
> > > > > diff --git a/drivers/Kconfig b/drivers/Kconfig
> > > > > index 417d6f88c2..b26ca8cf70 100644
> > > > > --- a/drivers/Kconfig
> > > > > +++ b/drivers/Kconfig
> > > > > @@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig"
> > > > >
> > > > >  source "drivers/input/Kconfig"
> > > > >
> > > > > +source "drivers/iommu/Kconfig"
> > > > > +
> > > > >  source "drivers/led/Kconfig"
> > > > >
> > > > >  source "drivers/mailbox/Kconfig"
> > > > > diff --git a/drivers/Makefile b/drivers/Makefile
> > > > > index fd218c9056..166aeb9817 100644
> > > > > --- a/drivers/Makefile
> > > > > +++ b/drivers/Makefile
> > > > > @@ -109,6 +109,7 @@ obj-y += mtd/
> > > > >  obj-y += pwm/
> > > > >  obj-y += reset/
> > > > >  obj-y += input/
> > > > > +obj-y += iommu/
> > > > >  # SOC specific infrastructure drivers.
> > > > >  obj-y += smem/
> > > > >  obj-y += thermal/
> > > > > diff --git a/drivers/core/device.c b/drivers/core/device.c
> > > > > index 29668f6fb3..5f480ad443 100644
> > > > > --- a/drivers/core/device.c
> > > > > +++ b/drivers/core/device.c
> > > > > @@ -28,6 +28,7 @@
> > > > >  #include 
> > > > >  #include 
> > > > >  #include 
> > > > > +#include 
> > > > >  #include 
> > > > >  #include 
> > > > >  #include 
> > > > > @@ -543,6 +544,13 @@ int device_probe(struct udevice *dev)
> > > > > goto fail;
> > > > > }
> > > > >
> > > > > +   if (CONFIG_IS_ENABLED(IOMMU) && dev->parent &&
> > > > > +   (device_get_uclass_id(dev) != UCLASS_IOMMU)) {
> > > > > +   ret = dev_iommu_probe(dev);
> > > > > +   if (ret)
> > > > > +   goto fail;
> > > > > +   }
> > > > > +
> > > > > ret = device_get_dma_constraints(dev);
> > > > > if (ret)
> > > > > goto fail;
> > > > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> > > > > new file mode 100644
> > > > > index 00..8cb377560e
> > > > > --- /dev/null
> > > > > +++ b/drivers/iommu/Kconfig
> > > > > @@ -0,0 +1,13 @@
> > > > > +#
> > > > > +# IOMMU devices
> > > > > +#
> > > > > +
> > > > > +menu "IOMMU device drivers"
> > > > > +
> > > > > +config IOMMU
> > > > > +   bool "Enable Driver Model for IOMMU drivers"
> > > > > +   depends on DM
> > > > > +   help
> > > > > + Enable driver model for IOMMU devices.
> > > >
> > > > Need at least three lines. What is an IOMMU? How does it relate to
> > > > other devices?
> > >
> > > Not sure if I can describe what an IOMMU is in just a few lines, but
> > > I'll try.
> > >
> > > > > +
> > > > > +endmenu
> > > > > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> > > > > new file mode 100644
> > > > > index 00..f1ceb10150
> > > > > --- /dev/null
> > > > > +++ b/drivers/iommu/Makefile
> > > > > @@ -0,0 +1,3 @@
> > > > > +# SPDX-License-Identifier: GPL-2.0+
> > > > > +
> > > > > +obj-$(CONFIG_IOMMU) += iommu-uclass.o
> > > > > diff --git a/drivers/iommu/iommu-uclass.c 
> > > > > b/drivers/iommu/iommu-uclass.c
> > > > > new file mode 100644
> > > > > index 00..5c55df3066
> > > > > --- /dev/null
> > > > > +++ b/drivers/iommu/iommu-uclass.c
> > > > > @@ -0,0 +1,45 @@
> > > > > +// 

Re: [PATCH v2 1/7] iommu: Add IOMMU uclass

2021-10-14 Thread Mark Kettenis
> From: Simon Glass 
> Date: Thu, 14 Oct 2021 14:20:21 -0600
> 
> Hi Mark,
> 
> On Thu, 14 Oct 2021 at 13:35, Mark Kettenis  wrote:
> >
> > > From: Simon Glass 
> > > Date: Mon, 11 Oct 2021 11:00:34 -0600
> > >
> > > Hi Mark,
> > >
> > > On Sun, 3 Oct 2021 at 12:31, Mark Kettenis  wrote:
> > > >
> > > > This uclass is intended to manage IOMMUs on systems where the
> > > > IOMMUs are not in bypass mode by default.  In that case U-Boot
> > > > cannot ignore the IOMMUs if it wants to use devices that need
> > > > to do DMA and sit behind such an IOMMU.
> > > >
> > > > This initial IOMMU uclass implementation does not implement and
> > > > device ops and is intended for IOMMUs that have a bypass mode
> > > > that does not require address translation.  Support for IOMMUs
> > > > that do require address translation is planned and device ops
> > > > will be defined when support for such IOMMUs will be added.
> > > >
> > > > Signed-off-by: Mark Kettenis 
> > > > ---
> > > >  drivers/Kconfig  |  2 ++
> > > >  drivers/Makefile |  1 +
> > > >  drivers/core/device.c|  8 +++
> > > >  drivers/iommu/Kconfig| 13 +++
> > > >  drivers/iommu/Makefile   |  3 +++
> > > >  drivers/iommu/iommu-uclass.c | 45 
> > > >  include/dm/uclass-id.h   |  1 +
> > > >  include/iommu.h  | 16 +
> > > >  8 files changed, 89 insertions(+)
> > > >  create mode 100644 drivers/iommu/Kconfig
> > > >  create mode 100644 drivers/iommu/Makefile
> > > >  create mode 100644 drivers/iommu/iommu-uclass.c
> > > >  create mode 100644 include/iommu.h
> > > >
> > > > diff --git a/drivers/Kconfig b/drivers/Kconfig
> > > > index 417d6f88c2..b26ca8cf70 100644
> > > > --- a/drivers/Kconfig
> > > > +++ b/drivers/Kconfig
> > > > @@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig"
> > > >
> > > >  source "drivers/input/Kconfig"
> > > >
> > > > +source "drivers/iommu/Kconfig"
> > > > +
> > > >  source "drivers/led/Kconfig"
> > > >
> > > >  source "drivers/mailbox/Kconfig"
> > > > diff --git a/drivers/Makefile b/drivers/Makefile
> > > > index fd218c9056..166aeb9817 100644
> > > > --- a/drivers/Makefile
> > > > +++ b/drivers/Makefile
> > > > @@ -109,6 +109,7 @@ obj-y += mtd/
> > > >  obj-y += pwm/
> > > >  obj-y += reset/
> > > >  obj-y += input/
> > > > +obj-y += iommu/
> > > >  # SOC specific infrastructure drivers.
> > > >  obj-y += smem/
> > > >  obj-y += thermal/
> > > > diff --git a/drivers/core/device.c b/drivers/core/device.c
> > > > index 29668f6fb3..5f480ad443 100644
> > > > --- a/drivers/core/device.c
> > > > +++ b/drivers/core/device.c
> > > > @@ -28,6 +28,7 @@
> > > >  #include 
> > > >  #include 
> > > >  #include 
> > > > +#include 
> > > >  #include 
> > > >  #include 
> > > >  #include 
> > > > @@ -543,6 +544,13 @@ int device_probe(struct udevice *dev)
> > > > goto fail;
> > > > }
> > > >
> > > > +   if (CONFIG_IS_ENABLED(IOMMU) && dev->parent &&
> > > > +   (device_get_uclass_id(dev) != UCLASS_IOMMU)) {
> > > > +   ret = dev_iommu_probe(dev);
> > > > +   if (ret)
> > > > +   goto fail;
> > > > +   }
> > > > +
> > > > ret = device_get_dma_constraints(dev);
> > > > if (ret)
> > > > goto fail;
> > > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> > > > new file mode 100644
> > > > index 00..8cb377560e
> > > > --- /dev/null
> > > > +++ b/drivers/iommu/Kconfig
> > > > @@ -0,0 +1,13 @@
> > > > +#
> > > > +# IOMMU devices
> > > > +#
> > > > +
> > > > +menu "IOMMU device drivers"
> > > > +
> > > > +config IOMMU
> > > > +   bool "Enable Driver Model for IOMMU drivers"
> > > > +   depends on DM
> > > > +   help
> > > > + Enable driver model for IOMMU devices.
> > >
> > > Need at least three lines. What is an IOMMU? How does it relate to
> > > other devices?
> >
> > Not sure if I can describe what an IOMMU is in just a few lines, but
> > I'll try.
> >
> > > > +
> > > > +endmenu
> > > > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> > > > new file mode 100644
> > > > index 00..f1ceb10150
> > > > --- /dev/null
> > > > +++ b/drivers/iommu/Makefile
> > > > @@ -0,0 +1,3 @@
> > > > +# SPDX-License-Identifier: GPL-2.0+
> > > > +
> > > > +obj-$(CONFIG_IOMMU) += iommu-uclass.o
> > > > diff --git a/drivers/iommu/iommu-uclass.c b/drivers/iommu/iommu-uclass.c
> > > > new file mode 100644
> > > > index 00..5c55df3066
> > > > --- /dev/null
> > > > +++ b/drivers/iommu/iommu-uclass.c
> > > > @@ -0,0 +1,45 @@
> > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > +/*
> > > > + * Copyright (C) 2021 Mark Kettenis 
> > > > + */
> > > > +
> > > > +#define LOG_CATEGORY UCLASS_IOMMU
> > > > +
> > > > +#include 
> > > > +#include 
> > > > +
> > > > +#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA))
> > > > +int dev_iommu_probe(struct udevice *dev)
> > >
> > 

Re: [PATCH v3 7/7] doc: board: apple: Add Apple M1 documentation

2021-10-14 Thread Simon Glass
Hi Mark,

On Thu, 14 Oct 2021 at 14:09, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Mon, 11 Oct 2021 11:01:20 -0600
> >
> > Hi Mark,
> >
> > On Mon, 11 Oct 2021 at 10:40, Mark Kettenis  wrote:
> > >
> > > Provide preliminary instructions on how to get U-Boot to run on
> > > Apple Silicon Macs.
> > >
> >
> > Please can you add a change log to this patch? Patman will do it for you.
>
> Sorry, I'm confused.  The changelog is on the cover letter.  This
> particular patch did not change at all...

OK perhaps that is why I am confused too...it is better to have the
change log on each patch as well.

Regards,
Simon


Re: [PATCH v3 7/7] doc: board: apple: Add Apple M1 documentation

2021-10-14 Thread Simon Glass
Hi Mark,

On Thu, 14 Oct 2021 at 14:15, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Mon, 11 Oct 2021 13:10:02 -0600
> >
> > Hi Mark,
> >
> > On Mon, 11 Oct 2021 at 10:40, Mark Kettenis  wrote:
> > >
> > > Provide preliminary instructions on how to get U-Boot to run on
> > > Apple Silicon Macs.
> >
> > Apple-Silicon
> >
> > This is ambiguous. The Macs are not made out of silicon. It is a Mac
> > using Apple Silicon.
>
> Well, this is the marketing term that tends to be used to distinguish
> them from the Macs with an Intel CPU in them.  It doesn't have to make
> sense ;).
>
> >
> > >
> > > Signed-off-by: Mark Kettenis 
> > > ---
> > >  doc/board/apple/index.rst |  9 +++
> > >  doc/board/apple/m1.rst| 56 +++
> > >  doc/board/index.rst   |  1 +
> > >  3 files changed, 66 insertions(+)
> > >  create mode 100644 doc/board/apple/index.rst
> > >  create mode 100644 doc/board/apple/m1.rst
> > >
> > > diff --git a/doc/board/apple/index.rst b/doc/board/apple/index.rst
> > > new file mode 100644
> > > index 00..8446847818
> > > --- /dev/null
> > > +++ b/doc/board/apple/index.rst
> > > @@ -0,0 +1,9 @@
> > > +.. SPDX-License-Identifier: GPL-2.0+
> > > +
> > > +Apple
> > > +=
> > > +
> > > +.. toctree::
> > > +   :maxdepth: 2
> > > +
> > > +   m1
> > > diff --git a/doc/board/apple/m1.rst b/doc/board/apple/m1.rst
> > > new file mode 100644
> > > index 00..2f2d940a4c
> > > --- /dev/null
> > > +++ b/doc/board/apple/m1.rst
> > > @@ -0,0 +1,56 @@
> > > +.. SPDX-License-Identifier: GPL-2.0+
> > > +
> > > +U-Boot for Apple Silicon Macs
> >
> > Apple-Silicon
> >
> > > +=
> > > +
> > > +Allows Apple Silicon Macs to boot U-Boot via the m1n1 bootloader
> >
> > Apple-Silicon
> >
> > > +developed by the Asahi Linux project.  At this point the machines with
> > > +the following SoCs work:
> > > +
> > > + - Apple M1 SoC
> > > +
> > > +On these SoCs the following hardware is supported:
> > > +
> > > + - S5L serial port
> > > + - Framebuffer
> > > + - USB 3.1 Type-C ports
> > > +
> > > +Device trees are currently provided for the M1 Mac mini (2020, J274)
> > > +and M1 MacBook Pro 13" (2020, J293).  The M1 MacBook Air (2020) is
> > > +expected to work with the J293 device tree.  The M1 iMac (2021) may
> >
> > Tested on MacBook Air 2020 A2337
> > Tested-by: Simon Glass 
> >
> > > +work with the J274 device tree.
> > > +
> > > +Building U-Boot
> > > +---
> > > +
> > > +.. code-block:: bash
> > > +
> > > +$ export CROSS_COMPILE=aarch64-none-elf-
> > > +$ make apple_m1_defconfig
> > > +$ make
> > > +
> > > +This will build ``u-boot-nodtb.bin`` as well as devices trees for some
> > > +of the supported machines.  These device trees can be found in the
> > > +``arch/arm/dts`` subdirectory of your build.
> > > +
> > > +Image creation
> > > +--
> > > +
> > > +In order to run U-Boot on an Apple Silicon Mac, U-Boot has to be used
> > > +as a payload for the m1n1 bootloader.  Instructions for building m1n1
> > > +can be found here:
> > > +
> > > +https://github.com/AsahiLinux/docs/wiki/SW%3Am1n1
> > > +
> > > +.. code-block:: bash
> > > +
> > > +$ cat m1n1.macho t8103-j274.dtb u-boot-nodtb.bin > u-boot.macho
> >
> > or just u-boot.bin which is more normal
>
> But that one has the DTB baked in, so it makes no sense to use it in
> this context as the DTB is provided separately.

Yes, that's true. Please add a note explaining that.

Regards,
Simon


Re: [PATCH v2 2/7] test: Add tests for IOMMU uclass

2021-10-14 Thread Simon Glass
Hi Mark,

On Thu, 14 Oct 2021 at 13:51, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Mon, 11 Oct 2021 11:00:36 -0600
> >
> > On Sun, 3 Oct 2021 at 12:31, Mark Kettenis  wrote:
> > >
> > > Add a set of tests for the IOMMU uclass.
> > >
> > > Signed-off-by: Mark Kettenis 
> > > ---
> > >  arch/sandbox/dts/test.dts  |  6 ++
> > >  configs/sandbox64_defconfig|  1 +
> > >  configs/sandbox_defconfig  |  1 +
> > >  configs/sandbox_flattree_defconfig |  1 +
> > >  configs/sandbox_noinst_defconfig   |  1 +
> > >  configs/sandbox_spl_defconfig  |  1 +
> > >  drivers/iommu/Makefile |  2 ++
> > >  drivers/iommu/sandbox_iommu.c  | 18 ++
> > >  test/dm/Makefile   |  1 +
> > >  test/dm/iommu.c| 28 
> > >  10 files changed, 60 insertions(+)
> > >  create mode 100644 drivers/iommu/sandbox_iommu.c
> > >  create mode 100644 test/dm/iommu.c
> > >
> >
> > Reviewed-by: Simon Glass 
> >
> > You could add the CONFIG options to sandbox's Kconfig in arch/Kconfig
>
> The codebase is a bit inconsistent in that respect isn't it?

Do you mean sometimes it is in defconfig and sometimes in Kconfig? Yes.

For the sandbox board, we try to enable everything
For the other boards that use the sandbox arch, we have to enable what
is needed to run tests, but not necessarily every feature

Regards,
Simon


Re: External dts building

2021-10-14 Thread Simon Glass
Hi Giulio,

On Thu, 14 Oct 2021 at 13:23, Giulio Benetti
 wrote:
>
> Hi Simon,
>
> > Il giorno 14 ott 2021, alle ore 20:24, Simon Glass  ha 
> > scritto:
> >
> > Hi,
> >
> >> On Thu, 14 Oct 2021 at 07:46, Tom Rini  wrote:
> >>
> >>> On Thu, Oct 14, 2021 at 02:53:30AM +0200, Giulio Benetti wrote:
> >>>
> >>> Hello All,
> >>>
> >>> is there a way to pass a dts file without touching the 
> >>> arch/arm/boot/dts/Makefile?
> >>>
> >>> On Buildroot we support the possibility to pass an external dts by 
> >>> copying it to the uboot sources to
> >>> be built but since uboot version 2020.01 it doesn’t work anymore.
> >>>
> >>> So I’ve proposed a patch to prepend the dts file in the Makefile above, 
> >>> but this has drawbacks, like we reconfigure(it keeps adding files every 
> >>> time).
> >>>
> >>> So I ask you, is there a more canonical way already to achieve this?
> >>
> >> Not exactly, and it's something we're very much actively discussing
> >> right now.
> >
> > Are you using 'make DEVICE_TREE=xxx' ?
>
> Yes but it doesn’t work if you don’t add an entry into arch/arm/dts/Makefile
> Before version 2020.01 worked, but not after it.

What board are you building?

Regards,
Simon


Re: [PATCH v2 6/7] arm: dts: apple: Add preliminary device trees

2021-10-14 Thread Mark Kettenis
> From: Rob Herring 
> Date: Mon, 11 Oct 2021 14:48:46 -0500

Hi Rob,

Trimming the CC list a bit and adding marcan.

> On Mon, Oct 11, 2021 at 2:00 PM Mark Kettenis  wrote:
> >
> > > From: Rob Herring 
> > > Date: Mon, 11 Oct 2021 13:36:29 -0500
> >
> > Hi Rob,
> >
> > > On Sun, Oct 3, 2021 at 1:35 PM Mark Kettenis  wrote:
> > > >
> > > > Add preliminary device trees for the Apple M1 mini (2020) and
> > > > Apple M1 Macbook Pro 13" (2020).  Device tree bindings for
> > > > the Apple M1 SoC are still being formalized and these device
> > > > trees will be synchronized with the Linux kernel as needed.
> > >
> > > So not synchronized currently? If it is sync'ed, you should specify
> > > which version you got.
> >
> > Not synched at the moment.  It is based on what was in 5.13 or 5.14,
> > but with lots of stuff added so specifying a version would be
> > misleading.  It should be mostly aligned with the bindings that are
> > making their way into 5.15 or 5.16 though.
> 
> This and what's added or preliminary would be good to have in the commit msg.

Sure.  I added that information to the commit message for v4.

> > Hopefully now that the power domains are getting addressed we'll have
> > something that can be synchronized soon.  I was explicitly encouraged
> > to start upstreaming the U-Boot code even though not all the DT
> > bindings had been sorted out.
> 
> In general, sounds like a recipe for getting out of sync and bindings
> never getting documented properly without any checks in place. The
> good news is checking that is at least possible now.
> 
> > > > These device trees are provided as a reference only as U-Boot
> > > > uses the device tree passed by the m1n1 bootloader.
> > >
> > > If reference only, why do they need to be checked in here? We're
> > > trying to get to fewer copies both of dtbs at runtime and dts files in
> > > source trees.
> >
> > The U-Boot maintainers insist there is a DT for each supported system
> > in the U-Boot tree.
> 
> Ok, fair enough.
> 
> > > I mainly bring it up here because this is a platform with multiple OS
> > > targets, following the model that DT comes from the firmware, and
> > > should be free of schema validation warnings. In other words, it's a
> > > good candidate to define best practices.
> >
> > You're preaching to the choir ;).
> 
> Good.
> 
> > Must admit that it is somewhat convenient for me to have a somewhat
> > complete DT for these devices at the moment.  But in the long run I
> > think it will just confuse people.  That said, I plan to be aggressive
> > in keeping the U-Boot tree synchronized with Linux.
> 
> What I'd like to see here is some sort of automatic synchronization.
> The idea I have here is just a list of boards to sync from the kernel
> tree to wherever. The requirement to get on the list would be passing
> schema validation and would be a declaration of stability (there's
> been numerous discussions over the years of how to declare a DT stable
> or unstable). It would perhaps also include passing validation on an
> older schema. I'm not sure how well that would catch compatibility
> issues, but that's the only idea I've come up with besides just
> testing of mixed versions. I'm happy to do the tooling to support that
> if we have a board/device to put in the list and u-boot folks agree to
> use it. I suppose even if just m1n1 used it to start with, I'd be
> willing to do the tooling.

Sounds interesting.

One of the things we would want to do a ship device trees for new
models with m1n1 as soon as we get our hands on the hardware such that
the they can be used with existing distro kernels as soon as possible.
Under the assumption that the new hardware is compatible with the old
of course.  That means those new device trees should pass validation.

But as soon as the device tree for a model is available in the Linux
tree, we probably want to be rather strict in synching it to m1n1.

Thanks,

Mark


Re: [PATCH v2 1/7] iommu: Add IOMMU uclass

2021-10-14 Thread Simon Glass
Hi Mark,

On Thu, 14 Oct 2021 at 13:35, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Mon, 11 Oct 2021 11:00:34 -0600
> >
> > Hi Mark,
> >
> > On Sun, 3 Oct 2021 at 12:31, Mark Kettenis  wrote:
> > >
> > > This uclass is intended to manage IOMMUs on systems where the
> > > IOMMUs are not in bypass mode by default.  In that case U-Boot
> > > cannot ignore the IOMMUs if it wants to use devices that need
> > > to do DMA and sit behind such an IOMMU.
> > >
> > > This initial IOMMU uclass implementation does not implement and
> > > device ops and is intended for IOMMUs that have a bypass mode
> > > that does not require address translation.  Support for IOMMUs
> > > that do require address translation is planned and device ops
> > > will be defined when support for such IOMMUs will be added.
> > >
> > > Signed-off-by: Mark Kettenis 
> > > ---
> > >  drivers/Kconfig  |  2 ++
> > >  drivers/Makefile |  1 +
> > >  drivers/core/device.c|  8 +++
> > >  drivers/iommu/Kconfig| 13 +++
> > >  drivers/iommu/Makefile   |  3 +++
> > >  drivers/iommu/iommu-uclass.c | 45 
> > >  include/dm/uclass-id.h   |  1 +
> > >  include/iommu.h  | 16 +
> > >  8 files changed, 89 insertions(+)
> > >  create mode 100644 drivers/iommu/Kconfig
> > >  create mode 100644 drivers/iommu/Makefile
> > >  create mode 100644 drivers/iommu/iommu-uclass.c
> > >  create mode 100644 include/iommu.h
> > >
> > > diff --git a/drivers/Kconfig b/drivers/Kconfig
> > > index 417d6f88c2..b26ca8cf70 100644
> > > --- a/drivers/Kconfig
> > > +++ b/drivers/Kconfig
> > > @@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig"
> > >
> > >  source "drivers/input/Kconfig"
> > >
> > > +source "drivers/iommu/Kconfig"
> > > +
> > >  source "drivers/led/Kconfig"
> > >
> > >  source "drivers/mailbox/Kconfig"
> > > diff --git a/drivers/Makefile b/drivers/Makefile
> > > index fd218c9056..166aeb9817 100644
> > > --- a/drivers/Makefile
> > > +++ b/drivers/Makefile
> > > @@ -109,6 +109,7 @@ obj-y += mtd/
> > >  obj-y += pwm/
> > >  obj-y += reset/
> > >  obj-y += input/
> > > +obj-y += iommu/
> > >  # SOC specific infrastructure drivers.
> > >  obj-y += smem/
> > >  obj-y += thermal/
> > > diff --git a/drivers/core/device.c b/drivers/core/device.c
> > > index 29668f6fb3..5f480ad443 100644
> > > --- a/drivers/core/device.c
> > > +++ b/drivers/core/device.c
> > > @@ -28,6 +28,7 @@
> > >  #include 
> > >  #include 
> > >  #include 
> > > +#include 
> > >  #include 
> > >  #include 
> > >  #include 
> > > @@ -543,6 +544,13 @@ int device_probe(struct udevice *dev)
> > > goto fail;
> > > }
> > >
> > > +   if (CONFIG_IS_ENABLED(IOMMU) && dev->parent &&
> > > +   (device_get_uclass_id(dev) != UCLASS_IOMMU)) {
> > > +   ret = dev_iommu_probe(dev);
> > > +   if (ret)
> > > +   goto fail;
> > > +   }
> > > +
> > > ret = device_get_dma_constraints(dev);
> > > if (ret)
> > > goto fail;
> > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> > > new file mode 100644
> > > index 00..8cb377560e
> > > --- /dev/null
> > > +++ b/drivers/iommu/Kconfig
> > > @@ -0,0 +1,13 @@
> > > +#
> > > +# IOMMU devices
> > > +#
> > > +
> > > +menu "IOMMU device drivers"
> > > +
> > > +config IOMMU
> > > +   bool "Enable Driver Model for IOMMU drivers"
> > > +   depends on DM
> > > +   help
> > > + Enable driver model for IOMMU devices.
> >
> > Need at least three lines. What is an IOMMU? How does it relate to
> > other devices?
>
> Not sure if I can describe what an IOMMU is in just a few lines, but
> I'll try.
>
> > > +
> > > +endmenu
> > > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> > > new file mode 100644
> > > index 00..f1ceb10150
> > > --- /dev/null
> > > +++ b/drivers/iommu/Makefile
> > > @@ -0,0 +1,3 @@
> > > +# SPDX-License-Identifier: GPL-2.0+
> > > +
> > > +obj-$(CONFIG_IOMMU) += iommu-uclass.o
> > > diff --git a/drivers/iommu/iommu-uclass.c b/drivers/iommu/iommu-uclass.c
> > > new file mode 100644
> > > index 00..5c55df3066
> > > --- /dev/null
> > > +++ b/drivers/iommu/iommu-uclass.c
> > > @@ -0,0 +1,45 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +/*
> > > + * Copyright (C) 2021 Mark Kettenis 
> > > + */
> > > +
> > > +#define LOG_CATEGORY UCLASS_IOMMU
> > > +
> > > +#include 
> > > +#include 
> > > +
> > > +#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA))
> > > +int dev_iommu_probe(struct udevice *dev)
> >
> > Can we rename to dev_iommus_enable()? I like to keep probe for use by
> > DM itself so it is confusing to talk about probing in a context other
> > than probing a single device.
>
> Sure.  That was one of the names I considered myself when writing the
> code.
>
> > > +{
> > > +   struct ofnode_phandle_args args;
> > > +   struct udevice 

Re: [PATCH v3 7/7] doc: board: apple: Add Apple M1 documentation

2021-10-14 Thread Mark Kettenis
> From: Simon Glass 
> Date: Mon, 11 Oct 2021 13:10:02 -0600
> 
> Hi Mark,
> 
> On Mon, 11 Oct 2021 at 10:40, Mark Kettenis  wrote:
> >
> > Provide preliminary instructions on how to get U-Boot to run on
> > Apple Silicon Macs.
> 
> Apple-Silicon
> 
> This is ambiguous. The Macs are not made out of silicon. It is a Mac
> using Apple Silicon.

Well, this is the marketing term that tends to be used to distinguish
them from the Macs with an Intel CPU in them.  It doesn't have to make
sense ;).

> 
> >
> > Signed-off-by: Mark Kettenis 
> > ---
> >  doc/board/apple/index.rst |  9 +++
> >  doc/board/apple/m1.rst| 56 +++
> >  doc/board/index.rst   |  1 +
> >  3 files changed, 66 insertions(+)
> >  create mode 100644 doc/board/apple/index.rst
> >  create mode 100644 doc/board/apple/m1.rst
> >
> > diff --git a/doc/board/apple/index.rst b/doc/board/apple/index.rst
> > new file mode 100644
> > index 00..8446847818
> > --- /dev/null
> > +++ b/doc/board/apple/index.rst
> > @@ -0,0 +1,9 @@
> > +.. SPDX-License-Identifier: GPL-2.0+
> > +
> > +Apple
> > +=
> > +
> > +.. toctree::
> > +   :maxdepth: 2
> > +
> > +   m1
> > diff --git a/doc/board/apple/m1.rst b/doc/board/apple/m1.rst
> > new file mode 100644
> > index 00..2f2d940a4c
> > --- /dev/null
> > +++ b/doc/board/apple/m1.rst
> > @@ -0,0 +1,56 @@
> > +.. SPDX-License-Identifier: GPL-2.0+
> > +
> > +U-Boot for Apple Silicon Macs
> 
> Apple-Silicon
> 
> > +=
> > +
> > +Allows Apple Silicon Macs to boot U-Boot via the m1n1 bootloader
> 
> Apple-Silicon
> 
> > +developed by the Asahi Linux project.  At this point the machines with
> > +the following SoCs work:
> > +
> > + - Apple M1 SoC
> > +
> > +On these SoCs the following hardware is supported:
> > +
> > + - S5L serial port
> > + - Framebuffer
> > + - USB 3.1 Type-C ports
> > +
> > +Device trees are currently provided for the M1 Mac mini (2020, J274)
> > +and M1 MacBook Pro 13" (2020, J293).  The M1 MacBook Air (2020) is
> > +expected to work with the J293 device tree.  The M1 iMac (2021) may
> 
> Tested on MacBook Air 2020 A2337
> Tested-by: Simon Glass 
> 
> > +work with the J274 device tree.
> > +
> > +Building U-Boot
> > +---
> > +
> > +.. code-block:: bash
> > +
> > +$ export CROSS_COMPILE=aarch64-none-elf-
> > +$ make apple_m1_defconfig
> > +$ make
> > +
> > +This will build ``u-boot-nodtb.bin`` as well as devices trees for some
> > +of the supported machines.  These device trees can be found in the
> > +``arch/arm/dts`` subdirectory of your build.
> > +
> > +Image creation
> > +--
> > +
> > +In order to run U-Boot on an Apple Silicon Mac, U-Boot has to be used
> > +as a payload for the m1n1 bootloader.  Instructions for building m1n1
> > +can be found here:
> > +
> > +https://github.com/AsahiLinux/docs/wiki/SW%3Am1n1
> > +
> > +.. code-block:: bash
> > +
> > +$ cat m1n1.macho t8103-j274.dtb u-boot-nodtb.bin > u-boot.macho
> 
> or just u-boot.bin which is more normal

But that one has the DTB baked in, so it makes no sense to use it in
this context as the DTB is provided separately.

> > +
> > +Image installation
> > +--
> > +
> > +Instructions on how to install U-Boot on your Mac can be found at:
> > +
> > +https://github.com/AsahiLinux/docs/wiki/Developer-Quickstart
> > +
> > +Just replace ``m1n1.macho`` with ``u-boot.macho`` in the instructions.
> > diff --git a/doc/board/index.rst b/doc/board/index.rst
> > index aa397ab942..1b93ced563 100644
> > --- a/doc/board/index.rst
> > +++ b/doc/board/index.rst
> > @@ -10,6 +10,7 @@ Board-specific doc
> > advantech/index
> > AndesTech/index
> > amlogic/index
> > +   apple/index
> > atmel/index
> > congatec/index
> > coreboot/index
> > --
> > 2.33.0
> >
> 
> Regards,
> Simon
> 


Re: [PATCH v3 7/7] doc: board: apple: Add Apple M1 documentation

2021-10-14 Thread Mark Kettenis
> From: Simon Glass 
> Date: Mon, 11 Oct 2021 11:01:20 -0600
> 
> Hi Mark,
> 
> On Mon, 11 Oct 2021 at 10:40, Mark Kettenis  wrote:
> >
> > Provide preliminary instructions on how to get U-Boot to run on
> > Apple Silicon Macs.
> >
>
> Please can you add a change log to this patch? Patman will do it for you.

Sorry, I'm confused.  The changelog is on the cover letter.  This
particular patch did not change at all...

> > Signed-off-by: Mark Kettenis 
> > ---
> >  doc/board/apple/index.rst |  9 +++
> >  doc/board/apple/m1.rst| 56 +++
> >  doc/board/index.rst   |  1 +
> >  3 files changed, 66 insertions(+)
> >  create mode 100644 doc/board/apple/index.rst
> >  create mode 100644 doc/board/apple/m1.rst
> 
> [..]
> 
> Regards,
> Simon
> 


Re: [PATCH v2 4/7] serial: s5p: Add Apple M1 support

2021-10-14 Thread Mark Kettenis
> From: Simon Glass 
> Date: Mon, 11 Oct 2021 11:00:39 -0600
> 
> Hi Mark,
> 
> On Sun, 3 Oct 2021 at 12:33, Mark Kettenis  wrote:
> >
> > Apple M1 SoCs include an S5L UART which is a variant of the S5P
> > UART.  Add support for this variant and enable it by default
> > on Apple SoCs.
> >
> > Signed-off-by: Mark Kettenis 
> > ---
> >  arch/arm/Kconfig|   1 +
> >  arch/arm/include/asm/arch-m1/uart.h |  41 +++
> >  configs/apple_m1_defconfig  |   4 ++
> >  drivers/serial/Kconfig  |   4 +-
> >  drivers/serial/serial_s5p.c | 104 ++--
> >  5 files changed, 130 insertions(+), 24 deletions(-)
> >  create mode 100644 arch/arm/include/asm/arch-m1/uart.h
> >
> 
> Reviewed-by: Simon Glass 
> [..]
> 
> > diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c
> > index 6d09952a5d..53a7b0bd1b 100644
> > --- a/drivers/serial/serial_s5p.c
> > +++ b/drivers/serial/serial_s5p.c
> [..]
> > @@ -93,7 +116,7 @@ int s5p_serial_setbrg(struct udevice *dev, int baudrate)
> > struct s5p_uart *const uart = plat->reg;
> > u32 uclk;
> >
> > -#ifdef CONFIG_CLK_EXYNOS
> > +#if CONFIG_IS_ENABLED(CLK_EXYNOS) || CONFIG_IS_ENABLED(ARCH_APPLE)
> 
> I really don't like making this any worse.
> 
> Does this work?
> 
> ret = clk_get_by_index(...)
> if (ret && ret != -ENOSYS)
>return ret

The problem really is that I'm trying to avoid having to define
get_uart_clock() for the new platform.  So I need an #if of some sorts
to avoid that code.  I really think the current diff is the cleanest I
can come up.
 
> > struct clk clk;
> > u32 ret;
> >
> > @@ -105,7 +128,7 @@ int s5p_serial_setbrg(struct udevice *dev, int baudrate)
> > uclk = get_uart_clk(plat->port_id);
> >  #endif
> >
> > -   s5p_serial_baud(uart, uclk, baudrate);
> > +   s5p_serial_baud(uart, plat->reg_width, uclk, baudrate);
> >
> > return 0;
> >  }
> [..]
> 
> Regards,
> Simon
> 


Re: [PATCH v2 2/7] test: Add tests for IOMMU uclass

2021-10-14 Thread Mark Kettenis
> From: Simon Glass 
> Date: Mon, 11 Oct 2021 11:00:36 -0600
> 
> On Sun, 3 Oct 2021 at 12:31, Mark Kettenis  wrote:
> >
> > Add a set of tests for the IOMMU uclass.
> >
> > Signed-off-by: Mark Kettenis 
> > ---
> >  arch/sandbox/dts/test.dts  |  6 ++
> >  configs/sandbox64_defconfig|  1 +
> >  configs/sandbox_defconfig  |  1 +
> >  configs/sandbox_flattree_defconfig |  1 +
> >  configs/sandbox_noinst_defconfig   |  1 +
> >  configs/sandbox_spl_defconfig  |  1 +
> >  drivers/iommu/Makefile |  2 ++
> >  drivers/iommu/sandbox_iommu.c  | 18 ++
> >  test/dm/Makefile   |  1 +
> >  test/dm/iommu.c| 28 
> >  10 files changed, 60 insertions(+)
> >  create mode 100644 drivers/iommu/sandbox_iommu.c
> >  create mode 100644 test/dm/iommu.c
> >
> 
> Reviewed-by: Simon Glass 
> 
> You could add the CONFIG options to sandbox's Kconfig in arch/Kconfig

The codebase is a bit inconsistent in that respect isn't it?


Re: [PATCH v2 1/7] iommu: Add IOMMU uclass

2021-10-14 Thread Mark Kettenis
> From: Simon Glass 
> Date: Mon, 11 Oct 2021 11:00:34 -0600
> 
> Hi Mark,
> 
> On Sun, 3 Oct 2021 at 12:31, Mark Kettenis  wrote:
> >
> > This uclass is intended to manage IOMMUs on systems where the
> > IOMMUs are not in bypass mode by default.  In that case U-Boot
> > cannot ignore the IOMMUs if it wants to use devices that need
> > to do DMA and sit behind such an IOMMU.
> >
> > This initial IOMMU uclass implementation does not implement and
> > device ops and is intended for IOMMUs that have a bypass mode
> > that does not require address translation.  Support for IOMMUs
> > that do require address translation is planned and device ops
> > will be defined when support for such IOMMUs will be added.
> >
> > Signed-off-by: Mark Kettenis 
> > ---
> >  drivers/Kconfig  |  2 ++
> >  drivers/Makefile |  1 +
> >  drivers/core/device.c|  8 +++
> >  drivers/iommu/Kconfig| 13 +++
> >  drivers/iommu/Makefile   |  3 +++
> >  drivers/iommu/iommu-uclass.c | 45 
> >  include/dm/uclass-id.h   |  1 +
> >  include/iommu.h  | 16 +
> >  8 files changed, 89 insertions(+)
> >  create mode 100644 drivers/iommu/Kconfig
> >  create mode 100644 drivers/iommu/Makefile
> >  create mode 100644 drivers/iommu/iommu-uclass.c
> >  create mode 100644 include/iommu.h
> >
> > diff --git a/drivers/Kconfig b/drivers/Kconfig
> > index 417d6f88c2..b26ca8cf70 100644
> > --- a/drivers/Kconfig
> > +++ b/drivers/Kconfig
> > @@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig"
> >
> >  source "drivers/input/Kconfig"
> >
> > +source "drivers/iommu/Kconfig"
> > +
> >  source "drivers/led/Kconfig"
> >
> >  source "drivers/mailbox/Kconfig"
> > diff --git a/drivers/Makefile b/drivers/Makefile
> > index fd218c9056..166aeb9817 100644
> > --- a/drivers/Makefile
> > +++ b/drivers/Makefile
> > @@ -109,6 +109,7 @@ obj-y += mtd/
> >  obj-y += pwm/
> >  obj-y += reset/
> >  obj-y += input/
> > +obj-y += iommu/
> >  # SOC specific infrastructure drivers.
> >  obj-y += smem/
> >  obj-y += thermal/
> > diff --git a/drivers/core/device.c b/drivers/core/device.c
> > index 29668f6fb3..5f480ad443 100644
> > --- a/drivers/core/device.c
> > +++ b/drivers/core/device.c
> > @@ -28,6 +28,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -543,6 +544,13 @@ int device_probe(struct udevice *dev)
> > goto fail;
> > }
> >
> > +   if (CONFIG_IS_ENABLED(IOMMU) && dev->parent &&
> > +   (device_get_uclass_id(dev) != UCLASS_IOMMU)) {
> > +   ret = dev_iommu_probe(dev);
> > +   if (ret)
> > +   goto fail;
> > +   }
> > +
> > ret = device_get_dma_constraints(dev);
> > if (ret)
> > goto fail;
> > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> > new file mode 100644
> > index 00..8cb377560e
> > --- /dev/null
> > +++ b/drivers/iommu/Kconfig
> > @@ -0,0 +1,13 @@
> > +#
> > +# IOMMU devices
> > +#
> > +
> > +menu "IOMMU device drivers"
> > +
> > +config IOMMU
> > +   bool "Enable Driver Model for IOMMU drivers"
> > +   depends on DM
> > +   help
> > + Enable driver model for IOMMU devices.
> 
> Need at least three lines. What is an IOMMU? How does it relate to
> other devices?

Not sure if I can describe what an IOMMU is in just a few lines, but
I'll try.
 
> > +
> > +endmenu
> > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> > new file mode 100644
> > index 00..f1ceb10150
> > --- /dev/null
> > +++ b/drivers/iommu/Makefile
> > @@ -0,0 +1,3 @@
> > +# SPDX-License-Identifier: GPL-2.0+
> > +
> > +obj-$(CONFIG_IOMMU) += iommu-uclass.o
> > diff --git a/drivers/iommu/iommu-uclass.c b/drivers/iommu/iommu-uclass.c
> > new file mode 100644
> > index 00..5c55df3066
> > --- /dev/null
> > +++ b/drivers/iommu/iommu-uclass.c
> > @@ -0,0 +1,45 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2021 Mark Kettenis 
> > + */
> > +
> > +#define LOG_CATEGORY UCLASS_IOMMU
> > +
> > +#include 
> > +#include 
> > +
> > +#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA))
> > +int dev_iommu_probe(struct udevice *dev)
> 
> Can we rename to dev_iommus_enable()? I like to keep probe for use by
> DM itself so it is confusing to talk about probing in a context other
> than probing a single device.

Sure.  That was one of the names I considered myself when writing the
code.

> > +{
> > +   struct ofnode_phandle_args args;
> > +   struct udevice *dev_iommu;
> > +   int i, count, ret = 0;
> > +
> > +   count = dev_count_phandle_with_args(dev, "iommus",
> > +   "#iommu-cells", 0);
> 
> Do you have a binding file you can add to docs/device-tree-bindings ?

The binding is available in Documentation/bindings/iommu/iommu.txt in
the Linux tree.  But I 

Re: External dts building

2021-10-14 Thread Giulio Benetti
Hi Simon,

> Il giorno 14 ott 2021, alle ore 20:24, Simon Glass  ha 
> scritto:
> 
> Hi,
> 
>> On Thu, 14 Oct 2021 at 07:46, Tom Rini  wrote:
>> 
>>> On Thu, Oct 14, 2021 at 02:53:30AM +0200, Giulio Benetti wrote:
>>> 
>>> Hello All,
>>> 
>>> is there a way to pass a dts file without touching the 
>>> arch/arm/boot/dts/Makefile?
>>> 
>>> On Buildroot we support the possibility to pass an external dts by copying 
>>> it to the uboot sources to
>>> be built but since uboot version 2020.01 it doesn’t work anymore.
>>> 
>>> So I’ve proposed a patch to prepend the dts file in the Makefile above, but 
>>> this has drawbacks, like we reconfigure(it keeps adding files every time).
>>> 
>>> So I ask you, is there a more canonical way already to achieve this?
>> 
>> Not exactly, and it's something we're very much actively discussing
>> right now.
> 
> Are you using 'make DEVICE_TREE=xxx' ?

Yes but it doesn’t work if you don’t add an entry into arch/arm/dts/Makefile
Before version 2020.01 worked, but not after it.

Best regards
Giulio

> 
> Regards,
> Simon



Re: IMX8M OP-TEE

2021-10-14 Thread Tim Harvey
On Mon, Oct 11, 2021 at 3:15 PM Tim Harvey  wrote:
>
> Greetings,
>
> Is anyone successfully booting U-Boot with OP-TEE support on the IMX8M?
>
> My understanding is that you need to add tee.bin to the images in the
> FIT image and include it in loadables following the ATF.
>
> While this was done with arch/arm/mach-imx/mkimage_fit_atf.sh before
> the switch to binman by simply having tee.bin in the U-Boot directory
> and passing in TEE_LOAD_ADDR (or accepting the default of 0xfe00)
> once you switch to binman it needs to be added for your board.
>
> Additionally in order to use OP-TEE from U-Boot (ie for dek_blob
> command) you need to add a node with compatible=linaro,optee-tz as
> well.
>
> I've done the following to add OP-TEE for imx8mm_venice:
> diff --git a/configs/imx8mm_venice_defconfig b/configs/imx8mm_venice_defconfig
> index d85827b588..85d2b20810 100644
> -u-boot.dtsi
> index e0fa9ff4bf..7a71b974e1 100644
> --- a/arch/arm/dts/imx8mm-venice-u-boot.dtsi
> +++ b/arch/arm/dts/imx8mm-venice-u-boot.dtsi
> @@ -10,6 +10,13 @@
> multiple-images;
> };
>
> +   firmware {
> +   optee {
> +   compatible = "linaro,optee-tz";
> +   method = "smc";
> +   };
> +   };
> +
> wdt-reboot {
> compatible = "wdt-reboot";
> wdt = <>;
> @@ -152,6 +159,16 @@
> };
> };
>
> +   tee {
> +   description = "TEE firmware";
> +   type = "firmware";
> +   arch = "arm64";
> +   compression = "none";
> +   data = "tee.bin";
> +   load = <0xbe00>;
> +   entry = <0xbe00>;
> +   };
> +
> @fdt-SEQ {
> description = "NAME";
> type = "flat_dt";
> @@ -165,7 +182,7 @@
> @config-SEQ {
> description = "NAME";
> firmware = "uboot";
> -   loadables = "atf";
> +   loadables = "atf", "tee";
> fdt = "fdt-SEQ";
> };
> };
>
>
> However, when I attempt to boot I hang when the ATF is run.
>
> Where does the TEE_LOAD_ADDR come from specifically? I would think
> this needs to be defined when building tee and needs to match the load
> address used in the FIT image. It appears that perhaps this is supped
> to be DDR_BASE + DDR_SIZE - 32MIB but I'm not entirely sure.
>
> I'm currently using NXP's ATF (imx_5.4.3_2.0.0) and NXP's TEE
> (imx_5.4.70_2.3.0) and would also like to understand if NXP's branches
> are strictly required here and if so what the pros and cons of using
> them are.
>
> Anyone using IMX8MM OP-TEE that could point me in the right direction?
>

Here's what I've learned so far via various responses, research and testing.

There are multiple boot flows that can be used with OP-TEE:
1. SPL -> ATF -> OP-TEE -> U-boot -> LInux
2. SPL -> OP-TEE -> U-boot -> Linux

I'm not really clear what the pros and cons of each are - can anyone
shed some light on this?

Method #1 is what I've found the most info on and have mostly gotten
working so I will go over that here. As IMX8MM runs on Cortex-A Arm
TrustZone is available and thus TF-A can be used.

By the way, I'm a bit confused as to ATF vs TF-A. From what I can find:
- ATF (Arm Trusted Firmware) is a Trusted Firmware reference
implementation of secure world software for Armv7-A, Armv8-A, and
Armv8-M architectures.
- TF-A (Trusted Firmware-A) also appears to provide the same thing
Are these the same? Which one is it that NXP uses for imx-atf [1]

When OP-TEE is used with TF-A the TF-A gets invoked with the TEE as
bl32 and main u-boot as bl33. Once it has done its startup TF-A jumps
into the bl32(OP-TEE) for the TEE startup, returns to TF-A and then
jumps to bl33(U-Boot).

For this boot flow on IMX8MM you need to do the following:
- build TF-A (bl31.bin) with OP-TEE as a Secure Payload Dispatcher
(SPD) (add 'SPD=opteed' to env)
- build OP-TEE (tee.bin)
- add tee.bin to U-Boot FIT image along with TF-A binary in images node
 * for boards still using arch/arm/mach-imx/mkimage_fit_atf.sh FIT
generation this is done automatically when tee.bin is U-Boot's build
directory but you also need to set TEE_LOAD_ADDR env to specify the
load addr of the TEE which depends on the board DRAM size
 * for boards using binman the generation of the FIT image has moved
to using the 'binman' tool thus adding tee.bin 

RE: i.mx7ulp u-boot image flashing to SD card - Doesn't use the new image from SD card.

2021-10-14 Thread Karicheri, Murali
Found the issue. The of=/dev/sde
>sudo dd if=u-boot-dtb.imx of=/dev/sde1 bs=1k seek=1 conv=fsync

Murali Karicheri, Software Architect
S Electric Company
(Work from Home)
18702 Broken Oak Rd, Boyds,
Maryland, USA 20841
Phone: (301) 256 8139
E-Mail: murali.karich...@sandc.com


-Original Message-
From: Karicheri, Murali
Sent: Tuesday, October 12, 2021 5:33 PM
To: u-boot@lists.denx.de
Subject: i.mx7ulp u-boot image flashing to SD card - Doesn't use the new image 
from SD card.

Hello imx7 developers,
I have an i.mx7ulp evk board and have been chasing an issue that prevents me 
from using my own u-boot image flashed to the SD card to boot the board. The 
basic steps I followed are 1. build u-boot image using mx7ulp_evk_defconfig and 
I get u-boot-dtb.imx. I am using NXP's 5.4.x GA release. But would like to use 
the latest from upstream tree as well. So your response can be based on 
upstream version.
2. SD card formatting. create 2 partitions using fdisk command. u-boot image is 
at the start of partition 1 as per available information. So partition 1 starts 
with first section at 20480 and last at 1024000. Partition 2 at 1228800.
3. For now I just want to boot with u-boot only and not to Linux. So I program 
u-boot image using dd command as
sudo dd if=u-boot-dtb.imx of=/dev/sde1 bs=1k seek=1 conv=fsync
where u-boot-dtb.imx is my u-boot image from step 1. /dev/sde1 is device 
for the first partition

>sudo dd if=u-boot-dtb.imx of=/dev/sde1 bs=1k seek=1 conv=fsync
[sudo] password for sandc:
495+0 records in
495+0 records out
506880 bytes (507 kB, 495 KiB) copied, 0.127887 s, 4.0 MB/s 
sandc@sandc-VirtualBox:~/git/uboot-imx (imx_v2020.04_5.4.70_2.3.0)$ sync

4. Eject the sd card and boot i.mx7ulp evk with this SD card.

Unfortunately the console shows the old image U-Boot 
2020.04-5.4.47-2.2.0+gffc3fbe7e5 (Sep 11 2020 - 19:56:06 +)

Have anyone seen similar issue and have clue on what is going on. Thanks for 
your feedback.

Thanks
Murali Karicheri



NOTICE OF CONFIDENTIALITY:
This message may contain information that is considered confidential and which 
may be prohibited from disclosure under applicable law or by contractual 
agreement. The information is intended solely for the use of the individual or 
entity named above. If you are not the intended recipient, you are hereby 
notified that any disclosure, copying, distribution or use of the information 
contained in or attached to this message is strictly prohibited. If you have 
received this email transmission in error, please notify the sender by replying 
to this email and then delete it from your system.


[PATCH v3 17/18] doc: Move distro boot doc to rST

2021-10-14 Thread Simon Glass
Move this over to the new rST format.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/{README.distro => develop/distro.rst} | 177 ++
 doc/develop/index.rst |   1 +
 2 files changed, 80 insertions(+), 98 deletions(-)
 rename doc/{README.distro => develop/distro.rst} (76%)

diff --git a/doc/README.distro b/doc/develop/distro.rst
similarity index 76%
rename from doc/README.distro
rename to doc/develop/distro.rst
index fa8cec11028..c522be69349 100644
--- a/doc/README.distro
+++ b/doc/develop/distro.rst
@@ -1,9 +1,4 @@
-SPDX-License-Identifier: GPL-2.0+
-/*
- * (C) Copyright 2014 Red Hat Inc.
- * Copyright (c) 2014-2015, NVIDIA CORPORATION.  All rights reserved.
- * Copyright (C) 2015 K. Merker 
- */
+.. SPDX-License-Identifier: GPL-2.0+
 
 Generic Distro Configuration Concept
 
@@ -73,9 +68,8 @@ Boot Configuration Files
 
 The standard format for boot configuration files is that of extlinux.conf, as
 handled by U-Boot's "syslinux" (disk) or "pxe boot" (network). This is roughly
-as specified at:
+as specified at BootLoaderSpec_:
 
-http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
 
 ... with the exceptions that the BootLoaderSpec document:
 
@@ -87,73 +81,70 @@ 
http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
 * Does not document the fdtdir option, which automatically selects the DTB to
   pass to the kernel.
 
-One example extlinux.conf generated by the Fedora installer is:
+One example extlinux.conf generated by the Fedora installer is::
 
-
-# extlinux.conf generated by anaconda
+# extlinux.conf generated by anaconda
 
-ui menu.c32
+ui menu.c32
 
-menu autoboot Welcome to Fedora. Automatic boot in # second{,s}. Press a key 
for options.
-menu title Fedora Boot Options.
-menu hidden
+menu autoboot Welcome to Fedora. Automatic boot in # second{,s}. Press a 
key for options.
+menu title Fedora Boot Options.
+menu hidden
 
-timeout 50
-#totaltimeout 9000
+timeout 50
+#totaltimeout 9000
 
-default Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
+default Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
 
-label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl) 22 (Rawhide)
-   kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl
-   append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 
console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
-   fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl
-   initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl.img
+label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl) 22 (Rawhide)
+kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl
+append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 
console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
+fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl
+initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl.img
 
-label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
-   kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
-   append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 
console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
-   fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
-   initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae.img
+label Fedora (3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae) 22 (Rawhide)
+kernel /boot/vmlinuz-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
+append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 
console=ttyS0,115200n8 LANG=en_US.UTF-8 drm.debug=0xf
+fdtdir /boot/dtb-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae
+initrd /boot/initramfs-3.17.0-0.rc4.git2.1.fc22.armv7hl+lpae.img
 
-label Fedora-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc 
(0-rescue-8f6ba7b039524e0eb957d2c9203f04bc)
-   kernel /boot/vmlinuz-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc
-   initrd /boot/initramfs-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc.img
-   append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 
console=ttyS0,115200n8
-   fdtdir /boot/dtb-3.16.0-0.rc6.git1.1.fc22.armv7hl+lpae
-
+label Fedora-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc 
(0-rescue-8f6ba7b039524e0eb957d2c9203f04bc)
+kernel /boot/vmlinuz-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc
+initrd /boot/initramfs-0-rescue-8f6ba7b039524e0eb957d2c9203f04bc.img
+append ro root=UUID=8eac677f-8ea8-4270-8479-d5ddbb797450 
console=ttyS0,115200n8
+fdtdir /boot/dtb-3.16.0-0.rc6.git1.1.fc22.armv7hl+lpae
 
-Another hand-crafted network boot configuration file is:
 
-
-TIMEOUT 100
+Another hand-crafted network boot configuration file is::
 
-MENU TITLE TFTP boot options
+TIMEOUT 100
 
-LABEL jetson-tk1-emmc
-MENU LABEL ../zImage root on Jetson TK1 

[PATCH v3 15/18] pxe: Return the file size from the getfile() function

2021-10-14 Thread Simon Glass
It is pretty strange that the pxe code uses the 'filesize' environment
variable find the size of a file it has just read.

Partly this is because it uses the command-line interpreter to parse its
request to load the file.

As a first step towards unwinding this, return it directly from the
getfile() function. This makes the code a bit longer, for now, but will be
cleaned up in future patches.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/pxe_utils.c| 70 -
 cmd/pxe.c   |  7 -
 cmd/sysboot.c   | 21 --
 include/pxe_utils.h | 13 -
 4 files changed, 79 insertions(+), 32 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index f36f1f8a60c..e377e16be56 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -30,6 +30,20 @@
 
 #define MAX_TFTP_PATH_LEN 512
 
+int pxe_get_file_size(ulong *sizep)
+{
+   const char *val;
+
+   val = from_env("filesize");
+   if (!val)
+   return -ENOENT;
+
+   if (strict_strtoul(val, 16, sizep) < 0)
+   return -EINVAL;
+
+   return 0;
+}
+
 /**
  * format_mac_pxe() - obtain a MAC address in the PXE format
  *
@@ -75,14 +89,17 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
  * @ctx: PXE context
  * @file_path: File path to read (relative to the PXE file)
  * @file_addr: Address to load file to
+ * @filesizep: If not NULL, returns the file size in bytes
  * Returns 1 for success, or < 0 on error
  */
 static int get_relfile(struct pxe_context *ctx, const char *file_path,
-  unsigned long file_addr)
+  unsigned long file_addr, ulong *filesizep)
 {
size_t path_len;
char relfile[MAX_TFTP_PATH_LEN + 1];
char addr_buf[18];
+   ulong size;
+   int ret;
 
if (file_path[0] == '/' && ctx->allow_abs_path)
*relfile = '\0';
@@ -103,7 +120,13 @@ static int get_relfile(struct pxe_context *ctx, const char 
*file_path,
 
sprintf(addr_buf, "%lx", file_addr);
 
-   return ctx->getfile(ctx, relfile, addr_buf);
+   ret = ctx->getfile(ctx, relfile, addr_buf, );
+   if (ret < 0)
+   return log_msg_ret("get", ret);
+   if (filesizep)
+   *filesizep = size;
+
+   return 1;
 }
 
 /**
@@ -117,29 +140,17 @@ static int get_relfile(struct pxe_context *ctx, const 
char *file_path,
  * Returns 1 for success, or < 0 on error
  */
 int get_pxe_file(struct pxe_context *ctx, const char *file_path,
-unsigned long file_addr)
+ulong file_addr)
 {
-   unsigned long config_file_size;
-   char *tftp_filesize;
+   ulong size;
int err;
char *buf;
 
-   err = get_relfile(ctx, file_path, file_addr);
+   err = get_relfile(ctx, file_path, file_addr, );
if (err < 0)
return err;
 
-   /*
-* the file comes without a NUL byte at the end, so find out its size
-* and add the NUL byte.
-*/
-   tftp_filesize = from_env("filesize");
-   if (!tftp_filesize)
-   return -ENOENT;
-
-   if (strict_strtoul(tftp_filesize, 16, _file_size) < 0)
-   return -EINVAL;
-
-   buf = map_sysmem(file_addr + config_file_size, 1);
+   buf = map_sysmem(file_addr + size, 1);
*buf = '\0';
unmap_sysmem(buf);
 
@@ -184,12 +195,13 @@ int get_pxelinux_path(struct pxe_context *ctx, const char 
*file,
  * @file_path: File path to read (relative to the PXE file)
  * @envaddr_name: Name of environment variable which contains the address to
  * load to
+ * @filesizep: Returns the file size in bytes
  * Returns 1 on success, -ENOENT if @envaddr_name does not exist as an
  * environment variable, -EINVAL if its format is not valid hex, or other
  * value < 0 on other error
  */
 static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path,
-  const char *envaddr_name)
+  const char *envaddr_name, ulong *filesizep)
 {
unsigned long file_addr;
char *envaddr;
@@ -201,7 +213,7 @@ static int get_relfile_envaddr(struct pxe_context *ctx, 
const char *file_path,
if (strict_strtoul(envaddr, 16, _addr) < 0)
return -EINVAL;
 
-   return get_relfile(ctx, file_path, file_addr);
+   return get_relfile(ctx, file_path, file_addr, filesizep);
 }
 
 /**
@@ -357,8 +369,8 @@ static void label_boot_fdtoverlay(struct pxe_context *ctx,
goto skip_overlay;
 
/* Load overlay file */
-   err = get_relfile_envaddr(ctx, overlayfile,
- "fdtoverlay_addr_r");
+   err = get_relfile_envaddr(ctx, overlayfile, "fdtoverlay_addr_r",
+ NULL);
if (err < 0) {
printf("Failed loading overlay %s\n", overlayfile);
 

[PATCH v3 18/18] pxe: Allow calling the pxe_get logic directly

2021-10-14 Thread Simon Glass
Refactor this code so that we can call the 'pxe get' command without going
through the command-line interpreter. This makes it easier to get the
information we need, without going through environment variables.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Rebase to -master

Changes in v2:
- Rebase to -next
- Split out from the bootmethod patches

 cmd/pxe.c   | 92 +
 include/pxe_utils.h | 14 +++
 2 files changed, 73 insertions(+), 33 deletions(-)

diff --git a/cmd/pxe.c b/cmd/pxe.c
index 81703386c42..db8e4697f24 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -104,6 +104,49 @@ static int pxe_ipaddr_paths(struct pxe_context *ctx, 
unsigned long pxefile_addr_
 
return -ENOENT;
 }
+
+int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep)
+{
+   struct cmd_tbl cmdtp[] = {};/* dummy */
+   struct pxe_context ctx;
+   int i;
+
+   if (pxe_setup_ctx(, cmdtp, do_get_tftp, NULL, false,
+ env_get("bootfile")))
+   return -ENOMEM;
+   /*
+* Keep trying paths until we successfully get a file we're looking
+* for.
+*/
+   if (pxe_uuid_path(, pxefile_addr_r) > 0 ||
+   pxe_mac_path(, pxefile_addr_r) > 0 ||
+   pxe_ipaddr_paths(, pxefile_addr_r) > 0)
+   goto done;
+
+   i = 0;
+   while (pxe_default_paths[i]) {
+   if (get_pxelinux_path(, pxe_default_paths[i],
+ pxefile_addr_r) > 0)
+   goto done;
+   i++;
+   }
+
+   pxe_destroy_ctx();
+
+   return -ENOENT;
+done:
+   *bootdirp = env_get("bootfile");
+
+   /*
+* The PXE file size is returned but not the name. It is probably not
+* that useful.
+*/
+   *sizep = ctx.pxe_file_size;
+   pxe_destroy_ctx();
+
+   return 0;
+}
+
 /*
  * Entry point for the 'pxe get' command.
  * This Follows pxelinux's rules to download a config file from a tftp server.
@@ -122,9 +165,10 @@ static int
 do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
char *pxefile_addr_str;
-   unsigned long pxefile_addr_r;
-   struct pxe_context ctx;
-   int err, i = 0;
+   ulong pxefile_addr_r;
+   char *fname;
+   ulong size;
+   int ret;
 
if (argc != 1)
return CMD_RET_USAGE;
@@ -134,43 +178,25 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
if (!pxefile_addr_str)
return 1;
 
-   err = strict_strtoul(pxefile_addr_str, 16,
+   ret = strict_strtoul(pxefile_addr_str, 16,
 (unsigned long *)_addr_r);
-   if (err < 0)
+   if (ret < 0)
return 1;
 
-   if (pxe_setup_ctx(, cmdtp, do_get_tftp, NULL, false,
- env_get("bootfile"))) {
+   ret = pxe_get(pxefile_addr_r, , );
+   switch (ret) {
+   case 0:
+   printf("Config file '%s' found\n", fname);
+   break;
+   case -ENOMEM:
printf("Out of memory\n");
return CMD_RET_FAILURE;
+   default:
+   printf("Config file not found\n");
+   return CMD_RET_FAILURE;
}
-   /*
-* Keep trying paths until we successfully get a file we're looking
-* for.
-*/
-   if (pxe_uuid_path(, pxefile_addr_r) > 0 ||
-   pxe_mac_path(, pxefile_addr_r) > 0 ||
-   pxe_ipaddr_paths(, pxefile_addr_r) > 0) {
-   printf("Config file found\n");
-   pxe_destroy_ctx();
-
-   return 0;
-   }
-
-   while (pxe_default_paths[i]) {
-   if (get_pxelinux_path(, pxe_default_paths[i],
- pxefile_addr_r) > 0) {
-   printf("Config file found\n");
-   pxe_destroy_ctx();
-   return 0;
-   }
-   i++;
-   }
-
-   printf("Config file not found\n");
-   pxe_destroy_ctx();
 
-   return 1;
+   return 0;
 }
 
 /*
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index 194a5ed8cc7..b7037f841a6 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -236,4 +236,18 @@ int pxe_process(struct pxe_context *ctx, ulong 
pxefile_addr_r, bool prompt);
  */
 int pxe_get_file_size(ulong *sizep);
 
+/**
+ * pxe_get() - Get the PXE file from the server
+ *
+ * This tries various filenames to obtain a PXE file
+ *
+ * @pxefile_addr_r: Address to put file
+ * @bootdirp: Returns the boot filename, or NULL if none. This is the 
'bootfile'
+ * option provided by the DHCP server. If none, returns NULL. For example,
+ * "rpi/info", which indicates that all files should be fetched from the
+ * "rpi/" subdirectory
+ * @sizep: Size of the PXE file (not bootfile)
+ */
+int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong 

[PATCH v3 14/18] lib: Add a function to convert a string to a hex value

2021-10-14 Thread Simon Glass
Add an xtoa() function, similar to itoa() but for hex instead.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/vsprintf.h | 16 ++--
 lib/vsprintf.c | 20 ++--
 test/print_ut.c| 24 
 3 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/include/vsprintf.h b/include/vsprintf.h
index 4479df0af3f..b4746301462 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -177,14 +177,26 @@ int vsprintf(char *buf, const char *fmt, va_list args);
  * simple_itoa() - convert an unsigned integer to a string
  *
  * This returns a static string containing the decimal representation of the
- * given value. The returned value may be overwritten by other calls to the
- * same function, so should be used immediately
+ * given value. The returned value may be overwritten by other calls to other
+ * simple_... functions, so should be used immediately
  *
  * @val: Value to convert
  * @return string containing the decimal representation of @val
  */
 char *simple_itoa(ulong val);
 
+/**
+ * simple_xtoa() - convert an unsigned integer to a hex string
+ *
+ * This returns a static string containing the hexadecimal representation of 
the
+ * given value. The returned value may be overwritten by other calls to other
+ * simple_... functions, so should be used immediately
+ *
+ * @val: Value to convert
+ * @return string containing the hexecimal representation of @val
+ */
+char *simple_xtoa(ulong num);
+
 /**
  * Format a string and place it in a buffer
  *
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index d7ee35b4773..e634bd70b66 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -816,11 +816,12 @@ int vprintf(const char *fmt, va_list args)
 }
 #endif
 
+static char local_toa[22];
+
 char *simple_itoa(ulong i)
 {
/* 21 digits plus null terminator, good for 64-bit or smaller ints */
-   static char local[22];
-   char *p = [21];
+   char *p = _toa[21];
 
*p-- = '\0';
do {
@@ -830,6 +831,21 @@ char *simple_itoa(ulong i)
return p + 1;
 }
 
+char *simple_xtoa(ulong num)
+{
+   /* 16 digits plus nul terminator, good for 64-bit or smaller ints */
+   char *p = _toa[17];
+
+   *--p = '\0';
+   do {
+   p -= 2;
+   hex_byte_pack(p, num & 0xff);
+   num >>= 8;
+   } while (num > 0);
+
+   return p;
+}
+
 /* We don't seem to have %'d in U-Boot */
 void print_grouped_ull(unsigned long long int_val, int digits)
 {
diff --git a/test/print_ut.c b/test/print_ut.c
index 4fbb15b6d3c..152a8c3334f 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -335,16 +335,40 @@ static int print_itoa(struct unit_test_state *uts)
ut_asserteq_str("0", simple_itoa(0));
ut_asserteq_str("2147483647", simple_itoa(0x7fff));
ut_asserteq_str("4294967295", simple_itoa(0x));
+
+   /* Use #ifdef here to avoid a compiler warning on 32-bit machines */
+#ifdef CONFIG_PHYS_64BIT
if (sizeof(ulong) == 8) {
ut_asserteq_str("9223372036854775807",
simple_itoa((1UL << 63) - 1));
ut_asserteq_str("18446744073709551615", simple_itoa(-1));
}
+#endif /* CONFIG_PHYS_64BIT */
 
return 0;
 }
 PRINT_TEST(print_itoa, 0);
 
+static int print_xtoa(struct unit_test_state *uts)
+{
+   ut_asserteq_str("7f", simple_xtoa(127));
+   ut_asserteq_str("00", simple_xtoa(0));
+   ut_asserteq_str("7fff", simple_xtoa(0x7fff));
+   ut_asserteq_str("", simple_xtoa(0x));
+
+   /* Use #ifdef here to avoid a compiler warning on 32-bit machines */
+#ifdef CONFIG_PHYS_64BIT
+   if (sizeof(ulong) == 8) {
+   ut_asserteq_str("7fff",
+   simple_xtoa((1UL << 63) - 1));
+   ut_asserteq_str("", simple_xtoa(-1));
+   }
+#endif /* CONFIG_PHYS_64BIT */
+
+   return 0;
+}
+PRINT_TEST(print_xtoa, 0);
+
 int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(print_test);
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 16/18] pxe: Refactor sysboot to have one helper

2021-10-14 Thread Simon Glass
The only difference between the three helpers is the filesystem type.
Factor this out and call the filesystem functions directly, instead of
through the command-line interpreter. This allows the file size to be
obtained directly, instead of via an environment variable.

We cannot do the same thing with PXE's tftpboot since there is no API
at present to obtain information about the file that was read. So there
is no point in changing pxe_getfile_func to use a ulong for the address,
for example.

This is as far as the refactoring can go for the present.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/sysboot.c | 94 ---
 1 file changed, 36 insertions(+), 58 deletions(-)

diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index 6344ecd357b..04c07020269 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -6,63 +6,40 @@
 #include 
 #include 
 
-static char *fs_argv[5];
-
-static int do_get_ext2(struct pxe_context *ctx, const char *file_path,
-  char *file_addr, ulong *sizep)
+/**
+ * struct sysboot_info - useful information for sysboot helpers
+ *
+ * @fstype: Filesystem type (FS_TYPE_...)
+ * @ifname: Interface name (e.g. "ide", "scsi")
+ * @dev_part_str is in the format:
+ * .: where  is the device number,
+ *  is the optional hardware partition number and
+ *  is the partition number
+ */
+struct sysboot_info {
+   int fstype;
+   const char *ifname;
+   const char *dev_part_str;
+};
+
+static int sysboot_read_file(struct pxe_context *ctx, const char *file_path,
+char *file_addr, ulong *sizep)
 {
-#ifdef CONFIG_CMD_EXT2
+   struct sysboot_info *info = ctx->userdata;
+   loff_t len_read;
+   ulong addr;
int ret;
 
-   fs_argv[0] = "ext2load";
-   fs_argv[3] = file_addr;
-   fs_argv[4] = (void *)file_path;
-
-   if (!do_ext2load(ctx->cmdtp, 0, 5, fs_argv))
-   return 1;
-   ret = pxe_get_file_size(sizep);
+   addr = simple_strtoul(file_addr, NULL, 16);
+   ret = fs_set_blk_dev(info->ifname, info->dev_part_str, info->fstype);
if (ret)
-   return log_msg_ret("tftp", ret);
-#endif
-   return -ENOENT;
-}
-
-static int do_get_fat(struct pxe_context *ctx, const char *file_path,
- char *file_addr, ulong *sizep)
-{
-#ifdef CONFIG_CMD_FAT
-   int ret;
-
-   fs_argv[0] = "fatload";
-   fs_argv[3] = file_addr;
-   fs_argv[4] = (void *)file_path;
-
-   if (!do_fat_fsload(ctx->cmdtp, 0, 5, fs_argv))
-   return 1;
-   ret = pxe_get_file_size(sizep);
+   return ret;
+   ret = fs_read(file_path, addr, 0, 0, _read);
if (ret)
-   return log_msg_ret("tftp", ret);
-#endif
-   return -ENOENT;
-}
-
-static int do_get_any(struct pxe_context *ctx, const char *file_path,
- char *file_addr, ulong *sizep)
-{
-#ifdef CONFIG_CMD_FS_GENERIC
-   int ret;
-
-   fs_argv[0] = "load";
-   fs_argv[3] = file_addr;
-   fs_argv[4] = (void *)file_path;
+   return ret;
+   *sizep = len_read;
 
-   if (!do_load(ctx->cmdtp, 0, 5, fs_argv, FS_TYPE_ANY))
-   return 1;
-   ret = pxe_get_file_size(sizep);
-   if (ret)
-   return log_msg_ret("tftp", ret);
-#endif
-   return -ENOENT;
+   return 0;
 }
 
 /*
@@ -74,9 +51,9 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int 
argc,
  char *const argv[])
 {
unsigned long pxefile_addr_r;
-   pxe_getfile_func getfile;
struct pxe_context ctx;
char *pxefile_addr_str;
+   struct sysboot_info info;
char *filename;
int prompt = 0;
int ret;
@@ -106,24 +83,25 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int 
argc,
}
 
if (strstr(argv[3], "ext2")) {
-   getfile = do_get_ext2;
+   info.fstype = FS_TYPE_EXT;
} else if (strstr(argv[3], "fat")) {
-   getfile = do_get_fat;
+   info.fstype = FS_TYPE_FAT;
} else if (strstr(argv[3], "any")) {
-   getfile = do_get_any;
+   info.fstype = FS_TYPE_ANY;
} else {
printf("Invalid filesystem: %s\n", argv[3]);
return 1;
}
-   fs_argv[1] = argv[1];
-   fs_argv[2] = argv[2];
+   info.ifname = argv[1];
+   info.dev_part_str = argv[2];
 
if (strict_strtoul(pxefile_addr_str, 16, _addr_r) < 0) {
printf("Invalid pxefile address: %s\n", pxefile_addr_str);
return 1;
}
 
-   if (pxe_setup_ctx(, cmdtp, getfile, NULL, true, filename)) {
+   if (pxe_setup_ctx(, cmdtp, sysboot_read_file, , true,
+ filename)) {
printf("Out of memory\n");
return CMD_RET_FAILURE;
}
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 10/18] pxe: Move common parsing coding into pxe_util

2021-10-14 Thread Simon Glass
Both the syslinux and pxe commands use essentially the same code to parse
and run extlinux.conf files. Move this into a common function.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/pxe_utils.c| 20 
 cmd/pxe.c   | 15 ---
 cmd/sysboot.c   | 18 --
 include/pxe_utils.h |  9 +
 4 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 9f3edeab06a..225729ce57f 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -1486,3 +1486,23 @@ void pxe_setup_ctx(struct pxe_context *ctx, struct 
cmd_tbl *cmdtp,
ctx->userdata = userdata;
ctx->allow_abs_path = allow_abs_path;
 }
+
+int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt)
+{
+   struct pxe_menu *cfg;
+
+   cfg = parse_pxefile(ctx, pxefile_addr_r);
+   if (!cfg) {
+   printf("Error parsing config file\n");
+   return 1;
+   }
+
+   if (prompt)
+   cfg->prompt = 1;
+
+   handle_pxe_menu(ctx, cfg);
+
+   destroy_pxe_menu(cfg);
+
+   return 0;
+}
diff --git a/cmd/pxe.c b/cmd/pxe.c
index 17fe364bed9..4fa51d2e053 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -171,9 +171,9 @@ static int
 do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
unsigned long pxefile_addr_r;
-   struct pxe_menu *cfg;
char *pxefile_addr_str;
struct pxe_context ctx;
+   int ret;
 
pxe_setup_ctx(, cmdtp, do_get_tftp, NULL, false);
 
@@ -193,16 +193,9 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
return 1;
}
 
-   cfg = parse_pxefile(, pxefile_addr_r);
-
-   if (!cfg) {
-   printf("Error parsing config file\n");
-   return 1;
-   }
-
-   handle_pxe_menu(, cfg);
-
-   destroy_pxe_menu(cfg);
+   ret = pxe_process(, pxefile_addr_r, false);
+   if (ret)
+   return CMD_RET_FAILURE;
 
copy_filename(net_boot_file_name, "", sizeof(net_boot_file_name));
 
diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index b81255e155a..7ee14df79e5 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -60,10 +60,10 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int 
argc,
 {
unsigned long pxefile_addr_r;
struct pxe_context ctx;
-   struct pxe_menu *cfg;
char *pxefile_addr_str;
char *filename;
int prompt = 0;
+   int ret;
 
if (argc > 1 && strstr(argv[1], "-p")) {
prompt = 1;
@@ -113,19 +113,9 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int 
argc,
return 1;
}
 
-   cfg = parse_pxefile(, pxefile_addr_r);
-
-   if (!cfg) {
-   printf("Error parsing config file\n");
-   return 1;
-   }
-
-   if (prompt)
-   cfg->prompt = 1;
-
-   handle_pxe_menu(, cfg);
-
-   destroy_pxe_menu(cfg);
+   ret = pxe_process(, pxefile_addr_r, prompt);
+   if (ret)
+   return CMD_RET_FAILURE;
 
return 0;
 }
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index 6681442ea55..0cae0dabec3 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -202,4 +202,13 @@ void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl 
*cmdtp,
   pxe_getfile_func getfile, void *userdata,
   bool allow_abs_path);
 
+/**
+ * pxe_process() - Process a PXE file through to boot
+ *
+ * @ctx: PXE context created with pxe_setup_ctx()
+ * @pxefile_addr_r: Address to load file
+ * @prompt: Force a prompt for the user
+ */
+int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt);
+
 #endif /* __PXE_UTILS_H */
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 13/18] lib: Add tests for simple_itoa()

2021-10-14 Thread Simon Glass
Add test and a comment for this function.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/vsprintf.h | 13 -
 test/print_ut.c| 17 +
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/vsprintf.h b/include/vsprintf.h
index 83d187e53d4..4479df0af3f 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -172,7 +172,18 @@ int sprintf(char *buf, const char *fmt, ...)
  * See the vsprintf() documentation for format string extensions over C99.
  */
 int vsprintf(char *buf, const char *fmt, va_list args);
-char *simple_itoa(ulong i);
+
+/**
+ * simple_itoa() - convert an unsigned integer to a string
+ *
+ * This returns a static string containing the decimal representation of the
+ * given value. The returned value may be overwritten by other calls to the
+ * same function, so should be used immediately
+ *
+ * @val: Value to convert
+ * @return string containing the decimal representation of @val
+ */
+char *simple_itoa(ulong val);
 
 /**
  * Format a string and place it in a buffer
diff --git a/test/print_ut.c b/test/print_ut.c
index 11d8580e55c..4fbb15b6d3c 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -328,6 +329,22 @@ static int print_do_hex_dump(struct unit_test_state *uts)
 }
 PRINT_TEST(print_do_hex_dump, UT_TESTF_CONSOLE_REC);
 
+static int print_itoa(struct unit_test_state *uts)
+{
+   ut_asserteq_str("123", simple_itoa(123));
+   ut_asserteq_str("0", simple_itoa(0));
+   ut_asserteq_str("2147483647", simple_itoa(0x7fff));
+   ut_asserteq_str("4294967295", simple_itoa(0x));
+   if (sizeof(ulong) == 8) {
+   ut_asserteq_str("9223372036854775807",
+   simple_itoa((1UL << 63) - 1));
+   ut_asserteq_str("18446744073709551615", simple_itoa(-1));
+   }
+
+   return 0;
+}
+PRINT_TEST(print_itoa, 0);
+
 int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(print_test);
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 11/18] pxe: Clean up the use of bootfile

2021-10-14 Thread Simon Glass
The 'bootfile' environment variable is read in the bowels of pxe_util to
provide a directory to which all loaded files are relative.

This is not obvious from the API to PXE and it is strange to make the
caller set an environment variable rather than pass this as a parameter.

The code is also convoluted, which this feature implemented by
get_bootfile_path().

Update the API to improve this. Unfortunately this means that
pxe_setup_ctx() can fail, so add error checking.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/pxe_utils.c| 60 -
 cmd/pxe.c   | 18 +++---
 cmd/sysboot.c   | 15 +---
 include/pxe_utils.h | 19 +++---
 4 files changed, 79 insertions(+), 33 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 225729ce57f..c04be110ea4 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -67,10 +67,10 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
 /**
  * get_bootfile_path() - Figure out the path of a file to read
  *
- * Returns the directory the file specified in the 'bootfile' env variable is
- * in. If bootfile isn't defined in the environment, return NULL, which should
- * be interpreted as "don't prepend anything to paths".
+ * Copies the boot directory into the supplied buffer. If there is no boot
+ * directory, set it to ""
  *
+ * @ctx: PXE context
  * @file_path: File path to read (relative to the PXE file)
  * @bootfile_path: Place to put the bootfile path
  * @bootfile_path_size: Size of @bootfile_path in bytes
@@ -79,34 +79,25 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
  * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the
  * resulting path
  */
-static int get_bootfile_path(const char *file_path, char *bootfile_path,
-size_t bootfile_path_size, bool allow_abs_path)
+static int get_bootfile_path(struct pxe_context *ctx, const char *file_path,
+char *bootfile_path, size_t bootfile_path_size,
+bool allow_abs_path)
 {
-   char *bootfile, *last_slash;
size_t path_len = 0;
 
/* Only syslinux allows absolute paths */
if (file_path[0] == '/' && allow_abs_path)
goto ret;
 
-   bootfile = from_env("bootfile");
-   if (!bootfile)
-   goto ret;
-
-   last_slash = strrchr(bootfile, '/');
-   if (!last_slash)
-   goto ret;
-
-   path_len = (last_slash - bootfile) + 1;
-
-   if (bootfile_path_size < path_len) {
+   path_len = strlen(ctx->bootdir);
+   if (bootfile_path_size < path_len + 1) {
printf("bootfile_path too small. (%zd < %zd)\n",
   bootfile_path_size, path_len);
 
return -ENOSPC;
}
 
-   strncpy(bootfile_path, bootfile, path_len);
+   strncpy(bootfile_path, ctx->bootdir, path_len);
 
  ret:
bootfile_path[path_len] = '\0';
@@ -135,7 +126,7 @@ static int get_relfile(struct pxe_context *ctx, const char 
*file_path,
char addr_buf[18];
int err;
 
-   err = get_bootfile_path(file_path, relfile, sizeof(relfile),
+   err = get_bootfile_path(ctx, file_path, relfile, sizeof(relfile),
ctx->allow_abs_path);
if (err < 0)
return err;
@@ -1477,14 +1468,39 @@ void handle_pxe_menu(struct pxe_context *ctx, struct 
pxe_menu *cfg)
boot_unattempted_labels(ctx, cfg);
 }
 
-void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-  pxe_getfile_func getfile, void *userdata,
-  bool allow_abs_path)
+int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
+ pxe_getfile_func getfile, void *userdata,
+ bool allow_abs_path, const char *bootfile)
 {
+   const char *last_slash;
+   size_t path_len = 0;
+
+   memset(ctx, '\0', sizeof(*ctx));
ctx->cmdtp = cmdtp;
ctx->getfile = getfile;
ctx->userdata = userdata;
ctx->allow_abs_path = allow_abs_path;
+
+   /* figure out the boot directory, if there is one */
+   if (bootfile && strlen(bootfile) >= MAX_TFTP_PATH_LEN)
+   return -ENOSPC;
+   ctx->bootdir = strdup(bootfile ? bootfile : "");
+   if (!ctx->bootdir)
+   return -ENOMEM;
+
+   if (bootfile) {
+   last_slash = strrchr(bootfile, '/');
+   if (last_slash)
+   path_len = (last_slash - bootfile) + 1;
+   }
+   ctx->bootdir[path_len] = '\0';
+
+   return 0;
+}
+
+void pxe_destroy_ctx(struct pxe_context *ctx)
+{
+   free(ctx->bootdir);
 }
 
 int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt)
diff --git a/cmd/pxe.c b/cmd/pxe.c
index 4fa51d2e053..e319db51ef5 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -121,8 +121,6 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, 

[PATCH v3 12/18] pxe: Drop get_bootfile_path()

2021-10-14 Thread Simon Glass
This function no longer makes sense, since it is pretty easy to prepend
the boot directory to the filename. Drop it and update its only caller.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/pxe_utils.c| 53 +
 include/pxe_utils.h |  3 ++-
 2 files changed, 7 insertions(+), 49 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index c04be110ea4..f36f1f8a60c 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -64,47 +64,6 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
return 1;
 }
 
-/**
- * get_bootfile_path() - Figure out the path of a file to read
- *
- * Copies the boot directory into the supplied buffer. If there is no boot
- * directory, set it to ""
- *
- * @ctx: PXE context
- * @file_path: File path to read (relative to the PXE file)
- * @bootfile_path: Place to put the bootfile path
- * @bootfile_path_size: Size of @bootfile_path in bytes
- * @allow_abs_path: true to allow an absolute path (where @file_path starts 
with
- * '/', false to return an empty path (and success) in that case
- * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the
- * resulting path
- */
-static int get_bootfile_path(struct pxe_context *ctx, const char *file_path,
-char *bootfile_path, size_t bootfile_path_size,
-bool allow_abs_path)
-{
-   size_t path_len = 0;
-
-   /* Only syslinux allows absolute paths */
-   if (file_path[0] == '/' && allow_abs_path)
-   goto ret;
-
-   path_len = strlen(ctx->bootdir);
-   if (bootfile_path_size < path_len + 1) {
-   printf("bootfile_path too small. (%zd < %zd)\n",
-  bootfile_path_size, path_len);
-
-   return -ENOSPC;
-   }
-
-   strncpy(bootfile_path, ctx->bootdir, path_len);
-
- ret:
-   bootfile_path[path_len] = '\0';
-
-   return 1;
-}
-
 /**
  * get_relfile() - read a file relative to the PXE file
  *
@@ -124,15 +83,13 @@ static int get_relfile(struct pxe_context *ctx, const char 
*file_path,
size_t path_len;
char relfile[MAX_TFTP_PATH_LEN + 1];
char addr_buf[18];
-   int err;
 
-   err = get_bootfile_path(ctx, file_path, relfile, sizeof(relfile),
-   ctx->allow_abs_path);
-   if (err < 0)
-   return err;
+   if (file_path[0] == '/' && ctx->allow_abs_path)
+   *relfile = '\0';
+   else
+   strncpy(relfile, ctx->bootdir, MAX_TFTP_PATH_LEN);
 
-   path_len = strlen(file_path);
-   path_len += strlen(relfile);
+   path_len = strlen(file_path) + strlen(relfile);
 
if (path_len > MAX_TFTP_PATH_LEN) {
printf("Base path too long (%s%s)\n", relfile, file_path);
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index 543d0245c8a..8b50f2e6861 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -202,7 +202,8 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  * @allow_abs_path: true to allow absolute paths
  * @bootfile: Bootfile whose directory loaded files are relative to, NULL if
  * none
- * @return 0 if OK, -ENOMEM if out of memory
+ * @return 0 if OK, -ENOMEM if out of memory, -E2BIG if bootfile is larger than
+ * MAX_TFTP_PATH_LEN bytes
  */
 int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
  pxe_getfile_func getfile, void *userdata,
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 08/18] pxe: Tidy up some comments in pxe_utils

2021-10-14 Thread Simon Glass
Some of these functions are a big vague in the comments. Tidy them up a
bit.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/pxe_utils.c | 189 ++-
 1 file changed, 138 insertions(+), 51 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 7d15c75dd87..7a2213a5925 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -30,6 +30,21 @@
 
 #define MAX_TFTP_PATH_LEN 512
 
+/**
+ * format_mac_pxe() - obtain a MAC address in the PXE format
+ *
+ * This produces a MAC-address string in the format for the current ethernet
+ * device:
+ *
+ *   01-aa-bb-cc-dd-ee-ff
+ *
+ * where aa-ff is the MAC address in hex
+ *
+ * @outbuf: Buffer to write string to
+ * @outbuf_len: length of buffer
+ * @return 1 if OK, -ENOSPC if buffer is too small, -ENOENT is there is no
+ * current ethernet device
+ */
 int format_mac_pxe(char *outbuf, size_t outbuf_len)
 {
uchar ethaddr[6];
@@ -37,7 +52,7 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
if (outbuf_len < 21) {
printf("outbuf is too small (%zd < 21)\n", outbuf_len);
 
-   return -EINVAL;
+   return -ENOSPC;
}
 
if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr))
@@ -50,10 +65,20 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
return 1;
 }
 
-/*
- * Returns the directory the file specified in the bootfile env variable is
+/**
+ * get_bootfile_path() - Figure out the path of a file to read
+ *
+ * Returns the directory the file specified in the 'bootfile' env variable is
  * in. If bootfile isn't defined in the environment, return NULL, which should
  * be interpreted as "don't prepend anything to paths".
+ *
+ * @file_path: File path to read (relative to the PXE file)
+ * @bootfile_path: Place to put the bootfile path
+ * @bootfile_path_size: Size of @bootfile_path in bytes
+ * @allow_abs_path: true to allow an absolute path (where @file_path starts 
with
+ * '/', false to return an empty path (and success) in that case
+ * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the
+ * resulting path
  */
 static int get_bootfile_path(const char *file_path, char *bootfile_path,
 size_t bootfile_path_size, bool allow_abs_path)
@@ -81,7 +106,7 @@ static int get_bootfile_path(const char *file_path, char 
*bootfile_path,
printf("bootfile_path too small. (%zd < %zd)\n",
   bootfile_path_size, path_len);
 
-   return -1;
+   return -ENOSPC;
}
 
strncpy(bootfile_path, bootfile, path_len);
@@ -92,13 +117,18 @@ static int get_bootfile_path(const char *file_path, char 
*bootfile_path,
return 1;
 }
 
-/*
+/**
+ * get_relfile() - read a file relative to the PXE file
+ *
  * As in pxelinux, paths to files referenced from files we retrieve are
  * relative to the location of bootfile. get_relfile takes such a path and
  * joins it with the bootfile path to get the full path to the target file. If
  * the bootfile path is NULL, we use file_path as is.
  *
- * Returns 1 for success, or < 0 on error.
+ * @ctx: PXE context
+ * @file_path: File path to read (relative to the PXE file)
+ * @file_addr: Address to load file to
+ * Returns 1 for success, or < 0 on error
  */
 static int get_relfile(struct pxe_context *ctx, const char *file_path,
   unsigned long file_addr)
@@ -132,6 +162,16 @@ static int get_relfile(struct pxe_context *ctx, const char 
*file_path,
return ctx->getfile(ctx, relfile, addr_buf);
 }
 
+/**
+ * get_pxe_file() - read a file
+ *
+ * The file is read and nul-terminated
+ *
+ * @ctx: PXE context
+ * @file_path: File path to read (relative to the PXE file)
+ * @file_addr: Address to load file to
+ * Returns 1 for success, or < 0 on error
+ */
 int get_pxe_file(struct pxe_context *ctx, const char *file_path,
 unsigned long file_addr)
 {
@@ -166,6 +206,14 @@ int get_pxe_file(struct pxe_context *ctx, const char 
*file_path,
 
 #define PXELINUX_DIR "pxelinux.cfg/"
 
+/**
+ * get_pxelinux_path() - Get a file in the pxelinux.cfg/ directory
+ *
+ * @ctx: PXE context
+ * @file: Filename to process (relative to pxelinux.cfg/)
+ * Returns 1 for success, -ENAMETOOLONG if the resulting path is too long.
+ * or other value < 0 on other error
+ */
 int get_pxelinux_path(struct pxe_context *ctx, const char *file,
  unsigned long pxefile_addr_r)
 {
@@ -183,12 +231,20 @@ int get_pxelinux_path(struct pxe_context *ctx, const char 
*file,
return get_pxe_file(ctx, path, pxefile_addr_r);
 }
 
-/*
+/**
+ * get_relfile_envaddr() - read a file to an address in an env var
+ *
  * Wrapper to make it easier to store the file at file_path in the location
  * specified by envaddr_name. file_path will be joined to the bootfile path,
  * if any is specified.
  *
- * Returns 1 on success or < 0 on error.
+ * 

[PATCH v3 09/18] pxe: Tidy up code style a little in pxe_utils

2021-10-14 Thread Simon Glass
There are a few more blank lines than makes sense for readability. Also
free() handles a NULL pointer so drop the pointless checks.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/pxe_utils.c | 66 ++--
 1 file changed, 13 insertions(+), 53 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 7a2213a5925..9f3edeab06a 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -51,7 +51,6 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
 
if (outbuf_len < 21) {
printf("outbuf is too small (%zd < 21)\n", outbuf_len);
-
return -ENOSPC;
}
 
@@ -91,12 +90,10 @@ static int get_bootfile_path(const char *file_path, char 
*bootfile_path,
goto ret;
 
bootfile = from_env("bootfile");
-
if (!bootfile)
goto ret;
 
last_slash = strrchr(bootfile, '/');
-
if (!last_slash)
goto ret;
 
@@ -140,7 +137,6 @@ static int get_relfile(struct pxe_context *ctx, const char 
*file_path,
 
err = get_bootfile_path(file_path, relfile, sizeof(relfile),
ctx->allow_abs_path);
-
if (err < 0)
return err;
 
@@ -181,7 +177,6 @@ int get_pxe_file(struct pxe_context *ctx, const char 
*file_path,
char *buf;
 
err = get_relfile(ctx, file_path, file_addr);
-
if (err < 0)
return err;
 
@@ -190,7 +185,6 @@ int get_pxe_file(struct pxe_context *ctx, const char 
*file_path,
 * and add the NUL byte.
 */
tftp_filesize = from_env("filesize");
-
if (!tftp_filesize)
return -ENOENT;
 
@@ -253,7 +247,6 @@ static int get_relfile_envaddr(struct pxe_context *ctx, 
const char *file_path,
char *envaddr;
 
envaddr = from_env(envaddr_name);
-
if (!envaddr)
return -ENOENT;
 
@@ -276,7 +269,6 @@ static struct pxe_label *label_create(void)
struct pxe_label *label;
 
label = malloc(sizeof(struct pxe_label));
-
if (!label)
return NULL;
 
@@ -300,30 +292,14 @@ static struct pxe_label *label_create(void)
  */
 static void label_destroy(struct pxe_label *label)
 {
-   if (label->name)
-   free(label->name);
-
-   if (label->kernel)
-   free(label->kernel);
-
-   if (label->config)
-   free(label->config);
-
-   if (label->append)
-   free(label->append);
-
-   if (label->initrd)
-   free(label->initrd);
-
-   if (label->fdt)
-   free(label->fdt);
-
-   if (label->fdtdir)
-   free(label->fdtdir);
-
-   if (label->fdtoverlays)
-   free(label->fdtoverlays);
-
+   free(label->name);
+   free(label->kernel);
+   free(label->config);
+   free(label->append);
+   free(label->initrd);
+   free(label->fdt);
+   free(label->fdtdir);
+   free(label->fdtoverlays);
free(label);
 }
 
@@ -359,7 +335,6 @@ static int label_localboot(struct pxe_label *label)
char *localcmd;
 
localcmd = from_env("localcmd");
-
if (!localcmd)
return -ENOENT;
 
@@ -718,8 +693,8 @@ static int label_boot(struct pxe_context *ctx, struct 
pxe_label *label)
unmap_sysmem(buf);
 
 cleanup:
-   if (fit_addr)
-   free(fit_addr);
+   free(fit_addr);
+
return 1;
 }
 
@@ -832,7 +807,6 @@ static char *get_string(char **p, struct token *t, char 
delim, int lower)
 */
b = *p;
e = *p;
-
while (*e) {
if ((delim == ' ' && isspace(*e)) || delim == *e)
break;
@@ -858,11 +832,8 @@ static char *get_string(char **p, struct token *t, char 
delim, int lower)
 
t->val[len] = '\0';
 
-   /*
-* Update *p so the caller knows where to continue scanning.
-*/
+   /* Update *p so the caller knows where to continue scanning */
*p = e;
-
t->type = T_STRING;
 
return t->val;
@@ -988,7 +959,6 @@ static int parse_integer(char **c, int *dst)
char *s = *c;
 
get_token(c, , L_SLITERAL);
-
if (t.type != T_STRING) {
printf("Expected string: %.*s\n", (int)(*c - s), s);
return -EINVAL;
@@ -1022,14 +992,12 @@ static int handle_include(struct pxe_context *ctx, char 
**c, unsigned long base,
int ret;
 
err = parse_sliteral(c, _path);
-
if (err < 0) {
printf("Expected include path: %.*s\n", (int)(*c - s), s);
return err;
}
 
err = get_pxe_file(ctx, include_path, base);
-
if (err < 0) {
printf("Couldn't retrieve %s\n", include_path);
return err;
@@ -1079,7 +1047,6 @@ static int parse_menu(struct pxe_context *ctx, char **c, 
struct pxe_menu *cfg,
printf("Ignoring malformed menu command: 

[PATCH v3 07/18] pxe: Move pxe_utils files

2021-10-14 Thread Simon Glass
Move the header file into the main include/ directory so we can use it
from the bootmethod code. Move the C file into boot/ since it relates to
booting.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Makefile| 3 +++
 {cmd => boot}/pxe_utils.c| 0
 cmd/Makefile | 4 ++--
 cmd/sysboot.c| 2 +-
 {cmd => include}/pxe_utils.h | 0
 5 files changed, 6 insertions(+), 3 deletions(-)
 rename {cmd => boot}/pxe_utils.c (100%)
 rename {cmd => include}/pxe_utils.h (100%)

diff --git a/boot/Makefile b/boot/Makefile
index a19e85cf6c8..2938c3f1458 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -14,6 +14,9 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o bootm_os.o
 obj-$(CONFIG_CMD_BOOTZ) += bootm.o bootm_os.o
 obj-$(CONFIG_CMD_BOOTI) += bootm.o bootm_os.o
 
+obj-$(CONFIG_CMD_PXE) += pxe_utils.o
+obj-$(CONFIG_CMD_SYSBOOT) += pxe_utils.o
+
 endif
 
 obj-y += image.o image-board.o
diff --git a/cmd/pxe_utils.c b/boot/pxe_utils.c
similarity index 100%
rename from cmd/pxe_utils.c
rename to boot/pxe_utils.c
diff --git a/cmd/Makefile b/cmd/Makefile
index ed3669411e6..891819ae0f6 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -123,7 +123,7 @@ obj-$(CONFIG_CMD_PINMUX) += pinmux.o
 obj-$(CONFIG_CMD_PMC) += pmc.o
 obj-$(CONFIG_CMD_PSTORE) += pstore.o
 obj-$(CONFIG_CMD_PWM) += pwm.o
-obj-$(CONFIG_CMD_PXE) += pxe.o pxe_utils.o
+obj-$(CONFIG_CMD_PXE) += pxe.o
 obj-$(CONFIG_CMD_WOL) += wol.o
 obj-$(CONFIG_CMD_QFW) += qfw.o
 obj-$(CONFIG_CMD_READ) += read.o
@@ -145,7 +145,7 @@ obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o
 obj-$(CONFIG_CMD_SPI) += spi.o
 obj-$(CONFIG_CMD_STRINGS) += strings.o
 obj-$(CONFIG_CMD_SMC) += smccc.o
-obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o pxe_utils.o
+obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o
 obj-$(CONFIG_CMD_STACKPROTECTOR_TEST) += stackprot_test.o
 obj-$(CONFIG_CMD_TERMINAL) += terminal.o
 obj-$(CONFIG_CMD_TIME) += time.o
diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index 85fa5d8aa01..b81255e155a 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -4,7 +4,7 @@
 #include 
 #include 
 #include 
-#include "pxe_utils.h"
+#include 
 
 static char *fs_argv[5];
 
diff --git a/cmd/pxe_utils.h b/include/pxe_utils.h
similarity index 100%
rename from cmd/pxe_utils.h
rename to include/pxe_utils.h
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 06/18] pxe: Tidy up the is_pxe global

2021-10-14 Thread Simon Glass
Move this into the context to avoid a global variable. Also rename it
since the current name does not explain what it actually affects.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/pxe.c   |  6 ++
 cmd/pxe_utils.c | 13 +++--
 cmd/pxe_utils.h |  8 +---
 cmd/sysboot.c   |  4 +---
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/cmd/pxe.c b/cmd/pxe.c
index d79b9b733d7..17fe364bed9 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -121,7 +121,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
struct pxe_context ctx;
int err, i = 0;
 
-   pxe_setup_ctx(, cmdtp, do_get_tftp, NULL);
+   pxe_setup_ctx(, cmdtp, do_get_tftp, NULL, false);
 
if (argc != 1)
return CMD_RET_USAGE;
@@ -175,7 +175,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
char *pxefile_addr_str;
struct pxe_context ctx;
 
-   pxe_setup_ctx(, cmdtp, do_get_tftp, NULL);
+   pxe_setup_ctx(, cmdtp, do_get_tftp, NULL, false);
 
if (argc == 1) {
pxefile_addr_str = from_env("pxefile_addr_r");
@@ -235,8 +235,6 @@ static int do_pxe(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
if (argc < 2)
return CMD_RET_USAGE;
 
-   is_pxe = true;
-
/* drop initial "pxe" arg */
argc--;
argv++;
diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
index 5ad6d3e3d44..7d15c75dd87 100644
--- a/cmd/pxe_utils.c
+++ b/cmd/pxe_utils.c
@@ -30,8 +30,6 @@
 
 #define MAX_TFTP_PATH_LEN 512
 
-bool is_pxe;
-
 int format_mac_pxe(char *outbuf, size_t outbuf_len)
 {
uchar ethaddr[6];
@@ -58,13 +56,13 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
  * be interpreted as "don't prepend anything to paths".
  */
 static int get_bootfile_path(const char *file_path, char *bootfile_path,
-size_t bootfile_path_size)
+size_t bootfile_path_size, bool allow_abs_path)
 {
char *bootfile, *last_slash;
size_t path_len = 0;
 
/* Only syslinux allows absolute paths */
-   if (file_path[0] == '/' && !is_pxe)
+   if (file_path[0] == '/' && allow_abs_path)
goto ret;
 
bootfile = from_env("bootfile");
@@ -110,7 +108,8 @@ static int get_relfile(struct pxe_context *ctx, const char 
*file_path,
char addr_buf[18];
int err;
 
-   err = get_bootfile_path(file_path, relfile, sizeof(relfile));
+   err = get_bootfile_path(file_path, relfile, sizeof(relfile),
+   ctx->allow_abs_path);
 
if (err < 0)
return err;
@@ -1432,9 +1431,11 @@ void handle_pxe_menu(struct pxe_context *ctx, struct 
pxe_menu *cfg)
 }
 
 void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-  pxe_getfile_func getfile, void *userdata)
+  pxe_getfile_func getfile, void *userdata,
+  bool allow_abs_path)
 {
ctx->cmdtp = cmdtp;
ctx->getfile = getfile;
ctx->userdata = userdata;
+   ctx->allow_abs_path = allow_abs_path;
 }
diff --git a/cmd/pxe_utils.h b/cmd/pxe_utils.h
index 921455f694e..6681442ea55 100644
--- a/cmd/pxe_utils.h
+++ b/cmd/pxe_utils.h
@@ -75,8 +75,6 @@ struct pxe_menu {
struct list_head labels;
 };
 
-extern bool is_pxe;
-
 struct pxe_context;
 typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
char *file_addr);
@@ -87,6 +85,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, 
const char *file_path,
  * @cmdtp: Pointer to command table to use when calling other commands
  * @getfile: Function called by PXE to read a file
  * @userdata: Data the caller requires for @getfile
+ * @allow_abs_path: true to allow absolute paths
  */
 struct pxe_context {
struct cmd_tbl *cmdtp;
@@ -102,6 +101,7 @@ struct pxe_context {
pxe_getfile_func getfile;
 
void *userdata;
+   bool allow_abs_path;
 };
 
 /**
@@ -196,8 +196,10 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  * @cmdtp: Command table entry which started this action
  * @getfile: Function to call to read a file
  * @userdata: Data the caller requires for @getfile - stored in ctx->userdata
+ * @allow_abs_path: true to allow absolute paths
  */
 void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-  pxe_getfile_func getfile, void *userdata);
+  pxe_getfile_func getfile, void *userdata,
+  bool allow_abs_path);
 
 #endif /* __PXE_UTILS_H */
diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index 5615e81e9ca..85fa5d8aa01 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -65,8 +65,6 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int 
argc,
char *filename;
int prompt = 0;
 
-   is_pxe = false;
-
if (argc > 1 && strstr(argv[1], "-p")) {

[PATCH v3 03/18] pxe: Use a context pointer

2021-10-14 Thread Simon Glass
At present the PXE functions pass around a pointer to command-table entry
which is very strange. It is only needed in a few places and it is odd to
pass around a data structure from another module in this way.

For bootmethod we will need to provide some context information when
reading files.

Create a PXE context struct to hold the command-table-entry pointer and
pass that around instead. We can then add more things to the context as
needed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/pxe.c   | 28 +
 cmd/pxe_utils.c | 80 ++---
 cmd/pxe_utils.h | 43 +++---
 cmd/sysboot.c   |  8 +++--
 4 files changed, 97 insertions(+), 62 deletions(-)

diff --git a/cmd/pxe.c b/cmd/pxe.c
index 46ac08fa3a0..17ce54fc049 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -43,7 +43,7 @@ static int do_get_tftp(struct cmd_tbl *cmdtp, const char 
*file_path,
  *
  * Returns 1 on success or < 0 on error.
  */
-static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
+static int pxe_uuid_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
 {
char *uuid_str;
 
@@ -52,7 +52,7 @@ static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long 
pxefile_addr_r)
if (!uuid_str)
return -ENOENT;
 
-   return get_pxelinux_path(cmdtp, uuid_str, pxefile_addr_r);
+   return get_pxelinux_path(ctx, uuid_str, pxefile_addr_r);
 }
 
 /*
@@ -61,7 +61,7 @@ static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long 
pxefile_addr_r)
  *
  * Returns 1 on success or < 0 on error.
  */
-static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
+static int pxe_mac_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
 {
char mac_str[21];
int err;
@@ -71,7 +71,7 @@ static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long 
pxefile_addr_r)
if (err < 0)
return err;
 
-   return get_pxelinux_path(cmdtp, mac_str, pxefile_addr_r);
+   return get_pxelinux_path(ctx, mac_str, pxefile_addr_r);
 }
 
 /*
@@ -81,7 +81,7 @@ static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long 
pxefile_addr_r)
  *
  * Returns 1 on success or < 0 on error.
  */
-static int pxe_ipaddr_paths(struct cmd_tbl *cmdtp, unsigned long 
pxefile_addr_r)
+static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long 
pxefile_addr_r)
 {
char ip_addr[9];
int mask_pos, err;
@@ -89,7 +89,7 @@ static int pxe_ipaddr_paths(struct cmd_tbl *cmdtp, unsigned 
long pxefile_addr_r)
sprintf(ip_addr, "%08X", ntohl(net_ip.s_addr));
 
for (mask_pos = 7; mask_pos >= 0;  mask_pos--) {
-   err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r);
+   err = get_pxelinux_path(ctx, ip_addr, pxefile_addr_r);
 
if (err > 0)
return err;
@@ -118,8 +118,10 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
 {
char *pxefile_addr_str;
unsigned long pxefile_addr_r;
+   struct pxe_context ctx;
int err, i = 0;
 
+   pxe_setup_ctx(, cmdtp);
do_getfile = do_get_tftp;
 
if (argc != 1)
@@ -139,16 +141,16 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
 * Keep trying paths until we successfully get a file we're looking
 * for.
 */
-   if (pxe_uuid_path(cmdtp, pxefile_addr_r) > 0 ||
-   pxe_mac_path(cmdtp, pxefile_addr_r) > 0 ||
-   pxe_ipaddr_paths(cmdtp, pxefile_addr_r) > 0) {
+   if (pxe_uuid_path(, pxefile_addr_r) > 0 ||
+   pxe_mac_path(, pxefile_addr_r) > 0 ||
+   pxe_ipaddr_paths(, pxefile_addr_r) > 0) {
printf("Config file found\n");
 
return 0;
}
 
while (pxe_default_paths[i]) {
-   if (get_pxelinux_path(cmdtp, pxe_default_paths[i],
+   if (get_pxelinux_path(, pxe_default_paths[i],
  pxefile_addr_r) > 0) {
printf("Config file found\n");
return 0;
@@ -172,7 +174,9 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
unsigned long pxefile_addr_r;
struct pxe_menu *cfg;
char *pxefile_addr_str;
+   struct pxe_context ctx;
 
+   pxe_setup_ctx(, cmdtp);
do_getfile = do_get_tftp;
 
if (argc == 1) {
@@ -191,14 +195,14 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
return 1;
}
 
-   cfg = parse_pxefile(cmdtp, pxefile_addr_r);
+   cfg = parse_pxefile(, pxefile_addr_r);
 
if (!cfg) {
printf("Error parsing config file\n");
return 1;
}
 
-   handle_pxe_menu(cmdtp, cfg);
+   handle_pxe_menu(, cfg);
 
destroy_pxe_menu(cfg);
 
diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
index 

[PATCH v3 02/18] pxe: Move API comments to the header files

2021-10-14 Thread Simon Glass
Put the function comments in the header file so that the full API can we
examined in one place.

Expand the comments to cover parameters and return values.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/pxe_utils.c | 45 -
 cmd/pxe_utils.h | 77 +++--
 2 files changed, 74 insertions(+), 48 deletions(-)

diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
index 067c24e5ff4..d7f4017efeb 100644
--- a/cmd/pxe_utils.c
+++ b/cmd/pxe_utils.c
@@ -32,16 +32,6 @@
 
 bool is_pxe;
 
-/*
- * Convert an ethaddr from the environment to the format used by pxelinux
- * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to
- * the beginning of the ethernet address to indicate a hardware type of
- * Ethernet. Also converts uppercase hex characters into lowercase, to match
- * pxelinux's behavior.
- *
- * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the
- * environment, or some other value < 0 on error.
- */
 int format_mac_pxe(char *outbuf, size_t outbuf_len)
 {
uchar ethaddr[6];
@@ -146,13 +136,6 @@ static int get_relfile(struct cmd_tbl *cmdtp, const char 
*file_path,
return do_getfile(cmdtp, relfile, addr_buf);
 }
 
-/*
- * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
- * 'bootfile' was specified in the environment, the path to bootfile will be
- * prepended to 'file_path' and the resulting path will be used.
- *
- * Returns 1 on success, or < 0 for error.
- */
 int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
 unsigned long file_addr)
 {
@@ -187,13 +170,6 @@ int get_pxe_file(struct cmd_tbl *cmdtp, const char 
*file_path,
 
 #define PXELINUX_DIR "pxelinux.cfg/"
 
-/*
- * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file
- * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
- * from the bootfile path, as described above.
- *
- * Returns 1 on success or < 0 on error.
- */
 int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
  unsigned long pxefile_addr_r)
 {
@@ -1309,15 +1285,6 @@ void destroy_pxe_menu(struct pxe_menu *cfg)
free(cfg);
 }
 
-/*
- * Entry point for parsing a pxe file. This is only used for the top level
- * file.
- *
- * Returns NULL if there is an error, otherwise, returns a pointer to a
- * pxe_menu struct populated with the results of parsing the pxe file (and any
- * files it includes). The resulting pxe_menu struct can be free()'d by using
- * the destroy_pxe_menu() function.
- */
 struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, unsigned long menucfg)
 {
struct pxe_menu *cfg;
@@ -1415,18 +1382,6 @@ static void boot_unattempted_labels(struct cmd_tbl 
*cmdtp, struct pxe_menu *cfg)
}
 }
 
-/*
- * Boot the system as prescribed by a pxe_menu.
- *
- * Use the menu system to either get the user's choice or the default, based
- * on config or user input.  If there is no default or user's choice,
- * attempted to boot labels in the order they were given in pxe files.
- * If the default or user's choice fails to boot, attempt to boot other
- * labels in the order they were given in pxe files.
- *
- * If this function returns, there weren't any labels that successfully
- * booted, or the user interrupted the menu selection via ctrl+c.
- */
 void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
 {
void *choice;
diff --git a/cmd/pxe_utils.h b/cmd/pxe_utils.h
index bf58e15347c..441beefa2bc 100644
--- a/cmd/pxe_utils.h
+++ b/cmd/pxe_utils.h
@@ -80,12 +80,83 @@ extern bool is_pxe;
 extern int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
 char *file_addr);
 void destroy_pxe_menu(struct pxe_menu *cfg);
+
+/**
+ * get_pxe_file() - Read a file
+ *
+ * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If
+ * 'bootfile' was specified in the environment, the path to bootfile will be
+ * prepended to 'file_path' and the resulting path will be used.
+ *
+ * @cmdtp: Pointer to command-table entry for the initiating command
+ * @file_path: Path to file
+ * @file_addr: Address to place file
+ * Returns 1 on success, or < 0 for error
+ */
 int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
-unsigned long file_addr);
+ulong file_addr);
+
+/**
+ * get_pxelinux_path() - Read a file from the same place as pxelinux.cfg
+ *
+ * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses 
get_pxe_file()
+ * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
+ * from the bootfile path, as described in get_pxe_file().
+ *
+ * @cmdtp: Pointer to command-table entry for the initiating command
+ * @file: Relative path to file
+ * @pxefile_addr_r: Address to load file
+ * Returns 1 on success or < 0 on error.
+ */
 int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
- 

[PATCH v3 04/18] pxe: Move do_getfile() into the context

2021-10-14 Thread Simon Glass
Rather than having a global variable, pass the function as part of the
context.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/pxe.c   | 10 --
 cmd/pxe_utils.c |  9 -
 cmd/pxe_utils.h | 20 +---
 cmd/sysboot.c   | 20 ++--
 4 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/cmd/pxe.c b/cmd/pxe.c
index 17ce54fc049..70dbde3a636 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -24,7 +24,7 @@ const char *pxe_default_paths[] = {
NULL
 };
 
-static int do_get_tftp(struct cmd_tbl *cmdtp, const char *file_path,
+static int do_get_tftp(struct pxe_context *ctx, const char *file_path,
   char *file_addr)
 {
char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
@@ -32,7 +32,7 @@ static int do_get_tftp(struct cmd_tbl *cmdtp, const char 
*file_path,
tftp_argv[1] = file_addr;
tftp_argv[2] = (void *)file_path;
 
-   if (do_tftpb(cmdtp, 0, 3, tftp_argv))
+   if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv))
return -ENOENT;
 
return 1;
@@ -121,8 +121,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
struct pxe_context ctx;
int err, i = 0;
 
-   pxe_setup_ctx(, cmdtp);
-   do_getfile = do_get_tftp;
+   pxe_setup_ctx(, cmdtp, do_get_tftp);
 
if (argc != 1)
return CMD_RET_USAGE;
@@ -176,8 +175,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
char *pxefile_addr_str;
struct pxe_context ctx;
 
-   pxe_setup_ctx(, cmdtp);
-   do_getfile = do_get_tftp;
+   pxe_setup_ctx(, cmdtp, do_get_tftp);
 
if (argc == 1) {
pxefile_addr_str = from_env("pxefile_addr_r");
diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
index 280be55d9b3..2caae6d1555 100644
--- a/cmd/pxe_utils.c
+++ b/cmd/pxe_utils.c
@@ -94,9 +94,6 @@ static int get_bootfile_path(const char *file_path, char 
*bootfile_path,
return 1;
 }
 
-int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
- char *file_addr);
-
 /*
  * As in pxelinux, paths to files referenced from files we retrieve are
  * relative to the location of bootfile. get_relfile takes such a path and
@@ -133,7 +130,7 @@ static int get_relfile(struct pxe_context *ctx, const char 
*file_path,
 
sprintf(addr_buf, "%lx", file_addr);
 
-   return do_getfile(ctx->cmdtp, relfile, addr_buf);
+   return ctx->getfile(ctx, relfile, addr_buf);
 }
 
 int get_pxe_file(struct pxe_context *ctx, const char *file_path,
@@ -1434,7 +1431,9 @@ void handle_pxe_menu(struct pxe_context *ctx, struct 
pxe_menu *cfg)
boot_unattempted_labels(ctx, cfg);
 }
 
-void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp)
+void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
+  pxe_getfile_func getfile)
 {
ctx->cmdtp = cmdtp;
+   ctx->getfile = getfile;
 }
diff --git a/cmd/pxe_utils.h b/cmd/pxe_utils.h
index cd0d3371765..ca2696f48b0 100644
--- a/cmd/pxe_utils.h
+++ b/cmd/pxe_utils.h
@@ -77,16 +77,28 @@ struct pxe_menu {
 
 extern bool is_pxe;
 
-extern int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
-char *file_addr);
+struct pxe_context;
+typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
+   char *file_addr);
 
 /**
  * struct pxe_context - context information for PXE parsing
  *
  * @cmdtp: Pointer to command table to use when calling other commands
+ * @getfile: Function called by PXE to read a file
  */
 struct pxe_context {
struct cmd_tbl *cmdtp;
+   /**
+* getfile() - read a file
+*
+* @ctx: PXE context
+* @file_path: Path to the file
+* @file_addr: String containing the hex address to put the file in
+*  memory
+* Return 0 if OK, -ve on error
+*/
+   pxe_getfile_func getfile;
 };
 
 /**
@@ -179,7 +191,9 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  *
  * @ctx: Context to set up
  * @cmdtp: Command table entry which started this action
+ * @getfile: Function to call to read a file
  */
-void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp);
+void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
+  pxe_getfile_func getfile);
 
 #endif /* __PXE_UTILS_H */
diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index 9ba713c8aae..082f23543d1 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -8,7 +8,7 @@
 
 static char *fs_argv[5];
 
-static int do_get_ext2(struct cmd_tbl *cmdtp, const char *file_path,
+static int do_get_ext2(struct pxe_context *ctx, const char *file_path,
   char *file_addr)
 {
 #ifdef CONFIG_CMD_EXT2
@@ -16,13 +16,13 @@ static int do_get_ext2(struct cmd_tbl *cmdtp, const char 
*file_path,
fs_argv[3] = file_addr;
fs_argv[4] = (void *)file_path;
 
-   if 

[PATCH v3 05/18] pxe: Add a userdata field to the context

2021-10-14 Thread Simon Glass
Allow the caller to provide some info which is passed back to the
readfile() method.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/pxe.c   | 4 ++--
 cmd/pxe_utils.c | 3 ++-
 cmd/pxe_utils.h | 6 +-
 cmd/sysboot.c   | 2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/cmd/pxe.c b/cmd/pxe.c
index 70dbde3a636..d79b9b733d7 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -121,7 +121,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
struct pxe_context ctx;
int err, i = 0;
 
-   pxe_setup_ctx(, cmdtp, do_get_tftp);
+   pxe_setup_ctx(, cmdtp, do_get_tftp, NULL);
 
if (argc != 1)
return CMD_RET_USAGE;
@@ -175,7 +175,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
char *pxefile_addr_str;
struct pxe_context ctx;
 
-   pxe_setup_ctx(, cmdtp, do_get_tftp);
+   pxe_setup_ctx(, cmdtp, do_get_tftp, NULL);
 
if (argc == 1) {
pxefile_addr_str = from_env("pxefile_addr_r");
diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
index 2caae6d1555..5ad6d3e3d44 100644
--- a/cmd/pxe_utils.c
+++ b/cmd/pxe_utils.c
@@ -1432,8 +1432,9 @@ void handle_pxe_menu(struct pxe_context *ctx, struct 
pxe_menu *cfg)
 }
 
 void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-  pxe_getfile_func getfile)
+  pxe_getfile_func getfile, void *userdata)
 {
ctx->cmdtp = cmdtp;
ctx->getfile = getfile;
+   ctx->userdata = userdata;
 }
diff --git a/cmd/pxe_utils.h b/cmd/pxe_utils.h
index ca2696f48b0..921455f694e 100644
--- a/cmd/pxe_utils.h
+++ b/cmd/pxe_utils.h
@@ -86,6 +86,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, 
const char *file_path,
  *
  * @cmdtp: Pointer to command table to use when calling other commands
  * @getfile: Function called by PXE to read a file
+ * @userdata: Data the caller requires for @getfile
  */
 struct pxe_context {
struct cmd_tbl *cmdtp;
@@ -99,6 +100,8 @@ struct pxe_context {
 * Return 0 if OK, -ve on error
 */
pxe_getfile_func getfile;
+
+   void *userdata;
 };
 
 /**
@@ -192,8 +195,9 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  * @ctx: Context to set up
  * @cmdtp: Command table entry which started this action
  * @getfile: Function to call to read a file
+ * @userdata: Data the caller requires for @getfile - stored in ctx->userdata
  */
 void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
-  pxe_getfile_func getfile);
+  pxe_getfile_func getfile, void *userdata);
 
 #endif /* __PXE_UTILS_H */
diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index 082f23543d1..5615e81e9ca 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -91,7 +91,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int 
argc,
env_set("bootfile", filename);
}
 
-   pxe_setup_ctx(, cmdtp, NULL);
+   pxe_setup_ctx(, cmdtp, NULL, NULL);
if (strstr(argv[3], "ext2")) {
ctx.getfile = do_get_ext2;
} else if (strstr(argv[3], "fat")) {
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 01/18] Create a new boot/ directory

2021-10-14 Thread Simon Glass
Quite a lot of the code in common/relates to booting and images. Before
adding more it seems like a good time to move the code into its own
directory.

Most files with 'boot' or 'image' in them are moved, except:

- autoboot.c which relates to U-Boot automatically running a script
- bootstage.c which relates to U-Boot timing

Drop the removal of boot* files from the output directory, since this
interfers with the symlinks created by tools and there does not appear
to be any such file from my brief testing.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Kconfig |  2 ++
 Makefile|  3 ++-
 README  |  1 +
 common/Kconfig.boot => boot/Kconfig |  0
 boot/Makefile   | 34 +
 {common => boot}/android_ab.c   |  0
 {common => boot}/boot_fit.c |  0
 {common => boot}/bootm.c|  0
 {common => boot}/bootm_os.c |  0
 {common => boot}/bootretry.c|  0
 {common => boot}/common_fit.c   |  0
 {common => boot}/fdt_region.c   |  0
 {common => boot}/image-android-dt.c |  0
 {common => boot}/image-android.c|  0
 {common => boot}/image-board.c  |  0
 {common => boot}/image-cipher.c |  0
 {common => boot}/image-fdt.c|  0
 {common => boot}/image-fit-sig.c|  0
 {common => boot}/image-fit.c|  0
 {common => boot}/image-host.c   |  0
 {common => boot}/image-sig.c|  0
 {common => boot}/image.c|  0
 common/Kconfig  |  2 --
 common/Makefile | 22 ---
 doc/android/boot-image.rst  |  2 +-
 scripts/Makefile.spl|  4 ++--
 tools/Makefile  | 18 +++
 27 files changed, 51 insertions(+), 37 deletions(-)
 rename common/Kconfig.boot => boot/Kconfig (100%)
 create mode 100644 boot/Makefile
 rename {common => boot}/android_ab.c (100%)
 rename {common => boot}/boot_fit.c (100%)
 rename {common => boot}/bootm.c (100%)
 rename {common => boot}/bootm_os.c (100%)
 rename {common => boot}/bootretry.c (100%)
 rename {common => boot}/common_fit.c (100%)
 rename {common => boot}/fdt_region.c (100%)
 rename {common => boot}/image-android-dt.c (100%)
 rename {common => boot}/image-android.c (100%)
 rename {common => boot}/image-board.c (100%)
 rename {common => boot}/image-cipher.c (100%)
 rename {common => boot}/image-fdt.c (100%)
 rename {common => boot}/image-fit-sig.c (100%)
 rename {common => boot}/image-fit.c (100%)
 rename {common => boot}/image-host.c (100%)
 rename {common => boot}/image-sig.c (100%)
 rename {common => boot}/image.c (100%)

diff --git a/Kconfig b/Kconfig
index 931a22806e4..c46f4fce862 100644
--- a/Kconfig
+++ b/Kconfig
@@ -466,6 +466,8 @@ endmenu # General setup
 
 source "api/Kconfig"
 
+source "boot/Kconfig"
+
 source "common/Kconfig"
 
 source "cmd/Kconfig"
diff --git a/Makefile b/Makefile
index f911f703443..4e064acdcff 100644
--- a/Makefile
+++ b/Makefile
@@ -804,6 +804,7 @@ HAVE_VENDOR_COMMON_LIB = $(if $(wildcard 
$(srctree)/board/$(VENDOR)/common/Makef
 
 libs-$(CONFIG_API) += api/
 libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
+libs-y += boot/
 libs-y += cmd/
 libs-y += common/
 libs-$(CONFIG_OF_EMBED) += dts/
@@ -2076,7 +2077,7 @@ CLEAN_DIRS  += $(MODVERDIR) \
$(filter-out include, $(shell ls -1 $d 2>/dev/null
 
 CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h tools/version.h \
-  boot* u-boot* MLO* SPL System.map fit-dtb.blob* \
+  u-boot* MLO* SPL System.map fit-dtb.blob* \
   u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log \
   lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* \
   idbloader.img flash.bin flash.log defconfig keep-syms-lto.c
diff --git a/README b/README
index 840b192aae5..49c79ca6a2d 100644
--- a/README
+++ b/README
@@ -144,6 +144,7 @@ Directory Hierarchy:
   /xtensa  Files generic to Xtensa architecture
 /api   Machine/arch-independent API for external apps
 /board Board-dependent files
+/boot  Support for images and booting
 /cmd   U-Boot commands functions
 /commonMisc architecture-independent functions
 /configs   Board default configuration files
diff --git a/common/Kconfig.boot b/boot/Kconfig
similarity index 100%
rename from common/Kconfig.boot
rename to boot/Kconfig
diff --git a/boot/Makefile b/boot/Makefile
new file mode 100644
index 000..a19e85cf6c8
--- /dev/null
+++ b/boot/Makefile
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2004-2006
+# Wolfgang Denk, DENX Software Engineering, w...@denx.de.
+
+ifndef CONFIG_SPL_BUILD
+
+# This option is not just y/n - it can have a numeric value
+ifdef CONFIG_BOOT_RETRY_TIME
+obj-y += bootretry.o
+endif
+

[PATCH v3 00/18] pxe: Refactoring to tidy up and prepare for bootflow

2021-10-14 Thread Simon Glass
This collects together the patches previously sent relating to PXE.

Firstly, it moves the boot code out of common/ and into a new boot/
directory. This helps to collect these related files in one place, as
common/ is quite large.

Secondly, it provides patache so clean up the PXE code and refactor it
into something closer to a module that can be called, teasing apart its
reliance on the command-line interpreter to access filesystems and the
like. Also it now uses function arguments and its own context struct
internally rather than environment variables, which is very hard to
follow. No core functional change is intended.

Changes in v3:
- Rebase to -master

Changes in v2:
- Rebase to -next
- Split out from the bootmethod patches

Simon Glass (18):
  Create a new boot/ directory
  pxe: Move API comments to the header files
  pxe: Use a context pointer
  pxe: Move do_getfile() into the context
  pxe: Add a userdata field to the context
  pxe: Tidy up the is_pxe global
  pxe: Move pxe_utils files
  pxe: Tidy up some comments in pxe_utils
  pxe: Tidy up code style a little in pxe_utils
  pxe: Move common parsing coding into pxe_util
  pxe: Clean up the use of bootfile
  pxe: Drop get_bootfile_path()
  lib: Add tests for simple_itoa()
  lib: Add a function to convert a string to a hex value
  pxe: Return the file size from the getfile() function
  pxe: Refactor sysboot to have one helper
  doc: Move distro boot doc to rST
  pxe: Allow calling the pxe_get logic directly

 Kconfig   |   2 +
 Makefile  |   3 +-
 README|   1 +
 common/Kconfig.boot => boot/Kconfig   |   0
 boot/Makefile |  37 ++
 {common => boot}/android_ab.c |   0
 {common => boot}/boot_fit.c   |   0
 {common => boot}/bootm.c  |   0
 {common => boot}/bootm_os.c   |   0
 {common => boot}/bootretry.c  |   0
 {common => boot}/common_fit.c |   0
 {common => boot}/fdt_region.c |   0
 {common => boot}/image-android-dt.c   |   0
 {common => boot}/image-android.c  |   0
 {common => boot}/image-board.c|   0
 {common => boot}/image-cipher.c   |   0
 {common => boot}/image-fdt.c  |   0
 {common => boot}/image-fit-sig.c  |   0
 {common => boot}/image-fit.c  |   0
 {common => boot}/image-host.c |   0
 {common => boot}/image-sig.c  |   0
 {common => boot}/image.c  |   0
 {cmd => boot}/pxe_utils.c | 512 +++---
 cmd/Makefile  |   4 +-
 cmd/pxe.c | 136 +++---
 cmd/pxe_utils.h   |  91 
 cmd/sysboot.c | 114 +++--
 common/Kconfig|   2 -
 common/Makefile   |  22 -
 doc/android/boot-image.rst|   2 +-
 doc/{README.distro => develop/distro.rst} | 177 
 doc/develop/index.rst |   1 +
 include/pxe_utils.h   | 253 +++
 include/vsprintf.h|  25 +-
 lib/vsprintf.c|  20 +-
 scripts/Makefile.spl  |   4 +-
 test/print_ut.c   |  41 ++
 tools/Makefile|  18 +-
 38 files changed, 874 insertions(+), 591 deletions(-)
 rename common/Kconfig.boot => boot/Kconfig (100%)
 create mode 100644 boot/Makefile
 rename {common => boot}/android_ab.c (100%)
 rename {common => boot}/boot_fit.c (100%)
 rename {common => boot}/bootm.c (100%)
 rename {common => boot}/bootm_os.c (100%)
 rename {common => boot}/bootretry.c (100%)
 rename {common => boot}/common_fit.c (100%)
 rename {common => boot}/fdt_region.c (100%)
 rename {common => boot}/image-android-dt.c (100%)
 rename {common => boot}/image-android.c (100%)
 rename {common => boot}/image-board.c (100%)
 rename {common => boot}/image-cipher.c (100%)
 rename {common => boot}/image-fdt.c (100%)
 rename {common => boot}/image-fit-sig.c (100%)
 rename {common => boot}/image-fit.c (100%)
 rename {common => boot}/image-host.c (100%)
 rename {common => boot}/image-sig.c (100%)
 rename {common => boot}/image.c (100%)
 rename {cmd => boot}/pxe_utils.c (74%)
 delete mode 100644 cmd/pxe_utils.h
 rename doc/{README.distro => develop/distro.rst} (76%)
 create mode 100644 include/pxe_utils.h

-- 
2.33.0.1079.g6e70778dc9-goog



Re: [PATCH v3 2/3] timer: cadence: Add bind function to driver

2021-10-14 Thread Sean Anderson




On 10/14/21 2:24 PM, Simon Glass wrote:

Hi Sean,

On Thu, 14 Oct 2021 at 09:36, Sean Anderson  wrote:




On 10/14/21 11:09 AM, Simon Glass wrote:
> Hi Michal,
>
> On Wed, 6 Oct 2021 at 08:19, Michal Simek  wrote:
>>
>> When DT node has pwm-cells property it shouldn't be bind as timer driver
>> but as PWM driver. That's why make sure that this property is checked.
>>
>> Signed-off-by: Michal Simek 
>> ---
>>
>> Changes in v3:
>> - New patch in series
>>
>>  drivers/timer/cadence-ttc.c | 12 
>>  1 file changed, 12 insertions(+)
>>
>
> Why not have two compatible strings?

As I understand it, because the hardware is the same, it should have the
same compatible string.

>> diff --git a/drivers/timer/cadence-ttc.c b/drivers/timer/cadence-ttc.c
>> index 2f95d45ecd7a..2eff45060ad6 100644
>> --- a/drivers/timer/cadence-ttc.c
>> +++ b/drivers/timer/cadence-ttc.c
>> @@ -97,6 +97,17 @@ static int cadence_ttc_of_to_plat(struct udevice *dev)
>> return 0;
>>  }
>>
>> +static int cadence_ttc_bind(struct udevice *dev)
>> +{
>> +   const char *cells;
>> +
>> +   cells = dev_read_prop(dev, "#pwm-cells", NULL);
>> +   if (cells)
>> +   return -ENODEV;
>
> We can read properties in bind() when necessary, but this is very
> strange...it seems like the bindings are messed up?

This is the preferred way to select between a PWM and a timer driver.
See e.g. Rob's comment for xlnx,pwm at [1].


I actually don't understand his comment. Is it the 'No...' one?


No, it's the


If a PWM, perhaps you want a '#pwm-cells' property which can serve as
the hint to configure as a PWM.


--Sean



Anyway, it seems you understand what you are doing, and this is
supposed to be supported by driver model.

Reviewed-by: Simon Glass 

Regards,
Simon



Re: [PATCH v3 2/3] timer: cadence: Add bind function to driver

2021-10-14 Thread Simon Glass
Hi Sean,

On Thu, 14 Oct 2021 at 09:36, Sean Anderson  wrote:
>
>
>
> On 10/14/21 11:09 AM, Simon Glass wrote:
> > Hi Michal,
> >
> > On Wed, 6 Oct 2021 at 08:19, Michal Simek  wrote:
> >>
> >> When DT node has pwm-cells property it shouldn't be bind as timer driver
> >> but as PWM driver. That's why make sure that this property is checked.
> >>
> >> Signed-off-by: Michal Simek 
> >> ---
> >>
> >> Changes in v3:
> >> - New patch in series
> >>
> >>  drivers/timer/cadence-ttc.c | 12 
> >>  1 file changed, 12 insertions(+)
> >>
> >
> > Why not have two compatible strings?
>
> As I understand it, because the hardware is the same, it should have the
> same compatible string.
>
> >> diff --git a/drivers/timer/cadence-ttc.c b/drivers/timer/cadence-ttc.c
> >> index 2f95d45ecd7a..2eff45060ad6 100644
> >> --- a/drivers/timer/cadence-ttc.c
> >> +++ b/drivers/timer/cadence-ttc.c
> >> @@ -97,6 +97,17 @@ static int cadence_ttc_of_to_plat(struct udevice *dev)
> >> return 0;
> >>  }
> >>
> >> +static int cadence_ttc_bind(struct udevice *dev)
> >> +{
> >> +   const char *cells;
> >> +
> >> +   cells = dev_read_prop(dev, "#pwm-cells", NULL);
> >> +   if (cells)
> >> +   return -ENODEV;
> >
> > We can read properties in bind() when necessary, but this is very
> > strange...it seems like the bindings are messed up?
>
> This is the preferred way to select between a PWM and a timer driver.
> See e.g. Rob's comment for xlnx,pwm at [1].

I actually don't understand his comment. Is it the 'No...' one?

Anyway, it seems you understand what you are doing, and this is
supposed to be supported by driver model.

Reviewed-by: Simon Glass 

Regards,
Simon


Re: [PATCH v2 04/13] env: Change env_match() to static and remove from header

2021-10-14 Thread Simon Glass
Hi Marek,

On Thu, 14 Oct 2021 at 10:06, Marek Behún  wrote:
>
> On Thu, 14 Oct 2021 09:11:08 -0600
> Simon Glass  wrote:
>
> > Hi Marek,
> >
> > On Wed, 13 Oct 2021 at 09:46, Marek Behún  wrote:
> > >
> > > From: Marek Behún 
> > >
> > > This function was used by other parts of U-Boot in the past when
> > > environment was read from underlying device one character at a time.
> > >
> > > This is not the case anymore.
> > >
> > > Signed-off-by: Marek Behún 
> > > ---
> > >  cmd/nvedit.c  | 30 +++---
> > >  include/env.h | 11 ---
> > >  2 files changed, 15 insertions(+), 26 deletions(-)
> > >
> > > diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> > > index ddc715b4f9..742e0924af 100644
> > > --- a/cmd/nvedit.c
> > > +++ b/cmd/nvedit.c
> > > @@ -706,6 +706,21 @@ char *from_env(const char *envvar)
> > > return ret;
> > >  }
> > >
> >
> > Please can you add the function comment here? We don't want to lose
> > it.
>
> Simon, the comment is invalid (the function does something
> different from what the comment says) and the function is only used as a
> helper by env_get_f(), which comes right after it. The function is
> refactored and renamend in subsequent patches, and its purpose seems
> obvious to me.
>
> Should I really leave the comment there?

That's fine but it would be good to mention that in the commit message
explicitly.

Also you add matching_name_get_value(). Can you add a comment to that, then?

Regards,
Simon


Re: [PATCH] cmd: sysboot: dont overwrite bootfile env

2021-10-14 Thread Simon Glass
Hi Art,

On Wed, 13 Oct 2021 at 22:34, Art Nikpal  wrote:
>
> > Please also see this refactor which conflicts with this patch:
> >
> > http://patchwork.ozlabs.org/project/uboot/list/?series=264265
> >
> > I think that series should be reviewed/applied first since it was sent
> in August.
>
> yes ! i think need update your series because  cant apply it for
> current uboot state

OK I am not sure why that is, but I will rebase and send v3.

[..]
Regards,
Simon


Re: [PATCH] cmd: pxe_utils: Check fdtcontroladdr in label_boot

2021-10-14 Thread Simon Glass
Hi Peter,

On Thu, 14 Oct 2021 at 02:40, Peter Hoyes  wrote:
>
> From: Peter Hoyes 
>
> If using OF_CONTROL, fdtcontroladdr is set to the fdt used to configure
> U-Boot. When using PXE, if no fdt is defined in the menu file, and
> there is no fdt at fdt_addr, add fall back on fdtcontroladdr too.
>
> We are developing board support for the Armv8r64 FVP using
> config_distro_bootcmd. We are also using OF_BOARD and would like the
> PXE boot option to default to the fdt provided by board_fdt_blob_setup.
>
> Signed-off-by: Peter Hoyes 
> ---
>  cmd/pxe_utils.c | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
> index 067c24e5ff..8f8e69ca97 100644
> --- a/cmd/pxe_utils.c
> +++ b/cmd/pxe_utils.c
> @@ -556,7 +556,10 @@ static int label_boot(struct cmd_tbl *cmdtp, struct 
> pxe_label *label)
>  * Scenario 2: If there is an fdt_addr specified, pass it along to
>  * bootm, and adjust argc appropriately.
>  *
> -* Scenario 3: fdt blob is not available.
> +* Scenario 3: If there is an fdtcontroladdr specified, pass it along 
> to
> +* bootm, and adjust argc appropriately.
> +*
> +* Scenario 4: fdt blob is not available.
>  */
> bootm_argv[3] = env_get("fdt_addr_r");
>
> @@ -646,6 +649,9 @@ static int label_boot(struct cmd_tbl *cmdtp, struct 
> pxe_label *label)
> if (!bootm_argv[3])
> bootm_argv[3] = env_get("fdt_addr");
>
> +   if (!bootm_argv[3])
> +   bootm_argv[3] = env_get("fdtcontroladdr");
> +
> if (bootm_argv[3]) {
> if (!bootm_argv[2])
> bootm_argv[2] = "-";
> --
> 2.25.1
>

This is a bit strange as fdtcontroladdr is the control dtb that U-Boot
uses. Can you not set fdt_addr to that, if you need to? Is it not
already set to that?

Also, there is a clean-up series for this code outstanding. I will
send v3 and copy you, if you are able to review it.

Regards,
Simon


Re: External dts building

2021-10-14 Thread Simon Glass
Hi,

On Thu, 14 Oct 2021 at 07:46, Tom Rini  wrote:
>
> On Thu, Oct 14, 2021 at 02:53:30AM +0200, Giulio Benetti wrote:
>
> > Hello All,
> >
> > is there a way to pass a dts file without touching the 
> > arch/arm/boot/dts/Makefile?
> >
> > On Buildroot we support the possibility to pass an external dts by copying 
> > it to the uboot sources to
> > be built but since uboot version 2020.01 it doesn’t work anymore.
> >
> > So I’ve proposed a patch to prepend the dts file in the Makefile above, but 
> > this has drawbacks, like we reconfigure(it keeps adding files every time).
> >
> > So I ask you, is there a more canonical way already to achieve this?
>
> Not exactly, and it's something we're very much actively discussing
> right now.

Are you using 'make DEVICE_TREE=xxx' ?

Regards,
Simon


  1   2   >