Skip to contentSkip to conversation

aspeed: Support secure boot chain with FIT image verification

PATCH Superseded Chia-Wei Wang 3 participants 21 messages Jul 20, 2021 – Jul 26, 2021

Subsystems (7)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v3 cover aspeed: Support secure boot chain with FIT image verification

This patch series intends to provide a secure boot chain from SPL to Linux kernel based on the hash and signature verification of FIT image paradigm.

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

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

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

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

v2:
- update commit authors

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

Joel Stanley (5):
clk: ast2600: Add YCLK control for HACE
crypto: aspeed: Add AST2600 HACE support
ast2600: spl: Add HACE probing
ARM: dts: ast2600: Add HACE to device tree
common: fit: Use hash.c to call CRC/SHA function

 arch/arm/dts/ast2600-evb.dts                  |  10 +
 arch/arm/dts/ast2600.dtsi                     |  18 +
 arch/arm/include/asm/arch-aspeed/platform.h   |   2 +-
 .../arm/include/asm/arch-aspeed/scu_ast2600.h |   6 +-
 arch/arm/mach-aspeed/ast2600/spl.c            |  29 +-
 common/image-fit.c                            |  35 +-
 configs/evb-ast2600_defconfig                 |  26 +-
 drivers/clk/aspeed/clk_ast2600.c              |  35 ++
 drivers/crypto/Kconfig                        |   2 +
 drivers/crypto/Makefile                       |   1 +
 drivers/crypto/aspeed/Kconfig                 |  22 ++
 drivers/crypto/aspeed/Makefile                |   2 +
 drivers/crypto/aspeed/aspeed_arcy.c           | 182 +++++++++++
 drivers/crypto/aspeed/aspeed_hace.c           | 308 ++++++++++++++++++
 include/configs/aspeed-common.h               |   9 -
 include/configs/evb_ast2500.h                 |   6 +
 include/configs/evb_ast2600.h                 |  13 +
 lib/rsa/Kconfig                               |  10 +-
 18 files changed, 666 insertions(+), 50 deletions(-)
 create mode 100644 drivers/crypto/aspeed/Kconfig
 create mode 100644 drivers/crypto/aspeed/Makefile
 create mode 100644 drivers/crypto/aspeed/aspeed_arcy.c
 create mode 100644 drivers/crypto/aspeed/aspeed_hace.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/14 aspeed: ast2600: Enlarge SRAM size

The AST2600 SRAM has been extended to 88KB since A1 chip revision. This patch updates the SRAM size to offer more space for early stack/heap use.

---
 arch/arm/include/asm/arch-aspeed/platform.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/include/asm/arch-aspeed/platform.h +1 -1
index d50ec5f8a9..589abd4a3f 100644
@@ -17,7 +17,7 @@
 #define ASPEED_MAC_COUNT	4
 #define ASPEED_DRAM_BASE	0x80000000
 #define ASPEED_SRAM_BASE	0x10000000
-#define ASPEED_SRAM_SIZE	0x10000
+#define ASPEED_SRAM_SIZE	0x16000
 #else
 #err "Unrecognized Aspeed platform."
 #endif
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 2/14 clk: ast2600: Add YCLK control for HACE

In reply to Chia-Wei Wang

From: Joel Stanley <[email protected]>

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

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

PATCH v3 3/14 crypto: aspeed: Add AST2600 HACE support

In reply to Chia-Wei Wang

From: Joel Stanley <[email protected]>

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

---
 drivers/crypto/Kconfig              |   2 +
 drivers/crypto/Makefile             |   1 +
 drivers/crypto/aspeed/Kconfig       |  12 ++
 drivers/crypto/aspeed/Makefile      |   1 +
 drivers/crypto/aspeed/aspeed_hace.c | 308 ++++++++++++++++++++++++++++
 5 files changed, 324 insertions(+)
 create mode 100644 drivers/crypto/aspeed/Kconfig
 create mode 100644 drivers/crypto/aspeed/Makefile
 create mode 100644 drivers/crypto/aspeed/aspeed_hace.c
drivers/crypto/Kconfig +2 -0
index 1ea116be75..422d01403e 100644
@@ -2,4 +2,6 @@ menu "Hardware crypto devices"
 
 source drivers/crypto/fsl/Kconfig
 
+source drivers/crypto/aspeed/Kconfig
+
 endmenu
drivers/crypto/Makefile +1 -0
index efbd1d3fca..0442067e5e 100644
@@ -6,3 +6,4 @@
 obj-$(CONFIG_EXYNOS_ACE_SHA)	+= ace_sha.o
 obj-y += rsa_mod_exp/
 obj-y += fsl/
