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 63CD6C4321E for ; Sat, 26 Nov 2022 17:19:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5197C85270; Sat, 26 Nov 2022 18:18:25 +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="MrCDLAtS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 80ED584494; Sat, 26 Nov 2022 17:59:45 +0100 (CET) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 14C6685023 for ; Sat, 26 Nov 2022 17:59:43 +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=souajih@baylibre.com Received: by mail-wm1-x32d.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so8435144wma.1 for ; Sat, 26 Nov 2022 08:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T+nXAs0wbZJtihGVc8O8KG5auctE350b1PHb/ZLdYhw=; b=MrCDLAtSM7jQLz6hc79/Ipr6zrrURyFdXvd74dK80PJReUvs/VrULGTo4fg/1vlwq2 hYIcQwrBCWOpe4/afFLxVMze9syPIvJCVaGSEGBu/8IlCZ2KA/edCyX0+0/SUlgzweO8 QnaB6G+lVjcTW7xYsGvt3qFngLfHxhSVdWtMXXryyzVA/zw+tJn+FvNAr+CtuohDUULt XVXuIMDEzsj4zCr7OnXmqcl8pP3W9xhjUDlV54GrcIDlVekGcVQFT0+KDUTPFwqDehdc ORbh5QZbGMlKWWEjm6n83Lm7JsyypyYr2kSzZbHpbQVDlBfKoFtz197s384EYPaOWspl hyoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T+nXAs0wbZJtihGVc8O8KG5auctE350b1PHb/ZLdYhw=; b=gZMtDwaGiTw7ta9B/+/cyZOJg1AFpG/oqsWgOvjqsHfjlNqd0sQHVi/Xc1sAqE1fcK MB1j28EhnlUfS1CcUvBBqfKKU+FPQtlutSUzZ6qMcq8sU6bODyP1AaTmN5VSqEA6Twvw 0e4zaGJ1ucUElE8J9a84T5ZY628vwkA6XI5hGFEYeAlCUYUooGSnz8gQORXZWIjBXC3+ GxnD4mLjs8yTmrjKM8EOD/cIPU/I1jTixSgKVo1L8vCtMBFIhrqzt8fexKjAckyqmu96 zpjPJ6EhHkk9EgQ9sTRajmYoKyZ1RY8aZGQ7FH1VOLUV/CdECQRdmSr3DeN6KnPU8B2P NofQ== X-Gm-Message-State: ANoB5plV05RP2F/R+w1FYjRIBuBfnTc0WBjR69WSDNT7a2g6eCLMg5/W MG34nxwUHkuBc2HqnFFDAtDXq/zvZjlF3A== X-Google-Smtp-Source: AA0mqf7+rV69BUB+XfpcPvpC/9d1tkscSexDWuxVdLlcddTw+THQowMCiAuwYQv4R/t3CREoHv6fOw== X-Received: by 2002:a05:600c:3495:b0:3cf:a258:99b with SMTP id a21-20020a05600c349500b003cfa258099bmr31911226wmq.34.1669481982591; Sat, 26 Nov 2022 08:59:42 -0800 (PST) Received: from safae.baylibre.local ([2a04:cec0:11b5:4031:7588:eb2c:a5c2:aa6d]) by smtp.gmail.com with ESMTPSA id c15-20020adfe70f000000b00241e8d00b79sm7462408wrm.54.2022.11.26.08.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 08:59:42 -0800 (PST) From: Safae Ouajih To: sjg@chromium.org Cc: u-boot@lists.denx.de, sean.anderson@seco.com, r.stratiienko@gmail.com, mkorpershoek@baylibre.com, glaroque@baylibre.com, khilman@baylibre.com Subject: [PATCH 06/17] android: boot: kcomp: support andr_image_data Date: Sat, 26 Nov 2022 17:59:20 +0100 Message-Id: <20221126165931.197607-7-souajih@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221126165931.197607-1-souajih@baylibre.com> References: <20221126165931.197607-1-souajih@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Sat, 26 Nov 2022 18:18:14 +0100 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 andr_image_data structure is used as a global representation of boot image header structure. This new structure is introduced to support all boot header versions : v0,v1.v2.v3.v4 and will be used to support v3 and v4 while maitaining support for v0,v1,v2. The need of using andr_image_data comes from the change of header structure in both version 3 and 4. android_image_get_kcomp() is reworked to support this new struct. Signed-off-by: Safae Ouajih --- boot/image-android.c | 74 ++++++++++++++++++++++++++++++++++++++++- include/android_image.h | 27 +++++++++++++++ include/image.h | 2 ++ 3 files changed, 102 insertions(+), 1 deletion(-) diff --git a/boot/image-android.c b/boot/image-android.c index c67949b8b563..79d987a3b044 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -18,6 +18,73 @@ static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1]; +static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, + struct andr_image_data *data) +{ + ulong end; + + data->image_name = hdr->name; + data->kcmdline = hdr->cmdline; + data->kernel_addr = hdr->kernel_addr; + data->ramdisk_addr = hdr->ramdisk_addr; + data->header_version = hdr->header_version; + + end = (ulong)hdr; + + /* + * The header takes a full page, the remaining components are aligned + * on page boundary + */ + + end += hdr->page_size; + + data->kernel_ptr = end; + data->kernel_size = hdr->kernel_size; + end += ALIGN(hdr->kernel_size, hdr->page_size); + + data->ramdisk_ptr = end; + data->ramdisk_size = hdr->ramdisk_size; + end += ALIGN(hdr->ramdisk_size, hdr->page_size); + + data->second_ptr = end; + data->second_size = hdr->second_size; + end += ALIGN(hdr->second_size, hdr->page_size); + + if (hdr->header_version >= 1) { + data->recovery_dtbo_ptr = end; + data->recovery_dtbo_size = hdr->recovery_dtbo_size; + end += ALIGN(hdr->recovery_dtbo_size, hdr->page_size); + } + + if (hdr->header_version >= 2) { + data->dtb_ptr = end; + data->dtb_size = hdr->dtb_size; + end += ALIGN(hdr->dtb_size, hdr->page_size); + } + + data->boot_img_total_size = end - (ulong)hdr; +} + +bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data) +{ + if (!boot_hdr || !data) { + printf("boot_hdr or data params can't be NULL\n"); + return false; + } + + if (!is_android_boot_image_header(boot_hdr)) { + printf("Incorrect boot image header\n"); + return false; + } + + if (((struct andr_boot_img_hdr_v0_v1_v2 *)boot_hdr)->header_version > 2) + printf("Only boot image header version 2 and below are supported\n"); + else + android_boot_image_v0_v1_v2_parse_hdr(boot_hdr, data); + + return true; +} + static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) { /* @@ -157,8 +224,13 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) { - const void *p = (void *)((uintptr_t)hdr + hdr->page_size); + struct andr_image_data img_data; + const void *p; + + if (!android_image_get_data(hdr, &img_data)) + return -EINVAL; + p = (const void *)img_data.kernel_ptr; if (image_get_magic((struct legacy_img_hdr *)p) == IH_MAGIC) return image_get_comp((struct legacy_img_hdr *)p); else if (get_unaligned_le32(p) == LZ4F_MAGIC) diff --git a/include/android_image.h b/include/android_image.h index 62121e2a109b..98a91cbf2f9c 100644 --- a/include/android_image.h +++ b/include/android_image.h @@ -317,4 +317,31 @@ struct andr_boot_img_hdr_v0_v1_v2 { * contained outside boot and vendor boot partitions), otherwise * jump to kernel_addr */ + +/* Private struct */ +struct andr_image_data { + ulong kernel_ptr; + u32 kernel_size; + u32 ramdisk_size; + u32 boot_ramdisk_size; + ulong second_ptr; + u32 second_size; + ulong dtb_ptr; + u32 dtb_size; + ulong recovery_dtbo_ptr; + u32 recovery_dtbo_size; + + const char *kcmdline; + const char *kcmdline_extra; + const char *image_name; + + u32 kernel_addr; + ulong ramdisk_addr; + ulong ramdisk_ptr; + ulong dtb_load_addr; + ulong tags_addr; + u32 header_version; + u32 boot_img_total_size; +}; + #endif diff --git a/include/image.h b/include/image.h index e175c920d3fb..738ef54ce6d5 100644 --- a/include/image.h +++ b/include/image.h @@ -1722,7 +1722,9 @@ struct cipher_algo { int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo); struct cipher_algo *image_get_cipher_algo(const char *full_name); +struct andr_image_data; +bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data); struct andr_boot_img_hdr_v0_v1_v2; int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify, ulong *os_data, ulong *os_len); -- 2.25.1