[PATCH v3 9/9] sunxi: binman: Add support for including SCP firmware

2020-09-05 Thread Samuel Holland
Allwinner sun50i SoCs contain an OpenRISC 1000 CPU that functions as a
System Control Processor, or SCP. ARM Trusted Firmware (ATF)
communicates with the SCP over SCPI to implement the PSCI system
suspend, shutdown and reset functionality. Currently, SCP firmware is
optional; the system will boot and run without it, but system suspend
will be unavailable.

Since all communication with the SCP is mediated by ATF, the only thing
U-Boot needs to do is load the firmware into SRAM. The SCP firmware
occupies the last 16KiB of SRAM A2, immediately following ATF.

Signed-off-by: Samuel Holland 
---
 arch/arm/dts/sunxi-u-boot.dtsi | 16 -
 board/sunxi/README.sunxi64 | 43 --
 2 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
index ff3fff599f4..5ab7c6c23b7 100644
--- a/arch/arm/dts/sunxi-u-boot.dtsi
+++ b/arch/arm/dts/sunxi-u-boot.dtsi
@@ -2,8 +2,10 @@
 
 #ifdef CONFIG_MACH_SUN50I_H6
 #define BL31_ADDR 0x104000
+#define  SCP_ADDR 0x114000
 #else
 #define BL31_ADDR  0x44000
+#define  SCP_ADDR  0x5
 #endif
 
 / {
@@ -58,6 +60,18 @@
};
};
 
+   scp {
+   description = "SCP firmware";
+   type = "firmware";
+   arch = "or1k";
+   compression = "none";
+   load = ;
+
+   scp {
+   filename = "scp.bin";
+   };
+   };
+
@fdt-SEQ {
description = "NAME";
type = "flat_dt";
@@ -71,7 +85,7 @@
@config-SEQ {
description = "NAME";
firmware = "atf";
-   loadables = "uboot";
+   loadables = "scp", "uboot";
fdt = "fdt-SEQ";
};
};
diff --git a/board/sunxi/README.sunxi64 b/board/sunxi/README.sunxi64
index 258921af22d..9a67e5301eb 100644
--- a/board/sunxi/README.sunxi64
+++ b/board/sunxi/README.sunxi64
@@ -14,8 +14,12 @@ Quick Start / Overview
 - Build the ARM Trusted Firmware binary (see "ARM Trusted Firmware (ATF)" 
below)
   $ cd /src/arm-trusted-firmware
   $ make PLAT=sun50i_a64 DEBUG=1 bl31
+- Build the SCP firmware binary (see "SCP firmware (Crust)" below)
+  $ cd /src/crust
+  $ make pine64_plus_defconfig && make -j5 scp
 - Build U-Boot (see "SPL/U-Boot" below)
   $ export BL31=/path/to/bl31.bin
+  $ export SCP=/src/crust/build/scp/scp.bin
   $ make pine64_plus_defconfig && make -j5
 - Transfer to an uSD card (see "microSD card" below)
   $ dd if=u-boot-sunxi-with-spl.bin of=/dev/sdx bs=8k seek=1
@@ -24,13 +28,17 @@ Quick Start / Overview
 Building the firmware
 =
 
-The Allwinner A64/H5 firmware consists of three parts: U-Boot's SPL, an
-ARM Trusted Firmware (ATF) build and the U-Boot proper.
-The SPL will load both ATF and U-Boot proper along with the right device
-tree blob (.dtb) and will pass execution to ATF (in EL3), which in turn will
-drop into the U-Boot proper (in EL2).
-As the ATF binary will become part of the U-Boot image file, you will need
-to build it first.
+The Allwinner A64/H5/H6 firmware consists of several parts: U-Boot's SPL,
+ARM Trusted Firmware (ATF), optional System Control Processor (SCP) firmware
+(e.g. Crust), and the U-Boot proper.
+
+The SPL will load all of the other firmware binaries into RAM, along with the
+right device tree blob (.dtb), and will pass execution to ATF (in EL3). If SCP
+firmware was loaded, ATF will power on the SCP and wait for it to boot.
+ATF will then drop into U-Boot proper (in EL2).
+
+As the ATF binary and SCP firmware will become part of the U-Boot image file,
+you will need to build them first.
 
  ARM Trusted Firmware (ATF)
 
@@ -53,6 +61,27 @@ As sometimes the ATF build process is a bit picky about the 
toolchain used,
 or if you can't be bothered with building ATF, there are known working
 binaries in the firmware repository[3], purely for convenience reasons.
 
+ SCP firmware (Crust)
+--
+SCP firmware is responsible for implementing system suspend/resume, and (on
+boards without a PMIC) soft poweroff/on. ATF contains fallback code for CPU
+power control, so SCP firmware is optional if you don't need either of these
+features. It runs on the AR100, with is an or1k CPU, not ARM, so it needs a
+different cross toolchain.
+
+There is one SCP firmware implementation currently 

[PATCH v3 6/9] sunxi: binman: Use a macro for the BL31 load address

2020-09-05 Thread Samuel Holland
This consolidates the SoC-specific part at the top of the file to avoid
cluttering it up with preprocessor conditions.

Signed-off-by: Samuel Holland 
---
 arch/arm/dts/sunxi-u-boot.dtsi | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
index 6ab0c783ba5..4d599720382 100644
--- a/arch/arm/dts/sunxi-u-boot.dtsi
+++ b/arch/arm/dts/sunxi-u-boot.dtsi
@@ -1,5 +1,11 @@
 #include 
 
+#ifdef CONFIG_MACH_SUN50I_H6
+#define BL31_ADDR 0x104000
+#else
+#define BL31_ADDR  0x44000
+#endif
+
 / {
aliases {
mmc1 = 
@@ -42,14 +48,8 @@
type = "firmware";
arch = "arm64";
compression = "none";
-/* TODO: Do this with an overwrite in this board's dtb? */
-#ifdef CONFIG_MACH_SUN50I_H6
-   load = <0x104000>;
-   entry = <0x104000>;
-#else
-   load = <0x44000>;
-   entry = <0x44000>;
-#endif
+   load = ;
+   entry = ;
 
atf-bl31 {
filename = "bl31.bin";
-- 
2.26.2



[PATCH v3 8/9] binman: Add support for SCP firmware

2020-09-05 Thread Samuel Holland
Add an entry type for a firmware blob for a Sytem Control Processor,
given by an entry arg. This firmware is a raw binary blob.

Signed-off-by: Samuel Holland 
---
 Makefile  |  2 +-
 tools/binman/etype/scp.py | 19 +++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/etype/scp.py

diff --git a/Makefile b/Makefile
index d5aa8605c0a..5a6681f129e 100644
--- a/Makefile
+++ b/Makefile
@@ -1328,7 +1328,7 @@ cmd_binman = $(srctree)/tools/binman/binman $(if 
$(BINMAN_DEBUG),-D) \
build -u -d u-boot.dtb -O . -m --allow-missing \
-I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
-I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
-   -a atf-bl31-path=${BL31} \
+   -a atf-bl31-path=${BL31} -a scp-path=${SCP} \
$(BINMAN_$(@F))
 
 OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
diff --git a/tools/binman/etype/scp.py b/tools/binman/etype/scp.py
new file mode 100644
index 000..93f8787d2d7
--- /dev/null
+++ b/tools/binman/etype/scp.py
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2020 Samuel Holland 
+#
+# Entry-type module for System Control Processor (SCP) firmware blob
+#
+
+from binman.etype.blob_named_by_arg import Entry_blob_named_by_arg
+
+class Entry_scp(Entry_blob_named_by_arg):
+"""Entry containing a System Control Processor (SCP) firmware blob
+
+Properties / Entry arguments:
+- scp-path: Filename of file to read into the entry, typically scp.bin
+
+This entry holds firmware for an external platform-specific coprocessor.
+"""
+def __init__(self, section, etype, node):
+super().__init__(section, etype, node, 'scp')
+self.external = True
-- 
2.26.2



[PATCH v3 1/9] Makefile: Only define u-boot.itb rule when applicable

2020-09-05 Thread Samuel Holland
If neither CONFIG_SPL_FIT_SOURCE nor CONFIG_USE_SPL_FIT_GENERATOR is
enabled, U_BOOT_ITS will be undefined, and attempting to make u-boot.itb
will pass invalid arguments to mkimage, causing it to print its help
message.

Remove the rule in that case, so it is more obvious that u-boot.itb is
not something that can be made. This will reduce confusion as platforms
move away from CONFIG_USE_SPL_FIT_GENERATOR, as u-boot.itb was
previously a valid goal for those platforms.

Signed-off-by: Samuel Holland 
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Makefile b/Makefile
index 65024c74089..d5aa8605c0a 100644
--- a/Makefile
+++ b/Makefile
@@ -1438,11 +1438,13 @@ else
 MKIMAGEFLAGS_u-boot.itb = -E
 endif
 
+ifdef U_BOOT_ITS
 u-boot.itb: u-boot-nodtb.bin \
$(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_OF_HOSTFILE),dts/dt.dtb) \
$(U_BOOT_ITS) FORCE
$(call if_changed,mkfitimage)
$(BOARD_SIZE_CHECK)
+endif
 
 u-boot-spl.kwb: u-boot.img spl/u-boot-spl.bin FORCE
$(call if_changed,mkimage)
-- 
2.26.2



[PATCH v3 4/9] sunxi: binman: Fix spacing between nodes

2020-09-05 Thread Samuel Holland
Nodes should have a blank line separating them from sibling nodes and
properties. Add the necessary lines.

Signed-off-by: Samuel Holland 
---
 arch/arm/dts/sunxi-u-boot.dtsi | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
index 1d1c3691099..82b97a9503f 100644
--- a/arch/arm/dts/sunxi-u-boot.dtsi
+++ b/arch/arm/dts/sunxi-u-boot.dtsi
@@ -14,9 +14,11 @@
u-boot-sunxi-with-spl {
filename = "u-boot-sunxi-with-spl.bin";
pad-byte = <0xff>;
+
blob {
filename = "spl/sunxi-spl.bin";
};
+
 #ifdef CONFIG_ARM64
fit {
description = "Configuration to load ATF before U-Boot";
@@ -34,6 +36,7 @@
u-boot-nodtb {
};
};
+
atf {
description = "ARM Trusted Firmware";
type = "firmware";
@@ -47,6 +50,7 @@
load = <0x44000>;
entry = <0x44000>;
 #endif
+
atf-bl31 {
};
};
@@ -60,6 +64,7 @@
 
configurations {
default = "config-1";
+
@config-SEQ {
description = "NAME";
firmware = "uboot";
-- 
2.26.2



[PATCH v3 2/9] binman: Only write FDT once per node

2020-09-05 Thread Samuel Holland
Due to an extra level of indentation, the "data" property containing the
FDT was being written repeatedly after every other property in the node.
Move the block up one level, so the property is added exactly once.

Signed-off-by: Samuel Holland 
---
 tools/binman/etype/fit.py | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
index c291eb26bad..01fa51367e6 100644
--- a/tools/binman/etype/fit.py
+++ b/tools/binman/etype/fit.py
@@ -179,10 +179,10 @@ class Entry_fit(Entry):
 b'SEQ', tools.ToBytes(str(seq + 1)))
 fsw.property(pname, val)
 
-# Add data for 'fdt' nodes (but not 
'config')
-if depth == 1 and in_images:
-fsw.property('data',
- tools.ReadFile(fname))
+# Add data for 'fdt' nodes (but not 'config')
+if depth == 1 and in_images:
+fsw.property('data',
+ tools.ReadFile(fname))
 else:
 if self._fdts is None:
 if self._fit_list_prop:
-- 
2.26.2



[PATCH v3 7/9] sunxi: binman: Update FIT component descriptions

2020-09-05 Thread Samuel Holland
Since commit d879616e9e64 ("spl: fit: simplify logic for FDT loading for
non-OS boots"), the SPL looks at the "os" properties of FIT images to
determine where to append the FDT.

The "os" property of the "firmware" image also determines how to execute
the next stage of the boot process, as in 1d3790905d9c ("spl: atf:
introduce spl_invoke_atf and make bl31_entry private"). For this reason,
the next stage must be specified in "firmware", not in "loadables".

To support this additional functionality, and to properly model the boot
process, where ATF runs before U-Boot, add the "os" properties and swap
the firmware/loadable images in the FIT image.

Since this description was copied as an example in commit 70248d6a2916
("binman: Support generating FITs with multiple dtbs"), update those
examples as well for correctness and consistency.

Acked-by: Patrick Wildt 
Signed-off-by: Samuel Holland 
---
 arch/arm/dts/sunxi-u-boot.dtsi | 6 --
 tools/binman/README.entries| 4 ++--
 tools/binman/etype/fit.py  | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
index 4d599720382..ff3fff599f4 100644
--- a/arch/arm/dts/sunxi-u-boot.dtsi
+++ b/arch/arm/dts/sunxi-u-boot.dtsi
@@ -35,6 +35,7 @@
uboot {
description = "U-Boot (64-bit)";
type = "standalone";
+   os = "u-boot";
arch = "arm64";
compression = "none";
load = <0x4a00>;
@@ -46,6 +47,7 @@
atf {
description = "ARM Trusted Firmware";
type = "firmware";
+   os = "arm-trusted-firmware";
arch = "arm64";
compression = "none";
load = ;
@@ -68,8 +70,8 @@
 
@config-SEQ {
description = "NAME";
-   firmware = "uboot";
-   loadables = "atf";
+   firmware = "atf";
+   loadables = "uboot";
fdt = "fdt-SEQ";
};
};
diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index d2628dffd5d..c45aed0a681 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -385,8 +385,8 @@ You can create config nodes in a similar way:
 default = "@config-DEFAULT-SEQ";
 @config-SEQ {
 description = "NAME";
-firmware = "uboot";
-loadables = "atf";
+firmware = "atf";
+loadables = "uboot";
 fdt = "fdt-SEQ";
 };
 };
diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
index 01fa51367e6..73793ecda31 100644
--- a/tools/binman/etype/fit.py
+++ b/tools/binman/etype/fit.py
@@ -73,8 +73,8 @@ class Entry_fit(Entry):
 default = "@config-DEFAULT-SEQ";
 @config-SEQ {
 description = "NAME";
-firmware = "uboot";
-loadables = "atf";
+firmware = "atf";
+loadables = "uboot";
 fdt = "fdt-SEQ";
 };
 };
-- 
2.26.2



[PATCH v3 0/9] sunxi: binman fixes and SCP firmware support

2020-09-05 Thread Samuel Holland
This is a rebase of my previous patch series adding SCP firmware support
for system suspend, onto the binman rewrite of mksunxi_fit_atf.sh.

It is based on u-boot-dm/next.

- The first two patches apply to binman FIT support generally.
- The third patch is unchanged from previous versions.
- Patches 4-6 fix small issues in the new sunxi binman description.
- Patches 7-9 implement the same functionality as previous versions
  of this series, but using binman instead of a shell script.

Samuel Holland (9):
  Makefile: Only define u-boot.itb rule when applicable
  binman: Only write FDT once per node
  spl: fit: Minimally parse OS properties with FIT_IMAGE_TINY
  sunxi: binman: Fix spacing between nodes
  sunxi: binman: Provide a default BL31 filename
  sunxi: binman: Use a macro for the BL31 load address
  sunxi: binman: Update FIT component descriptions
  binman: Add support for SCP firmware
  sunxi: binman: Add support for including SCP firmware

 Makefile   |  4 +++-
 arch/arm/dts/sunxi-u-boot.dtsi | 42 +
 board/sunxi/README.sunxi64 | 43 --
 common/spl/Kconfig |  4 +---
 common/spl/spl_fit.c   | 17 +-
 tools/binman/README.entries|  4 ++--
 tools/binman/etype/fit.py  | 12 +-
 tools/binman/etype/scp.py  | 19 +++
 8 files changed, 115 insertions(+), 30 deletions(-)
 create mode 100644 tools/binman/etype/scp.py

-- 
2.26.2



[PATCH v3 5/9] sunxi: binman: Provide a default BL31 filename

2020-09-05 Thread Samuel Holland
Prior to commit 7f7f8aca8257 ("sunxi: Convert 64-bit boards to use
binman"), if the BL31 environment variable was not defined, the firmware
would be loaded from a file "bl31.bin" in the current directory. Restore
that behavior by providing that as the default filename in case no entry
arg is provided, which will be the case if the environment variable is
unset.

Signed-off-by: Samuel Holland 
---

I tested this and verified it to work. The key code is from
tools/binman/etype/blob_named_by_arg.py:
super().__init__(...)
filename, = self.GetEntryArgsOrProps(...)
if filename:
self._filename = filename

If `filename` is the empty string, it evaluates to False, and the filename
set from the DT property in the superclass constructor is not overwritten.

---
 arch/arm/dts/sunxi-u-boot.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
index 82b97a9503f..6ab0c783ba5 100644
--- a/arch/arm/dts/sunxi-u-boot.dtsi
+++ b/arch/arm/dts/sunxi-u-boot.dtsi
@@ -52,6 +52,7 @@
 #endif
 
atf-bl31 {
+   filename = "bl31.bin";
};
};
 
-- 
2.26.2



[PATCH v3 3/9] spl: fit: Minimally parse OS properties with FIT_IMAGE_TINY

2020-09-05 Thread Samuel Holland
Some boards, specifically 64-bit Allwinner boards (sun50i), are
extremely limited on SPL size. One strategy that was used to make space
was to remove the FIT "os" property parsing code, because it uses a
rather large lookup table.

However, this forces the legacy FIT parsing code path, which requires
the "firmware" entry in the FIT to reference the U-Boot binary, even if
U-Boot is not the next binary in the boot sequence (for example, on
sun50i boards, ATF is run first).

This prevents the same FIT image from being used with a SPL with
CONFIG_SPL_FIT_IMAGE_TINY=n and CONFIG_SPL_ATF=y, because the boot
method selection code looks at `spl_image.os`, which is only set from
the "firmware" entry's "os" property.

To be able to use CONFIG_SPL_ATF=y, the "firmware" entry in the FIT
must be ATF, and U-Boot must be a loadable. For this to work, we need to
parse the "os" property just enough to tell U-Boot from other images, so
we can find it in the loadables list to append the FDT, and so we don't
try to append the FDT to ATF (which could clobber adjacent firmware).

So add the minimal code necessary to distinguish U-Boot/non-U-Boot
loadables with CONFIG_SPL_FIT_IMAGE_TINY=y. This adds about 300 bytes,
much less than the 7400 bytes added by CONFIG_SPL_FIT_IMAGE_TINY=n.

Acked-by: Patrick Wildt 
Signed-off-by: Samuel Holland 
---
 common/spl/Kconfig   |  4 +---
 common/spl/spl_fit.c | 17 -
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index af8255a8d6a..041b47244bd 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -465,9 +465,7 @@ config SPL_FIT_IMAGE_TINY
  Enable this to reduce the size of the FIT image loading code
  in SPL, if space for the SPL binary is very tight.
 
- This removes the detection of image types (which forces the
- first image to be treated as having a U-Boot style calling
- convention) and skips the recording of each loaded payload
+ This skips the recording of each loaded payload
  (i.e. loadable) into the FDT (modifying the loaded FDT to
  ensure this information is available to the next image
  invoked).
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 365104fe028..a31ab6c5992 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -466,7 +466,22 @@ static int spl_fit_record_loadable(const void *fit, int 
images, int index,
 static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
 {
 #if CONFIG_IS_ENABLED(FIT_IMAGE_TINY) && !defined(CONFIG_SPL_OS_BOOT)
-   return -ENOTSUPP;
+   const char *name = fdt_getprop(fit, noffset, FIT_OS_PROP, NULL);
+
+   if (!name)
+   return -ENOENT;
+
+   /*
+* We don't care what the type of the image actually is,
+* only whether or not it is U-Boot. This saves some
+* space by omitting the large table of OS types.
+*/
+   if (!strcmp(name, "u-boot"))
+   *os = IH_OS_U_BOOT;
+   else
+   *os = IH_OS_INVALID;
+
+   return 0;
 #else
return fit_image_get_os(fit, noffset, os);
 #endif
-- 
2.26.2



Re: [PATCH v3 08/12] sunxi: Convert 64-bit boards to use binman

2020-09-05 Thread Simon Glass
Hi Samuel,

On Sat, 5 Sep 2020 at 19:49, Samuel Holland  wrote:
>
> Simon,
>
> On 9/5/20 7:18 PM, Simon Glass wrote:
> > On Sat, 5 Sep 2020 at 17:10, Samuel Holland  wrote:
> >> On 9/1/20 6:14 AM, Simon Glass wrote:
> >>> At present 64-bit sunxi boards use the Makefile to create a FIT, using
> >>> USE_SPL_FIT_GENERATOR. This is deprecated.
> >>>
> >>> Update sunxi to use binman instead.
> >>>
> >>> Signed-off-by: Simon Glass 
> >>> ---
> >>>
> >>> (no changes since v2)
> >>>
> >>> Changes in v2:
> >>> - Add a 'fit-fdt-list' property
> >>> - Fix 'board' typo in commit message
> >>>
> >>>  Kconfig|  3 +-
> >>>  Makefile   | 18 ++
> >>>  arch/arm/dts/sunxi-u-boot.dtsi | 61 +-
> >>>  3 files changed, 63 insertions(+), 19 deletions(-)
> >>>
> >>> diff --git a/Kconfig b/Kconfig
> >>> index 883e3f71d01..837b2f517ae 100644
> >>> --- a/Kconfig
> >>> +++ b/Kconfig
> >>> @@ -659,12 +659,11 @@ config SPL_FIT_SOURCE
> >>>
> >>>  config USE_SPL_FIT_GENERATOR
> >>>   bool "Use a script to generate the .its script"
> >>> - default y if SPL_FIT
> >>> + default y if SPL_FIT && !ARCH_SUNXI
> >>
> >> Now `make u-boot.itb` doesn't work.
> >>
> >> u-boot.itb is helpful to have because, with CONFIG_OF_LIST, it can be 
> >> shared
> >> across all boards of a platform. Only SPL is board-specific (on arm64 
> >> sunxi, at
> >> least).
> >
> > It is generated, just with a different filename.
>
> Thanks. From looking at the code and comparing with u-boot-sunxi-with-spl.bin,
> it seems that u-boot-sunxi-with-spl.fit.fit is the "final" ITB file. My only
> hesitation is that it seems like an implementation detail, but I guess it's 
> fine
> for now.
>
> >>
> >> Is there a way to make binman also write the FIT without the SPL? Would 
> >> that
> >> require duplicating the whole binman node?
> >
> > Yes it would. We could get more complicated and allow an image to
> > build on another perhaps. I'm not sure what is easiest here.
>
> u-boot-sunxi-with-spl.fit.fit is good enough for my purposes, but others may
> have an opinion.
>
> >>
> >>>  config SPL_FIT_GENERATOR
> >>>   string ".its file generator script for U-Boot FIT image"
> >>>   depends on USE_SPL_FIT_GENERATOR
> >>> - default "board/sunxi/mksunxi_fit_atf.sh" if SPL_LOAD_FIT && 
> >>> ARCH_SUNXI
> >>>   default "arch/arm/mach-rockchip/make_fit_atf.py" if SPL_LOAD_FIT && 
> >>> ARCH_ROCKCHIP
> >>>   default "arch/arm/mach-zynqmp/mkimage_fit_atf.sh" if SPL_LOAD_FIT 
> >>> && ARCH_ZYNQMP
> >>>   default "arch/riscv/lib/mkimage_fit_opensbi.sh" if SPL_LOAD_FIT && 
> >>> RISCV
> >>> diff --git a/Makefile b/Makefile
> >>> index 5b4e60496d6..65024c74089 100644
> >>> --- a/Makefile
> >>> +++ b/Makefile
> >>> @@ -923,11 +923,6 @@ INPUTS-$(CONFIG_REMAKE_ELF) += u-boot.elf
> >>>  INPUTS-$(CONFIG_EFI_APP) += u-boot-app.efi
> >>>  INPUTS-$(CONFIG_EFI_STUB) += u-boot-payload.efi
> >>>
> >>> -# Build a combined spl + u-boot image for sunxi
> >>> -ifeq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64)$(CONFIG_SPL),yyy)
> >>> -INPUTS-y += u-boot-sunxi-with-spl.bin
> >>> -endif
> >>> -
> >>>  # Generate this input file for binman
> >>>  ifeq ($(CONFIG_SPL),)
> >>>  INPUTS-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
> >>> @@ -1024,13 +1019,9 @@ PHONY += inputs
> >>>  inputs: $(INPUTS-y)
> >>>
> >>>  all: .binman_stamp inputs
> >>> -# Hack for sunxi which doesn't have a proper binman definition for
> >>> -# 64-bit boards
> >>> -ifneq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64),yy)
> >>>  ifeq ($(CONFIG_BINMAN),y)
> >>>   $(call if_changed,binman)
> >>>  endif
> >>> -endif
> >>>
> >>>  # Timestamp file to make sure that binman always runs
> >>>  .binman_stamp: FORCE
> >>> @@ -1336,6 +1327,8 @@ cmd_binman = $(srctree)/tools/binman/binman $(if 
> >>> $(BINMAN_DEBUG),-D) \
> >>>   $(if $(BINMAN_VERBOSE),-v$(BINMAN_VERBOSE)) \
> >>>   build -u -d u-boot.dtb -O . -m --allow-missing \
> >>>   -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
> >>> + -I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
> >>> + -a atf-bl31-path=${BL31} \
> >>>   $(BINMAN_$(@F))
> >>>
> >>>  OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
> >>> @@ -1625,13 +1618,6 @@ u-boot-x86-reset16.bin: u-boot FORCE
> >>>
> >>>  endif # CONFIG_X86
> >>>
> >>> -ifneq ($(CONFIG_ARCH_SUNXI),)
> >>> -ifeq ($(CONFIG_ARM64),y)
> >>> -u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
> >>> - $(call if_changed,cat)
> >>> -endif
> >>> -endif
> >>> -
> >>
> >> Now `make u-boot-sunxi-with-spl.bin` doesn't work.
> >>
> >> This is less of an issue, but still probably breaks some scripts. It breaks
> >> mine, at least.
> >
> > Why do you specify a target? Doesn't it build the file without the target?
>
> Yes, the file is built either way. I provide a specific target to avoid 
> building
> other files I don't need -- for example, a plain `make` used to rebuild the
> 

Re: [PATCH v3 08/12] sunxi: Convert 64-bit boards to use binman

2020-09-05 Thread Samuel Holland
Simon,

On 9/5/20 7:18 PM, Simon Glass wrote:
> On Sat, 5 Sep 2020 at 17:10, Samuel Holland  wrote:
>> On 9/1/20 6:14 AM, Simon Glass wrote:
>>> At present 64-bit sunxi boards use the Makefile to create a FIT, using
>>> USE_SPL_FIT_GENERATOR. This is deprecated.
>>>
>>> Update sunxi to use binman instead.
>>>
>>> Signed-off-by: Simon Glass 
>>> ---
>>>
>>> (no changes since v2)
>>>
>>> Changes in v2:
>>> - Add a 'fit-fdt-list' property
>>> - Fix 'board' typo in commit message
>>>
>>>  Kconfig|  3 +-
>>>  Makefile   | 18 ++
>>>  arch/arm/dts/sunxi-u-boot.dtsi | 61 +-
>>>  3 files changed, 63 insertions(+), 19 deletions(-)
>>>
>>> diff --git a/Kconfig b/Kconfig
>>> index 883e3f71d01..837b2f517ae 100644
>>> --- a/Kconfig
>>> +++ b/Kconfig
>>> @@ -659,12 +659,11 @@ config SPL_FIT_SOURCE
>>>
>>>  config USE_SPL_FIT_GENERATOR
>>>   bool "Use a script to generate the .its script"
>>> - default y if SPL_FIT
>>> + default y if SPL_FIT && !ARCH_SUNXI
>>
>> Now `make u-boot.itb` doesn't work.
>>
>> u-boot.itb is helpful to have because, with CONFIG_OF_LIST, it can be shared
>> across all boards of a platform. Only SPL is board-specific (on arm64 sunxi, 
>> at
>> least).
> 
> It is generated, just with a different filename.

Thanks. From looking at the code and comparing with u-boot-sunxi-with-spl.bin,
it seems that u-boot-sunxi-with-spl.fit.fit is the "final" ITB file. My only
hesitation is that it seems like an implementation detail, but I guess it's fine
for now.

>>
>> Is there a way to make binman also write the FIT without the SPL? Would that
>> require duplicating the whole binman node?
> 
> Yes it would. We could get more complicated and allow an image to
> build on another perhaps. I'm not sure what is easiest here.

u-boot-sunxi-with-spl.fit.fit is good enough for my purposes, but others may
have an opinion.

>>
>>>  config SPL_FIT_GENERATOR
>>>   string ".its file generator script for U-Boot FIT image"
>>>   depends on USE_SPL_FIT_GENERATOR
>>> - default "board/sunxi/mksunxi_fit_atf.sh" if SPL_LOAD_FIT && ARCH_SUNXI
>>>   default "arch/arm/mach-rockchip/make_fit_atf.py" if SPL_LOAD_FIT && 
>>> ARCH_ROCKCHIP
>>>   default "arch/arm/mach-zynqmp/mkimage_fit_atf.sh" if SPL_LOAD_FIT && 
>>> ARCH_ZYNQMP
>>>   default "arch/riscv/lib/mkimage_fit_opensbi.sh" if SPL_LOAD_FIT && 
>>> RISCV
>>> diff --git a/Makefile b/Makefile
>>> index 5b4e60496d6..65024c74089 100644
>>> --- a/Makefile
>>> +++ b/Makefile
>>> @@ -923,11 +923,6 @@ INPUTS-$(CONFIG_REMAKE_ELF) += u-boot.elf
>>>  INPUTS-$(CONFIG_EFI_APP) += u-boot-app.efi
>>>  INPUTS-$(CONFIG_EFI_STUB) += u-boot-payload.efi
>>>
>>> -# Build a combined spl + u-boot image for sunxi
>>> -ifeq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64)$(CONFIG_SPL),yyy)
>>> -INPUTS-y += u-boot-sunxi-with-spl.bin
>>> -endif
>>> -
>>>  # Generate this input file for binman
>>>  ifeq ($(CONFIG_SPL),)
>>>  INPUTS-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
>>> @@ -1024,13 +1019,9 @@ PHONY += inputs
>>>  inputs: $(INPUTS-y)
>>>
>>>  all: .binman_stamp inputs
>>> -# Hack for sunxi which doesn't have a proper binman definition for
>>> -# 64-bit boards
>>> -ifneq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64),yy)
>>>  ifeq ($(CONFIG_BINMAN),y)
>>>   $(call if_changed,binman)
>>>  endif
>>> -endif
>>>
>>>  # Timestamp file to make sure that binman always runs
>>>  .binman_stamp: FORCE
>>> @@ -1336,6 +1327,8 @@ cmd_binman = $(srctree)/tools/binman/binman $(if 
>>> $(BINMAN_DEBUG),-D) \
>>>   $(if $(BINMAN_VERBOSE),-v$(BINMAN_VERBOSE)) \
>>>   build -u -d u-boot.dtb -O . -m --allow-missing \
>>>   -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
>>> + -I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
>>> + -a atf-bl31-path=${BL31} \
>>>   $(BINMAN_$(@F))
>>>
>>>  OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
>>> @@ -1625,13 +1618,6 @@ u-boot-x86-reset16.bin: u-boot FORCE
>>>
>>>  endif # CONFIG_X86
>>>
>>> -ifneq ($(CONFIG_ARCH_SUNXI),)
>>> -ifeq ($(CONFIG_ARM64),y)
>>> -u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
>>> - $(call if_changed,cat)
>>> -endif
>>> -endif
>>> -
>>
>> Now `make u-boot-sunxi-with-spl.bin` doesn't work.
>>
>> This is less of an issue, but still probably breaks some scripts. It breaks
>> mine, at least.
> 
> Why do you specify a target? Doesn't it build the file without the target?

