From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BEF0C61DA4 for ; Thu, 9 Feb 2023 14:46:41 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 47EE085C73; Thu, 9 Feb 2023 15:46:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com 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=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="LqFwCtGs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2E22B85CF3; Thu, 9 Feb 2023 15:46:37 +0100 (CET) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 A14B285C5F for ; Thu, 9 Feb 2023 15:46:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mkorpershoek@baylibre.com Received: by mail-wm1-x32f.google.com with SMTP id l37-20020a05600c1d2500b003dfe46a9801so1739730wms.0 for ; Thu, 09 Feb 2023 06:46:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=45S2ImlpF//9wx8og3tEXR5o0jqLicKSpDwZ8ODzTbc=; b=LqFwCtGsd1oL/hYIKIw6x2dmtVu0VL0qENXjbe5pHttK1eGWL1AEhzn/twCbFMuI0p 8oTndzQOlwulFIn1eChNpXNtaiuN7O/zdCKfjV/+E1FQ0lHSHElnHNDkNe/oatSsa8RR 3Xlouo+tpGPVNlx3PhInfDOHv78vAKQoKfAnNVBuV6LeGcQRaAAlVo9d4qT9xbE/wDs1 icSLAYUaaO/IcKO+N2KHj5lmyvQUL+Z3meGARIA7fsmRSzt2AKYT8k5jxcANaqx69Lsx XWdm+wtAw0dqckcRPfs57WG//VtOqeRzdG4tw9R4LUy/9nTPHiZLRDSZH2FT2IV/k/kC LGmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=45S2ImlpF//9wx8og3tEXR5o0jqLicKSpDwZ8ODzTbc=; b=tb8Y/uLesze8rMeqEn0j+fHwtw3ZSEVOsO5if9vk/Y7LU6m7DioHxKHgbslDwKrm2v MiMP5TK64KA6qdJxmVP1sUrz+lc4iPULPBTylKjsZQaEZMCudBH57Wy8nm+JTumRSach Sh+xyBARaV39Qp6IuQFm/Y+slWs1463wWJPwwiKyJlAIZcXh9qm7T4Qv3xu4Tu7zfXNJ Z9iyjXzcW+luy62Yavz3uDpk2OsupxR7oWXFzunLyFhh/IzsjdfgboHLHoiyCh72VcPi TcI9v9Yj8ld4MubSF54dWQX7Z+BnIbDYsnOU0hiHOWWFFTajEgsRhYUzJWZcppNeXW1x Thmg== X-Gm-Message-State: AO0yUKXcJlAeQO/jvHGP8N6aO/+wMbHGM0KYqnXngdADx8sVJMikKL9b jqU+WPey26N9cgw4vDWhgz8g7Q== X-Google-Smtp-Source: AK7set+4aiJDLo6GmaptqWookibYq/FL8ZIRbsseIhXlSli8I5CFwGBLMei4LEyI8gUKB2Yh20TZ3A== X-Received: by 2002:a05:600c:2e87:b0:3e0:1a9:b1f5 with SMTP id p7-20020a05600c2e8700b003e001a9b1f5mr10202450wmn.28.1675953993118; Thu, 09 Feb 2023 06:46:33 -0800 (PST) Received: from localhost ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id p21-20020a05600c359500b003db06224953sm2279410wmq.41.2023.02.09.06.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 06:46:32 -0800 (PST) From: Mattijs Korpershoek To: Safae Ouajih , sjg@chromium.org Cc: u-boot@lists.denx.de, sean.anderson@seco.com, r.stratiienko@gmail.com, glaroque@baylibre.com, khilman@baylibre.com Subject: Re: [PATCH v3 15/19] android: boot: support boot image header version 3 and 4 In-Reply-To: <20230205235021.355410-16-souajih@baylibre.com> References: <20230205235021.355410-1-souajih@baylibre.com> <20230205235021.355410-16-souajih@baylibre.com> Date: Thu, 09 Feb 2023 15:46:31 +0100 Message-ID: <87r0uyj3qw.fsf@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain 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.6 at phobos.denx.de X-Virus-Status: Clean On Mon, Feb 06, 2023 at 00:50, Safae Ouajih wrote: > Enable the support for boot image header version 3 and 4 > using abootimg command. > > In order to use version 3 or 4: > > 1- Vendor boot image address should be given to abootimg cmd. > > abootimg addr $1 $vendor_boot_load_addr > > 2- "ramdisk_addr_r" env variable (ramdisk address) should be set to host > the ramdisk : generic ramdisk + vendor ramdisk > > Replace "struct andr_boot_img_hdr_v0*" by "void *" in > some functions since v3 and v4 are now supported as well. > > Signed-off-by: Safae Ouajih Reviewed-by: Mattijs Korpershoek > --- > boot/bootm.c | 37 ++++++++++++++++++++++++++++++++----- > boot/image-android.c | 16 ++++++++++------ > boot/image-board.c | 18 +++++++++++++++--- > boot/image-fdt.c | 2 +- > cmd/abootimg.c | 24 ++++++++++++++++++++++-- > include/image.h | 25 +++++++++++++++++++------ > 6 files changed, 99 insertions(+), 23 deletions(-) > > diff --git a/boot/bootm.c b/boot/bootm.c > index a58e6f391e..a7fc6c4545 100644 > --- a/boot/bootm.c > +++ b/boot/bootm.c > @@ -113,6 +113,10 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, > char *const argv[]) > { > const void *os_hdr; > +#ifdef CONFIG_ANDROID_BOOT_IMAGE > + const void *vendor_boot_img; > + const void *boot_img; > +#endif > bool ep_found = false; > int ret; > > @@ -181,14 +185,23 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, > #endif > #ifdef CONFIG_ANDROID_BOOT_IMAGE > case IMAGE_FORMAT_ANDROID: > + boot_img = os_hdr; > + vendor_boot_img = NULL; > + if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { > + boot_img = map_sysmem(get_abootimg_addr(), 0); > + vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0); > + } > images.os.type = IH_TYPE_KERNEL; > - images.os.comp = android_image_get_kcomp(os_hdr, NULL); > + images.os.comp = android_image_get_kcomp(boot_img, vendor_boot_img); > images.os.os = IH_OS_LINUX; > - > - images.os.end = android_image_get_end(os_hdr, NULL); > - images.os.load = android_image_get_kload(os_hdr, NULL); > + images.os.end = android_image_get_end(boot_img, vendor_boot_img); > + images.os.load = android_image_get_kload(boot_img, vendor_boot_img); > images.ep = images.os.load; > ep_found = true; > + if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { > + unmap_sysmem(vendor_boot_img); > + unmap_sysmem(boot_img); > + } > break; > #endif > default: > @@ -889,6 +902,10 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, > int os_noffset; > #endif > > +#ifdef CONFIG_ANDROID_BOOT_IMAGE > + const void *boot_img; > + const void *vendor_boot_img; > +#endif > img_addr = genimg_get_kernel_addr_fit(argc < 1 ? NULL : argv[0], > &fit_uname_config, > &fit_uname_kernel); > @@ -964,10 +981,20 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, > #endif > #ifdef CONFIG_ANDROID_BOOT_IMAGE > case IMAGE_FORMAT_ANDROID: > + boot_img = buf; > + vendor_boot_img = NULL; > + if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { > + boot_img = map_sysmem(get_abootimg_addr(), 0); > + vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0); > + } > printf("## Booting Android Image at 0x%08lx ...\n", img_addr); > - if (android_image_get_kernel(buf, NULL, images->verify, > + if (android_image_get_kernel(boot_img, vendor_boot_img, images->verify, > os_data, os_len)) > return NULL; > + if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { > + unmap_sysmem(vendor_boot_img); > + unmap_sysmem(boot_img); > + } > break; > #endif > default: > diff --git a/boot/image-android.c b/boot/image-android.c > index 6be439ed12..fb29ff403f 100644 > --- a/boot/image-android.c > +++ b/boot/image-android.c > @@ -201,7 +201,7 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data) > * Return: Zero, os start address and length on success, > * otherwise on failure. > */ > -int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, > +int android_image_get_kernel(const void *hdr, > const void *vendor_boot_img, int verify, > ulong *os_data, ulong *os_len) > { > @@ -286,7 +286,7 @@ bool is_android_vendor_boot_image_header(const void *vendor_boot_img) > return !memcmp(VENDOR_BOOT_MAGIC, vendor_boot_img, ANDR_VENDOR_BOOT_MAGIC_SIZE); > } > > -bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr) > +bool is_android_boot_image_header(const void *hdr) > { > return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE); > } > @@ -305,7 +305,7 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr, > return img_data.boot_img_total_size; > } > > -ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, > +ulong android_image_get_kload(const void *hdr, > const void *vendor_boot_img) > { > struct andr_image_data img_data; > @@ -316,7 +316,7 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, > return android_image_get_kernel_addr(&img_data); > } > > -ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr, > +ulong android_image_get_kcomp(const void *hdr, > const void *vendor_boot_img) > { > struct andr_image_data img_data; > @@ -364,14 +364,18 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, > return 0; > } > > -int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, > - ulong *second_data, ulong *second_len) > +int android_image_get_second(const void *hdr, ulong *second_data, ulong *second_len) > { > struct andr_image_data img_data; > > if (!android_image_get_data(hdr, NULL, &img_data)) > return -EINVAL; > > + if (img_data.header_version > 2) { > + printf("Second stage bootloader is only supported for boot image version <= 2\n"); > + return -EOPNOTSUPP; > + } > + > if (!img_data.second_size) { > *second_data = *second_len = 0; > return -1; > diff --git a/boot/image-board.c b/boot/image-board.c > index b6c9bbe8f5..318aed30f8 100644 > --- a/boot/image-board.c > +++ b/boot/image-board.c > @@ -426,10 +426,22 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a > break; > case IMAGE_FORMAT_ANDROID: > if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) { > - void *ptr = map_sysmem(images->os.start, 0); > int ret; > - ret = android_image_get_ramdisk(ptr, NULL, rd_datap, rd_lenp); > - unmap_sysmem(ptr); > + if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { > + void *boot_img = map_sysmem(get_abootimg_addr(), 0); > + void *vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0); > + > + ret = android_image_get_ramdisk(boot_img, vendor_boot_img, > + rd_datap, rd_lenp); > + unmap_sysmem(vendor_boot_img); > + unmap_sysmem(boot_img); > + } else { > + void *ptr = map_sysmem(images->os.start, 0); > + > + ret = android_image_get_ramdisk(ptr, NULL, rd_datap, rd_lenp); > + unmap_sysmem(ptr); > + } > + > if (ret) > return ret; > done = true; > diff --git a/boot/image-fdt.c b/boot/image-fdt.c > index f270d00a5f..5f9cf7b4e6 100644 > --- a/boot/image-fdt.c > +++ b/boot/image-fdt.c > @@ -529,7 +529,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, > } > #ifdef CONFIG_ANDROID_BOOT_IMAGE > } else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) { > - struct andr_boot_img_hdr_v0 *hdr = buf; > + void *hdr = buf; > ulong fdt_data, fdt_len; > u32 fdt_size, dtb_idx; > /* > diff --git a/cmd/abootimg.c b/cmd/abootimg.c > index 4d6cf0fa3e..2653b555b1 100644 > --- a/cmd/abootimg.c > +++ b/cmd/abootimg.c > @@ -17,6 +17,16 @@ > static ulong _abootimg_addr = -1; > static ulong _avendor_bootimg_addr = -1; > > +ulong get_abootimg_addr(void) > +{ > + return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr); > +} > + > +ulong get_avendor_bootimg_addr(void) > +{ > + return _avendor_bootimg_addr; > +} > + > static int abootimg_get_ver(int argc, char *const argv[]) > { > const struct andr_boot_img_hdr_v0 *hdr; > @@ -70,12 +80,21 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[]) > return CMD_RET_USAGE; > struct andr_image_data img_data = {0}; > const struct andr_boot_img_hdr_v0 *hdr; > + const struct andr_vnd_boot_img_hdr *vhdr; > > hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); > - if (!android_image_get_data(hdr, NULL, &img_data)) { > + if (get_avendor_bootimg_addr() != -1) > + vhdr = map_sysmem(get_avendor_bootimg_addr(), sizeof(*vhdr)); > + > + if (!android_image_get_data(hdr, vhdr, &img_data)) { > + if (get_avendor_bootimg_addr() != -1) > + unmap_sysmem(vhdr); > unmap_sysmem(hdr); > return CMD_RET_FAILURE; > } > + > + if (get_avendor_bootimg_addr() != -1) > + unmap_sysmem(vhdr); > unmap_sysmem(hdr); > > if (img_data.header_version < 2) { > @@ -119,7 +138,8 @@ static int abootimg_get_dtb_by_index(int argc, char *const argv[]) > return CMD_RET_FAILURE; > } > > - if (!android_image_get_dtb_by_index(abootimg_addr(), 0, num, > + if (!android_image_get_dtb_by_index(abootimg_addr(), > + get_avendor_bootimg_addr(), num, > &addr, &size)) { > return CMD_RET_FAILURE; > } > diff --git a/include/image.h b/include/image.h > index c4d9b1c575..456197d6fd 100644 > --- a/include/image.h > +++ b/include/image.h > @@ -1767,7 +1767,7 @@ struct andr_boot_img_hdr_v0; > * Return: Zero, os start address and length on success, > * otherwise on failure. > */ > -int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, > +int android_image_get_kernel(const void *hdr, > const void *vendor_boot_img, int verify, > ulong *os_data, ulong *os_len); > > @@ -1796,8 +1796,7 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, > * @second_len : Pointer to a ulong variable, will hold secondary bootloader length > * Return: 0 if succeeded, -1 if secondary bootloader size is 0 > */ > -int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, > - ulong *second_data, ulong *second_len); > +int android_image_get_second(const void *hdr, ulong *second_data, ulong *second_len); > bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size); > > /** > @@ -1838,7 +1837,7 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr, > * @vendor_boot_img : Pointer to vendor boot image header > * Return: The kernel load address > */ > -ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, > +ulong android_image_get_kload(const void *hdr, > const void *vendor_boot_img); > > /** > @@ -1850,7 +1849,7 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, > * @vendor_boot_img : Pointer to vendor boot image header > * Return: Kernel compression type > */ > -ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr, > +ulong android_image_get_kcomp(const void *hdr, > const void *vendor_boot_img); > > /** > @@ -1874,7 +1873,7 @@ bool android_image_print_dtb_contents(ulong hdr_addr); > * @hdr: Pointer to boot image > * Return: non-zero if the magic is correct, zero otherwise > */ > -bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr); > +bool is_android_boot_image_header(const void *hdr); > > /** > * is_android_vendor_boot_image_header() - Check the magic of vendor boot image > @@ -1887,6 +1886,20 @@ bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr); > */ > bool is_android_vendor_boot_image_header(const void *vendor_boot_img); > > +/** > + * get_abootimg_addr() - Get Android boot image address > + * > + * Return: Android boot image address > + */ > +ulong get_abootimg_addr(void); > + > +/** > + * get_avendor_bootimg_addr() - Get Android vendor boot image address > + * > + * Return: Android vendor boot image address > + */ > +ulong get_avendor_bootimg_addr(void); > + > /** > * board_fit_config_name_match() - Check for a matching board name > * > -- > 2.34.1