Re: [PATCH 1/4] lib: sha256: add feature sha256_hmac
Hi Tom, Le 17/07/2024 à 19:58, Tom Rini a écrit : On Wed, Jul 17, 2024 at 07:08:27PM +0200, Philippe REYNES wrote: Hi Peter, Le 16/07/2024 à 18:56, Peter Robinson a écrit : This Mail comes from Outside of SoftAtHome: Do not answer, click links or open attachments unless you recognize the sender and know the content is safe. Hi Philippe, It might be useful to have a cover letter explaining what the plans for this code are, great that there are tests but adding code in without it being used isn't always a feature so a cover letter with some details often helps with the context. You right, I should have added a cover letter. My goal was to add key derivation and use this feature to fill a key manager, and then provide those keys (or some of them) to the kernel. So the kernel may (for example) add them in the KRS. Do you know if there are some work or interest in a key manager for u-boot please ? Also if you're not aware there's work to integrate MBedTLS [1] and I'm not sure if that also may provide the functionality. Good point, I miss it. MBedTLS has the feature of key derivation. https://mbed-tls.readthedocs.io/en/latest/getting_started/psa/#deriving-a-new-key-from-an-existing-key So unless someone wants to use key derivation without all MBedTLS, this serie is not very useful. Unless you object, I would really prefer to have this been a feature U-Boot only has with MBedTLS enabled as one of the goals with that integration is to have U-Boot leverage existing and well audited/monitored codebases for security sensitive code paths when possible. I don't object, I also think that a feature should be only implemented once. I just have a question on this topic, I am planning to use a key manager in u-boot. Do you think a key manager would be nice in u-boot, and if someone has already planned to work on this topic please ? Regards, Philippe
Re: [PATCH 1/4] lib: sha256: add feature sha256_hmac
Hi Peter, Le 16/07/2024 à 18:56, Peter Robinson a écrit : This Mail comes from Outside of SoftAtHome: Do not answer, click links or open attachments unless you recognize the sender and know the content is safe. Hi Philippe, It might be useful to have a cover letter explaining what the plans for this code are, great that there are tests but adding code in without it being used isn't always a feature so a cover letter with some details often helps with the context. You right, I should have added a cover letter. My goal was to add key derivation and use this feature to fill a key manager, and then provide those keys (or some of them) to the kernel. So the kernel may (for example) add them in the KRS. Do you know if there are some work or interest in a key manager for u-boot please ? Also if you're not aware there's work to integrate MBedTLS [1] and I'm not sure if that also may provide the functionality. Good point, I miss it. MBedTLS has the feature of key derivation. https://mbed-tls.readthedocs.io/en/latest/getting_started/psa/#deriving-a-new-key-from-an-existing-key So unless someone wants to use key derivation without all MBedTLS, this serie is not very useful. Peter Regards, Philippe [1] https://lists.denx.de/pipermail/u-boot/2024-July/557832.html On Tue, 16 Jul 2024 at 16:16, Philippe Reynes wrote: Adds the support of the hmac based on sha256. This implementation is based on rfc2104. Signed-off-by: Philippe Reynes --- include/u-boot/sha256.h | 4 lib/sha256.c| 40 2 files changed, 44 insertions(+) diff --git a/include/u-boot/sha256.h b/include/u-boot/sha256.h index a4fe176c0b4..7aa4c54d0d4 100644 --- a/include/u-boot/sha256.h +++ b/include/u-boot/sha256.h @@ -24,4 +24,8 @@ void sha256_finish(sha256_context * ctx, uint8_t digest[SHA256_SUM_LEN]); void sha256_csum_wd(const unsigned char *input, unsigned int ilen, unsigned char *output, unsigned int chunk_sz); +void sha256_hmac(const unsigned char *key, int keylen, +const unsigned char *input, unsigned int ilen, +unsigned char *output); + #endif /* _SHA256_H */ diff --git a/lib/sha256.c b/lib/sha256.c index 665ba6f152e..64f6b48974b 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -298,3 +298,43 @@ void sha256_csum_wd(const unsigned char *input, unsigned int ilen, sha256_finish(&ctx, output); } + +/* + * Output = HMAC-SHA-256( input buffer, hmac key ) + */ +void sha256_hmac(const unsigned char *key, int keylen, +const unsigned char *input, unsigned int ilen, +unsigned char *output) +{ + int i; + sha256_context ctx; + unsigned char k_ipad[64]; + unsigned char k_opad[64]; + unsigned char tmpbuf[32]; + + memset(k_ipad, 0x36, 64); + memset(k_opad, 0x5C, 64); + + for (i = 0; i < keylen; i++) { + if (i >= 64) + break; + + k_ipad[i] ^= key[i]; + k_opad[i] ^= key[i]; + } + + sha256_starts(&ctx); + sha256_update(&ctx, k_ipad, 64); + sha256_update(&ctx, input, ilen); + sha256_finish(&ctx, tmpbuf); + + sha256_starts(&ctx); + sha256_update(&ctx, k_opad, 64); + sha256_update(&ctx, tmpbuf, 32); + sha256_finish(&ctx, output); + + memset(k_ipad, 0, 64); + memset(k_opad, 0, 64); + memset(tmpbuf, 0, 32); + memset(&ctx, 0, sizeof(sha256_context)); +} -- 2.25.1
[PATCH 4/4] test: lib: add test for key derivation
Adds a test for the function sha256_hkdf. Signed-off-by: Philippe Reynes --- test/lib/Makefile | 2 +- test/lib/test_sha256_hkdf.c | 104 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 test/lib/test_sha256_hkdf.c diff --git a/test/lib/Makefile b/test/lib/Makefile index 170c5a539ca..1b7baa696db 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -19,7 +19,7 @@ obj-$(CONFIG_ERRNO_STR) += test_errno_str.o obj-$(CONFIG_UT_LIB_ASN1) += asn1.o obj-$(CONFIG_UT_LIB_RSA) += rsa.o obj-$(CONFIG_AES) += test_aes.o -obj-$(CONFIG_SHA256) += test_sha256_hmac.o +obj-$(CONFIG_SHA256) += test_sha256_hmac.o test_sha256_hkdf.o obj-$(CONFIG_GETOPT) += getopt.o obj-$(CONFIG_CRC8) += test_crc8.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o diff --git a/test/lib/test_sha256_hkdf.c b/test/lib/test_sha256_hkdf.c new file mode 100644 index 000..ca173a13afc --- /dev/null +++ b/test/lib/test_sha256_hkdf.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2024 Philippe Reynes + * + * Unit tests for sha256_hkdf functions + */ + +#include +#include +#include +#include +#include + +struct test_sha256_hkdf_s { + unsigned char *salt; + int saltlen; + unsigned char *ikm; + int ikmlen; + unsigned char *info; + int infolen; + unsigned char *expected; + int expectedlen; +}; + +/* + * data comes from: + * https://www.rfc-editor.org/rfc/rfc5869 + */ +static unsigned char salt_test1[] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c }; + +static unsigned char ikm_test1[] = { + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; + +static unsigned char info_test1[] = { + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; + +static unsigned char expected_test1[] = { + 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, + 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, + 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c, + 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, + 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, + 0x58, 0x65 }; + +static struct test_sha256_hkdf_s test_sha256_hkdf[] = { + { + .salt = salt_test1, + .saltlen = sizeof(salt_test1), + .ikm = ikm_test1, + .ikmlen = sizeof(ikm_test1), + .info = info_test1, + .infolen = sizeof(info_test1), + .expected = expected_test1, + .expectedlen = sizeof(expected_test1), + }, +}; + +static int _lib_test_sha256_hkdf_run(struct unit_test_state *uts, +unsigned char *salt, int saltlen, +unsigned char *ikm, int ikmlen, +unsigned char *info, int infolen, +unsigned char *expected, int expectedlen) +{ + unsigned char output[64]; + + sha256_hkdf(salt, saltlen, ikm, ikmlen, info, infolen, output, expectedlen); + ut_asserteq_mem(expected, output, expectedlen); + + return 0; +} + +static int lib_test_sha256_hkdf_run(struct unit_test_state *uts, + struct test_sha256_hkdf_s *test) +{ + unsigned char *salt = test->salt; + int saltlen = test->saltlen; + unsigned char *ikm = test->ikm; + int ikmlen = test->ikmlen; + unsigned char *info = test->info; + int infolen = test->infolen; + unsigned char *expected = test->expected; + int expectedlen = test->expectedlen; + + return _lib_test_sha256_hkdf_run(uts, salt, saltlen, ikm, ikmlen, +info, infolen, expected, expectedlen); +} + +static int lib_test_sha256_hkdf(struct unit_test_state *uts) +{ + int i, ret = 0; + + for (i = 0; i < ARRAY_SIZE(test_sha256_hkdf); i++) { + ret = lib_test_sha256_hkdf_run(uts, &test_sha256_hkdf[i]); + if (ret) + break; + } + + return ret; +} + +LIB_TEST(lib_test_sha256_hkdf, 0); -- 2.25.1
[PATCH 1/4] lib: sha256: add feature sha256_hmac
Adds the support of the hmac based on sha256. This implementation is based on rfc2104. Signed-off-by: Philippe Reynes --- include/u-boot/sha256.h | 4 lib/sha256.c| 40 2 files changed, 44 insertions(+) diff --git a/include/u-boot/sha256.h b/include/u-boot/sha256.h index a4fe176c0b4..7aa4c54d0d4 100644 --- a/include/u-boot/sha256.h +++ b/include/u-boot/sha256.h @@ -24,4 +24,8 @@ void sha256_finish(sha256_context * ctx, uint8_t digest[SHA256_SUM_LEN]); void sha256_csum_wd(const unsigned char *input, unsigned int ilen, unsigned char *output, unsigned int chunk_sz); +void sha256_hmac(const unsigned char *key, int keylen, +const unsigned char *input, unsigned int ilen, +unsigned char *output); + #endif /* _SHA256_H */ diff --git a/lib/sha256.c b/lib/sha256.c index 665ba6f152e..64f6b48974b 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -298,3 +298,43 @@ void sha256_csum_wd(const unsigned char *input, unsigned int ilen, sha256_finish(&ctx, output); } + +/* + * Output = HMAC-SHA-256( input buffer, hmac key ) + */ +void sha256_hmac(const unsigned char *key, int keylen, +const unsigned char *input, unsigned int ilen, +unsigned char *output) +{ + int i; + sha256_context ctx; + unsigned char k_ipad[64]; + unsigned char k_opad[64]; + unsigned char tmpbuf[32]; + + memset(k_ipad, 0x36, 64); + memset(k_opad, 0x5C, 64); + + for (i = 0; i < keylen; i++) { + if (i >= 64) + break; + + k_ipad[i] ^= key[i]; + k_opad[i] ^= key[i]; + } + + sha256_starts(&ctx); + sha256_update(&ctx, k_ipad, 64); + sha256_update(&ctx, input, ilen); + sha256_finish(&ctx, tmpbuf); + + sha256_starts(&ctx); + sha256_update(&ctx, k_opad, 64); + sha256_update(&ctx, tmpbuf, 32); + sha256_finish(&ctx, output); + + memset(k_ipad, 0, 64); + memset(k_opad, 0, 64); + memset(tmpbuf, 0, 32); + memset(&ctx, 0, sizeof(sha256_context)); +} -- 2.25.1
[PATCH 2/4] test: lib: add test for sha256_hamc
Adds a test for the function sha256_hmac Signed-off-by: Philippe Reynes --- test/lib/Makefile | 1 + test/lib/test_sha256_hmac.c | 108 2 files changed, 109 insertions(+) create mode 100644 test/lib/test_sha256_hmac.c diff --git a/test/lib/Makefile b/test/lib/Makefile index e75a263e6a4..170c5a539ca 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_ERRNO_STR) += test_errno_str.o obj-$(CONFIG_UT_LIB_ASN1) += asn1.o obj-$(CONFIG_UT_LIB_RSA) += rsa.o obj-$(CONFIG_AES) += test_aes.o +obj-$(CONFIG_SHA256) += test_sha256_hmac.o obj-$(CONFIG_GETOPT) += getopt.o obj-$(CONFIG_CRC8) += test_crc8.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o diff --git a/test/lib/test_sha256_hmac.c b/test/lib/test_sha256_hmac.c new file mode 100644 index 000..473922bd9b0 --- /dev/null +++ b/test/lib/test_sha256_hmac.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2024 Philippe Reynes + * + * Unit tests for sha256_hmac functions + */ + +#include +#include +#include +#include +#include + +struct test_sha256_hmac_s { + unsigned char *key; + int keylen; + unsigned char *input; + int ilen; + unsigned char *expected; +}; + +/* + * data comes from: + * https://datatracker.ietf.org/doc/html/rfc4231 + */ +static unsigned char key_test1[] = { + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; + +static unsigned char input_test1[] = { + 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 }; + +static unsigned char expected_test1[] = { + 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53, + 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b, + 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7, + 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7 }; + +static unsigned char key_test2[] = { 0x4a, 0x65, 0x66, 0x65 }; + +static unsigned char input_test2[] = { + 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }; + +static unsigned char expected_test2[] = { + 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e, + 0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7, + 0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83, + 0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43 }; + +static struct test_sha256_hmac_s test_sha256_hmac[] = { + { + .key = key_test1, + .keylen = sizeof(key_test1), + .input = input_test1, + .ilen = sizeof(input_test1), + .expected = expected_test1, + }, + { + .key = key_test2, + .keylen = sizeof(key_test2), + .input = input_test2, + .ilen = sizeof(input_test2), + .expected = expected_test2, + }, +}; + +static int _lib_test_sha256_hmac_run(struct unit_test_state *uts, +unsigned char *key, int keylen, +unsigned char *input, int ilen, +unsigned char *expected) +{ + unsigned char output[32]; + + sha256_hmac(key, keylen, input, ilen, output); + ut_asserteq_mem(expected, output, 32); + + return 0; +} + +static int lib_test_sha256_hmac_run(struct unit_test_state *uts, + struct test_sha256_hmac_s *test) +{ + unsigned char *key = test->key; + int keylen = test->keylen; + unsigned char *input = test->input; + int ilen = test->ilen; + unsigned char *expected = test->expected; + + return _lib_test_sha256_hmac_run(uts, key, keylen, input, ilen, expected); +} + +static int lib_test_sha256_hmac(struct unit_test_state *uts) +{ + int i, ret = 0; + + for (i = 0; i < ARRAY_SIZE(test_sha256_hmac); i++) { + ret = lib_test_sha256_hmac_run(uts, &test_sha256_hmac[i]); + if (ret) + break; + } + + return ret; +} + +LIB_TEST(lib_test_sha256_hmac, 0); -- 2.25.1
[PATCH 3/4] lib: sha256: add support of key derivation
Adds the support of key derivation using the scheme hkdf. This scheme is defined in rfc5869. Signed-off-by: Philippe Reynes --- include/u-boot/sha256.h | 8 lib/sha256.c| 42 + 2 files changed, 50 insertions(+) diff --git a/include/u-boot/sha256.h b/include/u-boot/sha256.h index 7aa4c54d0d4..46d20bf9b79 100644 --- a/include/u-boot/sha256.h +++ b/include/u-boot/sha256.h @@ -6,6 +6,9 @@ #define SHA256_SUM_LEN 32 #define SHA256_DER_LEN 19 +#define SHA256_HKDF_MAX_INFO_LEN 256 +#define SHA256_HKDF_MAX_DATA_LEN (SHA256_HKDF_MAX_INFO_LEN + SHA256_SUM_LEN + 1) + extern const uint8_t sha256_der_prefix[]; /* Reset watchdog each time we process this many bytes */ @@ -28,4 +31,9 @@ void sha256_hmac(const unsigned char *key, int keylen, const unsigned char *input, unsigned int ilen, unsigned char *output); +void sha256_hkdf(const unsigned char *salt, int saltlen, +const unsigned char *ikm, int ikmlen, +const unsigned char *info, int infolen, +unsigned char *output, int outputlen); + #endif /* _SHA256_H */ diff --git a/lib/sha256.c b/lib/sha256.c index 64f6b48974b..9a4fd452cd8 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -338,3 +338,45 @@ void sha256_hmac(const unsigned char *key, int keylen, memset(tmpbuf, 0, 32); memset(&ctx, 0, sizeof(sha256_context)); } + +static void sha256_hkdf_expand(const unsigned char *prk, int prklen, + const unsigned char *info, int infolen, + unsigned char *okm, int okmlen) +{ + unsigned char t[SHA256_SUM_LEN]; + unsigned char data[SHA256_HKDF_MAX_DATA_LEN]; + int i, l = (okmlen + SHA256_SUM_LEN - 1) / SHA256_SUM_LEN; + int tlen, datalen, len, offset = 0; + + for (i = 1; i <= l; i++) { + tlen = (i == 1) ? 0 : SHA256_SUM_LEN; + memcpy(&data[0], &t[0], tlen); + datalen = tlen; + memcpy(&data[datalen], info, infolen); + datalen += infolen; + data[datalen] = i; + datalen++; + + sha256_hmac(prk, prklen, data, datalen, t); + + len = (okmlen > SHA256_SUM_LEN) ? SHA256_SUM_LEN : okmlen; + memcpy(&okm[offset], t, len); + offset += len; + okmlen -= len; + } +} + +void sha256_hkdf(const unsigned char *salt, int saltlen, +const unsigned char *ikm, int ikmlen, +const unsigned char *info, int infolen, +unsigned char *output, int outputlen) +{ + unsigned char prk[SHA256_SUM_LEN]; + + /* Step 1: Extract */ + sha256_hmac(salt, saltlen, ikm, ikmlen, prk); + + /* Step 2: Expand */ + sha256_hkdf_expand(prk, SHA256_SUM_LEN, info, infolen, + output, outputlen); +} -- 2.25.1
Re: [PATCH] drivers: led: bcm6858: do not use null label to find the top
Hi Tom, Le 18/07/2023 à 15:43, Tom Rini a écrit : On Tue, Jul 18, 2023 at 11:20:52AM +0200, Philippe REYNES wrote: Hi Tom, For this patch, I see that it is accepted on patchwork: https://patchwork.ozlabs.org/project/uboot/patch/20230623163642.241034-1-philippe.rey...@softathome.com/ But I don't see it in master/next. Is it a "miss" or I have to update it please ? This commit: https://source.denx.de/u-boot/u-boot/-/commit/910b01c27c0499ae8f84104a0db745dd3a056c04 is that patch, yes? No, it is not this patch I have sent two patches: one for bcm6753: https://patchwork.ozlabs.org/project/uboot/patch/20230629092523.448644-1-philippe.rey...@softathome.com/ => I see it in the branch master: https://source.denx.de/u-boot/u-boot/-/commit/910b01c27c0499ae8f84104a0db745dd3a056c04 one for 6858: https://patchwork.ozlabs.org/project/uboot/patch/20230623163642.241034-1-philippe.rey...@softathome.com/ => I don't see this patch in the branch master Note: there are still some others led driver that are broken: - bcm6328 - bcm6358 - cortina Regards, Philippe Regards, Philippe Le 23/06/2023 à 18:36, Philippe Reynes a écrit : This driver considers that a node with an empty label is the top. But the led class has changed, if a label is not provided for a led, the label is filed with the node name. So we update this driver to use a wrapper to manage the top led node. Signed-off-by: Philippe Reynes --- drivers/led/led_bcm6858.c | 122 -- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/drivers/led/led_bcm6858.c b/drivers/led/led_bcm6858.c index 6b3698674b..397dc0d869 100644 --- a/drivers/led/led_bcm6858.c +++ b/drivers/led/led_bcm6858.c @@ -180,63 +180,71 @@ static const struct led_ops bcm6858_led_ops = { static int bcm6858_led_probe(struct udevice *dev) { - struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); - - /* Top-level LED node */ - if (!uc_plat->label) { - void __iomem *regs; - u32 set_bits = 0; - - regs = dev_remap_addr(dev); - if (!regs) - return -EINVAL; - - if (dev_read_bool(dev, "brcm,serial-led-msb-first")) - set_bits |= LED_CTRL_SERIAL_LED_MSB_FIRST; - if (dev_read_bool(dev, "brcm,serial-led-en-pol")) - set_bits |= LED_CTRL_SERIAL_LED_EN_POL; - if (dev_read_bool(dev, "brcm,serial-led-clk-pol")) - set_bits |= LED_CTRL_SERIAL_LED_CLK_POL; - if (dev_read_bool(dev, "brcm,serial-led-data-ppol")) - set_bits |= LED_CTRL_SERIAL_LED_DATA_PPOL; - if (dev_read_bool(dev, "brcm,led-test-mode")) - set_bits |= LED_CTRL_LED_TEST_MODE; - - clrsetbits_32(regs + LED_CTRL_REG, ~0, set_bits); - } else { - struct bcm6858_led_priv *priv = dev_get_priv(dev); - void __iomem *regs; - unsigned int pin, brightness; - - regs = dev_remap_addr(dev_get_parent(dev)); - if (!regs) - return -EINVAL; - - pin = dev_read_u32_default(dev, "reg", LEDS_MAX); - if (pin >= LEDS_MAX) - return -EINVAL; - - priv->regs = regs; - priv->pin = pin; - - /* this led is managed by software */ - clrbits_32(regs + LED_HW_LED_EN_REG, 1 << pin); - - /* configure the polarity */ - if (dev_read_bool(dev, "active-low")) - clrbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); - else - setbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + struct bcm6858_led_priv *priv = dev_get_priv(dev); + void __iomem *regs; + unsigned int pin, brightness; + + regs = dev_remap_addr(dev_get_parent(dev)); + if (!regs) + return -EINVAL; + + pin = dev_read_u32_default(dev, "reg", LEDS_MAX); + if (pin >= LEDS_MAX) + return -EINVAL; + + priv->regs = regs; + priv->pin = pin; + + /* this led is managed by software */ + clrbits_32(regs + LED_HW_LED_EN_REG, 1 << pin); - brightness = dev_read_u32_default(dev, "default-brightness", + /* configure the polarity */ + if (dev_read_bool(dev, "active-low")) + clrbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + else + setbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + + brightness = dev_read_u32_default(dev, "default-brightness", LEDS_MAX_BRIGHTNESS); - led_set_brightness(dev, brightness); - } + led_set_brightness(dev, brightness); return 0; } -static int bcm6858_led_bind(stru
Re: [PATCH] drivers: led: bcm6858: do not use null label to find the top
Hi Tom, For this patch, I see that it is accepted on patchwork: https://patchwork.ozlabs.org/project/uboot/patch/20230623163642.241034-1-philippe.rey...@softathome.com/ But I don't see it in master/next. Is it a "miss" or I have to update it please ? Regards, Philippe Le 23/06/2023 à 18:36, Philippe Reynes a écrit : This driver considers that a node with an empty label is the top. But the led class has changed, if a label is not provided for a led, the label is filed with the node name. So we update this driver to use a wrapper to manage the top led node. Signed-off-by: Philippe Reynes --- drivers/led/led_bcm6858.c | 122 -- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/drivers/led/led_bcm6858.c b/drivers/led/led_bcm6858.c index 6b3698674b..397dc0d869 100644 --- a/drivers/led/led_bcm6858.c +++ b/drivers/led/led_bcm6858.c @@ -180,63 +180,71 @@ static const struct led_ops bcm6858_led_ops = { static int bcm6858_led_probe(struct udevice *dev) { - struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); - - /* Top-level LED node */ - if (!uc_plat->label) { - void __iomem *regs; - u32 set_bits = 0; - - regs = dev_remap_addr(dev); - if (!regs) - return -EINVAL; - - if (dev_read_bool(dev, "brcm,serial-led-msb-first")) - set_bits |= LED_CTRL_SERIAL_LED_MSB_FIRST; - if (dev_read_bool(dev, "brcm,serial-led-en-pol")) - set_bits |= LED_CTRL_SERIAL_LED_EN_POL; - if (dev_read_bool(dev, "brcm,serial-led-clk-pol")) - set_bits |= LED_CTRL_SERIAL_LED_CLK_POL; - if (dev_read_bool(dev, "brcm,serial-led-data-ppol")) - set_bits |= LED_CTRL_SERIAL_LED_DATA_PPOL; - if (dev_read_bool(dev, "brcm,led-test-mode")) - set_bits |= LED_CTRL_LED_TEST_MODE; - - clrsetbits_32(regs + LED_CTRL_REG, ~0, set_bits); - } else { - struct bcm6858_led_priv *priv = dev_get_priv(dev); - void __iomem *regs; - unsigned int pin, brightness; - - regs = dev_remap_addr(dev_get_parent(dev)); - if (!regs) - return -EINVAL; - - pin = dev_read_u32_default(dev, "reg", LEDS_MAX); - if (pin >= LEDS_MAX) - return -EINVAL; - - priv->regs = regs; - priv->pin = pin; - - /* this led is managed by software */ - clrbits_32(regs + LED_HW_LED_EN_REG, 1 << pin); - - /* configure the polarity */ - if (dev_read_bool(dev, "active-low")) - clrbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); - else - setbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + struct bcm6858_led_priv *priv = dev_get_priv(dev); + void __iomem *regs; + unsigned int pin, brightness; + + regs = dev_remap_addr(dev_get_parent(dev)); + if (!regs) + return -EINVAL; + + pin = dev_read_u32_default(dev, "reg", LEDS_MAX); + if (pin >= LEDS_MAX) + return -EINVAL; + + priv->regs = regs; + priv->pin = pin; + + /* this led is managed by software */ + clrbits_32(regs + LED_HW_LED_EN_REG, 1 << pin); - brightness = dev_read_u32_default(dev, "default-brightness", + /* configure the polarity */ + if (dev_read_bool(dev, "active-low")) + clrbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + else + setbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + + brightness = dev_read_u32_default(dev, "default-brightness", LEDS_MAX_BRIGHTNESS); - led_set_brightness(dev, brightness); - } + led_set_brightness(dev, brightness); return 0; } -static int bcm6858_led_bind(struct udevice *parent) +U_BOOT_DRIVER(bcm6858_led) = { + .name = "bcm6858-led", + .id = UCLASS_LED, + .probe = bcm6858_led_probe, + .priv_auto = sizeof(struct bcm6858_led_priv), + .ops = &bcm6858_led_ops, +}; + +static int bcm6858_led_wrap_probe(struct udevice *dev) +{ + void __iomem *regs; + u32 set_bits = 0; + + regs = dev_remap_addr(dev); + if (!regs) + return -EINVAL; + + if (dev_read_bool(dev, "brcm,serial-led-msb-first")) + set_bits |= LED_CTRL_SERIAL_LED_MSB_FIRST; + if (dev_read_bool(dev, "brcm,serial-led-en-pol")) + set_bits |= LED_CTRL_SERI
[PATCH] drivers: led: bcm6753: do not use null label to find the top
This driver considers that a node with an empty label is the top. But the led class has changed, if a label is not provided for a led, the label is filed with the node name. So we update this driver to use a wrapper to manage the top led node. Signed-off-by: Philippe Reynes --- drivers/led/led_bcm6753.c | 114 -- 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/drivers/led/led_bcm6753.c b/drivers/led/led_bcm6753.c index 88b650cbfc..2466d93011 100644 --- a/drivers/led/led_bcm6753.c +++ b/drivers/led/led_bcm6753.c @@ -174,57 +174,65 @@ static const struct led_ops bcm6753_led_ops = { static int bcm6753_led_probe(struct udevice *dev) { - struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); - - /* Top-level LED node */ - if (!uc_plat->label) { - void __iomem *regs; - u32 set_bits = 0; - - regs = dev_remap_addr(dev); - if (!regs) - return -EINVAL; - - if (dev_read_bool(dev, "brcm,serial-led-msb-first")) - set_bits |= CLED_CTRL_SERIAL_LED_MSB_FIRST; - if (dev_read_bool(dev, "brcm,serial-led-en-pol")) - set_bits |= CLED_CTRL_SERIAL_LED_EN_POL; - if (dev_read_bool(dev, "brcm,serial-led-clk-pol")) - set_bits |= CLED_CTRL_SERIAL_LED_CLK_POL; - if (dev_read_bool(dev, "brcm,serial-led-data-ppol")) - set_bits |= CLED_CTRL_SERIAL_LED_DATA_PPOL; - - clrsetbits_32(regs + CLED_CTRL_REG, CLED_CTRL_MASK, set_bits); - } else { - struct bcm6753_led_priv *priv = dev_get_priv(dev); - void __iomem *regs; - unsigned int pin; - - regs = dev_remap_addr(dev_get_parent(dev)); - if (!regs) - return -EINVAL; - - pin = dev_read_u32_default(dev, "reg", LEDS_MAX); - if (pin >= LEDS_MAX) - return -EINVAL; - - priv->regs = regs; - priv->pin = pin; - - /* this led is managed by software */ - clrbits_32(regs + CLED_HW_LED_EN_REG, 1 << pin); - - /* configure the polarity */ - if (dev_read_bool(dev, "active-low")) - clrbits_32(regs + CLED_PLED_OP_PPOL_REG, 1 << pin); - else - setbits_32(regs + CLED_PLED_OP_PPOL_REG, 1 << pin); - } + struct bcm6753_led_priv *priv = dev_get_priv(dev); + void __iomem *regs; + unsigned int pin; + + regs = dev_remap_addr(dev_get_parent(dev)); + if (!regs) + return -EINVAL; + + pin = dev_read_u32_default(dev, "reg", LEDS_MAX); + if (pin >= LEDS_MAX) + return -EINVAL; + + priv->regs = regs; + priv->pin = pin; + + /* this led is managed by software */ + clrbits_32(regs + CLED_HW_LED_EN_REG, 1 << pin); + + /* configure the polarity */ + if (dev_read_bool(dev, "active-low")) + clrbits_32(regs + CLED_PLED_OP_PPOL_REG, 1 << pin); + else + setbits_32(regs + CLED_PLED_OP_PPOL_REG, 1 << pin); return 0; } -static int bcm6753_led_bind(struct udevice *parent) +U_BOOT_DRIVER(bcm6753_led) = { + .name = "bcm6753-led", + .id = UCLASS_LED, + .probe = bcm6753_led_probe, + .priv_auto = sizeof(struct bcm6753_led_priv), + .ops = &bcm6753_led_ops, +}; + +static int bcm6753_led_wrap_probe(struct udevice *dev) +{ + void __iomem *regs; + u32 set_bits = 0; + + regs = dev_remap_addr(dev); + if (!regs) + return -EINVAL; + + if (dev_read_bool(dev, "brcm,serial-led-msb-first")) + set_bits |= CLED_CTRL_SERIAL_LED_MSB_FIRST; + if (dev_read_bool(dev, "brcm,serial-led-en-pol")) + set_bits |= CLED_CTRL_SERIAL_LED_EN_POL; + if (dev_read_bool(dev, "brcm,serial-led-clk-pol")) + set_bits |= CLED_CTRL_SERIAL_LED_CLK_POL; + if (dev_read_bool(dev, "brcm,serial-led-data-ppol")) + set_bits |= CLED_CTRL_SERIAL_LED_DATA_PPOL; + + clrsetbits_32(regs + CLED_CTRL_REG, CLED_CTRL_MASK, set_bits); + + return 0; +} + +static int bcm6753_led_wrap_bind(struct udevice *parent) { ofnode node; @@ -247,12 +255,10 @@ static const struct udevice_id bcm6753_led_ids[] = { { /* sentinel */ } }; -U_BOOT_DRIVER(bcm6753_led) = { - .name = "bcm6753-led", - .id = UCLASS_LED, +U_BOOT_DRIVER(bcm6753_led_wrap) = { + .name = "bcm6753_led_wrap", + .id = UCLASS_NOP, .of_match = bcm6753_led_ids, - .bind = bcm6753_
[PATCH] drivers: led: bcm6858: do not use null label to find the top
This driver considers that a node with an empty label is the top. But the led class has changed, if a label is not provided for a led, the label is filed with the node name. So we update this driver to use a wrapper to manage the top led node. Signed-off-by: Philippe Reynes --- drivers/led/led_bcm6858.c | 122 -- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/drivers/led/led_bcm6858.c b/drivers/led/led_bcm6858.c index 6b3698674b..397dc0d869 100644 --- a/drivers/led/led_bcm6858.c +++ b/drivers/led/led_bcm6858.c @@ -180,63 +180,71 @@ static const struct led_ops bcm6858_led_ops = { static int bcm6858_led_probe(struct udevice *dev) { - struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); - - /* Top-level LED node */ - if (!uc_plat->label) { - void __iomem *regs; - u32 set_bits = 0; - - regs = dev_remap_addr(dev); - if (!regs) - return -EINVAL; - - if (dev_read_bool(dev, "brcm,serial-led-msb-first")) - set_bits |= LED_CTRL_SERIAL_LED_MSB_FIRST; - if (dev_read_bool(dev, "brcm,serial-led-en-pol")) - set_bits |= LED_CTRL_SERIAL_LED_EN_POL; - if (dev_read_bool(dev, "brcm,serial-led-clk-pol")) - set_bits |= LED_CTRL_SERIAL_LED_CLK_POL; - if (dev_read_bool(dev, "brcm,serial-led-data-ppol")) - set_bits |= LED_CTRL_SERIAL_LED_DATA_PPOL; - if (dev_read_bool(dev, "brcm,led-test-mode")) - set_bits |= LED_CTRL_LED_TEST_MODE; - - clrsetbits_32(regs + LED_CTRL_REG, ~0, set_bits); - } else { - struct bcm6858_led_priv *priv = dev_get_priv(dev); - void __iomem *regs; - unsigned int pin, brightness; - - regs = dev_remap_addr(dev_get_parent(dev)); - if (!regs) - return -EINVAL; - - pin = dev_read_u32_default(dev, "reg", LEDS_MAX); - if (pin >= LEDS_MAX) - return -EINVAL; - - priv->regs = regs; - priv->pin = pin; - - /* this led is managed by software */ - clrbits_32(regs + LED_HW_LED_EN_REG, 1 << pin); - - /* configure the polarity */ - if (dev_read_bool(dev, "active-low")) - clrbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); - else - setbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + struct bcm6858_led_priv *priv = dev_get_priv(dev); + void __iomem *regs; + unsigned int pin, brightness; + + regs = dev_remap_addr(dev_get_parent(dev)); + if (!regs) + return -EINVAL; + + pin = dev_read_u32_default(dev, "reg", LEDS_MAX); + if (pin >= LEDS_MAX) + return -EINVAL; + + priv->regs = regs; + priv->pin = pin; + + /* this led is managed by software */ + clrbits_32(regs + LED_HW_LED_EN_REG, 1 << pin); - brightness = dev_read_u32_default(dev, "default-brightness", + /* configure the polarity */ + if (dev_read_bool(dev, "active-low")) + clrbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + else + setbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + + brightness = dev_read_u32_default(dev, "default-brightness", LEDS_MAX_BRIGHTNESS); - led_set_brightness(dev, brightness); - } + led_set_brightness(dev, brightness); return 0; } -static int bcm6858_led_bind(struct udevice *parent) +U_BOOT_DRIVER(bcm6858_led) = { + .name = "bcm6858-led", + .id = UCLASS_LED, + .probe = bcm6858_led_probe, + .priv_auto = sizeof(struct bcm6858_led_priv), + .ops = &bcm6858_led_ops, +}; + +static int bcm6858_led_wrap_probe(struct udevice *dev) +{ + void __iomem *regs; + u32 set_bits = 0; + + regs = dev_remap_addr(dev); + if (!regs) + return -EINVAL; + + if (dev_read_bool(dev, "brcm,serial-led-msb-first")) + set_bits |= LED_CTRL_SERIAL_LED_MSB_FIRST; + if (dev_read_bool(dev, "brcm,serial-led-en-pol")) + set_bits |= LED_CTRL_SERIAL_LED_EN_POL; + if (dev_read_bool(dev, "brcm,serial-led-clk-pol")) + set_bits |= LED_CTRL_SERIAL_LED_CLK_POL; + if (dev_read_bool(dev, "brcm,serial-led-data-ppol")) + set_bits |= LED_CTRL_SERIAL_LED_DATA_PPOL; + if (dev_read_bool(dev, "brcm,led-test-mode")) + set_bits
Re: [PATCH v2] arm: bcmbca: add bcm63138 SoC support
Hi William, Le 06/08/2022 à 03:25, William Zhang a écrit : BCM63138 is an ARM A9 based DSL Broadband SoC. It is part of the BCA (Broadband Carrier Access origin) chipset family so it's added under ARCH_BCMBCA platform. This initial support includes a bare-bone implementation and dts with CPU subsystem, memory, ARM A9 global timer and Broadcom uart. This SoC is supported in the linux-next git repository so the dts and dtsi files are stripped down version of linux copies with mininum blocks needed by u-boot. The u-boot image can be loaded from flash or network to the entry point address in the memory and boot from there to the console. This patch applies on top of the my previous patch [1]. [1] https://lists.denx.de/pipermail/u-boot/2022-August/490570.html Signed-off-by: William Zhang Reviewed-by: Florian Fainelli Reviewed-by: Philippe Reynes --- Changes in v2: - Drop bcmbca timer and use ARM A9 global timer instead as it is already supported in u-boot - Add Florian reviewed-by tag for v1 patch MAINTAINERS| 1 + arch/arm/dts/Makefile | 2 + arch/arm/dts/bcm63138.dtsi | 149 + arch/arm/dts/bcm963138.dts | 30 + arch/arm/mach-bcmbca/Kconfig | 9 ++ arch/arm/mach-bcmbca/Makefile | 1 + arch/arm/mach-bcmbca/bcm63138/Kconfig | 17 +++ arch/arm/mach-bcmbca/bcm63138/Makefile | 5 + board/broadcom/bcmbca/Kconfig | 7 ++ configs/bcm963138_defconfig| 22 include/configs/bcm963138.h| 12 ++ 11 files changed, 255 insertions(+) create mode 100644 arch/arm/dts/bcm63138.dtsi create mode 100644 arch/arm/dts/bcm963138.dts create mode 100644 arch/arm/mach-bcmbca/bcm63138/Kconfig create mode 100644 arch/arm/mach-bcmbca/bcm63138/Makefile create mode 100644 configs/bcm963138_defconfig create mode 100644 include/configs/bcm963138.h diff --git a/MAINTAINERS b/MAINTAINERS index 8c3a7d77f17d..2a27d15705cb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -219,6 +219,7 @@ F: board/broadcom/bcmbca/ F:drivers/timer/bcmbca-timer.c N:bcmbca N:bcm[9]?47622 +N: bcm[9]?63138 N:bcm[9]?63148 N:bcm[9]?63178 N:bcm[9]?6756 diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index b8d136bd129b..f4fa6f517744 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1165,6 +1165,8 @@ dtb-$(CONFIG_ARCH_BCMSTB) += bcm7xxx.dtb dtb-$(CONFIG_BCM47622) += \ bcm947622.dtb +dtb-$(CONFIG_BCM63138) += \ + bcm963138.dtb dtb-$(CONFIG_BCM63148) += \ bcm963148.dtb dtb-$(CONFIG_BCM63178) += \ diff --git a/arch/arm/dts/bcm63138.dtsi b/arch/arm/dts/bcm63138.dtsi new file mode 100644 index ..42b442aec9f4 --- /dev/null +++ b/arch/arm/dts/bcm63138.dtsi @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Broadcom BCM63138 DSL SoCs Device Tree + */ + +#include +#include + +/ { + compatible = "brcm,bcm63138", "brcm,bcmbca"; + #address-cells = <1>; + #size-cells = <1>; + + interrupt-parent = <&gic>; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a9"; + next-level-cache = <&L2>; + reg = <0>; + enable-method = "brcm,bcm63138"; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a9"; + next-level-cache = <&L2>; + reg = <1>; + enable-method = "brcm,bcm63138"; + }; + }; + + clocks { + /* UBUS peripheral clock */ + periph_clk: periph_clk { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <5000>; + clock-output-names = "periph"; + }; + + /* peripheral clock for system timer */ + axi_clk: axi_clk { + #clock-cells = <0>; + compatible = "fixed-factor-clock"; + clocks = <&armpll>; + clock-div = <2>; + clock-mult = <1>; + }; + + /* APB bus clock */ + apb_clk: apb_clk { + #clock-cells = <0>; + compatible = "fixed-factor-clock"; + clocks = <&armpll>; + clock-div = <4
Re: [PATCH v3 5/5] arm: bcmbca: make reset_cpu function weak
Hi William Le 22/08/2022 à 20:19, William Zhang a écrit : BCM63158 carries the CONFIG_SYSRESET from the original configuration. It provide reset_cpu function already so need to define weak version of the dummy reset_cpu for other BCMBCA SoCs to avoid linking error. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v3: -Fix reset_cpu function prototype. board/broadcom/bcmbca/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board/broadcom/bcmbca/board.c b/board/broadcom/bcmbca/board.c index 4aa1d659d5c7..bcecb4d78392 100644 --- a/board/broadcom/bcmbca/board.c +++ b/board/broadcom/bcmbca/board.c @@ -30,6 +30,6 @@ int print_cpuinfo(void) return 0; } -void reset_cpu(ulong addr) +__weak void reset_cpu(void) { }
Re: [PATCH v3 4/5] MAINTAINERS: Add BCM63158 maintainer to BCMBCA entry
Hi William, Le 22/08/2022 à 20:19, William Zhang a écrit : Since ARCH_BCM63158 SoC support is merged into ARCH_BCMBCA, add BCM63158 maintainer Philippe to bcmbca maintainer list. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- (no changes since v1) MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 5b219d62f6bf..d0a5b2352cc8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -213,6 +213,7 @@ M: Anand Gore M:William Zhang M:Kursad Oney M:Joel Peshkin +M: Philippe Reynes S:Maintained F:arch/arm/mach-bcmbca/ F:board/broadcom/bcmbca/
Re: [PATCH v3 3/5] arm: bcmbca: replace ARCH_BCM63158 symbols in Kconfig with BCM63158
Hi William, Le 22/08/2022 à 20:19, William Zhang a écrit : As CONFIG_ARCH_BCM63158 is replaced with CONFIG_BCM63158, update the Kconfig to use the new config symbol. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v3: -Update subject line to be more clear drivers/gpio/Kconfig | 2 +- drivers/led/Kconfig | 2 +- drivers/mtd/nand/raw/Kconfig | 2 +- drivers/spi/Kconfig | 2 +- drivers/watchdog/Kconfig | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index aaa152fae73b..83f4f5089992 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -111,7 +111,7 @@ config BCM2835_GPIO config BCM6345_GPIO bool "BCM6345 GPIO driver" depends on DM_GPIO && (ARCH_BMIPS || ARCH_BCM68360 || \ - ARCH_BCM6858 || ARCH_BCM63158 || \ + ARCH_BCM6858 || BCM63158 || \ ARCH_BCM6753) help This driver supports the GPIO banks on BCM6345 SoCs. diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index ccdd7d7395c8..d777414dda8d 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -37,7 +37,7 @@ config LED_BCM6753 config LED_BCM6858 bool "LED Support for BCM6858" - depends on LED && (ARCH_BCM68360 || ARCH_BCM6858 || ARCH_BCM63158) + depends on LED && (ARCH_BCM68360 || ARCH_BCM6858 || BCM63158) help This option enables support for LEDs connected to the BCM6858 HW has blinking capabilities and up to 32 LEDs can be controlled. diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig index ce67d1abde25..24c27b6ecf7f 100644 --- a/drivers/mtd/nand/raw/Kconfig +++ b/drivers/mtd/nand/raw/Kconfig @@ -121,7 +121,7 @@ config NAND_BRCMNAND_6858 config NAND_BRCMNAND_63158 bool "Support Broadcom NAND controller on bcm63158" - depends on NAND_BRCMNAND && ARCH_BCM63158 + depends on NAND_BRCMNAND && BCM63158 help Enable support for broadcom nand driver on bcm63158. diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 75b794548b22..0a666eee80e7 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -92,7 +92,7 @@ config ATMEL_SPI config BCM63XX_HSSPI bool "BCM63XX HSSPI driver" depends on (ARCH_BMIPS || ARCH_BCM68360 || \ - ARCH_BCM6858 || ARCH_BCM63158) + ARCH_BCM6858 || BCM63158) help Enable the BCM6328 HSSPI driver. This driver can be used to access the SPI NOR flash on platforms embedding this Broadcom diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 50e6a1efba51..ff4d1ee530d2 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -129,7 +129,7 @@ config WDT_AT91 config WDT_BCM6345 bool "BCM6345 watchdog timer support" depends on WDT && (ARCH_BMIPS || ARCH_BCM68360 || \ - ARCH_BCM6858 || ARCH_BCM63158 || \ + ARCH_BCM6858 || BCM63158 || \ ARCH_BCM6753) help Select this to enable watchdog timer for BCM6345 SoCs.
Re: [PATCH v3 2/5] arm: bcmbca: remove bcm63158 support under CONFIG_ARCH_BCM63158
Hi William, Le 22/08/2022 à 20:19, William Zhang a écrit : Now that BCM63158 is supported under CONFIG_ARCH_BCMBCA and CONFIG_BCM63158, remove the original ARCH_BCM63158 support and migrate configuration settings. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- (no changes since v2) Changes in v2: - Remove bcm963158_ram_defconfig per discussion with Philippe as a basic config version of bcm963158_defconfig is now added. arch/arm/Kconfig | 8 +--- arch/arm/dts/Makefile| 3 -- board/broadcom/bcm963158/Kconfig | 17 --- board/broadcom/bcm963158/MAINTAINERS | 6 --- board/broadcom/bcm963158/Makefile| 3 -- board/broadcom/bcm963158/bcm963158.c | 62 - configs/bcm963158_ram_defconfig | 67 include/configs/bcm963158.h | 4 ++ include/configs/broadcom_bcm963158.h | 32 - 9 files changed, 5 insertions(+), 197 deletions(-) delete mode 100644 board/broadcom/bcm963158/Kconfig delete mode 100644 board/broadcom/bcm963158/MAINTAINERS delete mode 100644 board/broadcom/bcm963158/Makefile delete mode 100644 board/broadcom/bcm963158/bcm963158.c delete mode 100644 configs/bcm963158_ram_defconfig delete mode 100644 include/configs/broadcom_bcm963158.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 0d4903a2eb5b..da4defa08466 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -665,12 +665,6 @@ config ARCH_BCM283X imply CMD_DM imply FAT_WRITE -config ARCH_BCM63158 - bool "Broadcom BCM63158 family" - select DM - select OF_CONTROL - imply CMD_DM - config ARCH_BCM6753 bool "Broadcom BCM6753 family" select CPU_V7A @@ -706,6 +700,7 @@ config ARCH_BCMBCA bool "Broadcom broadband chip family" select DM select OF_CONTROL + imply CMD_DM config TARGET_VEXPRESS_CA9X4 bool "Support vexpress_ca9x4" @@ -2284,7 +2279,6 @@ source "board/Marvell/octeontx2/Kconfig" source "board/armltd/vexpress/Kconfig" source "board/armltd/vexpress64/Kconfig" source "board/cortina/presidio-asic/Kconfig" -source "board/broadcom/bcm963158/Kconfig" source "board/broadcom/bcm96753ref/Kconfig" source "board/broadcom/bcm968360bg/Kconfig" source "board/broadcom/bcm968580xref/Kconfig" diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index a7fc3d7d7021..c55bc3569662 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1147,9 +1147,6 @@ dtb-$(CONFIG_ARCH_BCM283X) += \ bcm2837-rpi-cm3-io3.dtb \ bcm2711-rpi-4-b.dtb -dtb-$(CONFIG_ARCH_BCM63158) += \ - bcm963158.dtb - dtb-$(CONFIG_ARCH_BCM68360) += \ bcm968360bg.dtb diff --git a/board/broadcom/bcm963158/Kconfig b/board/broadcom/bcm963158/Kconfig deleted file mode 100644 index 08a8bc1c14d3.. --- a/board/broadcom/bcm963158/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -if TARGET_BCM963158 - -config SYS_VENDOR - default "broadcom" - -config SYS_BOARD - default "bcm963158" - -config SYS_CONFIG_NAME - default "broadcom_bcm963158" - -endif - -config TARGET_BCM963158 - bool "Support Broadcom bcm963158" - depends on ARCH_BCM63158 - select ARM64 diff --git a/board/broadcom/bcm963158/MAINTAINERS b/board/broadcom/bcm963158/MAINTAINERS deleted file mode 100644 index d28d971f9d36.. --- a/board/broadcom/bcm963158/MAINTAINERS +++ /dev/null @@ -1,6 +0,0 @@ -BROADCOM BCM963158 -M: Philippe Reynes -S: Maintained -F: board/broadcom/bcm963158/ -F: include/configs/broadcom_bcm963158.h -F: configs/bcm963158_ram_defconfig diff --git a/board/broadcom/bcm963158/Makefile b/board/broadcom/bcm963158/Makefile deleted file mode 100644 index 0a902c9cf618.. --- a/board/broadcom/bcm963158/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ - -obj-y += bcm963158.o diff --git a/board/broadcom/bcm963158/bcm963158.c b/board/broadcom/bcm963158/bcm963158.c deleted file mode 100644 index 9feaee3c0fc4..0000 --- a/board/broadcom/bcm963158/bcm963158.c +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2019 Philippe Reynes - */ - -#include -#include -#include -#include - -#ifdef CONFIG_ARM64 -#include - -static struct mm_region broadcom_bcm963158_mem_map[] = { - { - /* RAM */ - .virt = 0xUL, - .phys = 0xUL, - .size = 8UL * SZ_1G, - .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | -PTE_BLOCK_INNER_SHARE - }, { - /* SoC */ - .virt = 0x8000UL, - .phys = 0x8000UL, - .size = 0xff8000UL, -
Re: [PATCH v3 1/5] arm: bcmbca: add bcm63158 SoC support under CONFIG_ARCH_BCMBCA
Hi William, Le 22/08/2022 à 20:19, William Zhang a écrit : BCM63158 is a Broadcom B53 based DSL Gateway SoC. It is part of the BCA (Broadband Carrier Access origin) chipset family. Like other Broadband SoC, this patch adds it under CONFIG_BCM63158 chip config and CONFIG_ARCH_BCMBCA platform config. This initial support includes a bare-bone implementation and dts with CPU subsystem, memory and ARM PL011 uart. This SoC is supported in the linux-next git repository so the dts and dtsi files are copied from linux. The u-boot image can be loaded from flash or network to the entry point address in the memory and boot from there to the console. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- (no changes since v2) Changes in v2: - Remove extra nodes from bcm963158.dts and keep it as a generic minimun board support dts following other BCA chip convention. MAINTAINERS | 1 + arch/arm/dts/Makefile | 2 + arch/arm/dts/bcm63158.dtsi| 207 +- arch/arm/dts/bcm963158.dts| 121 + arch/arm/mach-bcmbca/Kconfig | 8 + arch/arm/mach-bcmbca/Makefile | 1 + arch/arm/mach-bcmbca/bcm63158/Kconfig | 17 ++ arch/arm/mach-bcmbca/bcm63158/Makefile| 5 + arch/arm/mach-bcmbca/bcm63158/mmu_table.c | 32 board/broadcom/bcmbca/Kconfig | 7 + configs/bcm963158_defconfig | 23 +++ include/configs/bcm963158.h | 11 ++ 12 files changed, 239 insertions(+), 196 deletions(-) create mode 100644 arch/arm/mach-bcmbca/bcm63158/Kconfig create mode 100644 arch/arm/mach-bcmbca/bcm63158/Makefile create mode 100644 arch/arm/mach-bcmbca/bcm63158/mmu_table.c create mode 100644 configs/bcm963158_defconfig create mode 100644 include/configs/bcm963158.h diff --git a/MAINTAINERS b/MAINTAINERS index 3f250942ced1..5b219d62f6bf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -224,6 +224,7 @@ N: bcm[9]?4912 N:bcm[9]?63138 N:bcm[9]?63146 N:bcm[9]?63148 +N: bcm[9]?63158 N:bcm[9]?63178 N:bcm[9]?6756 N:bcm[9]?6813 diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index 9a6582d9c1c8..a7fc3d7d7021 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1175,6 +1175,8 @@ dtb-$(CONFIG_BCM63146) += \ bcm963146.dtb dtb-$(CONFIG_BCM63148) += \ bcm963148.dtb +dtb-$(CONFIG_BCM63158) += \ + bcm963158.dtb dtb-$(CONFIG_BCM63178) += \ bcm963178.dtb dtb-$(CONFIG_BCM6756) += \ diff --git a/arch/arm/dts/bcm63158.dtsi b/arch/arm/dts/bcm63158.dtsi index 7dd285843849..8b179ba0fca8 100644 --- a/arch/arm/dts/bcm63158.dtsi +++ b/arch/arm/dts/bcm63158.dtsi @@ -1,122 +1,167 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2019 Philippe Reynes + * Copyright 2022 Broadcom Ltd. */ -#include "skeleton64.dtsi" +#include +#include / { - compatible = "brcm,bcm63158"; + compatible = "brcm,bcm63158", "brcm,bcmbca"; #address-cells = <2>; #size-cells = <2>; - aliases { - spi0 = &hsspi; - }; + interrupt-parent = <&gic>; cpus { #address-cells = <2>; #size-cells = <0>; - u-boot,dm-pre-reloc; - cpu0: cpu@0 { - compatible = "arm,cortex-a53", "arm,armv8"; + B53_0: cpu@0 { + compatible = "brcm,brahma-b53"; device_type = "cpu"; reg = <0x0 0x0>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; + next-level-cache = <&L2_0>; + enable-method = "psci"; }; - cpu1: cpu@1 { - compatible = "arm,cortex-a53", "arm,armv8"; + B53_1: cpu@1 { + compatible = "brcm,brahma-b53"; device_type = "cpu"; reg = <0x0 0x1>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; + next-level-cache = <&L2_0>; + enable-method = "psci"; }; - cpu2: cpu@2 { - compatible = "arm,cortex-a53", "arm,armv8"; + B53_2: cpu@2 { + compatible = "brcm,brahma-b53"; device_type = "cpu"; reg = <0x0 0x2>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; + next-level-cache = <&
Re: [PATCH v2 3/3] arm: bcmbca: replace ARCH_BCM6753 symbols in Kconfig with BCM6855
Hi William, Le 22/08/2022 à 20:49, William Zhang a écrit : As CONFIG_ARCH_BCM6753 is replaced with CONFIG_BCM6855, update the driver Kconfig to use the new config symbol. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v2: - Update subject line to be more clear for patch 3 drivers/gpio/Kconfig | 2 +- drivers/led/Kconfig | 2 +- drivers/mtd/nand/raw/Kconfig | 2 +- drivers/watchdog/Kconfig | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 929f3fb9eacb..d8020de969ef 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -111,7 +111,7 @@ config BCM2835_GPIO config BCM6345_GPIO bool "BCM6345 GPIO driver" depends on DM_GPIO && (ARCH_BMIPS || BCM6856 || \ - BCM6858 || BCM63158 || ARCH_BCM6753) + BCM6858 || BCM63158 || BCM6855) help This driver supports the GPIO banks on BCM6345 SoCs. diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index 98f015a07f97..996b757e6d00 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -30,7 +30,7 @@ config LED_BCM6358 config LED_BCM6753 bool "LED Support for BCM6753" - depends on LED && ARCH_BCM6753 + depends on LED && BCM6855 help This option enables support for LEDs connected to the BCM6753 HW has blinking and fading capabilities and up to 32 LEDs can be controlled. diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig index f8445e09633c..d6e3eeb3c093 100644 --- a/drivers/mtd/nand/raw/Kconfig +++ b/drivers/mtd/nand/raw/Kconfig @@ -97,7 +97,7 @@ config NAND_BRCMNAND_6368 config NAND_BRCMNAND_6753 bool "Support Broadcom NAND controller on bcm6753" - depends on NAND_BRCMNAND && ARCH_BCM6753 + depends on NAND_BRCMNAND && BCM6855 help Enable support for broadcom nand driver on bcm6753. diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 84a4034fe87c..65f2d0821c60 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -129,7 +129,7 @@ config WDT_AT91 config WDT_BCM6345 bool "BCM6345 watchdog timer support" depends on WDT && (ARCH_BMIPS || BCM6856 || \ - BCM6858 || BCM63158 || ARCH_BCM6753) + BCM6858 || BCM63158 || BCM6855) help Select this to enable watchdog timer for BCM6345 SoCs. The watchdog timer is stopped when initialized.
Re: [PATCH v2 2/3] arm: bcmbca: remove bcm6753 support under CONFIG_ARCH_BCM6753
Hi William, Le 22/08/2022 à 20:49, William Zhang a écrit : BCM6753 is essentially same as the main chip BCM6855 but with different SKU number. Now that BCM6855 is supported under CONFIG_ARCH_BCMBCA and CONFIG_BCM6855, remove the original ARCH_BCM6753 support and migrate its configuration and dts settings. This includes: - Remove the bcm96753ref board folder. It is replaced by the generic bcmbca board folder. - Merge the 6753.dtsi setting to the new 6855.dtsi file. Update 96753ref board dts with the new compatible string. - Delete broadcom_bcm96763ref.h and merge its setting to the new bcm96855.h file. - Delete bcm96753ref_ram_defconfig and use a basic config version of bcm96855_defconfig Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- (no changes since v1) arch/arm/Kconfig | 8 - arch/arm/dts/Makefile| 6 +- arch/arm/dts/bcm6753.dtsi| 208 --- arch/arm/dts/bcm6855.dtsi| 137 +++ arch/arm/dts/bcm96753ref.dts | 6 +- board/broadcom/bcm96753ref/Kconfig | 16 -- board/broadcom/bcm96753ref/MAINTAINERS | 6 - board/broadcom/bcm96753ref/Makefile | 3 - board/broadcom/bcm96753ref/bcm96753ref.c | 40 - configs/bcm96753ref_ram_defconfig| 87 -- include/configs/bcm96855.h | 4 + include/configs/broadcom_bcm96753ref.h | 32 12 files changed, 146 insertions(+), 407 deletions(-) delete mode 100644 arch/arm/dts/bcm6753.dtsi delete mode 100644 board/broadcom/bcm96753ref/Kconfig delete mode 100644 board/broadcom/bcm96753ref/MAINTAINERS delete mode 100644 board/broadcom/bcm96753ref/Makefile delete mode 100644 board/broadcom/bcm96753ref/bcm96753ref.c delete mode 100644 configs/bcm96753ref_ram_defconfig delete mode 100644 include/configs/broadcom_bcm96753ref.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 063616ff8d0b..c1f195e9d106 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -665,13 +665,6 @@ config ARCH_BCM283X imply CMD_DM imply FAT_WRITE -config ARCH_BCM6753 - bool "Broadcom BCM6753 family" - select CPU_V7A - select DM - select OF_CONTROL - imply CMD_DM - config ARCH_BCMSTB bool "Broadcom BCM7XXX family" select CPU_V7A @@ -2267,7 +2260,6 @@ source "board/Marvell/octeontx2/Kconfig" source "board/armltd/vexpress/Kconfig" source "board/armltd/vexpress64/Kconfig" source "board/cortina/presidio-asic/Kconfig" -source "board/broadcom/bcm96753ref/Kconfig" source "board/broadcom/bcmns3/Kconfig" source "board/cavium/thunderx/Kconfig" source "board/eets/pdu001/Kconfig" diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index 5fd38cc63b63..8fba735cc8ab 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1147,9 +1147,6 @@ dtb-$(CONFIG_ARCH_BCM283X) += \ bcm2837-rpi-cm3-io3.dtb \ bcm2711-rpi-4-b.dtb -dtb-$(CONFIG_ARCH_BCM6753) += \ - bcm96753ref.dtb - dtb-$(CONFIG_TARGET_BCMNS3) += ns3-board.dtb dtb-$(CONFIG_ARCH_BCMSTB) += bcm7xxx.dtb @@ -1177,7 +1174,8 @@ dtb-$(CONFIG_BCM6813) += \ dtb-$(CONFIG_BCM6846) += \ bcm96846.dtb dtb-$(CONFIG_BCM6855) += \ - bcm96855.dtb + bcm96855.dtb \ + bcm96753ref.dtb dtb-$(CONFIG_BCM6856) += \ bcm96856.dtb \ bcm968360bg.dtb diff --git a/arch/arm/dts/bcm6753.dtsi b/arch/arm/dts/bcm6753.dtsi deleted file mode 100644 index e88ab095c290.. --- a/arch/arm/dts/bcm6753.dtsi +++ /dev/null @@ -1,208 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2022 Philippe Reynes - */ - -#include "skeleton.dtsi" - -/ { - compatible = "brcm,bcm6753"; - #address-cells = <1>; - #size-cells = <1>; - - cpus { - #address-cells = <1>; - #size-cells = <0>; - u-boot,dm-pre-reloc; - - cpu0: cpu@0 { - compatible = "arm,cortex-a7"; - device_type = "cpu"; - reg = <0x0>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; - }; - - cpu1: cpu@1 { - compatible = "arm,cortex-a7"; - device_type = "cpu"; - reg = <0x1>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; - }; - - cpu2: cpu@2 { - compatible = "arm,cortex-a7"; - device_type = "cpu"; - reg = <0x2>; - next-level-cache =
Re: [PATCH v2 1/3] arm: bcmbca: add bcm6855 SoC support under CONFIG_ARCH_BCMBCA
Hi William, Le 22/08/2022 à 20:49, William Zhang a écrit : BCM6855 is a Broadcom ARM A7 based PON Gateway SoC. It is part of the BCA (Broadband Carrier Access origin) chipset family. Like other broadband SoC, this patch adds it under CONFIG_BCM6855 chip config and CONFIG_ARCH_BCMBCA platform config. This initial support includes a bare-bone implementation and dts with CPU subsystem, memory and ARM PL101 uart. This SoC is supported in the linux-next git repository so the dts and dtsi files are copied from linux. The u-boot image can be loaded from flash or network to the entry point address in the memory and boot from there to the console. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v2: - Add help in BCM6855 Kconfig option to include the list of the supported chips. MAINTAINERS | 1 + arch/arm/dts/Makefile | 2 + arch/arm/dts/bcm6855.dtsi | 120 ++ arch/arm/dts/bcm96855.dts | 30 +++ arch/arm/mach-bcmbca/Kconfig | 11 +++ arch/arm/mach-bcmbca/Makefile | 1 + arch/arm/mach-bcmbca/bcm6855/Kconfig | 17 arch/arm/mach-bcmbca/bcm6855/Makefile | 5 ++ board/broadcom/bcmbca/Kconfig | 7 ++ configs/bcm96855_defconfig| 23 + include/configs/bcm96855.h| 11 +++ 11 files changed, 228 insertions(+) create mode 100644 arch/arm/dts/bcm6855.dtsi create mode 100644 arch/arm/dts/bcm96855.dts create mode 100644 arch/arm/mach-bcmbca/bcm6855/Kconfig create mode 100644 arch/arm/mach-bcmbca/bcm6855/Makefile create mode 100644 configs/bcm96855_defconfig create mode 100644 include/configs/bcm96855.h diff --git a/MAINTAINERS b/MAINTAINERS index 819fa5b87824..371e84de1bc1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -230,6 +230,7 @@ N: bcm[9]?63178 N:bcm[9]?6756 N:bcm[9]?6813 N:bcm[9]?6846 +N: bcm[9]?6855 N:bcm[9]?6856 N:bcm[9]?6858 N:bcm[9]?6878 diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index 07e6130042f5..5fd38cc63b63 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1176,6 +1176,8 @@ dtb-$(CONFIG_BCM6813) += \ bcm96813.dtb dtb-$(CONFIG_BCM6846) += \ bcm96846.dtb +dtb-$(CONFIG_BCM6855) += \ + bcm96855.dtb dtb-$(CONFIG_BCM6856) += \ bcm96856.dtb \ bcm968360bg.dtb diff --git a/arch/arm/dts/bcm6855.dtsi b/arch/arm/dts/bcm6855.dtsi new file mode 100644 index ..620f51aee1a2 --- /dev/null +++ b/arch/arm/dts/bcm6855.dtsi @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright 2022 Broadcom Ltd. + */ + +#include +#include + +/ { + compatible = "brcm,bcm6855", "brcm,bcmbca"; + #address-cells = <1>; + #size-cells = <1>; + + interrupt-parent = <&gic>; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + CA7_0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a7"; + reg = <0x0>; + next-level-cache = <&L2_0>; + enable-method = "psci"; + }; + + CA7_1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a7"; + reg = <0x1>; + next-level-cache = <&L2_0>; + enable-method = "psci"; + }; + + CA7_2: cpu@2 { + device_type = "cpu"; + compatible = "arm,cortex-a7"; + reg = <0x2>; + next-level-cache = <&L2_0>; + enable-method = "psci"; + }; + + L2_0: l2-cache0 { + compatible = "cache"; + }; + }; + + timer { + compatible = "arm,armv7-timer"; + interrupts = , + , + , + ; + arm,cpu-registers-not-fw-configured; + }; + + pmu: pmu { + compatible = "arm,cortex-a7-pmu"; + interrupts = , + , + ; + interrupt-affinity = <&CA7_0>, <&CA7_1>, <&CA7_2>; + }; + + clocks: clocks { + periph_clk: periph-clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <2>; + }; + + uart_clk: uart-clk { +
Re: [PATCH v2 3/3] arm: bcmbca: replace ARCH_BCM6858 symbols in Kconfig with BCM6858
Hi William, Le 22/08/2022 à 20:39, William Zhang a écrit : As CONFIG_ARCH_BCM6858 is replaced with CONFIG_BCM6858, update the driver Kconfig to use the new config symbol. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v2: -Update subject line to be more clear for patch 3 drivers/gpio/Kconfig | 3 +-- drivers/led/Kconfig | 2 +- drivers/mtd/nand/raw/Kconfig | 2 +- drivers/spi/Kconfig | 3 +-- drivers/watchdog/Kconfig | 3 +-- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 9e00b48234ab..929f3fb9eacb 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -111,8 +111,7 @@ config BCM2835_GPIO config BCM6345_GPIO bool "BCM6345 GPIO driver" depends on DM_GPIO && (ARCH_BMIPS || BCM6856 || \ - ARCH_BCM6858 || BCM63158 || \ - ARCH_BCM6753) + BCM6858 || BCM63158 || ARCH_BCM6753) help This driver supports the GPIO banks on BCM6345 SoCs. diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index bd8f23fd9631..98f015a07f97 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -37,7 +37,7 @@ config LED_BCM6753 config LED_BCM6858 bool "LED Support for BCM6858" - depends on LED && (BCM6856 || ARCH_BCM6858 || BCM63158) + depends on LED && (BCM6856 || BCM6858 || BCM63158) help This option enables support for LEDs connected to the BCM6858 HW has blinking capabilities and up to 32 LEDs can be controlled. diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig index 5d006ca1ea07..f8445e09633c 100644 --- a/drivers/mtd/nand/raw/Kconfig +++ b/drivers/mtd/nand/raw/Kconfig @@ -115,7 +115,7 @@ config NAND_BRCMNAND_6838 config NAND_BRCMNAND_6858 bool "Support Broadcom NAND controller on bcm6858" - depends on NAND_BRCMNAND && ARCH_BCM6858 + depends on NAND_BRCMNAND && BCM6858 help Enable support for broadcom nand driver on bcm6858. diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 978e5c86a420..e815a715f9b2 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -91,8 +91,7 @@ config ATMEL_SPI config BCM63XX_HSSPI bool "BCM63XX HSSPI driver" - depends on (ARCH_BMIPS || BCM6856 || \ - ARCH_BCM6858 || BCM63158) + depends on (ARCH_BMIPS || BCM6856 || BCM6858 || BCM63158) help Enable the BCM6328 HSSPI driver. This driver can be used to access the SPI NOR flash on platforms embedding this Broadcom diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 6d559515b78b..84a4034fe87c 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -129,8 +129,7 @@ config WDT_AT91 config WDT_BCM6345 bool "BCM6345 watchdog timer support" depends on WDT && (ARCH_BMIPS || BCM6856 || \ - ARCH_BCM6858 || BCM63158 || \ - ARCH_BCM6753) + BCM6858 || BCM63158 || ARCH_BCM6753) help Select this to enable watchdog timer for BCM6345 SoCs. The watchdog timer is stopped when initialized.
Re: [PATCH v2 2/3] arm: bcmbca: remove bcm6858 support under CONFIG_ARCH_BCM6858
Hi William, Le 22/08/2022 à 20:39, William Zhang a écrit : Now that BCM6858 is supported under CONFIG_ARCH_BCMBCA and CONFIG_BCM6858, remove the original ARCH_BCM6858 support and migrate its configuration and dts settings. This includes: - Remove the bcm968580xref board folder. It is replaced by the generic bcmbca board folder. - Update bcm968580xref board dts with the new compatible string. - Delete broadcom_bcm968580xref.h and merge its setting to the new bcm96858.h file. - Remove bcm968580xref_ram_defconfig as a basic config version of bcm96858_defconfig is now added. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- (no changes since v1) arch/arm/Kconfig | 7 --- arch/arm/dts/Makefile| 6 +- arch/arm/dts/bcm968580xref.dts | 4 +- board/broadcom/bcm968580xref/Kconfig | 17 -- board/broadcom/bcm968580xref/MAINTAINERS | 6 -- board/broadcom/bcm968580xref/Makefile| 3 - board/broadcom/bcm968580xref/bcm968580xref.c | 62 --- configs/bcm968580xref_ram_defconfig | 64 include/configs/bcm96858.h | 4 ++ include/configs/broadcom_bcm968580xref.h | 32 -- 10 files changed, 8 insertions(+), 197 deletions(-) delete mode 100644 board/broadcom/bcm968580xref/Kconfig delete mode 100644 board/broadcom/bcm968580xref/MAINTAINERS delete mode 100644 board/broadcom/bcm968580xref/Makefile delete mode 100644 board/broadcom/bcm968580xref/bcm968580xref.c delete mode 100644 configs/bcm968580xref_ram_defconfig delete mode 100644 include/configs/broadcom_bcm968580xref.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 3f124ab0ce85..063616ff8d0b 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -672,12 +672,6 @@ config ARCH_BCM6753 select OF_CONTROL imply CMD_DM -config ARCH_BCM6858 - bool "Broadcom BCM6858 family" - select DM - select OF_CONTROL - imply CMD_DM - config ARCH_BCMSTB bool "Broadcom BCM7XXX family" select CPU_V7A @@ -2274,7 +2268,6 @@ source "board/armltd/vexpress/Kconfig" source "board/armltd/vexpress64/Kconfig" source "board/cortina/presidio-asic/Kconfig" source "board/broadcom/bcm96753ref/Kconfig" -source "board/broadcom/bcm968580xref/Kconfig" source "board/broadcom/bcmns3/Kconfig" source "board/cavium/thunderx/Kconfig" source "board/eets/pdu001/Kconfig" diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index ee3475b97a40..07e6130042f5 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1150,9 +1150,6 @@ dtb-$(CONFIG_ARCH_BCM283X) += \ dtb-$(CONFIG_ARCH_BCM6753) += \ bcm96753ref.dtb -dtb-$(CONFIG_ARCH_BCM6858) += \ - bcm968580xref.dtb - dtb-$(CONFIG_TARGET_BCMNS3) += ns3-board.dtb dtb-$(CONFIG_ARCH_BCMSTB) += bcm7xxx.dtb @@ -1183,7 +1180,8 @@ dtb-$(CONFIG_BCM6856) += \ bcm96856.dtb \ bcm968360bg.dtb dtb-$(CONFIG_BCM6858) += \ - bcm96858.dtb + bcm96858.dtb \ + bcm968580xref.dtb dtb-$(CONFIG_BCM6878) += \ bcm96878.dtb diff --git a/arch/arm/dts/bcm968580xref.dts b/arch/arm/dts/bcm968580xref.dts index a034e38318bd..6d787bd011b8 100644 --- a/arch/arm/dts/bcm968580xref.dts +++ b/arch/arm/dts/bcm968580xref.dts @@ -8,8 +8,8 @@ #include "bcm6858.dtsi" / { - model = "Broadcom bcm68580xref"; - compatible = "broadcom,bcm68580xref", "brcm,bcm6858"; + model = "Broadcom BCM968580xref Reference Board"; + compatible = "brcm,bcm968580xref", "brcm,bcm6858", "brcm,bcmbca"; aliases { serial0 = &uart0; diff --git a/board/broadcom/bcm968580xref/Kconfig b/board/broadcom/bcm968580xref/Kconfig deleted file mode 100644 index b5730367a2d2.. --- a/board/broadcom/bcm968580xref/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -if ARCH_BCM6858 - -config SYS_VENDOR - default "broadcom" - -config SYS_BOARD - default "bcm968580xref" - -config SYS_CONFIG_NAME - default "broadcom_bcm968580xref" - -endif - -config TARGET_BCM968580XREF - bool "Support Broadcom bcm968580xref" - depends on ARCH_BCM6858 - select ARM64 diff --git a/board/broadcom/bcm968580xref/MAINTAINERS b/board/broadcom/bcm968580xref/MAINTAINERS deleted file mode 100644 index 5ee0c4dd4e42.. --- a/board/broadcom/bcm968580xref/MAINTAINERS +++ /dev/null @@ -1,6 +0,0 @@ -BCM968580XREF BOARD -M: Philippe Reynes -S: Maintained -F: board/broadcom/bcm968580xref/ -F: include/configs/broadcom_bcm968580xref.h -F: configs/bcm968580xref_ram_defconfig diff --git a/board/broadcom/bcm968580xref/Makefile b/board/broadcom/bcm968580xref/Makefile d
Re: [PATCH v2 1/3] arm: bcmbca: add bcm6858 SoC support under CONFIG_ARCH_BCMBCA
Hi William, Le 22/08/2022 à 20:39, William Zhang a écrit : BCM6858 is a Broadcom B53 based PON Gateway SoC. It is part of the BCA (Broadband Carrier Access origin) chipset family. Like other broadband SoC, this patch adds it under CONFIG_BCM6858 chip config and CONFIG_ARCH_BCMBCA platform config. This initial support includes a bare-bone implementation and the original dts is updated with the one from linux next git repository. The u-boot image can be loaded from flash or network to the entry point address in the memory and boot from there to the console. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v2: -Add help in BCM6858 Kconfig option to include the list of the supported chips. MAINTAINERS | 1 + arch/arm/dts/Makefile| 2 + arch/arm/dts/bcm6858.dtsi| 197 ++- arch/arm/dts/bcm96858.dts| 30 arch/arm/mach-bcmbca/Kconfig | 11 ++ arch/arm/mach-bcmbca/Makefile| 1 + arch/arm/mach-bcmbca/bcm6858/Kconfig | 17 ++ arch/arm/mach-bcmbca/bcm6858/Makefile| 5 + arch/arm/mach-bcmbca/bcm6858/mmu_table.c | 32 board/broadcom/bcmbca/Kconfig| 7 + configs/bcm96858_defconfig | 23 +++ include/configs/bcm96858.h | 11 ++ 12 files changed, 258 insertions(+), 79 deletions(-) create mode 100644 arch/arm/dts/bcm96858.dts create mode 100644 arch/arm/mach-bcmbca/bcm6858/Kconfig create mode 100644 arch/arm/mach-bcmbca/bcm6858/Makefile create mode 100644 arch/arm/mach-bcmbca/bcm6858/mmu_table.c create mode 100644 configs/bcm96858_defconfig create mode 100644 include/configs/bcm96858.h diff --git a/MAINTAINERS b/MAINTAINERS index 1f50dad583ce..819fa5b87824 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -231,6 +231,7 @@ N: bcm[9]?6756 N:bcm[9]?6813 N:bcm[9]?6846 N:bcm[9]?6856 +N: bcm[9]?6858 N:bcm[9]?6878 ARM BROADCOM BCMSTB diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index a0ea9fa6029d..ee3475b97a40 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1182,6 +1182,8 @@ dtb-$(CONFIG_BCM6846) += \ dtb-$(CONFIG_BCM6856) += \ bcm96856.dtb \ bcm968360bg.dtb +dtb-$(CONFIG_BCM6858) += \ + bcm96858.dtb dtb-$(CONFIG_BCM6878) += \ bcm96878.dtb diff --git a/arch/arm/dts/bcm6858.dtsi b/arch/arm/dts/bcm6858.dtsi index 02225621710b..19c4dd6fa7e4 100644 --- a/arch/arm/dts/bcm6858.dtsi +++ b/arch/arm/dts/bcm6858.dtsi @@ -1,122 +1,161 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2018 Philippe Reynes + * Copyright 2022 Broadcom Ltd. */ -#include "skeleton64.dtsi" +#include +#include / { - compatible = "brcm,bcm6858"; + compatible = "brcm,bcm6858", "brcm,bcmbca"; #address-cells = <2>; #size-cells = <2>; - aliases { - spi0 = &hsspi; - }; + interrupt-parent = <&gic>; cpus { #address-cells = <2>; #size-cells = <0>; - u-boot,dm-pre-reloc; - cpu0: cpu@0 { - compatible = "arm,cortex-a53", "arm,armv8"; + B53_0: cpu@0 { + compatible = "brcm,brahma-b53"; device_type = "cpu"; reg = <0x0 0x0>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; + next-level-cache = <&L2_0>; + enable-method = "psci"; }; - cpu1: cpu@1 { - compatible = "arm,cortex-a53", "arm,armv8"; + B53_1: cpu@1 { + compatible = "brcm,brahma-b53"; device_type = "cpu"; reg = <0x0 0x1>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; + next-level-cache = <&L2_0>; + enable-method = "psci"; }; - cpu2: cpu@2 { - compatible = "arm,cortex-a53", "arm,armv8"; + B53_2: cpu@2 { + compatible = "brcm,brahma-b53"; device_type = "cpu"; reg = <0x0 0x2>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; + next-level-cache = <&L2_0>; + enable-method = "psci"; }; - cpu3: cpu@3 { - compatible = "arm,cortex-a53", "arm,armv
Re: [PATCH v4 3/3] arm: bcmbca: replace ARCH_BCM68360 symbols in Kconfig with BCM6856
Hi William, Le 22/08/2022 à 20:31, William Zhang a écrit : As CONFIG_ARCH_BCM68360 is replaced with CONFIG_BCM6856, update the driver Kconfig to use the new config symbol. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v4: -Update subject line to be more clear for patch 3 drivers/gpio/Kconfig | 2 +- drivers/led/Kconfig | 2 +- drivers/mtd/nand/raw/Kconfig | 2 +- drivers/spi/Kconfig | 2 +- drivers/watchdog/Kconfig | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 83f4f5089992..9e00b48234ab 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -110,7 +110,7 @@ config BCM2835_GPIO config BCM6345_GPIO bool "BCM6345 GPIO driver" - depends on DM_GPIO && (ARCH_BMIPS || ARCH_BCM68360 || \ + depends on DM_GPIO && (ARCH_BMIPS || BCM6856 || \ ARCH_BCM6858 || BCM63158 || \ ARCH_BCM6753) help diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index d777414dda8d..bd8f23fd9631 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -37,7 +37,7 @@ config LED_BCM6753 config LED_BCM6858 bool "LED Support for BCM6858" - depends on LED && (ARCH_BCM68360 || ARCH_BCM6858 || BCM63158) + depends on LED && (BCM6856 || ARCH_BCM6858 || BCM63158) help This option enables support for LEDs connected to the BCM6858 HW has blinking capabilities and up to 32 LEDs can be controlled. diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig index 24c27b6ecf7f..5d006ca1ea07 100644 --- a/drivers/mtd/nand/raw/Kconfig +++ b/drivers/mtd/nand/raw/Kconfig @@ -103,7 +103,7 @@ config NAND_BRCMNAND_6753 config NAND_BRCMNAND_68360 bool "Support Broadcom NAND controller on bcm68360" - depends on NAND_BRCMNAND && ARCH_BCM68360 + depends on NAND_BRCMNAND && BCM6856 help Enable support for broadcom nand driver on bcm68360. diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 0a666eee80e7..978e5c86a420 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -91,7 +91,7 @@ config ATMEL_SPI config BCM63XX_HSSPI bool "BCM63XX HSSPI driver" - depends on (ARCH_BMIPS || ARCH_BCM68360 || \ + depends on (ARCH_BMIPS || BCM6856 || \ ARCH_BCM6858 || BCM63158) help Enable the BCM6328 HSSPI driver. This driver can be used to diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index ff4d1ee530d2..6d559515b78b 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -128,7 +128,7 @@ config WDT_AT91 config WDT_BCM6345 bool "BCM6345 watchdog timer support" - depends on WDT && (ARCH_BMIPS || ARCH_BCM68360 || \ + depends on WDT && (ARCH_BMIPS || BCM6856 || \ ARCH_BCM6858 || BCM63158 || \ ARCH_BCM6753) help
Re: [PATCH v4 2/3] arm: bcmbca: remove bcm68360 support under CONFIG_ARCH_BCM68360
Hi William, Le 22/08/2022 à 20:31, William Zhang a écrit : BCM68360 is a variant within the BCM6856 chip family. Now that BCM6856 is supported under CONFIG_ARCH_BCMBCA and CONFIG_BCM6856, remove the original ARCH_BCM68360 support and migrate its configuration and dts settings. This includes: - Remove the bcm968360bg board folder. It is replaced by the generic bcmbca board folder. - Merge the 68360.dtsi setting to the new 6856.dtsi file. Update board dts with the new compatible string. - Merge broadcom_bcm968360bg.h setting to the new bcm96856.h file. - Remove bcm968360bg_ram_defconfig as a basic config version of bcm96856_defconfig is now added. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- (no changes since v3) Changes in v3: - Remove bcm968360bg_ram_defconfig per discussion with Philippe as a basic config version of bcm96856_defconfig is now added. - Update commit message Changes in v2: - Bring Philippe Reynes copyright tag from 68360 dts to 6856 dts arch/arm/Kconfig | 7 - arch/arm/dts/Makefile| 6 +- arch/arm/dts/bcm68360.dtsi | 217 --- arch/arm/dts/bcm6856.dtsi| 150 arch/arm/dts/bcm968360bg.dts | 6 +- board/broadcom/bcm968360bg/Kconfig | 17 -- board/broadcom/bcm968360bg/MAINTAINERS | 6 - board/broadcom/bcm968360bg/Makefile | 3 - board/broadcom/bcm968360bg/bcm968360bg.c | 62 --- configs/bcm968360bg_ram_defconfig| 63 --- include/configs/bcm96856.h | 4 + include/configs/broadcom_bcm968360bg.h | 32 12 files changed, 159 insertions(+), 414 deletions(-) delete mode 100644 arch/arm/dts/bcm68360.dtsi delete mode 100644 board/broadcom/bcm968360bg/Kconfig delete mode 100644 board/broadcom/bcm968360bg/MAINTAINERS delete mode 100644 board/broadcom/bcm968360bg/Makefile delete mode 100644 board/broadcom/bcm968360bg/bcm968360bg.c delete mode 100644 configs/bcm968360bg_ram_defconfig delete mode 100644 include/configs/broadcom_bcm968360bg.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index da4defa08466..3f124ab0ce85 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -672,12 +672,6 @@ config ARCH_BCM6753 select OF_CONTROL imply CMD_DM -config ARCH_BCM68360 - bool "Broadcom BCM68360 family" - select DM - select OF_CONTROL - imply CMD_DM - config ARCH_BCM6858 bool "Broadcom BCM6858 family" select DM @@ -2280,7 +2274,6 @@ source "board/armltd/vexpress/Kconfig" source "board/armltd/vexpress64/Kconfig" source "board/cortina/presidio-asic/Kconfig" source "board/broadcom/bcm96753ref/Kconfig" -source "board/broadcom/bcm968360bg/Kconfig" source "board/broadcom/bcm968580xref/Kconfig" source "board/broadcom/bcmns3/Kconfig" source "board/cavium/thunderx/Kconfig" diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index a32bdf8c9f17..a0ea9fa6029d 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1147,9 +1147,6 @@ dtb-$(CONFIG_ARCH_BCM283X) += \ bcm2837-rpi-cm3-io3.dtb \ bcm2711-rpi-4-b.dtb -dtb-$(CONFIG_ARCH_BCM68360) += \ - bcm968360bg.dtb - dtb-$(CONFIG_ARCH_BCM6753) += \ bcm96753ref.dtb @@ -1183,7 +1180,8 @@ dtb-$(CONFIG_BCM6813) += \ dtb-$(CONFIG_BCM6846) += \ bcm96846.dtb dtb-$(CONFIG_BCM6856) += \ - bcm96856.dtb + bcm96856.dtb \ + bcm968360bg.dtb dtb-$(CONFIG_BCM6878) += \ bcm96878.dtb diff --git a/arch/arm/dts/bcm68360.dtsi b/arch/arm/dts/bcm68360.dtsi deleted file mode 100644 index 7bbe207794eb.. --- a/arch/arm/dts/bcm68360.dtsi +++ /dev/null @@ -1,217 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2020 Philippe Reynes - */ - -#include "skeleton64.dtsi" - -/ { - compatible = "brcm,bcm68360"; - #address-cells = <2>; - #size-cells = <2>; - - aliases { - spi0 = &hsspi; - }; - - cpus { - #address-cells = <2>; - #size-cells = <0>; - u-boot,dm-pre-reloc; - - cpu0: cpu@0 { - compatible = "arm,cortex-a53", "arm,armv8"; - device_type = "cpu"; - reg = <0x0 0x0>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; - }; - - cpu1: cpu@1 { - compatible = "arm,cortex-a53", "arm,armv8"; - device_type = "cpu"; - reg = <0x0 0x1>; - next-level-cache = <&l2&
Re: [PATCH v4 1/3] arm: bcmbca: add bcm6856 SoC support under CONFIG_ARCH_BCMBCA
Hi William, Le 22/08/2022 à 20:31, William Zhang a écrit : BCM6856 is a Broadcom B53 based PON Gateway SoC. It is part of the BCA (Broadband Carrier Access origin) chipset family. Like other Broadband SoC, this patch adds it under CONFIG_BCM6856 chip config and CONFIG_ARCH_BCMBCA platform config. This initial support includes a bare-bone implementation and dts with CPU subsystem, memory and Broadcom uart. This SoC is supported in the linux-next git repository so the dts and dtsi files are copied from linux. The u-boot image can be loaded from flash or network to the entry point address in the memory and boot from there to the console. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v4: -Add help in BCM6856 Kconfig option to include the list of the supported chips. MAINTAINERS | 1 + arch/arm/dts/Makefile| 2 + arch/arm/dts/bcm6856.dtsi| 103 +++ arch/arm/dts/bcm96856.dts| 30 +++ arch/arm/mach-bcmbca/Kconfig | 11 +++ arch/arm/mach-bcmbca/Makefile| 1 + arch/arm/mach-bcmbca/bcm6856/Kconfig | 17 arch/arm/mach-bcmbca/bcm6856/Makefile| 5 ++ arch/arm/mach-bcmbca/bcm6856/mmu_table.c | 32 +++ board/broadcom/bcmbca/Kconfig| 7 ++ configs/bcm96856_defconfig | 23 + include/configs/bcm96856.h | 11 +++ 12 files changed, 243 insertions(+) create mode 100644 arch/arm/dts/bcm6856.dtsi create mode 100644 arch/arm/dts/bcm96856.dts create mode 100644 arch/arm/mach-bcmbca/bcm6856/Kconfig create mode 100644 arch/arm/mach-bcmbca/bcm6856/Makefile create mode 100644 arch/arm/mach-bcmbca/bcm6856/mmu_table.c create mode 100644 configs/bcm96856_defconfig create mode 100644 include/configs/bcm96856.h diff --git a/MAINTAINERS b/MAINTAINERS index d0a5b2352cc8..1f50dad583ce 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -230,6 +230,7 @@ N: bcm[9]?63178 N:bcm[9]?6756 N:bcm[9]?6813 N:bcm[9]?6846 +N: bcm[9]?6856 N:bcm[9]?6878 ARM BROADCOM BCMSTB diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index c55bc3569662..a32bdf8c9f17 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1182,6 +1182,8 @@ dtb-$(CONFIG_BCM6813) += \ bcm96813.dtb dtb-$(CONFIG_BCM6846) += \ bcm96846.dtb +dtb-$(CONFIG_BCM6856) += \ + bcm96856.dtb dtb-$(CONFIG_BCM6878) += \ bcm96878.dtb diff --git a/arch/arm/dts/bcm6856.dtsi b/arch/arm/dts/bcm6856.dtsi new file mode 100644 index ..0bce6497219f --- /dev/null +++ b/arch/arm/dts/bcm6856.dtsi @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright 2022 Broadcom Ltd. + */ + +#include +#include + +/ { + compatible = "brcm,bcm6856", "brcm,bcmbca"; + #address-cells = <2>; + #size-cells = <2>; + + interrupt-parent = <&gic>; + + cpus { + #address-cells = <2>; + #size-cells = <0>; + + B53_0: cpu@0 { + compatible = "brcm,brahma-b53"; + device_type = "cpu"; + reg = <0x0 0x0>; + next-level-cache = <&L2_0>; + enable-method = "psci"; + }; + + B53_1: cpu@1 { + compatible = "brcm,brahma-b53"; + device_type = "cpu"; + reg = <0x0 0x1>; + next-level-cache = <&L2_0>; + enable-method = "psci"; + }; + + L2_0: l2-cache0 { + compatible = "cache"; + }; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupts = , + , + , + ; + }; + + pmu: pmu { + compatible = "arm,cortex-a53-pmu"; + interrupts = , + ; + interrupt-affinity = <&B53_0>, <&B53_1>; + }; + + clocks: clocks { + periph_clk:periph-clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <2>; + }; + }; + + psci { + compatible = "arm,psci-0.2"; + method = "smc"; + }; + + axi@8100 { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x0 0x81
Re: [PATCH v2 3/3] arm: bcmbca: make bcm68360 driver depending on CONFIG_BCM6856
Hi William, Le 15/08/2022 à 20:55, William Zhang a écrit : As CONFIG_ARCH_BCM68360 is replaced with CONFIG_BCM6856, update the driver Kconfig to use the new config symbol Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- (no changes since v1) drivers/gpio/Kconfig | 2 +- drivers/led/Kconfig | 2 +- drivers/mtd/nand/raw/Kconfig | 2 +- drivers/spi/Kconfig | 2 +- drivers/watchdog/Kconfig | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 83f4f5089992..9e00b48234ab 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -110,7 +110,7 @@ config BCM2835_GPIO config BCM6345_GPIO bool "BCM6345 GPIO driver" - depends on DM_GPIO && (ARCH_BMIPS || ARCH_BCM68360 || \ + depends on DM_GPIO && (ARCH_BMIPS || BCM6856 || \ ARCH_BCM6858 || BCM63158 || \ ARCH_BCM6753) help diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index d777414dda8d..bd8f23fd9631 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -37,7 +37,7 @@ config LED_BCM6753 config LED_BCM6858 bool "LED Support for BCM6858" - depends on LED && (ARCH_BCM68360 || ARCH_BCM6858 || BCM63158) + depends on LED && (BCM6856 || ARCH_BCM6858 || BCM63158) help This option enables support for LEDs connected to the BCM6858 HW has blinking capabilities and up to 32 LEDs can be controlled. diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig index 24c27b6ecf7f..5d006ca1ea07 100644 --- a/drivers/mtd/nand/raw/Kconfig +++ b/drivers/mtd/nand/raw/Kconfig @@ -103,7 +103,7 @@ config NAND_BRCMNAND_6753 config NAND_BRCMNAND_68360 bool "Support Broadcom NAND controller on bcm68360" - depends on NAND_BRCMNAND && ARCH_BCM68360 + depends on NAND_BRCMNAND && BCM6856 help Enable support for broadcom nand driver on bcm68360. diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 0a666eee80e7..978e5c86a420 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -91,7 +91,7 @@ config ATMEL_SPI config BCM63XX_HSSPI bool "BCM63XX HSSPI driver" - depends on (ARCH_BMIPS || ARCH_BCM68360 || \ + depends on (ARCH_BMIPS || BCM6856 || \ ARCH_BCM6858 || BCM63158) help Enable the BCM6328 HSSPI driver. This driver can be used to diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index ff4d1ee530d2..6d559515b78b 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -128,7 +128,7 @@ config WDT_AT91 config WDT_BCM6345 bool "BCM6345 watchdog timer support" - depends on WDT && (ARCH_BMIPS || ARCH_BCM68360 || \ + depends on WDT && (ARCH_BMIPS || BCM6856 || \ ARCH_BCM6858 || BCM63158 || \ ARCH_BCM6753) help
Re: [PATCH v2 2/3] arm: bcmbca: remove bcm68360 support under CONFIG_ARCH_BCM68360
Hi William, Le 15/08/2022 à 20:55, William Zhang a écrit : BCM68360 is a variant within the BCM6856 chip family. Now that BCM6856 is supported under CONFIG_ARCH_BCMBCA and CONFIG_BCM6856, remove the original ARCH_BCM68360 support and migrate its configuration and dts settings. This includes: - Remove the bcm968360bg board folder. It is replaced by the generic bcmbca board folder. - Merge the 68360.dtsi setting to the new 6856.dtsi file. Update board dts with the new compatible string. - Merge broadcom_bcm968360bg.h setting to the new bcm96856.h file. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- Changes in v2: - Bring Philippe Reynes copyright tag from 68360 dts to 6856 dts arch/arm/Kconfig | 7 - arch/arm/dts/Makefile| 6 +- arch/arm/dts/bcm68360.dtsi | 217 --- arch/arm/dts/bcm6856.dtsi| 150 arch/arm/dts/bcm968360bg.dts | 6 +- board/broadcom/bcm968360bg/Kconfig | 17 -- board/broadcom/bcm968360bg/MAINTAINERS | 6 - board/broadcom/bcm968360bg/Makefile | 3 - board/broadcom/bcm968360bg/bcm968360bg.c | 62 --- configs/bcm968360bg_ram_defconfig| 10 +- include/configs/bcm96856.h | 4 + include/configs/broadcom_bcm968360bg.h | 32 12 files changed, 164 insertions(+), 356 deletions(-) delete mode 100644 arch/arm/dts/bcm68360.dtsi delete mode 100644 board/broadcom/bcm968360bg/Kconfig delete mode 100644 board/broadcom/bcm968360bg/MAINTAINERS delete mode 100644 board/broadcom/bcm968360bg/Makefile delete mode 100644 board/broadcom/bcm968360bg/bcm968360bg.c delete mode 100644 include/configs/broadcom_bcm968360bg.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index da4defa08466..3f124ab0ce85 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -672,12 +672,6 @@ config ARCH_BCM6753 select OF_CONTROL imply CMD_DM -config ARCH_BCM68360 - bool "Broadcom BCM68360 family" - select DM - select OF_CONTROL - imply CMD_DM - config ARCH_BCM6858 bool "Broadcom BCM6858 family" select DM @@ -2280,7 +2274,6 @@ source "board/armltd/vexpress/Kconfig" source "board/armltd/vexpress64/Kconfig" source "board/cortina/presidio-asic/Kconfig" source "board/broadcom/bcm96753ref/Kconfig" -source "board/broadcom/bcm968360bg/Kconfig" source "board/broadcom/bcm968580xref/Kconfig" source "board/broadcom/bcmns3/Kconfig" source "board/cavium/thunderx/Kconfig" diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index a32bdf8c9f17..a0ea9fa6029d 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1147,9 +1147,6 @@ dtb-$(CONFIG_ARCH_BCM283X) += \ bcm2837-rpi-cm3-io3.dtb \ bcm2711-rpi-4-b.dtb -dtb-$(CONFIG_ARCH_BCM68360) += \ - bcm968360bg.dtb - dtb-$(CONFIG_ARCH_BCM6753) += \ bcm96753ref.dtb @@ -1183,7 +1180,8 @@ dtb-$(CONFIG_BCM6813) += \ dtb-$(CONFIG_BCM6846) += \ bcm96846.dtb dtb-$(CONFIG_BCM6856) += \ - bcm96856.dtb + bcm96856.dtb \ + bcm968360bg.dtb dtb-$(CONFIG_BCM6878) += \ bcm96878.dtb diff --git a/arch/arm/dts/bcm68360.dtsi b/arch/arm/dts/bcm68360.dtsi deleted file mode 100644 index 7bbe207794eb.. --- a/arch/arm/dts/bcm68360.dtsi +++ /dev/null @@ -1,217 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2020 Philippe Reynes - */ - -#include "skeleton64.dtsi" - -/ { - compatible = "brcm,bcm68360"; - #address-cells = <2>; - #size-cells = <2>; - - aliases { - spi0 = &hsspi; - }; - - cpus { - #address-cells = <2>; - #size-cells = <0>; - u-boot,dm-pre-reloc; - - cpu0: cpu@0 { - compatible = "arm,cortex-a53", "arm,armv8"; - device_type = "cpu"; - reg = <0x0 0x0>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; - }; - - cpu1: cpu@1 { - compatible = "arm,cortex-a53", "arm,armv8"; - device_type = "cpu"; - reg = <0x0 0x1>; - next-level-cache = <&l2>; - u-boot,dm-pre-reloc; - }; - - l2: l2-cache0 { - compatible = "cache"; - u-boot,dm-pre-reloc; - }; - }; - - clocks { - compatible = "simple-bus"; - #address-cells = <2>; - #size
Re: [PATCH v2 1/3] arm: bcmbca: add bcm6856 SoC support under CONFIG_ARCH_BCMBCA
Hi William, Le 15/08/2022 à 20:55, William Zhang a écrit : BCM6856 is a Broadcom B53 based PON Gateway SoC. It is part of the BCA (Broadband Carrier Access origin) chipset family. Like other Broadband SoC, this patch adds it under CONFIG_BCM6856 chip config and CONFIG_ARCH_BCMBCA platform config. This initial support includes a bare-bone implementation and dts with CPU subsystem, memory and Broadcom uart. This SoC is supported in the linux-next git repository so the dts and dtsi files are copied from linux. The u-boot image can be loaded from flash or network to the entry point address in the memory and boot from there to the console. Signed-off-by: William Zhang Reviewed-by: Philippe Reynes --- (no changes since v1) MAINTAINERS | 1 + arch/arm/dts/Makefile| 2 + arch/arm/dts/bcm6856.dtsi| 103 +++ arch/arm/dts/bcm96856.dts| 30 +++ arch/arm/mach-bcmbca/Kconfig | 8 ++ arch/arm/mach-bcmbca/Makefile| 1 + arch/arm/mach-bcmbca/bcm6856/Kconfig | 17 arch/arm/mach-bcmbca/bcm6856/Makefile| 5 ++ arch/arm/mach-bcmbca/bcm6856/mmu_table.c | 32 +++ board/broadcom/bcmbca/Kconfig| 7 ++ configs/bcm96856_defconfig | 23 + include/configs/bcm96856.h | 11 +++ 12 files changed, 240 insertions(+) create mode 100644 arch/arm/dts/bcm6856.dtsi create mode 100644 arch/arm/dts/bcm96856.dts create mode 100644 arch/arm/mach-bcmbca/bcm6856/Kconfig create mode 100644 arch/arm/mach-bcmbca/bcm6856/Makefile create mode 100644 arch/arm/mach-bcmbca/bcm6856/mmu_table.c create mode 100644 configs/bcm96856_defconfig create mode 100644 include/configs/bcm96856.h diff --git a/MAINTAINERS b/MAINTAINERS index d0a5b2352cc8..1f50dad583ce 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -230,6 +230,7 @@ N: bcm[9]?63178 N:bcm[9]?6756 N:bcm[9]?6813 N:bcm[9]?6846 +N: bcm[9]?6856 N:bcm[9]?6878 ARM BROADCOM BCMSTB diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index c55bc3569662..a32bdf8c9f17 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1182,6 +1182,8 @@ dtb-$(CONFIG_BCM6813) += \ bcm96813.dtb dtb-$(CONFIG_BCM6846) += \ bcm96846.dtb +dtb-$(CONFIG_BCM6856) += \ + bcm96856.dtb dtb-$(CONFIG_BCM6878) += \ bcm96878.dtb diff --git a/arch/arm/dts/bcm6856.dtsi b/arch/arm/dts/bcm6856.dtsi new file mode 100644 index ..0bce6497219f --- /dev/null +++ b/arch/arm/dts/bcm6856.dtsi @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright 2022 Broadcom Ltd. + */ + +#include +#include + +/ { + compatible = "brcm,bcm6856", "brcm,bcmbca"; + #address-cells = <2>; + #size-cells = <2>; + + interrupt-parent = <&gic>; + + cpus { + #address-cells = <2>; + #size-cells = <0>; + + B53_0: cpu@0 { + compatible = "brcm,brahma-b53"; + device_type = "cpu"; + reg = <0x0 0x0>; + next-level-cache = <&L2_0>; + enable-method = "psci"; + }; + + B53_1: cpu@1 { + compatible = "brcm,brahma-b53"; + device_type = "cpu"; + reg = <0x0 0x1>; + next-level-cache = <&L2_0>; + enable-method = "psci"; + }; + + L2_0: l2-cache0 { + compatible = "cache"; + }; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupts = , + , + , + ; + }; + + pmu: pmu { + compatible = "arm,cortex-a53-pmu"; + interrupts = , + ; + interrupt-affinity = <&B53_0>, <&B53_1>; + }; + + clocks: clocks { + periph_clk:periph-clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <2>; + }; + }; + + psci { + compatible = "arm,psci-0.2"; + method = "smc"; + }; + + axi@8100 { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x0 0x8100 0x8000>; + + gic: interrupt-controller@1000 { + compatible =
Re: [PATCH v3 1/1] arm: bcmbca: introduce the bcmbca architecture and 47622 SOC
Hi William, Le 09/05/2022 à 18:28, William Zhang a écrit : This is the initial support for Broadcom's ARM-based 47622 SOC. In this change, our first SOC is an armv7 platform called 47622. The initial support includes a bare-bone implementation and dts with ARM PL011 uart. The SOC-specific code resides in arch/arm/mach-bcmbca/ and board related code is in board/broadcom/bcmba. The u-boot image can be loaded from flash or network to the entry point address in the memory and boot from there. Signed-off-by: William Zhang Signed-off-by: Kursad Oney Signed-off-by: Anand Gore Reviewed-by: Philippe Reynes --- Changes in v3: - Remove the CONFIG_SYS_BAUDRATE_TABLE to use the u-boot default table Changes in v2: - Updated dts and dtsi files which are accpeted in linux-next upstream - Changed CONFIG_SYS_TEXT_BASE to 0x0100 from 0x1000 to work on boards with 256MB or less memory MAINTAINERS| 11 +++ arch/arm/Kconfig | 7 ++ arch/arm/Makefile | 1 + arch/arm/dts/Makefile | 3 + arch/arm/dts/bcm47622.dtsi | 126 + arch/arm/dts/bcm947622.dts | 30 ++ arch/arm/mach-bcmbca/Kconfig | 17 arch/arm/mach-bcmbca/Makefile | 6 ++ arch/arm/mach-bcmbca/bcm47622/Kconfig | 17 arch/arm/mach-bcmbca/bcm47622/Makefile | 5 + board/broadcom/bcmbca/Kconfig | 17 board/broadcom/bcmbca/Makefile | 5 + board/broadcom/bcmbca/board.c | 35 +++ configs/bcm947622_defconfig| 18 include/configs/bcm947622.h| 18 15 files changed, 316 insertions(+) create mode 100644 arch/arm/dts/bcm47622.dtsi create mode 100644 arch/arm/dts/bcm947622.dts create mode 100644 arch/arm/mach-bcmbca/Kconfig create mode 100644 arch/arm/mach-bcmbca/Makefile create mode 100644 arch/arm/mach-bcmbca/bcm47622/Kconfig create mode 100644 arch/arm/mach-bcmbca/bcm47622/Makefile create mode 100644 board/broadcom/bcmbca/Kconfig create mode 100644 board/broadcom/bcmbca/Makefile create mode 100644 board/broadcom/bcmbca/board.c create mode 100644 configs/bcm947622_defconfig create mode 100644 include/configs/bcm947622.h diff --git a/MAINTAINERS b/MAINTAINERS index 56be0bfad00c..96cd85dd1c7a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -195,6 +195,17 @@ F: drivers/pinctrl/broadcom/ F:configs/rpi_* T:git https://source.denx.de/u-boot/custodians/u-boot-arm.git +ARM BROADCOM BCMBCA +M: Anand Gore +M: William Zhang +M: Kursad Oney +M: Joel Peshkin +S: Maintained +F: arch/arm/mach-bcmbca/ +F: board/broadcom/bcmbca/ +F: configs/bcm947622_defconfig +F: include/configs/bcm947622.h + ARM BROADCOM BCMSTB M:Thomas Fitzsimmons S:Maintained diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 57946f61fabe..5e231fc72854 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -712,6 +712,11 @@ config ARCH_BCMSTB This enables support for Broadcom ARM-based set-top box chipsets, including the 7445 family of chips. +config ARCH_BCMBCA + bool "Broadcom broadband chip family" + select DM + select OF_CONTROL + config TARGET_VEXPRESS_CA9X4 bool "Support vexpress_ca9x4" select CPU_V7A @@ -2175,6 +2180,8 @@ source "arch/arm/mach-at91/Kconfig" source "arch/arm/mach-bcm283x/Kconfig" +source "arch/arm/mach-bcmbca/Kconfig" + source "arch/arm/mach-bcmstb/Kconfig" source "arch/arm/mach-davinci/Kconfig" diff --git a/arch/arm/Makefile b/arch/arm/Makefile index ad757e982e37..0fd127e0e7e4 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -59,6 +59,7 @@ machine-$(CONFIG_ARCH_APPLE) += apple machine-$(CONFIG_ARCH_ASPEED) += aspeed machine-$(CONFIG_ARCH_AT91) += at91 machine-$(CONFIG_ARCH_BCM283X)+= bcm283x +machine-$(CONFIG_ARCH_BCMBCA) += bcmbca machine-$(CONFIG_ARCH_BCMSTB) += bcmstb machine-$(CONFIG_ARCH_DAVINCI)+= davinci machine-$(CONFIG_ARCH_EXYNOS) += exynos diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index ab2d0da192c6..db42475bba1c 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -1132,6 +1132,9 @@ dtb-$(CONFIG_TARGET_BCMNS3) += ns3-board.dtb dtb-$(CONFIG_ARCH_BCMSTB) += bcm7xxx.dtb +dtb-$(CONFIG_BCM47622) += \ + bcm947622.dtb + dtb-$(CONFIG_ASPEED_AST2500) += ast2500-evb.dtb dtb-$(CONFIG_ASPEED_AST2600) += ast2600-evb.dtb diff --git a/arch/arm/dts/bcm47622.dtsi b/arch/arm/dts/bcm47622.dtsi new file mode 100644 index ..c016e12b7372 --- /dev/null +++ b/arch/arm/dts/bcm47622.dtsi @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright 2022 Broadcom Ltd. + */ + +#in
[PATCH 1/3] disk: part_efi: add support to repair gpt table
If a gpt table is corrupted (after a power cut for example), then the gpt table should repaired. The function gpt_repair_headers check if at least one gpt table is valid, and then only write the corrupted gpt table. Signed-off-by: Philippe Reynes --- disk/part_efi.c | 86 + include/part.h | 10 ++ 2 files changed, 96 insertions(+) diff --git a/disk/part_efi.c b/disk/part_efi.c index f1f3e5bcef..829ccb6bd1 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -705,6 +705,92 @@ int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head, return 0; } +static void restore_primary_gpt_header(gpt_header *gpt_h, struct blk_desc *dev_desc) +{ + u32 calc_crc32; + u64 val; + + /* recalculate the values for the Primary GPT Header */ + val = le64_to_cpu(gpt_h->my_lba); + gpt_h->my_lba = gpt_h->alternate_lba; + gpt_h->alternate_lba = cpu_to_le64(val); + gpt_h->partition_entry_lba = cpu_to_le64(partition_entries_offset(dev_desc)); + + gpt_h->header_crc32 = 0; + + calc_crc32 = efi_crc32((const unsigned char *)gpt_h, + le32_to_cpu(gpt_h->header_size)); + gpt_h->header_crc32 = cpu_to_le32(calc_crc32); +} + +static int write_one_gpt_table(struct blk_desc *dev_desc, + gpt_header *gpt_h, gpt_entry *gpt_e) +{ + const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries + * sizeof(gpt_entry)), dev_desc); + lbaint_t start; + int ret = 0; + + start = le64_to_cpu(gpt_h->my_lba); + if (blk_dwrite(dev_desc, start, 1, gpt_h) != 1) { + ret = -1; + goto out; + } + + start = le64_to_cpu(gpt_h->partition_entry_lba); + if (blk_dwrite(dev_desc, start, pte_blk_cnt, gpt_e) != pte_blk_cnt) { + ret = -1; + goto out; + } + + out: + return ret; +} + +int gpt_repair_headers(struct blk_desc *dev_desc) +{ + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_h1, 1, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_h2, 1, dev_desc->blksz); + gpt_entry *gpt_e1 = NULL, *gpt_e2 = NULL; + int is_gpt1_valid, is_gpt2_valid; + int ret = -1; + + is_gpt1_valid = is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, +gpt_h1, &gpt_e1); + is_gpt2_valid = is_gpt_valid(dev_desc, dev_desc->lba - 1, +gpt_h2, &gpt_e2); + + if (is_gpt1_valid && is_gpt2_valid) { + ret = 0; + goto out; + } + + if (is_gpt1_valid && !is_gpt2_valid) { + prepare_backup_gpt_header(gpt_h1); + ret = write_one_gpt_table(dev_desc, gpt_h1, gpt_e1); + goto out; + } + + if (!is_gpt1_valid && is_gpt2_valid) { + restore_primary_gpt_header(gpt_h2, dev_desc); + ret = write_one_gpt_table(dev_desc, gpt_h2, gpt_e2); + goto out; + } + + if (!is_gpt1_valid && !is_gpt2_valid) { + ret = -1; + goto out; + } + + out: + if (is_gpt1_valid) + free(gpt_e1); + if (is_gpt2_valid) + free(gpt_e2); + + return ret; +} + int gpt_verify_partitions(struct blk_desc *dev_desc, struct disk_partition *partitions, int parts, gpt_header *gpt_head, gpt_entry **gpt_pte) diff --git a/include/part.h b/include/part.h index 53cfbdd876..5b15a99d69 100644 --- a/include/part.h +++ b/include/part.h @@ -433,6 +433,16 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf); int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head, gpt_entry **gpt_pte); +/** + * gpt_repair_headers() - Function to repair the GPT's header + *and partition table entries (PTE) + * + * @param dev_desc - block device descriptor + * + * Return: - '0' on success, otherwise error + */ +int gpt_repair_headers(struct blk_desc *dev_desc); + /** * gpt_verify_partitions() - Function to check if partitions' name, start and * size correspond to '$partitions' env variable -- 2.25.1
[PATCH 2/3] cmd: gpt: add subcommand repair
Adds a sub-command repair to the command gpt that allow to repair a corrupted gpt table. If the both gpt table (primary and backup) are valid, then the command does nothing. Signed-off-by: Philippe Reynes --- cmd/gpt.c | 16 +++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/gpt.c b/cmd/gpt.c index 1c0525fbf6..007a68eaa7 100644 --- a/cmd/gpt.c +++ b/cmd/gpt.c @@ -586,6 +586,15 @@ err: return errno; } +static int gpt_repair(struct blk_desc *blk_dev_desc) +{ + int ret = 0; + + ret = gpt_repair_headers(blk_dev_desc); + + return ret; +} + static int gpt_default(struct blk_desc *blk_dev_desc, const char *str_part) { int ret; @@ -997,7 +1006,10 @@ static int do_gpt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_FAILURE; } - if ((strcmp(argv[1], "write") == 0) && (argc == 5)) { + if (strcmp(argv[1], "repair") == 0) { + printf("Repairing GPT: "); + ret = gpt_repair(blk_dev_desc); + } else if ((strcmp(argv[1], "write") == 0) && (argc == 5)) { printf("Writing GPT: "); ret = gpt_default(blk_dev_desc, argv[4]); } else if ((strcmp(argv[1], "verify") == 0)) { @@ -1036,6 +1048,8 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt, " Restore or verify GPT information on a device connected\n" " to interface\n" " Example usage:\n" + " gpt repair mmc 0\n" + "- repair the GPT on the device\n" " gpt write mmc 0 $partitions\n" "- write the GPT to device\n" " gpt verify mmc 0 $partitions\n" -- 2.25.1
[PATCH 3/3] test: py: tests: test_gpt.py: add a simple test for the command gpt repair
Adds a simple test for the command gpt repair. Signed-off-by: Philippe Reynes --- test/py/tests/test_gpt.py | 10 ++ 1 file changed, 10 insertions(+) diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py index 229d7eb2c2..f707d9f253 100644 --- a/test/py/tests/test_gpt.py +++ b/test/py/tests/test_gpt.py @@ -98,6 +98,16 @@ def test_gpt_verify(state_disk_image, u_boot_console): output = u_boot_console.run_command('gpt verify host 0') assert 'Verify GPT: success!' in output +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpt') +@pytest.mark.requiredtool('sgdisk') +def test_gpt_repair(state_disk_image, u_boot_console): +"""Test the gpt repair command.""" + +u_boot_console.run_command('host bind 0 ' + state_disk_image.path) +output = u_boot_console.run_command('gpt repair host 0') +assert 'Repairing GPT: success!' in output + @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_gpt') @pytest.mark.requiredtool('sgdisk') -- 2.25.1
[PATCH 0/3] gpt: add support to repair gpt
This serie adds a sub-command repair to command gpt to repair a gpt. It only writes the gpt that is corrupted, and not both gpt. So a powercut in the middle of the sub-command repair should not corrupt the last valid gpt. Philippe Reynes (3): disk: part_efi: add support to repair gpt table cmd: gpt: add subcommand repair test: py: tests: test_gpt.py: add a simple test for the command gpt repair cmd/gpt.c | 16 +++- disk/part_efi.c | 86 +++ include/part.h| 10 + test/py/tests/test_gpt.py | 10 + 4 files changed, 121 insertions(+), 1 deletion(-) -- 2.25.1
[PATCH 0/4] mmc: add support for bcm63158
This serie adds the support of mmc for bcm63158. The first commit adds a driver that support sdhci on bcm63158. The two next commits add support of mmc in the device tree, and the last one enables the support of mmc and gpt for the reference board bcm963158. Philippe Reynes (4): drivers: mmc: bcm63158_sdhci: initial support arch: arm: dts: bcm63158.dtsi: add mmc support arch: arm: dts: bcm963158.dts: enable sdhci support configs: bcm963158_ram_defconfig: enable mmc and gpt support arch/arm/dts/bcm63158.dtsi | 9 ++ arch/arm/dts/bcm963158.dts | 4 + configs/bcm963158_ram_defconfig | 8 +- drivers/mmc/Kconfig | 12 +++ drivers/mmc/Makefile| 1 + drivers/mmc/bcm63158_sdhci.c| 153 6 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 drivers/mmc/bcm63158_sdhci.c -- 2.25.1
[PATCH 1/4] drivers: mmc: bcm63158_sdhci: initial support
Adds a driver to support shdci on bcm63158. Signed-off-by: Philippe Reynes --- drivers/mmc/Kconfig | 12 +++ drivers/mmc/Makefile | 1 + drivers/mmc/bcm63158_sdhci.c | 153 +++ 3 files changed, 166 insertions(+) create mode 100644 drivers/mmc/bcm63158_sdhci.c diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index f04cc44e19..a08e8245cf 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -520,6 +520,18 @@ config MMC_SDHCI_BCM2835 If unsure, say N. +config MMC_SDHCI_BCM63158 + bool "SDHCI support for the BCM63158 SD/MMC Controller" + depends on ARCH_BCM63158 + depends on MMC_SDHCI + help + This selects the BCM63158 SD/MMC controller. + + If you have a BCM63158 platform with SD or MMC devices, + say Y here. + + If unsure, say N. + config MMC_SDHCI_BCMSTB tristate "SDHCI support for the BCMSTB SD/MMC Controller" depends on MMC_SDHCI diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile index 17ebc04203..5cebd55549 100644 --- a/drivers/mmc/Makefile +++ b/drivers/mmc/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_MMC_SDHCI) += sdhci.o obj-$(CONFIG_MMC_SDHCI_ASPEED) += aspeed_sdhci.o obj-$(CONFIG_MMC_SDHCI_ATMEL) += atmel_sdhci.o obj-$(CONFIG_MMC_SDHCI_BCM2835)+= bcm2835_sdhci.o +obj-$(CONFIG_MMC_SDHCI_BCM63158) += bcm63158_sdhci.o obj-$(CONFIG_MMC_SDHCI_BCMSTB) += bcmstb_sdhci.o obj-$(CONFIG_MMC_SDHCI_CADENCE)+= sdhci-cadence.o obj-$(CONFIG_MMC_SDHCI_AM654) += am654_sdhci.o diff --git a/drivers/mmc/bcm63158_sdhci.c b/drivers/mmc/bcm63158_sdhci.c new file mode 100644 index 00..42295d113d --- /dev/null +++ b/drivers/mmc/bcm63158_sdhci.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Philippe Reynes + * + * based on: + * drivers/mmc/bcmstb_sdhci.c + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* 400KHz is max freq for card ID etc. Use that as min */ +#define MIN_FREQ 40 + +#define BCM63158_MMC_BOOT_MAIN_CTL_REG 0x0 +#define BCM63158_MMC_BOOT_STATUS_REG 0x4 +#define BCM63158_MMC_BOOT_MODE_MASK1 + +struct sdhci_bcm63158_plat { + struct mmc_config cfg; + struct mmc mmc; +}; + +static int sdhci_bcm63158_bind(struct udevice *dev) +{ + struct sdhci_bcm63158_plat *plat = dev_get_plat(dev); + + return sdhci_bind(dev, &plat->mmc, &plat->cfg); +} + +static int sdhci_bcm63158_set_normal_mode(void *boot_regs) +{ + void *boot_main_ctl_reg = boot_regs + BCM63158_MMC_BOOT_MAIN_CTL_REG; + void *boot_status_reg = boot_regs + BCM63158_MMC_BOOT_STATUS_REG; + u32 status; + int i, max_retry = 10; + int ret = -1; + + status = readl(boot_status_reg); + if ((status & BCM63158_MMC_BOOT_MODE_MASK) == 0) { + ret = 0; + goto out; + } + + clrbits_32(boot_main_ctl_reg, BCM63158_MMC_BOOT_MODE_MASK); + + for (i = 0; i < max_retry; i++) { + status = readl(boot_status_reg); + if ((status & BCM63158_MMC_BOOT_MODE_MASK) == 0) { + ret = 0; + goto out; + } + + mdelay(10); + } + + log_err("%s: can't set mode normal\n", __func__); + + out: + return ret; +} + +static int sdhci_bcm63158_probe(struct udevice *dev) +{ + struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); + struct sdhci_bcm63158_plat *plat = dev_get_plat(dev); + struct sdhci_host *host = dev_get_priv(dev); + struct resource res; + void *boot_regs; + int ret; + + host->name = dev->name; + + /* Get sdhci controller base address */ + ret = dev_read_resource_byname(dev, "sdhci-base", &res); + if (ret) { + dev_err(dev, "can't get regs sdhci-base address(ret = %d)!\n", ret); + return ret; + } + + host->quirks |= SDHCI_QUIRK_WAIT_SEND_CMD; + host->ioaddr = devm_ioremap(dev, res.start, resource_size(&res)); + if (IS_ERR(host->ioaddr)) + return PTR_ERR(host->ioaddr); + + /* Get sdhci boot controller base address */ + ret = dev_read_resource_byname(dev, "sdhci-boot", &res); + if (ret) { + dev_err(dev, "can't get regs sdhci-boot address(ret = %d)!\n", ret); + return ret; + } + + boot_regs = devm_ioremap(dev, res.start, resource_size(&res)); + if (IS_ERR(boot_regs)) + return PTR_ERR(boot_regs); + + /* Set normal mode instead of boot mode */ + ret = sdhci_bcm63158_set_normal_mode(boot_regs); + if (ret) +
[PATCH 2/4] arch: arm: dts: bcm63158.dtsi: add mmc support
Adds the support of sdhci on bcm63158. Signed-off-by: Philippe Reynes --- arch/arm/dts/bcm63158.dtsi | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/arm/dts/bcm63158.dtsi b/arch/arm/dts/bcm63158.dtsi index 7dd2858438..4e0f5f2dbd 100644 --- a/arch/arm/dts/bcm63158.dtsi +++ b/arch/arm/dts/bcm63158.dtsi @@ -229,5 +229,14 @@ status = "disabled"; }; + + sdhci: sdhci { + compatible = "brcm,bcm63158-sdhci"; + reg-names = "sdhci-base", "sdhci-boot"; + reg = <0x 0xff81 0x 0x0100>, + <0x 0xff810200 0x 0x0040>; + bus-width = <0x0008>; + no-1-8-v; + }; }; }; -- 2.25.1
[PATCH 4/4] configs: bcm963158_ram_defconfig: enable mmc and gpt support
Enable the support of emmc and gpt on bcm63158 Signed-off-by: Philippe Reynes --- configs/bcm963158_ram_defconfig | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/configs/bcm963158_ram_defconfig b/configs/bcm963158_ram_defconfig index 642faf511f..5fc89fc99d 100644 --- a/configs/bcm963158_ram_defconfig +++ b/configs/bcm963158_ram_defconfig @@ -24,21 +24,23 @@ CONFIG_HUSH_PARSER=y # CONFIG_CMD_UNZIP is not set # CONFIG_CMD_FLASH is not set CONFIG_CMD_GPIO=y +CONFIG_CMD_GPT=y +CONFIG_CMD_GPT_RENAME=y +CONFIG_CMD_MMC=y CONFIG_CMD_MTD=y CONFIG_CMD_NAND=y CONFIG_CMD_CACHE=y CONFIG_DOS_PARTITION=y CONFIG_ISO_PARTITION=y -CONFIG_EFI_PARTITION=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y # CONFIG_NET is not set -CONFIG_BLK=y CONFIG_CLK=y CONFIG_BCM6345_GPIO=y CONFIG_LED=y CONFIG_LED_BCM6858=y CONFIG_LED_BLINK=y -# CONFIG_MMC is not set +CONFIG_MMC_SDHCI=y +CONFIG_MMC_SDHCI_BCM63158=y CONFIG_MTD=y CONFIG_DM_MTD=y CONFIG_MTD_RAW_NAND=y -- 2.25.1
[PATCH 3/4] arch: arm: dts: bcm963158.dts: enable sdhci support
Enable the support of sdhci on bcm63158. Signed-off-by: Philippe Reynes --- arch/arm/dts/bcm963158.dts | 4 1 file changed, 4 insertions(+) diff --git a/arch/arm/dts/bcm963158.dts b/arch/arm/dts/bcm963158.dts index c2bdd33274..c96fa60841 100644 --- a/arch/arm/dts/bcm963158.dts +++ b/arch/arm/dts/bcm963158.dts @@ -137,3 +137,7 @@ spi-max-frequency = <2500>; }; }; + +&sdhci { + status = "okay"; +}; -- 2.25.1
Re: [PATCH v6 15/16] cmd: verify: initial import
Hi Simon, Le 28/03/2022 à 08:35, Simon Glass a écrit : Hi Philippe, On Thu, 10 Mar 2022 at 09:53, Philippe REYNES wrote: Hi Simon, Le 03/03/2022 à 04:37, Simon Glass a écrit : Hi Philippe, On Fri, 25 Feb 2022 at 07:58, Philippe Reynes wrote: Add the command verify that check the signature of an image with the pre-load header. If the check succeed, the u-boot env variable 'loadaddr_verified' is set to the address of the image (without the header). It allows to run such commands: tftp script.img && verify $loadaddr && source $loadaddr_verified Signed-off-by: Philippe Reynes --- cmd/Kconfig | 7 +++ cmd/Makefile | 1 + cmd/verify.c | 53 3 files changed, 61 insertions(+) create mode 100644 cmd/verify.c Using the 'verify' command seems a bit vague. Could it be a sub-command of bootm perhaps? The command verify may be used with any binary (script, video firmware, .). So a lot of binaries that are not launched by bootm. I think that it is not "logic" to used a bootm subcommand. But we could use another name if you want. For example : pre_load_verify ? I see. Well, I suppose this is a boot loader, so 'verify' would be expected to mean verifying an image or something to boot, so this seems reasonable to me. But I do like the idea of putting pre_load in there somewhere if you can, since we do most other verification as part of the 'bootm' command. Up to you. I have sent a v8 where I remove the command pre_load_verify, and add the subcommand preload to bootm. Reviewed-by: Simon Glass Regards, Simon Regards, Philippe
Re: [PATCH v7 14/16] test: py: vboot: add test for global image signature
Hi Tom, Le 26/03/2022 à 00:02, Tom Rini a écrit : On Fri, Mar 25, 2022 at 11:54:18PM +0100, Philippe REYNES wrote: Hi Tom, Le 25/03/2022 à 18:11, Tom Rini a écrit : On Mon, Mar 14, 2022 at 03:57:43PM +0100, Philippe Reynes wrote: Adds test units for the pre-load header signature. Signed-off-by: Philippe Reynes --- test/py/tests/test_vboot.py | 145 -- test/py/tests/vboot/sandbox-binman-pss.dts| 25 +++ test/py/tests/vboot/sandbox-binman.dts| 24 +++ .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 test/py/tests/vboot/sandbox-u-boot-global.dts | 27 test/py/tests/vboot/simple-images.its | 36 + 6 files changed, 269 insertions(+), 16 deletions(-) create mode 100644 test/py/tests/vboot/sandbox-binman-pss.dts create mode 100644 test/py/tests/vboot/sandbox-binman.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-pss.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global.dts create mode 100644 test/py/tests/vboot/simple-images.its This leads to CI failures such as: https://source.denx.de/u-boot/u-boot/-/jobs/412046 and I guess maybe we need something new in test/py/requirements.txt maybe? I think that this issue should be fixed with this patch : https://patchwork.ozlabs.org/project/uboot/patch/20220127140314.10264-2-philippe.rey...@softathome.com/ OK, but that's a rather specific hard-coded path to add, and won't work in my setup for example since I use mktemp to make the base dir for all my tests. I have sent a v8 with a change in test_vboot to use PYTHONPATH, so the CI should be fixed. And this patch is no longer needed. Regards, Philippe
[PATCH v8 14/15] test: py: vboot: add test for global image signature
Adds test units for the pre-load header signature. Signed-off-by: Philippe Reynes --- test/py/tests/test_vboot.py | 148 -- test/py/tests/vboot/sandbox-binman-pss.dts| 25 +++ test/py/tests/vboot/sandbox-binman.dts| 24 +++ .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 test/py/tests/vboot/sandbox-u-boot-global.dts | 27 test/py/tests/vboot/simple-images.its | 36 + 6 files changed, 272 insertions(+), 16 deletions(-) create mode 100644 test/py/tests/vboot/sandbox-binman-pss.dts create mode 100644 test/py/tests/vboot/sandbox-binman.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-pss.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global.dts create mode 100644 test/py/tests/vboot/simple-images.its diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py index ac8ed9f114..040147d88b 100644 --- a/test/py/tests/test_vboot.py +++ b/test/py/tests/test_vboot.py @@ -21,6 +21,14 @@ For configuration verification: - Corrupt the signature - Check that image verification no-longer works +For pre-load header verification: +- Create FIT image with a pre-load header +- Check that signature verification succeeds +- Corrupt the FIT image +- Check that signature verification fails +- Launch an FIT image without a pre-load header +- Check that image verification fails + Tests run with both SHA1 and SHA256 hashing. """ @@ -35,19 +43,21 @@ import vboot_evil # Only run the full suite on a few combinations, since it doesn't add any more # test coverage. TESTDATA = [ -['sha1-basic', 'sha1', '', None, False, True, False], -['sha1-pad', 'sha1', '', '-E -p 0x1', False, False, False], -['sha1-pss', 'sha1', '-pss', None, False, False, False], -['sha1-pss-pad', 'sha1', '-pss', '-E -p 0x1', False, False, False], -['sha256-basic', 'sha256', '', None, False, False, False], -['sha256-pad', 'sha256', '', '-E -p 0x1', False, False, False], -['sha256-pss', 'sha256', '-pss', None, False, False, False], -['sha256-pss-pad', 'sha256', '-pss', '-E -p 0x1', False, False, False], -['sha256-pss-required', 'sha256', '-pss', None, True, False, False], -['sha256-pss-pad-required', 'sha256', '-pss', '-E -p 0x1', True, True, False], -['sha384-basic', 'sha384', '', None, False, False, False], -['sha384-pad', 'sha384', '', '-E -p 0x1', False, False, False], -['algo-arg', 'algo-arg', '', '-o sha256,rsa2048', False, False, True], +['sha1-basic', 'sha1', '', None, False, True, False, False], +['sha1-pad', 'sha1', '', '-E -p 0x1', False, False, False, False], +['sha1-pss', 'sha1', '-pss', None, False, False, False, False], +['sha1-pss-pad', 'sha1', '-pss', '-E -p 0x1', False, False, False, False], +['sha256-basic', 'sha256', '', None, False, False, False, False], +['sha256-pad', 'sha256', '', '-E -p 0x1', False, False, False, False], +['sha256-pss', 'sha256', '-pss', None, False, False, False, False], +['sha256-pss-pad', 'sha256', '-pss', '-E -p 0x1', False, False, False, False], +['sha256-pss-required', 'sha256', '-pss', None, True, False, False, False], +['sha256-pss-pad-required', 'sha256', '-pss', '-E -p 0x1', True, True, False, False], +['sha384-basic', 'sha384', '', None, False, False, False, False], +['sha384-pad', 'sha384', '', '-E -p 0x1', False, False, False, False], +['algo-arg', 'algo-arg', '', '-o sha256,rsa2048', False, False, True, False], +['sha256-global-sign', 'sha256', '', '', False, False, False, True], +['sha256-global-sign-pss', 'sha256', '-pss', '', False, False, False, True], ] @pytest.mark.boardspec('sandbox') @@ -56,10 +66,10 @@ TESTDATA = [ @pytest.mark.requiredtool('fdtget') @pytest.mark.requiredtool('fdtput') @pytest.mark.requiredtool('openssl') -@pytest.mark.parametrize("name,sha_
[PATCH v8 12/15] tools: binman: add support for pre-load header
Adds the support of the pre-load header with the image signature to binman. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- tools/binman/entries.rst | 38 tools/binman/etype/pre_load.py| 162 ++ tools/binman/ftest.py | 51 ++ tools/binman/test/225_dev.key | 28 +++ tools/binman/test/225_pre_load.dts| 22 +++ tools/binman/test/226_pre_load_pkcs.dts | 23 +++ tools/binman/test/227_pre_load_pss.dts| 23 +++ .../test/228_pre_load_invalid_padding.dts | 23 +++ .../binman/test/229_pre_load_invalid_sha.dts | 23 +++ .../binman/test/230_pre_load_invalid_algo.dts | 23 +++ .../binman/test/231_pre_load_invalid_key.dts | 23 +++ 11 files changed, 439 insertions(+) create mode 100644 tools/binman/etype/pre_load.py create mode 100644 tools/binman/test/225_dev.key create mode 100644 tools/binman/test/225_pre_load.dts create mode 100644 tools/binman/test/226_pre_load_pkcs.dts create mode 100644 tools/binman/test/227_pre_load_pss.dts create mode 100644 tools/binman/test/228_pre_load_invalid_padding.dts create mode 100644 tools/binman/test/229_pre_load_invalid_sha.dts create mode 100644 tools/binman/test/230_pre_load_invalid_algo.dts create mode 100644 tools/binman/test/231_pre_load_invalid_key.dts diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst index 484cde5c80..ef8351d969 100644 --- a/tools/binman/entries.rst +++ b/tools/binman/entries.rst @@ -1009,6 +1009,44 @@ placed at offset 'RESET_VECTOR_ADDRESS - 0xffc'. +Entry: pre-load: Pre load image header +-- + +Properties / Entry arguments: +- key-path: Path of the directory that store key (provided by the environment variable KEY_PATH) +- content: List of phandles to entries to sign +- algo-name: Hash and signature algo to use for the signature +- padding-name: Name of the padding (pkcs-1.5 or pss) +- key-name: Filename of the private key to sign +- header-size: Total size of the header +- version: Version of the header + +This entry creates a pre-load header that contains a global +image signature. + +For example, this creates an image with a pre-load header and a binary:: + +binman { +image2 { +filename = "sandbox.bin"; + +pre-load { +content = <&image>; +algo-name = "sha256,rsa2048"; +padding-name = "pss"; +key-name = "private.pem"; +header-size = <4096>; +version = <1>; +}; + +image: blob-ext { +filename = "sandbox.itb"; +}; +}; +}; + + + Entry: scp: System Control Processor (SCP) firmware blob diff --git a/tools/binman/etype/pre_load.py b/tools/binman/etype/pre_load.py new file mode 100644 index 00..245ee75525 --- /dev/null +++ b/tools/binman/etype/pre_load.py @@ -0,0 +1,162 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2022 Softathome +# Written by Philippe Reynes +# +# Entry-type for the global header +# + +import os +import struct +from dtoc import fdt_util +from patman import tools + +from binman.entry import Entry +from binman.etype.collection import Entry_collection +from binman.entry import EntryArg + +from Cryptodome.Hash import SHA256, SHA384, SHA512 +from Cryptodome.PublicKey import RSA +from Cryptodome.Signature import pkcs1_15 +from Cryptodome.Signature import pss + +PRE_LOAD_MAGIC = b'UBSH' + +RSAS = { +'rsa1024': 1024 / 8, +'rsa2048': 2048 / 8, +'rsa4096': 4096 / 8 +} + +SHAS = { +'sha256': SHA256, +'sha384': SHA384, +'sha512': SHA512 +} + +class Entry_pre_load(Entry_collection): +"""Pre load image header + +Properties / Entry arguments: +- pre-load-key-path: Path of the directory that store key (provided by the environment variable PRE_LOAD_KEY_PATH) +- content: List of phandles to entries to sign +- algo-name: Hash and signature algo to use for the signature +- padding-name: Name of the padding (pkcs-1.5 or pss) +- key-name: Filename of the private key to sign +- header-size: Total size of the header +- version: Version of the header + +This entry creates a pre-load header that contains a global +image signature. + +For example, this creates an image with a pre-load header and a binary:: + +binman { +image2 { +filename = "sandbox.bin"; + +pre-load { +content = <&image>; +algo-name = "sha256,rsa2048"; +paddi
[PATCH v8 15/15] cmd: bootm: add subcommand preload
Add a subcommand preload to bootm that execute the preload stage on the image. Right now, it checks the signature of the image with the pre-load header. If the check succeed, the u-boot env variable 'loadaddr_verified' is set to the address of the image (without the header). It allows to run such commands: tftp script.img && bootm preload $loadaddr && source $loadaddr_verified Signed-off-by: Philippe Reynes --- cmd/bootm.c | 30 ++ 1 file changed, 30 insertions(+) diff --git a/cmd/bootm.c b/cmd/bootm.c index 87d40d494c..1f70ee9e91 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -44,6 +44,9 @@ static int do_imls(struct cmd_tbl *cmdtp, int flag, int argc, static struct cmd_tbl cmd_bootm_sub[] = { U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""), U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""), +#ifdef CONFIG_CMD_BOOTM_PRE_LOAD + U_BOOT_CMD_MKENT(preload, 0, 1, (void *)BOOTM_STATE_PRE_LOAD, "", ""), +#endif #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""), #endif @@ -57,6 +60,20 @@ static struct cmd_tbl cmd_bootm_sub[] = { U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""), }; +#if defined(CONFIG_CMD_BOOTM_PRE_LOAD) +static ulong bootm_get_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = hextoul(argv[0], NULL); + else + addr = image_load_addr; + + return addr; +} +#endif + static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -72,6 +89,10 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, if (state == BOOTM_STATE_START) state |= BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; +#if defined(CONFIG_CMD_BOOTM_PRE_LOAD) + if (state == BOOTM_STATE_PRE_LOAD) + state |= BOOTM_STATE_START; +#endif } else { /* Unrecognized command */ return CMD_RET_USAGE; @@ -85,6 +106,12 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); +#if defined(CONFIG_CMD_BOOTM_PRE_LOAD) + if (!ret && (state & BOOTM_STATE_PRE_LOAD)) + env_set_hex("loadaddr_verified", + bootm_get_addr(argc, argv) + image_load_offset); +#endif + return ret; } @@ -177,6 +204,9 @@ static char bootm_help_text[] = "must be\n" "issued in the order below (it's ok to not issue all sub-commands):\n" "\tstart [addr [arg ...]]\n" +#if defined(CONFIG_CMD_BOOTM_PRE_LOAD) + "\tpreload [addr [arg ..]] - run only the preload stage\n" +#endif "\tloados - load OS image\n" #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n" -- 2.25.1
[PATCH v8 13/15] configs: sandbox_defconfig: enable stage pre-load in bootm
Enable the support of stage pre-load in bootm. For the moment, this stage allow to verify the signature of the full image with a header. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- configs/sandbox_defconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index ab0e2defee..a2bdd3f26a 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -27,6 +27,8 @@ CONFIG_AUTOBOOT_SHA256_FALLBACK=y CONFIG_AUTOBOOT_NEVER_TIMEOUT=y CONFIG_AUTOBOOT_STOP_STR_ENABLE=y CONFIG_AUTOBOOT_STOP_STR_CRYPT="$5$rounds=64$HrpE65IkB8CM5nCL$BKT3QdF98Bo8fJpTr9tjZLZQyzqPASBY20xuK5Rent9" +CONFIG_IMAGE_PRE_LOAD=y +CONFIG_IMAGE_PRE_LOAD_SIG=y CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_PRE_CONSOLE_BUFFER=y @@ -37,6 +39,7 @@ CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y +CONFIG_CMD_BOOTM_PRE_LOAD=y CONFIG_CMD_BOOTZ=y CONFIG_CMD_BOOTEFI_HELLO=y CONFIG_CMD_ABOOTIMG=y -- 2.25.1
[PATCH v8 11/15] Makefile: provide sah-key to binman
Set the variable pre-load-key-path with the shell variable PRE_LOAD_KEY_PATH that contain the keys path (used for signature). This variable pre-load-key-path is provided to binman. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 699834..da57315259 100644 --- a/Makefile +++ b/Makefile @@ -1335,6 +1335,7 @@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \ -a tpl-bss-pad=$(if $(CONFIG_TPL_SEPARATE_BSS),,1) \ -a spl-dtb=$(CONFIG_SPL_OF_REAL) \ -a tpl-dtb=$(CONFIG_TPL_OF_REAL) \ + -a pre-load-key-path=${PRE_LOAD_KEY_PATH} \ $(BINMAN_$(@F)) OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex -- 2.25.1
[PATCH v8 07/15] boot: image: add a stage pre-load
Add a stage pre-load that could check or modify an image. For the moment, only a header with a signature is supported. This header has the following format: - magic : 4 bytes - version : 4 bytes - header size : 4 bytes - image size : 4 bytes - offset image signature : 4 bytes - flags : 4 bytes - reserved0 : 4 bytes - reserved1 : 4 bytes - sha256 of the image signature : 32 bytes - signature of the first 64 bytes : n bytes - image signature : n bytes - padding : up to header size The stage uses a node /image/pre-load/sig to get some informations: - algo-name (mandatory) : name of the algo used to sign - padding-name : name of padding used to sign - signature-size : size of the signature (in the header) - mandatory : set to yes if this sig is mandatory - public-key (madatory) : value of the public key Before running the image, the stage pre-load checks the signature provided in the header. This is an initial support, later we could add the support of: - ciphering - uncompressing - ... Signed-off-by: Philippe Reynes --- boot/Kconfig | 55 ++ boot/Makefile | 1 + boot/image-pre-load.c | 416 ++ include/image.h | 14 ++ 4 files changed, 486 insertions(+) create mode 100644 boot/image-pre-load.c diff --git a/boot/Kconfig b/boot/Kconfig index b83a4e8400..cb5f48dcf9 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -993,6 +993,61 @@ config AUTOBOOT_MENU_SHOW endmenu +menu "Image support" + +config IMAGE_PRE_LOAD + bool "Image pre-load support" + help + Enable an image pre-load stage in the SPL. + This pre-load stage allows to do some manipulation + or check (for example signature check) on an image + before launching it. + +config SPL_IMAGE_PRE_LOAD + bool "Image pre-load support within SPL" + depends on SPL && IMAGE_PRE_LOAD + help + Enable an image pre-load stage in the SPL. + This pre-load stage allows to do some manipulation + or check (for example signature check) on an image + before launching it. + +config IMAGE_PRE_LOAD_SIG + bool "Image pre-load signature support" + depends on IMAGE_PRE_LOAD + select FIT_SIGNATURE + select RSA + select RSA_VERIFY_WITH_PKEY + help + Enable signature check support in the pre-load stage. + For this feature a very simple header is added before + the image with few fields: + - a magic + - the image size + - the signature + All other information (header size, type of signature, + ...) are provided in the node /image/pre-load/sig of + u-boot. + +config SPL_IMAGE_PRE_LOAD_SIG + bool "Image pre-load signature support witin SPL" + depends on SPL_IMAGE_PRE_LOAD && IMAGE_PRE_LOAD_SIG + select SPL_FIT_SIGNATURE + select SPL_RSA + select SPL_RSA_VERIFY_WITH_PKEY + help + Enable signature check support in the pre-load stage in the SPL. + For this feature a very simple header is added before + the image with few fields: + - a magic + - the image size + - the signature + All other information (header size, type of signature, + ...) are provided in the node /image/pre-load/sig of + u-boot. + +endmenu + config USE_BOOTARGS bool "Enable boot arguments" help diff --git a/boot/Makefile b/boot/Makefile index 2938c3f145..59752c65ca 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o +obj-$(CONFIG_$(SPL_TPL_)IMAGE_PRE_LOAD) += image-pre-load.o obj-$(CONFIG_$(SPL_TPL_)IMAGE_SIGN_INFO) += image-sig.o obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += image-fit-sig.o obj-$(CONFIG_$(SPL_TPL_)FIT_CIPHER) += image-cipher.o diff --git a/boot/image-pre-load.c b/boot/image-pre-load.c new file mode 100644 index 00..78d89069a9 --- /dev/null +++ b/boot/image-pre-load.c @@ -0,0 +1,416 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Philippe Reynes + */ + +#include +#include +DECLARE_GLOBAL_DATA_PTR; +#include +#include + +#include + +#define IMAGE_PRE_LOAD_SIG_MAGIC 0x55425348 +#define IMAGE_PRE_LOAD_SIG_OFFSET_MAGIC0 +#define IMAGE_PRE_LOAD_SIG_OFFSET_IMG_LEN 4 +#define IMAGE_PRE_LOAD_SIG_OFFSET_SIG 8 + +#define IMAGE_PRE_LOAD_PATH"/image/pre-load/sig" +#define IMAGE_PRE_LOAD_PROP_ALGO_NAME "algo-name" +#define IMAGE_PRE_LOAD_PROP_PADDING_NAME "padding-name" +#define IMAGE_PRE_LOAD_PROP_SIG_SIZE "signature-size" +#define IMAGE_PRE_LOAD_PROP_PUBLIC_
[PATCH v8 09/15] common: spl: fit_ram: allow to use image pre load
Add the support of image pre load in spl or tpl when loading an image from ram. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- common/spl/spl_ram.c | 21 - 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/common/spl/spl_ram.c b/common/spl/spl_ram.c index 3f7f7accc1..8296459257 100644 --- a/common/spl/spl_ram.c +++ b/common/spl/spl_ram.c @@ -24,9 +24,17 @@ static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, ulong count, void *buf) { + ulong addr; + debug("%s: sector %lx, count %lx, buf %lx\n", __func__, sector, count, (ulong)buf); - memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count); + + addr = (ulong)CONFIG_SPL_LOAD_FIT_ADDRESS + sector; + if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) + addr += image_load_offset; + + memcpy(buf, (void *)addr, count); + return count; } @@ -37,6 +45,17 @@ static int spl_ram_load_image(struct spl_image_info *spl_image, header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS; + if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) { + unsigned long addr = (unsigned long)header; + int ret = image_pre_load(addr); + + if (ret) + return ret; + + addr += image_load_offset; + header = (struct image_header *)addr; + } + #if CONFIG_IS_ENABLED(DFU) if (bootdev->boot_device == BOOT_DEVICE_DFU) spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0"); -- 2.25.1
[PATCH v8 10/15] mkimage: add public key for image pre-load stage
This commit enhances mkimage to update the node /image/pre-load/sig with the public key. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- include/image.h| 15 ++ tools/fit_image.c | 3 ++ tools/image-host.c | 114 + 3 files changed, 132 insertions(+) diff --git a/include/image.h b/include/image.h index 496b7af3f3..498eb7f2e3 100644 --- a/include/image.h +++ b/include/image.h @@ -1019,6 +1019,21 @@ int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, int fit_set_timestamp(void *fit, int noffset, time_t timestamp); +/** + * fit_pre_load_data() - add public key to fdt blob + * + * Adds public key to the node pre load. + * + * @keydir:Directory containing keys + * @keydest: FDT blob to write public key + * @fit: Pointer to the FIT format image header + * + * returns: + * 0, on success + * < 0, on failure + */ +int fit_pre_load_data(const char *keydir, void *keydest, void *fit); + int fit_cipher_data(const char *keydir, void *keydest, void *fit, const char *comment, int require_keys, const char *engine_id, const char *cmdname); diff --git a/tools/fit_image.c b/tools/fit_image.c index 15f7c82d61..1884a2eb0b 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -59,6 +59,9 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, ret = fit_set_timestamp(ptr, 0, time); } + if (!ret) + ret = fit_pre_load_data(params->keydir, dest_blob, ptr); + if (!ret) { ret = fit_cipher_data(params->keydir, dest_blob, ptr, params->comment, diff --git a/tools/image-host.c b/tools/image-host.c index eaeb76545c..ab6f756cf1 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -14,6 +14,11 @@ #include #include +#include +#include + +#define IMAGE_PRE_LOAD_PATH "/image/pre-load/sig" + /** * fit_set_hash_value - set hash value in requested has node * @fit: pointer to the FIT format image header @@ -,6 +1116,115 @@ static int fit_config_add_verification_data(const char *keydir, return 0; } +/* + * 0) open file (open) + * 1) read certificate (PEM_read_X509) + * 2) get public key (X509_get_pubkey) + * 3) provide der format (d2i_RSAPublicKey) + */ +static int read_pub_key(const char *keydir, const void *name, + unsigned char **pubkey, int *pubkey_len) +{ + char path[1024]; + EVP_PKEY *key = NULL; + X509 *cert; + FILE *f; + int ret; + + memset(path, 0, 1024); + snprintf(path, sizeof(path), "%s/%s.crt", keydir, (char *)name); + + /* Open certificate file */ + f = fopen(path, "r"); + if (!f) { + fprintf(stderr, "Couldn't open RSA certificate: '%s': %s\n", + path, strerror(errno)); + return -EACCES; + } + + /* Read the certificate */ + cert = NULL; + if (!PEM_read_X509(f, &cert, NULL, NULL)) { + printf("Couldn't read certificate"); + ret = -EINVAL; + goto err_cert; + } + + /* Get the public key from the certificate. */ + key = X509_get_pubkey(cert); + if (!key) { + printf("Couldn't read public key\n"); + ret = -EINVAL; + goto err_pubkey; + } + + /* Get DER form */ + ret = i2d_PublicKey(key, pubkey); + if (ret < 0) { + printf("Couldn't get DER form\n"); + ret = -EINVAL; + goto err_pubkey; + } + + *pubkey_len = ret; + ret = 0; + +err_pubkey: + X509_free(cert); +err_cert: + fclose(f); + return ret; +} + +int fit_pre_load_data(const char *keydir, void *keydest, void *fit) +{ + int pre_load_noffset; + const void *algo_name; + const void *key_name; + unsigned char *pubkey = NULL; + int ret, pubkey_len; + + if (!keydir || !keydest || !fit) + return 0; + + /* Search node pre-load sig */ + pre_load_noffset = fdt_path_offset(keydest, IMAGE_PRE_LOAD_PATH); + if (pre_load_noffset < 0) { + ret = 0; + goto out; + } + + algo_name = fdt_getprop(keydest, pre_load_noffset, "algo-name", NULL); + key_name = fdt_getprop(keydest, pre_load_noffset, "key-name", NULL); + + /* Check that all mandatory properties are present */ + if (!algo_name || !key_name) { + if (!algo_name) + printf("The property algo-name is missing in the node %s\n", + IMAGE_PRE_LOAD_PATH); + if (!key_name) +
[PATCH v8 08/15] cmd: bootm: add a stage pre-load
Add a stage pre-load to the command bootm. Right now, this stage may be used to read a header and check the signature of the full image. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- boot/bootm.c| 33 + cmd/Kconfig | 10 ++ cmd/bootm.c | 5 +++-- include/image.h | 1 + 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index 00c00aef84..714406ab66 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -87,6 +87,33 @@ static int bootm_start(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } +static ulong bootm_data_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = simple_strtoul(argv[0], NULL, 16); + else + addr = image_load_addr; + + return addr; +} + +static int bootm_pre_load(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong data_addr = bootm_data_addr(argc, argv); + int ret = 0; + + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) + ret = image_pre_load(data_addr); + + if (ret) + ret = CMD_RET_FAILURE; + + return ret; +} + static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -677,6 +704,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, if (states & BOOTM_STATE_START) ret = bootm_start(cmdtp, flag, argc, argv); + if (!ret && (states & BOOTM_STATE_PRE_LOAD)) + ret = bootm_pre_load(cmdtp, flag, argc, argv); + if (!ret && (states & BOOTM_STATE_FINDOS)) ret = bootm_find_os(cmdtp, flag, argc, argv); @@ -866,6 +896,9 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, &fit_uname_config, &fit_uname_kernel); + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) + img_addr += image_load_offset; + bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC); /* check image type, for FIT images get FIT kernel node */ diff --git a/cmd/Kconfig b/cmd/Kconfig index 5e25e45fd2..87aa3fb11a 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -194,6 +194,16 @@ config CMD_BOOTM help Boot an application image from the memory. +config CMD_BOOTM_PRE_LOAD + bool "enable pre-load on bootm" + depends on CMD_BOOTM + depends on IMAGE_PRE_LOAD + default n + help + Enable support of stage pre-load for the bootm command. +This stage allow to check or modify the image provided +to the bootm command. + config BOOTM_EFI bool "Support booting UEFI FIT images" depends on CMD_BOOTEFI && CMD_BOOTM && FIT diff --git a/cmd/bootm.c b/cmd/bootm.c index e8b7066888..87d40d494c 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -70,7 +70,8 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, if (c) { state = (long)c->cmd; if (state == BOOTM_STATE_START) - state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; + state |= BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOS | +BOOTM_STATE_FINDOTHER; } else { /* Unrecognized command */ return CMD_RET_USAGE; @@ -126,7 +127,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | - BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | + BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH BOOTM_STATE_RAMDISK | diff --git a/include/image.h b/include/image.h index fbcf70f5e4..496b7af3f3 100644 --- a/include/image.h +++ b/include/image.h @@ -351,6 +351,7 @@ typedef struct bootm_headers { #defineBOOTM_STATE_OS_PREP (0x0100) #defineBOOTM_STATE_OS_FAKE_GO (0x0200)/* 'Almost' run the OS */ #defineBOOTM_STATE_OS_GO (0x0400) +#defineBOOTM_STATE_PRE_LOAD0x0800 int state; #if defined(CONFIG_LMB) && !defined(USE_HOSTCC) -- 2.25.1
[PATCH v8 05/15] lib: crypto: allow to build crypyo in SPL
This commit adds the options: - SPL_ASYMMETRIC_KEY_TYPE - SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE - SPL_RSA_PUBLIC_KEY_PARSER Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Makefile| 3 ++- lib/crypto/Kconfig | 29 + lib/crypto/Makefile | 19 +-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 13e5d8f7a6..13fe5fb7a4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,7 +17,6 @@ obj-$(CONFIG_OF_LIVE) += of_live.o obj-$(CONFIG_CMD_DHRYSTONE) += dhry/ obj-$(CONFIG_ARCH_AT91) += at91/ obj-$(CONFIG_OPTEE_LIB) += optee/ -obj-y += crypto/ obj-$(CONFIG_AES) += aes.o obj-$(CONFIG_AES) += aes/ @@ -63,6 +62,8 @@ obj-$(CONFIG_TPM_V1) += tpm-v1.o obj-$(CONFIG_TPM_V2) += tpm-v2.o endif +obj-y += crypto/ + obj-$(CONFIG_$(SPL_TPL_)GENERATE_ACPI_TABLE) += acpi/ obj-$(CONFIG_$(SPL_)MD5) += md5.o obj-$(CONFIG_ECDSA) += ecdsa/ diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig index 6369bafac0..509bc28311 100644 --- a/lib/crypto/Kconfig +++ b/lib/crypto/Kconfig @@ -8,6 +8,15 @@ menuconfig ASYMMETRIC_KEY_TYPE if ASYMMETRIC_KEY_TYPE +config SPL_ASYMMETRIC_KEY_TYPE + bool "Asymmetric (public-key cryptographic) key Support within SPL" + depends on SPL + help + This option provides support for a key type that holds the data for + the asymmetric keys used for public key cryptographic operations such + as encryption, decryption, signature generation and signature + verification in the SPL. + config ASYMMETRIC_PUBLIC_KEY_SUBTYPE bool "Asymmetric public-key crypto algorithm subtype" help @@ -16,6 +25,15 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE appropriate hash algorithms (such as SHA-1) must be available. ENOPKG will be reported if the requisite algorithm is unavailable. +config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE + bool "Asymmetric public-key crypto algorithm subtype within SPL" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + help + This option provides support for asymmetric public key type handling in the SPL. + If signature generation and/or verification are to be used, + appropriate hash algorithms (such as SHA-1) must be available. + ENOPKG will be reported if the requisite algorithm is unavailable. + config RSA_PUBLIC_KEY_PARSER bool "RSA public key parser" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE @@ -27,6 +45,17 @@ config RSA_PUBLIC_KEY_PARSER public key data and provides the ability to instantiate a public key. +config SPL_RSA_PUBLIC_KEY_PARSER + bool "RSA public key parser within SPL" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select SPL_ASN1_DECODER + select ASN1_COMPILER + select SPL_OID_REGISTRY + help + This option provides support for parsing a blob containing RSA + public key data and provides the ability to instantiate a public + key in the SPL. + config X509_CERTIFICATE_PARSER bool "X.509 certificate parser" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index f3a414525d..6792b1d4f0 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -3,27 +3,34 @@ # Makefile for asymmetric cryptographic keys # -obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o asymmetric_keys-y := asymmetric_type.o -obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o # # RSA public key parser # -obj-$(CONFIG_RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o +obj-$(CONFIG_$(SPL_)RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o rsa_public_key-y := \ rsapubkey.asn1.o \ rsa_helper.o $(obj)/rsapubkey.asn1.o: $(obj)/rsapubkey.asn1.c $(obj)/rsapubkey.asn1.h +ifdef CONFIG_SPL_BUILD +CFLAGS_rsapubkey.asn1.o += -I$(obj) +endif + $(obj)/rsa_helper.o: $(obj)/rsapubkey.asn1.h +ifdef CONFIG_SPL_BUILD +CFLAGS_rsa_helper.o += -I$(obj) +endif # # X.509 Certificate handling # -obj-$(CONFIG_X509_CERTIFICATE_PARSER) += x509_key_parser.o +obj-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER) += x509_key_parser.o x509_key_parser-y := \ x509.asn1.o \ x509_akid.asn1.o \ @@ -40,11 +47,11 @@ $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h # # PKCS#7 message handling # -obj-$(CONFIG_PKCS7_MESSAGE_PARSER) += pkcs7_message.o +obj-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER) += pkcs7_message.o pkcs7_message-y := \ pkcs7.asn1.o \ pkcs7_parser.o -obj-$(CONFIG_PKCS7_VERIFY) += pkcs7_verify.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 -- 2.25.1
[PATCH v8 06/15] lib: rsa: allow rsa verify with pkey in SPL
This commit adds the option SPL_RSA_VERIFY_WITH_PKEY. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/rsa/Kconfig | 19 +++ 1 file changed, 19 insertions(+) diff --git a/lib/rsa/Kconfig b/lib/rsa/Kconfig index be9775bcce..b773f17c26 100644 --- a/lib/rsa/Kconfig +++ b/lib/rsa/Kconfig @@ -47,6 +47,25 @@ config RSA_VERIFY_WITH_PKEY directly specified in image_sign_info, where all the necessary key properties will be calculated on the fly in verification code. +config SPL_RSA_VERIFY_WITH_PKEY + bool "Execute RSA verification without key parameters from FDT within SPL" + depends on SPL + select SPL_RSA_VERIFY + select SPL_ASYMMETRIC_KEY_TYPE + select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select SPL_RSA_PUBLIC_KEY_PARSER + help + The standard RSA-signature verification code (FIT_SIGNATURE) uses + pre-calculated key properties, that are stored in fdt blob, in + decrypting a signature. + This does not suit the use case where there is no way defined to + provide such additional key properties in standardized form, + particularly UEFI secure boot. + This options enables RSA signature verification with a public key + directly specified in image_sign_info, where all the necessary + key properties will be calculated on the fly in verification code + in the SPL. + config RSA_SOFTWARE_EXP bool "Enable driver for RSA Modular Exponentiation in software" depends on DM -- 2.25.1
[PATCH v8 04/15] lib: allow to build asn1 decoder and oid registry in SPL
This commit adds the options: - SPL_ASN1_DECODER - SPL_OID_REGISTRY Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Kconfig | 19 +++ lib/Makefile | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Kconfig b/lib/Kconfig index e749826f22..effe735365 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -809,6 +809,16 @@ config ASN1_DECODER and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). This option enables the support of the asn1 decoder. +config SPL_ASN1_DECODER + bool + help + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 decoder in the SPL. + config OID_REGISTRY bool help @@ -818,6 +828,15 @@ config OID_REGISTRY unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). Enable fast lookup object identifier registry. +config SPL_OID_REGISTRY + bool + help + In computing, object identifiers or OIDs are an identifier mechanism + standardized by the International Telecommunication Union (ITU) and + ISO/IEC for naming any object, concept, or "thing" with a globally + unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). + Enable fast lookup object identifier registry in the SPL. + config SMBIOS_PARSER bool "SMBIOS parser" help diff --git a/lib/Makefile b/lib/Makefile index 11b03d1cbe..13e5d8f7a6 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,7 +17,6 @@ obj-$(CONFIG_OF_LIVE) += of_live.o obj-$(CONFIG_CMD_DHRYSTONE) += dhry/ obj-$(CONFIG_ARCH_AT91) += at91/ obj-$(CONFIG_OPTEE_LIB) += optee/ -obj-$(CONFIG_ASN1_DECODER) += asn1_decoder.o obj-y += crypto/ obj-$(CONFIG_AES) += aes.o @@ -74,6 +73,7 @@ obj-$(CONFIG_SHA1) += sha1.o obj-$(CONFIG_SHA256) += sha256.o obj-$(CONFIG_SHA512) += sha512.o obj-$(CONFIG_CRYPT_PW) += crypt/ +obj-$(CONFIG_$(SPL_)ASN1_DECODER) += asn1_decoder.o obj-$(CONFIG_$(SPL_)ZLIB) += zlib/ obj-$(CONFIG_$(SPL_)ZSTD) += zstd/ @@ -135,9 +135,9 @@ obj-$(CONFIG_$(SPL_TPL_)STRTO) += strto.o else # Main U-Boot always uses the full printf support obj-y += vsprintf.o strto.o -obj-$(CONFIG_OID_REGISTRY) += oid_registry.o obj-$(CONFIG_SSCANF) += sscanf.o endif +obj-$(CONFIG_$(SPL_)OID_REGISTRY) += oid_registry.o obj-y += abuf.o obj-y += date.o -- 2.25.1
[PATCH v8 03/15] lib: Kconfig: enhance the help of OID_REGISTRY
Enhance the help for the config OID_REGISTRY. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Kconfig | 4 1 file changed, 4 insertions(+) diff --git a/lib/Kconfig b/lib/Kconfig index b0e5d60b3d..e749826f22 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -812,6 +812,10 @@ config ASN1_DECODER config OID_REGISTRY bool help + In computing, object identifiers or OIDs are an identifier mechanism + standardized by the International Telecommunication Union (ITU) and + ISO/IEC for naming any object, concept, or "thing" with a globally + unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). Enable fast lookup object identifier registry. config SMBIOS_PARSER -- 2.25.1
[PATCH v8 01/15] arch: Kconfig: imply BINMAN for SANDBOX
To be able to use the tool binman on sandbox, the config SANDBOX should imply BINMAN. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- arch/Kconfig | 1 + arch/sandbox/dts/sandbox.dtsi | 3 +++ arch/sandbox/dts/test.dts | 3 +++ test/py/tests/test_fit.py | 3 +++ test/py/tests/vboot/sandbox-u-boot.dts | 3 +++ 5 files changed, 13 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index e6191446a3..35624377ca 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -203,6 +203,7 @@ config SANDBOX imply KEYBOARD imply PHYSMEM imply GENERATE_ACPI_TABLE + imply BINMAN config SH bool "SuperH architecture" diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 66b813faad..826db26fc2 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -7,6 +7,9 @@ #define USB_CLASS_HUB 9 / { + binman { + }; + chosen { stdout-path = "/serial"; }; diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 48ca3e1e47..c11ad8cb9f 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -61,6 +61,9 @@ osd0 = "/osd"; }; + binman { + }; + config { testing-bool; testing-int = <123>; diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py index 6d5b43c3ba..5856960be2 100755 --- a/test/py/tests/test_fit.py +++ b/test/py/tests/test_fit.py @@ -89,6 +89,9 @@ base_fdt = ''' model = "Sandbox Verified Boot Test"; compatible = "sandbox"; + binman { + }; + reset@0 { compatible = "sandbox,reset"; reg = <0>; diff --git a/test/py/tests/vboot/sandbox-u-boot.dts b/test/py/tests/vboot/sandbox-u-boot.dts index 63f8f401de..5809c62fc1 100644 --- a/test/py/tests/vboot/sandbox-u-boot.dts +++ b/test/py/tests/vboot/sandbox-u-boot.dts @@ -4,6 +4,9 @@ model = "Sandbox Verified Boot Test"; compatible = "sandbox"; + binman { + }; + reset@0 { compatible = "sandbox,reset"; }; -- 2.25.1
[PATCH v8 02/15] lib: Kconfig: enhance help for ASN1
Enhance the help for configs ASN1_COMPILER and ASN1_decoder. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Kconfig | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Kconfig b/lib/Kconfig index 3c6fa99b1a..b0e5d60b3d 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -791,11 +791,23 @@ endmenu config ASN1_COMPILER bool + help + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 compiler. config ASN1_DECODER bool help - Enable asn1 decoder library. + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 decoder. config OID_REGISTRY bool -- 2.25.1
[PATCH v8 00/15] image: add a stage pre-load
This serie adds a stage pre-load before launching an image. This stage is used to read a header before the image and this header contains the signature of the full image. So u-boot may check the full image before using any data of the image. The support of this header is added to binman, and a command verify checks the signature of a blob and set the u-boot env variable "loadaddr_verified" to the beginning of the "real" image. The support of this header is only added to binman, but it may also be added to mkimage. Changelog: v8: - remove command pre_load_verify - add subcommand preload to bootm - add stage pre_load in "bootm start" - use PYTHONPATH to use binman in py test vboot v7: - rename command verify to pre_load_verify - add usage doc for command pre_load_verify - some cleanup in support of pre-load in binman - rename variable key-path to pre-load-key-path - some cleanup in test vboot for pre-load v6: - set values in big endian in the pre-load header - binman: etypes: pre-load: read image from other entry instead of directly from a file - binman: etypes: pre-load: add test unit - lib: Makefile: no longer add -I$(obj) for SPL It was to fix build when oid is built on spl but not on u-boot. It is not longer possible. v5: - replace config SANDBOX_BINMAN by an imply v4: - add a config SANDBOX_BIN - enhance help for asn1 and oid - change the format of the pre-load header - add the support of pre-load header in binman - add py test for pre-load header - add a command verify v3: - move image-pre-load.c to /boot - update mkimage to add public key in u-boot device tree - add script gen_pre_load_header.sh v2: - move the code to image-pre-load - add support of stage pre-load for spl - add support of stage pre-load on spl_ram Philippe Reynes (15): arch: Kconfig: imply BINMAN for SANDBOX lib: Kconfig: enhance help for ASN1 lib: Kconfig: enhance the help of OID_REGISTRY lib: allow to build asn1 decoder and oid registry in SPL lib: crypto: allow to build crypyo in SPL lib: rsa: allow rsa verify with pkey in SPL boot: image: add a stage pre-load cmd: bootm: add a stage pre-load common: spl: fit_ram: allow to use image pre load mkimage: add public key for image pre-load stage Makefile: provide sah-key to binman tools: binman: add support for pre-load header configs: sandbox_defconfig: enable stage pre-load in bootm test: py: vboot: add test for global image signature cmd: bootm: add subcommand preload Makefile | 1 + arch/Kconfig | 1 + arch/sandbox/dts/sandbox.dtsi | 3 + arch/sandbox/dts/test.dts | 3 + boot/Kconfig | 55 +++ boot/Makefile | 1 + boot/bootm.c | 33 ++ boot/image-pre-load.c | 416 ++ cmd/Kconfig | 10 + cmd/bootm.c | 35 +- common/spl/spl_ram.c | 21 +- configs/sandbox_defconfig | 3 + include/image.h | 30 ++ lib/Kconfig | 37 +- lib/Makefile | 7 +- lib/crypto/Kconfig| 29 ++ lib/crypto/Makefile | 19 +- lib/rsa/Kconfig | 19 + test/py/tests/test_fit.py | 3 + test/py/tests/test_vboot.py | 148 ++- test/py/tests/vboot/sandbox-binman-pss.dts| 25 ++ test/py/tests/vboot/sandbox-binman.dts| 24 + .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 ++ test/py/tests/vboot/sandbox-u-boot-global.dts | 27 ++ test/py/tests/vboot/sandbox-u-boot.dts| 3 + test/py/tests/vboot/simple-images.its | 36 ++ tools/binman/entries.rst | 38 ++ tools/binman/etype/pre_load.py| 162 +++ tools/binman/ftest.py | 51 +++ tools/binman/test/225_dev.key | 28 ++ tools/binman/test/225_pre_load.dts| 22 + tools/binman/test/226_pre_load_pkcs.dts | 23 + tools/binman/test/227_pre_load_pss.dts| 23 + .../test/228_pre_load_invalid_padding.dts | 23 + .../binman/test/229_pre_load_invalid_sha.dts | 23 + .../binman/test/230_pre_load_invalid_algo.dts | 23 + .../binman/test/231_pre_load_invalid_key.dts | 23 + tools/fit_image.c | 3 + tools/image-host.c| 114 + 39 files changed, 1544 insertions(+), 29 deletions(-) create mode 100644 boot/image-pre-load.c create mode 100644 test/py/tests/vboot/sandbox-binman-pss.dts create mode 100644 test/py/tests/vboot/sandbox-binman.dts create mode 100644 test/py/tests/vboot/sandbox
Re: [PATCH v7 14/16] test: py: vboot: add test for global image signature
Hi Tom, Le 25/03/2022 à 18:11, Tom Rini a écrit : On Mon, Mar 14, 2022 at 03:57:43PM +0100, Philippe Reynes wrote: Adds test units for the pre-load header signature. Signed-off-by: Philippe Reynes --- test/py/tests/test_vboot.py | 145 -- test/py/tests/vboot/sandbox-binman-pss.dts| 25 +++ test/py/tests/vboot/sandbox-binman.dts| 24 +++ .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 test/py/tests/vboot/sandbox-u-boot-global.dts | 27 test/py/tests/vboot/simple-images.its | 36 + 6 files changed, 269 insertions(+), 16 deletions(-) create mode 100644 test/py/tests/vboot/sandbox-binman-pss.dts create mode 100644 test/py/tests/vboot/sandbox-binman.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-pss.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global.dts create mode 100644 test/py/tests/vboot/simple-images.its This leads to CI failures such as: https://source.denx.de/u-boot/u-boot/-/jobs/412046 and I guess maybe we need something new in test/py/requirements.txt maybe? I think that this issue should be fixed with this patch : https://patchwork.ozlabs.org/project/uboot/patch/20220127140314.10264-2-philippe.rey...@softathome.com/ The rest of the series seems fine, btw. great, thanks a lot Regards, Philippe
[PATCH v7 16/16] configs: sandbox_defconfig: enable config CMD_PRE_LOAD_VERIFY
Enable the command pre_load_verify on sandbox. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 46bf18bc98..35fd4e3f49 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -44,6 +44,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_BOOTEFI_HELLO=y CONFIG_CMD_ABOOTIMG=y # CONFIG_CMD_ELF is not set +CONFIG_CMD_PRE_LOAD_VERIFY=y CONFIG_CMD_ASKENV=y CONFIG_CMD_GREPENV=y CONFIG_CMD_ERASEENV=y -- 2.17.1
[PATCH v7 08/16] cmd: bootm: add a stage pre-load
Add a stage pre-load to the command bootm. Right now, this stage may be used to read a header and check the signature of the full image. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- boot/bootm.c| 33 + cmd/Kconfig | 10 ++ cmd/bootm.c | 2 +- include/image.h | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/boot/bootm.c b/boot/bootm.c index 00c00aef84..714406ab66 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -87,6 +87,33 @@ static int bootm_start(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } +static ulong bootm_data_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = simple_strtoul(argv[0], NULL, 16); + else + addr = image_load_addr; + + return addr; +} + +static int bootm_pre_load(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong data_addr = bootm_data_addr(argc, argv); + int ret = 0; + + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) + ret = image_pre_load(data_addr); + + if (ret) + ret = CMD_RET_FAILURE; + + return ret; +} + static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -677,6 +704,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, if (states & BOOTM_STATE_START) ret = bootm_start(cmdtp, flag, argc, argv); + if (!ret && (states & BOOTM_STATE_PRE_LOAD)) + ret = bootm_pre_load(cmdtp, flag, argc, argv); + if (!ret && (states & BOOTM_STATE_FINDOS)) ret = bootm_find_os(cmdtp, flag, argc, argv); @@ -866,6 +896,9 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, &fit_uname_config, &fit_uname_kernel); + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) + img_addr += image_load_offset; + bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC); /* check image type, for FIT images get FIT kernel node */ diff --git a/cmd/Kconfig b/cmd/Kconfig index 5e25e45fd2..87aa3fb11a 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -194,6 +194,16 @@ config CMD_BOOTM help Boot an application image from the memory. +config CMD_BOOTM_PRE_LOAD + bool "enable pre-load on bootm" + depends on CMD_BOOTM + depends on IMAGE_PRE_LOAD + default n + help + Enable support of stage pre-load for the bootm command. +This stage allow to check or modify the image provided +to the bootm command. + config BOOTM_EFI bool "Support booting UEFI FIT images" depends on CMD_BOOTEFI && CMD_BOOTM && FIT diff --git a/cmd/bootm.c b/cmd/bootm.c index e8b7066888..c5de339fba 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -126,7 +126,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | - BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | + BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH BOOTM_STATE_RAMDISK | diff --git a/include/image.h b/include/image.h index fbcf70f5e4..496b7af3f3 100644 --- a/include/image.h +++ b/include/image.h @@ -351,6 +351,7 @@ typedef struct bootm_headers { #defineBOOTM_STATE_OS_PREP (0x0100) #defineBOOTM_STATE_OS_FAKE_GO (0x0200)/* 'Almost' run the OS */ #defineBOOTM_STATE_OS_GO (0x0400) +#defineBOOTM_STATE_PRE_LOAD0x0800 int state; #if defined(CONFIG_LMB) && !defined(USE_HOSTCC) -- 2.17.1
[PATCH v7 07/16] boot: image: add a stage pre-load
Add a stage pre-load that could check or modify an image. For the moment, only a header with a signature is supported. This header has the following format: - magic : 4 bytes - version : 4 bytes - header size : 4 bytes - image size : 4 bytes - offset image signature : 4 bytes - flags : 4 bytes - reserved0 : 4 bytes - reserved1 : 4 bytes - sha256 of the image signature : 32 bytes - signature of the first 64 bytes : n bytes - image signature : n bytes - padding : up to header size The stage uses a node /image/pre-load/sig to get some informations: - algo-name (mandatory) : name of the algo used to sign - padding-name : name of padding used to sign - signature-size : size of the signature (in the header) - mandatory : set to yes if this sig is mandatory - public-key (madatory) : value of the public key Before running the image, the stage pre-load checks the signature provided in the header. This is an initial support, later we could add the support of: - ciphering - uncompressing - ... Signed-off-by: Philippe Reynes --- boot/Kconfig | 55 ++ boot/Makefile | 1 + boot/image-pre-load.c | 416 ++ include/image.h | 14 ++ 4 files changed, 486 insertions(+) create mode 100644 boot/image-pre-load.c diff --git a/boot/Kconfig b/boot/Kconfig index b83a4e8400..cb5f48dcf9 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -993,6 +993,61 @@ config AUTOBOOT_MENU_SHOW endmenu +menu "Image support" + +config IMAGE_PRE_LOAD + bool "Image pre-load support" + help + Enable an image pre-load stage in the SPL. + This pre-load stage allows to do some manipulation + or check (for example signature check) on an image + before launching it. + +config SPL_IMAGE_PRE_LOAD + bool "Image pre-load support within SPL" + depends on SPL && IMAGE_PRE_LOAD + help + Enable an image pre-load stage in the SPL. + This pre-load stage allows to do some manipulation + or check (for example signature check) on an image + before launching it. + +config IMAGE_PRE_LOAD_SIG + bool "Image pre-load signature support" + depends on IMAGE_PRE_LOAD + select FIT_SIGNATURE + select RSA + select RSA_VERIFY_WITH_PKEY + help + Enable signature check support in the pre-load stage. + For this feature a very simple header is added before + the image with few fields: + - a magic + - the image size + - the signature + All other information (header size, type of signature, + ...) are provided in the node /image/pre-load/sig of + u-boot. + +config SPL_IMAGE_PRE_LOAD_SIG + bool "Image pre-load signature support witin SPL" + depends on SPL_IMAGE_PRE_LOAD && IMAGE_PRE_LOAD_SIG + select SPL_FIT_SIGNATURE + select SPL_RSA + select SPL_RSA_VERIFY_WITH_PKEY + help + Enable signature check support in the pre-load stage in the SPL. + For this feature a very simple header is added before + the image with few fields: + - a magic + - the image size + - the signature + All other information (header size, type of signature, + ...) are provided in the node /image/pre-load/sig of + u-boot. + +endmenu + config USE_BOOTARGS bool "Enable boot arguments" help diff --git a/boot/Makefile b/boot/Makefile index 2938c3f145..59752c65ca 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o +obj-$(CONFIG_$(SPL_TPL_)IMAGE_PRE_LOAD) += image-pre-load.o obj-$(CONFIG_$(SPL_TPL_)IMAGE_SIGN_INFO) += image-sig.o obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += image-fit-sig.o obj-$(CONFIG_$(SPL_TPL_)FIT_CIPHER) += image-cipher.o diff --git a/boot/image-pre-load.c b/boot/image-pre-load.c new file mode 100644 index 00..78d89069a9 --- /dev/null +++ b/boot/image-pre-load.c @@ -0,0 +1,416 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Philippe Reynes + */ + +#include +#include +DECLARE_GLOBAL_DATA_PTR; +#include +#include + +#include + +#define IMAGE_PRE_LOAD_SIG_MAGIC 0x55425348 +#define IMAGE_PRE_LOAD_SIG_OFFSET_MAGIC0 +#define IMAGE_PRE_LOAD_SIG_OFFSET_IMG_LEN 4 +#define IMAGE_PRE_LOAD_SIG_OFFSET_SIG 8 + +#define IMAGE_PRE_LOAD_PATH"/image/pre-load/sig" +#define IMAGE_PRE_LOAD_PROP_ALGO_NAME "algo-name" +#define IMAGE_PRE_LOAD_PROP_PADDING_NAME "padding-name" +#define IMAGE_PRE_LOAD_PROP_SIG_SIZE "signature-size" +#define IMAGE_PRE_LOAD_PROP_PUBLIC_
[PATCH v7 14/16] test: py: vboot: add test for global image signature
Adds test units for the pre-load header signature. Signed-off-by: Philippe Reynes --- test/py/tests/test_vboot.py | 145 -- test/py/tests/vboot/sandbox-binman-pss.dts| 25 +++ test/py/tests/vboot/sandbox-binman.dts| 24 +++ .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 test/py/tests/vboot/sandbox-u-boot-global.dts | 27 test/py/tests/vboot/simple-images.its | 36 + 6 files changed, 269 insertions(+), 16 deletions(-) create mode 100644 test/py/tests/vboot/sandbox-binman-pss.dts create mode 100644 test/py/tests/vboot/sandbox-binman.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-pss.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global.dts create mode 100644 test/py/tests/vboot/simple-images.its diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py index ac8ed9f114..039ba50aef 100644 --- a/test/py/tests/test_vboot.py +++ b/test/py/tests/test_vboot.py @@ -21,6 +21,14 @@ For configuration verification: - Corrupt the signature - Check that image verification no-longer works +For pre-load header verification: +- Create FIT image with a pre-load header +- Check that signature verification succeeds +- Corrupt the FIT image +- Check that signature verification fails +- Launch an FIT image without a pre-load header +- Check that image verification fails + Tests run with both SHA1 and SHA256 hashing. """ @@ -35,19 +43,21 @@ import vboot_evil # Only run the full suite on a few combinations, since it doesn't add any more # test coverage. TESTDATA = [ -['sha1-basic', 'sha1', '', None, False, True, False], -['sha1-pad', 'sha1', '', '-E -p 0x1', False, False, False], -['sha1-pss', 'sha1', '-pss', None, False, False, False], -['sha1-pss-pad', 'sha1', '-pss', '-E -p 0x1', False, False, False], -['sha256-basic', 'sha256', '', None, False, False, False], -['sha256-pad', 'sha256', '', '-E -p 0x1', False, False, False], -['sha256-pss', 'sha256', '-pss', None, False, False, False], -['sha256-pss-pad', 'sha256', '-pss', '-E -p 0x1', False, False, False], -['sha256-pss-required', 'sha256', '-pss', None, True, False, False], -['sha256-pss-pad-required', 'sha256', '-pss', '-E -p 0x1', True, True, False], -['sha384-basic', 'sha384', '', None, False, False, False], -['sha384-pad', 'sha384', '', '-E -p 0x1', False, False, False], -['algo-arg', 'algo-arg', '', '-o sha256,rsa2048', False, False, True], +['sha1-basic', 'sha1', '', None, False, True, False, False], +['sha1-pad', 'sha1', '', '-E -p 0x1', False, False, False, False], +['sha1-pss', 'sha1', '-pss', None, False, False, False, False], +['sha1-pss-pad', 'sha1', '-pss', '-E -p 0x1', False, False, False, False], +['sha256-basic', 'sha256', '', None, False, False, False, False], +['sha256-pad', 'sha256', '', '-E -p 0x1', False, False, False, False], +['sha256-pss', 'sha256', '-pss', None, False, False, False, False], +['sha256-pss-pad', 'sha256', '-pss', '-E -p 0x1', False, False, False, False], +['sha256-pss-required', 'sha256', '-pss', None, True, False, False, False], +['sha256-pss-pad-required', 'sha256', '-pss', '-E -p 0x1', True, True, False, False], +['sha384-basic', 'sha384', '', None, False, False, False, False], +['sha384-pad', 'sha384', '', '-E -p 0x1', False, False, False, False], +['algo-arg', 'algo-arg', '', '-o sha256,rsa2048', False, False, True, False], +['sha256-global-sign', 'sha256', '', '', False, False, False, True], +['sha256-global-sign-pss', 'sha256', '-pss', '', False, False, False, True], ] @pytest.mark.boardspec('sandbox') @@ -56,10 +66,10 @@ TESTDATA = [ @pytest.mark.requiredtool('fdtget') @pytest.mark.requiredtool('fdtput') @pytest.mark.requiredtool('openssl') -@pytest.mark.parametrize("name,sha_
[PATCH v7 12/16] tools: binman: add support for pre-load header
Adds the support of the pre-load header with the image signature to binman. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- doc/usage/index.rst | 1 + tools/binman/entries.rst | 38 tools/binman/etype/pre_load.py| 162 ++ tools/binman/ftest.py | 51 ++ tools/binman/test/225_dev.key | 28 +++ tools/binman/test/225_pre_load.dts| 22 +++ tools/binman/test/226_pre_load_pkcs.dts | 23 +++ tools/binman/test/227_pre_load_pss.dts| 23 +++ .../test/228_pre_load_invalid_padding.dts | 23 +++ .../binman/test/229_pre_load_invalid_sha.dts | 23 +++ .../binman/test/230_pre_load_invalid_algo.dts | 23 +++ .../binman/test/231_pre_load_invalid_key.dts | 23 +++ 12 files changed, 440 insertions(+) create mode 100644 tools/binman/etype/pre_load.py create mode 100644 tools/binman/test/225_dev.key create mode 100644 tools/binman/test/225_pre_load.dts create mode 100644 tools/binman/test/226_pre_load_pkcs.dts create mode 100644 tools/binman/test/227_pre_load_pss.dts create mode 100644 tools/binman/test/228_pre_load_invalid_padding.dts create mode 100644 tools/binman/test/229_pre_load_invalid_sha.dts create mode 100644 tools/binman/test/230_pre_load_invalid_algo.dts create mode 100644 tools/binman/test/231_pre_load_invalid_key.dts diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 0aacf531b2..00baf3daa6 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -42,6 +42,7 @@ Shell commands md mmc pinmux + pre-load-verify pstore qfw reset diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst index 484cde5c80..ef8351d969 100644 --- a/tools/binman/entries.rst +++ b/tools/binman/entries.rst @@ -1009,6 +1009,44 @@ placed at offset 'RESET_VECTOR_ADDRESS - 0xffc'. +Entry: pre-load: Pre load image header +-- + +Properties / Entry arguments: +- key-path: Path of the directory that store key (provided by the environment variable KEY_PATH) +- content: List of phandles to entries to sign +- algo-name: Hash and signature algo to use for the signature +- padding-name: Name of the padding (pkcs-1.5 or pss) +- key-name: Filename of the private key to sign +- header-size: Total size of the header +- version: Version of the header + +This entry creates a pre-load header that contains a global +image signature. + +For example, this creates an image with a pre-load header and a binary:: + +binman { +image2 { +filename = "sandbox.bin"; + +pre-load { +content = <&image>; +algo-name = "sha256,rsa2048"; +padding-name = "pss"; +key-name = "private.pem"; +header-size = <4096>; +version = <1>; +}; + +image: blob-ext { +filename = "sandbox.itb"; +}; +}; +}; + + + Entry: scp: System Control Processor (SCP) firmware blob diff --git a/tools/binman/etype/pre_load.py b/tools/binman/etype/pre_load.py new file mode 100644 index 00..245ee75525 --- /dev/null +++ b/tools/binman/etype/pre_load.py @@ -0,0 +1,162 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2022 Softathome +# Written by Philippe Reynes +# +# Entry-type for the global header +# + +import os +import struct +from dtoc import fdt_util +from patman import tools + +from binman.entry import Entry +from binman.etype.collection import Entry_collection +from binman.entry import EntryArg + +from Cryptodome.Hash import SHA256, SHA384, SHA512 +from Cryptodome.PublicKey import RSA +from Cryptodome.Signature import pkcs1_15 +from Cryptodome.Signature import pss + +PRE_LOAD_MAGIC = b'UBSH' + +RSAS = { +'rsa1024': 1024 / 8, +'rsa2048': 2048 / 8, +'rsa4096': 4096 / 8 +} + +SHAS = { +'sha256': SHA256, +'sha384': SHA384, +'sha512': SHA512 +} + +class Entry_pre_load(Entry_collection): +"""Pre load image header + +Properties / Entry arguments: +- pre-load-key-path: Path of the directory that store key (provided by the environment variable PRE_LOAD_KEY_PATH) +- content: List of phandles to entries to sign +- algo-name: Hash and signature algo to use for the signature +- padding-name: Name of the padding (pkcs-1.5 or pss) +- key-name: Filename of the private key to sign +- header-size: Total size of the header +- version: Version of the header + +This entry creates a pre-load header that contains a global +image signature. + +For example, this creates an image with a pre-loa
[PATCH v7 15/16] cmd: pre_load_verify: initial import
Add the command pre_load_verify that check the signature of an image with the pre-load header. If the check succeed, the u-boot env variable 'loadaddr_verified' is set to the address of the image (without the header). It allows to run such commands: tftp script.img && pre_load_verify $loadaddr && source $loadaddr_verified Signed-off-by: Philippe Reynes --- cmd/Kconfig | 8 ++ cmd/Makefile | 2 ++ cmd/pre-load-verify.c | 53 +++ doc/usage/pre-load-verify.rst | 44 + 4 files changed, 107 insertions(+) create mode 100644 cmd/pre-load-verify.c create mode 100644 doc/usage/pre-load-verify.rst diff --git a/cmd/Kconfig b/cmd/Kconfig index 87aa3fb11a..9b235210e3 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -428,6 +428,14 @@ config CMD_THOR_DOWNLOAD There is no documentation about this within the U-Boot source code but you should be able to find something on the interwebs. +config CMD_PRE_LOAD_VERIFY + bool "verify the global signature" + depends on IMAGE_PRE_LOAD + help + Verify the signature provided in a pre-load header of + a full image. + Documentation is available in doc/usage/pre-load-verify.txt + config CMD_ZBOOT bool "zboot - x86 boot command" help diff --git a/cmd/Makefile b/cmd/Makefile index 166c652d98..29ee9b8fab 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -188,6 +188,8 @@ obj-$(CONFIG_CMD_ETHSW) += ethsw.o obj-$(CONFIG_CMD_AXI) += axi.o obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o +obj-$(CONFIG_CMD_PRE_LOAD_VERIFY) += pre-load-verify.o + # Power obj-$(CONFIG_CMD_PMIC) += pmic.o obj-$(CONFIG_CMD_REGULATOR) += regulator.o diff --git a/cmd/pre-load-verify.c b/cmd/pre-load-verify.c new file mode 100644 index 00..c2c4e57d5f --- /dev/null +++ b/cmd/pre-load-verify.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Philippe Reynes + */ + +#include +#include +#include +#include + +static ulong verify_get_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = hextoul(argv[0], NULL); + else + addr = image_load_addr; + + return addr; +} + +static int do_verify(struct cmd_tbl *cmdtp, int flag, int argc, +char *const argv[]) +{ + ulong addr = verify_get_addr(argc, argv); + int ret = 0; + + argc--; argv++; + + addr = verify_get_addr(argc, argv); + + if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) { + ret = image_pre_load(addr); + + if (ret) { + ret = CMD_RET_FAILURE; + goto out; + } + + env_set_hex("loadaddr_verified", addr + image_load_offset); + } + + out: + return ret; +} + +U_BOOT_CMD(pre_load_verify, 2, 1, do_verify, + "verify the global signature provided in the pre-load header,\n", + "\tif the check succeed, the u-boot env variable loadaddr_verified\n" + "\tis set to the address of the image (without the header)" + "" +); diff --git a/doc/usage/pre-load-verify.rst b/doc/usage/pre-load-verify.rst new file mode 100644 index 00..7b833d079b --- /dev/null +++ b/doc/usage/pre-load-verify.rst @@ -0,0 +1,44 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +pre-load-verify command +=== + +Synopsis + + +:: + +pre_load_verify + +Description +--- + +The pre-load-verify command verify the signature of the binary at address addr +using the pre-load header that should be at the beginning of the binary. + +addr +Address of the binary to verify + + +Examples + + + +:: + +=> pre_load_verify 100 +INFO: signature check has succeed + +If succeed, the u-boot env variable loadaddr_verified is set to the address +if the binary after the pre-load header + +:: + +=> printenv loadaddr_verified +loadaddr_verified=1100 + + +Return value + + +The return value $? is 0 is the signature check succeed, 1 otherwise -- 2.17.1
[PATCH v7 05/16] lib: crypto: allow to build crypyo in SPL
This commit adds the options: - SPL_ASYMMETRIC_KEY_TYPE - SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE - SPL_RSA_PUBLIC_KEY_PARSER Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Makefile| 3 ++- lib/crypto/Kconfig | 29 + lib/crypto/Makefile | 19 +-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 13e5d8f7a6..13fe5fb7a4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,7 +17,6 @@ obj-$(CONFIG_OF_LIVE) += of_live.o obj-$(CONFIG_CMD_DHRYSTONE) += dhry/ obj-$(CONFIG_ARCH_AT91) += at91/ obj-$(CONFIG_OPTEE_LIB) += optee/ -obj-y += crypto/ obj-$(CONFIG_AES) += aes.o obj-$(CONFIG_AES) += aes/ @@ -63,6 +62,8 @@ obj-$(CONFIG_TPM_V1) += tpm-v1.o obj-$(CONFIG_TPM_V2) += tpm-v2.o endif +obj-y += crypto/ + obj-$(CONFIG_$(SPL_TPL_)GENERATE_ACPI_TABLE) += acpi/ obj-$(CONFIG_$(SPL_)MD5) += md5.o obj-$(CONFIG_ECDSA) += ecdsa/ diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig index 6369bafac0..509bc28311 100644 --- a/lib/crypto/Kconfig +++ b/lib/crypto/Kconfig @@ -8,6 +8,15 @@ menuconfig ASYMMETRIC_KEY_TYPE if ASYMMETRIC_KEY_TYPE +config SPL_ASYMMETRIC_KEY_TYPE + bool "Asymmetric (public-key cryptographic) key Support within SPL" + depends on SPL + help + This option provides support for a key type that holds the data for + the asymmetric keys used for public key cryptographic operations such + as encryption, decryption, signature generation and signature + verification in the SPL. + config ASYMMETRIC_PUBLIC_KEY_SUBTYPE bool "Asymmetric public-key crypto algorithm subtype" help @@ -16,6 +25,15 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE appropriate hash algorithms (such as SHA-1) must be available. ENOPKG will be reported if the requisite algorithm is unavailable. +config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE + bool "Asymmetric public-key crypto algorithm subtype within SPL" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + help + This option provides support for asymmetric public key type handling in the SPL. + If signature generation and/or verification are to be used, + appropriate hash algorithms (such as SHA-1) must be available. + ENOPKG will be reported if the requisite algorithm is unavailable. + config RSA_PUBLIC_KEY_PARSER bool "RSA public key parser" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE @@ -27,6 +45,17 @@ config RSA_PUBLIC_KEY_PARSER public key data and provides the ability to instantiate a public key. +config SPL_RSA_PUBLIC_KEY_PARSER + bool "RSA public key parser within SPL" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select SPL_ASN1_DECODER + select ASN1_COMPILER + select SPL_OID_REGISTRY + help + This option provides support for parsing a blob containing RSA + public key data and provides the ability to instantiate a public + key in the SPL. + config X509_CERTIFICATE_PARSER bool "X.509 certificate parser" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index f3a414525d..6792b1d4f0 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -3,27 +3,34 @@ # Makefile for asymmetric cryptographic keys # -obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o asymmetric_keys-y := asymmetric_type.o -obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o # # RSA public key parser # -obj-$(CONFIG_RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o +obj-$(CONFIG_$(SPL_)RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o rsa_public_key-y := \ rsapubkey.asn1.o \ rsa_helper.o $(obj)/rsapubkey.asn1.o: $(obj)/rsapubkey.asn1.c $(obj)/rsapubkey.asn1.h +ifdef CONFIG_SPL_BUILD +CFLAGS_rsapubkey.asn1.o += -I$(obj) +endif + $(obj)/rsa_helper.o: $(obj)/rsapubkey.asn1.h +ifdef CONFIG_SPL_BUILD +CFLAGS_rsa_helper.o += -I$(obj) +endif # # X.509 Certificate handling # -obj-$(CONFIG_X509_CERTIFICATE_PARSER) += x509_key_parser.o +obj-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER) += x509_key_parser.o x509_key_parser-y := \ x509.asn1.o \ x509_akid.asn1.o \ @@ -40,11 +47,11 @@ $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h # # PKCS#7 message handling # -obj-$(CONFIG_PKCS7_MESSAGE_PARSER) += pkcs7_message.o +obj-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER) += pkcs7_message.o pkcs7_message-y := \ pkcs7.asn1.o \ pkcs7_parser.o -obj-$(CONFIG_PKCS7_VERIFY) += pkcs7_verify.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 -- 2.17.1
[PATCH v7 10/16] mkimage: add public key for image pre-load stage
This commit enhances mkimage to update the node /image/pre-load/sig with the public key. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- include/image.h| 15 ++ tools/fit_image.c | 3 ++ tools/image-host.c | 114 + 3 files changed, 132 insertions(+) diff --git a/include/image.h b/include/image.h index 496b7af3f3..498eb7f2e3 100644 --- a/include/image.h +++ b/include/image.h @@ -1019,6 +1019,21 @@ int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, int fit_set_timestamp(void *fit, int noffset, time_t timestamp); +/** + * fit_pre_load_data() - add public key to fdt blob + * + * Adds public key to the node pre load. + * + * @keydir:Directory containing keys + * @keydest: FDT blob to write public key + * @fit: Pointer to the FIT format image header + * + * returns: + * 0, on success + * < 0, on failure + */ +int fit_pre_load_data(const char *keydir, void *keydest, void *fit); + int fit_cipher_data(const char *keydir, void *keydest, void *fit, const char *comment, int require_keys, const char *engine_id, const char *cmdname); diff --git a/tools/fit_image.c b/tools/fit_image.c index 15f7c82d61..1884a2eb0b 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -59,6 +59,9 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, ret = fit_set_timestamp(ptr, 0, time); } + if (!ret) + ret = fit_pre_load_data(params->keydir, dest_blob, ptr); + if (!ret) { ret = fit_cipher_data(params->keydir, dest_blob, ptr, params->comment, diff --git a/tools/image-host.c b/tools/image-host.c index eaeb76545c..ab6f756cf1 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -14,6 +14,11 @@ #include #include +#include +#include + +#define IMAGE_PRE_LOAD_PATH "/image/pre-load/sig" + /** * fit_set_hash_value - set hash value in requested has node * @fit: pointer to the FIT format image header @@ -,6 +1116,115 @@ static int fit_config_add_verification_data(const char *keydir, return 0; } +/* + * 0) open file (open) + * 1) read certificate (PEM_read_X509) + * 2) get public key (X509_get_pubkey) + * 3) provide der format (d2i_RSAPublicKey) + */ +static int read_pub_key(const char *keydir, const void *name, + unsigned char **pubkey, int *pubkey_len) +{ + char path[1024]; + EVP_PKEY *key = NULL; + X509 *cert; + FILE *f; + int ret; + + memset(path, 0, 1024); + snprintf(path, sizeof(path), "%s/%s.crt", keydir, (char *)name); + + /* Open certificate file */ + f = fopen(path, "r"); + if (!f) { + fprintf(stderr, "Couldn't open RSA certificate: '%s': %s\n", + path, strerror(errno)); + return -EACCES; + } + + /* Read the certificate */ + cert = NULL; + if (!PEM_read_X509(f, &cert, NULL, NULL)) { + printf("Couldn't read certificate"); + ret = -EINVAL; + goto err_cert; + } + + /* Get the public key from the certificate. */ + key = X509_get_pubkey(cert); + if (!key) { + printf("Couldn't read public key\n"); + ret = -EINVAL; + goto err_pubkey; + } + + /* Get DER form */ + ret = i2d_PublicKey(key, pubkey); + if (ret < 0) { + printf("Couldn't get DER form\n"); + ret = -EINVAL; + goto err_pubkey; + } + + *pubkey_len = ret; + ret = 0; + +err_pubkey: + X509_free(cert); +err_cert: + fclose(f); + return ret; +} + +int fit_pre_load_data(const char *keydir, void *keydest, void *fit) +{ + int pre_load_noffset; + const void *algo_name; + const void *key_name; + unsigned char *pubkey = NULL; + int ret, pubkey_len; + + if (!keydir || !keydest || !fit) + return 0; + + /* Search node pre-load sig */ + pre_load_noffset = fdt_path_offset(keydest, IMAGE_PRE_LOAD_PATH); + if (pre_load_noffset < 0) { + ret = 0; + goto out; + } + + algo_name = fdt_getprop(keydest, pre_load_noffset, "algo-name", NULL); + key_name = fdt_getprop(keydest, pre_load_noffset, "key-name", NULL); + + /* Check that all mandatory properties are present */ + if (!algo_name || !key_name) { + if (!algo_name) + printf("The property algo-name is missing in the node %s\n", + IMAGE_PRE_LOAD_PATH); + if (!key_name) +
[PATCH v7 13/16] configs: sandbox_defconfig: enable stage pre-load in bootm
Enable the support of stage pre-load in bootm. For the moment, this stage allow to verify the signature of the full image with a header. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- configs/sandbox_defconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 7ebeb89264..46bf18bc98 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -27,6 +27,8 @@ CONFIG_AUTOBOOT_SHA256_FALLBACK=y CONFIG_AUTOBOOT_NEVER_TIMEOUT=y CONFIG_AUTOBOOT_STOP_STR_ENABLE=y CONFIG_AUTOBOOT_STOP_STR_CRYPT="$5$rounds=64$HrpE65IkB8CM5nCL$BKT3QdF98Bo8fJpTr9tjZLZQyzqPASBY20xuK5Rent9" +CONFIG_IMAGE_PRE_LOAD=y +CONFIG_IMAGE_PRE_LOAD_SIG=y CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_PRE_CONSOLE_BUFFER=y @@ -37,6 +39,7 @@ CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y +CONFIG_CMD_BOOTM_PRE_LOAD=y CONFIG_CMD_BOOTZ=y CONFIG_CMD_BOOTEFI_HELLO=y CONFIG_CMD_ABOOTIMG=y -- 2.17.1
[PATCH v7 09/16] common: spl: fit_ram: allow to use image pre load
Add the support of image pre load in spl or tpl when loading an image from ram. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- common/spl/spl_ram.c | 21 - 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/common/spl/spl_ram.c b/common/spl/spl_ram.c index 3f7f7accc1..8296459257 100644 --- a/common/spl/spl_ram.c +++ b/common/spl/spl_ram.c @@ -24,9 +24,17 @@ static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, ulong count, void *buf) { + ulong addr; + debug("%s: sector %lx, count %lx, buf %lx\n", __func__, sector, count, (ulong)buf); - memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count); + + addr = (ulong)CONFIG_SPL_LOAD_FIT_ADDRESS + sector; + if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) + addr += image_load_offset; + + memcpy(buf, (void *)addr, count); + return count; } @@ -37,6 +45,17 @@ static int spl_ram_load_image(struct spl_image_info *spl_image, header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS; + if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) { + unsigned long addr = (unsigned long)header; + int ret = image_pre_load(addr); + + if (ret) + return ret; + + addr += image_load_offset; + header = (struct image_header *)addr; + } + #if CONFIG_IS_ENABLED(DFU) if (bootdev->boot_device == BOOT_DEVICE_DFU) spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0"); -- 2.17.1
[PATCH v7 06/16] lib: rsa: allow rsa verify with pkey in SPL
This commit adds the option SPL_RSA_VERIFY_WITH_PKEY. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/rsa/Kconfig | 19 +++ 1 file changed, 19 insertions(+) diff --git a/lib/rsa/Kconfig b/lib/rsa/Kconfig index be9775bcce..b773f17c26 100644 --- a/lib/rsa/Kconfig +++ b/lib/rsa/Kconfig @@ -47,6 +47,25 @@ config RSA_VERIFY_WITH_PKEY directly specified in image_sign_info, where all the necessary key properties will be calculated on the fly in verification code. +config SPL_RSA_VERIFY_WITH_PKEY + bool "Execute RSA verification without key parameters from FDT within SPL" + depends on SPL + select SPL_RSA_VERIFY + select SPL_ASYMMETRIC_KEY_TYPE + select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select SPL_RSA_PUBLIC_KEY_PARSER + help + The standard RSA-signature verification code (FIT_SIGNATURE) uses + pre-calculated key properties, that are stored in fdt blob, in + decrypting a signature. + This does not suit the use case where there is no way defined to + provide such additional key properties in standardized form, + particularly UEFI secure boot. + This options enables RSA signature verification with a public key + directly specified in image_sign_info, where all the necessary + key properties will be calculated on the fly in verification code + in the SPL. + config RSA_SOFTWARE_EXP bool "Enable driver for RSA Modular Exponentiation in software" depends on DM -- 2.17.1
[PATCH v7 03/16] lib: Kconfig: enhance the help of OID_REGISTRY
Enhance the help for the config OID_REGISTRY. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Kconfig | 4 1 file changed, 4 insertions(+) diff --git a/lib/Kconfig b/lib/Kconfig index b0e5d60b3d..e749826f22 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -812,6 +812,10 @@ config ASN1_DECODER config OID_REGISTRY bool help + In computing, object identifiers or OIDs are an identifier mechanism + standardized by the International Telecommunication Union (ITU) and + ISO/IEC for naming any object, concept, or "thing" with a globally + unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). Enable fast lookup object identifier registry. config SMBIOS_PARSER -- 2.17.1
[PATCH v7 11/16] Makefile: provide sah-key to binman
Set the variable pre-load-key-path with the shell variable PRE_LOAD_KEY_PATH that contain the keys path (used for signature). This variable pre-load-key-path is provided to binman. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index f8f3f24641..ce31d2018c 100644 --- a/Makefile +++ b/Makefile @@ -1335,6 +1335,7 @@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \ -a tpl-bss-pad=$(if $(CONFIG_TPL_SEPARATE_BSS),,1) \ -a spl-dtb=$(CONFIG_SPL_OF_REAL) \ -a tpl-dtb=$(CONFIG_TPL_OF_REAL) \ + -a pre-load-key-path=${PRE_LOAD_KEY_PATH} \ $(BINMAN_$(@F)) OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex -- 2.17.1
[PATCH v7 01/16] arch: Kconfig: imply BINMAN for SANDBOX
To be able to use the tool binman on sandbox, the config SANDBOX should imply BINMAN. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- arch/Kconfig | 1 + arch/sandbox/dts/sandbox.dtsi | 3 +++ arch/sandbox/dts/test.dts | 3 +++ test/py/tests/test_fit.py | 3 +++ test/py/tests/vboot/sandbox-u-boot.dts | 3 +++ 5 files changed, 13 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index e6191446a3..35624377ca 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -203,6 +203,7 @@ config SANDBOX imply KEYBOARD imply PHYSMEM imply GENERATE_ACPI_TABLE + imply BINMAN config SH bool "SuperH architecture" diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 66b813faad..826db26fc2 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -7,6 +7,9 @@ #define USB_CLASS_HUB 9 / { + binman { + }; + chosen { stdout-path = "/serial"; }; diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 48ca3e1e47..c11ad8cb9f 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -61,6 +61,9 @@ osd0 = "/osd"; }; + binman { + }; + config { testing-bool; testing-int = <123>; diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py index 6d5b43c3ba..5856960be2 100755 --- a/test/py/tests/test_fit.py +++ b/test/py/tests/test_fit.py @@ -89,6 +89,9 @@ base_fdt = ''' model = "Sandbox Verified Boot Test"; compatible = "sandbox"; + binman { + }; + reset@0 { compatible = "sandbox,reset"; reg = <0>; diff --git a/test/py/tests/vboot/sandbox-u-boot.dts b/test/py/tests/vboot/sandbox-u-boot.dts index 63f8f401de..5809c62fc1 100644 --- a/test/py/tests/vboot/sandbox-u-boot.dts +++ b/test/py/tests/vboot/sandbox-u-boot.dts @@ -4,6 +4,9 @@ model = "Sandbox Verified Boot Test"; compatible = "sandbox"; + binman { + }; + reset@0 { compatible = "sandbox,reset"; }; -- 2.17.1
[PATCH v7 02/16] lib: Kconfig: enhance help for ASN1
Enhance the help for configs ASN1_COMPILER and ASN1_decoder. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Kconfig | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Kconfig b/lib/Kconfig index 3c6fa99b1a..b0e5d60b3d 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -791,11 +791,23 @@ endmenu config ASN1_COMPILER bool + help + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 compiler. config ASN1_DECODER bool help - Enable asn1 decoder library. + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 decoder. config OID_REGISTRY bool -- 2.17.1
[PATCH v7 04/16] lib: allow to build asn1 decoder and oid registry in SPL
This commit adds the options: - SPL_ASN1_DECODER - SPL_OID_REGISTRY Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Kconfig | 19 +++ lib/Makefile | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Kconfig b/lib/Kconfig index e749826f22..effe735365 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -809,6 +809,16 @@ config ASN1_DECODER and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). This option enables the support of the asn1 decoder. +config SPL_ASN1_DECODER + bool + help + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 decoder in the SPL. + config OID_REGISTRY bool help @@ -818,6 +828,15 @@ config OID_REGISTRY unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). Enable fast lookup object identifier registry. +config SPL_OID_REGISTRY + bool + help + In computing, object identifiers or OIDs are an identifier mechanism + standardized by the International Telecommunication Union (ITU) and + ISO/IEC for naming any object, concept, or "thing" with a globally + unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). + Enable fast lookup object identifier registry in the SPL. + config SMBIOS_PARSER bool "SMBIOS parser" help diff --git a/lib/Makefile b/lib/Makefile index 11b03d1cbe..13e5d8f7a6 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,7 +17,6 @@ obj-$(CONFIG_OF_LIVE) += of_live.o obj-$(CONFIG_CMD_DHRYSTONE) += dhry/ obj-$(CONFIG_ARCH_AT91) += at91/ obj-$(CONFIG_OPTEE_LIB) += optee/ -obj-$(CONFIG_ASN1_DECODER) += asn1_decoder.o obj-y += crypto/ obj-$(CONFIG_AES) += aes.o @@ -74,6 +73,7 @@ obj-$(CONFIG_SHA1) += sha1.o obj-$(CONFIG_SHA256) += sha256.o obj-$(CONFIG_SHA512) += sha512.o obj-$(CONFIG_CRYPT_PW) += crypt/ +obj-$(CONFIG_$(SPL_)ASN1_DECODER) += asn1_decoder.o obj-$(CONFIG_$(SPL_)ZLIB) += zlib/ obj-$(CONFIG_$(SPL_)ZSTD) += zstd/ @@ -135,9 +135,9 @@ obj-$(CONFIG_$(SPL_TPL_)STRTO) += strto.o else # Main U-Boot always uses the full printf support obj-y += vsprintf.o strto.o -obj-$(CONFIG_OID_REGISTRY) += oid_registry.o obj-$(CONFIG_SSCANF) += sscanf.o endif +obj-$(CONFIG_$(SPL_)OID_REGISTRY) += oid_registry.o obj-y += abuf.o obj-y += date.o -- 2.17.1
[PATCH v7 00/16] image: add a stage pre-load
This serie adds a stage pre-load before launching an image. This stage is used to read a header before the image and this header contains the signature of the full image. So u-boot may check the full image before using any data of the image. The support of this header is added to binman, and a command verify checks the signature of a blob and set the u-boot env variable "loadaddr_verified" to the beginning of the "real" image. The support of this header is only added to binman, but it may also be added to mkimage. Changelog: v7: - rename command verify to pre_load_verify - add usage doc for command pre_load_verify - some cleanup in support of pre-load in binman - rename variable key-path to pre-load-key-path - some cleanup in test vboot for pre-load v6: - set values in big endian in the pre-load header - binman: etypes: pre-load: read image from other entry instead of directly from a file - binman: etypes: pre-load: add test unit - lib: Makefile: no longer add -I$(obj) for SPL It was to fix build when oid is built on spl but not on u-boot. It is not longer possible. v5: - replace config SANDBOX_BINMAN by an imply v4: - add a config SANDBOX_BIN - enhance help for asn1 and oid - change the format of the pre-load header - add the support of pre-load header in binman - add py test for pre-load header - add a command verify v3: - move image-pre-load.c to /boot - update mkimage to add public key in u-boot device tree - add script gen_pre_load_header.sh v2: - move the code to image-pre-load - add support of stage pre-load for spl - add support of stage pre-load on spl_ram Philippe Reynes (16): arch: Kconfig: imply BINMAN for SANDBOX lib: Kconfig: enhance help for ASN1 lib: Kconfig: enhance the help of OID_REGISTRY lib: allow to build asn1 decoder and oid registry in SPL lib: crypto: allow to build crypyo in SPL lib: rsa: allow rsa verify with pkey in SPL boot: image: add a stage pre-load cmd: bootm: add a stage pre-load common: spl: fit_ram: allow to use image pre load mkimage: add public key for image pre-load stage Makefile: provide sah-key to binman tools: binman: add support for pre-load header configs: sandbox_defconfig: enable stage pre-load in bootm test: py: vboot: add test for global image signature cmd: pre_load_verify: initial import configs: sandbox_defconfig: enable config CMD_PRE_LOAD_VERIFY Makefile | 1 + arch/Kconfig | 1 + arch/sandbox/dts/sandbox.dtsi | 3 + arch/sandbox/dts/test.dts | 3 + boot/Kconfig | 55 +++ boot/Makefile | 1 + boot/bootm.c | 33 ++ boot/image-pre-load.c | 416 ++ cmd/Kconfig | 18 + cmd/Makefile | 2 + cmd/bootm.c | 2 +- cmd/pre-load-verify.c | 53 +++ common/spl/spl_ram.c | 21 +- configs/sandbox_defconfig | 4 + doc/usage/index.rst | 1 + doc/usage/pre-load-verify.rst | 44 ++ include/image.h | 30 ++ lib/Kconfig | 37 +- lib/Makefile | 7 +- lib/crypto/Kconfig| 29 ++ lib/crypto/Makefile | 19 +- lib/rsa/Kconfig | 19 + test/py/tests/test_fit.py | 3 + test/py/tests/test_vboot.py | 145 +- test/py/tests/vboot/sandbox-binman-pss.dts| 25 ++ test/py/tests/vboot/sandbox-binman.dts| 24 + .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 ++ test/py/tests/vboot/sandbox-u-boot-global.dts | 27 ++ test/py/tests/vboot/sandbox-u-boot.dts| 3 + test/py/tests/vboot/simple-images.its | 36 ++ tools/binman/entries.rst | 38 ++ tools/binman/etype/pre_load.py| 162 +++ tools/binman/ftest.py | 51 +++ tools/binman/test/225_dev.key | 28 ++ tools/binman/test/225_pre_load.dts| 22 + tools/binman/test/226_pre_load_pkcs.dts | 23 + tools/binman/test/227_pre_load_pss.dts| 23 + .../test/228_pre_load_invalid_padding.dts | 23 + .../binman/test/229_pre_load_invalid_sha.dts | 23 + .../binman/test/230_pre_load_invalid_algo.dts | 23 + .../binman/test/231_pre_load_invalid_key.dts | 23 + tools/fit_image.c | 3 + tools/image-host.c| 114 + 43 files changed, 1618 insertions(+), 28 deletions(-) create mode 100644 boot/image-pre-load.c create mode 100644 cmd/pre-load-verify.c create m
Re: [PATCH v6 07/16] boot: image: add a stage pre-load
Hi Simon, Le 03/03/2022 à 04:37, Simon Glass a écrit : Hi Philippe, On Fri, 25 Feb 2022 at 07:58, Philippe Reynes wrote: Add a stage pre-load that could check or modify an image. For the moment, only a header with a signature is supported. This header has the following format: - magic : 4 bytes - version : 4 bytes - header size : 4 bytes - image size : 4 bytes - offset image signature : 4 bytes - flags : 4 bytes - reserved0 : 4 bytes - reserved1 : 4 bytes - sha256 of the image signature : 32 bytes - signature of the first 64 bytes : n bytes It is a bit hard to understand without docs, but what is the point of taking the sha256 of the signature? Also, why is the signature only of the first 64 bytes? Normally we hash the whole image and then sign that. The size of the header is dynamic and specified in the header. The golden rule is: no data is used before being checked. To check the header, the size of the header is needed, but as this size is in the header and the header is not checked yet, it is not possible to read/use it. So to check the header, we use a two steps scheme: 1) the first 64 bytes of the header contains informations about the header, call it header_header. As this header_header has a fixed size, it possible to check its signature. 2) the header_header contains a hash of the image signature, and its offset in the header. So it is possible to check the hash of the image signature. After those two steps, the image signature contained in the header is checked and can be used to verify the signature of the image. So the golden rule is respected, no data are used before being checked. - image signature : n bytes - padding : up to header size The stage uses a node /image/pre-load/sig to get some informations: - algo-name (mandatory) : name of the algo used to sign - padding-name : name of padding used to sign - signature-size : size of the signature (in the header) - mandatory : set to yes if this sig is mandatory - public-key (madatory) : value of the public key Does this mean you read the DT properties to find out the sig info? I thought the point of this series was to have a signature check that did not rely on the devicetree, i.e. another layer of security? Yes, some properties are in the device tree, like the name of the algo (sha256,rsa4096, ), the padding name, the signature size, the public key, and if a signature is mandatory before launching a binary with bootm. The first goal of this serie is to be able to verify the signature of an image without using data not yet verified. If the signature is in the FIT image, the header of the fit, and some node of the fit must be read and used before verifying the signature of the FIT. Another goal appears with this serie, to be able to verify the signature of other binary than FIT (script, firmware, ...). Before running the image, the stage pre-load checks the signature provided in the header. This is an initial support, later we could add the support of: - ciphering - uncompressing - ... Signed-off-by: Philippe Reynes --- boot/Kconfig | 55 ++ boot/Makefile | 1 + boot/image-pre-load.c | 416 ++ include/image.h | 14 ++ 4 files changed, 486 insertions(+) create mode 100644 boot/image-pre-load.c Regards, Simon Regards, Philippe
Re: [PATCH v6 15/16] cmd: verify: initial import
Hi Simon, Le 03/03/2022 à 04:37, Simon Glass a écrit : Hi Philippe, On Fri, 25 Feb 2022 at 07:58, Philippe Reynes wrote: Add the command verify that check the signature of an image with the pre-load header. If the check succeed, the u-boot env variable 'loadaddr_verified' is set to the address of the image (without the header). It allows to run such commands: tftp script.img && verify $loadaddr && source $loadaddr_verified Signed-off-by: Philippe Reynes --- cmd/Kconfig | 7 +++ cmd/Makefile | 1 + cmd/verify.c | 53 3 files changed, 61 insertions(+) create mode 100644 cmd/verify.c Using the 'verify' command seems a bit vague. Could it be a sub-command of bootm perhaps? The command verify may be used with any binary (script, video firmware, .). So a lot of binaries that are not launched by bootm. I think that it is not "logic" to used a bootm subcommand. But we could use another name if you want. For example : pre_load_verify ? diff --git a/cmd/Kconfig b/cmd/Kconfig index 87aa3fb11a..0460d5c3a0 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -428,6 +428,13 @@ config CMD_THOR_DOWNLOAD There is no documentation about this within the U-Boot source code but you should be able to find something on the interwebs. +config CMD_VERIFY + bool "verify the global signature" +depends on CMD_BOOTM_PRE_LOAD + help + Verify the signature provided in a pre-load header of + a full image. Please point to docs here + config CMD_ZBOOT bool "zboot - x86 boot command" help diff --git a/cmd/Makefile b/cmd/Makefile index 166c652d98..80e054e806 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -177,6 +177,7 @@ obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o obj-$(CONFIG_CMD_XIMG) += ximg.o obj-$(CONFIG_CMD_YAFFS2) += yaffs2.o obj-$(CONFIG_CMD_SPL) += spl.o +obj-$(CONFIG_CMD_VERIFY) += verify.o obj-$(CONFIG_CMD_W1) += w1.o obj-$(CONFIG_CMD_ZIP) += zip.o obj-$(CONFIG_CMD_ZFS) += zfs.o diff --git a/cmd/verify.c b/cmd/verify.c new file mode 100644 index 00..4d055e0790 --- /dev/null +++ b/cmd/verify.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Philippe Reynes + */ + +#include +#include +#include +#include + +static ulong verify_get_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = simple_strtoul(argv[0], NULL, 16); hextoul + else + addr = image_load_addr; + + return addr; +} + +static int do_verify(struct cmd_tbl *cmdtp, int flag, int argc, +char *const argv[]) +{ + ulong addr = verify_get_addr(argc, argv); + int ret = 0; + + argc--; argv++; + + addr = verify_get_addr(argc, argv); + + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) { + ret = image_pre_load(addr); + + if (ret) { + ret = CMD_RET_FAILURE; + goto out; + } + + env_set_hex("loadaddr_verified", addr + image_load_offset); + } + + out: + return ret; +} + +U_BOOT_CMD(verify, 2, 1, do_verify, + "verify the global signature provided in the pre-load header,\n" + "\tif the check succeed, the u-boot env variable loadaddr_verified\n" + "\tis set to the address of the image (without the header)", + "" +); -- 2.17.1 Regards, Simon Regards, Philippe
[PATCH] doc: device-tree-bindings: watchdog: document common properties
Adds simple documentation about common properties for watchdog in the device tree. Signed-off-by: Philippe Reynes --- doc/device-tree-bindings/watchdog/common.txt | 12 1 file changed, 12 insertions(+) create mode 100644 doc/device-tree-bindings/watchdog/common.txt diff --git a/doc/device-tree-bindings/watchdog/common.txt b/doc/device-tree-bindings/watchdog/common.txt new file mode 100644 index 00..9db6dd6146 --- /dev/null +++ b/doc/device-tree-bindings/watchdog/common.txt @@ -0,0 +1,12 @@ +Common watchdog properties. + +Optional properties: +- timeout-sec : Timeout of the watchdog in seconds +If this timeout is not defined, the value of WATCHDOG_TIMEOUT_MSECS will +be used instead. +- hw_margin_ms : Period used to reset the watchdog in ms + If this period is not defined, the default value is 1000. +- u-boot,noautostart : Specify that this watchdog should not autostart + When the config option WATCHDOG_AUTOSTART is set, all enabled + watchdogs are started. This property allows specifying that this + watchdog should NOT be started. -- 2.17.1
Re: [PATCH v4] scripts: Makefile.lib: generate dsdt_generated.c instead of dsdt.c
Hi Tom, Le 25/02/2022 à 21:53, Tom Rini a écrit : On Fri, Feb 25, 2022 at 06:30:05PM +0100, Philippe Reynes wrote: There is a conflict between the static file lib/acpi/dsdt.c and the file dsdt.c generated dynamicaly by scripts/Makefile.lib. When a mrproper is done, the static file dsdt.c is removed. If a build with acpi enabled is launched after, the following error is raised: CC lib/acpi/acpi_table.o make[2]: *** No rule to make target 'lib/acpi/dsdt.asl', needed by 'lib/acpi/dsdt.c'. Stop. scripts/Makefile.build:394: recipe for target 'lib/acpi' failed To avoid such error, the generated file is named dsdt_generated.c instead of dstdt.c. Tested-by: Heiko Thiery Signed-off-by: Philippe Reynes --- Changelog: v4: - update dsdt.* to dsdt_generated.* in several .gitignore v3: - update comments in file scripts/Makefile.lib - add changelog v2 - change generated file name (dsdt_generated.c) instead of changing the name of the static file - NOTE : forgot to call it v2 and forgot changelog Sorry, I missed that this had come through while testing and applying v3. Can you please do an incremental patch with the changes? Thanks! No problem, I understand, I just send a new patch with only the update on files .gitignore Regards, Philippe
[PATCH] board: .gitignore: replace dsdt.c by dsdt_generated.c
Since commit 5d94cbd1dca7 ("scripts: Makefile.lib: generate dsdt_generated.c instead of dsdt.c"), the file generated is named dsdt_generated.c instead of dsdt.c. So all files .gitignore referencing dsdt.c should be upated with dsdt_generated.c. Signed-off-by: Philippe Reynes --- board/advantech/som-db5800-som-6867/.gitignore| 6 +++--- board/congatec/conga-qeval20-qa3-e3845/.gitignore | 6 +++--- board/intel/bayleybay/.gitignore | 6 +++--- board/intel/edison/.gitignore | 6 +++--- board/intel/galileo/.gitignore| 6 +++--- board/intel/minnowmax/.gitignore | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/board/advantech/som-db5800-som-6867/.gitignore b/board/advantech/som-db5800-som-6867/.gitignore index 6eb8a5481a..39e46ba0ae 100644 --- a/board/advantech/som-db5800-som-6867/.gitignore +++ b/board/advantech/som-db5800-som-6867/.gitignore @@ -1,3 +1,3 @@ -dsdt.aml -dsdt.asl.tmp -dsdt.c +dsdt_generated.aml +dsdt_generated.asl.tmp +dsdt_generated.c diff --git a/board/congatec/conga-qeval20-qa3-e3845/.gitignore b/board/congatec/conga-qeval20-qa3-e3845/.gitignore index 6eb8a5481a..39e46ba0ae 100644 --- a/board/congatec/conga-qeval20-qa3-e3845/.gitignore +++ b/board/congatec/conga-qeval20-qa3-e3845/.gitignore @@ -1,3 +1,3 @@ -dsdt.aml -dsdt.asl.tmp -dsdt.c +dsdt_generated.aml +dsdt_generated.asl.tmp +dsdt_generated.c diff --git a/board/intel/bayleybay/.gitignore b/board/intel/bayleybay/.gitignore index 6eb8a5481a..39e46ba0ae 100644 --- a/board/intel/bayleybay/.gitignore +++ b/board/intel/bayleybay/.gitignore @@ -1,3 +1,3 @@ -dsdt.aml -dsdt.asl.tmp -dsdt.c +dsdt_generated.aml +dsdt_generated.asl.tmp +dsdt_generated.c diff --git a/board/intel/edison/.gitignore b/board/intel/edison/.gitignore index 6eb8a5481a..39e46ba0ae 100644 --- a/board/intel/edison/.gitignore +++ b/board/intel/edison/.gitignore @@ -1,3 +1,3 @@ -dsdt.aml -dsdt.asl.tmp -dsdt.c +dsdt_generated.aml +dsdt_generated.asl.tmp +dsdt_generated.c diff --git a/board/intel/galileo/.gitignore b/board/intel/galileo/.gitignore index 6eb8a5481a..39e46ba0ae 100644 --- a/board/intel/galileo/.gitignore +++ b/board/intel/galileo/.gitignore @@ -1,3 +1,3 @@ -dsdt.aml -dsdt.asl.tmp -dsdt.c +dsdt_generated.aml +dsdt_generated.asl.tmp +dsdt_generated.c diff --git a/board/intel/minnowmax/.gitignore b/board/intel/minnowmax/.gitignore index 6eb8a5481a..39e46ba0ae 100644 --- a/board/intel/minnowmax/.gitignore +++ b/board/intel/minnowmax/.gitignore @@ -1,3 +1,3 @@ -dsdt.aml -dsdt.asl.tmp -dsdt.c +dsdt_generated.aml +dsdt_generated.asl.tmp +dsdt_generated.c -- 2.17.1
[PATCH v4] scripts: Makefile.lib: generate dsdt_generated.c instead of dsdt.c
There is a conflict between the static file lib/acpi/dsdt.c and the file dsdt.c generated dynamicaly by scripts/Makefile.lib. When a mrproper is done, the static file dsdt.c is removed. If a build with acpi enabled is launched after, the following error is raised: CC lib/acpi/acpi_table.o make[2]: *** No rule to make target 'lib/acpi/dsdt.asl', needed by 'lib/acpi/dsdt.c'. Stop. scripts/Makefile.build:394: recipe for target 'lib/acpi' failed To avoid such error, the generated file is named dsdt_generated.c instead of dstdt.c. Tested-by: Heiko Thiery Signed-off-by: Philippe Reynes --- Changelog: v4: - update dsdt.* to dsdt_generated.* in several .gitignore v3: - update comments in file scripts/Makefile.lib - add changelog v2 - change generated file name (dsdt_generated.c) instead of changing the name of the static file - NOTE : forgot to call it v2 and forgot changelog Makefile | 3 ++- board/advantech/som-db5800-som-6867/.gitignore| 6 +++--- board/advantech/som-db5800-som-6867/Makefile | 2 +- board/congatec/conga-qeval20-qa3-e3845/.gitignore | 6 +++--- board/congatec/conga-qeval20-qa3-e3845/Makefile | 2 +- board/dfi/dfi-bt700/Makefile | 2 +- board/google/chromebook_coral/Makefile| 2 +- board/intel/bayleybay/.gitignore | 6 +++--- board/intel/bayleybay/Makefile| 2 +- board/intel/edison/.gitignore | 6 +++--- board/intel/edison/Makefile | 2 +- board/intel/galileo/.gitignore| 6 +++--- board/intel/galileo/Makefile | 2 +- board/intel/minnowmax/.gitignore | 6 +++--- board/intel/minnowmax/Makefile| 2 +- scripts/Makefile.lib | 8 16 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 697cc51d67..66d9e78cc7 100644 --- a/Makefile +++ b/Makefile @@ -2227,7 +2227,8 @@ clean: $(clean-dirs) -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ -o -name modules.builtin -o -name '.tmp_*.o.*' \ - -o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \ + -o -name 'dsdt_generated.aml' -o -name 'dsdt_generated.asl.tmp' \ + -o -name 'dsdt_generated.c' \ -o -name '*.efi' -o -name '*.gcno' -o -name '*.so' \) \ -type f -print | xargs rm -f diff --git a/board/advantech/som-db5800-som-6867/.gitignore b/board/advantech/som-db5800-som-6867/.gitignore index 6eb8a5481a..39e46ba0ae 100644 --- a/board/advantech/som-db5800-som-6867/.gitignore +++ b/board/advantech/som-db5800-som-6867/.gitignore @@ -1,3 +1,3 @@ -dsdt.aml -dsdt.asl.tmp -dsdt.c +dsdt_generated.aml +dsdt_generated.asl.tmp +dsdt_generated.c diff --git a/board/advantech/som-db5800-som-6867/Makefile b/board/advantech/som-db5800-som-6867/Makefile index 7975547f41..95af6c4df7 100644 --- a/board/advantech/som-db5800-som-6867/Makefile +++ b/board/advantech/som-db5800-som-6867/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += som-db5800-som-6867.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/congatec/conga-qeval20-qa3-e3845/.gitignore b/board/congatec/conga-qeval20-qa3-e3845/.gitignore index 6eb8a5481a..39e46ba0ae 100644 --- a/board/congatec/conga-qeval20-qa3-e3845/.gitignore +++ b/board/congatec/conga-qeval20-qa3-e3845/.gitignore @@ -1,3 +1,3 @@ -dsdt.aml -dsdt.asl.tmp -dsdt.c +dsdt_generated.aml +dsdt_generated.asl.tmp +dsdt_generated.c diff --git a/board/congatec/conga-qeval20-qa3-e3845/Makefile b/board/congatec/conga-qeval20-qa3-e3845/Makefile index 451a4fcd6c..215f5680dc 100644 --- a/board/congatec/conga-qeval20-qa3-e3845/Makefile +++ b/board/congatec/conga-qeval20-qa3-e3845/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += conga-qeval20-qa3.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/dfi/dfi-bt700/Makefile b/board/dfi/dfi-bt700/Makefile index 50d88f2954..1c4329a058 100644 --- a/board/dfi/dfi-bt700/Makefile +++ b/board/dfi/dfi-bt700/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += dfi-bt700.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/google/chromebook_coral/Makefile b/board/google/chromebook_coral/Makefile index f7a0ca6cc0..846558d777 100644 --- a/board/google/chromebook_coral/Makefile +++ b/board/google/chromebook_coral/Makefile @@ -3,4 +3,4 @@ # Copyright 2019 Google LLC obj-y += coral.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) +=
Re: [PATCH v3] scripts: Makefile.lib: generate dsdt_generated.c instead of dsdt.c
Hi Heinrich, Le 25/02/2022 à 15:59, Heinrich Schuchardt a écrit : On 2/25/22 13:33, Heiko Thiery wrote: Hi, Am Di., 22. Feb. 2022 um 14:55 Uhr schrieb Philippe Reynes : There is a conflict between the static file lib/acpi/dsdt.c and the file dsdt.c generated dynamicaly by scripts/Makefile.lib. When a mrproper is done, the static file dsdt.c is removed. If a build with acpi enabled is launched after, the following error is raised: CC lib/acpi/acpi_table.o make[2]: *** No rule to make target 'lib/acpi/dsdt.asl', needed by 'lib/acpi/dsdt.c'. Stop. scripts/Makefile.build:394: recipe for target 'lib/acpi' failed To avoid such error, the generated file is named dsdt_generated.c instead of dstdt.c. This issue can also be seen when doing a make clean and do a git status -- 8< -- Hi Changes not staged for commit: (use "git add/rm ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) deleted: lib/acpi/dsdt.c -- 8< -- After applying this patch this cannot be seen anymore. Signed-off-by: Philippe Reynes Tested-by: Heiko Thiery The patch should update the .gitignore entries: board/advantech/som-db5800-som-6867/.gitignore:1:dsdt.aml board/advantech/som-db5800-som-6867/.gitignore:2:dsdt.asl.tmp board/advantech/som-db5800-som-6867/.gitignore:3:dsdt.c board/congatec/conga-qeval20-qa3-e3845/.gitignore:1:dsdt.aml board/congatec/conga-qeval20-qa3-e3845/.gitignore:2:dsdt.asl.tmp board/congatec/conga-qeval20-qa3-e3845/.gitignore:3:dsdt.c board/intel/bayleybay/.gitignore:1:dsdt.aml board/intel/bayleybay/.gitignore:2:dsdt.asl.tmp board/intel/bayleybay/.gitignore:3:dsdt.c board/intel/edison/.gitignore:1:dsdt.aml board/intel/edison/.gitignore:2:dsdt.asl.tmp board/intel/edison/.gitignore:3:dsdt.c board/intel/galileo/.gitignore:1:dsdt.aml board/intel/galileo/.gitignore:2:dsdt.asl.tmp board/intel/galileo/.gitignore:3:dsdt.c board/intel/minnowmax/.gitignore:1:dsdt.aml board/intel/minnowmax/.gitignore:2:dsdt.asl.tmp board/intel/minnowmax/.gitignore:3:dsdt.c You're right, I forgot it. I sent a v4 with this change. Thanks a lot. Best regards Heinrich Best Regards, Philippe --- Changelog: v3: - update comments in file scripts/Makefile.lib - add changelog v2 - change generated file name (dsdt_generated.c) instead of changing the name of the static file - NOTE : forgot to call it v2 and forgot changelog Makefile | 3 ++- board/advantech/som-db5800-som-6867/Makefile | 2 +- board/congatec/conga-qeval20-qa3-e3845/Makefile | 2 +- board/dfi/dfi-bt700/Makefile | 2 +- board/google/chromebook_coral/Makefile | 2 +- board/intel/bayleybay/Makefile | 2 +- board/intel/edison/Makefile | 2 +- board/intel/galileo/Makefile | 2 +- board/intel/minnowmax/Makefile | 2 +- scripts/Makefile.lib | 8 10 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4b152249ca..94bc48f00c 100644 --- a/Makefile +++ b/Makefile @@ -2226,7 +2226,8 @@ clean: $(clean-dirs) -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ -o -name modules.builtin -o -name '.tmp_*.o.*' \ - -o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \ + -o -name 'dsdt_generated.aml' -o -name 'dsdt_generated.asl.tmp' \ + -o -name 'dsdt_generated.c' \ -o -name '*.efi' -o -name '*.gcno' -o -name '*.so' \) \ -type f -print | xargs rm -f diff --git a/board/advantech/som-db5800-som-6867/Makefile b/board/advantech/som-db5800-som-6867/Makefile index 7975547f41..95af6c4df7 100644 --- a/board/advantech/som-db5800-som-6867/Makefile +++ b/board/advantech/som-db5800-som-6867/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += som-db5800-som-6867.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/congatec/conga-qeval20-qa3-e3845/Makefile b/board/congatec/conga-qeval20-qa3-e3845/Makefile index 451a4fcd6c..215f5680dc 100644 --- a/board/congatec/conga-qeval20-qa3-e3845/Makefile +++ b/board/congatec/conga-qeval20-qa3-e3845/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += conga-qeval20-qa3.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/dfi/dfi-bt700/Makefile b/board/dfi/dfi-bt700/Makefile index 50d88f2954..1c4329a058 100644 --- a/board/dfi/dfi-bt700/Makefile +++ b/board/dfi/dfi-bt700/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google
[PATCH v6 16/16] configs: sandbox_defconfig: enable config CMD_VERIFY
Enable the command verify on sandbox. Signed-off-by: Philippe Reynes --- configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 46bf18bc98..a56aa92f94 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -44,6 +44,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_BOOTEFI_HELLO=y CONFIG_CMD_ABOOTIMG=y # CONFIG_CMD_ELF is not set +CONFIG_CMD_VERIFY=y CONFIG_CMD_ASKENV=y CONFIG_CMD_GREPENV=y CONFIG_CMD_ERASEENV=y -- 2.17.1
[PATCH v6 12/16] tools: binman: add support for pre-load header
Adds the support of the pre-load header with the image signature to binman. Signed-off-by: Philippe Reynes --- tools/binman/etype/pre_load.py| 165 ++ tools/binman/ftest.py | 45 + tools/binman/test/225_dev.key | 28 +++ tools/binman/test/225_pre_load.dts| 22 +++ tools/binman/test/226_pre_load_pkcs.dts | 23 +++ tools/binman/test/227_pre_load_pss.dts| 23 +++ .../test/228_pre_load_invalid_padding.dts | 23 +++ .../binman/test/229_pre_load_invalid_sha.dts | 23 +++ .../binman/test/230_pre_load_invalid_algo.dts | 23 +++ .../binman/test/231_pre_load_invalid_key.dts | 23 +++ 10 files changed, 398 insertions(+) create mode 100644 tools/binman/etype/pre_load.py create mode 100644 tools/binman/test/225_dev.key create mode 100644 tools/binman/test/225_pre_load.dts create mode 100644 tools/binman/test/226_pre_load_pkcs.dts create mode 100644 tools/binman/test/227_pre_load_pss.dts create mode 100644 tools/binman/test/228_pre_load_invalid_padding.dts create mode 100644 tools/binman/test/229_pre_load_invalid_sha.dts create mode 100644 tools/binman/test/230_pre_load_invalid_algo.dts create mode 100644 tools/binman/test/231_pre_load_invalid_key.dts diff --git a/tools/binman/etype/pre_load.py b/tools/binman/etype/pre_load.py new file mode 100644 index 00..2af2857404 --- /dev/null +++ b/tools/binman/etype/pre_load.py @@ -0,0 +1,165 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2022 Softathome +# Written by Philippe Reynes +# +# Entry-type for the global header +# + +import struct +from dtoc import fdt_util +from patman import tools + +from binman.entry import Entry +from binman.etype.collection import Entry_collection +from binman.entry import EntryArg + +from Cryptodome.Hash import SHA256, SHA384, SHA512 +from Cryptodome.PublicKey import RSA +from Cryptodome.Signature import pkcs1_15 +from Cryptodome.Signature import pss + +PRE_LOAD_MAGIC = b'UBSH' + +RSAS = { +'rsa1024': 1024 / 8, +'rsa2048': 2048 / 8, +'rsa4096': 4096 / 8 +} + +SHAS = { +'sha256': SHA256, +'sha384': SHA384, +'sha512': SHA512 +} + +class Entry_pre_load(Entry_collection): +"""Pre load image header + +Properties / Entry arguments: +- key-path: Path of the directory that store key (provided by the environment variable KEY_PATH) +- content: List of phandles to entries to sign +- algo-name: Hash and signature algo to use for the signature +- padding-name: Name of the padding (pkcs-1.5 or pss) +- key-name: Filename of the private key to sign +- header-size: Total size of the header +- version: Version of the header + +This entry create a pre-load header that contain a global +image signature. + +For example, this creates an image with a pre-load header and a binary:: + +binman { + image2 { + filename = "sandbox.bin"; + + pre-load { + content = <&image>; + algo-name = "sha256,rsa2048"; + padding-name = "pss"; + key-name = "private.pem"; + header-size = <4096>; + version = <1>; + }; + + image: blob-ext { + filename = "sandbox.itb"; + }; + }; +}; +""" + +def __init__(self, section, etype, node): +super().__init__(section, etype, node) +self.algo_name = fdt_util.GetString(self._node, 'algo-name') +self.padding_name = fdt_util.GetString(self._node, 'padding-name') +self.key_name = fdt_util.GetString(self._node, 'key-name') +self.header_size = fdt_util.GetInt(self._node, 'header-size') +self.version = fdt_util.GetInt(self._node, 'version') + +def _CreateHeader(self): +"""Create a pre load header""" +hash_name, sign_name = self.algo_name.split(',') +padding_name=self.padding_name +key_path, = self.GetEntryArgsOrProps([EntryArg('key-path', str)]) +if key_path is None or key_path == "": +key_name = self.key_name +else: +key_name = key_path + "/" + self.key_name + +# Check hash and signature name/type +if hash_name not in SHAS: +raise ValueError(hash_name + " is not supported") +if sign_name not in RSAS: +raise ValueError(sign_name + "is not supported") + +# Read the key +with open(key_name, 'rb') as pem: +key = RSA.import_key(pem.read()) + +# Check if
[PATCH v6 13/16] configs: sandbox_defconfig: enable stage pre-load in bootm
Enable the support of stage pre-load in bootm. For the moment, this stage allow to verify the signature of the full image with a header. Signed-off-by: Philippe Reynes --- configs/sandbox_defconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 7ebeb89264..46bf18bc98 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -27,6 +27,8 @@ CONFIG_AUTOBOOT_SHA256_FALLBACK=y CONFIG_AUTOBOOT_NEVER_TIMEOUT=y CONFIG_AUTOBOOT_STOP_STR_ENABLE=y CONFIG_AUTOBOOT_STOP_STR_CRYPT="$5$rounds=64$HrpE65IkB8CM5nCL$BKT3QdF98Bo8fJpTr9tjZLZQyzqPASBY20xuK5Rent9" +CONFIG_IMAGE_PRE_LOAD=y +CONFIG_IMAGE_PRE_LOAD_SIG=y CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_PRE_CONSOLE_BUFFER=y @@ -37,6 +39,7 @@ CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y +CONFIG_CMD_BOOTM_PRE_LOAD=y CONFIG_CMD_BOOTZ=y CONFIG_CMD_BOOTEFI_HELLO=y CONFIG_CMD_ABOOTIMG=y -- 2.17.1
[PATCH v6 14/16] test: py: vboot: add test for global image signature
Adds test units for the pre-load header signature. Signed-off-by: Philippe Reynes --- test/py/tests/test_vboot.py | 125 +++--- test/py/tests/vboot/sandbox-binman-pss.dts| 25 test/py/tests/vboot/sandbox-binman.dts| 24 .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 test/py/tests/vboot/sandbox-u-boot-global.dts | 27 test/py/tests/vboot/simple-images.its | 36 + 6 files changed, 249 insertions(+), 16 deletions(-) create mode 100644 test/py/tests/vboot/sandbox-binman-pss.dts create mode 100644 test/py/tests/vboot/sandbox-binman.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-pss.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global.dts create mode 100644 test/py/tests/vboot/simple-images.its diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py index ac8ed9f114..a4a2bb2955 100644 --- a/test/py/tests/test_vboot.py +++ b/test/py/tests/test_vboot.py @@ -35,19 +35,21 @@ import vboot_evil # Only run the full suite on a few combinations, since it doesn't add any more # test coverage. TESTDATA = [ -['sha1-basic', 'sha1', '', None, False, True, False], -['sha1-pad', 'sha1', '', '-E -p 0x1', False, False, False], -['sha1-pss', 'sha1', '-pss', None, False, False, False], -['sha1-pss-pad', 'sha1', '-pss', '-E -p 0x1', False, False, False], -['sha256-basic', 'sha256', '', None, False, False, False], -['sha256-pad', 'sha256', '', '-E -p 0x1', False, False, False], -['sha256-pss', 'sha256', '-pss', None, False, False, False], -['sha256-pss-pad', 'sha256', '-pss', '-E -p 0x1', False, False, False], -['sha256-pss-required', 'sha256', '-pss', None, True, False, False], -['sha256-pss-pad-required', 'sha256', '-pss', '-E -p 0x1', True, True, False], -['sha384-basic', 'sha384', '', None, False, False, False], -['sha384-pad', 'sha384', '', '-E -p 0x1', False, False, False], -['algo-arg', 'algo-arg', '', '-o sha256,rsa2048', False, False, True], +['sha1-basic', 'sha1', '', None, False, True, False, False], +['sha1-pad', 'sha1', '', '-E -p 0x1', False, False, False, False], +['sha1-pss', 'sha1', '-pss', None, False, False, False, False], +['sha1-pss-pad', 'sha1', '-pss', '-E -p 0x1', False, False, False, False], +['sha256-basic', 'sha256', '', None, False, False, False, False], +['sha256-pad', 'sha256', '', '-E -p 0x1', False, False, False, False], +['sha256-pss', 'sha256', '-pss', None, False, False, False, False], +['sha256-pss-pad', 'sha256', '-pss', '-E -p 0x1', False, False, False, False], +['sha256-pss-required', 'sha256', '-pss', None, True, False, False, False], +['sha256-pss-pad-required', 'sha256', '-pss', '-E -p 0x1', True, True, False, False], +['sha384-basic', 'sha384', '', None, False, False, False, False], +['sha384-pad', 'sha384', '', '-E -p 0x1', False, False, False, False], +['algo-arg', 'algo-arg', '', '-o sha256,rsa2048', False, False, True, False], +['sha256-global-sign', 'sha256', '', '', False, False, False, True], +['sha256-global-sign-pss', 'sha256', '-pss', '', False, False, False, True], ] @pytest.mark.boardspec('sandbox') @@ -56,10 +58,10 @@ TESTDATA = [ @pytest.mark.requiredtool('fdtget') @pytest.mark.requiredtool('fdtput') @pytest.mark.requiredtool('openssl') -@pytest.mark.parametrize("name,sha_algo,padding,sign_options,required,full_test,algo_arg", +@pytest.mark.parametrize("name,sha_algo,padding,sign_options,required,full_test,algo_arg,global_sign", TESTDATA) def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required, - full_test, algo_arg): + full_test, algo_arg, global_sign): """Test verified boot signing with mkimage and verificat
[PATCH v6 15/16] cmd: verify: initial import
Add the command verify that check the signature of an image with the pre-load header. If the check succeed, the u-boot env variable 'loadaddr_verified' is set to the address of the image (without the header). It allows to run such commands: tftp script.img && verify $loadaddr && source $loadaddr_verified Signed-off-by: Philippe Reynes --- cmd/Kconfig | 7 +++ cmd/Makefile | 1 + cmd/verify.c | 53 3 files changed, 61 insertions(+) create mode 100644 cmd/verify.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 87aa3fb11a..0460d5c3a0 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -428,6 +428,13 @@ config CMD_THOR_DOWNLOAD There is no documentation about this within the U-Boot source code but you should be able to find something on the interwebs. +config CMD_VERIFY + bool "verify the global signature" +depends on CMD_BOOTM_PRE_LOAD + help + Verify the signature provided in a pre-load header of + a full image. + config CMD_ZBOOT bool "zboot - x86 boot command" help diff --git a/cmd/Makefile b/cmd/Makefile index 166c652d98..80e054e806 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -177,6 +177,7 @@ obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o obj-$(CONFIG_CMD_XIMG) += ximg.o obj-$(CONFIG_CMD_YAFFS2) += yaffs2.o obj-$(CONFIG_CMD_SPL) += spl.o +obj-$(CONFIG_CMD_VERIFY) += verify.o obj-$(CONFIG_CMD_W1) += w1.o obj-$(CONFIG_CMD_ZIP) += zip.o obj-$(CONFIG_CMD_ZFS) += zfs.o diff --git a/cmd/verify.c b/cmd/verify.c new file mode 100644 index 00..4d055e0790 --- /dev/null +++ b/cmd/verify.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Philippe Reynes + */ + +#include +#include +#include +#include + +static ulong verify_get_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = simple_strtoul(argv[0], NULL, 16); + else + addr = image_load_addr; + + return addr; +} + +static int do_verify(struct cmd_tbl *cmdtp, int flag, int argc, +char *const argv[]) +{ + ulong addr = verify_get_addr(argc, argv); + int ret = 0; + + argc--; argv++; + + addr = verify_get_addr(argc, argv); + + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) { + ret = image_pre_load(addr); + + if (ret) { + ret = CMD_RET_FAILURE; + goto out; + } + + env_set_hex("loadaddr_verified", addr + image_load_offset); + } + + out: + return ret; +} + +U_BOOT_CMD(verify, 2, 1, do_verify, + "verify the global signature provided in the pre-load header,\n" + "\tif the check succeed, the u-boot env variable loadaddr_verified\n" + "\tis set to the address of the image (without the header)", + "" +); -- 2.17.1
[PATCH v6 07/16] boot: image: add a stage pre-load
Add a stage pre-load that could check or modify an image. For the moment, only a header with a signature is supported. This header has the following format: - magic : 4 bytes - version : 4 bytes - header size : 4 bytes - image size : 4 bytes - offset image signature : 4 bytes - flags : 4 bytes - reserved0 : 4 bytes - reserved1 : 4 bytes - sha256 of the image signature : 32 bytes - signature of the first 64 bytes : n bytes - image signature : n bytes - padding : up to header size The stage uses a node /image/pre-load/sig to get some informations: - algo-name (mandatory) : name of the algo used to sign - padding-name : name of padding used to sign - signature-size : size of the signature (in the header) - mandatory : set to yes if this sig is mandatory - public-key (madatory) : value of the public key Before running the image, the stage pre-load checks the signature provided in the header. This is an initial support, later we could add the support of: - ciphering - uncompressing - ... Signed-off-by: Philippe Reynes --- boot/Kconfig | 55 ++ boot/Makefile | 1 + boot/image-pre-load.c | 416 ++ include/image.h | 14 ++ 4 files changed, 486 insertions(+) create mode 100644 boot/image-pre-load.c diff --git a/boot/Kconfig b/boot/Kconfig index b83a4e8400..cb5f48dcf9 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -993,6 +993,61 @@ config AUTOBOOT_MENU_SHOW endmenu +menu "Image support" + +config IMAGE_PRE_LOAD + bool "Image pre-load support" + help + Enable an image pre-load stage in the SPL. + This pre-load stage allows to do some manipulation + or check (for example signature check) on an image + before launching it. + +config SPL_IMAGE_PRE_LOAD + bool "Image pre-load support within SPL" + depends on SPL && IMAGE_PRE_LOAD + help + Enable an image pre-load stage in the SPL. + This pre-load stage allows to do some manipulation + or check (for example signature check) on an image + before launching it. + +config IMAGE_PRE_LOAD_SIG + bool "Image pre-load signature support" + depends on IMAGE_PRE_LOAD + select FIT_SIGNATURE + select RSA + select RSA_VERIFY_WITH_PKEY + help + Enable signature check support in the pre-load stage. + For this feature a very simple header is added before + the image with few fields: + - a magic + - the image size + - the signature + All other information (header size, type of signature, + ...) are provided in the node /image/pre-load/sig of + u-boot. + +config SPL_IMAGE_PRE_LOAD_SIG + bool "Image pre-load signature support witin SPL" + depends on SPL_IMAGE_PRE_LOAD && IMAGE_PRE_LOAD_SIG + select SPL_FIT_SIGNATURE + select SPL_RSA + select SPL_RSA_VERIFY_WITH_PKEY + help + Enable signature check support in the pre-load stage in the SPL. + For this feature a very simple header is added before + the image with few fields: + - a magic + - the image size + - the signature + All other information (header size, type of signature, + ...) are provided in the node /image/pre-load/sig of + u-boot. + +endmenu + config USE_BOOTARGS bool "Enable boot arguments" help diff --git a/boot/Makefile b/boot/Makefile index 2938c3f145..59752c65ca 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o +obj-$(CONFIG_$(SPL_TPL_)IMAGE_PRE_LOAD) += image-pre-load.o obj-$(CONFIG_$(SPL_TPL_)IMAGE_SIGN_INFO) += image-sig.o obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += image-fit-sig.o obj-$(CONFIG_$(SPL_TPL_)FIT_CIPHER) += image-cipher.o diff --git a/boot/image-pre-load.c b/boot/image-pre-load.c new file mode 100644 index 00..78d89069a9 --- /dev/null +++ b/boot/image-pre-load.c @@ -0,0 +1,416 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Philippe Reynes + */ + +#include +#include +DECLARE_GLOBAL_DATA_PTR; +#include +#include + +#include + +#define IMAGE_PRE_LOAD_SIG_MAGIC 0x55425348 +#define IMAGE_PRE_LOAD_SIG_OFFSET_MAGIC0 +#define IMAGE_PRE_LOAD_SIG_OFFSET_IMG_LEN 4 +#define IMAGE_PRE_LOAD_SIG_OFFSET_SIG 8 + +#define IMAGE_PRE_LOAD_PATH"/image/pre-load/sig" +#define IMAGE_PRE_LOAD_PROP_ALGO_NAME "algo-name" +#define IMAGE_PRE_LOAD_PROP_PADDING_NAME "padding-name" +#define IMAGE_PRE_LOAD_PROP_SIG_SIZE "signature-size" +#define IMAGE_PRE_LOAD_PROP_PUBLIC_
[PATCH v6 11/16] Makefile: provide sah-key to binman
Set the variable key-path with the shell variable KEY_PATH that contain the keys path (used for signature). This variable key-path is provided to binman. Signed-off-by: Philippe Reynes --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 697cc51d67..c6da6cdba0 100644 --- a/Makefile +++ b/Makefile @@ -1335,6 +1335,7 @@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \ -a tpl-bss-pad=$(if $(CONFIG_TPL_SEPARATE_BSS),,1) \ -a spl-dtb=$(CONFIG_SPL_OF_REAL) \ -a tpl-dtb=$(CONFIG_TPL_OF_REAL) \ + -a key-path=${KEY_PATH} \ $(BINMAN_$(@F)) OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex -- 2.17.1
[PATCH v6 09/16] common: spl: fit_ram: allow to use image pre load
Add the support of image pre load in spl or tpl when loading an image from ram. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- common/spl/spl_ram.c | 21 - 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/common/spl/spl_ram.c b/common/spl/spl_ram.c index 3f7f7accc1..8296459257 100644 --- a/common/spl/spl_ram.c +++ b/common/spl/spl_ram.c @@ -24,9 +24,17 @@ static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, ulong count, void *buf) { + ulong addr; + debug("%s: sector %lx, count %lx, buf %lx\n", __func__, sector, count, (ulong)buf); - memcpy(buf, (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + sector), count); + + addr = (ulong)CONFIG_SPL_LOAD_FIT_ADDRESS + sector; + if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) + addr += image_load_offset; + + memcpy(buf, (void *)addr, count); + return count; } @@ -37,6 +45,17 @@ static int spl_ram_load_image(struct spl_image_info *spl_image, header = (struct image_header *)CONFIG_SPL_LOAD_FIT_ADDRESS; + if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) { + unsigned long addr = (unsigned long)header; + int ret = image_pre_load(addr); + + if (ret) + return ret; + + addr += image_load_offset; + header = (struct image_header *)addr; + } + #if CONFIG_IS_ENABLED(DFU) if (bootdev->boot_device == BOOT_DEVICE_DFU) spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0"); -- 2.17.1
[PATCH v6 03/16] lib: Kconfig: enhance the help of OID_REGISTRY
Enhance the help for the config OID_REGISTRY. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Kconfig | 4 1 file changed, 4 insertions(+) diff --git a/lib/Kconfig b/lib/Kconfig index b0e5d60b3d..e749826f22 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -812,6 +812,10 @@ config ASN1_DECODER config OID_REGISTRY bool help + In computing, object identifiers or OIDs are an identifier mechanism + standardized by the International Telecommunication Union (ITU) and + ISO/IEC for naming any object, concept, or "thing" with a globally + unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). Enable fast lookup object identifier registry. config SMBIOS_PARSER -- 2.17.1
[PATCH v6 02/16] lib: Kconfig: enhance help for ASN1
Enhance the help for configs ASN1_COMPILER and ASN1_decoder. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Kconfig | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Kconfig b/lib/Kconfig index 3c6fa99b1a..b0e5d60b3d 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -791,11 +791,23 @@ endmenu config ASN1_COMPILER bool + help + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 compiler. config ASN1_DECODER bool help - Enable asn1 decoder library. + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 decoder. config OID_REGISTRY bool -- 2.17.1
[PATCH v6 10/16] mkimage: add public key for image pre-load stage
This commit enhances mkimage to update the node /image/pre-load/sig with the public key. Signed-off-by: Philippe Reynes --- include/image.h| 15 ++ tools/fit_image.c | 3 ++ tools/image-host.c | 114 + 3 files changed, 132 insertions(+) diff --git a/include/image.h b/include/image.h index 496b7af3f3..498eb7f2e3 100644 --- a/include/image.h +++ b/include/image.h @@ -1019,6 +1019,21 @@ int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, int fit_set_timestamp(void *fit, int noffset, time_t timestamp); +/** + * fit_pre_load_data() - add public key to fdt blob + * + * Adds public key to the node pre load. + * + * @keydir:Directory containing keys + * @keydest: FDT blob to write public key + * @fit: Pointer to the FIT format image header + * + * returns: + * 0, on success + * < 0, on failure + */ +int fit_pre_load_data(const char *keydir, void *keydest, void *fit); + int fit_cipher_data(const char *keydir, void *keydest, void *fit, const char *comment, int require_keys, const char *engine_id, const char *cmdname); diff --git a/tools/fit_image.c b/tools/fit_image.c index 15f7c82d61..1884a2eb0b 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -59,6 +59,9 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, ret = fit_set_timestamp(ptr, 0, time); } + if (!ret) + ret = fit_pre_load_data(params->keydir, dest_blob, ptr); + if (!ret) { ret = fit_cipher_data(params->keydir, dest_blob, ptr, params->comment, diff --git a/tools/image-host.c b/tools/image-host.c index eaeb76545c..ab6f756cf1 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -14,6 +14,11 @@ #include #include +#include +#include + +#define IMAGE_PRE_LOAD_PATH "/image/pre-load/sig" + /** * fit_set_hash_value - set hash value in requested has node * @fit: pointer to the FIT format image header @@ -,6 +1116,115 @@ static int fit_config_add_verification_data(const char *keydir, return 0; } +/* + * 0) open file (open) + * 1) read certificate (PEM_read_X509) + * 2) get public key (X509_get_pubkey) + * 3) provide der format (d2i_RSAPublicKey) + */ +static int read_pub_key(const char *keydir, const void *name, + unsigned char **pubkey, int *pubkey_len) +{ + char path[1024]; + EVP_PKEY *key = NULL; + X509 *cert; + FILE *f; + int ret; + + memset(path, 0, 1024); + snprintf(path, sizeof(path), "%s/%s.crt", keydir, (char *)name); + + /* Open certificate file */ + f = fopen(path, "r"); + if (!f) { + fprintf(stderr, "Couldn't open RSA certificate: '%s': %s\n", + path, strerror(errno)); + return -EACCES; + } + + /* Read the certificate */ + cert = NULL; + if (!PEM_read_X509(f, &cert, NULL, NULL)) { + printf("Couldn't read certificate"); + ret = -EINVAL; + goto err_cert; + } + + /* Get the public key from the certificate. */ + key = X509_get_pubkey(cert); + if (!key) { + printf("Couldn't read public key\n"); + ret = -EINVAL; + goto err_pubkey; + } + + /* Get DER form */ + ret = i2d_PublicKey(key, pubkey); + if (ret < 0) { + printf("Couldn't get DER form\n"); + ret = -EINVAL; + goto err_pubkey; + } + + *pubkey_len = ret; + ret = 0; + +err_pubkey: + X509_free(cert); +err_cert: + fclose(f); + return ret; +} + +int fit_pre_load_data(const char *keydir, void *keydest, void *fit) +{ + int pre_load_noffset; + const void *algo_name; + const void *key_name; + unsigned char *pubkey = NULL; + int ret, pubkey_len; + + if (!keydir || !keydest || !fit) + return 0; + + /* Search node pre-load sig */ + pre_load_noffset = fdt_path_offset(keydest, IMAGE_PRE_LOAD_PATH); + if (pre_load_noffset < 0) { + ret = 0; + goto out; + } + + algo_name = fdt_getprop(keydest, pre_load_noffset, "algo-name", NULL); + key_name = fdt_getprop(keydest, pre_load_noffset, "key-name", NULL); + + /* Check that all mandatory properties are present */ + if (!algo_name || !key_name) { + if (!algo_name) + printf("The property algo-name is missing in the node %s\n", + IMAGE_PRE_LOAD_PATH); + if (!key_name) + printf("The p
[PATCH v6 06/16] lib: rsa: allow rsa verify with pkey in SPL
This commit adds the option SPL_RSA_VERIFY_WITH_PKEY. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/rsa/Kconfig | 19 +++ 1 file changed, 19 insertions(+) diff --git a/lib/rsa/Kconfig b/lib/rsa/Kconfig index be9775bcce..b773f17c26 100644 --- a/lib/rsa/Kconfig +++ b/lib/rsa/Kconfig @@ -47,6 +47,25 @@ config RSA_VERIFY_WITH_PKEY directly specified in image_sign_info, where all the necessary key properties will be calculated on the fly in verification code. +config SPL_RSA_VERIFY_WITH_PKEY + bool "Execute RSA verification without key parameters from FDT within SPL" + depends on SPL + select SPL_RSA_VERIFY + select SPL_ASYMMETRIC_KEY_TYPE + select SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select SPL_RSA_PUBLIC_KEY_PARSER + help + The standard RSA-signature verification code (FIT_SIGNATURE) uses + pre-calculated key properties, that are stored in fdt blob, in + decrypting a signature. + This does not suit the use case where there is no way defined to + provide such additional key properties in standardized form, + particularly UEFI secure boot. + This options enables RSA signature verification with a public key + directly specified in image_sign_info, where all the necessary + key properties will be calculated on the fly in verification code + in the SPL. + config RSA_SOFTWARE_EXP bool "Enable driver for RSA Modular Exponentiation in software" depends on DM -- 2.17.1
[PATCH v6 04/16] lib: allow to build asn1 decoder and oid registry in SPL
This commit adds the options: - SPL_ASN1_DECODER - SPL_OID_REGISTRY Signed-off-by: Philippe Reynes --- lib/Kconfig | 19 +++ lib/Makefile | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Kconfig b/lib/Kconfig index e749826f22..effe735365 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -809,6 +809,16 @@ config ASN1_DECODER and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). This option enables the support of the asn1 decoder. +config SPL_ASN1_DECODER + bool + help + ASN.1 (Abstract Syntax Notation One) is a standard interface + description language for defining data structures that can be + serialized and deserialized in a cross-platform way. It is + broadly used in telecommunications and computer networking, + and especially in cryptography (https://en.wikipedia.org/wiki/ASN.1). + This option enables the support of the asn1 decoder in the SPL. + config OID_REGISTRY bool help @@ -818,6 +828,15 @@ config OID_REGISTRY unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). Enable fast lookup object identifier registry. +config SPL_OID_REGISTRY + bool + help + In computing, object identifiers or OIDs are an identifier mechanism + standardized by the International Telecommunication Union (ITU) and + ISO/IEC for naming any object, concept, or "thing" with a globally + unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). + Enable fast lookup object identifier registry in the SPL. + config SMBIOS_PARSER bool "SMBIOS parser" help diff --git a/lib/Makefile b/lib/Makefile index 11b03d1cbe..13e5d8f7a6 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,7 +17,6 @@ obj-$(CONFIG_OF_LIVE) += of_live.o obj-$(CONFIG_CMD_DHRYSTONE) += dhry/ obj-$(CONFIG_ARCH_AT91) += at91/ obj-$(CONFIG_OPTEE_LIB) += optee/ -obj-$(CONFIG_ASN1_DECODER) += asn1_decoder.o obj-y += crypto/ obj-$(CONFIG_AES) += aes.o @@ -74,6 +73,7 @@ obj-$(CONFIG_SHA1) += sha1.o obj-$(CONFIG_SHA256) += sha256.o obj-$(CONFIG_SHA512) += sha512.o obj-$(CONFIG_CRYPT_PW) += crypt/ +obj-$(CONFIG_$(SPL_)ASN1_DECODER) += asn1_decoder.o obj-$(CONFIG_$(SPL_)ZLIB) += zlib/ obj-$(CONFIG_$(SPL_)ZSTD) += zstd/ @@ -135,9 +135,9 @@ obj-$(CONFIG_$(SPL_TPL_)STRTO) += strto.o else # Main U-Boot always uses the full printf support obj-y += vsprintf.o strto.o -obj-$(CONFIG_OID_REGISTRY) += oid_registry.o obj-$(CONFIG_SSCANF) += sscanf.o endif +obj-$(CONFIG_$(SPL_)OID_REGISTRY) += oid_registry.o obj-y += abuf.o obj-y += date.o -- 2.17.1
[PATCH v6 05/16] lib: crypto: allow to build crypyo in SPL
This commit adds the options: - SPL_ASYMMETRIC_KEY_TYPE - SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE - SPL_RSA_PUBLIC_KEY_PARSER Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- lib/Makefile| 3 ++- lib/crypto/Kconfig | 29 + lib/crypto/Makefile | 19 +-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 13e5d8f7a6..13fe5fb7a4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,7 +17,6 @@ obj-$(CONFIG_OF_LIVE) += of_live.o obj-$(CONFIG_CMD_DHRYSTONE) += dhry/ obj-$(CONFIG_ARCH_AT91) += at91/ obj-$(CONFIG_OPTEE_LIB) += optee/ -obj-y += crypto/ obj-$(CONFIG_AES) += aes.o obj-$(CONFIG_AES) += aes/ @@ -63,6 +62,8 @@ obj-$(CONFIG_TPM_V1) += tpm-v1.o obj-$(CONFIG_TPM_V2) += tpm-v2.o endif +obj-y += crypto/ + obj-$(CONFIG_$(SPL_TPL_)GENERATE_ACPI_TABLE) += acpi/ obj-$(CONFIG_$(SPL_)MD5) += md5.o obj-$(CONFIG_ECDSA) += ecdsa/ diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig index 6369bafac0..509bc28311 100644 --- a/lib/crypto/Kconfig +++ b/lib/crypto/Kconfig @@ -8,6 +8,15 @@ menuconfig ASYMMETRIC_KEY_TYPE if ASYMMETRIC_KEY_TYPE +config SPL_ASYMMETRIC_KEY_TYPE + bool "Asymmetric (public-key cryptographic) key Support within SPL" + depends on SPL + help + This option provides support for a key type that holds the data for + the asymmetric keys used for public key cryptographic operations such + as encryption, decryption, signature generation and signature + verification in the SPL. + config ASYMMETRIC_PUBLIC_KEY_SUBTYPE bool "Asymmetric public-key crypto algorithm subtype" help @@ -16,6 +25,15 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE appropriate hash algorithms (such as SHA-1) must be available. ENOPKG will be reported if the requisite algorithm is unavailable. +config SPL_ASYMMETRIC_PUBLIC_KEY_SUBTYPE + bool "Asymmetric public-key crypto algorithm subtype within SPL" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + help + This option provides support for asymmetric public key type handling in the SPL. + If signature generation and/or verification are to be used, + appropriate hash algorithms (such as SHA-1) must be available. + ENOPKG will be reported if the requisite algorithm is unavailable. + config RSA_PUBLIC_KEY_PARSER bool "RSA public key parser" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE @@ -27,6 +45,17 @@ config RSA_PUBLIC_KEY_PARSER public key data and provides the ability to instantiate a public key. +config SPL_RSA_PUBLIC_KEY_PARSER + bool "RSA public key parser within SPL" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select SPL_ASN1_DECODER + select ASN1_COMPILER + select SPL_OID_REGISTRY + help + This option provides support for parsing a blob containing RSA + public key data and provides the ability to instantiate a public + key in the SPL. + config X509_CERTIFICATE_PARSER bool "X.509 certificate parser" depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index f3a414525d..6792b1d4f0 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -3,27 +3,34 @@ # Makefile for asymmetric cryptographic keys # -obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o asymmetric_keys-y := asymmetric_type.o -obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o +obj-$(CONFIG_$(SPL_)ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o # # RSA public key parser # -obj-$(CONFIG_RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o +obj-$(CONFIG_$(SPL_)RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o rsa_public_key-y := \ rsapubkey.asn1.o \ rsa_helper.o $(obj)/rsapubkey.asn1.o: $(obj)/rsapubkey.asn1.c $(obj)/rsapubkey.asn1.h +ifdef CONFIG_SPL_BUILD +CFLAGS_rsapubkey.asn1.o += -I$(obj) +endif + $(obj)/rsa_helper.o: $(obj)/rsapubkey.asn1.h +ifdef CONFIG_SPL_BUILD +CFLAGS_rsa_helper.o += -I$(obj) +endif # # X.509 Certificate handling # -obj-$(CONFIG_X509_CERTIFICATE_PARSER) += x509_key_parser.o +obj-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER) += x509_key_parser.o x509_key_parser-y := \ x509.asn1.o \ x509_akid.asn1.o \ @@ -40,11 +47,11 @@ $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h # # PKCS#7 message handling # -obj-$(CONFIG_PKCS7_MESSAGE_PARSER) += pkcs7_message.o +obj-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER) += pkcs7_message.o pkcs7_message-y := \ pkcs7.asn1.o \ pkcs7_parser.o -obj-$(CONFIG_PKCS7_VERIFY) += pkcs7_verify.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 -- 2.17.1
[PATCH v6 08/16] cmd: bootm: add a stage pre-load
Add a stage pre-load to the command bootm. Right now, this stage may be used to read a header and check the signature of the full image. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- boot/bootm.c| 33 + cmd/Kconfig | 10 ++ cmd/bootm.c | 2 +- include/image.h | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/boot/bootm.c b/boot/bootm.c index 00c00aef84..714406ab66 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -87,6 +87,33 @@ static int bootm_start(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } +static ulong bootm_data_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = simple_strtoul(argv[0], NULL, 16); + else + addr = image_load_addr; + + return addr; +} + +static int bootm_pre_load(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong data_addr = bootm_data_addr(argc, argv); + int ret = 0; + + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) + ret = image_pre_load(data_addr); + + if (ret) + ret = CMD_RET_FAILURE; + + return ret; +} + static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -677,6 +704,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, if (states & BOOTM_STATE_START) ret = bootm_start(cmdtp, flag, argc, argv); + if (!ret && (states & BOOTM_STATE_PRE_LOAD)) + ret = bootm_pre_load(cmdtp, flag, argc, argv); + if (!ret && (states & BOOTM_STATE_FINDOS)) ret = bootm_find_os(cmdtp, flag, argc, argv); @@ -866,6 +896,9 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, &fit_uname_config, &fit_uname_kernel); + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) + img_addr += image_load_offset; + bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC); /* check image type, for FIT images get FIT kernel node */ diff --git a/cmd/Kconfig b/cmd/Kconfig index 5e25e45fd2..87aa3fb11a 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -194,6 +194,16 @@ config CMD_BOOTM help Boot an application image from the memory. +config CMD_BOOTM_PRE_LOAD + bool "enable pre-load on bootm" + depends on CMD_BOOTM + depends on IMAGE_PRE_LOAD + default n + help + Enable support of stage pre-load for the bootm command. +This stage allow to check or modify the image provided +to the bootm command. + config BOOTM_EFI bool "Support booting UEFI FIT images" depends on CMD_BOOTEFI && CMD_BOOTM && FIT diff --git a/cmd/bootm.c b/cmd/bootm.c index e8b7066888..c5de339fba 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -126,7 +126,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | - BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | + BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH BOOTM_STATE_RAMDISK | diff --git a/include/image.h b/include/image.h index fbcf70f5e4..496b7af3f3 100644 --- a/include/image.h +++ b/include/image.h @@ -351,6 +351,7 @@ typedef struct bootm_headers { #defineBOOTM_STATE_OS_PREP (0x0100) #defineBOOTM_STATE_OS_FAKE_GO (0x0200)/* 'Almost' run the OS */ #defineBOOTM_STATE_OS_GO (0x0400) +#defineBOOTM_STATE_PRE_LOAD0x0800 int state; #if defined(CONFIG_LMB) && !defined(USE_HOSTCC) -- 2.17.1
[PATCH v6 00/16] image: add a stage pre-load
This serie adds a stage pre-load before launching an image. This stage is used to read a header before the image and this header contains the signature of the full image. So u-boot may check the full image before using any data of the image. The support of this header is added to binman, and a command verify checks the signature of a blob and set the u-boot env variable "loadaddr_verified" to the beginning of the "real" image. The support of this header is only added to binman, but it may also be added to mkimage. Changelog: v6: - set values in big endian in the pre-load header - binman: etypes: pre-load: read image from other entry instead of directly from a file - binman: etypes: pre-load: add test unit - lib: Makefile: no longer add -I$(obj) for SPL It was to fix build when oid is built on spl but not on u-boot. It is not longer possible. v5: - replace config SANDBOX_BINMAN by an imply v4: - add a config SANDBOX_BIN - enhance help for asn1 and oid - change the format of the pre-load header - add the support of pre-load header in binman - add py test for pre-load header - add a command verify v3: - move image-pre-load.c to /boot - update mkimage to add public key in u-boot device tree - add script gen_pre_load_header.sh v2: - move the code to image-pre-load - add support of stage pre-load for spl - add support of stage pre-load on spl_ram Philippe Reynes (16): arch: Kconfig: imply BINMAN for SANDBOX lib: Kconfig: enhance help for ASN1 lib: Kconfig: enhance the help of OID_REGISTRY lib: allow to build asn1 decoder and oid registry in SPL lib: crypto: allow to build crypyo in SPL lib: rsa: allow rsa verify with pkey in SPL boot: image: add a stage pre-load cmd: bootm: add a stage pre-load common: spl: fit_ram: allow to use image pre load mkimage: add public key for image pre-load stage Makefile: provide sah-key to binman tools: binman: add support for pre-load header configs: sandbox_defconfig: enable stage pre-load in bootm test: py: vboot: add test for global image signature cmd: verify: initial import configs: sandbox_defconfig: enable config CMD_VERIFY Makefile | 1 + arch/Kconfig | 1 + arch/sandbox/dts/sandbox.dtsi | 3 + arch/sandbox/dts/test.dts | 3 + boot/Kconfig | 55 +++ boot/Makefile | 1 + boot/bootm.c | 33 ++ boot/image-pre-load.c | 416 ++ cmd/Kconfig | 17 + cmd/Makefile | 1 + cmd/bootm.c | 2 +- cmd/verify.c | 53 +++ common/spl/spl_ram.c | 21 +- configs/sandbox_defconfig | 4 + include/image.h | 30 ++ lib/Kconfig | 37 +- lib/Makefile | 7 +- lib/crypto/Kconfig| 29 ++ lib/crypto/Makefile | 19 +- lib/rsa/Kconfig | 19 + test/py/tests/test_fit.py | 3 + test/py/tests/test_vboot.py | 125 +- test/py/tests/vboot/sandbox-binman-pss.dts| 25 ++ test/py/tests/vboot/sandbox-binman.dts| 24 + .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 ++ test/py/tests/vboot/sandbox-u-boot-global.dts | 27 ++ test/py/tests/vboot/sandbox-u-boot.dts| 3 + test/py/tests/vboot/simple-images.its | 36 ++ tools/binman/etype/pre_load.py| 165 +++ tools/binman/ftest.py | 45 ++ tools/binman/test/225_dev.key | 28 ++ tools/binman/test/225_pre_load.dts| 22 + tools/binman/test/226_pre_load_pkcs.dts | 23 + tools/binman/test/227_pre_load_pss.dts| 23 + .../test/228_pre_load_invalid_padding.dts | 23 + .../binman/test/229_pre_load_invalid_sha.dts | 23 + .../binman/test/230_pre_load_invalid_algo.dts | 23 + .../binman/test/231_pre_load_invalid_key.dts | 23 + tools/fit_image.c | 3 + tools/image-host.c| 114 + 40 files changed, 1510 insertions(+), 28 deletions(-) create mode 100644 boot/image-pre-load.c create mode 100644 cmd/verify.c create mode 100644 test/py/tests/vboot/sandbox-binman-pss.dts create mode 100644 test/py/tests/vboot/sandbox-binman.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-pss.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global.dts create mode 100644 test/py/tests/vboot/simple-images.its create mode 100644 tools/binman/etype/pre_load.py create mode 100644 tools/binman/test/225_dev.key create mode
[PATCH v6 01/16] arch: Kconfig: imply BINMAN for SANDBOX
To be able to use the tool binman on sandbox, the config SANDBOX should imply BINMAN. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- arch/Kconfig | 1 + arch/sandbox/dts/sandbox.dtsi | 3 +++ arch/sandbox/dts/test.dts | 3 +++ test/py/tests/test_fit.py | 3 +++ test/py/tests/vboot/sandbox-u-boot.dts | 3 +++ 5 files changed, 13 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index e6191446a3..35624377ca 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -203,6 +203,7 @@ config SANDBOX imply KEYBOARD imply PHYSMEM imply GENERATE_ACPI_TABLE + imply BINMAN config SH bool "SuperH architecture" diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 66b813faad..826db26fc2 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -7,6 +7,9 @@ #define USB_CLASS_HUB 9 / { + binman { + }; + chosen { stdout-path = "/serial"; }; diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 48ca3e1e47..c11ad8cb9f 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -61,6 +61,9 @@ osd0 = "/osd"; }; + binman { + }; + config { testing-bool; testing-int = <123>; diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py index 6d5b43c3ba..5856960be2 100755 --- a/test/py/tests/test_fit.py +++ b/test/py/tests/test_fit.py @@ -89,6 +89,9 @@ base_fdt = ''' model = "Sandbox Verified Boot Test"; compatible = "sandbox"; + binman { + }; + reset@0 { compatible = "sandbox,reset"; reg = <0>; diff --git a/test/py/tests/vboot/sandbox-u-boot.dts b/test/py/tests/vboot/sandbox-u-boot.dts index 63f8f401de..5809c62fc1 100644 --- a/test/py/tests/vboot/sandbox-u-boot.dts +++ b/test/py/tests/vboot/sandbox-u-boot.dts @@ -4,6 +4,9 @@ model = "Sandbox Verified Boot Test"; compatible = "sandbox"; + binman { + }; + reset@0 { compatible = "sandbox,reset"; }; -- 2.17.1
[PATCH v3] scripts: Makefile.lib: generate dsdt_generated.c instead of dsdt.c
There is a conflict between the static file lib/acpi/dsdt.c and the file dsdt.c generated dynamicaly by scripts/Makefile.lib. When a mrproper is done, the static file dsdt.c is removed. If a build with acpi enabled is launched after, the following error is raised: CC lib/acpi/acpi_table.o make[2]: *** No rule to make target 'lib/acpi/dsdt.asl', needed by 'lib/acpi/dsdt.c'. Stop. scripts/Makefile.build:394: recipe for target 'lib/acpi' failed To avoid such error, the generated file is named dsdt_generated.c instead of dstdt.c. Signed-off-by: Philippe Reynes --- Changelog: v3: - update comments in file scripts/Makefile.lib - add changelog v2 - change generated file name (dsdt_generated.c) instead of changing the name of the static file - NOTE : forgot to call it v2 and forgot changelog Makefile| 3 ++- board/advantech/som-db5800-som-6867/Makefile| 2 +- board/congatec/conga-qeval20-qa3-e3845/Makefile | 2 +- board/dfi/dfi-bt700/Makefile| 2 +- board/google/chromebook_coral/Makefile | 2 +- board/intel/bayleybay/Makefile | 2 +- board/intel/edison/Makefile | 2 +- board/intel/galileo/Makefile| 2 +- board/intel/minnowmax/Makefile | 2 +- scripts/Makefile.lib| 8 10 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4b152249ca..94bc48f00c 100644 --- a/Makefile +++ b/Makefile @@ -2226,7 +2226,8 @@ clean: $(clean-dirs) -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ -o -name modules.builtin -o -name '.tmp_*.o.*' \ - -o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \ + -o -name 'dsdt_generated.aml' -o -name 'dsdt_generated.asl.tmp' \ + -o -name 'dsdt_generated.c' \ -o -name '*.efi' -o -name '*.gcno' -o -name '*.so' \) \ -type f -print | xargs rm -f diff --git a/board/advantech/som-db5800-som-6867/Makefile b/board/advantech/som-db5800-som-6867/Makefile index 7975547f41..95af6c4df7 100644 --- a/board/advantech/som-db5800-som-6867/Makefile +++ b/board/advantech/som-db5800-som-6867/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += som-db5800-som-6867.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/congatec/conga-qeval20-qa3-e3845/Makefile b/board/congatec/conga-qeval20-qa3-e3845/Makefile index 451a4fcd6c..215f5680dc 100644 --- a/board/congatec/conga-qeval20-qa3-e3845/Makefile +++ b/board/congatec/conga-qeval20-qa3-e3845/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += conga-qeval20-qa3.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/dfi/dfi-bt700/Makefile b/board/dfi/dfi-bt700/Makefile index 50d88f2954..1c4329a058 100644 --- a/board/dfi/dfi-bt700/Makefile +++ b/board/dfi/dfi-bt700/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += dfi-bt700.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/google/chromebook_coral/Makefile b/board/google/chromebook_coral/Makefile index f7a0ca6cc0..846558d777 100644 --- a/board/google/chromebook_coral/Makefile +++ b/board/google/chromebook_coral/Makefile @@ -3,4 +3,4 @@ # Copyright 2019 Google LLC obj-y += coral.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/intel/bayleybay/Makefile b/board/intel/bayleybay/Makefile index d19447184a..fa263b7bf5 100644 --- a/board/intel/bayleybay/Makefile +++ b/board/intel/bayleybay/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Bin Meng obj-y += bayleybay.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/intel/edison/Makefile b/board/intel/edison/Makefile index 1eaf7ca7f8..f7f70dfaa7 100644 --- a/board/intel/edison/Makefile +++ b/board/intel/edison/Makefile @@ -5,4 +5,4 @@ # obj-y += edison.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/intel/galileo/Makefile b/board/intel/galileo/Makefile index 4130bb0236..7d5f4df0f9 100644 --- a/board/intel/galileo/Makefile +++ b/board/intel/galileo/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Bin Meng obj-y += galileo.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/intel/minnowmax/Makefile b/board/intel/minnowmax/Makefile index d339b5ad0a..a20322a1a1 1
Re: [PATCH] scripts: Makefile.lib: generate dsdt_generated.c instead of dsdt.c
Hi Heinrich, Le 22/02/2022 à 10:40, Heinrich Schuchardt a écrit : On 2/22/22 10:16, Philippe Reynes wrote: There is a conflict between the static file lib/acpi/dsdt.c and the file dsdt.c generated dynamicaly by scripts/Makefile.lib. When a mrproper is done, the static file dsdt.c is removed. If a build with acpi enabled is launched after, the following error is raised: CC lib/acpi/acpi_table.o make[2]: *** No rule to make target 'lib/acpi/dsdt.asl', needed by 'lib/acpi/dsdt.c'. Stop. scripts/Makefile.build:394: recipe for target 'lib/acpi' failed To avoid such error, the generated file is named dsdt_generated.c instead of dstdt.c. Signed-off-by: Philippe Reynes Marking the patch as v2 and adding a change history would have been preferable. Oh yes, sorry, I forgot it ... --- Makefile | 3 ++- board/advantech/som-db5800-som-6867/Makefile | 2 +- board/congatec/conga-qeval20-qa3-e3845/Makefile | 2 +- board/dfi/dfi-bt700/Makefile | 2 +- board/google/chromebook_coral/Makefile | 2 +- board/intel/bayleybay/Makefile | 2 +- board/intel/edison/Makefile | 2 +- board/intel/galileo/Makefile | 2 +- board/intel/minnowmax/Makefile | 2 +- scripts/Makefile.lib | 4 ++-- 10 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 4b152249ca..94bc48f00c 100644 --- a/Makefile +++ b/Makefile @@ -2226,7 +2226,8 @@ clean: $(clean-dirs) -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ -o -name modules.builtin -o -name '.tmp_*.o.*' \ - -o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \ + -o -name 'dsdt_generated.aml' -o -name 'dsdt_generated.asl.tmp' \ + -o -name 'dsdt_generated.c' \ -o -name '*.efi' -o -name '*.gcno' -o -name '*.so' \) \ -type f -print | xargs rm -f diff --git a/board/advantech/som-db5800-som-6867/Makefile b/board/advantech/som-db5800-som-6867/Makefile index 7975547f41..95af6c4df7 100644 --- a/board/advantech/som-db5800-som-6867/Makefile +++ b/board/advantech/som-db5800-som-6867/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += som-db5800-som-6867.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/congatec/conga-qeval20-qa3-e3845/Makefile b/board/congatec/conga-qeval20-qa3-e3845/Makefile index 451a4fcd6c..215f5680dc 100644 --- a/board/congatec/conga-qeval20-qa3-e3845/Makefile +++ b/board/congatec/conga-qeval20-qa3-e3845/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += conga-qeval20-qa3.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/dfi/dfi-bt700/Makefile b/board/dfi/dfi-bt700/Makefile index 50d88f2954..1c4329a058 100644 --- a/board/dfi/dfi-bt700/Makefile +++ b/board/dfi/dfi-bt700/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Google, Inc obj-y += dfi-bt700.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/google/chromebook_coral/Makefile b/board/google/chromebook_coral/Makefile index f7a0ca6cc0..846558d777 100644 --- a/board/google/chromebook_coral/Makefile +++ b/board/google/chromebook_coral/Makefile @@ -3,4 +3,4 @@ # Copyright 2019 Google LLC obj-y += coral.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/intel/bayleybay/Makefile b/board/intel/bayleybay/Makefile index d19447184a..fa263b7bf5 100644 --- a/board/intel/bayleybay/Makefile +++ b/board/intel/bayleybay/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Bin Meng obj-y += bayleybay.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/intel/edison/Makefile b/board/intel/edison/Makefile index 1eaf7ca7f8..f7f70dfaa7 100644 --- a/board/intel/edison/Makefile +++ b/board/intel/edison/Makefile @@ -5,4 +5,4 @@ # obj-y += edison.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/intel/galileo/Makefile b/board/intel/galileo/Makefile index 4130bb0236..7d5f4df0f9 100644 --- a/board/intel/galileo/Makefile +++ b/board/intel/galileo/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2015, Bin Meng obj-y += galileo.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt.o +obj-$(CONFIG_GENERATE_ACPI_TABLE) += dsdt_generated.o diff --git a/board/intel/minnowmax/Makefile b/board/intel/minnowmax/Makefile index d339b5ad0a..a20322a1a1 10064