Re: [PATCH 08/12] net/httpd: add httpd common code
On 7/1/24 19:54, Peter Robinson wrote: > Hi Mikhail, > >> This patch adds HTTP/1.1 compatible web-server that can be used >> by other. Server supports GET, POST, and HEAD requests. On client >> request it will call user specified GET/POST callback. Then results >> will be transmitted to client. > Why are we adding a HTTP server? I don't see a cover letter explaining > overall what you're attempting to achieve with this patch set so > please add that. Also I suggest you look at the LWIP patch set [1] as > that may make what you wish to achieve more straight forward. > > Peter > > [1] https://lists.denx.de/pipermail/u-boot/2024-June/556526.html This patch series consist of * TCP fixes. Current U-Boot implementation of TCP is bad. It is especially bad for uploading. This patch series fixes TCP support. I know about attempts to add LWIP to u-Boot, but it's not in U-Boot yet. * Rewrite of existing TCP clients (wget, fastboot_tcp) on the base of new code * netcat client/server. It was written to test data downloading and uploading using TCP. * HTTPD support. It consist of 2 parts: common code and sample web-server. Sample web-server can be used as a reference httpd implementation. We use this HTTPD support for our firmware upgrade web-server. It is similar to the sample web-server. PS: Will resend patches with a cover letter tomorrow. >> The following restrictions exist on the POST request >> at the moment: >> * only multipart/form-data with a single file object >> * object will be stored to a memory area specified in >> image_load_addr variable >> >> Signed-off-by: Mikhail Kshevetskiy >> --- >> include/net.h | 2 +- >> include/net/httpd.h | 64 >> net/Kconfig | 14 + >> net/Makefile| 1 + >> net/httpd.c | 695 >> net/net.c | 6 + >> 6 files changed, 781 insertions(+), 1 deletion(-) >> create mode 100644 include/net/httpd.h >> create mode 100644 net/httpd.c >> >> diff --git a/include/net.h b/include/net.h >> index 235396a171b..6debbf8ed2a 100644 >> --- a/include/net.h >> +++ b/include/net.h >> @@ -516,7 +516,7 @@ extern int net_restart_wrap; /* Tried all >> network devices */ >> enum proto_t { >> BOOTP, RARP, ARP, TFTPGET, DHCP, DHCP6, PING, PING6, DNS, NFS, CDP, >> NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT_UDP, >> FASTBOOT_TCP, >> - WOL, UDP, NCSI, WGET, NETCAT_LOAD, NETCAT_STORE, RS >> + WOL, UDP, NCSI, WGET, NETCAT_LOAD, NETCAT_STORE, HTTPD, RS >> }; >> >> extern charnet_boot_file_name[1024];/* Boot File name */ >> diff --git a/include/net/httpd.h b/include/net/httpd.h >> new file mode 100644 >> index 000..ff0dc93ecf5 >> --- /dev/null >> +++ b/include/net/httpd.h >> @@ -0,0 +1,64 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +/* >> + * httpd support header file >> + * Copyright (C) 2024 IOPSYS Software Solutions AB >> + * Author: Mikhail Kshevetskiy >> + * >> + */ >> +#ifndef __NET_HTTPD_COMMON_H__ >> +#define __NET_HTTPD_COMMON_H__ >> + >> +struct http_reply { >> + int code; >> + const char *code_msg; >> + const char *data_type; >> + void*data; >> + u32 len; >> +}; >> + >> +struct httpd_post_data { >> + const char *name; >> + const char *filename; >> + void*addr; >> + u32 size; >> +}; >> + >> +enum httpd_req_check { >> + HTTPD_REQ_OK, >> + HTTPD_BAD_URL, >> + HTTPD_BAD_REQ, >> + HTTPD_CLNT_RST >> +}; >> + >> +struct httpd_config { >> + enum net_loop_state (*on_stop)(void); >> + void(*on_req_end)(void *req_id); >> + >> + enum httpd_req_check(*pre_get)(void *req_id, const char *url); >> + enum httpd_req_check(*pre_post)(void *req_id, const char *url, >> + struct httpd_post_data *post); >> + >> + struct http_reply * (*get)(void *req_id, const char *url); >> + struct http_reply * (*post)(void *req_id, const char *url, >> + struct httpd_post_data *post); >> + >> + struct http_reply *error_400; >> + struct http_reply *error_404; >> +}; >> + >> +/** >> + * httpd_setup() - configure the webserver >> + */ >> +void httpd_setup(struct httpd_config *config); >> + >> +/** >> + * httpd_stop() - start stopping of the webserver >> + */ >> +void httpd_stop(void); >> + >> +/** >> + * httpd_start() - start the webserver >> + */ >> +void httpd_start(void); >> + >> +#endif /* __NET_HTTPD_COMMON_H__ */ >> diff --git a/net/Kconfig b/net/Kconfig >> index 5dff6336293..424c5f0dae8 100644 >> --- a/net/Kconfig >> +++ b/net/Kconfig >> @@ -243,6 +243,20 @@ config PROT_TCP_SACK >> This option should be turn on if you want to achieve the fastest >> file transfer possible. >> >> +config HTTPD_COMMON
Re: [PATCH] gpt: allow spaces in partition list
On 7/2/24 19:51, Simon Glass wrote: > Hi Mikhail, > > On Tue, 2 Jul 2024 at 10:42, Mikhail Kshevetskiy > wrote: >> >> On 27.06.2024 22:05, Simon Glass wrote: >>> Hi Mikhail, >>> >>> On Thu, 27 Jun 2024 at 12:29, Mikhail Kshevetskiy >>> wrote: This allows spliting partition list to several lines in environment file ex: gpt_partition_list= name=boot1,size=5MiB,start=0x10; name=boot2,size=5MiB; name=rootfs1,size=70MiB; name=rootfs2,size=70MiB; name=overlay1,size=20MiB; name=overlay2,size=20MiB; name=art,size=4MiB; >>> Is this referring to a .env file, i.e. a text environment file? If so, >>> I would hope that spaces at the start of a line would be automatically >>> removed. >> This is refer to a .env file, so starting space/tabs will be removed, >> all '\n' will be replaced by spaces. Thus we will get a single line where >> each partition divided from other with a single space (like below) >> >> gpt_partition_list=name=boot1,size=5MiB,start=0x10; >> name=boot2,size=5MiB; ... > Reviewed-by: Simon Glass > > But I wonder if the \t is needed? no, \t is not mandatory. Spaces can be used instead. > Signed-off-by: Mikhail Kshevetskiy --- cmd/gpt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/gpt.c b/cmd/gpt.c index 7aaf1889a5a..2b29ab98ccc 100644 --- a/cmd/gpt.c +++ b/cmd/gpt.c @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char *key) k = strsep(&v, "="); if (!k) break; + k += strspn(k, " \t"); if (strcmp(k, key) == 0) { new = strdup(v); break; @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key) k = strsep(&s, ","); if (!k) break; + k += strspn(k, " \t"); if (strcmp(k, key) == 0) { result = true; break; -- 2.43.0 > Regards, > Simon
Re: [PATCH 1/2] spi: soft_spi: fix miso gpio property name
Hi Mikhail, On Tue, Jul 2, 2024 at 10:16 PM Mikhail Kshevetskiy wrote: > > The patch fix a missprint introduced in commit 2e9fe73a883a ("spi: soft_spi: > Support the recommended soft spi properties"). > > Signed-off-by: Mikhail Kshevetskiy Thanks for the fix: Reviewed-by: Fabio Estevam
Re: [PATCH v4 00/29] Integrate MbedTLS v3.6 LTS with U-Boot
On Tue, Jul 02, 2024 at 11:22:36AM -0700, Raymond Mao wrote: > Integrate MbedTLS v3.6 LTS (currently v3.6.0-RC1) with U-Boot. > > Motivations: > > > 1. MbedTLS is well maintained with LTS versions. > 2. LWIP is integrated with MbedTLS and easily to enable HTTPS. > 3. MbedTLS recently switched license back to GPLv2. > > Prerequisite: > - > > This patch series requires mbedtls git repo to be added as a > subtree to the main U-Boot repo via: > $ git subtree add --prefix lib/mbedtls/external/mbedtls \ > https://github.com/Mbed-TLS/mbedtls.git \ > v3.6.0 --squash > Moreover, due to the Windows-style files from mbedtls git repo, > we need to convert the CRLF endings to LF and do a commit manually: > $ git add --renormalize . > $ git commit > > New Kconfig options: > > > `MBEDTLS_LIB` is for MbedTLS general switch. > `MBEDTLS_LIB_CRYPTO` is for replacing original digest and crypto libs with > MbedTLS. > `MBEDTLS_LIB_X509` is for replacing original X509, PKCS7, MSCode, ASN1, > and Pubkey parser with MbedTLS. > `MBEDTLS_LIB_TLS` is for SSL/TLS (Disabled until LWIP port for MbedTLS is > ready). > `LEGACY_CRYPTO` is introduced as a main switch for legacy crypto library. > `LEGACY_CRYPTO_BASIC` is for the basic crypto functionalities and > `LEGACY_CRYPTO_CERT` is for the certificate related functionalities. > For each of the algorithm, a pair of `_LEGACY` and `_MBEDTLS` > Kconfig options are introduced. Meanwhile, `SPL_` Kconfig options are > introduced. > > In this patch set, MBEDTLS_LIB, MBEDTLS_LIB_CRYPTO and MBEDTLS_LIB_X509 > are by default enabled in qemu_arm64_defconfig for testing purpose. > > Patches for external MbedTLS project: > - > > Since U-Boot uses Microsoft Authentication Code to verify PE/COFFs > executables which is not supported by MbedTLS at the moment, > addtional patches for MbedTLS are created to adapt with the EFI loader: > 1. Decoding of Microsoft Authentication Code. > 2. Decoding of PKCS#9 Authenticate Attributes. > 3. Extending MbedTLS PKCS#7 lib to support multiple signer's certificates. > 4. MbedTLS native test suites for PKCS#7 signer's info. > > All above 4 patches (tagged with `mbedtls/external`) are submitted to > MbedTLS project and being reviewed, eventually they should be part of > MbedTLS LTS release. > But before that, please merge them into U-Boot, otherwise the building > will be broken when MBEDTLS_LIB_X509 is enabled. > > See below PR link for the reference: > https://github.com/Mbed-TLS/mbedtls/pull/9001 > > Miscellaneous: > -- > > Optimized MbedTLS library size by tailoring the config file > and disabling all unnecessary features for EFI loader. > From v2, original libs (rsa, asn1_decoder, rsa_helper, md5, sha1, sha256, > sha512) are completely replaced when MbedTLS is enabled. > From v3, the size-growth is slightly reduced by refactoring Hash functions. > > Target(QEMU arm64) size-growth when enabling MbedTLS: > v1: 6.03% > v2: 4.66% > v3 & v4: 4.55% > > Please see the latest output of bloat-o-meter for the reference of the > size-growth on QEMU arm64 target [1]. > > Tests done: > --- > > EFI Secure Boot test (EFI variables loading and verifying, EFI signed image > verifying and booting) via U-Boot console. > EFI Secure Boot and Capsule sandbox test passed. > > Known issues: > - > > None. > > [1]: bloat-o-meter output between disabling/enabling MbedTLS (QEMU arm64) > ``` > add/remove: 206/81 grow/shrink: 19/17 up/down: 55548/-17495 (38053) bloat-o-meter is a bit off then, since buildman shows: u-boot: add: 243/-17, grow: 18/-17 bytes: 65723/-8480 (57243) (Please use buildman for the size comparisons in the future). And in both cases, there's a pretty big non-removal of code I was expecting since overall we're replacing a lot of functionality, not just enabling new functionality? If I'm wrong about that and we're doing both, please separate out "enables new features" from "feature parity with legacy" in commit updates to qemu_arm64 since buildman's handy "show the delta for each commit in a series" is quite helpful in spotting when we changed more/less than expected. And in this case perhaps qemu_army64 wasn't fully enabling stuff before? sandbox changes by only ~16Kib which is much better and I see pkcs7 and x509 related removals in the size comparison. Another note is that qemu-x86_64, which should be similar in EFI feature function only grows by 129 bytes. Which isn't zero, but isn't bad. I haven't done a for-each-commit build, but if we have generic bugfixes here, we should split those out. For example, I do see we're dropping some legacy hash related code, but I'd want to dig a bit to make sure it's all of it. And for v4 I'm not doing a world build comparison with mbedTLS being default rather than legacy since I think the logic there is where some of the Kconfig issues I mentioned are from and so
[PATCH 1/2] spi: soft_spi: fix miso gpio property name
The patch fix a missprint introduced in commit 2e9fe73a883a ("spi: soft_spi: Support the recommended soft spi properties"). Signed-off-by: Mikhail Kshevetskiy --- drivers/spi/soft_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c index 0fa14339bdc..3fe62818a44 100644 --- a/drivers/spi/soft_spi.c +++ b/drivers/spi/soft_spi.c @@ -272,7 +272,7 @@ static int soft_spi_probe(struct udevice *dev) ret = gpio_request_by_name(dev, "gpio-miso", 0, &plat->miso, GPIOD_IS_IN); if (ret) - ret = gpio_request_by_name(dev, "gpio-miso", 0, &plat->miso, + ret = gpio_request_by_name(dev, "miso-gpios", 0, &plat->miso, GPIOD_IS_IN); if (ret) plat->flags |= SPI_MASTER_NO_RX; -- 2.39.2
[PATCH 2/2] spi: soft_spi: Parse cs-gpios only if num-chipselects is not <0>
From: Michael Polyntsov Some boards don't have chipselect lines for leds so cs-gpios is not specified in the dts leading to probing error. Fix it by making behavior similar to the one in Linux, parse num-chipselects and if it is zero, ignore cs-gpios. Signed-off-by: Michael Polyntsov Signed-off-by: Mikhail Kshevetskiy --- doc/device-tree-bindings/spi/soft-spi.txt | 5 +++-- drivers/spi/soft_spi.c| 22 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/device-tree-bindings/spi/soft-spi.txt b/doc/device-tree-bindings/spi/soft-spi.txt index bdf7e86befb..77b01b2fd9a 100644 --- a/doc/device-tree-bindings/spi/soft-spi.txt +++ b/doc/device-tree-bindings/spi/soft-spi.txt @@ -8,14 +8,15 @@ The soft SPI node requires the following properties: Mandatory properties: compatible: "spi-gpio" -cs-gpios: GPIOs to use for SPI chip select (output) +cs-gpios: GPIOs to use for SPI chip select (output), not required if num-chipselects = <0> sck-gpios: GPIO to use for SPI clock (output) And at least one of: mosi-gpios: GPIO to use for SPI MOSI line (output) miso-gpios: GPIO to use for SPI MISO line (input) -Optional propertie: +Optional properties: spi-delay-us: Number of microseconds of delay between each CS transition +num-chipselects: Number of chipselect lines The GPIOs should be specified as required by the GPIO controller referenced. The first cell holds the phandle of the controller and the second cell diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c index 3fe62818a44..2e80b7bb08e 100644 --- a/drivers/spi/soft_spi.c +++ b/drivers/spi/soft_spi.c @@ -238,6 +238,18 @@ static int soft_spi_of_to_plat(struct udevice *dev) return 0; } +static int retrieve_num_chipselects(struct udevice *dev) +{ + int chipselects; + int ret; + + ret = ofnode_read_u32(dev_ofnode(dev), "num-chipselects", &chipselects); + if (ret) + return ret; + + return chipselects; +} + static int soft_spi_probe(struct udevice *dev) { struct spi_slave *slave = dev_get_parent_priv(dev); @@ -250,7 +262,15 @@ static int soft_spi_probe(struct udevice *dev) ret = gpio_request_by_name(dev, "cs-gpios", 0, &plat->cs, GPIOD_IS_OUT | cs_flags); - if (ret) + /* +* If num-chipselects is zero we're ignoring absence of cs-gpios. This +* code relies on the fact that `gpio_request_by_name` call above +* initiailizes plat->cs to correct value with invalid GPIO even when +* there is no cs-gpios node in dts. All other functions which work +* with plat->cs verify it via `dm_gpio_is_valid` before using it, so +* such value doesn't cause any problems. +*/ + if (ret && retrieve_num_chipselects(dev) != 0) return -EINVAL; ret = gpio_request_by_name(dev, "gpio-sck", 0, &plat->sclk, -- 2.39.2
[PATCH 2/2] led: Add dts property to specify blinking of the led
From: Michael Polyntsov The standard property linux,default-trigger = "pattern"; used to get an effect. No blinking parameters can be set yet. Signed-off-by: Michael Polyntsov Signed-off-by: Mikhail Kshevetskiy --- drivers/led/led-uclass.c | 34 ++ 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c index d021c3bbf20..78d1a3d152b 100644 --- a/drivers/led/led-uclass.c +++ b/drivers/led/led-uclass.c @@ -190,6 +190,9 @@ static int led_post_bind(struct udevice *dev) { struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); const char *default_state; +#ifdef CONFIG_LED_BLINK + const char *trigger; +#endif if (!uc_plat->label) uc_plat->label = dev_read_string(dev, "label"); @@ -210,6 +213,13 @@ static int led_post_bind(struct udevice *dev) else return 0; +#ifdef CONFIG_LED_BLINK + trigger = dev_read_string(dev, "linux,default-trigger"); + if (trigger && !strncmp(trigger, "pattern", 7)) { + uc_plat->default_state = LEDST_BLINK; + } +#endif + /* * In case the LED has default-state DT property, trigger * probe() to configure its default state during startup. @@ -222,12 +232,28 @@ static int led_post_bind(struct udevice *dev) static int led_post_probe(struct udevice *dev) { struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); + int rc = 0; - if (uc_plat->default_state == LEDST_ON || - uc_plat->default_state == LEDST_OFF) - led_set_state(dev, uc_plat->default_state); + switch (uc_plat->default_state) { + case LEDST_ON: + case LEDST_OFF: + rc = led_set_state(dev, uc_plat->default_state); + break; +#ifdef CONFIG_LED_BLINK + case LEDST_BLINK: { + const int default_period_ms = 1000; - return 0; + rc = led_set_period(dev, default_period_ms); + if (rc == 0) + rc = led_set_state(dev, uc_plat->default_state); + break; + } +#endif + default: + break; + } + + return rc; } UCLASS_DRIVER(led) = { -- 2.39.2
[PATCH 1/2] led: Implement software led blinking
From: Michael Polyntsov If hardware (or driver) doesn't support leds blinking, it's now possible to use software implementation of blinking instead. This relies on cyclic functions. v2 changes: * Drop sw_blink_state structure, move its necessary fields to led_uc_plat structure. * Add cyclic_info pointer to led_uc_plat structure. This simplify code a lot. * Remove cyclic function search logic. Not needed anymore. * Fix blinking period. It was twice large. * Other cleanups. Signed-off-by: Michael Polyntsov Signed-off-by: Mikhail Kshevetskiy --- drivers/led/Kconfig | 14 ++ drivers/led/led-uclass.c | 102 +++ include/led.h| 12 + 3 files changed, 128 insertions(+) diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index 9837960198d..1afb081df11 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -73,6 +73,20 @@ config LED_BLINK This option enables support for this which adds slightly to the code size. +config LED_SW_BLINK + bool "Support software LED blinking" + depends on LED_BLINK + select CYCLIC + help + Turns on led blinking implemented in the software, useful when + the hardware doesn't support led blinking. Half of the period + led will be ON and the rest time it will be OFF. Standard + led commands can be used to configure blinking. Does nothing + if driver supports blinking. + WARNING: Blinking may be inaccurate during execution of time + consuming commands (ex. flash reading). Also it will completely + stops during OS booting. + config SPL_LED bool "Enable LED support in SPL" depends on SPL_DM diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c index a4be56fc258..d021c3bbf20 100644 --- a/drivers/led/led-uclass.c +++ b/drivers/led/led-uclass.c @@ -52,6 +52,94 @@ int led_get_by_label(const char *label, struct udevice **devp) return -ENODEV; } +#ifdef CONFIG_LED_SW_BLINK +static void led_sw_blink(void *data) +{ + struct udevice *dev = data; + struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); + struct led_ops *ops = led_get_ops(dev); + + switch (uc_plat->sw_blink_state) { + case LED_SW_BLINK_ST_OFF: + uc_plat->sw_blink_state = LED_SW_BLINK_ST_ON; + ops->set_state(dev, LEDST_ON); + break; + case LED_SW_BLINK_ST_ON: + uc_plat->sw_blink_state = LED_SW_BLINK_ST_OFF; + ops->set_state(dev, LEDST_OFF); + break; + case LED_SW_BLINK_ST_NONE: + /* +* led_set_period has been called, but +* led_set_state(LDST_BLINK) has not yet, +* so doing nothing +*/ + break; + } +} + +static int led_sw_set_period(struct udevice *dev, int period_ms) +{ + struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); + struct cyclic_info *cyclic = uc_plat->cyclic; + struct led_ops *ops = led_get_ops(dev); + char cyclic_name[64]; + int half_period_us; + + uc_plat->sw_blink_state = LED_SW_BLINK_ST_NONE; + ops->set_state(dev, LEDST_OFF); + + half_period_us = period_ms * 1000 / 2; + + if (cyclic) { + cyclic->delay_us = half_period_us; + cyclic->start_time_us = timer_get_us(); + } else { + snprintf(cyclic_name, sizeof(cyclic_name), +"led_sw_blink_%s", uc_plat->label); + + cyclic = cyclic_register(led_sw_blink, half_period_us, +cyclic_name, dev); + if (!cyclic) { + log_err("Registering of blinking function for %s failed\n", + uc_plat->label); + return -ENOMEM; + } + + uc_plat->cyclic = cyclic; + } + + return 0; +} + +static bool led_sw_is_blinking(struct udevice *dev) +{ + struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); + + return (uc_plat->sw_blink_state != LED_SW_BLINK_ST_NONE); +} + +static bool led_sw_on_state_change(struct udevice *dev, enum led_state_t state) +{ + struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); + + if (uc_plat->cyclic) { + if (state == LEDST_BLINK) { + /* start blinking on next led_sw_blink() call */ + uc_plat->sw_blink_state = LED_SW_BLINK_ST_OFF; + return true; + } + + /* stop blinking */ + cyclic_unregister(uc_plat->cyclic); + uc_plat->cyclic = NULL; + uc_plat->sw_blink_state = LED_SW_BLINK_ST_NONE; + } + + return false; +} +#endif /* CONFIG_LED_SW_BLINK */ + int led_set_state(struct udevice *dev, enum led_state_t state) { struct led_ops *
led blinking patches
Hi Simon and all, This patch series implements: * software led blinking (via cyclic functions) * add support of dts property to specify blinking of the led v2 changes: * Drop sw_blink_state structure, move its necessary fields to led_uc_plat structure. * Add cyclic_info pointer to led_uc_plat structure. This simplify code a lot. * Remove cyclic function search logic. Not needed anymore. * Fix blinking period. It was twice large. * Other cleanups. Thanks, Mikhail Kshevetskiy
RE: [PATCH] mx9: Correct repeatable build error
> Subject: [PATCH] mx9: Correct repeatable build error > > For some reason every second time imx93_11x11_evk is built it gives > an > error: > >make O=/tmp/x BINMAN_ALLOW_MISSING=1 > > It seems to sometimes skip generation of the .cfgout file and then > eventually Binman complains: > >ValueError: Error 1 running 'mkimage -d ./mkimage.spl.mkimage -n > spl/u-boot-spl.cfgout -T imx8image -e 0x2049A000 > ./mkimage-out.spl.mkimage': Fail open first container file > mx93a1-ahab-container.img > > Correct this by using if_changed instead of if_changed_dep > > The only reason this hasn't come up in CI is that buildman did not retry > failing builds of current source, but now it does. > > Note: The logic in this Makefile should be moved to Binman, e.g. these > warnings duplicate Binman functionality: > > WARNING 'bl31.bin' not found, resulting binary may be not-functional > WARNING 'tee.bin' not found, resulting binary may be not-functional > > Signed-off-by: Simon Glass Reviewed-by: Peng Fan
Re: [PATCH v4 04/29] lib: Adapt digest header files to MbedTLS
On Tue, Jul 02, 2024 at 08:02:37PM -0400, Raymond Mao wrote: > Hi Tom, > > On Tue, 2 Jul 2024 at 18:48, Tom Rini wrote: > > > On Tue, Jul 02, 2024 at 11:22:40AM -0700, Raymond Mao wrote: > > > > > Adapt digest header files to support both original libs and MbedTLS > > > by switching on/off MBEDTLS_LIB_CRYPTO. > > > Introduce _LEGACY kconfig for legacy hash implementations. > > [snip] > > > diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig > > > index 3e9057f1acf..6662a9d20f1 100644 > > > --- a/lib/mbedtls/Kconfig > > > +++ b/lib/mbedtls/Kconfig > > > @@ -21,9 +21,105 @@ if LEGACY_CRYPTO > > > > > > config LEGACY_CRYPTO_BASIC > > > bool "legacy basic crypto libraries" > > > + select MD5_LEGACY if MD5 > > > + select SHA1_LEGACY if SHA1 > > > + select SHA256_LEGACY if SHA256 > > > + select SHA512_LEGACY if SHA512 > > > + select SHA384_LEGACY if SHA384 > > > + select SPL_MD5_LEGACY if MD5 && SPL > > > + select SPL_SHA1_LEGACY if SHA1 && SPL > > > + select SPL_SHA256_LEGACY if SHA256 && SPL > > > + select SPL_SHA512_LEGACY if SHA512 && SPL > > > + select SPL_SHA384_LEGACY if SHA384 && SPL > > > help > > > Enable legacy basic crypto libraries. > > > > > > +if LEGACY_CRYPTO_BASIC > > > + > > > +config SHA1_LEGACY > > > + bool "Enable SHA1 support with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SHA1 > > > + help > > > + This option enables support of hashing using SHA1 algorithm > > > + with legacy crypto library. > > > + > > > +config SHA256_LEGACY > > > + bool "Enable SHA256 support with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SHA256 > > > + help > > > + This option enables support of hashing using SHA256 algorithm > > > + with legacy crypto library. > > > + > > > +config SHA512_LEGACY > > > + bool "Enable SHA512 support with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SHA512 > > > + default y if TI_SECURE_DEVICE && FIT_SIGNATURE > > > + help > > > + This option enables support of hashing using SHA512 algorithm > > > + with legacy crypto library. > > > + > > > +config SHA384_LEGACY > > > + bool "Enable SHA384 support with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SHA384 > > > + select SHA512_LEGACY > > > + help > > > + This option enables support of hashing using SHA384 algorithm > > > + with legacy crypto library. > > > + > > > +config MD5_LEGACY > > > + bool "Enable MD5 support with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && MD5 > > > + help > > > + This option enables support of hashing using MD5 algorithm > > > + with legacy crypto library. > > > + > > > +if SPL > > > + > > > +config SPL_SHA1_LEGACY > > > + bool "Enable SHA1 support in SPL with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA1 > > > + default y if SHA1 && LEGACY_CRYPTO_BASIC > > > + help > > > + This option enables support of hashing using SHA1 algorithm > > > + with legacy crypto library. > > > + > > > +config SPL_SHA256_LEGACY > > > + bool "Enable SHA256 support in SPL with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA256 > > > + default y if SHA256 && LEGACY_CRYPTO_BASIC > > > + help > > > + This option enables support of hashing using SHA256 algorithm > > > + with legacy crypto library. > > > + > > > +config SPL_SHA512_LEGACY > > > + bool "Enable SHA512 support in SPL with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA512 > > > + default y if SHA512 && LEGACY_CRYPTO_BASIC > > > + help > > > + This option enables support of hashing using SHA512 algorithm > > > + with legacy crypto library. > > > + > > > +config SPL_SHA384_LEGACY > > > + bool "Enable SHA384 support in SPL with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA384 > > > + default y if SHA384 && LEGACY_CRYPTO_BASIC > > > + select SPL_SHA512 > > > + help > > > + This option enables support of hashing using SHA384 algorithm > > > + with legacy crypto library. > > > + > > > +config SPL_MD5_LEGACY > > > + bool "Enable MD5 support in SPL with legacy crypto library" > > > + depends on LEGACY_CRYPTO_BASIC && SPL_MD5 > > > + default y if MD5 && LEGACY_CRYPTO_BASIC > > > + help > > > + This option enables support of hashing using MD5 algorithm > > > + with legacy crypto library. > > > + > > > +endif # SPL > > > + > > > +endif # LEGACY_CRYPTO_BASIC > > > + > > > config LEGACY_CRYPTO_CERT > > > bool "legacy certificate libraries" > > > help > > > > This is all certainly moving in the right direction, but there's > > dependency issues: > >aarch64: w+ xilinx_zynqmp_kria > > +(xilinx_zynqmp_kria) > > +(xilinx_zynqmp_kria) WARN
Re: [PATCH v4 04/29] lib: Adapt digest header files to MbedTLS
Hi Tom, On Tue, 2 Jul 2024 at 18:48, Tom Rini wrote: > On Tue, Jul 02, 2024 at 11:22:40AM -0700, Raymond Mao wrote: > > > Adapt digest header files to support both original libs and MbedTLS > > by switching on/off MBEDTLS_LIB_CRYPTO. > > Introduce _LEGACY kconfig for legacy hash implementations. > [snip] > > diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig > > index 3e9057f1acf..6662a9d20f1 100644 > > --- a/lib/mbedtls/Kconfig > > +++ b/lib/mbedtls/Kconfig > > @@ -21,9 +21,105 @@ if LEGACY_CRYPTO > > > > config LEGACY_CRYPTO_BASIC > > bool "legacy basic crypto libraries" > > + select MD5_LEGACY if MD5 > > + select SHA1_LEGACY if SHA1 > > + select SHA256_LEGACY if SHA256 > > + select SHA512_LEGACY if SHA512 > > + select SHA384_LEGACY if SHA384 > > + select SPL_MD5_LEGACY if MD5 && SPL > > + select SPL_SHA1_LEGACY if SHA1 && SPL > > + select SPL_SHA256_LEGACY if SHA256 && SPL > > + select SPL_SHA512_LEGACY if SHA512 && SPL > > + select SPL_SHA384_LEGACY if SHA384 && SPL > > help > > Enable legacy basic crypto libraries. > > > > +if LEGACY_CRYPTO_BASIC > > + > > +config SHA1_LEGACY > > + bool "Enable SHA1 support with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SHA1 > > + help > > + This option enables support of hashing using SHA1 algorithm > > + with legacy crypto library. > > + > > +config SHA256_LEGACY > > + bool "Enable SHA256 support with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SHA256 > > + help > > + This option enables support of hashing using SHA256 algorithm > > + with legacy crypto library. > > + > > +config SHA512_LEGACY > > + bool "Enable SHA512 support with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SHA512 > > + default y if TI_SECURE_DEVICE && FIT_SIGNATURE > > + help > > + This option enables support of hashing using SHA512 algorithm > > + with legacy crypto library. > > + > > +config SHA384_LEGACY > > + bool "Enable SHA384 support with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SHA384 > > + select SHA512_LEGACY > > + help > > + This option enables support of hashing using SHA384 algorithm > > + with legacy crypto library. > > + > > +config MD5_LEGACY > > + bool "Enable MD5 support with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && MD5 > > + help > > + This option enables support of hashing using MD5 algorithm > > + with legacy crypto library. > > + > > +if SPL > > + > > +config SPL_SHA1_LEGACY > > + bool "Enable SHA1 support in SPL with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA1 > > + default y if SHA1 && LEGACY_CRYPTO_BASIC > > + help > > + This option enables support of hashing using SHA1 algorithm > > + with legacy crypto library. > > + > > +config SPL_SHA256_LEGACY > > + bool "Enable SHA256 support in SPL with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA256 > > + default y if SHA256 && LEGACY_CRYPTO_BASIC > > + help > > + This option enables support of hashing using SHA256 algorithm > > + with legacy crypto library. > > + > > +config SPL_SHA512_LEGACY > > + bool "Enable SHA512 support in SPL with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA512 > > + default y if SHA512 && LEGACY_CRYPTO_BASIC > > + help > > + This option enables support of hashing using SHA512 algorithm > > + with legacy crypto library. > > + > > +config SPL_SHA384_LEGACY > > + bool "Enable SHA384 support in SPL with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA384 > > + default y if SHA384 && LEGACY_CRYPTO_BASIC > > + select SPL_SHA512 > > + help > > + This option enables support of hashing using SHA384 algorithm > > + with legacy crypto library. > > + > > +config SPL_MD5_LEGACY > > + bool "Enable MD5 support in SPL with legacy crypto library" > > + depends on LEGACY_CRYPTO_BASIC && SPL_MD5 > > + default y if MD5 && LEGACY_CRYPTO_BASIC > > + help > > + This option enables support of hashing using MD5 algorithm > > + with legacy crypto library. > > + > > +endif # SPL > > + > > +endif # LEGACY_CRYPTO_BASIC > > + > > config LEGACY_CRYPTO_CERT > > bool "legacy certificate libraries" > > help > > This is all certainly moving in the right direction, but there's > dependency issues: >aarch64: w+ xilinx_zynqmp_kria > +(xilinx_zynqmp_kria) > +(xilinx_zynqmp_kria) WARNING: unmet direct dependencies detected for > SPL_MD5_LEGACY > +(xilinx_zynqmp_kria) Depends on [n]: LEGACY_CRYPTO [=y] && SPL [=y] && > LEGACY_CRYPTO_BASIC [=y] && SPL_MD5 [=n] > +(xilinx_zynqmp_kria) Selected by [y]: > +(xilinx_zynqmp_kria) - LEGACY_CRYPTO_BASIC [=y] && LEGACY_CRYPTO [=y] > && MD5 [=y] &
Re: [PATCH v3 08/19] test: Introduce the concept of a role
On Thu, Jun 27, 2024 at 09:37:18AM +0100, Simon Glass wrote: > Hi Tom, > > On Wed, 26 Jun 2024 at 15:29, Tom Rini wrote: > > > > On Wed, Jun 26, 2024 at 09:00:33AM +0100, Simon Glass wrote: > > > Hi Tom, > > > > > > On Tue, 25 Jun 2024 at 15:27, Tom Rini wrote: > > > > > > > > On Tue, Jun 25, 2024 at 01:38:08PM +0100, Simon Glass wrote: > > > > > Hi Tom, > > > > > > > > > > On Mon, 24 Jun 2024 at 19:13, Tom Rini wrote: > > > > > > > > > > > > On Sun, Jun 23, 2024 at 02:32:02PM -0600, Simon Glass wrote: > > > > > > > > > > > > > In Labgrid there is the concept of a 'role', which is similar to > > > > > > > the > > > > > > > U-Boot board ID in U-Boot's pytest subsystem. > > > > > > > > > > > > > > The role indicates both the target and information about the > > > > > > > U-Boot > > > > > > > build to use. It can also provide any amount of other > > > > > > > configuration. > > > > > > > The information is obtained using the 'labgrid-client query' > > > > > > > operation. > > > > > > > > > > > > > > Make use of this in tests, so that only the role is required in > > > > > > > gitlab > > > > > > > and other situations. The board type and other things can be > > > > > > > queried > > > > > > > as needed. > > > > > > > > > > > > > > Use a new 'u-boot-test-getrole' script to obtain the requested > > > > > > > information. > > > > > > > > > > > > > > With this it is possible to run lab tests in gitlab with just a > > > > > > > single > > > > > > > 'ROLE' variable for each board. > > > > > > > > > > > > > > Signed-off-by: Simon Glass > > > > > > > --- > > > > > > > > > > > > > > (no changes since v1) > > > > > > > > > > > > > > test/py/conftest.py | 31 +++ > > > > > > > 1 file changed, 27 insertions(+), 4 deletions(-) > > > > > > > > > > > > > > diff --git a/test/py/conftest.py b/test/py/conftest.py > > > > > > > index 6547c6922c6..5de8d7b0e23 100644 > > > > > > > --- a/test/py/conftest.py > > > > > > > +++ b/test/py/conftest.py > > > > > > > @@ -23,6 +23,7 @@ from pathlib import Path > > > > > > > import pytest > > > > > > > import re > > > > > > > from _pytest.runner import runtestprotocol > > > > > > > +import subprocess > > > > > > > import sys > > > > > > > > > > > > > > # Globals: The HTML log file, and the connection to the U-Boot > > > > > > > console. > > > > > > > @@ -79,6 +80,7 @@ def pytest_addoption(parser): > > > > > > > parser.addoption('--gdbserver', default=None, > > > > > > > help='Run sandbox under gdbserver. The argument is the > > > > > > > channel '+ > > > > > > > 'over which gdbserver should communicate, e.g. > > > > > > > localhost:1234') > > > > > > > +parser.addoption('--role', help='U-Boot board role (for > > > > > > > Labgrid)') > > > > > > > parser.addoption('--no-prompt-wait', default=False, > > > > > > > action='store_true', > > > > > > > help="Assume that U-Boot is ready and don't wait for a > > > > > > > prompt") > > > > > > > > > > > > > > @@ -130,12 +132,33 @@ def get_details(config): > > > > > > > str: Build directory > > > > > > > str: Source directory > > > > > > > """ > > > > > > > -board_type = config.getoption('board_type') > > > > > > > -board_identity = config.getoption('board_identity') > > > > > > > +role = config.getoption('role') > > > > > > > build_dir = config.getoption('build_dir') > > > > > > > +if role: > > > > > > > +board_identity = role > > > > > > > +cmd = ['u-boot-test-getrole', role, '--configure'] > > > > > > > +env = os.environ.copy() > > > > > > > +if build_dir: > > > > > > > +env['U_BOOT_BUILD_DIR'] = build_dir > > > > > > > +proc = subprocess.run(cmd, capture_output=True, > > > > > > > encoding='utf-8', > > > > > > > + env=env) > > > > > > > +if proc.returncode: > > > > > > > +raise ValueError(proc.stderr) > > > > > > > +print('conftest: lab:', proc.stdout) > > > > > > > +vals = {} > > > > > > > +for line in proc.stdout.splitlines(): > > > > > > > +item, value = line.split(' ', maxsplit=1) > > > > > > > +k = item.split(':')[-1] > > > > > > > +vals[k] = value > > > > > > > +print('conftest: lab info:', vals) > > > > > > > +board_type, default_build_dir, source_dir = > > > > > > > (vals['board'], > > > > > > > +vals['build_dir'], vals['source_dir']) > > > > > > > +else: > > > > > > > +board_type = config.getoption('board_type') > > > > > > > +board_identity = config.getoption('board_identity') > > > > > > > > > > > > > > -source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR)) > > > > > > > -default_build_dir = source_dir + '/build-' + board_type > > > > > > > +source_dir = > > > > > > > os.path.dirname(os.path.dirname(TEST_PY_DIR)) > > > > > > > +default_build_dir = source_dir
Re: [PATCH v4 04/29] lib: Adapt digest header files to MbedTLS
On Tue, Jul 02, 2024 at 11:22:40AM -0700, Raymond Mao wrote: > Adapt digest header files to support both original libs and MbedTLS > by switching on/off MBEDTLS_LIB_CRYPTO. > Introduce _LEGACY kconfig for legacy hash implementations. [snip] > diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig > index 3e9057f1acf..6662a9d20f1 100644 > --- a/lib/mbedtls/Kconfig > +++ b/lib/mbedtls/Kconfig > @@ -21,9 +21,105 @@ if LEGACY_CRYPTO > > config LEGACY_CRYPTO_BASIC > bool "legacy basic crypto libraries" > + select MD5_LEGACY if MD5 > + select SHA1_LEGACY if SHA1 > + select SHA256_LEGACY if SHA256 > + select SHA512_LEGACY if SHA512 > + select SHA384_LEGACY if SHA384 > + select SPL_MD5_LEGACY if MD5 && SPL > + select SPL_SHA1_LEGACY if SHA1 && SPL > + select SPL_SHA256_LEGACY if SHA256 && SPL > + select SPL_SHA512_LEGACY if SHA512 && SPL > + select SPL_SHA384_LEGACY if SHA384 && SPL > help > Enable legacy basic crypto libraries. > > +if LEGACY_CRYPTO_BASIC > + > +config SHA1_LEGACY > + bool "Enable SHA1 support with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SHA1 > + help > + This option enables support of hashing using SHA1 algorithm > + with legacy crypto library. > + > +config SHA256_LEGACY > + bool "Enable SHA256 support with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SHA256 > + help > + This option enables support of hashing using SHA256 algorithm > + with legacy crypto library. > + > +config SHA512_LEGACY > + bool "Enable SHA512 support with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SHA512 > + default y if TI_SECURE_DEVICE && FIT_SIGNATURE > + help > + This option enables support of hashing using SHA512 algorithm > + with legacy crypto library. > + > +config SHA384_LEGACY > + bool "Enable SHA384 support with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SHA384 > + select SHA512_LEGACY > + help > + This option enables support of hashing using SHA384 algorithm > + with legacy crypto library. > + > +config MD5_LEGACY > + bool "Enable MD5 support with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && MD5 > + help > + This option enables support of hashing using MD5 algorithm > + with legacy crypto library. > + > +if SPL > + > +config SPL_SHA1_LEGACY > + bool "Enable SHA1 support in SPL with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA1 > + default y if SHA1 && LEGACY_CRYPTO_BASIC > + help > + This option enables support of hashing using SHA1 algorithm > + with legacy crypto library. > + > +config SPL_SHA256_LEGACY > + bool "Enable SHA256 support in SPL with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA256 > + default y if SHA256 && LEGACY_CRYPTO_BASIC > + help > + This option enables support of hashing using SHA256 algorithm > + with legacy crypto library. > + > +config SPL_SHA512_LEGACY > + bool "Enable SHA512 support in SPL with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA512 > + default y if SHA512 && LEGACY_CRYPTO_BASIC > + help > + This option enables support of hashing using SHA512 algorithm > + with legacy crypto library. > + > +config SPL_SHA384_LEGACY > + bool "Enable SHA384 support in SPL with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SPL_SHA384 > + default y if SHA384 && LEGACY_CRYPTO_BASIC > + select SPL_SHA512 > + help > + This option enables support of hashing using SHA384 algorithm > + with legacy crypto library. > + > +config SPL_MD5_LEGACY > + bool "Enable MD5 support in SPL with legacy crypto library" > + depends on LEGACY_CRYPTO_BASIC && SPL_MD5 > + default y if MD5 && LEGACY_CRYPTO_BASIC > + help > + This option enables support of hashing using MD5 algorithm > + with legacy crypto library. > + > +endif # SPL > + > +endif # LEGACY_CRYPTO_BASIC > + > config LEGACY_CRYPTO_CERT > bool "legacy certificate libraries" > help This is all certainly moving in the right direction, but there's dependency issues: aarch64: w+ xilinx_zynqmp_kria +(xilinx_zynqmp_kria) +(xilinx_zynqmp_kria) WARNING: unmet direct dependencies detected for SPL_MD5_LEGACY +(xilinx_zynqmp_kria) Depends on [n]: LEGACY_CRYPTO [=y] && SPL [=y] && LEGACY_CRYPTO_BASIC [=y] && SPL_MD5 [=n] +(xilinx_zynqmp_kria) Selected by [y]: +(xilinx_zynqmp_kria) - LEGACY_CRYPTO_BASIC [=y] && LEGACY_CRYPTO [=y] && MD5 [=y] && SPL [=y] Annoyingly I was not able to previously figure out how to make such problems a fatal error, but if you look at the output from each of the world build CI steps you'll see a lot of hits for "WARNING: unmet direct dependencies" and that'll help you track down which are where and what to do ab
Re: [PATCH v4 02/29] mbedtls: Add script to update MbedTLS subtree
On Tue, Jul 02, 2024 at 11:22:38AM -0700, Raymond Mao wrote: > lib/mbedtls/update-mbedtls-subtree.sh is a wrapper of git subtree > commands. > Usage from U-Boot top directory, run: > > $ ./lib/mbedtls/update-mbedtls-subtree.sh pull > $ ./lib/mbedtls/update-mbedtls-subtree.sh pick > > Signed-off-by: Raymond Mao > --- > Changes in v2 > - Initial patch. > Changes in v3 > - None. > Changes in v4 > - Minor fix and move the script into tools dir. > > tools/update-mbedtls-subtree.sh | 47 + > 1 file changed, 47 insertions(+) > create mode 100755 tools/update-mbedtls-subtree.sh Given how amazingly close this is to dts/update-dts-subtree.sh and also the lwIP version, can you and Jerome please co-ordinate on a short series that you can then both depend on a pre-req that makes, I don't know, tools/update-git-subtree.sh and that script takes upstream URI and whatever else would be needed so that all 3 of our "update or cherry-pick from a git subtree" scripts call that and are more or less one line scripts themselves? Thanks. -- Tom signature.asc Description: PGP signature
[PATCH v1] mmc: am654_sdhci: Add the quirk to set TESTCD bit
From: Emanuele Ghidoli The ARASAN MMC controller on Keystone 3 class of devices need the SDCD line to be connected for proper functioning. In cases where this can't be connected, add a quirk to force the controller into test mode and set the TESTCD bit. Use the flag "ti,fails-without-test-cd", to implement this above quirk when required. Additionally, this quirk also avoids waiting for the controller debounce time. This commit is similar to linux kernel commit c7666240ec76 ("drivers: mmc: sdhci_am654: Add the quirk to set TESTCD bit"). Signed-off-by: Emanuele Ghidoli --- drivers/mmc/am654_sdhci.c | 38 +- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/am654_sdhci.c b/drivers/mmc/am654_sdhci.c index fadab7d40bb7..43f890d269e9 100644 --- a/drivers/mmc/am654_sdhci.c +++ b/drivers/mmc/am654_sdhci.c @@ -106,6 +106,8 @@ struct am654_sdhci_plat { #define FREQSEL_2_BIT BIT(2) #define STRBSEL_4_BIT BIT(3) #define DLL_CALIB BIT(4) + u32 quirks; +#define SDHCI_AM654_QUIRK_FORCE_CDTEST BIT(0) }; struct timing_data { @@ -351,10 +353,8 @@ int am654_sdhci_init(struct am654_sdhci_plat *plat) } #define MAX_SDCD_DEBOUNCE_TIME 2000 -static int am654_sdhci_deferred_probe(struct sdhci_host *host) +static int am654_sdhci_cd_poll(struct mmc *mmc) { - struct udevice *dev = host->mmc->dev; - struct am654_sdhci_plat *plat = dev_get_plat(dev); unsigned long start; int val; @@ -369,12 +369,35 @@ static int am654_sdhci_deferred_probe(struct sdhci_host *host) if (get_timer(start) > MAX_SDCD_DEBOUNCE_TIME) return -ENOMEDIUM; - val = mmc_getcd(host->mmc); + val = mmc_getcd(mmc); } while (!val); + return 0; +} + +static int am654_sdhci_deferred_probe(struct sdhci_host *host) +{ + struct udevice *dev = host->mmc->dev; + struct am654_sdhci_plat *plat = dev_get_plat(dev); + int ret; + + if (!(plat->quirks & SDHCI_AM654_QUIRK_FORCE_CDTEST)) { + if (am654_sdhci_cd_poll(host->mmc)) + return -ENOMEDIUM; + } + am654_sdhci_init(plat); - return sdhci_probe(dev); + ret = sdhci_probe(dev); + + if (plat->quirks & SDHCI_AM654_QUIRK_FORCE_CDTEST) { + u8 hostctrlreg = sdhci_readb(host, SDHCI_HOST_CONTROL); + + hostctrlreg |= SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST; + sdhci_writeb(host, hostctrlreg, SDHCI_HOST_CONTROL); + } + + return ret; } static void am654_sdhci_write_b(struct sdhci_host *host, u8 val, int reg) @@ -680,6 +703,9 @@ static int am654_sdhci_probe(struct udevice *dev) regmap_init_mem_index(dev_ofnode(dev), &plat->base, 1); + if (plat->quirks & SDHCI_AM654_QUIRK_FORCE_CDTEST) + am654_sdhci_deferred_probe(host); + return 0; } @@ -729,6 +755,8 @@ static int am654_sdhci_of_to_plat(struct udevice *dev) dev_read_u32(dev, "ti,strobe-sel", &plat->strb_sel); dev_read_u32(dev, "ti,clkbuf-sel", &plat->clkbuf_sel); + if (dev_read_bool(dev, "ti,fails-without-test-cd")) + plat->quirks |= SDHCI_AM654_QUIRK_FORCE_CDTEST; ret = mmc_of_parse(dev, cfg); if (ret) -- 2.34.1
[PATCH 2/2] ext4: Fix zalloc()
The zalloc() function suffers from two problems. 1. If memalign() fails it will return NULL and memset() will use a NULL pointer. 2. memalign() itself seems to crash when more than 2^32 bytes are requested. So, check the return value of memalign() and allocate only of size is less than CONFIG_SYS_MALLOC_LEN. Signed-off-by: Richard Weinberger --- FWIW, I didn't investigate further why memalign() fails for large sizes. Maybe this is an issue on it's own. Thanks, //richard --- fs/ext4/ext4_common.h | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h index 84500e990a..0d1f72ae01 100644 --- a/fs/ext4/ext4_common.h +++ b/fs/ext4/ext4_common.h @@ -43,8 +43,14 @@ static inline void *zalloc(size_t size) { - void *p = memalign(ARCH_DMA_MINALIGN, size); - memset(p, 0, size); + void *p = NULL; + + if (size < CONFIG_SYS_MALLOC_LEN) + p = memalign(ARCH_DMA_MINALIGN, size); + + if (p) + memset(p, 0, size); + return p; } -- 2.35.3
[PATCH 1/2] ext4: Fix integer overflow in ext4fs_read_symlink()
While zalloc() takes a size_t type, adding 1 to the le32 variable will overflow. A carefully crafted ext4 filesystem can exhibit an inode size of 0x and as consequence zalloc() will do a zero allocation. Later in the function the inode size is again used for copying data. So an attacker can overwrite memory. Avoid the overflow by using the __builtin_add_overflow() helper. Signed-off-by: Richard Weinberger --- fs/ext4/ext4_common.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 2ff0dca249..32364b72fb 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -2183,13 +2183,18 @@ static char *ext4fs_read_symlink(struct ext2fs_node *node) struct ext2fs_node *diro = node; int status; loff_t actread; + size_t alloc_size; if (!diro->inode_read) { status = ext4fs_read_inode(diro->data, diro->ino, &diro->inode); if (status == 0) return NULL; } - symlink = zalloc(le32_to_cpu(diro->inode.size) + 1); + + if (__builtin_add_overflow(le32_to_cpu(diro->inode.size), 1, &alloc_size)) + return NULL; + + symlink = zalloc(alloc_size); if (!symlink) return NULL; -- 2.35.3
[PATCH v2] ext4: Improve feature checking
Evaluate the filesystem incompat and ro_compat bit fields to judge whether the filesystem can be read or written. For the read side only a scary warning is shown so far. I'd love to abort mounting too, but I fear this will break some setups where the driver works by chance. Signed-off-by: Richard Weinberger --- changes since v1: - Spelling errors - Coding style - Better log messages --- fs/ext4/ext4_common.c | 14 fs/ext4/ext4_write.c | 12 -- include/ext4fs.h | 52 ++- 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 2ff0dca249..2c42aff06d 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -2386,6 +2386,20 @@ int ext4fs_mount(void) fs->inodesz = 128; fs->gdsize = 32; } else { + int missing = __le32_to_cpu(data->sblock.feature_incompat) & + ~(EXT4_FEATURE_INCOMPAT_SUPP | + EXT4_FEATURE_INCOMPAT_SUPP_LAZY_RO); + + if (missing) { + /* +* This code used to be relaxed about feature flags. +* We don't stop the mount to avoid breaking existing setups. +* But, incompatible features can cause serious read errors. +*/ + log_err("fs uses incompatible features: %08x, ignoring\n", + missing); + } + debug("EXT4 features COMPAT: %08x INCOMPAT: %08x RO_COMPAT: %08x\n", __le32_to_cpu(data->sblock.feature_compatibility), __le32_to_cpu(data->sblock.feature_incompat), diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c index d057f6b5a7..4aae3c5f7f 100644 --- a/fs/ext4/ext4_write.c +++ b/fs/ext4/ext4_write.c @@ -869,6 +869,7 @@ int ext4fs_write(const char *fname, const char *buffer, ALLOC_CACHE_ALIGN_BUFFER(char, filename, 256); bool store_link_in_inode = false; memset(filename, 0x00, 256); + int missing_feat; if (type != FILETYPE_REG && type != FILETYPE_SYMLINK) return -1; @@ -882,8 +883,15 @@ int ext4fs_write(const char *fname, const char *buffer, return -1; } - if (le32_to_cpu(fs->sb->feature_ro_compat) & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) { - printf("Unsupported feature metadata_csum found, not writing.\n"); + missing_feat = le32_to_cpu(fs->sb->feature_incompat) & ~EXT4_FEATURE_INCOMPAT_SUPP; + if (missing_feat) { + log_err("Unsupported features found %08x, not writing.\n", missing_feat); + return -1; + } + + missing_feat = le32_to_cpu(fs->sb->feature_ro_compat) & ~EXT4_FEATURE_RO_COMPAT_SUPP; + if (missing_feat) { + log_err("Unsupported RO compat features found %08x, not writing.\n", missing_feat); return -1; } diff --git a/include/ext4fs.h b/include/ext4fs.h index d96edfd057..79d087b6f9 100644 --- a/include/ext4fs.h +++ b/include/ext4fs.h @@ -34,12 +34,62 @@ struct disk_partition; #define EXT4_TOPDIR_FL 0x0002 /* Top of directory hierarchies*/ #define EXT4_EXTENTS_FL0x0008 /* Inode uses extents */ #define EXT4_EXT_MAGIC 0xf30a -#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM0x0010 + +#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 +#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE0x0002 +#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 +#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 +#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 +#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 +#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 +#define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100 +#define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200 #define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 + +#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002 +#define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 #define EXT4_FEATURE_INCOMPAT_64BIT0x0080 +#define EXT4_FEATURE_INCOMPAT_MMP 0x0100 +#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 +#define EXT4_FEATURE_INCOMPAT_CSUM_SEED 0x2000 +#define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x1 + #define EXT4_INDIRECT_BLOCKS 12 +/* + * Incompat features supported by this implementation. + */ +#define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE | \ + EXT4_FEATURE_INCOMPAT_RECOVER | \ + EXT4_FEATURE_INCOMPAT_EXTENTS | \ + EXT4_FEATURE_INCOMPAT_64BIT | \ + EXT4_FEATURE_INCOMPAT_FLEX_BG) + +/* + * Incompat features supported by this implementation only in a lazy + * way, good enough for reading files. + *
Re: [RESEND PATCH v4 0/3] provide names for emmc hardware partitions
On Tue, Jul 02, 2024 at 11:14:15AM -0700, Tim Harvey wrote: > On Fri, May 31, 2024 at 8:36 AM Tim Harvey wrote: > > > > Modern eMMC v4+ devices have multiple hardware partitions per the JEDEC > > specification described as: > > Boot Area Partition 1 > > Boot Area Partition 2 > > RPMB Partition > > General Purpose Partition 1 > > General Purpose Partition 2 > > General Purpose Partition 3 > > General Purpose Partition 4 > > User Data Area > > > > These are referenced by fields in the PARTITION_CONFIG register > > (Extended CSD Register 179) which is defined as: > > bit 7: reserved > > bit 6: BOOT_ACK > > 0x0: No boot acknowledge sent (default > > 0x1: Boot acknowledge sent during boot operation Bit > > bit 5:3: BOOT_PARTITION_ENABLE > > 0x0: Device not boot enabled (default) > > 0x1: Boot Area partition 1 enabled for boot > > 0x2: Boot Area partition 2 enabled for boot > > 0x3-0x6: Reserved > > 0x7: User area enabled for boot > > bit 2:0 PARTITION_ACCESS > > 0x0: No access to boot partition (default) > > 0x1: Boot Area partition 1 > > 0x2: Boot Area partition 2 > > 0x3: Replay Protected Memory Block (RPMB) > > 0x4: Access to General Purpose partition 1 > > 0x5: Access to General Purpose partition 2 > > 0x6: Access to General Purpose partition 3 > > 0x7: Access to General Purpose partition 4 > > > > Note that setting PARTITION_ACCESS to 0x0 results in selecting the User > > Data Area partition. > > > > You can see above that the two fields BOOT_PARTITION_ENABLE and > > PARTITION_ACCESS do not use the same enumerated values. > > > > U-Boot uses a set of macros to access fields of the PARTITION_CONFIG > > register: > > EXT_CSD_BOOT_ACK_ENABLE (1 << 6) > > EXT_CSD_BOOT_PARTITION_ENABLE (1 << 3) > > EXT_CSD_PARTITION_ACCESS_ENABLE (1 << 0) > > EXT_CSD_PARTITION_ACCESS_DISABLE(0 << 0) > > > > EXT_CSD_BOOT_ACK(x) (x << 6) > > EXT_CSD_BOOT_PART_NUM(x)(x << 3) > > EXT_CSD_PARTITION_ACCESS(x) (x << 0) > > > > EXT_CSD_EXTRACT_BOOT_ACK(x) (((x) >> 6) & 0x1) > > EXT_CSD_EXTRACT_BOOT_PART(x) (((x) >> 3) & 0x7) > > EXT_CSD_EXTRACT_PARTITION_ACCESS(x) ((x) & 0x7) > > > > There are various places in U-Boot where the BOOT_PARTITION_ENABLE field > > is accessed via EXT_CSD_EXTRACT_PARTITION_ACCESS and converted to a > > hardware partition consistent with the definition of the > > PARTITION_ACCESS field used by the various mmc_switch incarnations. > > > > To add some sanity to the distinction between BOOT_PARTITION_ENABLE > > (used to specify the active device on power-cycle) and PARTITION_ACCESS > > (used to switch between hardware partitions) create two enumerated types > > and use them wherever struct mmc * part_config is used or the above > > macros are used. > > > > Additionally provide arrays of the field names and allow those to be > > used in the 'mmc partconf' command and in board support files. > > > > The first patch adds enumerated types and makes use of them which > > represents no compiled code change. > > > > The 2nd patch adds the array of names and uses them in the 'mmc > > partconf' command. > > > > The 3rd patch uses the array of hardware partition names in a board > > support file to show what emmc hardware partition U-Boot is being loaded > > from. > > > > I'm sending this as a series this time around as previously it was > > repsented as two different patches. > > > > Tim Harvey (3): > > mmc: use an enumerated type to represent PARTITION_CONFIG fields > > mmc: allow use of hardware partition names for mmc partconf > > venice: show emmc boot hardware partition > > > > arch/arm/mach-imx/image-container.c | 10 - > > arch/arm/mach-sunxi/board.c | 2 +- > > board/gateworks/venice/spl.c| 20 - > > board/gateworks/venice/venice.c | 22 +- > > board/purism/librem5/librem5.c | 4 ++-- > > board/storopack/smegw01/smegw01.c | 4 ++-- > > cmd/mmc.c | 27 ++ > > cmd/mvebu/bubt.c| 4 ++-- > > common/spl/spl_mmc.c| 4 ++-- > > drivers/mmc/mmc.c | 35 + > > include/mmc.h | 26 + > > 11 files changed, 123 insertions(+), 35 deletions(-) > > > > -- > > 2.25.1 > > > > Greetings, > > Is there any feedback on this series? I got feedback from several > people on my first attempt (cc'd) but nothing on this version. Jaehoon, will you have time to review and pick this up, now that the merge window is open? Thanks. -- Tom signature.asc Description: PGP signature
Re: Please pull u-boot-dm/next
On Tue, Jul 02, 2024 at 04:51:30PM +0100, Simon Glass wrote: > Hi Tom, > > This is for -next but we need to figure out the patch I just sent > first. I can redo the pull if that patch is acceptable, or you can > pick that up first. I thought you meant the i.MX9 patch, but with that applied before your series, CI now fails on those platforms. So yes, lets hold off on whatever is causing that for now and rebase to exclude it. -- Tom signature.asc Description: PGP signature
Re: [RESEND PATCH v4 0/3] provide names for emmc hardware partitions
On Tue, Jul 2, 2024 at 11:25 AM Dragan Simic wrote: > > Hello Tim, > > On 2024-07-02 20:14, Tim Harvey wrote: > > On Fri, May 31, 2024 at 8:36 AM Tim Harvey > > wrote: > >> > >> Modern eMMC v4+ devices have multiple hardware partitions per the > >> JEDEC > >> specification described as: > >> Boot Area Partition 1 > >> Boot Area Partition 2 > >> RPMB Partition > >> General Purpose Partition 1 > >> General Purpose Partition 2 > >> General Purpose Partition 3 > >> General Purpose Partition 4 > >> User Data Area > >> > >> These are referenced by fields in the PARTITION_CONFIG register > >> (Extended CSD Register 179) which is defined as: > >> bit 7: reserved > >> bit 6: BOOT_ACK > >> 0x0: No boot acknowledge sent (default > >> 0x1: Boot acknowledge sent during boot operation Bit > >> bit 5:3: BOOT_PARTITION_ENABLE > >> 0x0: Device not boot enabled (default) > >> 0x1: Boot Area partition 1 enabled for boot > >> 0x2: Boot Area partition 2 enabled for boot > >> 0x3-0x6: Reserved > >> 0x7: User area enabled for boot > >> bit 2:0 PARTITION_ACCESS > >> 0x0: No access to boot partition (default) > >> 0x1: Boot Area partition 1 > >> 0x2: Boot Area partition 2 > >> 0x3: Replay Protected Memory Block (RPMB) > >> 0x4: Access to General Purpose partition 1 > >> 0x5: Access to General Purpose partition 2 > >> 0x6: Access to General Purpose partition 3 > >> 0x7: Access to General Purpose partition 4 > >> > >> Note that setting PARTITION_ACCESS to 0x0 results in selecting the > >> User > >> Data Area partition. > >> > >> You can see above that the two fields BOOT_PARTITION_ENABLE and > >> PARTITION_ACCESS do not use the same enumerated values. > >> > >> U-Boot uses a set of macros to access fields of the PARTITION_CONFIG > >> register: > >> EXT_CSD_BOOT_ACK_ENABLE (1 << 6) > >> EXT_CSD_BOOT_PARTITION_ENABLE (1 << 3) > >> EXT_CSD_PARTITION_ACCESS_ENABLE (1 << 0) > >> EXT_CSD_PARTITION_ACCESS_DISABLE(0 << 0) > >> > >> EXT_CSD_BOOT_ACK(x) (x << 6) > >> EXT_CSD_BOOT_PART_NUM(x)(x << 3) > >> EXT_CSD_PARTITION_ACCESS(x) (x << 0) > >> > >> EXT_CSD_EXTRACT_BOOT_ACK(x) (((x) >> 6) & 0x1) > >> EXT_CSD_EXTRACT_BOOT_PART(x) (((x) >> 3) & 0x7) > >> EXT_CSD_EXTRACT_PARTITION_ACCESS(x) ((x) & 0x7) > >> > >> There are various places in U-Boot where the BOOT_PARTITION_ENABLE > >> field > >> is accessed via EXT_CSD_EXTRACT_PARTITION_ACCESS and converted to a > >> hardware partition consistent with the definition of the > >> PARTITION_ACCESS field used by the various mmc_switch incarnations. > >> > >> To add some sanity to the distinction between BOOT_PARTITION_ENABLE > >> (used to specify the active device on power-cycle) and > >> PARTITION_ACCESS > >> (used to switch between hardware partitions) create two enumerated > >> types > >> and use them wherever struct mmc * part_config is used or the above > >> macros are used. > >> > >> Additionally provide arrays of the field names and allow those to be > >> used in the 'mmc partconf' command and in board support files. > >> > >> The first patch adds enumerated types and makes use of them which > >> represents no compiled code change. > >> > >> The 2nd patch adds the array of names and uses them in the 'mmc > >> partconf' command. > >> > >> The 3rd patch uses the array of hardware partition names in a board > >> support file to show what emmc hardware partition U-Boot is being > >> loaded > >> from. > >> > >> I'm sending this as a series this time around as previously it was > >> repsented as two different patches. > >> > >> Tim Harvey (3): > >> mmc: use an enumerated type to represent PARTITION_CONFIG fields > >> mmc: allow use of hardware partition names for mmc partconf > >> venice: show emmc boot hardware partition > >> > >> arch/arm/mach-imx/image-container.c | 10 - > >> arch/arm/mach-sunxi/board.c | 2 +- > >> board/gateworks/venice/spl.c| 20 - > >> board/gateworks/venice/venice.c | 22 +- > >> board/purism/librem5/librem5.c | 4 ++-- > >> board/storopack/smegw01/smegw01.c | 4 ++-- > >> cmd/mmc.c | 27 ++ > >> cmd/mvebu/bubt.c| 4 ++-- > >> common/spl/spl_mmc.c| 4 ++-- > >> drivers/mmc/mmc.c | 35 > >> + > >> include/mmc.h | 26 + > >> 11 files changed, 123 insertions(+), 35 deletions(-) > > > > Is there any feedback on this series? I got feedback from several > > people on my first attempt (cc'd) but nothing on this version. > > Any chances, please, to provide links to each of the patch and series > versions on https://lore.kernel.org/u-boot/ , together with a brief > changelog and history? I'm having troubles refreshing my memory on > what patches were actually pulled into what series. > > My guess is that other people would also benef
[PATCH v4 29/29] configs: enable MbedTLS as default setting
Enable MbedTLS as default setting for qemu arm64 Signed-off-by: Raymond Mao --- Changes in v2 - None. Changes in v3 - None. Changes in v4 - removed the unused CONFIG_MBEDTLS_LIB_TLS. configs/qemu_arm64_defconfig | 4 configs/sandbox_defconfig| 3 +++ 2 files changed, 7 insertions(+) diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig index 7e166f43908..9e2c490192c 100644 --- a/configs/qemu_arm64_defconfig +++ b/configs/qemu_arm64_defconfig @@ -67,4 +67,8 @@ CONFIG_TPM2_MMIO=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_PCI=y CONFIG_SEMIHOSTING=y +CONFIG_MBEDTLS_LIB=y +CONFIG_MBEDTLS_LIB_CRYPTO=y +CONFIG_MBEDTLS_LIB_X509=y CONFIG_TPM=y +CONFIG_EFI_SECURE_BOOT=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 93b52f2de5c..679bbf69936 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -343,6 +343,9 @@ CONFIG_FS_CBFS=y CONFIG_FS_CRAMFS=y CONFIG_ADDR_MAP=y CONFIG_CMD_DHRYSTONE=y +CONFIG_MBEDTLS_LIB=y +CONFIG_MBEDTLS_LIB_CRYPTO=y +CONFIG_MBEDTLS_LIB_X509=y CONFIG_ECDSA=y CONFIG_ECDSA_VERIFY=y CONFIG_TPM=y -- 2.25.1
[PATCH v4 28/29] test: Remove ASN1 library test
With MBEDTLS_LIB_X509 enabled, we don't build the original ASN1 lib, So remove it from test. Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas --- Changes in v2 - Initial patch. Changes in v3 - None. Changes in v4 - None. test/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Kconfig b/test/Kconfig index e2ec0994a2e..558a9cd49b4 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -32,7 +32,7 @@ if UT_LIB config UT_LIB_ASN1 bool "Unit test for asn1 compiler and decoder function" - depends on SANDBOX + depends on SANDBOX && !MBEDTLS_LIB_X509 default y imply ASYMMETRIC_KEY_TYPE imply ASYMMETRIC_PUBLIC_KEY_SUBTYPE -- 2.25.1
[PATCH v4 27/29] asn1_decoder: add build options for ASN1 decoder
When building with MbedTLS, we are using MbedTLS to decode ASN1 data for x509, pkcs7 and mscode. Introduce _LEGACY and _MBEDTLS kconfigs for ASN1 decoder legacy and MbedTLS implementations respectively. Signed-off-by: Raymond Mao --- Changes in v2 - Initial patch. Changes in v3 - None. Changes in v4 - Introduce _LEGACY and _MBEDTLS kconfigs for ASN1 decoder legacy and MbedTLS implementations respectively. - Update the commit subject. lib/Makefile | 2 +- lib/mbedtls/Kconfig | 28 lib/mbedtls/Makefile | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index f76af77a969..c3b44c3c9ae 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -80,7 +80,7 @@ obj-$(CONFIG_$(SPL_)SHA256_LEGACY) += sha256.o obj-$(CONFIG_$(SPL_)SHA512_LEGACY) += sha512.o obj-$(CONFIG_CRYPT_PW) += crypt/ -obj-$(CONFIG_$(SPL_)ASN1_DECODER) += asn1_decoder.o +obj-$(CONFIG_$(SPL_)ASN1_DECODER_LEGACY) += asn1_decoder.o obj-$(CONFIG_$(SPL_)ZLIB) += zlib/ obj-$(CONFIG_$(SPL_)ZSTD) += zstd/ diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig index 87c500d6ca9..4dd2fe07a1f 100644 --- a/lib/mbedtls/Kconfig +++ b/lib/mbedtls/Kconfig @@ -122,12 +122,14 @@ endif # LEGACY_CRYPTO_BASIC config LEGACY_CRYPTO_CERT bool "legacy certificate libraries" + select ASN1_DECODER_LEGACY if ASN1_DECODER select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE select RSA_PUBLIC_KEY_PARSER_LEGACY if RSA_PUBLIC_KEY_PARSER select X509_CERTIFICATE_PARSER_LEGACY if X509_CERTIFICATE_PARSER select PKCS7_MESSAGE_PARSER_LEGACY if PKCS7_MESSAGE_PARSER select MSCODE_PARSER_LEGACY if MSCODE_PARSER + select SPL_ASN1_DECODER_LEGACY if ASN1_DECODER && SPL select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL select SPL_RSA_PUBLIC_KEY_PARSER_LEGACY if RSA_PUBLIC_KEY_PARSER && SPL @@ -136,6 +138,12 @@ config LEGACY_CRYPTO_CERT if LEGACY_CRYPTO_CERT +config ASN1_DECODER_LEGACY + bool "ASN1 decoder with legacy certificate library" + depends on LEGACY_CRYPTO_CERT && ASN1_DECODER + help + This option chooses legacy certificate library for ASN1 decoder. + config ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY bool "Asymmetric public key crypto with legacy certificate library" depends on LEGACY_CRYPTO_CERT && ASYMMETRIC_PUBLIC_KEY_SUBTYPE @@ -177,6 +185,13 @@ config MSCODE_PARSER_LEGACY if SPL +config SPL_ASN1_DECODER_LEGACY + bool "ASN1 decoder with legacy certificate library in SPL" + depends on LEGACY_CRYPTO_CERT && SPL_ASN1_DECODER + help + This option chooses legacy certificate library for ASN1 decoder in + SPL. + config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY bool "Asymmetric public key crypto with legacy certificate library in SPL" depends on LEGACY_CRYPTO_CERT && SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE @@ -303,12 +318,14 @@ endif # MBEDTLS_LIB_CRYPTO config MBEDTLS_LIB_X509 bool "MbedTLS certificate libraries" + select ASN1_DECODER_MBEDTLS if ASN1_DECODER select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE select RSA_PUBLIC_KEY_PARSER_MBEDTLS if RSA_PUBLIC_KEY_PARSER select X509_CERTIFICATE_PARSER_MBEDTLS if X509_CERTIFICATE_PARSER select PKCS7_MESSAGE_PARSER_MBEDTLS if PKCS7_MESSAGE_PARSER select MSCODE_PARSER_MBEDTLS if MSCODE_PARSER + select SPL_ASN1_DECODER_MBEDTLS if ASN1_DECODER && SPL select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL select SPL_RSA_PUBLIC_KEY_PARSER_MBEDTLS if RSA_PUBLIC_KEY_PARSER && SPL @@ -317,6 +334,11 @@ config MBEDTLS_LIB_X509 if MBEDTLS_LIB_X509 +config ASN1_DECODER_MBEDTLS + bool "ASN1 decoder with MbedTLS certificate library" + help + This option chooses MbedTLS certificate library for ASN1 decoder. + config ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS bool "Asymmetric public key crypto with MbedTLS certificate library" help @@ -356,6 +378,12 @@ config MSCODE_PARSER_MBEDTLS if SPL +config SPL_ASN1_DECODER_MBEDTLS + bool "ASN1 decoder with MbedTLS certificate library in SPL" + help + This option chooses MbedTLS certificate library for ASN1 decoder in + SPL. + config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS bool "Asymmetric public key crypto with MbedTLS certificate library in SPL" help diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile index 9c6991f8783..9b09fbcea28 100644 --- a/lib/mbedtls/Makefile +++ b/lib/mbedtls/Makefile @@ -46,7 +46,7 @@ mbedtls_lib_crypto-$(CONFIG_$(SPL_)SHA512_MBEDTLS) += \ # MbedTLS X509 library obj-$(CONFIG_MBEDTLS_LIB_X509) += mbedtls_lib_x509.o mbedtls_lib_x509-y += $(MBEDTLS_LIB_DIR)/x509.o -mbedt
[PATCH v4 26/29] lib/rypto: Adapt rsa_helper to MbedTLS
Previous patch has introduced MbedTLS porting layer for RSA helper, here to adjust the makefile accordingly. Signed-off-by: Raymond Mao --- Changes in v2 - Initial patch. Changes in v3 - Update commit message. Changes in v4 - Control building legacy library via '_LEGACY' Kconfig. lib/crypto/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 9bbd8b48d77..281e507743a 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -13,7 +13,7 @@ obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY) += public_key.o # # RSA public key parser # -obj-$(CONFIG_$(SPL_)RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o +obj-$(CONFIG_$(SPL_)RSA_PUBLIC_KEY_PARSER_LEGACY) += rsa_public_key.o rsa_public_key-y := \ rsapubkey.asn1.o \ rsa_helper.o -- 2.25.1
[PATCH v4 25/29] mbedtls: add RSA helper layer on MbedTLS
Add RSA helper layer on top on MbedTLS PK and RSA library. Introduce _LEGACY and _MBEDTLS kconfigs for RSA helper legacy and MbedTLS implementations respectively. Signed-off-by: Raymond Mao --- Changes in v2 - Initial patch. Changes in v3 - None. Changes in v4 - Introduce _LEGACY and _MBEDTLS kconfigs for RSA helper legacy and MbedTLS implementations respectively. - Remove unnecessary type casting. - Minor fix of the include directories. lib/mbedtls/Kconfig | 36 +++ lib/mbedtls/Makefile | 3 +- lib/mbedtls/rsa_helper.c | 95 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 lib/mbedtls/rsa_helper.c diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig index d8a8f87e031..87c500d6ca9 100644 --- a/lib/mbedtls/Kconfig +++ b/lib/mbedtls/Kconfig @@ -124,11 +124,13 @@ config LEGACY_CRYPTO_CERT bool "legacy certificate libraries" select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select RSA_PUBLIC_KEY_PARSER_LEGACY if RSA_PUBLIC_KEY_PARSER select X509_CERTIFICATE_PARSER_LEGACY if X509_CERTIFICATE_PARSER select PKCS7_MESSAGE_PARSER_LEGACY if PKCS7_MESSAGE_PARSER select MSCODE_PARSER_LEGACY if MSCODE_PARSER select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL + select SPL_RSA_PUBLIC_KEY_PARSER_LEGACY if RSA_PUBLIC_KEY_PARSER && SPL help Enable legacy certificate libraries. @@ -141,6 +143,14 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY This option chooses legacy certificate library for asymmetric public key crypto algorithm. +config RSA_PUBLIC_KEY_PARSER_LEGACY + bool "RSA public key parser with legacy certificate library" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY + select ASN1_DECODER_LEGACY + help + This option chooses legacy certificate library for RSA public key + parser. + config X509_CERTIFICATE_PARSER_LEGACY bool "X.509 certificate parser with legacy certificate library" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY @@ -174,6 +184,14 @@ config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY This option chooses legacy certificate library for asymmetric public key crypto algorithm in SPL. +config SPL_RSA_PUBLIC_KEY_PARSER_LEGACY + bool "RSA public key parser with legacy certificate library in SPL" + depends on SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY + select SPL_ASN1_DECODER_LEGACY + help + This option chooses legacy certificate library for RSA public key + parser in SPL. + endif # SPL endif # LEGACY_CRYPTO_CERT @@ -287,11 +305,13 @@ config MBEDTLS_LIB_X509 bool "MbedTLS certificate libraries" select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select RSA_PUBLIC_KEY_PARSER_MBEDTLS if RSA_PUBLIC_KEY_PARSER select X509_CERTIFICATE_PARSER_MBEDTLS if X509_CERTIFICATE_PARSER select PKCS7_MESSAGE_PARSER_MBEDTLS if PKCS7_MESSAGE_PARSER select MSCODE_PARSER_MBEDTLS if MSCODE_PARSER select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL + select SPL_RSA_PUBLIC_KEY_PARSER_MBEDTLS if RSA_PUBLIC_KEY_PARSER && SPL help Enable MbedTLS certificate libraries. @@ -303,6 +323,14 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS This option chooses MbedTLS certificate library for asymmetric public key crypto algorithm. +config RSA_PUBLIC_KEY_PARSER_MBEDTLS + bool "RSA public key parser with MbedTLS certificate library" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS + select ASN1_DECODER_MBEDTLS + help + This option chooses MbedTLS certificate library for RSA public key + parser. + config X509_CERTIFICATE_PARSER_MBEDTLS bool "X.509 certificate parser with MbedTLS certificate library" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS @@ -334,6 +362,14 @@ config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS This option chooses MbedTLS certificate library for asymmetric public key crypto algorithm in SPL. +config SPL_RSA_PUBLIC_KEY_PARSER_MBEDTLS + bool "RSA public key parser with MbedTLS certificate library in SPL" + depends on SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS + select SPL_ASN1_DECODER_MBEDTLS + help + This option chooses MbedTLS certificate library for RSA public key + parser in SPL. + endif # SPL endif # MBEDTLS_LIB_X509 diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile index ac7c487449d..9c6991f8783 100644 --- a/lib/mbedtls/Makefile +++ b/lib/mbedtls/Makefile @@ -28,6 +28,7 @@ x509_mbedtls-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER_MBEDTLS) += \ x509_cert_parser.o x509_mbedtls-$(C
[PATCH v4 24/29] lib/crypto: Adapt mscode_parser to MbedTLS
Previous patch has introduced MbedTLS porting layer for mscode parser, here to adjust the header and makefiles accordingly. Signed-off-by: Raymond Mao --- Changes in v2 - Move the porting layer to MbedTLS dir. Changes in v3 - Update commit message. Changes in v4 - Control building legacy library via '_LEGACY' Kconfig. - Minor fix of the include directories. include/crypto/mscode.h | 4 lib/crypto/Makefile | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/crypto/mscode.h b/include/crypto/mscode.h index 551058b96e6..678e69001b9 100644 --- a/include/crypto/mscode.h +++ b/include/crypto/mscode.h @@ -9,6 +9,10 @@ #ifndef __UBOOT__ #include #endif +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) +#include +#include +#endif struct pefile_context { #ifndef __UBOOT__ diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 428dcba0a6b..9bbd8b48d77 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -63,7 +63,7 @@ obj-$(CONFIG_$(SPL_)PKCS7_VERIFY) += pkcs7_verify.o # # Signed PE binary-wrapped key handling # -obj-$(CONFIG_$(SPL_)MSCODE_PARSER) += mscode.o +obj-$(CONFIG_$(SPL_)MSCODE_PARSER_LEGACY) += mscode.o mscode-y := \ mscode_parser.o \ -- 2.25.1
[PATCH v4 23/29] mbedtls: add MSCode parser porting layer
Add porting layer for MSCode on top of MbedTLS ASN1 library. Introduce _LEGACY and _MBEDTLS kconfigs for MSCode legacy and MbedTLS implementations respectively. Signed-off-by: Raymond Mao --- Changes in v2 - Move the porting layer to MbedTLS dir. Changes in v3 - None. Changes in v4 - Introduce _LEGACY and _MBEDTLS kconfigs for MSCode legacy and MbedTLS implementations respectively. - Fix a few code style. lib/mbedtls/Kconfig | 17 + lib/mbedtls/Makefile| 1 + lib/mbedtls/mscode_parser.c | 123 3 files changed, 141 insertions(+) create mode 100644 lib/mbedtls/mscode_parser.c diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig index 8c5b617bb48..d8a8f87e031 100644 --- a/lib/mbedtls/Kconfig +++ b/lib/mbedtls/Kconfig @@ -126,6 +126,7 @@ config LEGACY_CRYPTO_CERT ASYMMETRIC_PUBLIC_KEY_SUBTYPE select X509_CERTIFICATE_PARSER_LEGACY if X509_CERTIFICATE_PARSER select PKCS7_MESSAGE_PARSER_LEGACY if PKCS7_MESSAGE_PARSER + select MSCODE_PARSER_LEGACY if MSCODE_PARSER select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL help @@ -156,6 +157,14 @@ config PKCS7_MESSAGE_PARSER_LEGACY This option chooses legacy certificate library for PKCS7 message parser. +config MSCODE_PARSER_LEGACY + bool "MS authenticode parser with legacy certificate library" + depends on LEGACY_CRYPTO_CERT && MSCODE_PARSER + select ASN1_DECODER_LEGACY + help + This option chooses legacy certificate library for MS authenticode + parser. + if SPL config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY @@ -280,6 +289,7 @@ config MBEDTLS_LIB_X509 ASYMMETRIC_PUBLIC_KEY_SUBTYPE select X509_CERTIFICATE_PARSER_MBEDTLS if X509_CERTIFICATE_PARSER select PKCS7_MESSAGE_PARSER_MBEDTLS if PKCS7_MESSAGE_PARSER + select MSCODE_PARSER_MBEDTLS if MSCODE_PARSER select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL help @@ -309,6 +319,13 @@ config PKCS7_MESSAGE_PARSER_MBEDTLS This option chooses MbedTLS certificate library for PKCS7 message parser. +config MSCODE_PARSER_MBEDTLS + bool "MS authenticode parser with MbedTLS certificate library" + select ASN1_DECODER_MBEDTLS + help + This option chooses MbedTLS certificate library for MS authenticode + parser. + if SPL config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile index 7b40ff0c467..ac7c487449d 100644 --- a/lib/mbedtls/Makefile +++ b/lib/mbedtls/Makefile @@ -27,6 +27,7 @@ x509_mbedtls-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS) += \ x509_mbedtls-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER_MBEDTLS) += \ x509_cert_parser.o x509_mbedtls-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER_MBEDTLS) += pkcs7_parser.o +x509_mbedtls-$(CONFIG_$(SPL_)MSCODE_PARSER_MBEDTLS) += mscode_parser.o # MbedTLS crypto library obj-$(CONFIG_MBEDTLS_LIB_CRYPTO) += mbedtls_lib_crypto.o diff --git a/lib/mbedtls/mscode_parser.c b/lib/mbedtls/mscode_parser.c new file mode 100644 index 000..c3805c6503c --- /dev/null +++ b/lib/mbedtls/mscode_parser.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * MSCode parser using MbedTLS ASN1 library + * + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ + +#include +#include +#include +#include + +/* + * Parse a Microsoft Individual Code Signing blob + * + * U.P.SEQUENCE { + *U.P.OBJECTIDENTIFIER 1.3.6.1.4.1.311.2.1.15 (SPC_PE_IMAGE_DATA_OBJID) + *U.P.SEQUENCE { + * U.P.BITSTRING NaN : 0 unused bit(s); + * [C.P.0] { + * [C.P.2] { + * [C.P.0] + * } + * } + *} + * } + * U.P.SEQUENCE { + *U.P.SEQUENCE { + * U.P.OBJECTIDENTIFIER + * U.P.NULL + *} + *U.P.OCTETSTRING + * } + * + * @ctx: PE file context. + * @content_data: content data pointer. + * @data_len: content data length. + * @asn1hdrlen: ASN1 header length. + */ +int mscode_parse(void *ctx, const void *content_data, size_t data_len, +size_t asn1hdrlen) +{ + struct pefile_context *_ctx = ctx; + unsigned char *p = (unsigned char *)content_data; + unsigned char *end = (unsigned char *)content_data + data_len; + size_t len = 0; + int ret; + unsigned char *inner_p; + size_t seq_len = 0; + + ret = mbedtls_asn1_get_tag(&p, end, &seq_len, + MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_SEQUENCE); + if (ret) + return ret; + + inner_p = p; + ret = mbedtls_asn1_get_tag(&inner_p, inner_p + seq_len, &len, + MBEDTLS_ASN1_OID); + if (ret) + return ret; + + /* Sanity check on
[PATCH v4 22/29] lib/crypto: Adapt PKCS7 parser to MbedTLS
Previous patch has introduced MbedTLS porting layer for PKCS7 parser, here to adjust the header and makefiles accordingly. Signed-off-by: Raymond Mao --- Changes in v2 - Move the porting layer to MbedTLS dir. Changes in v3 - Update commit message. Changes in v4 - Control building legacy library via '_LEGACY' Kconfig. - Minor fix of the include directories. include/crypto/pkcs7_parser.h | 56 +++ lib/crypto/Makefile | 7 +++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/include/crypto/pkcs7_parser.h b/include/crypto/pkcs7_parser.h index 2c45cce5234..469c2711fa6 100644 --- a/include/crypto/pkcs7_parser.h +++ b/include/crypto/pkcs7_parser.h @@ -11,6 +11,12 @@ #include #include #include +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) +#include +#include +#include +#include +#endif #include #define kenter(FMT, ...) \ @@ -18,7 +24,54 @@ #define kleave(FMT, ...) \ pr_devel("<== %s()"FMT"\n", __func__, ##__VA_ARGS__) +/* Backup the parsed MedTLS context that we need */ +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) +struct pkcs7_mbedtls_ctx { + void *content_data; +}; + +struct pkcs7_sinfo_mbedtls_ctx { + void *authattrs_data; + void *content_data_digest; +}; +#endif + +/* + * MbedTLS integration Notes: + * + * MbedTLS PKCS#7 library does not originally support parsing MicroSoft + * Authentication Code which is used for verifying the PE image digest. + * + * 1. Authenticated Attributes (authenticatedAttributes) + * MbedTLS assumes unauthenticatedAttributes and authenticatedAttributes + * fields not exist. + * See MbedTLS function 'pkcs7_get_signer_info' for details. + * + * 2. MicroSoft Authentication Code (mscode) + * MbedTLS only supports Content Data type defined as 1.2.840.113549.1.7.1 + * (MBEDTLS_OID_PKCS7_DATA, aka OID_data). + * 1.3.6.1.4.1.311.2.1.4 (MicroSoft Authentication Code, aka + * OID_msIndirectData) is not supported. + * See MbedTLS function 'pkcs7_get_content_info_type' for details. + * + * But the EFI loader assumes that a PKCS#7 message with an EFI image always + * contains MicroSoft Authentication Code as Content Data (msg->data is NOT + * NULL), see function 'efi_signature_verify'. + * + * MbedTLS patch "0002-support-MicroSoft-authentication-code-in-PKCS7-lib.patch" + * is to support both above features by parsing the Content Data and + * Authenticate Attributes from a given PKCS#7 message. + * + * Other fields we don't need to populate from MbedTLS, which are used + * internally by pkcs7_verify: + * 'signer', 'unsupported_crypto', 'blacklisted' + * 'sig->digest' is used internally by pkcs7_digest to calculate the hash of + * Content Data or Authenticate Attributes. + */ struct pkcs7_signed_info { +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) + struct pkcs7_sinfo_mbedtls_ctx *mbedtls_ctx; +#endif struct pkcs7_signed_info *next; struct x509_certificate *signer; /* Signing certificate (in msg->certs) */ unsignedindex; @@ -55,6 +108,9 @@ struct pkcs7_signed_info { }; struct pkcs7_message { +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) + struct pkcs7_mbedtls_ctx *mbedtls_ctx; +#endif struct x509_certificate *certs; /* Certificate list */ struct x509_certificate *crl; /* Revocation list */ struct pkcs7_signed_info *signed_infos; diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 7f5f04d582c..428dcba0a6b 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -50,15 +50,16 @@ $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h # PKCS#7 message handling # obj-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER) += pkcs7_message.o -pkcs7_message-y := \ +pkcs7_message-y := pkcs7_helper.o +pkcs7_message-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER_LEGACY) += \ pkcs7.asn1.o \ - pkcs7_helper.o \ pkcs7_parser.o -obj-$(CONFIG_$(SPL_)PKCS7_VERIFY) += pkcs7_verify.o $(obj)/pkcs7_parser.o: $(obj)/pkcs7.asn1.h $(obj)/pkcs7.asn1.o: $(obj)/pkcs7.asn1.c $(obj)/pkcs7.asn1.h +obj-$(CONFIG_$(SPL_)PKCS7_VERIFY) += pkcs7_verify.o + # # Signed PE binary-wrapped key handling # -- 2.25.1
[PATCH v4 21/29] mbedtls: add PKCS7 parser porting layer
Add porting layer for PKCS7 parser on top of MbedTLS PKCS7 library. Introduce _LEGACY and _MBEDTLS kconfigs for PKCS7 parser legacy and MbedTLS implementations respectively. Signed-off-by: Raymond Mao --- Changes in v2 - Move the porting layer to MbedTLS dir. - Fix EFI Capsule CI test failures. Changes in v3 - None. Changes in v4 - Introduce _LEGACY and _MBEDTLS kconfigs for PKCS7 parser legacy and MbedTLS implementations respectively. - Move common functions to helper. - Fix an unnecessary pointer casting. lib/mbedtls/Kconfig| 18 ++ lib/mbedtls/Makefile | 3 +- lib/mbedtls/pkcs7_parser.c | 506 + 3 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 lib/mbedtls/pkcs7_parser.c diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig index c62a556a39a..8c5b617bb48 100644 --- a/lib/mbedtls/Kconfig +++ b/lib/mbedtls/Kconfig @@ -125,6 +125,7 @@ config LEGACY_CRYPTO_CERT select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE select X509_CERTIFICATE_PARSER_LEGACY if X509_CERTIFICATE_PARSER + select PKCS7_MESSAGE_PARSER_LEGACY if PKCS7_MESSAGE_PARSER select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL help @@ -147,6 +148,14 @@ config X509_CERTIFICATE_PARSER_LEGACY This option chooses legacy certificate library for X509 certificate parser. +config PKCS7_MESSAGE_PARSER_LEGACY + bool "PKCS#7 message parser with legacy certificate library" + depends on X509_CERTIFICATE_PARSER_LEGACY + select ASN1_DECODER_LEGACY + help + This option chooses legacy certificate library for PKCS7 message + parser. + if SPL config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY @@ -270,6 +279,7 @@ config MBEDTLS_LIB_X509 select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE select X509_CERTIFICATE_PARSER_MBEDTLS if X509_CERTIFICATE_PARSER + select PKCS7_MESSAGE_PARSER_MBEDTLS if PKCS7_MESSAGE_PARSER select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL help @@ -291,6 +301,14 @@ config X509_CERTIFICATE_PARSER_MBEDTLS This option chooses MbedTLS certificate library for X509 certificate parser. +config PKCS7_MESSAGE_PARSER_MBEDTLS + bool "PKCS#7 message parser with MbedTLS certificate library" + depends on X509_CERTIFICATE_PARSER_MBEDTLS + select ASN1_DECODER_MBEDTLS + help + This option chooses MbedTLS certificate library for PKCS7 message + parser. + if SPL config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile index 75d6a2cca07..7b40ff0c467 100644 --- a/lib/mbedtls/Makefile +++ b/lib/mbedtls/Makefile @@ -26,6 +26,7 @@ x509_mbedtls-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS) += \ public_key.o x509_mbedtls-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER_MBEDTLS) += \ x509_cert_parser.o +x509_mbedtls-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER_MBEDTLS) += pkcs7_parser.o # MbedTLS crypto library obj-$(CONFIG_MBEDTLS_LIB_CRYPTO) += mbedtls_lib_crypto.o @@ -59,5 +60,5 @@ mbedtls_lib_x509-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS) += \ mbedtls_lib_x509-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER_MBEDTLS) += \ $(MBEDTLS_LIB_DIR)/x509_crl.o \ $(MBEDTLS_LIB_DIR)/x509_crt.o -mbedtls_lib_x509-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER) += \ +mbedtls_lib_x509-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER_MBEDTLS) += \ $(MBEDTLS_LIB_DIR)/pkcs7.o diff --git a/lib/mbedtls/pkcs7_parser.c b/lib/mbedtls/pkcs7_parser.c new file mode 100644 index 000..69ca784858e --- /dev/null +++ b/lib/mbedtls/pkcs7_parser.c @@ -0,0 +1,506 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * PKCS#7 parser using MbedTLS PKCS#7 library + * + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ + +#include +#include +#include +#include +#include + +static void pkcs7_free_mbedtls_ctx(struct pkcs7_mbedtls_ctx *ctx) +{ + if (ctx) { + kfree(ctx->content_data); + kfree(ctx); + } +} + +static void pkcs7_free_sinfo_mbedtls_ctx(struct pkcs7_sinfo_mbedtls_ctx *ctx) +{ + if (ctx) { + kfree(ctx->authattrs_data); + kfree(ctx->content_data_digest); + kfree(ctx); + } +} + +/* + * Parse Authenticate Attributes + * TODO: Shall we consider to integrate decoding of authenticate attribute into + * MbedTLS library? + * + * There are two kinds of structure for the Authenticate Attributes being used + * in U-Boot. + * + * Type 1 - contains in a PE/COFF EFI image: + * + * [C.P.0] { + * U.P.SEQUENCE { + * U.P.OBJECTIDENTIFIER 1.2.840.113549.1.9.3 (OID_contentType) + * U.P.SET { + *U.P.OBJECTIDENTIFIER 1.3.6.1.4.1.311.2.1.4
[PATCH v4 20/29] lib/crypto: Adapt x509_cert_parser to MbedTLS
Previous patch has introduced MbedTLS porting layer for x509 cert parser, here to adjust the header and makefiles accordingly. Signed-off-by: Raymond Mao --- Changes in v2 - Move the porting layer to MbedTLS dir. Changes in v3 - Update commit message. Changes in v4 - Control building legacy library via '_LEGACY' Kconfig. - Add function comments for the new APIs. - Update the dependence of ASYMMETRIC_KEY_TYPE. - Minor fix of the include directories. include/crypto/x509_parser.h | 56 lib/crypto/Kconfig | 2 +- lib/crypto/Makefile | 4 +-- lib/crypto/x509_public_key.c | 2 ++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/include/crypto/x509_parser.h b/include/crypto/x509_parser.h index 4cbdc1d6612..3f917da5430 100644 --- a/include/crypto/x509_parser.h +++ b/include/crypto/x509_parser.h @@ -11,8 +11,36 @@ #include #include #include +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) +#include +#include +#include +#endif +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) +/* Backup of part of the parsing context */ +struct x509_cert_mbedtls_ctx { + void*tbs; /* Signed data */ + void*raw_serial;/* Raw serial number in ASN.1 */ + void*raw_issuer;/* Raw issuer name in ASN.1 */ + void*raw_subject; /* Raw subject name in ASN.1 */ + void*raw_skid; /* Raw subjectKeyId in ASN.1 */ +}; +#endif + +/* + * MbedTLS integration Notes: + * + * Fields we don't need to populate from MbedTLS: + * 'raw_sig' and 'raw_sig_size' are buffer for x509_parse_context, + * not needed for MbedTLS. + * 'signer' and 'seen' are used internally by pkcs7_verify. + * 'verified' is not inuse. + */ struct x509_certificate { +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) + struct x509_cert_mbedtls_ctx *mbedtls_ctx; +#endif struct x509_certificate *next; struct x509_certificate *signer;/* Certificate that signed this one */ struct public_key *pub; /* Public key details */ @@ -48,6 +76,32 @@ struct x509_certificate { * x509_cert_parser.c */ extern void x509_free_certificate(struct x509_certificate *cert); +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) +/** + * x509_populate_pubkey() - Populate public key from MbedTLS context + * + * @cert: Pointer to MbedTLS X509 cert + * @pub_key: Pointer to the populated public key handle + * Return: 0 on succcess, error code on failure + */ +int x509_populate_pubkey(mbedtls_x509_crt *cert, struct public_key **pub_key); +/** + * x509_populate_cert() - Populate X509 cert from MbedTLS context + * + * @mbedtls_cert: Pointer to MbedTLS X509 cert + * @pcert: Pointer to the populated X509 cert handle + * Return: 0 on succcess, error code on failure + */ +int x509_populate_cert(mbedtls_x509_crt *mbedtls_cert, + struct x509_certificate **pcert); +/** + * x509_get_timestamp() - Translate timestamp from MbedTLS context + * + * @x509_time: Pointer to MbedTLS time + * Return: Time in time64_t format + */ +time64_t x509_get_timestamp(const mbedtls_x509_time *x509_time); +#endif extern struct x509_certificate *x509_cert_parse(const void *data, size_t datalen); extern int x509_decode_time(time64_t *_t, size_t hdrlen, unsigned char tag, @@ -56,6 +110,8 @@ extern int x509_decode_time(time64_t *_t, size_t hdrlen, /* * x509_public_key.c */ +#if !CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) extern int x509_get_sig_params(struct x509_certificate *cert); +#endif extern int x509_check_for_self_signed(struct x509_certificate *cert); #endif /* _X509_PARSER_H */ diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig index 6e0656ad1c5..6106190677e 100644 --- a/lib/crypto/Kconfig +++ b/lib/crypto/Kconfig @@ -1,6 +1,6 @@ menuconfig ASYMMETRIC_KEY_TYPE bool "Asymmetric (public-key cryptographic) key Support" - depends on FIT_SIGNATURE + depends on LEGACY_CRYPTO_CERT || MBEDTLS_LIB_X509 help This option provides support for a key type that holds the data for the asymmetric keys used for public key cryptographic operations such diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 228ae443a27..7f5f04d582c 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -32,11 +32,11 @@ endif # X.509 Certificate handling # obj-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER) += x509_key_parser.o -x509_key_parser-y := \ +x509_key_parser-y := x509_helper.o +x509_key_parser-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER_LEGACY) += \ x509.asn1.o \ x509_akid.asn1.o \ x509_cert_parser.o \ - x509_helper.o \ x509_public_key.o $(obj)/x509_cert_parser.o: \ diff --git a/lib/crypto/x509_public_key.c b/lib/crypto/x509_public_key.c index 4ba13c1adc3..310edbd21be 100644 --- a/lib/crypto/x509_public_key.c +++ b/lib/crypto/x509_public_key.c @@ -30,6 +30,8 @@ #include "x509_pars
[PATCH v4 19/29] mbedtls: add X509 cert parser porting layer
Add porting layer for X509 cert parser on top of MbedTLS X509 library. Introduce _LEGACY and _MBEDTLS kconfigs for X509 cert parser legacy and MbedTLS implementations respectively. Signed-off-by: Raymond Mao --- Changes in v2 - Move the porting layer to MbedTLS dir. Changes in v3 - None. Changes in v4 - Introduce _LEGACY and _MBEDTLS kconfigs for X509 cert parser legacy and MbedTLS implementations respectively. - Move common functions to helper. lib/mbedtls/Kconfig| 18 ++ lib/mbedtls/Makefile | 4 +- lib/mbedtls/x509_cert_parser.c | 446 + 3 files changed, 467 insertions(+), 1 deletion(-) create mode 100644 lib/mbedtls/x509_cert_parser.c diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig index 6f29b0c81a2..c62a556a39a 100644 --- a/lib/mbedtls/Kconfig +++ b/lib/mbedtls/Kconfig @@ -124,6 +124,7 @@ config LEGACY_CRYPTO_CERT bool "legacy certificate libraries" select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select X509_CERTIFICATE_PARSER_LEGACY if X509_CERTIFICATE_PARSER select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL help @@ -138,6 +139,14 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY This option chooses legacy certificate library for asymmetric public key crypto algorithm. +config X509_CERTIFICATE_PARSER_LEGACY + bool "X.509 certificate parser with legacy certificate library" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY + select ASN1_DECODER_LEGACY + help + This option chooses legacy certificate library for X509 certificate + parser. + if SPL config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY @@ -260,6 +269,7 @@ config MBEDTLS_LIB_X509 bool "MbedTLS certificate libraries" select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select X509_CERTIFICATE_PARSER_MBEDTLS if X509_CERTIFICATE_PARSER select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL help @@ -273,6 +283,14 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS This option chooses MbedTLS certificate library for asymmetric public key crypto algorithm. +config X509_CERTIFICATE_PARSER_MBEDTLS + bool "X.509 certificate parser with MbedTLS certificate library" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS + select ASN1_DECODER_MBEDTLS + help + This option chooses MbedTLS certificate library for X509 certificate + parser. + if SPL config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile index f06d0704502..75d6a2cca07 100644 --- a/lib/mbedtls/Makefile +++ b/lib/mbedtls/Makefile @@ -24,6 +24,8 @@ hash_mbedtls-$(CONFIG_$(SPL_)SHA512_MBEDTLS) += sha512.o obj-$(CONFIG_MBEDTLS_LIB_X509) += x509_mbedtls.o x509_mbedtls-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS) += \ public_key.o +x509_mbedtls-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER_MBEDTLS) += \ + x509_cert_parser.o # MbedTLS crypto library obj-$(CONFIG_MBEDTLS_LIB_CRYPTO) += mbedtls_lib_crypto.o @@ -54,7 +56,7 @@ mbedtls_lib_x509-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS) += \ $(MBEDTLS_LIB_DIR)/pk.o \ $(MBEDTLS_LIB_DIR)/pk_wrap.o \ $(MBEDTLS_LIB_DIR)/pkparse.o -mbedtls_lib_x509-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER) += \ +mbedtls_lib_x509-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER_MBEDTLS) += \ $(MBEDTLS_LIB_DIR)/x509_crl.o \ $(MBEDTLS_LIB_DIR)/x509_crt.o mbedtls_lib_x509-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER) += \ diff --git a/lib/mbedtls/x509_cert_parser.c b/lib/mbedtls/x509_cert_parser.c new file mode 100644 index 000..0323dea3152 --- /dev/null +++ b/lib/mbedtls/x509_cert_parser.c @@ -0,0 +1,446 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * X509 cert parser using MbedTLS X509 library + * + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ + +#include +#include +#include + +static void x509_free_mbedtls_ctx(struct x509_cert_mbedtls_ctx *ctx) +{ + if (!ctx) + return; + + kfree(ctx->tbs); + kfree(ctx->raw_serial); + kfree(ctx->raw_issuer); + kfree(ctx->raw_subject); + kfree(ctx->raw_skid); + kfree(ctx); +} + +static int x509_set_cert_flags(struct x509_certificate *cert) +{ + struct public_key_signature *sig = cert->sig; + + if (!sig || !cert->pub) { + pr_err("Signature or public key is not initialized\n"); + return -ENOPKG; + } + + if (!cert->pub->pkey_algo) + cert->unsupported_key = true; + + if (!sig->pkey_algo) + cert->unsupported_sig = true; + + if (!sig->hash_algo) + cert->unsupported_sig = true; + + /* TODO
[PATCH v4 18/29] lib/crypto: Adapt public_key header with MbedTLS
Previous patch has introduced MbedTLS porting layer for public key, here to adjust the header and makefiles accordingly. Signed-off-by: Raymond Mao --- Changes in v2 - Move the porting layer to MbedTLS dir. Changes in v3 - Update commit message. Changes in v4 - Control building legacy library via '_LEGACY' Kconfig. - Minor fix of the include directories. include/crypto/public_key.h | 6 ++ lib/crypto/Makefile | 5 ++--- lib/crypto/asymmetric_type.c | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h index 3ba90fcc348..25cfb68adce 100644 --- a/include/crypto/public_key.h +++ b/include/crypto/public_key.h @@ -12,6 +12,12 @@ #ifdef __UBOOT__ #include +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) +#include +#include +#include +#include +#endif #else #include #endif diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 16059088f26..228ae443a27 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -7,9 +7,8 @@ obj-$(CONFIG_$(SPL_)ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o asymmetric_keys-y := asymmetric_type.o -obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += \ - public_key_helper.o \ - public_key.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key_helper.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY) += public_key.o # # RSA public key parser diff --git a/lib/crypto/asymmetric_type.c b/lib/crypto/asymmetric_type.c index 24c2d15ef97..95b82cd8e84 100644 --- a/lib/crypto/asymmetric_type.c +++ b/lib/crypto/asymmetric_type.c @@ -12,7 +12,6 @@ #include #include #endif -#include #ifdef __UBOOT__ #include #include @@ -26,6 +25,7 @@ #include #include #endif +#include #ifdef __UBOOT__ #include #else -- 2.25.1
[PATCH v4 17/29] mbedtls: add public key porting layer
Add porting layer for public key on top of MbedTLS X509 library. Introduce _LEGACY and _MBEDTLS kconfigs for public key legacy and MbedTLS implementations respectively. Signed-off-by: Raymond Mao --- Changes in v2 - Move the porting layer to MbedTLS dir. Changes in v3 - None. Changes in v4 - Introduce _LEGACY and _MBEDTLS kconfigs for public key legacy and MbedTLS implementations respectively. - Move common functions to helper. lib/mbedtls/Kconfig | 50 lib/mbedtls/Makefile | 7 +++- lib/mbedtls/public_key.c | 82 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 lib/mbedtls/public_key.c diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig index 0cdf0135667..6f29b0c81a2 100644 --- a/lib/mbedtls/Kconfig +++ b/lib/mbedtls/Kconfig @@ -122,9 +122,35 @@ endif # LEGACY_CRYPTO_BASIC config LEGACY_CRYPTO_CERT bool "legacy certificate libraries" + select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ + ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY if \ + ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL help Enable legacy certificate libraries. +if LEGACY_CRYPTO_CERT + +config ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY + bool "Asymmetric public key crypto with legacy certificate library" + depends on LEGACY_CRYPTO_CERT && ASYMMETRIC_PUBLIC_KEY_SUBTYPE + help + This option chooses legacy certificate library for asymmetric public + key crypto algorithm. + +if SPL + +config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_LEGACY + bool "Asymmetric public key crypto with legacy certificate library in SPL" + depends on LEGACY_CRYPTO_CERT && SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE + help + This option chooses legacy certificate library for asymmetric public + key crypto algorithm in SPL. + +endif # SPL + +endif # LEGACY_CRYPTO_CERT + endif # LEGACY_CRYPTO if MBEDTLS_LIB @@ -232,7 +258,31 @@ endif # MBEDTLS_LIB_CRYPTO config MBEDTLS_LIB_X509 bool "MbedTLS certificate libraries" + select ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ + ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS if \ + ASYMMETRIC_PUBLIC_KEY_SUBTYPE && SPL help Enable MbedTLS certificate libraries. +if MBEDTLS_LIB_X509 + +config ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS + bool "Asymmetric public key crypto with MbedTLS certificate library" + help + This option chooses MbedTLS certificate library for asymmetric public + key crypto algorithm. + +if SPL + +config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS + bool "Asymmetric public key crypto with MbedTLS certificate library in SPL" + help + This option chooses MbedTLS certificate library for asymmetric public + key crypto algorithm in SPL. + +endif # SPL + +endif # MBEDTLS_LIB_X509 + endif # MBEDTLS_LIB diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile index 32a98b7f4ca..f06d0704502 100644 --- a/lib/mbedtls/Makefile +++ b/lib/mbedtls/Makefile @@ -20,6 +20,11 @@ hash_mbedtls-$(CONFIG_$(SPL_)SHA1_MBEDTLS) += sha1.o hash_mbedtls-$(CONFIG_$(SPL_)SHA256_MBEDTLS) += sha256.o hash_mbedtls-$(CONFIG_$(SPL_)SHA512_MBEDTLS) += sha512.o +# x509 libraries +obj-$(CONFIG_MBEDTLS_LIB_X509) += x509_mbedtls.o +x509_mbedtls-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS) += \ + public_key.o + # MbedTLS crypto library obj-$(CONFIG_MBEDTLS_LIB_CRYPTO) += mbedtls_lib_crypto.o mbedtls_lib_crypto-y += \ @@ -45,7 +50,7 @@ mbedtls_lib_x509-$(CONFIG_$(SPL_)RSA_PUBLIC_KEY_PARSER) += \ $(MBEDTLS_LIB_DIR)/bignum_core.o \ $(MBEDTLS_LIB_DIR)/rsa.o \ $(MBEDTLS_LIB_DIR)/rsa_alt_helpers.o -mbedtls_lib_x509-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += \ +mbedtls_lib_x509-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE_MBEDTLS) += \ $(MBEDTLS_LIB_DIR)/pk.o \ $(MBEDTLS_LIB_DIR)/pk_wrap.o \ $(MBEDTLS_LIB_DIR)/pkparse.o diff --git a/lib/mbedtls/public_key.c b/lib/mbedtls/public_key.c new file mode 100644 index 000..076a61862cb --- /dev/null +++ b/lib/mbedtls/public_key.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Public key helper functions using MbedTLS X509 library + * + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ + +#include +#include + +int public_key_verify_signature(const struct public_key *pkey, + const struct public_key_signature *sig) +{ + mbedtls_md_type_t mb_hash_algo; + mbedtls_pk_context pk_ctx; + int ret; + + if (!pkey || !sig || pkey->key_is_private) + return -EINVAL; + + /* +* ECRDSA (Elliptic Curve RedDSA) from Red Hat is not supported by +* MbedTLS +*/ + if (strcmp(pkey->pkey_algo, "rsa")) { + pr_err(
[PATCH v4 16/29] pkcs7: move common functions to PKCS7 helper
Move pkcs7_get_content_data as a helper function that can be shared by legacy crypto lib and MbedTLS implementation. Signed-off-by: Raymond Mao --- Changes in v4 - Initial patch. lib/crypto/Makefile | 1 + lib/crypto/pkcs7_helper.c | 40 +++ lib/crypto/pkcs7_parser.c | 28 --- 3 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 lib/crypto/pkcs7_helper.c diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 946cc3a7b59..16059088f26 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -53,6 +53,7 @@ $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h obj-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER) += pkcs7_message.o pkcs7_message-y := \ pkcs7.asn1.o \ + pkcs7_helper.o \ pkcs7_parser.o obj-$(CONFIG_$(SPL_)PKCS7_VERIFY) += pkcs7_verify.o diff --git a/lib/crypto/pkcs7_helper.c b/lib/crypto/pkcs7_helper.c new file mode 100644 index 000..6c8dcd1a935 --- /dev/null +++ b/lib/crypto/pkcs7_helper.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * PKCS7 helper functions + * + * Copyright (c) 2012 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowe...@redhat.com) + * + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ +#include +#include +#include + +/** + * pkcs7_get_content_data - Get access to the PKCS#7 content + * @pkcs7: The preparsed PKCS#7 message to access + * @_data: Place to return a pointer to the data + * @_data_len: Place to return the data length + * @_headerlen: Size of ASN.1 header not included in _data + * + * Get access to the data content of the PKCS#7 message. The size of the + * header of the ASN.1 object that contains it is also provided and can be used + * to adjust *_data and *_data_len to get the entire object. + * + * Returns -ENODATA if the data object was missing from the message. + */ +int pkcs7_get_content_data(const struct pkcs7_message *pkcs7, + const void **_data, size_t *_data_len, + size_t *_headerlen) +{ + if (!pkcs7->data) + return -ENODATA; + + *_data = pkcs7->data; + *_data_len = pkcs7->data_len; + if (_headerlen) + *_headerlen = pkcs7->data_hdrlen; + return 0; +} diff --git a/lib/crypto/pkcs7_parser.c b/lib/crypto/pkcs7_parser.c index d5efa828d6a..c849dc0d92d 100644 --- a/lib/crypto/pkcs7_parser.c +++ b/lib/crypto/pkcs7_parser.c @@ -182,34 +182,6 @@ out_no_ctx: } EXPORT_SYMBOL_GPL(pkcs7_parse_message); -/** - * pkcs7_get_content_data - Get access to the PKCS#7 content - * @pkcs7: The preparsed PKCS#7 message to access - * @_data: Place to return a pointer to the data - * @_data_len: Place to return the data length - * @_headerlen: Size of ASN.1 header not included in _data - * - * Get access to the data content of the PKCS#7 message. The size of the - * header of the ASN.1 object that contains it is also provided and can be used - * to adjust *_data and *_data_len to get the entire object. - * - * Returns -ENODATA if the data object was missing from the message. - */ -int pkcs7_get_content_data(const struct pkcs7_message *pkcs7, - const void **_data, size_t *_data_len, - size_t *_headerlen) -{ - if (!pkcs7->data) - return -ENODATA; - - *_data = pkcs7->data; - *_data_len = pkcs7->data_len; - if (_headerlen) - *_headerlen = pkcs7->data_hdrlen; - return 0; -} -EXPORT_SYMBOL_GPL(pkcs7_get_content_data); - /* * Note an OID when we find one for later processing when we know how * to interpret it. -- 2.25.1
[PATCH v4 15/29] x509: move common functions to x509 helper
Move x509_check_for_self_signed as a common helper function that can be shared by legacy crypto lib and MbedTLS implementation. Signed-off-by: Raymond Mao --- Changes in v4 - Initial patch. lib/crypto/Makefile | 1 + lib/crypto/x509_helper.c | 67 lib/crypto/x509_public_key.c | 56 +- 3 files changed, 69 insertions(+), 55 deletions(-) create mode 100644 lib/crypto/x509_helper.c diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 4ad1849040d..946cc3a7b59 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -37,6 +37,7 @@ x509_key_parser-y := \ x509.asn1.o \ x509_akid.asn1.o \ x509_cert_parser.o \ + x509_helper.o \ x509_public_key.o $(obj)/x509_cert_parser.o: \ diff --git a/lib/crypto/x509_helper.c b/lib/crypto/x509_helper.c new file mode 100644 index 000..d0c80907ec3 --- /dev/null +++ b/lib/crypto/x509_helper.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * X509 helper functions + * + * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowe...@redhat.com) + * + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ +#include +#include +#include + +/* + * Check for self-signedness in an X.509 cert and if found, check the signature + * immediately if we can. + */ +int x509_check_for_self_signed(struct x509_certificate *cert) +{ + int ret = 0; + + if (cert->raw_subject_size != cert->raw_issuer_size || + memcmp(cert->raw_subject, cert->raw_issuer, + cert->raw_issuer_size)) + goto not_self_signed; + + if (cert->sig->auth_ids[0] || cert->sig->auth_ids[1]) { + /* +* If the AKID is present it may have one or two parts. If +* both are supplied, both must match. +*/ + bool a = asymmetric_key_id_same(cert->skid, + cert->sig->auth_ids[1]); + bool b = asymmetric_key_id_same(cert->id, + cert->sig->auth_ids[0]); + + if (!a && !b) + goto not_self_signed; + + ret = -EKEYREJECTED; + if (((a && !b) || (b && !a)) && + cert->sig->auth_ids[0] && cert->sig->auth_ids[1]) + goto out; + } + + ret = -EKEYREJECTED; + if (strcmp(cert->pub->pkey_algo, cert->sig->pkey_algo)) + goto out; + + ret = public_key_verify_signature(cert->pub, cert->sig); + if (ret == -ENOPKG) { + cert->unsupported_sig = true; + goto not_self_signed; + } + if (ret < 0) + goto out; + + pr_devel("Cert Self-signature verified"); + cert->self_signed = true; + +out: + return ret; + +not_self_signed: + return 0; +} diff --git a/lib/crypto/x509_public_key.c b/lib/crypto/x509_public_key.c index a10145a7cdc..4ba13c1adc3 100644 --- a/lib/crypto/x509_public_key.c +++ b/lib/crypto/x509_public_key.c @@ -139,61 +139,7 @@ error: return ret; } -/* - * Check for self-signedness in an X.509 cert and if found, check the signature - * immediately if we can. - */ -int x509_check_for_self_signed(struct x509_certificate *cert) -{ - int ret = 0; - - pr_devel("==>%s()\n", __func__); - - if (cert->raw_subject_size != cert->raw_issuer_size || - memcmp(cert->raw_subject, cert->raw_issuer, - cert->raw_issuer_size) != 0) - goto not_self_signed; - - if (cert->sig->auth_ids[0] || cert->sig->auth_ids[1]) { - /* If the AKID is present it may have one or two parts. If -* both are supplied, both must match. -*/ - bool a = asymmetric_key_id_same(cert->skid, cert->sig->auth_ids[1]); - bool b = asymmetric_key_id_same(cert->id, cert->sig->auth_ids[0]); - - if (!a && !b) - goto not_self_signed; - - ret = -EKEYREJECTED; - if (((a && !b) || (b && !a)) && - cert->sig->auth_ids[0] && cert->sig->auth_ids[1]) - goto out; - } - - ret = -EKEYREJECTED; - if (strcmp(cert->pub->pkey_algo, cert->sig->pkey_algo) != 0) - goto out; - - ret = public_key_verify_signature(cert->pub, cert->sig); - if (ret < 0) { - if (ret == -ENOPKG) { - cert->unsupported_sig = true; - ret = 0; - } - goto out; - } - - pr_devel("Cert Self-signature verified"); - cert->self_signed = true; - -out: - pr_devel("<==%s() = %d\n", __func__, ret); - return ret; - -not_self_signed: - pr_devel("<==%s() = 0 [not]\n", __func__); - return 0; -} +#endif /* !CONF
[PATCH v4 14/29] public_key: move common functions to public key helper
Move public_key_free and public_key_signature_free as helper functions that can be shared by legacy crypto lib and MbedTLS implementation. Signed-off-by: Raymond Mao --- Changes in v4 - Initial patch. lib/crypto/Makefile| 4 +++- lib/crypto/public_key.c| 31 - lib/crypto/public_key_helper.c | 42 ++ 3 files changed, 45 insertions(+), 32 deletions(-) create mode 100644 lib/crypto/public_key_helper.c diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index bec1bc95a65..4ad1849040d 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -7,7 +7,9 @@ obj-$(CONFIG_$(SPL_)ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o asymmetric_keys-y := asymmetric_type.o -obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += \ + public_key_helper.o \ + public_key.o # # RSA public key parser diff --git a/lib/crypto/public_key.c b/lib/crypto/public_key.c index 6efe951c057..408742907f1 100644 --- a/lib/crypto/public_key.c +++ b/lib/crypto/public_key.c @@ -51,38 +51,7 @@ static void public_key_describe(const struct key *asymmetric_key, } #endif -/* - * Destroy a public key algorithm key. - */ -void public_key_free(struct public_key *key) -{ - if (key) { - kfree(key->key); - kfree(key->params); - kfree(key); - } -} -EXPORT_SYMBOL_GPL(public_key_free); - #ifdef __UBOOT__ -/* - * from /crypto/asymmetric_keys/signature.c - * - * Destroy a public key signature. - */ -void public_key_signature_free(struct public_key_signature *sig) -{ - int i; - - if (sig) { - for (i = 0; i < ARRAY_SIZE(sig->auth_ids); i++) - free(sig->auth_ids[i]); - free(sig->s); - free(sig->digest); - free(sig); - } -} -EXPORT_SYMBOL_GPL(public_key_signature_free); /** * public_key_verify_signature - Verify a signature using a public key. diff --git a/lib/crypto/public_key_helper.c b/lib/crypto/public_key_helper.c new file mode 100644 index 000..4cb21edddf3 --- /dev/null +++ b/lib/crypto/public_key_helper.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * X509 helper functions + * + * Copyright (c) 2012 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowe...@redhat.com) + * + * Copyright (c) 2024 Linaro Limited + * Author: Raymond Mao + */ +#include +#include + +/* + * Destroy a public key algorithm key. + */ +void public_key_free(struct public_key *key) +{ + if (key) { + kfree(key->key); + kfree(key->params); + kfree(key); + } +} + +/* + * from /crypto/asymmetric_keys/signature.c + * + * Destroy a public key signature. + */ +void public_key_signature_free(struct public_key_signature *sig) +{ + int i; + + if (sig) { + for (i = 0; i < ARRAY_SIZE(sig->auth_ids); i++) + kfree(sig->auth_ids[i]); + kfree(sig->s); + kfree(sig->digest); + kfree(sig); + } +} -- 2.25.1
[PATCH v4 13/29] mbedtls/external: update MbedTLS PKCS7 test suites
Update the PKCS7 test suites for multiple certs. The PR for this patch is at: https://github.com/Mbed-TLS/mbedtls/pull/9001 For enabling EFI loader PKCS7 features with MbedTLS build, we need this patch on top of MbedTLS v3.6.0 before it is merged into the next MbedTLS LTS release. Signed-off-by: Raymond Mao --- Changes in v2 - None. Changes in v3 - Update commit message. Changes in v4 - None. .../external/mbedtls/tests/suites/test_suite_pkcs7.data | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mbedtls/external/mbedtls/tests/suites/test_suite_pkcs7.data b/lib/mbedtls/external/mbedtls/tests/suites/test_suite_pkcs7.data index d3b83cdf0aa..2dd1c56109f 100644 --- a/lib/mbedtls/external/mbedtls/tests/suites/test_suite_pkcs7.data +++ b/lib/mbedtls/external/mbedtls/tests/suites/test_suite_pkcs7.data @@ -14,9 +14,9 @@ PKCS7 Signed Data Parse with zero signers depends_on:MBEDTLS_MD_CAN_SHA256 pkcs7_parse:"data_files/pkcs7_data_no_signers.der":MBEDTLS_PKCS7_SIGNED_DATA -PKCS7 Signed Data Parse Fail with multiple certs #4 +PKCS7 Signed Data Parse Pass with multiple certs #4 depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C -pkcs7_parse:"data_files/pkcs7_data_multiple_certs_signed.der":MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE +pkcs7_parse:"data_files/pkcs7_data_multiple_certs_signed.der":MBEDTLS_PKCS7_SIGNED_DATA PKCS7 Signed Data Parse Fail with corrupted cert #5.0 depends_on:MBEDTLS_MD_CAN_SHA256:MBEDTLS_RSA_C -- 2.25.1
[PATCH v4 12/29] mbedtls/external: support decoding multiple signer's cert
Support decoding multiple signer's cert in the signed data within a PKCS7 message. The PR for this patch is at: https://github.com/Mbed-TLS/mbedtls/pull/9001 For enabling EFI loader PKCS7 features with MbedTLS build, we need this patch on top of MbedTLS v3.6.0 before it is merged into the next MbedTLS LTS release. Signed-off-by: Raymond Mao --- Changes in v2 - None. Changes in v3 - Update commit message. Changes in v4 - None. lib/mbedtls/external/mbedtls/library/pkcs7.c | 75 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/lib/mbedtls/external/mbedtls/library/pkcs7.c b/lib/mbedtls/external/mbedtls/library/pkcs7.c index da73fb341d6..01105227d7a 100644 --- a/lib/mbedtls/external/mbedtls/library/pkcs7.c +++ b/lib/mbedtls/external/mbedtls/library/pkcs7.c @@ -61,6 +61,36 @@ static int pkcs7_get_next_content_len(unsigned char **p, unsigned char *end, return ret; } +/** + * Get and decode one cert from a sequence. + * Return 0 for success, + * Return negative error code for failure. + **/ +static int pkcs7_get_one_cert(unsigned char **p, unsigned char *end, + mbedtls_x509_crt *certs) +{ +int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; +size_t len = 0; +unsigned char *start = *p; +unsigned char *end_cert; + +ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_CONSTRUCTED + | MBEDTLS_ASN1_SEQUENCE); +if (ret != 0) { +return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PKCS7_INVALID_CERT, ret); +} + +end_cert = *p + len; + +if ((ret = mbedtls_x509_crt_parse_der(certs, start, end_cert - start)) < 0) { +return MBEDTLS_ERR_PKCS7_INVALID_CERT; +} + +*p = end_cert; + +return 0; +} + /** * version Version * Version ::= INTEGER @@ -178,11 +208,12 @@ static int pkcs7_get_certificates(unsigned char **p, unsigned char *end, mbedtls_x509_crt *certs) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; -size_t len1 = 0; -size_t len2 = 0; -unsigned char *end_set, *end_cert, *start; +size_t len = 0; +unsigned char *end_set; +int num_of_certs = 0; -ret = mbedtls_asn1_get_tag(p, end, &len1, MBEDTLS_ASN1_CONSTRUCTED +/* Get the set of certs */ +ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC); if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { return 0; @@ -190,38 +221,26 @@ static int pkcs7_get_certificates(unsigned char **p, unsigned char *end, if (ret != 0) { return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PKCS7_INVALID_FORMAT, ret); } -start = *p; -end_set = *p + len1; +end_set = *p + len; -ret = mbedtls_asn1_get_tag(p, end_set, &len2, MBEDTLS_ASN1_CONSTRUCTED - | MBEDTLS_ASN1_SEQUENCE); +ret = pkcs7_get_one_cert(p, end_set, certs); if (ret != 0) { -return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PKCS7_INVALID_CERT, ret); +return ret; } -end_cert = *p + len2; +num_of_certs++; -/* - * This is to verify that there is only one signer certificate. It seems it is - * not easy to differentiate between the chain vs different signer's certificate. - * So, we support only the root certificate and the single signer. - * The behaviour would be improved with addition of multiple signer support. - */ -if (end_cert != end_set) { -return MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE; -} - -if ((ret = mbedtls_x509_crt_parse_der(certs, start, len1)) < 0) { -return MBEDTLS_ERR_PKCS7_INVALID_CERT; +while (*p != end_set) { +ret = pkcs7_get_one_cert(p, end_set, certs); +if (ret != 0) { +return ret; +} +num_of_certs++; } -*p = end_cert; +*p = end_set; -/* - * Since in this version we strictly support single certificate, and reaching - * here implies we have parsed successfully, we return 1. - */ -return 1; +return num_of_certs; } /** -- 2.25.1
[PATCH v4 11/29] mbedtls/external: support PKCS9 Authenticate Attributes
Populate PKCS9 Authenticate Attributes from signer info if it exists in a PKCS7 message. Add OIDs for describing objects using for Authenticate Attributes. The PR for this patch is at: https://github.com/Mbed-TLS/mbedtls/pull/9001 For enabling EFI loader PKCS7 features with MbedTLS build, we need this patch on top of MbedTLS v3.6.0 before it is merged into the next MbedTLS LTS release. Signed-off-by: Raymond Mao --- Changes in v2 - None. Changes in v3 - Update commit message. Changes in v4 - None. .../external/mbedtls/include/mbedtls/oid.h| 5 + .../external/mbedtls/include/mbedtls/pkcs7.h | 11 +++ lib/mbedtls/external/mbedtls/library/pkcs7.c | 19 ++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/mbedtls/external/mbedtls/include/mbedtls/oid.h b/lib/mbedtls/external/mbedtls/include/mbedtls/oid.h index 2ee982808fa..43cef99f1e3 100644 --- a/lib/mbedtls/external/mbedtls/include/mbedtls/oid.h +++ b/lib/mbedtls/external/mbedtls/include/mbedtls/oid.h @@ -238,6 +238,11 @@ #define MBEDTLS_OID_RSA_SHA_OBS "\x2B\x0E\x03\x02\x1D" #define MBEDTLS_OID_PKCS9_EMAIL MBEDTLS_OID_PKCS9 "\x01" /**< emailAddress AttributeType ::= { pkcs-9 1 } */ +#define MBEDTLS_OID_PKCS9_CONTENTTYPE MBEDTLS_OID_PKCS9 "\x03" /**< contentType AttributeType ::= { pkcs-9 3 } */ +#define MBEDTLS_OID_PKCS9_MESSAGEDIGEST MBEDTLS_OID_PKCS9 "\x04" /**< messageDigest AttributeType ::= { pkcs-9 4 } */ +#define MBEDTLS_OID_PKCS9_SIGNINGTIME MBEDTLS_OID_PKCS9 "\x05" /**< signingTime AttributeType ::= { pkcs-9 5 } */ +#define MBEDTLS_OID_PKCS9_SMIMECAP MBEDTLS_OID_PKCS9 "\x0f" /**< smimeCapabilites AttributeType ::= { pkcs-9 15 } */ +#define MBEDTLS_OID_PKCS9_SMIMEAA MBEDTLS_OID_PKCS9 "\x10\x02\x0b" /**< smimeCapabilites AttributeType ::= { pkcs-9 16 2 11} */ /* RFC 4055 */ #define MBEDTLS_OID_RSASSA_PSS MBEDTLS_OID_PKCS1 "\x0a" /**< id-RSASSA-PSS ::= { pkcs-1 10 } */ diff --git a/lib/mbedtls/external/mbedtls/include/mbedtls/pkcs7.h b/lib/mbedtls/external/mbedtls/include/mbedtls/pkcs7.h index 9e29b74af70..a88a5e858fc 100644 --- a/lib/mbedtls/external/mbedtls/include/mbedtls/pkcs7.h +++ b/lib/mbedtls/external/mbedtls/include/mbedtls/pkcs7.h @@ -102,6 +102,16 @@ typedef enum { } mbedtls_pkcs7_type; +/* + * Authenticate Attributes for MicroSoft Authentication Code using in U-Boot + * Secure Boot + */ +typedef struct mbedtls_pkcs7_authattrs { +size_t data_len; +void *data; +} +mbedtls_pkcs7_authattrs; + /** * Structure holding PKCS #7 signer info */ @@ -113,6 +123,7 @@ typedef struct mbedtls_pkcs7_signer_info { mbedtls_x509_buf MBEDTLS_PRIVATE(alg_identifier); mbedtls_x509_buf MBEDTLS_PRIVATE(sig_alg_identifier); mbedtls_x509_buf MBEDTLS_PRIVATE(sig); +mbedtls_pkcs7_authattrs authattrs; struct mbedtls_pkcs7_signer_info *MBEDTLS_PRIVATE(next); } mbedtls_pkcs7_signer_info; diff --git a/lib/mbedtls/external/mbedtls/library/pkcs7.c b/lib/mbedtls/external/mbedtls/library/pkcs7.c index 0c2436b56b7..da73fb341d6 100644 --- a/lib/mbedtls/external/mbedtls/library/pkcs7.c +++ b/lib/mbedtls/external/mbedtls/library/pkcs7.c @@ -288,6 +288,7 @@ static int pkcs7_get_signer_info(unsigned char **p, unsigned char *end, unsigned char *end_signer, *end_issuer_and_sn; int asn1_ret = 0, ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t len = 0; +unsigned char *tmp_p; asn1_ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE); @@ -349,7 +350,23 @@ static int pkcs7_get_signer_info(unsigned char **p, unsigned char *end, goto out; } -/* Assume authenticatedAttributes is nonexistent */ +/* Save authenticatedAttributes if present */ +if (*p < end_signer && +**p == (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)) { +tmp_p = *p; + +ret = mbedtls_asn1_get_tag(p, end_signer, &len, + MBEDTLS_ASN1_CONTEXT_SPECIFIC | + MBEDTLS_ASN1_CONSTRUCTED | 0); +if (ret != 0) { +goto out; +} + +signer->authattrs.data = tmp_p; +signer->authattrs.data_len = len + *p - tmp_p; +*p += len; +} + ret = pkcs7_get_digest_algorithm(p, end_signer, &signer->sig_alg_identifier); if (ret != 0) { goto out; -- 2.25.1
[PATCH v4 10/29] mbedtls/external: support Microsoft Authentication Code
Populate Microsoft Authentication Code from the content data into PKCS7 decoding context if it exists in a PKCS7 message. Add OIDs for describing objects using for Microsoft Authentication Code. The PR for this patch is at: https://github.com/Mbed-TLS/mbedtls/pull/9001 For enabling EFI loader PKCS7 features with MbedTLS build, we need this patch on top of MbedTLS v3.6.0 before it is merged into the next MbedTLS LTS release. Signed-off-by: Raymond Mao --- Changes in v2 - None. Changes in v3 - Update commit message. Changes in v4 - None. .../external/mbedtls/include/mbedtls/oid.h| 30 ++ .../external/mbedtls/include/mbedtls/pkcs7.h | 10 lib/mbedtls/external/mbedtls/library/pkcs7.c | 60 +++ 3 files changed, 90 insertions(+), 10 deletions(-) diff --git a/lib/mbedtls/external/mbedtls/include/mbedtls/oid.h b/lib/mbedtls/external/mbedtls/include/mbedtls/oid.h index fdc25ebf885..2ee982808fa 100644 --- a/lib/mbedtls/external/mbedtls/include/mbedtls/oid.h +++ b/lib/mbedtls/external/mbedtls/include/mbedtls/oid.h @@ -352,6 +352,36 @@ #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_128_CBC MBEDTLS_OID_PKCS12_PBE "\x05" /**< pbeWithSHAAnd128BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 5} */ #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_40_CBC MBEDTLS_OID_PKCS12_PBE "\x06" /**< pbeWithSHAAnd40BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 6} */ +/* + * MicroSoft Authenticate Code OIDs + */ +#define MBEDTLS_OID_PRIVATE_ENTERPRISE MBEDTLS_OID_INTERNET "\x04\x01" /* {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) */ +#define MBEDTLS_OID_MICROSOFT "\x82\x37" /* {microsoft(311)} */ +/* + * OID_msIndirectData: (1.3.6.1.4.1.311.2.1.4) + * {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) microsoft(311) 2(2) 1(1) 4(4)} + */ +#define MBEDTLS_OID_MICROSOFT_INDIRECTDATA MBEDTLS_OID_PRIVATE_ENTERPRISE MBEDTLS_OID_MICROSOFT \ +"\x02\x01\x04" +/* + * OID_msStatementType: (1.3.6.1.4.1.311.2.1.11) + * {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) microsoft(311) 2(2) 1(1) 11(11)} + */ +#define MBEDTLS_OID_MICROSOFT_STATETYPE MBEDTLS_OID_PRIVATE_ENTERPRISE MBEDTLS_OID_MICROSOFT \ +"\x02\x01\x0b" +/* + * OID_msSpOpusInfo: (1.3.6.1.4.1.311.2.1.12) + * {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) microsoft(311) 2(2) 1(1) 12(12)} + */ +#define MBEDTLS_OID_MICROSOFT_SPOPUSINFO MBEDTLS_OID_PRIVATE_ENTERPRISE MBEDTLS_OID_MICROSOFT \ +"\x02\x01\x0b" +/* + * OID_msPeImageDataObjId: (1.3.6.1.4.1.311.2.1.15) + * {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) microsoft(311) 2(2) 1(1) 15(15)} + */ +#define MBEDTLS_OID_MICROSOFT_PEIMAGEDATA MBEDTLS_OID_PRIVATE_ENTERPRISE MBEDTLS_OID_MICROSOFT \ +"\x02\x01\x0f" + /* * EC key algorithms from RFC 5480 */ diff --git a/lib/mbedtls/external/mbedtls/include/mbedtls/pkcs7.h b/lib/mbedtls/external/mbedtls/include/mbedtls/pkcs7.h index e9b482208e6..9e29b74af70 100644 --- a/lib/mbedtls/external/mbedtls/include/mbedtls/pkcs7.h +++ b/lib/mbedtls/external/mbedtls/include/mbedtls/pkcs7.h @@ -132,12 +132,22 @@ typedef struct mbedtls_pkcs7_signed_data { } mbedtls_pkcs7_signed_data; +/* Content Data for MicroSoft Authentication Code using in U-Boot Secure Boot */ +typedef struct mbedtls_pkcs7_conten_data { +int data_type; /* Type of Data */ +size_t data_len;/* Length of Data */ +size_t data_hdrlen; /* Length of Data ASN.1 header */ +void *data; /* Content Data */ +} +mbedtls_pkcs7_conten_data; + /** * Structure holding PKCS #7 structure, only signed data for now */ typedef struct mbedtls_pkcs7 { mbedtls_pkcs7_buf MBEDTLS_PRIVATE(raw); mbedtls_pkcs7_signed_data MBEDTLS_PRIVATE(signed_data); +mbedtls_pkcs7_conten_data content_data; } mbedtls_pkcs7; diff --git a/lib/mbedtls/external/mbedtls/library/pkcs7.c b/lib/mbedtls/external/mbedtls/library/pkcs7.c index 3aac662ba69..0c2436b56b7 100644 --- a/lib/mbedtls/external/mbedtls/library/pkcs7.c +++ b/lib/mbedtls/external/mbedtls/library/pkcs7.c @@ -29,6 +29,13 @@ #include #endif +enum OID { +/* PKCS#7 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-7(7)} */ +MBEDTLS_OID_DATA = 13, /* 1.2.840.113549.1.7.1 */ +/* Microsoft Authenticode & Software Publishing */ +MBEDTLS_OID_MS_INDIRECTDATA = 24,/* 1.3.6.1.4.1.311.2.1.4 */ +}; + /** * Initializes the mbedtls_pkcs7 structure. */ @@ -449,7 +456,7 @@ cleanup: * signerInfos SignerInfos } */ static int pkcs7_get_signed_data(unsigned char *buf, size_t buflen, - mbedtls_pkcs7_signed_data *signed_data) + mbedtls_pkcs7 *pkcs7) { unsigned char *p = buf; unsigned char *end = buf + buflen; @@ -457,6 +464,7 @@ static int pkcs7_get_signed_data(unsigned char *buf, size_t bufle
[PATCH v4 09/29] makefile: add mbedtls include directories
Add the mbedtls include directories into the build system. Signed-off-by: Raymond Mao --- Changes in v2 - None. Changes in v3 - Remove changes for PLATFORM_CPPFLAGS. Changes in v4 - Fix errors when building without "O=". - Minor fix of the include directories. Makefile | 6 ++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 07d7947c8af..fd855dbd5c9 100644 --- a/Makefile +++ b/Makefile @@ -829,6 +829,12 @@ KBUILD_HOSTCFLAGS += $(if $(CONFIG_TOOLS_DEBUG),-g) UBOOTINCLUDE:= \ -Iinclude \ $(if $(KBUILD_SRC), -I$(srctree)/include) \ + $(if $(CONFIG_MBEDTLS_LIB), \ + "-DMBEDTLS_CONFIG_FILE=\"mbedtls_def_config.h\"" \ + -I$(srctree)/lib/mbedtls \ + -I$(srctree)/lib/mbedtls/port \ + -I$(srctree)/lib/mbedtls/external/mbedtls \ + -I$(srctree)/lib/mbedtls/external/mbedtls/include) \ $(if $(CONFIG_$(SPL_)SYS_THUMB_BUILD), \ $(if $(CONFIG_HAS_THUMB2), \ $(if $(CONFIG_CPU_V7M), \ -- 2.25.1
[PATCH v4 08/29] hash: integrate hash on mbedtls
Integrate common/hash.c on the hash shim layer so that hash APIs from mbedtls can be leveraged by boot/image and efi_loader. Signed-off-by: Raymond Mao --- Changes in v2 - Use the original head files instead of creating new ones. Changes in v3 - Add handle checkers for malloc. Changes in v4 - None. common/hash.c | 143 ++ 1 file changed, 143 insertions(+) diff --git a/common/hash.c b/common/hash.c index ac63803fed9..96caf074374 100644 --- a/common/hash.c +++ b/common/hash.c @@ -35,6 +35,141 @@ #include #include +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO) + +static int hash_init_sha1(struct hash_algo *algo, void **ctxp) +{ + int ret; + mbedtls_sha1_context *ctx = malloc(sizeof(mbedtls_sha1_context)); + + if (!ctx) + return -ENOMEM; + + mbedtls_sha1_init(ctx); + ret = mbedtls_sha1_starts(ctx); + if (!ret) { + *ctxp = ctx; + } else { + mbedtls_sha1_free(ctx); + free(ctx); + } + + return ret; +} + +static int hash_update_sha1(struct hash_algo *algo, void *ctx, const void *buf, + unsigned int size, int is_last) +{ + return mbedtls_sha1_update((mbedtls_sha1_context *)ctx, buf, size); +} + +static int +hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf, int size) +{ + int ret; + + if (size < algo->digest_size) + return -1; + + ret = mbedtls_sha1_finish((mbedtls_sha1_context *)ctx, dest_buf); + if (!ret) { + mbedtls_sha1_free((mbedtls_sha1_context *)ctx); + free(ctx); + } + + return ret; +} + +static int hash_init_sha256(struct hash_algo *algo, void **ctxp) +{ + int ret; + int is224 = algo->digest_size == SHA224_SUM_LEN ? 1 : 0; + mbedtls_sha256_context *ctx = malloc(sizeof(mbedtls_sha256_context)); + + if (!ctx) + return -ENOMEM; + + mbedtls_sha256_init(ctx); + ret = mbedtls_sha256_starts(ctx, is224); + if (!ret) { + *ctxp = ctx; + } else { + mbedtls_sha256_free(ctx); + free(ctx); + } + + return ret; +} + +static int hash_update_sha256(struct hash_algo *algo, void *ctx, const void *buf, + uint size, int is_last) +{ + return mbedtls_sha256_update((mbedtls_sha256_context *)ctx, buf, size); +} + +static int +hash_finish_sha256(struct hash_algo *algo, void *ctx, void *dest_buf, int size) +{ + int ret; + + if (size < algo->digest_size) + return -1; + + ret = mbedtls_sha256_finish((mbedtls_sha256_context *)ctx, dest_buf); + if (!ret) { + mbedtls_sha256_free((mbedtls_sha256_context *)ctx); + free(ctx); + } + + return ret; +} + +static int hash_init_sha512(struct hash_algo *algo, void **ctxp) +{ + int ret; + int is384 = algo->digest_size == SHA384_SUM_LEN ? 1 : 0; + mbedtls_sha512_context *ctx = malloc(sizeof(mbedtls_sha512_context)); + + if (!ctx) + return -ENOMEM; + + mbedtls_sha512_init(ctx); + ret = mbedtls_sha512_starts(ctx, is384); + if (!ret) { + *ctxp = ctx; + } else { + mbedtls_sha512_free(ctx); + free(ctx); + } + + return ret; +} + +static int hash_update_sha512(struct hash_algo *algo, void *ctx, const void *buf, + uint size, int is_last) +{ + return mbedtls_sha512_update((mbedtls_sha512_context *)ctx, buf, size); +} + +static int +hash_finish_sha512(struct hash_algo *algo, void *ctx, void *dest_buf, int size) +{ + int ret; + + if (size < algo->digest_size) + return -1; + + ret = mbedtls_sha512_finish((mbedtls_sha512_context *)ctx, dest_buf); + if (!ret) { + mbedtls_sha512_free((mbedtls_sha512_context *)ctx); + free(ctx); + } + + return ret; +} + +#else /* CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO) */ + static int __maybe_unused hash_init_sha1(struct hash_algo *algo, void **ctxp) { sha1_context *ctx = malloc(sizeof(sha1_context)); @@ -143,6 +278,8 @@ static int __maybe_unused hash_finish_sha512(struct hash_algo *algo, void *ctx, return 0; } +#endif /* CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO) */ + static int hash_init_crc16_ccitt(struct hash_algo *algo, void **ctxp) { uint16_t *ctx = malloc(sizeof(uint16_t)); @@ -267,10 +404,16 @@ static struct hash_algo hash_algo[] = { .hash_init = hw_sha_init, .hash_update= hw_sha_update, .hash_finish= hw_sha_finish, +#else +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO) + .hash_init = hash_init_sha512, + .hash_update= hash_update_sha512, + .hash_finish= hash_finish_sha512, #else .hash_init
[PATCH v4 07/29] mbedtls: add digest shim layer for MbedTLS
Implement digest shim layer on top of MbedTLS crypto library. Introduce _MBEDTLS kconfig for MbedTLS crypto implementations. Signed-off-by: Raymond Mao --- Changes in v2 - Split the shim layer into separated files and use the original head files instead of creating new ones. Changes in v3 - Refactored sha1_hmac and removed non-watchdog md5 function. Changes in v4 - Refactored hash _wd functions. - Introduce _MBEDTLS kconfig for MbedTLS crypto implementations. include/u-boot/sha1.h | 4 ++ lib/mbedtls/Kconfig | 95 + lib/mbedtls/Makefile | 15 +-- lib/mbedtls/md5.c | 57 + lib/mbedtls/sha1.c| 99 +++ lib/mbedtls/sha256.c | 62 +++ lib/mbedtls/sha512.c | 93 7 files changed, 421 insertions(+), 4 deletions(-) create mode 100644 lib/mbedtls/md5.c create mode 100644 lib/mbedtls/sha1.c create mode 100644 lib/mbedtls/sha256.c create mode 100644 lib/mbedtls/sha512.c diff --git a/include/u-boot/sha1.h b/include/u-boot/sha1.h index 36c3db15e22..2fca7f1be16 100644 --- a/include/u-boot/sha1.h +++ b/include/u-boot/sha1.h @@ -41,6 +41,10 @@ extern "C" { #define SHA1_DEF_CHUNK_SZ 0x1 +#define K_IPAD_VAL 0x36 +#define K_OPAD_VAL 0x5C +#define K_PAD_LEN 64 + extern const uint8_t sha1_der_prefix[]; #if defined(CONFIG_MBEDTLS_LIB_CRYPTO) diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig index 6662a9d20f1..0cdf0135667 100644 --- a/lib/mbedtls/Kconfig +++ b/lib/mbedtls/Kconfig @@ -131,9 +131,104 @@ if MBEDTLS_LIB config MBEDTLS_LIB_CRYPTO bool "MbedTLS crypto libraries" + select MD5_MBEDTLS if MD5 + select SHA1_MBEDTLS if SHA1 + select SHA256_MBEDTLS if SHA256 + select SHA512_MBEDTLS if SHA512 + select SHA384_MBEDTLS if SHA384 + select SPL_MD5_MBEDTLS if MD5 && SPL + select SPL_SHA1_MBEDTLS if SHA1 && SPL + select SPL_SHA256_MBEDTLS if SHA256 && SPL + select SPL_SHA512_MBEDTLS if SHA512 && SPL + select SPL_SHA384_MBEDTLS if SHA384 && SPL help Enable MbedTLS crypto libraries. +if MBEDTLS_LIB_CRYPTO + +config SHA1_MBEDTLS + bool "Enable SHA1 support with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && SHA1 + help + This option enables support of hashing using SHA1 algorithm + with MbedTLS crypto library. + +config SHA256_MBEDTLS + bool "Enable SHA256 support with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && SHA256 + help + This option enables support of hashing using SHA256 algorithm + with MbedTLS crypto library. + +config SHA512_MBEDTLS + bool "Enable SHA512 support with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && SHA512 + default y if TI_SECURE_DEVICE && FIT_SIGNATURE + help + This option enables support of hashing using SHA512 algorithm + with MbedTLS crypto library. + +config SHA384_MBEDTLS + bool "Enable SHA384 support with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && SHA384 + select SHA512_MBEDTLS + help + This option enables support of hashing using SHA384 algorithm + with MbedTLS crypto library. + +config MD5_MBEDTLS + bool "Enable MD5 support with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && MD5 + help + This option enables support of hashing using MD5 algorithm + with MbedTLS crypto library. + +if SPL + +config SPL_SHA1_MBEDTLS + bool "Enable SHA1 support in SPL with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && SPL_SHA1 + default y if SHA1 && MBEDTLS_LIB_CRYPTO + help + This option enables support of hashing using SHA1 algorithm + with MbedTLS crypto library. + +config SPL_SHA256_MBEDTLS + bool "Enable SHA256 support in SPL with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && SPL_SHA256 + default y if SHA256 && MBEDTLS_LIB_CRYPTO + help + This option enables support of hashing using SHA256 algorithm + with MbedTLS crypto library. + +config SPL_SHA512_MBEDTLS + bool "Enable SHA512 support in SPL with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && SPL_SHA512 + default y if SHA512 && MBEDTLS_LIB_CRYPTO + help + This option enables support of hashing using SHA512 algorithm + with MbedTLS crypto library. + +config SPL_SHA384_MBEDTLS + bool "Enable SHA384 support in SPL with MbedTLS crypto library" + depends on MBEDTLS_LIB_CRYPTO && SPL_SHA384 + default y if SHA384 && MBEDTLS_LIB_CRYPTO + select SPL_SHA512 + help + This option enables support of hashing using SHA384 algorithm + with MbedTLS crypto library. + +config SPL_MD5_MBEDTLS + bool "Enable MD5 support in SPL with Mb
[PATCH v4 06/29] sha1: Remove sha1 non-watchdog API
We don't need an API specially for non-watchdog since sha1_csum_wd supports it by disabling CONFIG_HW_WATCHDOG and CONFIG_WATCHDOG. Set 0x1 as default chunk size for SHA1. Signed-off-by: Raymond Mao --- Changes in v4 - Initial patch. board/gdsys/a38x/hre.c | 2 +- include/u-boot/sha1.h | 12 ++-- lib/sha1.c | 13 - lib/tpm-v1.c | 2 +- 4 files changed, 4 insertions(+), 25 deletions(-) diff --git a/board/gdsys/a38x/hre.c b/board/gdsys/a38x/hre.c index f303793b63b..06856ea36d3 100644 --- a/board/gdsys/a38x/hre.c +++ b/board/gdsys/a38x/hre.c @@ -166,7 +166,7 @@ static int find_key(struct udevice *tpm, const uint8_t auth[20], return -1; if (err) continue; - sha1_csum(buf, buf_len, digest); + sha1_csum_wd(buf, buf_len, digest, SHA1_DEF_CHUNK_SZ); if (!memcmp(digest, pubkey_digest, 20)) { *handle = key_handles[i]; return 0; diff --git a/include/u-boot/sha1.h b/include/u-boot/sha1.h index ab88134fb98..36c3db15e22 100644 --- a/include/u-boot/sha1.h +++ b/include/u-boot/sha1.h @@ -39,6 +39,8 @@ extern "C" { #define SHA1_SUM_LEN 20 #define SHA1_DER_LEN 15 +#define SHA1_DEF_CHUNK_SZ 0x1 + extern const uint8_t sha1_der_prefix[]; #if defined(CONFIG_MBEDTLS_LIB_CRYPTO) @@ -81,16 +83,6 @@ void sha1_update(sha1_context *ctx, const unsigned char *input, */ void sha1_finish( sha1_context *ctx, unsigned char output[20] ); -/** - * \brief Output = SHA-1( input buffer ) - * - * \param inputbuffer holding the data - * \param ilenlength of the input data - * \param output SHA-1 checksum result - */ -void sha1_csum(const unsigned char *input, unsigned int ilen, - unsigned char *output); - /** * \brief Output = SHA-1( input buffer ), with watchdog triggering * diff --git a/lib/sha1.c b/lib/sha1.c index 7ef536f4b5d..81412283b49 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -304,19 +304,6 @@ void sha1_finish (sha1_context * ctx, unsigned char output[20]) PUT_UINT32_BE (ctx->state[4], output, 16); } -/* - * Output = SHA-1( input buffer ) - */ -void sha1_csum(const unsigned char *input, unsigned int ilen, - unsigned char *output) -{ - sha1_context ctx; - - sha1_starts (&ctx); - sha1_update (&ctx, input, ilen); - sha1_finish (&ctx, output); -} - /* * Output = SHA-1( input buffer ). Trigger the watchdog every 'chunk_sz' * bytes of input processed. diff --git a/lib/tpm-v1.c b/lib/tpm-v1.c index e66023da5e6..a6727c575fd 100644 --- a/lib/tpm-v1.c +++ b/lib/tpm-v1.c @@ -871,7 +871,7 @@ u32 tpm1_find_key_sha1(struct udevice *dev, const u8 auth[20], return -1; if (err) continue; - sha1_csum(buf, buf_len, digest); + sha1_csum_wd(buf, buf_len, digest, SHA1_DEF_CHUNK_SZ); if (!memcmp(digest, pubkey_digest, 20)) { *handle = key_handles[i]; return 0; -- 2.25.1
[PATCH v4 05/29] md5: Remove md5 non-watchdog API
We don't need an API specially for non-watchdog since md5_wd supports it by disabling CONFIG_HW_WATCHDOG and CONFIG_WATCHDOG. Set 0x1 as default chunk size for MD5. Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas Reviewed-by: Michal Simek --- Changes in v3 - Initial patch. Changes in v4 - Update commit message. board/friendlyarm/nanopi2/board.c | 3 ++- board/intel/edison/edison.c | 3 ++- board/xilinx/zynq/bootimg.c | 2 +- include/u-boot/md5.h | 7 +-- lib/md5.c | 15 --- 5 files changed, 6 insertions(+), 24 deletions(-) diff --git a/board/friendlyarm/nanopi2/board.c b/board/friendlyarm/nanopi2/board.c index c8cbc5a15fa..2d764e8eef3 100644 --- a/board/friendlyarm/nanopi2/board.c +++ b/board/friendlyarm/nanopi2/board.c @@ -263,7 +263,8 @@ static void make_ether_addr(u8 *addr) hash[6] = readl(PHY_BASEADDR_ECID + 0x08); hash[7] = readl(PHY_BASEADDR_ECID + 0x0c); - md5((unsigned char *)&hash[4], 64, (unsigned char *)hash); + md5_wd((unsigned char *)&hash[4], 64, (unsigned char *)hash, + MD5_DEF_CHUNK_SZ); hash[0] ^= hash[2]; hash[1] ^= hash[3]; diff --git a/board/intel/edison/edison.c b/board/intel/edison/edison.c index 911ffda2fc7..27fda3fc1d2 100644 --- a/board/intel/edison/edison.c +++ b/board/intel/edison/edison.c @@ -32,7 +32,8 @@ static void assign_serial(void) if (!mmc) return; - md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn); + md5_wd((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn, + MD5_DEF_CHUNK_SZ); snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x", ssn[13], ssn[14], ssn[15]); diff --git a/board/xilinx/zynq/bootimg.c b/board/xilinx/zynq/bootimg.c index 79bec3a4cfb..9eb0735f55d 100644 --- a/board/xilinx/zynq/bootimg.c +++ b/board/xilinx/zynq/bootimg.c @@ -135,7 +135,7 @@ int zynq_validate_partition(u32 start_addr, u32 len, u32 chksum_off) memcpy(&checksum[0], (u32 *)chksum_off, MD5_CHECKSUM_SIZE); - md5_wd((u8 *)start_addr, len, &calchecksum[0], 0x1); + md5_wd((u8 *)start_addr, len, &calchecksum[0], MD5_DEF_CHUNK_SZ); if (!memcmp(checksum, calchecksum, MD5_CHECKSUM_SIZE)) return 0; diff --git a/include/u-boot/md5.h b/include/u-boot/md5.h index 69898fcbe49..c98b1a58088 100644 --- a/include/u-boot/md5.h +++ b/include/u-boot/md5.h @@ -12,6 +12,7 @@ #include "compiler.h" #define MD5_SUM_LEN16 +#define MD5_DEF_CHUNK_SZ 0x1 #if defined(CONFIG_MBEDTLS_LIB_CRYPTO) typedef mbedtls_md5_context MD5Context; @@ -30,12 +31,6 @@ void MD5Init(MD5Context *ctx); void MD5Update(MD5Context *ctx, unsigned char const *buf, unsigned int len); void MD5Final(unsigned char digest[16], MD5Context *ctx); -/* - * Calculate and store in 'output' the MD5 digest of 'len' bytes at - * 'input'. 'output' must have enough space to hold 16 bytes. - */ -void md5 (unsigned char *input, int len, unsigned char output[16]); - /* * Calculate and store in 'output' the MD5 digest of 'len' bytes at 'input'. * 'output' must have enough space to hold 16 bytes. If 'chunk' Trigger the diff --git a/lib/md5.c b/lib/md5.c index 34343cf8e23..2d8977b2e85 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -262,21 +262,6 @@ MD5Transform(__u32 buf[4], __u32 const in[16]) buf[3] += d; } -/* - * Calculate and store in 'output' the MD5 digest of 'len' bytes at - * 'input'. 'output' must have enough space to hold 16 bytes. - */ -void -md5 (unsigned char *input, int len, unsigned char output[16]) -{ - MD5Context context; - - MD5Init(&context); - MD5Update(&context, input, len); - MD5Final(output, &context); -} - - /* * Calculate and store in 'output' the MD5 digest of 'len' bytes at 'input'. * 'output' must have enough space to hold 16 bytes. If 'chunk' Trigger the -- 2.25.1
[PATCH v4 04/29] lib: Adapt digest header files to MbedTLS
Adapt digest header files to support both original libs and MbedTLS by switching on/off MBEDTLS_LIB_CRYPTO. Introduce _LEGACY kconfig for legacy hash implementations. FIXME: `IS_ENABLED` or `CONFIG_IS_ENABLED` is not applicable here, since including causes undefined reference on schedule() with sandbox build. As includes which enables `CONFIG_HW_WATCHDOG` and `CONFIG_WATCHDOG` but no schedule() are defined in sandbox build. `#if defined(CONFIG_MBEDTLS_LIB_CRYPTO)` is a workaround. Signed-off-by: Raymond Mao --- Changes in v2 - Initial patch. Changes in v3 - Remove the changes that were done in previous clean-up patch set. Changes in v4 - Introduce _LEGACY kconfig for legacy hash implementations. - Minor fix of the include directories. include/u-boot/md5.h| 7 +++ include/u-boot/sha1.h | 21 - include/u-boot/sha256.h | 20 + include/u-boot/sha512.h | 22 -- lib/Makefile| 10 +++-- lib/mbedtls/Kconfig | 96 + 6 files changed, 168 insertions(+), 8 deletions(-) diff --git a/include/u-boot/md5.h b/include/u-boot/md5.h index c465925ea8d..69898fcbe49 100644 --- a/include/u-boot/md5.h +++ b/include/u-boot/md5.h @@ -6,10 +6,16 @@ #ifndef _MD5_H #define _MD5_H +#if defined(CONFIG_MBEDTLS_LIB_CRYPTO) +#include +#endif #include "compiler.h" #define MD5_SUM_LEN16 +#if defined(CONFIG_MBEDTLS_LIB_CRYPTO) +typedef mbedtls_md5_context MD5Context; +#else typedef struct MD5Context { __u32 buf[4]; __u32 bits[2]; @@ -18,6 +24,7 @@ typedef struct MD5Context { __u32 in32[16]; }; } MD5Context; +#endif void MD5Init(MD5Context *ctx); void MD5Update(MD5Context *ctx, unsigned char const *buf, unsigned int len); diff --git a/include/u-boot/sha1.h b/include/u-boot/sha1.h index c1e9f67068d..ab88134fb98 100644 --- a/include/u-boot/sha1.h +++ b/include/u-boot/sha1.h @@ -16,6 +16,21 @@ #include +#if defined(CONFIG_MBEDTLS_LIB_CRYPTO) +/* + * FIXME: + * MbedTLS define the members of "mbedtls_sha256_context" as private, + * but "state" needs to be access by arch/arm/cpu/armv8/sha1_ce_glue. + * MBEDTLS_ALLOW_PRIVATE_ACCESS needs to be enabled to allow the external + * access. + * Directly including is not allowed, + * since this will include and break the sandbox test. + */ +#define MBEDTLS_ALLOW_PRIVATE_ACCESS + +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -26,6 +41,9 @@ extern "C" { extern const uint8_t sha1_der_prefix[]; +#if defined(CONFIG_MBEDTLS_LIB_CRYPTO) +typedef mbedtls_sha1_context sha1_context; +#else /** * \brief SHA-1 context structure */ @@ -36,13 +54,14 @@ typedef struct unsigned char buffer[64]; /*!< data block being processed */ } sha1_context; +#endif /** * \brief SHA-1 context setup * * \param ctx SHA-1 context to be initialized */ -void sha1_starts( sha1_context *ctx ); +void sha1_starts(sha1_context *ctx); /** * \brief SHA-1 process buffer diff --git a/include/u-boot/sha256.h b/include/u-boot/sha256.h index a4fe176c0b4..b58d5b58d39 100644 --- a/include/u-boot/sha256.h +++ b/include/u-boot/sha256.h @@ -3,6 +3,22 @@ #include +#if defined(CONFIG_MBEDTLS_LIB_CRYPTO) +/* + * FIXME: + * MbedTLS define the members of "mbedtls_sha256_context" as private, + * but "state" needs to be access by arch/arm/cpu/armv8/sha256_ce_glue. + * MBEDTLS_ALLOW_PRIVATE_ACCESS needs to be enabled to allow the external + * access. + * Directly including is not allowed, + * since this will include and break the sandbox test. + */ +#define MBEDTLS_ALLOW_PRIVATE_ACCESS + +#include +#endif + +#define SHA224_SUM_LEN 28 #define SHA256_SUM_LEN 32 #define SHA256_DER_LEN 19 @@ -11,11 +27,15 @@ extern const uint8_t sha256_der_prefix[]; /* Reset watchdog each time we process this many bytes */ #define CHUNKSZ_SHA256 (64 * 1024) +#if defined(CONFIG_MBEDTLS_LIB_CRYPTO) +typedef mbedtls_sha256_context sha256_context; +#else typedef struct { uint32_t total[2]; uint32_t state[8]; uint8_t buffer[64]; } sha256_context; +#endif void sha256_starts(sha256_context * ctx); void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length); diff --git a/include/u-boot/sha512.h b/include/u-boot/sha512.h index 90bd96a3f8c..2b5a21a7c70 100644 --- a/include/u-boot/sha512.h +++ b/include/u-boot/sha512.h @@ -3,6 +3,10 @@ #include +#if defined(CONFIG_MBEDTLS_LIB_CRYPTO) +#include +#endif + #define SHA384_SUM_LEN 48 #define SHA384_DER_LEN 19 #define SHA512_SUM_LEN 64 @@ -12,11 +16,16 @@ #define CHUNKSZ_SHA384 (16 * 1024) #define CHUNKSZ_SHA512 (16 * 1024) +#if defined(CONFIG_MBEDTLS_LIB_CRYPTO) +typedef mbedtls_sha512_context sha384_context; +typedef mbedtls_sha512_context sha512_context; +#else typedef struct { uint64_t state[SHA512_SUM_LEN / 8]; uint64_t count[2]; uint8_t buf[SHA512_BLOCK_SIZE]; } sha512_contex
Re: [RESEND PATCH v4 0/3] provide names for emmc hardware partitions
Hello Tim, On 2024-07-02 20:14, Tim Harvey wrote: On Fri, May 31, 2024 at 8:36 AM Tim Harvey wrote: Modern eMMC v4+ devices have multiple hardware partitions per the JEDEC specification described as: Boot Area Partition 1 Boot Area Partition 2 RPMB Partition General Purpose Partition 1 General Purpose Partition 2 General Purpose Partition 3 General Purpose Partition 4 User Data Area These are referenced by fields in the PARTITION_CONFIG register (Extended CSD Register 179) which is defined as: bit 7: reserved bit 6: BOOT_ACK 0x0: No boot acknowledge sent (default 0x1: Boot acknowledge sent during boot operation Bit bit 5:3: BOOT_PARTITION_ENABLE 0x0: Device not boot enabled (default) 0x1: Boot Area partition 1 enabled for boot 0x2: Boot Area partition 2 enabled for boot 0x3-0x6: Reserved 0x7: User area enabled for boot bit 2:0 PARTITION_ACCESS 0x0: No access to boot partition (default) 0x1: Boot Area partition 1 0x2: Boot Area partition 2 0x3: Replay Protected Memory Block (RPMB) 0x4: Access to General Purpose partition 1 0x5: Access to General Purpose partition 2 0x6: Access to General Purpose partition 3 0x7: Access to General Purpose partition 4 Note that setting PARTITION_ACCESS to 0x0 results in selecting the User Data Area partition. You can see above that the two fields BOOT_PARTITION_ENABLE and PARTITION_ACCESS do not use the same enumerated values. U-Boot uses a set of macros to access fields of the PARTITION_CONFIG register: EXT_CSD_BOOT_ACK_ENABLE (1 << 6) EXT_CSD_BOOT_PARTITION_ENABLE (1 << 3) EXT_CSD_PARTITION_ACCESS_ENABLE (1 << 0) EXT_CSD_PARTITION_ACCESS_DISABLE(0 << 0) EXT_CSD_BOOT_ACK(x) (x << 6) EXT_CSD_BOOT_PART_NUM(x)(x << 3) EXT_CSD_PARTITION_ACCESS(x) (x << 0) EXT_CSD_EXTRACT_BOOT_ACK(x) (((x) >> 6) & 0x1) EXT_CSD_EXTRACT_BOOT_PART(x) (((x) >> 3) & 0x7) EXT_CSD_EXTRACT_PARTITION_ACCESS(x) ((x) & 0x7) There are various places in U-Boot where the BOOT_PARTITION_ENABLE field is accessed via EXT_CSD_EXTRACT_PARTITION_ACCESS and converted to a hardware partition consistent with the definition of the PARTITION_ACCESS field used by the various mmc_switch incarnations. To add some sanity to the distinction between BOOT_PARTITION_ENABLE (used to specify the active device on power-cycle) and PARTITION_ACCESS (used to switch between hardware partitions) create two enumerated types and use them wherever struct mmc * part_config is used or the above macros are used. Additionally provide arrays of the field names and allow those to be used in the 'mmc partconf' command and in board support files. The first patch adds enumerated types and makes use of them which represents no compiled code change. The 2nd patch adds the array of names and uses them in the 'mmc partconf' command. The 3rd patch uses the array of hardware partition names in a board support file to show what emmc hardware partition U-Boot is being loaded from. I'm sending this as a series this time around as previously it was repsented as two different patches. Tim Harvey (3): mmc: use an enumerated type to represent PARTITION_CONFIG fields mmc: allow use of hardware partition names for mmc partconf venice: show emmc boot hardware partition arch/arm/mach-imx/image-container.c | 10 - arch/arm/mach-sunxi/board.c | 2 +- board/gateworks/venice/spl.c| 20 - board/gateworks/venice/venice.c | 22 +- board/purism/librem5/librem5.c | 4 ++-- board/storopack/smegw01/smegw01.c | 4 ++-- cmd/mmc.c | 27 ++ cmd/mvebu/bubt.c| 4 ++-- common/spl/spl_mmc.c| 4 ++-- drivers/mmc/mmc.c | 35 + include/mmc.h | 26 + 11 files changed, 123 insertions(+), 35 deletions(-) Is there any feedback on this series? I got feedback from several people on my first attempt (cc'd) but nothing on this version. Any chances, please, to provide links to each of the patch and series versions on https://lore.kernel.org/u-boot/ , together with a brief changelog and history? I'm having troubles refreshing my memory on what patches were actually pulled into what series. My guess is that other people would also benefit from such a refresher.
[PATCH v4 03/29] mbedtls: add mbedtls into the build system
Port mbedtls with adapted libc header files. Add mbedtls default config header file. Optimize mbedtls default config by disabling unused features to reduce the target size. Add mbedtls kbuild makefile. Add Kconfig skeleton and config submenu entry for selecting crypto libraries between mbedtls and legacy ones. Subsequent patches will separate those Kconfigs into pairs of _LEGACY and _MBEDTLS for controlling the implementations of legacy crypto libraries and MbedTLS ones respectively. The motivation of moving and adapting *INT* macros from kernel.h to limits.h is to fullfill the MbedTLS building requirement. The conditional compilation statements in MbedTLS expects the *INT* macros as constant expressions, thus expressions like `((int)(~0U >> 1))` will not work. Prerequisite This patch series requires mbedtls git repo to be added as a subtree to the main U-Boot repo via: $ git subtree add --prefix lib/mbedtls/external/mbedtls \ https://github.com/Mbed-TLS/mbedtls.git \ v3.6.0 --squash Moreover, due to the Windows-style files from mbedtls git repo, we need to convert the CRLF endings to LF and do a commit manually: $ git add --renormalize . $ git commit Signed-off-by: Raymond Mao --- Changes in v2 - Disabled unused MbedTLS features to optimize the target size. Changes in v3 - Removed changes in stdio.h. Changes in v4 - Move limits.h as a common header file that is included by kernel.h. - Refactor the Kconfig to support legacy and MbedTLS options for each algorithm. - Refactor MbedTLS makefile and default config file to remove unused config options and objects. - removed the unused CONFIG_MBEDTLS_LIB_TLS. include/limits.h | 29 ++ include/linux/kernel.h | 13 +- include/stdlib.h | 1 + lib/Kconfig | 4 ++ lib/Makefile | 2 + lib/mbedtls/Kconfig | 47 ++ lib/mbedtls/Makefile | 49 +++ lib/mbedtls/mbedtls_def_config.h | 69 lib/mbedtls/port/assert.h| 12 ++ 9 files changed, 214 insertions(+), 12 deletions(-) create mode 100644 include/limits.h create mode 100644 lib/mbedtls/Kconfig create mode 100644 lib/mbedtls/Makefile create mode 100644 lib/mbedtls/mbedtls_def_config.h create mode 100644 lib/mbedtls/port/assert.h diff --git a/include/limits.h b/include/limits.h new file mode 100644 index 000..cc691d15650 --- /dev/null +++ b/include/limits.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2023 Linaro Limited + * Author: Raymond Mao + */ + +#ifndef _LIMITS_H +#define _LIMITS_H + +#define INT_MAX 0x7fff +#define UINT_MAX 0xUL +#define CHAR_BIT8 +#define UINT32_MAX 0xUL +#define UINT64_MAX 0xUL + +#ifdef CONFIG_64BIT +#define UINTPTR_MAX UINT64_MAX +#else +#define UINTPTR_MAX UINT32_MAX +#endif + +#ifndef SIZE_MAX +#define SIZE_MAXUINTPTR_MAX +#endif +#ifndef SSIZE_MAX +#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) +#endif + +#endif /* _LIMITS_H */ diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 5cd6c9dc821..2cb2ceaf84b 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -3,25 +3,18 @@ #include #include /* for printf/pr_* utilities */ +#include #define USHRT_MAX ((u16)(~0U)) #define SHRT_MAX ((s16)(USHRT_MAX>>1)) #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) -#define INT_MAX((int)(~0U>>1)) #define INT_MIN(-INT_MAX - 1) -#define UINT_MAX (~0U) #define LONG_MAX ((long)(~0UL>>1)) #define LONG_MIN (-LONG_MAX - 1) #define ULONG_MAX (~0UL) #define LLONG_MAX ((long long)(~0ULL>>1)) #define LLONG_MIN (-LLONG_MAX - 1) #define ULLONG_MAX (~0ULL) -#ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) -#endif -#ifndef SSIZE_MAX -#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) -#endif #define U8_MAX ((u8)~0U) #define S8_MAX ((s8)(U8_MAX>>1)) @@ -36,10 +29,6 @@ #define S64_MAX((s64)(U64_MAX>>1)) #define S64_MIN((s64)(-S64_MAX - 1)) -/* Aliases defined by stdint.h */ -#define UINT32_MAX U32_MAX -#define UINT64_MAX U64_MAX - #define INT32_MAX S32_MAX #define STACK_MAGIC0xdeadbeef diff --git a/include/stdlib.h b/include/stdlib.h index 9c175d4d74c..dedfd52a144 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -7,5 +7,6 @@ #define __STDLIB_H_ #include +#include #endif /* __STDLIB_H_ */ diff --git a/lib/Kconfig b/lib/Kconfig index 189e6eb31aa..ff89af6be74 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -418,6 +418,10 @@ config CIRCBUF source "lib/dhry/Kconfig" +menu "Alternative crypto libraries" +source lib/mbedtls/Kconfig +endmenu + menu "Security support" config AES diff --git a/lib/Makefile b/lib/Makefile index 2a76acf
[PATCH v4 02/29] mbedtls: Add script to update MbedTLS subtree
lib/mbedtls/update-mbedtls-subtree.sh is a wrapper of git subtree commands. Usage from U-Boot top directory, run: $ ./lib/mbedtls/update-mbedtls-subtree.sh pull $ ./lib/mbedtls/update-mbedtls-subtree.sh pick Signed-off-by: Raymond Mao --- Changes in v2 - Initial patch. Changes in v3 - None. Changes in v4 - Minor fix and move the script into tools dir. tools/update-mbedtls-subtree.sh | 47 + 1 file changed, 47 insertions(+) create mode 100755 tools/update-mbedtls-subtree.sh diff --git a/tools/update-mbedtls-subtree.sh b/tools/update-mbedtls-subtree.sh new file mode 100755 index 000..0a98a4d6e82 --- /dev/null +++ b/tools/update-mbedtls-subtree.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2024 Linaro Ltd. +# +# Usage: from the top level U-Boot source tree, run: +# $ ./tools/update-mbedtls-subtree.sh pull +# $ ./tools/update-mbedtls-subtree.sh pick +# +# The script will pull changes from MbedTLS repo into U-Boot +# as a subtree located as /lib/mbedtls/external/mbedtls sub-directory. +# It will automatically create a squash/merge commit listing the commits +# imported. + +set -e + +merge_commit_msg=$(cat << EOF +Subtree merge tag '$2' of MbedTLS repo [1] into lib/mbedtls/external/mbedtls + +[1] https://github.com/Mbed-TLS/mbedtls.git +EOF +) + +remote_add_and_fetch() { +if [ -z "$(git remote get-url mbedtls_upstream 2>/dev/null)" ]; then +echo "Warning: Script automatically adds new git remote via:" +echo "git remote add mbedtls_upstream \\" +echo "https://github.com/Mbed-TLS/mbedtls.git"; +git remote add mbedtls_upstream \ +https://github.com/Mbed-TLS/mbedtls.git +fi +git fetch mbedtls_upstream master +} + +if [ "$1" = 'pull' ]; then +remote_add_and_fetch +git subtree pull --prefix lib/mbedtls/external/mbedtls mbedtls_upstream \ +"$2" --squash -m "${merge_commit_msg}" +elif [ "$1" = 'pick' ]; then +remote_add_and_fetch +git cherry-pick -x --strategy=subtree \ +-Xsubtree=lib/mbedtls/external/mbedtls/ "$2" +else +echo "usage: $0 " +echo " pull or pick" +echo " release tag [pull] or commit id [pick]" +fi -- 2.25.1
[PATCH v4 01/29] CI: Exclude MbedTLS subtree for CONFIG checks
Since MbedTLS is an external repo with its own coding style, exclude it from Azure and gitlab CI CONFIG checks. Signed-off-by: Raymond Mao Reviewed-by: Tom Rini Reviewed-by: Ilias Apalodimas --- Changes in v2 - Initial patch. Changes in v3 - None. Changes in v4 - None. .azure-pipelines.yml | 3 ++- .gitlab-ci.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 27f69583c65..c8052771fa8 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -65,7 +65,8 @@ stages: # have no matches. - script: git grep -E '^#[[:blank:]]*(define|undef)[[:blank:]]*CONFIG_' :^doc/ :^arch/arm/dts/ :^scripts/kconfig/lkc.h - :^include/linux/kconfig.h :^tools/ :^dts/upstream/ && + :^include/linux/kconfig.h :^tools/ :^dts/upstream/ + :^lib/mbedtls/external :^lib/mbedtls/mbedtls_def_config.h && exit 1 || exit 0 - job: docs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 165f765a833..a8f7f1940f3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -156,7 +156,8 @@ check for new CONFIG symbols outside Kconfig: # have no matches. - git grep -E '^#[[:blank:]]*(define|undef)[[:blank:]]*CONFIG_' :^doc/ :^arch/arm/dts/ :^scripts/kconfig/lkc.h -:^include/linux/kconfig.h :^tools/ :^dts/upstream/ && +:^include/linux/kconfig.h :^tools/ :^dts/upstream/ +:^lib/mbedtls/external :^lib/mbedtls/mbedtls_def_config.h && exit 1 || exit 0 # build documentation -- 2.25.1
[PATCH v4 00/29] Integrate MbedTLS v3.6 LTS with U-Boot
Integrate MbedTLS v3.6 LTS (currently v3.6.0-RC1) with U-Boot. Motivations: 1. MbedTLS is well maintained with LTS versions. 2. LWIP is integrated with MbedTLS and easily to enable HTTPS. 3. MbedTLS recently switched license back to GPLv2. Prerequisite: - This patch series requires mbedtls git repo to be added as a subtree to the main U-Boot repo via: $ git subtree add --prefix lib/mbedtls/external/mbedtls \ https://github.com/Mbed-TLS/mbedtls.git \ v3.6.0 --squash Moreover, due to the Windows-style files from mbedtls git repo, we need to convert the CRLF endings to LF and do a commit manually: $ git add --renormalize . $ git commit New Kconfig options: `MBEDTLS_LIB` is for MbedTLS general switch. `MBEDTLS_LIB_CRYPTO` is for replacing original digest and crypto libs with MbedTLS. `MBEDTLS_LIB_X509` is for replacing original X509, PKCS7, MSCode, ASN1, and Pubkey parser with MbedTLS. `MBEDTLS_LIB_TLS` is for SSL/TLS (Disabled until LWIP port for MbedTLS is ready). `LEGACY_CRYPTO` is introduced as a main switch for legacy crypto library. `LEGACY_CRYPTO_BASIC` is for the basic crypto functionalities and `LEGACY_CRYPTO_CERT` is for the certificate related functionalities. For each of the algorithm, a pair of `_LEGACY` and `_MBEDTLS` Kconfig options are introduced. Meanwhile, `SPL_` Kconfig options are introduced. In this patch set, MBEDTLS_LIB, MBEDTLS_LIB_CRYPTO and MBEDTLS_LIB_X509 are by default enabled in qemu_arm64_defconfig for testing purpose. Patches for external MbedTLS project: - Since U-Boot uses Microsoft Authentication Code to verify PE/COFFs executables which is not supported by MbedTLS at the moment, addtional patches for MbedTLS are created to adapt with the EFI loader: 1. Decoding of Microsoft Authentication Code. 2. Decoding of PKCS#9 Authenticate Attributes. 3. Extending MbedTLS PKCS#7 lib to support multiple signer's certificates. 4. MbedTLS native test suites for PKCS#7 signer's info. All above 4 patches (tagged with `mbedtls/external`) are submitted to MbedTLS project and being reviewed, eventually they should be part of MbedTLS LTS release. But before that, please merge them into U-Boot, otherwise the building will be broken when MBEDTLS_LIB_X509 is enabled. See below PR link for the reference: https://github.com/Mbed-TLS/mbedtls/pull/9001 Miscellaneous: -- Optimized MbedTLS library size by tailoring the config file and disabling all unnecessary features for EFI loader. >From v2, original libs (rsa, asn1_decoder, rsa_helper, md5, sha1, sha256, sha512) are completely replaced when MbedTLS is enabled. >From v3, the size-growth is slightly reduced by refactoring Hash functions. Target(QEMU arm64) size-growth when enabling MbedTLS: v1: 6.03% v2: 4.66% v3 & v4: 4.55% Please see the latest output of bloat-o-meter for the reference of the size-growth on QEMU arm64 target [1]. Tests done: --- EFI Secure Boot test (EFI variables loading and verifying, EFI signed image verifying and booting) via U-Boot console. EFI Secure Boot and Capsule sandbox test passed. Known issues: - None. [1]: bloat-o-meter output between disabling/enabling MbedTLS (QEMU arm64) ``` add/remove: 206/81 grow/shrink: 19/17 up/down: 55548/-17495 (38053) Function old new delta mbedtls_internal_sha1_process -4540 +4540 mbedtls_x509_crt_parse_der_internal-3072 +3072 mbedtls_internal_md5_process -2928 +2928 mbedtls_internal_sha256_process-2052 +2052 mbedtls_pkcs7_parse_der-1608 +1608 mbedtls_rsa_private-1468 +1468 pkcs7_parse_message 3721648 +1276 mbedtls_mpi_div_mpi-1168 +1168 mbedtls_internal_sha512_process-1056 +1056 mbedtls_mpi_inv_mod-1000 +1000 mbedtls_x509_dn_gets - 996+996 x509_populate_cert - 948+948 K - 896+896 oid_x520_attr_type - 840+840 __udivti3 - 832+832 mbedtls_x509_parse_subject_alt_name- 724+724 mbedtls_rsa_deduce_primes - 720+720 mbedtls_mpi_exp_mod- 668+668 mbedtls_rsa_rsaes_pkcs1_v15_decrypt- 652+652 pkcs7_get_signer_info - 632+632 mbedtls_rsa_complete - 624+624 mbedtls_rsa_validate_params- 608+608 mbedtls_mpi_core_exp_mod - 560+560 mbedtls_sha512_finish - 556+556 mscode_parse
Re: [RESEND PATCH v4 0/3] provide names for emmc hardware partitions
On Fri, May 31, 2024 at 8:36 AM Tim Harvey wrote: > > Modern eMMC v4+ devices have multiple hardware partitions per the JEDEC > specification described as: > Boot Area Partition 1 > Boot Area Partition 2 > RPMB Partition > General Purpose Partition 1 > General Purpose Partition 2 > General Purpose Partition 3 > General Purpose Partition 4 > User Data Area > > These are referenced by fields in the PARTITION_CONFIG register > (Extended CSD Register 179) which is defined as: > bit 7: reserved > bit 6: BOOT_ACK > 0x0: No boot acknowledge sent (default > 0x1: Boot acknowledge sent during boot operation Bit > bit 5:3: BOOT_PARTITION_ENABLE > 0x0: Device not boot enabled (default) > 0x1: Boot Area partition 1 enabled for boot > 0x2: Boot Area partition 2 enabled for boot > 0x3-0x6: Reserved > 0x7: User area enabled for boot > bit 2:0 PARTITION_ACCESS > 0x0: No access to boot partition (default) > 0x1: Boot Area partition 1 > 0x2: Boot Area partition 2 > 0x3: Replay Protected Memory Block (RPMB) > 0x4: Access to General Purpose partition 1 > 0x5: Access to General Purpose partition 2 > 0x6: Access to General Purpose partition 3 > 0x7: Access to General Purpose partition 4 > > Note that setting PARTITION_ACCESS to 0x0 results in selecting the User > Data Area partition. > > You can see above that the two fields BOOT_PARTITION_ENABLE and > PARTITION_ACCESS do not use the same enumerated values. > > U-Boot uses a set of macros to access fields of the PARTITION_CONFIG > register: > EXT_CSD_BOOT_ACK_ENABLE (1 << 6) > EXT_CSD_BOOT_PARTITION_ENABLE (1 << 3) > EXT_CSD_PARTITION_ACCESS_ENABLE (1 << 0) > EXT_CSD_PARTITION_ACCESS_DISABLE(0 << 0) > > EXT_CSD_BOOT_ACK(x) (x << 6) > EXT_CSD_BOOT_PART_NUM(x)(x << 3) > EXT_CSD_PARTITION_ACCESS(x) (x << 0) > > EXT_CSD_EXTRACT_BOOT_ACK(x) (((x) >> 6) & 0x1) > EXT_CSD_EXTRACT_BOOT_PART(x) (((x) >> 3) & 0x7) > EXT_CSD_EXTRACT_PARTITION_ACCESS(x) ((x) & 0x7) > > There are various places in U-Boot where the BOOT_PARTITION_ENABLE field > is accessed via EXT_CSD_EXTRACT_PARTITION_ACCESS and converted to a > hardware partition consistent with the definition of the > PARTITION_ACCESS field used by the various mmc_switch incarnations. > > To add some sanity to the distinction between BOOT_PARTITION_ENABLE > (used to specify the active device on power-cycle) and PARTITION_ACCESS > (used to switch between hardware partitions) create two enumerated types > and use them wherever struct mmc * part_config is used or the above > macros are used. > > Additionally provide arrays of the field names and allow those to be > used in the 'mmc partconf' command and in board support files. > > The first patch adds enumerated types and makes use of them which > represents no compiled code change. > > The 2nd patch adds the array of names and uses them in the 'mmc > partconf' command. > > The 3rd patch uses the array of hardware partition names in a board > support file to show what emmc hardware partition U-Boot is being loaded > from. > > I'm sending this as a series this time around as previously it was > repsented as two different patches. > > Tim Harvey (3): > mmc: use an enumerated type to represent PARTITION_CONFIG fields > mmc: allow use of hardware partition names for mmc partconf > venice: show emmc boot hardware partition > > arch/arm/mach-imx/image-container.c | 10 - > arch/arm/mach-sunxi/board.c | 2 +- > board/gateworks/venice/spl.c| 20 - > board/gateworks/venice/venice.c | 22 +- > board/purism/librem5/librem5.c | 4 ++-- > board/storopack/smegw01/smegw01.c | 4 ++-- > cmd/mmc.c | 27 ++ > cmd/mvebu/bubt.c| 4 ++-- > common/spl/spl_mmc.c| 4 ++-- > drivers/mmc/mmc.c | 35 + > include/mmc.h | 26 + > 11 files changed, 123 insertions(+), 35 deletions(-) > > -- > 2.25.1 > Greetings, Is there any feedback on this series? I got feedback from several people on my first attempt (cc'd) but nothing on this version. Best Regards, Tim
Re: [PATCH v2] binman: Update cbfstool
On Tue, Jul 02, 2024 at 05:37:28PM +0100, Simon Glass wrote: > Update to a newer version of this tool, 4.22.01. This runs OK with the > current binman tests and matches the one in CI. > > Signed-off-by: Simon Glass Reviewed-by: Tom Rini -- Tom signature.asc Description: PGP signature
[PATCH v2] sandbox: Fix LTO to work with STACKPROTECTOR
Add the STACKPROTECTOR symbols to the script that generates the symbols that should not be removed by the use of LTO when linking a shared object. This prevents a fail to build due to link errors. https://source.denx.de/u-boot/u-boot/-/issues/35 Signed-off-by: Andrew Goodbody --- Changes in v2: - Made the new match more specific and added it to the grep run rather than run grep twice scripts/gen_ll_addressable_symbols.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/gen_ll_addressable_symbols.sh b/scripts/gen_ll_addressable_symbols.sh index 13f670ae0e..fc5ee0e9c0 100755 --- a/scripts/gen_ll_addressable_symbols.sh +++ b/scripts/gen_ll_addressable_symbols.sh @@ -11,5 +11,6 @@ set -e echo '#include ' -$@ 2>/dev/null | grep -oe '_u_boot_list_2_[a-zA-Z0-9_]*_2_[a-zA-Z0-9_]*' | \ - sort -u | sed -e 's/^\(.*\)/extern char \1[];\n__ADDRESSABLE(\1);/' +$@ 2>/dev/null | grep -oe '_u_boot_list_2_[a-zA-Z0-9_]*_2_[a-zA-Z0-9_]*' \ + -e '__stack_chk_guard' | sort -u | \ + sed -e 's/^\(.*\)/extern char \1[];\n__ADDRESSABLE(\1);/' -- 2.39.2
[PATCH v2] binman: Update cbfstool
Update to a newer version of this tool, 4.22.01. This runs OK with the current binman tests and matches the one in CI. Signed-off-by: Simon Glass --- Changes in v2: - Use the same version as CI (4.22.01) tools/binman/btool/cbfstool.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/binman/btool/cbfstool.py b/tools/binman/btool/cbfstool.py index 29be2d8a2b5..2d8559abb2b 100644 --- a/tools/binman/btool/cbfstool.py +++ b/tools/binman/btool/cbfstool.py @@ -214,6 +214,7 @@ class Bintoolcbfstool(bintool.Bintool): """ if method != bintool.FETCH_BIN: return None +# Version 4.22.01 fname, tmpdir = self.fetch_from_drive( -'1IOnE0Qvy97d-0WOCwF64xBGpKSY2sMtJ') +'1gxNxRuJgD0Iiy9LAPCSB_0959eJCp98g') return fname, tmpdir -- 2.34.1
Re: [RFC v2 2/2] doc: add missing table of content links
Hi Sam, On Tue, 2 Jul 2024 at 02:14, Sam Povilus wrote: > Please can you add a commit message? > Signed-off-by: Sam Povilus > --- > doc/usage/fit/index.rst | 20 > 1 file changed, 20 insertions(+) > > diff --git a/doc/usage/fit/index.rst b/doc/usage/fit/index.rst > index af2e481212..904f1593cb 100644 > --- a/doc/usage/fit/index.rst > +++ b/doc/usage/fit/index.rst > @@ -16,3 +16,23 @@ images that it it reads and boots. Documentation about FIT > is available in > verified-boot > beaglebone_vboot > overlay-fdt-boot > +beaglebone_vboot This seems to duplicate an entry above. Can you try 'make htmldocs' and check that it passes? > +howto > +kernel_fdt > +kernel_fdts_compressed > +kernel > +multi > +multi_spl > +multi-with-fpga > +multi-with-loadables > +overlay-fdt-boot > +sec_firmware_ppa > +signature > +sign-configs > +sign-images > +uefi > +update3 > +update_uboot > +verified-boot > +x86-fit-boot > + > -- > 2.34.1 > Regards, Simon
Re: [PATCH v2] tools: patman: fix `pip install` with Python 3.12
On Mon, 1 Jul 2024 at 18:51, Brandon Maier wrote: > > Installing patman with `cd ./tools/patman && pip install -e .` fails > with the error below. > > As described in the error output below, the license line is not allowed > to be only defined in the setup.py. We remove the 'license' field > entirely, as the Python Packaging User Guide recommends using projects > classifiers instead[1] and we already set the GPL-2.0+ classifier. > > > $ cd ./tools/patman && pip install -e . > > Obtaining file:///.../u-boot/tools/patman > > Installing build dependencies ... done > > Checking if build backend supports build_editable ... done > > Getting requirements to build editable ... error > > error: subprocess-exited-with-error > > > > × Getting requirements to build editable did not run successfully. > > │ exit code: 1 > > ╰─> [61 lines of output] > > > > /tmp/pip-build-env-mqjvnmz8/overlay/lib/python3.12/site-packages/setuptools/config/_apply_pyprojecttoml.py:76: > > _MissingDynamic: `license` defined outside of `pyproject.toml` is > > ignored. > > !! > > > > > > > > The following seems to be defined outside of `pyproject.toml`: > > > > `license = 'GPL-2.0+'` > > > > According to the spec (see the link below), however, setuptools CANNOT > > consider this value unless `license` is listed as `dynamic`. > > > > > > https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table > > > > To prevent this problem, you can list `license` under `dynamic` or > > alternatively > > remove the `[project]` table from your file and rely entirely on > > other means of > > configuration. > > > > > > > > !! > > [1] > https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license > > Signed-off-by: Brandon Maier > --- > Changes in v2: > - drop the license in favor of license classifiers > --- > tools/patman/setup.py | 1 - > 1 file changed, 1 deletion(-) Reviewed-by: Simon Glass Thanks
Re: [PATCH 1/1] doc: fix heading level of itest examples
On Mon, 1 Jul 2024 at 21:43, Heinrich Schuchardt wrote: > > The Examples section should be on the second heading level. > > Signed-off-by: Heinrich Schuchardt > --- > doc/usage/cmd/itest.rst | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Reviewed-by: Simon Glass
Re: [PATCH 1/2] led: Implement software led blinking
Hi Mikhail, On Tue, 2 Jul 2024 at 12:54, Mikhail Kshevetskiy wrote: > > > On 27.06.2024 22:05, Simon Glass wrote: > > Hi Mikhail, > > > > On Thu, 27 Jun 2024 at 12:31, Mikhail Kshevetskiy > > wrote: > >> From: Michael Polyntsov > >> > >> If hardware (or driver) doesn't support leds blinking, it's > >> now possible to use software implementation of blinking instead. > >> This relies on cyclic functions. > >> > >> Signed-off-by: Michael Polyntsov > >> Signed-off-by: Mikhail Kshevetskiy > >> --- > >> drivers/led/Kconfig | 9 ++ > >> drivers/led/led-uclass.c | 190 ++- > >> 2 files changed, 195 insertions(+), 4 deletions(-) > >> > >> diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig > >> index 9837960198d..4330f014239 100644 > >> --- a/drivers/led/Kconfig > >> +++ b/drivers/led/Kconfig > >> @@ -73,6 +73,15 @@ config LED_BLINK > >> This option enables support for this which adds slightly to the > >> code size. > >> > >> +config LED_SW_BLINK > >> + bool "Support software LED blinking" > >> + depends on LED_BLINK > >> + select CYCLIC > >> + help > >> + Turns on led blinking implemented in the software, useful when > >> + the hardware doesn't support led blinking. Does nothing if > >> + driver supports blinking. > > Can you talk about the blinking p[eriod / API? > > Could you clarify what do you mean? I mean can you explain in this help [..] Regards, Simon
Please pull u-boot-dm/next
Hi Tom, This is for -next but we need to figure out the patch I just sent first. I can redo the pull if that patch is acceptable, or you can pick that up first. https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/21414 Note failure fixed by: https://patchwork.ozlabs.org/project/uboot/patch/20240702153739.2651815-1-...@chromium.org/ https://dev.azure.com/simon0972/u-boot/_build/results?buildId=64&view=results (same failure) The following changes since commit b4cbd1a257d4027038b4f997d73bdb0a066db045: Merge tag 'u-boot-amlogic-20240701' of https://source.denx.de/u-boot/custodians/u-boot-amlogic into next (2024-07-01 08:44:28 -0600) are available in the Git repository at: git://git.denx.de/u-boot-dm.git tags/dm-next-2jul24 for you to fetch changes up to 001af73bdc4cd975f087bfef6ccff30d6f510c83: bootstd: cros: store partition type in an efi_guid_t (2024-07-02 07:32:30 +0100) buildman CI improvements binman fixes and assumed size partial tools fixes for Python 3.12 patman enhancements Brandon Maier (3): tools: binman: fix deprecated Python unittest methods tools: binman: fix deprecated Python ConfigParser methods tools: patman: fix deprecated Python ConfigParser methods Heinrich Schuchardt (2): sandbox: use sane access rights for files acpi: set creator_revision in acpi_fill_header Ilias Apalodimas (2): sandbox: cleanup linker scripts and sections configs: enable setvariable at runtime on sandbox Jonathan Liu (1): sandbox: enable support for the unlz4 command Quentin Schulz (4): dm: core: fix misleading debug message when matching compatible dm: core: fix signedness in debug messages dm: core: migrate debug() messages to use dm_warn dm: core: fix typo in SPL_DM_WARN prompt text Rasmus Villemoes (1): global_data.h: drop write-only field dm_root_f Sean Anderson (3): patman: Fix tests if add_maintainers is set to False patman: Add Commit-cc as an alias for Patch-cc patman: Add a tag for when a patch gets added to a series Simon Glass (19): binman: efi: Correct entry docs binman: Regenerate nxp docs binman: ti: Regenerate entry docs binman: Update the entrydocs header binman: Support an assumed size for missing binaries binman: Make Intel ME default to position 0x1000 x86: Set up some assumed sizes for binary blobs buildman: Make mrproper an argument to _reconfigure() buildman: Make mrproper an argument to _config_and_build() buildman: Make mrproper an argument to run_commit() buildman: Avoid rebuilding when --mrproper is used buildman: Add a flag to force mrproper on failure buildman: Retry the build for current source buildman: Add a way to limit the number of buildmans buildman: Add python3-coverage buildman: Add python3-pycryptodome buildman: Fix a few typos in toolchain code buildman: Always use the full path in CROSS_COMPILE u_boot_pylib: Use correct coverage tool within venv Vincent Stehlé (1): bootstd: cros: store partition type in an efi_guid_t arch/sandbox/cpu/os.c | 6 +- arch/sandbox/cpu/u-boot.lds | 20 ++ arch/sandbox/lib/Makefile | 2 +- arch/sandbox/lib/sections.c | 13 arch/x86/dts/u-boot.dtsi | 5 ++ arch/x86/lib/acpi_table.c | 2 - boot/bootmeth_cros.c | 4 +- cmd/unlz4.c | 4 +- common/board_r.c | 3 +- configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + drivers/core/Kconfig | 2 +- drivers/core/device.c | 2 +- drivers/core/fdtaddr.c | 7 +- drivers/core/lists.c | 7 +- drivers/core/of_access.c | 51 +++--- drivers/core/of_addr.c | 41 ++-- drivers/core/of_extra.c | 33 +- drivers/core/ofnode.c | 81 --- drivers/core/regmap.c | 57 drivers/core/root.c | 14 ++-- drivers/core/uclass.c | 4 +- include/asm-generic/global_data.h | 4 -- lib/acpi/acpi_table.c | 2 +- lib/acpi/ssdt.c | 1 - test/dm/acpi.c | 3 +- test/dm/core.c | 1 - tools/binman/binman.rst | 7 ++ tools/binman/entries.rst | 115 tools/binman/entry.py | 3 +- tools/binman/entry_test.py | 6 +- tools/binman/etype/blob.py | 7 +- tools/binman/etype/efi_capsule.py | 40 +-- tools/binman/etype/efi_empty_capsule.py | 22 --- tools/binman/etype/intel_descriptor.py |
Re: [PATCH] gpt: allow spaces in partition list
Hi Mikhail, On Tue, 2 Jul 2024 at 10:42, Mikhail Kshevetskiy wrote: > > > On 27.06.2024 22:05, Simon Glass wrote: > > Hi Mikhail, > > > > On Thu, 27 Jun 2024 at 12:29, Mikhail Kshevetskiy > > wrote: > >> This allows spliting partition list to several lines in environment file > >> > >> ex: > >> > >> gpt_partition_list= > >> name=boot1,size=5MiB,start=0x10; > >> name=boot2,size=5MiB; > >> name=rootfs1,size=70MiB; > >> name=rootfs2,size=70MiB; > >> name=overlay1,size=20MiB; > >> name=overlay2,size=20MiB; > >> name=art,size=4MiB; > > Is this referring to a .env file, i.e. a text environment file? If so, > > I would hope that spaces at the start of a line would be automatically > > removed. > > This is refer to a .env file, so starting space/tabs will be removed, > all '\n' will be replaced by spaces. Thus we will get a single line where > each partition divided from other with a single space (like below) > > gpt_partition_list=name=boot1,size=5MiB,start=0x10; name=boot2,size=5MiB; > ... Reviewed-by: Simon Glass But I wonder if the \t is needed? > > >> Signed-off-by: Mikhail Kshevetskiy > >> --- > >> cmd/gpt.c | 2 ++ > >> 1 file changed, 2 insertions(+) > >> > >> diff --git a/cmd/gpt.c b/cmd/gpt.c > >> index 7aaf1889a5a..2b29ab98ccc 100644 > >> --- a/cmd/gpt.c > >> +++ b/cmd/gpt.c > >> @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char > >> *key) > >> k = strsep(&v, "="); > >> if (!k) > >> break; > >> + k += strspn(k, " \t"); > >> if (strcmp(k, key) == 0) { > >> new = strdup(v); > >> break; > >> @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key) > >> k = strsep(&s, ","); > >> if (!k) > >> break; > >> + k += strspn(k, " \t"); > >> if (strcmp(k, key) == 0) { > >> result = true; > >> break; > >> -- > >> 2.43.0 Regards, Simon
Warnings with xilinx_zynqmp_virt
Hi Michal, I am seeing errors when building xilinx_zynqmp_virt: Can't set hash 'value' property for 'hash' node(FDT_ERR_NOSPACE) Can't set hash value for 'hash' hash node in 'fdt_35' image node Can't add verification data for node 'fdt_35' () The problem is visible in CI, e.g. [1] A bisect points to this, but it might not be helpful: 46f04087712 (refs/bisect/bad) arm64: zynqmp: Add support for vck190 revB system controller Also the board seems to be the only one still using SPL_FIT_GENERATOR. The migration message was added almost 3 years ago. Would it be possible to move it to use Binman? = WARNING == This board uses CONFIG_SPL_FIT_GENERATOR. Please migrate to binman instead, to avoid the proliferation of arch-specific scripts with no tests. Regards, Simon [1] https://source.denx.de/u-boot/u-boot/-/jobs/861282
Re: [PATCH] sandbox: Fix LTO to work with STACKPROTECTOR
Hi Andrew, On Mon, 1 Jul 2024 at 16:01, Andrew Goodbody wrote: > > On 01/07/2024 14:57, Simon Glass wrote: > > Hi Andrew, > > > > On Mon, 24 Jun 2024 at 10:29, Andrew Goodbody > > wrote: > >> > >> Add the STACKPROTECTOR symbols to the script that generates the > >> symbols that should not be removed by the use of LTO when linking > >> a shared object. This prevents a fail to build due to link errors. > >> > >> https://source.denx.de/u-boot/u-boot/-/issues/35 > >> > >> Signed-off-by: Andrew Goodbody > >> --- > >> > >> scripts/gen_ll_addressable_symbols.sh | 2 ++ > >> 1 file changed, 2 insertions(+) > >> > >> diff --git a/scripts/gen_ll_addressable_symbols.sh > >> b/scripts/gen_ll_addressable_symbols.sh > >> index d0864804aa..ebf89b04bf 100755 > >> --- a/scripts/gen_ll_addressable_symbols.sh > >> +++ b/scripts/gen_ll_addressable_symbols.sh > >> @@ -13,3 +13,5 @@ set -e > >> echo '#include ' > >> $@ 2>/dev/null | grep -oe '_u_boot_list_2_[a-zA-Z0-9_]*_2_[a-zA-Z0-9_]*' > >> | \ > >> sort -u | sed -e 's/^\(.*\)/extern char > >> \1[];\n__ADDRESSABLE(\1);/' > >> +$@ 2>/dev/null | grep -oe '__stack_chk_.*' | \ > >> + sort -u | sed -e 's/^\(.*\)/extern char \1[];\n__ADDRESSABLE(\1);/' > >> -- > > > > It is OK to add these new ones, but here you seem to be adding lots of > > other things also. So far we are only allowing linker lists. So can > > you update this to allow just linker lists and stack_chk? Perhaps > > egrep (_u_boot_list_2_|__stack_chk_) or similar? > > > > Regards, > > Simon > > I am sorry but I do not follow you here. I am not sure what you mean by > 'linker lists'. The script is matching on symbols from object files as > output by nm. I have not changed that original match expression. > > My addition only adds the following 3 symbols to the output of > gen_ll_addressable_symbols.sh > > __stack_chk_guard > __stack_chk_fail > __stack_chk_fail_local > > These all come from the same file, common/stackprot.c > > I can reduce the match to just search for '__stack_chk_guard' and that > still works and I can put that as another expression in the grep instead > of doing the whole nm | grep | sort | sed thing a second time. Would > that address your concerns? Ah yes that would help, thank you, just running grep once. Regards, Simon
[PATCH] mx9: Correct repeatable build error
For some reason every second time imx93_11x11_evk is built it gives an error: make O=/tmp/x BINMAN_ALLOW_MISSING=1 It seems to sometimes skip generation of the .cfgout file and then eventually Binman complains: ValueError: Error 1 running 'mkimage -d ./mkimage.spl.mkimage -n spl/u-boot-spl.cfgout -T imx8image -e 0x2049A000 ./mkimage-out.spl.mkimage': Fail open first container file mx93a1-ahab-container.img Correct this by using if_changed instead of if_changed_dep The only reason this hasn't come up in CI is that buildman did not retry failing builds of current source, but now it does. Note: The logic in this Makefile should be moved to Binman, e.g. these warnings duplicate Binman functionality: WARNING 'bl31.bin' not found, resulting binary may be not-functional WARNING 'tee.bin' not found, resulting binary may be not-functional Signed-off-by: Simon Glass --- arch/arm/mach-imx/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index ef0caed3f7f..640e332e78b 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -227,7 +227,7 @@ flash.bin: MKIMAGEOUTPUT = flash.log spl/u-boot-spl.cfgout: $(IMX_CONFIG) FORCE $(Q)mkdir -p $(dir $@) - $(call if_changed_dep,cpp_cfg) + $(call if_changed_,cpp_cfg) $(call if_changed,imx9_check) spl/u-boot-spl-ddr.bin: spl/u-boot-spl.bin spl/u-boot-spl.cfgout FORCE -- 2.34.1
Re: [PATCH] usb: cdns3: continue probe even when USB PHY device does not exist
On 02/07/2024 16:36, Siddharth Vadapalli wrote: > On Tue, Jul 02, 2024 at 04:20:43PM +0300, Roger Quadros wrote: >> >> >> On 02/07/2024 15:07, Siddharth Vadapalli wrote: >>> Prior to commit cd295286c786 ("usb: cdns3: avoid error messages if phys >>> don't exist"), cdns3_probe() errors out only on failing to initialize the >>> USB2/USB3 PHY. However, since commit cd295286c786, absence of the PHY >>> device is also treated as an error, resulting in a regression. >>> >>> Extend commit cd295286c786 to treat -ENODEV as an acceptable return value >>> of generic_phy_get_by_name() and continue device probe as was the case >>> prior to the commit. >>> >>> Fixes: cd295286c786 ("usb: cdns3: avoid error messages if phys don't exist") >>> Signed-off-by: Siddharth Vadapalli >>> --- >>> >>> Hello, >>> >>> This patch is based on commit >>> b4cbd1a257 Merge tag 'u-boot-amlogic-20240701' of >>> https://source.denx.de/u-boot/custodians/u-boot-amlogic into next >>> of the next branch of U-Boot. >>> >>> Regards, >>> Siddharth. >>> >>> drivers/usb/cdns3/core.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c >>> index b4e931646b..5b3e32953e 100644 >>> --- a/drivers/usb/cdns3/core.c >>> +++ b/drivers/usb/cdns3/core.c >>> @@ -338,7 +338,7 @@ static int cdns3_probe(struct cdns3 *cdns) >>> dev_err(dev, "USB2 PHY init failed: %d\n", ret); >>> return ret; >>> } >>> - } else if (ret != -ENOENT && ret != -ENODATA) { >>> + } else if (ret != -ENOENT && ret != -ENODATA && ret != -ENODEV) { >> >> With this change we will not error out on a genuine error condition >> that produces ENODEV. > > It isn't necessarily a genuine error condition which is why it was a > "dev_warn" earlier for any error. If the previous stage has already Earlier it was clearly wrong to warn for everything. > configured the PHY, or if the PHY present in the device-tree in Linux is > not the same as the PHY being used at U-Boot (USB 2 PHY at U-Boot vs > SERDES in Linux), then it isn't an error. > >> >> If PHY phandle is not present the API should return ENOENT right? >> >> static int __of_parse_phandle_with_args(const struct device_node *np, >> >> /* Retrieve the phandle list property */ >> list = of_get_property(np, list_name, &size); >> if (!list) >> return -ENOENT; > > The PHY phandle is present, but it isn't the one being used by U-Boot. OK. commit cd295286c786 was only addressing the case if USB PHY node is not present (-ENOENT case). So there is no regression there right? > The device-tree could be pointing to SERDES as the PHY, since Linux uses > USB with SERDES. So the entry exists, but the error is -ENODEV rather > than -ENOENT. If the device tree contains the PHY then it should be initialized and any error initializing it is an error condition we cannot ignore. > >> >> Can you please check and point where the -ENODEV error is coming from? > > The sequence of function calls is as follows: > generic_phy_get_by_name > generic_phy_get_by_index > generic_phy_get_by_index_nodev > uclass_get_device_by_ofnode > uclass_find_device_by_ofnode > -ENODEV uclass_find_device_by_ofnode() ... ret = uclass_get(id, &uc); if (ret) return ret; uclass_foreach_dev(dev, uc) { log(LOGC_DM, LOGL_DEBUG_CONTENT, " - checking %s\n", dev->name); if (ofnode_equal(dev_ofnode(dev), node)) { *devp = dev; goto done; } } ret = -ENODEV; This means the class driver was not registered yet? Do you know why that might be the case? Was the SERDES PHY driver enabled? Are there any error there? > > In the above sequence, the device-tree contains SERDES PHY as the USB > PHY since Linux uses the same and U-Boot's device-tree is in sync with > Linux's. However, USB at U-Boot will use the USB 2 PHY. So one option is > to remove the SERDES PHY from USB node to have it fallback to USB 2 PHY. Ideally we would want u-boot to behave like Linux. If USB3 can be supported it should be made to work on u-boot as well. Any reason why USB3 cannot work on u-boot? > At the same time, if the previous stage has configured SERDES for example, > it might not be necessary to reconfigure SERDES. -ENODEV might be an > acceptable error in such a situation as well. Please let me know. Let's not assume error codes can be acceptable. There is patch on Linux to not re-initialize SERDES if it was already configured by previous stage. Maybe we could use something similar on u-boot? -- cheers, -roger
Re: [PATCH] Proposed changes to dynamic UUIDs v3
Hi Vincent, On 27/06/2024 11:55, Vincent Stehlé wrote: Here are the changes that I would like to suggest for the "efi: CapsuleUpdate: support for dynamic UUIDs" v3 patch series: - Convert from big-endian UUID to little-endian GUID in efi_capsule_update_info_gen_ids(). - Fix tmp size and masking in gen_uuid_v5(). - Use UUID_STR_FORMAT_STD in all places where we are dealing with a big-endian UUID. - Update all GUIDs constants in the code and in the tests accordingly. This gets rid of the following broken UUIDs: 5af91295-5a99-f62b-80d7-e9574de87170 8ee418dc-7e00-e156-80a7-274fbbc05ba8 935fe837-fac8-4394-c008-737d8852c60d fd5db83c-12f3-a46b-80a9-e3007c7ff56e ffd97379-0956-fa94-c003-8bfcf5cc097b - Also, a few minor modifications here and there. Thanks, this was really helpful for prepping v4. I decided to go with a slightly different approach and just make the the v5 generator produce a little endian GUID rather than a BE UUID. V4 is here: https://lore.kernel.org/u-boot/20240702-b4-dynamic-uuid-v4-0-a00c82d1f...@linaro.org Kind regards, Signed-off-by: Vincent Stehlé Cc: Caleb Connolly Cc: Tom Rini Cc: Heinrich Schuchardt Cc: Ilias Apalodimas Cc: Simon Glass Cc: Mario Six Cc: Alper Nebi Yasak Cc: Abdellatif El Khlifi Cc: Richard Hughes --- include/sandbox_efi_capsule.h | 6 +++--- lib/efi_loader/efi_firmware.c | 14 +++--- lib/uuid.c | 8 test/lib/uuid.c| 12 ++-- .../test_efi_capsule/test_capsule_firmware_fit.py | 4 ++-- .../test_efi_capsule/test_capsule_firmware_raw.py | 8 .../test_capsule_firmware_signed_fit.py| 2 +- .../test_capsule_firmware_signed_raw.py| 4 ++-- test/py/tests/test_efi_capsule/version.dts | 6 +++--- tools/.gitignore | 1 + tools/binman/etype/efi_capsule.py | 2 +- tools/binman/ftest.py | 2 +- tools/genguid.c| 7 +++ 13 files changed, 42 insertions(+), 34 deletions(-) diff --git a/include/sandbox_efi_capsule.h b/include/sandbox_efi_capsule.h index 25ac496ea24..6f0de5a1e25 100644 --- a/include/sandbox_efi_capsule.h +++ b/include/sandbox_efi_capsule.h @@ -6,9 +6,9 @@ #if !defined(_SANDBOX_EFI_CAPSULE_H_) #define _SANDBOX_EFI_CAPSULE_H_ -#define SANDBOX_UBOOT_IMAGE_GUID "fd5db83c-12f3-a46b-80a9-e3007c7ff56e" -#define SANDBOX_UBOOT_ENV_IMAGE_GUID "935fe837-fac8-4394-c008-737d8852c60d" -#define SANDBOX_FIT_IMAGE_GUID "ffd97379-0956-fa94-c003-8bfcf5cc097b" +#define SANDBOX_UBOOT_IMAGE_GUID "50980990-5af9-5522-86e2-8f05f4d7313c" +#define SANDBOX_UBOOT_ENV_IMAGE_GUID "3554b655-b9f0-5240-ace2-6f34c2f7fcca" +#define SANDBOX_FIT_IMAGE_GUID "8b38adc7-df0c-5769-8b89-c090ca3d07a7" #define SANDBOX_INCORRECT_GUID "058b7d83-50d5-4c47-a195-60d86ad341c4" #define UBOOT_FIT_IMAGE "u-boot_bin_env.itb" diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index a8dafe4f01a..f0d0c3fa972 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -258,7 +258,7 @@ void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_ static efi_status_t efi_capsule_update_info_gen_ids(void) { int ret, i; - struct uuid namespace; + struct uuid namespace, type; const char *compatible; /* Full array including null bytes */ struct efi_fw_image *fw_array; @@ -269,7 +269,7 @@ static efi_status_t efi_capsule_update_info_gen_ids(void) return EFI_SUCCESS; ret = uuid_str_to_bin(CONFIG_EFI_CAPSULE_NAMESPACE_UUID, - (unsigned char *)&namespace, UUID_STR_FORMAT_GUID); + (unsigned char *)&namespace, UUID_STR_FORMAT_STD); if (ret) { log_debug("%s: CONFIG_EFI_CAPSULE_NAMESPACE_UUID is invalid: %d\n", __func__, ret); return EFI_UNSUPPORTED; @@ -289,12 +289,20 @@ static efi_status_t efi_capsule_update_info_gen_ids(void) for (i = 0; i < update_info.num_images; i++) { gen_uuid_v5(&namespace, - (struct uuid *)&fw_array[i].image_type_id, + &type, compatible, strlen(compatible), fw_array[i].fw_name, u16_strsize(fw_array[i].fw_name) - sizeof(uint16_t), NULL); + /* Convert to little-endian GUID. */ + fw_array[i].image_type_id = (efi_guid_t)EFI_GUID( + be32_to_cpu(type.time_low), be16_to_cpu(type.time_mid), +
Re: [PATCH] usb: cdns3: continue probe even when USB PHY device does not exist
On Tue, Jul 02, 2024 at 04:20:43PM +0300, Roger Quadros wrote: > > > On 02/07/2024 15:07, Siddharth Vadapalli wrote: > > Prior to commit cd295286c786 ("usb: cdns3: avoid error messages if phys > > don't exist"), cdns3_probe() errors out only on failing to initialize the > > USB2/USB3 PHY. However, since commit cd295286c786, absence of the PHY > > device is also treated as an error, resulting in a regression. > > > > Extend commit cd295286c786 to treat -ENODEV as an acceptable return value > > of generic_phy_get_by_name() and continue device probe as was the case > > prior to the commit. > > > > Fixes: cd295286c786 ("usb: cdns3: avoid error messages if phys don't exist") > > Signed-off-by: Siddharth Vadapalli > > --- > > > > Hello, > > > > This patch is based on commit > > b4cbd1a257 Merge tag 'u-boot-amlogic-20240701' of > > https://source.denx.de/u-boot/custodians/u-boot-amlogic into next > > of the next branch of U-Boot. > > > > Regards, > > Siddharth. > > > > drivers/usb/cdns3/core.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c > > index b4e931646b..5b3e32953e 100644 > > --- a/drivers/usb/cdns3/core.c > > +++ b/drivers/usb/cdns3/core.c > > @@ -338,7 +338,7 @@ static int cdns3_probe(struct cdns3 *cdns) > > dev_err(dev, "USB2 PHY init failed: %d\n", ret); > > return ret; > > } > > - } else if (ret != -ENOENT && ret != -ENODATA) { > > + } else if (ret != -ENOENT && ret != -ENODATA && ret != -ENODEV) { > > With this change we will not error out on a genuine error condition > that produces ENODEV. It isn't necessarily a genuine error condition which is why it was a "dev_warn" earlier for any error. If the previous stage has already configured the PHY, or if the PHY present in the device-tree in Linux is not the same as the PHY being used at U-Boot (USB 2 PHY at U-Boot vs SERDES in Linux), then it isn't an error. > > If PHY phandle is not present the API should return ENOENT right? > > static int __of_parse_phandle_with_args(const struct device_node *np, > > /* Retrieve the phandle list property */ > list = of_get_property(np, list_name, &size); > if (!list) > return -ENOENT; The PHY phandle is present, but it isn't the one being used by U-Boot. The device-tree could be pointing to SERDES as the PHY, since Linux uses USB with SERDES. So the entry exists, but the error is -ENODEV rather than -ENOENT. > > Can you please check and point where the -ENODEV error is coming from? The sequence of function calls is as follows: generic_phy_get_by_name generic_phy_get_by_index generic_phy_get_by_index_nodev uclass_get_device_by_ofnode uclass_find_device_by_ofnode -ENODEV In the above sequence, the device-tree contains SERDES PHY as the USB PHY since Linux uses the same and U-Boot's device-tree is in sync with Linux's. However, USB at U-Boot will use the USB 2 PHY. So one option is to remove the SERDES PHY from USB node to have it fallback to USB 2 PHY. At the same time, if the previous stage has configured SERDES for example, it might not be necessary to reconfigure SERDES. -ENODEV might be an acceptable error in such a situation as well. Please let me know. [...] Regards, Siddharth.
[PATCH v4 10/10] test: lib/uuid: add unit tests for dynamic UUIDs
Add some basic unit tests to validate that the UUID generation behaves as expected. This matches the implementation in efi_loader for sandbox and a Qualcomm board and should catch any regressions. Signed-off-by: Caleb Connolly --- test/lib/uuid.c | 82 + 1 file changed, 82 insertions(+) diff --git a/test/lib/uuid.c b/test/lib/uuid.c index 9629d378c329..2c6cfd42ddc3 100644 --- a/test/lib/uuid.c +++ b/test/lib/uuid.c @@ -7,15 +7,20 @@ * Authors: * Abdellatif El Khlifi */ +#include #include #include #include #include +#include + /* test UUID */ #define TEST_SVC_UUID "ed32d533-4209-99e6-2d72-cdd998a79cc0" +/* U-Boot default fw image namespace */ +#define DEFAULT_FW_IMAGE_NAMESPACE "8c9f137e-91dc-427b-b2d6-b420faebaf2a" #define UUID_SIZE 16 /* The UUID binary data (little-endian format) */ @@ -37,4 +42,81 @@ static int lib_test_uuid_to_le(struct unit_test_state *uts) return 0; } LIB_TEST(lib_test_uuid_to_le, 0); + +struct dynamic_uuid_test_data { + const char *compatible; + const u16 *images[4]; + const char *expected_uuids[4]; +}; + +static int lib_test_dynamic_uuid_case(struct unit_test_state *uts, + const struct dynamic_uuid_test_data *data) +{ + struct uuid namespace; + int j; + + ut_assertok(uuid_str_to_bin(DEFAULT_FW_IMAGE_NAMESPACE, (unsigned char *)&namespace, + UUID_STR_FORMAT_GUID)); + + for (j = 0; data->images[j]; j++) { + const char *expected_uuid = data->expected_uuids[j]; + const u16 *image = data->images[j]; + efi_guid_t uuid; + char uuid_str[37]; + + gen_v5_guid(&namespace, &uuid, + data->compatible, strlen(data->compatible), + image, u16_strlen(image) * sizeof(uint16_t), + NULL); + uuid_bin_to_str((unsigned char *)&uuid, uuid_str, UUID_STR_FORMAT_GUID); + + ut_asserteq_str(expected_uuid, uuid_str); + } + + return 0; +} + +static int lib_test_dynamic_uuid(struct unit_test_state *uts) +{ + int ret, i; + const struct dynamic_uuid_test_data test_data[] = { + { + .compatible = "sandbox", + .images = { + u"SANDBOX-UBOOT", + u"SANDBOX-UBOOT-ENV", + u"SANDBOX-FIT", + NULL, + }, + .expected_uuids = { + "985f2937-7c2e-5e9a-8a5e-8e063312964b", + "9e339473-c2eb-530a-a69b-0cd6bbbed40e", + "46610520-469e-59dc-a8dd-c11832b877ea", + NULL, + } + }, + { + .compatible = "qcom,qrb4210-rb2", + .images = { + u"QUALCOMM-UBOOT", + NULL, + }, + .expected_uuids = { + "d5021fac-8dd0-5ed7-90c2-763c304aaf86", + NULL, + } + }, + }; + + for (i = 0; i < ARRAY_SIZE(test_data); i++) { + ret = lib_test_dynamic_uuid_case(uts, &test_data[i]); + if (ret) + return ret; + } + + return 0; +} + +LIB_TEST(lib_test_dynamic_uuid, 0); + -- 2.45.2
[PATCH v4 09/10] tools: mkeficapsule: support generating dynamic GUIDs
Add a tool that can generate GUIDs that match those generated internally by U-Boot for capsule update fw_images. Dynamic UUIDs in U-Boot work by taking a namespace UUID and hashing it with the board compatible and fw_image name. This tool accepts the same inputs and will produce the same GUID as U-Boot would at runtime. Signed-off-by: Caleb Connolly --- doc/mkeficapsule.1 | 23 tools/Makefile | 3 + tools/mkeficapsule.c | 157 +-- 3 files changed, 178 insertions(+), 5 deletions(-) diff --git a/doc/mkeficapsule.1 b/doc/mkeficapsule.1 index c4c2057d5c7a..bf735295effa 100644 --- a/doc/mkeficapsule.1 +++ b/doc/mkeficapsule.1 @@ -9,8 +9,11 @@ mkeficapsule \- Generate EFI capsule file for U-Boot .SH SYNOPSIS .B mkeficapsule .RI [ options ] " " [ image-blob ] " " capsule-file +.B mkeficapsule +.RI guidgen " " [ GUID ] " " DTB " " IMAGE_NAME... + .SH "DESCRIPTION" The .B mkeficapsule command is used to create an EFI capsule file to be used by U-Boot for firmware @@ -41,8 +44,12 @@ format is the same as used in the new uImage format and allows for multiple binary blobs in a single capsule file. This type of image file can be generated by .BR mkimage . +mkeficapsule can also be used to simulate the dynamic GUID generation used to +identify firmware images in capsule updates by providing the namespace guid, dtb +for the board, and a list of firmware images. + .SH "OPTIONS" .TP .BI "-g\fR,\fB --guid " guid-string @@ -112,8 +119,24 @@ at every firmware update. .TP .B "-d\fR,\fB --dump_sig" Dump signature data into *.p7 file +.SH "GUIDGEN OPTIONS" + +.TP +.B "[GUID]" +The namespace/salt GUID, by default this is EFI_CAPSULE_NAMESPACE_GUID. +The format is: +---- + +.TP +.B DTB +The device tree blob file for the board. + +.TP +.B IMAGE_NAME... +The names of the firmware images to generate GUIDs for. + .PP .SH FILES .TP .I /EFI/UpdateCapsule diff --git a/tools/Makefile b/tools/Makefile index ee08a9675df8..7d1b29943471 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -253,8 +253,11 @@ mkeficapsule-objs := generated/lib/uuid.o \ $(LIBFDT_OBJS) \ mkeficapsule.o hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule +genguid-objs := generated/lib/uuid.o generated/lib/sha1.o genguid.o +hostprogs-$(CONFIG_TOOLS_GENGUID) += genguid + mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o HOSTLDLIBS_mkfwumdata += -luuid hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c index 54fb4dee3ee5..593380e4236a 100644 --- a/tools/mkeficapsule.c +++ b/tools/mkeficapsule.c @@ -19,12 +19,16 @@ #include #include #include +#include #include #include "eficapsule.h" +// Matches CONFIG_EFI_CAPSULE_NAMESPACE_GUID +#define DEFAULT_NAMESPACE_GUID "8c9f137e-91dc-427b-b2d6-b420faebaf2a" + static const char *tool_name = "mkeficapsule"; efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID; efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID; @@ -38,8 +42,9 @@ enum { } capsule_type; static struct option options[] = { {"guid", required_argument, NULL, 'g'}, + {"dtb", required_argument, NULL, 'd'}, {"index", required_argument, NULL, 'i'}, {"instance", required_argument, NULL, 'I'}, {"fw-version", required_argument, NULL, 'v'}, {"private-key", required_argument, NULL, 'p'}, @@ -53,11 +58,23 @@ static struct option options[] = { {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}, }; -static void print_usage(void) + +static void print_usage_guidgen(void) { - fprintf(stderr, "Usage: %s [options] \n" + fprintf(stderr, "%s guidgen [GUID] DTB IMAGE_NAME...\n" + "Options:\n" + + "\tGUIDNamespace GUID (default: %s)\n" + "\tDTB Device Tree Blob\n" + "\tIMAGE_NAME... One or more names of fw_images to generate GUIDs for\n", + tool_name, DEFAULT_NAMESPACE_GUID); +} + +static void print_usage_mkeficapsule(void) +{ + fprintf(stderr, "Usage: \n\n%s [options] \n" "Options:\n" "\t-g, --guid guid for image blob type\n" "\t-i, --index update image index\n" @@ -70,10 +87,11 @@ static void print_usage(void) "\t-A, --fw-accept firmware accept capsule, requires GUID, no image blob\n" "\t-R, --fw-revert firmware revert capsule, takes no GUID, no image blob\n" "\t-o, --capoemflag Capsule OEM Flag, an integer between 0x and 0x\n" "\t-D, --dump-capsule dump the contents of the capsule headers\n" - "\t-h, --help print a help message\n", + "\t-h, --help print a help message\n\n",
[PATCH v4 08/10] tools: mkeficapsule: use u-boot UUID library
Replace the use of libuuid with U-Boot's own UUID library. This prepares us to add support for generating v5 GUIDs. Signed-off-by: Caleb Connolly --- tools/Makefile | 8 tools/mkeficapsule.c | 53 ++-- 2 files changed, 10 insertions(+), 51 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index 6a4280e3668f..ee08a9675df8 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -245,14 +245,14 @@ hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include HOSTCFLAGS_mkeficapsule.o += \ $(shell pkg-config --cflags gnutls 2> /dev/null || echo "") -HOSTCFLAGS_mkeficapsule.o += \ - $(shell pkg-config --cflags uuid 2> /dev/null || echo "") HOSTLDLIBS_mkeficapsule += \ $(shell pkg-config --libs gnutls 2> /dev/null || echo "-lgnutls") -HOSTLDLIBS_mkeficapsule += \ - $(shell pkg-config --libs uuid 2> /dev/null || echo "-luuid") +mkeficapsule-objs := generated/lib/uuid.o \ + generated/lib/sha1.o \ + $(LIBFDT_OBJS) \ + mkeficapsule.o hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o HOSTLDLIBS_mkfwumdata += -luuid diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c index 6a261ff549dc..54fb4dee3ee5 100644 --- a/tools/mkeficapsule.c +++ b/tools/mkeficapsule.c @@ -14,14 +14,15 @@ #include #include #include -#include #include #include #include +#include + #include "eficapsule.h" static const char *tool_name = "mkeficapsule"; @@ -573,39 +574,8 @@ err: return ret; } -/** - * convert_uuid_to_guid() - convert UUID to GUID - * @buf: UUID binary - * - * UUID and GUID have the same data structure, but their binary - * formats are different due to the endianness. See lib/uuid.c. - * Since uuid_parse() can handle only UUID, this function must - * be called to get correct data for GUID when parsing a string. - * - * The correct data will be returned in @buf. - */ -void convert_uuid_to_guid(unsigned char *buf) -{ - unsigned char c; - - c = buf[0]; - buf[0] = buf[3]; - buf[3] = c; - c = buf[1]; - buf[1] = buf[2]; - buf[2] = c; - - c = buf[4]; - buf[4] = buf[5]; - buf[5] = c; - - c = buf[6]; - buf[6] = buf[7]; - buf[7] = c; -} - static int create_empty_capsule(char *path, efi_guid_t *guid, bool fw_accept) { struct efi_capsule_header header = { 0 }; FILE *f = NULL; @@ -649,22 +619,12 @@ err: } static void print_guid(void *ptr) { - int i; - efi_guid_t *guid = ptr; - const uint8_t seq[] = { - 3, 2, 1, 0, '-', 5, 4, '-', 7, 6, - '-', 8, 9, '-', 10, 11, 12, 13, 14, 15 }; + static char buf[37] = { 0 }; - for (i = 0; i < ARRAY_SIZE(seq); i++) { - if (seq[i] == '-') - putchar(seq[i]); - else - printf("%02X", guid->b[seq[i]]); - } - - printf("\n"); + uuid_bin_to_str(ptr, buf, UUID_STR_FORMAT_GUID|UUID_STR_UPPER_CASE); + printf("%s\n", buf); } static uint32_t dump_fmp_payload_header( struct fmp_payload_header *fmp_payload_hdr) @@ -902,13 +862,12 @@ int main(int argc, char **argv) fprintf(stderr, "Image type already specified\n"); exit(EXIT_FAILURE); } - if (uuid_parse(optarg, uuid_buf)) { + if (uuid_str_to_bin(optarg, uuid_buf, UUID_STR_FORMAT_GUID)) { fprintf(stderr, "Wrong guid format\n"); exit(EXIT_FAILURE); } - convert_uuid_to_guid(uuid_buf); guid = (efi_guid_t *)uuid_buf; break; case 'i': index = strtoul(optarg, NULL, 0); -- 2.45.2
[PATCH v4 07/10] include: export uuid.h
Move this header to include/u-boot/ so that it can be used by external tools. Signed-off-by: Caleb Connolly --- arch/arm/mach-rockchip/board.c | 2 +- board/cobra5272/flash.c| 2 +- board/gardena/smart-gateway-mt7688/board.c | 2 +- board/socrates/socrates.c | 2 +- board/xilinx/common/board.c| 2 +- cmd/efi.c | 2 +- cmd/efi_common.c | 2 +- cmd/flash.c| 2 +- cmd/gpt.c | 2 +- cmd/nvedit_efi.c | 2 +- cmd/x86/hob.c | 2 +- common/flash.c | 2 +- disk/part_efi.c| 2 +- drivers/firmware/arm-ffa/arm-ffa-uclass.c | 2 +- env/sf.c | 2 +- fs/btrfs/btrfs.c | 2 +- fs/btrfs/compat.h | 2 +- fs/btrfs/disk-io.c | 2 +- fs/ext4/ext4fs.c | 2 +- include/fwu.h | 2 +- include/part.h | 2 +- include/rkmtd.h| 2 +- include/{ => u-boot}/uuid.h| 0 lib/acpi/acpi_dp.c | 2 +- lib/acpi/acpigen.c | 2 +- lib/efi/efi_app.c | 2 +- lib/efi_loader/efi_capsule.c | 2 +- lib/efi_loader/efi_device_path.c | 2 +- lib/efi_loader/efi_variable.c | 2 +- lib/fwu_updates/fwu_mtd.c | 2 +- lib/uuid.c | 2 +- lib/vsprintf.c | 2 +- net/bootp.c| 2 +- test/dm/acpi_dp.c | 2 +- test/dm/acpigen.c | 2 +- test/lib/uuid.c| 2 +- 36 files changed, 35 insertions(+), 35 deletions(-) diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c index 8a57b8217ff2..0fdf9365b41e 100644 --- a/arch/arm/mach-rockchip/board.c +++ b/arch/arm/mach-rockchip/board.c @@ -24,9 +24,9 @@ #include #include #include #include -#include +#include #include #include #include #include diff --git a/board/cobra5272/flash.c b/board/cobra5272/flash.c index 157b71da85e8..0c1b1c7decd8 100644 --- a/board/cobra5272/flash.c +++ b/board/cobra5272/flash.c @@ -10,9 +10,9 @@ #include #include #include #include -#include +#include #include #include #include diff --git a/board/gardena/smart-gateway-mt7688/board.c b/board/gardena/smart-gateway-mt7688/board.c index c6b14bed41fb..eb7fcd630a10 100644 --- a/board/gardena/smart-gateway-mt7688/board.c +++ b/board/gardena/smart-gateway-mt7688/board.c @@ -15,9 +15,9 @@ #include #include #include #include -#include +#include #include #include #define MT76XX_AGPIO_CFG 0x103c diff --git a/board/socrates/socrates.c b/board/socrates/socrates.c index 6e6e276cc741..5e5a45ee00db 100644 --- a/board/socrates/socrates.c +++ b/board/socrates/socrates.c @@ -14,9 +14,9 @@ #include #include #include #include -#include +#include #include #include #include #include diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index 30a81376ac41..e11141b94260 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -30,9 +30,9 @@ #include #include #include #include -#include +#include #include "fru.h" #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) diff --git a/cmd/efi.c b/cmd/efi.c index 6bed2d743ba6..687ccb520428 100644 --- a/cmd/efi.c +++ b/cmd/efi.c @@ -10,9 +10,9 @@ #include #include #include #include -#include +#include #include DECLARE_GLOBAL_DATA_PTR; diff --git a/cmd/efi_common.c b/cmd/efi_common.c index c46764e6eea7..d2f2b59e9e3b 100644 --- a/cmd/efi_common.c +++ b/cmd/efi_common.c @@ -7,9 +7,9 @@ */ #include #include -#include +#include void efi_show_tables(struct efi_system_table *systab) { int i; diff --git a/cmd/flash.c b/cmd/flash.c index de0e04f09cfb..fd660ec477c9 100644 --- a/cmd/flash.c +++ b/cmd/flash.c @@ -9,9 +9,9 @@ */ #include #include #include -#include +#include #if defined(CONFIG_CMD_MTDPARTS) #include diff --git a/cmd/gpt.c b/cmd/gpt.c index 36b112d59784..be040d7f94a6 100644 --- a/cmd/gpt.c +++ b/cmd/gpt.c @@ -18,9 +18,9 @@ #include #include #include #include -#include +#include #include #include #include #include diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index 64ae2ad2ce24..32b7d0490747 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -14,9 +14,9 @@ #include #include #include #include -#include +#include #include /* * From efi_variable.c, diff --git a/cmd/x86/hob.c b/cmd/x86/hob.c index 2dd30808bd10..d3713cef3312 100644 --- a/cmd/x86/hob.c +++ b/cmd/x86/hob.c @@ -4
[PATCH v4 06/10] lib: uuid: supporting building as part of host tools
Adjust the UUID library code so that it can be compiled as part of a host tool. This removes the one redundant log_debug() call, as well as the incorrectly defined LOG_CATEGORY. In general this is a fairly trivial change, just adjusting includes and disabling list_guid. This will be used by a new genguid tool to generate v5 GUIDs that match those generated by U-Boot at runtime. Signed-off-by: Caleb Connolly --- include/uuid.h | 4 ++-- lib/uuid.c | 44 ++-- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/include/uuid.h b/include/uuid.h index 1f4fa103b5e9..7f8414dc906c 100644 --- a/include/uuid.h +++ b/include/uuid.h @@ -69,10 +69,10 @@ struct uuid { } __packed; /* Bits of a bitmask specifying the output format for GUIDs */ #define UUID_STR_FORMAT_STD0 -#define UUID_STR_FORMAT_GUID BIT(0) -#define UUID_STR_UPPER_CASEBIT(1) +#define UUID_STR_FORMAT_GUID 0x1 +#define UUID_STR_UPPER_CASE0x2 /* Use UUID_STR_LEN + 1 for string space */ #define UUID_STR_LEN 36 #define UUID_BIN_LEN sizeof(struct uuid) diff --git a/lib/uuid.c b/lib/uuid.c index 7d0a8273d157..272e07dc1613 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -6,25 +6,38 @@ * Authors: * Abdellatif El Khlifi */ -#define LOG_CATEGOT LOGC_CORE - +#ifndef USE_HOSTCC #include #include #include #include #include -#include -#include -#include #include #include #include #include #include +#include +#include +#else +#include +#include +#include +#include +#endif +#include +#include +#include +#include #include +#ifdef USE_HOSTCC +/* polyfill hextoul to avoid pulling in strto.c */ +#define hextoul(cp, endp) strtoul(cp, endp, 16) +#endif + int uuid_str_valid(const char *uuid) { int i, valid; @@ -51,8 +64,9 @@ int uuid_str_valid(const char *uuid) static const struct { const char *string; efi_guid_t guid; } list_guid[] = { +#ifndef USE_HOSTCC #ifdef CONFIG_PARTITION_TYPE_GUID {"system", PARTITION_SYSTEM_GUID}, {"mbr", LEGACY_MBR_PARTITION_GUID}, {"msft",PARTITION_MSFT_RESERVED_GUID}, @@ -231,8 +245,9 @@ static const struct { { "EFI_MEMORY_TYPE", EFI_MEMORY_TYPE }, { "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC }, { "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 }, #endif +#endif /* !USE_HOSTCC */ }; int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin) { @@ -266,9 +281,8 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, uint32_t tmp32; uint64_t tmp64; if (!uuid_str_valid(uuid_str)) { - log_debug("not valid\n"); #ifdef CONFIG_PARTITION_TYPE_GUID if (!uuid_guid_get_bin(uuid_str, uuid_bin)) return 0; #endif @@ -297,19 +311,19 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, tmp16 = cpu_to_be16(hextoul(uuid_str + 19, NULL)); memcpy(uuid_bin + 8, &tmp16, 2); - tmp64 = cpu_to_be64(simple_strtoull(uuid_str + 24, NULL, 16)); + tmp64 = cpu_to_be64(hextoul(uuid_str + 24, NULL)); memcpy(uuid_bin + 10, (char *)&tmp64 + 2, 6); return 0; } int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin) { - u16 tmp16; - u32 tmp32; - u64 tmp64; + uint16_t tmp16; + uint32_t tmp32; + uint64_t tmp64; if (!uuid_str_valid(uuid_str) || !uuid_bin) return -EINVAL; @@ -324,22 +338,22 @@ int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin) tmp16 = cpu_to_le16(hextoul(uuid_str + 19, NULL)); memcpy(uuid_bin + 8, &tmp16, 2); - tmp64 = cpu_to_le64(simple_strtoull(uuid_str + 24, NULL, 16)); + tmp64 = cpu_to_le64(hextoul(uuid_str + 24, NULL)); memcpy(uuid_bin + 10, &tmp64, 6); return 0; } void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str, int str_format) { - const u8 uuid_char_order[UUID_BIN_LEN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, + const uint8_t uuid_char_order[UUID_BIN_LEN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; - const u8 guid_char_order[UUID_BIN_LEN] = {3, 2, 1, 0, 5, 4, 7, 6, 8, + const uint8_t guid_char_order[UUID_BIN_LEN] = {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15}; - const u8 *char_order; + const uint8_t *char_order; const char *format; int i; /* @@ -418,8 +432,9 @@ void gen_v5_guid(const struct uuid *namespace, struct efi_guid *guid, ...) tmp16 = (uint16_t *)&guid->b[6]; *tmp16 = be16_to_cpu(*tmp16); } +#ifndef USE_HOSTCC #if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID) void gen_rand_uuid(unsigned char *uuid_bin) { u32 ptr[4]; @@ -501,
[PATCH v4 05/10] sandbox: switch to dynamic UUIDs
Migrate sandbox over to generating it's capsule update image GUIDs dynamically from the namespace and board/image info. Update the reference and tests to use the new GUIDs. Signed-off-by: Caleb Connolly --- board/sandbox/sandbox.c | 16 include/sandbox_efi_capsule.h| 6 +++--- .../tests/test_efi_capsule/test_capsule_firmware_fit.py | 2 +- .../tests/test_efi_capsule/test_capsule_firmware_raw.py | 8 .../test_efi_capsule/test_capsule_firmware_signed_fit.py | 2 +- .../test_efi_capsule/test_capsule_firmware_signed_raw.py | 4 ++-- test/py/tests/test_efi_capsule/version.dts | 6 +++--- tools/binman/etype/efi_capsule.py| 2 +- tools/binman/ftest.py| 2 +- 9 files changed, 16 insertions(+), 32 deletions(-) diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c index 802596569c64..d97945e58fcf 100644 --- a/board/sandbox/sandbox.c +++ b/board/sandbox/sandbox.c @@ -31,36 +31,20 @@ */ gd_t *gd; #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) -/* GUIDs for capsule updatable firmware images */ -#define SANDBOX_UBOOT_IMAGE_GUID \ - EFI_GUID(0x09d7cf52, 0x0720, 0x4710, 0x91, 0xd1, \ -0x08, 0x46, 0x9b, 0x7f, 0xe9, 0xc8) - -#define SANDBOX_UBOOT_ENV_IMAGE_GUID \ - EFI_GUID(0x5a7021f5, 0xfef2, 0x48b4, 0xaa, 0xba, \ -0x83, 0x2e, 0x77, 0x74, 0x18, 0xc0) - -#define SANDBOX_FIT_IMAGE_GUID \ - EFI_GUID(0x3673b45d, 0x6a7c, 0x46f3, 0x9e, 0x60, \ -0xad, 0xab, 0xb0, 0x3f, 0x79, 0x37) - struct efi_fw_image fw_images[] = { #if defined(CONFIG_EFI_CAPSULE_FIRMWARE_RAW) { - .image_type_id = SANDBOX_UBOOT_IMAGE_GUID, .fw_name = u"SANDBOX-UBOOT", .image_index = 1, }, { - .image_type_id = SANDBOX_UBOOT_ENV_IMAGE_GUID, .fw_name = u"SANDBOX-UBOOT-ENV", .image_index = 2, }, #elif defined(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) { - .image_type_id = SANDBOX_FIT_IMAGE_GUID, .fw_name = u"SANDBOX-FIT", .image_index = 1, }, #endif diff --git a/include/sandbox_efi_capsule.h b/include/sandbox_efi_capsule.h index 3e288e8a84a2..84d45ec5cfd5 100644 --- a/include/sandbox_efi_capsule.h +++ b/include/sandbox_efi_capsule.h @@ -5,11 +5,11 @@ #if !defined(_SANDBOX_EFI_CAPSULE_H_) #define _SANDBOX_EFI_CAPSULE_H_ -#define SANDBOX_UBOOT_IMAGE_GUID "09d7cf52-0720-4710-91d1-08469b7fe9c8" -#define SANDBOX_UBOOT_ENV_IMAGE_GUID "5a7021f5-fef2-48b4-aaba-832e777418c0" -#define SANDBOX_FIT_IMAGE_GUID "3673b45d-6a7c-46f3-9e60-adabb03f7937" +#define SANDBOX_UBOOT_IMAGE_GUID "985f2937-7c2e-5e9a-8a5e-8e063312964b" +#define SANDBOX_UBOOT_ENV_IMAGE_GUID "9e339473-c2eb-530a-a69b-0cd6bbbed40e" +#define SANDBOX_FIT_IMAGE_GUID "46610520-469e-59dc-a8dd-c11832b877ea" #define SANDBOX_INCORRECT_GUID "058b7d83-50d5-4c47-a195-60d86ad341c4" #define UBOOT_FIT_IMAGE"u-boot_bin_env.itb" diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py index 11bcdc2bb293..a726c71c1138 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py @@ -146,9 +146,9 @@ class TestEfiCapsuleFirmwareFit(): verify_content(u_boot_console, '10', 'u-boot:Old') verify_content(u_boot_console, '15', 'u-boot-env:Old') else: # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT. -assert '3673B45D-6A7C-46F3-9E60-ADABB03F7937' in ''.join(output) +assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output) assert 'ESRT: fw_version=5' in ''.join(output) assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output) verify_content(u_boot_console, '10', 'u-boot:New') diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py index a5b5c8a3853a..ca51a279763f 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py @@ -133,12 +133,12 @@ class TestEfiCapsuleFirmwareRaw: 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x10 0x5;u-boot-env raw 0x15 0x20"', 'efidebug capsule esrt']) # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT. -assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output) +assert '9E339473-C2EB-530A-A69B-0CD6BBBED40E' in ''.join(output) # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT. -assert '09D
[PATCH v4 04/10] doc: uefi: document dynamic UUID generation
Document how platforms can generate GUIDs at runtime rather than maintaining a list of UUIDs per-board. Reviewed-by: Ilias Apalodimas Signed-off-by: Caleb Connolly --- doc/develop/uefi/uefi.rst | 27 +++ 1 file changed, 27 insertions(+) diff --git a/doc/develop/uefi/uefi.rst b/doc/develop/uefi/uefi.rst index 0389b269c01b..19931af9ced7 100644 --- a/doc/develop/uefi/uefi.rst +++ b/doc/develop/uefi/uefi.rst @@ -448,8 +448,35 @@ the location of the firmware updates is not a very secure practice. Getting this information from the firmware itself is more secure, assuming the firmware has been verified by a previous stage boot loader. +Dynamic FWU GUIDs +* + +The image_type_id contains a GUID value which is specific to the image +and board being updated, that is to say it should uniquely identify the +board model (and revision if relevant) and image pair. Traditionally, +these GUIDs are generated manually and hardcoded on a per-board basis, +however this scheme makes it difficult to scale up to support many +boards. + +To address this, v5 GUIDs can be used to generate board-specific GUIDs +at runtime, based on the board's devicetree root compatible +(e.g. "qcom,qrb5165-rb5"). + +These strings are combined with the fw_image name to generate GUIDs for +each image. Support for dynamic UUIDs can be enabled by generating a new +namespace UUID and setting EFI_CAPSULE_NAMESPACE_GUID to it. Dynamic GUID +generation is only enabled if the image_type_id property is unset for your +firmware images, this is to avoid breaking existing boards with hardcoded +GUIDs. + +The mkeficapsule tool can be used to determine the GUIDs for a particular +board and image. It can be found in the tools directory. + +Firmware update images +** + The firmware images structure defines the GUID values, image index values and the name of the images that are to be updated through the capsule update feature. These values are to be defined as part of an array. These GUID values would be used by the Firmware Management -- 2.45.2
[PATCH v4 03/10] efi: add a helper to generate dynamic UUIDs
Introduce a new helper efi_capsule_update_info_gen_ids() which populates the capsule update fw images image_type_id field. This allows for determinstic UUIDs to be used that can scale to a large number of different boards and board variants without the need to maintain a big list. We call this from efi_fill_image_desc_array() to populate the UUIDs lazily on-demand. Signed-off-by: Caleb Connolly --- lib/efi_loader/Kconfig| 12 ++ lib/efi_loader/efi_capsule.c | 1 + lib/efi_loader/efi_firmware.c | 52 +++ 3 files changed, 65 insertions(+) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 430bb7f0f7dc..9553520c6bba 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -235,8 +235,20 @@ config EFI_CAPSULE_ON_DISK_EARLY If this option is enabled, capsules will be enforced to be executed as part of U-Boot initialisation so that they will surely take place whatever is set to distro_bootcmd. +config EFI_CAPSULE_NAMESPACE_GUID + string "Namespace for dynamic capsule GUIDs" + # v4 UUID as a default for upstream U-Boot boards + default "8c9f137e-91dc-427b-b2d6-b420faebaf2a" + depends on EFI_HAVE_CAPSULE_SUPPORT + help + Define the namespace or "salt" GUID used to generate the per-image + GUIDs. This should be a GUID in the standard 8-4-4-4-12 format. + + Device vendors are expected to generate their own namespace GUID + to avoid conflicts with upstream/community images. + config EFI_CAPSULE_FIRMWARE bool config EFI_CAPSULE_FIRMWARE_MANAGEMENT diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 0937800e588f..ac02e79ae7d8 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -19,8 +19,9 @@ #include #include #include #include +#include #include #include #include diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index ba5aba098c0f..81d060b47a34 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -244,8 +244,57 @@ void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_ free(var_state); } +/** + * efi_capsule_update_info_gen_ids - generate GUIDs for the images + * + * Generate the image_type_id for each image in the update_info.images array + * using the first compatible from the device tree and a salt + * UUID defined at build time. + * + * Returns:status code + */ +static efi_status_t efi_capsule_update_info_gen_ids(void) +{ + int ret, i; + struct uuid namespace; + const char *compatible; /* Full array including null bytes */ + struct efi_fw_image *fw_array; + + fw_array = update_info.images; + /* Check if we need to run (there are images and we didn't already generate their IDs) */ + if (!update_info.num_images || + memchr_inv(&fw_array[0].image_type_id, 0, sizeof(fw_array[0].image_type_id))) + return EFI_SUCCESS; + + ret = uuid_str_to_bin(CONFIG_EFI_CAPSULE_NAMESPACE_GUID, + (unsigned char *)&namespace, UUID_STR_FORMAT_GUID); + if (ret) { + log_debug("%s: EFI_CAPSULE_NAMESPACE_GUID is invalid: %d\n", __func__, ret); + return EFI_UNSUPPORTED; + } + + compatible = ofnode_read_string(ofnode_root(), "compatible"); + if (!compatible) { + log_debug("%s: model or compatible not defined\n", __func__); + return EFI_UNSUPPORTED; + } + + for (i = 0; i < update_info.num_images; i++) { + gen_v5_guid(&namespace, + &fw_array[i].image_type_id, + compatible, strlen(compatible), + fw_array[i].fw_name, u16_strlen(fw_array[i].fw_name) * sizeof(uint16_t), + NULL); + + log_debug("Image %ls UUID %pUl\n", fw_array[i].fw_name, + &fw_array[i].image_type_id); + } + + return EFI_SUCCESS; +} + /** * efi_fill_image_desc_array - populate image descriptor array * @image_info_size: Size of @image_info * @image_info:Image information @@ -282,8 +331,11 @@ static efi_status_t efi_fill_image_desc_array( return EFI_BUFFER_TOO_SMALL; } *image_info_size = total_size; + if (efi_capsule_update_info_gen_ids() != EFI_SUCCESS) + return EFI_UNSUPPORTED; + fw_array = update_info.images; *descriptor_count = update_info.num_images; *descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION; *descriptor_size = sizeof(*image_info); -- 2.45.2
[PATCH v4 02/10] lib: uuid: add UUID v5 support
Add support for generating version 5 UUIDs, these are determistic and work by hashing a "namespace" UUID together with some unique data. One intended usecase is to allow for dynamically generate payload UUIDs for UEFI capsule updates, so that supported boards can have their own UUIDs without needing to hardcode them. In addition, move the common bit twiddling code from gen_ran_uuid into a separate function and rewrite it not to use clrsetbits (which is not available when building as part of host tools). Tests for this are added in an upcoming patch. Signed-off-by: Caleb Connolly --- include/uuid.h | 17 +++-- lib/Kconfig| 1 + lib/uuid.c | 58 +++--- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/include/uuid.h b/include/uuid.h index f5a941250f48..1f4fa103b5e9 100644 --- a/include/uuid.h +++ b/include/uuid.h @@ -10,8 +10,9 @@ #ifndef __UUID_H__ #define __UUID_H__ #include +#include /* * UUID - Universally Unique IDentifier - 128 bits unique number. *There are 5 versions and one variant of UUID defined by RFC4122 @@ -45,10 +46,10 @@ * where x is a hexadecimal character. Fields are separated by '-'s. * When converting to a binary UUID, le means the field should be converted * to little endian and be means it should be converted to big endian. * - * UUID is also used as GUID (Globally Unique Identifier) with the same binary - * format but it differs in string format like below. + * UUID is also used as GUID (Globally Unique Identifier) with the same format + * but with some fields stored in little endian. * * GUID: * 0914 19 24 * ---- @@ -142,8 +143,20 @@ void gen_rand_uuid(unsigned char *uuid_bin); * @param - uuid output type: UUID - 0, GUID - 1 */ void gen_rand_uuid_str(char *uuid_str, int str_format); +struct efi_guid; + +/** + * gen_v5_guid() - generate little endian v5 GUID from namespace and other seed data. + * + * @namespace: pointer to UUID namespace salt + * @guid:pointer to allocated GUID output + * @...: NULL terminated list of seed data as pairs of pointers + * to data and their lengths + */ +void gen_v5_guid(const struct uuid *namespace, struct efi_guid *guid, ...); + /** * uuid_str_to_le_bin() - Convert string UUID to little endian binary data. * @uuid_str: pointer to UUID string * @uuid_bin: pointer to allocated array for little endian output [16B] diff --git a/lib/Kconfig b/lib/Kconfig index 189e6eb31aa1..9aa882d5f882 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -72,8 +72,9 @@ config HAVE_PRIVATE_LIBGCC bool config LIB_UUID bool + select SHA1 config RANDOM_UUID bool "GPT Random UUID generation" select LIB_UUID diff --git a/lib/uuid.c b/lib/uuid.c index dfa2320ba267..7d0a8273d157 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -21,8 +21,9 @@ #include #include #include #include +#include int uuid_str_valid(const char *uuid) { int i, valid; @@ -368,8 +369,57 @@ void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str, } } } +static void configure_uuid(struct uuid *uuid, unsigned char version) +{ + uint16_t tmp; + + /* Configure variant/version bits */ + tmp = be16_to_cpu(uuid->time_hi_and_version); + tmp = (tmp & ~UUID_VERSION_MASK) | (version << UUID_VERSION_SHIFT); + uuid->time_hi_and_version = cpu_to_be16(tmp); + + uuid->clock_seq_hi_and_reserved &= ~UUID_VARIANT_MASK; + uuid->clock_seq_hi_and_reserved |= (UUID_VARIANT << UUID_VARIANT_SHIFT); +} + +void gen_v5_guid(const struct uuid *namespace, struct efi_guid *guid, ...) +{ + sha1_context ctx; + va_list args; + const uint8_t *data; + uint32_t *tmp32; + uint16_t *tmp16; + uint8_t hash[SHA1_SUM_LEN]; + + sha1_starts(&ctx); + /* Hash the namespace UUID as salt */ + sha1_update(&ctx, (unsigned char *)namespace, UUID_BIN_LEN); + va_start(args, guid); + + while ((data = va_arg(args, const uint8_t *))) { + unsigned int len = va_arg(args, size_t); + sha1_update(&ctx, data, len); + } + + va_end(args); + sha1_finish(&ctx, hash); + + /* Truncate the hash into output UUID, it is already big endian */ + memcpy(guid, hash, sizeof(*guid)); + + configure_uuid((struct uuid *)guid, 5); + + /* Make little endian */ + tmp32 = (uint32_t *)&guid->b[0]; + *tmp32 = be32_to_cpu(*tmp32); + tmp16 = (uint16_t *)&guid->b[4]; + *tmp16 = be16_to_cpu(*tmp16); + tmp16 = (uint16_t *)&guid->b[6]; + *tmp16 = be16_to_cpu(*tmp16); +} + #if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID) void gen_rand_uuid(unsigned char *uuid_bin) { u32 ptr[4]; @@ -394,15 +444,9 @@ void gen_rand_uuid(unsigned char *uuid_bin) /*
[PATCH v4 01/10] efi: define struct efi_guid
This let's us forward declare efi_guid_t in the UUID code without pulling in efi.h Signed-off-by: Caleb Connolly --- include/efi.h | 2 +- tools/eficapsule.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/efi.h b/include/efi.h index c3c4b93f860a..b92c961a2afd 100644 --- a/include/efi.h +++ b/include/efi.h @@ -73,9 +73,9 @@ struct efi_device_path { * EDK2 reference implementation both define EFI_GUID as * struct { u32 a; u16; b; u16 c; u8 d[8]; }; which is 4-byte * aligned. */ -typedef struct { +typedef struct efi_guid { u8 b[16]; } efi_guid_t __attribute__((aligned(4))); #define EFI_BITS_PER_LONG (sizeof(long) * 8) diff --git a/tools/eficapsule.h b/tools/eficapsule.h index 6efd07d2eb6b..97d077536d5b 100644 --- a/tools/eficapsule.h +++ b/tools/eficapsule.h @@ -23,9 +23,9 @@ #endif #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -typedef struct { +typedef struct efi_guid { uint8_t b[16]; } efi_guid_t __aligned(8); #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ -- 2.45.2
[PATCH v4 00/10] efi: CapsuleUpdate: support for dynamic UUIDs
As more boards adopt support for the EFI CapsuleUpdate mechanism, there is a growing issue of being able to target updates to them properly. The current mechanism of hardcoding UUIDs for each board at compile time is unsustainable, and maintaining lists of GUIDs is similarly cumbersome. In this series, I propose that we adopt v5 GUIDs, these are generated by using a well-known salt GUID as well as board specific information the DT root compatible string, these are hashed together and the result is truncated to form a new UUID. The well-known salt GUID can be specific to the architecture (SoC vendor), or OEM. It is defined in the board defconfig so that vendors can easily bring their own. Specifically, the following fields are used to generate a GUID for a particular fw_image: * namespace salt * board compatible (usually the first entry in the dt root compatible array). * fw_image name (the string identifying the specific image, especially relevant for board that can update multiple images). == Usage == Boards can enable dynamic UUID support by simply not setting the efi_fw_image image_type_id property. Vendors may also wish to set a custom namespace GUID (by setting CONFIG_EFI_CAPSULE_NAMESPACE_GUID). == Limitations == * Changing GUIDs The primary limitation with this approach is that if any of the source fields change, so will the GUID for the board. It is therefore pretty important to ensure that GUID changes are caught during development. * Supporting multiple boards with a single image This now requires having an entry with the GUID for every board which might lead to larger UpdateCapsule images. == Tooling == The mkeficapsule command is updated to add a new guidgen subcommand, this can generate GUIDs that match those the board would generate at runtime. It accepts an optional namespace GUID (if the default isn't used), a path to the board DTB, and a list of firmware image names. This series follows a related discussion started by Ilias: https://lore.kernel.org/u-boot/cac_iwjjnha4gmf897mqyzndbgjfg8k4kwgstxwuy72wkyli...@mail.gmail.com/ CI run for this series: https://source.denx.de/u-boot/custodians/u-boot-snapdragon/-/pipelines/21419 --- Changes in v4: - Make UUID v5 support always enabled rather than being optional. - Fix endianness issues (thanks Vincent and Ilias) - Merge genguid tool into mkeficapsule. - And move mkeficapsule over to using U-Boot's UUID code rather than libuuid. - Provide a default namespace UUID for all U-Boot boards. - Link to v3: https://lore.kernel.org/r/20240531-b4-dynamic-uuid-v3-0-ca4a4865d...@linaro.org Changes in v3: - Add manpage for genguid - Add dedicated CONFIG_TOOLS_GENGUID option - Minor code fixes addressing v2 feedback - Link to v2: https://lore.kernel.org/r/20240529-b4-dynamic-uuid-v2-0-c26f31057...@linaro.org Changes in v2: - Move namespace UUID to be defined in defconfig - Add tests and tooling - Only use the first board compatible to generate UUID. - Link to v1: https://lore.kernel.org/r/20240426-b4-dynamic-uuid-v1-0-e8154e00e...@linaro.org --- Caleb Connolly (10): efi: define struct efi_guid lib: uuid: add UUID v5 support efi: add a helper to generate dynamic UUIDs doc: uefi: document dynamic UUID generation sandbox: switch to dynamic UUIDs lib: uuid: supporting building as part of host tools include: export uuid.h tools: mkeficapsule: use u-boot UUID library tools: mkeficapsule: support generating dynamic GUIDs test: lib/uuid: add unit tests for dynamic UUIDs arch/arm/mach-rockchip/board.c | 2 +- board/cobra5272/flash.c| 2 +- board/gardena/smart-gateway-mt7688/board.c | 2 +- board/sandbox/sandbox.c| 16 -- board/socrates/socrates.c | 2 +- board/xilinx/common/board.c| 2 +- cmd/efi.c | 2 +- cmd/efi_common.c | 2 +- cmd/flash.c| 2 +- cmd/gpt.c | 2 +- cmd/nvedit_efi.c | 2 +- cmd/x86/hob.c | 2 +- common/flash.c | 2 +- disk/part_efi.c| 2 +- doc/develop/uefi/uefi.rst | 27 +++ doc/mkeficapsule.1 | 23 +++ drivers/firmware/arm-ffa/arm-ffa-uclass.c | 2 +- env/sf.c | 2 +- fs/btrfs/btrfs.c | 2 +- fs/btrfs/compat.h | 2 +- fs/btrfs/disk-io.c | 2 +- fs/ext4/ext4fs.c | 2 +- include/efi.h | 2 +- include/fwu.h
Re: [PATCH] usb: cdns3: continue probe even when USB PHY device does not exist
On 02/07/2024 15:07, Siddharth Vadapalli wrote: > Prior to commit cd295286c786 ("usb: cdns3: avoid error messages if phys > don't exist"), cdns3_probe() errors out only on failing to initialize the > USB2/USB3 PHY. However, since commit cd295286c786, absence of the PHY > device is also treated as an error, resulting in a regression. > > Extend commit cd295286c786 to treat -ENODEV as an acceptable return value > of generic_phy_get_by_name() and continue device probe as was the case > prior to the commit. > > Fixes: cd295286c786 ("usb: cdns3: avoid error messages if phys don't exist") > Signed-off-by: Siddharth Vadapalli > --- > > Hello, > > This patch is based on commit > b4cbd1a257 Merge tag 'u-boot-amlogic-20240701' of > https://source.denx.de/u-boot/custodians/u-boot-amlogic into next > of the next branch of U-Boot. > > Regards, > Siddharth. > > drivers/usb/cdns3/core.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c > index b4e931646b..5b3e32953e 100644 > --- a/drivers/usb/cdns3/core.c > +++ b/drivers/usb/cdns3/core.c > @@ -338,7 +338,7 @@ static int cdns3_probe(struct cdns3 *cdns) > dev_err(dev, "USB2 PHY init failed: %d\n", ret); > return ret; > } > - } else if (ret != -ENOENT && ret != -ENODATA) { > + } else if (ret != -ENOENT && ret != -ENODATA && ret != -ENODEV) { With this change we will not error out on a genuine error condition that produces ENODEV. If PHY phandle is not present the API should return ENOENT right? static int __of_parse_phandle_with_args(const struct device_node *np, ... { ... /* Retrieve the phandle list property */ list = of_get_property(np, list_name, &size); if (!list) return -ENOENT; Can you please check and point where the -ENODEV error is coming from? > dev_err(dev, "Couldn't get USB2 PHY: %d\n", ret); > return ret; > } > @@ -350,7 +350,7 @@ static int cdns3_probe(struct cdns3 *cdns) > dev_err(dev, "USB3 PHY init failed: %d\n", ret); > return ret; > } > - } else if (ret != -ENOENT && ret != -ENODATA) { > + } else if (ret != -ENOENT && ret != -ENODATA && ret != -ENODEV) { > dev_err(dev, "Couldn't get USB3 PHY: %d\n", ret); > return ret; > } -- cheers, -roger
Re: [PATCH] board: phytec: k3: k3_ddrss_patch: Add ddr phy reg count
Am 02.07.24 um 11:22 schrieb Dominik Haller: Add and use the correct number of ddr phy registers to update the corresponding settings. Fixes: cbf5c99ef317 ("board: phytec: common: Introduce a method to inject DDR timings deltas") Signed-off-by: Dominik Haller Reviewed-by: Wadim Egorov --- board/phytec/common/k3/k3_ddrss_patch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/board/phytec/common/k3/k3_ddrss_patch.c b/board/phytec/common/k3/k3_ddrss_patch.c index 39f7be8dc922..5afe5a20c7f3 100644 --- a/board/phytec/common/k3/k3_ddrss_patch.c +++ b/board/phytec/common/k3/k3_ddrss_patch.c @@ -12,6 +12,7 @@ #ifdef CONFIG_K3_AM64_DDRSS #define LPDDR4_INTR_CTL_REG_COUNT (423U) #define LPDDR4_INTR_PHY_INDEP_REG_COUNT (345U) +#define LPDDR4_INTR_PHY_REG_COUNT (1406U) #endif static int fdt_setprop_inplace_idx_u32(void *fdt, int nodeoffset, @@ -54,7 +55,7 @@ int fdt_apply_ddrss_timings_patch(void *fdt, struct ddrss *ddrss) return ret; } - for (i = 0; i < LPDDR4_INTR_PHY_INDEP_REG_COUNT; i++) + for (i = 0; i < LPDDR4_INTR_PHY_REG_COUNT; i++) for (j = 0; j < ddrss->phy_regs_num; j++) if (i == ddrss->phy_regs[j].off) { ret = fdt_setprop_inplace_idx_u32(fdt,
Re: [PATCH 0/2] Import environment variables from FIT configuration
Hi Lukas, On 7/2/24 2:58 PM, Lukas Funke wrote: Hi Quentin, On 02.07.2024 13:37, Quentin Schulz wrote: Hi Lukas, On 7/2/24 1:01 PM, Lukas Funke wrote: Hi Quentin, On 02.07.2024 11:16, Quentin Schulz wrote: Hi Lukas, On 7/2/24 8:48 AM, lukas.funke-...@weidmueller.com wrote: From: Lukas Funke This series enables U-Boot to import environment variables from the selectd FIT configuration. One use-case is that the overall build process enriches the FIT configuration node with dm-verity information which should be injected into the kernel commandline. U-Boot will then read these (possibly signed) environment variables and put them into the actual Kernel commandline using variable replacement (see CONFIG_BOOTARGS_SUBST). Example: Config: CONFIG_BOOTARGS_SUBST=y CONFIG_ENV_IMPORT_FIT_CONF=y FIT: configurations { default = "conf-1"; conf-1 { kernel = "kernel-1"; fdt = "fdt-1"; env,dm-verity-args = "dm-mod.create=..."; env,bar = "someothervalue"; }; }; U-Boot cmdline: => env set bootargs="rootfstype=squashfs root=/dev/xyz ${dm-verity-args} ro" => boot Kernel cmdline: Kernel command line: rootfstype=squashfs ... dm-mod.create= ... I think FIT supports storing U-Boot scripts and running those via `source` command (usually the file extension is .scr). I do not know if there's support for automatically loading this .scr as part of a config node though, but if there isn't I guess it'd make more sense to support this case than to come up with yet another implementation? What do you think? I wasn't aware of this, thanks for pointing it out! This patch was mainly inspired by the dm-vertiy use-case which requires just env-variables and no (complex) scripts. There is currently no mechanism to source/run such scripts automatically. How would you distinguish between scripts that should run automatically und scripts which are sourced by a specific board/shell-script implementation? I guess there are good reasons to not run such scripts Scripts in conf would be automatically run? Scripts not in conf needs to be executed via `source` command for example? Not sure what to do if you want a script linked to a conf but not run automatically though (and what would be the use-case?). I guess you could have a script automatically run (so in conf node) that sets a variable to know where to look for the other script that isn't automatically executed? Sounds like yet another level of indirection. Not sure if this a good or a bad thing, but makes things definitely more complicated. Yes, but this isn't an indirection the project has to support. We currently support scripts that are in the images node to source. We would need to support automatically running the script if it's in a conf node and that'd be it. To be clear, I am not blocking this (and I don't have any veto power anyway :) ), just wanted to raise that something else already exists and could be extended to fit your usecase. Cheers, Quentin
Re: [PATCH 1/2] led: Implement software led blinking
On 27.06.2024 22:05, Simon Glass wrote: > Hi Mikhail, > > On Thu, 27 Jun 2024 at 12:31, Mikhail Kshevetskiy > wrote: >> From: Michael Polyntsov >> >> If hardware (or driver) doesn't support leds blinking, it's >> now possible to use software implementation of blinking instead. >> This relies on cyclic functions. >> >> Signed-off-by: Michael Polyntsov >> Signed-off-by: Mikhail Kshevetskiy >> --- >> drivers/led/Kconfig | 9 ++ >> drivers/led/led-uclass.c | 190 ++- >> 2 files changed, 195 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig >> index 9837960198d..4330f014239 100644 >> --- a/drivers/led/Kconfig >> +++ b/drivers/led/Kconfig >> @@ -73,6 +73,15 @@ config LED_BLINK >> This option enables support for this which adds slightly to the >> code size. >> >> +config LED_SW_BLINK >> + bool "Support software LED blinking" >> + depends on LED_BLINK >> + select CYCLIC >> + help >> + Turns on led blinking implemented in the software, useful when >> + the hardware doesn't support led blinking. Does nothing if >> + driver supports blinking. > Can you talk about the blinking p[eriod / API? Could you clarify what do you mean? >> + >> config SPL_LED >> bool "Enable LED support in SPL" >> depends on SPL_DM >> diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c >> index a4be56fc258..b35964f2e99 100644 >> --- a/drivers/led/led-uclass.c >> +++ b/drivers/led/led-uclass.c >> @@ -15,6 +15,10 @@ >> #include >> #include >> >> +#ifdef CONFIG_LED_SW_BLINK >> +#include >> +#endif > You should not need to #ifdef include files will fix >> + >> int led_bind_generic(struct udevice *parent, const char *driver_name) >> { >> struct udevice *dev; >> @@ -41,6 +45,7 @@ int led_get_by_label(const char *label, struct udevice >> **devp) >> ret = uclass_get(UCLASS_LED, &uc); >> if (ret) >> return ret; >> + >> uclass_foreach_dev(dev, uc) { >> struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); >> >> @@ -52,14 +57,180 @@ int led_get_by_label(const char *label, struct udevice >> **devp) >> return -ENODEV; >> } >> >> -int led_set_state(struct udevice *dev, enum led_state_t state) >> +#ifdef CONFIG_LED_SW_BLINK >> + >> +enum led_sw_blink_state_t { >> + LED_SW_BLINK_ST_OFF = 0, >> + LED_SW_BLINK_ST_ON = 1, >> + LED_SW_BLINK_ST_NONE = 2, >> +}; >> + >> +struct sw_blink_state { >> + struct udevice *dev; >> + enum led_sw_blink_state_t cur_blink_state; >> +}; >> + >> +static bool led_driver_supports_hw_blinking(const struct udevice *dev) >> +{ >> + struct led_ops *ops = led_get_ops(dev); >> + >> + /* >> +* We assume that if driver supports set_period, then it correctly >> +* handles all other requests, for example, that >> +* led_set_state(LEDST_BLINK) works correctly. >> +*/ >> + return ops->set_period != NULL; >> +} >> + >> +static const char *led_sw_label_to_cyclic_func_name(const char *label) >> +{ >> +#define MAX_NAME_LEN 50 >> + static char cyclic_func_name[MAX_NAME_LEN] = {0}; >> + >> + snprintf(cyclic_func_name, MAX_NAME_LEN, "sw_blink_%s", label); >> + return cyclic_func_name; >> +#undef MAX_NAME_LEN >> +} >> + >> +static struct cyclic_info *led_sw_find_blinking_led(const char *label) >> +{ >> + struct cyclic_info *cyclic; >> + const char *cyclic_name; >> + >> + cyclic_name = led_sw_label_to_cyclic_func_name(label); >> + >> + hlist_for_each_entry(cyclic, cyclic_get_list(), list) { >> + if (strcmp(cyclic->name, cyclic_name) == 0) >> + return cyclic; >> + } >> + >> + return NULL; >> +} >> + >> +static bool led_sw_is_blinking(struct udevice *dev) >> +{ >> + struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); >> + struct cyclic_info *cyclic = >> led_sw_find_blinking_led(uc_plat->label); >> + >> + if (cyclic != NULL) { > if (cyclic) { will fix > >> + struct sw_blink_state *state; >> + >> + state = (struct sw_blink_state *)cyclic->ctx; >> + return state->cur_blink_state != LED_SW_BLINK_ST_NONE; >> + } >> + >> + return false; >> +} >> + >> +static void led_sw_blink(void *void_state) >> +{ >> + struct sw_blink_state *state = (struct sw_blink_state *)void_state; > You should not need that cast will fix > >> + struct udevice *dev = state->dev; >> + struct led_ops *ops = led_get_ops(dev); >> + >> + switch (state->cur_blink_state) { >> + case LED_SW_BLINK_ST_OFF: >> + state->cur_blink_state = LED_SW_BLINK_ST_ON; >> + ops->set_state(dev, LEDST_ON); >> + break; >> + case LED_SW_BLINK_ST_ON: >> + state->cur_blink_state = LED_SW_BLINK_ST_OFF; >> +
Re: [PATCH 1/2] spi: soft_spi: fix miso gpio property name
On 27.06.2024 14:34, Fabio Estevam wrote: > [You don't often get email from feste...@gmail.com. Learn why this is > important at https://aka.ms/LearnAboutSenderIdentification ] > > On Thu, Jun 27, 2024 at 8:31 AM Mikhail Kshevetskiy > wrote: >> Signed-off-by: Mikhail Kshevetskiy >> --- >> drivers/spi/soft_spi.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c >> index 0fa14339bdc..3fe62818a44 100644 >> --- a/drivers/spi/soft_spi.c >> +++ b/drivers/spi/soft_spi.c >> @@ -272,7 +272,7 @@ static int soft_spi_probe(struct udevice *dev) >> ret = gpio_request_by_name(dev, "gpio-miso", 0, &plat->miso, >>GPIOD_IS_IN); >> if (ret) >> - ret = gpio_request_by_name(dev, "gpio-miso", 0, &plat->miso, >> + ret = gpio_request_by_name(dev, "miso-gpios", 0, &plat->miso, > We should support the deprecated 'gpio-miso' property and the > preferred 'miso-gpios' one. > > The same applies for gpio-sck and gpio-mosi. This is exactly what the patch did. Actually it just fix a miss-print. Other properties already have a proper fallback. >>GPIOD_IS_IN); >> if (ret) >> plat->flags |= SPI_MASTER_NO_RX; >> -- >> 2.43.0 >>
Re: [PATCH] gpt: allow spaces in partition list
On 27.06.2024 22:05, Simon Glass wrote: > Hi Mikhail, > > On Thu, 27 Jun 2024 at 12:29, Mikhail Kshevetskiy > wrote: >> This allows spliting partition list to several lines in environment file >> >> ex: >> >> gpt_partition_list= >> name=boot1,size=5MiB,start=0x10; >> name=boot2,size=5MiB; >> name=rootfs1,size=70MiB; >> name=rootfs2,size=70MiB; >> name=overlay1,size=20MiB; >> name=overlay2,size=20MiB; >> name=art,size=4MiB; > Is this referring to a .env file, i.e. a text environment file? If so, > I would hope that spaces at the start of a line would be automatically > removed. This is refer to a .env file, so starting space/tabs will be removed, all '\n' will be replaced by spaces. Thus we will get a single line where each partition divided from other with a single space (like below) gpt_partition_list=name=boot1,size=5MiB,start=0x10; name=boot2,size=5MiB; ... >> Signed-off-by: Mikhail Kshevetskiy >> --- >> cmd/gpt.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/cmd/gpt.c b/cmd/gpt.c >> index 7aaf1889a5a..2b29ab98ccc 100644 >> --- a/cmd/gpt.c >> +++ b/cmd/gpt.c >> @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char >> *key) >> k = strsep(&v, "="); >> if (!k) >> break; >> + k += strspn(k, " \t"); >> if (strcmp(k, key) == 0) { >> new = strdup(v); >> break; >> @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key) >> k = strsep(&s, ","); >> if (!k) >> break; >> + k += strspn(k, " \t"); >> if (strcmp(k, key) == 0) { >> result = true; >> break; >> -- >> 2.43.0 >> > Regards, > Simon
Re: [PATCH] imx: hab: Make imx_hab_is_enabled dependent on FIELD_RETURN
Hi Ye, > Hi Paul, > >On 7/1/2024 8:39 PM, Paul Geurts wrote: >> Hi Ye, >> >>> Hi Paul, >>> >>> On 6/26/2024 3:17 PM, Paul Geurts wrote: Hi, Thanks for the feedback. > Hi Paul, > > On 6/24/2024 8:09 PM, Fabio Estevam wrote: > >> Hi Paul, >> >> On Fri, Jun 21, 2024 at 10:06 AM Paul Geurts >> wrote: >> >>> -struct imx_sec_config_fuse_t { >>> +struct imx_fuse_t { >> Please make the struct renaming a separate patch. >> >> Peng Fan, Ye Li, >> >> Could you please help review this patch? >> >> Thanks > Can you take a look iMX8MP FIELD_RETURN fuse, I think it does not > have 1 bit but 8 bits which requires to burn a sequence. Only when > the bits sequence is matched, the field return can work. So checking > the bit 0 is not enough. Are you sure about that? The security reference manual (IMX8MPSRM) says in Table 5-5 that the FIELD_RETURN fuse is located on fuse 0x630[0], which is a single bit. Also, the "Chip Security Lifecycle" section (2.15.1) says the following: FEILD RETURN (SEC_CONFIG[1] fuse = 1 and FIELD_RETURN fuse = 1) Are you maybe confusing the FIELD_RETURN fuse with the FIELD_RETURN_LOCK sticky bit? clearing the lock bit _is_ quite the procedure, but it is unrelated to U-Boot, as this is done by ROM code through CSF. I tested this on an i.MX8M Plus and it seems to work fine. >>> I know the steps for field return. What I mean is the FIELD_RETURN >>> fuse. It is true that security RM mentions it as you quote. But from >>> 8MP fuse map and ROM codes, I get different things. >>> >>> FIELD_RETURN 8-bit code. >>> FIELD_RETURN = 0, is non-field return mode, functional/secure mode. >>> FIELD_RETURN = Matching Sequence, device is in field_return mode >>> FIELD_RETURN != Matching Sequence, device asserts security violation >> That is indeed different from what is mentioned in documentation. I have >> asked our NXP FAE about the discrepancy and I will adjust the code if >> needed. > > Thanks for confirm. I also cross checked with teams. 8MP must burn a > pattern. Otherwise HAB won't covert to field return. Okay, thanks for checking, I will wait for the details and make the necessary adjustments > > Additional, do you think it is very necessary to add this patch set? > Because field return is a pure debug feature, it won't be deployed on > productions. The developers working on field return parts can re-build > u-boot with CONFIG_IMX_HAB disabled. In an OEM situation, is a lot of cases, the company creating the bootloader (OEM) is typically neither the one singing the bootloader nor performing the FIELD_RETURN setting (end customer/VAR). The end customer is typically neither interested nor capable of rebuilding the bootloader with CONFIG_IMX_HAB disabled. This means 2 bootloaders need to be maintained in parallel by the OEM, creating unnecessary overhead. This also introduces additional risk as the end customer may sign the wrong bootloader (with HAB disabled). > > This patch may introduce risk to HAB in some sense, especially for > productions. One mistake would make unsigned image bypass authentication > result. I think this risk is mitigated by the fuse unlocking procedure imposed by HAB. I don't think someone will accidentally go through the entire procedure of unlocking the FIELD_RETURN fuse and then also accidentally burning the fuse. The risk in code IMO is not greater then the risk already there by reading out the SEC_CONFIG fuse. > > > Best regards, > > Ye Li > >>> >>> However, I'm not sure how is it implemented in HAB. Since you have >>> tested 8M plus, can you confirm the closed part is successfully >>> converted to field return and can boot without signing? >> Maybe I did something wrong while testing. I will retest it on a new >> board when I have received some more information from NXP. >> >>> >>> Best regards, >>> >>> Ye Li >>>
Re: [PATCH] ARM: socfpga: fix broken function call for arria10
Hi U-boot-teers! (...) > Reviewed-by: Marek Vasut > > Could you by any chance also send a patch to enable this QSPI NOR > support on one of the A10 targets, so the CI would compile this code and > this code wouldn't bitrot again ? > > Thanks I've sent you now a series of one patch showing the error for me. And another one with the above fix. NB: I did not apply reviewed-by tags, so far. Also note, it is not supposed to turn on the (bloody) cadence QSPI flash permanently. We have this piece and having turned on, it can lead into situations due to ...interesting hardware behavior. Best, L
[PATCH] ARM: socfpga: fix broken function call for arria10
Remove obsolete arguments in the function call. The call's argument list differs from its more recent definition. This breaks compilation of the 'socfpga_arria10_defconfig' target, with additionally enabled: CONFIG_CADENCE_QSPI=y' The removed arguments are obtained from device-tree declaration. Signed-off-by: Lothar Rubusch --- The patch makes the problem disappear. While messing with some old Intels, it looked to me as if this usually turned off code region of the misc_arria10.c still contains legacy arguments in the call. Thus broke my compilation. I'm unsure. Please verify. --- arch/arm/mach-socfpga/misc_arria10.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/arm/mach-socfpga/misc_arria10.c b/arch/arm/mach-socfpga/misc_arria10.c index 93c9e8b0..5c782f6b 100644 --- a/arch/arm/mach-socfpga/misc_arria10.c +++ b/arch/arm/mach-socfpga/misc_arria10.c @@ -211,11 +211,9 @@ int qspi_flash_software_reset(void) struct udevice *flash; int ret; - /* Get the flash info */ + /* Get the flash info, speed and mode will be read from DT */ ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, -CONFIG_SF_DEFAULT_SPEED, -CONFIG_SF_DEFAULT_MODE, &flash); if (ret) { -- 2.25.1
[PATCH] ARM: socfpga: show broken function call for arria10
This patch only shows the problem on an existing platform. Turning on the cadence QSPI flash breaks the build for arria10. Can you reproduce? make socfpga_arria10_defconfig make Signed-off-by: Lothar Rubusch --- NB: Don't apply this config/patch permanently! The Cadence QSPI flash can be tricky due to a write reset register instruction which can brick the board if interrupted. We experienced this situation. So, that's why I removed the config option in my boards (to be upstreamed soon). Hence, my boards won't show the above problem anymore. Anyway, I think the code section in misc_arria10.c have a bug. So, I presented the before patch. --- configs/socfpga_arria10_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/socfpga_arria10_defconfig b/configs/socfpga_arria10_defconfig index 6d27deeb..c7321bab 100644 --- a/configs/socfpga_arria10_defconfig +++ b/configs/socfpga_arria10_defconfig @@ -61,6 +61,7 @@ CONFIG_ETH_DESIGNWARE=y CONFIG_MII=y CONFIG_SYS_NS16550_MEM32=y CONFIG_SPI=y +CONFIG_CADENCE_QSPI=y CONFIG_TIMER=y CONFIG_SPL_TIMER=y CONFIG_DESIGNWARE_APB_TIMER=y -- 2.25.1
Re: [PATCH 0/2] Import environment variables from FIT configuration
Hi Quentin, On 02.07.2024 13:37, Quentin Schulz wrote: Hi Lukas, On 7/2/24 1:01 PM, Lukas Funke wrote: Hi Quentin, On 02.07.2024 11:16, Quentin Schulz wrote: Hi Lukas, On 7/2/24 8:48 AM, lukas.funke-...@weidmueller.com wrote: From: Lukas Funke This series enables U-Boot to import environment variables from the selectd FIT configuration. One use-case is that the overall build process enriches the FIT configuration node with dm-verity information which should be injected into the kernel commandline. U-Boot will then read these (possibly signed) environment variables and put them into the actual Kernel commandline using variable replacement (see CONFIG_BOOTARGS_SUBST). Example: Config: CONFIG_BOOTARGS_SUBST=y CONFIG_ENV_IMPORT_FIT_CONF=y FIT: configurations { default = "conf-1"; conf-1 { kernel = "kernel-1"; fdt = "fdt-1"; env,dm-verity-args = "dm-mod.create=..."; env,bar = "someothervalue"; }; }; U-Boot cmdline: => env set bootargs="rootfstype=squashfs root=/dev/xyz ${dm-verity-args} ro" => boot Kernel cmdline: Kernel command line: rootfstype=squashfs ... dm-mod.create= ... I think FIT supports storing U-Boot scripts and running those via `source` command (usually the file extension is .scr). I do not know if there's support for automatically loading this .scr as part of a config node though, but if there isn't I guess it'd make more sense to support this case than to come up with yet another implementation? What do you think? I wasn't aware of this, thanks for pointing it out! This patch was mainly inspired by the dm-vertiy use-case which requires just env-variables and no (complex) scripts. There is currently no mechanism to source/run such scripts automatically. How would you distinguish between scripts that should run automatically und scripts which are sourced by a specific board/shell-script implementation? I guess there are good reasons to not run such scripts Scripts in conf would be automatically run? Scripts not in conf needs to be executed via `source` command for example? Not sure what to do if you want a script linked to a conf but not run automatically though (and what would be the use-case?). I guess you could have a script automatically run (so in conf node) that sets a variable to know where to look for the other script that isn't automatically executed? Sounds like yet another level of indirection. Not sure if this a good or a bad thing, but makes things definitely more complicated. per default. I would also change current behaviour. For env variables I see no harm. If the env properties in the FIT image are part of the checksum and signature of the conf node, which is necessary for secure boot, I guess "no harm" fits the bill. To my current knowledge the configuration node itself is signed. Thus, all env-properties are signed. Please correct me if I'm wrong. Cheers, Quentin
[PATCH] usb: cdns3: continue probe even when USB PHY device does not exist
Prior to commit cd295286c786 ("usb: cdns3: avoid error messages if phys don't exist"), cdns3_probe() errors out only on failing to initialize the USB2/USB3 PHY. However, since commit cd295286c786, absence of the PHY device is also treated as an error, resulting in a regression. Extend commit cd295286c786 to treat -ENODEV as an acceptable return value of generic_phy_get_by_name() and continue device probe as was the case prior to the commit. Fixes: cd295286c786 ("usb: cdns3: avoid error messages if phys don't exist") Signed-off-by: Siddharth Vadapalli --- Hello, This patch is based on commit b4cbd1a257 Merge tag 'u-boot-amlogic-20240701' of https://source.denx.de/u-boot/custodians/u-boot-amlogic into next of the next branch of U-Boot. Regards, Siddharth. drivers/usb/cdns3/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index b4e931646b..5b3e32953e 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -338,7 +338,7 @@ static int cdns3_probe(struct cdns3 *cdns) dev_err(dev, "USB2 PHY init failed: %d\n", ret); return ret; } - } else if (ret != -ENOENT && ret != -ENODATA) { + } else if (ret != -ENOENT && ret != -ENODATA && ret != -ENODEV) { dev_err(dev, "Couldn't get USB2 PHY: %d\n", ret); return ret; } @@ -350,7 +350,7 @@ static int cdns3_probe(struct cdns3 *cdns) dev_err(dev, "USB3 PHY init failed: %d\n", ret); return ret; } - } else if (ret != -ENOENT && ret != -ENODATA) { + } else if (ret != -ENOENT && ret != -ENODATA && ret != -ENODEV) { dev_err(dev, "Couldn't get USB3 PHY: %d\n", ret); return ret; } -- 2.40.1
Re: [PATCH 0/2] Import environment variables from FIT configuration
Hi Lukas, On 7/2/24 1:01 PM, Lukas Funke wrote: Hi Quentin, On 02.07.2024 11:16, Quentin Schulz wrote: Hi Lukas, On 7/2/24 8:48 AM, lukas.funke-...@weidmueller.com wrote: From: Lukas Funke This series enables U-Boot to import environment variables from the selectd FIT configuration. One use-case is that the overall build process enriches the FIT configuration node with dm-verity information which should be injected into the kernel commandline. U-Boot will then read these (possibly signed) environment variables and put them into the actual Kernel commandline using variable replacement (see CONFIG_BOOTARGS_SUBST). Example: Config: CONFIG_BOOTARGS_SUBST=y CONFIG_ENV_IMPORT_FIT_CONF=y FIT: configurations { default = "conf-1"; conf-1 { kernel = "kernel-1"; fdt = "fdt-1"; env,dm-verity-args = "dm-mod.create=..."; env,bar = "someothervalue"; }; }; U-Boot cmdline: => env set bootargs="rootfstype=squashfs root=/dev/xyz ${dm-verity-args} ro" => boot Kernel cmdline: Kernel command line: rootfstype=squashfs ... dm-mod.create= ... I think FIT supports storing U-Boot scripts and running those via `source` command (usually the file extension is .scr). I do not know if there's support for automatically loading this .scr as part of a config node though, but if there isn't I guess it'd make more sense to support this case than to come up with yet another implementation? What do you think? I wasn't aware of this, thanks for pointing it out! This patch was mainly inspired by the dm-vertiy use-case which requires just env-variables and no (complex) scripts. There is currently no mechanism to source/run such scripts automatically. How would you distinguish between scripts that should run automatically und scripts which are sourced by a specific board/shell-script implementation? I guess there are good reasons to not run such scripts Scripts in conf would be automatically run? Scripts not in conf needs to be executed via `source` command for example? Not sure what to do if you want a script linked to a conf but not run automatically though (and what would be the use-case?). I guess you could have a script automatically run (so in conf node) that sets a variable to know where to look for the other script that isn't automatically executed? per default. I would also change current behaviour. For env variables I see no harm. If the env properties in the FIT image are part of the checksum and signature of the conf node, which is necessary for secure boot, I guess "no harm" fits the bill. Cheers, Quentin
Re: [PATCH 0/2] Import environment variables from FIT configuration
Hi Quentin, On 02.07.2024 11:16, Quentin Schulz wrote: Hi Lukas, On 7/2/24 8:48 AM, lukas.funke-...@weidmueller.com wrote: From: Lukas Funke This series enables U-Boot to import environment variables from the selectd FIT configuration. One use-case is that the overall build process enriches the FIT configuration node with dm-verity information which should be injected into the kernel commandline. U-Boot will then read these (possibly signed) environment variables and put them into the actual Kernel commandline using variable replacement (see CONFIG_BOOTARGS_SUBST). Example: Config: CONFIG_BOOTARGS_SUBST=y CONFIG_ENV_IMPORT_FIT_CONF=y FIT: configurations { default = "conf-1"; conf-1 { kernel = "kernel-1"; fdt = "fdt-1"; env,dm-verity-args = "dm-mod.create=..."; env,bar = "someothervalue"; }; }; U-Boot cmdline: => env set bootargs="rootfstype=squashfs root=/dev/xyz ${dm-verity-args} ro" => boot Kernel cmdline: Kernel command line: rootfstype=squashfs ... dm-mod.create= ... I think FIT supports storing U-Boot scripts and running those via `source` command (usually the file extension is .scr). I do not know if there's support for automatically loading this .scr as part of a config node though, but if there isn't I guess it'd make more sense to support this case than to come up with yet another implementation? What do you think? I wasn't aware of this, thanks for pointing it out! This patch was mainly inspired by the dm-vertiy use-case which requires just env-variables and no (complex) scripts. There is currently no mechanism to source/run such scripts automatically. How would you distinguish between scripts that should run automatically und scripts which are sourced by a specific board/shell-script implementation? I guess there are good reasons to not run such scripts per default. I would also change current behaviour. For env variables I see no harm. Please let me know what you think. Cheers - Lukas Cheers, Quentin
Re: [PATCH 1/2] spi: soft_spi: fix miso gpio property name
Hi Mikhail, On Tue, Jul 2, 2024 at 6:50 AM Mikhail Kshevetskiy wrote: > This is exactly what the patch did. Actually it just fix a miss-print. > Other properties already have a proper fallback. Ah, you are right. I introduced this issue in commit 2e9fe73a883a ("spi: soft_spi: Support the recommended soft spi properties"). Please add a commit log explaining this. Reviewed-by: Fabio Estevam Thanks
[PATCH 2/2] clk: imx: Fix wrong flags assignment clk-composite-93
The mux flags (u8), div flags (u8), and gate flags (u8) are not the clk flags (unsigned long). They have different meanings Signed-off-by: Michael Trimarchi --- drivers/clk/imx/clk-composite-93.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/clk/imx/clk-composite-93.c b/drivers/clk/imx/clk-composite-93.c index 6d71c0c03ff..34026c5e42f 100644 --- a/drivers/clk/imx/clk-composite-93.c +++ b/drivers/clk/imx/clk-composite-93.c @@ -103,7 +103,6 @@ struct clk *imx93_clk_composite_flags(const char *name, mux->mask = CCM_MUX_MASK; mux->num_parents = num_parents; mux->parent_names = parent_names; - mux->flags = flags; div = kzalloc(sizeof(*div), GFP_KERNEL); if (!div) @@ -120,7 +119,6 @@ struct clk *imx93_clk_composite_flags(const char *name, gate->reg = reg; gate->bit_idx = CCM_OFF_SHIFT; - gate->flags = flags; clk = clk_register_composite(NULL, name, parent_names, num_parents, -- 2.43.0
[PATCH 1/2] clk: imx: Fix wrong flags assignment clk-composite-8m
The mux flags (u8), div flags (u8), and gate flags (u8) are not the clk flags (unsigned long). They have different meanings Signed-off-by: Michael Trimarchi --- drivers/clk/imx/clk-composite-8m.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/clk/imx/clk-composite-8m.c b/drivers/clk/imx/clk-composite-8m.c index 494156751da..560d74aac80 100644 --- a/drivers/clk/imx/clk-composite-8m.c +++ b/drivers/clk/imx/clk-composite-8m.c @@ -135,7 +135,6 @@ struct clk *imx8m_clk_composite_flags(const char *name, mux->shift = PCG_PCS_SHIFT; mux->mask = PCG_PCS_MASK; mux->num_parents = num_parents; - mux->flags = flags; mux->parent_names = parent_names; div = kzalloc(sizeof(*div), GFP_KERNEL); @@ -145,7 +144,7 @@ struct clk *imx8m_clk_composite_flags(const char *name, div->reg = reg; div->shift = PCG_PREDIV_SHIFT; div->width = PCG_PREDIV_WIDTH; - div->flags = CLK_DIVIDER_ROUND_CLOSEST | flags; + div->flags = CLK_DIVIDER_ROUND_CLOSEST; gate = kzalloc(sizeof(*gate), GFP_KERNEL); if (!gate) @@ -153,7 +152,6 @@ struct clk *imx8m_clk_composite_flags(const char *name, gate->reg = reg; gate->bit_idx = PCG_CGC_SHIFT; - gate->flags = flags; clk = clk_register_composite(NULL, name, parent_names, num_parents, -- 2.43.0
[PATCH] board: phytec: k3: k3_ddrss_patch: Add ddr phy reg count
Add and use the correct number of ddr phy registers to update the corresponding settings. Fixes: cbf5c99ef317 ("board: phytec: common: Introduce a method to inject DDR timings deltas") Signed-off-by: Dominik Haller --- board/phytec/common/k3/k3_ddrss_patch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/board/phytec/common/k3/k3_ddrss_patch.c b/board/phytec/common/k3/k3_ddrss_patch.c index 39f7be8dc922..5afe5a20c7f3 100644 --- a/board/phytec/common/k3/k3_ddrss_patch.c +++ b/board/phytec/common/k3/k3_ddrss_patch.c @@ -12,6 +12,7 @@ #ifdef CONFIG_K3_AM64_DDRSS #define LPDDR4_INTR_CTL_REG_COUNT (423U) #define LPDDR4_INTR_PHY_INDEP_REG_COUNT (345U) +#define LPDDR4_INTR_PHY_REG_COUNT (1406U) #endif static int fdt_setprop_inplace_idx_u32(void *fdt, int nodeoffset, @@ -54,7 +55,7 @@ int fdt_apply_ddrss_timings_patch(void *fdt, struct ddrss *ddrss) return ret; } - for (i = 0; i < LPDDR4_INTR_PHY_INDEP_REG_COUNT; i++) + for (i = 0; i < LPDDR4_INTR_PHY_REG_COUNT; i++) for (j = 0; j < ddrss->phy_regs_num; j++) if (i == ddrss->phy_regs[j].off) { ret = fdt_setprop_inplace_idx_u32(fdt, -- 2.25.1
Re: [PATCH 0/2] Import environment variables from FIT configuration
Hi Lukas, On 7/2/24 8:48 AM, lukas.funke-...@weidmueller.com wrote: From: Lukas Funke This series enables U-Boot to import environment variables from the selectd FIT configuration. One use-case is that the overall build process enriches the FIT configuration node with dm-verity information which should be injected into the kernel commandline. U-Boot will then read these (possibly signed) environment variables and put them into the actual Kernel commandline using variable replacement (see CONFIG_BOOTARGS_SUBST). Example: Config: CONFIG_BOOTARGS_SUBST=y CONFIG_ENV_IMPORT_FIT_CONF=y FIT: configurations { default = "conf-1"; conf-1 { kernel = "kernel-1"; fdt = "fdt-1"; env,dm-verity-args = "dm-mod.create=..."; env,bar = "someothervalue"; }; }; U-Boot cmdline: => env set bootargs="rootfstype=squashfs root=/dev/xyz ${dm-verity-args} ro" => boot Kernel cmdline: Kernel command line: rootfstype=squashfs ... dm-mod.create= ... I think FIT supports storing U-Boot scripts and running those via `source` command (usually the file extension is .scr). I do not know if there's support for automatically loading this .scr as part of a config node though, but if there isn't I guess it'd make more sense to support this case than to come up with yet another implementation? What do you think? Cheers, Quentin
Re: [PATCH] imx: hab: Make imx_hab_is_enabled dependent on FIELD_RETURN
Hi Paul, On 7/1/2024 8:39 PM, Paul Geurts wrote: Hi Ye, Hi Paul, On 6/26/2024 3:17 PM, Paul Geurts wrote: Hi, Thanks for the feedback. Hi Paul, On 6/24/2024 8:09 PM, Fabio Estevam wrote: Hi Paul, On Fri, Jun 21, 2024 at 10:06 AM Paul Geurts wrote: -struct imx_sec_config_fuse_t { +struct imx_fuse_t { Please make the struct renaming a separate patch. Peng Fan, Ye Li, Could you please help review this patch? Thanks Can you take a look iMX8MP FIELD_RETURN fuse, I think it does not have 1 bit but 8 bits which requires to burn a sequence. Only when the bits sequence is matched, the field return can work. So checking the bit 0 is not enough. Are you sure about that? The security reference manual (IMX8MPSRM) says in Table 5-5 that the FIELD_RETURN fuse is located on fuse 0x630[0], which is a single bit. Also, the "Chip Security Lifecycle" section (2.15.1) says the following: FEILD RETURN (SEC_CONFIG[1] fuse = 1 and FIELD_RETURN fuse = 1) Are you maybe confusing the FIELD_RETURN fuse with the FIELD_RETURN_LOCK sticky bit? clearing the lock bit _is_ quite the procedure, but it is unrelated to U-Boot, as this is done by ROM code through CSF. I tested this on an i.MX8M Plus and it seems to work fine. I know the steps for field return. What I mean is the FIELD_RETURN fuse. It is true that security RM mentions it as you quote. But from 8MP fuse map and ROM codes, I get different things. FIELD_RETURN 8-bit code. FIELD_RETURN = 0, is non-field return mode, functional/secure mode. FIELD_RETURN = Matching Sequence, device is in field_return mode FIELD_RETURN != Matching Sequence, device asserts security violation That is indeed different from what is mentioned in documentation. I have asked our NXP FAE about the discrepancy and I will adjust the code if needed. Thanks for confirm. I also cross checked with teams. 8MP must burn a pattern. Otherwise HAB won't covert to field return. Additional, do you think it is very necessary to add this patch set? Because field return is a pure debug feature, it won't be deployed on productions. The developers working on field return parts can re-build u-boot with CONFIG_IMX_HAB disabled. This patch may introduce risk to HAB in some sense, especially for productions. One mistake would make unsigned image bypass authentication result. Best regards, Ye Li However, I'm not sure how is it implemented in HAB. Since you have tested 8M plus, can you confirm the closed part is successfully converted to field return and can boot without signing? Maybe I did something wrong while testing. I will retest it on a new board when I have received some more information from NXP. Best regards, Ye Li