Yes, the file is built either way. I provide a specific target to avoid building
other files I don't need -- for example, a plain `make` used to rebuild the
hello world EFI application every time.

> One problem with buildman is that there is no definitely of what files
> it will produce when run, or at least there is, but it is in the
> binman description itself.
> 
> This means that 'make clean' doesn't work fully, for example. I can
> think of a few ways to implement this. One would be to put a 

Re: [PATCH v3 06/12] binman: Support generating FITs with multiple dtbs

2020-09-05 Thread Simon Glass
Hi Samuel,

On Sat, 5 Sep 2020 at 16:41, Samuel Holland  wrote:
>
> On 9/1/20 6:13 AM, Simon Glass wrote:
> > In some cases it is useful to generate a FIT which has a number of DTB
> > images, selectable by configuration. Add support for this in binman,
> > using a simple iterator and string substitution.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v3:
> > - Rebase on top of earlier binman series
> >
> > Changes in v2:
> > - Add a check for a missing fit,fdt-list property
> > - Add a check for a missing of-list property
> > - Add a check for an empty of-list
> >
> >  tools/binman/README.entries   |  48 +++-
> >  tools/binman/etype/fit.py |  94 +++-
> >  tools/binman/ftest.py | 106 +-
> >  tools/binman/test/170_fit_fdt.dts |  55 +
> >  .../binman/test/171_fit_fdt_missing_prop.dts  |  54 +
> >  5 files changed, 346 insertions(+), 11 deletions(-)
> >  create mode 100644 tools/binman/test/170_fit_fdt.dts
> >  create mode 100644 tools/binman/test/171_fit_fdt_missing_prop.dts
>
> [snip]
>
> > @@ -357,7 +358,52 @@ For example, this creates an image containing a FIT 
> > with U-Boot SPL:
> >  };
> >  };
> >
> > -Properties:
> > +U-Boot supports creating fdt and config nodes automatically. To do this,
> > +pass an of-list property (e.g. -a of-list=file1 file2). This tells binman
> > +that you want to generates nodes for two files: file1.dtb and file2.dtb
> > +The fit,fdt-list property (see above) indicates that of-list should be 
> > used.
> > +If the property is missing you will get an error.
> > +
> > +Then add a 'generator node', a node with a name starting with '@':
> > +
> > +images {
> > +@fdt-SEQ {
> > +description = "fdt-NAME";
> > +type = "flat_dt";
> > +compression = "none";
> > +};
> > +};
> > +
> > +This tells binman to create nodes fdt-1 and fdt-2 for each of your two
> > +files. All the properties you specify will be included in the node. This
> > +node acts like a template to generate the nodes. The generator node itself
> > +does not appear in the output - it is replaced with what binman generates.
>
> Is this output written anywhere? The compiled DTB has the unprocessed template
> in it, and the final image created by binman requires some dissection to get 
> to
> the FIT ITS.

Yes both the input to mkimage and the output are written out. See the
build directory for these files, which are named after the node names.

>
> > +
> > +You can create config nodes in a similar way:
> > +
> > +configurations {
> > +default = "@config-DEFAULT-SEQ";
> > +@config-SEQ {
> > +description = "NAME";
> > +firmware = "uboot";
> > +loadables = "atf";
> > +fdt = "fdt-SEQ";
> > +};
> > +};
> > +
> > +This tells binman to create nodes config-1 and config-2, i.e. a config for
> > +each of your two files.
> > +
> > +Available substitutions for '@' nodes are:
> > +
> > +SEQSequence number of the generated fdt (1, 2, ...)
> > +NAME   Name of the dtb as provided (i.e. without adding '.dtb')
>
> There is no mention of DEFAULT-SEQ here.

That feature is added in a later patch. I will make sure it is documented here.

>
> > +
> > +Note that if no devicetree files are provided (with '-a of-list' as above)
> > +then no nodes will be generated.
> > +
> > +
> > +Properties (in the 'fit' node itself):
> >  fit,external-offset: Indicates that the contents of the FIT are 
> > external
> >  and provides the external offset. This is passsed to mkimage via
> >  the -E and -p flags.
>
> [snip]

Regards,
Simon


Re: [PATCH v3 05/12] binman: Add support for ATF BL31

2020-09-05 Thread Simon Glass
Hi Samuel,

On Sat, 5 Sep 2020 at 16:57, Samuel Holland  wrote:
>
> On 9/1/20 6:13 AM, Simon Glass wrote:
> > Add an entry for ARM Trusted Firmware's 'BL31' payload, which is the
> > device's main firmware. Typically this is U-Boot.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v3:
> > - Rebase on top of earlier binman series
> >
> > Changes in v2:
> > - Add the URL of ARM Trusted Firmware and mention of U-Boot docs
> > - Fix copyright year
> > - Update docs to indicate that BL31 is loaded from SPL
> > - Update docs to mention both bl31.bin and bl31.elf
> >
> >  tools/binman/README.entries| 14 ++
> >  tools/binman/etype/atf_bl31.py | 24 
> >  tools/binman/ftest.py  |  9 +
> >  tools/binman/test/169_atf_bl31.dts | 16 
> >  4 files changed, 63 insertions(+)
> >  create mode 100644 tools/binman/etype/atf_bl31.py
> >  create mode 100644 tools/binman/test/169_atf_bl31.dts
>
> Does this mean every kind of firmware blob referenced by FIT generator scripts
> (TEE fimware, SCP firmware, OpenSBI firmware, etc.) needs its own Python 
> package?

No, but in general I would like to do that if possible. It is easier
that having random filenames in the description.

>
> What if you need multiple versions of ATF BL31 and TEE firmware for different
> configurations, like Rockchip currently does?

You can always specify a filename in the node.

> You would need dynamic argument
> names, but then how do you get them in the Makefile?

Using the -a flag.

>
> This approach doesn't seem very flexible or scalable.
>
> Why not have a generic Entry_blob_named_by_env, with a "filename-var" (or
> similar) property in addition to "filename"? Then the existing interface of 
> the
> FIT generator scripts could be maintained without tons of boilerplate.

You can do that if you like (see blob-named-by-arg and -a), but the
idea with binman is that it knows how to deal with various types of
binaries, and each one has a name. This makes it easier to see what is
going on, I think.

Also we get documentation about each binary type in README.entries

Regards,
Simon


Re: [PATCH v3 08/12] sunxi: Convert 64-bit boards to use binman

2020-09-05 Thread Simon Glass
Hi Samuel,

On Sat, 5 Sep 2020 at 17:10, Samuel Holland  wrote:
>
> On 9/1/20 6:14 AM, Simon Glass wrote:
> > At present 64-bit sunxi boards use the Makefile to create a FIT, using
> > USE_SPL_FIT_GENERATOR. This is deprecated.
> >
> > Update sunxi to use binman instead.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > (no changes since v2)
> >
> > Changes in v2:
> > - Add a 'fit-fdt-list' property
> > - Fix 'board' typo in commit message
> >
> >  Kconfig|  3 +-
> >  Makefile   | 18 ++
> >  arch/arm/dts/sunxi-u-boot.dtsi | 61 +-
> >  3 files changed, 63 insertions(+), 19 deletions(-)
> >
> > diff --git a/Kconfig b/Kconfig
> > index 883e3f71d01..837b2f517ae 100644
> > --- a/Kconfig
> > +++ b/Kconfig
> > @@ -659,12 +659,11 @@ config SPL_FIT_SOURCE
> >
> >  config USE_SPL_FIT_GENERATOR
> >   bool "Use a script to generate the .its script"
> > - default y if SPL_FIT
> > + default y if SPL_FIT && !ARCH_SUNXI
>
> Now `make u-boot.itb` doesn't work.
>
> u-boot.itb is helpful to have because, with CONFIG_OF_LIST, it can be shared
> across all boards of a platform. Only SPL is board-specific (on arm64 sunxi, 
> at
> least).

It is generated, just with a different filename.

>
> Is there a way to make binman also write the FIT without the SPL? Would that
> require duplicating the whole binman node?

Yes it would. We could get more complicated and allow an image to
build on another perhaps. I'm not sure what is easiest here.

>
> >  config SPL_FIT_GENERATOR
> >   string ".its file generator script for U-Boot FIT image"
> >   depends on USE_SPL_FIT_GENERATOR
> > - default "board/sunxi/mksunxi_fit_atf.sh" if SPL_LOAD_FIT && ARCH_SUNXI
> >   default "arch/arm/mach-rockchip/make_fit_atf.py" if SPL_LOAD_FIT && 
> > ARCH_ROCKCHIP
> >   default "arch/arm/mach-zynqmp/mkimage_fit_atf.sh" if SPL_LOAD_FIT && 
> > ARCH_ZYNQMP
> >   default "arch/riscv/lib/mkimage_fit_opensbi.sh" if SPL_LOAD_FIT && 
> > RISCV
> > diff --git a/Makefile b/Makefile
> > index 5b4e60496d6..65024c74089 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -923,11 +923,6 @@ INPUTS-$(CONFIG_REMAKE_ELF) += u-boot.elf
> >  INPUTS-$(CONFIG_EFI_APP) += u-boot-app.efi
> >  INPUTS-$(CONFIG_EFI_STUB) += u-boot-payload.efi
> >
> > -# Build a combined spl + u-boot image for sunxi
> > -ifeq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64)$(CONFIG_SPL),yyy)
> > -INPUTS-y += u-boot-sunxi-with-spl.bin
> > -endif
> > -
> >  # Generate this input file for binman
> >  ifeq ($(CONFIG_SPL),)
> >  INPUTS-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
> > @@ -1024,13 +1019,9 @@ PHONY += inputs
> >  inputs: $(INPUTS-y)
> >
> >  all: .binman_stamp inputs
> > -# Hack for sunxi which doesn't have a proper binman definition for
> > -# 64-bit boards
> > -ifneq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64),yy)
> >  ifeq ($(CONFIG_BINMAN),y)
> >   $(call if_changed,binman)
> >  endif
> > -endif
> >
> >  # Timestamp file to make sure that binman always runs
> >  .binman_stamp: FORCE
> > @@ -1336,6 +1327,8 @@ cmd_binman = $(srctree)/tools/binman/binman $(if 
> > $(BINMAN_DEBUG),-D) \
> >   $(if $(BINMAN_VERBOSE),-v$(BINMAN_VERBOSE)) \
> >   build -u -d u-boot.dtb -O . -m --allow-missing \
> >   -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
> > + -I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
> > + -a atf-bl31-path=${BL31} \
> >   $(BINMAN_$(@F))
> >
> >  OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
> > @@ -1625,13 +1618,6 @@ u-boot-x86-reset16.bin: u-boot FORCE
> >
> >  endif # CONFIG_X86
> >
> > -ifneq ($(CONFIG_ARCH_SUNXI),)
> > -ifeq ($(CONFIG_ARM64),y)
> > -u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
> > - $(call if_changed,cat)
> > -endif
> > -endif
> > -
>
> Now `make u-boot-sunxi-with-spl.bin` doesn't work.
>
> This is less of an issue, but still probably breaks some scripts. It breaks
> mine, at least.

Why do you specify a target? Doesn't it build the file without the target?

One problem with buildman is that there is no definitely of what files
it will produce when run, or at least there is, but it is in the
binman description itself.

This means that 'make clean' doesn't work fully, for example. I can
think of a few ways to implement this. One would be to put a list of
target files into a text file and have 'make clean' use that. We could
also have an option to tell binman to produce a list of files it would
generate if run. Then we might be able to tell binman to generate a
particular file.

>
> >  OBJCOPYFLAGS_u-boot-app.efi := $(OBJCOPYFLAGS_EFI)
> >  u-boot-app.efi: u-boot FORCE
> >   $(call if_changed,zobjcopy)
> > diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
> > index fdd4c80aa46..1d1c3691099 100644
> > --- a/arch/arm/dts/sunxi-u-boot.dtsi
> > +++ b/arch/arm/dts/sunxi-u-boot.dtsi
> > @@ -5,14 +5,73 @@
> >   mmc1 = 

Re: [PATCH 1/3] binman: Support cross-compiling test files to x86

2020-09-05 Thread Simon Glass
Hi Alper,

