Re: [PATCH 0/5] Apple M1 Support
> From: Simon Glass > Date: Fri, 24 Sep 2021 19:20:32 -0600 > > Hi Mark, > > On Sat, 18 Sept 2021 at 07:54, Mark Kettenis wrote: > > > > This series adds basic support for Apple's M1 SoC to U-Boot. > > This builds a basic U-Boot that can be used as a payload > > for the m1n1 boot loader being developed by the Asahi Linux > > project. > > > > The goal here is to privide an UEFI interface on these machines that > > provide > > > allows booting various open source OSes. This initial series provides > > support for the serial port, framebuffer and the USB 3.1 Type-C ports. > > It can boot a support OS (e.g. OpenBSD/arm64) from a USB disk. > > > > Mark Kettenis (5): > > arm: apple: Add initial support for Apple's M1 SoC > > serial: s5p: Add Apple M1 support > > misc: Add Apple DART driver > > arm: dts: apple: Add preliminary device trees > > doc: board: apple: Add Apple M1 documentation > > > > arch/arm/Kconfig | 22 + > > arch/arm/Makefile | 1 + > > arch/arm/dts/t8103-j274.dts | 135 + > > arch/arm/dts/t8103-j293.dts | 97 > > arch/arm/dts/t8103.dtsi | 506 ++ > > arch/arm/include/asm/arch-m1/clk.h| 11 + > > arch/arm/include/asm/arch-m1/uart.h | 41 ++ > > arch/arm/mach-apple/Kconfig | 18 + > > arch/arm/mach-apple/Makefile | 4 + > > arch/arm/mach-apple/board.c | 163 ++ > > arch/arm/mach-apple/lowlevel_init.S | 16 + > > configs/apple_m1_defconfig| 14 + > > doc/board/apple/index.rst | 9 + > > doc/board/apple/m1.rst| 54 ++ > > doc/board/index.rst | 1 + > > drivers/misc/Kconfig | 7 + > > drivers/misc/Makefile | 1 + > > drivers/misc/apple_dart.c | 171 ++ > > drivers/serial/Kconfig| 2 +- > > drivers/serial/serial_s5p.c | 22 + > > include/configs/apple.h | 38 ++ > > .../interrupt-controller/apple-aic.h | 15 + > > include/dt-bindings/pinctrl/apple.h | 13 + > > include/dt-bindings/spmi/spmi.h | 10 + > > 24 files changed, 1370 insertions(+), 1 deletion(-) > > create mode 100644 arch/arm/dts/t8103-j274.dts > > create mode 100644 arch/arm/dts/t8103-j293.dts > > create mode 100644 arch/arm/dts/t8103.dtsi > > create mode 100644 arch/arm/include/asm/arch-m1/clk.h > > create mode 100644 arch/arm/include/asm/arch-m1/uart.h > > create mode 100644 arch/arm/mach-apple/Kconfig > > create mode 100644 arch/arm/mach-apple/Makefile > > create mode 100644 arch/arm/mach-apple/board.c > > create mode 100644 arch/arm/mach-apple/lowlevel_init.S > > create mode 100644 configs/apple_m1_defconfig > > create mode 100644 doc/board/apple/index.rst > > create mode 100644 doc/board/apple/m1.rst > > create mode 100644 drivers/misc/apple_dart.c > > create mode 100644 include/configs/apple.h > > create mode 100644 include/dt-bindings/interrupt-controller/apple-aic.h > > create mode 100644 include/dt-bindings/pinctrl/apple.h > > create mode 100644 include/dt-bindings/spmi/spmi.h > > > > -- > > 2.33.0 > > > > I gave this a whirl on a Macbook Air A2337 and needed the patch below > to build the devicetree files. Sorry the formatting is broken. > > Also when booting I get this: > > ... > Preparing to boot kernel at 0x80820 with fdt at 0x8082e8000 > Valid payload found > Preparing to run next stage at 0x80820... > MMU: shutting down... > MMU: shutdown successful, clearing caches > > > Then the display clears and it hangs. If I try the J274 devicetree it > just reboots at that point. > > What should I expect? I was hoping for console output as I don't have > serial connected. I don't have a suitable serial cable, and the USB > gadget mode did not result in a ttyACM0 device appearing. For framebuffer support you also need the "30bpp framebuffer support" series I posted earlier: https://patchwork.ozlabs.org/project/uboot/list/?series=262617 With that your should get the usual U-Boot output on the screen. I've not tested the Air, but it should work there. I'll probably post a v2 of that series this weekend as I fixed the EFI GOP support with the help of Heinrich. But that shouldn't matter for U-Boot itself. Regarding the device tree, I was afraid that setting CONFIG_DEFAULT_DEVICE_TREE would make the distroboot commands try to load a device tree from disk before loading the EFI bootloader, but it looks I was mistaken there. It still is a little bit pointless to build the device tree and a u-boot.bin that includes it, but if that makes you happier, I'll add it to the series. Cheers, Mark > Subject: [PATCH] Fix up devicetree > > Get these building. > > Signed-off-by: Simon Gla
[PATCH] board: rpi: always set fdt_addr if provided by firmware
From: Ricardo Salveti Otherwise if the env gets saved with an incorrect or different fdt_addr (by moving sdcard between different rpi versions), it won't be able to boot with the correct address. This allows fdt_addr to always be in sync with what gets set by the firmware. Signed-off-by: Ricardo Salveti Signed-off-by: Oleksandr Suvorov --- board/raspberrypi/rpi/rpi.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index 372b26b6f2..e12f8c0c31 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -318,9 +318,6 @@ static void set_fdtfile(void) */ static void set_fdt_addr(void) { - if (env_get("fdt_addr")) - return; - if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) return; -- 2.31.1
[RFC PATCH] RFC: Replace CONFIG_SYS_BAUDRATE_TABLE by board and UART driver rounding functions
Add new functions which returns the nearest baudrate and use them instead of hardcoded and incomplete CONFIG_SYS_BAUDRATE_TABLE compile time option. Add implementation of rounding function for serial_mvebu_a3700 driver and also for A3720 Espressobin board which has integrated pl2303 USB<->UART converter, which basically limits baudrates which can user set. Completely remove CONFIG_SYS_BAUDRATE_TABLE defines from all A3720 boards as now with rounding functions it is not used anymore. NOTE: This is just an example how to kill CONFIG_SYS_BAUDRATE_TABLE compile time definitions. I tested it that it works on A3720 Turris Mox board. I have not tested A3720 Espressobin board yet. More discussion on this approach is required, so take this just as RFC change. Signed-off-by: Pali Rohár --- board/Marvell/mvebu_armada-37xx/board.c | 28 ++ drivers/serial/serial-uclass.c | 71 + drivers/serial/serial_mvebu_a3700.c | 39 ++ include/configs/mvebu_armada-37xx.h | 8 --- include/configs/turris_mox.h| 8 --- include/serial.h| 24 + 6 files changed, 152 insertions(+), 26 deletions(-) diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c index fdc873b1952f..0cd9ea6a1515 100644 --- a/board/Marvell/mvebu_armada-37xx/board.c +++ b/board/Marvell/mvebu_armada-37xx/board.c @@ -435,3 +435,31 @@ int ft_board_setup(void *blob, struct bd_info *bd) return 0; } #endif + +int board_round_baudrate(int baudrate) +{ + /* +* Espressobin has on-board pl2303 connected to A3720 UART. +* So calculate the final real baudrate supported by pl2303. +* Code from linux kernel function pl2303_encode_baud_rate_divisor() +* Exact formula is: baudrate = 12M * 32 / (mantissa * 4^exponent) +*/ + unsigned int baseline, mantissa, exponent; + + baseline = 1200 * 32; + mantissa = baseline / baudrate; + if (mantissa == 0) + mantissa = 1; + exponent = 0; + while (mantissa >= 512) { + if (exponent < 7) { + mantissa >>= 2; + exponent++; + } else { + mantissa = 511; + break; + } + } + + return (baseline / mantissa) >> (exponent << 1); +} diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 8171b17faf88..0d725ed764e6 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -299,6 +299,20 @@ int serial_tstc(void) return _serial_tstc(gd->cur_serial_dev); } +int serial_round_baudrate(int baudrate) +{ + struct dm_serial_ops *ops; + + if (!gd->cur_serial_dev) + return 0; + + ops = serial_get_ops(gd->cur_serial_dev); + if (!ops->round_baudrate) + return 0; + + return ops->round_baudrate(gd->cur_serial_dev, baudrate); +} + void serial_setbrg(void) { struct dm_serial_ops *ops; @@ -378,6 +392,11 @@ static int serial_stub_tstc(struct stdio_dev *sdev) } #endif +int __weak board_round_baudrate(int baudrate) +{ + return 0; +} + /** * on_baudrate() - Update the actual baudrate when the env var changes * @@ -388,6 +407,8 @@ static int on_baudrate(const char *name, const char *value, enum env_op op, { int i; int baudrate; + int real_baudrate; + int board_baudrate; switch (op) { case env_op_create: @@ -397,20 +418,50 @@ static int on_baudrate(const char *name, const char *value, enum env_op op, */ baudrate = dectoul(value, NULL); - /* Not actually changing */ - if (gd->baudrate == baudrate) - return 0; + real_baudrate = serial_round_baudrate(baudrate); - for (i = 0; i < ARRAY_SIZE(baudrate_table); ++i) { - if (baudrate == baudrate_table[i]) - break; - } - if (i == ARRAY_SIZE(baudrate_table)) { - if ((flags & H_FORCE) == 0) + if (real_baudrate) { + /* Baudrate is supported if is within 3% tolerance */ + if (100 * real_baudrate < baudrate * (100 - 3) || + 100 * real_baudrate > baudrate * (100 + 3)) { printf("## Baudrate %d bps not supported\n", baudrate); - return 1; + return 1; + } + baudrate = real_baudrate; + } else { + /* +* If round_baudrate() callback is unsupported then +* check supported baudrate against baudrate_table[] +
Re: [PATCH 5/5] serial: Rework CONFIG_SYS_BAUDRATE_TABLE
On Friday 24 September 2021 18:07:36 Tom Rini wrote: > On Fri, Sep 24, 2021 at 09:08:15PM +0200, Pali Rohár wrote: > > Hello! > > > > On Monday 13 September 2021 18:11:38 Tom Rini wrote: > > > On Mon, Sep 13, 2021 at 05:03:13PM -0500, Alex G. wrote: > > > > > > > > > > > > On 9/13/21 4:24 PM, Tom Rini wrote: > > > > > In order to move CONFIG_SYS_BAUDRATE_TABLE to Kconfig, we need to > > > > > rework > > > > > the logic a bit. Rename the users of CONFIG_SYS_BAUDRATE_TABLE to > > > > > SYS_BAUDRATE_TABLE. Introduce a series of CONFIG_BAUDRATE_TABLE_... > > > > > that include some number of baud rates. These match all existing > > > > > users. > > > > > The help for each entry specifies what the exact table is, for a given > > > > > option. Define what SYS_BAUDRATE_TABLE will be in include/serial.h > > > > > now. > > > > > > > > > > Signed-off-by: Tom Rini > > > > > --- > > > > > > > > > diff --git a/include/serial.h b/include/serial.h > > > > > index 6d1e62c6770c..150644c4c3d4 100644 > > > > > --- a/include/serial.h > > > > > +++ b/include/serial.h > > > > > @@ -3,6 +3,42 @@ > > > > > #include > > > > > +#if defined(CONFIG_BAUDRATE_TABLE_300_TO_38400_115200) > > > > > +#define SYS_BAUDRATE_TABLE { 300, 600, 1200, 2400, 4800, 9600, > > > > > 19200, \ > > > > > + 38400, 115200 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_300_TO_115200) > > > > > +#define SYS_BAUDRATE_TABLE { 300, 600, 1200, 2400, 4800, 9600, > > > > > 19200, \ > > > > > + 38400, 57600, 115200 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_300_TO_230400) > > > > > +#define SYS_BAUDRATE_TABLE { 300, 600, 1200, 2400, 4800, 9600, > > > > > 19200, \ > > > > > + 38400, 57600, 115200, 230400 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_300_TO_600) > > > > > +#define SYS_BAUDRATE_TABLE { 300, 600, 1200, 1800, 2400, 4800, > > > > > 9600, \ > > > > > + 19200, 38400, 57600, 115200, 230400, \ > > > > > + 460800, 50, 576000, 921600, > > > > > 100, \ > > > > > + 1152000, 150, 200, 250, \ > > > > > + 300, 350, 400, 450, \ > > > > > + 500, 550, 600 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_4800_TO_115200) > > > > > +#define SYS_BAUDRATE_TABLE { 4800, 9600, 19200, 38400, 57600, > > > > > 115200 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_9600_TO_115200) > > > > > +#define SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_9600_TO_230400) > > > > > +#define SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200, > > > > > 230400 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_9600_TO_460800) > > > > > +#define SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200, > > > > > 230400, 460800 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_9600_TO_921600) > > > > > +#define SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200, > > > > > 230400, \ > > > > > + 460800, 921600 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_9600_TO_230400_50_150) > > > > > +#define SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200, > > > > > 230400, \ > > > > > + 50, 150 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_38400_115200_ONLY) > > > > > +#define SYS_BAUDRATE_TABLE { 38400, 115200 } > > > > > +#elif defined(CONFIG_BAUDRATE_TABLE_115200_ONLY) > > > > > +#define SYS_BAUDRATE_TABLE { 115200 } > > > > > +#endif > > > > > + > > > > > struct serial_device { > > > > > /* enough bytes to match alignment of following func pointer */ > > > > > charname[16]; > > > > > > > > > > > > This opens the gates to #ifdefing the heck out of serial.h. What > > > > happens to > > > > my board that goes from 300 to 200? > > > > * We need a new Kconfig and new ifdef > > > > What happens to my other board that goes from 300 to 250? > > > > * We need a new Kconfig and new ifdef > > > > The pattern doesn't look promising. > > > > > > This reminds me I was tempted to do a cover letter, but didn't. What > > > happens is I tell you no. Most boards are using the standard table of > > > common rates from 9600 to 115200. A nice follow-up would be to change > > > every board with a special case that's not above 115200 to just use the > > > normal table. Everyone else? There's the maximal table. That's it. > > > That's even come in fairly recently, for mvebu platforms. > > > > I think that above #ifdef hell is the worst what could be done. It does > > not solve existing problems and just introduce new way which opens doors > > for problems for new boards... > > I don't think this will open new problems, since I do intend to fire off > the "easy" reduction option of switching to
[PATCH v4 00/15] image: A partial series for the image clean-up
Now that the competing image clean-up has landed and the smoke has cleared, we can come back to this one. This series includes about a third of the original patches, mostly the ones that apply cleanly. It does not reduce the #idefs by as much, but it does make some small code improvements. Further patches can be pulled in once these ones have been reviewed and land. Build here: https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/9251 Changes in v4: - Rebase to master Changes in v3: - Pick up only the first part of the original v2 series Changes in v2: - Add a patch to introduce a memdup() function - Add new abuf_init_set() function - Update abuf_realloc() to return after every case - Use const for abuf_data() and abuf_size() - Make use of memdup() - Add abuf_init_move() - Add comments about the assumptions made by lib_test_abuf_realloc() - Add better comments about why some tests are skipped at present - Correct 'hose' typo Simon Glass (15): lib: Add memdup() Add support for an owned buffer compiler: Add a comment to host_build() zstd: Create a function for use from U-Boot btrfs: Use U-Boot API for decompression image: Avoid switch default in image_decomp() image: Update zstd to avoid reporting error twice gzip: Avoid use of u64 image: Update image_decomp() to avoid ifdefs image: Split board code out into its own file image: Fix up checkpatch warnings in image-board.c image: Split host code out into its own file image: Create a function to do manual relocation image: Avoid #ifdefs for manual relocation image: Remove ifdefs around image_setup_linux() el at common/Makefile |2 +- common/bootm.c| 16 +- common/image-board.c | 939 + common/image-host.c | 27 + common/image-sig.c| 40 +- common/image.c| 1177 +++-- configs/sandbox_defconfig |1 + fs/btrfs/compression.c| 51 +- include/abuf.h| 159 + include/compiler.h|8 + include/gzip.h|8 +- include/linux/string.h| 13 + include/linux/zstd.h | 11 + include/relocate.h| 30 +- lib/Makefile |1 + lib/abuf.c| 109 lib/gunzip.c | 28 +- lib/string.c | 13 + lib/zstd/Makefile |2 +- lib/zstd/zstd.c | 64 ++ test/lib/Makefile |1 + test/lib/abuf.c | 344 +++ test/lib/string.c | 32 + tools/Makefile|1 + 24 files changed, 1887 insertions(+), 1190 deletions(-) create mode 100644 common/image-board.c create mode 100644 common/image-host.c create mode 100644 include/abuf.h create mode 100644 lib/abuf.c create mode 100644 lib/zstd/zstd.c create mode 100644 test/lib/abuf.c -- 2.33.0.685.g46640cef36-goog
[PATCH v4 03/15] compiler: Add a comment to host_build()
This function should have a comment explaining what it does. Add one. Signed-off-by: Simon Glass --- (no changes since v2) Changes in v2: - Correct 'hose' typo include/compiler.h | 5 + 1 file changed, 5 insertions(+) diff --git a/include/compiler.h b/include/compiler.h index 27b9843497a..67e52050b12 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -151,6 +151,11 @@ typedef unsigned long int uintptr_t; #define MEM_SUPPORT_64BIT_DATA 0 #endif +/** + * host_build() - check if we are building for the host + * + * @return true if building for the host, false if for a target + */ static inline bool host_build(void) { #ifdef USE_HOSTCC return true; -- 2.33.0.685.g46640cef36-goog
[PATCH v4 05/15] btrfs: Use U-Boot API for decompression
Use the common function to avoid code duplication. Acked-by: Qu Wenruo Signed-off-by: Simon Glass --- (no changes since v1) fs/btrfs/compression.c | 51 +- 1 file changed, 5 insertions(+), 46 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 23efefa1997..7adfbb04a7c 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -6,6 +6,7 @@ */ #include "btrfs.h" +#include #include #include #include @@ -136,54 +137,12 @@ static u32 decompress_zlib(const u8 *_cbuf, u32 clen, u8 *dbuf, u32 dlen) static u32 decompress_zstd(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen) { - ZSTD_DStream *dstream; - ZSTD_inBuffer in_buf; - ZSTD_outBuffer out_buf; - void *workspace; - size_t wsize; - u32 res = -1; - - wsize = ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT); - workspace = malloc(wsize); - if (!workspace) { - debug("%s: cannot allocate workspace of size %zu\n", __func__, - wsize); - return -1; - } - - dstream = ZSTD_initDStream(ZSTD_BTRFS_MAX_INPUT, workspace, wsize); - if (!dstream) { - printf("%s: ZSTD_initDStream failed\n", __func__); - goto err_free; - } + struct abuf in, out; - in_buf.src = cbuf; - in_buf.pos = 0; - in_buf.size = clen; + abuf_init_set(&in, (u8 *)cbuf, clen); + abuf_init_set(&out, dbuf, dlen); - out_buf.dst = dbuf; - out_buf.pos = 0; - out_buf.size = dlen; - - while (1) { - size_t ret; - - ret = ZSTD_decompressStream(dstream, &out_buf, &in_buf); - if (ZSTD_isError(ret)) { - printf("%s: ZSTD_decompressStream error %d\n", __func__, - ZSTD_getErrorCode(ret)); - goto err_free; - } - - if (in_buf.pos >= clen || !ret) - break; - } - - res = out_buf.pos; - -err_free: - free(workspace); - return res; + return zstd_decompress(&in, &out); } u32 btrfs_decompress(u8 type, const char *c, u32 clen, char *d, u32 dlen) -- 2.33.0.685.g46640cef36-goog
[PATCH v4 01/15] lib: Add memdup()
Add a function to duplicate a memory region, a little like strdup(). Signed-off-by: Simon Glass --- (no changes since v2) Changes in v2: - Add a patch to introduce a memdup() function include/linux/string.h | 13 + lib/string.c | 13 + test/lib/string.c | 32 3 files changed, 58 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index dd255f21633..3169c93796e 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -129,6 +129,19 @@ extern void * memchr(const void *,int,__kernel_size_t); void *memchr_inv(const void *, int, size_t); #endif +/** + * memdup() - allocate a buffer and copy in the contents + * + * Note that this returns a valid pointer even if @len is 0 + * + * @src: data to copy in + * @len: number of bytes to copy + * @return allocated buffer with the copied contents, or NULL if not enough + * memory is available + * + */ +char *memdup(const void *src, size_t len); + unsigned long ustrtoul(const char *cp, char **endp, unsigned int base); unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base); diff --git a/lib/string.c b/lib/string.c index ba176fb08f7..78bd65c4136 100644 --- a/lib/string.c +++ b/lib/string.c @@ -659,6 +659,19 @@ void * memscan(void * addr, int c, size_t size) } #endif +char *memdup(const void *src, size_t len) +{ + char *p; + + p = malloc(len); + if (!p) + return NULL; + + memcpy(p, src, len); + + return p; +} + #ifndef __HAVE_ARCH_STRSTR /** * strstr - Find the first substring in a %NUL terminated string diff --git a/test/lib/string.c b/test/lib/string.c index 64234bef36c..5dcf4d6db00 100644 --- a/test/lib/string.c +++ b/test/lib/string.c @@ -23,6 +23,8 @@ /* Allow for copying up to 32 bytes */ #define BUFLEN (SWEEP + 33) +#define TEST_STR "hello" + /** * init_buffer() - initialize buffer * @@ -193,3 +195,33 @@ static int lib_memmove(struct unit_test_state *uts) } LIB_TEST(lib_memmove, 0); + +/** lib_memdup() - unit test for memdup() */ +static int lib_memdup(struct unit_test_state *uts) +{ + char buf[BUFLEN]; + size_t len; + char *p, *q; + + /* Zero size should do nothing */ + p = memdup(NULL, 0); + ut_assertnonnull(p); + free(p); + + p = memdup(buf, 0); + ut_assertnonnull(p); + free(p); + + strcpy(buf, TEST_STR); + len = sizeof(TEST_STR); + p = memdup(buf, len); + ut_asserteq_mem(p, buf, len); + + q = memdup(p, len); + ut_asserteq_mem(q, buf, len); + free(q); + free(p); + + return 0; +} +LIB_TEST(lib_memdup, 0); -- 2.33.0.685.g46640cef36-goog
[PATCH v4 04/15] zstd: Create a function for use from U-Boot
The existing zstd API requires the same sequence of calls to perform its task. Create a helper for U-Boot, to avoid code duplication, as is done with other compression algorithms. Make use of of this from the image code. Note that the zstd code lacks a test in test/compression.c and this should be added by the maintainer. Signed-off-by: Simon Glass --- (no changes since v1) common/image.c | 50 +++--- include/linux/zstd.h | 11 lib/zstd/Makefile| 2 +- lib/zstd/zstd.c | 64 4 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 lib/zstd/zstd.c diff --git a/common/image.c b/common/image.c index e199d61a4c3..e58793bd69f 100644 --- a/common/image.c +++ b/common/image.c @@ -22,6 +22,7 @@ #include #endif +#include #include #include @@ -527,50 +528,17 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, #ifndef USE_HOSTCC #if CONFIG_IS_ENABLED(ZSTD) case IH_COMP_ZSTD: { - size_t size = unc_len; - ZSTD_DStream *dstream; - ZSTD_inBuffer in_buf; - ZSTD_outBuffer out_buf; - void *workspace; - size_t wsize; - - wsize = ZSTD_DStreamWorkspaceBound(image_len); - workspace = malloc(wsize); - if (!workspace) { - debug("%s: cannot allocate workspace of size %zu\n", __func__, - wsize); - return -1; - } - - dstream = ZSTD_initDStream(image_len, workspace, wsize); - if (!dstream) { - printf("%s: ZSTD_initDStream failed\n", __func__); - return ZSTD_getErrorCode(ret); - } - - in_buf.src = image_buf; - in_buf.pos = 0; - in_buf.size = image_len; + struct abuf in, out; - out_buf.dst = load_buf; - out_buf.pos = 0; - out_buf.size = size; - - while (1) { - size_t ret; - - ret = ZSTD_decompressStream(dstream, &out_buf, &in_buf); - if (ZSTD_isError(ret)) { - printf("%s: ZSTD_decompressStream error %d\n", __func__, - ZSTD_getErrorCode(ret)); - return ZSTD_getErrorCode(ret); - } - - if (in_buf.pos >= image_len || !ret) - break; + abuf_init_set(&in, image_buf, image_len); + abuf_init_set(&in, load_buf, unc_len); + ret = zstd_decompress(&in, &out); + if (ret < 0) { + printf("ZSTD decompression failed\n"); + return ret; } - image_len = out_buf.pos; + image_len = ret; break; } diff --git a/include/linux/zstd.h b/include/linux/zstd.h index 724f69350e0..35ba4c90aa4 100644 --- a/include/linux/zstd.h +++ b/include/linux/zstd.h @@ -1144,4 +1144,15 @@ size_t ZSTD_decompressBlock(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, size_t ZSTD_insertBlock(ZSTD_DCtx *dctx, const void *blockStart, size_t blockSize); +struct abuf; + +/** + * zstd_decompress() - Decompress Zstandard data + * + * @in: Input buffer to decompress + * @out: Output buffer to hold the results (must be large enough) + * @return size of the decompressed data, or -ve on error + */ +int zstd_decompress(struct abuf *in, struct abuf *out); + #endif /* ZSTD_H */ diff --git a/lib/zstd/Makefile b/lib/zstd/Makefile index 33c1df48ec8..12170892923 100644 --- a/lib/zstd/Makefile +++ b/lib/zstd/Makefile @@ -1,4 +1,4 @@ obj-y += zstd_decompress.o zstd_decompress-y := huf_decompress.o decompress.o \ -entropy_common.o fse_decompress.o zstd_common.o +entropy_common.o fse_decompress.o zstd_common.o zstd.o diff --git a/lib/zstd/zstd.c b/lib/zstd/zstd.c new file mode 100644 index 000..bf9cd19cfa3 --- /dev/null +++ b/lib/zstd/zstd.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2021 Google LLC + */ + +#define LOG_CATEGORY LOGC_BOOT + +#include +#include +#include +#include +#include + +int zstd_decompress(struct abuf *in, struct abuf *out) +{ + ZSTD_DStream *dstream; + ZSTD_inBuffer in_buf; + ZSTD_outBuffer out_buf; + void *workspace; + size_t wsize; + int ret; + + wsize = ZSTD_DStreamWorkspaceBound(abuf_size(in)); + workspace = malloc(wsize); + if (!workspace) { + debug("%s: cannot allocate workspace of size %zu\n", __func__, + wsize); + return -ENOMEM; + } + + dstream = ZSTD_initDStream(abuf_size(in), workspace, wsize); +
[PATCH v4 06/15] image: Avoid switch default in image_decomp()
At present this function is full of preprocessor macros. Adjust it to check for an unsupported algorithm after the switch(). This will allow us to drop the macros. Fix up the return-value path and an extra blank line while we are here. Signed-off-by: Simon Glass --- (no changes since v1) common/image.c | 14 -- 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/common/image.c b/common/image.c index e58793bd69f..d80781f2eb4 100644 --- a/common/image.c +++ b/common/image.c @@ -446,7 +446,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, void *load_buf, void *image_buf, ulong image_len, uint unc_len, ulong *load_end) { - int ret = 0; + int ret = -ENOSYS; *load_end = load; print_decomp_msg(comp, type, load == image_start); @@ -458,6 +458,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, */ switch (comp) { case IH_COMP_NONE: + ret = 0; if (load == image_start) break; if (image_len <= unc_len) @@ -539,22 +540,23 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, } image_len = ret; - break; } #endif /* CONFIG_ZSTD */ #endif - default: + } + if (ret == -ENOSYS) { printf("Unimplemented compression type %d\n", comp); - return -ENOSYS; + return ret; } + if (ret) + return ret; *load_end = load + image_len; - return ret; + return 0; } - #ifndef USE_HOSTCC #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) /** -- 2.33.0.685.g46640cef36-goog
[PATCH v4 02/15] Add support for an owned buffer
When passing a data buffer back from a function, it is not always clear who owns the buffer, i.e. who is responsible for freeing the memory used. An example of this is where multiple files are decompressed from the firmware image, using a temporary buffer for reading (since the compressed data has to live somewhere) and producing a temporary or permanent buffer with the resuilts. Where the firmware image can be memory-mapped, as on x86, the compressed data does not need to be buffered, but the complexity of having a buffer which is either allocated or not, makes the code hard to understand. Introduce a new 'abuf' which supports simple buffer operations: - encapsulating a buffer and its size - either allocated with malloc() or not - able to be reliably freed if necessary - able to be converted to an allocated buffer if needed This simple API makes it easier to deal with allocated and memory-mapped buffers. Signed-off-by: Simon Glass --- (no changes since v2) Changes in v2: - Add new abuf_init_set() function - Update abuf_realloc() to return after every case - Use const for abuf_data() and abuf_size() - Make use of memdup() - Add abuf_init_move() - Add comments about the assumptions made by lib_test_abuf_realloc() - Add better comments about why some tests are skipped at present include/abuf.h| 159 + lib/Makefile | 1 + lib/abuf.c| 109 +++ test/lib/Makefile | 1 + test/lib/abuf.c | 344 ++ 5 files changed, 614 insertions(+) create mode 100644 include/abuf.h create mode 100644 lib/abuf.c create mode 100644 test/lib/abuf.c diff --git a/include/abuf.h b/include/abuf.h new file mode 100644 index 000..d230f72806d --- /dev/null +++ b/include/abuf.h @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Handles a buffer that can be allocated and freed + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#ifndef __ABUF_H +#define __ABUF_H + +#include + +/** + * struct abuf - buffer that can be allocated and freed + * + * This is useful for a block of data which may be allocated with malloc(), or + * not, so that it needs to be freed correctly when finished with. + * + * For now it has a very simple purpose. + * + * Using memset() to zero all fields is guaranteed to be equivalent to + * abuf_init(). + * + * @data: Pointer to data + * @size: Size of data in bytes + * @alloced: true if allocated with malloc(), so must be freed after use + */ +struct abuf { + void *data; + size_t size; + bool alloced; +}; + +static inline void *abuf_data(const struct abuf *abuf) +{ + return abuf->data; +} + +static inline size_t abuf_size(const struct abuf *abuf) +{ + return abuf->size; +} + +/** + * abuf_set() - set the (unallocated) data in a buffer + * + * This simply makes the abuf point to the supplied data, which must be live + * for the lifetime of the abuf. It is not alloced. + * + * Any existing data in the abuf is freed and the alloced member is set to + * false. + * + * @abuf: abuf to adjust + * @data: New contents of abuf + * @size: New size of abuf + */ +void abuf_set(struct abuf *abuf, void *data, size_t size); + +/** + * abuf_map_sysmem() - calls map_sysmem() to set up an abuf + * + * This is equivalent to abuf_set(abuf, map_sysmem(addr, size), size) + * + * Any existing data in the abuf is freed and the alloced member is set to + * false. + * + * @abuf: abuf to adjust + * @addr: Address to set the abuf to + * @size: New size of abuf + */ +void abuf_map_sysmem(struct abuf *abuf, ulong addr, size_t size); + +/** + * abuf_realloc() - Change the size of a buffer + * + * This uses realloc() to change the size of the buffer, with the same semantics + * as that function. If the abuf is not currently alloced, then it will alloc + * it if the size needs to increase (i.e. set the alloced member to true) + * + * @abuf: abuf to adjust + * @new_size: new size in bytes. + * if 0, the abuf is freed + * if greater than the current size, the abuf is extended and the new + *space is not inited. The alloced member is set to true + * if less than the current size, the abuf is contracted and the data at + *the end is lost. If @new_size is 0, this sets the alloced member to + *false + * @return true if OK, false if out of memory + */ +bool abuf_realloc(struct abuf *abuf, size_t new_size); + +/** + * abuf_uninit_move() - Return the allocated contents and uninit the abuf + * + * This returns the abuf data to the caller, allocating it if necessary, so that + * the caller receives data that it can be sure will hang around. The caller is + * responsible for freeing the data. + * + * If the abuf has allocated data, it is returned. If the abuf has data but it + * is not allocated, then it is first allocated, then returned. + * + * If the abuf size is 0, this returns NULL + * + * The abuf is uninited as part of this, except if the al
[PATCH v4 07/15] image: Update zstd to avoid reporting error twice
The zstd implementation prints the error in image_decomp() which is incorrect and does not match other algorithms. Drop this and let the caller report the error. Signed-off-by: Simon Glass --- (no changes since v1) common/image.c | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/common/image.c b/common/image.c index d80781f2eb4..7fd4a567626 100644 --- a/common/image.c +++ b/common/image.c @@ -534,12 +534,10 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, abuf_init_set(&in, image_buf, image_len); abuf_init_set(&in, load_buf, unc_len); ret = zstd_decompress(&in, &out); - if (ret < 0) { - printf("ZSTD decompression failed\n"); - return ret; + if (ret >= 0) { + image_len = ret; + ret = 0; } - - image_len = ret; break; } #endif /* CONFIG_ZSTD */ -- 2.33.0.685.g46640cef36-goog
[PATCH v4 08/15] gzip: Avoid use of u64
The gzip API uses the u64 type in it, which is not available in the host build. This makes it impossible to include the header file. We could make this type available, but it seems unnecessary. Limiting the compression size to that of the 'unsigned long' type seems good enough. On 32-bit machines the limit then becomes 4GB, which likely exceeds available RAM anyway, therefore it should be sufficient. On 64-bit machines this is effectively u64 anyway. Update the header file and implementation to use 'ulong' instead of 'u64'. Add a definition of u32 for the cases that seem to need exactly that length. This should be safe enough. Signed-off-by: Simon Glass --- (no changes since v1) include/compiler.h | 3 +++ include/gzip.h | 8 lib/gunzip.c | 28 ++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/compiler.h b/include/compiler.h index 67e52050b12..6b0d3bf5374 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -68,6 +68,9 @@ typedef uint32_t __u32; typedef unsigned int uint; typedef unsigned long ulong; +/* Define these on the host so we can build some target code */ +typedef __u32 u32; + #define uswap_16(x) \ x) & 0xff00) >> 8) | \ (((x) & 0x00ff) << 8)) diff --git a/include/gzip.h b/include/gzip.h index 783acbb60d2..cb4db3d70fe 100644 --- a/include/gzip.h +++ b/include/gzip.h @@ -54,11 +54,11 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, * gzwrite_progress_finish called at end of loop to * indicate success (retcode=0) or failure */ -void gzwrite_progress_init(u64 expected_size); +void gzwrite_progress_init(ulong expected_size); -void gzwrite_progress(int iteration, u64 bytes_written, u64 total_bytes); +void gzwrite_progress(int iteration, ulong bytes_written, ulong total_bytes); -void gzwrite_progress_finish(int retcode, u64 totalwritten, u64 totalsize, +void gzwrite_progress_finish(int retcode, ulong totalwritten, ulong totalsize, u32 expected_crc, u32 calculated_crc); /** @@ -74,7 +74,7 @@ void gzwrite_progress_finish(int retcode, u64 totalwritten, u64 totalsize, * @return 0 if OK, -1 on error */ int gzwrite(unsigned char *src, int len, struct blk_desc *dev, ulong szwritebuf, - u64 startoffs, u64 szexpected); + ulong startoffs, ulong szexpected); /** * gzip()- Compress data into a buffer using the gzip algorithm diff --git a/lib/gunzip.c b/lib/gunzip.c index bee3b9261f3..a8e498d98d8 100644 --- a/lib/gunzip.c +++ b/lib/gunzip.c @@ -84,32 +84,32 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) #ifdef CONFIG_CMD_UNZIP __weak -void gzwrite_progress_init(u64 expectedsize) +void gzwrite_progress_init(ulong expectedsize) { putc('\n'); } __weak void gzwrite_progress(int iteration, -u64 bytes_written, -u64 total_bytes) +ulong bytes_written, +ulong total_bytes) { if (0 == (iteration & 3)) - printf("%llu/%llu\r", bytes_written, total_bytes); + printf("%lu/%lu\r", bytes_written, total_bytes); } __weak void gzwrite_progress_finish(int returnval, -u64 bytes_written, -u64 total_bytes, +ulong bytes_written, +ulong total_bytes, u32 expected_crc, u32 calculated_crc) { if (0 == returnval) { - printf("\n\t%llu bytes, crc 0x%08x\n", + printf("\n\t%lu bytes, crc 0x%08x\n", total_bytes, calculated_crc); } else { - printf("\n\tuncompressed %llu of %llu\n" + printf("\n\tuncompressed %lu of %lu\n" "\tcrcs == 0x%08x/0x%08x\n", bytes_written, total_bytes, expected_crc, calculated_crc); @@ -119,15 +119,15 @@ void gzwrite_progress_finish(int returnval, int gzwrite(unsigned char *src, int len, struct blk_desc *dev, unsigned long szwritebuf, - u64 startoffs, - u64 szexpected) + ulong startoffs, + ulong szexpected) { int i, flags; z_stream s; int r = 0; unsigned char *writebuf; unsigned crc = 0; - u64 totalfilled = 0; + ulong totalfilled = 0; lbaint_t blksperbuf, outblock; u32 expected_crc; u32 payload_size; @@ -142,7 +142,7 @@ int gzwrite(unsigned char *src, int len, } if (startoffs & (dev->blksz-1)) { - printf("%s: start offset %llu not a multiple of %lu\n", + printf("%s: start offset %lu not a multiple of %lu\n", __func__, startoffs, dev->blksz); return -1; } @@ -182,12 +182,1
[PATCH v4 09/15] image: Update image_decomp() to avoid ifdefs
Adjust this function so that preprocessor macros are not needed. With this, the host build uses more of the same header files as the target build. Rather than definining CONFIG_SYS_MALLOC_LEN, add a CONSERVE_MEMORY define, since that is the purpose of the value. This appears to have no impact on code size from a spot check of a few boards (snow, firefly-rk3288, boston32r2el, m53menlo). Signed-off-by: Simon Glass --- (no changes since v1) common/image.c| 145 ++ configs/sandbox_defconfig | 1 + 2 files changed, 69 insertions(+), 77 deletions(-) diff --git a/common/image.c b/common/image.c index 7fd4a567626..80aeb4398ec 100644 --- a/common/image.c +++ b/common/image.c @@ -22,12 +22,9 @@ #include #endif -#include #include -#include #include -#include #include #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT @@ -43,13 +40,6 @@ #include #include -#include -#include -#include -#include -#include -#include - #ifdef CONFIG_CMD_BDI extern int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); @@ -61,7 +51,15 @@ DECLARE_GLOBAL_DATA_PTR; static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, int verify); #endif + +/* Set this if we have less than 4 MB of malloc() space */ +#if CONFIG_SYS_MALLOC_LEN < (4096 * 1024) +#define CONSERVE_MEMORYtrue #else +#define CONSERVE_MEMORYfalse +#endif + +#else /* USE_HOSTCC */ #include "mkimage.h" #include #include @@ -70,10 +68,23 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, #ifndef __maybe_unused # define __maybe_unused/* unimplemented */ #endif + +#define CONSERVE_MEMORYfalse + #endif /* !USE_HOSTCC*/ -#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #ifndef CONFIG_SYS_BARGSIZE #define CONFIG_SYS_BARGSIZE 512 @@ -466,83 +477,63 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, else ret = -ENOSPC; break; -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(GZIP) - case IH_COMP_GZIP: { - ret = gunzip(load_buf, unc_len, image_buf, &image_len); + case IH_COMP_GZIP: + if (!host_build() && CONFIG_IS_ENABLED(GZIP)) + ret = gunzip(load_buf, unc_len, image_buf, &image_len); break; - } -#endif /* CONFIG_GZIP */ -#endif -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(BZIP2) - case IH_COMP_BZIP2: { - uint size = unc_len; + case IH_COMP_BZIP2: + if (!host_build() && CONFIG_IS_ENABLED(BZIP2)) { + uint size = unc_len; - /* -* If we've got less than 4 MB of malloc() space, -* use slower decompression algorithm which requires -* at most 2300 KB of memory. -*/ - ret = BZ2_bzBuffToBuffDecompress(load_buf, &size, - image_buf, image_len, - CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); - image_len = size; + /* +* If we've got less than 4 MB of malloc() space, +* use slower decompression algorithm which requires +* at most 2300 KB of memory. +*/ + ret = BZ2_bzBuffToBuffDecompress(load_buf, &size, + image_buf, image_len, CONSERVE_MEMORY, 0); + image_len = size; + } break; - } -#endif /* CONFIG_BZIP2 */ -#endif -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(LZMA) - case IH_COMP_LZMA: { - SizeT lzma_len = unc_len; + case IH_COMP_LZMA: + if (!host_build() && CONFIG_IS_ENABLED(LZMA)) { + SizeT lzma_len = unc_len; - ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len, - image_buf, image_len); - image_len = lzma_len; + ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len, + image_buf, image_len); + image_len = lzma_len; + } break; - } -#endif /* CONFIG_LZMA */ -#endif -#ifndef USE_HOSTCC -#if CONFIG_IS_ENABLED(LZO) - case IH_COMP_LZO: { - size_t size = unc_len; + case IH_COMP_LZO: + if (!host_build() && CONFIG_IS_ENABLED(LZO)) { + size_t size = unc_len; - ret = lzop_decompress(image_buf, image_len, load_buf, &size); - image_len = size; + ret = lzop_decompress(i
[PATCH v4 12/15] image: Split host code out into its own file
To avoid having #ifdefs in a few functions which are completely different in the board and host code, create a new image-host.c file. Signed-off-by: Simon Glass --- (no changes since v1) common/image-board.c | 17 + common/image-host.c | 27 +++ common/image.c | 38 +- tools/Makefile | 1 + 4 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 common/image-host.c diff --git a/common/image-board.c b/common/image-board.c index 15419c78c48..d0307d7625c 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -925,3 +926,19 @@ int image_setup_linux(bootm_headers_t *images) return 0; } #endif /* CONFIG_LMB */ + +void genimg_print_size(uint32_t size) +{ + printf("%d Bytes = ", size); + print_size(size, "\n"); +} + +void genimg_print_time(time_t timestamp) +{ + struct rtc_time tm; + + rtc_to_tm(timestamp, &tm); + printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n", + tm.tm_year, tm.tm_mon, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); +} diff --git a/common/image-host.c b/common/image-host.c new file mode 100644 index 000..20a9521948b --- /dev/null +++ b/common/image-host.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Image code used by host tools (and not boards) + * + * (C) Copyright 2008 Semihalf + * + * (C) Copyright 2000-2006 + * Wolfgang Denk, DENX Software Engineering, w...@denx.de. + */ + +#include + +void memmove_wd(void *to, void *from, size_t len, ulong chunksz) +{ + memmove(to, from, len); +} + +void genimg_print_size(uint32_t size) +{ + printf("%d Bytes = %.2f KiB = %.2f MiB\n", size, (double)size / 1.024e3, + (double)size / 1.048576e6); +} + +void genimg_print_time(time_t timestamp) +{ + printf("%s", ctime(×tamp)); +} diff --git a/common/image.c b/common/image.c index ed7f188b591..3eb6a7fca1d 100644 --- a/common/image.c +++ b/common/image.c @@ -18,8 +18,6 @@ #include #endif -#include - #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT #include #include @@ -60,6 +58,7 @@ DECLARE_GLOBAL_DATA_PTR; #include #include +#include #include #include #include @@ -528,41 +527,6 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, return 0; } -#ifdef USE_HOSTCC -void memmove_wd(void *to, void *from, size_t len, ulong chunksz) -{ - memmove(to, from, len); -} -#endif /* !USE_HOSTCC */ - -void genimg_print_size(uint32_t size) -{ -#ifndef USE_HOSTCC - printf("%d Bytes = ", size); - print_size(size, "\n"); -#else - printf("%d Bytes = %.2f KiB = %.2f MiB\n", - size, (double)size / 1.024e3, - (double)size / 1.048576e6); -#endif -} - -#if IMAGE_ENABLE_TIMESTAMP -void genimg_print_time(time_t timestamp) -{ -#ifndef USE_HOSTCC - struct rtc_time tm; - - rtc_to_tm(timestamp, &tm); - printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n", - tm.tm_year, tm.tm_mon, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); -#else - printf("%s", ctime(×tamp)); -#endif -} -#endif - const table_entry_t *get_table_entry(const table_entry_t *table, int id) { for (; table->id >= 0; ++table) { diff --git a/tools/Makefile b/tools/Makefile index 4a86321f646..999fd465316 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -113,6 +113,7 @@ dumpimage-mkimage-objs := aisimage.o \ lib/fdtdec_common.o \ lib/fdtdec.o \ common/image.o \ + common/image-host.o \ imagetool.o \ imximage.o \ imx8image.o \ -- 2.33.0.685.g46640cef36-goog
[PATCH v4 13/15] image: Create a function to do manual relocation
Rather than adding an #ifdef and open-coding this calculation, add a helper function to handle it. Use this in the image code. Signed-off-by: Simon Glass --- (no changes since v1) common/image.c | 33 +++-- include/relocate.h | 24 +++- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/common/image.c b/common/image.c index 3eb6a7fca1d..2f2fd052c50 100644 --- a/common/image.c +++ b/common/image.c @@ -63,6 +63,7 @@ DECLARE_GLOBAL_DATA_PTR; #include #include #include +#include #include #include #include @@ -565,11 +566,7 @@ const char *genimg_get_cat_name(enum ih_category category, uint id) entry = get_table_entry(table_info[category].table, id); if (!entry) return unknown_msg(category); -#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) - return entry->lname; -#else - return entry->lname + gd->reloc_off; -#endif + return manual_reloc(entry->lname); } /** @@ -589,11 +586,7 @@ const char *genimg_get_cat_short_name(enum ih_category category, uint id) entry = get_table_entry(table_info[category].table, id); if (!entry) return unknown_msg(category); -#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) - return entry->sname; -#else - return entry->sname + gd->reloc_off; -#endif + return manual_reloc(entry->sname); } int genimg_get_cat_count(enum ih_category category) @@ -643,11 +636,7 @@ char *get_table_entry_name(const table_entry_t *table, char *msg, int id) table = get_table_entry(table, id); if (!table) return msg; -#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) - return table->lname; -#else - return table->lname + gd->reloc_off; -#endif + return manual_reloc(table->lname); } const char *genimg_get_os_name(uint8_t os) @@ -677,11 +666,7 @@ static const char *genimg_get_short_name(const table_entry_t *table, int val) table = get_table_entry(table, val); if (!table) return "unknown"; -#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) - return table->sname; -#else - return table->sname + gd->reloc_off; -#endif + return manual_reloc(table->sname); } const char *genimg_get_type_short_name(uint8_t type) @@ -724,12 +709,8 @@ int get_table_entry_id(const table_entry_t *table, const table_entry_t *t; for (t = table; t->id >= 0; ++t) { -#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC) - if (t->sname && strcasecmp(t->sname + gd->reloc_off, name) == 0) -#else - if (t->sname && strcasecmp(t->sname, name) == 0) -#endif - return (t->id); + if (t->sname && !strcasecmp(manual_reloc(t->sname), name)) + return t->id; } debug("Invalid %s Type: %s\n", table_name, name); diff --git a/include/relocate.h b/include/relocate.h index 9ceeecdbe71..c4fad336128 100644 --- a/include/relocate.h +++ b/include/relocate.h @@ -7,7 +7,11 @@ #ifndef _RELOCATE_H_ #define _RELOCATE_H_ -#include +#ifndef USE_HOSTCC +#include + +DECLARE_GLOBAL_DATA_PTR; +#endif /** * copy_uboot_to_ram() - Copy U-Boot to its new relocated position @@ -35,4 +39,22 @@ int clear_bss(void); */ int do_elf_reloc_fixups(void); +/** + * manual_reloc() - Manually relocate a pointer if needed + * + * This is a nop in almost all cases, except for the systems with a broken gcc + * which need to manually relocate some things. + * + * @ptr: Pointer to relocate + * @return new pointer value + */ +static inline void *manual_reloc(void *ptr) +{ +#ifndef USE_HOSTCC + if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) + return ptr + gd->reloc_off; +#endif + return ptr; +} + #endif /* _RELOCATE_H_ */ -- 2.33.0.685.g46640cef36-goog
[PATCH v4 11/15] image: Fix up checkpatch warnings in image-board.c
Tidy up the warnings. Signed-off-by: Simon Glass --- (no changes since v1) common/image-board.c | 142 ++- 1 file changed, 72 insertions(+), 70 deletions(-) diff --git a/common/image-board.c b/common/image-board.c index f9053552e74..15419c78c48 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -41,8 +41,8 @@ DECLARE_GLOBAL_DATA_PTR; * pointer to a ramdisk image header, if image was found and valid * otherwise, return NULL */ -static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, - int verify) +static const image_header_t *image_get_ramdisk(ulong rd_addr, u8 arch, + int verify) { const image_header_t *rd_hdr = (const image_header_t *)rd_addr; @@ -77,7 +77,7 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, !image_check_arch(rd_hdr, arch) || !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) { printf("No Linux %s Ramdisk Image\n", - genimg_get_arch_name(arch)); + genimg_get_arch_name(arch)); bootstage_error(BOOTSTAGE_ID_RAMDISK); return NULL; } @@ -94,7 +94,7 @@ ulong image_save_addr;/* Default Save Address */ ulong image_save_size; /* Default Save Size (in bytes) */ static int on_loadaddr(const char *name, const char *value, enum env_op op, - int flags) + int flags) { switch (op) { case env_op_create: @@ -112,6 +112,7 @@ U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr); ulong env_get_bootm_low(void) { char *s = env_get("bootm_low"); + if (s) { ulong tmp = hextoul(s, NULL); return tmp; @@ -131,6 +132,7 @@ phys_size_t env_get_bootm_size(void) phys_size_t tmp, size; phys_addr_t start; char *s = env_get("bootm_size"); + if (s) { tmp = (phys_size_t)simple_strtoull(s, NULL, 16); return tmp; @@ -155,6 +157,7 @@ phys_size_t env_get_bootm_mapsize(void) { phys_size_t tmp; char *s = env_get("bootm_mapsize"); + if (s) { tmp = (phys_size_t)simple_strtoull(s, NULL, 16); return tmp; @@ -179,6 +182,7 @@ void memmove_wd(void *to, void *from, size_t len, ulong chunksz) } while (len > 0) { size_t tail = (len > chunksz) ? chunksz : len; + WATCHDOG_RESET(); if (to > from) { to -= tail; @@ -212,8 +216,8 @@ void memmove_wd(void *to, void *from, size_t len, ulong chunksz) * kernel start address */ ulong genimg_get_kernel_addr_fit(char * const img_addr, -const char **fit_uname_config, -const char **fit_uname_kernel) +const char **fit_uname_config, +const char **fit_uname_kernel) { ulong kernel_addr; @@ -319,7 +323,7 @@ int genimg_has_config(bootm_headers_t *images) * @rd_end: pointer to a ulong variable, will hold ramdisk end * * boot_get_ramdisk() is responsible for finding a valid ramdisk image. - * Curently supported are the following ramdisk sources: + * Currently supported are the following ramdisk sources: * - multicomponent kernel/ramdisk image, * - commandline provided address of decicated ramdisk image. * @@ -332,7 +336,7 @@ int genimg_has_config(bootm_headers_t *images) * rd_start and rd_end are set to 0 if no ramdisk exists */ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, -uint8_t arch, ulong *rd_start, ulong *rd_end) +u8 arch, ulong *rd_start, ulong *rd_end) { ulong rd_addr, rd_load; ulong rd_data, rd_len; @@ -372,7 +376,8 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, */ if (select && strcmp(select, "-") == 0) { debug("## Skipping init Ramdisk\n"); - rd_len = rd_data = 0; + rd_len = 0; + rd_data = 0; } else if (select || genimg_has_config(images)) { #if IMAGE_ENABLE_FIT if (select) { @@ -389,21 +394,19 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, if (fit_parse_conf(select, default_addr, &rd_addr, &fit_uname_config)) { - debug("* ramdisk: config '%s' from image at " - "0x%08lx\n", - fit_uname_config, rd_addr); + debug("* ramdisk: config '%s' from image at 0x%08lx\n", +
[PATCH v4 14/15] image: Avoid #ifdefs for manual relocation
Add a macro to handle manually relocating a pointer. Update the iamge code to use this to avoid needing #ifdefs. This also fixes a bug where the 'done' flag was not set. Signed-off-by: Simon Glass --- (no changes since v1) common/image-sig.c | 40 ++-- include/relocate.h | 6 ++ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/common/image-sig.c b/common/image-sig.c index fa9407bb300..1aa0b586450 100644 --- a/common/image-sig.c +++ b/common/image-sig.c @@ -9,6 +9,7 @@ #include DECLARE_GLOBAL_DATA_PTR; #include +#include #include #include #include @@ -56,17 +57,19 @@ struct checksum_algo *image_get_checksum_algo(const char *full_name) int i; const char *name; -#if defined(CONFIG_NEEDS_MANUAL_RELOC) - static bool done; + if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) { + static bool done; - if (!done) { - done = true; - for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) { - checksum_algos[i].name += gd->reloc_off; - checksum_algos[i].calculate += gd->reloc_off; + if (!done) { + done = true; + for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) { + struct checksum_algo *algo = &checksum_algos[i]; + + MANUAL_RELOC(algo->name); + MANUAL_RELOC(algo->calculate); + } } } -#endif for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) { name = checksum_algos[i].name; @@ -84,18 +87,19 @@ struct crypto_algo *image_get_crypto_algo(const char *full_name) struct crypto_algo *crypto, *end; const char *name; -#if defined(CONFIG_NEEDS_MANUAL_RELOC) - static bool done; - - if (!done) { - crypto = ll_entry_start(struct crypto_algo, cryptos); - end = ll_entry_end(struct crypto_algo, cryptos); - for (; crypto < end; crypto++) { - crypto->name += gd->reloc_off; - crypto->verify += gd->reloc_off; + if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) { + static bool done; + + if (!done) { + done = true; + crypto = ll_entry_start(struct crypto_algo, cryptos); + end = ll_entry_end(struct crypto_algo, cryptos); + for (; crypto < end; crypto++) { + MANUAL_RELOC(crypto->name); + MANUAL_RELOC(crypto->verify); + } } } -#endif /* Move name to after the comma */ name = strchr(full_name, ','); diff --git a/include/relocate.h b/include/relocate.h index c4fad336128..26682da955f 100644 --- a/include/relocate.h +++ b/include/relocate.h @@ -57,4 +57,10 @@ static inline void *manual_reloc(void *ptr) return ptr; } +#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC) +#define MANUAL_RELOC(ptr) (ptr) = manual_reloc(ptr) +#else +#define MANUAL_RELOC(ptr) (void)(ptr) +#endif + #endif /* _RELOCATE_H_ */ -- 2.33.0.685.g46640cef36-goog
[PATCH v4 10/15] image: Split board code out into its own file
To avoid a large #ifdef in the image.c file, move the affected code into a separate file. Avoid any style fix-ups for easier review. Those are in the next patch. Signed-off-by: Simon Glass --- (no changes since v1) common/Makefile | 2 +- common/image-board.c | 925 +++ common/image.c | 925 +-- 3 files changed, 928 insertions(+), 924 deletions(-) create mode 100644 common/image-board.c diff --git a/common/Makefile b/common/Makefile index fb8173a5b82..e7839027b6c 100644 --- a/common/Makefile +++ b/common/Makefile @@ -101,7 +101,7 @@ obj-y += malloc_simple.o endif endif -obj-y += image.o +obj-y += image.o image-board.o obj-$(CONFIG_$(SPL_TPL_)HASH) += hash.o obj-$(CONFIG_ANDROID_AB) += android_ab.o obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o diff --git a/common/image-board.c b/common/image-board.c new file mode 100644 index 000..f9053552e74 --- /dev/null +++ b/common/image-board.c @@ -0,0 +1,925 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Image code used by boards (and not host tools) + * + * (C) Copyright 2008 Semihalf + * + * (C) Copyright 2000-2006 + * Wolfgang Denk, DENX Software Engineering, w...@denx.de. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef CONFIG_SYS_BARGSIZE +#define CONFIG_SYS_BARGSIZE 512 +#endif + +DECLARE_GLOBAL_DATA_PTR; + +#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) +/** + * image_get_ramdisk - get and verify ramdisk image + * @rd_addr: ramdisk image start address + * @arch: expected ramdisk architecture + * @verify: checksum verification flag + * + * image_get_ramdisk() returns a pointer to the verified ramdisk image + * header. Routine receives image start address and expected architecture + * flag. Verification done covers data and header integrity and os/type/arch + * fields checking. + * + * returns: + * pointer to a ramdisk image header, if image was found and valid + * otherwise, return NULL + */ +static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, + int verify) +{ + const image_header_t *rd_hdr = (const image_header_t *)rd_addr; + + if (!image_check_magic(rd_hdr)) { + puts("Bad Magic Number\n"); + bootstage_error(BOOTSTAGE_ID_RD_MAGIC); + return NULL; + } + + if (!image_check_hcrc(rd_hdr)) { + puts("Bad Header Checksum\n"); + bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM); + return NULL; + } + + bootstage_mark(BOOTSTAGE_ID_RD_MAGIC); + image_print_contents(rd_hdr); + + if (verify) { + puts(" Verifying Checksum ... "); + if (!image_check_dcrc(rd_hdr)) { + puts("Bad Data CRC\n"); + bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM); + return NULL; + } + puts("OK\n"); + } + + bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM); + + if (!image_check_os(rd_hdr, IH_OS_LINUX) || + !image_check_arch(rd_hdr, arch) || + !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) { + printf("No Linux %s Ramdisk Image\n", + genimg_get_arch_name(arch)); + bootstage_error(BOOTSTAGE_ID_RAMDISK); + return NULL; + } + + return rd_hdr; +} +#endif + +/*/ +/* Shared dual-format routines */ +/*/ +ulong image_load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */ +ulong image_save_addr; /* Default Save Address */ +ulong image_save_size; /* Default Save Size (in bytes) */ + +static int on_loadaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + switch (op) { + case env_op_create: + case env_op_overwrite: + image_load_addr = hextoul(value, NULL); + break; + default: + break; + } + + return 0; +} +U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr); + +ulong env_get_bootm_low(void) +{ + char *s = env_get("bootm_low"); + if (s) { + ulong tmp = hextoul(s, NULL); + return tmp; + } + +#if defined(CONFIG_SYS_SDRAM_BASE) + return CONFIG_SYS_SDRAM_BASE; +#elif defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE) + return gd->bd->bi_dram[0].start; +#else + return 0; +#endif +} + +phys_size_t env_get_bootm_size(void) +{ + phys_size_t tmp, size; + phys_addr_t start; + char *s = env_get("bootm_size"); + if (s) { + tmp = (phys_size_t)simple_strtoull(s, NULL, 16); + return tmp; +
[PATCH v4 15/15] image: Remove ifdefs around image_setup_linux() el at
Drop some more ifdefs in image-board.c and also the FPGA part of bootm.c which calls into it. Signed-off-by: Simon Glass --- Changes in v4: - Rebase to master Changes in v3: - Pick up only the first part of the original v2 series common/bootm.c | 16 common/image-board.c | 11 +++ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/common/bootm.c b/common/bootm.c index ea71522d0c9..fe17d1da9e5 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -296,15 +296,15 @@ int bootm_find_images(int flag, int argc, char *const argv[], ulong start, #endif #if IMAGE_ENABLE_FIT -#if defined(CONFIG_FPGA) - /* find bitstreams */ - ret = boot_get_fpga(argc, argv, &images, IH_ARCH_DEFAULT, - NULL, NULL); - if (ret) { - printf("FPGA image is corrupted or invalid\n"); - return 1; + if (IS_ENABLED(CONFIG_FPGA)) { + /* find bitstreams */ + ret = boot_get_fpga(argc, argv, &images, IH_ARCH_DEFAULT, + NULL, NULL); + if (ret) { + printf("FPGA image is corrupted or invalid\n"); + return 1; + } } -#endif /* find all of the loadables */ ret = boot_get_loadable(argc, argv, &images, IH_ARCH_DEFAULT, diff --git a/common/image-board.c b/common/image-board.c index d0307d7625c..c13d0493ca3 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -814,7 +814,6 @@ int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images, } #endif -#ifdef CONFIG_SYS_BOOT_GET_CMDLINE /** * boot_get_cmdline - allocate and initialize kernel cmdline * @lmb: pointer to lmb handle, will be used for memory mgmt @@ -853,9 +852,7 @@ int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end) return 0; } -#endif /* CONFIG_SYS_BOOT_GET_CMDLINE */ -#ifdef CONFIG_SYS_BOOT_GET_KBD /** * boot_get_kbd - allocate and initialize kernel copy of board info * @lmb: pointer to lmb handle, will be used for memory mgmt @@ -883,15 +880,14 @@ int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd) debug("## kernel board info at 0x%08lx\n", (ulong)*kbd); -#if defined(DEBUG) && defined(CONFIG_CMD_BDI) - do_bdinfo(NULL, 0, 0, NULL); +#if defined(DEBUG) + if (IS_ENABLED(CONFIG_CMD_BDI) + do_bdinfo(NULL, 0, 0, NULL); #endif return 0; } -#endif /* CONFIG_SYS_BOOT_GET_KBD */ -#ifdef CONFIG_LMB int image_setup_linux(bootm_headers_t *images) { ulong of_size = images->ft_len; @@ -925,7 +921,6 @@ int image_setup_linux(bootm_headers_t *images) return 0; } -#endif /* CONFIG_LMB */ void genimg_print_size(uint32_t size) { -- 2.33.0.685.g46640cef36-goog
[PATCH] ARM: vexpress_ca9x4: Correct missing SYS_LOAD_ADDR
Add this missing option since it otherwise causes the build to fail in an infinite loop of: Address in memory to use by default (SYS_LOAD_ADDR) [] (NEW) Error in reading or end of file. Signed-off-by: Simon Glass Fixes: 15e30106ce6 (ARM: vexpress_ca9x4: Reintroduce board in order to use with QEMU.") --- configs/vexpress_ca9x4_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/vexpress_ca9x4_defconfig b/configs/vexpress_ca9x4_defconfig index 36ee3787b96..eddaf9764ab 100644 --- a/configs/vexpress_ca9x4_defconfig +++ b/configs/vexpress_ca9x4_defconfig @@ -5,6 +5,7 @@ CONFIG_NR_DRAM_BANKS=2 CONFIG_ENV_SIZE=0x4 CONFIG_ENV_SECT_SIZE=0x4 CONFIG_DISTRO_DEFAULTS=y +CONFIG_SYS_LOAD_ADDR=0x9000 CONFIG_BOOTCOMMAND="run distro_bootcmd; run bootflash" CONFIG_DEFAULT_FDT_FILE="vexpress-v2p-ca9.dtb" # CONFIG_DISPLAY_CPUINFO is not set -- 2.33.0.685.g46640cef36-goog
Re: [PATCH 0/5] Apple M1 Support
Hi Mark, On Sat, 25 Sept 2021 at 02:11, Mark Kettenis wrote: > > > From: Simon Glass > > Date: Fri, 24 Sep 2021 19:20:32 -0600 > > > > Hi Mark, > > > > On Sat, 18 Sept 2021 at 07:54, Mark Kettenis wrote: > > > > > > This series adds basic support for Apple's M1 SoC to U-Boot. > > > This builds a basic U-Boot that can be used as a payload > > > for the m1n1 boot loader being developed by the Asahi Linux > > > project. > > > > > > The goal here is to privide an UEFI interface on these machines that > > > > provide > > > > > allows booting various open source OSes. This initial series provides > > > support for the serial port, framebuffer and the USB 3.1 Type-C ports. > > > It can boot a support OS (e.g. OpenBSD/arm64) from a USB disk. > > > > > > Mark Kettenis (5): > > > arm: apple: Add initial support for Apple's M1 SoC > > > serial: s5p: Add Apple M1 support > > > misc: Add Apple DART driver > > > arm: dts: apple: Add preliminary device trees > > > doc: board: apple: Add Apple M1 documentation > > > > > > arch/arm/Kconfig | 22 + > > > arch/arm/Makefile | 1 + > > > arch/arm/dts/t8103-j274.dts | 135 + > > > arch/arm/dts/t8103-j293.dts | 97 > > > arch/arm/dts/t8103.dtsi | 506 ++ > > > arch/arm/include/asm/arch-m1/clk.h| 11 + > > > arch/arm/include/asm/arch-m1/uart.h | 41 ++ > > > arch/arm/mach-apple/Kconfig | 18 + > > > arch/arm/mach-apple/Makefile | 4 + > > > arch/arm/mach-apple/board.c | 163 ++ > > > arch/arm/mach-apple/lowlevel_init.S | 16 + > > > configs/apple_m1_defconfig| 14 + > > > doc/board/apple/index.rst | 9 + > > > doc/board/apple/m1.rst| 54 ++ > > > doc/board/index.rst | 1 + > > > drivers/misc/Kconfig | 7 + > > > drivers/misc/Makefile | 1 + > > > drivers/misc/apple_dart.c | 171 ++ > > > drivers/serial/Kconfig| 2 +- > > > drivers/serial/serial_s5p.c | 22 + > > > include/configs/apple.h | 38 ++ > > > .../interrupt-controller/apple-aic.h | 15 + > > > include/dt-bindings/pinctrl/apple.h | 13 + > > > include/dt-bindings/spmi/spmi.h | 10 + > > > 24 files changed, 1370 insertions(+), 1 deletion(-) > > > create mode 100644 arch/arm/dts/t8103-j274.dts > > > create mode 100644 arch/arm/dts/t8103-j293.dts > > > create mode 100644 arch/arm/dts/t8103.dtsi > > > create mode 100644 arch/arm/include/asm/arch-m1/clk.h > > > create mode 100644 arch/arm/include/asm/arch-m1/uart.h > > > create mode 100644 arch/arm/mach-apple/Kconfig > > > create mode 100644 arch/arm/mach-apple/Makefile > > > create mode 100644 arch/arm/mach-apple/board.c > > > create mode 100644 arch/arm/mach-apple/lowlevel_init.S > > > create mode 100644 configs/apple_m1_defconfig > > > create mode 100644 doc/board/apple/index.rst > > > create mode 100644 doc/board/apple/m1.rst > > > create mode 100644 drivers/misc/apple_dart.c > > > create mode 100644 include/configs/apple.h > > > create mode 100644 include/dt-bindings/interrupt-controller/apple-aic.h > > > create mode 100644 include/dt-bindings/pinctrl/apple.h > > > create mode 100644 include/dt-bindings/spmi/spmi.h > > > > > > -- > > > 2.33.0 > > > > > > > I gave this a whirl on a Macbook Air A2337 and needed the patch below > > to build the devicetree files. Sorry the formatting is broken. > > > > Also when booting I get this: > > > > ... > > Preparing to boot kernel at 0x80820 with fdt at 0x8082e8000 > > Valid payload found > > Preparing to run next stage at 0x80820... > > MMU: shutting down... > > MMU: shutdown successful, clearing caches > > > > > > Then the display clears and it hangs. If I try the J274 devicetree it > > just reboots at that point. > > > > What should I expect? I was hoping for console output as I don't have > > serial connected. I don't have a suitable serial cable, and the USB > > gadget mode did not result in a ttyACM0 device appearing. > > For framebuffer support you also need the "30bpp framebuffer support" > series I posted earlier: > > https://patchwork.ozlabs.org/project/uboot/list/?series=262617 > > With that your should get the usual U-Boot output on the screen. I've > not tested the Air, but it should work there. Ah OK, yes that fixes it, thanks! So how do I get the keyboard to work in U-Boot? Or are you using serial somehow? Also it takes for ever to put a test version on the device...how are you doing that for development? > > I'll probably post a v2 of that series this weekend as I fixed the EFI > GOP support with the help of Heinrich. But that shouldn't matter for > U-Boot itself. O
Re: [PATCH 2/5] serial: s5p: Add Apple M1 support
On Sun, 19 Sept 2021 at 21:15, Simon Glass wrote: > > Hi Mark, > > On Sat, 18 Sept 2021 at 07:55, Mark Kettenis wrote: > > > > Apple M1 SoCs include an S5L UART which is a variant of the S5P > > UART. Add support for this variant and enable it by default > > on Apple SoCs. > > > > Signed-off-by: Mark Kettenis > > --- > > arch/arm/include/asm/arch-m1/clk.h | 11 > > arch/arm/include/asm/arch-m1/uart.h | 41 + > > arch/arm/mach-apple/board.c | 5 > > drivers/serial/Kconfig | 2 +- > > drivers/serial/serial_s5p.c | 22 > > 5 files changed, 80 insertions(+), 1 deletion(-) > > create mode 100644 arch/arm/include/asm/arch-m1/clk.h > > create mode 100644 arch/arm/include/asm/arch-m1/uart.h > > Tested on: Macbook Air M1 Tested-by: Simon Glass
Re: [PATCH 1/5] arm: apple: Add initial support for Apple's M1 SoC
Hi Mark, On Tue, 21 Sept 2021 at 10:09, Mark Kettenis wrote: > > > From: Bin Meng > > Date: Tue, 21 Sep 2021 23:53:10 +0800 > > > > On Tue, Sep 21, 2021 at 8:42 PM Tom Rini wrote: > > > > > > On Sun, Sep 19, 2021 at 10:33:25PM +0200, Mark Kettenis wrote: > > > > > From: Bin Meng > > > > > Date: Sun, 19 Sep 2021 09:17:07 +0800 > > > > > > > > > > Hi Mark, > > > > > > > > > > On Sun, Sep 19, 2021 at 9:04 AM Bin Meng wrote: > > > > > > > > > > > > Hi Mark, > > > > > > > > > > > > On Sat, Sep 18, 2021 at 9:55 PM Mark Kettenis > > > > > > wrote: > > > > > > > > > > > > > > Add support for Apple's M1 SoC that is used in "Apple Silicon" > > > > > > > Macs. This builds a basic U-Boot that can be used as a payload > > > > > > > for the m1n1 boot loader being developed by the Asahi Linux > > > > > > > project. > > > > > > > > > > > > > > Signed-off-by: Mark Kettenis > > > > > > > --- > > > > > > > arch/arm/Kconfig| 22 > > > > > > > arch/arm/Makefile | 1 + > > > > > > > arch/arm/mach-apple/Kconfig | 18 > > > > > > > arch/arm/mach-apple/Makefile| 4 + > > > > > > > arch/arm/mach-apple/board.c | 158 > > > > > > > > > > > > > > arch/arm/mach-apple/lowlevel_init.S | 16 +++ > > > > > > > configs/apple_m1_defconfig | 14 +++ > > > > > > > include/configs/apple.h | 38 +++ > > > > > > > 8 files changed, 271 insertions(+) > > > > > > > create mode 100644 arch/arm/mach-apple/Kconfig > > > > > > > create mode 100644 arch/arm/mach-apple/Makefile > > > > > > > create mode 100644 arch/arm/mach-apple/board.c > > > > > > > create mode 100644 arch/arm/mach-apple/lowlevel_init.S > > > > > > > create mode 100644 configs/apple_m1_defconfig > > > > > > > create mode 100644 include/configs/apple.h > > > > > > > [..] > > > > > > > diff --git a/arch/arm/mach-apple/lowlevel_init.S > > > > > > > b/arch/arm/mach-apple/lowlevel_init.S > > > > > > > new file mode 100644 > > > > > > > index 00..0f5313163e > > > > > > > --- /dev/null > > > > > > > +++ b/arch/arm/mach-apple/lowlevel_init.S > > > > > > > @@ -0,0 +1,16 @@ > > > > > > > +/* SPDX-License-Identifier: GPL-2.0+ */ > > > > > > > +/* > > > > > > > + * (C) Copyright 2021 Mark Kettenis > > > > > > > + */ > > > > > > > + > > > > > > > +.align 8 > > > > > > > +.global fw_dtb_pointer > > > > > > > +fw_dtb_pointer: > > > > > > > + .quad 0 > > > > > > > > > > > > Is this filled in by m1n1? > > > > > > > > > > Sorry I misread, so this is passed by m1n1 and filled in by U-Boot. I > > > > > think we should stop using CONFIG_OF_BOARD, and for such case we > > > > > should use CONFIG_OF_PRIOR_STAGE. > > > > > > > > Yes, CONFIG_OF_PRIOR_STAGE would work as well. But Tom was talking > > > > about removing that option in favour of CONFIG_OF_BOARD the other day. > > > > > > Yes. I was even looking for some feedback from you, Bin, on converting > > > some boards from CONFIG_OF_PRIOR_STAGE to CONFIG_OF_BOARD. It seems > > > like CONFIG_OF_PRIOR_STAGE is a subset of CONFIG_OF_BOARD, at the cost > > > of possibly a few bytes. > > > > Ah, I thought we wanted to do the other way around, by removing > > CONFIG_OF_BOARD, and convert that to CONFIG_OF_PRIORI_STAGE? > > I must say that I see some logic in keeping both, where > CONFIG_OF_BOARD indicates that the device tree is somehow stored on > the board and U-Boot has to run some code to fetch it, and > CONFIG_OF_PRIOR_STAGE is used when the device tree is provided by > firmware that runs before U-Boot. > > In that case I obviously should use CONFIG_OF_PRIOR_STAGE here. Well see Ilias' series where he proposed going with OF_BOARD! Tested on: Macbook Air M1 Tested-by: Simon Glass Regards, Simon
Re: [PATCH 3/5] misc: Add Apple DART driver
On Mon, 20 Sept 2021 at 19:11, Simon Glass wrote: > > Hi Mark, > > On Mon, 20 Sept 2021 at 02:33, Mark Kettenis wrote: > > > > > From: Simon Glass > > > Date: Sun, 19 Sep 2021 21:16:00 -0600 > > > > > > Hi Mark, > > > > > > On Sat, 18 Sept 2021 at 07:55, Mark Kettenis wrote: > > > > > > > > The DART is an IOMMU that is used on Apple's M1 SoC. This driver > > > > supports the DART in bypass mode as well as in a mode where it > > > > creates a 1:1 mapping of a subset of RAM as not all DARTs support > > > > bypass mode. The USB3 ports integrated on the SoC use a DART > > > > that supports bypass mode. The 1:1 mapping will be used in the > > > > future to support other devices such as the PCIe host bridge > > > > of the M1 SoC. > > > > > > > > Signed-off-by: Mark Kettenis > > > > --- > > > > drivers/misc/Kconfig | 7 ++ > > > > drivers/misc/Makefile | 1 + > > > > drivers/misc/apple_dart.c | 171 ++ > > > > 3 files changed, 179 insertions(+) > > > > create mode 100644 drivers/misc/apple_dart.c > > > > > Tested on: Macbook Air M1 Tested-by: Simon Glass
Re: [PATCH 5/5] doc: board: apple: Add Apple M1 documentation
On Sun, 19 Sept 2021 at 21:16, Simon Glass wrote: > > On Sat, 18 Sept 2021 at 07:56, Mark Kettenis wrote: > > > > Provide preliminary instructions on how to get U-Boot to run on > > Apple Silicon Macs. > > > > Signed-off-by: Mark Kettenis > > --- > > doc/board/apple/index.rst | 9 +++ > > doc/board/apple/m1.rst| 56 +++ > > doc/board/index.rst | 1 + > > 3 files changed, 66 insertions(+) > > create mode 100644 doc/board/apple/index.rst > > create mode 100644 doc/board/apple/m1.rst > > Reviewed-by: Simon Glass Tested on: Macbook Air M1 Tested-by: Simon Glass
Re: [PATCH 4/5] arm: dts: apple: Add preliminary device trees
On Sun, 19 Sept 2021 at 21:16, Simon Glass wrote: > > On Sat, 18 Sept 2021 at 07:56, Mark Kettenis wrote: > > > > Add preliminary device trees for the Apple M1 mini (2020) and > > Apple M1 Macbook Pro 13" (2020). Device tree bindings for > > the Apple M1 SoC are still being formalized and these device > > trees will be synchronized with the Linux kernel as needed. > > > > These device trees are provided as a reference only as U-Boot > > uses the device tree passed by the m1n1 bootloader. > > > > Signed-off-by: Mark Kettenis > > --- > > arch/arm/dts/t8103-j274.dts | 135 + > > arch/arm/dts/t8103-j293.dts | 97 > > arch/arm/dts/t8103.dtsi | 506 ++ > > .../interrupt-controller/apple-aic.h | 15 + > > include/dt-bindings/pinctrl/apple.h | 13 + > > include/dt-bindings/spmi/spmi.h | 10 + > > 6 files changed, 776 insertions(+) > > create mode 100644 arch/arm/dts/t8103-j274.dts > > create mode 100644 arch/arm/dts/t8103-j293.dts > > create mode 100644 arch/arm/dts/t8103.dtsi > > create mode 100644 include/dt-bindings/interrupt-controller/apple-aic.h > > create mode 100644 include/dt-bindings/pinctrl/apple.h > > create mode 100644 include/dt-bindings/spmi/spmi.h > > Reviewed-by: Simon Glass Tested on: Macbook Air M1 Tested-by: Simon Glass
Re: [PATCH 1/3] video: Add 30bpp support
On Thu, 16 Sept 2021 at 07:01, Mark Kettenis wrote: > > Add support for 30bpp mode where pixels are picked in 32-bit > integers but use 10 bits instead of 8 bits for each component. > > Signed-off-by: Mark Kettenis > --- > drivers/video/console_normal.c| 2 ++ > drivers/video/console_rotate.c| 6 ++ > drivers/video/console_truetype.c | 3 +++ > drivers/video/vidconsole-uclass.c | 7 +++ > drivers/video/video-uclass.c | 1 + > include/video.h | 1 + > 6 files changed, 20 insertions(+) > > diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c > index 04f022491e..e0b89cbb93 100644 > --- a/drivers/video/console_normal.c > +++ b/drivers/video/console_normal.c > @@ -41,6 +41,7 @@ static int console_normal_set_row(struct udevice *dev, uint > row, int clr) > end = dst; > break; > } > + case VIDEO_BPP30: > case VIDEO_BPP32: > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > uint32_t *dst = line; > @@ -126,6 +127,7 @@ static int console_normal_putc_xy(struct udevice *dev, > uint x_frac, uint y, > } > break; > } > + case VIDEO_BPP30: > case VIDEO_BPP32: > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > uint32_t *dst = line; > diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c > index 36c8d0609d..bf81b80a39 100644 > --- a/drivers/video/console_rotate.c > +++ b/drivers/video/console_rotate.c > @@ -40,6 +40,7 @@ static int console_set_row_1(struct udevice *dev, uint row, > int clr) > *dst++ = clr; > break; > } > + case VIDEO_BPP30: > case VIDEO_BPP32: > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > uint32_t *dst = line; > @@ -128,6 +129,7 @@ static int console_putc_xy_1(struct udevice *dev, uint > x_frac, uint y, char ch) > } > break; > } > + case VIDEO_BPP30: > case VIDEO_BPP32: > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > uint32_t *dst = line; > @@ -183,6 +185,7 @@ static int console_set_row_2(struct udevice *dev, uint > row, int clr) > end = dst; > break; > } > + case VIDEO_BPP30: > case VIDEO_BPP32: > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > uint32_t *dst = line; > @@ -266,6 +269,7 @@ static int console_putc_xy_2(struct udevice *dev, uint > x_frac, uint y, char ch) > } > break; > } > + case VIDEO_BPP30: > case VIDEO_BPP32: > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > uint32_t *dst = line; > @@ -318,6 +322,7 @@ static int console_set_row_3(struct udevice *dev, uint > row, int clr) > *dst++ = clr; > break; > } > + case VIDEO_BPP30: > case VIDEO_BPP32: > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > uint32_t *dst = line; > @@ -402,6 +407,7 @@ static int console_putc_xy_3(struct udevice *dev, uint > x_frac, uint y, char ch) > } > break; > } > + case VIDEO_BPP30: > case VIDEO_BPP32: > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > uint32_t *dst = line; > diff --git a/drivers/video/console_truetype.c > b/drivers/video/console_truetype.c > index 98427f4c61..0195d996de 100644 > --- a/drivers/video/console_truetype.c > +++ b/drivers/video/console_truetype.c > @@ -153,6 +153,7 @@ static int console_truetype_set_row(struct udevice *dev, > uint row, int clr) > } > #endif > #ifdef CONFIG_VIDEO_BPP32 > + case VIDEO_BPP30: > case VIDEO_BPP32: { > u32 *dst = line; > > @@ -299,6 +300,7 @@ static int console_truetype_putc_xy(struct udevice *dev, > uint x, uint y, > } > #endif > #ifdef CONFIG_VIDEO_BPP32 > + case VIDEO_BPP30: > case VIDEO_BPP32: { > u32 *dst = (u32 *)line + xoff; > int i; > @@ -381,6 +383,7 @@ static int console_truetype_erase(struct udevice *dev, > int xstart, int ystart, > } > #endif > #ifdef CONFIG_VIDEO_BPP32 > + case
Re: [PATCH 3/3] video: simplefb: Add 30bpp support
On Thu, 16 Sept 2021 at 07:02, Mark Kettenis wrote: > > Recognize the canonical format strings for framebuffers in > 30bpp mode. > > Signed-off-by: Mark Kettenis > --- > drivers/video/simplefb.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/video/simplefb.c b/drivers/video/simplefb.c > index fd58426cf5..7e1cc4560f 100644 > --- a/drivers/video/simplefb.c > +++ b/drivers/video/simplefb.c > @@ -52,6 +52,9 @@ static int simple_video_probe(struct udevice *dev) > uc_priv->bpix = VIDEO_BPP16; > } else if (strcmp(format, "a8b8g8r8") == 0) { > uc_priv->bpix = VIDEO_BPP32; > + } else if (strcmp(format, "a2r10g10b10") == 0 || > + strcmp(format, "x2r10g10b10") == 0) { > + uc_priv->bpix = VIDEO_BPP30; > } else { > printf("%s: invalid format: %s\n", __func__, format); > return -EINVAL; > -- > 2.33.0 > Reviewed-by: Simon Glass Tested on: Macbook Air M1 Tested-by: Simon Glass
Re: [PATCH 2/3] efi_loader: GOP: Add 30bpp support
Hi Mark, On Thu, 16 Sept 2021 at 07:02, Mark Kettenis wrote: > > Provide correct framebuffer information for 30bpp modes. > > Signed-off-by: Mark Kettenis > --- > lib/efi_loader/efi_gop.c | 10 ++ > 1 file changed, 10 insertions(+) > > diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c > index 1206b2d7a2..42bf49b184 100644 > --- a/lib/efi_loader/efi_gop.c > +++ b/lib/efi_loader/efi_gop.c > @@ -227,6 +227,7 @@ static efi_uintn_t gop_get_bpp(struct efi_gop *this) > > switch (gopobj->bpix) { > #ifdef CONFIG_DM_VIDEO > + case VIDEO_BPP30: > case VIDEO_BPP32: > #else > case LCD_COLOR32: > @@ -468,6 +469,7 @@ efi_status_t efi_gop_register(void) > switch (bpix) { > #ifdef CONFIG_DM_VIDEO > case VIDEO_BPP16: > + case VIDEO_BPP30: > case VIDEO_BPP32: > #else > case LCD_COLOR32: > @@ -518,6 +520,14 @@ efi_status_t efi_gop_register(void) > #endif > { > gopobj->info.pixel_format = EFI_GOT_BGRA8; > +#ifdef CONFIG_DM_VIDEO Can avoid #ifdefs please? Does this work? if (IS_ENABLED(CONFIG_DM_VIDEO) && IS_ENABLED(CONFIG_VIDEO_BPP30) && bpix == VIDEO_BPP30) Heinrich might know if we can just require DM_VIDEO. > + } else if (bpix == VIDEO_BPP30) { > + gopobj->info.pixel_format = EFI_GOT_BITMASK; > + gopobj->info.pixel_bitmask[0] = 0x3ff0; /* red */ > + gopobj->info.pixel_bitmask[1] = 0x000ffc00; /* green */ > + gopobj->info.pixel_bitmask[2] = 0x03ff; /* blue */ > + gopobj->info.pixel_bitmask[3] = 0xc000; /* reserved */ > +#endif > } else { > gopobj->info.pixel_format = EFI_GOT_BITMASK; > gopobj->info.pixel_bitmask[0] = 0xf800; /* red */ > -- > 2.33.0 > Tested on: Macbook Air M1 Tested-by: Simon Glass Regards, Simon
Re: [PATCH] ARM: vexpress_ca9x4: Correct missing SYS_LOAD_ADDR
On Sat, Sep 25, 2021 at 07:04:18AM -0600, Simon Glass wrote: > Add this missing option since it otherwise causes the build to fail in > an infinite loop of: > >Address in memory to use by default (SYS_LOAD_ADDR) [] (NEW) >Error in reading or end of file. > > Signed-off-by: Simon Glass > Fixes: 15e30106ce6 (ARM: vexpress_ca9x4: Reintroduce board in order to use > with QEMU.") I pushed something like this through last night, FYI. -- Tom signature.asc Description: PGP signature
Re: [RFC PATCH] RFC: Replace CONFIG_SYS_BAUDRATE_TABLE by board and UART driver rounding functions
On Sat, Sep 25, 2021 at 02:19:58PM +0200, Pali Rohár wrote: > Add new functions which returns the nearest baudrate and use them instead > of hardcoded and incomplete CONFIG_SYS_BAUDRATE_TABLE compile time option. > > Add implementation of rounding function for serial_mvebu_a3700 driver and > also for A3720 Espressobin board which has integrated pl2303 USB<->UART > converter, which basically limits baudrates which can user set. > > Completely remove CONFIG_SYS_BAUDRATE_TABLE defines from all A3720 boards > as now with rounding functions it is not used anymore. > > NOTE: This is just an example how to kill CONFIG_SYS_BAUDRATE_TABLE compile > time definitions. I tested it that it works on A3720 Turris Mox board. I > have not tested A3720 Espressobin board yet. > > More discussion on this approach is required, so take this just as RFC > change. > > Signed-off-by: Pali Rohár Thanks for doing this. My first question is, is this really per-board? Or per SoC / UART chipset. I would hope for example that for plain old ns16550s this would be a generic function, perhaps with an optional board call-out for board design limitations. This does feel like a reasonable amount of code for platforms like this that were supporting what was the maximal rate table before. -- Tom signature.asc Description: PGP signature
Re: [PATCH 0/5] Apple M1 Support
> From: Simon Glass > Date: Sat, 25 Sep 2021 07:27:41 -0600 > > Hi Mark, > > On Sat, 25 Sept 2021 at 02:11, Mark Kettenis wrote: > > > > > From: Simon Glass > > > Date: Fri, 24 Sep 2021 19:20:32 -0600 > > > > > > Hi Mark, > > > > > > On Sat, 18 Sept 2021 at 07:54, Mark Kettenis wrote: > > > > > > > > This series adds basic support for Apple's M1 SoC to U-Boot. > > > > This builds a basic U-Boot that can be used as a payload > > > > for the m1n1 boot loader being developed by the Asahi Linux > > > > project. > > > > > > > > The goal here is to privide an UEFI interface on these machines that > > > > > > provide > > > > > > > allows booting various open source OSes. This initial series provides > > > > support for the serial port, framebuffer and the USB 3.1 Type-C ports. > > > > It can boot a support OS (e.g. OpenBSD/arm64) from a USB disk. > > > > > > > > Mark Kettenis (5): > > > > arm: apple: Add initial support for Apple's M1 SoC > > > > serial: s5p: Add Apple M1 support > > > > misc: Add Apple DART driver > > > > arm: dts: apple: Add preliminary device trees > > > > doc: board: apple: Add Apple M1 documentation > > > > > > > > arch/arm/Kconfig | 22 + > > > > arch/arm/Makefile | 1 + > > > > arch/arm/dts/t8103-j274.dts | 135 + > > > > arch/arm/dts/t8103-j293.dts | 97 > > > > arch/arm/dts/t8103.dtsi | 506 ++ > > > > arch/arm/include/asm/arch-m1/clk.h| 11 + > > > > arch/arm/include/asm/arch-m1/uart.h | 41 ++ > > > > arch/arm/mach-apple/Kconfig | 18 + > > > > arch/arm/mach-apple/Makefile | 4 + > > > > arch/arm/mach-apple/board.c | 163 ++ > > > > arch/arm/mach-apple/lowlevel_init.S | 16 + > > > > configs/apple_m1_defconfig| 14 + > > > > doc/board/apple/index.rst | 9 + > > > > doc/board/apple/m1.rst| 54 ++ > > > > doc/board/index.rst | 1 + > > > > drivers/misc/Kconfig | 7 + > > > > drivers/misc/Makefile | 1 + > > > > drivers/misc/apple_dart.c | 171 ++ > > > > drivers/serial/Kconfig| 2 +- > > > > drivers/serial/serial_s5p.c | 22 + > > > > include/configs/apple.h | 38 ++ > > > > .../interrupt-controller/apple-aic.h | 15 + > > > > include/dt-bindings/pinctrl/apple.h | 13 + > > > > include/dt-bindings/spmi/spmi.h | 10 + > > > > 24 files changed, 1370 insertions(+), 1 deletion(-) > > > > create mode 100644 arch/arm/dts/t8103-j274.dts > > > > create mode 100644 arch/arm/dts/t8103-j293.dts > > > > create mode 100644 arch/arm/dts/t8103.dtsi > > > > create mode 100644 arch/arm/include/asm/arch-m1/clk.h > > > > create mode 100644 arch/arm/include/asm/arch-m1/uart.h > > > > create mode 100644 arch/arm/mach-apple/Kconfig > > > > create mode 100644 arch/arm/mach-apple/Makefile > > > > create mode 100644 arch/arm/mach-apple/board.c > > > > create mode 100644 arch/arm/mach-apple/lowlevel_init.S > > > > create mode 100644 configs/apple_m1_defconfig > > > > create mode 100644 doc/board/apple/index.rst > > > > create mode 100644 doc/board/apple/m1.rst > > > > create mode 100644 drivers/misc/apple_dart.c > > > > create mode 100644 include/configs/apple.h > > > > create mode 100644 include/dt-bindings/interrupt-controller/apple-aic.h > > > > create mode 100644 include/dt-bindings/pinctrl/apple.h > > > > create mode 100644 include/dt-bindings/spmi/spmi.h > > > > > > > > -- > > > > 2.33.0 > > > > > > > > > > I gave this a whirl on a Macbook Air A2337 and needed the patch below > > > to build the devicetree files. Sorry the formatting is broken. > > > > > > Also when booting I get this: > > > > > > ... > > > Preparing to boot kernel at 0x80820 with fdt at 0x8082e8000 > > > Valid payload found > > > Preparing to run next stage at 0x80820... > > > MMU: shutting down... > > > MMU: shutdown successful, clearing caches > > > > > > > > > Then the display clears and it hangs. If I try the J274 devicetree it > > > just reboots at that point. > > > > > > What should I expect? I was hoping for console output as I don't have > > > serial connected. I don't have a suitable serial cable, and the USB > > > gadget mode did not result in a ttyACM0 device appearing. > > > > For framebuffer support you also need the "30bpp framebuffer support" > > series I posted earlier: > > > > https://patchwork.ozlabs.org/project/uboot/list/?series=262617 > > > > With that your should get the usual U-Boot output on the screen. I've > > not tested the Air, but it should work there. > > Ah OK, yes that fixes it, thanks! > > So how do I get the keyboard to work in U-Boot? Or are you using > s
[PATCH] arm: spl: flush and disable cache before jumping to OPTEE
From: Ricardo Salveti Make sure to flush, disable caches and interrupts before jumpint to OPTEE. This fixes the SDP->SPL->OPTEE boot flow on iMX6Q and most likely on some other ARM SoCs. Signed-off-by: Ricardo Salveti Co-developed-by: Oleksandr Suvorov Signed-off-by: Oleksandr Suvorov --- arch/arm/lib/spl.c | 11 +++ common/spl/spl.c | 11 +-- include/spl.h | 9 + 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/arch/arm/lib/spl.c b/arch/arm/lib/spl.c index 8e2bdf3536..16e3cd557a 100644 --- a/arch/arm/lib/spl.c +++ b/arch/arm/lib/spl.c @@ -77,3 +77,14 @@ void __noreturn jump_to_image_linux(struct spl_image_info *spl_image) } #endif /* CONFIG_ARM64 */ #endif + +#if CONFIG_IS_ENABLED(OPTEE) +void __noreturn jump_to_image_optee(struct spl_image_info *spl_image) +{ + /* flush and turn off caches before jumping to OPTEE */ + cleanup_before_linux(); + + spl_optee_entry(NULL, NULL, spl_image->fdt_addr, + (void *)spl_image->entry_point); +} +#endif diff --git a/common/spl/spl.c b/common/spl/spl.c index d55d3c2848..f3fab3c4d9 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -171,6 +171,14 @@ __weak void spl_board_prepare_for_optee(void *fdt) { } +#if CONFIG_IS_ENABLED(OPTEE) +__weak void __noreturn jump_to_image_optee(struct spl_image_info *spl_image) +{ + spl_optee_entry(NULL, NULL, spl_image->fdt_addr, + (void *)spl_image->entry_point); +} +#endif + __weak void spl_board_prepare_for_boot(void) { /* Nothing to do! */ @@ -777,8 +785,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2) case IH_OS_TEE: debug("Jumping to U-Boot via OP-TEE\n"); spl_board_prepare_for_optee(spl_image.fdt_addr); - spl_optee_entry(NULL, NULL, spl_image.fdt_addr, - (void *)spl_image.entry_point); + jump_to_image_optee(&spl_image); break; #endif #if CONFIG_IS_ENABLED(OPENSBI) diff --git a/include/spl.h b/include/spl.h index afbf39bef4..8e7173d294 100644 --- a/include/spl.h +++ b/include/spl.h @@ -460,6 +460,15 @@ int spl_board_boot_device(u32 boot_device); */ void __noreturn jump_to_image_linux(struct spl_image_info *spl_image); +/** + * jump_to_image_linux() - Jump to OP-TEE OS from SPL + * + * This jumps into OP-TEE OS using the information in @spl_image. + * + * @spl_image: Image description to set up + */ +void __noreturn jump_to_image_optee(struct spl_image_info *spl_image); + /** * spl_start_uboot() - Check if SPL should start the kernel or U-Boot * -- 2.31.1
Re: [RFC PATCH] RFC: Replace CONFIG_SYS_BAUDRATE_TABLE by board and UART driver rounding functions
On Saturday 25 September 2021 09:51:08 Tom Rini wrote: > On Sat, Sep 25, 2021 at 02:19:58PM +0200, Pali Rohár wrote: > > > Add new functions which returns the nearest baudrate and use them instead > > of hardcoded and incomplete CONFIG_SYS_BAUDRATE_TABLE compile time option. > > > > Add implementation of rounding function for serial_mvebu_a3700 driver and > > also for A3720 Espressobin board which has integrated pl2303 USB<->UART > > converter, which basically limits baudrates which can user set. > > > > Completely remove CONFIG_SYS_BAUDRATE_TABLE defines from all A3720 boards > > as now with rounding functions it is not used anymore. > > > > NOTE: This is just an example how to kill CONFIG_SYS_BAUDRATE_TABLE compile > > time definitions. I tested it that it works on A3720 Turris Mox board. I > > have not tested A3720 Espressobin board yet. > > > > More discussion on this approach is required, so take this just as RFC > > change. > > > > Signed-off-by: Pali Rohár > > Thanks for doing this. My first question is, is this really per-board? There is per UART chipset rounding / limitation and this should be implemented in UART driver (like I did it in serial_mvebu_a3700.c). Then there can be per SoC limitation, e.g. SoC has unstable clock source for high baudrates. Meaning that UART chipset can support higher baudrates (as exposed by UART driver) but for some reasons they are not possible on SoC. And then there can be really per-board limitations, like it is for Espressobin board. In most cases SoC has UART pins which people can connect to other UART device (e.g. to other SoC with UART or to some universal USB<->UART cables for "computers"). But Espressobin board has integrated pl2303 chip which is soldered directly to A3720 SoC UART pins. This pl2303 chip is USB<->UART converter and board itself has just micro-USB port (which is soldered to this pl2303). So at the end you can on this board use UART only via that integrated micro-USB port, which talks with standard USB protocol. Therefore on this board you have two limitations for UART baudrates. First one is exposed by UART SoC chip (serial_mvebu_a3700.c) and second one is exposed by what that pl2303 supports. And this second limitation is board specific -- not A3720 SoC. Other boards with A3720 SoC, e.g. Turris Mox has exposed directly UART pins and you are free to connect any USB<->UART cable to these pins as you want. And this design with soldered USB<->UART chip on the board is not rare. So U-Boot should have better support for it. Note that lot of times clock source for these USB<->UART chips and SoC UART chip is different (because these USB based chips have its own clock source). So there are less common supported baudrates which can be used on the boards. And when talking about high speed baudrates (above 115200 bauds) then lot of times these "common supported baudrates" are just non-standard baudrate numbers (e.g. 3 125 000 bauds). Because you have to choose divisors both both chips to produce baudrate with only about 2-3% difference. > Or per SoC / UART chipset. I would hope for example that for plain old > ns16550s this would be a generic function, perhaps with an optional > board call-out for board design limitations. This does feel like a > reasonable amount of code for platforms like this that were supporting > what was the maximal rate table before. > > -- > Tom
Re: [PATCH 0/5] Apple M1 Support
Hi Mark, On Sat, 25 Sept 2021 at 07:52, Mark Kettenis wrote: > > > From: Simon Glass > > Date: Sat, 25 Sep 2021 07:27:41 -0600 > > > > Hi Mark, > > > > On Sat, 25 Sept 2021 at 02:11, Mark Kettenis > > wrote: > > > > > > > From: Simon Glass > > > > Date: Fri, 24 Sep 2021 19:20:32 -0600 > > > > > > > > Hi Mark, > > > > > > > > On Sat, 18 Sept 2021 at 07:54, Mark Kettenis > > > > wrote: > > > > > > > > > > This series adds basic support for Apple's M1 SoC to U-Boot. > > > > > This builds a basic U-Boot that can be used as a payload > > > > > for the m1n1 boot loader being developed by the Asahi Linux > > > > > project. > > > > > > > > > > The goal here is to privide an UEFI interface on these machines that > > > > > > > > provide > > > > > > > > > allows booting various open source OSes. This initial series provides > > > > > support for the serial port, framebuffer and the USB 3.1 Type-C ports. > > > > > It can boot a support OS (e.g. OpenBSD/arm64) from a USB disk. > > > > > > > > > > Mark Kettenis (5): > > > > > arm: apple: Add initial support for Apple's M1 SoC > > > > > serial: s5p: Add Apple M1 support > > > > > misc: Add Apple DART driver > > > > > arm: dts: apple: Add preliminary device trees > > > > > doc: board: apple: Add Apple M1 documentation > > > > > > > > > > arch/arm/Kconfig | 22 + > > > > > arch/arm/Makefile | 1 + > > > > > arch/arm/dts/t8103-j274.dts | 135 + > > > > > arch/arm/dts/t8103-j293.dts | 97 > > > > > arch/arm/dts/t8103.dtsi | 506 > > > > > ++ > > > > > arch/arm/include/asm/arch-m1/clk.h| 11 + > > > > > arch/arm/include/asm/arch-m1/uart.h | 41 ++ > > > > > arch/arm/mach-apple/Kconfig | 18 + > > > > > arch/arm/mach-apple/Makefile | 4 + > > > > > arch/arm/mach-apple/board.c | 163 ++ > > > > > arch/arm/mach-apple/lowlevel_init.S | 16 + > > > > > configs/apple_m1_defconfig| 14 + > > > > > doc/board/apple/index.rst | 9 + > > > > > doc/board/apple/m1.rst| 54 ++ > > > > > doc/board/index.rst | 1 + > > > > > drivers/misc/Kconfig | 7 + > > > > > drivers/misc/Makefile | 1 + > > > > > drivers/misc/apple_dart.c | 171 ++ > > > > > drivers/serial/Kconfig| 2 +- > > > > > drivers/serial/serial_s5p.c | 22 + > > > > > include/configs/apple.h | 38 ++ > > > > > .../interrupt-controller/apple-aic.h | 15 + > > > > > include/dt-bindings/pinctrl/apple.h | 13 + > > > > > include/dt-bindings/spmi/spmi.h | 10 + > > > > > 24 files changed, 1370 insertions(+), 1 deletion(-) > > > > > create mode 100644 arch/arm/dts/t8103-j274.dts > > > > > create mode 100644 arch/arm/dts/t8103-j293.dts > > > > > create mode 100644 arch/arm/dts/t8103.dtsi > > > > > create mode 100644 arch/arm/include/asm/arch-m1/clk.h > > > > > create mode 100644 arch/arm/include/asm/arch-m1/uart.h > > > > > create mode 100644 arch/arm/mach-apple/Kconfig > > > > > create mode 100644 arch/arm/mach-apple/Makefile > > > > > create mode 100644 arch/arm/mach-apple/board.c > > > > > create mode 100644 arch/arm/mach-apple/lowlevel_init.S > > > > > create mode 100644 configs/apple_m1_defconfig > > > > > create mode 100644 doc/board/apple/index.rst > > > > > create mode 100644 doc/board/apple/m1.rst > > > > > create mode 100644 drivers/misc/apple_dart.c > > > > > create mode 100644 include/configs/apple.h > > > > > create mode 100644 > > > > > include/dt-bindings/interrupt-controller/apple-aic.h > > > > > create mode 100644 include/dt-bindings/pinctrl/apple.h > > > > > create mode 100644 include/dt-bindings/spmi/spmi.h > > > > > > > > > > -- > > > > > 2.33.0 > > > > > > > > > > > > > I gave this a whirl on a Macbook Air A2337 and needed the patch below > > > > to build the devicetree files. Sorry the formatting is broken. > > > > > > > > Also when booting I get this: > > > > > > > > ... > > > > Preparing to boot kernel at 0x80820 with fdt at 0x8082e8000 > > > > Valid payload found > > > > Preparing to run next stage at 0x80820... > > > > MMU: shutting down... > > > > MMU: shutdown successful, clearing caches > > > > > > > > > > > > Then the display clears and it hangs. If I try the J274 devicetree it > > > > just reboots at that point. > > > > > > > > What should I expect? I was hoping for console output as I don't have > > > > serial connected. I don't have a suitable serial cable, and the USB > > > > gadget mode did not result in a ttyACM0 device appearing. > > > > > > For framebuffer support you also need the "30bpp framebuffer support" > > > series I posted earlier: > > > >
Re: [PATCH] ARM: vexpress_ca9x4: Correct missing SYS_LOAD_ADDR
Hi Tom, On Sat, 25 Sept 2021 at 07:47, Tom Rini wrote: > > On Sat, Sep 25, 2021 at 07:04:18AM -0600, Simon Glass wrote: > > > Add this missing option since it otherwise causes the build to fail in > > an infinite loop of: > > > >Address in memory to use by default (SYS_LOAD_ADDR) [] (NEW) > >Error in reading or end of file. > > > > Signed-off-by: Simon Glass > > Fixes: 15e30106ce6 (ARM: vexpress_ca9x4: Reintroduce board in order to use > > with QEMU.") > > I pushed something like this through last night, FYI. OK ta, should have checked this morning! - Simon
[PATCH V2] configs: omap3x_logic: Enable LTO on more LogicPD OMAP3 boards
There are five omap3 based boards from LogicPD. Two of them have added LTO support. Add the remaining three to use LTO. Signed-off-by: Adam Ford --- V2: Rebase diff --git a/configs/omap35_logic_defconfig b/configs/omap35_logic_defconfig index 8b0c943024..5c1e19555c 100644 --- a/configs/omap35_logic_defconfig +++ b/configs/omap35_logic_defconfig @@ -12,6 +12,7 @@ CONFIG_SPL_TEXT_BASE=0x4020 CONFIG_TARGET_OMAP3_LOGIC=y # CONFIG_SPL_OMAP3_ID_NAND is not set CONFIG_SPL=y +CONFIG_LTO=y CONFIG_DISTRO_DEFAULTS=y CONFIG_ANDROID_BOOT_IMAGE=y # CONFIG_USE_BOOTCOMMAND is not set diff --git a/configs/omap35_logic_somlv_defconfig b/configs/omap35_logic_somlv_defconfig index 2ab92551e4..deaabace4c 100644 --- a/configs/omap35_logic_somlv_defconfig +++ b/configs/omap35_logic_somlv_defconfig @@ -12,6 +12,7 @@ CONFIG_SPL_TEXT_BASE=0x4020 CONFIG_TARGET_OMAP3_LOGIC=y # CONFIG_SPL_OMAP3_ID_NAND is not set CONFIG_SPL=y +CONFIG_LTO=y CONFIG_DISTRO_DEFAULTS=y CONFIG_ANDROID_BOOT_IMAGE=y # CONFIG_USE_BOOTCOMMAND is not set diff --git a/configs/omap3_logic_somlv_defconfig b/configs/omap3_logic_somlv_defconfig index f2e9d20e8f..a1e4c95edf 100644 --- a/configs/omap3_logic_somlv_defconfig +++ b/configs/omap3_logic_somlv_defconfig @@ -12,6 +12,7 @@ CONFIG_SPL_TEXT_BASE=0x4020 CONFIG_TARGET_OMAP3_LOGIC=y # CONFIG_SPL_OMAP3_ID_NAND is not set CONFIG_SPL=y +CONFIG_LTO=y CONFIG_DISTRO_DEFAULTS=y CONFIG_ANDROID_BOOT_IMAGE=y # CONFIG_USE_BOOTCOMMAND is not set -- 2.25.1
Re: [PATCH 1/3] Add fdt network helper header file
Hi Tony, On Thu, 5 Aug 2021 at 22:50, Tony Dinh wrote: > > Add include header file include/fdt_support_net.h > > Signed-off-by: Tony Dinh > --- > > include/fdt_support_net.h | 39 +++ > 1 file changed, 39 insertions(+) > create mode 100644 include/fdt_support_net.h Sorry for the delay but I am only now coming to this after being away for a month and finding it in my queue. Can you please - move this to drivers/core/of_extra.c and include/dm/ofnode.h - use the livetree interface (ofnode) instead of fdt - merge everything into a single patch since the first patch creates a build error Regards, Simon
[PATCH] imx: syscounter: allow timer_init for SPL build
From: Michael Scott If we enable SPL and SKIP_LOWLEVEL_INIT, this results in the weak function timer_init() being used in the SPL build. This is not desirable as on iMX6 SoC, MMC will then fail once u-boot proper is booted due to timing issue. Fixes: be277c3a89 ("imx: mx7: avoid some initialization if low level is skipped") Signed-off-by: Michael Scott Signed-off-by: Oleksandr Suvorov --- arch/arm/mach-imx/syscounter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/syscounter.c b/arch/arm/mach-imx/syscounter.c index 6dfed365d2..e69a168a95 100644 --- a/arch/arm/mach-imx/syscounter.c +++ b/arch/arm/mach-imx/syscounter.c @@ -59,7 +59,7 @@ static inline unsigned long long us_to_tick(unsigned long long usec) return usec; } -#ifndef CONFIG_SKIP_LOWLEVEL_INIT +#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) || defined(CONFIG_SPL_BUILD) int timer_init(void) { struct sctr_regs *sctr = (struct sctr_regs *)SCTR_BASE_ADDR; -- 2.31.1
Re: [PATCH v3 2/3] arm: Add an __image_copy_start symbol for ARMv8
Hi Scott, On Thu, 5 Aug 2021 at 13:20, Simon Glass wrote: > > Hi Scott, > > On Wed, 4 Aug 2021 at 13:53, Scott Wood wrote: > > > > On Sun, 2021-08-01 at 14:59 -0600, Simon Glass wrote: > > > This symbol is needed for binman to locate the start of the image. Add it. > > > > > > Note: the existing line to bring in the .__image_copy_start symbol does > > > not appear to do anything. > > > > > > Signed-off-by: Simon Glass > > > --- > > > I have copied Scott Wood who originally added the line about the > > > __image_copy_start in the hope that he can decide if we should remove it. > > > > It's been a long time since I looked at this stuff, but __image_copy_start > > is > > used for relocation and that code does not seem to be in the SPL, so the > > *(.__image_copy_start) was probably just a copy-and-paste leftover from the > > main SPL that can go away. > > > > Of course, that doesn't resolve the binman issue. :-) > > > > > diff --git a/arch/arm/cpu/armv8/u-boot-spl.lds > > > b/arch/arm/cpu/armv8/u-boot- > > > spl.lds > > > index 9edb662b094..2827a07590d 100644 > > > --- a/arch/arm/cpu/armv8/u-boot-spl.lds > > > +++ b/arch/arm/cpu/armv8/u-boot-spl.lds > > > @@ -22,6 +22,7 @@ ENTRY(_start) > > > SECTIONS > > > { > > > .text : { > > > + __image_copy_start = .; > > > . = ALIGN(8); > > > *(.__image_copy_start) > > > CPUDIR/start.o (.text*) > > > > If for whatever reason you did need to define the symbol this way, shouldn't > > it be after the alignment? > > Well I don't want to miss out any of the image, otherwise the offsets > would be off. > > But perhaps that is another question. Since this is the first section, > it should already be aligned (to 16 I suspect). So why do we need it? I'd like to get this applied, assuming it is correct, because at present binman is silently ignoring problems where it cannot find symbols. The fix for that is: http://patchwork.ozlabs.org/project/uboot/patch/20210722210216.1.Id1246d1ff1cb5750f8c7ddde9665cf6f09615a7c@changeid/ which has been sitting there for a while. Regards, Simon
Re: [PATCH u-boot-marvell] arm: mvebu: turris_omnia: fix leaked mtd device
On Saturday 25 September 2021 02:49:18 Marek Behún wrote: > From: Marek Behún > > After getting MTD device via get_mtd_device_nm(), we need to put it with > put_mtd_device(), otherwise we get > > Removing MTD device #0 (mx25l6405d) with use count 1 > > before booting kernel. > > Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Tested-by: Pali Rohár Fixes: 92f36c8e74c1 ("arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB") Above commit was introduced in v2021.10-rc1, so I think this fixup should go into v2021.10. Stefan, what do you think? > --- > board/CZ.NIC/turris_omnia/turris_omnia.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c > b/board/CZ.NIC/turris_omnia/turris_omnia.c > index bac78af04e..a48e1f5c30 100644 > --- a/board/CZ.NIC/turris_omnia/turris_omnia.c > +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c > @@ -647,10 +647,13 @@ int ft_board_setup(void *blob, struct bd_info *bd) > if (!fixup_mtd_partitions(blob, node, mtd)) > goto fail; > > + put_mtd_device(mtd); > return 0; > > fail: > printf("Failed fixing SPI NOR partitions!\n"); > + if (!IS_ERR_OR_NULL(mtd)) > + put_mtd_device(mtd); > return 0; > } > #endif > -- > 2.32.0 >
Re: [PATCH 0/5] Apple M1 Support
> From: Simon Glass > Date: Sat, 25 Sep 2021 08:42:30 -0600 > > Hi Mark, > > On Sat, 25 Sept 2021 at 07:52, Mark Kettenis wrote: > > > > > From: Simon Glass > > > Date: Sat, 25 Sep 2021 07:27:41 -0600 > > > > > > Hi Mark, > > > > > > On Sat, 25 Sept 2021 at 02:11, Mark Kettenis > > > wrote: > > > > > > > > > From: Simon Glass > > > > > Date: Fri, 24 Sep 2021 19:20:32 -0600 > > > > > > > > > > Hi Mark, > > > > > > > > > > On Sat, 18 Sept 2021 at 07:54, Mark Kettenis > > > > > wrote: > > > > > > > > > > > > This series adds basic support for Apple's M1 SoC to U-Boot. > > > > > > This builds a basic U-Boot that can be used as a payload > > > > > > for the m1n1 boot loader being developed by the Asahi Linux > > > > > > project. > > > > > > > > > > > > The goal here is to privide an UEFI interface on these machines that > > > > > > > > > > provide > > > > > > > > > > > allows booting various open source OSes. This initial series > > > > > > provides > > > > > > support for the serial port, framebuffer and the USB 3.1 Type-C > > > > > > ports. > > > > > > It can boot a support OS (e.g. OpenBSD/arm64) from a USB disk. > > > > > > > > > > > > Mark Kettenis (5): > > > > > > arm: apple: Add initial support for Apple's M1 SoC > > > > > > serial: s5p: Add Apple M1 support > > > > > > misc: Add Apple DART driver > > > > > > arm: dts: apple: Add preliminary device trees > > > > > > doc: board: apple: Add Apple M1 documentation > > > > > > > > > > > > arch/arm/Kconfig | 22 + > > > > > > arch/arm/Makefile | 1 + > > > > > > arch/arm/dts/t8103-j274.dts | 135 + > > > > > > arch/arm/dts/t8103-j293.dts | 97 > > > > > > arch/arm/dts/t8103.dtsi | 506 > > > > > > ++ > > > > > > arch/arm/include/asm/arch-m1/clk.h| 11 + > > > > > > arch/arm/include/asm/arch-m1/uart.h | 41 ++ > > > > > > arch/arm/mach-apple/Kconfig | 18 + > > > > > > arch/arm/mach-apple/Makefile | 4 + > > > > > > arch/arm/mach-apple/board.c | 163 ++ > > > > > > arch/arm/mach-apple/lowlevel_init.S | 16 + > > > > > > configs/apple_m1_defconfig| 14 + > > > > > > doc/board/apple/index.rst | 9 + > > > > > > doc/board/apple/m1.rst| 54 ++ > > > > > > doc/board/index.rst | 1 + > > > > > > drivers/misc/Kconfig | 7 + > > > > > > drivers/misc/Makefile | 1 + > > > > > > drivers/misc/apple_dart.c | 171 ++ > > > > > > drivers/serial/Kconfig| 2 +- > > > > > > drivers/serial/serial_s5p.c | 22 + > > > > > > include/configs/apple.h | 38 ++ > > > > > > .../interrupt-controller/apple-aic.h | 15 + > > > > > > include/dt-bindings/pinctrl/apple.h | 13 + > > > > > > include/dt-bindings/spmi/spmi.h | 10 + > > > > > > 24 files changed, 1370 insertions(+), 1 deletion(-) > > > > > > create mode 100644 arch/arm/dts/t8103-j274.dts > > > > > > create mode 100644 arch/arm/dts/t8103-j293.dts > > > > > > create mode 100644 arch/arm/dts/t8103.dtsi > > > > > > create mode 100644 arch/arm/include/asm/arch-m1/clk.h > > > > > > create mode 100644 arch/arm/include/asm/arch-m1/uart.h > > > > > > create mode 100644 arch/arm/mach-apple/Kconfig > > > > > > create mode 100644 arch/arm/mach-apple/Makefile > > > > > > create mode 100644 arch/arm/mach-apple/board.c > > > > > > create mode 100644 arch/arm/mach-apple/lowlevel_init.S > > > > > > create mode 100644 configs/apple_m1_defconfig > > > > > > create mode 100644 doc/board/apple/index.rst > > > > > > create mode 100644 doc/board/apple/m1.rst > > > > > > create mode 100644 drivers/misc/apple_dart.c > > > > > > create mode 100644 include/configs/apple.h > > > > > > create mode 100644 > > > > > > include/dt-bindings/interrupt-controller/apple-aic.h > > > > > > create mode 100644 include/dt-bindings/pinctrl/apple.h > > > > > > create mode 100644 include/dt-bindings/spmi/spmi.h > > > > > > > > > > > > -- > > > > > > 2.33.0 > > > > > > > > > > > > > > > > I gave this a whirl on a Macbook Air A2337 and needed the patch below > > > > > to build the devicetree files. Sorry the formatting is broken. > > > > > > > > > > Also when booting I get this: > > > > > > > > > > ... > > > > > Preparing to boot kernel at 0x80820 with fdt at 0x8082e8000 > > > > > Valid payload found > > > > > Preparing to run next stage at 0x80820... > > > > > MMU: shutting down... > > > > > MMU: shutdown successful, clearing caches > > > > > > > > > > > > > > > Then the display clears and it hangs. If I try the J274 devicetree it > > > > > just reboots at that point. > > > > > > > > > > What should I expect? I was ho
[PATCH] misc: ocotp: Allow disabling ocotp driver in SPL
From: Michael Scott This allows removal of the OCOTP driver when SPL is enabled. Disabling OCOTP reduces SPL size efficiently. Signed-off-by: Michael Scott Co-developed-by: Oleksandr Suvorov Signed-off-by: Oleksandr Suvorov --- drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 997b713221..4d6a4384f1 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -233,6 +233,15 @@ config MXC_OCOTP Programmable memory pages that are stored on the some Freescale i.MX processors. +config SPL_MXC_OCOTP + bool "Enable MXC OCOTP driver in SPL" + depends on SPL && (ARCH_IMX8M || ARCH_MX6 || ARCH_MX7 || ARCH_MX7ULP || ARCH_VF610) + default y + help + If you say Y here, you will get support for the One Time + Programmable memory pages, that are stored on some + Freescale i.MX processors, in SPL. + config NUVOTON_NCT6102D bool "Enable Nuvoton NCT6102D Super I/O driver" help diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index b64cd2a4de..3fb367b34a 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -50,7 +50,7 @@ obj-$(CONFIG_IMX8ULP) += imx8ulp/ obj-$(CONFIG_LED_STATUS) += status_led.o obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.o -obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o +obj-$(CONFIG_$(SPL_)MXC_OCOTP) += mxc_ocotp.o obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o obj-$(CONFIG_P2SB) += p2sb-uclass.o -- 2.31.1
Re: [PATCH 1/3] video: Add 30bpp support
> From: Simon Glass > Date: Sat, 25 Sep 2021 07:40:54 -0600 > > On Thu, 16 Sept 2021 at 07:01, Mark Kettenis wrote: > > > > Add support for 30bpp mode where pixels are picked in 32-bit > > integers but use 10 bits instead of 8 bits for each component. > > > > Signed-off-by: Mark Kettenis > > --- > > drivers/video/console_normal.c| 2 ++ > > drivers/video/console_rotate.c| 6 ++ > > drivers/video/console_truetype.c | 3 +++ > > drivers/video/vidconsole-uclass.c | 7 +++ > > drivers/video/video-uclass.c | 1 + > > include/video.h | 1 + > > 6 files changed, 20 insertions(+) > > > > diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c > > index 04f022491e..e0b89cbb93 100644 > > --- a/drivers/video/console_normal.c > > +++ b/drivers/video/console_normal.c > > @@ -41,6 +41,7 @@ static int console_normal_set_row(struct udevice *dev, > > uint row, int clr) > > end = dst; > > break; > > } > > + case VIDEO_BPP30: > > case VIDEO_BPP32: > > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > > uint32_t *dst = line; > > @@ -126,6 +127,7 @@ static int console_normal_putc_xy(struct udevice *dev, > > uint x_frac, uint y, > > } > > break; > > } > > + case VIDEO_BPP30: > > case VIDEO_BPP32: > > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > > uint32_t *dst = line; > > diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c > > index 36c8d0609d..bf81b80a39 100644 > > --- a/drivers/video/console_rotate.c > > +++ b/drivers/video/console_rotate.c > > @@ -40,6 +40,7 @@ static int console_set_row_1(struct udevice *dev, uint > > row, int clr) > > *dst++ = clr; > > break; > > } > > + case VIDEO_BPP30: > > case VIDEO_BPP32: > > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > > uint32_t *dst = line; > > @@ -128,6 +129,7 @@ static int console_putc_xy_1(struct udevice *dev, uint > > x_frac, uint y, char ch) > > } > > break; > > } > > + case VIDEO_BPP30: > > case VIDEO_BPP32: > > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > > uint32_t *dst = line; > > @@ -183,6 +185,7 @@ static int console_set_row_2(struct udevice *dev, uint > > row, int clr) > > end = dst; > > break; > > } > > + case VIDEO_BPP30: > > case VIDEO_BPP32: > > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > > uint32_t *dst = line; > > @@ -266,6 +269,7 @@ static int console_putc_xy_2(struct udevice *dev, uint > > x_frac, uint y, char ch) > > } > > break; > > } > > + case VIDEO_BPP30: > > case VIDEO_BPP32: > > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > > uint32_t *dst = line; > > @@ -318,6 +322,7 @@ static int console_set_row_3(struct udevice *dev, uint > > row, int clr) > > *dst++ = clr; > > break; > > } > > + case VIDEO_BPP30: > > case VIDEO_BPP32: > > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > > uint32_t *dst = line; > > @@ -402,6 +407,7 @@ static int console_putc_xy_3(struct udevice *dev, uint > > x_frac, uint y, char ch) > > } > > break; > > } > > + case VIDEO_BPP30: > > case VIDEO_BPP32: > > if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { > > uint32_t *dst = line; > > diff --git a/drivers/video/console_truetype.c > > b/drivers/video/console_truetype.c > > index 98427f4c61..0195d996de 100644 > > --- a/drivers/video/console_truetype.c > > +++ b/drivers/video/console_truetype.c > > @@ -153,6 +153,7 @@ static int console_truetype_set_row(struct udevice > > *dev, uint row, int clr) > > } > > #endif > > #ifdef CONFIG_VIDEO_BPP32 > > + case VIDEO_BPP30: > > case VIDEO_BPP32: { > > u32 *dst = line; > > > > @@ -299,6 +300,7 @@ static int console_truetype_putc_xy(struct udevice > > *dev, uint x, uint y, > > } > > #endif > > #ifdef CONFIG_VIDEO_BPP32 > > + case VIDEO_BPP30: > >
Re: [PATCH 1/1 RFC] treewide: Deprecate OF_PRIOR_STAGE
> From: Ilias Apalodimas > Date: Fri, 24 Sep 2021 16:12:51 +0300 > > Forgot to include Mark, which showed some interest for MBPs Well, I am currently using OF_BOARD, so this doesn't affect me. I was merely pointing out that having OF_PRIOR_STAGE makes some sense as it clearly indicates that the DT is coming from an earlier firmware stage. OF_BOARD is more flexible and could be used to read the DT from an onboard ROM or something like that. > On Fri, 24 Sept 2021 at 16:10, Ilias Apalodimas > wrote: > > > > At some point back in 2018 prior_stage_fdt_address and OF_PRIOR_STAGE got > > introduced, in order to support a DTB handed over by an earlier stage boot > > loader. However we have another option in the Kconfig (OF_BOARD) which has > > identical semantics. > > > > A good example of this is RISC-V boards which during their startup, > > pick up the DTB from a1 and copy it in their private gd_t. Apart from that > > they also copy it to prior_stage_fdt_address, if the Kconfig option is > > selected, which seems unnecessary(??). > > > > This is mostly an RFC, trying to figure out if I am missing some subtle > > functionality, which would justify having 2 Kconfig options doing similar > > things present. > > > > - Should we do this? > > - Doesn't OF_BOARD and OF_PRIOR_STAGE practically mean "Someone else is > > going to pass me my DTB". Why should we care if that someone is a prior > > bootloader or runtime memory generated on the fly by U-Boot? It all > > boils down to having a *board* specific callback for that. > > - RISC-V binman should get rid of the option as well if we decide to go > > though with this (but I have no idea what RISC-V expects there). > > - Can we apply similar logic to OF_HOSTFILE? It seems like we could just > > have a board_fdt_blob_setup() for the sandbox that reads the file we > > want and get rid of another Kconfig option. > > > > Note that the original board which introduced CONFIG_OF_PRIOR_STAGE is still > > there. If someone cares enough I guess he could fix that as well, but I > > don't > > have the board around, so I prefer keeping it as is and mark the option as > > deprecated. For that board we could also keep the prior_stage_fdt_address > > without the Kconfig option and simply copy the location there, but the > > board must define it's own board_fdt_blob_setup(). That would get rid of > > the Kconfig option entirely instead of limiting it to that board only. > > > > Signed-off-by: Ilias Apalodimas > > --- > > arch/riscv/cpu/cpu.c| 3 --- > > arch/riscv/cpu/start.S | 5 - > > board/emulation/qemu-riscv/qemu-riscv.c | 8 > > board/sifive/unleashed/unleashed.c | 10 -- > > board/sifive/unmatched/unmatched.c | 10 -- > > configs/ae350_rv32_defconfig| 2 +- > > configs/ae350_rv32_spl_defconfig| 2 +- > > configs/ae350_rv64_defconfig| 2 +- > > configs/ae350_rv64_spl_defconfig| 2 +- > > configs/bcm7260_defconfig | 2 +- > > configs/qemu-riscv32_defconfig | 2 +- > > configs/qemu-riscv32_smode_defconfig| 2 +- > > configs/qemu-riscv32_spl_defconfig | 2 +- > > configs/qemu-riscv64_defconfig | 2 +- > > configs/qemu-riscv64_smode_defconfig| 2 +- > > configs/qemu-riscv64_spl_defconfig | 2 +- > > dts/Kconfig | 3 ++- > > lib/fdtdec.c| 4 > > 18 files changed, 33 insertions(+), 32 deletions(-) > > > > diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c > > index c894ac10b536..e16f1df30254 100644 > > --- a/arch/riscv/cpu/cpu.c > > +++ b/arch/riscv/cpu/cpu.c > > @@ -16,9 +16,6 @@ > > * The variables here must be stored in the data section since they are > > used > > * before the bss section is available. > > */ > > -#ifdef CONFIG_OF_PRIOR_STAGE > > -phys_addr_t prior_stage_fdt_address __section(".data"); > > -#endif > > #ifndef CONFIG_XIP > > u32 hart_lottery __section(".data") = 0; > > > > diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S > > index 308b0a97a58f..76850ec9be2c 100644 > > --- a/arch/riscv/cpu/start.S > > +++ b/arch/riscv/cpu/start.S > > @@ -142,11 +142,6 @@ call_harts_early_init: > > bneztp, secondary_hart_loop > > #endif > > > > -#ifdef CONFIG_OF_PRIOR_STAGE > > - la t0, prior_stage_fdt_address > > - SREGs1, 0(t0) > > -#endif > > - > > jal board_init_f_init_reserve > > > > SREGs1, GD_FIRMWARE_FDT_ADDR(gp) > > diff --git a/board/emulation/qemu-riscv/qemu-riscv.c > > b/board/emulation/qemu-riscv/qemu-riscv.c > > index dcfd3f20bee6..7dfe471dee15 100644 > > --- a/board/emulation/qemu-riscv/qemu-riscv.c > > +++ b/board/emulation/qemu-riscv/qemu-riscv.c > > @@ -14,6 +14,8 @@ > > #include > > #include > > > > +DECLARE_GLOBAL_DATA_PTR; > > + > > int board_init(void) > > { > > /* > > @@ -69,3 +71,9 @@ int boa
Re: [PATCH 1/1 RFC] treewide: Deprecate OF_PRIOR_STAGE
> From: Simon Glass > Date: Fri, 24 Sep 2021 07:57:00 -0600 > > Hi Ilias, > > On Fri, 24 Sept 2021 at 07:10, Ilias Apalodimas > wrote: > > > > At some point back in 2018 prior_stage_fdt_address and OF_PRIOR_STAGE got > > introduced, in order to support a DTB handed over by an earlier stage boot > > loader. However we have another option in the Kconfig (OF_BOARD) which has > > identical semantics. > > > > A good example of this is RISC-V boards which during their startup, > > pick up the DTB from a1 and copy it in their private gd_t. Apart from that > > they also copy it to prior_stage_fdt_address, if the Kconfig option is > > selected, which seems unnecessary(??). > > > > This is mostly an RFC, trying to figure out if I am missing some subtle > > functionality, which would justify having 2 Kconfig options doing similar > > things present. > > > > - Should we do this? > > I think one option is better than two. I have a slight preference for > OF_PRIOR_STAGE because it is board-agnostic, but I'm not sure it > matters, since some of these boards are doing strange things anyway > and cannot use OF_PRIOR_STAGE. So let's go with this. > > > - Doesn't OF_BOARD and OF_PRIOR_STAGE practically mean "Someone else is > > going to pass me my DTB". Why should we care if that someone is a prior > > bootloader or runtime memory generated on the fly by U-Boot? It all > > boils down to having a *board* specific callback for that. > > More generally, I think OF_BOARD is basically 'opt out of the normal > flow and do something special'. > > So at some point I would like to define what 'normal' is. At present, > normal is OF_SEPARATE which means that the devicetree is packed with > U-Boot. > > Really we want to add a second 'normal', to permit a devicetree (and > perhaps other stuff) to be passed in. I think this should be that a > bloblist is passed in, which can contain a devicetree. If it does, > then the one in U-Boot is ignored. > > There should be a standard way to do this with U-Boot. Apart from the > arch-specific selection of machine registers, the standard way should > work for all boards, at some indeterminate point in the future. There are well-established ABIs here that you can't really change. One of those ABIs is how the Linux kernel expects to be called. On both riscv and arm64 Linux expects to find a pointer to the DTB in a register. Several U-Boot platforms take advantage of this by pretending to be a Linux kernel. This way they can be loaded by prior stage firmware that was designed to directly load a Linux kernel. This is what I do for the Apple M1, but this is also how chainloading works on some chromebooks, and there are a few platforms where a proprietary closed source first stage bootloader is used. So once again, U-Boot should be flexible here. We can certainly recommend a certain approach to folks that are building a firmware stack for new platforms, but we can't really enforce it.
[PATCH u-boot-spi v2 1/9] mtd: spi-nor-core: Try cleaning up in case writing BAR failed
From: Marek Behún Use the cleanup codepath of spi_nor_erase() also in the event of failure of writing the BAR register. Signed-off-by: Marek Behún Reviewed-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Masami Hiramatsu --- drivers/mtd/spi/spi-nor-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index d5d905fa5a..529e7e9178 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -927,7 +927,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) #ifdef CONFIG_SPI_FLASH_BAR ret = write_bar(nor, addr); if (ret < 0) - return ret; + goto erase_err; #endif write_enable(nor); -- 2.32.0
[PATCH u-boot-spi v2 0/9] Fix `mtd erase` when used with mtdpart
From: Marek Behún The original cover letter said: this patch series fixes the `mtd erase` command when used with mtdpart with a partition of non-zero offset. Currently when the `mtd erase` command is used for such a partition, it does not erase all blocks. Instead after a block is erased, the next block address not current block address + block size, but current block address + block size + partition offset, due to spi_nor_erase() not calling mtd_erase_callback(): => mtd erase "Rescue system" Erasing 0x ... 0x006f (1792 eraseblock(s)) jedec_spi_nor spi-nor@0: at 0x10, len 4096 jedec_spi_nor spi-nor@0: at 0x201000, len 4096 jedec_spi_nor spi-nor@0: at 0x302000, len 4096 jedec_spi_nor spi-nor@0: at 0x403000, len 4096 jedec_spi_nor spi-nor@0: at 0x504000, len 4096 jedec_spi_nor spi-nor@0: at 0x605000, len 4096 jedec_spi_nor spi-nor@0: at 0x706000, len 4096 This series adds some fixes to spi_nor_erase() function, then adds calling of mtd_erase_callback() to fix this bug. The series also contains an improvement - adding the posibility to interrupt spi_nor_erase() with Ctrl+C; and another one - making mtdpart's _erase() method more sane so that the above mentioned bug will not occur even if underlying driver does not call mtd_erase_callback(). Finally the last patch removes mtd_erase_callback() entirely, since: - all provided callbacks across U-Boot are no-ops - mtd_erase_callback() is abused for completely different purpose than the original one (as explained in last commit message) Marek Changes since v1: - fixed CI bugs (by removing mtd_erase_callback() entirely) Marek Behún (9): mtd: spi-nor-core: Try cleaning up in case writing BAR failed mtd: spi-nor-core: Check return value of write_enable() in spi_nor_erase() mtd: spi-nor-core: Don't overwrite return value if it is non-zero mtd: spi-nor-core: Check return value of write_disable() in spi_nor_erase() mtd: spi-nor-core: Don't check for zero length in spi_nor_erase() mtd: spi-nor-core: Call mtd_erase_callback() from spi_nor_erase() mtd: spi-nor-core: Check for ctrlc() in spi_nor_erase() mtd: mtdpart: Make mtdpart's _erase method sane mtd: Remove mtd_erase_callback() entirely cmd/onenand.c | 9 ++- drivers/mtd/altera_qspi.c | 3 --- drivers/mtd/cfi_mtd.c | 1 - drivers/mtd/mtdconcat.c| 11 drivers/mtd/mtdcore.c | 8 -- drivers/mtd/mtdpart.c | 23 +--- drivers/mtd/nand/raw/nand_base.c | 4 --- drivers/mtd/onenand/onenand_base.c | 3 --- drivers/mtd/spi/sf_mtd.c | 1 - drivers/mtd/spi/spi-nor-core.c | 43 +++--- drivers/mtd/ubi/io.c | 13 - env/onenand.c | 4 +-- fs/yaffs2/yaffs_mtdif.c| 1 - include/linux/mtd/mtd.h| 11 include/nand.h | 1 - 15 files changed, 42 insertions(+), 94 deletions(-) -- 2.32.0
[PATCH u-boot-spi v2 2/9] mtd: spi-nor-core: Check return value of write_enable() in spi_nor_erase()
From: Marek Behún The spi_nor_erase() function does not check return value of the write_enable() call. Fix this. Signed-off-by: Marek Behún Reviewed-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Masami Hiramatsu --- drivers/mtd/spi/spi-nor-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 529e7e9178..d2018ab702 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -929,7 +929,9 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) if (ret < 0) goto erase_err; #endif - write_enable(nor); + ret = write_enable(nor); + if (ret < 0) + goto erase_err; ret = spi_nor_erase_sector(nor, addr); if (ret < 0) -- 2.32.0
[PATCH u-boot-spi v2 4/9] mtd: spi-nor-core: Check return value of write_disable() in spi_nor_erase()
From: Marek Behún The cleanup code of spi_nor_erase() function calls write_disable(), but does not return it's return value even in case of failure. Fix this. Signed-off-by: Marek Behún Reviewed-by: Simon Glass Tested-by: Masami Hiramatsu --- drivers/mtd/spi/spi-nor-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 30c0afc08c..9e936cbe1a 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -951,7 +951,9 @@ erase_err: if (!ret) ret = err; #endif - write_disable(nor); + err = write_disable(nor); + if (!ret) + ret = err; return ret; } -- 2.32.0
[PATCH u-boot-spi v2 3/9] mtd: spi-nor-core: Don't overwrite return value if it is non-zero
From: Marek Behún The cleanup code of the spi_nor_erase() function overwrites the ret variable with return value of clean_bar(), even if the ret variable is already set. Fix this. Signed-off-by: Marek Behún Reviewed-by: Simon Glass Tested-by: Masami Hiramatsu --- drivers/mtd/spi/spi-nor-core.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index d2018ab702..30c0afc08c 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -907,7 +907,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) { struct spi_nor *nor = mtd_to_spi_nor(mtd); u32 addr, len, rem; - int ret; + int ret, err; dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr, (long long)instr->len); @@ -947,7 +947,9 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) erase_err: #ifdef CONFIG_SPI_FLASH_BAR - ret = clean_bar(nor); + err = clean_bar(nor); + if (!ret) + ret = err; #endif write_disable(nor); -- 2.32.0
[PATCH u-boot-spi v2 5/9] mtd: spi-nor-core: Don't check for zero length in spi_nor_erase()
From: Marek Behún This check is already done in mtdcore's mtd_erase(), no reason to do this here as well. Signed-off-by: Marek Behún Reviewed-by: Simon Glass Tested-by: Masami Hiramatsu --- drivers/mtd/spi/spi-nor-core.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 9e936cbe1a..211eea22a4 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -912,9 +912,6 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr, (long long)instr->len); - if (!instr->len) - return 0; - div_u64_rem(instr->len, mtd->erasesize, &rem); if (rem) return -EINVAL; -- 2.32.0
[PATCH u-boot-spi v2 6/9] mtd: spi-nor-core: Call mtd_erase_callback() from spi_nor_erase()
From: Marek Behún The spi_nor_erase() function does not call mtd_erase_callback() as it should. The mtdpart code currently implements the subtraction of partition offset in mtd_erase_callback(). This results in partition offset being added prior calling spi_nor_erase(), but not subtracted back on return. The result is that the `mtd erase` command does not erase the whole partition, only some of it's blocks: => mtd erase "Rescue system" Erasing 0x ... 0x006f (1792 eraseblock(s)) jedec_spi_nor spi-nor@0: at 0x10, len 4096 jedec_spi_nor spi-nor@0: at 0x201000, len 4096 jedec_spi_nor spi-nor@0: at 0x302000, len 4096 jedec_spi_nor spi-nor@0: at 0x403000, len 4096 jedec_spi_nor spi-nor@0: at 0x504000, len 4096 jedec_spi_nor spi-nor@0: at 0x605000, len 4096 jedec_spi_nor spi-nor@0: at 0x706000, len 4096 This is obviously wrong. Add proper calling of mtd_erase_callback() into the spi_nor_erase() function. Signed-off-by: Marek Behún Reviewed-by: Simon Glass Reported-by: Masami Hiramatsu Tested-by: Masami Hiramatsu --- drivers/mtd/spi/spi-nor-core.c | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index 211eea22a4..f3e08ed412 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -906,6 +906,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) { struct spi_nor *nor = mtd_to_spi_nor(mtd); + bool addr_known = false; u32 addr, len, rem; int ret, err; @@ -913,12 +914,17 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) (long long)instr->len); div_u64_rem(instr->len, mtd->erasesize, &rem); - if (rem) - return -EINVAL; + if (rem) { + ret = -EINVAL; + goto erase_err_callback; + } addr = instr->addr; len = instr->len; + instr->state = MTD_ERASING; + addr_known = true; + while (len) { WATCHDOG_RESET(); #ifdef CONFIG_SPI_FLASH_BAR @@ -942,6 +948,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) goto erase_err; } + addr_known = false; erase_err: #ifdef CONFIG_SPI_FLASH_BAR err = clean_bar(nor); @@ -952,6 +959,15 @@ erase_err: if (!ret) ret = err; +erase_err_callback: + if (ret) { + instr->fail_addr = addr_known ? addr : MTD_FAIL_ADDR_UNKNOWN; + instr->state = MTD_ERASE_FAILED; + } else { + instr->state = MTD_ERASE_DONE; + } + mtd_erase_callback(instr); + return ret; } -- 2.32.0
[PATCH u-boot-spi v2 7/9] mtd: spi-nor-core: Check for ctrlc() in spi_nor_erase()
From: Marek Behún May it possible to interrupt the spi_nor_erase() function. Signed-off-by: Marek Behún Reviewed-by: Simon Glass Tested-by: Masami Hiramatsu --- drivers/mtd/spi/spi-nor-core.c | 5 + 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index f3e08ed412..124594f0cd 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -927,6 +927,11 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) while (len) { WATCHDOG_RESET(); + if (ctrlc()) { + addr_known = false; + ret = -EINTR; + goto erase_err; + } #ifdef CONFIG_SPI_FLASH_BAR ret = write_bar(nor, addr); if (ret < 0) -- 2.32.0
[PATCH u-boot-spi v2 8/9] mtd: mtdpart: Make mtdpart's _erase method sane
From: Marek Behún The _erase() method of the mtdpart driver, part_erase(), currently implements offset shifting (for given mtdpart partition) in a weird way: 1. part_erase() adds partition offset to block address 2. parent driver's _erase() method is called 3. parent driver's _erase() method calls mtd_erase_callback() 4. mtd_erase_callback() subtracts partition offset from block address so that the callback function is given correct address The problem here is that if the parent's driver does not call mtd_erase_callback() in some scenario (this was recently a case for spi_nor_erase(), which did not call mtd_erase_callback() at all), the offset is not shifted back. Moreover the code would be more readable if part_erase() not only added partition offset before calling parent's _erase(), but also subtracted it back afterwards. Currently the mtd_erase_callback() is expected to do this subtracting since it does have to do it anyway. Add the more steps to this procedure: 5. mtd_erase_callback() adds partition offset to block address so that it returns the the erase_info structure members as it received them 6. part_erase() subtracts partition offset from block address This makes the code more logical and also prevents errors in case parent's driver does not call mtd_erase_callback() for some reason. (BTW, the purpose of mtd_erase_callback() in Linux is to inform the caller that it is done, since in Linux erasing is done asynchronously. We are abusing the purpose of mtd_erase_callback() in U-Boot for completely different purpose. The callback function itself has empty implementation in all cases in U-Boot.) Signed-off-by: Marek Behún Reviewed-by: Simon Glass Tested-by: Masami Hiramatsu --- drivers/mtd/mtdpart.c | 26 ++ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index aa58f722da..6ab481a7b1 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -446,24 +446,34 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr) int ret; instr->addr += mtd->offset; + ret = mtd->parent->_erase(mtd->parent, instr); - if (ret) { - if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) - instr->fail_addr -= mtd->offset; - instr->addr -= mtd->offset; - } + if (ret && instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) + instr->fail_addr -= mtd->offset; + + instr->addr -= mtd->offset; + return ret; } void mtd_erase_callback(struct erase_info *instr) { - if (instr->mtd->_erase == part_erase) { + if (!instr->callback) + return; + + if (instr->mtd->_erase == part_erase && instr->len) { if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) instr->fail_addr -= instr->mtd->offset; instr->addr -= instr->mtd->offset; } - if (instr->callback) - instr->callback(instr); + + instr->callback(instr); + + if (instr->mtd->_erase == part_erase && instr->len) { + if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) + instr->fail_addr += instr->mtd->offset; + instr->addr += instr->mtd->offset; + } } EXPORT_SYMBOL_GPL(mtd_erase_callback); -- 2.32.0
[PATCH u-boot-spi v2 9/9] mtd: Remove mtd_erase_callback() entirely
From: Marek Behún The original purpose of mtd_erase_callback() in Linux at the time it was imported to U-Boot, was to inform the caller that erasing is done (since it was an asynchronous operation). All supplied callback methods in U-Boot do nothing, but the mtd_erase_callback() function was (until previous patch) grossly abused in U-Boot's mtdpart implementation for completely different purpose. Since we got rid of the abusement, remove the mtd_erase_callback() function and the .callback member from struct erase_info entirely, in order to avoid such problems in the future. Signed-off-by: Marek Behún --- cmd/onenand.c | 9 ++--- drivers/mtd/altera_qspi.c | 3 --- drivers/mtd/cfi_mtd.c | 1 - drivers/mtd/mtdconcat.c| 11 --- drivers/mtd/mtdcore.c | 8 drivers/mtd/mtdpart.c | 21 - drivers/mtd/nand/raw/nand_base.c | 4 drivers/mtd/onenand/onenand_base.c | 3 --- drivers/mtd/spi/sf_mtd.c | 1 - drivers/mtd/spi/spi-nor-core.c | 5 ++--- drivers/mtd/ubi/io.c | 13 - env/onenand.c | 4 +--- fs/yaffs2/yaffs_mtdif.c| 1 - include/linux/mtd/mtd.h| 11 --- include/nand.h | 1 - 15 files changed, 5 insertions(+), 91 deletions(-) diff --git a/cmd/onenand.c b/cmd/onenand.c index 852ed5c7b2..592985a7ee 100644 --- a/cmd/onenand.c +++ b/cmd/onenand.c @@ -186,9 +186,7 @@ next: static int onenand_block_erase(u32 start, u32 size, int force) { struct onenand_chip *this = mtd->priv; - struct erase_info instr = { - .callback = NULL, - }; + struct erase_info instr = {}; loff_t ofs; int ret; int blocksize = 1 << this->erase_shift; @@ -219,10 +217,7 @@ static int onenand_block_erase(u32 start, u32 size, int force) static int onenand_block_test(u32 start, u32 size) { struct onenand_chip *this = mtd->priv; - struct erase_info instr = { - .callback = NULL, - .priv = 0, - }; + struct erase_info instr = {}; int blocks; loff_t ofs; diff --git a/drivers/mtd/altera_qspi.c b/drivers/mtd/altera_qspi.c index 7bac599a54..d31391f36a 100644 --- a/drivers/mtd/altera_qspi.c +++ b/drivers/mtd/altera_qspi.c @@ -153,7 +153,6 @@ static int altera_qspi_erase(struct mtd_info *mtd, struct erase_info *instr) putc('\n'); instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; instr->state = MTD_ERASE_FAILED; - mtd_erase_callback(instr); return -EIO; } flash = pdata->base + addr; @@ -177,7 +176,6 @@ static int altera_qspi_erase(struct mtd_info *mtd, struct erase_info *instr) writel(stat, ®s->isr); /* clear isr */ instr->fail_addr = addr; instr->state = MTD_ERASE_FAILED; - mtd_erase_callback(instr); return -EIO; } if (flash_verbose) @@ -189,7 +187,6 @@ static int altera_qspi_erase(struct mtd_info *mtd, struct erase_info *instr) addr += mtd->erasesize; } instr->state = MTD_ERASE_DONE; - mtd_erase_callback(instr); return 0; } diff --git a/drivers/mtd/cfi_mtd.c b/drivers/mtd/cfi_mtd.c index 78293caa2f..2295bb7220 100644 --- a/drivers/mtd/cfi_mtd.c +++ b/drivers/mtd/cfi_mtd.c @@ -58,7 +58,6 @@ static int cfi_mtd_erase(struct mtd_info *mtd, struct erase_info *instr) } instr->state = MTD_ERASE_DONE; - mtd_erase_callback(instr); return 0; } diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 684bc94998..af3c4765c4 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -338,14 +338,6 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) return -EINVAL; } -static void concat_erase_callback(struct erase_info *instr) -{ - /* Nothing to do here in U-Boot */ -#ifndef __UBOOT__ - wake_up((wait_queue_head_t *) instr->priv); -#endif -} - static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase) { int err; @@ -358,7 +350,6 @@ static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase) init_waitqueue_head(&waitq); erase->mtd = mtd; - erase->callback = concat_erase_callback; erase->priv = (unsigned long) &waitq; /* @@ -498,8 +489,6 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr) if (err) return err; - if (instr->callback) - instr->callback(instr);
Re: [PATCH 1/1 RFC] treewide: Deprecate OF_PRIOR_STAGE
Hi Mark, On Sat, Sep 25, 2021 at 07:01:07PM +0200, Mark Kettenis wrote: > > From: Ilias Apalodimas > > Date: Fri, 24 Sep 2021 16:12:51 +0300 > > > > Forgot to include Mark, which showed some interest for MBPs > > Well, I am currently using OF_BOARD, so this doesn't affect me. I was > merely pointing out that having OF_PRIOR_STAGE makes some sense as it > clearly indicates that the DT is coming from an earlier firmware > stage. OF_BOARD is more flexible and could be used to read the DT > from an onboard ROM or something like that. Sure, the naming is something we'd loose. But it doesn't truly offer us any advantage does it? Unless we know of a board that can read the DT from an onboard ROM *or* a register. That would make some sense in having 2 config options, so that a user could specify which DT he wants. But even in that case, I'd prefer the config to be easier and hide the details under the hood. E.g have a callback that reads the register and if you don't find any valid DTB go read a ROM (which is close too what I suggested on a following mail). The obvious disadvantage of this approach would be not allowing someone to explicitly request which DT to read, but I can live with that. Regards /Ilias > > > On Fri, 24 Sept 2021 at 16:10, Ilias Apalodimas > > wrote: > > > > > > At some point back in 2018 prior_stage_fdt_address and OF_PRIOR_STAGE got > > > introduced, in order to support a DTB handed over by an earlier stage > > > boot > > > loader. However we have another option in the Kconfig (OF_BOARD) which > > > has > > > identical semantics. > > > > > > A good example of this is RISC-V boards which during their startup, > > > pick up the DTB from a1 and copy it in their private gd_t. Apart from > > > that > > > they also copy it to prior_stage_fdt_address, if the Kconfig option is > > > selected, which seems unnecessary(??). > > > > > > This is mostly an RFC, trying to figure out if I am missing some subtle > > > functionality, which would justify having 2 Kconfig options doing similar > > > things present. > > > > > > - Should we do this? > > > - Doesn't OF_BOARD and OF_PRIOR_STAGE practically mean "Someone else is > > > going to pass me my DTB". Why should we care if that someone is a prior > > > bootloader or runtime memory generated on the fly by U-Boot? It all > > > boils down to having a *board* specific callback for that. > > > - RISC-V binman should get rid of the option as well if we decide to go > > > though with this (but I have no idea what RISC-V expects there). > > > - Can we apply similar logic to OF_HOSTFILE? It seems like we could just > > > have a board_fdt_blob_setup() for the sandbox that reads the file we > > > want and get rid of another Kconfig option. > > > > > > Note that the original board which introduced CONFIG_OF_PRIOR_STAGE is > > > still > > > there. If someone cares enough I guess he could fix that as well, but I > > > don't > > > have the board around, so I prefer keeping it as is and mark the option as > > > deprecated. For that board we could also keep the prior_stage_fdt_address > > > without the Kconfig option and simply copy the location there, but the > > > board must define it's own board_fdt_blob_setup(). That would get rid of > > > the Kconfig option entirely instead of limiting it to that board only. > > > > > > Signed-off-by: Ilias Apalodimas > > > --- > > > arch/riscv/cpu/cpu.c| 3 --- > > > arch/riscv/cpu/start.S | 5 - > > > board/emulation/qemu-riscv/qemu-riscv.c | 8 > > > board/sifive/unleashed/unleashed.c | 10 -- > > > board/sifive/unmatched/unmatched.c | 10 -- > > > configs/ae350_rv32_defconfig| 2 +- > > > configs/ae350_rv32_spl_defconfig| 2 +- > > > configs/ae350_rv64_defconfig| 2 +- > > > configs/ae350_rv64_spl_defconfig| 2 +- > > > configs/bcm7260_defconfig | 2 +- > > > configs/qemu-riscv32_defconfig | 2 +- > > > configs/qemu-riscv32_smode_defconfig| 2 +- > > > configs/qemu-riscv32_spl_defconfig | 2 +- > > > configs/qemu-riscv64_defconfig | 2 +- > > > configs/qemu-riscv64_smode_defconfig| 2 +- > > > configs/qemu-riscv64_spl_defconfig | 2 +- > > > dts/Kconfig | 3 ++- > > > lib/fdtdec.c| 4 > > > 18 files changed, 33 insertions(+), 32 deletions(-) > > > > > > diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c > > > index c894ac10b536..e16f1df30254 100644 > > > --- a/arch/riscv/cpu/cpu.c > > > +++ b/arch/riscv/cpu/cpu.c > > > @@ -16,9 +16,6 @@ > > > * The variables here must be stored in the data section since they are > > > used > > > * before the bss section is available. > > > */ > > > -#ifdef CONFIG_OF_PRIOR_STAGE > > > -phys_addr_t prior_stage_fdt_address __section(".data"); > > > -#endif > > > #ifndef CONFIG_XIP > > > u32 h
[PATCH u-boot-marvell 0/6] A3720 PCIe enhancements
From: Marek Behún Hello Stefan, Pali has worked on some more enhancements for Armada 3720 PCIe driver (Aardvark). The main change is adding support for accessing configuration space of the PCI Bridge on the PCIe Root Port. Linux does something similar with pci-bridge-emul. Marek Marek Behún (2): arm: a37xx: pci: Cosmetic change arm: a37xx: pci: Update private structure documentation Pali Rohár (4): arm: a37xx: pci: Fix pcie_advk_link_up() arm: a37xx: pci: Add support for accessing PCI Bridge on root bus arm: a37xx: pci: Do not automatically enable bus mastering on PCI Bridge arm: a37xx: pci: Handle propagation of CRSSVE bit from PCIe Root Port drivers/pci/pci-aardvark.c | 199 + include/pci.h | 4 + 2 files changed, 163 insertions(+), 40 deletions(-) -- 2.32.0
[PATCH u-boot-marvell 1/6] arm: a37xx: pci: Fix pcie_advk_link_up()
From: Pali Rohár Aardvark reports Disabled and Hot Reset LTSSM states as values >= 0x20. Link is not up in these states, so fix pcie_advk_link_up() function. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- drivers/pci/pci-aardvark.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index cf6e30f936..741e0431e1 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -145,6 +145,7 @@ #define LTSSM_SHIFT24 #define LTSSM_MASK 0x3f #define LTSSM_L0 0x10 +#define LTSSM_DISABLED 0x20 #define VENDOR_ID_REG (LMI_BASE_ADDR + 0x44) /* PCIe core controller registers */ @@ -569,7 +570,7 @@ static int pcie_advk_link_up(struct pcie_advk *pcie) val = advk_readl(pcie, CFG_REG); ltssm_state = (val >> LTSSM_SHIFT) & LTSSM_MASK; - return ltssm_state >= LTSSM_L0; + return ltssm_state >= LTSSM_L0 && ltssm_state < LTSSM_DISABLED; } /** -- 2.32.0
[PATCH u-boot-marvell 2/6] arm: a37xx: pci: Add support for accessing PCI Bridge on root bus
From: Pali Rohár Aardvark does not have a real PCIe Root Port device on the root bus. Instead it has PCIe registers of PCIe Root Port device mapped in internal Aardvark memory space starting at offset 0xc0. The PCIe Root Port itself is normally available as a PCI Bridge device on the root bus with bus number zero. Aardvark instead has the configuration registers of this PCI Bridge at offset 0x00 of Aardvark's memory space, but the class code of this device is Mass Storage Controller (0x010400), instead of PCI Bridge (0x600400), which causes U-Boot to fail to recognize it as a P2P Bridge Add a hook into the pcie_advk_read_config() / pcie_advk_write_config() functions to redirect access for root bus from PIO transfer to this internal Aardvark memory space. This will allow U-Boot to access configuration space of this PCI Bridge which represents PCIe Root Port. Redirect access to PCI Bridge registers in range 0x10 - 0x34 to driver's internal buffer (cfgcache[]). This is because at those addresses Aardvark has different registers, incompatible with config space of a PCI Bridge. Redirect access to PCI Bridge register PCI_ROM_ADDRESS1 (0x38) to Aardvark internal address for that register (0x30). When reading PCI Bridge register PCI_HEADER_TYPE, set it explicitly to value Type 1 (PCI_HEADER_TYPE_BRIDGE) as PCI Bridge must be of Type 1. When writing to PCI_PRIMARY_BUS or PCI_SECONDARY_BUS registers on this PCI Bridge, correctly update driver's first_busno and sec_busno variables, so that pcie_advk_addr_valid() function can check if address of any device behind the root bus is valid and that PIO transfers are started with correct config type (1 vs 0), which is required for accessing devices behind some PCI bridge after the root bus. U-Boot's PCI_PNP code sets primary and secondary bus numbers as relative to the configured bus number of the root bus. This is done so that U-Boot can support multiple PCIe host bridges or multiple root port buses, when internal bus numbers are different. Now that root bus is available, update code in pcie_advk_read_config() and pcie_advk_write_config() functions to correctly calculate real Aardvark bus number of the target device from U-Boot's bus number as: busno = PCI_BUS(bdf) - dev_seq(bus) Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- drivers/pci/pci-aardvark.c | 143 - 1 file changed, 124 insertions(+), 19 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 741e0431e1..692210ded9 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -39,6 +39,8 @@ #define PCIE_CORE_CMD_IO_ACCESS_EN BIT(0) #define PCIE_CORE_CMD_MEM_ACCESS_ENBIT(1) #define PCIE_CORE_CMD_MEM_IO_REQ_ENBIT(2) +#define PCIE_CORE_DEV_REV_REG 0x8 +#define PCIE_CORE_EXP_ROM_BAR_REG 0x30 #define PCIE_CORE_DEV_CTRL_STATS_REG 0xc8 #define PCIE_CORE_DEV_CTRL_STATS_RELAX_ORDER_DISABLE (0 << 4) #define PCIE_CORE_DEV_CTRL_STATS_SNOOP_DISABLE (0 << 11) @@ -163,7 +165,7 @@ #define PCIE_CONFIG_WR_TYPE1 0xb /* PCI_BDF shifts 8bit, so we need extra 4bit shift */ -#define PCIE_BDF(dev) (dev << 4) +#define PCIE_BDF(b, d, f) (PCI_BDF(b, d, f) << 4) #define PCIE_CONF_BUS(bus) (((bus) & 0xff) << 20) #define PCIE_CONF_DEV(dev) (((dev) & 0x1f) << 15) #define PCIE_CONF_FUNC(fun)(((fun) & 0x7) << 12) @@ -188,13 +190,17 @@ * first_busno stores the bus number of the PCIe root-port * number which may vary depending on the PCIe setup * (PEX switches etc). + * @sec_busno: sec_busno stores the bus number for the device behind + * the PCIe root-port * @device: The pointer to PCI uclass device. */ struct pcie_advk { void *base; intfirst_busno; + intsec_busno; struct udevice *dev; struct gpio_desc reset_gpio; + u32cfgcache[0x34 - 0x10]; }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) @@ -210,22 +216,30 @@ static inline uint advk_readl(struct pcie_advk *pcie, uint reg) /** * pcie_advk_addr_valid() - Check for valid bus address * + * @pcie: Pointer to the PCI bus + * @busno: Bus number of PCI device + * @dev: Device number of PCI device + * @func: Function number of PCI device * @bdf: The PCI device to access - * @first_busno: Bus number of the PCIe controller root complex * - * Return: 1 on valid, 0 on invalid + * Return: true on valid, false on invalid */ -static int pcie_advk_addr_valid(pci_dev_t bdf, int first_busno) +static bool pcie_advk_addr_valid(struct pcie_advk *pcie, +
[PATCH u-boot-marvell 3/6] arm: a37xx: pci: Do not automatically enable bus mastering on PCI Bridge
From: Pali Rohár Now that PCI Bridge is working for the PCIe Root Port, U-Boot's PCI_PNP code automatically enables memory access and bus mastering when needed. We do not need to enable it when setting the HW up. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- drivers/pci/pci-aardvark.c | 6 -- 1 file changed, 6 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 692210ded9..8c025dc45d 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -910,12 +910,6 @@ static int pcie_advk_setup_hw(struct pcie_advk *pcie) if (pcie_advk_wait_for_link(pcie)) return -ENXIO; - reg = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG); - reg |= PCIE_CORE_CMD_MEM_ACCESS_EN | - PCIE_CORE_CMD_IO_ACCESS_EN | - PCIE_CORE_CMD_MEM_IO_REQ_EN; - advk_writel(pcie, reg, PCIE_CORE_CMD_STATUS_REG); - return 0; } -- 2.32.0
[PATCH u-boot-marvell 5/6] arm: a37xx: pci: Cosmetic change
From: Marek Behún Update indentation in driver's private structure. Signed-off-by: Marek Behún --- drivers/pci/pci-aardvark.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 53e9e23d4a..b4f350ca2c 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -196,13 +196,13 @@ * @device: The pointer to PCI uclass device. */ struct pcie_advk { - void *base; - intfirst_busno; - intsec_busno; - struct udevice *dev; - struct gpio_desc reset_gpio; - u32cfgcache[0x34 - 0x10]; - bool cfgcrssve; + void*base; + int first_busno; + int sec_busno; + struct udevice *dev; + struct gpio_descreset_gpio; + u32 cfgcache[0x34 - 0x10]; + boolcfgcrssve; }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) -- 2.32.0
[PATCH u-boot-marvell 4/6] arm: a37xx: pci: Handle propagation of CRSSVE bit from PCIe Root Port
From: Pali Rohár Now that PCI Bridge (PCIe Root Port) for Aardvark is emulated in U-Boot, add support for handling and propagation of CRSSVE bit. When CRSSVE bit is unset (default), driver has to reissue config read/write request on CRS response. CRSSVE bit is supported only when CRSVIS bit is provided in read-only Root Capabilities register. So manually inject this CRSVIS bit into read response for that register. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- drivers/pci/pci-aardvark.c | 26 ++ include/pci.h | 4 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 8c025dc45d..53e9e23d4a 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -41,6 +41,7 @@ #define PCIE_CORE_CMD_MEM_IO_REQ_ENBIT(2) #define PCIE_CORE_DEV_REV_REG 0x8 #define PCIE_CORE_EXP_ROM_BAR_REG 0x30 +#define PCIE_CORE_PCIEXP_CAP_OFF 0xc0 #define PCIE_CORE_DEV_CTRL_STATS_REG 0xc8 #define PCIE_CORE_DEV_CTRL_STATS_RELAX_ORDER_DISABLE (0 << 4) #define PCIE_CORE_DEV_CTRL_STATS_SNOOP_DISABLE (0 << 11) @@ -201,6 +202,7 @@ struct pcie_advk { struct udevice *dev; struct gpio_desc reset_gpio; u32cfgcache[0x34 - 0x10]; + bool cfgcrssve; }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) @@ -413,6 +415,18 @@ static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, data |= PCI_HEADER_TYPE_BRIDGE << 16; } + if ((offset & ~3) == PCIE_CORE_PCIEXP_CAP_OFF + PCI_EXP_RTCTL) { + /* CRSSVE bit is stored only in cache */ + if (pcie->cfgcrssve) + data |= PCI_EXP_RTCTL_CRSSVE; + } + + if ((offset & ~3) == PCIE_CORE_PCIEXP_CAP_OFF + +(PCI_EXP_RTCAP & ~3)) { + /* CRS is emulated below, so set CRSVIS capability */ + data |= PCI_EXP_RTCAP_CRSVIS << 16; + } + *valuep = pci_conv_32_to_size(data, offset, size); return 0; @@ -423,13 +437,14 @@ static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, * OS is allowed only for 4-byte PCI_VENDOR_ID config read request and * only when CRSSVE bit in Root Port PCIe device is enabled. In all * other error PCIe Root Complex must return all-ones. -* Aardvark HW does not have Root Port PCIe device and U-Boot does not -* implement emulation of this device. +* * U-Boot currently does not support handling of CRS return value for * PCI_VENDOR_ID config read request and also does not set CRSSVE bit. -* Therefore disable returning CRS response for now. +* So it means that pcie->cfgcrssve is false. But the code is prepared +* for returning CRS, so that if U-Boot does support CRS in the future, +* it will work for Aardvark. */ - allow_crs = false; + allow_crs = pcie->cfgcrssve; if (advk_readl(pcie, PIO_START)) { dev_err(pcie->dev, @@ -583,6 +598,9 @@ static int pcie_advk_write_config(struct udevice *bus, pci_dev_t bdf, (offset == PCI_PRIMARY_BUS && size != PCI_SIZE_8)) pcie->sec_busno = (data >> 8) & 0xff; + if ((offset & ~3) == PCIE_CORE_PCIEXP_CAP_OFF + PCI_EXP_RTCTL) + pcie->cfgcrssve = data & PCI_EXP_RTCTL_CRSSVE; + return 0; } diff --git a/include/pci.h b/include/pci.h index 0fc22adffd..69eafeb4b9 100644 --- a/include/pci.h +++ b/include/pci.h @@ -495,6 +495,10 @@ #define PCI_EXP_LNKSTA_DLLLA 0x2000 /* Data Link Layer Link Active */ #define PCI_EXP_SLTCAP 20 /* Slot Capabilities */ #define PCI_EXP_SLTCAP_PSN0xfff8 /* Physical Slot Number */ +#define PCI_EXP_RTCTL 28 /* Root Control */ +#define PCI_EXP_RTCTL_CRSSVE 0x0010 /* CRS Software Visibility Enable */ +#define PCI_EXP_RTCAP 30 /* Root Capabilities */ +#define PCI_EXP_RTCAP_CRSVIS 0x0001 /* CRS Software Visibility capability */ #define PCI_EXP_DEVCAP236 /* Device Capabilities 2 */ #define PCI_EXP_DEVCAP2_ARI 0x0020 /* ARI Forwarding Supported */ #define PCI_EXP_DEVCTL240 /* Device Control 2 */ -- 2.32.0
[PATCH u-boot-marvell 6/6] arm: a37xx: pci: Update private structure documentation
From: Marek Behún There were several changes for this structure but the documentation was not changed at the time. Fix this. Signed-off-by: Marek Behún --- drivers/pci/pci-aardvark.c | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index b4f350ca2c..76cb2098e8 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -186,14 +186,15 @@ /** * struct pcie_advk - Advk PCIe controller state * - * @reg_base:The base address of the register space. - * @first_busno: This driver supports multiple PCIe controllers. - * first_busno stores the bus number of the PCIe root-port - * number which may vary depending on the PCIe setup - * (PEX switches etc). - * @sec_busno: sec_busno stores the bus number for the device behind - * the PCIe root-port - * @device: The pointer to PCI uclass device. + * @base:The base address of the register space. + * @first_busno: Bus number for the device behind the PCIe root-port. + * This may vary depending on the PCIe setup. + * @sec_busno: Bus number for the device behind the PCIe root-port. + * @dev: The pointer to PCI uclass device. + * @reset_gpio: GPIO descriptor for PERST. + * @cfgcache:Buffer for emulation of PCIe Root Port's PCI Bridge registers + * that are not available on Aardvark. + * @cfgcrssve: For CRSSVE emulation. */ struct pcie_advk { void*base; -- 2.32.0
[PATCH v2 0/4] 30bpp framebuffer support
Apple M1 machines come up with a framebuffer that in 30bpp mode. This series adds basic support for this mode. What I call 30bpp mode here is really a 32bpp mode with pixels where each color channel is 10 bits deep. To distinguish this mode from the "regular" 32bpp mode (where each channel is 8 bits deep) we need to keep track of the pixel format. In order to avoid having to update each and every video driver, I've introduced an "unknown" format that is the default, where the code continues to infer the pixel format from the bpp value. Changelog: v2: - Encode pixel format in favour of adding VIDEO_30BPP - Recognize more format strings in simplefb driver - Fix EFI block image transfer for 30bpp mode Mark Kettenis (4): video: Add 30bpp support efi_loader: GOP: Add 30bpp support video: simplefb: Add 30bpp support efi_loader: GOP: Fix 30bpp block transfer support drivers/video/simplefb.c | 12 +- drivers/video/vidconsole-uclass.c | 11 -- include/video.h | 9 + lib/efi_loader/efi_gop.c | 61 +-- 4 files changed, 86 insertions(+), 7 deletions(-) -- 2.33.0
[PATCH v2 1/4] video: Add 30bpp support
Add support for 30bpp mode where pixels are picked in 32-bit integers but use 10 bits instead of 8 bits for each component. Signed-off-by: Mark Kettenis --- drivers/video/vidconsole-uclass.c | 11 --- include/video.h | 9 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 8132efa55a..f42db40d4c 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -155,9 +155,14 @@ u32 vid_console_color(struct video_priv *priv, unsigned int idx) break; case VIDEO_BPP32: if (CONFIG_IS_ENABLED(VIDEO_BPP32)) { - return (colors[idx].r << 16) | - (colors[idx].g << 8) | - (colors[idx].b << 0); + if (priv->format == VIDEO_X2R10G10B10) + return (colors[idx].r << 22) | + (colors[idx].g << 12) | + (colors[idx].b << 2); + else + return (colors[idx].r << 16) | + (colors[idx].g << 8) | + (colors[idx].b << 0); } break; default: diff --git a/include/video.h b/include/video.h index 827733305e..f14fb15f84 100644 --- a/include/video.h +++ b/include/video.h @@ -64,6 +64,13 @@ enum video_log2_bpp { #define VNBITS(bpix) (1 << (bpix)) +enum video_format { + VIDEO_UNKNOWN, + VIDEO_X8B8G8R8, + VIDEO_X8R8G8B8, + VIDEO_X2R10G10B10, +}; + /** * struct video_priv - Device information used by the video uclass * @@ -71,6 +78,7 @@ enum video_log2_bpp { * @ysize: Number of pixels rows (e.g.. 768) * @rot: Display rotation (0=none, 1=90 degrees clockwise, etc.) * @bpix: Encoded bits per pixel (enum video_log2_bpp) + * @format:Pixel format (enum video_format) * @vidconsole_drv_name: Driver to use for the text console, NULL to * select automatically * @font_size: Font size in pixels (0 to use a default value) @@ -95,6 +103,7 @@ struct video_priv { ushort ysize; ushort rot; enum video_log2_bpp bpix; + enum video_format format; const char *vidconsole_drv_name; int font_size; -- 2.33.0
[PATCH v2 2/4] efi_loader: GOP: Add 30bpp support
Provide correct framebuffer information for 30bpp modes. Signed-off-by: Mark Kettenis --- lib/efi_loader/efi_gop.c | 14 -- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 1206b2d7a2..5033a2c9e3 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -432,7 +432,7 @@ efi_status_t EFIAPI gop_blt(struct efi_gop *this, struct efi_gop_pixel *buffer, efi_status_t efi_gop_register(void) { struct efi_gop_obj *gopobj; - u32 bpix, col, row; + u32 bpix, format, col, row; u64 fb_base, fb_size; void *fb; efi_status_t ret; @@ -449,6 +449,7 @@ efi_status_t efi_gop_register(void) priv = dev_get_uclass_priv(vdev); bpix = priv->bpix; + format = priv->format; col = video_get_xsize(vdev); row = video_get_ysize(vdev); fb_base = (uintptr_t)priv->fb; @@ -458,6 +459,7 @@ efi_status_t efi_gop_register(void) int line_len; bpix = panel_info.vl_bpix; + format = VIDEO_UNKNOWN; col = panel_info.vl_col; row = panel_info.vl_row; fb_base = gd->fb_base; @@ -517,7 +519,15 @@ efi_status_t efi_gop_register(void) if (bpix == LCD_COLOR32) #endif { - gopobj->info.pixel_format = EFI_GOT_BGRA8; + if (format == VIDEO_X2R10G10B10) { + gopobj->info.pixel_format = EFI_GOT_BITMASK; + gopobj->info.pixel_bitmask[0] = 0x3ff0; /* red */ + gopobj->info.pixel_bitmask[1] = 0x000ffc00; /* green */ + gopobj->info.pixel_bitmask[2] = 0x03ff; /* blue */ + gopobj->info.pixel_bitmask[3] = 0xc000; /* reserved */ + } else { + gopobj->info.pixel_format = EFI_GOT_BGRA8; + } } else { gopobj->info.pixel_format = EFI_GOT_BITMASK; gopobj->info.pixel_bitmask[0] = 0xf800; /* red */ -- 2.33.0
[PATCH v2 4/4] efi_loader: GOP: Fix 30bpp block transfer support
Convert pixel values when necessary like we do for 16bpp framebuffers. Signed-off-by: Mark Kettenis --- lib/efi_loader/efi_gop.c | 47 +++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 5033a2c9e3..7683a34a96 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -64,6 +64,27 @@ out: return EFI_EXIT(ret); } +static __always_inline struct efi_gop_pixel efi_vid30_to_blt_col(u32 vid) +{ + struct efi_gop_pixel blt = { + .reserved = 0, + }; + + blt.blue = (vid & 0x3ff) >> 2; + vid >>= 10; + blt.green = (vid & 0x3ff) >> 2; + vid >>= 10; + blt.red = (vid & 0x3ff) >> 2; + return blt; +} + +static __always_inline u32 efi_blt_col_to_vid30(struct efi_gop_pixel *blt) +{ + return (u32)(blt->red << 2) << 20 | + (u32)(blt->green << 2) << 10 | + (u32)(blt->blue << 2); +} + static __always_inline struct efi_gop_pixel efi_vid16_to_blt_col(u16 vid) { struct efi_gop_pixel blt = { @@ -191,6 +212,9 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this, if (vid_bpp == 32) pix = *(struct efi_gop_pixel *)&fb32[ slineoff + j + sx]; + else if (vid_bpp == 30) + pix = efi_vid30_to_blt_col(fb32[ + slineoff + j + sx]); else pix = efi_vid16_to_blt_col(fb16[ slineoff + j + sx]); @@ -207,6 +231,9 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this, case EFI_BLT_VIDEO_TO_VIDEO: if (vid_bpp == 32) fb32[dlineoff + j + dx] = *(u32 *)&pix; + else if (vid_bpp == 30) + fb32[dlineoff + j + dx] = + efi_blt_col_to_vid30(&pix); else fb16[dlineoff + j + dx] = efi_blt_col_to_vid16(&pix); @@ -231,7 +258,10 @@ static efi_uintn_t gop_get_bpp(struct efi_gop *this) #else case LCD_COLOR32: #endif - vid_bpp = 32; + if (gopobj->info.pixel_format == EFI_GOT_BGRA8) + vid_bpp = 32; + else + vid_bpp = 30; break; #ifdef CONFIG_DM_VIDEO case VIDEO_BPP16: @@ -277,6 +307,17 @@ static efi_status_t gop_blt_buf_to_vid16(struct efi_gop *this, dy, width, height, delta, 16); } +static efi_status_t gop_blt_buf_to_vid30(struct efi_gop *this, +struct efi_gop_pixel *buffer, +u32 foo, efi_uintn_t sx, +efi_uintn_t sy, efi_uintn_t dx, +efi_uintn_t dy, efi_uintn_t width, +efi_uintn_t height, efi_uintn_t delta) +{ + return gop_blt_int(this, buffer, EFI_BLT_BUFFER_TO_VIDEO, sx, sy, dx, + dy, width, height, delta, 30); +} + static efi_status_t gop_blt_buf_to_vid32(struct efi_gop *this, struct efi_gop_pixel *buffer, u32 foo, efi_uintn_t sx, @@ -394,6 +435,10 @@ efi_status_t EFIAPI gop_blt(struct efi_gop *this, struct efi_gop_pixel *buffer, ret = gop_blt_buf_to_vid32(this, buffer, operation, sx, sy, dx, dy, width, height, delta); + else if (vid_bpp == 30) + ret = gop_blt_buf_to_vid30(this, buffer, operation, sx, + sy, dx, dy, width, height, + delta); else ret = gop_blt_buf_to_vid16(this, buffer, operation, sx, sy, dx, dy, width, height, -- 2.33.0
[PATCH v2 3/4] video: simplefb: Add 30bpp support
Recognize the canonical format strings for framebuffers in 30bpp mode and 32/24bpp mode. Signed-off-by: Mark Kettenis --- drivers/video/simplefb.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/video/simplefb.c b/drivers/video/simplefb.c index fd58426cf5..2b0d8835e3 100644 --- a/drivers/video/simplefb.c +++ b/drivers/video/simplefb.c @@ -50,8 +50,18 @@ static int simple_video_probe(struct udevice *dev) if (strcmp(format, "r5g6b5") == 0) { uc_priv->bpix = VIDEO_BPP16; - } else if (strcmp(format, "a8b8g8r8") == 0) { + } else if (strcmp(format, "a8b8g8r8") == 0 || + strcmp(format, "x8b8g8r8") == 0) { uc_priv->bpix = VIDEO_BPP32; + uc_priv->format = VIDEO_X8B8G8R8; + } else if (strcmp(format, "a8r8g8b8") == 0 || + strcmp(format, "x8r8g8b8") == 0) { + uc_priv->bpix = VIDEO_BPP32; + uc_priv->format = VIDEO_X8R8G8B8; + } else if (strcmp(format, "a2r10g10b10") == 0 || + strcmp(format, "x2r10g10b10") == 0) { + uc_priv->bpix = VIDEO_BPP32; + uc_priv->format = VIDEO_X2R10G10B10; } else { printf("%s: invalid format: %s\n", __func__, format); return -EINVAL; -- 2.33.0
Re: [PATCH u-boot-marvell 6/6] arm: a37xx: pci: Update private structure documentation
On Saturday 25 September 2021 22:37:06 Marek Behún wrote: > From: Marek Behún > > There were several changes for this structure but the documentation was > not changed at the time. Fix this. > > Signed-off-by: Marek Behún > --- > drivers/pci/pci-aardvark.c | 17 + > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c > index b4f350ca2c..76cb2098e8 100644 > --- a/drivers/pci/pci-aardvark.c > +++ b/drivers/pci/pci-aardvark.c > @@ -186,14 +186,15 @@ > /** > * struct pcie_advk - Advk PCIe controller state > * > - * @reg_base:The base address of the register space. > - * @first_busno: This driver supports multiple PCIe controllers. > - * first_busno stores the bus number of the PCIe root-port > - * number which may vary depending on the PCIe setup > - * (PEX switches etc). > - * @sec_busno: sec_busno stores the bus number for the device behind > - * the PCIe root-port > - * @device: The pointer to PCI uclass device. > + * @base:The base address of the register space. > + * @first_busno: Bus number for the device behind the PCIe root-port. > + * This may vary depending on the PCIe setup. > + * @sec_busno: Bus number for the device behind the PCIe root-port. Seems like there is copy+paste error here. First (primary) bus is for PCIe root port and secondary bus for device behind the root port. And both bus numbers are set by u-boot pnp code. > + * @dev: The pointer to PCI uclass device. > + * @reset_gpio: GPIO descriptor for PERST. > + * @cfgcache:Buffer for emulation of PCIe Root Port's PCI Bridge > registers > + * that are not available on Aardvark. > + * @cfgcrssve: For CRSSVE emulation. > */ > struct pcie_advk { > void*base; > -- > 2.32.0 >
Re: [PATCH v3 2/3] arm: Add an __image_copy_start symbol for ARMv8
On Sat, 2021-09-25 at 09:46 -0600, Simon Glass wrote: > Hi Scott, > > On Thu, 5 Aug 2021 at 13:20, Simon Glass wrote: > > > > Hi Scott, > > > > On Wed, 4 Aug 2021 at 13:53, Scott Wood wrote: > > > > > > On Sun, 2021-08-01 at 14:59 -0600, Simon Glass wrote: > > > > This symbol is needed for binman to locate the start of the image. Add > > > > it. > > > > > > > > Note: the existing line to bring in the .__image_copy_start symbol > > > > does > > > > not appear to do anything. > > > > > > > > Signed-off-by: Simon Glass > > > > --- > > > > I have copied Scott Wood who originally added the line about the > > > > __image_copy_start in the hope that he can decide if we should remove > > > > it. > > > > > > It's been a long time since I looked at this stuff, but > > > __image_copy_start is > > > used for relocation and that code does not seem to be in the SPL, so the > > > *(.__image_copy_start) was probably just a copy-and-paste leftover from > > > the > > > main SPL that can go away. > > > > > > Of course, that doesn't resolve the binman issue. :-) > > > > > > > diff --git a/arch/arm/cpu/armv8/u-boot-spl.lds b/arch/arm/cpu/armv8/u- > > > > boot- > > > > spl.lds > > > > index 9edb662b094..2827a07590d 100644 > > > > --- a/arch/arm/cpu/armv8/u-boot-spl.lds > > > > +++ b/arch/arm/cpu/armv8/u-boot-spl.lds > > > > @@ -22,6 +22,7 @@ ENTRY(_start) > > > > SECTIONS > > > > { > > > > .text : { > > > > + __image_copy_start = .; > > > > . = ALIGN(8); > > > > *(.__image_copy_start) > > > > CPUDIR/start.o (.text*) > > > > > > If for whatever reason you did need to define the symbol this way, > > > shouldn't > > > it be after the alignment? > > > > Well I don't want to miss out any of the image, otherwise the offsets > > would be off. > > > > But perhaps that is another question. Since this is the first section, > > it should already be aligned (to 16 I suspect). So why do we need it? > > I'd like to get this applied, assuming it is correct, because at > present binman is silently ignoring problems where it cannot find > symbols. The fix for that is: > > http://patchwork.ozlabs.org/project/uboot/patch/20210722210216.1.Id1246d1ff1cb5750f8c7ddde9665cf6f09615a7c@changeid/ > > which has been sitting there for a while. I'm not sure what you need from me... as I said before, as far as I can tell the __image_copy_start stuff should not be needed by the SPL itself. If you want to add it just for binman, there should probably be a comment to that effect, but I'm not the ARM maintainer (or involved in U-Boot development at all these days) so I can't help you get anything applied. As for why the alignment is there, it's probably just paranoia, but in any case, the SPL linker script probably shouldn't handle alignment in a gratuitously different way from the main linker script. -Scott
[PATCH u-boot-marvell v2 0/6] A3720 PCIe enhancements
From: Marek Behún Hello Stefan, Pali has worked on some more enhancements for Armada 3720 PCIe driver (Aardvark). The main change is adding support for accessing configuration space of the PCI Bridge on the PCIe Root Port. Linux does something similar with pci-bridge-emul. Marek Changes since v1: - fix mistake in the documentation change in the last patch Marek Behún (2): arm: a37xx: pci: Cosmetic change arm: a37xx: pci: Update private structure documentation Pali Rohár (4): arm: a37xx: pci: Fix pcie_advk_link_up() arm: a37xx: pci: Add support for accessing PCI Bridge on root bus arm: a37xx: pci: Do not automatically enable bus mastering on PCI Bridge arm: a37xx: pci: Handle propagation of CRSSVE bit from PCIe Root Port drivers/pci/pci-aardvark.c | 199 + include/pci.h | 4 + 2 files changed, 163 insertions(+), 40 deletions(-) -- 2.32.0
[PATCH u-boot-marvell v2 1/6] arm: a37xx: pci: Fix pcie_advk_link_up()
From: Pali Rohár Aardvark reports Disabled and Hot Reset LTSSM states as values >= 0x20. Link is not up in these states, so fix pcie_advk_link_up() function. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- drivers/pci/pci-aardvark.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index cf6e30f936..741e0431e1 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -145,6 +145,7 @@ #define LTSSM_SHIFT24 #define LTSSM_MASK 0x3f #define LTSSM_L0 0x10 +#define LTSSM_DISABLED 0x20 #define VENDOR_ID_REG (LMI_BASE_ADDR + 0x44) /* PCIe core controller registers */ @@ -569,7 +570,7 @@ static int pcie_advk_link_up(struct pcie_advk *pcie) val = advk_readl(pcie, CFG_REG); ltssm_state = (val >> LTSSM_SHIFT) & LTSSM_MASK; - return ltssm_state >= LTSSM_L0; + return ltssm_state >= LTSSM_L0 && ltssm_state < LTSSM_DISABLED; } /** -- 2.32.0
[PATCH u-boot-marvell v2 3/6] arm: a37xx: pci: Do not automatically enable bus mastering on PCI Bridge
From: Pali Rohár Now that PCI Bridge is working for the PCIe Root Port, U-Boot's PCI_PNP code automatically enables memory access and bus mastering when needed. We do not need to enable it when setting the HW up. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- drivers/pci/pci-aardvark.c | 6 -- 1 file changed, 6 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 692210ded9..8c025dc45d 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -910,12 +910,6 @@ static int pcie_advk_setup_hw(struct pcie_advk *pcie) if (pcie_advk_wait_for_link(pcie)) return -ENXIO; - reg = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG); - reg |= PCIE_CORE_CMD_MEM_ACCESS_EN | - PCIE_CORE_CMD_IO_ACCESS_EN | - PCIE_CORE_CMD_MEM_IO_REQ_EN; - advk_writel(pcie, reg, PCIE_CORE_CMD_STATUS_REG); - return 0; } -- 2.32.0
[PATCH u-boot-marvell v2 2/6] arm: a37xx: pci: Add support for accessing PCI Bridge on root bus
From: Pali Rohár Aardvark does not have a real PCIe Root Port device on the root bus. Instead it has PCIe registers of PCIe Root Port device mapped in internal Aardvark memory space starting at offset 0xc0. The PCIe Root Port itself is normally available as a PCI Bridge device on the root bus with bus number zero. Aardvark instead has the configuration registers of this PCI Bridge at offset 0x00 of Aardvark's memory space, but the class code of this device is Mass Storage Controller (0x010400), instead of PCI Bridge (0x600400), which causes U-Boot to fail to recognize it as a P2P Bridge Add a hook into the pcie_advk_read_config() / pcie_advk_write_config() functions to redirect access for root bus from PIO transfer to this internal Aardvark memory space. This will allow U-Boot to access configuration space of this PCI Bridge which represents PCIe Root Port. Redirect access to PCI Bridge registers in range 0x10 - 0x34 to driver's internal buffer (cfgcache[]). This is because at those addresses Aardvark has different registers, incompatible with config space of a PCI Bridge. Redirect access to PCI Bridge register PCI_ROM_ADDRESS1 (0x38) to Aardvark internal address for that register (0x30). When reading PCI Bridge register PCI_HEADER_TYPE, set it explicitly to value Type 1 (PCI_HEADER_TYPE_BRIDGE) as PCI Bridge must be of Type 1. When writing to PCI_PRIMARY_BUS or PCI_SECONDARY_BUS registers on this PCI Bridge, correctly update driver's first_busno and sec_busno variables, so that pcie_advk_addr_valid() function can check if address of any device behind the root bus is valid and that PIO transfers are started with correct config type (1 vs 0), which is required for accessing devices behind some PCI bridge after the root bus. U-Boot's PCI_PNP code sets primary and secondary bus numbers as relative to the configured bus number of the root bus. This is done so that U-Boot can support multiple PCIe host bridges or multiple root port buses, when internal bus numbers are different. Now that root bus is available, update code in pcie_advk_read_config() and pcie_advk_write_config() functions to correctly calculate real Aardvark bus number of the target device from U-Boot's bus number as: busno = PCI_BUS(bdf) - dev_seq(bus) Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- drivers/pci/pci-aardvark.c | 143 - 1 file changed, 124 insertions(+), 19 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 741e0431e1..692210ded9 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -39,6 +39,8 @@ #define PCIE_CORE_CMD_IO_ACCESS_EN BIT(0) #define PCIE_CORE_CMD_MEM_ACCESS_ENBIT(1) #define PCIE_CORE_CMD_MEM_IO_REQ_ENBIT(2) +#define PCIE_CORE_DEV_REV_REG 0x8 +#define PCIE_CORE_EXP_ROM_BAR_REG 0x30 #define PCIE_CORE_DEV_CTRL_STATS_REG 0xc8 #define PCIE_CORE_DEV_CTRL_STATS_RELAX_ORDER_DISABLE (0 << 4) #define PCIE_CORE_DEV_CTRL_STATS_SNOOP_DISABLE (0 << 11) @@ -163,7 +165,7 @@ #define PCIE_CONFIG_WR_TYPE1 0xb /* PCI_BDF shifts 8bit, so we need extra 4bit shift */ -#define PCIE_BDF(dev) (dev << 4) +#define PCIE_BDF(b, d, f) (PCI_BDF(b, d, f) << 4) #define PCIE_CONF_BUS(bus) (((bus) & 0xff) << 20) #define PCIE_CONF_DEV(dev) (((dev) & 0x1f) << 15) #define PCIE_CONF_FUNC(fun)(((fun) & 0x7) << 12) @@ -188,13 +190,17 @@ * first_busno stores the bus number of the PCIe root-port * number which may vary depending on the PCIe setup * (PEX switches etc). + * @sec_busno: sec_busno stores the bus number for the device behind + * the PCIe root-port * @device: The pointer to PCI uclass device. */ struct pcie_advk { void *base; intfirst_busno; + intsec_busno; struct udevice *dev; struct gpio_desc reset_gpio; + u32cfgcache[0x34 - 0x10]; }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) @@ -210,22 +216,30 @@ static inline uint advk_readl(struct pcie_advk *pcie, uint reg) /** * pcie_advk_addr_valid() - Check for valid bus address * + * @pcie: Pointer to the PCI bus + * @busno: Bus number of PCI device + * @dev: Device number of PCI device + * @func: Function number of PCI device * @bdf: The PCI device to access - * @first_busno: Bus number of the PCIe controller root complex * - * Return: 1 on valid, 0 on invalid + * Return: true on valid, false on invalid */ -static int pcie_advk_addr_valid(pci_dev_t bdf, int first_busno) +static bool pcie_advk_addr_valid(struct pcie_advk *pcie, +
[PATCH u-boot-marvell v2 5/6] arm: a37xx: pci: Cosmetic change
From: Marek Behún Update indentation in driver's private structure. Signed-off-by: Marek Behún --- drivers/pci/pci-aardvark.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 53e9e23d4a..b4f350ca2c 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -196,13 +196,13 @@ * @device: The pointer to PCI uclass device. */ struct pcie_advk { - void *base; - intfirst_busno; - intsec_busno; - struct udevice *dev; - struct gpio_desc reset_gpio; - u32cfgcache[0x34 - 0x10]; - bool cfgcrssve; + void*base; + int first_busno; + int sec_busno; + struct udevice *dev; + struct gpio_descreset_gpio; + u32 cfgcache[0x34 - 0x10]; + boolcfgcrssve; }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) -- 2.32.0
[PATCH u-boot-marvell v2 4/6] arm: a37xx: pci: Handle propagation of CRSSVE bit from PCIe Root Port
From: Pali Rohár Now that PCI Bridge (PCIe Root Port) for Aardvark is emulated in U-Boot, add support for handling and propagation of CRSSVE bit. When CRSSVE bit is unset (default), driver has to reissue config read/write request on CRS response. CRSSVE bit is supported only when CRSVIS bit is provided in read-only Root Capabilities register. So manually inject this CRSVIS bit into read response for that register. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- drivers/pci/pci-aardvark.c | 26 ++ include/pci.h | 4 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index 8c025dc45d..53e9e23d4a 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -41,6 +41,7 @@ #define PCIE_CORE_CMD_MEM_IO_REQ_ENBIT(2) #define PCIE_CORE_DEV_REV_REG 0x8 #define PCIE_CORE_EXP_ROM_BAR_REG 0x30 +#define PCIE_CORE_PCIEXP_CAP_OFF 0xc0 #define PCIE_CORE_DEV_CTRL_STATS_REG 0xc8 #define PCIE_CORE_DEV_CTRL_STATS_RELAX_ORDER_DISABLE (0 << 4) #define PCIE_CORE_DEV_CTRL_STATS_SNOOP_DISABLE (0 << 11) @@ -201,6 +202,7 @@ struct pcie_advk { struct udevice *dev; struct gpio_desc reset_gpio; u32cfgcache[0x34 - 0x10]; + bool cfgcrssve; }; static inline void advk_writel(struct pcie_advk *pcie, uint val, uint reg) @@ -413,6 +415,18 @@ static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, data |= PCI_HEADER_TYPE_BRIDGE << 16; } + if ((offset & ~3) == PCIE_CORE_PCIEXP_CAP_OFF + PCI_EXP_RTCTL) { + /* CRSSVE bit is stored only in cache */ + if (pcie->cfgcrssve) + data |= PCI_EXP_RTCTL_CRSSVE; + } + + if ((offset & ~3) == PCIE_CORE_PCIEXP_CAP_OFF + +(PCI_EXP_RTCAP & ~3)) { + /* CRS is emulated below, so set CRSVIS capability */ + data |= PCI_EXP_RTCAP_CRSVIS << 16; + } + *valuep = pci_conv_32_to_size(data, offset, size); return 0; @@ -423,13 +437,14 @@ static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, * OS is allowed only for 4-byte PCI_VENDOR_ID config read request and * only when CRSSVE bit in Root Port PCIe device is enabled. In all * other error PCIe Root Complex must return all-ones. -* Aardvark HW does not have Root Port PCIe device and U-Boot does not -* implement emulation of this device. +* * U-Boot currently does not support handling of CRS return value for * PCI_VENDOR_ID config read request and also does not set CRSSVE bit. -* Therefore disable returning CRS response for now. +* So it means that pcie->cfgcrssve is false. But the code is prepared +* for returning CRS, so that if U-Boot does support CRS in the future, +* it will work for Aardvark. */ - allow_crs = false; + allow_crs = pcie->cfgcrssve; if (advk_readl(pcie, PIO_START)) { dev_err(pcie->dev, @@ -583,6 +598,9 @@ static int pcie_advk_write_config(struct udevice *bus, pci_dev_t bdf, (offset == PCI_PRIMARY_BUS && size != PCI_SIZE_8)) pcie->sec_busno = (data >> 8) & 0xff; + if ((offset & ~3) == PCIE_CORE_PCIEXP_CAP_OFF + PCI_EXP_RTCTL) + pcie->cfgcrssve = data & PCI_EXP_RTCTL_CRSSVE; + return 0; } diff --git a/include/pci.h b/include/pci.h index 0fc22adffd..69eafeb4b9 100644 --- a/include/pci.h +++ b/include/pci.h @@ -495,6 +495,10 @@ #define PCI_EXP_LNKSTA_DLLLA 0x2000 /* Data Link Layer Link Active */ #define PCI_EXP_SLTCAP 20 /* Slot Capabilities */ #define PCI_EXP_SLTCAP_PSN0xfff8 /* Physical Slot Number */ +#define PCI_EXP_RTCTL 28 /* Root Control */ +#define PCI_EXP_RTCTL_CRSSVE 0x0010 /* CRS Software Visibility Enable */ +#define PCI_EXP_RTCAP 30 /* Root Capabilities */ +#define PCI_EXP_RTCAP_CRSVIS 0x0001 /* CRS Software Visibility capability */ #define PCI_EXP_DEVCAP236 /* Device Capabilities 2 */ #define PCI_EXP_DEVCAP2_ARI 0x0020 /* ARI Forwarding Supported */ #define PCI_EXP_DEVCTL240 /* Device Control 2 */ -- 2.32.0
[PATCH u-boot-marvell v2 6/6] arm: a37xx: pci: Update private structure documentation
From: Marek Behún There were several changes for this structure but the documentation was not changed at the time. Fix this. Signed-off-by: Marek Behún --- drivers/pci/pci-aardvark.c | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index b4f350ca2c..414872ed35 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -186,14 +186,15 @@ /** * struct pcie_advk - Advk PCIe controller state * - * @reg_base:The base address of the register space. - * @first_busno: This driver supports multiple PCIe controllers. - * first_busno stores the bus number of the PCIe root-port - * number which may vary depending on the PCIe setup - * (PEX switches etc). - * @sec_busno: sec_busno stores the bus number for the device behind - * the PCIe root-port - * @device: The pointer to PCI uclass device. + * @base:The base address of the register space. + * @first_busno: Bus number of the PCIe root-port. + * This may vary depending on the PCIe setup. + * @sec_busno: Bus number for the device behind the PCIe root-port. + * @dev: The pointer to PCI uclass device. + * @reset_gpio: GPIO descriptor for PERST. + * @cfgcache:Buffer for emulation of PCIe Root Port's PCI Bridge registers + * that are not available on Aardvark. + * @cfgcrssve: For CRSSVE emulation. */ struct pcie_advk { void*base; -- 2.32.0
[PATCH v5 00/29] image: Reduce #ifdefs and ad-hoc defines in image code (Part B)
Much of the image-handling code predates the introduction of Kconfig and has quite a few #ifdefs in it. It also uses its own IMAGE_... defines to help reduce the #ifdefs, which is unnecessary now that we can use IS_ENABLED() et al. The image code is also where quite a bit of code is shared with the host tools. At present this uses a lot of checks of USE_HOSTCC. This series introduces more 'tools' Kconfig options and a way to use CONFIG_IS_ENABLED() to check them. This works in a similar way to SPL, so CONFIG_IS_ENABLED(FIT) will evaluate to true on the host build (USE_HOSTCC) if CONFIG_TOOLS_FIT is enabled. This allows quite a bit of clean-up of the image.h header file and many of the image C files. The 'tools' Kconfig options should help to solve a more general problem in that we mostly want the host tools to build with all features enabled, no matter which features the 'target' build actually uses. This is a pain to arrange at present, but with 'host' Kconfigs, we can just define them all to y. There are cases where the host tools do not have features which are present on the target, for example environment and physical addressing. To help with this, some of the core image code is split out into image-board.c and image-host.c files. Even with these changes, some #ifdefs remain (down from about 100 to about 40 in common/image*). But the code is somewhat easier to follow and there are fewer build paths. Note: The original version of this series met with resistance and resulted in another series that went in first. That did make some improvements but the fundamental problem of sharing code with tools remains. It seems like a good time to get this one in, before further refactoring happens. It was a significant effort to rebase this series on -next and I hope not to do it again. This series is available at u-boot-dm/host-working Changes in v5: - Add a new patch to rename host_build() to tools_build() - Add new patch to bring back SPL_ versions of SHA - Avoid preprocessor in a few more places - Drop I_WANT_MD5 - Drop changes to tools/Makefile since they already use TOOLS_ Kconfigs - Drop rd_load since it is not used - Fix up tools/Makefile to have the correct condition - Rebase to next - Update commit message - Update commit message to indicate that the code is in a separate file - Use TOOLS_ instead of HOST_ Changes in v2: - Add SPL_ Kconfigs also, since otherwise hashing algorithms drop from SPL - All patches rebased to -next - Consider selecting a raw FDT to be success - Correct comment about USE_HOSTCC being undefined in CONFIG_VAL() - Correct logic for the non-FIT case - Drop unnecessary setting of rd_len, etc. - Fix up comment to put an underscore after every CONFIG Simon Glass (29): compiler: Rename host_build() to tools_build() kconfig: Add tools support to CONFIG_IS_ENABLED() image: Add Kconfig options for FIT in the tools build spl: cypto: Bring back SPL_ versions of SHA hash: Use Kconfig to enable hashing in host tools and SPL hash: Drop some #ifdefs in hash.c image: Drop IMAGE_ENABLE_FIT image: Drop IMAGE_ENABLE_OF_LIBFDT image: Use Kconfig to enable CONFIG_FIT_VERBOSE on host image: Use Kconfig to enable FIT_RSASSA_PSS on host image: Use the correct checks for CRC32 image: Drop IMAGE_BOOT_GET_CMDLINE image: Drop IMAGE_OF_BOARD_SETUP image: Drop IMAGE_OF_SYSTEM_SETUP image: Drop IMAGE_ENABLE_IGNORE efi: Correct dependency on FIT_SIGNATURE image: Drop IMAGE_ENABLE_SIGN/VERIFY defines image: Drop IMAGE_ENABLE_EN/DECRYPT defines image: Tidy up fit_unsupported_reset() image: Drop unnecessary #ifdefs from image.h image: Drop #ifdefs for fit_print_contents() image: Drop most #ifdefs in image-board.c image: Reduce variable scope in boot_get_ramdisk() image: Split up boot_get_ramdisk() image: Remove #ifdefs from select_ramdisk() image: Remove some #ifdefs from image-fit and image-fit-sig image: Reduce variable scope in boot_get_fdt() image: Split up boot_get_fdt() image: Remove #ifdefs from select_fdt() arch/arc/lib/bootm.c | 2 +- arch/arm/lib/bootm.c | 4 +- arch/arm/mach-imx/hab.c| 2 +- arch/microblaze/lib/bootm.c| 2 +- arch/nds32/lib/bootm.c | 4 +- arch/riscv/lib/bootm.c | 4 +- board/synopsys/hsdk/hsdk.c | 2 +- common/Kconfig.boot| 10 + common/bootm.c | 14 +- common/bootm_os.c | 8 + common/hash.c | 108 +- common/image-board.c | 359 + common/image-cipher.c | 6 +- common/image-fdt.c | 275 + common/image-fit-sig.c | 7 +- common/image-fit.c | 36 ++-- common/image.c | 14 +- common/spl/Kconfig | 13 +- include/compiler.h | 5 +- include/fdt_support.h | 2 +- include/image.h| 127 ++-- include/linux
[PATCH v5 04/29] spl: cypto: Bring back SPL_ versions of SHA
Unfortunately these were removed by mistake. This means that adding hash support to SPL brings in all software algorithms, with a substantial increase in code size. The origin of the problem was renaming them to SPL_FIT_xxx and then these were removed altogether in a later commit. Add them back. This aligns with CONFIG_MD5, for example, which has an SPL variant. Signed-off-by: Simon Glass Fixes: f5bc9c25f31 ("image: Rename SPL_SHAxxx_SUPPORT to SPL_FIT_SHAxxx") Fixes: eb5171ddec9 ("common: Remove unused CONFIG_FIT_SHAxxx selectors") --- For now this has no effect but the next patch updates hash.c to deal with this condition for both SPL and tools. Changes in v5: - Add new patch to bring back SPL_ versions of SHA lib/Kconfig | 43 ++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/Kconfig b/lib/Kconfig index 034af724b5d..7899e756f99 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -373,7 +373,6 @@ config SHA256 The SHA256 algorithm produces a 256-bit (32-byte) hash value (digest). - config SHA512 bool "Enable SHA512 support" help @@ -399,6 +398,48 @@ config SHA_HW_ACCEL hashing algorithms. This affects the 'hash' command and also the hash_lookup_algo() function. +if SPL + +config SPL_SHA1 + bool "Enable SHA1 support in SPL" + default y if SHA1 + help + This option enables support of hashing using SHA1 algorithm. + The hash is calculated in software. + The SHA1 algorithm produces a 160-bit (20-byte) hash value + (digest). + +config SPL_SHA256 + bool "Enable SHA256 support in SPL" + default y if SHA256 + help + This option enables support of hashing using SHA256 algorithm. + The hash is calculated in software. + The SHA256 algorithm produces a 256-bit (32-byte) hash value + (digest). + +config SPL_SHA512 + bool "Enable SHA512 support in SPL" + default y if SHA512 + help + This option enables support of hashing using SHA512 algorithm. + The hash is calculated in software. + The SHA512 algorithm produces a 512-bit (64-byte) hash value + (digest). + +config SPL_SHA384 + bool "Enable SHA384 support in SPL" + default y if SHA384 + select SPL_SHA512 + help + This option enables support of hashing using SHA384 algorithm. + The hash is calculated in software. This is also selects SHA512, + because these implementations share the bulk of the code.. + The SHA384 algorithm produces a 384-bit (48-byte) hash value + (digest). + +endif + if SHA_HW_ACCEL config SHA512_HW_ACCEL -- 2.33.0.685.g46640cef36-goog
[PATCH v5 02/29] kconfig: Add tools support to CONFIG_IS_ENABLED()
At present we must separately test for the host build for many options, since we force them to be enabled. For example, CONFIG_FIT is always enabled in the host tools, even if CONFIG_FIT is not enabled by the board itself. It would be more convenient if we could use, for example, CONFIG_IS_ENABLED(FIT) and get CONFIG_HOST_FIT, when building for the host. Add support for this. With this and the tools_build() function, we should be able to remove all the #ifdefs currently needed in code that is build by tools and targets. This will be even nicer when we move to using CONFIG(xxx) everywhere, since all the #ifdef and IS_ENABLED/CONFIG_IS_ENABLED stuff will go away. Signed-off-by: Simon Glass Suggested-by: Rasmus Villemoes # b4f73886 --- Changes in v5: - Update commit message - Use TOOLS_ instead of HOST_ Changes in v2: - Correct comment about USE_HOSTCC being undefined in CONFIG_VAL() - Fix up comment to put an underscore after every CONFIG include/linux/kconfig.h | 13 ++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h index d109ed3119e..a1d1a298426 100644 --- a/include/linux/kconfig.h +++ b/include/linux/kconfig.h @@ -31,11 +31,14 @@ (config_enabled(option)) /* - * U-Boot add-on: Helper macros to reference to different macros - * (CONFIG_ or CONFIG_SPL_ prefixed), depending on the build context. + * U-Boot add-on: Helper macros to reference to different macros (prefixed by + * CONFIG_, CONFIG_SPL_, CONFIG_TPL_ or CONFIG_TOOLS_), depending on the build + * context. */ -#if defined(CONFIG_TPL_BUILD) +#ifdef USE_HOSTCC +#define _CONFIG_PREFIX TOOLS_ +#elif defined(CONFIG_TPL_BUILD) #define _CONFIG_PREFIX TPL_ #elif defined(CONFIG_SPL_BUILD) #define _CONFIG_PREFIX SPL_ @@ -49,6 +52,7 @@ /* * CONFIG_VAL(FOO) evaluates to the value of + * CONFIG_TOOLS_FOO if USE_HOSTCC is defined, * CONFIG_FOO if CONFIG_SPL_BUILD is undefined, * CONFIG_SPL_FOO if CONFIG_SPL_BUILD is defined. * CONFIG_TPL_FOO if CONFIG_TPL_BUILD is defined. @@ -76,18 +80,21 @@ /* * CONFIG_IS_ENABLED(FOO) expands to + * 1 if USE_HOSTCC is defined and CONFIG_TOOLS_FOO is set to 'y', * 1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y', * 1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y', * 1 if CONFIG_TPL_BUILD is defined and CONFIG_TPL_FOO is set to 'y', * 0 otherwise. * * CONFIG_IS_ENABLED(FOO, (abc)) expands to + * abc if USE_HOSTCC is defined and CONFIG_TOOLS_FOO is set to 'y', * abc if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y', * abc if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y', * abc if CONFIG_TPL_BUILD is defined and CONFIG_TPL_FOO is set to 'y', * nothing otherwise. * * CONFIG_IS_ENABLED(FOO, (abc), (def)) expands to + * abc if USE_HOSTCC is defined and CONFIG_TOOLS_FOO is set to 'y', * abc if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y', * abc if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y', * abc if CONFIG_TPL_BUILD is defined and CONFIG_TPL_FOO is set to 'y', -- 2.33.0.685.g46640cef36-goog
[PATCH v5 01/29] compiler: Rename host_build() to tools_build()
With the new TOOLS_LIBCRYPTO and some other changes, it seems that we are heading towards calling this a tools build rather than a host build, although of course it does happen on the host. I cannot think of anything built by the host which cannot be described as a tool, so rename this function. Signed-off-by: Simon Glass --- Changes in v5: - Add a new patch to rename host_build() to tools_build() common/image-fit.c | 8 common/image.c | 12 ++-- include/compiler.h | 5 +++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index 5a0a0cc2007..6f8e67e4158 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -509,7 +509,7 @@ void fit_image_print(const void *fit, int image_noffset, const char *p) ret = fit_image_get_data_and_size(fit, image_noffset, &data, &size); - if (!host_build()) { + if (!tools_build()) { printf("%s Data Start: ", p); if (ret) { printf("unavailable\n"); @@ -1845,7 +1845,7 @@ int fit_conf_get_node(const void *fit, const char *conf_uname) if (conf_uname == NULL) { /* get configuration unit name from the default property */ debug("No configuration specified, trying default...\n"); - if (!host_build() && IS_ENABLED(CONFIG_MULTI_DTB_FIT)) { + if (!tools_build() && IS_ENABLED(CONFIG_MULTI_DTB_FIT)) { noffset = fit_find_config_node(fit); if (noffset < 0) return noffset; @@ -2093,7 +2093,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr, } bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH); - if (!host_build() && IS_ENABLED(CONFIG_SANDBOX)) { + if (!tools_build() && IS_ENABLED(CONFIG_SANDBOX)) { if (!fit_image_check_target_arch(fit, noffset)) { puts("Unsupported Architecture\n"); bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH); @@ -2158,7 +2158,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr, } /* perform any post-processing on the image data */ - if (!host_build() && IS_ENABLED(CONFIG_FIT_IMAGE_POST_PROCESS)) + if (!tools_build() && IS_ENABLED(CONFIG_FIT_IMAGE_POST_PROCESS)) board_fit_image_post_process(fit, noffset, &buf, &size); len = (ulong)size; diff --git a/common/image.c b/common/image.c index 2f2fd052c50..66685b4ba99 100644 --- a/common/image.c +++ b/common/image.c @@ -460,11 +460,11 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, ret = -ENOSPC; break; case IH_COMP_GZIP: - if (!host_build() && CONFIG_IS_ENABLED(GZIP)) + if (!tools_build() && CONFIG_IS_ENABLED(GZIP)) ret = gunzip(load_buf, unc_len, image_buf, &image_len); break; case IH_COMP_BZIP2: - if (!host_build() && CONFIG_IS_ENABLED(BZIP2)) { + if (!tools_build() && CONFIG_IS_ENABLED(BZIP2)) { uint size = unc_len; /* @@ -478,7 +478,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, } break; case IH_COMP_LZMA: - if (!host_build() && CONFIG_IS_ENABLED(LZMA)) { + if (!tools_build() && CONFIG_IS_ENABLED(LZMA)) { SizeT lzma_len = unc_len; ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len, @@ -487,7 +487,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, } break; case IH_COMP_LZO: - if (!host_build() && CONFIG_IS_ENABLED(LZO)) { + if (!tools_build() && CONFIG_IS_ENABLED(LZO)) { size_t size = unc_len; ret = lzop_decompress(image_buf, image_len, load_buf, &size); @@ -495,7 +495,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, } break; case IH_COMP_LZ4: - if (!host_build() && CONFIG_IS_ENABLED(LZ4)) { + if (!tools_build() && CONFIG_IS_ENABLED(LZ4)) { size_t size = unc_len; ret = ulz4fn(image_buf, image_len, load_buf, &size); @@ -503,7 +503,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, } break; case IH_COMP_ZSTD: - if (!host_build() && CONFIG_IS_ENABLED(ZSTD)) { + if (!tools_build() && CONFIG_IS_ENABLED(ZSTD)) { struct abuf in, out; abuf_init_set(&in, image_buf, image_len); diff --git a/include/compiler.h b/include/compiler.h index 6b0d3bf5374..8cf11792e24
[PATCH v5 06/29] hash: Drop some #ifdefs in hash.c
We can use the __maybe_unused attribute to avoid some of the #ifdefs in this file. Update the functions accordingly. Note: The actual hashing interface is still a mess, with four separate combinations and lots of #ifdefs. This should really use a driver approach, e.g. as is done with partition drivers. Signed-off-by: Simon Glass --- Changes in v5: - Rebase to next common/hash.c | 54 --- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/common/hash.c b/common/hash.c index 0fe65c959d0..e92f9a9594f 100644 --- a/common/hash.c +++ b/common/hash.c @@ -24,6 +24,7 @@ #include #else #include "mkimage.h" +#include #include #include #endif /* !USE_HOSTCC*/ @@ -42,8 +43,7 @@ DECLARE_GLOBAL_DATA_PTR; static void reloc_update(void); -#if CONFIG_IS_ENABLED(SHA1) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) -static int hash_init_sha1(struct hash_algo *algo, void **ctxp) +static int __maybe_unused hash_init_sha1(struct hash_algo *algo, void **ctxp) { sha1_context *ctx = malloc(sizeof(sha1_context)); sha1_starts(ctx); @@ -51,15 +51,16 @@ static int hash_init_sha1(struct hash_algo *algo, void **ctxp) return 0; } -static int hash_update_sha1(struct hash_algo *algo, void *ctx, const void *buf, - unsigned int size, int is_last) +static int __maybe_unused hash_update_sha1(struct hash_algo *algo, void *ctx, + const void *buf, unsigned int size, + int is_last) { sha1_update((sha1_context *)ctx, buf, size); return 0; } -static int hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf, - int size) +static int __maybe_unused hash_finish_sha1(struct hash_algo *algo, void *ctx, + void *dest_buf, int size) { if (size < algo->digest_size) return -1; @@ -68,10 +69,8 @@ static int hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf, free(ctx); return 0; } -#endif -#if CONFIG_IS_ENABLED(SHA256) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) -static int hash_init_sha256(struct hash_algo *algo, void **ctxp) +static int __maybe_unused hash_init_sha256(struct hash_algo *algo, void **ctxp) { sha256_context *ctx = malloc(sizeof(sha256_context)); sha256_starts(ctx); @@ -79,15 +78,16 @@ static int hash_init_sha256(struct hash_algo *algo, void **ctxp) return 0; } -static int hash_update_sha256(struct hash_algo *algo, void *ctx, - const void *buf, unsigned int size, int is_last) +static int __maybe_unused hash_update_sha256(struct hash_algo *algo, void *ctx, +const void *buf, uint size, +int is_last) { sha256_update((sha256_context *)ctx, buf, size); return 0; } -static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void - *dest_buf, int size) +static int __maybe_unused hash_finish_sha256(struct hash_algo *algo, void *ctx, +void *dest_buf, int size) { if (size < algo->digest_size) return -1; @@ -96,10 +96,8 @@ static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void free(ctx); return 0; } -#endif -#if CONFIG_IS_ENABLED(SHA384) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) -static int hash_init_sha384(struct hash_algo *algo, void **ctxp) +static int __maybe_unused hash_init_sha384(struct hash_algo *algo, void **ctxp) { sha512_context *ctx = malloc(sizeof(sha512_context)); sha384_starts(ctx); @@ -107,15 +105,16 @@ static int hash_init_sha384(struct hash_algo *algo, void **ctxp) return 0; } -static int hash_update_sha384(struct hash_algo *algo, void *ctx, - const void *buf, unsigned int size, int is_last) +static int __maybe_unused hash_update_sha384(struct hash_algo *algo, void *ctx, +const void *buf, uint size, +int is_last) { sha384_update((sha512_context *)ctx, buf, size); return 0; } -static int hash_finish_sha384(struct hash_algo *algo, void *ctx, void - *dest_buf, int size) +static int __maybe_unused hash_finish_sha384(struct hash_algo *algo, void *ctx, +void *dest_buf, int size) { if (size < algo->digest_size) return -1; @@ -124,10 +123,8 @@ static int hash_finish_sha384(struct hash_algo *algo, void *ctx, void free(ctx); return 0; } -#endif -#if CONFIG_IS_ENABLED(SHA512) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) -static int hash_init_sha512(struct hash_algo *algo, void **ctxp) +static int __maybe_unused hash_in
[PATCH v5 03/29] image: Add Kconfig options for FIT in the tools build
In preparation for enabling CONFIG_IS_ENABLED() on the host build, add some options to enable the various FIT options expected in these tools. This will ensure that the code builds correctly when CONFIG_TOOLS_xxx is distinct from CONFIG_xxx. Drop some #ifdefs which are immediately unnecessary (many more are in later patches). Signed-off-by: Simon Glass --- Changes in v5: - Drop changes to tools/Makefile since they already use TOOLS_ Kconfigs - Use TOOLS_ instead of HOST_ common/image-fit-sig.c | 3 ++- common/image-fit.c | 4 ++-- tools/Kconfig | 25 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c index b979cd2a4b6..e95e64bd2fe 100644 --- a/common/image-fit-sig.c +++ b/common/image-fit-sig.c @@ -72,11 +72,12 @@ static int fit_image_setup_verify(struct image_sign_info *info, char *algo_name; const char *padding_name; +#ifndef USE_HOSTCC if (fdt_totalsize(fit) > CONFIG_FIT_SIGNATURE_MAX_SIZE) { *err_msgp = "Total size too large"; return 1; } - +#endif if (fit_image_hash_get_algo(fit, noffset, &algo_name)) { *err_msgp = "Can't get hash algo property"; return -1; diff --git a/common/image-fit.c b/common/image-fit.c index 6f8e67e4158..17c6d4e7813 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -170,7 +170,7 @@ int fit_get_subimage_count(const void *fit, int images_noffset) return count; } -#if CONFIG_IS_ENABLED(FIT_PRINT) || CONFIG_IS_ENABLED(SPL_FIT_PRINT) +#if CONFIG_IS_ENABLED(FIT_PRINT) /** * fit_image_print_data() - prints out the hash node details * @fit: pointer to the FIT format image header @@ -578,7 +578,7 @@ void fit_image_print(const void *fit, int image_noffset, const char *p) #else void fit_print_contents(const void *fit) { } void fit_image_print(const void *fit, int image_noffset, const char *p) { } -#endif /* CONFIG_IS_ENABLED(FIR_PRINT) || CONFIG_IS_ENABLED(SPL_FIT_PRINT) */ +#endif /* CONFIG_IS_ENABLED(FIT_PRINT) */ /** * fit_get_desc - get node description property diff --git a/tools/Kconfig b/tools/Kconfig index d6f82cd949b..ea986ab0479 100644 --- a/tools/Kconfig +++ b/tools/Kconfig @@ -20,4 +20,29 @@ config TOOLS_LIBCRYPTO This selection does not affect target features, such as runtime FIT signature verification. +config TOOLS_FIT + def_bool y + help + Enable FIT support in the tools builds. + +config TOOLS_FIT_FULL_CHECK + def_bool y + help + Do a full check of the FIT before using it in the tools builds + +config TOOLS_FIT_PRINT + def_bool y + help + Print the content of the FIT verbosely in the tools builds + +config TOOLS_FIT_SIGNATURE + def_bool y + help + Enable signature verification of FIT uImages in the tools builds + +config TOOLS_FIT_SIGNATURE_MAX_SIZE + hex + depends on TOOLS_FIT_SIGNATURE + default 0x1000 + endmenu -- 2.33.0.685.g46640cef36-goog
[PATCH v5 05/29] hash: Use Kconfig to enable hashing in host tools and SPL
At present when building host tools, we force CONFIG_SHAxxx to be enabled regardless of the board Kconfig setting. This is done in the image.h header file. For SPL we currently just assume the algorithm is desired if U-Boot proper enables it. Clean this up by adding new Kconfig options to enable hashing on the host, relying on CONFIG_IS_ENABLED() to deal with the different builds. Add new SPL Kconfigs for hardware-accelerated hashing, to maintain the current settings. This allows us to drop the image.h code and the I_WANT_MD5 hack. Signed-off-by: Simon Glass --- Changes in v5: - Drop I_WANT_MD5 - Use TOOLS_ instead of HOST_ Changes in v2: - Add SPL_ Kconfigs also, since otherwise hashing algorithms drop from SPL common/hash.c | 49 +++-- include/image.h | 5 - lib/Kconfig | 18 ++ tools/Kconfig | 25 + 4 files changed, 66 insertions(+), 31 deletions(-) diff --git a/common/hash.c b/common/hash.c index 6277fe65b3e..0fe65c959d0 100644 --- a/common/hash.c +++ b/common/hash.c @@ -25,6 +25,7 @@ #else #include "mkimage.h" #include +#include #endif /* !USE_HOSTCC*/ #include @@ -41,7 +42,7 @@ DECLARE_GLOBAL_DATA_PTR; static void reloc_update(void); -#if defined(CONFIG_SHA1) && !defined(CONFIG_SHA_PROG_HW_ACCEL) +#if CONFIG_IS_ENABLED(SHA1) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) static int hash_init_sha1(struct hash_algo *algo, void **ctxp) { sha1_context *ctx = malloc(sizeof(sha1_context)); @@ -69,7 +70,7 @@ static int hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf, } #endif -#if defined(CONFIG_SHA256) && !defined(CONFIG_SHA_PROG_HW_ACCEL) +#if CONFIG_IS_ENABLED(SHA256) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) static int hash_init_sha256(struct hash_algo *algo, void **ctxp) { sha256_context *ctx = malloc(sizeof(sha256_context)); @@ -97,7 +98,7 @@ static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void } #endif -#if defined(CONFIG_SHA384) && !defined(CONFIG_SHA_PROG_HW_ACCEL) +#if CONFIG_IS_ENABLED(SHA384) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) static int hash_init_sha384(struct hash_algo *algo, void **ctxp) { sha512_context *ctx = malloc(sizeof(sha512_context)); @@ -125,7 +126,7 @@ static int hash_finish_sha384(struct hash_algo *algo, void *ctx, void } #endif -#if defined(CONFIG_SHA512) && !defined(CONFIG_SHA_PROG_HW_ACCEL) +#if CONFIG_IS_ENABLED(SHA512) && !CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) static int hash_init_sha512(struct hash_algo *algo, void **ctxp) { sha512_context *ctx = malloc(sizeof(sha512_context)); @@ -207,18 +208,13 @@ static int hash_finish_crc32(struct hash_algo *algo, void *ctx, void *dest_buf, return 0; } -#ifdef USE_HOSTCC -# define I_WANT_MD51 -#else -# define I_WANT_MD5CONFIG_IS_ENABLED(MD5) -#endif /* * These are the hash algorithms we support. If we have hardware acceleration * is enable we will use that, otherwise a software version of the algorithm. * Note that algorithm names must be in lower case. */ static struct hash_algo hash_algo[] = { -#if I_WANT_MD5 +#if CONFIG_IS_ENABLED(MD5) { .name = "md5", .digest_size= MD5_SUM_LEN, @@ -226,17 +222,17 @@ static struct hash_algo hash_algo[] = { .hash_func_ws = md5_wd, }, #endif -#ifdef CONFIG_SHA1 +#if CONFIG_IS_ENABLED(SHA1) { .name = "sha1", .digest_size= SHA1_SUM_LEN, .chunk_size = CHUNKSZ_SHA1, -#ifdef CONFIG_SHA_HW_ACCEL +#if CONFIG_IS_ENABLED(SHA_HW_ACCEL) .hash_func_ws = hw_sha1, #else .hash_func_ws = sha1_csum_wd, #endif -#ifdef CONFIG_SHA_PROG_HW_ACCEL +#if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) .hash_init = hw_sha_init, .hash_update= hw_sha_update, .hash_finish= hw_sha_finish, @@ -247,17 +243,17 @@ static struct hash_algo hash_algo[] = { #endif }, #endif -#ifdef CONFIG_SHA256 +#if CONFIG_IS_ENABLED(SHA256) { .name = "sha256", .digest_size= SHA256_SUM_LEN, .chunk_size = CHUNKSZ_SHA256, -#ifdef CONFIG_SHA_HW_ACCEL +#if CONFIG_IS_ENABLED(SHA_HW_ACCEL) .hash_func_ws = hw_sha256, #else .hash_func_ws = sha256_csum_wd, #endif -#ifdef CONFIG_SHA_PROG_HW_ACCEL +#if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) .hash_init = hw_sha_init, .hash_update= hw_sha_update, .hash_finish= hw_sha_finish, @@ -268,17 +264,17 @@ static struct hash_algo hash_algo[] = { #endif }, #endif -#ifdef CONFIG_SHA384 +#if CONFIG_IS_ENABLED(SHA384) { .name = "sha384", .digest_size= SHA384_SUM_LEN, .chunk_size = CHUNKSZ_SHA384,
[PATCH v5 07/29] image: Drop IMAGE_ENABLE_FIT
Make use of the host Kconfig for FIT. With this we can use CONFIG_IS_ENABLED(FIT) directly in the host build, so drop the unnecessary indirection. Signed-off-by: Simon Glass --- Changes in v5: - Rebase to next arch/arm/mach-imx/hab.c | 2 +- common/bootm.c | 10 +- common/image-board.c| 16 common/image.c | 2 +- include/fdt_support.h | 2 +- include/image.h | 17 - 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c index cc39e6bf569..55317abba23 100644 --- a/arch/arm/mach-imx/hab.c +++ b/arch/arm/mach-imx/hab.c @@ -591,7 +591,7 @@ static ulong get_image_ivt_offset(ulong img_addr) return (image_get_image_size((image_header_t *)img_addr) + 0x1000 - 1) & ~(0x1000 - 1); #endif -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) case IMAGE_FORMAT_FIT: return (fit_get_size(buf) + 0x1000 - 1) & ~(0x1000 - 1); #endif diff --git a/common/bootm.c b/common/bootm.c index fe17d1da9e5..8d614fe140e 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -115,7 +115,7 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, images.os.arch = image_get_arch(os_hdr); break; #endif -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) case IMAGE_FORMAT_FIT: if (fit_image_get_type(images.fit_hdr_os, images.fit_noffset_os, @@ -187,7 +187,7 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, /* Kernel entry point is the setup.bin */ } else if (images.legacy_hdr_valid) { images.ep = image_get_ep(&images.legacy_hdr_os_copy); -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) } else if (images.fit_uname_os) { int ret; @@ -295,7 +295,7 @@ int bootm_find_images(int flag, int argc, char *const argv[], ulong start, set_working_fdt_addr(map_to_sysmem(images.ft_addr)); #endif -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) if (IS_ENABLED(CONFIG_FPGA)) { /* find bitstreams */ ret = boot_get_fpga(argc, argv, &images, IH_ARCH_DEFAULT, @@ -858,7 +858,7 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, const void *buf; const char *fit_uname_config = NULL; const char *fit_uname_kernel = NULL; -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) int os_noffset; #endif @@ -916,7 +916,7 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE); break; #endif -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) case IMAGE_FORMAT_FIT: os_noffset = fit_image_load(images, img_addr, &fit_uname_kernel, &fit_uname_config, diff --git a/common/image-board.c b/common/image-board.c index c13d0493ca3..c699232ba13 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -282,7 +282,7 @@ int genimg_get_format(const void *img_addr) if (image_check_magic(hdr)) return IMAGE_FORMAT_LEGACY; #endif -#if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT +#if CONFIG_IS_ENABLED(FIT) || IMAGE_ENABLE_OF_LIBFDT if (fdt_check_header(img_addr) == 0) return IMAGE_FORMAT_FIT; #endif @@ -307,7 +307,7 @@ int genimg_get_format(const void *img_addr) */ int genimg_has_config(bootm_headers_t *images) { -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) if (images->fit_uname_cfg) return 1; #endif @@ -348,7 +348,7 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, #ifdef CONFIG_SUPPORT_RAW_INITRD char *end; #endif -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) const char *fit_uname_config = images->fit_uname_cfg; const char *fit_uname_ramdisk = NULL; ulong default_addr; @@ -380,7 +380,7 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, rd_len = 0; rd_data = 0; } else if (select || genimg_has_config(images)) { -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) if (select) { /* * If the init ramdisk comes from the FIT image and @@ -409,7 +409,7 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, debug("* ramdisk: cmdline image address = 0x%08lx\n", rd_addr); } -#if IMAGE_ENABLE_FIT +#if CONFIG_IS_ENABLED(FIT) } else { /* use FIT configuration provided in first bootm * command argument. If the property is not defined, @@ -
[PATCH v5 08/29] image: Drop IMAGE_ENABLE_OF_LIBFDT
Add a host Kconfig for OF_LIBFDT. With this we can use CONFIG_IS_ENABLED(OF_LIBFDT) directly in the host build, so drop the unnecessary indirection. Signed-off-by: Simon Glass --- Changes in v5: - Use TOOLS_ instead of HOST_ arch/arc/lib/bootm.c| 2 +- arch/arm/lib/bootm.c| 4 ++-- arch/microblaze/lib/bootm.c | 2 +- arch/nds32/lib/bootm.c | 4 ++-- arch/riscv/lib/bootm.c | 4 ++-- board/synopsys/hsdk/hsdk.c | 2 +- common/bootm.c | 4 ++-- common/image-board.c| 8 common/image.c | 2 +- include/image.h | 3 --- lib/lmb.c | 2 +- tools/Kconfig | 5 + 12 files changed, 22 insertions(+), 20 deletions(-) diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c index 41408c2b460..ed6c5dfa584 100644 --- a/arch/arc/lib/bootm.c +++ b/arch/arc/lib/bootm.c @@ -63,7 +63,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag) "(fake run for tracing)" : ""); bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { + if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { r0 = 2; r2 = (unsigned int)images->ft_addr; } else { diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index dd6a69315ac..a59a5e6c0ea 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -199,7 +199,7 @@ static void boot_prep_linux(bootm_headers_t *images) { char *commandline = env_get("bootargs"); - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { + if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { #ifdef CONFIG_OF_LIBFDT debug("using: FDT\n"); if (image_setup_linux(images)) { @@ -356,7 +356,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag) bootstage_mark(BOOTSTAGE_ID_RUN_OS); announce_and_cleanup(fake); - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) + if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) r2 = (unsigned long)images->ft_addr; else r2 = gd->bd->bi_boot_params; diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c index 3a6da6e29ff..12ea32488e6 100644 --- a/arch/microblaze/lib/bootm.c +++ b/arch/microblaze/lib/bootm.c @@ -75,7 +75,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag) static void boot_prep_linux(bootm_headers_t *images) { - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { + if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { debug("using: FDT\n"); if (image_setup_linux(images)) { printf("FDT creation failed! hanging..."); diff --git a/arch/nds32/lib/bootm.c b/arch/nds32/lib/bootm.c index 1c7f7856999..71ebfb4225b 100644 --- a/arch/nds32/lib/bootm.c +++ b/arch/nds32/lib/bootm.c @@ -69,7 +69,7 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) debug("## Transferring control to Linux (at address %08lx) ...\n", (ulong)theKernel); - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { + if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { #ifdef CONFIG_OF_LIBFDT debug("using: FDT\n"); if (image_setup_linux(images)) { @@ -110,7 +110,7 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) #endif } cleanup_before_linux(); - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) + if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) theKernel(0, machid, (unsigned long)images->ft_addr); else theKernel(0, machid, bd->bi_boot_params); diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index ff1bdf71318..2e1e286c8ef 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -64,7 +64,7 @@ static void announce_and_cleanup(int fake) static void boot_prep_linux(bootm_headers_t *images) { - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { + if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { #ifdef CONFIG_OF_LIBFDT debug("using: FDT\n"); if (image_setup_linux(images)) { @@ -96,7 +96,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag) announce_and_cleanup(fake); if (!fake) { - if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { + if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { #ifdef CONFIG_SMP ret = smp_call_function(images->ep, (ulong)images->ft_addr, 0, 0); diff --git a/board/synopsys/hsdk/hsdk.c b/board/synopsys/hsdk/hsdk.c index 892b94bb083..226fbba6296 100644 --- a/board/synopsys/hsdk/hsdk.c +++ b/board/synopsys/hsdk/hsdk.c @@ -871,7 +871,7 @@ int board_prep_linux(bootm_headers_t *images) if (env_common.core_mask.va
[PATCH v5 09/29] image: Use Kconfig to enable CONFIG_FIT_VERBOSE on host
Add a host Kconfig for FIT_VERBOSE. With this we can use CONFIG_IS_ENABLED(FIT_VERBOSE) directly in the host build, so drop the forcing of this in the image.h header. Signed-off-by: Simon Glass --- Changes in v5: - Use TOOLS_ instead of HOST_ include/image.h | 5 ++--- tools/Kconfig | 5 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/image.h b/include/image.h index f09eb9de516..6efbef06e64 100644 --- a/include/image.h +++ b/include/image.h @@ -28,7 +28,6 @@ struct fdt_region; #include /* new uImage format support enabled on host */ -#define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */ #define CONFIG_FIT_RSASSA_PSS 1 #define IMAGE_ENABLE_IGNORE0 @@ -1458,7 +1457,7 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo); struct cipher_algo *image_get_cipher_algo(const char *full_name); -#ifdef CONFIG_FIT_VERBOSE +#if CONFIG_IS_ENABLED(FIT_VERBOSE) #define fit_unsupported(msg) printf("! %s:%d " \ "FIT images not supported for '%s'\n", \ __FILE__, __LINE__, (msg)) @@ -1470,7 +1469,7 @@ struct cipher_algo *image_get_cipher_algo(const char *full_name); #else #define fit_unsupported(msg) #define fit_unsupported_reset(msg) -#endif /* CONFIG_FIT_VERBOSE */ +#endif /* FIT_VERBOSE */ #endif /* CONFIG_FIT */ #if !defined(USE_HOSTCC) diff --git a/tools/Kconfig b/tools/Kconfig index 747d221803f..9d1c0efd40c 100644 --- a/tools/Kconfig +++ b/tools/Kconfig @@ -45,6 +45,11 @@ config TOOLS_FIT_SIGNATURE_MAX_SIZE depends on TOOLS_FIT_SIGNATURE default 0x1000 +config TOOLS_FIT_VERBOSE + def_bool y + help + Support verbose FIT output in the tools builds + config TOOLS_MD5 def_bool y help -- 2.33.0.685.g46640cef36-goog
[PATCH v5 12/29] image: Drop IMAGE_BOOT_GET_CMDLINE
This is not needed with Kconfig, since we can use IS_ENABLED() easily enough and the board code is now in a separate file. Update the only place where this is used and drop it. Signed-off-by: Simon Glass --- Changes in v5: - Update commit message to indicate that the code is in a separate file common/image-board.c | 2 +- include/image.h | 6 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/common/image-board.c b/common/image-board.c index a9a6011ce02..599d6779df5 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -898,7 +898,7 @@ int image_setup_linux(bootm_headers_t *images) if (CONFIG_IS_ENABLED(OF_LIBFDT)) boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree); - if (IMAGE_BOOT_GET_CMDLINE) { + if (IS_ENABLED(CONFIG_SYS_BOOT_GET_CMDLINE)) { ret = boot_get_cmdline(lmb, &images->cmdline_start, &images->cmdline_end); if (ret) { diff --git a/include/image.h b/include/image.h index dc872ef5b24..00a80999584 100644 --- a/include/image.h +++ b/include/image.h @@ -49,12 +49,6 @@ struct fdt_region; #include #endif /* FIT */ -#ifdef CONFIG_SYS_BOOT_GET_CMDLINE -# define IMAGE_BOOT_GET_CMDLINE1 -#else -# define IMAGE_BOOT_GET_CMDLINE0 -#endif - #ifdef CONFIG_OF_BOARD_SETUP # define IMAGE_OF_BOARD_SETUP 1 #else -- 2.33.0.685.g46640cef36-goog
[PATCH v5 16/29] efi: Correct dependency on FIT_SIGNATURE
At present EFI_SECURE BOOT selects RSA but does not necessarily enable FIT_SIGNATURE. Mostly this is fine, but a few boards do not enable it, so U-Boot tries to do RSA verification when loading FIT images, but it is not enabled. This worked because the condition for checking the RSA signature is wrong in the fit_image_verify_with_data() function. In order to fix it we need to fix this dependency. Make sure that FIT_SIGNATURE is enabled so that RSA can be used. It might be better to avoid using 'select' in this situation. Signed-off-by: Simon Glass --- (no changes since v1) lib/efi_loader/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 14bf5f7e92e..c1cc143f354 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -343,7 +343,7 @@ config EFI_LOAD_FILE2_INITRD config EFI_SECURE_BOOT bool "Enable EFI secure boot support" - depends on EFI_LOADER + depends on EFI_LOADER && FIT_SIGNATURE select HASH select SHA256 select RSA -- 2.33.0.685.g46640cef36-goog
[PATCH v5 19/29] image: Tidy up fit_unsupported_reset()
This function is only used in one place and does not need to use the preprocessor. Move it to the C file and convert it to a normal function. Drop fit_unsupported() since it is not used. Signed-off-by: Simon Glass --- (no changes since v1) common/bootm_os.c | 8 include/image.h | 13 - 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/common/bootm_os.c b/common/bootm_os.c index d635037064a..39623f9126b 100644 --- a/common/bootm_os.c +++ b/common/bootm_os.c @@ -58,6 +58,14 @@ static void copy_args(char *dest, int argc, char *const argv[], char delim) } #endif +static void __maybe_unused fit_unsupported_reset(const char *msg) +{ + if (CONFIG_IS_ENABLED(FIT_VERBOSE)) { + printf("! FIT images not supported for '%s' - must reset board to recover!\n", + msg); + } +} + #ifdef CONFIG_BOOTM_NETBSD static int do_bootm_netbsd(int flag, int argc, char *const argv[], bootm_headers_t *images) diff --git a/include/image.h b/include/image.h index 75a63db4c1a..0dd8481611e 100644 --- a/include/image.h +++ b/include/image.h @@ -1413,19 +1413,6 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo); struct cipher_algo *image_get_cipher_algo(const char *full_name); -#if CONFIG_IS_ENABLED(FIT_VERBOSE) -#define fit_unsupported(msg) printf("! %s:%d " \ - "FIT images not supported for '%s'\n", \ - __FILE__, __LINE__, (msg)) - -#define fit_unsupported_reset(msg) printf("! %s:%d " \ - "FIT images not supported for '%s' " \ - "- must reset board to recover!\n", \ - __FILE__, __LINE__, (msg)) -#else -#define fit_unsupported(msg) -#define fit_unsupported_reset(msg) -#endif /* FIT_VERBOSE */ #endif /* CONFIG_FIT */ #if !defined(USE_HOSTCC) -- 2.33.0.685.g46640cef36-goog
[PATCH v5 13/29] image: Drop IMAGE_OF_BOARD_SETUP
This is not needed with Kconfig, since we can use IS_ENABLED() easily enough. Drop it. Signed-off-by: Simon Glass --- (no changes since v1) common/image-fdt.c | 4 ++-- include/image.h| 6 -- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/common/image-fdt.c b/common/image-fdt.c index 9441e63a3d4..cd664649e2c 100644 --- a/common/image-fdt.c +++ b/common/image-fdt.c @@ -582,7 +582,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob, /* Append PStore configuration */ fdt_fixup_pstore(blob); #endif - if (IMAGE_OF_BOARD_SETUP) { + if (IS_ENABLED(CONFIG_OF_BOARD_SETUP)) { const char *skip_board_fixup; skip_board_fixup = env_get("skip_board_fixup"); @@ -629,7 +629,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob, goto err; #if defined(CONFIG_SOC_KEYSTONE) - if (IMAGE_OF_BOARD_SETUP) + if (IS_ENABLED(CONFIG_OF_BOARD_SETUP)) ft_board_setup_ex(blob, gd->bd); #endif diff --git a/include/image.h b/include/image.h index 00a80999584..e1e4148e4c8 100644 --- a/include/image.h +++ b/include/image.h @@ -49,12 +49,6 @@ struct fdt_region; #include #endif /* FIT */ -#ifdef CONFIG_OF_BOARD_SETUP -# define IMAGE_OF_BOARD_SETUP 1 -#else -# define IMAGE_OF_BOARD_SETUP 0 -#endif - #ifdef CONFIG_OF_SYSTEM_SETUP # define IMAGE_OF_SYSTEM_SETUP 1 #else -- 2.33.0.685.g46640cef36-goog
[PATCH v5 14/29] image: Drop IMAGE_OF_SYSTEM_SETUP
This is not needed with Kconfig, since we can use IS_ENABLED() easily enough. Drop it. Signed-off-by: Simon Glass --- (no changes since v1) common/image-fdt.c | 2 +- include/image.h| 6 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/common/image-fdt.c b/common/image-fdt.c index cd664649e2c..cf87e455230 100644 --- a/common/image-fdt.c +++ b/common/image-fdt.c @@ -597,7 +597,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob, } } } - if (IMAGE_OF_SYSTEM_SETUP) { + if (IS_ENABLED(CONFIG_OF_SYSTEM_SETUP)) { fdt_ret = ft_system_setup(blob, gd->bd); if (fdt_ret) { printf("ERROR: system-specific fdt fixup failed: %s\n", diff --git a/include/image.h b/include/image.h index e1e4148e4c8..e190f59232d 100644 --- a/include/image.h +++ b/include/image.h @@ -49,12 +49,6 @@ struct fdt_region; #include #endif /* FIT */ -#ifdef CONFIG_OF_SYSTEM_SETUP -# define IMAGE_OF_SYSTEM_SETUP 1 -#else -# define IMAGE_OF_SYSTEM_SETUP 0 -#endif - extern ulong image_load_addr; /* Default Load Address */ extern ulong image_save_addr; /* Default Save Address */ extern ulong image_save_size; /* Default Save Size */ -- 2.33.0.685.g46640cef36-goog
[PATCH v5 15/29] image: Drop IMAGE_ENABLE_IGNORE
We can use the new host_build() function for this, so drop it. Signed-off-by: Simon Glass --- (no changes since v1) common/image-fit.c | 2 +- include/image.h| 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index 17c6d4e7813..f44f5527b9f 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1277,7 +1277,7 @@ static int fit_image_check_hash(const void *fit, int noffset, const void *data, } printf("%s", algo); - if (IMAGE_ENABLE_IGNORE) { + if (!tools_build()) { fit_image_hash_get_ignore(fit, noffset, &ignore); if (ignore) { printf("-skipped "); diff --git a/include/image.h b/include/image.h index e190f59232d..a236180ccdd 100644 --- a/include/image.h +++ b/include/image.h @@ -27,7 +27,6 @@ struct fdt_region; #include #include -#define IMAGE_ENABLE_IGNORE0 #define IMAGE_INDENT_STRING"" #else @@ -37,8 +36,6 @@ struct fdt_region; #include #include -/* Take notice of the 'ignore' property for hashes */ -#define IMAGE_ENABLE_IGNORE1 #define IMAGE_INDENT_STRING" " #endif /* USE_HOSTCC */ -- 2.33.0.685.g46640cef36-goog
[PATCH v5 20/29] image: Drop unnecessary #ifdefs from image.h
This file has a lot of conditional code and much of it is unnecessary. Clean this up to reduce the number of build combinations. Signed-off-by: Simon Glass --- Changes in v5: - Rebase to next include/image.h| 39 -- include/u-boot/hash-checksum.h | 5 +++-- lib/hash-checksum.c| 2 +- 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/include/image.h b/include/image.h index 0dd8481611e..4ba69a15bf0 100644 --- a/include/image.h +++ b/include/image.h @@ -40,11 +40,10 @@ struct fdt_region; #endif /* USE_HOSTCC */ -#if CONFIG_IS_ENABLED(FIT) #include #include #include -#endif /* FIT */ +#include extern ulong image_load_addr; /* Default Load Address */ extern ulong image_save_addr; /* Default Save Address */ @@ -504,8 +503,7 @@ int genimg_get_type_id(const char *name); int genimg_get_comp_id(const char *name); void genimg_print_size(uint32_t size); -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \ - defined(USE_HOSTCC) +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) #define IMAGE_ENABLE_TIMESTAMP 1 #else #define IMAGE_ENABLE_TIMESTAMP 0 @@ -523,12 +521,9 @@ enum fit_load_op { int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start, ulong *setup_len); -#ifndef USE_HOSTCC /* Image format types, returned by _get_format() routine */ #define IMAGE_FORMAT_INVALID 0x00 -#if defined(CONFIG_LEGACY_IMAGE_FORMAT) #define IMAGE_FORMAT_LEGACY0x01/* legacy image_header based format */ -#endif #define IMAGE_FORMAT_FIT 0x02/* new, libfdt based format */ #define IMAGE_FORMAT_ANDROID 0x03/* Android boot image */ @@ -567,7 +562,6 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, */ int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images, uint8_t arch, const ulong *ld_start, ulong *const ld_len); -#endif /* !USE_HOSTCC */ int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch, ulong *setup_start, ulong *setup_len); @@ -644,7 +638,6 @@ int fit_image_load(bootm_headers_t *images, ulong addr, */ int image_source_script(ulong addr, const char *fit_uname); -#ifndef USE_HOSTCC /** * fit_get_node_from_config() - Look up an image a FIT by type * @@ -684,10 +677,7 @@ int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size); int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len, ulong *initrd_start, ulong *initrd_end); int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end); -#ifdef CONFIG_SYS_BOOT_GET_KBD int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd); -#endif /* CONFIG_SYS_BOOT_GET_KBD */ -#endif /* !USE_HOSTCC */ /***/ /* Legacy format specific code (prefixed with image_) */ @@ -802,11 +792,9 @@ static inline int image_check_type(const image_header_t *hdr, uint8_t type) } static inline int image_check_arch(const image_header_t *hdr, uint8_t arch) { -#ifndef USE_HOSTCC /* Let's assume that sandbox can load any architecture */ - if (IS_ENABLED(CONFIG_SANDBOX)) + if (!tools_build() && IS_ENABLED(CONFIG_SANDBOX)) return true; -#endif return (image_get_arch(hdr) == arch) || (image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64); } @@ -954,7 +942,6 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size, #define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE -#if CONFIG_IS_ENABLED(FIT) /* cmdline argument format parsing */ int fit_parse_conf(const char *spec, ulong addr_curr, ulong *addr, const char **conf_name); @@ -1128,7 +1115,6 @@ int fit_conf_get_prop_node(const void *fit, int noffset, int fit_check_ramdisk(const void *fit, int os_noffset, uint8_t arch, int verify); -#endif /* FIT */ int calculate_hash(const void *data, int data_len, const char *algo, uint8_t *value, int *value_len); @@ -1141,7 +1127,6 @@ int calculate_hash(const void *data, int data_len, const char *algo, #include #endif -#if CONFIG_IS_ENABLED(FIT) #ifdef USE_HOSTCC void *image_get_host_blob(void); void image_set_host_blob(void *host_blob); @@ -1150,8 +1135,6 @@ void image_set_host_blob(void *host_blob); # define gd_fdt_blob() (gd->fdt_blob) #endif -#endif /* IMAGE_ENABLE_FIT */ - /* * Information passed to the signing routines * @@ -1188,9 +1171,6 @@ struct image_region { int size; }; -#if CONFIG_IS_ENABLED(RSA_VERIFY) -# include -#endif struct checksum_algo { const char *name; const int checksum_len; @@ -1200,7 +1180,7 @@ struct checksum_algo { const EVP_MD *(*calculate_sign)(void); #endif int (*calculate)(const char *name, -
[PATCH v5 26/29] image: Remove some #ifdefs from image-fit and image-fit-sig
Drop the #ifdefs which are easy to remove without refactoring. Signed-off-by: Simon Glass --- (no changes since v1) common/Kconfig.boot| 10 ++ common/image-fit-sig.c | 8 ++-- common/image-fit.c | 7 --- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/common/Kconfig.boot b/common/Kconfig.boot index f23b9988521..9b84a8d005f 100644 --- a/common/Kconfig.boot +++ b/common/Kconfig.boot @@ -165,6 +165,16 @@ config SPL_FIT_SIGNATURE select SPL_IMAGE_SIGN_INFO select SPL_FIT_FULL_CHECK +config SPL_FIT_SIGNATURE_MAX_SIZE + hex "Max size of signed FIT structures in SPL" + depends on SPL_FIT_SIGNATURE + default 0x1000 + help + This option sets a max size in bytes for verified FIT uImages. + A sane value of 256MB protects corrupted DTB structures from overlapping + device memory. Assure this size does not extend past expected storage + space. + config SPL_LOAD_FIT bool "Enable SPL loading U-Boot as a FIT (basic fitImage features)" select SPL_FIT diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c index e95e64bd2fe..4edebbf2d32 100644 --- a/common/image-fit-sig.c +++ b/common/image-fit-sig.c @@ -49,10 +49,8 @@ struct image_region *fit_region_make_list(const void *fit, * Use malloc() except in SPL (to save code size). In SPL the caller * must allocate the array. */ -#ifndef CONFIG_SPL_BUILD - if (!region) + if (!IS_ENABLED(CONFIG_SPL_BUILD) && !region) region = calloc(sizeof(*region), count); -#endif if (!region) return NULL; for (i = 0; i < count; i++) { @@ -72,12 +70,10 @@ static int fit_image_setup_verify(struct image_sign_info *info, char *algo_name; const char *padding_name; -#ifndef USE_HOSTCC - if (fdt_totalsize(fit) > CONFIG_FIT_SIGNATURE_MAX_SIZE) { + if (fdt_totalsize(fit) > CONFIG_VAL(FIT_SIGNATURE_MAX_SIZE)) { *err_msgp = "Total size too large"; return 1; } -#endif if (fit_image_hash_get_algo(fit, noffset, &algo_name)) { *err_msgp = "Can't get hash algo property"; return -1; diff --git a/common/image-fit.c b/common/image-fit.c index 3952ab749ad..5a377a7f85f 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -2009,9 +2009,6 @@ int fit_image_load(bootm_headers_t *images, ulong addr, int type_ok, os_ok; ulong load, load_end, data, len; uint8_t os, comp; -#ifndef USE_HOSTCC - uint8_t os_arch; -#endif const char *prop_name; int ret; @@ -2103,8 +2100,12 @@ int fit_image_load(bootm_headers_t *images, ulong addr, } #ifndef USE_HOSTCC + { + uint8_t os_arch; + fit_image_get_arch(fit, noffset, &os_arch); images->os.arch = os_arch; + } #endif bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); -- 2.33.0.685.g46640cef36-goog
[PATCH v5 23/29] image: Reduce variable scope in boot_get_ramdisk()
Move the variables declarations to where they are needed, to reduce the number of #ifdefs needed. Signed-off-by: Simon Glass --- (no changes since v1) common/image-board.c | 22 +++--- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/common/image-board.c b/common/image-board.c index cbc8a55ba9f..0c9500829a1 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -337,18 +337,8 @@ int genimg_has_config(bootm_headers_t *images) int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, u8 arch, ulong *rd_start, ulong *rd_end) { - ulong rd_addr, rd_load; ulong rd_data, rd_len; -#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) - const image_header_t *rd_hdr; -#endif void *buf; -#if CONFIG_IS_ENABLED(FIT) - const char *fit_uname_config = images->fit_uname_cfg; - const char *fit_uname_ramdisk = NULL; - ulong default_addr; - int rd_noffset; -#endif const char *select = NULL; *rd_start = 0; @@ -373,8 +363,15 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, rd_len = 0; rd_data = 0; } else if (select || genimg_has_config(images)) { + ulong rd_addr, rd_load; + #if CONFIG_IS_ENABLED(FIT) + const char *fit_uname_config = images->fit_uname_cfg; + const char *fit_uname_ramdisk = NULL; + int rd_noffset; + if (select) { + ulong default_addr; /* * If the init ramdisk comes from the FIT image and * the FIT image address is omitted in the command @@ -427,7 +424,9 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, buf = map_sysmem(rd_addr, 0); switch (genimg_get_format(buf)) { #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) - case IMAGE_FORMAT_LEGACY: + case IMAGE_FORMAT_LEGACY: { + const image_header_t *rd_hdr; + printf("## Loading init Ramdisk from Legacy Image at %08lx ...\n", rd_addr); @@ -442,6 +441,7 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, rd_len = image_get_data_size(rd_hdr); rd_load = image_get_load(rd_hdr); break; + } #endif #if CONFIG_IS_ENABLED(FIT) case IMAGE_FORMAT_FIT: -- 2.33.0.685.g46640cef36-goog
[PATCH v5 24/29] image: Split up boot_get_ramdisk()
This function is far too long. Before trying to remove #ifdefs, split out the code that deals with selecting the ramdisk into a separate function. Leave the code indented as it was for easier review. The next patch cleans this up along with checkpatch violations. Signed-off-by: Simon Glass --- Changes in v5: - Drop rd_load since it is not used Changes in v2: - Drop unnecessary setting of rd_len, etc. common/image-board.c | 149 +-- 1 file changed, 86 insertions(+), 63 deletions(-) diff --git a/common/image-board.c b/common/image-board.c index 0c9500829a1..fecc4bf6365 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -313,57 +313,21 @@ int genimg_has_config(bootm_headers_t *images) } /** - * boot_get_ramdisk - main ramdisk handling routine - * @argc: command argument count - * @argv: command argument list + * select_ramdisk() - Select and locate the ramdisk to use + * * @images: pointer to the bootm images structure + * @select: name of ramdisk to select, or NULL for any * @arch: expected ramdisk architecture - * @rd_start: pointer to a ulong variable, will hold ramdisk start address - * @rd_end: pointer to a ulong variable, will hold ramdisk end - * - * boot_get_ramdisk() is responsible for finding a valid ramdisk image. - * Currently supported are the following ramdisk sources: - * - multicomponent kernel/ramdisk image, - * - commandline provided address of decicated ramdisk image. - * - * returns: - * 0, if ramdisk image was found and valid, or skiped - * rd_start and rd_end are set to ramdisk start/end addresses if - * ramdisk image is found and valid - * - * 1, if ramdisk image is found but corrupted, or invalid - * rd_start and rd_end are set to 0 if no ramdisk exists + * @rd_datap: pointer to a ulong variable, will hold ramdisk pointer + * @rd_lenp: pointer to a ulong variable, will hold ramdisk length + * @return 0 if OK, -ENOPKG if no ramdisk (but an error should not be reported), + * other -ve value on other error */ -int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, -u8 arch, ulong *rd_start, ulong *rd_end) +static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch, + ulong *rd_datap, ulong *rd_lenp) { - ulong rd_data, rd_len; - void *buf; - const char *select = NULL; - - *rd_start = 0; - *rd_end = 0; - - if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) { - /* Look for an Android boot image */ - buf = map_sysmem(images->os.start, 0); - if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) - select = (argc == 0) ? env_get("loadaddr") : argv[0]; - } - - if (argc >= 2) - select = argv[1]; - - /* -* Look for a '-' which indicates to ignore the -* ramdisk argument -*/ - if (select && strcmp(select, "-") == 0) { - debug("## Skipping init Ramdisk\n"); - rd_len = 0; - rd_data = 0; - } else if (select || genimg_has_config(images)) { - ulong rd_addr, rd_load; + ulong rd_addr; + char *buf; #if CONFIG_IS_ENABLED(FIT) const char *fit_uname_config = images->fit_uname_cfg; @@ -403,16 +367,16 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, } else { /* use FIT configuration provided in first bootm * command argument. If the property is not defined, -* quit silently. +* quit silently (with -ENOPKG) */ rd_addr = map_to_sysmem(images->fit_hdr_os); rd_noffset = fit_get_node_from_config(images, FIT_RAMDISK_PROP, rd_addr); if (rd_noffset == -ENOENT) - return 0; + return -ENOPKG; else if (rd_noffset < 0) - return 1; + return rd_noffset; } #endif @@ -435,11 +399,10 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, images->verify); if (!rd_hdr) - return 1; + return -ENOENT; - rd_data = image_get_data(rd_hdr); - rd_len = image_get_data_size(rd_hdr); - rd_load = image_get_load(rd_hdr); + *rd_datap = image_get_data(rd_hdr); + *rd_lenp = image_get_data_size(rd_hdr);
[PATCH v5 25/29] image: Remove #ifdefs from select_ramdisk()
Use boolean variables to deal with the strange #ifdef logic of this function, so we can remove the #ifdefs. Signed-off-by: Simon Glass --- Changes in v5: - Rebase to next common/image-board.c | 139 ++- 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/common/image-board.c b/common/image-board.c index fecc4bf6365..742ca66298b 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -26,7 +26,6 @@ DECLARE_GLOBAL_DATA_PTR; -#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) /** * image_get_ramdisk - get and verify ramdisk image * @rd_addr: ramdisk image start address @@ -85,7 +84,6 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, u8 arch, return rd_hdr; } -#endif /*/ /* Shared dual-format routines */ @@ -326,16 +324,18 @@ int genimg_has_config(bootm_headers_t *images) static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch, ulong *rd_datap, ulong *rd_lenp) { - ulong rd_addr; + ulong rd_addr = 0; char *buf; + const char *fit_uname_config = images->fit_uname_cfg; + const char *fit_uname_ramdisk = NULL; + bool processed; + int rd_noffset; -#if CONFIG_IS_ENABLED(FIT) - const char *fit_uname_config = images->fit_uname_cfg; - const char *fit_uname_ramdisk = NULL; - int rd_noffset; + if (select) { + ulong default_addr; + bool done = true; - if (select) { - ulong default_addr; + if (CONFIG_IS_ENABLED(FIT)) { /* * If the init ramdisk comes from the FIT image and * the FIT image address is omitted in the command @@ -347,8 +347,8 @@ static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch, else default_addr = image_load_addr; - if (fit_parse_conf(select, default_addr, - &rd_addr, &fit_uname_config)) { + if (fit_parse_conf(select, default_addr, &rd_addr, + &fit_uname_config)) { debug("* ramdisk: config '%s' from image at 0x%08lx\n", fit_uname_config, rd_addr); } else if (fit_parse_subimage(select, default_addr, @@ -356,60 +356,58 @@ static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch, &fit_uname_ramdisk)) { debug("* ramdisk: subimage '%s' from image at 0x%08lx\n", fit_uname_ramdisk, rd_addr); - } else -#endif - { - rd_addr = hextoul(select, NULL); - debug("* ramdisk: cmdline image address = 0x%08lx\n", - rd_addr); + } else { + done = false; } -#if CONFIG_IS_ENABLED(FIT) - } else { - /* use FIT configuration provided in first bootm -* command argument. If the property is not defined, -* quit silently (with -ENOPKG) -*/ - rd_addr = map_to_sysmem(images->fit_hdr_os); - rd_noffset = fit_get_node_from_config(images, - FIT_RAMDISK_PROP, - rd_addr); - if (rd_noffset == -ENOENT) - return -ENOPKG; - else if (rd_noffset < 0) - return rd_noffset; } -#endif - - /* -* Check if there is an initrd image at the -* address provided in the second bootm argument -* check image type, for FIT images get FIT node. + if (!done) { + rd_addr = hextoul(select, NULL); + debug("* ramdisk: cmdline image address = 0x%08lx\n", + rd_addr); + } + } else if (CONFIG_IS_ENABLED(FIT)) { + /* use FIT configuration provided in first bootm +* command argument. If the property is not defined, +* quit silently (with -ENOPKG ) */ - buf = map_sysmem(rd_addr, 0); - switch (genimg_get_format(buf)) { -#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) - case IMAGE_FORMAT_LEGACY: { +