+obj-y += aspeed/
drivers/crypto/aspeed/Kconfig new file +12 -0
new file mode 100644
index 0000000000..299efc223f
@@ -0,0 +1,12 @@
+config ASPEED_HACE
+	bool "ASPEED Hash and Crypto Engine"
+	depends on ASPEED_AST2600
+	imply SHA_HW_ACCEL
+	imply SHA_PROG_HW_ACCEL
+	imply CMD_HASH
+	help
+	 Select this option to enable a driver for using the SHA engine in
+	 the ASPEED BMC SoCs.
+
+	 Enabling this allows the use of SHA operations in hardware without requiring the
+	 SHA software implementations. It also improves performance and saves code size.
drivers/crypto/aspeed/Makefile new file +1 -0
new file mode 100644
index 0000000000..84e6bfe82a
@@ -0,0 +1 @@
+obj-$(CONFIG_ASPEED_HACE) += aspeed_hace.o
drivers/crypto/aspeed/aspeed_hace.c new file +308 -0

308 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v3 03/14] crypto: aspeed: Add AST2600 HACE support

Hi Chia-Wei,

Quoted 8 lines · Chia-Wei Wang

From: Joel Stanley <[email protected]>

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

Quoted 10 lines
---
 drivers/crypto/Kconfig              |   2 +
 drivers/crypto/Makefile             |   1 +
 drivers/crypto/aspeed/Kconfig       |  12 ++
 drivers/crypto/aspeed/Makefile      |   1 +
 drivers/crypto/aspeed/aspeed_hace.c | 308 ++++++++++++++++++++++++++++
 5 files changed, 324 insertions(+)
 create mode 100644 drivers/crypto/aspeed/Kconfig
 create mode 100644 drivers/crypto/aspeed/Makefile
 create mode 100644 drivers/crypto/aspeed/aspeed_hace.c

This hash interface is wonky.

There should be a hash uclass and this driver should be in that uclass. The existing hw_... functions should be dropped.

Please let me know if you need further guidance, but basically, we need a proper uclass and driver.

Regards,
Simon

#5 lore raw

RE: [PATCH v3 03/14] crypto: aspeed: Add AST2600 HACE support

Hi Simon,

Quoted 28 lines

-----Original Message-----
From: Simon Glass <[email protected]>
Sent: Wednesday, July 21, 2021 2:33 AM

Hi Chia-Wei,

Quoted 17 lines · Chia-Wei Wang

From: Joel Stanley <[email protected]>

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

---
 drivers/crypto/Kconfig              |   2 +
 drivers/crypto/Makefile             |   1 +
 drivers/crypto/aspeed/Kconfig       |  12 ++
 drivers/crypto/aspeed/Makefile      |   1 +
 drivers/crypto/aspeed/aspeed_hace.c | 308
++++++++++++++++++++++++++++
 5 files changed, 324 insertions(+)
 create mode 100644 drivers/crypto/aspeed/Kconfig  create mode 100644
Quoted 2 lines

drivers/crypto/aspeed/Makefile create mode 100644 drivers/crypto/aspeed/aspeed_hace.c

Quoted 7 lines

This hash interface is wonky.

There should be a hash uclass and this driver should be in that uclass. The existing hw_... functions should be dropped.

Please let me know if you need further guidance, but basically, we need a proper uclass and driver.

I am thinking to take the UCLASS_MOD_EXP as an example to create UCLASS_HASH.
This UCLASS_HASH should provide .ops callback like UCLASS_MOD_EXP do to support both SW and HW implemented HSAH. Is this a right direction to start with?

In addition, adding UCLASS_HASH may involve lots of common code modification. Should we make it part of the current patch series? Or a new patch series after this one?

Thanks,
Chiawei

#6 lore raw

Re: [PATCH v3 03/14] crypto: aspeed: Add AST2600 HACE support

Hi ChiaWei,

Quoted 36 lines · ChiaWei Wang

Hi Simon,

Quoted 33 lines

-----Original Message-----
From: Simon Glass <[email protected]>
Sent: Wednesday, July 21, 2021 2:33 AM

Hi Chia-Wei,

Quoted 17 lines · Chia-Wei Wang

From: Joel Stanley <[email protected]>

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

---
 drivers/crypto/Kconfig              |   2 +
 drivers/crypto/Makefile             |   1 +
 drivers/crypto/aspeed/Kconfig       |  12 ++
 drivers/crypto/aspeed/Makefile      |   1 +
 drivers/crypto/aspeed/aspeed_hace.c | 308
++++++++++++++++++++++++++++
 5 files changed, 324 insertions(+)
 create mode 100644 drivers/crypto/aspeed/Kconfig  create mode 100644
Quoted 2 lines

drivers/crypto/aspeed/Makefile create mode 100644 drivers/crypto/aspeed/aspeed_hace.c