On Sat, 5 Sep 2020 at 16:51, Alper Nebi Yasak  wrote:
>
> On 05/09/2020 19:36, Simon Glass wrote:
> > For me this fails on x86_64, complaining for example:
> >
> > Exception: Error 2 running 'make -C /tmp/binmant.d17vfu3j/elftest -f
> > /scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/Makefile
> > SRC=/scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/':
> > /scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/Makefile:14:
> > *** Binman tests need to compile to x86, but the CPU arch of your
> > machine is x86_64. Set CROSS_COMPILE to a suitable cross compiler.
> > Stop.
> >
> > Can you make it work on both i386 and x86_64 without complaining? It
> > looks like that is the intent.
>
> I messed up the variable names: defined HOST_ARCH, but used HOSTARCH in
> the check. Fixing that makes it work like it should. (I'll go with
> HOSTARCH since that's where I took the "uname -m | sed" call from).
>
> > Also I'm not sure we need to define vars for all the tools, so you
> > could perhaps drop those that are not needed.
>
> Looks like we don't need anything except CC and OBJCOPY, I'll drop the
> rest.

OK great.

Regards,
Simon


Re: [PATCH v3 08/12] sunxi: Convert 64-bit boards to use binman

2020-09-05 Thread Simon Glass
Hi Samuel,

On Sat, 5 Sep 2020 at 17:42, Samuel Holland  wrote:
>
> On 9/5/20 6:10 PM, Samuel Holland wrote:
> > On 9/1/20 6:14 AM, Simon Glass wrote:
> >> At present 64-bit sunxi boards use the Makefile to create a FIT, using
> >> USE_SPL_FIT_GENERATOR. This is deprecated.
> >>
> >> Update sunxi to use binman instead.
> >>
> >> Signed-off-by: Simon Glass 
> >> ---
> >>
> >> (no changes since v2)
> >>
> >> Changes in v2:
> >> - Add a 'fit-fdt-list' property
> >> - Fix 'board' typo in commit message
> >>
> >>  Kconfig|  3 +-
> >>  Makefile   | 18 ++
> >>  arch/arm/dts/sunxi-u-boot.dtsi | 61 +-
> >>  3 files changed, 63 insertions(+), 19 deletions(-)
> >>
> >> diff --git a/Kconfig b/Kconfig
> >> index 883e3f71d01..837b2f517ae 100644
> >> --- a/Kconfig
> >> +++ b/Kconfig
> >> @@ -659,12 +659,11 @@ config SPL_FIT_SOURCE
> >>
> >>  config USE_SPL_FIT_GENERATOR
> >>  bool "Use a script to generate the .its script"
> >> -default y if SPL_FIT
> >> +default y if SPL_FIT && !ARCH_SUNXI
> >
> > Now `make u-boot.itb` doesn't work.
> >
> > u-boot.itb is helpful to have because, with CONFIG_OF_LIST, it can be shared
> > across all boards of a platform. Only SPL is board-specific (on arm64 
> > sunxi, at
> > least).
> >
> > Is there a way to make binman also write the FIT without the SPL? Would that
> > require duplicating the whole binman node?
> >
> >>  config SPL_FIT_GENERATOR
> >>  string ".its file generator script for U-Boot FIT image"
> >>  depends on USE_SPL_FIT_GENERATOR
> >> -default "board/sunxi/mksunxi_fit_atf.sh" if SPL_LOAD_FIT && ARCH_SUNXI
> >>  default "arch/arm/mach-rockchip/make_fit_atf.py" if SPL_LOAD_FIT && 
> >> ARCH_ROCKCHIP
> >>  default "arch/arm/mach-zynqmp/mkimage_fit_atf.sh" if SPL_LOAD_FIT && 
> >> ARCH_ZYNQMP
> >>  default "arch/riscv/lib/mkimage_fit_opensbi.sh" if SPL_LOAD_FIT && 
> >> RISCV
> >> diff --git a/Makefile b/Makefile
> >> index 5b4e60496d6..65024c74089 100644
> >> --- a/Makefile
> >> +++ b/Makefile
> >> @@ -923,11 +923,6 @@ INPUTS-$(CONFIG_REMAKE_ELF) += u-boot.elf
> >>  INPUTS-$(CONFIG_EFI_APP) += u-boot-app.efi
> >>  INPUTS-$(CONFIG_EFI_STUB) += u-boot-payload.efi
> >>
> >> -# Build a combined spl + u-boot image for sunxi
> >> -ifeq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64)$(CONFIG_SPL),yyy)
> >> -INPUTS-y += u-boot-sunxi-with-spl.bin
> >> -endif
> >> -
> >>  # Generate this input file for binman
> >>  ifeq ($(CONFIG_SPL),)
> >>  INPUTS-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
> >> @@ -1024,13 +1019,9 @@ PHONY += inputs
> >>  inputs: $(INPUTS-y)
> >>
> >>  all: .binman_stamp inputs
> >> -# Hack for sunxi which doesn't have a proper binman definition for
> >> -# 64-bit boards
> >> -ifneq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64),yy)
> >>  ifeq ($(CONFIG_BINMAN),y)
> >>  $(call if_changed,binman)
> >>  endif
> >> -endif
> >>
> >>  # Timestamp file to make sure that binman always runs
> >>  .binman_stamp: FORCE
> >> @@ -1336,6 +1327,8 @@ cmd_binman = $(srctree)/tools/binman/binman $(if 
> >> $(BINMAN_DEBUG),-D) \
> >>  $(if $(BINMAN_VERBOSE),-v$(BINMAN_VERBOSE)) \
> >>  build -u -d u-boot.dtb -O . -m --allow-missing \
> >>  -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
> >> +-I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
> >> +-a atf-bl31-path=${BL31} \
> >>  $(BINMAN_$(@F))
> >>
> >>  OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
> >> @@ -1625,13 +1618,6 @@ u-boot-x86-reset16.bin: u-boot FORCE
> >>
> >>  endif # CONFIG_X86
> >>
> >> -ifneq ($(CONFIG_ARCH_SUNXI),)
> >> -ifeq ($(CONFIG_ARM64),y)
> >> -u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
> >> -$(call if_changed,cat)
> >> -endif
> >> -endif
> >> -
> >
> > Now `make u-boot-sunxi-with-spl.bin` doesn't work.
> >
> > This is less of an issue, but still probably breaks some scripts. It breaks
> > mine, at least.
> >
> >>  OBJCOPYFLAGS_u-boot-app.efi := $(OBJCOPYFLAGS_EFI)
> >>  u-boot-app.efi: u-boot FORCE
> >>  $(call if_changed,zobjcopy)
> >> diff --git a/arch/arm/dts/sunxi-u-boot.dtsi 
> >> b/arch/arm/dts/sunxi-u-boot.dtsi
> >> index fdd4c80aa46..1d1c3691099 100644
> >> --- a/arch/arm/dts/sunxi-u-boot.dtsi
> >> +++ b/arch/arm/dts/sunxi-u-boot.dtsi
> >> @@ -5,14 +5,73 @@
> >>  mmc1 = 
> >>  };
> >>
> >> -binman {
> >> +binman: binman {
> >> +multiple-images;
> >> +};
> >> +};
> >> +
> >> + {
> >> +u-boot-sunxi-with-spl {
> >>  filename = "u-boot-sunxi-with-spl.bin";
> >>  pad-byte = <0xff>;
> >
> > style: blank line here (and above "atf" and "@config-SEQ" below).
> >
> >>  blob {
> >>  filename = "spl/sunxi-spl.bin";
> >>  };
> >> +#ifdef CONFIG_ARM64
> >> +fit {
> >> +description = "Configuration to load ATF before 
> >> U-Boot";
> >> +

Re: [PATCH v3 06/12] binman: Support generating FITs with multiple dtbs

2020-09-05 Thread Simon Glass
Hi Samuel,

On Sat, 5 Sep 2020 at 17:19, Samuel Holland  wrote:
>
> On 9/5/20 5:41 PM, Samuel Holland wrote:
> > On 9/1/20 6:13 AM, Simon Glass wrote:
> >> In some cases it is useful to generate a FIT which has a number of DTB
> >> images, selectable by configuration. Add support for this in binman,
> >> using a simple iterator and string substitution.
> >>
> >> Signed-off-by: Simon Glass 
> >> ---
> >>
> >> Changes in v3:
> >> - Rebase on top of earlier binman series
> >>
> >> Changes in v2:
> >> - Add a check for a missing fit,fdt-list property
> >> - Add a check for a missing of-list property
> >> - Add a check for an empty of-list
> >>
> >>  tools/binman/README.entries   |  48 +++-
> >>  tools/binman/etype/fit.py |  94 +++-
> >>  tools/binman/ftest.py | 106 +-
> >>  tools/binman/test/170_fit_fdt.dts |  55 +
> >>  .../binman/test/171_fit_fdt_missing_prop.dts  |  54 +
> >>  5 files changed, 346 insertions(+), 11 deletions(-)
> >>  create mode 100644 tools/binman/test/170_fit_fdt.dts
> >>  create mode 100644 tools/binman/test/171_fit_fdt_missing_prop.dts
> >
> > [snip]
> >
> >> @@ -357,7 +358,52 @@ For example, this creates an image containing a FIT 
> >> with U-Boot SPL:
> >>  };
> >>  };
> >>
> >> -Properties:
> >> +U-Boot supports creating fdt and config nodes automatically. To do this,
> >> +pass an of-list property (e.g. -a of-list=file1 file2). This tells binman
> >> +that you want to generates nodes for two files: file1.dtb and file2.dtb
> >> +The fit,fdt-list property (see above) indicates that of-list should be 
> >> used.
> >> +If the property is missing you will get an error.
> >> +
> >> +Then add a 'generator node', a node with a name starting with '@':
> >> +
> >> +images {
> >> +@fdt-SEQ {
> >> +description = "fdt-NAME";
> >> +type = "flat_dt";
> >> +compression = "none";
> >> +};
> >> +};
> >> +
> >> +This tells binman to create nodes fdt-1 and fdt-2 for each of your two
> >> +files. All the properties you specify will be included in the node. This
> >> +node acts like a template to generate the nodes. The generator node itself
> >> +does not appear in the output - it is replaced with what binman generates.
> >
> > Is this output written anywhere? The compiled DTB has the unprocessed 
> > template
> > in it, and the final image created by binman requires some dissection to 
> > get to
> > the FIT ITS.
> >
> >> +
> >> +You can create config nodes in a similar way:
> >> +
> >> +configurations {
> >> +default = "@config-DEFAULT-SEQ";
> >> +@config-SEQ {
> >> +description = "NAME";
> >> +firmware = "uboot";
> >> +loadables = "atf";
> >> +fdt = "fdt-SEQ";
> >> +};
> >> +};
> >> +
> >> +This tells binman to create nodes config-1 and config-2, i.e. a config for
> >> +each of your two files.
> >> +
> >> +Available substitutions for '@' nodes are:
> >> +
> >> +SEQSequence number of the generated fdt (1, 2, ...)
> >> +NAME   Name of the dtb as provided (i.e. without adding '.dtb')
> >
> > There is no mention of DEFAULT-SEQ here.
>
> I see now that you added DEFAULT-SEQ in a later patch, even though it's 
> present
> in the example above(?). The comment here and on the sunxi dtsi still apply,
> whichever patch the change should go in.

OK. Well the existing has something that is documented in a later
patch, unfortunately.

>
> >> +
> >> +Note that if no devicetree files are provided (with '-a of-list' as above)
> >> +then no nodes will be generated.
> >> +
> >> +
> >> +Properties (in the 'fit' node itself):
> >>  fit,external-offset: Indicates that the contents of the FIT are 
> >> external
> >>  and provides the external offset. This is passsed to mkimage via
> >>  the -E and -p flags.
> >
> > [snip]
> >
>

Regards,
Simon


Re: [PATCH 2/3] binman: Use target-specific tools when cross-compiling

2020-09-05 Thread Simon Glass
Hi Alper,

On Sat, 5 Sep 2020 at 17:04, Alper Nebi Yasak  wrote:
>
> On 05/09/2020 19:37, Simon Glass wrote:
> > This looks good, but it drops the use of DTC to specify the
> > device-tree compiler. Can you add it back?
>
> I think you're referring to this hunk:
>
> >  # If we don't have a directory, put it in the tools tempdir
> >  search_list = []
> >  for path in search_paths:
> >  search_list.extend(['-i', path])
> > -args = ['-I', 'dts', '-o', dtb_output, '-O', 'dtb',
> > +dtc, args = tools.GetTargetCompileTool('dtc')
> > +args += ['-I', 'dts', '-o', dtb_output, '-O', 'dtb',
> >  '-W', 'no-unit_address_vs_reg']
> >  args.extend(search_list)
> >  args.append(dts_input)
> > -dtc = os.environ.get('DTC') or 'dtc'
> >  command.Run(dtc, *args, capture_stderr=capture_stderr)
> >  return dtb_output
>
> where I removed the os.environ.get('DTC'). Instead of that, I get the
> command for dtc from GetTargetCompileTool('dtc'), which does check the
> 'DTC' environment variable:
>
> > +def GetTargetCompileTool(name, cross_compile=None):
> >  [...]
> > +env = dict(os.environ)
> > +
> > +target_name = None
> > +extra_args = []
> > +if name in ('as', 'ld', 'cc', 'cpp', 'ar', 'nm', 'ldr', 'strip',
> > +'objcopy', 'objdump', 'dtc'):
> > +target_name, *extra_args = env.get(name.upper(), '').split(' ')
> > +
> > +if target_name:
> > +return target_name, extra_args
>
> If that's not convincing enough: running 'DTC=false binman test' gets me
> a lot of test errors that I don't get without the 'DTC=false'.

OK I did look at that function thinking you might have done that, but
was expecting the same code...so this seems OK to me.

Reviewed-by: Simon Glass 

Regards,
Simon


Re: [PATCH v3 08/12] sunxi: Convert 64-bit boards to use binman

2020-09-05 Thread Samuel Holland
On 9/5/20 6:10 PM, Samuel Holland wrote:
> On 9/1/20 6:14 AM, Simon Glass wrote:
>> At present 64-bit sunxi boards use the Makefile to create a FIT, using
>> USE_SPL_FIT_GENERATOR. This is deprecated.
>>
>> Update sunxi to use binman instead.
>>
>> Signed-off-by: Simon Glass 
>> ---
>>
>> (no changes since v2)
>>
>> Changes in v2:
>> - Add a 'fit-fdt-list' property
>> - Fix 'board' typo in commit message
>>
>>  Kconfig|  3 +-
>>  Makefile   | 18 ++
>>  arch/arm/dts/sunxi-u-boot.dtsi | 61 +-
>>  3 files changed, 63 insertions(+), 19 deletions(-)
>>
>> diff --git a/Kconfig b/Kconfig
>> index 883e3f71d01..837b2f517ae 100644
>> --- a/Kconfig
>> +++ b/Kconfig
>> @@ -659,12 +659,11 @@ config SPL_FIT_SOURCE
>>  
>>  config USE_SPL_FIT_GENERATOR
>>  bool "Use a script to generate the .its script"
>> -default y if SPL_FIT
>> +default y if SPL_FIT && !ARCH_SUNXI
> 
> Now `make u-boot.itb` doesn't work.
> 
> u-boot.itb is helpful to have because, with CONFIG_OF_LIST, it can be shared
> across all boards of a platform. Only SPL is board-specific (on arm64 sunxi, 
> at
> least).
> 
> Is there a way to make binman also write the FIT without the SPL? Would that
> require duplicating the whole binman node?
> 
>>  config SPL_FIT_GENERATOR
>>  string ".its file generator script for U-Boot FIT image"
>>  depends on USE_SPL_FIT_GENERATOR
>> -default "board/sunxi/mksunxi_fit_atf.sh" if SPL_LOAD_FIT && ARCH_SUNXI
>>  default "arch/arm/mach-rockchip/make_fit_atf.py" if SPL_LOAD_FIT && 
>> ARCH_ROCKCHIP
>>  default "arch/arm/mach-zynqmp/mkimage_fit_atf.sh" if SPL_LOAD_FIT && 
>> ARCH_ZYNQMP
>>  default "arch/riscv/lib/mkimage_fit_opensbi.sh" if SPL_LOAD_FIT && RISCV
>> diff --git a/Makefile b/Makefile
>> index 5b4e60496d6..65024c74089 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -923,11 +923,6 @@ INPUTS-$(CONFIG_REMAKE_ELF) += u-boot.elf
>>  INPUTS-$(CONFIG_EFI_APP) += u-boot-app.efi
>>  INPUTS-$(CONFIG_EFI_STUB) += u-boot-payload.efi
>>  
>> -# Build a combined spl + u-boot image for sunxi
>> -ifeq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64)$(CONFIG_SPL),yyy)
>> -INPUTS-y += u-boot-sunxi-with-spl.bin
>> -endif
>> -
>>  # Generate this input file for binman
>>  ifeq ($(CONFIG_SPL),)
>>  INPUTS-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
>> @@ -1024,13 +1019,9 @@ PHONY += inputs
>>  inputs: $(INPUTS-y)
>>  
>>  all: .binman_stamp inputs
>> -# Hack for sunxi which doesn't have a proper binman definition for
>> -# 64-bit boards
>> -ifneq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64),yy)
>>  ifeq ($(CONFIG_BINMAN),y)
>>  $(call if_changed,binman)
>>  endif
>> -endif
>>  
>>  # Timestamp file to make sure that binman always runs
>>  .binman_stamp: FORCE
>> @@ -1336,6 +1327,8 @@ cmd_binman = $(srctree)/tools/binman/binman $(if 
>> $(BINMAN_DEBUG),-D) \
>>  $(if $(BINMAN_VERBOSE),-v$(BINMAN_VERBOSE)) \
>>  build -u -d u-boot.dtb -O . -m --allow-missing \
>>  -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
>> +-I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
>> +-a atf-bl31-path=${BL31} \
>>  $(BINMAN_$(@F))
>>  
>>  OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
>> @@ -1625,13 +1618,6 @@ u-boot-x86-reset16.bin: u-boot FORCE
>>  
>>  endif # CONFIG_X86
>>  
>> -ifneq ($(CONFIG_ARCH_SUNXI),)
>> -ifeq ($(CONFIG_ARM64),y)
>> -u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
>> -$(call if_changed,cat)
>> -endif
>> -endif
>> -
> 
> Now `make u-boot-sunxi-with-spl.bin` doesn't work.
> 
> This is less of an issue, but still probably breaks some scripts. It breaks
> mine, at least.
> 
>>  OBJCOPYFLAGS_u-boot-app.efi := $(OBJCOPYFLAGS_EFI)
>>  u-boot-app.efi: u-boot FORCE
>>  $(call if_changed,zobjcopy)
>> diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
>> index fdd4c80aa46..1d1c3691099 100644
>> --- a/arch/arm/dts/sunxi-u-boot.dtsi
>> +++ b/arch/arm/dts/sunxi-u-boot.dtsi
>> @@ -5,14 +5,73 @@
>>  mmc1 = 
>>  };
>>  
>> -binman {
>> +binman: binman {
>> +multiple-images;
>> +};
>> +};
>> +
>> + {
>> +u-boot-sunxi-with-spl {
>>  filename = "u-boot-sunxi-with-spl.bin";
>>  pad-byte = <0xff>;
> 
> style: blank line here (and above "atf" and "@config-SEQ" below).
> 
>>  blob {
>>  filename = "spl/sunxi-spl.bin";
>>  };
>> +#ifdef CONFIG_ARM64
>> +fit {
>> +description = "Configuration to load ATF before U-Boot";
>> +#address-cells = <1>;
>> +fit,fdt-list = "of-list";
>> +
>> +images {
>> +uboot {
>> +description = "U-Boot (64-bit)";
>> +type = "standalone";
>> +arch = "arm64";
>> 

Re: [PATCH v3 06/12] binman: Support generating FITs with multiple dtbs

2020-09-05 Thread Samuel Holland
On 9/5/20 5:41 PM, Samuel Holland wrote:
> On 9/1/20 6:13 AM, Simon Glass wrote:
>> In some cases it is useful to generate a FIT which has a number of DTB
>> images, selectable by configuration. Add support for this in binman,
>> using a simple iterator and string substitution.
>>
>> Signed-off-by: Simon Glass 
>> ---
>>
>> Changes in v3:
>> - Rebase on top of earlier binman series
>>
>> Changes in v2:
>> - Add a check for a missing fit,fdt-list property
>> - Add a check for a missing of-list property
>> - Add a check for an empty of-list
>>
>>  tools/binman/README.entries   |  48 +++-
>>  tools/binman/etype/fit.py |  94 +++-
>>  tools/binman/ftest.py | 106 +-
>>  tools/binman/test/170_fit_fdt.dts |  55 +
>>  .../binman/test/171_fit_fdt_missing_prop.dts  |  54 +
>>  5 files changed, 346 insertions(+), 11 deletions(-)
>>  create mode 100644 tools/binman/test/170_fit_fdt.dts
>>  create mode 100644 tools/binman/test/171_fit_fdt_missing_prop.dts
> 
> [snip]
> 
>> @@ -357,7 +358,52 @@ For example, this creates an image containing a FIT 
>> with U-Boot SPL:
>>  };
>>  };
>>  
>> -Properties:
>> +U-Boot supports creating fdt and config nodes automatically. To do this,
>> +pass an of-list property (e.g. -a of-list=file1 file2). This tells binman
>> +that you want to generates nodes for two files: file1.dtb and file2.dtb
>> +The fit,fdt-list property (see above) indicates that of-list should be used.
>> +If the property is missing you will get an error.
>> +
>> +Then add a 'generator node', a node with a name starting with '@':
>> +
>> +images {
>> +@fdt-SEQ {
>> +description = "fdt-NAME";
>> +type = "flat_dt";
>> +compression = "none";
>> +};
>> +};
>> +
>> +This tells binman to create nodes fdt-1 and fdt-2 for each of your two
>> +files. All the properties you specify will be included in the node. This
>> +node acts like a template to generate the nodes. The generator node itself
>> +does not appear in the output - it is replaced with what binman generates.
> 
> Is this output written anywhere? The compiled DTB has the unprocessed template
> in it, and the final image created by binman requires some dissection to get 
> to
> the FIT ITS.
> 
>> +
>> +You can create config nodes in a similar way:
>> +
>> +configurations {
>> +default = "@config-DEFAULT-SEQ";
>> +@config-SEQ {
>> +description = "NAME";
>> +firmware = "uboot";
>> +loadables = "atf";
>> +fdt = "fdt-SEQ";
>> +};
>> +};
>> +
>> +This tells binman to create nodes config-1 and config-2, i.e. a config for
>> +each of your two files.
>> +
>> +Available substitutions for '@' nodes are:
>> +
>> +SEQSequence number of the generated fdt (1, 2, ...)
>> +NAME   Name of the dtb as provided (i.e. without adding '.dtb')
> 
> There is no mention of DEFAULT-SEQ here.

I see now that you added DEFAULT-SEQ in a later patch, even though it's present
in the example above(?). The comment here and on the sunxi dtsi still apply,
whichever patch the change should go in.

>> +
>> +Note that if no devicetree files are provided (with '-a of-list' as above)
>> +then no nodes will be generated.
>> +
>> +
>> +Properties (in the 'fit' node itself):
>>  fit,external-offset: Indicates that the contents of the FIT are external
>>  and provides the external offset. This is passsed to mkimage via
>>  the -E and -p flags.
> 
> [snip]
> 



Re: [PATCH 3/3] binman: Allow resolving host-specific tools from env vars

2020-09-05 Thread Alper Nebi Yasak
On 05/09/2020 19:37, Simon Glass wrote:
> Please see below.
> 
> Also please add a mention of the CROSS_COMPILE thing in binman's README.
> 
>> +def GetHostCompileTool(name):
>> +"""Get the host-specific version for a compile tool
>> +
>> +This checks the environment variables that specify which version of
>> +the tool should be used.
> 
> Can you please expand the comment to mention the environment variables
> it checks?

OK, will send a v2 after doing these with the fixes for the first patch
(unless you point out until then something new that I should fix).


Re: [PATCH v3 08/12] sunxi: Convert 64-bit boards to use binman

2020-09-05 Thread Samuel Holland
On 9/1/20 6:14 AM, Simon Glass wrote:
> At present 64-bit sunxi boards use the Makefile to create a FIT, using
> USE_SPL_FIT_GENERATOR. This is deprecated.
> 
> Update sunxi to use binman instead.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v2)
> 
> Changes in v2:
> - Add a 'fit-fdt-list' property
> - Fix 'board' typo in commit message
> 
>  Kconfig|  3 +-
>  Makefile   | 18 ++
>  arch/arm/dts/sunxi-u-boot.dtsi | 61 +-
>  3 files changed, 63 insertions(+), 19 deletions(-)
> 
> diff --git a/Kconfig b/Kconfig
> index 883e3f71d01..837b2f517ae 100644
> --- a/Kconfig
> +++ b/Kconfig
> @@ -659,12 +659,11 @@ config SPL_FIT_SOURCE
>  
>  config USE_SPL_FIT_GENERATOR
>   bool "Use a script to generate the .its script"
> - default y if SPL_FIT
> + default y if SPL_FIT && !ARCH_SUNXI

Now `make u-boot.itb` doesn't work.

u-boot.itb is helpful to have because, with CONFIG_OF_LIST, it can be shared
across all boards of a platform. Only SPL is board-specific (on arm64 sunxi, at
least).

Is there a way to make binman also write the FIT without the SPL? Would that
require duplicating the whole binman node?

>  config SPL_FIT_GENERATOR
>   string ".its file generator script for U-Boot FIT image"
>   depends on USE_SPL_FIT_GENERATOR
> - default "board/sunxi/mksunxi_fit_atf.sh" if SPL_LOAD_FIT && ARCH_SUNXI
>   default "arch/arm/mach-rockchip/make_fit_atf.py" if SPL_LOAD_FIT && 
> ARCH_ROCKCHIP
>   default "arch/arm/mach-zynqmp/mkimage_fit_atf.sh" if SPL_LOAD_FIT && 
> ARCH_ZYNQMP
>   default "arch/riscv/lib/mkimage_fit_opensbi.sh" if SPL_LOAD_FIT && RISCV
> diff --git a/Makefile b/Makefile
> index 5b4e60496d6..65024c74089 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -923,11 +923,6 @@ INPUTS-$(CONFIG_REMAKE_ELF) += u-boot.elf
>  INPUTS-$(CONFIG_EFI_APP) += u-boot-app.efi
>  INPUTS-$(CONFIG_EFI_STUB) += u-boot-payload.efi
>  
> -# Build a combined spl + u-boot image for sunxi
> -ifeq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64)$(CONFIG_SPL),yyy)
> -INPUTS-y += u-boot-sunxi-with-spl.bin
> -endif
> -
>  # Generate this input file for binman
>  ifeq ($(CONFIG_SPL),)
>  INPUTS-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
> @@ -1024,13 +1019,9 @@ PHONY += inputs
>  inputs: $(INPUTS-y)
>  
>  all: .binman_stamp inputs
> -# Hack for sunxi which doesn't have a proper binman definition for
> -# 64-bit boards
> -ifneq ($(CONFIG_ARCH_SUNXI)$(CONFIG_ARM64),yy)
>  ifeq ($(CONFIG_BINMAN),y)
>   $(call if_changed,binman)
>  endif
> -endif
>  
>  # Timestamp file to make sure that binman always runs
>  .binman_stamp: FORCE
> @@ -1336,6 +1327,8 @@ cmd_binman = $(srctree)/tools/binman/binman $(if 
> $(BINMAN_DEBUG),-D) \
>   $(if $(BINMAN_VERBOSE),-v$(BINMAN_VERBOSE)) \
>   build -u -d u-boot.dtb -O . -m --allow-missing \
>   -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
> + -I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
> + -a atf-bl31-path=${BL31} \
>   $(BINMAN_$(@F))
>  
>  OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
> @@ -1625,13 +1618,6 @@ u-boot-x86-reset16.bin: u-boot FORCE
>  
>  endif # CONFIG_X86
>  
> -ifneq ($(CONFIG_ARCH_SUNXI),)
> -ifeq ($(CONFIG_ARM64),y)
> -u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
> - $(call if_changed,cat)
> -endif
> -endif
> -

Now `make u-boot-sunxi-with-spl.bin` doesn't work.

This is less of an issue, but still probably breaks some scripts. It breaks
mine, at least.

>  OBJCOPYFLAGS_u-boot-app.efi := $(OBJCOPYFLAGS_EFI)
>  u-boot-app.efi: u-boot FORCE
>   $(call if_changed,zobjcopy)
> diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
> index fdd4c80aa46..1d1c3691099 100644
> --- a/arch/arm/dts/sunxi-u-boot.dtsi
> +++ b/arch/arm/dts/sunxi-u-boot.dtsi
> @@ -5,14 +5,73 @@
>   mmc1 = 
>   };
>  
> - binman {
> + binman: binman {
> + multiple-images;
> + };
> +};
> +
> + {
> + u-boot-sunxi-with-spl {
>   filename = "u-boot-sunxi-with-spl.bin";
>   pad-byte = <0xff>;

style: blank line here (and above "atf" and "@config-SEQ" below).

>   blob {
>   filename = "spl/sunxi-spl.bin";
>   };
> +#ifdef CONFIG_ARM64
> + fit {
> + description = "Configuration to load ATF before U-Boot";
> + #address-cells = <1>;
> + fit,fdt-list = "of-list";
> +
> + images {
> + uboot {
> + description = "U-Boot (64-bit)";
> + type = "standalone";
> + arch = "arm64";
> + compression = "none";
> + load = <0x4a00>;
> +
> + 

Re: [PATCH 2/3] binman: Use target-specific tools when cross-compiling

2020-09-05 Thread Alper Nebi Yasak
On 05/09/2020 19:37, Simon Glass wrote:
> This looks good, but it drops the use of DTC to specify the
> device-tree compiler. Can you add it back?

I think you're referring to this hunk:

>  # If we don't have a directory, put it in the tools tempdir
>  search_list = []
>  for path in search_paths:
>  search_list.extend(['-i', path])
> -args = ['-I', 'dts', '-o', dtb_output, '-O', 'dtb',
> +dtc, args = tools.GetTargetCompileTool('dtc')
> +args += ['-I', 'dts', '-o', dtb_output, '-O', 'dtb',
>  '-W', 'no-unit_address_vs_reg']
>  args.extend(search_list)
>  args.append(dts_input)
> -dtc = os.environ.get('DTC') or 'dtc'
>  command.Run(dtc, *args, capture_stderr=capture_stderr)
>  return dtb_output

where I removed the os.environ.get('DTC'). Instead of that, I get the
command for dtc from GetTargetCompileTool('dtc'), which does check the
'DTC' environment variable:

> +def GetTargetCompileTool(name, cross_compile=None):
>  [...]
> +env = dict(os.environ)
> +
> +target_name = None
> +extra_args = []
> +if name in ('as', 'ld', 'cc', 'cpp', 'ar', 'nm', 'ldr', 'strip',
> +'objcopy', 'objdump', 'dtc'):
> +target_name, *extra_args = env.get(name.upper(), '').split(' ')
> +
> +if target_name:
> +return target_name, extra_args

If that's not convincing enough: running 'DTC=false binman test' gets me
a lot of test errors that I don't get without the 'DTC=false'.


Re: [PATCH v3 05/12] binman: Add support for ATF BL31

2020-09-05 Thread Samuel Holland
On 9/1/20 6:13 AM, Simon Glass wrote:
> Add an entry for ARM Trusted Firmware's 'BL31' payload, which is the
> device's main firmware. Typically this is U-Boot.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v3:
> - Rebase on top of earlier binman series
> 
> Changes in v2:
> - Add the URL of ARM Trusted Firmware and mention of U-Boot docs
> - Fix copyright year
> - Update docs to indicate that BL31 is loaded from SPL
> - Update docs to mention both bl31.bin and bl31.elf
> 
>  tools/binman/README.entries| 14 ++
>  tools/binman/etype/atf_bl31.py | 24 
>  tools/binman/ftest.py  |  9 +
>  tools/binman/test/169_atf_bl31.dts | 16 
>  4 files changed, 63 insertions(+)
>  create mode 100644 tools/binman/etype/atf_bl31.py
>  create mode 100644 tools/binman/test/169_atf_bl31.dts

Does this mean every kind of firmware blob referenced by FIT generator scripts
(TEE fimware, SCP firmware, OpenSBI firmware, etc.) needs its own Python 
package?

What if you need multiple versions of ATF BL31 and TEE firmware for different
configurations, like Rockchip currently does? You would need dynamic argument
names, but then how do you get them in the Makefile?

This approach doesn't seem very flexible or scalable.

Why not have a generic Entry_blob_named_by_env, with a "filename-var" (or
similar) property in addition to "filename"? Then the existing interface of the
FIT generator scripts could be maintained without tons of boilerplate.


Re: [PATCH 1/3] binman: Support cross-compiling test files to x86

2020-09-05 Thread Alper Nebi Yasak
On 05/09/2020 19:36, Simon Glass wrote:
> For me this fails on x86_64, complaining for example:
> 
> Exception: Error 2 running 'make -C /tmp/binmant.d17vfu3j/elftest -f
> /scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/Makefile
> SRC=/scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/':
> /scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/Makefile:14:
> *** Binman tests need to compile to x86, but the CPU arch of your
> machine is x86_64. Set CROSS_COMPILE to a suitable cross compiler.
> Stop.
> 
> Can you make it work on both i386 and x86_64 without complaining? It
> looks like that is the intent.

I messed up the variable names: defined HOST_ARCH, but used HOSTARCH in
the check. Fixing that makes it work like it should. (I'll go with
HOSTARCH since that's where I took the "uname -m | sed" call from).

> Also I'm not sure we need to define vars for all the tools, so you
> could perhaps drop those that are not needed.

Looks like we don't need anything except CC and OBJCOPY, I'll drop the
rest.


Re: [PATCH v3 06/12] binman: Support generating FITs with multiple dtbs

2020-09-05 Thread Samuel Holland
On 9/1/20 6:13 AM, Simon Glass wrote:
> In some cases it is useful to generate a FIT which has a number of DTB
> images, selectable by configuration. Add support for this in binman,
> using a simple iterator and string substitution.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v3:
> - Rebase on top of earlier binman series
> 
> Changes in v2:
> - Add a check for a missing fit,fdt-list property
> - Add a check for a missing of-list property
> - Add a check for an empty of-list
> 
>  tools/binman/README.entries   |  48 +++-
>  tools/binman/etype/fit.py |  94 +++-
>  tools/binman/ftest.py | 106 +-
>  tools/binman/test/170_fit_fdt.dts |  55 +
>  .../binman/test/171_fit_fdt_missing_prop.dts  |  54 +
>  5 files changed, 346 insertions(+), 11 deletions(-)
>  create mode 100644 tools/binman/test/170_fit_fdt.dts
>  create mode 100644 tools/binman/test/171_fit_fdt_missing_prop.dts

[snip]

> @@ -357,7 +358,52 @@ For example, this creates an image containing a FIT with 
> U-Boot SPL:
>  };
>  };
>  
> -Properties:
> +U-Boot supports creating fdt and config nodes automatically. To do this,
> +pass an of-list property (e.g. -a of-list=file1 file2). This tells binman
> +that you want to generates nodes for two files: file1.dtb and file2.dtb
> +The fit,fdt-list property (see above) indicates that of-list should be used.
> +If the property is missing you will get an error.
> +
> +Then add a 'generator node', a node with a name starting with '@':
> +
> +images {
> +@fdt-SEQ {
> +description = "fdt-NAME";
> +type = "flat_dt";
> +compression = "none";
> +};
> +};
> +
> +This tells binman to create nodes fdt-1 and fdt-2 for each of your two
> +files. All the properties you specify will be included in the node. This
> +node acts like a template to generate the nodes. The generator node itself
> +does not appear in the output - it is replaced with what binman generates.

Is this output written anywhere? The compiled DTB has the unprocessed template
in it, and the final image created by binman requires some dissection to get to
the FIT ITS.

> +
> +You can create config nodes in a similar way:
> +
> +configurations {
> +default = "@config-DEFAULT-SEQ";
> +@config-SEQ {
> +description = "NAME";
> +firmware = "uboot";
> +loadables = "atf";
> +fdt = "fdt-SEQ";
> +};
> +};
> +
> +This tells binman to create nodes config-1 and config-2, i.e. a config for
> +each of your two files.
> +
> +Available substitutions for '@' nodes are:
> +
> +SEQSequence number of the generated fdt (1, 2, ...)
> +NAME   Name of the dtb as provided (i.e. without adding '.dtb')

There is no mention of DEFAULT-SEQ here.

> +
> +Note that if no devicetree files are provided (with '-a of-list' as above)
> +then no nodes will be generated.
> +
> +
> +Properties (in the 'fit' node itself):
>  fit,external-offset: Indicates that the contents of the FIT are external
>  and provides the external offset. This is passsed to mkimage via
>  the -E and -p flags.

[snip]


Re: [PATCH] spl: Add SPL_SERIAL as requirement for SDP_USB_SDP

2020-09-05 Thread Fabio Estevam
Hi Otavio,

On Sat, Sep 5, 2020 at 6:37 PM Otavio Salvador  wrote:
>
> Signed-off-by: Otavio Salvador 

Please always provide a commit log for the patches.


[PATCH] spl: Add SPL_SERIAL as requirement for SDP_USB_SDP

2020-09-05 Thread Otavio Salvador
Signed-off-by: Otavio Salvador 
---

 common/spl/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index af8255a8d6..20c5c4af3c 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -1237,6 +1237,7 @@ endchoice
 
 config SPL_USB_SDP_SUPPORT
bool "Support SDP (Serial Download Protocol)"
+   depends on SPL_SERIAL_SUPPORT
help
  Enable Serial Download Protocol (SDP) device support in SPL. This
  allows to download images into memory and execute (jump to) them
-- 
2.28.0



Re: [PATCH v3 07/12] Makefile: Support missing external blobs always

2020-09-05 Thread Simon Glass
At present binman warns about missing external blobs only when the
BUILD_ROM is defined. Enable this behaviour always, since many boards
are starting to use these (e.g. ARM Trusted Firmware's BL31).

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to support missing external blobs always

 Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 06/12] binman: Support generating FITs with multiple dtbs

2020-09-05 Thread Simon Glass
In some cases it is useful to generate a FIT which has a number of DTB
images, selectable by configuration. Add support for this in binman,
using a simple iterator and string substitution.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Rebase on top of earlier binman series

Changes in v2:
- Add a check for a missing fit,fdt-list property
- Add a check for a missing of-list property
- Add a check for an empty of-list

 tools/binman/README.entries   |  48 +++-
 tools/binman/etype/fit.py |  94 +++-
 tools/binman/ftest.py | 106 +-
 tools/binman/test/170_fit_fdt.dts |  55 +
 .../binman/test/171_fit_fdt_missing_prop.dts  |  54 +
 5 files changed, 346 insertions(+), 11 deletions(-)
 create mode 100644 tools/binman/test/170_fit_fdt.dts
 create mode 100644 tools/binman/test/171_fit_fdt_missing_prop.dts

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 01/12] binman: Allow entry args to be required

2020-09-05 Thread Simon Glass
If an entry argument is needed by an entry but the entry argument is not
present, then a strange error can occur when trying to read the file.

Fix this by allowing arguments to be required. Select this option for the
cros-ec-rw entry. If a filename is provided in the node, allow that to be
used.

Also tidy up a few related tests to make the error string easier to find,
and fully ignore unused return values.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/README.entries |  7 ++-
 tools/binman/etype/blob_named_by_arg.py | 10 ++
 tools/binman/etype/cros_ec_rw.py|  3 +--
 tools/binman/ftest.py   | 15 +++
 4 files changed, 24 insertions(+), 11 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH 1/2] core: improve of_match_ptr with OF_PLATDATA

2020-09-05 Thread Simon Glass
On Wed, 29 Jul 2020 at 10:17, Walter Lozano  wrote:
>
> Currently of_match_ptr is used to avoid referencing compatible strings
> when OF_CONTROL is not enabled. This behaviour could be improved by
> taking into account also OF_PLATDATA, as when this configuration is
> enabled the compatible strings are not used at all.
>
> Signed-off-by: Walter Lozano 
> ---
>
>  include/dm/device.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 02/12] binman: Fix up a few missing comments

2020-09-05 Thread Simon Glass
Tidy up a few test functions which lack argument comments. Rename one that
has the same name as a different test.

Also fix up the comment for PrepareImagesAndDtbs().

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/control.py |  5 +
 tools/binman/ftest.py   | 22 +-
 2 files changed, 26 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 03/12] libfdt: Detected out-of-space with fdt_finish()

2020-09-05 Thread Simon Glass
At present the Python sequential-write interface can produce an error when
it calls fdt_finish(), since this needs to add a terminating tag to the
end of the struct section.

Fix this by automatically expanding the buffer if needed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 scripts/dtc/pylibfdt/libfdt.i_shipped | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2] buildman: Use git worktrees instead of git clones when possible

2020-09-05 Thread Simon Glass
On Sat, 5 Sep 2020 at 10:36, Simon Glass  wrote:
>
> On Thu, 3 Sep 2020 at 06:51, Alper Nebi Yasak  
> wrote:
> >
> > This patch makes buildman create linked working trees instead of clones
> > of the source repository, but keeps updating the older clones of the
> > repository that might already exist. These worktrees share "everything
> > except working directory specific files such as HEAD, index, etc." with
> > the source repository. See the git-worktree(1) manual page for more
> > information.
> >
> > If git-worktree isn't available, silently falls back to cloning the
> > repository.
> >
> > Signed-off-by: Alper Nebi Yasak 
> > ---
> > I used 'git worktree list's return code, since 'git worktree' returns
> > non-zero (prints usage) even if it's available.
> >
> > This does fall back to git clone on my Ubuntu 14.04 amd64 VM, but all
> > the builds instantly give an error about the Makefile even before this
> > patch. The buildman parts are working as far as I can tell.
> >
> > Changes in v2:
> > - Fall back to cloning if git-worktree isn't available
> > - Add a gitutil.CheckWorktreeIsAvailable(git_dir) function
> > - Refactor the _PrepareThread changes
> > - Make _PrepeareThread's setup_git argument accept 'clone' or 'worktree'
> > - Some comment and docstring changes
> >
> > v1: https://patchwork.ozlabs.org/project/uboot/list/?series=199060
> >
> >  tools/buildman/builder.py   | 48 ++---
> >  tools/buildman/func_test.py |  2 ++
> >  tools/patman/gitutil.py | 42 
> >  3 files changed, 84 insertions(+), 8 deletions(-)
>
> Reviewed-by: Simon Glass 

Tested-by: Simon Glass 

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 05/12] binman: Add support for ATF BL31

2020-09-05 Thread Simon Glass
Add an entry for ARM Trusted Firmware's 'BL31' payload, which is the
device's main firmware. Typically this is U-Boot.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Rebase on top of earlier binman series

Changes in v2:
- Add the URL of ARM Trusted Firmware and mention of U-Boot docs
- Fix copyright year
- Update docs to indicate that BL31 is loaded from SPL
- Update docs to mention both bl31.bin and bl31.elf

 tools/binman/README.entries| 14 ++
 tools/binman/etype/atf_bl31.py | 24 
 tools/binman/ftest.py  |  9 +
 tools/binman/test/169_atf_bl31.dts | 16 
 4 files changed, 63 insertions(+)
 create mode 100644 tools/binman/etype/atf_bl31.py
 create mode 100644 tools/binman/test/169_atf_bl31.dts

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 04/12] binman: Move 'external' support into base class

2020-09-05 Thread Simon Glass
At present we have an Entry_blob_ext which implement a blob which holds an
external binary. We need to support other entry types that hold external
binaries, e.g. Entry_blob_named_by_arg. Move the support into the base
Entry class to allow this.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to move 'external' support into base class

 tools/binman/README.entries|  2 +-
 tools/binman/entry.py  | 14 ++
 tools/binman/etype/blob.py |  8 +++-
 tools/binman/etype/blob_ext.py | 11 ---
 tools/binman/etype/section.py  | 14 ++
 5 files changed, 24 insertions(+), 25 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH] Revert "env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set"

2020-09-05 Thread Marek Vasut
On 8/27/20 3:03 PM, Tom Rini wrote:
> On Thu, Aug 27, 2020 at 11:49:25AM +0200, Marek Vasut wrote:
>> On 8/27/20 11:43 AM, Alex Kiernan wrote:
>>> This reverts commit 0f036bf4b87e6416f5c4d23865a62a62d9073c20.
>>>
>>> With this change applied and CONFIG_ENV_ACCESS_IGNORE_FORCE disabled,
>>> the warning appears on every force overwrite, but the variable is then
>>> written to:
>>>
>>>   => env print ethaddr
>>>   ethaddr=00:1C:2B:08:AF:65
>>>   => env set ethaddr 00:00:00:00:00:00
>>>   ## Error: Can't overwrite "ethaddr"
>>>   ## Error inserting "ethaddr" variable, errno=1
>>>   => env print ethaddr
>>>   ethaddr=00:1C:2B:08:AF:65
>>>   => env set -f ethaddr 00:00:00:00:00:00
>>>   ## Error: Can't force access to "ethaddr"
>>>   => env print ethaddr
>>>   ethaddr=00:00:00:00:00:00
>>>
>>> Signed-off-by: Alex Kiernan 
>>> ---
>>> As I noted in my email, I can't see an immediately obvious way to make
>>> this work as intended and given we're at -rc3, I think a revert is the
>>> most appropriate way forward.
>>
>> Can you please spend some more time on proper fix, instead of just
>> reverting ? Reverting isn't the way forward most of the time.
> 
> Can you assist in that?  So far the original patch broke the EFI tests,
> but Heinrich and I came up with a compromise (but it's also I suspect
> that Alex saw).  It is probably better to go back to the same behavior
> as the last release and try again next release once the problem can be
> addressed by someone.

I have to wonder how could the original patch break anything, when it
only adds a single printf() statement. The issue described above would
manifest either way -- with or without the patch -- and is thus a
separate issue altogether.

So I believe this patch is wrong.


[PATCH v3 17/17] cros: Add information about booting Chrome OS on x86

2020-09-05 Thread Simon Glass
Recent versions of Chrome OS do not have a kernel in the root disk, to
save space.

With the improvements to the 'zboot' command it is fairly easy to load
the kernel from the raw partition. Add instructions on how to do this.

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

(no changes since v1)

 doc/README.chromium | 32 
 1 file changed, 32 insertions(+)

diff --git a/doc/README.chromium b/doc/README.chromium
index c56545cb7ff..75f2f24042c 100644
--- a/doc/README.chromium
+++ b/doc/README.chromium
@@ -27,6 +27,9 @@ available:
 since many of them only support coreboot as the bootloader and have
 no bare-metal support in U-Boot. For this, use the 'coreboot' target.
 
+   - Running U-Boot and booting into a Chrome OS image, but without verified
+boot. This can be useful for testing.
+
 
 U-Boot with Chromium OS verified boot
 -
@@ -175,6 +178,35 @@ course the above sandbox feature provides a sort of 
functional test and can
 detect problems that affect the flow or particular vboot features.
 
 
+U-Boot without Chromium OS verified boot
+
+
+The following script can be used to boot a Chrome OS image on coral:
+
+   # Read the image header and obtain the address of the kernel
+   # The offset 4f0 is defined by verified boot and may change for other
+   # Chromebooks
+   read mmc 2:2 10 0 80; setexpr loader *001004f0;
+
+   # Get the kernel size and calculate the number of blocks (0x200 bytes each)
+   setexpr size *00100518; setexpr blocks $size / 200;
+
+   # Read the full kernel and calculate the address of the setup block
+   read mmc 2:2 10 80 $blocks; setexpr setup $loader - 1000;
+
+   # Locate the command line
+   setexpr cmdline $loader - 2000;
+
+   # Start the zboot process with the loaded kernel, setup block and cmdline
+   zboot start 10 0 0 0 $setup $cmdline;
+
+   # Load the kernel, fix up the 'setup' block, dump information
+   zboot load; zboot setup; zboot dump
+
+   # Boot into Chrome OS
+   zboot go
+
+
 TO DO
 -
 
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 15/17] x86: zboot: Allow overriding the command line

2020-09-05 Thread Simon Glass
When booting Chrome OS images the command line is stored separately
from the kernel. Add a way to specify this address so that images boot
correctly.

Also add comments to the zimage.h header.

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

Changes in v3:
- Adjust maxargs in this patch

 arch/x86/include/asm/zimage.h | 30 +-
 arch/x86/lib/bootm.c  |  2 +-
 arch/x86/lib/zimage.c | 23 +--
 3 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
index 80e128ccf36..64c0e6e857b 100644
--- a/arch/x86/include/asm/zimage.h
+++ b/arch/x86/include/asm/zimage.h
@@ -30,10 +30,38 @@
 #define BZIMAGE_LOAD_ADDR  0x10
 #define ZIMAGE_LOAD_ADDR   0x1
 
+/**
+ * load_zimage() - Load a zImage or bzImage
+ *
+ * This copies an image into the standard location ready for setup
+ *
+ * @image: Address of image to load
+ * @kernel_size: Size of kernel including setup block (or 0 if the kernel is
+ * new enough to have a 'syssize' value)
+ * @load_addressp: Returns the address where the kernel has been loaded
+ * @return address of setup block, or NULL if something went wrong
+ */
 struct boot_params *load_zimage(char *image, unsigned long kernel_size,
ulong *load_addressp);
+
+/**
+ * setup_zimage() - Set up a loaded zImage or bzImage ready for booting
+ *
+ * @setup_base: Pointer to the boot parameters, typically at address
+ * DEFAULT_SETUP_BASE
+ * @cmd_line: Place to put the command line, or NULL to use the one in the 
setup
+ * block
+ * @initrd_addr: Address of the initial ramdisk, or 0 if none
+ * @initrd_size: Size of the initial ramdisk, or 0 if none
+ * @load_address: Address where the bzImage is moved before booting, either
+ * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
+ * @cmdline_force: Address of 'override' command line, or 0 to use the one in
+ * the *   setup block
+ * @return 0 (always)
+ */
 int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
-unsigned long initrd_addr, unsigned long initrd_size);
+ulong initrd_addr, ulong initrd_size, ulong cmdline_force);
+
 void setup_video(struct screen_info *screen_info);
 void setup_efi_info(struct efi_info *efi_info);
 
diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c
index 1198a52ecac..da6b8ce1ec1 100644
--- a/arch/x86/lib/bootm.c
+++ b/arch/x86/lib/bootm.c
@@ -136,7 +136,7 @@ static int boot_prep_linux(bootm_headers_t *images)
printf("Setup at %#08lx\n", images->ep);
ret = setup_zimage((void *)images->ep, cmd_line_dest,
0, images->rd_start,
-   images->rd_end - images->rd_start);
+   images->rd_end - images->rd_start, 0);
 
if (ret) {
printf("## Setting up boot parameters failed ...\n");
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index e4813d20c2f..a00964cc8d9 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -56,6 +56,8 @@
  * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
  * @base_ptr: Pointer to the boot parameters, typically at address
  * DEFAULT_SETUP_BASE
+ * @cmdline: Address of 'override' command line, or 0 to use the one in the
+ * setup block
  */
 struct zboot_state {
ulong bzimage_addr;
@@ -64,6 +66,7 @@ struct zboot_state {
ulong initrd_size;
ulong load_address;
struct boot_params *base_ptr;
+   ulong cmdline;
 } state;
 
 enum {
@@ -284,7 +287,7 @@ struct boot_params *load_zimage(char *image, unsigned long 
kernel_size,
 }
 
 int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
-unsigned long initrd_addr, unsigned long initrd_size)
+ulong initrd_addr, ulong initrd_size, ulong cmdline_force)
 {
struct setup_header *hdr = _base->hdr;
int bootproto = get_boot_protocol(hdr, false);
@@ -325,7 +328,10 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
}
 
/* build command line at COMMAND_LINE_OFFSET */
-   build_command_line(cmd_line, auto_boot);
+   if (cmdline_force)
+   strcpy(cmd_line, (char *)cmdline_force);
+   else
+   build_command_line(cmd_line, auto_boot);
}
 
if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207)
@@ -384,6 +390,8 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, 
int argc,
state.load_address = state.bzimage_addr;
state.bzimage_addr = 0;
}
+   if (argc >= 7)
+   state.cmdline = simple_strtoul(argv[6], NULL, 16);
 
return 0;
 }
@@ -427,7 +435,8 @@ static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, 
int argc,
return CMD_RET_FAILURE;
}
 

[PATCH v3 16/17] cros: Update chromium documentation

2020-09-05 Thread Simon Glass
A few things have changed since this was written about 18 months ago.
Update the README.

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

(no changes since v1)

 doc/README.chromium | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/doc/README.chromium b/doc/README.chromium
index 8f67da6c728..c56545cb7ff 100644
--- a/doc/README.chromium
+++ b/doc/README.chromium
@@ -23,6 +23,10 @@ available:
 from U-Boot in 2013) and coreboot. See below for more information on
 this.
 
+   - Running U-Boot from coreboot. This allows U-Boot to run on more devices
+since many of them only support coreboot as the bootloader and have
+no bare-metal support in U-Boot. For this, use the 'coreboot' target.
+
 
 U-Boot with Chromium OS verified boot
 -
@@ -168,14 +172,13 @@ existed in U-Boot were not brought over to coreboot or 
depthcharge.
 The U-Boot tests ('make check') do operate, but at present there are no
 Chromium OS tests available. These will hopefully come together over time. Of
 course the above sandbox feature provides a sort of functional test and can
-detecte problems that affect the flow or particular vboot features.
+detect problems that affect the flow or particular vboot features.
 
 
 TO DO
 -
 
-- Support for booting from coreboot (patches expected March 2019)
-- Support for booting from an ARM board, e.g. bob
+Get the full ACPI tables working with Coral
 
 
 Simon Glass
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 13/17] x86: zboot: Allow setting a separate setup base address

2020-09-05 Thread Simon Glass
At present the setup block is always obtained from the image
automatically. In some cases it can be useful to use a setup block
obtained elsewhere, e.g. if the image has already been unpacked. Add an
argument to support this and update the logic to use it if provided.

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

(no changes since v2)

Changes in v2:
- Add a comment explaining the logic for a specified setup-base address
- Adjust maxargs in this patch

 arch/x86/lib/zimage.c | 41 ++---
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 11f1c60d53d..368b7d0c3f3 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -366,6 +366,22 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, 
int argc,
state.initrd_addr = simple_strtoul(argv[3], NULL, 16);
if (argc >= 5)
state.initrd_size = simple_strtoul(argv[4], NULL, 16);
+   if (argc >= 6) {
+   /*
+* When the base_ptr is passed in, we assume that the image is
+* already loaded at the address given by argv[1] and therefore
+* the original bzImage is somewhere else, or not accessible.
+* In any case, we don't need access to the bzImage since all
+* the processing is assumed to be done.
+*
+* So set the base_ptr to the given address, use this arg as the
+* load address and set bzimage_addr to 0 so we know that it
+* cannot be proceesed (or processed again).
+*/
+   state.base_ptr = (void *)simple_strtoul(argv[5], NULL, 16);
+   state.load_address = state.bzimage_addr;
+   state.bzimage_addr = 0;
+   }
 
return 0;
 }
@@ -375,11 +391,20 @@ static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, 
int argc,
 {
struct boot_params *base_ptr;
 
-   base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
-  _address);
-   if (!base_ptr) {
-   puts("## Kernel loading failed ...\n");
-   return CMD_RET_FAILURE;
+   if (state.base_ptr) {
+   struct boot_params *from = (struct boot_params *)state.base_ptr;
+
+   base_ptr = (struct boot_params *)DEFAULT_SETUP_BASE;
+   printf("Building boot_params at 0x%8.8lx\n", (ulong)base_ptr);
+   memset(base_ptr, '\0', sizeof(*base_ptr));
+   base_ptr->hdr = from->hdr;
+   } else {
+   base_ptr = load_zimage((void *)state.bzimage_addr, 
state.bzimage_size,
+  _address);
+   if (!base_ptr) {
+   puts("## Kernel loading failed ...\n");
+   return CMD_RET_FAILURE;
+   }
}
state.base_ptr = base_ptr;
if (env_set_hex("zbootbase", (ulong)base_ptr) ||
@@ -486,8 +511,8 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int 
argc,
 }
 
 U_BOOT_CMDREP_COMPLETE(
-   zboot, 6, do_zboot_parent, "Boot bzImage",
-   "[addr] [size] [initrd addr] [initrd size]\n"
+   zboot, 7, do_zboot_parent, "Boot bzImage",
+   "[addr] [size] [initrd addr] [initrd size] [setup]\n"
"  addr -The optional starting address of the bzimage.\n"
"If not set it defaults to the environment\n"
"variable \"fileaddr\".\n"
@@ -495,6 +520,8 @@ U_BOOT_CMDREP_COMPLETE(
"zero.\n"
"  initrd addr - The address of the initrd image to use, if any.\n"
"  initrd size - The size of the initrd image to use, if any.\n"
+   "  setup -   The address of the kernel setup region, if this\n"
+   "is not at addr\n"
"\n"
"Sub-commands to do part of the zboot sequence:\n"
"\tstart [addr [arg ...]] - specify arguments\n"
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 14/17] x86: zboot: Add an option to dump the setup information

2020-09-05 Thread Simon Glass
There is a lot of information in the setup block and it is quite hard to
decode manually. Add a 'zboot dump' command to decode it into a
human-readable format.

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

Changes in v3:
- Update two local arrays to be static
- Use 'Commandline' instead of 'Commandline'

 arch/x86/include/asm/e820.h |   1 +
 arch/x86/lib/zimage.c   | 199 +++-
 2 files changed, 199 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
index 9d29f82f972..d7f8a4ba1df 100644
--- a/arch/x86/include/asm/e820.h
+++ b/arch/x86/include/asm/e820.h
@@ -8,6 +8,7 @@
 #define E820_ACPI  3
 #define E820_NVS   4
 #define E820_UNUSABLE  5
+#define E820_COUNT 6   /* Number of types */
 
 #ifndef __ASSEMBLY__
 #include 
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 368b7d0c3f3..e4813d20c2f 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -73,6 +73,8 @@ enum {
ZBOOT_STATE_INFO= BIT(3),
ZBOOT_STATE_GO  = BIT(4),
 
+   /* This one doesn't execute automatically, so stop the count before 5 */
+   ZBOOT_STATE_DUMP= BIT(5),
ZBOOT_STATE_COUNT   = 5,
 };
 
@@ -458,6 +460,199 @@ static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, 
int argc,
return CMD_RET_FAILURE;
 }
 
+static void print_num(const char *name, ulong value)
+{
+   printf("%-20s: %lx\n", name, value);
+}
+
+static void print_num64(const char *name, u64 value)
+{
+   printf("%-20s: %llx\n", name, value);
+}
+
+static const char *const e820_type_name[E820_COUNT] = {
+   [E820_RAM] = "RAM",
+   [E820_RESERVED] = "Reserved",
+   [E820_ACPI] = "ACPI",
+   [E820_NVS] = "ACPI NVS",
+   [E820_UNUSABLE] = "Unusable",
+};
+
+static const char *const bootloader_id[] = {
+   "LILO",
+   "Loadlin",
+   "bootsect-loader",
+   "Syslinux",
+   "Etherboot/gPXE/iPXE",
+   "ELILO",
+   "undefined",
+   "GRUB",
+   "U-Boot",
+   "Xen",
+   "Gujin",
+   "Qemu",
+   "Arcturus Networks uCbootloader",
+   "kexec-tools",
+   "Extended",
+   "Special",
+   "Reserved",
+   "Minimal Linux Bootloader",
+   "OVMF UEFI virtualization stack",
+};
+
+struct flag_info {
+   uint bit;
+   const char *name;
+};
+
+static struct flag_info load_flags[] = {
+   { LOADED_HIGH, "loaded-high" },
+   { QUIET_FLAG, "quiet" },
+   { KEEP_SEGMENTS, "keep-segments" },
+   { CAN_USE_HEAP, "can-use-heap" },
+};
+
+static struct flag_info xload_flags[] = {
+   { XLF_KERNEL_64, "64-bit-entry" },
+   { XLF_CAN_BE_LOADED_ABOVE_4G, "can-load-above-4gb" },
+   { XLF_EFI_HANDOVER_32, "32-efi-handoff" },
+   { XLF_EFI_HANDOVER_64, "64-efi-handoff" },
+   { XLF_EFI_KEXEC, "kexec-efi-runtime" },
+};
+
+static void print_flags(struct flag_info *flags, int count, uint value)
+{
+   int i;
+
+   printf("%-20s:", "");
+   for (i = 0; i < count; i++) {
+   uint mask = flags[i].bit;
+
+   if (value & mask)
+   printf(" %s", flags[i].name);
+   }
+   printf("\n");
+}
+
+static void show_loader(struct setup_header *hdr)
+{
+   bool version_valid = false;
+   int type, version;
+   const char *name;
+
+   type = hdr->type_of_loader >> 4;
+   version = hdr->type_of_loader & 0xf;
+   if (type == 0xe)
+   type = 0x10 + hdr->ext_loader_type;
+   version |= hdr->ext_loader_ver << 4;
+   if (!hdr->type_of_loader) {
+   name = "pre-2.00 bootloader";
+   } else if (hdr->type_of_loader == 0xff) {
+   name = "unknown";
+   } else if (type < ARRAY_SIZE(bootloader_id)) {
+   name = bootloader_id[type];
+   version_valid = true;
+   } else {
+   name = "undefined";
+   }
+   printf("%20s  %s", "", name);
+   if (version_valid)
+   printf(", version %x", version);
+   printf("\n");
+}
+
+int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
+{
+   struct boot_params *base_ptr = state.base_ptr;
+   struct setup_header *hdr;
+   const char *version;
+   int i;
+
+   if (argc > 1)
+   base_ptr = (void *)simple_strtoul(argv[1], NULL, 16);
+   if (!base_ptr) {
+   printf("No zboot setup_base\n");
+   return CMD_RET_FAILURE;
+   }
+   printf("Setup located at %p:\n\n", base_ptr);
+   print_num64("ACPI RSDP addr", base_ptr->acpi_rsdp_addr);
+
+   printf("E820: %d entries\n", base_ptr->e820_entries);
+   if (base_ptr->e820_entries) {
+   printf("%18s  %16s  %s\n", "Addr", "Size", "Type");
+   for (i = 0; i < base_ptr->e820_entries; i++) {
+   struct e820_entry *entry = _ptr->e820_map[i];
+
+   

Re: [PATCH v2 07/16] x86: zboot: Set up a sub-command structure

2020-09-05 Thread Simon Glass
Hi Bin,

On Tue, 1 Sep 2020 at 03:30, Bin Meng  wrote:
>
> Hi Simon,
>
> On Sun, Aug 30, 2020 at 5:42 AM Simon Glass  wrote:
> >
> > Add subcommands to zboot. At present there is only one called 'start'
> > which does the whole boot. It is the default command so is optional.
> >
> > Change the 's' string variable to const while we are here.
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v2:
> > - Fix comment about argv[0] in do_zboot_parent()
> >
> >  arch/x86/lib/zimage.c | 64 +++
> >  1 file changed, 58 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
> > index 8651dea93b3..e3e3efdde43 100644
> > --- a/arch/x86/lib/zimage.c
> > +++ b/arch/x86/lib/zimage.c
> > @@ -63,6 +63,12 @@ struct zboot_state {
> > ulong load_address;
> >  } state;
> >
> > +enum {
> > +   ZBOOT_STATE_START   = BIT(0),
> > +
> > +   ZBOOT_STATE_COUNT   = 1,
> > +};
> > +
> >  static void build_command_line(char *command_line, int auto_boot)
> >  {
> > char *env_command_line;
> > @@ -328,10 +334,11 @@ int setup_zimage(struct boot_params *setup_base, char 
> > *cmd_line, int auto_boot,
> > return 0;
> >  }
> >
> > -int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> > +static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
> > + char *const argv[])
> >  {
> > struct boot_params *base_ptr;
> > -   char *s;
> > +   const char *s;
> >
> > memset(, '\0', sizeof(state));
> > if (argc >= 2) {
> > @@ -373,9 +380,53 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int 
> > argc, char *const argv[])
> > return boot_linux_kernel((ulong)base_ptr, state.load_address, 
> > false);
> >  }
> >
> > -U_BOOT_CMD(
> > -   zboot, 5, 0,do_zboot,
> > -   "Boot bzImage",
> > +U_BOOT_SUBCMDS(zboot,
> > +   U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
>
> should the maxargs be 5 instead of 8?

Yes, for this patch. I'll update it and adjust it in each following
patch as needed.

>
> > +)
> > +
> > +int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
> > +   char *const argv[], int state_mask)
> > +{
> > +   int i;
> > +
> > +   for (i = 0; i < ZBOOT_STATE_COUNT; i++) {
> > +   struct cmd_tbl *cmd = _subcmds[i];
> > +   int mask = 1 << i;
> > +   int ret;
> > +
> > +   if (mask & state_mask) {
> > +   ret = cmd->cmd(cmd, flag, argc, argv);
> > +   if (ret)
> > +   return ret;
> > +   }
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> > +int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
> > +   char *const argv[], int *repeatable)
> > +{
> > +   /* determine if we have a sub command */
> > +   if (argc > 1) {
> > +   char *endp;
> > +
> > +   simple_strtoul(argv[1], , 16);
> > +   /*
> > +* endp pointing to nul means that argv[1] was just a valid
> > +* number, so pass it along to the normal processing
> > +*/
> > +   if (*endp)
> > +   return do_zboot(cmdtp, flag, argc, argv, 
> > repeatable);
> > +   }
> > +
> > +   do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START);
> > +
> > +   return CMD_RET_FAILURE;
> > +}
> > +
> > +U_BOOT_CMDREP_COMPLETE(
> > +   zboot, 8, do_zboot_parent, "Boot bzImage",
> > "[addr] [size] [initrd addr] [initrd size]\n"
> > "  addr -The optional starting address of the 
> > bzimage.\n"
> > "If not set it defaults to the environment\n"
> > @@ -383,5 +434,6 @@ U_BOOT_CMD(
> > "  size -The optional size of the bzimage. Defaults 
> > to\n"
> > "zero.\n"
> > "  initrd addr - The address of the initrd image to use, if 
> > any.\n"
> > -   "  initrd size - The size of the initrd image to use, if any.\n"
> > +   "  initrd size - The size of the initrd image to use, if 
> > any.\n",
> > +   complete_zboot
>
> What's "complete_zboot"?

It is defined by the U_BOOT_SUBCMDS() macro. I'll add a comment.

Regards,
SImon


[PATCH v3 10/17] x86: zboot: Add an 'load' subcommand

2020-09-05 Thread Simon Glass
Add a subcommand that loads the kernel into the right places in memory.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Move command help into the patch for each command
- Split the 'load' command into its own patch

 arch/x86/lib/zimage.c | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index f4a6b83b246..f53e9b572b6 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -69,9 +69,10 @@ struct zboot_state {
 enum {
ZBOOT_STATE_START   = BIT(0),
ZBOOT_STATE_INFO= BIT(1),
-   ZBOOT_STATE_GO  = BIT(2),
+   ZBOOT_STATE_LOAD= BIT(2),
+   ZBOOT_STATE_GO  = BIT(3),
 
-   ZBOOT_STATE_COUNT   = 3,
+   ZBOOT_STATE_COUNT   = 4,
 };
 
 static void build_command_line(char *command_line, int auto_boot)
@@ -342,7 +343,6 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
 static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[])
 {
-   struct boot_params *base_ptr;
const char *s;
 
memset(, '\0', sizeof(state));
@@ -366,12 +366,19 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int 
flag, int argc,
if (argc >= 5)
state.initrd_size = simple_strtoul(argv[4], NULL, 16);
 
-   /* Lets look for */
+   return 0;
+}
+
+static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   struct boot_params *base_ptr;
+
base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
   _address);
if (!base_ptr) {
puts("## Kernel loading failed ...\n");
-   return -1;
+   return CMD_RET_FAILURE;
}
state.base_ptr = base_ptr;
 
@@ -411,6 +418,7 @@ static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int 
argc,
 /* Note: This defines the complete_zboot() function */
 U_BOOT_SUBCMDS(zboot,
U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
+   U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""),
U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
 )
@@ -452,7 +460,7 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int 
argc,
}
 
do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
-   ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
+   ZBOOT_STATE_LOAD | ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
 
return CMD_RET_FAILURE;
 }
@@ -470,6 +478,7 @@ U_BOOT_CMDREP_COMPLETE(
"\n"
"Sub-commands to do part of the zboot sequence:\n"
"\tstart [addr [arg ...]] - specify arguments\n"
+   "\tload   - load OS image\n"
"\tinfo   - show summary info\n"
"\tgo - start OS\n",
complete_zboot
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 09/17] x86: zboot: Add an 'info' subcommand

2020-09-05 Thread Simon Glass
Add a little subcommand that prints out where the kernel was loaded and
its setup pointer. Run it by default in the normal boot.

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

Changes in v3:
- Move command help into the patch for each command

 arch/x86/lib/zimage.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index d0b997b7dea..f4a6b83b246 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -68,9 +68,10 @@ struct zboot_state {
 
 enum {
ZBOOT_STATE_START   = BIT(0),
-   ZBOOT_STATE_GO  = BIT(1),
+   ZBOOT_STATE_INFO= BIT(1),
+   ZBOOT_STATE_GO  = BIT(2),
 
-   ZBOOT_STATE_COUNT   = 2,
+   ZBOOT_STATE_COUNT   = 3,
 };
 
 static void build_command_line(char *command_line, int auto_boot)
@@ -383,6 +384,15 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, 
int argc,
return 0;
 }
 
+static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   printf("Kernel loaded at %08lx, setup_base=%p\n",
+  state.load_address, state.base_ptr);
+
+   return 0;
+}
+
 static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
   char *const argv[])
 {
@@ -401,6 +411,7 @@ static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int 
argc,
 /* Note: This defines the complete_zboot() function */
 U_BOOT_SUBCMDS(zboot,
U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
+   U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
 )
 
@@ -441,7 +452,7 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int 
argc,
}
 
do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
-   ZBOOT_STATE_GO);
+   ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
 
return CMD_RET_FAILURE;
 }
@@ -459,6 +470,7 @@ U_BOOT_CMDREP_COMPLETE(
"\n"
"Sub-commands to do part of the zboot sequence:\n"
"\tstart [addr [arg ...]] - specify arguments\n"
+   "\tinfo   - show summary info\n"
"\tgo - start OS\n",
complete_zboot
 );
-- 
2.28.0.526.ge36021eeef-goog



Re: [PATCH v2 3/3] sunxi: Add support for including SCP firmware

2020-09-05 Thread Simon Glass
Hi Samuel,

On Thu, 3 Sep 2020 at 00:08, Samuel Holland  wrote:
>
> Allwinner sun50i SoCs contain an OpenRISC 1000 CPU that functions as a
> System Control Processor, or SCP. ARM Trusted Firmware (ATF)
> communicates with the SCP over SCPI to implement the PSCI system suspend
> and shutdown functionality. Currently, SCP firmware is optional; the
> system will boot and run without it, but system suspend will be
> unavailable.
>
> Since all communication with the SCP is mediated by ATF, the only thing
> U-Boot needs to do is load the firmware into SRAM. The SCP firmware
> occupies the last 16KiB of SRAM A2, immediately following ATF.
>
> Signed-off-by: Samuel Holland 
> ---
>
> Changes since v1:
>   - None
>
> ---
>  board/sunxi/README.sunxi64 | 43 --
>  board/sunxi/mksunxi_fit_atf.sh | 23 +++---
>  2 files changed, 56 insertions(+), 10 deletions(-)

This needs to be done with binman. See u-boot-dm/next for the updated
implementation.

Regards,
Simon


[PATCH v3 11/17] x86: zboot: Add an 'setup' subcommand

2020-09-05 Thread Simon Glass
Add a subcommand that sets up the kernel ready for execution.

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

Changes in v3:
- Fix 'summary' typo
- Move command help into the patch for each command

 arch/x86/lib/zimage.c | 34 ++
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index f53e9b572b6..d27c3b9284c 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -68,11 +68,12 @@ struct zboot_state {
 
 enum {
ZBOOT_STATE_START   = BIT(0),
-   ZBOOT_STATE_INFO= BIT(1),
-   ZBOOT_STATE_LOAD= BIT(2),
-   ZBOOT_STATE_GO  = BIT(3),
+   ZBOOT_STATE_LOAD= BIT(1),
+   ZBOOT_STATE_SETUP   = BIT(2),
+   ZBOOT_STATE_INFO= BIT(3),
+   ZBOOT_STATE_GO  = BIT(4),
 
-   ZBOOT_STATE_COUNT   = 4,
+   ZBOOT_STATE_COUNT   = 5,
 };
 
 static void build_command_line(char *command_line, int auto_boot)
@@ -382,10 +383,24 @@ static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, 
int argc,
}
state.base_ptr = base_ptr;
 
-   if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0,
-state.initrd_addr, state.initrd_size)) {
+   return 0;
+}
+
+static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   struct boot_params *base_ptr = state.base_ptr;
+   int ret;
+
+   if (!base_ptr) {
+   printf("base is not set: use 'zboot load' first\n");
+   return CMD_RET_FAILURE;
+   }
+   ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
+  0, state.initrd_addr, state.initrd_size);
+   if (ret) {
puts("Setting up boot parameters failed ...\n");
-   return -1;
+   return CMD_RET_FAILURE;
}
 
return 0;
@@ -419,6 +434,7 @@ static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int 
argc,
 U_BOOT_SUBCMDS(zboot,
U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""),
+   U_BOOT_CMD_MKENT(setup, 1, 1, do_zboot_setup, "", ""),
U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
 )
@@ -460,7 +476,8 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int 
argc,
}
 
do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
-   ZBOOT_STATE_LOAD | ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
+   ZBOOT_STATE_LOAD | ZBOOT_STATE_SETUP |
+   ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
 
return CMD_RET_FAILURE;
 }
@@ -479,6 +496,7 @@ U_BOOT_CMDREP_COMPLETE(
"Sub-commands to do part of the zboot sequence:\n"
"\tstart [addr [arg ...]] - specify arguments\n"
"\tload   - load OS image\n"
+   "\tsetup  - set up table\n"
"\tinfo   - show summary info\n"
"\tgo - start OS\n",
complete_zboot
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 12/17] x86: zboot: Set environment variables for image locations

2020-09-05 Thread Simon Glass
At present it is not possible to tell from a script where the setup block
is, or where the image was loaded to. Add environment variables for this.

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

Changes in v3:
- Mention that the environment variables are for x86 only

 README| 4 
 arch/x86/lib/zimage.c | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/README b/README
index 6cb0567ba66..5132b2278cb 100644
--- a/README
+++ b/README
@@ -3425,6 +3425,10 @@ List of environment variables (most likely not complete):
   mempos   - Index position of the last match found by the 'ms' command,
  in units of the size (.b, .w, .l) of the search
 
+  zbootbase- (x86 only) Base address of the bzImage 'setup' block
+
+  zbootaddr- (x86 only) Address of the loaded bzImage, typically
+ BZIMAGE_LOAD_ADDR which is 0x10
 
 The following image location variables contain the location of images
 used in booting. The "Image" column gives the role of the image and is
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index d27c3b9284c..11f1c60d53d 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -382,6 +382,9 @@ static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, 
int argc,
return CMD_RET_FAILURE;
}
state.base_ptr = base_ptr;
+   if (env_set_hex("zbootbase", (ulong)base_ptr) ||
+   env_set_hex("zbootaddr", state.load_address))
+   return CMD_RET_FAILURE;
 
return 0;
 }
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 08/17] x86: zboot: Add a 'go' subcommand

2020-09-05 Thread Simon Glass
Split out the code that actually boots linux into a separate sub-command.
Add base_ptr to the state to support this.

Show an error if the boot fails, since this should not happen.

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

Changes in v3:
- Move command help into the patch for each command

 arch/x86/lib/zimage.c | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index f037bd5dc56..d0b997b7dea 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -54,6 +54,8 @@
  * @initrd_size: Size of the initial ramdisk, or 0 if none
  * @load_address: Address where the bzImage is moved before booting, either
  * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
+ * @base_ptr: Pointer to the boot parameters, typically at address
+ * DEFAULT_SETUP_BASE
  */
 struct zboot_state {
ulong bzimage_addr;
@@ -61,12 +63,14 @@ struct zboot_state {
ulong initrd_addr;
ulong initrd_size;
ulong load_address;
+   struct boot_params *base_ptr;
 } state;
 
 enum {
ZBOOT_STATE_START   = BIT(0),
+   ZBOOT_STATE_GO  = BIT(1),
 
-   ZBOOT_STATE_COUNT   = 1,
+   ZBOOT_STATE_COUNT   = 2,
 };
 
 static void build_command_line(char *command_line, int auto_boot)
@@ -368,6 +372,7 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, 
int argc,
puts("## Kernel loading failed ...\n");
return -1;
}
+   state.base_ptr = base_ptr;
 
if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0,
 state.initrd_addr, state.initrd_size)) {
@@ -375,14 +380,28 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int 
flag, int argc,
return -1;
}
 
+   return 0;
+}
+
+static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
+  char *const argv[])
+{
+   int ret;
+
disable_interrupts();
+
/* we assume that the kernel is in place */
-   return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
+   ret = boot_linux_kernel((ulong)state.base_ptr, state.load_address,
+   false);
+   printf("Kernel returned! (err=%d)\n", ret);
+
+   return CMD_RET_FAILURE;
 }
 
 /* Note: This defines the complete_zboot() function */
 U_BOOT_SUBCMDS(zboot,
U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
+   U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
 )
 
 int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -421,7 +440,8 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int 
argc,
return do_zboot(cmdtp, flag, argc, argv, repeatable);
}
 
-   do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START);
+   do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
+   ZBOOT_STATE_GO);
 
return CMD_RET_FAILURE;
 }
@@ -438,6 +458,7 @@ U_BOOT_CMDREP_COMPLETE(
"  initrd size - The size of the initrd image to use, if any.\n"
"\n"
"Sub-commands to do part of the zboot sequence:\n"
-   "\tstart [addr [arg ...]] - specify arguments\n",
+   "\tstart [addr [arg ...]] - specify arguments\n"
+   "\tgo - start OS\n",
complete_zboot
 );
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 07/17] x86: zboot: Set up a sub-command structure

2020-09-05 Thread Simon Glass
Add subcommands to zboot. At present there is only one called 'start'
which does the whole boot. It is the default command so is optional.

Change the 's' string variable to const while we are here.
Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

Changes in v3:
- Add a comment about complete_zboot()
- Move command help into the patch for each command
- Reduce maxargs to 6

Changes in v2:
- Fix comment about argv[0] in do_zboot_parent()

 arch/x86/lib/zimage.c | 66 +++
 1 file changed, 61 insertions(+), 5 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 8651dea93b3..f037bd5dc56 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -63,6 +63,12 @@ struct zboot_state {
ulong load_address;
 } state;
 
+enum {
+   ZBOOT_STATE_START   = BIT(0),
+
+   ZBOOT_STATE_COUNT   = 1,
+};
+
 static void build_command_line(char *command_line, int auto_boot)
 {
char *env_command_line;
@@ -328,10 +334,11 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
return 0;
 }
 
-int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
 {
struct boot_params *base_ptr;
-   char *s;
+   const char *s;
 
memset(, '\0', sizeof(state));
if (argc >= 2) {
@@ -373,9 +380,54 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
 }
 
-U_BOOT_CMD(
-   zboot, 5, 0,do_zboot,
-   "Boot bzImage",
+/* Note: This defines the complete_zboot() function */
+U_BOOT_SUBCMDS(zboot,
+   U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
+)
+
+int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[], int state_mask)
+{
+   int i;
+
+   for (i = 0; i < ZBOOT_STATE_COUNT; i++) {
+   struct cmd_tbl *cmd = _subcmds[i];
+   int mask = 1 << i;
+   int ret;
+
+   if (mask & state_mask) {
+   ret = cmd->cmd(cmd, flag, argc, argv);
+   if (ret)
+   return ret;
+   }
+   }
+
+   return 0;
+}
+
+int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[], int *repeatable)
+{
+   /* determine if we have a sub command */
+   if (argc > 1) {
+   char *endp;
+
+   simple_strtoul(argv[1], , 16);
+   /*
+* endp pointing to nul means that argv[1] was just a valid
+* number, so pass it along to the normal processing
+*/
+   if (*endp)
+   return do_zboot(cmdtp, flag, argc, argv, repeatable);
+   }
+
+   do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START);
+
+   return CMD_RET_FAILURE;
+}
+
+U_BOOT_CMDREP_COMPLETE(
+   zboot, 6, do_zboot_parent, "Boot bzImage",
"[addr] [size] [initrd addr] [initrd size]\n"
"  addr -The optional starting address of the bzimage.\n"
"If not set it defaults to the environment\n"
@@ -384,4 +436,8 @@ U_BOOT_CMD(
"zero.\n"
"  initrd addr - The address of the initrd image to use, if any.\n"
"  initrd size - The size of the initrd image to use, if any.\n"
+   "\n"
+   "Sub-commands to do part of the zboot sequence:\n"
+   "\tstart [addr [arg ...]] - specify arguments\n",
+   complete_zboot
 );
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 05/17] x86: zboot: Correct image type

2020-09-05 Thread Simon Glass
At present U-Boot sets a loader type of 8 which means LILO version 8,
according to the spec. Update it to 0x80, which means U-Boot with no
particular version.

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

(no changes since v1)

 arch/x86/lib/zimage.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index b2c3daf225d..ba9eb50b0ba 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -282,8 +282,7 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET;
}
if (bootproto >= 0x0200) {
-   hdr->type_of_loader = 8;
-
+   hdr->type_of_loader = 0x80; /* U-Boot version 0 */
if (initrd_addr) {
printf("Initial RAM disk at linear address "
   "0x%08lx, size %ld bytes\n",
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 06/17] x86: zimage: Disable interrupts just before booting

2020-09-05 Thread Simon Glass
At present if an error occurs while setting up the boot, interrupts are
left disabled. Move this call later in the sequence to avoid this problem.

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

(no changes since v1)

 arch/x86/lib/zimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index ba9eb50b0ba..8651dea93b3 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -333,7 +333,6 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
struct boot_params *base_ptr;
char *s;
 
-   disable_interrupts();
memset(, '\0', sizeof(state));
if (argc >= 2) {
/* argv[1] holds the address of the bzImage */
@@ -369,6 +368,7 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
return -1;
}
 
+   disable_interrupts();
/* we assume that the kernel is in place */
return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
 }
-- 
2.28.0.526.ge36021eeef-goog



Re: [PATCH v2 2/3] mksunxi_fit_atf.sh: Update FIT component descriptions

2020-09-05 Thread Simon Glass
Hi Samuel,

On Thu, 3 Sep 2020 at 00:08, Samuel Holland  wrote:
>
> Since commit d879616e9e64 ("spl: fit: simplify logic for FDT loading for
> non-OS boots"), the SPL looks at the "os" properties of FIT images to
> determine where to append the FDT.
>
> The "os" property of the "firmware" image also determines how to execute
> the next stage of the boot process, as in 1d3790905d9c ("spl: atf:
> introduce spl_invoke_atf and make bl31_entry private").
>
> To support this additional functionality, and to properly model the boot
> process, where ATF runs before U-Boot, add the "os" properties and swap
> the firmware/loadable images in the FIT image.
>
> Acked-by: Patrick Wildt 
> Signed-off-by: Samuel Holland 
> ---
>
> Changes since v1:
>   - Collect tags
>
> ---
>  board/sunxi/mksunxi_fit_atf.sh | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)

This is moving to use binman so please check u-boot-dm/next.

Regards,
Simon


[PATCH v3 02/17] x86: zimage: Use a state struct to hold the state

2020-09-05 Thread Simon Glass
At present the 'zboot' command does everything in one go. It would be
better if it supported sub-commands like bootm, so it is possible to
examine what will be booted before actually booting it.

In preparation for this, move the 'state' of the command into a struct.
This will allow it to be shared among multiple functions in this file.

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

(no changes since v1)

 arch/x86/lib/zimage.c | 44 ---
 1 file changed, 29 insertions(+), 15 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index d2b6002008a..a79971f052c 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -45,6 +45,24 @@
 
 #define COMMAND_LINE_SIZE  2048
 
+/**
+ * struct zboot_state - Current state of the boot
+ *
+ * @bzimage_addr: Address of the bzImage to boot
+ * @bzimage_size: Size of the bzImage, or 0 to detect this
+ * @initrd_addr: Address of the initial ramdisk, or 0 if none
+ * @initrd_size: Size of the initial ramdisk, or 0 if none
+ * @load_address: Address where the bzImage is moved before booting, either
+ * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
+ */
+struct zboot_state {
+   ulong bzimage_addr;
+   ulong bzimage_size;
+   ulong initrd_addr;
+   ulong initrd_size;
+   ulong load_address;
+} state;
+
 static void build_command_line(char *command_line, int auto_boot)
 {
char *env_command_line;
@@ -307,15 +325,10 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
 int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct boot_params *base_ptr;
-   void *bzImage_addr = NULL;
-   ulong load_address;
char *s;
-   ulong bzImage_size = 0;
-   ulong initrd_addr = 0;
-   ulong initrd_size = 0;
 
disable_interrupts();
-
+   memset(, '\0', sizeof(state));
if (argc >= 2) {
/* argv[1] holds the address of the bzImage */
s = argv[1];
@@ -324,33 +337,34 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
}
 
if (s)
-   bzImage_addr = (void *)simple_strtoul(s, NULL, 16);
+   state.bzimage_addr = simple_strtoul(s, NULL, 16);
 
if (argc >= 3) {
/* argv[2] holds the size of the bzImage */
-   bzImage_size = simple_strtoul(argv[2], NULL, 16);
+   state.bzimage_size = simple_strtoul(argv[2], NULL, 16);
}
 
if (argc >= 4)
-   initrd_addr = simple_strtoul(argv[3], NULL, 16);
+   state.initrd_addr = simple_strtoul(argv[3], NULL, 16);
if (argc >= 5)
-   initrd_size = simple_strtoul(argv[4], NULL, 16);
+   state.initrd_size = simple_strtoul(argv[4], NULL, 16);
 
/* Lets look for */
-   base_ptr = load_zimage(bzImage_addr, bzImage_size, _address);
-
+   base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
+  _address);
if (!base_ptr) {
puts("## Kernel loading failed ...\n");
return -1;
}
-   if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
-   0, initrd_addr, initrd_size)) {
+
+   if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0,
+state.initrd_addr, state.initrd_size)) {
puts("Setting up boot parameters failed ...\n");
return -1;
}
 
/* we assume that the kernel is in place */
-   return boot_linux_kernel((ulong)base_ptr, load_address, false);
+   return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
 }
 
 U_BOOT_CMD(
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 01/17] x86: Update the bootparam header

2020-09-05 Thread Simon Glass
This header is missing a few of the newer features from the specification.
Add these as well as a link to the spec. Also use the BIT() macros where
appropriate.

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

(no changes since v1)

 arch/x86/include/asm/bootparam.h | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/bootparam.h b/arch/x86/include/asm/bootparam.h
index d961dddc9e1..7a3c1f51554 100644
--- a/arch/x86/include/asm/bootparam.h
+++ b/arch/x86/include/asm/bootparam.h
@@ -24,6 +24,11 @@ struct setup_data {
__u8 data[0];
 };
 
+/**
+ * struct setup_header - Information needed by Linux to boot
+ *
+ * See https://www.kernel.org/doc/html/latest/x86/boot.html
+ */
 struct setup_header {
__u8setup_sects;
__u16   root_flags;
@@ -43,15 +48,16 @@ struct setup_header {
__u16   kernel_version;
__u8type_of_loader;
__u8loadflags;
-#define LOADED_HIGH(1<<0)
-#define QUIET_FLAG (1<<5)
-#define KEEP_SEGMENTS  (1<<6)
-#define CAN_USE_HEAP   (1<<7)
+#define LOADED_HIGHBIT(0)
+#define KASLR_FLAG BIT(1)
+#define QUIET_FLAG BIT(5)
+#define KEEP_SEGMENTS  BIT(6)  /* Obsolete */
+#define CAN_USE_HEAP   BIT(7)
__u16   setup_move_size;
__u32   code32_start;
__u32   ramdisk_image;
__u32   ramdisk_size;
-   __u32   bootsect_kludge;
+   __u32   bootsect_kludge;/* Obsolete */
__u16   heap_end_ptr;
__u8ext_loader_ver;
__u8ext_loader_type;
@@ -59,7 +65,13 @@ struct setup_header {
__u32   initrd_addr_max;
__u32   kernel_alignment;
__u8relocatable_kernel;
-   __u8_pad2[3];
+   u8  min_alignment;
+#define XLF_KERNEL_64  BIT(0)
+#define XLF_CAN_BE_LOADED_ABOVE_4G BIT(1)
+#define XLF_EFI_HANDOVER_32BIT(2)
+#define XLF_EFI_HANDOVER_64BIT(3)
+#define XLF_EFI_KEXEC  BIT(4)
+   u16 xloadflags;
__u32   cmdline_size;
__u32   hardware_subarch;
__u64   hardware_subarch_data;
@@ -69,6 +81,7 @@ struct setup_header {
__u64   pref_address;
__u32   init_size;
__u32   handover_offset;
+   u32 kernel_info_offset;
 } __attribute__((packed));
 
 struct sys_desc_table {
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 04/17] x86: zboot: Move kernel-version code into a function

2020-09-05 Thread Simon Glass
To help reduce the size and complexity of load_zimage(), move the code
that reads the kernel version into a separate function. Update
get_boot_protocol() to allow printing the 'Magic signature' message only
once, under control of its callers.

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

(no changes since v1)

 arch/x86/lib/zimage.c | 43 +++
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 3c8081a48bb..b2c3daf225d 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -103,21 +103,23 @@ static int kernel_magic_ok(struct setup_header *hdr)
}
 }
 
-static int get_boot_protocol(struct setup_header *hdr)
+static int get_boot_protocol(struct setup_header *hdr, bool verbose)
 {
if (hdr->header == KERNEL_V2_MAGIC) {
-   printf("Magic signature found\n");
+   if (verbose)
+   printf("Magic signature found\n");
return hdr->version;
} else {
/* Very old kernel */
-   printf("Magic signature not found\n");
+   if (verbose)
+   printf("Magic signature not found\n");
return 0x0100;
}
 }
 
 static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob)
 {
-   int bootproto = get_boot_protocol(hdr);
+   int bootproto = get_boot_protocol(hdr, false);
struct setup_data *sd;
int size;
 
@@ -147,10 +149,24 @@ static int setup_device_tree(struct setup_header *hdr, 
const void *fdt_blob)
return 0;
 }
 
+static const char *get_kernel_version(struct boot_params *params,
+ void *kernel_base)
+{
+   struct setup_header *hdr = >hdr;
+   int bootproto;
+
+   bootproto = get_boot_protocol(hdr, false);
+   if (bootproto < 0x0200 || hdr->setup_sects < 15)
+   return NULL;
+
+   return kernel_base + hdr->kernel_version + 0x200;
+}
+
 struct boot_params *load_zimage(char *image, unsigned long kernel_size,
ulong *load_addressp)
 {
struct boot_params *setup_base;
+   const char *version;
int setup_size;
int bootproto;
int big_image;
@@ -178,21 +194,16 @@ struct boot_params *load_zimage(char *image, unsigned 
long kernel_size,
printf("Error: Setup is too large (%d bytes)\n", setup_size);
 
/* determine boot protocol version */
-   bootproto = get_boot_protocol(hdr);
+   bootproto = get_boot_protocol(hdr, true);
 
printf("Using boot protocol version %x.%02x\n",
   (bootproto & 0xff00) >> 8, bootproto & 0xff);
 
-   if (bootproto >= 0x0200) {
-   if (hdr->setup_sects >= 15) {
-   printf("Linux kernel version %s\n",
-   (char *)params +
-   hdr->kernel_version + 0x200);
-   } else {
-   printf("Setup Sectors < 15 - "
-   "Cannot print kernel version.\n");
-   }
-   }
+   version = get_kernel_version(params, image);
+   if (version)
+   printf("Linux kernel version %s\n", version);
+   else
+   printf("Setup Sectors < 15 - Cannot print kernel version\n");
 
/* Determine image type */
big_image = (bootproto >= 0x0200) &&
@@ -261,7 +272,7 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
 unsigned long initrd_addr, unsigned long initrd_size)
 {
struct setup_header *hdr = _base->hdr;
-   int bootproto = get_boot_protocol(hdr);
+   int bootproto = get_boot_protocol(hdr, false);
 
setup_base->e820_entries = install_e820_map(
ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map);
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 03/17] x86: zimage: Avoid using #ifdef

2020-09-05 Thread Simon Glass
Use IS_ENABLED() instead of #ifdef in this file.

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

(no changes since v1)

 arch/x86/lib/zimage.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index a79971f052c..3c8081a48bb 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -303,21 +303,17 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
build_command_line(cmd_line, auto_boot);
}
 
-#ifdef CONFIG_INTEL_MID
-   if (bootproto >= 0x0207)
+   if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207)
hdr->hardware_subarch = X86_SUBARCH_INTEL_MID;
-#endif
 
-#ifdef CONFIG_GENERATE_ACPI_TABLE
-   setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr();
-#endif
+   if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE))
+   setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr();
 
setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0));
setup_video(_base->screen_info);
 
-#ifdef CONFIG_EFI_STUB
-   setup_efi_info(_base->efi_info);
-#endif
+   if (IS_ENABLED(CONFIG_EFI_STUB))
+   setup_efi_info(_base->efi_info);
 
return 0;
 }
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 00/17] x86: zboot: Enhance the 'zboot' command

2020-09-05 Thread Simon Glass
This command is currently monolithic and does not support scripts which
want to adjust the boot process. This series updates it to be more like
'bootm', in that it has sub-commands for each stage of the boot. This
allows some stages to be adjusted or skipped.

It also adds a way to dump out the setup block.

With these changes it is possible to boot an x86 Chrome OS image from a
script.

Changes in v3:
- Add a comment about complete_zboot()
- Adjust maxargs in this patch
- Fix 'summary' typo
- Mention that the environment variables are for x86 only
- Move command help into the patch for each command
- Reduce maxargs to 6
- Split the 'load' command into its own patch
- Update two local arrays to be static
- Use 'Commandline' instead of 'Commandline'

Changes in v2:
- Add a comment explaining the logic for a specified setup-base address
- Adjust maxargs in this patch
- Fix comment about argv[0] in do_zboot_parent()

Simon Glass (17):
  x86: Update the bootparam header
  x86: zimage: Use a state struct to hold the state
  x86: zimage: Avoid using #ifdef
  x86: zboot: Move kernel-version code into a function
  x86: zboot: Correct image type
  x86: zimage: Disable interrupts just before booting
  x86: zboot: Set up a sub-command structure
  x86: zboot: Add a 'go' subcommand
  x86: zboot: Add an 'info' subcommand
  x86: zboot: Add an 'load' subcommand
  x86: zboot: Add an 'setup' subcommand
  x86: zboot: Set environment variables for image locations
  x86: zboot: Allow setting a separate setup base address
  x86: zboot: Add an option to dump the setup information
  x86: zboot: Allow overriding the command line
  cros: Update chromium documentation
  cros: Add information about booting Chrome OS on x86

 README   |   4 +
 arch/x86/include/asm/bootparam.h |  25 +-
 arch/x86/include/asm/e820.h  |   1 +
 arch/x86/include/asm/zimage.h|  30 +-
 arch/x86/lib/bootm.c |   2 +-
 arch/x86/lib/zimage.c| 484 +++
 doc/README.chromium  |  41 ++-
 7 files changed, 521 insertions(+), 66 deletions(-)

-- 
2.28.0.526.ge36021eeef-goog



Re: [PATCH v2 2/2] sandbox: enable support of generic udp protocol

2020-09-05 Thread Simon Glass
On Mon, 31 Aug 2020 at 11:27, Philippe Reynes
 wrote:
>
> This commit enable the support of the generic udp protocol.
>
> Signed-off-by: Philippe Reynes 
> ---
>
> Changelog:
> v2:
> - new patch in the serie
>
>  configs/sandbox_defconfig | 1 +
>  1 file changed, 1 insertion(+)
>

Reviewed-by: Simon Glass 

But I think this needs to actually use it!


Re: [PATCH v2 1/2] net: add a generic udp protocol

2020-09-05 Thread Simon Glass
On Mon, 31 Aug 2020 at 11:27, Philippe Reynes
 wrote:
>
> This commit adds a generic udp protocol framework in the
> network loop. So protocol based on udp may be implemented
> without modifying the network loop (for example custom
> wait magic packet).
>
> Signed-off-by: Philippe Reynes 
> ---
>
> Changelog:
> v2:
> - no change
>
>  include/net.h |  2 +-
>  include/net/udp.h | 31 +++
>  net/Kconfig   |  6 ++
>  net/Makefile  |  1 +
>  net/net.c | 15 ++-
>  net/udp.c | 48 
>  6 files changed, 101 insertions(+), 2 deletions(-)
>  create mode 100644 include/net/udp.h
>  create mode 100644 net/udp.c
>

Reviewed-by: Simon Glass 

Needs a mention in docs somewhere.

nits below

> diff --git a/include/net.h b/include/net.h
> index 1bf9867..2191071 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -551,7 +551,7 @@ extern int  net_restart_wrap;   /* Tried all 
> network devices */
>
>  enum proto_t {
> BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
> -   TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL
> +   TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP
>  };
>
>  extern charnet_boot_file_name[1024];/* Boot File name */
> diff --git a/include/net/udp.h b/include/net/udp.h
> new file mode 100644
> index 000..f97df8d
> --- /dev/null
> +++ b/include/net/udp.h
> @@ -0,0 +1,31 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2020 Philippe Reynes 
> + */
> +
> +#ifndef __UDP
> +#define __UDP
> +
> +/**
> + * struct udp_ops - function to handle udp packet
> + *
> + * This structure provides the function to handle udp packet in
> + * the network loop.
> + *
> + * @prereq: callback called to check the requirement
> + * @start: callback called to start the protocol/feature
> + * @data: pointer to store private data (used by prereq and start)
> + */
> +struct udp_ops {
> +   int (*prereq)(void *data);
> +   int (*start)(void *data);
> +   void *data;
> +};
> +
> +int udp_prereq(void);
> +
> +int udp_start(void);
> +
> +int udp_loop(struct udp_ops *h);

Need function comments for these. Also how about 'ops' instead of 'h'?

> +
> +#endif
> diff --git a/net/Kconfig b/net/Kconfig
> index 6874b55..db8d796 100644
> --- a/net/Kconfig
> +++ b/net/Kconfig
> @@ -8,6 +8,12 @@ menuconfig NET
>
>  if NET
>
> +config PROT_UDP
> +   bool "Enable generic udp framework"
> +   help
> + Enable a generic udp framework that allow to define custom

that allows defining a custom

> + handler for udp protocol.
> +
>  config BOOTP_SEND_HOSTNAME
> bool "Send hostname to DNS server"
> help
> diff --git a/net/Makefile b/net/Makefile
> index fef71b9..76527f7 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -27,6 +27,7 @@ obj-$(CONFIG_CMD_SNTP) += sntp.o
>  obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
>  obj-$(CONFIG_UDP_FUNCTION_FASTBOOT)  += fastboot.o
>  obj-$(CONFIG_CMD_WOL)  += wol.o
> +obj-$(CONFIG_PROT_UDP) += udp.o
>
>  # Disable this warning as it is triggered by:
>  # sprintf(buf, index ? "foo%d" : "foo", index)
> diff --git a/net/net.c b/net/net.c
> index 28d9eeb..f6ae814 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -102,6 +102,7 @@
>  #if defined(CONFIG_CMD_PCAP)
>  #include 
>  #endif
> +#include 
>  #if defined(CONFIG_LED_STATUS)
>  #include 
>  #include 
> @@ -540,6 +541,11 @@ restart:
> wol_start();
> break;
>  #endif
> +#if defined(CONFIG_PROT_UDP)

I think you can get the same effect by putting if() after the case

> +   case UDP:
> +   udp_start();
> +   break;
> +#endif
> default:
> break;
> }
> @@ -1364,6 +1370,13 @@ static int net_check_prereq(enum proto_t protocol)
> }
> goto common;
>  #endif
> +#if defined(CONFIG_PROT_UDP)

Same here

> +   case UDP:
> +   if (udp_prereq())
> +   return 1;
> +   goto common;
> +#endif
> +
>  #if defined(CONFIG_CMD_NFS)
> case NFS:
>  #endif
> @@ -1375,7 +1388,7 @@ static int net_check_prereq(enum proto_t protocol)
> return 1;
> }
>  #ifdefined(CONFIG_CMD_PING) || defined(CONFIG_CMD_SNTP) || \
> -   defined(CONFIG_CMD_DNS)
> +   defined(CONFIG_CMD_DNS) || defined(CONFIG_PROT_UDP)
>  common:
>  #endif
> /* Fall through */
> diff --git a/net/udp.c b/net/udp.c
> new file mode 100644
> index 000..2409ce4
> --- /dev/null
> +++ b/net/udp.c
> @@ -0,0 +1,48 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2020 Philippe Reynes 
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +static struct udp_ops *udp_ops;
> +
> +int udp_prereq(void)
> +{
> +   int ret = 0;
> +
> +   if (udp_ops && udp_ops->prereq)

You 

[PATCH] x86: Drop duplicate declaration of emulator state

2020-09-05 Thread Simon Glass
With x86 we can execute an option ROM either natively or using the x86
emulator (if enabled with CONFIG_BIOSEMU). Both of these share the
_X86EMU_env variable, with the native code using it to hold register state
during interrupt processing.

At present, in 32-bit U-Boot, the variable is declared twice, once in
common code and once in code only compiled with CONFIG_BIOSEMU.

With gcc-10 this causes a 'multiple definitions' error on boards with
CONFIG_BIOSEMU.

Drop the emulator definition, except for 64-bit builds.

Also drop inclusion of the emulator in 64-bit U-Boot since this does not
work at present, and generally isn't needed if 32-bit code has already set
up the option ROMs.

Reported-by: Heinrich Schuchardt 
Signed-off-by: Simon Glass 
---

 drivers/bios_emulator/x86emu/sys.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/bios_emulator/x86emu/sys.c 
b/drivers/bios_emulator/x86emu/sys.c
index c2db1213fe6..146586b3ceb 100644
--- a/drivers/bios_emulator/x86emu/sys.c
+++ b/drivers/bios_emulator/x86emu/sys.c
@@ -44,7 +44,11 @@
 
 /*- Global Variables --*/
 
+/* Definite this here since the emulator is not present on 64-bit */
+#ifdef CONFIG_X86_64
 X86EMU_sysEnv _X86EMU_env; /* Global emulator machine state */
+#endif
+
 X86EMU_intrFuncs _X86EMU_intrTab[256];
 
 int debug_intr;
-- 
2.28.0.526.ge36021eeef-goog



Re: x86: multiple definition of `_X86EMU_env'

2020-09-05 Thread Simon Glass
Hi Heinrich,

On Tue, 1 Sep 2020 at 00:41, Heinrich Schuchardt  wrote:
>
> Dear Simon,
>
> make chromebook_coral_defconfig
> make
>
> using gcc (Debian 10.2.0-5) 10.2.0 and GNU ld (GNU Binutils for Debian)
> 2.35 results in:
>
> ld.bfd: drivers/built-in.o:drivers/bios_emulator/x86emu/sys.c:47:
> multiple definition of `_X86EMU_env';
> arch/x86/lib/built-in.o:arch/x86/lib/bios.c:25: first defined here
>
> ld.bfd: arch/x86/cpu/built-in.o: warning:
> relocation in read-only section `.text'
> ld.bfd: warning: creating DT_TEXTREL in a PIE
> make: *** [Makefile:1753: u-boot] Error 1
>
> My git head is at current origin/master: 23e333a5c083a000d0.

OK I will send a patch.

Regards,
Simon


Re: [PATCH v2] buildman: Use git worktrees instead of git clones when possible

2020-09-05 Thread Simon Glass
On Sat, 5 Sep 2020 at 10:36, Simon Glass  wrote:
>
> On Thu, 3 Sep 2020 at 06:51, Alper Nebi Yasak  
> wrote:
> >
> > This patch makes buildman create linked working trees instead of clones
> > of the source repository, but keeps updating the older clones of the
> > repository that might already exist. These worktrees share "everything
> > except working directory specific files such as HEAD, index, etc." with
> > the source repository. See the git-worktree(1) manual page for more
> > information.
> >
> > If git-worktree isn't available, silently falls back to cloning the
> > repository.
> >
> > Signed-off-by: Alper Nebi Yasak 
> > ---
> > I used 'git worktree list's return code, since 'git worktree' returns
> > non-zero (prints usage) even if it's available.
> >
> > This does fall back to git clone on my Ubuntu 14.04 amd64 VM, but all
> > the builds instantly give an error about the Makefile even before this
> > patch. The buildman parts are working as far as I can tell.
> >
> > Changes in v2:
> > - Fall back to cloning if git-worktree isn't available
> > - Add a gitutil.CheckWorktreeIsAvailable(git_dir) function
> > - Refactor the _PrepareThread changes
> > - Make _PrepeareThread's setup_git argument accept 'clone' or 'worktree'
> > - Some comment and docstring changes
> >
> > v1: https://patchwork.ozlabs.org/project/uboot/list/?series=199060
> >
> >  tools/buildman/builder.py   | 48 ++---
> >  tools/buildman/func_test.py |  2 ++
> >  tools/patman/gitutil.py | 42 
> >  3 files changed, 84 insertions(+), 8 deletions(-)
>
> Reviewed-by: Simon Glass 

Tested-by: Simon Glass 


Re: [PATCH 2/3] binman: Use target-specific tools when cross-compiling

2020-09-05 Thread Simon Glass
Hi Alper,

On Sat, 5 Sep 2020 at 08:44, Alper Nebi Yasak  wrote:
>
> Currently, binman always runs the compile tools like cc, objcopy, strip,
> etc. using their literal name. Instead, this patch makes it use the
> target-specific versions by default, derived from the tool-specific
> environment variables (CC, OBJCOPY, STRIP, etc.) or from the
> CROSS_COMPILE environment variable.
>
> For example, the u-boot-elf etype directly uses 'strip'. Trying to run
> the tests with 'CROSS_COMPILE=i686-linux-gnu- binman test' on an arm64
> host results in the '097_elf_strip.dts' test to fail as the arm64
> version of 'strip' can't understand the format of the x86 ELF file.
>
> This also adjusts some command.Output() calls that caused test errors or
> failures to use the target versions of the tools they call. After this,
> patch, an arm64 host can run all tests with no errors or failures using
> a correct CROSS_COMPILE value.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
>
>  tools/binman/elf.py  |  6 +++--
>  tools/binman/elf_test.py |  4 ++-
>  tools/dtoc/fdt_util.py   |  9 ---
>  tools/patman/tools.py| 58 
>  4 files changed, 70 insertions(+), 7 deletions(-)

This looks good, but it drops the use of DTC to specify the
device-tree compiler. Can you add it back?

Regards,
Simon


Re: [PATCH 3/3] binman: Allow resolving host-specific tools from env vars

2020-09-05 Thread Simon Glass
On Sat, 5 Sep 2020 at 08:44, Alper Nebi Yasak  wrote:
>
> This patch lets tools.Run() use host-specific versions with the
> for_host keyword argument, based on the host-specific environment
> variables (HOSTCC, HOSTOBJCOPY, HOSTSTRIP, etc.).
>
> Signed-off-by: Alper Nebi Yasak 
> ---
> Not sure if this patch will ever be useful, but it complements the
> previous patch very well.

Yes, agreed.

>
>  tools/patman/tools.py | 32 +++-
>  1 file changed, 31 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass 

Please see below.

Also please add a mention of the CROSS_COMPILE thing in binman's README.

>
> diff --git a/tools/patman/tools.py b/tools/patman/tools.py
> index ee8b70d0cc..6d539fe594 100644
> --- a/tools/patman/tools.py
> +++ b/tools/patman/tools.py
> @@ -188,6 +188,31 @@ def PathHasFile(path_spec, fname):
>  return True
>  return False
>
> +def GetHostCompileTool(name):
> +"""Get the host-specific version for a compile tool
> +
> +This checks the environment variables that specify which version of
> +the tool should be used.

Can you please expand the comment to mention the environment variables
it checks?


> +
> +Args:
> +name: Command name to run
> +
> +Returns:
> +host_name: Exact command name to run instead
> +extra_args: List of extra arguments to pass
> +"""
> +host_name = None
> +extra_args = []
> +if name in ('as', 'ld', 'cc', 'cpp', 'ar', 'nm', 'ldr', 'strip',
> +'objcopy', 'objdump', 'dtc'):
> +host_name, *host_args = env.get('HOST' + name.upper(), '').split(' ')
> +elif name == 'c++':
> +host_name, *host_args = env.get('HOSTCXX', '').split(' ')
> +
> +if host_name:
> +return host_name, extra_args
> +return name, []
> +
>  def GetTargetCompileTool(name, cross_compile=None):
>  """Get the target-specific version for a compile tool
>
> @@ -250,6 +275,7 @@ def Run(name, *args, **kwargs):
>  Args:
>  name: Command name to run
>  args: Arguments to the tool
> +for_host: True to resolve the command to the version for the host
>  for_target: False to run the command as-is, without resolving it
> to the version for the compile target
>
> @@ -258,7 +284,8 @@ def Run(name, *args, **kwargs):
>  """
>  try:
>  binary = kwargs.get('binary')
> -for_target = kwargs.get('for_target', True)
> +for_host = kwargs.get('for_host', False)
> +for_target = kwargs.get('for_target', not for_host)
>  env = None
>  if tool_search_paths:
>  env = dict(os.environ)
> @@ -266,6 +293,9 @@ def Run(name, *args, **kwargs):
>  if for_target:
>  name, extra_args = GetTargetCompileTool(name)
>  args = tuple(extra_args) + args
> +elif for_host:
> +name, extra_args = GetHostCompileTool(name)
> +args = tuple(extra_args) + args
>  all_args = (name,) + args
>  result = command.RunPipe([all_args], capture=True, 
> capture_stderr=True,
>   env=env, raise_on_error=False, 
> binary=binary)
> --
> 2.28.0
>


Re: [PATCH 1/3] binman: Support cross-compiling test files to x86

2020-09-05 Thread Simon Glass
Hi Alper,

On Sat, 5 Sep 2020 at 08:44, Alper Nebi Yasak  wrote:
>
> These test files are currently "intended for use on x86 hosts", but most
> of the tests using them can still pass when cross-compiled to x86 on an
> arm64 host.
>
> This patch enables non-x86 hosts to run the tests by specifying a
> cross-compiler via CROSS_COMPILE. The list of variables it sets is taken
> from the top-level Makefile. It would be possible to automatically set
> an x86 cross-compiler with a few blocks like:
>
> ifneq ($(shell i386-linux-gnu-gcc --version 2> /dev/null),)
> CROSS_COMPILE = i386-linux-gnu-
> endif
>
> But it wouldn't propagate to the binman process calling this Makefile,
> so it's better just raise an error and expect 'binman test' to be run
> with a correct CROSS_COMPILE.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
>
>  tools/binman/test/Makefile | 28 +++-
>  1 file changed, 27 insertions(+), 1 deletion(-)

For me this fails on x86_64, complaining for example:

Exception: Error 2 running 'make -C /tmp/binmant.d17vfu3j/elftest -f
/scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/Makefile
SRC=/scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/':
/scratch/sglass/cosarm/src/third_party/u-boot/files/tools/binman/test/Makefile:14:
*** Binman tests need to compile to x86, but the CPU arch of your
machine is x86_64. Set CROSS_COMPILE to a suitable cross compiler.
Stop.

Can you make it work on both i386 and x86_64 without complaining? It
looks like that is the intent.

Also I'm not sure we need to define vars for all the tools, so you
could perhaps drop those that are not needed.

Regards,
Simon


Re: [PATCH v2] buildman: Use git worktrees instead of git clones when possible

2020-09-05 Thread Simon Glass
On Thu, 3 Sep 2020 at 06:51, Alper Nebi Yasak  wrote:
>
> This patch makes buildman create linked working trees instead of clones
> of the source repository, but keeps updating the older clones of the
> repository that might already exist. These worktrees share "everything
> except working directory specific files such as HEAD, index, etc." with
> the source repository. See the git-worktree(1) manual page for more
> information.
>
> If git-worktree isn't available, silently falls back to cloning the
> repository.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
> I used 'git worktree list's return code, since 'git worktree' returns
> non-zero (prints usage) even if it's available.
>
> This does fall back to git clone on my Ubuntu 14.04 amd64 VM, but all
> the builds instantly give an error about the Makefile even before this
> patch. The buildman parts are working as far as I can tell.
>
> Changes in v2:
> - Fall back to cloning if git-worktree isn't available
> - Add a gitutil.CheckWorktreeIsAvailable(git_dir) function
> - Refactor the _PrepareThread changes
> - Make _PrepeareThread's setup_git argument accept 'clone' or 'worktree'
> - Some comment and docstring changes
>
> v1: https://patchwork.ozlabs.org/project/uboot/list/?series=199060
>
>  tools/buildman/builder.py   | 48 ++---
>  tools/buildman/func_test.py |  2 ++
>  tools/patman/gitutil.py | 42 
>  3 files changed, 84 insertions(+), 8 deletions(-)

Reviewed-by: Simon Glass 


[PATCH 3/3] binman: Allow resolving host-specific tools from env vars

2020-09-05 Thread Alper Nebi Yasak
This patch lets tools.Run() use host-specific versions with the
for_host keyword argument, based on the host-specific environment
variables (HOSTCC, HOSTOBJCOPY, HOSTSTRIP, etc.).

Signed-off-by: Alper Nebi Yasak 
---
Not sure if this patch will ever be useful, but it complements the
previous patch very well.

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

diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index ee8b70d0cc..6d539fe594 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -188,6 +188,31 @@ def PathHasFile(path_spec, fname):
 return True
 return False
 
+def GetHostCompileTool(name):
+"""Get the host-specific version for a compile tool
+
+This checks the environment variables that specify which version of
+the tool should be used.
+
+Args:
+name: Command name to run
+
+Returns:
+host_name: Exact command name to run instead
+extra_args: List of extra arguments to pass
+"""
+host_name = None
+extra_args = []
+if name in ('as', 'ld', 'cc', 'cpp', 'ar', 'nm', 'ldr', 'strip',
+'objcopy', 'objdump', 'dtc'):
+host_name, *host_args = env.get('HOST' + name.upper(), '').split(' ')
+elif name == 'c++':
+host_name, *host_args = env.get('HOSTCXX', '').split(' ')
+
+if host_name:
+return host_name, extra_args
+return name, []
+
 def GetTargetCompileTool(name, cross_compile=None):
 """Get the target-specific version for a compile tool
 
@@ -250,6 +275,7 @@ def Run(name, *args, **kwargs):
 Args:
 name: Command name to run
 args: Arguments to the tool
+for_host: True to resolve the command to the version for the host
 for_target: False to run the command as-is, without resolving it
to the version for the compile target
 
@@ -258,7 +284,8 @@ def Run(name, *args, **kwargs):
 """
 try:
 binary = kwargs.get('binary')
-for_target = kwargs.get('for_target', True)
+for_host = kwargs.get('for_host', False)
+for_target = kwargs.get('for_target', not for_host)
 env = None
 if tool_search_paths:
 env = dict(os.environ)
@@ -266,6 +293,9 @@ def Run(name, *args, **kwargs):
 if for_target:
 name, extra_args = GetTargetCompileTool(name)
 args = tuple(extra_args) + args
+elif for_host:
+name, extra_args = GetHostCompileTool(name)
+args = tuple(extra_args) + args
 all_args = (name,) + args
 result = command.RunPipe([all_args], capture=True, capture_stderr=True,
  env=env, raise_on_error=False, binary=binary)
-- 
2.28.0



[PATCH 0/3] binman: Make tests work on non-x86 architectures via cross-compilation

2020-09-05 Thread Alper Nebi Yasak
Right now the 'binman test' command fails spectacularly on arm64 since
it cannot even setup the test environments properly due to errors during
setUpClass(). I can get a 100% coverage result with all tests passing if
I cross-compile things to x86 and run the cross-compiling versions of
some tools. This series tries to implement that solution in a general
way.

I think the thoroughly proper thing would be to make the tests and their
files portable. I don't really know how. Another alternative is to split
the test environments into multiple parts and skip the parts that can't
be prepared for an architecture, but that affects the test coverage
results. In any case, this series doesn't really prevent these other
solutions from being implemented on top of it.


Alper Nebi Yasak (3):
  binman: Support cross-compiling test files to x86
  binman: Use target-specific tools when cross-compiling
  binman: Allow resolving host-specific tools from env vars

 tools/binman/elf.py|  6 ++-
 tools/binman/elf_test.py   |  4 +-
 tools/binman/test/Makefile | 28 +++-
 tools/dtoc/fdt_util.py |  9 ++--
 tools/patman/tools.py  | 88 ++
 5 files changed, 127 insertions(+), 8 deletions(-)

-- 
2.28.0



[PATCH 2/3] binman: Use target-specific tools when cross-compiling

2020-09-05 Thread Alper Nebi Yasak
Currently, binman always runs the compile tools like cc, objcopy, strip,
etc. using their literal name. Instead, this patch makes it use the
target-specific versions by default, derived from the tool-specific
environment variables (CC, OBJCOPY, STRIP, etc.) or from the
CROSS_COMPILE environment variable.

For example, the u-boot-elf etype directly uses 'strip'. Trying to run
the tests with 'CROSS_COMPILE=i686-linux-gnu- binman test' on an arm64
host results in the '097_elf_strip.dts' test to fail as the arm64
version of 'strip' can't understand the format of the x86 ELF file.

This also adjusts some command.Output() calls that caused test errors or
failures to use the target versions of the tools they call. After this,
patch, an arm64 host can run all tests with no errors or failures using
a correct CROSS_COMPILE value.

Signed-off-by: Alper Nebi Yasak 
---

 tools/binman/elf.py  |  6 +++--
 tools/binman/elf_test.py |  4 ++-
 tools/dtoc/fdt_util.py   |  9 ---
 tools/patman/tools.py| 58 
 4 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index f88031c2bf..5e566e56cb 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -234,8 +234,10 @@ SECTIONS
 #   text section at the start
 # -m32: Build for 32-bit x86
 # -T...: Specifies the link script, which sets the start address
-stdout = command.Output('cc', '-static', '-nostdlib', 
'-Wl,--build-id=none',
-'-m32','-T', lds_file, '-o', elf_fname, s_file)
+cc, args = tools.GetTargetCompileTool('cc')
+args += ['-static', '-nostdlib', '-Wl,--build-id=none', '-m32', '-T',
+lds_file, '-o', elf_fname, s_file]
+stdout = command.Output(cc, *args)
 shutil.rmtree(outdir)
 
 def DecodeElf(data, location):
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index 37e1b423cf..e3d218a89e 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -186,7 +186,9 @@ class TestElf(unittest.TestCase):
 # Make an Elf file and then convert it to a fkat binary file. This
 # should produce the original data.
 elf.MakeElf(elf_fname, expected_text, expected_data)
-stdout = command.Output('objcopy', '-O', 'binary', elf_fname, 
bin_fname)
+objcopy, args = tools.GetTargetCompileTool('objcopy')
+args += ['-O', 'binary', elf_fname, bin_fname]
+stdout = command.Output(objcopy, *args)
 with open(bin_fname, 'rb') as fd:
 data = fd.read()
 self.assertEqual(expected_text + expected_data, data)
diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py
index b040793772..37e96b9864 100644
--- a/tools/dtoc/fdt_util.py
+++ b/tools/dtoc/fdt_util.py
@@ -68,22 +68,23 @@ def EnsureCompiled(fname, tmpdir=None, 
capture_stderr=False):
 
 search_paths = [os.path.join(os.getcwd(), 'include')]
 root, _ = os.path.splitext(fname)
-args = ['-E', '-P', '-x', 'assembler-with-cpp', '-D__ASSEMBLY__']
+cc, args = tools.GetTargetCompileTool('cc')
+args += ['-E', '-P', '-x', 'assembler-with-cpp', '-D__ASSEMBLY__']
 args += ['-Ulinux']
 for path in search_paths:
 args.extend(['-I', path])
 args += ['-o', dts_input, fname]
-command.Run('cc', *args)
+command.Run(cc, *args)
 
 # If we don't have a directory, put it in the tools tempdir
 search_list = []
 for path in search_paths:
 search_list.extend(['-i', path])
-args = ['-I', 'dts', '-o', dtb_output, '-O', 'dtb',
+dtc, args = tools.GetTargetCompileTool('dtc')
+args += ['-I', 'dts', '-o', dtb_output, '-O', 'dtb',
 '-W', 'no-unit_address_vs_reg']
 args.extend(search_list)
 args.append(dts_input)
-dtc = os.environ.get('DTC') or 'dtc'
 command.Run(dtc, *args, capture_stderr=capture_stderr)
 return dtb_output
 
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index d41115a22c..ee8b70d0cc 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -188,6 +188,58 @@ def PathHasFile(path_spec, fname):
 return True
 return False
 
+def GetTargetCompileTool(name, cross_compile=None):
+"""Get the target-specific version for a compile tool
+
+This first checks the environment variables that specify which
+version of the tool should be used (e,g, ${CC}). If those aren't
+specified, it checks the CROSS_COMPILE variable as a prefix for the
+tool with some substitutions (e.g. "${CROSS_COMPILE}gcc" for cc).
+
+Args:
+name: Command name to run
+
+Returns:
+target_name: Exact command name to run instead
+extra_args: List of extra arguments to pass
+"""
+env = dict(os.environ)
+
+target_name = None
+extra_args = []
+if name in ('as', 'ld', 'cc', 'cpp', 'ar', 'nm', 'ldr', 'strip',
+'objcopy', 'objdump', 'dtc'):
+target_name, *extra_args = env.get(name.upper(), 

[PATCH 1/3] binman: Support cross-compiling test files to x86

2020-09-05 Thread Alper Nebi Yasak
These test files are currently "intended for use on x86 hosts", but most
of the tests using them can still pass when cross-compiled to x86 on an
arm64 host.

This patch enables non-x86 hosts to run the tests by specifying a
cross-compiler via CROSS_COMPILE. The list of variables it sets is taken
from the top-level Makefile. It would be possible to automatically set
an x86 cross-compiler with a few blocks like:

ifneq ($(shell i386-linux-gnu-gcc --version 2> /dev/null),)
CROSS_COMPILE = i386-linux-gnu-
endif

But it wouldn't propagate to the binman process calling this Makefile,
so it's better just raise an error and expect 'binman test' to be run
with a correct CROSS_COMPILE.

Signed-off-by: Alper Nebi Yasak 
---

 tools/binman/test/Makefile | 28 +++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/tools/binman/test/Makefile b/tools/binman/test/Makefile
index e4fd97bb2e..e10a8625db 100644
--- a/tools/binman/test/Makefile
+++ b/tools/binman/test/Makefile
@@ -7,6 +7,32 @@
 # SPDX-License-Identifier:  GPL-2.0+
 #
 
+HOST_ARCH := $(shell uname -m | sed -e s/i.86/x86/ )
+ifeq ($(findstring $(HOSTARCH),"x86" "x86_64"),)
+ifeq ($(findstring $(MAKECMDGOALS),"help" "clean"),)
+ifndef CROSS_COMPILE
+$(error Binman tests need to compile to x86, but the CPU arch of your \
+   machine is $(HOST_ARCH). Set CROSS_COMPILE to a suitable cross compiler)
+endif
+endif
+endif
+
+AS = $(CROSS_COMPILE)as
+# Always use GNU ld
+ifneq ($(shell $(CROSS_COMPILE)ld.bfd -v 2> /dev/null),)
+LD = $(CROSS_COMPILE)ld.bfd
+else
+LD = $(CROSS_COMPILE)ld
+endif
+CC = $(CROSS_COMPILE)gcc
+CPP= $(CC) -E
+AR = $(CROSS_COMPILE)ar
+NM = $(CROSS_COMPILE)nm
+LDR= $(CROSS_COMPILE)ldr
+STRIP  = $(CROSS_COMPILE)strip
+OBJCOPY= $(CROSS_COMPILE)objcopy
+OBJDUMP= $(CROSS_COMPILE)objdump
+
 VPATH := $(SRC)
 CFLAGS := -march=i386 -m32 -nostdlib -I $(SRC)../../../include \
-Wl,--no-dynamic-linker
@@ -32,7 +58,7 @@ bss_data: CFLAGS += $(SRC)bss_data.lds
 bss_data: bss_data.c
 
 u_boot_binman_syms.bin: u_boot_binman_syms
-   objcopy -O binary $< -R .note.gnu.build-id $@
+   $(OBJCOPY) -O binary $< -R .note.gnu.build-id $@
 
 u_boot_binman_syms: CFLAGS += $(LDS_BINMAN)
 u_boot_binman_syms: u_boot_binman_syms.c
-- 
2.28.0



Re: [PATCH v5 11/11] riscv: Add FPIOA and GPIO support for Kendryte K210

2020-09-05 Thread Sean Anderson
On 9/2/20 11:59 AM, Sean Anderson wrote:
> On 9/2/20 8:26 AM, Heinrich Schuchardt wrote:
>> After adding some debug functions the error appeared and disappeared
>> when changing the code in function panic(). So my guess is that there is
>> some alignment problem in the static data section.
> 
> I investigated this further using the following script
> 
> while true; do
>   sed -i 's/nop();$/nop(); nop();/g' board/sipeed/maix/maix.c &&
>   git commit --amend --no-edit board/sipeed/maix/maix.c &&
>   CROSS_COMPILE=riscv64-linux-gnu- make -j$(nproc) &&
>   kflash -tp /dev/ttyUSB0 -B bit_mic -b 150 u-boot-dtb.bin"
> done
> 
> To start this process, create a commit which adds a nop() to
> board/sipeed/maix/maix.c. On every iteration, this script will amend
> that commit by adding another nop. I tried up to 65 nops. If the amount
> of nops is 0, 24, 28, 29, 30, 31, 32, 40, 44, 46, 49, 56, 60, 61, 62,
> 63, or 64 the board fails to boot. Of these failures, all printed up to
> "DRAM: ..." except for those with 28, 29, 30, 31, 60, 61, 62, or 64
> nops. There is clearly a pattern whith failures occuring at or near
> (but not always exactly on) multiples of 4, and in the lead-up to
> multiples of 32.

These patterns cause two different bugs, which I will refer to as the
"multiple-of-four" bug and the "periodic-32" bug.

The multiple-of-four bug is fixed by [1]. This bug is not present in
u-boot/master atm, but I am not sure why. Perhaps adding more drivers
which depend on the device tree triggers the behavior.

>> On 01.09.20 03:19, Rick Chen wrote:
>>> To see if this way can pin down which instruction or the crucial code
>>> to cause the bus hang problem. And guess what maybe the root-cause.
>>>
>>> If you can find the instruction which may cause the bus hang, you can
>>> info all-registers and compare the differences between NG and OK. And
>>> guess what maybe the root-cause.
>>
>> Trying to narrow down on the problem I found the following:
>>
>> The system hangs before arch_cpu_init_dm() is called.
> 
> This is not always the case. On most boots, the following output is
> present:
> 
> U-Boot 2020.10-rc3-00045-g7532b003f0 (Sep 02 2020 - 11:09:16 -0400)
> 
> DRAM:  8 MiB
> 
> which means at least everything up to dram_init gets called.

This output is symptomatic of the multiple-of-four bug. After applying
[1], either a successful boot should take place, or there should be no
output at all (corresponding to the periodic-32 bug).

>>>
>>> Maybe you can try to set a break and access the bus, if the bus access
>>> fail, then you re-set a break a bit ahead until the bus access NOT
>>> fail.
> 
> Yeah, I was investigating that, however I was unable to get the k210 to
> break at 0x8000. I suspect this may be a problem with openocd, as
> the k210 port is rather buggy (e.g. it can cause address misaligned
> errors, and sometimes leaves the pc in the debug dection of memory). I
> *can* get it to break in the otp (0x8800), so perhaps I just need to
> identify the address before it jumps to U-Boot.

When attempting to boot with a U-boot which has the periodic-32 bug,
there is no output, even with an early uart and debug logs enabled. I
have tried using two versions of openocd to determine the cause. The kendryte
openocd [2] supports attaching to either core of the k210, but must be
restarted to debug the other core. It also keeps the non-debugged core
halted. The riscv openocd [3] only supports debugging core 0. However,
it contains numerous bugfixes and improvements which the kendryte
openocd does not contain.

When attaching the kendryte openocd, the following output (among other
things) is printed:

Core [1] halted at 0x80015590 due to debug interrupt
Core [0] halted at 0x88008c00 due to debug interrupt

The core 1's pc is located within _sifive_serial_putc, and this is
reflected by the console containing a partially-printed announcement
for the first printed initcall. This initcall is initf_bootstage, which
is the first initcall after log_init. If openocd is attached to core 1,
and it is resumed, then U-Boot boots as normal (in contrast to the
behavior exhibited if openocd is not attached).

What is more interesting is the pc of core 0. It is located in the boot
rom of the K210. According to [4] (and as verified by myself), this
address corresponds with the uarths_getc function. This function is
only called by isp_run. This means core 0 is stuck in ISP mode, which is
used to flash firmware.

Attaching a debugger clearly affects the boot process of this core, but
I am not sure in what manner. I am attempting to modify the riscv
openocd to support multiple cores, but it is slow going (there is a lot
of undocumented code with side-effects).

--Sean

[1] 
https://patchwork.ozlabs.org/project/uboot/patch/20200905132211.412711-1-sean...@gmail.com/
[2] https://github.com/kendryte/openocd-kendryte
[3] https://github.com/riscv/riscv-openocd
[4] 

[PATCH] riscv: Only enable OF_BOARD_FIXUP for S-Mode

2020-09-05 Thread Sean Anderson
It is unsafe to enable OF_BOARD_FIXUP only based on OF_SEPARATE.
OF_SEPARATE may indicate that the user wishes U-Boot to use a different
device tree than one obtained via OF_PRIOR_STAGE. However, OF_SEPARATE may
also indicate that the device tree which would be obtained via
OF_PRIOR_STAGE is invalid, nonexistant, or otherwise unusable. In this
latter case, enabling OF_BOARD_FIXUP will result in corruption of the
device tree. To remedy this, only enable OF_BOARD_FIXUP if U-Boot is
configured for S-Mode.

Fixes: 1c17e55594a394ced7de88d91be294eaf8c564c1
Signed-off-by: Sean Anderson 
---

 arch/riscv/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 009a545fcf..13fac51483 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT
default 14
 
 config OF_BOARD_FIXUP
-   default y if OF_SEPARATE
+   default y if OF_SEPARATE && RISCV_SMODE
 
 endmenu
-- 
2.28.0



Re: [PATCH 2/2] doc: describe building with GCC

2020-09-05 Thread Tom Rini
On Sat, Sep 05, 2020 at 10:58:53AM +0200, Heinrich Schuchardt wrote:

> Provide a description of the U-Boot build process with GCC in the HTML
> documentation.
> 
> Signed-off-by: Heinrich Schuchardt 
> ---
>  doc/build/gcc.rst   | 119 
>  doc/build/index.rst |   1 +
>  2 files changed, 120 insertions(+)
>  create mode 100644 doc/build/gcc.rst

It's good to have this.  Can we restructure things so that it's clear
that the majority of this is toolchain independent and we can update the
clang doc, or if this becomes a more generic "build U-Boot for target"
doc, we just need to add a section about the Clang caveat about how gd
works and then it's just noting that instead of
CROSS_COMPILE=aarch64-linux-gnu- it's CROSS_COMPILE="clang -target
aarch64-linux-gnu" ?  Thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] ARM: dts: stm32: Pull UART4 RX high on AV96

2020-09-05 Thread Marek Vasut
On 8/22/20 10:45 PM, Marek Vasut wrote:
> There is no dedicated pull resistor on the AV96 UART4 (console UART)
> pin. In case there is no UART adapter installed on the AV96, the line
> is floating and can trigger reception of garbage characters, which in
> turn can abort U-Boot autoboot. Add default pull up to mitigate this
> problem.
> 
> Signed-off-by: Marek Vasut 
> Cc: Patrick Delaunay 
> Cc: Patrice Chotard 

Bump, also AV96 PLL4.


[PATCH] arm: mvebu: Espressobin: Set environment variable fdtfile

2020-09-05 Thread Andre Heider
Required for the generic distro mechanism.

Linux ships with 4 variants:
marvell/armada-3720-espressobin-v7-emmc.dtb
marvell/armada-3720-espressobin-v7.dtb
marvell/armada-3720-espressobin-emmc.dtb
marvell/armada-3720-espressobin.dtb

Use available information to determine the appropriate filename.

Tested on a v5 board without eMMC.

Signed-off-by: Andre Heider 
---
 arch/arm/mach-mvebu/Kconfig |  1 +
 board/Marvell/mvebu_armada-37xx/board.c | 42 +
 2 files changed, 43 insertions(+)

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 0d8e0922a2..31f5d26dc2 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -100,6 +100,7 @@ config TARGET_HELIOS4
 config TARGET_MVEBU_ARMADA_37XX
bool "Support Armada 37xx platforms"
select ARMADA_3700
+   select BOARD_LATE_INIT
imply SCSI
 
 config TARGET_DB_88F6720
diff --git a/board/Marvell/mvebu_armada-37xx/board.c 
b/board/Marvell/mvebu_armada-37xx/board.c
index 90bfc139aa..3bf0a08897 100644
--- a/board/Marvell/mvebu_armada-37xx/board.c
+++ b/board/Marvell/mvebu_armada-37xx/board.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -50,6 +51,22 @@ DECLARE_GLOBAL_DATA_PTR;
 #define MVEBU_G2_SMI_PHY_CMD_REG   (24)
 #define MVEBU_G2_SMI_PHY_DATA_REG  (25)
 
+/*
+ * Memory Controller Registers
+ *
+ * Assembled based on public information:
+ * 
https://gitlab.nic.cz/turris/mox-boot-builder/-/blob/master/wtmi/main.c#L332-336
+ * 
https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell/blob/mv_ddr-armada-18.12/drivers/mv_ddr_mc6.h#L309-L332
+ *
+ * And checked against the written register values for the various topologies:
+ * 
https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell/blob/mv_ddr-armada-atf-mainline/a3700/mv_ddr_tim.h
+ */
+#define A3700_CH0_MC_CTRL2_REG MVEBU_REGISTER(0x002c4)
+#define A3700_MC_CTRL2_SDRAM_TYPE_MASK 0xf
+#define A3700_MC_CTRL2_SDRAM_TYPE_OFFS 4
+#define A3700_MC_CTRL2_SDRAM_TYPE_DDR3 2
+#define A3700_MC_CTRL2_SDRAM_TYPE_DDR4 3
+
 int board_early_init_f(void)
 {
return 0;
@@ -63,6 +80,31 @@ int board_init(void)
return 0;
 }
 
+int board_late_init(void)
+{
+   bool ddr4, emmc;
+
+   if (!of_machine_is_compatible("globalscale,espressobin"))
+   return 0;
+
+   /* If the memory controller has been configured for DDR4, we're running 
on v7 */
+   ddr4 = ((readl(A3700_CH0_MC_CTRL2_REG) >> 
A3700_MC_CTRL2_SDRAM_TYPE_OFFS)
+   & A3700_MC_CTRL2_SDRAM_TYPE_MASK) == 
A3700_MC_CTRL2_SDRAM_TYPE_DDR4;
+
+   emmc = of_machine_is_compatible("globalscale,espressobin-emmc");
+
+   if (ddr4 && emmc)
+   env_set("fdtfile", 
"marvell/armada-3720-espressobin-v7-emmc.dtb");
+   else if (ddr4)
+   env_set("fdtfile", "marvell/armada-3720-espressobin-v7.dtb");
+   else if (emmc)
+   env_set("fdtfile", "marvell/armada-3720-espressobin-emmc.dtb");
+   else
+   env_set("fdtfile", "marvell/armada-3720-espressobin.dtb");
+
+   return 0;
+}
+
 /* Board specific AHCI / SATA enable code */
 int board_ahci_enable(void)
 {
-- 
2.28.0



Fwd: [PATCH 1/1] espresso7420: remove unused symbol CONFIG_DEFAULT_CONSOLE

2020-09-05 Thread Heinrich Schuchardt


Hello Thomas,

I tried to send an U-Boot patch to Thomas Abraham
. But the email address thomas...@samsung.com
does not exist anymore.

I assume that you are the same person.

What shall happen with board/samsung/espresso7420/MAINTAINERS?

Best regards

Heinrich

 Forwarded Message 
Subject: [PATCH 1/1] espresso7420: remove unused symbol
CONFIG_DEFAULT_CONSOLE
Date: Sat,  5 Sep 2020 12:02:10 +0200
From: Heinrich Schuchardt 
To: Thomas Abraham 
CC: u-boot@lists.denx.de, Heinrich Schuchardt 

Symbol CONFIG_DEFAULT_CONSOLE in include/configs/espresso7420.h is not used
for espresso7420_defconfig.

Signed-off-by: Heinrich Schuchardt 
---
 include/configs/espresso7420.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/configs/espresso7420.h b/include/configs/espresso7420.h
index 5aeb009f03..2495db93f8 100644
--- a/include/configs/espresso7420.h
+++ b/include/configs/espresso7420.h
@@ -18,9 +18,6 @@
 #define CONFIG_SPL_STACK   CONFIG_IRAM_END
 #define CONFIG_SYS_INIT_SP_ADDRCONFIG_IRAM_END

-/* select serial console configuration */
-#define CONFIG_DEFAULT_CONSOLE "console=ttySAC1,115200n8\0"
-
 /* DRAM Memory Banks */
 #define SDRAM_BANK_SIZE(256UL << 20UL) /* 256 MB */

--
2.28.0



[PATCH] doc/sipeed/maix: describe RESET and BOOT button

2020-09-05 Thread Heinrich Schuchardt
In the boot flow description add the RESET and BOOT button as well as the
function of the DTR and RTS lines of the serial interface.

Signed-off-by: Heinrich Schuchardt 
---
 doc/board/sipeed/maix.rst | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/doc/board/sipeed/maix.rst b/doc/board/sipeed/maix.rst
index 90ef70b7cf..a8efc90440 100644
--- a/doc/board/sipeed/maix.rst
+++ b/doc/board/sipeed/maix.rst
@@ -345,11 +345,15 @@ Technical Details
 Boot Sequence
 ^

-1. ``RESET`` pin is deasserted.
+1. ``RESET`` pin is deasserted. The pin is connected to the ``RESET`` button. 
It
+   can also be set to low via either the ``DTR`` or the ``RTS`` line of the
+   serial interface (depending on the board).
 2. Both harts begin executing at ``0x1000``.
 3. Both harts jump to firmware at ``0x8800``.
 4. One hart is chosen as a boot hart.
-5. Firmware reads value of pin ``IO_16`` (ISP).
+5. Firmware reads the value of pin ``IO_16`` (ISP). This pin is connected to 
the
+   ``BOOT`` button. The pin can equally be set to low via either the ``DTR`` or
+   ``RTS`` line of the serial interface (depending on the board).

* If the pin is low, enter ISP mode. This mode allows loading data to ram,
  writing it to flash, and booting from specific addresses.
--
2.28.0



Re: [PATCH 18/31] misc: am33xx: add control module driver

2020-09-05 Thread Dario Binacchi
Hi Lokesh,

> Il 03/09/2020 08:31 Lokesh Vutla  ha scritto:
> 
>  
> On 25/08/20 2:51 pm, Dario Binacchi wrote:
> > The implementation of this driver was needed to bind the device tree
> > sub-nodes of the 'clocks' node. In fact, the lack of the compatible
> > property in the 'clocks' node does not allow the generic 'syscon' or
> > 'simple-bus' drivers linked to the 'scm_conf@0' node to bind the
> > 'clocks' node and in turn its sub-nodes.
> > The 'scm@21' node is therefore the node closest to the 'clocks' node
> > whose driver can bind all the 'clocks' sub-nodes.
> > 
> > scm: scm@21 {
> > compatible = "ti,am3-scm", "simple-bus";
> > ...
> > 
> > scm_conf: scm_conf@0 {
> > compatible = "syscon", "simple-bus";
> > #address-cells = <1>;
> > #size-cells = <1>;
> > ranges = <0 0 0x800>;
> > 
> > scm_clocks: clocks {
> > #address-cells = <1>;
> > #size-cells = <0>;
> > };
> > };
> > };
> > 
> > Signed-off-by: Dario Binacchi 
> > ---
> > 
> >  doc/device-tree-bindings/arm/omap,ctrl.txt|  82 ++
> >  .../pinctrl/pinctrl-single.txt| 255 ++
> 
> This documentation does not belong to this patch.

The omap,ctrl.txt file references to the pinctrl-single.txt document.
I thought it was better to add it rather than remove that
reference from the omap,ctrl.txt file.

> 
> >  drivers/misc/Kconfig  |   7 +
> >  drivers/misc/Makefile |   1 +
> >  drivers/misc/ti-am3-scm.c |  90 +++
> >  5 files changed, 435 insertions(+)
> >  create mode 100644 doc/device-tree-bindings/arm/omap,ctrl.txt
> >  create mode 100644 doc/device-tree-bindings/pinctrl/pinctrl-single.txt
> >  create mode 100644 drivers/misc/ti-am3-scm.c
> > 
> > diff --git a/doc/device-tree-bindings/arm/omap,ctrl.txt 
> > b/doc/device-tree-bindings/arm/omap,ctrl.txt
> > new file mode 100644
> > index 00..8efd321cfa
> > --- /dev/null
> > +++ b/doc/device-tree-bindings/arm/omap,ctrl.txt
> > @@ -0,0 +1,82 @@
> > +OMAP Control Module bindings
> > +
> > +Control Module contains miscellaneous features under it based on SoC type.
> > +Pincontrol is one common feature, and it has a specialized support
> > +described in [1]. Typically some clock nodes are also under control module.
> > +Syscon is used to share register level access to drivers external to
> > +control module driver itself.
> > +
> > +See [2] for documentation about clock/clockdomain nodes.
> > +
> > +[1] doc/device-tree-bindings/pinctrl/pinctrl-single.txt
> > +[2] doc/device-tree-bindings/clock/ti,*.txt
> > +
> > +Required properties:
> > +- compatible:  Must be one of:
> > +   "ti,am3-scm"
> > +   "ti,am4-scm"
> > +   "ti,dm814-scrm"
> > +   "ti,dm816-scrm"
> > +   "ti,omap2-scm"
> > +   "ti,omap3-scm"
> > +   "ti,omap4-scm-core"
> > +   "ti,omap4-scm-padconf-core"
> > +   "ti,omap4-scm-wkup"
> > +   "ti,omap4-scm-padconf-wkup"
> > +   "ti,omap5-scm-core"
> > +   "ti,omap5-scm-padconf-core"
> > +   "ti,omap5-scm-wkup-pad-conf"
> > +   "ti,dra7-scm-core"
> > +- reg: Contains Control Module register address range
> > +   (base address and length)
> > +
> > +Optional properties:
> > +- clocks:  clocks for this module
> > +- clockdomains:clockdomains for this module
> > +
> > +Examples:
> > +
> > +scm: scm@2000 {
> > +   compatible = "ti,omap3-scm", "simple-bus";
> > +   reg = <0x2000 0x2000>;
> > +   #address-cells = <1>;
> > +   #size-cells = <1>;
> > +   ranges = <0 0x2000 0x2000>;
> > +
> > +   omap3_pmx_core: pinmux@30 {
> > +   compatible = "ti,omap3-padconf",
> > +"pinctrl-single";
> > +   reg = <0x30 0x230>;
> > +   #address-cells = <1>;
> > +   #size-cells = <0>;
> > +   #interrupt-cells = <1>;
> > +   interrupt-controller;
> > +   pinctrl-single,register-width = <16>;
> > +   pinctrl-single,function-mask = <0xff1f>;
> > +   };
> > +
> > +   scm_conf: scm_conf@270 {
> > +   compatible = "syscon";
> > +   reg = <0x270 0x330>;
> > +   #address-cells = <1>;
> > +   #size-cells = <1>;
> > +
> > +   scm_clocks: clocks {
> > +   #address-cells = <1>;
> > +   #size-cells = <0>;
> > +   };
> > +   };
> > +
> > +   scm_clockdomains: clockdomains {
> > +   };
> > +}
> > +
> > +_clocks {
> > +   mcbsp5_mux_fck: mcbsp5_mux_fck {
> > +   #clock-cells = <0>;
> > +   compatible = "ti,composite-mux-clock";
> > +   clocks = <_96m_fck>, <_clks>;
> > +   ti,bit-shift = <4>;
> > +   reg = <0x02d8>;
> > +   };
> > +};
> 
> [...snip...]
> 
> 
> > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > index 

[PATCH 1/1] doc: correct kflash settings for Maix One Dock

2020-09-05 Thread Heinrich Schuchardt
The correct kflash parameter value for the Maix One Dock is "dan".

See:
https://github.com/sipeed/platform-kendryte210/blob/master/boards/sipeed-maix-one-dock.json#L22

Fixes: 137dc153fda9 ("doc: riscv: Update documentation for Sipeed MAIX boards")
Signed-off-by: Heinrich Schuchardt 
---
 doc/board/sipeed/maix.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/board/sipeed/maix.rst b/doc/board/sipeed/maix.rst
index efcde9aebf..0b3a58070c 100644
--- a/doc/board/sipeed/maix.rst
+++ b/doc/board/sipeed/maix.rst
@@ -59,7 +59,7 @@ Sipeed MAIX BiT  sipeed_maix_bitm_defconfig bit   
 first
 Sipeed MAIX BiT with Mic sipeed_maix_bitm_defconfig bit_micfirst
 Sipeed MAIXDUINO sipeed_maix_bitm_defconfig maixduino  first
 Sipeed MAIX GO  goEsecond
-Sipeed MAIX ONE DOCKgoDfirst
+Sipeed MAIX ONE DOCKdanfirst
  == == ==

 Flashing causes a reboot of the device. Parameter -t specifies that the serial
--
2.28.0



[PATCH 1/1] espresso7420: remove unused symbol CONFIG_DEFAULT_CONSOLE

2020-09-05 Thread Heinrich Schuchardt
Symbol CONFIG_DEFAULT_CONSOLE in include/configs/espresso7420.h is not used
for espresso7420_defconfig.

Signed-off-by: Heinrich Schuchardt 
---
 include/configs/espresso7420.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/configs/espresso7420.h b/include/configs/espresso7420.h
index 5aeb009f03..2495db93f8 100644
--- a/include/configs/espresso7420.h
+++ b/include/configs/espresso7420.h
@@ -18,9 +18,6 @@
 #define CONFIG_SPL_STACK   CONFIG_IRAM_END
 #define CONFIG_SYS_INIT_SP_ADDRCONFIG_IRAM_END

-/* select serial console configuration */
-#define CONFIG_DEFAULT_CONSOLE "console=ttySAC1,115200n8\0"
-
 /* DRAM Memory Banks */
 #define SDRAM_BANK_SIZE(256UL << 20UL) /* 256 MB */

--
2.28.0



[PATCH] Makefile: mrproper shall delete doc/output/

2020-09-05 Thread Heinrich Schuchardt
HTML documentation is generated in doc/output/. This directory shall be
deleted by 'make mrproper'

Signed-off-by: Heinrich Schuchardt 
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 5dd4c6bd40..eb6c47ef00 100644
--- a/Makefile
+++ b/Makefile
@@ -2025,7 +2025,7 @@ CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h 
tools/version.h \

 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl \
- .tmp_objdiff
+ .tmp_objdiff doc/output
 MRPROPER_FILES += .config .config.old include/autoconf.mk* include/config.h \
  ctags etags tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
  drivers/video/fonts/*.S
--
2.28.0



[PATCH 0/2] doc: describe building with GCC

2020-09-05 Thread Heinrich Schuchardt
Provide a newcomer friendly documentation how to obtain the U-Boot source
and how to build U-Boot with GCC.

Heinrich Schuchardt (2):
  doc: describe source repository
  doc: describe building with GCC

 doc/build/gcc.rst| 119 +++
 doc/build/index.rst  |   2 +
 doc/build/source.rst |  30 +++
 3 files changed, 151 insertions(+)
 create mode 100644 doc/build/gcc.rst
 create mode 100644 doc/build/source.rst

--
2.28.0



[PATCH 1/2] doc: describe source repository

2020-09-05 Thread Heinrich Schuchardt
Add a chapter to the HTML documentation describing how to retrieve the
U-Boot sources.

Signed-off-by: Heinrich Schuchardt 
---
 doc/build/index.rst  |  1 +
 doc/build/source.rst | 30 ++
 2 files changed, 31 insertions(+)
 create mode 100644 doc/build/source.rst

diff --git a/doc/build/index.rst b/doc/build/index.rst
index e0072afb5e..5051a97e70 100644
--- a/doc/build/index.rst
+++ b/doc/build/index.rst
@@ -6,5 +6,6 @@ Build U-Boot
 .. toctree::
:maxdepth: 2

+   source
clang
tools
diff --git a/doc/build/source.rst b/doc/build/source.rst
new file mode 100644
index 00..4627c1f79e
--- /dev/null
+++ b/doc/build/source.rst
@@ -0,0 +1,30 @@
+Obtaining the source
+=
+
+The source of the U-Boot project is maintained in a Git repository.
+
+You can download the source via
+
+.. code-block:: bash
+
+git clone https://gitlab.denx.de/u-boot/u-boot.git
+
+A mirror of the source is maintained on Github
+
+.. code-block:: bash
+
+git clone https://github.com/u-boot/u-boot
+
+The released versions are available as tags which use the naming scheme::
+
+v.
+
+Release candidates are named::
+
+v.-rc
+
+To checkout the October 2020 release you would use:
+
+.. code-block:: bash
+
+git checkout v2020.10
--
2.28.0



[PATCH 2/2] doc: describe building with GCC

2020-09-05 Thread Heinrich Schuchardt
Provide a description of the U-Boot build process with GCC in the HTML
documentation.

Signed-off-by: Heinrich Schuchardt 
---
 doc/build/gcc.rst   | 119 
 doc/build/index.rst |   1 +
 2 files changed, 120 insertions(+)
 create mode 100644 doc/build/gcc.rst

diff --git a/doc/build/gcc.rst b/doc/build/gcc.rst
new file mode 100644
index 00..fcb0b1ffb3
--- /dev/null
+++ b/doc/build/gcc.rst
@@ -0,0 +1,119 @@
+Building with GCC
+=
+
+Dependencies
+
+
+For building U-Boot you need a GCC compiler for your host platform. If you
+are not building on the target platform you further need  a GCC cross compiler.
+
+Debian based
+
+
+On Debian based systems the cross compiler packages are named
+gcc--linux-gnu.
+
+You could install GCC and the GCC cross compiler for the ARMv8 architecture 
with
+
+.. code-block:: bash
+
+sudo apt-get gcc gcc-aarch64-linux-gnu
+
+Depending on the build targets further packages maybe needed
+
+.. code-block:: bash
+
+sudo apt-get install bc bison build-essential coccinelle \
+  device-tree-compiler dfu-util efitools flex gdisk liblz4-tool \
+  libguestfs-tools libncurses-dev libpython3-dev libsdl2-dev libssl-dev \
+  lzma-alone openssl python3 python3-coverage python3-pyelftools \
+  python3-pytest python3-sphinxcontrib.apidoc python3-sphinx-rtd-theme swig
+
+Prerequisites
+-
+
+For some boards you have to build prerequisite files before you can build
+U-Boot, e.g. for the some boards you will need to build the ARM Trusted 
Firmware
+beforehand. Please, refer to the board specific documentation
+:doc:`../board/index`.
+
+Configuration
+-
+
+Directory configs/ contains the template configuration files for the maintained
+boards following the naming scheme::
+
+_defconfig
+
+These files have been stripped of default settings. So you cannot use them
+directly. Instead their name serves as a make target to generate the actual
+configuration file .config. For instance the configuration template for the
+Odroid C2 board is called odroid-c2_defconfig. The corresponding .config file
+is generated by
+
+.. code-block:: bash
+
+make odroid-c2_defconfig
+
+You can adjust the configuration using
+
+.. code-block:: bash
+
+make menuconfig
+
+Building
+
+
+When cross compiling you will have to specify the prefix of the cross-compiler.
+You can either specify the value of the CROSS_COMPILE variable on the make
+command line or export it beforehand.
+
+.. code-block:: bash
+
+CROSS_COMPILE= make
+
+Assuming cross compiling on Debian for ARMv8 this would be
+
+.. code-block:: bash
+
+CROSS_COMPILE=aarch64-linux-gnu- make
+
+Build parameters
+
+
+A list of available parameters for the make command can be obtained via
+
+.. code-block:: bash
+
+make help
+
+You can speed up compilation by parallelization using the -j parameter, e.g.
+
+.. code-block:: bash
+
+CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc)
+
+Further important build parameters are
+
+* O= - generate all output files in directory , including .config
+* V=1 - verbose build
+
+Other build targets
+~~~
+
+A list of all make targets can be obtained via
+
+.. code-block:: bash
+
+make help
+
+Important ones are
+
+* clean - remove most generated files but keep the configuration
+* mrproper - remove all generated files + config + various backup files
+
+Installation
+
+
+The process for installing U-Boot on the target device is device specific.
+Please, refer to the board specific documentation :doc:`../board/index`.
diff --git a/doc/build/index.rst b/doc/build/index.rst
index 5051a97e70..5f90f95aca 100644
--- a/doc/build/index.rst
+++ b/doc/build/index.rst
@@ -7,5 +7,6 @@ Build U-Boot
:maxdepth: 2

source
+   gcc
clang
tools
--
2.28.0