Skip to contentSkip to conversation

support remote system update on Intel Stratix10 SoC

PATCH Superseded richard.gong at linux.intel.com 1 participant 6 messages Sep 9, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover support remote system update on Intel Stratix10 SoC

From: Richard Gong <[email protected]>

The Intel Remote System Update (RSU) provides a way for users to update the QSPI configuration bitstream of a Intel Stratix10 SoC device with significantly reduced risk of corrupting the bitstream storage and bricking the system.

The patchset adds RSU support which allows user to perform a complete set of RSU operations via provided console commands.

The patches have reviewed by other colleagues at Intel.

Richard Gong (5):
arm: socfpga: stratix10: add RSU mailbox support
arm: socfpga: stratix10: add RSU support for Stratix10 SoC
arm: socfpga: stratix10: add environment variables for RSU support
arm: socfpga: stratix10: add console commands for RSU support
arm: socfpga: enable RSU build

 arch/arm/mach-socfpga/Makefile                   |    6 +
 arch/arm/mach-socfpga/include/mach/mailbox_s10.h |   36 +-
 arch/arm/mach-socfpga/include/mach/rsu.h         |  244 +++++
 arch/arm/mach-socfpga/include/mach/rsu_ll.h      |   71 ++
 arch/arm/mach-socfpga/include/mach/rsu_misc.h    |   46 +
 arch/arm/mach-socfpga/include/mach/rsu_s10.h     |   46 +
 arch/arm/mach-socfpga/mailbox_s10.c              |   45 +
 arch/arm/mach-socfpga/misc_s10.c                 |    9 +
 arch/arm/mach-socfpga/rsu.c                      |  569 ++++++++++++
 arch/arm/mach-socfpga/rsu_ll_qspi.c              | 1033 ++++++++++++++++++++++
 arch/arm/mach-socfpga/rsu_misc.c                 |  527 +++++++++++
 arch/arm/mach-socfpga/rsu_s10.c                  |  817 +++++++++++++++++
 12 files changed, 3439 insertions(+), 10 deletions(-)
 create mode 100644 arch/arm/mach-socfpga/include/mach/rsu.h
 create mode 100644 arch/arm/mach-socfpga/include/mach/rsu_ll.h
 create mode 100644 arch/arm/mach-socfpga/include/mach/rsu_misc.h
 create mode 100644 arch/arm/mach-socfpga/include/mach/rsu_s10.h
 create mode 100644 arch/arm/mach-socfpga/rsu.c
 create mode 100644 arch/arm/mach-socfpga/rsu_ll_qspi.c
 create mode 100644 arch/arm/mach-socfpga/rsu_misc.c
 create mode 100644 arch/arm/mach-socfpga/rsu_s10.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 arm: socfpga: stratix10: add RSU mailbox support

From: Richard Gong <[email protected]>

Add Remote System Update (RSU) related mailbox support. This includes RSU_STATUS which reports status of bitstream loaded by Configuration Management Firmware (CMF), RSU_UPDATE which will invokes CMF to load new bitstream, GET_SUBPARTITION_TABLE which will query CMF on the start address of sub-partition table, HPS_STAGE_NOTIFY which notifies firmware the stage of HPS code execution and related functions to support Secure Monitor Call (SMC).

---
 arch/arm/mach-socfpga/include/mach/mailbox_s10.h | 36 +++++++++++++------
 arch/arm/mach-socfpga/mailbox_s10.c              | 45 ++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 10 deletions(-)
arch/arm/mach-socfpga/include/mach/mailbox_s10.h +26 -10
index ae728a5..979fd06 100644
@@ -77,16 +77,20 @@ enum ALT_SDM_MBOX_RESP_CODE {
 };
 
 /* Mailbox command list */