This hash interface is wonky.

There should be a hash uclass and this driver should be in that uclass. The existing hw_... functions should be dropped.

Quoted 6 lines
Quoted 2 lines

Please let me know if you need further guidance, but basically, we need a proper uclass and driver.

I am thinking to take the UCLASS_MOD_EXP as an example to create UCLASS_HASH.
This UCLASS_HASH should provide .ops callback like UCLASS_MOD_EXP do to support both SW and HW implemented HSAH. Is this a right direction to start with?

Yes I think so. You can have API like those in struct hash_algo and hopefully remove that struct.

Then there is a software driver to write. Then people can add hardware drivers as needed.

The hash uclass needs provide a way to call the first driver it finds. We can either make it add a software driver or have it call the software functions directly if there is no (hardware) driver. I'm not sure which is best...

- having a s/w driver requires binding it at runtime
- not having a s/w driver makes the uclass a bit odd

Quoted 3 lines

In addition, adding UCLASS_HASH may involve lots of common code modification. Should we make it part of the current patch series? Or a new patch series after this one?

I would prefer a series before this one since it needs to be done before this. Or patches in the same series if you prefer.

The problem has been created already, unfortunately, so this is a clean-up.

Regards,
Simon

#7 lore raw

PATCH v3 4/14 ast2600: spl: Add HACE probing

In reply to Chia-Wei Wang

From: Joel Stanley <[email protected]>

Probe HACE driver in SPL board init if enabled.

---
 arch/arm/mach-aspeed/ast2600/spl.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm/mach-aspeed/ast2600/spl.c +14 -0
index 0d8cb29678..a0fc420ff1 100644
@@ -38,6 +38,20 @@ struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
 	return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
 }
 
+#ifdef CONFIG_SPL_BOARD_INIT
+void spl_board_init(void)
+{
+	int rc;
+	struct udevice *dev;
+
+	rc = uclass_get_device_by_driver(UCLASS_MISC,
+					 DM_DRIVER_GET(aspeed_hace),
+					 &dev);
+	if (rc)
+		debug("HACE initialization failure, rc=%d\n", rc);
+}
+#endif
+
 #ifdef CONFIG_SPL_OS_BOOT
 int spl_start_uboot(void)
 {
Signature · 1 line
2.17.1
#8 lore raw

PATCH v3 5/14 ARM: dts: ast2600: Add HACE to device tree

In reply to Chia-Wei Wang

From: Joel Stanley <[email protected]>

Add HACE DTS node and enable it for AST2600 EVB.

---
 arch/arm/dts/ast2600-evb.dts | 5 +++++
 arch/arm/dts/ast2600.dtsi    | 9 +++++++++
 2 files changed, 14 insertions(+)
arch/arm/dts/ast2600-evb.dts +5 -0
index 2abd31341c..adb80a30ef 100644
@@ -177,3 +177,8 @@
 			  0x08 0x04
 			  0x08 0x04>;
 };
+
+&hace {
+	u-boot,dm-pre-reloc;
+	status = "okay";
+};
arch/arm/dts/ast2600.dtsi +9 -0
index ac0f08b7ea..3061649205 100644
@@ -187,6 +187,15 @@
 			};
 		};
 
