From: Abdellatif El Khlifi <[email protected]>

No need for trial state handling in U-Boot for FWU Arm PSA.

In FWU Arm PSA mode, trial state is handled by secure world. Implement
local trial and update checks and dummy active and update bank hooks
required by capsule handling. This avoids using shared multi-bank FWU
metadata.

Signed-off-by: Abdellatif El Khlifi <[email protected]>
Signed-off-by: Alex Chapman <[email protected]>
Signed-off-by: David Hu <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Sughosh Ganu <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Casey Connolly <[email protected]>
Cc: Adriano Cordova <[email protected]>
---
 lib/efi_loader/efi_capsule.c |  9 +++--
 lib/efi_loader/fwu_arm_psa.c | 72 ++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index fe14eebf867..26cd5ccd636 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -553,10 +553,12 @@ static efi_status_t efi_capsule_update_firmware(
        uint update_index;
        bool fw_accept_os;
 
-       if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) {
+       if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE) || 
IS_ENABLED(CONFIG_FWU_ARM_PSA)) {
                if (fwu_empty_capsule(capsule_data)) {
                        if (fwu_empty_capsule_checks_pass()) {
-                               return fwu_empty_capsule_process(capsule_data);
+                               return !IS_ENABLED(CONFIG_FWU_ARM_PSA) ?
+                                       fwu_empty_capsule_process(capsule_data) 
:
+                                       0;
                        } else {
                                log_err("FWU empty capsule checks failed. 
Cannot start update\n");
                                return EFI_INVALID_PARAMETER;
@@ -1374,7 +1376,8 @@ efi_status_t efi_launch_capsules(void)
 
        efi_capsule_scan_done();
 
-       if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) {
+       if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE) &&
+           !IS_ENABLED(CONFIG_FWU_ARM_PSA)) {
                if (capsule_update == true && update_status == true) {
                        ret = fwu_post_update_process(fw_accept_os);
                } else if (capsule_update == true && update_status == false) {
diff --git a/lib/efi_loader/fwu_arm_psa.c b/lib/efi_loader/fwu_arm_psa.c
index 83c876d5d8a..40e0611adb9 100644
--- a/lib/efi_loader/fwu_arm_psa.c
+++ b/lib/efi_loader/fwu_arm_psa.c
@@ -25,6 +25,7 @@ static u64 g_max_payload_size;
 static u8 g_fwu_version_major;
 static u8 g_fwu_version_minor;
 static bool g_fwu_initialized;
+static bool g_in_trial;
 static struct fwu_image_directory *g_fwu_cached_directory;
 efi_guid_t g_update_guid[CONFIG_FWU_NUM_IMAGES_PER_BANK];
 
@@ -1225,6 +1226,77 @@ efi_status_t efi_fill_image_desc_array(efi_uintn_t 
*image_info_size,
        return EFI_SUCCESS;
 }
 
+/**
+ * fwu_update_checks_pass() - Check if FWU update can be done
+ *
+ * Check if the FWU update can be executed. The updates are
+ * allowed only when the platform is not in Trial State
+ *
+ * Return: 1 if OK, 0 if checks do not pass
+ *
+ */
+u8 fwu_update_checks_pass(void)
+{
+       return !g_in_trial;
+}
+
+/**
+ * fwu_empty_capsule_checks_pass() - Check if empty capsule can be processed
+ *
+ * Check if the empty capsule can be processed to either accept or revert
+ * an earlier executed update. The empty capsules need to be processed
+ * only when the platform is in Trial State
+ *
+ * Return: 1 if OK, 0 if not to be allowed
+ *
+ */
+u8 fwu_empty_capsule_checks_pass(void)
+{
+       return g_in_trial;
+}
+
+/**
+ * fwu_get_active_index() - Return a dummy active bank index
+ * @active_idx: Pointer to the dummy active bank index
+ *
+ * When U-Boot takes the role of Update Client, the active bank is managed
+ * by the Update Agent in the Secure World. This active index is therefore
+ * not required and a dummy value is returned and subsequently ignored
+ * in capsule handling, fwu_clear_accept_image() and fwu_accept_image().
+ *
+ * Return: EFI_SUCCESS if OK, -ve on error
+ *
+ */
+int fwu_get_active_index(uint *active_idx)
+{
+       if (!active_idx)
+               return -EINVAL;
+
+       *active_idx = 0x0;
+       return EFI_SUCCESS;
+}
+
+/**
+ * fwu_plat_get_update_index() - Return a dummy update bank index
+ * @update_idx: Pointer to the dummy update bank index
+ *
+ * When U-Boot takes the role of Update Client, the update bank is managed
+ * by the Update Agent in the Secure World. This update index is therefore
+ * not required and a dummy value is returned and subsequently ignored
+ * in capsule handling, fwu_clear_accept_image() and fwu_accept_image().
+ *
+ * Return: EFI_SUCCESS if OK, -ve on error
+ *
+ */
+int fwu_plat_get_update_index(uint *update_idx)
+{
+       if (!update_idx)
+               return -EINVAL;
+
+       *update_idx = 0x0;
+       return EFI_SUCCESS;
+}
+
 /**
  * fwu_accept_image() - Dummy hook for accepting an image
  * @img_type_id: Unused image type GUID
-- 
2.43.0

Reply via email to