mbox series

[v3,0/8] qcom: implement capsule updates

Message ID 20240603-b4-qcom-capsule-updates-v3-0-fe2e083289ec@linaro.org
Headers show
Series qcom: implement capsule updates | expand

Message

Caleb Connolly June 3, 2024, 12:49 p.m. UTC
Hook up support for capsule updates loaded from disk on Qualcomm
platforms.

Most Qualcomm devices have an A/B partition layout, with most partitions
duplicated. The metadata on which slot is active is stored in the GPT
headers in the vendor-specific attribute bits of each partition.

Add support for reading this attributes via the disk_partition struct
and using them to determine which boot partition U-Boot is flashed to
and generate the appropriate DFU string.

This logic is gated behind a check to ensure that U-Boot is actually
being chainloaded and not run via some other mechanism.

SCSI support for most Qualcomm platforms is not yet enabled upstream,
but will follow in future patches.

This series enables capsule updates on the RB2, however [1] is required
for it to work properly (as otherwise MMC won't be available).

[1]: https://lore.kernel.org/u-boot/20240527-b4-clk-stub-v2-0-29013855e343@linaro.org/

To: Tom Rini <trini@konsulko.com>
To: Simon Glass <sjg@chromium.org>
To: Lukasz Majewski <lukma@denx.de>
To: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Caleb Connolly <caleb.connolly@linaro.org>
To: Neil Armstrong <neil.armstrong@linaro.org>
To: Sumit Garg <sumit.garg@linaro.org>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: u-boot@lists.denx.de
Cc: u-boot-qcom@groups.io

Changes in v3:
- Address comments in scsi dfu support
- enable CONFIG_DFU_SCSI for qcom
- Link to v2: https://lore.kernel.org/r/20240527-b4-qcom-capsule-updates-v2-0-47583d7ad428@linaro.org

Changes in v2:
- Add qcom capsule update support patches
- Link to v1: https://lore.kernel.org/r/20240409-b4-dfu-scsi-v1-0-3e1441a60376@linaro.org

---
Caleb Connolly (8):
      dfu: add scsi backend
      disk: expose partition type flags
      mmc: msm_sdhci: work around a bug when writing
      mach-snapdragon: implement capsule update support
      qcom_defconfig: savedefconfig
      mach-snapdragon: use SYSRESET_PSCI
      mach-snapdragon: bump up heap size
      qcom_defconfig: enable capsule update support

 arch/arm/Kconfig                          |   2 +
 arch/arm/mach-snapdragon/Kconfig          |   3 +
 arch/arm/mach-snapdragon/Makefile         |   1 +
 arch/arm/mach-snapdragon/board.c          |   8 +-
 arch/arm/mach-snapdragon/capsule_update.c | 147 ++++++++++
 arch/arm/mach-snapdragon/qcom-priv.h      |   6 +
 configs/qcom_defconfig                    |  19 +-
 disk/part_efi.c                           |   1 +
 doc/usage/dfu.rst                         |  32 +++
 drivers/dfu/Kconfig                       |   7 +
 drivers/dfu/Makefile                      |   1 +
 drivers/dfu/dfu.c                         |   5 +-
 drivers/dfu/dfu_scsi.c                    | 435 ++++++++++++++++++++++++++++++
 drivers/mmc/msm_sdhci.c                   |   7 +
 include/configs/qcom.h                    |   5 +
 include/dfu.h                             |  26 ++
 include/part.h                            |   1 +
 17 files changed, 695 insertions(+), 11 deletions(-)
---
change-id: 20240523-b4-qcom-capsule-updates-ea2e4f8f0ff0
base-commit: 5d8881a0801241d68701e8644d495f1d535506f0

// Caleb (they/them)

Comments

Sumit Garg June 5, 2024, 5:31 a.m. UTC | #1
Hi Caleb,

On Mon, 3 Jun 2024 at 18:19, Caleb Connolly <caleb.connolly@linaro.org> wrote:
>
> Hook up support for capsule updates loaded from disk on Qualcomm
> platforms.
>
> Most Qualcomm devices have an A/B partition layout, with most partitions
> duplicated. The metadata on which slot is active is stored in the GPT
> headers in the vendor-specific attribute bits of each partition.

It's good to see capsule updates support coming up for Qualcomm
platforms. AFAICS, with this series we only update U-Boot on the
current active partition. IOW, real A/B support is still not
supported. Do you think it is possible for U-Boot to update metadata
in GPT headers and for proprietary bootloaders to pick up the U-Boot
from the updated partition?

-Sumit

>
> Add support for reading this attributes via the disk_partition struct
> and using them to determine which boot partition U-Boot is flashed to
> and generate the appropriate DFU string.
>
> This logic is gated behind a check to ensure that U-Boot is actually
> being chainloaded and not run via some other mechanism.
>
> SCSI support for most Qualcomm platforms is not yet enabled upstream,
> but will follow in future patches.
>
> This series enables capsule updates on the RB2, however [1] is required
> for it to work properly (as otherwise MMC won't be available).
>
> [1]: https://lore.kernel.org/u-boot/20240527-b4-clk-stub-v2-0-29013855e343@linaro.org/
>
> To: Tom Rini <trini@konsulko.com>
> To: Simon Glass <sjg@chromium.org>
> To: Lukasz Majewski <lukma@denx.de>
> To: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> To: Caleb Connolly <caleb.connolly@linaro.org>
> To: Neil Armstrong <neil.armstrong@linaro.org>
> To: Sumit Garg <sumit.garg@linaro.org>
> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Cc: u-boot@lists.denx.de
> Cc: u-boot-qcom@groups.io
>
> Changes in v3:
> - Address comments in scsi dfu support
> - enable CONFIG_DFU_SCSI for qcom
> - Link to v2: https://lore.kernel.org/r/20240527-b4-qcom-capsule-updates-v2-0-47583d7ad428@linaro.org
>
> Changes in v2:
> - Add qcom capsule update support patches
> - Link to v1: https://lore.kernel.org/r/20240409-b4-dfu-scsi-v1-0-3e1441a60376@linaro.org
>
> ---
> Caleb Connolly (8):
>       dfu: add scsi backend
>       disk: expose partition type flags
>       mmc: msm_sdhci: work around a bug when writing
>       mach-snapdragon: implement capsule update support
>       qcom_defconfig: savedefconfig
>       mach-snapdragon: use SYSRESET_PSCI
>       mach-snapdragon: bump up heap size
>       qcom_defconfig: enable capsule update support
>
>  arch/arm/Kconfig                          |   2 +
>  arch/arm/mach-snapdragon/Kconfig          |   3 +
>  arch/arm/mach-snapdragon/Makefile         |   1 +
>  arch/arm/mach-snapdragon/board.c          |   8 +-
>  arch/arm/mach-snapdragon/capsule_update.c | 147 ++++++++++
>  arch/arm/mach-snapdragon/qcom-priv.h      |   6 +
>  configs/qcom_defconfig                    |  19 +-
>  disk/part_efi.c                           |   1 +
>  doc/usage/dfu.rst                         |  32 +++
>  drivers/dfu/Kconfig                       |   7 +
>  drivers/dfu/Makefile                      |   1 +
>  drivers/dfu/dfu.c                         |   5 +-
>  drivers/dfu/dfu_scsi.c                    | 435 ++++++++++++++++++++++++++++++
>  drivers/mmc/msm_sdhci.c                   |   7 +
>  include/configs/qcom.h                    |   5 +
>  include/dfu.h                             |  26 ++
>  include/part.h                            |   1 +
>  17 files changed, 695 insertions(+), 11 deletions(-)
> ---
> change-id: 20240523-b4-qcom-capsule-updates-ea2e4f8f0ff0
> base-commit: 5d8881a0801241d68701e8644d495f1d535506f0
>
> // Caleb (they/them)
>
Caleb Connolly June 5, 2024, 12:42 p.m. UTC | #2
Hi Sumit,

On 05/06/2024 07:31, Sumit Garg wrote:
> Hi Caleb,
> 
> On Mon, 3 Jun 2024 at 18:19, Caleb Connolly <caleb.connolly@linaro.org> wrote:
>>
>> Hook up support for capsule updates loaded from disk on Qualcomm
>> platforms.
>>
>> Most Qualcomm devices have an A/B partition layout, with most partitions
>> duplicated. The metadata on which slot is active is stored in the GPT
>> headers in the vendor-specific attribute bits of each partition.
> 
> It's good to see capsule updates support coming up for Qualcomm
> platforms. AFAICS, with this series we only update U-Boot on the
> current active partition. IOW, real A/B support is still not
> supported. Do you think it is possible for U-Boot to update metadata
> in GPT headers and for proprietary bootloaders to pick up the U-Boot
> from the updated partition?

Yes this would be possible, I have some WIP patches to let us modify the 
slot attribute bits and write back the header.

The reason I haven't implement A/B is because we don't support it from 
the OS level on any of the boards I work on. We often patch ABL to 
disable or skip the slot logic and flash a partition table without 
slots. It also unlocks a bunch of additional complexity...

This isn't super high on my todo list but I'd be happy to help if 
someone wants to enable this functionality. We'd need:

1. Upstream support for modifying the GPT (see my PoC at [1] and [2]).
2. Logic to configure flashing the active or inactive slot

This logic would have to run after the capsule update, I don't know if 
there is currently a way to add a callback after the update.

If we enable updating other images (like XBL, hyp, tz, etc), we would 
need to either agree that a capsule update would have to update ALL 
partitions, or implement logic to copy over partitions that weren't 
flashed to the other slot.

[1]: 
https://git.codelinaro.org/linaro/qcomlt/u-boot/-/commit/34d3de6f79550527746303e0bf6337fa37e31fe5

[2]: 
https://git.codelinaro.org/linaro/qcomlt/u-boot/-/commit/656d9e816bef85e586460a999cc7874255be9f1d
> 
> -Sumit
> 
>>
>> Add support for reading this attributes via the disk_partition struct
>> and using them to determine which boot partition U-Boot is flashed to
>> and generate the appropriate DFU string.
>>
>> This logic is gated behind a check to ensure that U-Boot is actually
>> being chainloaded and not run via some other mechanism.
>>
>> SCSI support for most Qualcomm platforms is not yet enabled upstream,
>> but will follow in future patches.
>>
>> This series enables capsule updates on the RB2, however [1] is required
>> for it to work properly (as otherwise MMC won't be available).
>>
>> [1]: https://lore.kernel.org/u-boot/20240527-b4-clk-stub-v2-0-29013855e343@linaro.org/
>>
>> To: Tom Rini <trini@konsulko.com>
>> To: Simon Glass <sjg@chromium.org>
>> To: Lukasz Majewski <lukma@denx.de>
>> To: Mattijs Korpershoek <mkorpershoek@baylibre.com>
>> To: Caleb Connolly <caleb.connolly@linaro.org>
>> To: Neil Armstrong <neil.armstrong@linaro.org>
>> To: Sumit Garg <sumit.garg@linaro.org>
>> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
>> Cc: u-boot@lists.denx.de
>> Cc: u-boot-qcom@groups.io
>>
>> Changes in v3:
>> - Address comments in scsi dfu support
>> - enable CONFIG_DFU_SCSI for qcom
>> - Link to v2: https://lore.kernel.org/r/20240527-b4-qcom-capsule-updates-v2-0-47583d7ad428@linaro.org
>>
>> Changes in v2:
>> - Add qcom capsule update support patches
>> - Link to v1: https://lore.kernel.org/r/20240409-b4-dfu-scsi-v1-0-3e1441a60376@linaro.org
>>
>> ---
>> Caleb Connolly (8):
>>        dfu: add scsi backend
>>        disk: expose partition type flags
>>        mmc: msm_sdhci: work around a bug when writing
>>        mach-snapdragon: implement capsule update support
>>        qcom_defconfig: savedefconfig
>>        mach-snapdragon: use SYSRESET_PSCI
>>        mach-snapdragon: bump up heap size
>>        qcom_defconfig: enable capsule update support
>>
>>   arch/arm/Kconfig                          |   2 +
>>   arch/arm/mach-snapdragon/Kconfig          |   3 +
>>   arch/arm/mach-snapdragon/Makefile         |   1 +
>>   arch/arm/mach-snapdragon/board.c          |   8 +-
>>   arch/arm/mach-snapdragon/capsule_update.c | 147 ++++++++++
>>   arch/arm/mach-snapdragon/qcom-priv.h      |   6 +
>>   configs/qcom_defconfig                    |  19 +-
>>   disk/part_efi.c                           |   1 +
>>   doc/usage/dfu.rst                         |  32 +++
>>   drivers/dfu/Kconfig                       |   7 +
>>   drivers/dfu/Makefile                      |   1 +
>>   drivers/dfu/dfu.c                         |   5 +-
>>   drivers/dfu/dfu_scsi.c                    | 435 ++++++++++++++++++++++++++++++
>>   drivers/mmc/msm_sdhci.c                   |   7 +
>>   include/configs/qcom.h                    |   5 +
>>   include/dfu.h                             |  26 ++
>>   include/part.h                            |   1 +
>>   17 files changed, 695 insertions(+), 11 deletions(-)
>> ---
>> change-id: 20240523-b4-qcom-capsule-updates-ea2e4f8f0ff0
>> base-commit: 5d8881a0801241d68701e8644d495f1d535506f0
>>
>> // Caleb (they/them)
>>
Sumit Garg June 6, 2024, 7:34 a.m. UTC | #3
On Wed, 5 Jun 2024 at 18:12, Caleb Connolly <caleb.connolly@linaro.org> wrote:
>
> Hi Sumit,
>
> On 05/06/2024 07:31, Sumit Garg wrote:
> > Hi Caleb,
> >
> > On Mon, 3 Jun 2024 at 18:19, Caleb Connolly <caleb.connolly@linaro.org> wrote:
> >>
> >> Hook up support for capsule updates loaded from disk on Qualcomm
> >> platforms.
> >>
> >> Most Qualcomm devices have an A/B partition layout, with most partitions
> >> duplicated. The metadata on which slot is active is stored in the GPT
> >> headers in the vendor-specific attribute bits of each partition.
> >
> > It's good to see capsule updates support coming up for Qualcomm
> > platforms. AFAICS, with this series we only update U-Boot on the
> > current active partition. IOW, real A/B support is still not
> > supported. Do you think it is possible for U-Boot to update metadata
> > in GPT headers and for proprietary bootloaders to pick up the U-Boot
> > from the updated partition?
>
> Yes this would be possible, I have some WIP patches to let us modify the
> slot attribute bits and write back the header.

Nice to hear that possibility.

>
> The reason I haven't implement A/B is because we don't support it from
> the OS level on any of the boards I work on. We often patch ABL to
> disable or skip the slot logic and flash a partition table without
> slots. It also unlocks a bunch of additional complexity...

Please have a look at an alternative FWU Multi Bank Updates [1].
AFAIK, the UEFI capsules updates feature from the OS point of view
remains transparent. It's more about how those capsules are
interpreted with the logic to update the inactive partition and
metadata such that subsequent boot uses the updated firmware.

[1] https://docs.u-boot.org/en/latest/develop/uefi/fwu_updates.html

>
> This isn't super high on my todo list but I'd be happy to help if
> someone wants to enable this functionality. We'd need:
>
> 1. Upstream support for modifying the GPT (see my PoC at [1] and [2]).
> 2. Logic to configure flashing the active or inactive slot
>
> This logic would have to run after the capsule update, I don't know if
> there is currently a way to add a callback after the update.
>
> If we enable updating other images (like XBL, hyp, tz, etc), we would
> need to either agree that a capsule update would have to update ALL
> partitions, or implement logic to copy over partitions that weren't
> flashed to the other slot.

I would be interested to see how we can plug Qcom specific pieces
underneath in order to have multi bank updates. However, this patchset
is still usable in its current form. We can later add the real A/B
functionality.

Apart from patch #4 where we are still discussing the finer details,
feel free to add:

Acked-by: Sumit Garg <sumit.garg@linaro.org>

-Sumit

>
> [1]:
> https://git.codelinaro.org/linaro/qcomlt/u-boot/-/commit/34d3de6f79550527746303e0bf6337fa37e31fe5
>
> [2]:
> https://git.codelinaro.org/linaro/qcomlt/u-boot/-/commit/656d9e816bef85e586460a999cc7874255be9f1d