-#define MBOX_RESTART		2
-#define MBOX_CONFIG_STATUS	4
-#define MBOX_RECONFIG		6
-#define MBOX_RECONFIG_MSEL	7
-#define MBOX_RECONFIG_DATA	8
-#define MBOX_RECONFIG_STATUS	9
-#define MBOX_QSPI_OPEN		50
-#define MBOX_QSPI_CLOSE		51
-#define MBOX_QSPI_DIRECT	59
-#define MBOX_REBOOT_HPS		71
+#define MBOX_RESTART			2
+#define MBOX_CONFIG_STATUS		4
+#define MBOX_RECONFIG			6
+#define MBOX_RECONFIG_MSEL		7
+#define MBOX_RECONFIG_DATA		8
+#define MBOX_RECONFIG_STATUS		9
+#define MBOX_QSPI_OPEN			50
+#define MBOX_QSPI_CLOSE			51
+#define MBOX_QSPI_DIRECT		59
+#define MBOX_REBOOT_HPS			71
+#define MBOX_GET_SUBPARTITION_TABLE	90
+#define MBOX_RSU_STATUS			91
+#define MBOX_RSU_UPDATE			92
+#define MBOX_HPS_STAGE_NOTIFY		93
 
 /* Mailbox registers */
 #define MBOX_CIN			0	/* command valid offset */
