Hi Caleb, On Mon, 3 Jun 2024 at 15:49, Caleb Connolly <caleb.conno...@linaro.org> wrote: > > Qualcomm boards flash U-Boot to the boot partition, implement support > for determining which slot U-Boot is running from and finding the > correct boot partition for that slot and configuring the appropriate DFU > string. > > For now this only supports boards with SCSI/UFS storage where U-Boot is > flashed to the boot partition, and only U-Boot itself is updated. In the > future we may also support updating additional firmware components (tz, > hyp, xbl) as well as having U-Boot installed to other partitions (e.g. > as a first-stage bootloader). > > Signed-off-by: Caleb Connolly <caleb.conno...@linaro.org> > --- > arch/arm/mach-snapdragon/Makefile | 1 + > arch/arm/mach-snapdragon/board.c | 3 + > arch/arm/mach-snapdragon/capsule_update.c | 147 > ++++++++++++++++++++++++++++++ > arch/arm/mach-snapdragon/qcom-priv.h | 6 ++ > include/configs/qcom.h | 5 + > 5 files changed, 162 insertions(+) > > diff --git a/arch/arm/mach-snapdragon/Makefile > b/arch/arm/mach-snapdragon/Makefile > index 7a4495c8108f..343e825c6fdd 100644 > --- a/arch/arm/mach-snapdragon/Makefile > +++ b/arch/arm/mach-snapdragon/Makefile > @@ -2,5 +2,6 @@ > # > # (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikow...@gmail.com> > > obj-y += board.o > +obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += capsule_update.o > obj-$(CONFIG_OF_LIVE) += of_fixup.o > diff --git a/arch/arm/mach-snapdragon/board.c > b/arch/arm/mach-snapdragon/board.c > index b439a19ec7eb..c4a3394706e6 100644 > --- a/arch/arm/mach-snapdragon/board.c > +++ b/arch/arm/mach-snapdragon/board.c > @@ -299,8 +299,11 @@ int board_late_init(void) > > configure_env(); > qcom_late_init(); > > + /* Configure the dfu_string for capsule updates */ > + qcom_configure_capsule_updates(); > + > return 0; > } > > static void build_mem_map(void) > diff --git a/arch/arm/mach-snapdragon/capsule_update.c > b/arch/arm/mach-snapdragon/capsule_update.c > new file mode 100644 > index 000000000000..505f5bf5ae07 > --- /dev/null > +++ b/arch/arm/mach-snapdragon/capsule_update.c > @@ -0,0 +1,147 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Common initialisation for Qualcomm Snapdragon boards.
initialization > + * > + * Copyright (c) 2024 Linaro Ltd. > + * Author: Caleb Connolly <caleb.conno...@linaro.org> > + */ > + > +#define pr_fmt(fmt) "QCOM-FMP: " fmt > + > +#include <dm/device.h> > +#include <dm/uclass.h> > +#include <efi.h> > +#include <efi_loader.h> > +#include <malloc.h> > +#include <scsi.h> > +#include <part.h> > +#include <linux/err.h> > + > +#include "qcom-priv.h" > + > +struct efi_fw_image fw_images[] = { > + { > + .image_type_id = QUALCOMM_UBOOT_BOOT_IMAGE_GUID, > + .fw_name = u"QUALCOMM-UBOOT", > + .image_index = 1, > + }, > +}; > + > +struct efi_capsule_update_info update_info = { > + /* Filled in by configure_dfu_string() */ > + .dfu_string = NULL, > + .num_images = ARRAY_SIZE(fw_images), > + .images = fw_images, > +}; > + > +/* LSB first */ > +struct part_slot_status { > + u16: 2; > + u16 active : 1; > + u16: 3; > + u16 successful : 1; > + u16 unbootable : 1; > + u16 tries_remaining : 4; > +}; This is part of their first-stage boot loader and can't change right? [...] > +/** > + * qcom_configure_capsule_updates() - Configure the DFU string for capsule > updates > + * > + * U-Boot is flashed to the boot partition on Qualcomm boards. In most cases > there > + * are two boot partitions, boot_a and boot_b. As we don't currently support > doing > + * full A/B updates, we only support updating the currently active boot > partition. > + * > + * So we need to find the current slot suffix and the associated boot > partition. > + * We do this by looking for the boot partition that has the 'active' flag > set > + * in the GPT partition vendor attribute bits. > + */ > +void qcom_configure_capsule_updates(void) > +{ > + struct blk_desc *desc; > + int ret = 0, partnum = -1, devnum; > + static char dfu_string[32] = { 0 }; Use PART_NAME_LEN here, since that's the length struct disk_partition defines (and the one you end up copying) > + char name[32]; /* GPT partition name */ > + char *partname = "boot"; > + struct udevice *dev = NULL; > + > + /* > + * There is currently no good way to check how U-Boot is booting, but > we have > + * a few hueristics, like here checking if our DTB has a kaslr-seed > specified heuristics > + * will tell us if we were chainloaded by another bootloader. > + * FIXME: we should do this check once and use some proper API to > expose the data. > + */ > + if (!ofnode_has_property(ofnode_path("/chosen"), "kaslr-seed")) { [...] Acked-by: Ilias Apalodimas <ilias.apalodi...@linaro.org>