~postmarketos/pmbootstrap-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 2

[PATCH pmbootstrap v2] pmb.flasher: Improve flash_lk2nd action

Details
Message ID
<20230605104026.744005-1-luca@z3ntu.xyz>
DKIM signature
missing
Download raw message
Patch: +34 -11
* Check that we're not already running lk2nd as flashing boot partition
  inside lk2nd is different to flashing boot partition outside. We could
  improve this in the future to use "flash lk2nd lk2nd.img" as
  documented in the file.
* Grab the lk2nd package from the device package and install that. The
  device package is expected to have a dependency on the correct lk2nd
  package.
* Remove some log message in unusual styles for pmbootstrap.
* Group flash_lk2nd action together with the other flash actions and use
  string comparison.

See also: https://gitlab.com/postmarketOS/pmaports/-/issues/2074
---
Changes from v1:
- Drop get_device_package function
- Grab lk2nd package from device package directly instead of installing
  device package
- Reorder a log message for "checking current fastboot product" so it's
  clearer

 pmb/flasher/frontend.py | 45 +++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/pmb/flasher/frontend.py b/pmb/flasher/frontend.py
index 08e26063..9a7dc695 100644
--- a/pmb/flasher/frontend.py
+++ b/pmb/flasher/frontend.py
@@ -110,15 +110,38 @@ def sideload(args):


def flash_lk2nd(args):
    chroot_path = args.work + "/chroot_rootfs_" + args.device
    lk2nd_path = "/boot/lk2nd.img"
    if not os.path.exists(chroot_path + lk2nd_path):
        raise RuntimeError(f"{chroot_path+lk2nd_path} doesn't exist. Your"
                           " device may not support lk2nd.")

    logging.info(lk2nd_path)
    logging.info("It's normal if fastboot warns"
                 " \"Image not signed or corrupt\" or a similar warning")
    method = args.flash_method or args.deviceinfo["flash_method"]
    if method == "fastboot":
        # In the future this could be expanded to use "fastboot flash lk2nd $img"
        # which reflashes/updates lk2nd from itself. For now let the user handle this
        # manually since supporting the codepath with heimdall requires more effort.
        pmb.flasher.init(args)
        logging.info("(native) checking current fastboot product")
        output = pmb.chroot.root(args, ["fastboot", "getvar", "product"],
                                 output="interactive", output_return=True)
        # Variable "product" is e.g. "LK2ND_MSM8974" or "lk2nd-msm8226" depending
        # on the lk2nd version.
        if "lk2nd" in output.lower():
            raise RuntimeError("You are currently running lk2nd. Please reboot into the regular"
                               " bootloader mode to re-flash lk2nd.")

    # Get the lk2nd package (which is a dependency of the device package)
    device_pkg = f"device-{args.device}"
    apkbuild = pmb.helpers.pmaports.get(args, device_pkg)
    lk2nd_pkg = None
    for dep in apkbuild["depends"]:
        if dep.startswith("lk2nd"):
            lk2nd_pkg = dep
            break

    if not lk2nd_pkg:
        raise RuntimeError(f"{device_pkg} does not depend on any lk2nd package")

    # Install device package since that should also install lk2nd package
    suffix = "rootfs_" + args.device
    pmb.chroot.apk.install(args, [lk2nd_pkg], suffix)

    logging.info("(native) flash lk2nd image")
    pmb.flasher.run(args, "flash_lk2nd")


@@ -143,11 +166,11 @@ def frontend(args):
        flash_vbmeta(args)
    elif action == "flash_dtbo":
        flash_dtbo(args)
    elif action == "flash_lk2nd":
        flash_lk2nd(args)
    elif action == "list_flavors":
        list_flavors(args)
    elif action == "list_devices":
        list_devices(args)
    elif action == "sideload":
        sideload(args)
    elif action in ["flash_lk2nd"]:
        flash_lk2nd(args)
-- 
2.40.1

[pmbootstrap/patches/.build.yml] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CT4NNX1OSV09.I53T21W6UYXD@cirno2>
In-Reply-To
<20230605104026.744005-1-luca@z3ntu.xyz> (view parent)
DKIM signature
missing
Download raw message
pmbootstrap/patches/.build.yml: FAILED in 5m10s

[pmb.flasher: Improve flash_lk2nd action][0] v2 from [Luca Weiss][1]

[0]: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/patches/41657
[1]: luca@z3ntu.xyz