+		hace: hace@1e6d0000 {
+			compatible = "aspeed,ast2600-hace";
+			reg = <0x1e6d0000 0x200>;
+			interrupts = <GIC_SPI 4 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&scu ASPEED_CLK_GATE_YCLK>;
+			resets = <&rst ASPEED_RESET_HACE>;
+			status = "disabled";
+		};
+
 		edac: sdram@1e6e0000 {
 			compatible = "aspeed,ast2600-sdram-edac";
 			reg = <0x1e6e0000 0x174>;
Signature · 1 line
2.17.1
#9 lore raw

PATCH v3 6/14 common: fit: Use hash.c to call CRC/SHA function

In reply to Chia-Wei Wang

From: Joel Stanley <[email protected]>

Currently the FIT verification calls directly into SW implemented functions to get a CRC/SHA/MD5 hash.

This patch removes duplcated algorithm lookup and use hash_lookup_algo to get the hashing function with HW accelearation supported if configured.

The MD5 direct call remains as it is not included in the hash lookup table of hash.c.

---
 common/image-fit.c | 35 ++++++++++-------------------------
 1 file changed, 10 insertions(+), 25 deletions(-)
common/image-fit.c +10 -25
index 0c5a05948d..e52ff47bc3 100644
@@ -1196,7 +1196,7 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
  * calculate_hash - calculate and return hash for provided input data
  * @data: pointer to the input data
  * @data_len: data length
- * @algo: requested hash algorithm
+ * @algo_name: requested hash algorithm
  * @value: pointer to the char, will hold hash value data (caller must
  * allocate enough free space)
  * value_len: length of the calculated hash
@@ -1210,37 +1210,22 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
  *     0, on success
  *    -1, when algo is unsupported
  */
-int calculate_hash(const void *data, int data_len, const char *algo,
-			uint8_t *value, int *value_len)
+int calculate_hash(const void *data, int data_len, const char *algo_name,
+		   uint8_t *value, int *value_len)
 {
-	if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) {
-		*((uint32_t *)value) = crc32_wd(0, data, data_len,
-							CHUNKSZ_CRC32);
-		*((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value));
-		*value_len = 4;
-	} else if (IMAGE_ENABLE_SHA1 && strcmp(algo, "sha1") == 0) {
-		sha1_csum_wd((unsigned char *)data, data_len,
-			     (unsigned char *)value, CHUNKSZ_SHA1);
-		*value_len = 20;
-	} else if (IMAGE_ENABLE_SHA256 && strcmp(algo, "sha256") == 0) {
-		sha256_csum_wd((unsigned char *)data, data_len,
-			       (unsigned char *)value, CHUNKSZ_SHA256);
-		*value_len = SHA256_SUM_LEN;
-	} else if (IMAGE_ENABLE_SHA384 && strcmp(algo, "sha384") == 0) {
-		sha384_csum_wd((unsigned char *)data, data_len,
-			       (unsigned char *)value, CHUNKSZ_SHA384);
-		*value_len = SHA384_SUM_LEN;
-	} else if (IMAGE_ENABLE_SHA512 && strcmp(algo, "sha512") == 0) {
-		sha512_csum_wd((unsigned char *)data, data_len,
-			       (unsigned char *)value, CHUNKSZ_SHA512);
-		*value_len = SHA512_SUM_LEN;
-	} else if (IMAGE_ENABLE_MD5 && strcmp(algo, "md5") == 0) {
+	struct hash_algo *algo;
+
+	if (IMAGE_ENABLE_MD5 && strcmp(algo_name, "md5") == 0) {
 		md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
 		*value_len = 16;
+	} else if (hash_lookup_algo(algo_name, &algo) == 0) {
+		algo->hash_func_ws(data, data_len, value, algo->chunk_size);
+		*value_len = algo->digest_size;
 	} else {
 		debug("Unsupported hash alogrithm\n");
 		return -1;
 	}
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
#10 lore raw

Re: [PATCH v3 06/14] common: fit: Use hash.c to call CRC/SHA function

Quoted 9 lines · Chia-Wei Wang

From: Joel Stanley <[email protected]>

Currently the FIT verification calls directly into SW implemented functions to get a CRC/SHA/MD5 hash.

This patch removes duplcated algorithm lookup and use hash_lookup_algo to get the hashing function with HW accelearation supported if configured.

Quoted 5 lines

The MD5 direct call remains as it is not included in the hash lookup table of hash.c.

While this is a good idea, there's some required prep work. At least the following platforms don't compile due to this patch:
ls1046ardb_qspi imx8mm_beacon imx8mn_beacon imx8mn_beacon_2g imx8mm-icore-mx8mm-ctouch2 imx8mm-icore-mx8mm-edimm2.2 imx8mm_evk imx8mn_ddr4_evk imx8mn_evk imx8mp_evk imx8mq_evk imx8mm_venice imx8mq_phanbell phycore-imx8mm phycore-imx8mp pico-imx8mq verdin-imx8mm mt8183_pumpkin mt8516_pumpkin mscc_jr2 mscc_luton mscc_ocelot mscc_serval mscc_servalt mt7620_mt7530_rfb mt7620_rfb mt7628_rfb

Which is likely due to cases where HASH or SPL_HASH_SUPPORT are not being selected as it was not previously required.

Signature · 1 line
Tom
#11 lore raw

RE: [PATCH v3 06/14] common: fit: Use hash.c to call CRC/SHA function

Hi Tom,

Quoted 30 lines

From: Tom Rini <[email protected]>
Sent: Saturday, July 24, 2021 8:57 PM

Quoted 9 lines · Chia-Wei Wang

From: Joel Stanley <[email protected]>

Currently the FIT verification calls directly into SW implemented functions to get a CRC/SHA/MD5 hash.

This patch removes duplcated algorithm lookup and use hash_lookup_algo to get the hashing function with HW accelearation supported if configured.

Quoted 5 lines

The MD5 direct call remains as it is not included in the hash lookup table of hash.c.

While this is a good idea, there's some required prep work. At least the following platforms don't compile due to this patch:
ls1046ardb_qspi imx8mm_beacon imx8mn_beacon imx8mn_beacon_2g imx8mm-icore-mx8mm-ctouch2 imx8mm-icore-mx8mm-edimm2.2 imx8mm_evk imx8mn_ddr4_evk imx8mn_evk imx8mp_evk imx8mq_evk imx8mm_venice imx8mq_phanbell phycore-imx8mm phycore-imx8mp pico-imx8mq verdin-imx8mm mt8183_pumpkin mt8516_pumpkin mscc_jr2 mscc_luton mscc_ocelot mscc_serval mscc_servalt mt7620_mt7530_rfb mt7620_rfb mt7628_rfb

Quoted 3 lines

Which is likely due to cases where HASH or SPL_HASH_SUPPORT are not being selected as it was not previously required.

Thanks for the notification of this error. I will examine the code flow to figure out the root cause on these platforms.

Meanwhile, Simon also suggested the need to add a new UCLASS_HASH to refactor the hash structure.
http://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

I was wondering if I can prepare another leading patch for UCLASS_HASH and also to make sure the current codebase works fine? After that, we can restart this patch series for Aspeed FIT booting.

Regards,
Chiawei

#12 lore raw

Re: [PATCH v3 06/14] common: fit: Use hash.c to call CRC/SHA function

Quoted 36 lines · ChiaWei Wang

Hi Tom,

Quoted 30 lines

From: Tom Rini <[email protected]>
Sent: Saturday, July 24, 2021 8:57 PM

Quoted 9 lines · Chia-Wei Wang

From: Joel Stanley <[email protected]>

Currently the FIT verification calls directly into SW implemented functions to get a CRC/SHA/MD5 hash.

This patch removes duplcated algorithm lookup and use hash_lookup_algo to get the hashing function with HW accelearation supported if configured.

Quoted 5 lines

The MD5 direct call remains as it is not included in the hash lookup table of hash.c.

While this is a good idea, there's some required prep work. At least the following platforms don't compile due to this patch:
ls1046ardb_qspi imx8mm_beacon imx8mn_beacon imx8mn_beacon_2g imx8mm-icore-mx8mm-ctouch2 imx8mm-icore-mx8mm-edimm2.2 imx8mm_evk imx8mn_ddr4_evk imx8mn_evk imx8mp_evk imx8mq_evk imx8mm_venice imx8mq_phanbell phycore-imx8mm phycore-imx8mp pico-imx8mq verdin-imx8mm mt8183_pumpkin mt8516_pumpkin mscc_jr2 mscc_luton mscc_ocelot mscc_serval mscc_servalt mt7620_mt7530_rfb mt7620_rfb mt7628_rfb

Quoted 3 lines

Which is likely due to cases where HASH or SPL_HASH_SUPPORT are not being selected as it was not previously required.

Quoted 7 lines

Thanks for the notification of this error. I will examine the code flow to figure out the root cause on these platforms.

Meanwhile, Simon also suggested the need to add a new UCLASS_HASH to refactor the hash structure.
http://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

I was wondering if I can prepare another leading patch for UCLASS_HASH and also to make sure the current codebase works fine? After that, we can restart this patch series for Aspeed FIT booting.

OK, sounds like a good plan, thanks!

Signature · 1 line
Tom
#13 lore raw

PATCH v3 7/14 clk: ast2600: Add RSACLK control for ARCY

In reply to Chia-Wei Wang

Add RSACLK enable for ARCY, the HW RSA/ECC crypto engine of ASPEED AST2600 SoCs.

---
 arch/arm/include/asm/arch-aspeed/scu_ast2600.h |  1 +
 drivers/clk/aspeed/clk_ast2600.c               | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
arch/arm/include/asm/arch-aspeed/scu_ast2600.h +1 -0
index d7b500f656..27f4e9f994 100644
@@ -8,6 +8,7 @@
 #define SCU_UNLOCK_KEY			0x1688a8a8
 
 #define SCU_CLKGATE1_EMMC			BIT(27)
+#define SCU_CLKGATE1_ARCY			BIT(24)
 #define SCU_CLKGATE1_MAC2			BIT(21)
 #define SCU_CLKGATE1_MAC1			BIT(20)
 #define SCU_CLKGATE1_USB_HUB			BIT(14)
drivers/clk/aspeed/clk_ast2600.c +15 -0
index 69128fd3c4..bf3379fce2 100644
@@ -1030,6 +1030,18 @@ static ulong ast2600_enable_haceclk(struct ast2600_scu *scu)
 	return 0;
 }
 
+static ulong ast2600_enable_rsaclk(struct ast2600_scu *scu)
+{
+	uint32_t clkgate_bit;
+
+	clkgate_bit = SCU_CLKGATE1_ARCY;
+
+	writel(clkgate_bit, &scu->clkgate_clr1);
+	mdelay(20);
+
+	return 0;
+}
+
 static int ast2600_clk_enable(struct clk *clk)
 {
 	struct ast2600_clk_priv *priv = dev_get_priv(clk->dev);
@@ -1071,6 +1083,9 @@ static int ast2600_clk_enable(struct clk *clk)
 	case ASPEED_CLK_GATE_YCLK:
 		ast2600_enable_haceclk(priv->scu);
 		break;
+	case ASPEED_CLK_GATE_RSACLK:
+		ast2600_enable_rsaclk(priv->scu);
+		break;
 	default:
 		pr_err("can't enable clk\n");
 		return -ENOENT;
Signature · 1 line
2.17.1
#14 lore raw

PATCH v3 8/14 crypto: aspeed: Add AST2600 ARCY support

In reply to Chia-Wei Wang

ARCY is deisnged to accerlerate ECC/RSA digital signature generation and verification.

---
 drivers/crypto/aspeed/Kconfig       |  10 ++
 drivers/crypto/aspeed/Makefile      |   1 +
 drivers/crypto/aspeed/aspeed_arcy.c | 182 ++++++++++++++++++++++++++++
 lib/rsa/Kconfig                     |  10 +-
 4 files changed, 202 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/aspeed/aspeed_arcy.c
drivers/crypto/aspeed/Kconfig +10 -0
index 299efc223f..9d896afa8a 100644
@@ -10,3 +10,13 @@ config ASPEED_HACE
 
 	 Enabling this allows the use of SHA operations in hardware without requiring the
 	 SHA software implementations. It also improves performance and saves code size.
+
+config ASPEED_ARCY
+	bool "ASPEED RSA and ECC Engine"
+	depends on ASPEED_AST2600
+	help
+	 Select this option to enable a driver for using the RSA/ECC engine in
+	 the ASPEED BMC SoCs.
+
+	 Enabling this allows the use of RSA/ECC operations in hardware without requiring the
+	 software implementations. It also improves performance and saves code size.
drivers/crypto/aspeed/Makefile +1 -0
index 84e6bfe82a..8de95eef7e 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_ASPEED_HACE) += aspeed_hace.o
+obj-$(CONFIG_ASPEED_ARCY) += aspeed_arcy.o
drivers/crypto/aspeed/aspeed_arcy.c new file +182 -0

182 lines not on this page · raw message

lib/rsa/Kconfig +9 -1
index a90d67e5a8..81c0936e58 100644
@@ -1,7 +1,8 @@
 config RSA
 	bool "Use RSA Library"
 	select RSA_FREESCALE_EXP if FSL_CAAM && !ARCH_MX7 && !ARCH_MX6 && !ARCH_MX5
-	select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP
+	select RSA_ASPEED_EXP if ASPEED_ARCY
+	select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP && !RSA_ASPEED_EXP
 	help
 	  RSA support. This enables the RSA algorithm used for FIT image
 	  verification in U-Boot.
@@ -61,4 +62,11 @@ config RSA_FREESCALE_EXP
 	Enables driver for RSA modular exponentiation using Freescale cryptographic
 	accelerator - CAAM.
 
+config RSA_ASPEED_EXP
+	bool "Enable RSA Modular Exponentiation with ASPEED crypto accelerator"
+	depends on DM && ASPEED_ARCY
+	help
+	Enables driver for RSA modular exponentiation using ASPEED cryptographic
+	accelerator - ARCY
+
 endif
Signature · 1 line
2.17.1
#15 lore raw

PATCH v3 9/14 ast2600: spl: Add ARCY probing

In reply to Chia-Wei Wang

Probe ARCY driver in SPL board init if enabled.

---
 arch/arm/mach-aspeed/ast2600/spl.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-aspeed/ast2600/spl.c +6 -0
index a0fc420ff1..2172bb4ae7 100644
@@ -49,6 +49,12 @@ void spl_board_init(void)
 					 &dev);
 	if (rc)
 		debug("HACE initialization failure, rc=%d\n", rc);
