From patchwork Thu Jan 20 15:31:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533551 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1677599imu; Thu, 20 Jan 2022 07:31:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJytwv4pxYVz3jtHuoxEiHEuecA1s97YGxVkZMf57M7RmVZ2dO4hYxi9g7YFW//yJbemRIKX X-Received: by 2002:a50:8a94:: with SMTP id j20mr12938405edj.388.1642692700188; Thu, 20 Jan 2022 07:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692700; cv=none; d=google.com; s=arc-20160816; b=uLaG4Qd0btSsKcwupR80UEQjhU5u1d+ThuOajxONOokiy3fgbVomkoh42HWt1+8zoC IDokT9Q+w6mvZmLT2CY5n+gaxH9cekMCkClHrAu1cC5byoBeSB1sBLBosHGSSsXYZLqE jPzPQLOuqlLJAWja8nRqCTIaRIKXfMP1OqIS6XUxff3oObzfcxjfsVldojfFuAhHDIyj gbUqLHM+nhDfh/TCE4UA6+L+GH++vAZdgAGna4vuWNCX3E6Udp0OrVyVYsJKHq2xZ3/T gG5h0OSTq0rf4oZqsu5LFcAv4GPe3jAofiT39n9kQt8qEtLncAUlfKReKnUV8HjR+AQx hGJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=utOgsCpoG5dEgjvj/Dasjwnba7V0bRYQw5FAVA77OVY=; b=rhQOV1VwiS+eTMQSJUDyQuJdFkx0rg1UrvLchgFVKkBVPTNMdQ8kJDlDgVgJjzkd4d gX6Fa2BP6Pt54SxivsD5VQHejZTE5YmqhBvsY7qvNc0NVtZSbLG2+5AhMOwcvBCRU9GU niRUBoE7rDM3P/LYqvGGqwoiaxr2LttAO1ZZYlr9VxEl806QTou/u5XbxfWZshnfhm/6 oUrMqPISrAXUEQYiwC4ZK0r7jjFXy+6FCBUJhW7ls9I23T/0IPAJhsK+dDKvspmSR+4Z ZTHj/mx6F2jiN2ea2E8BVFIAdh0UcD/tkCGOwl1ynrxV8QfIMFORUQsRdfXm1r2lpr9G 35TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tTqGSkzC; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id b14si2145137edw.116.2022.01.20.07.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:40 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tTqGSkzC; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C39EC838E2; Thu, 20 Jan 2022 16:31:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="tTqGSkzC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8DD0F838C4; Thu, 20 Jan 2022 16:31:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 42499838E3 for ; Thu, 20 Jan 2022 16:31:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pj1-x1030.google.com with SMTP id d15-20020a17090a110f00b001b4e7d27474so6097579pja.2 for ; Thu, 20 Jan 2022 07:31:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=utOgsCpoG5dEgjvj/Dasjwnba7V0bRYQw5FAVA77OVY=; b=tTqGSkzCrj0Bhj8H+12IKrxfRAf7zusN9doZ/xP8bczBIahKgmga7Y5+S8McgzPRdm bLl/G/Di3lcUY74bLuwNvbkDU5zzKPd7lsvonoHczO5dYwd70AF4Zk00686f4Pfz2BvO 5apd4ouADD/QqQdOBVZPReaPKj6tAIQgJsNajvECMPS81LyVmtTk7/Q1N/KWKTtY1YBY UGqVVWEt5wzghznIlQCozPPXc8oL3UCscvkv0Gfsgngiq/PUR+vV9lWdLEGOeLnom52T 6BC6w1itmuHYqa0XYHASIZva//CQlhrJDfUJUzuqbgxaTvcgr0q6kxQCz+g1JBORjrq0 zL9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=utOgsCpoG5dEgjvj/Dasjwnba7V0bRYQw5FAVA77OVY=; b=m0Uvg9arag3xnnT0m3T9KvaBqEiuNZ57pZH9CX0dc0bS76wDCJd23ftTupPLxU+fY0 KOBmDZn7mInFPSVPmm30scRxIkPCr89DLO6OUi6FFS89s4gfPl3msBYr5E/iJyy/MQOM FFgOcz0GMie32kMb+aVCZ8sD3R9priGA1wnQX0zYzCd6HIrfcS/HBuiqcpffwaC60yR3 ujbZcYcmLqR6hCUai5NMWyi8IeZa11Qs+JnIlOOZb5o/qYqtWayvoDmZcTj3IQhXK7k3 ibg0lKI8dA0eFiv/u4MtWIXMGScfjnPLKAZ8IqrpoWORFLbMFpV56rxcvFUqEozutwOB 9FCg== X-Gm-Message-State: AOAM530M8GlKPenVdx3rjW9v5y9obSaYGWMOKHcsq1dAtUI63ouoyywy EdKnEhO1nrbqT3PeoThRywmilxLJX+bPrA== X-Received: by 2002:a17:90a:de08:: with SMTP id m8mr11376925pjv.102.1642692685203; Thu, 20 Jan 2022 07:31:25 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id s7sm4128650pfu.133.2022.01.20.07.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:31:24 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 12/14] FWU: synquacer: Add FWU Multi bank update support for DeveloperBox Date: Fri, 21 Jan 2022 00:31:20 +0900 Message-Id: <164269268052.39378.8998928319603683374.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean The DeveloperBox platform can support the FWU Multi bank update. SCP firmware will switch the boot mode by DSW3-4 and load the Multi bank update supported TF-A BL2 from 0x600000 offset on the SPI flash. Thus it can co-exist with the legacy boot mode (legacy U-Boot or EDK2). Signed-off-by: Masami Hiramatsu --- board/socionext/developerbox/Kconfig | 19 ++++ board/socionext/developerbox/Makefile | 1 board/socionext/developerbox/fwu_plat.c | 158 +++++++++++++++++++++++++++++++ include/configs/synquacer.h | 10 ++ include/efi_loader.h | 3 + lib/efi_loader/efi_firmware.c | 14 +-- 6 files changed, 198 insertions(+), 7 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c diff --git a/board/socionext/developerbox/Kconfig b/board/socionext/developerbox/Kconfig index c181d26a44..4e2c341aad 100644 --- a/board/socionext/developerbox/Kconfig +++ b/board/socionext/developerbox/Kconfig @@ -32,4 +32,23 @@ config SYS_CONFIG_NAME default "synquacer" endif + +config FWU_MULTI_BANK_UPDATE + select FWU_MULTI_BANK_UPDATE_SF + +config FWU_MULTI_BANK_UPDATE_SF + select DM_SPI_FLASH + +config FWU_NUM_BANKS + default 6 + +config FWU_NUM_IMAGES_PER_BANK + default 1 + +config FWU_SF_PRIMARY_MDATA_OFFSET + default 0x500000 + +config FWU_SF_SECONDARY_MDATA_OFFSET + default 0x520000 + endif diff --git a/board/socionext/developerbox/Makefile b/board/socionext/developerbox/Makefile index 4a46de995a..15cce9c57e 100644 --- a/board/socionext/developerbox/Makefile +++ b/board/socionext/developerbox/Makefile @@ -7,3 +7,4 @@ # obj-y := developerbox.o +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE_SF) += fwu_plat.o diff --git a/board/socionext/developerbox/fwu_plat.c b/board/socionext/developerbox/fwu_plat.c new file mode 100644 index 0000000000..dbb814f1fd --- /dev/null +++ b/board/socionext/developerbox/fwu_plat.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2021, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/* SPI Flash accessors */ +static struct spi_flash *plat_spi_flash; + +static int __plat_sf_get_flash(void) +{ + struct udevice *new; + int ret; + + //TODO: use CONFIG_FWU_SPI_* + ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, + CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE, + &new); + if (ret) + return ret; + + plat_spi_flash = dev_get_uclass_priv(new); + return 0; +} + +static int plat_sf_get_flash(struct spi_flash **flash) +{ + int ret = 0; + + if (!plat_spi_flash) + ret = __plat_sf_get_flash(); + + *flash = plat_spi_flash; + + return ret; +} + +static int sf_load_data(u32 offs, u32 size, void **data) +{ + struct spi_flash *flash; + int ret; + + ret = plat_sf_get_flash(&flash); + if (ret < 0) + return ret; + + *data = memalign(ARCH_DMA_MINALIGN, size); + if (!*data) + return -ENOMEM; + + ret = spi_flash_read(flash, offs, size, *data); + if (ret < 0) { + free(*data); + *data = NULL; + } + + return ret; +} + +/* Platform dependent GUIDs */ + +/* The GUID for the SNI FIP image type GUID */ +#define FWU_IMAGE_TYPE_DEVBOX_FIP_GUID \ + EFI_GUID(0x7d6dc310, 0x52ca, 0x43b8, 0xb7, 0xb9, \ + 0xf9, 0xd6, 0xc5, 0x01, 0xd1, 0x08) + +#define PLAT_METADATA_OFFSET 0x510000 +#define PLAT_METADATA_SIZE (sizeof(struct devbox_metadata)) + +struct __packed devbox_metadata { + u32 boot_index; + u32 boot_count; + u32 invert_dual; +} *devbox_plat_metadata; + +static const efi_guid_t devbox_fip_image_type_guid = FWU_IMAGE_TYPE_DEVBOX_FIP_GUID; + +int fwu_plat_get_image_alt_num(efi_guid_t image_type_id, u32 update_bank, + int *alt_no) +{ + /* DeveloperBox FWU Multi bank only supports FIP image. */ + if (guidcmp(&image_type_id, &devbox_fip_image_type_guid)) + return -EOPNOTSUPP; + + /* + * DeveloperBox FWU expects Bank:Image = 1:1, and the dfu_alt_info + * only has the entries for banks. Thus the alt_no should be equal + * to the update_bank. + */ + update_bank %= CONFIG_FWU_NUM_BANKS; + *alt_no = update_bank; + + return 0; +} + +/* SPI flash doesn't have GPT, and it's not blk device */ +int fwu_plat_fill_partition_guids(efi_guid_t **part_guid_arr) +{ + efi_status_t ret; + + free(*part_guid_arr); + + ret = efi_fill_part_guid_array(&devbox_fip_image_type_guid, part_guid_arr); + return (ret != EFI_SUCCESS) ? -ENOMEM : 0; +} + +/* TBD: add a usage counter for wear leveling */ +int fwu_plat_get_update_index(u32 *update_idx) +{ + int ret; + u32 active_idx; + + ret = fwu_get_active_index(&active_idx); + + if (ret < 0) + return -1; + + *update_idx = (active_idx + 1) % CONFIG_FWU_NUM_BANKS; + + return ret; +} + +static int devbox_load_plat_metadata(void) +{ + if (devbox_plat_metadata) + return 0; + + return sf_load_data(PLAT_METADATA_OFFSET, PLAT_METADATA_SIZE, + (void **)&devbox_plat_metadata); +} + +void fwu_plat_get_bootidx(void *boot_idx) +{ + u32 *bootidx = boot_idx; + + if (devbox_load_plat_metadata() < 0) + *bootidx = 0; + else + *bootidx = devbox_plat_metadata->boot_index; +} + +struct fwu_mdata_ops *get_plat_fwu_mdata_ops(void) +{ + return fwu_sf_get_fwu_mdata_ops(); +} + diff --git a/include/configs/synquacer.h b/include/configs/synquacer.h index 6d67bd2af5..f859237550 100644 --- a/include/configs/synquacer.h +++ b/include/configs/synquacer.h @@ -47,8 +47,18 @@ /* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */ +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ + "mtd nor1=bank0 raw 600000 400000;" \ + "bank1 raw a00000 400000;" \ + "bank2 raw e00000 400000;" \ + "bank3 raw 1200000 400000;" \ + "bank4 raw 1600000 400000;" \ + "bank5 raw 1a00000 400000\0" +#else #define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ "mtd nor1=fip.bin raw 600000 400000\0" +#endif /* Distro boot settings */ #ifndef CONFIG_SPL_BUILD diff --git a/include/efi_loader.h b/include/efi_loader.h index f20d361876..d6dc173feb 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -953,6 +953,9 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n); u16 *efi_create_indexed_name(u16 *buffer, size_t buffer_size, const char *name, unsigned int index); +efi_status_t efi_fill_part_guid_array(const efi_guid_t *guid, + efi_guid_t **part_guid_arr); + extern const struct efi_firmware_management_protocol efi_fmp_fit; extern const struct efi_firmware_management_protocol efi_fmp_raw; diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 107f0cb074..c100be35d3 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -97,8 +97,8 @@ efi_status_t EFIAPI efi_firmware_set_package_info_unsupported( return EFI_EXIT(EFI_UNSUPPORTED); } -static efi_status_t fill_part_guid_array(const efi_guid_t *guid, - efi_guid_t **part_guid_arr) +efi_status_t efi_fill_part_guid_array(const efi_guid_t *guid, + efi_guid_t **part_guid_arr) { int i; int dfu_num = 0; @@ -309,8 +309,8 @@ efi_status_t EFIAPI efi_firmware_fit_get_image_info( !descriptor_size || !package_version || !package_version_name)) return EFI_EXIT(EFI_INVALID_PARAMETER); - ret = fill_part_guid_array(&efi_firmware_image_type_uboot_fit, - &part_guid_arr); + ret = efi_fill_part_guid_array(&efi_firmware_image_type_uboot_fit, + &part_guid_arr); if (ret != EFI_SUCCESS) goto out; @@ -429,7 +429,7 @@ efi_status_t EFIAPI efi_firmware_raw_get_image_info( return EFI_EXIT(EFI_INVALID_PARAMETER); if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { - ret = fill_part_guid_array(&null_guid, &part_guid_arr); + ret = efi_fill_part_guid_array(&null_guid, &part_guid_arr); if (ret != EFI_SUCCESS) goto out; @@ -444,8 +444,8 @@ efi_status_t EFIAPI efi_firmware_raw_get_image_info( goto out; } } else { - ret = fill_part_guid_array(&efi_firmware_image_type_uboot_raw, - &part_guid_arr); + ret = efi_fill_part_guid_array(&efi_firmware_image_type_uboot_raw, + &part_guid_arr); if (ret != EFI_SUCCESS) goto out; }