From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Sam Protsenko <semen.protsenko@linaro.org>
Cc: Dmitry Rokosov <ddrokosov@salutedevices.com>,
Igor Opaniuk <igor.opaniuk@gmail.com>,
Tom Rini <trini@konsulko.com>, "Andrew F. Davis" <afd@ti.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Simon Glass <sjg@chromium.org>, Mario Six <mario.six@gdsys.cc>,
u-boot@lists.denx.de, u-boot-amlogic@groups.io,
rockosov@gmail.com, kernel@salutedevices.com,
Guillaume La Roque <glaroque@baylibre.com>
Subject: Re: [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block
Date: Wed, 06 Nov 2024 11:02:57 +0100 [thread overview]
Message-ID: <875xp08ysu.fsf@baylibre.com> (raw)
In-Reply-To: <CAPLW+4=-yPgMeDM5XRkBXR-nD4Ni2VtWqTKxJVVrfdU8g2sG4g@mail.gmail.com>
Hi Sam,
On mar., nov. 05, 2024 at 18:58, Sam Protsenko <semen.protsenko@linaro.org> wrote:
> On Tue, Nov 5, 2024 at 9:06 AM Mattijs Korpershoek
> <mkorpershoek@baylibre.com> wrote:
>>
>> Hi Sam,
>>
>
> Hey Mattijs,
>
> [snip]
>
>> >> @@ -328,7 +328,8 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,
>> >> * or the device tree.
>> >> */
>> >> memset(slot_suffix, 0, sizeof(slot_suffix));
>> >> - slot_suffix[0] = BOOT_SLOT_NAME(slot);
>> >> + slot_suffix[0] = '_';
>> >> + slot_suffix[1] = BOOT_SLOT_NAME(slot);
>> >
>> > AFAIU, this changes the behavior of two above functions, and
>> > consequently of "bcb ab_select" command? If so, just to double check:
>> > were all users of those reworked correspondingly? I can see next
>> > occurrences (there may be more):
>> >
>> > $ grep -sIrHn '"_' boot/bootmeth_android.c
>>
>> I thought the same when first reviewing the patch.
>> Looking a bit closer...
>>
>> >
>> > boot/bootmeth_android.c:74: sprintf(partname, BOOT_PART_NAME "_%s",
>> > priv->slot);
>> > boot/bootmeth_android.c:111: sprintf(partname,
>> > VENDOR_BOOT_PART_NAME "_%s", priv->slot);
>> > boot/bootmeth_android.c:156: sprintf(slot_suffix, "_%s", priv->slot);
>> > boot/bootmeth_android.c:397: sprintf(slot_suffix, "_%s", priv->slot);
>>
>> ... We can see that ab_select_slot() returns an integer
>> That integer is used later on to initialize priv->slot:
>>
>> """
>> priv->slot[0] = BOOT_SLOT_NAME(ret);
>> priv->slot[1] = '\0';
>> """
>>
>> The change from Dmitry only changes what we **write** to the BCB (into
>> the misc partition), not what is returned by ab_select_slot().
>>
>
> Sure. Just wanted to double check that the behavior is not changed in
> any related parts, as the commit message doesn't mention that. Btw,
> BCB is an interface between the bootloader and AOSP, so if this patch
> changes what's being written into BCB, does it affect AOSP part of it
> somehow? Especially for already existing devices with particular BCB
> data, in case U-Boot gets updated there.
Those are valid concerns.
Per my understanding, on recent Android versions the slot suffix is not
read from BCB, but from the ro.boot.slot_suffix property:
"""
// Initialize the current_slot from the read-only property. If the property
// was not set (from either the command line or the device tree), we can later
// initialize it from the bootloader_control struct.
std::string suffix_prop = android::base::GetProperty("ro.boot.slot_suffix", "");
if (suffix_prop.empty()) {
LOG(ERROR) << "Slot suffix property is not set";
return false;
}
current_slot_ = SlotSuffixToIndex(suffix_prop.c_str());
"""
See:
https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/boot/1.1/default/boot_control/libboot_control.cpp;l=185;drc=86b8f575059a1799c760ca7012f540a528d68a9d;bpv=1;bpt=1
This has been the case since 2019.
If we look at earlier implementations of libboot_control (which was in
bootable/recovery)
https://android-review.googlesource.com/c/platform/bootable/recovery/+/1191517
So implementations before 2019 that do not have this patch:
https://android-review.googlesource.com/c/platform/bootable/recovery/+/1111899
Will get the slot suffix from the BCB (not from the commandline)
For these older implementations, we will go through the following:
BootControl::Init()
LoadBootloaderControl(device.c_str(), &boot_ctrl)
android::base::ReadFully(fd.get(), buffer, sizeof(bootloader_control)
And struct bootloader_control has:
struct bootloader_control {
// NUL terminated active slot suffix.
char slot_suffix[4];
And if we look at how the BCB is initialized from userspace in:
https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/boot/1.1/default/boot_control/libboot_control.cpp;l=120;drc=86b8f575059a1799c760ca7012f540a528d68a9d
We can see that we copy _a, not a (for example, if slot == 0).
So I think this is fine.
If needed, I can dig more for behaviour on older devices (<2019), let me know!
>
>> ab_select_slot() still returns an integer which needs to be converted
>> via the BOOT_SLOT_NAME() macro.
>>
>> >
>> > $ grep -sIrHn 'slot_suffix _' include/configs/
>> > include/configs/ti_omap5_common.h:107: "setenv slot_suffix _${slot_name};"
>> > include/configs/meson64_android.h:65: "setenv slot_suffix
>> > _${current_slot}; " \
>>
>> Same goes for these 2 examples, we use:
>> The "bcb ab_select current_slot" command to store the slot into the
>> "current_slot" environment variable.
>> Looking at cmd/bcb.c we can see:
>>
>> """
>> ret = ab_select_slot(dev_desc, &part_info, dec_tries);
>> if (ret < 0) {
>> printf("Android boot failed, error %d.\n", ret);
>> return CMD_RET_FAILURE;
>> }
>>
>> /* Android standard slot names are 'a', 'b', ... */
>> slot[0] = BOOT_SLOT_NAME(ret);
>> slot[1] = '\0';
>> env_set(argv[1], slot);
>> printf("ANDROID: Booting slot: %s\n", slot);
>> """
>>
>> So I think this is fine.
>>
>
> [snip]
next prev parent reply other threads:[~2024-11-06 10:03 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 14:12 [PATCH v5 0/6] android_ab: introduce bcb ab_dump command and provide several bcb fixes Dmitry Rokosov
2024-10-17 14:12 ` [PATCH v5 1/6] include/android_ab: move ab_select_slot() documentation to @ notation Dmitry Rokosov
2024-10-17 14:12 ` [PATCH v5 2/6] cmd: bcb: rework the command to U_BOOT_LONGHELP approach Dmitry Rokosov
2024-10-22 8:44 ` Mattijs Korpershoek
2024-10-17 14:12 ` [PATCH v5 3/6] treewide: bcb: move ab_select command to bcb subcommands Dmitry Rokosov
2024-10-22 9:01 ` Mattijs Korpershoek
2024-10-17 14:12 ` [PATCH v5 4/6] cmd: bcb: change strcmp() usage style in the do_bcb_ab_select() Dmitry Rokosov
2024-10-17 14:12 ` [PATCH v5 5/6] cmd: bcb: introduce 'ab_dump' command to print BCB block content Dmitry Rokosov
2024-10-22 9:03 ` Mattijs Korpershoek
2024-10-17 14:12 ` [PATCH v5 6/6] common: android_ab: fix slot suffix for abc block Dmitry Rokosov
2024-11-03 9:43 ` Igor Opaniuk
2024-11-05 14:54 ` Mattijs Korpershoek
2024-11-04 23:06 ` Sam Protsenko
2024-11-05 15:05 ` Mattijs Korpershoek
2024-11-06 0:58 ` Sam Protsenko
2024-11-06 10:02 ` Mattijs Korpershoek [this message]
2024-11-07 3:17 ` Sam Protsenko
2024-11-07 8:53 ` Mattijs Korpershoek
2024-10-18 12:41 ` [PATCH v5 0/6] android_ab: introduce bcb ab_dump command and provide several bcb fixes Dmitry Rokosov
2024-10-22 8:32 ` Mattijs Korpershoek
2024-10-24 7:47 ` Mattijs Korpershoek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875xp08ysu.fsf@baylibre.com \
--to=mkorpershoek@baylibre.com \
--cc=afd@ti.com \
--cc=ddrokosov@salutedevices.com \
--cc=glaroque@baylibre.com \
--cc=igor.opaniuk@gmail.com \
--cc=kernel@salutedevices.com \
--cc=mario.six@gdsys.cc \
--cc=neil.armstrong@linaro.org \
--cc=rockosov@gmail.com \
--cc=semen.protsenko@linaro.org \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot-amlogic@groups.io \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.