+
+	rc = uclass_get_device_by_driver(UCLASS_MOD_EXP,
+					 DM_DRIVER_GET(aspeed_arcy),
+					 &dev);
+	if (rc)
+		debug("ARCY initialization failure, rc=%d\n", rc);
 }
 #endif
 
Signature · 1 line
2.17.1
#16 lore raw

PATCH v3 10/14 ARM: dts: ast2600: Add ARCY to device tree

In reply to Chia-Wei Wang

Add ARCY DTS node and enable it for AST2600 EVB.

---
 arch/arm/dts/ast2600-evb.dts | 5 +++++
 arch/arm/dts/ast2600.dtsi    | 9 +++++++++
 2 files changed, 14 insertions(+)
arch/arm/dts/ast2600-evb.dts +5 -0
index adb80a30ef..fd4e35e954 100644
@@ -182,3 +182,8 @@
 	u-boot,dm-pre-reloc;
 	status = "okay";
 };
+
+&arcy {
+	u-boot,dm-pre-reloc;
+	status = "okay";
+};
arch/arm/dts/ast2600.dtsi +9 -0
index 3061649205..3e20c16392 100644
@@ -196,6 +196,15 @@
 			status = "disabled";
 		};
 
+		arcy: arcy@1e6fa000 {
+			compatible = "aspeed,ast2600-arcy";
+			reg = <0x1e6fa000 0x1000>,
+			      <0x1e710000 0x10000>;
+			interrupts = <GIC_SPI 160 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&scu ASPEED_CLK_GATE_RSACLK>;
+			status = "disabled";
+		};
+
 		edac: sdram@1e6e0000 {
 			compatible = "aspeed,ast2600-sdram-edac";
 			reg = <0x1e6e0000 0x174>;
Signature · 1 line
2.17.1
#17 lore raw

PATCH v3 11/14 ast2600: spl: Locate load buffer in DRAM space

In reply to Chia-Wei Wang

Return CONFIG_SYS_LOAD_ADDR pointing to DRAM space for spl_get_load_buffer() to allow generic SPL image loading code (e.g. FIT and Ymodem) to store data in DRAM.

---
 arch/arm/mach-aspeed/ast2600/spl.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
arch/arm/mach-aspeed/ast2600/spl.c +1 -8
index 2172bb4ae7..42ef24316e 100644
@@ -28,14 +28,7 @@ u32 spl_boot_device(void)
 
 struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
 {
-	/*
-	 * When boot from SPI, AST2600 already remap 0x00000000 ~ 0x0fffffff
-	 * to BMC SPI memory space 0x20000000 ~ 0x2fffffff. The next stage BL
-	 * has been located in SPI for XIP. In this case, the load buffer for
-	 * SPL image loading will be set to the remapped address of the next
-	 * BL instead of the DRAM space CONFIG_SYS_LOAD_ADDR
-	 */
-	return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
+	return (struct image_header *)(CONFIG_SYS_LOAD_ADDR);
 }
 
 #ifdef CONFIG_SPL_BOARD_INIT
Signature · 1 line
2.17.1
#18 lore raw

PATCH v3 12/14 configs: ast2600-evb: Enable SPL FIT support

In reply to Chia-Wei Wang

Enable SPL FIT image load and verification support. The HW accelerated SHA is also available with the newly added support of the HACE HW hash engine.

---
 configs/evb-ast2600_defconfig | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
configs/evb-ast2600_defconfig +21 -3
index f24425997d..5049217b55 100644
@@ -1,7 +1,7 @@
 CONFIG_ARM=y
 CONFIG_SYS_DCACHE_OFF=y
 CONFIG_ARCH_ASPEED=y
-CONFIG_SYS_TEXT_BASE=0x10000
+CONFIG_SYS_TEXT_BASE=0x80000000
 CONFIG_ASPEED_AST2600=y
 CONFIG_TARGET_EVB_AST2600=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
@@ -11,12 +11,19 @@ CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x10000
 CONFIG_DEFAULT_DEVICE_TREE="ast2600-evb"
 CONFIG_SPL_SERIAL_SUPPORT=y
+CONFIG_SPL_DRIVERS_MISC_SUPPORT=y
+CONFIG_SPL_STACK_R_ADDR=0x83000000
 CONFIG_SPL_SIZE_LIMIT=0x10000
 CONFIG_SPL=y
 # CONFIG_ARMV7_NONSEC is not set
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_FIT=y
-# CONFIG_LEGACY_IMAGE_FORMAT is not set
+CONFIG_FIT_ENABLE_SHA384_SUPPORT=y
+CONFIG_FIT_ENABLE_SHA512_SUPPORT=y
+CONFIG_SPL_FIT_SIGNATURE=y
+CONFIG_SPL_LOAD_FIT=y
+CONFIG_SPL_LOAD_FIT_ADDRESS=0x10000
+# CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyS4,115200n8 root=/dev/ram rw"
 CONFIG_USE_BOOTCOMMAND=y
@@ -24,8 +31,15 @@ CONFIG_BOOTCOMMAND="bootm 20100000"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD=y
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC=y
-# CONFIG_SPL_LEGACY_IMAGE_SUPPORT is not set
+CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_STACK_R=y
+CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000000
+CONFIG_SPL_SHA1_SUPPORT=y
+CONFIG_SPL_SHA256_SUPPORT=y
+CONFIG_SPL_SHA384_SUPPORT=y
+CONFIG_SPL_SHA512_SUPPORT=y
+CONFIG_SPL_FIT_IMAGE_TINY=y
 CONFIG_SPL_DM_RESET=y
 CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
@@ -45,6 +59,8 @@ CONFIG_REGMAP=y
 CONFIG_SPL_OF_TRANSLATE=y
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_ASPEED_HACE=y
+CONFIG_ASPEED_ARCY=y
 CONFIG_DM_I2C=y
 CONFIG_MISC=y
 CONFIG_SPL_MISC=y
@@ -63,6 +79,8 @@ CONFIG_SYS_NS16550=y
 CONFIG_SYSRESET=y
 CONFIG_SPL_SYSRESET=y
 CONFIG_WDT=y
+CONFIG_SHA512_HW_ACCEL=y
 CONFIG_HEXDUMP=y
 # CONFIG_SPL_HEXDUMP is not set
 # CONFIG_EFI_LOADER is not set
+CONFIG_PHANDLE_CHECK_SEQ=y
Signature · 1 line
2.17.1
#19 lore raw

PATCH v3 13/14 configs: aspeed: Make EXTRA_ENV_SETTINGS board specific

In reply to Chia-Wei Wang

Move CONFIG_EXTRA_ENV_SETTINGS to board-specific
configuration headers.

---
 include/configs/aspeed-common.h | 9 ---------
 include/configs/evb_ast2500.h   | 6 ++++++
 include/configs/evb_ast2600.h   | 6 ++++++
 3 files changed, 12 insertions(+), 9 deletions(-)
include/configs/aspeed-common.h +0 -9
index df0f5d2e76..afe690af53 100644
@@ -43,13 +43,4 @@
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
 
-/*
- * Miscellaneous configurable options
- */
-
-#define CONFIG_EXTRA_ENV_SETTINGS \
-	"verify=yes\0"	\
-	"spi_dma=yes\0" \
-	""
-
 #endif	/* __AST_COMMON_CONFIG_H */
include/configs/evb_ast2500.h +6 -0
index 0ff01af833..a886fd941e 100644
@@ -16,4 +16,10 @@
 /* Memory Info */
 #define CONFIG_SYS_LOAD_ADDR		0x83000000
 
+/* Misc */
+#define CONFIG_EXTRA_ENV_SETTINGS \
+	"verify=yes\0"	\
+	"spi_dma=yes\0" \
+	""
+
 #endif	/* __CONFIG_H */
include/configs/evb_ast2600.h +6 -0
index e7975bf66d..d2aceb6663 100644
@@ -13,4 +13,10 @@
 /* Memory Info */
 #define CONFIG_SYS_LOAD_ADDR		0x83000000
 
+/* Misc */
+#define CONFIG_EXTRA_ENV_SETTINGS \
+	"verify=yes\0"	\
+	"spi_dma=yes\0" \
+	""
+
 #endif	/* __CONFIG_H */
Signature · 1 line
2.17.1
#20 lore raw

PATCH v3 14/14 configs: ast2600: Boot kernel FIT in DRAM

In reply to Chia-Wei Wang

AST2600 leverages the FIT hash/signature verification to fulfill secure boot trust chain. To improve the performance and save SW code size for those crypto operations, the two HW crypto engine, HACE and ARCY, are enabled.

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

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

---
 configs/evb-ast2600_defconfig | 2 +-
 include/configs/evb_ast2600.h | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
configs/evb-ast2600_defconfig +1 -1
index 5049217b55..f87487b82f 100644
@@ -27,7 +27,7 @@ CONFIG_SPL_LOAD_FIT_ADDRESS=0x10000
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyS4,115200n8 root=/dev/ram rw"
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="bootm 20100000"
+CONFIG_BOOTCOMMAND="run bootspi"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD=y
 CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC=y
include/configs/evb_ast2600.h +7 -0
index d2aceb6663..83002db317 100644
@@ -14,7 +14,14 @@
 #define CONFIG_SYS_LOAD_ADDR		0x83000000
 
 /* Misc */
+#define STR_HELPER(s)	#s
+#define STR(s)		STR_HELPER(s)
+
 #define CONFIG_EXTRA_ENV_SETTINGS \
+	"loadaddr=" STR(CONFIG_SYS_LOAD_ADDR) "\0" \
+	"bootspi=fdt addr 20100000 && fdt header get fitsize totalsize && " \
+	"cp.b 20100000 ${loadaddr} ${fitsize} && bootm; " \
+	"echo Error loading kernel FIT image\0" \
 	"verify=yes\0"	\
 	"spi_dma=yes\0" \
 	""
Signature · 1 line
2.17.1