@@ -130,6 +134,11 @@ enum ALT_SDM_MBOX_RESP_CODE {
 #define RCF_SOFTFUNC_STATUS_SEU_ERROR			BIT(3)
 #define RCF_PIN_STATUS_NSTATUS				BIT(31)
 
+/* Defines for HPS_STAGE_NOTIFY */
+#define HPS_EXECUTION_STATE_FSBL	0
+#define HPS_EXECUTION_STATE_SSBL	1
+#define HPS_EXECUTION_STATE_OS		2
+
 int mbox_send_cmd(u8 id, u32 cmd, u8 is_indirect, u32 len, u32 *arg, u8 urgent,
 		  u32 *resp_buf_len, u32 *resp_buf);
 int mbox_send_cmd_psci(u8 id, u32 cmd, u8 is_indirect, u32 len, u32 *arg,
@@ -146,6 +155,13 @@ int mbox_qspi_open(void);
 #endif
 
 int mbox_reset_cold(void);
+int mbox_rsu_get_spt_offset(u32 *resp_buf, u32 resp_buf_len);
+int mbox_rsu_status(u32 *resp_buf, u32 resp_buf_len);
+int mbox_rsu_status_psci(u32 *resp_buf, u32 resp_buf_len);
+int mbox_rsu_update(u32 *flash_offset);
+int mbox_rsu_update_psci(u32 *flash_offset);
+int mbox_hps_stage_notify(u32 execution_stage);
+int mbox_hps_stage_notify_psci(u32 execution_stage);
 int mbox_get_fpga_config_status(u32 cmd);
 int mbox_get_fpga_config_status_psci(u32 cmd);
 #endif /* _MAILBOX_S10_H_ */
arch/arm/mach-socfpga/mailbox_s10.c +45 -0

63 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/5 arm: socfpga: stratix10: add RSU support for Stratix10 SoC

In reply to richard.gong at linux.intel.com

From: Richard Gong <[email protected]>

The Intel Remote System Update (RSU) provides a way for users to update the QSPI configuration bitstream of an Intel Stratix 10 SoC device with significantly reduced risk of corrupting the bitstream storage and bricking the system.

This patch adds RSU support which allows user to perform a complete set of RSU operations:
1. Provides support for creating the initial flash images for a system to support RSU.
2. Allows several production images to be tried in a specific order until one of them is successful.
3. Loads a factory image if no production image is available, or all production images failed.
4. Provides users with the ability to add and remove production images.
5. Provides user with the ability to change the order in which production images are loaded.
6. Provides user with the ability to load a specific image from flash. The image is a production or factory image.
7. Provides user with information on which image is currently running, and what errors were encountered by RSU.

---
 arch/arm/mach-socfpga/include/mach/rsu.h      |  244 ++++++
 arch/arm/mach-socfpga/include/mach/rsu_ll.h   |   71 ++
 arch/arm/mach-socfpga/include/mach/rsu_misc.h |   46 ++
 arch/arm/mach-socfpga/rsu.c                   |  569 ++++++++++++++
 arch/arm/mach-socfpga/rsu_ll_qspi.c           | 1033 +++++++++++++++++++++++++
 arch/arm/mach-socfpga/rsu_misc.c              |  527 +++++++++++++
 6 files changed, 2490 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/include/mach/rsu.h
 create mode 100644 arch/arm/mach-socfpga/include/mach/rsu_ll.h
 create mode 100644 arch/arm/mach-socfpga/include/mach/rsu_misc.h
 create mode 100644 arch/arm/mach-socfpga/rsu.c
 create mode 100644 arch/arm/mach-socfpga/rsu_ll_qspi.c
 create mode 100644 arch/arm/mach-socfpga/rsu_misc.c
arch/arm/mach-socfpga/include/mach/rsu.h new file +244 -0
new file mode 100644
index 0000000..3b1868a
@@ -0,0 +1,244 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Intel Corporation
+ *
+ */
+
+#ifndef __RSU_H__
+#define __RSU_H__
+
+#include <asm/types.h>
+
+/* RSU Error Codes */
+#define EINTF		1
+#define ECFG		2
+#define ESLOTNUM	3
+#define EFORMAT		4
+#define EERASE		5
+#define EPROGRAM	6
+#define ECMP		7
+#define ESIZE		8
+#define ENAME		9
+#define EFILEIO		10
+#define ECALLBACK	11
+#define ELOWLEVEL	12
+#define EWRPROT		13
+#define EARGS		14
+
+/* RSU Notify Bitmasks */
+#define RSU_NOTIFY_IGNORE_STAGE         BIT(18)
+#define RSU_NOTIFY_CLEAR_ERROR_STATUS   BIT(17)
+#define RSU_NOTIFY_RESET_RETRY_COUNTER  BIT(16)
+
+/**
+ * struct rsu_status_info - firmware status log info structure
+ * @current_image:address of image currently running in flash
+ * @fail_image: address of failed image in flash
+ * @state: the state of RSU system
+ * @version: the version number of RSU firmware
+ * @error_location: the error offset inside the failed image
+ * @error_details: error code
+ * @retry_counter: current image retry counter
+ *
+ * This structure is used to capture firmware status log information
+ */
+struct rsu_status_info {
+	u64 current_image;
+	u64 fail_image;
+	u32 state;
+	u32 version;
+	u32 error_location;
+	u32 error_details;
+	u32 retry_counter;
+};
+
+/**
+ * struct rsu_slot_info - slot information structure
+ * @name: a slot name
+ * @offset: a slot offset
+ * @size: the size of a slot
+ * @priority: the priority of a slot
+ *
+ * This structure is used to capture the slot information details
+ */
+struct rsu_slot_info {
+	char name[16];
+	u64 offset;
+	u32 size;
+	int priority;
+};
+
+/**
+ * rsu_init() - initialize flash driver, SPT and CPB data
+ * @filename: NULL for qspi
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_init(char *filename);
+
+/**
+ * rsu_exit() - free flash driver, clean SPT and CPB data
+ */
+void rsu_exit(void);
+
+/**
+ * rsu_slot_count() - get the number of slots defined
+ *
+ * Returns: the number of defined slots
+ */
+int rsu_slot_count(void);
+
+/**
+ * rsu_slot_by_name() - get slot number based on name
+ * @name: name of slot
+ *
+ * Return:slot number on success, or error code
+ */
+int rsu_slot_by_name(char *name);
+
+/**
+ * rsu_slot_get_info() - get the attributes of a slot
+ * @slot: slot number
+ * @info: pointer to info structure to be filled in
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_get_info(int slot, struct rsu_slot_info *info);
+
+/**
+ * rsu_slot_size() - get the size of a slot
+ * @slot: slot number
+ *
+ * Returns: the size of the slot in bytes, or error code
+ */
+int rsu_slot_size(int slot);
+
+/**
+ * rsu_slot_priority() - get the Decision CMF load priority of a slot
+ * @slot: slot number
+ *
+ * Priority of zero means the slot has no priority and is disabled.
+ * The slot with priority of one has the highest priority.
+ *
+ * Returns: the priority of the slot, or error code
+ */
+int rsu_slot_priority(int slot);
+
+/**
+ * rsu_slot_erase() - erase all data in a slot
+ * @slot: slot number
+ *
+ * Erase all data in a slot to prepare for programming. Remove the slot
+ * if it is in the CMF pointer block.
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_erase(int slot);
+
+/**
+ * rsu_slot_program_buf() - program a slot from FPGA buffer data
+ * @slot: slot number
+ * @buf: pointer to data buffer
+ * @size: bytes to read from buffer, in hex value
+ *
+ * This function is used to program a slot using FPGA config data from a
+ * buffer and then enter the slot into CPB.
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_program_buf(int slot, void *buf, int size);
+
+/**
+ * rsu_slot_program_buf_raw() - program a slot from raw buffer data
+ * @slot: slot number
+ * @buf: pointer to data buffer
+ * @size: bytes to read from buffer, in hex value
+ *
+ * This function is used to program a slot using raw data from a buffer,
+ * and then enter this slot into CPB.
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_program_buf_raw(int slot, void *buf, int size);
+
+/**
+ * rsu_slot_verify_buf() - verify FPGA config data in a slot against a
+ * buffer
+ * @slot: slot number
+ * @buf: pointer to data buffer
+ * @size: bytes to read from buffer, in hex value
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_verify_buf(int slot, void *buf, int size);
+
+/**
+ * rsu_slot_verify_buf_raw() - verify raw data in a slot against a buffer
+ * @slot: slot number
+ * @buf: pointer to data buffer
+ * @size: bytes to read from buffer, in hex value
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_verify_buf_raw(int slot, void *buf, int size);
+
+/**
+ * rsu_slot_enable() - enable the selected slot
+ * @slot: slot number
+ *
+ * Set the selected slot as the highest priority. It will be the first
+ * slot to be tried after a power-on reset.
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_enable(int slot);
+
+/**
+ * rsu_slot_disable() - disable the selected slot
+ * @slot: slot number
+ *
+ * Remove the selected slot from the priority scheme, but don't erase the
+ * slot data so that it can be re-enabled.
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_disable(int slot);
+
+/**
+ * rsu_slot_load() - load the selected slot
+ * @slot: slot number
+ *
+ * This function is used to request the selected slot to be loaded
+ * immediately. On success, after a small delay, the system is rebooted.
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_load(int slot);
+
+/**
+ * rsu_slot_load_factory() - load the factory image
+ *
+ * This function is used to request the factory image to be loaded
+ * immediately. On success, after a small delay, the system is rebooted.
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_load_factory(void);
+
+/**
+ * rsu_slot_rename() - Rename the selected slot.
+ * @slot: slot number
+ * @name: new name for slot
+ *
+ * Returns: 0 on success, or error code
+ */
+int rsu_slot_rename(int slot, char *name);
+
+/**
+ * rsu_status_log() - Copy firmware status log to info struct
+ * @info: pointer to info struct to fill in
+ *
+ * Return 0 on success, or error code
+ */
+int rsu_status_log(struct rsu_status_info *info);
+#endif
arch/arm/mach-socfpga/include/mach/rsu_ll.h new file +71 -0

71 lines not on this page · raw message

arch/arm/mach-socfpga/include/mach/rsu_misc.h new file +46 -0

46 lines not on this page · raw message

arch/arm/mach-socfpga/rsu.c new file +569 -0

569 lines not on this page · raw message

arch/arm/mach-socfpga/rsu_ll_qspi.c new file +1033 -0

1,033 lines not on this page · raw message

arch/arm/mach-socfpga/rsu_misc.c new file +527 -0

527 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/5 arm: socfpga: stratix10: add environment variables for RSU support

In reply to richard.gong at linux.intel.com

From: Richard Gong <[email protected]>

Add two RSU environment variables:
1. rsu_log_level
the variable is unsigned integer and its default value is RSU_DEBUG (7), which only show log with RSU_INFO,RSU_WARNING and RSU_ERR.

To enable all logs (RSU_ERR, RSU_WARNING, RSU_INFO and RSU_DEBUG), you need set log level to 8 or above via “setenv rsu_log_level 8”.

To disable all logs, you need set log level to 3 or below.

2. rsu_protected_slot
by default there is no protected RSU slot, you need run "setenv rsu_protected_slot <slot_num>” to set a slot protected, and “setenv rsu_protected_slot <a space>” to unset a protected slot.

---
 arch/arm/mach-socfpga/misc_s10.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/mach-socfpga/misc_s10.c +9 -0
index 0a5fab1..c9a6f00 100644
@@ -21,6 +21,8 @@
 
 #include <dt-bindings/reset/altr,rst-mgr-s10.h>
 
+#define RSU_DEFAULT_LOG_LEVEL  7
+
 DECLARE_GLOBAL_DATA_PTR;
 
 static struct socfpga_system_manager *sysmgr_regs =
@@ -136,10 +138,17 @@ int print_cpuinfo(void)
 int arch_misc_init(void)
 {
 	char qspi_string[13];
+	char level[4];
+
+	snprintf(level, sizeof(level), "%u", RSU_DEFAULT_LOG_LEVEL);
 
 	sprintf(qspi_string, "<0x%08x>", cm_get_qspi_controller_clk_hz());
 	env_set("qspi_clock", qspi_string);
 
+	/* setup for RSU */
+	env_set("rsu_protected_slot", "");
+	env_set("rsu_log_level", level);
+
 	socfpga_set_phymode();
 	return 0;
 }
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/5 arm: socfpga: stratix10: add console commands for RSU support

In reply to richard.gong at linux.intel.com

From: Richard Gong <[email protected]>

The Intel Remote System Update (RSU) provides a way for users to update the QSPI configuration bitstream of a Intel Stratix 10 SoC device with significantly reduced risk of corrupting the bitstream storage and bricking the system.

This patch provides console commands to exercises the RSU APIs at Intel Stratix10 SoC. The commands use the term "slot" to refer to a sub-partition which is intended to contain a production image, and the term "priority" to refer to the fact that the images are loaded by firmware in the defined order.

The provided console commands are below, you can also refer to the header file rsu.h for the details of RSU APIs:
slot_count
slot_by_name
slot_get_info
slot_size
slot_priority
slot_erase
slot_program_buf
slot_program_buf_raw
slot_verify_buf
slot_verify_buf_raw
slot_enable
slot_disable
slot_load
slot_load_factory
slot_rename
status_log
list
dtb
update
notify
clear_error_status
reset_retry_counter

---
 arch/arm/mach-socfpga/include/mach/rsu_s10.h |  46 ++
 arch/arm/mach-socfpga/rsu_s10.c              | 817 +++++++++++++++++++++++++++
 2 files changed, 863 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/include/mach/rsu_s10.h
 create mode 100644 arch/arm/mach-socfpga/rsu_s10.c
arch/arm/mach-socfpga/include/mach/rsu_s10.h new file +46 -0
new file mode 100644
index 0000000..9a4ec53
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Intel Corporation
+ *
+ */
+#ifndef _RSU_S10_H_
+#define _RSU_S10_H_
+
+extern u32 smc_rsu_update_address;
+
+#define RSU_S10_CPB_MAGIC_NUMBER	0x57789609
+#define RSU_S10_SPT_MAGIC_NUMBER	0x57713427
+
+#define SPT0_INDEX	1
+#define SPT1_INDEX	3
+
+/* CMF pointer block */
+struct socfpga_rsu_s10_cpb {
+	u32 magic_number;
+	u32 header_size;
+	u32 total_size;
+	u32 reserved1;
+	u32 iptab_offset;
+	u32 nslots;
+	u32 reserved2;
+	u64 pointer_slot[508];
+};
+
+/* sub partition slot */
+struct socfpga_rsu_s10_spt_slot {
+	char name[16];
+	u32 offset[2];
+	u32 length;
+	u32 flag;
+};
+
+/* sub partition table */
+struct socfpga_rsu_s10_spt {
+	u32 magic_number;
+	u32 version;
+	u32 entries;
+	u32 reserved[5];
+	struct socfpga_rsu_s10_spt_slot spt_slot[127];
+};
+
+#endif /* _RSU_S10_H_ */
arch/arm/mach-socfpga/rsu_s10.c new file +817 -0

817 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

PATCH 5/5 arm: socfpga: enable RSU build

In reply to richard.gong at linux.intel.com

From: Richard Gong <[email protected]>

Add build support for RSU.

---
 arch/arm/mach-socfpga/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-socfpga/Makefile +6 -0
index fc1181c..17ec0bf 100644
@@ -33,6 +33,12 @@ obj-y	+= mailbox_s10.o
 obj-y	+= misc_s10.o
 obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
+ifndef CONFIG_SPL_BUILD
+obj-y   += rsu.o
+obj-y   += rsu_ll_qspi.o
+obj-y   += rsu_misc.o
+obj-y   += rsu_s10.o
+endif
 obj-y	+= system_manager_s10.o
 obj-y	+= timer_s10.o
 obj-y	+= wrap_pinmux_config_s10.o
Signature · 1 line
2.7.4