✗ #1001733 FAILED pmbootstrap/patches/.build.yml https://builds.sr.ht/~postmarketos/job/1001733
Details
Message ID
<CT4O50R6EW3C.9RKB4R2IDSY6@pm-mail-aerc>
In-Reply-To
<20230605104026.744005-1-luca@z3ntu.xyz> (view parent)
DKIM signature
missing
Download raw message
On Mon Jun 5, 2023 at 12:40 PM CEST, Luca Weiss wrote:
> * Check that we're not already running lk2nd as flashing boot partition
>   inside lk2nd is different to flashing boot partition outside. We could
>   improve this in the future to use "flash lk2nd lk2nd.img" as
>   documented in the file.
> * Grab the lk2nd package from the device package and install that. The
>   device package is expected to have a dependency on the correct lk2nd
>   package.
> * Remove some log message in unusual styles for pmbootstrap.
> * Group flash_lk2nd action together with the other flash actions and use
>   string comparison.
>
> See also: https://gitlab.com/postmarketOS/pmaports/-/issues/2074
> ---
> Changes from v1:
> - Drop get_device_package function
> - Grab lk2nd package from device package directly instead of installing
>   device package
> - Reorder a log message for "checking current fastboot product" so it's
>   clearer
>
>  pmb/flasher/frontend.py | 45 +++++++++++++++++++++++++++++++----------
>  1 file changed, 34 insertions(+), 11 deletions(-)
>
> diff --git a/pmb/flasher/frontend.py b/pmb/flasher/frontend.py
> index 08e26063..9a7dc695 100644
> --- a/pmb/flasher/frontend.py
> +++ b/pmb/flasher/frontend.py
> @@ -110,15 +110,38 @@ def sideload(args):
>  
>  
>  def flash_lk2nd(args):
> -    chroot_path = args.work + "/chroot_rootfs_" + args.device
> -    lk2nd_path = "/boot/lk2nd.img"
> -    if not os.path.exists(chroot_path + lk2nd_path):
> -        raise RuntimeError(f"{chroot_path+lk2nd_path} doesn't exist. Your"
> -                           " device may not support lk2nd.")
> -
> -    logging.info(lk2nd_path)
> -    logging.info("It's normal if fastboot warns"
> -                 " \"Image not signed or corrupt\" or a similar warning")
> +    method = args.flash_method or args.deviceinfo["flash_method"]
> +    if method == "fastboot":
> +        # In the future this could be expanded to use "fastboot flash lk2nd $img"
> +        # which reflashes/updates lk2nd from itself. For now let the user handle this
> +        # manually since supporting the codepath with heimdall requires more effort.
> +        pmb.flasher.init(args)
> +        logging.info("(native) checking current fastboot product")
> +        output = pmb.chroot.root(args, ["fastboot", "getvar", "product"],
> +                                 output="interactive", output_return=True)
> +        # Variable "product" is e.g. "LK2ND_MSM8974" or "lk2nd-msm8226" depending
> +        # on the lk2nd version.
> +        if "lk2nd" in output.lower():
> +            raise RuntimeError("You are currently running lk2nd. Please reboot into the regular"
> +                               " bootloader mode to re-flash lk2nd.")
> +
> +    # Get the lk2nd package (which is a dependency of the device package)
> +    device_pkg = f"device-{args.device}"
> +    apkbuild = pmb.helpers.pmaports.get(args, device_pkg)
> +    lk2nd_pkg = None
> +    for dep in apkbuild["depends"]:
> +        if dep.startswith("lk2nd"):
> +            lk2nd_pkg = dep
> +            break
> +
> +    if not lk2nd_pkg:
> +        raise RuntimeError(f"{device_pkg} does not depend on any lk2nd package")
> +
> +    # Install device package since that should also install lk2nd package

This comment is now outdated, but I'll fix it before merge.

Looks good otherwise, thanks!

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>

> +    suffix = "rootfs_" + args.device
> +    pmb.chroot.apk.install(args, [lk2nd_pkg], suffix)
> +
> +    logging.info("(native) flash lk2nd image")
>      pmb.flasher.run(args, "flash_lk2nd")
>  
>  
> @@ -143,11 +166,11 @@ def frontend(args):
>          flash_vbmeta(args)
>      elif action == "flash_dtbo":
>          flash_dtbo(args)
> +    elif action == "flash_lk2nd":
> +        flash_lk2nd(args)
>      elif action == "list_flavors":
>          list_flavors(args)
>      elif action == "list_devices":
>          list_devices(args)
>      elif action == "sideload":
>          sideload(args)
> -    elif action in ["flash_lk2nd"]:
> -        flash_lk2nd(args)
> -- 
> 2.40.1
Details
Message ID
<168596393294.2614.11388828972852551558.b4-ty@postmarketos.org>
In-Reply-To
<20230605104026.744005-1-luca@z3ntu.xyz> (view parent)
DKIM signature
missing
Download raw message
On Mon, 05 Jun 2023 12:40:27 +0200, Luca Weiss wrote:
> * Check that we're not already running lk2nd as flashing boot partition
>   inside lk2nd is different to flashing boot partition outside. We could
>   improve this in the future to use "flash lk2nd lk2nd.img" as
>   documented in the file.
> * Grab the lk2nd package from the device package and install that. The
>   device package is expected to have a dependency on the correct lk2nd
>   package.
> * Remove some log message in unusual styles for pmbootstrap.
> * Group flash_lk2nd action together with the other flash actions and use
>   string comparison.
> 
> [...]

Applied, thanks!

[1/1] pmb.flasher: Improve flash_lk2nd action
      commit: 68231d93e2d0435dda5ac845c718bc1c7d8e9293

Best regards,
-- 
Oliver Smith <ollieparanoid@postmarketos.org>
Reply to thread Export thread (mbox)