From patchwork Fri Jan 24 15:53:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228874 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=JfLVj7oG; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843bg4rqCz9sRW for ; Sat, 25 Jan 2020 02:54:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 38CA3817FF; Fri, 24 Jan 2020 16:53:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JfLVj7oG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1A184817FF; Fri, 24 Jan 2020 16:53:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) (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 B0E0381766 for ; Fri, 24 Jan 2020 16:53:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lf1-x142.google.com with SMTP id 203so1410464lfa.12 for ; Fri, 24 Jan 2020 07:53:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PI7SqSMtHpPOVgbv+WuffGLpmILYHxlZvJdGoBCw4LM=; b=JfLVj7oG1EjgiClUaHErGYWpSn3AtmOgUw/GINYgopZGuOWnigqR2rzwFVYeWdkCPn u8hr/+1qqHYB0HRALk/g8tbfefb2L69cV3g3xEAv9EtI2m12hfQZZSV1Md3OWqNviGEu 59XBNUrjbhVyZBf0rUg+UU09KBzHQYsH6kTgcfqVKtL8MjtOaih9IOvD4Za5jxl5u0JZ c5hehSrmdCEYrN3zl2qwTQMA8n5oVqNR3O0urAdZH/Wjk7OPvN1q+7wdp5nVdvxqEuqu t3ulpox2M8cOlm8Qc1j047ogGnSVhcRulWDDDIqq9b89WQHLdPQ7Wr/wE/83MVBUXqT2 lfXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PI7SqSMtHpPOVgbv+WuffGLpmILYHxlZvJdGoBCw4LM=; b=EiGRfzdAqyQao+3/jymw0TTdJVbjrg4WU8SgLiSJe3vCr2enAR2mDT903ht3tMnAwF e1anT5S30n8TW0XO0B1gmVBAp3ZJk3MSVINFUVDa5EezwGVomAz/Q9tG+lTUdu29f5tm wxwiWLKXfOhRr/yEQbHYF5jl0bVkEG0V/3l1b30Vxm4O3zRs6Js6ql1TU21Pxofwkiir ctXF+ZKeB5T0bMewj0oP5YnkmoAgY6ItohdWN6azmFbwUOOzX+69/MwhcVrtcR2tT6Fq 2hoPru1BI+S0hYIEsvEy6f/S07jPi5RsWXr1ctoo0FXiWikJs1crP3tVzF/CtaOp4+AP exfQ== X-Gm-Message-State: APjAAAUg8/DXKE8w6zDXuNbEtpSJAmRq92O7o+ix5+3D3An3k3GzeBfa AR1JG7PHk/XnN7yxdJywCWNTa+1CLtU= X-Google-Smtp-Source: APXvYqwrQ8BlITg1XTjuDhmUxU375OxnGO836YbfoxNEwFF8DfkrcCdv9fpz7SDnMfcepEY9Wfx4tg== X-Received: by 2002:a05:6512:407:: with SMTP id u7mr1635152lfk.146.1579881232502; Fri, 24 Jan 2020 07:53:52 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id i20sm2909341lfl.79.2020.01.24.07.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:53:52 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 01/10] image: android: Add functions for handling dtb field Date: Fri, 24 Jan 2020 17:53:40 +0200 Message-Id: <20200124155349.12927-2-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Android Boot Image v2 adds "DTB" payload (and corresponding field in the image header). Provide functions for its handling: - android_image_get_dtb_by_index(): Obtain DTB blob from "DTB" part of boot image, by blob's index - android_image_print_dtb_contents(): Iterate over all DTB blobs in "DTB" part of boot image and print those blobs info "DTB" payload might be in one of the following formats: 1. concatenated DTB blobs 2. Android DTBO format The latter requires "android-image-dt.c" functionality, so this commit selects that file for building for CONFIG_ANDROID_BOOT_IMAGE option. Right now this new functionality isn't used, but it can be used further. As it's required to apply some specific dtbo blob(s) from "dtbo" partition, we can't automate this process inside of "bootm" command. But we can do next: - come up with some new command like "abootimg" to extract dtb blob from boot image (using functions from this patch) - extract desired dtbo blobs from "dtbo" partition using "adtimg" command - merge dtbo blobs into dtb blob using "fdt apply" command - pass resulting dtb blob into bootm command in order to boot the Android kernel with Android ramdisk from boot image Signed-off-by: Sam Protsenko --- common/Makefile | 2 +- common/image-android.c | 221 +++++++++++++++++++++++++++++++++++++++++ include/image.h | 5 + 3 files changed, 227 insertions(+), 1 deletion(-) diff --git a/common/Makefile b/common/Makefile index 5f62b8d0b1..896e4af91d 100644 --- a/common/Makefile +++ b/common/Makefile @@ -108,7 +108,7 @@ endif obj-y += image.o obj-$(CONFIG_ANDROID_AB) += android_ab.o -obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o +obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o diff --git a/common/image-android.c b/common/image-android.c index 3564a64221..220983655a 100644 --- a/common/image-android.c +++ b/common/image-android.c @@ -6,10 +6,12 @@ #include #include #include +#include #include #include #include #include +#include #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000 @@ -195,6 +197,121 @@ int android_image_get_second(const struct andr_img_hdr *hdr, return 0; } +/** + * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image. + * @hdr_addr: Boot image header address + * @addr: Will contain the address of DTB area in boot image + * + * Return: true on success or false on fail. + */ +static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr) +{ + const struct andr_img_hdr *hdr; + ulong dtb_img_addr; + bool ret = true; + + hdr = map_sysmem(hdr_addr, sizeof(*hdr)); + if (android_image_check_header(hdr)) { + printf("Error: Boot Image header is incorrect\n"); + ret = false; + goto exit; + } + + if (hdr->header_version < 2) { + printf("Error: header_version must be >= 2 to get dtb\n"); + ret = false; + goto exit; + } + + if (hdr->dtb_size == 0) { + printf("Error: dtb_size is 0\n"); + ret = false; + goto exit; + } + + /* Calculate the address of DTB area in boot image */ + dtb_img_addr = hdr_addr; + dtb_img_addr += hdr->page_size; + dtb_img_addr += ALIGN(hdr->kernel_size, hdr->page_size); + dtb_img_addr += ALIGN(hdr->ramdisk_size, hdr->page_size); + dtb_img_addr += ALIGN(hdr->second_size, hdr->page_size); + dtb_img_addr += ALIGN(hdr->recovery_dtbo_size, hdr->page_size); + + *addr = dtb_img_addr; + +exit: + unmap_sysmem(hdr); + return ret; +} + +/** + * android_image_get_dtb_by_index() - Get address and size of blob in DTB area. + * @hdr_addr: Boot image header address + * @index: Index of desired DTB in DTB area (starting from 0) + * @addr: If not NULL, will contain address to specified DTB + * @size: If not NULL, will contain size of specified DTB + * + * Get the address and size of DTB blob by its index in DTB area of Android + * Boot Image in RAM. + * + * Return: true on success or false on error. + */ +bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, + u32 *size) +{ + const struct andr_img_hdr *hdr; + bool res; + ulong dtb_img_addr; /* address of DTB part in boot image */ + u32 dtb_img_size; /* size of DTB payload in boot image */ + ulong dtb_addr; /* address of DTB blob with specified index */ + u32 i; /* index iterator */ + + res = android_image_get_dtb_img_addr(hdr_addr, &dtb_img_addr); + if (!res) + return false; + + /* Check if DTB area of boot image is in DTBO format */ + if (android_dt_check_header(dtb_img_addr)) { + return android_dt_get_fdt_by_index(dtb_img_addr, index, addr, + size); + } + + /* Find out the address of DTB with specified index in concat blobs */ + hdr = map_sysmem(hdr_addr, sizeof(*hdr)); + dtb_img_size = hdr->dtb_size; + unmap_sysmem(hdr); + i = 0; + dtb_addr = dtb_img_addr; + while (dtb_addr < dtb_img_addr + dtb_img_size) { + const struct fdt_header *fdt; + u32 dtb_size; + + fdt = map_sysmem(dtb_addr, sizeof(*fdt)); + if (fdt_check_header(fdt) != 0) { + unmap_sysmem(fdt); + printf("Error: Invalid FDT header for index %u\n", i); + return false; + } + + dtb_size = fdt_totalsize(fdt); + unmap_sysmem(fdt); + + if (i == index) { + if (size) + *size = dtb_size; + if (addr) + *addr = dtb_addr; + return true; + } + + dtb_addr += dtb_size; + ++i; + } + + printf("Error: Index is out of bounds (%u/%u)\n", index, i); + return false; +} + #if !defined(CONFIG_SPL_BUILD) /** * android_print_contents - prints out the contents of the Android format image @@ -246,4 +363,108 @@ void android_print_contents(const struct andr_img_hdr *hdr) printf("%sdtb addr: %llx\n", p, hdr->dtb_addr); } } + +/** + * android_image_print_dtb_info - Print info for one DTB blob in DTB area. + * @fdt: DTB header + * @index: Number of DTB blob in DTB area. + * + * Return: true on success or false on error. + */ +static bool android_image_print_dtb_info(const struct fdt_header *fdt, + u32 index) +{ + int root_node_off; + u32 fdt_size; + const char *model; + const char *compatible; + + root_node_off = fdt_path_offset(fdt, "/"); + if (root_node_off < 0) { + printf("Error: Root node not found\n"); + return false; + } + + fdt_size = fdt_totalsize(fdt); + compatible = fdt_getprop(fdt, root_node_off, "compatible", + NULL); + model = fdt_getprop(fdt, root_node_off, "model", NULL); + + printf(" - DTB #%u:\n", index); + printf(" (DTB)size = %d\n", fdt_size); + printf(" (DTB)model = %s\n", model ? model : "(unknown)"); + printf(" (DTB)compatible = %s\n", + compatible ? compatible : "(unknown)"); + + return true; +} + +/** + * android_image_print_dtb_contents() - Print info for DTB blobs in DTB area. + * @hdr_addr: Boot image header address + * + * DTB payload in Android Boot Image v2+ can be in one of following formats: + * 1. Concatenated DTB blobs + * 2. Android DTBO format (see CONFIG_CMD_ADTIMG for details) + * + * This function does next: + * 1. Prints out the format used in DTB area + * 2. Iterates over all DTB blobs in DTB area and prints out the info for + * each blob. + * + * Return: true on success or false on error. + */ +bool android_image_print_dtb_contents(ulong hdr_addr) +{ + const struct andr_img_hdr *hdr; + bool res; + ulong dtb_img_addr; /* address of DTB part in boot image */ + u32 dtb_img_size; /* size of DTB payload in boot image */ + ulong dtb_addr; /* address of DTB blob with specified index */ + u32 i; /* index iterator */ + + res = android_image_get_dtb_img_addr(hdr_addr, &dtb_img_addr); + if (!res) + return false; + + /* Check if DTB area of boot image is in DTBO format */ + if (android_dt_check_header(dtb_img_addr)) { + printf("## DTB area contents (DTBO format):\n"); + android_dt_print_contents(dtb_img_addr); + return true; + } + + printf("## DTB area contents (concat format):\n"); + + /* Iterate over concatenated DTB blobs */ + hdr = map_sysmem(hdr_addr, sizeof(*hdr)); + dtb_img_size = hdr->dtb_size; + unmap_sysmem(hdr); + i = 0; + dtb_addr = dtb_img_addr; + while (dtb_addr < dtb_img_addr + dtb_img_size) { + const struct fdt_header *fdt; + u32 dtb_size; + + fdt = map_sysmem(dtb_addr, sizeof(*fdt)); + if (fdt_check_header(fdt) != 0) { + unmap_sysmem(fdt); + printf("Error: Invalid FDT header for index %u\n", i); + return false; + } + + res = android_image_print_dtb_info(fdt, i); + if (!res) { + unmap_sysmem(fdt); + return false; + } + + dtb_size = fdt_totalsize(fdt); + unmap_sysmem(fdt); + dtb_addr += dtb_size; + ++i; + } + + return true; +} #endif diff --git a/include/image.h b/include/image.h index 9c6b6d6054..4e36b87f42 100644 --- a/include/image.h +++ b/include/image.h @@ -1425,10 +1425,15 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr, ulong *rd_data, ulong *rd_len); int android_image_get_second(const struct andr_img_hdr *hdr, ulong *second_data, ulong *second_len); +bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, + u32 *size); ulong android_image_get_end(const struct andr_img_hdr *hdr); ulong android_image_get_kload(const struct andr_img_hdr *hdr); ulong android_image_get_kcomp(const struct andr_img_hdr *hdr); void android_print_contents(const struct andr_img_hdr *hdr); +#if !defined(CONFIG_SPL_BUILD) +bool android_image_print_dtb_contents(ulong hdr_addr); +#endif #endif /* CONFIG_ANDROID_BOOT_IMAGE */ From patchwork Fri Jan 24 15:53:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228876 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=JASaTz/1; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843c256Sjz9sRY for ; Sat, 25 Jan 2020 02:54:26 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DC19B81825; Fri, 24 Jan 2020 16:54:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JASaTz/1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C02A817B6; Fri, 24 Jan 2020 16:54:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) (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 E73D0817B6 for ; Fri, 24 Jan 2020 16:53:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lf1-x141.google.com with SMTP id b15so1439995lfc.4 for ; Fri, 24 Jan 2020 07:53:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/2nhEMJxv7ziCwzPchU1kqKZSwYID2ZRksKzT1ZTG6k=; b=JASaTz/1iglFCFxnrfvNNugDWl6jDj2/JUZcYLTrrUSWIirvvsXg8xlqvtFQz0v78L Xn1z/OeDam+zhLiEpmsYSKD8ND4iVPQXAyW7aYYwa5heY1kRiDU8Ls56h3gDwYjt2diU 16pdS0KQmV96/qsrt+HPvdflEQQFiieSWo9N4vb4RLTH2kcd8ev03DeLhKE+dA/hl+wX oFH5nqF/TYUcELnIxPI7KADDLZv5aGomR7IijoFXQjQEsXGhiUn/JJYvrfhJGHFLYVH1 /y+PEJr/q11Xk2RP08sKDGP8q/GJnNGw3DadbmilLrwuMqUT2VCj/QwpLHtq53InExVK xA2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/2nhEMJxv7ziCwzPchU1kqKZSwYID2ZRksKzT1ZTG6k=; b=FFqJb3fmrGvVNsrtAj5AfyWVskh6kZ7TGCWVBOzPETtmGO33pF5/NrDxdy851WPpIf mJcZ/86t9vZ2cbo4Ax0uFAPZmTTQ5RZB0o2pFZrr3W7IgYzXk1jGf2oNwOl2Ft8UOpQP tBgXZe5vhns7gQe0aKfOg2RKPHv1XpM7glkvkrQx6CJgiLM5ZFPkX9VikgIcpKUGNEzd iVVme2Wa5FR+WmnlSuLiQlpR2knD+HQpZ2s6HKdemt/Rppmk//tvyFzpKsw0bVEce8p+ muFW/ku+GVp1bICHFgSrXTOVXDUk5Y0MBv9YMo5xVjoHwylzSAykXacosp545duD7NDr KX3Q== X-Gm-Message-State: APjAAAXGThWytoGstIZqE7JKInae6/w/x36oMg112GDIFREmOo7aRt2z WQb/a3EnJxWQRsx7mxmnJQyqi66aVoo= X-Google-Smtp-Source: APXvYqykY9N8vjq9adgkB4W8hSlSJitbr32HUg31Hnryw4zbaTNdN9P6arGGznrX2rfhdhw7M5YplQ== X-Received: by 2002:ac2:482c:: with SMTP id 12mr1652636lft.163.1579881233874; Fri, 24 Jan 2020 07:53:53 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id s18sm3849573ljj.36.2020.01.24.07.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:53:53 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 02/10] image: android: Add routine to get dtbo params Date: Fri, 24 Jan 2020 17:53:41 +0200 Message-Id: <20200124155349.12927-3-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Android Boot Image v1 adds "Recovery DTB" field in image header and associate payload in boot image itself [1]. Payload should be in Android DTB/DTBO format [2]. That "Recovery DTB" area should be only populated for non-A/B devices, and only in recovery image. Add function to get an address and size of that payload. That function can be further used e.g. in 'abootimg' command to provide the user a way to get the address of recovery dtbo from U-Boot shell, which can be further parsed using 'adtimg' command. [1] https://source.android.com/devices/bootloader/boot-image-header [2] https://source.android.com/devices/architecture/dto/partitions Signed-off-by: Sam Protsenko --- common/image-android.c | 61 ++++++++++++++++++++++++++++++++++++++++++ include/image.h | 1 + 2 files changed, 62 insertions(+) diff --git a/common/image-android.c b/common/image-android.c index 220983655a..6af9baa121 100644 --- a/common/image-android.c +++ b/common/image-android.c @@ -197,6 +197,67 @@ int android_image_get_second(const struct andr_img_hdr *hdr, return 0; } +/** + * android_image_get_dtbo() - Get address and size of recovery DTBO image. + * @hdr_addr: Boot image header address + * @addr: If not NULL, will contain address of recovery DTBO image + * @size: If not NULL, will contain size of recovery DTBO image + * + * Get the address and size of DTBO image in "Recovery DTBO" area of Android + * Boot Image in RAM. The format of this image is Android DTBO (see + * corresponding "DTB/DTBO Partitions" AOSP documentation for details). Once + * the address is obtained from this function, one can use 'adtimg' U-Boot + * command or android_dt_*() functions to extract desired DTBO blob. + * + * This DTBO (included in boot image) is only needed for non-A/B devices, and it + * only can be found in recovery image. On A/B devices we can always rely on + * "dtbo" partition. See "Including DTBO in Recovery for Non-A/B Devices" in + * AOSP documentation for details. + * + * Return: true on success or false on error. + */ +bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size) +{ + const struct andr_img_hdr *hdr; + ulong dtbo_img_addr; + bool ret = true; + + hdr = map_sysmem(hdr_addr, sizeof(*hdr)); + if (android_image_check_header(hdr)) { + printf("Error: Boot Image header is incorrect\n"); + ret = false; + goto exit; + } + + if (hdr->header_version < 1) { + printf("Error: header_version must be >= 1 to get dtbo\n"); + ret = false; + goto exit; + } + + if (hdr->recovery_dtbo_size == 0) { + printf("Error: recovery_dtbo_size is 0\n"); + ret = false; + goto exit; + } + + /* Calculate the address of DTB area in boot image */ + dtbo_img_addr = hdr_addr; + dtbo_img_addr += hdr->page_size; + dtbo_img_addr += ALIGN(hdr->kernel_size, hdr->page_size); + dtbo_img_addr += ALIGN(hdr->ramdisk_size, hdr->page_size); + dtbo_img_addr += ALIGN(hdr->second_size, hdr->page_size); + + if (addr) + *addr = dtbo_img_addr; + if (size) + *size = hdr->recovery_dtbo_size; + +exit: + unmap_sysmem(hdr); + return ret; +} + /** * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image. * @hdr_addr: Boot image header address diff --git a/include/image.h b/include/image.h index 4e36b87f42..b316d167d8 100644 --- a/include/image.h +++ b/include/image.h @@ -1425,6 +1425,7 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr, ulong *rd_data, ulong *rd_len); int android_image_get_second(const struct andr_img_hdr *hdr, ulong *second_data, ulong *second_len); +bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size); bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, u32 *size); ulong android_image_get_end(const struct andr_img_hdr *hdr); From patchwork Fri Jan 24 15:53:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228877 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=q4bdjNHd; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843cL0NvHz9sRW for ; Sat, 25 Jan 2020 02:54:42 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 024E581813; Fri, 24 Jan 2020 16:54:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="q4bdjNHd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9DEDE817C0; Fri, 24 Jan 2020 16:54:01 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) (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 A955D81766 for ; Fri, 24 Jan 2020 16:53:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lj1-x243.google.com with SMTP id x14so638297ljd.13 for ; Fri, 24 Jan 2020 07:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vS+Fm1ryjCST2B6Mu+4pW4N9fsXyfJSRWD+pWmWAIlU=; b=q4bdjNHdhTtgaBQUo5htdVNwXUcnWHoTNVoL8D84QSwR1kXbGcx+iws4qfmnDXmHuD B27twBVJOnJ+bdE7/2095QEXRar3duNFsbTEAt6TVp7fEKMuhAEYEgCvgmiRwuKa1xSX mP96VgLMKmglbmyx/eJuFZqWb2Y1SYyQwuGlAsb1mX9aRypVHCRVvFAoih/zQHA9NSwH C8ytbivAJyrjupKHft4WN/e77RGQunrlV3XsI9vIaiOXZAlZGEbxoLvLS6kzsj2aZ9We 3S8A/CZSNa0RlxW11YKAXZMQK5iC32nJjphpeqIOhaJuDu3MKSjEXkDS7U7xJJX91NUw 4UuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vS+Fm1ryjCST2B6Mu+4pW4N9fsXyfJSRWD+pWmWAIlU=; b=GlJ6RB5VAMHQ5BQpmL3WbGtm4r2cdyfeCh9xhOi2O7YRYfY1fAco988a/vb6s5cDGh 7AkGZk3Qlu9eiupGQNAd76cCFcPHcjD/acBo/Xmh30VAjCK1N7YIJCumvX/F1P+C1QDF qUiNig6TiWqjjCc7JCAmtNMdM/X1ASuys7L3OkM5VLgKdmkcutFs3TvnCRIoYBV7prOb wrajAHCkzQWD1jhJaSKTNHa2QSZARun2F2pAxXgCtdpkYkUWmoXeNXLR58laNdzkixOu C2EJgwqxxM8cR9V0SFFYKBvDvTstx6uNk5uwxuSZN7gIScqk/o7HTmLyEJbeNHMQ1Hba Z8hA== X-Gm-Message-State: APjAAAW1PCaXZ/eI9mgjyPLfx7Lf6Fv47N7KbbT94Y6NqdIy/0A6tOoJ BaoR+DcmDrEWGyul54fQAsghqzDLPyU= X-Google-Smtp-Source: APXvYqw3cXVk4AZ/aQUEyXtObkObL3oQWbFfW8qGBikWLIS9I9V5x+nCd4k8CdKHBFEpx0VDuDozGw== X-Received: by 2002:a2e:b554:: with SMTP id a20mr2592902ljn.25.1579881235180; Fri, 24 Jan 2020 07:53:55 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id q10sm3281944ljj.60.2020.01.24.07.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:53:54 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 03/10] cmd: abootimg: Add abootimg command Date: Fri, 24 Jan 2020 17:53:42 +0200 Message-Id: <20200124155349.12927-4-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean This command can be used to extract fields and image payloads from Android Boot Image. It can be used for example to implement boot flow where dtb is taken from boot.img (as v2 incorporated dtb inside of boot.img). Using this command, one can obtain needed dtb blob from boot.img in scripting manner, and then apply needed dtbo's (from "dtbo" partition) on top of that, providing then the resulting image to bootm command in order to boot the Android. Also right now this command has the sub-command to get an address and size of recovery dtbo from recovery image (for non-A/B devices only, see [1,2] for details). It can be tested like this: => mmc dev 1 => part start mmc 1 boot_a boot_start => part size mmc 1 boot_a boot_size => mmc read $loadaddr $boot_start $boot_size => abootimg get ver => abootimg dump dtb [1] https://source.android.com/devices/bootloader/boot-image-header [2] https://source.android.com/devices/architecture/dto/partitions Signed-off-by: Sam Protsenko --- cmd/Kconfig | 8 ++ cmd/Makefile | 1 + cmd/abootimg.c | 258 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 cmd/abootimg.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 6e1efaaf85..4734da17fe 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -386,6 +386,14 @@ config CMD_ADTIMG files should be merged in one dtb further, which needs to be passed to the kernel, as part of a boot process. +config CMD_ABOOTIMG + bool "abootimg" + depends on ANDROID_BOOT_IMAGE + help + Android Boot Image manipulation commands. Allows one to extract + images contained in boot.img, like kernel, ramdisk, dtb, etc, and + obtain corresponding meta-information from boot.img. + config CMD_ELF bool "bootelf, bootvx" default y diff --git a/cmd/Makefile b/cmd/Makefile index 4f29b72c69..f1dd513a4b 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -48,6 +48,7 @@ ifdef CONFIG_POST obj-$(CONFIG_CMD_DIAG) += diag.o endif obj-$(CONFIG_CMD_ADTIMG) += adtimg.o +obj-$(CONFIG_CMD_ABOOTIMG) += abootimg.o obj-$(CONFIG_CMD_ECHO) += echo.o obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o obj-$(CONFIG_CMD_EEPROM) += eeprom.o diff --git a/cmd/abootimg.c b/cmd/abootimg.c new file mode 100644 index 0000000000..670bcb3aaa --- /dev/null +++ b/cmd/abootimg.c @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2020 + * Sam Protsenko + */ + +#include +#include +#include + +#define abootimg_addr() \ + (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr) + +/* Please use abootimg_addr() macro to obtain the boot image address */ +static ulong _abootimg_addr = -1; + +static int abootimg_get_ver(int argc, char * const argv[]) +{ + const struct andr_img_hdr *hdr; + int res = CMD_RET_SUCCESS; + + if (argc > 1) + return CMD_RET_USAGE; + + hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); + if (android_image_check_header(hdr)) { + printf("Error: Boot Image header is incorrect\n"); + res = CMD_RET_FAILURE; + goto exit; + } + + if (argc == 0) + printf("%u\n", hdr->header_version); + else + env_set_ulong(argv[0], hdr->header_version); + +exit: + unmap_sysmem(hdr); + return res; +} + +static int abootimg_get_recovery_dtbo(int argc, char * const argv[]) +{ + ulong addr; + u32 size; + + if (argc > 2) + return CMD_RET_USAGE; + + if (!android_image_get_dtbo(abootimg_addr(), &addr, &size)) + return CMD_RET_FAILURE; + + if (argc == 0) { + printf("%lx\n", addr); + } else { + env_set_hex(argv[0], addr); + if (argc == 2) + env_set_hex(argv[1], size); + } + + return CMD_RET_SUCCESS; +} + +static int abootimg_get_dtb_load_addr(int argc, char * const argv[]) +{ + const struct andr_img_hdr *hdr; + int res = CMD_RET_SUCCESS; + + if (argc > 1) + return CMD_RET_USAGE; + + hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); + if (android_image_check_header(hdr)) { + printf("Error: Boot Image header is incorrect\n"); + res = CMD_RET_FAILURE; + goto exit; + } + + if (hdr->header_version < 2) { + printf("Error: header_version must be >= 2 for this\n"); + res = CMD_RET_FAILURE; + goto exit; + } + + if (argc == 0) + printf("%lx\n", (ulong)hdr->dtb_addr); + else + env_set_hex(argv[0], (ulong)hdr->dtb_addr); + +exit: + unmap_sysmem(hdr); + return res; +} + +static int abootimg_get_dtb_by_index(int argc, char * const argv[]) +{ + const char *index_str; + u32 num; + char *endp; + ulong addr; + u32 size; + + if (argc < 1 || argc > 3) + return CMD_RET_USAGE; + + index_str = argv[0] + strlen("--index="); + if (index_str[0] == '\0') { + printf("Error: Wrong index num\n"); + return CMD_RET_FAILURE; + } + + num = simple_strtoul(index_str, &endp, 0); + if (*endp != '\0') { + printf("Error: Wrong index num\n"); + return CMD_RET_FAILURE; + } + + if (!android_image_get_dtb_by_index(abootimg_addr(), num, + &addr, &size)) { + return CMD_RET_FAILURE; + } + + if (argc == 1) { + printf("%lx\n", addr); + } else { + if (env_set_hex(argv[1], addr)) { + printf("Error: Can't set [addr_var]\n"); + return CMD_RET_FAILURE; + } + + if (argc == 3) { + if (env_set_hex(argv[2], size)) { + printf("Error: Can't set [size_var]\n"); + return CMD_RET_FAILURE; + } + } + } + + return CMD_RET_SUCCESS; +} + +static int abootimg_get_dtb(int argc, char * const argv[]) +{ + if (argc < 1) + return CMD_RET_USAGE; + + if (strstr(argv[0], "--index=")) + return abootimg_get_dtb_by_index(argc, argv); + + return CMD_RET_USAGE; +} + +static int do_abootimg_addr(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + char *endp; + ulong img_addr; + + if (argc != 2) + return CMD_RET_USAGE; + + img_addr = simple_strtoul(argv[1], &endp, 16); + if (*endp != '\0') { + printf("Error: Wrong image address\n"); + return CMD_RET_FAILURE; + } + + _abootimg_addr = img_addr; + return CMD_RET_SUCCESS; +} + +static int do_abootimg_get(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + const char *param; + + if (argc < 2) + return CMD_RET_USAGE; + + param = argv[1]; + argc -= 2; + argv += 2; + if (!strcmp(param, "ver")) + return abootimg_get_ver(argc, argv); + else if (!strcmp(param, "recovery_dtbo")) + return abootimg_get_recovery_dtbo(argc, argv); + else if (!strcmp(param, "dtb_load_addr")) + return abootimg_get_dtb_load_addr(argc, argv); + else if (!strcmp(param, "dtb")) + return abootimg_get_dtb(argc, argv); + + return CMD_RET_USAGE; +} + +static int do_abootimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + if (argc != 2) + return CMD_RET_USAGE; + + if (!strcmp(argv[1], "dtb")) { + if (android_image_print_dtb_contents(abootimg_addr())) + return CMD_RET_FAILURE; + } else { + return CMD_RET_USAGE; + } + + return CMD_RET_SUCCESS; +} + +static cmd_tbl_t cmd_abootimg_sub[] = { + U_BOOT_CMD_MKENT(addr, 2, 1, do_abootimg_addr, "", ""), + U_BOOT_CMD_MKENT(dump, 2, 1, do_abootimg_dump, "", ""), + U_BOOT_CMD_MKENT(get, 5, 1, do_abootimg_get, "", ""), +}; + +static int do_abootimg(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + cmd_tbl_t *cp; + + cp = find_cmd_tbl(argv[1], cmd_abootimg_sub, + ARRAY_SIZE(cmd_abootimg_sub)); + + /* Strip off leading 'abootimg' command argument */ + argc--; + argv++; + + if (!cp || argc > cp->maxargs) + return CMD_RET_USAGE; + if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) + return CMD_RET_SUCCESS; + + return cp->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD( + abootimg, CONFIG_SYS_MAXARGS, 0, do_abootimg, + "manipulate Android Boot Image", + "addr \n" + " - set the address in RAM where boot image is located\n" + " ($loadaddr is used by default)\n" + "abootimg dump dtb\n" + " - print info for all DT blobs in DTB area\n" + "abootimg get ver [varname]\n" + " - get header version\n" + "abootimg get recovery_dtbo [addr_var [size_var]]\n" + " - get address and size (hex) of recovery DTBO area in the image\n" + " [addr_var]: variable name to contain DTBO area address\n" + " [size_var]: variable name to contain DTBO area size\n" + "abootimg get dtb_load_addr [varname]\n" + " - get load address (hex) of DTB, from image header\n" + "abootimg get dtb --index= [addr_var [size_var]]\n" + " - get address and size (hex) of DT blob in the image by index\n" + " : index number of desired DT blob in DTB area\n" + " [addr_var]: variable name to contain DT blob address\n" + " [size_var]: variable name to contain DT blob size" +); From patchwork Fri Jan 24 15:53:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228878 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=EUFVHI2B; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843cT6Xs5z9sRY for ; Sat, 25 Jan 2020 02:54:49 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1A18081819; Fri, 24 Jan 2020 16:54:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EUFVHI2B"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C9424817C0; Fri, 24 Jan 2020 16:54:03 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) (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 EADF88177B for ; Fri, 24 Jan 2020 16:53:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lj1-x241.google.com with SMTP id r19so3042807ljg.3 for ; Fri, 24 Jan 2020 07:53:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wDGt3xIFCnGKPVV9qt/LOsgL+HBBNG9CRVKr4c0JyZo=; b=EUFVHI2BswEpMBDjC4oFbeRLD+3czSSNVzssIxAZJdHd0m8jS4IWSaBSItCb0BQ9Mx 0PbmyMHYDIufILDqgr6+gzYfjuJifdIpK94xISlZLc39KpvV986ztycIvskNzKB1/FP5 bh38klvuN2rREM7KlTS0L69UMhcglGkH4C8431iAlZy1c4rZv6n8uIDeTrBE2kEG3Wtw m3Iu/CPP6WibQLl1JycSEd2Yh4rru9mpJYpKGFx07XJ+iYFEQGEqaAZ7X3Qz3OkcVFsE fGKZ9tP8rFZ/0Uz1I5r2KcTHRTnLYFtOHXSwGmvf+H+J/98EiV9AUojtGR/OeKB6SKuk DOtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wDGt3xIFCnGKPVV9qt/LOsgL+HBBNG9CRVKr4c0JyZo=; b=MRRpuusXxlQHvnSFPQg+IVggenNwHF1mWCj/GWu91f3RtNIsIxrc5TcuRr6oXVg6XS /hgdZiGRK2pnvI1BdIE6TvVziYhbTfNthEpdV2UpexGOQHLMePdSxoNzNeexiXrMdLM5 tkjGjS8MeukxF9k9MWrEAUCdEBaSMVYPpia1h/iXCaSlp+1grBc9ozzxB3hfxGpwEqwi D59V+s41a23HWwy051qR7T2RiSyw38Vg7kEYbtfh2Ho/ok8xW9pnUBcu182zvVXKZQ90 CGP+BktbDb2CAM7/oLmWRBjt4gZb7d+U0gqHPzUmbVZZlwU8xN6uivofUrg0qnckHiAj 53YA== X-Gm-Message-State: APjAAAUnV9MX9m067Xzq0RCTBWsifi68fs27l26BX7LzdhKKEQgKRHzb VvIOgEhntHAabgndIhOfxlEFuhHxDiY= X-Google-Smtp-Source: APXvYqzwCAk//XP6KRrOIXzoRSa/gKcQm0NxCCO76qNfcOY+aCUSLd8OPt3qxWF1K6KFAAvDXlhhVg== X-Received: by 2002:a2e:9013:: with SMTP id h19mr2713436ljg.223.1579881236518; Fri, 24 Jan 2020 07:53:56 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id g15sm3240724ljn.32.2020.01.24.07.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:53:56 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 04/10] doc: android: Add documentation for Android Boot Image Date: Fri, 24 Jan 2020 17:53:43 +0200 Message-Id: <20200124155349.12927-5-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Describe Android Boot Image format, how its support is implemented in U-Boot and associated commands usage. Signed-off-by: Sam Protsenko --- cmd/Kconfig | 2 + doc/android/boot-image.rst | 154 +++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 doc/android/boot-image.rst diff --git a/cmd/Kconfig b/cmd/Kconfig index 4734da17fe..6a2f6fb070 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -394,6 +394,8 @@ config CMD_ABOOTIMG images contained in boot.img, like kernel, ramdisk, dtb, etc, and obtain corresponding meta-information from boot.img. + See doc/android/boot-image.rst for details. + config CMD_ELF bool "bootelf, bootvx" default y diff --git a/doc/android/boot-image.rst b/doc/android/boot-image.rst new file mode 100644 index 0000000000..195da688f4 --- /dev/null +++ b/doc/android/boot-image.rst @@ -0,0 +1,154 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. sectionauthor:: Sam Protsenko + +Android Boot Image +================== + +Overview +-------- + +Android Boot Image is used to boot Android OS. It usually contains kernel image +(like ``zImage`` file) and ramdisk. Sometimes it can contain additional +binaries. This image is built as a part of AOSP (called ``boot.img``), and being +flashed into ``boot`` partition on eMMC. Bootloader then reads that image from +``boot`` partition to RAM and boots the kernel from it. Kernel than starts +``init`` process from the ramdisk. It should be mentioned that recovery image +(``recovery.img``) also has Android Boot Image format. + +Android Boot Image format is described at [1]_. At the moment it can have one of +next image headers: + +* v0: it's called *legacy* boot image header; used in devices launched before + Android 9; contains kernel image, ramdisk and second stage bootloader + (usually unused) +* v1: used in devices launched with Android 9; adds ``recovery_dtbo`` field, + which should be used for non-A/B devices in ``recovery.img`` (see [2]_ for + details) +* v2: used in devices launched with Android 10; adds ``dtb`` field, which + references payload containing DTB blobs (either concatenated one after the + other, or in Android DTBO image format) + +v2, v1 and v0 formats are backward compatible. + +Android Boot Image format is represented by :c:type:`struct andr_img_hdr` in +U-Boot, and can be seen in ``include/android_image.h``. U-Boot supports booting +Android Boot Image and also has associated command + +Booting +------- + +U-Boot is able to boot the Android OS from Android Boot Image using ``bootm`` +command. In order to use Android Boot Image format support, next option should +be enabled:: + + CONFIG_ANDROID_BOOT_IMAGE=y + +Then one can use next ``bootm`` command call to run Android: + +.. code-block:: bash + + => bootm $loadaddr $loadaddr $fdtaddr + +where ``$loadaddr`` - address in RAM where boot image was loaded; ``$fdtaddr`` - +address in RAM where DTB blob was loaded. + +And parameters are, correspondingly: + + 1. Where kernel image is located in RAM + 2. Where ramdisk is located in RAM (can be ``"-"`` if not applicable) + 3. Where DTB blob is located in RAM + +``bootm`` command will figure out that image located in ``$loadaddr`` has +Android Boot Image format, will parse that and boot the kernel from it, +providing DTB blob to kernel (from 3rd parameter), passing info about ramdisk to +kernel via DTB. + +DTB and DTBO blobs +------------------ + +``bootm`` command can't just use DTB blob from Android Boot Image (``dtb`` +field), because: + +* there is no DTB area in Android Boot Image before v2 +* there may be several DTB blobs in DTB area (e.g. for different SoCs) +* some DTBO blobs may have to be merged in DTB blobs before booting + (e.g. for different boards) + +So user has to prepare DTB blob manually and provide it in a 3rd parameter +of ``bootm`` command. Next commands can be used to do so: + +1. ``abootimg``: manipulates Anroid Boot Image, allows one to extract + meta-information and payloads from it +2. ``adtimg``: manipulates Android DTB/DTBO image [3]_, allows one to extract + DTB/DTBO blobs from it + +In order to use those, please enable next config options:: + + CONFIG_CMD_ABOOTIMG=y + CONFIG_CMD_ADTIMG=y + +For example, let's assume we have next Android partitions on eMMC: + +* ``boot``: contains Android Boot Image v2 (including DTB blobs) +* ``dtbo``: contains DTBO blobs + +Then next command sequence can be used to boot Android: + +.. code-block:: bash + + => mmc dev 1 + + # Read boot image to RAM (into $loadaddr) + => part start mmc 1 boot boot_start + => part size mmc 1 boot boot_size + => mmc read $loadaddr $boot_start $boot_size + + # Read DTBO image to RAM (into $dtboaddr) + => part start mmc 1 dtbo dtbo_start + => part size mmc 1 dtbo dtbo_size + => mmc read $dtboaddr $dtbo_start $dtbo_size + + # Copy required DTB blob (into $fdtaddr) + => abootimg get dtb --index=0 dtb0_start dtb0_size + => cp.b $dtb0_start $fdtaddr $dtb0_size + + # Merge required DTBO blobs into DTB blob + => fdt addr $fdtaddr 0x100000 + => adtimg addr $dtboaddr + => adtimg get dt --index=0 $dtbo0_addr + => fdt apply $dtbo0_addr + + # Boot Android + => bootm $loadaddr $loadaddr $fdtaddr + +This sequence should be used for Android 10 boot. Of course, the whole Android +boot procedure includes much more actions, like: + +* obtaining reboot reason from BCB (see [4]_) +* implementing recovery boot +* implementing fastboot boot +* implementing A/B slotting (see [5]_) +* implementing AVB2.0 (see [6]_) + +But Android Boot Image booting is the most crucial part in Android boot scheme. + +All Android bootloader requirements documentation is available at [7]_. Some +overview on the whole Android 10 boot process can be found at [8]_. + +C API for working with Android Boot Image format +------------------------------------------------ + +.. kernel-doc:: common/image-android.c + :internal: + +References +---------- + +.. [1] https://source.android.com/devices/bootloader/boot-image-header +.. [2] https://source.android.com/devices/bootloader/recovery-image +.. [3] https://source.android.com/devices/architecture/dto/partitions +.. [4] :doc:`bcb` +.. [5] :doc:`ab` +.. [6] :doc:`avb2` +.. [7] https://source.android.com/devices/bootloader +.. [8] https://connect.linaro.org/resources/san19/san19-217/ From patchwork Fri Jan 24 15:53:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228881 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=eJfK9Rbs; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843dD4JrPz9sRW for ; Sat, 25 Jan 2020 02:55:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 839CA81952; Fri, 24 Jan 2020 16:54:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eJfK9Rbs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A03481836; Fri, 24 Jan 2020 16:54:08 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) (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 3236A81801 for ; Fri, 24 Jan 2020 16:54:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lf1-x12f.google.com with SMTP id 9so1423524lfq.10 for ; Fri, 24 Jan 2020 07:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=auwf9PMWyCqKzYo50A5HD2MnaAvpoMR5BohbFGcmsao=; b=eJfK9RbsxtAk3sU8SxlnV815aojNeYf/B4pNnq0IlSMtAyrXxB1gVyFpjFzT11OYME gZRw207DgY9njBLYtBY0PYVJQCYr8KoTRY2Meds7PTTy+Y5JbfnShlVgrospxwjSSUl/ eJL6Sk3JKQ6uYFHBfhrrfd1Ao69yCwY66euT9uEEfo6UFxQZNuvxL6iKn71V5gZIr1Ic SnSM9CK/LuMVHV3Frkf8j7JZNmepYysrd7Tr3KfSX/Hr4tRnmk+OK+bx/VJ0SACj6ECq xk/POZnaJhPjqPe8SEXAQMqgeuZlT25VnB7v5Q7ZKhi+ESqWLmeUttCLRZC+3glu1dpL 2O6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=auwf9PMWyCqKzYo50A5HD2MnaAvpoMR5BohbFGcmsao=; b=eAYXVOiCeR4wYjGF2vtmHJs60Ki8FVPmlTPDaK1LvAdNao/JgQ6wYF1HeGmp80Crx3 XsKyc+iTMzubm6Es/b3QZ73wdSSwPY8pMISqmJR9itbh55c5ktUimyLayNzruHUVIAB3 rftjB1fwkZtK+wXGOlD9I6at3tkPkkSZX28mEdBiA1RK+J+kCxZbhhg3/xfLEPxW7CHP KCyENbI5thrOhxY7dYgtpdXhYPl5/Loteiu26RWcVs7LZb6l95A842VHPHxA5VbsiJ2o oxOyPFR0turv9oAlVOIQmA41agLD3lPmYkw7u5URzwb3DsekzDlLvgih9fM1n374d4t6 Q0ig== X-Gm-Message-State: APjAAAUc4nO7/vcTs1hSsqPrljz/Kj5ABbvEj6iFmuGNhSI5H7PgQfFt UKIXN0SuFxUvtI2oglK9eWObpeLgG9U= X-Google-Smtp-Source: APXvYqxZ8dx3N/wBg1YvzERAQRNwQGPG95pjRBh/OAOrH4aivIFXJoOMfAPM0j/80t90VS9r0zjC2A== X-Received: by 2002:ac2:4909:: with SMTP id n9mr1663769lfi.21.1579881238399; Fri, 24 Jan 2020 07:53:58 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id s22sm3334568ljm.41.2020.01.24.07.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:53:57 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 05/10] doc: android: Convert to Sphinx format Date: Fri, 24 Jan 2020 17:53:44 +0200 Message-Id: <20200124155349.12927-6-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Convert Android documentation from regular txt format to Sphinx (RST). Also add Android index.rst file and reference it in root index.rst, so that Android documentation is visible. Test: $ make htmldocs $ xdg-open doc/output/index.html Signed-off-by: Sam Protsenko --- MAINTAINERS | 4 +- cmd/Kconfig | 2 +- doc/android/{ab.txt => ab.rst} | 39 ++--- doc/android/avb2.rst | 133 ++++++++++++++++++ doc/android/avb2.txt | 115 --------------- doc/android/bcb.rst | 100 +++++++++++++ doc/android/bcb.txt | 89 ------------ ...oot-protocol.txt => fastboot-protocol.rst} | 45 +++--- doc/android/{fastboot.txt => fastboot.rst} | 92 ++++++------ doc/android/index.rst | 14 ++ doc/index.rst | 12 ++ test/py/tests/test_android/test_avb.py | 2 +- 12 files changed, 351 insertions(+), 296 deletions(-) rename doc/android/{ab.txt => ab.rst} (52%) create mode 100644 doc/android/avb2.rst delete mode 100644 doc/android/avb2.txt create mode 100644 doc/android/bcb.rst delete mode 100644 doc/android/bcb.txt rename doc/android/{fastboot-protocol.txt => fastboot-protocol.rst} (82%) rename doc/android/{fastboot.txt => fastboot.rst} (79%) create mode 100644 doc/android/index.rst diff --git a/MAINTAINERS b/MAINTAINERS index b0634b23bc..9dce9f10f2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -56,7 +56,7 @@ R: Sam Protsenko S: Maintained F: cmd/ab_select.c F: common/android_ab.c -F: doc/android/ab.txt +F: doc/android/ab.rst F: include/android_ab.h F: test/py/tests/test_android/test_ab.py @@ -65,7 +65,7 @@ M: Igor Opaniuk S: Maintained F: cmd/avb.c F: common/avb_verify.c -F: doc/android/avb2.txt +F: doc/android/avb2.rst F: include/avb_verify.h F: lib/libavb/ F: test/py/tests/test_android/test_avb.py diff --git a/cmd/Kconfig b/cmd/Kconfig index 6a2f6fb070..e6ba57035e 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -880,7 +880,7 @@ config CMD_FASTBOOT Android devices. Fastboot requires either the network stack enabled or support for acting as a USB device. - See doc/android/fastboot.txt for more information. + See doc/android/fastboot.rst for more information. config CMD_FLASH bool "flinfo, erase, protect" diff --git a/doc/android/ab.txt b/doc/android/ab.rst similarity index 52% rename from doc/android/ab.txt rename to doc/android/ab.rst index 9f37ed5c58..961895c32e 100644 --- a/doc/android/ab.txt +++ b/doc/android/ab.rst @@ -1,3 +1,5 @@ +.. SPDX-License-Identifier: GPL-2.0+ + Android A/B updates =================== @@ -7,41 +9,44 @@ Overview A/B system updates ensures modern approach for system update. This feature allows one to use two sets (or more) of partitions referred to as slots (normally slot A and slot B). The system runs from the current slot while the -partitions in the unused slot can be updated [1]. +partitions in the unused slot can be updated [1]_. A/B enablement -------------- The A/B updates support can be activated by specifying next options in -your board configuration file: +your board configuration file:: CONFIG_ANDROID_AB=y CONFIG_CMD_AB_SELECT=y The disk space on target device must be partitioned in a way so that each partition which needs to be updated has two or more instances. The name of -each instance must be formed by adding suffixes: _a, _b, _c, etc. -For example: boot_a, boot_b, system_a, system_b, vendor_a, vendor_b. +each instance must be formed by adding suffixes: ``_a``, ``_b``, ``_c``, etc. +For example: ``boot_a``, ``boot_b``, ``system_a``, ``system_b``, ``vendor_a``, +``vendor_b``. -As a result you can use 'ab_select' command to ensure A/B boot process in your +As a result you can use ``ab_select`` command to ensure A/B boot process in your boot script. This command analyzes and processes A/B metadata stored on a -special partition (e.g. "misc") and determines which slot should be used for +special partition (e.g. ``misc``) and determines which slot should be used for booting up. Command usage ------------- +.. code-block:: none + ab_select -for example: +for example:: => ab_select slot_name mmc 1:4 -or +or:: => ab_select slot_name mmc 1#misc -Result: +Result:: => printenv slot_name slot_name=a @@ -49,19 +54,19 @@ Result: Based on this slot information, the current boot partition should be defined, and next kernel command line parameters should be generated: - - androidboot.slot_suffix= - - root= +* ``androidboot.slot_suffix=`` +* ``root=`` -For example: +For example:: androidboot.slot_suffix=_a root=/dev/mmcblk1p12 -A/B metadata is organized according to AOSP reference [2]. On the first system -start with A/B enabled, when 'misc' partition doesn't contain required data, -the default A/B metadata will be created and written to 'misc' partition. +A/B metadata is organized according to AOSP reference [2]_. On the first system +start with A/B enabled, when ``misc`` partition doesn't contain required data, +the default A/B metadata will be created and written to ``misc`` partition. References ---------- -[1] https://source.android.com/devices/tech/ota/ab -[2] bootable/recovery/bootloader_message/include/bootloader_message/bootloader_message.h +.. [1] https://source.android.com/devices/tech/ota/ab +.. [2] https://android.googlesource.com/platform/bootable/recovery/+/refs/tags/android-10.0.0_r25/bootloader_message/include/bootloader_message/bootloader_message.h diff --git a/doc/android/avb2.rst b/doc/android/avb2.rst new file mode 100644 index 0000000000..a072119574 --- /dev/null +++ b/doc/android/avb2.rst @@ -0,0 +1,133 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Android Verified Boot 2.0 +========================= + +This file contains information about the current support of Android Verified +Boot 2.0 in U-Boot. + +Overview +-------- + +Verified Boot establishes a chain of trust from the bootloader to system images: + +* Provides integrity checking for: + + * Android Boot image: Linux kernel + ramdisk. RAW hashing of the whole + partition is done and the hash is compared with the one stored in + the VBMeta image + * ``system``/``vendor`` partitions: verifying root hash of dm-verity hashtrees + +* Provides capabilities for rollback protection + +Integrity of the bootloader (U-Boot BLOB and environment) is out of scope. + +For additional details check [1]_. + +AVB using OP-TEE (optional) +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If AVB is configured to use OP-TEE (see `Enable on your board`_) rollback +indexes and device lock state are stored in RPMB. The RPMB partition is managed +by OP-TEE (see [2]_ for details) which is a secure OS leveraging ARM +TrustZone. + +AVB 2.0 U-Boot shell commands +----------------------------- + +Provides CLI interface to invoke AVB 2.0 verification + misc. commands for +different testing purposes:: + + avb init - initialize avb 2.0 for + avb verify - run verification process using hash data from vbmeta structure + avb read_rb - read rollback index at location + avb write_rb - write rollback index to + avb is_unlocked - returns unlock status of the device + avb get_uuid - read and print uuid of partition + avb read_part - read bytes from + partition to buffer + avb write_part - write bytes to + by using data from + +Partitions tampering (example) +------------------------------ + +Boot or system/vendor (dm-verity metadata section) is tampered:: + + => avb init 1 + => avb verify + avb_slot_verify.c:175: ERROR: boot: Hash of data does not match digest in + descriptor. + Slot verification result: ERROR_IO + +Vbmeta partition is tampered:: + + => avb init 1 + => avb verify + avb_vbmeta_image.c:206: ERROR: Hash does not match! + avb_slot_verify.c:388: ERROR: vbmeta: Error verifying vbmeta image: + HASH_MISMATCH + Slot verification result: ERROR_IO + +Enable on your board +-------------------- + +The following options must be enabled:: + + CONFIG_LIBAVB=y + CONFIG_AVB_VERIFY=y + CONFIG_CMD_AVB=y + +In addtion optionally if storing rollback indexes in RPMB with help of +OP-TEE:: + + CONFIG_TEE=y + CONFIG_OPTEE=y + CONFIG_OPTEE_TA_AVB=y + CONFIG_SUPPORT_EMMC_RPMB=y + +Then add ``avb verify`` invocation to your android boot sequence of commands, +e.g.:: + + => avb_verify=avb init $mmcdev; avb verify; + => if run avb_verify; then \ + echo AVB verification OK. Continue boot; \ + set bootargs $bootargs $avb_bootargs; \ + else \ + echo AVB verification failed; \ + exit; \ + fi; \ + + => emmc_android_boot= \ + echo Trying to boot Android from eMMC ...; \ + ... \ + run avb_verify; \ + mmc read ${fdtaddr} ${fdt_start} ${fdt_size}; \ + mmc read ${loadaddr} ${boot_start} ${boot_size}; \ + bootm $loadaddr $loadaddr $fdtaddr; \ + +If partitions you want to verify are slotted (have A/B suffixes), then current +slot suffix should be passed to ``avb verify`` sub-command, e.g.:: + + => avb verify _a + +To switch on automatic generation of vbmeta partition in AOSP build, add these +lines to device configuration mk file:: + + BOARD_AVB_ENABLE := true + BOARD_AVB_ALGORITHM := SHA512_RSA4096 + BOARD_BOOTIMAGE_PARTITION_SIZE := + +After flashing U-Boot don't forget to update environment and write new +partition table:: + + => env default -f -a + => setenv partitions $partitions_android + => env save + => gpt write mmc 1 $partitions_android + +References +---------- + +.. [1] https://android.googlesource.com/platform/external/avb/+/master/README.md +.. [2] https://www.op-tee.org/ diff --git a/doc/android/avb2.txt b/doc/android/avb2.txt deleted file mode 100644 index 48e9297c75..0000000000 --- a/doc/android/avb2.txt +++ /dev/null @@ -1,115 +0,0 @@ -Android Verified Boot 2.0 - -This file contains information about the current support of Android Verified -Boot 2.0 in U-boot - -1. OVERVIEW ---------------------------------- -Verified Boot establishes a chain of trust from the bootloader to system images -* Provides integrity checking for: - - Android Boot image: Linux kernel + ramdisk. RAW hashing of the whole - partition is done and the hash is compared with the one stored in - the VBMeta image - - system/vendor partitions: verifying root hash of dm-verity hashtrees. -* Provides capabilities for rollback protection. - -Integrity of the bootloader (U-boot BLOB and environment) is out of scope. - -For additional details check: -https://android.googlesource.com/platform/external/avb/+/master/README.md - -1.1. AVB using OP-TEE (optional) ---------------------------------- -If AVB is configured to use OP-TEE (see 4. below) rollback indexes and -device lock state are stored in RPMB. The RPMB partition is managed by -OP-TEE (https://www.op-tee.org/) which is a secure OS leveraging ARM -TrustZone. - - -2. AVB 2.0 U-BOOT SHELL COMMANDS ------------------------------------ -Provides CLI interface to invoke AVB 2.0 verification + misc. commands for -different testing purposes: - -avb init - initialize avb 2.0 for -avb verify - run verification process using hash data from vbmeta structure -avb read_rb - read rollback index at location -avb write_rb - write rollback index to -avb is_unlocked - returns unlock status of the device -avb get_uuid - read and print uuid of partition -avb read_part - read bytes from -partition to buffer -avb write_part - write bytes to - by using data from - - -3. PARTITIONS TAMPERING (EXAMPLE) ------------------------------------ -Boot or system/vendor (dm-verity metadata section) is tampered: -=> avb init 1 -=> avb verify -avb_slot_verify.c:175: ERROR: boot: Hash of data does not match digest in -descriptor. -Slot verification result: ERROR_IO - -Vbmeta partition is tampered: -=> avb init 1 -=> avb verify -avb_vbmeta_image.c:206: ERROR: Hash does not match! -avb_slot_verify.c:388: ERROR: vbmeta: Error verifying vbmeta image: -HASH_MISMATCH -Slot verification result: ERROR_IO - - -4. ENABLE ON YOUR BOARD ------------------------------------ -The following options must be enabled: -CONFIG_LIBAVB=y -CONFIG_AVB_VERIFY=y -CONFIG_CMD_AVB=y - -In addtion optionally if storing rollback indexes in RPMB with help of -OP-TEE: -CONFIG_TEE=y -CONFIG_OPTEE=y -CONFIG_OPTEE_TA_AVB=y -CONFIG_SUPPORT_EMMC_RPMB=y - -Then add `avb verify` invocation to your android boot sequence of commands, -e.g.: - -=> avb_verify=avb init $mmcdev; avb verify; -=> if run avb_verify; then \ - echo AVB verification OK. Continue boot; \ - set bootargs $bootargs $avb_bootargs; \ - else \ - echo AVB verification failed; \ - exit; \ - fi; \ - -=> emmc_android_boot= \ - echo Trying to boot Android from eMMC ...; \ - ... \ - run avb_verify; \ - mmc read ${fdtaddr} ${fdt_start} ${fdt_size}; \ - mmc read ${loadaddr} ${boot_start} ${boot_size}; \ - bootm $loadaddr $loadaddr $fdtaddr; \ - -If partitions you want to verify are slotted (have A/B suffixes), then current -slot suffix should be passed to 'avb verify' sub-command, e.g.: - -=> avb verify _a - -To switch on automatic generation of vbmeta partition in AOSP build, add these -lines to device configuration mk file: - -BOARD_AVB_ENABLE := true -BOARD_AVB_ALGORITHM := SHA512_RSA4096 -BOARD_BOOTIMAGE_PARTITION_SIZE := - -After flashing U-boot don't forget to update environment and write new -partition table: -=> env default -f -a -=> setenv partitions $partitions_android -=> env save -=> gpt write mmc 1 $partitions_android diff --git a/doc/android/bcb.rst b/doc/android/bcb.rst new file mode 100644 index 0000000000..8861608300 --- /dev/null +++ b/doc/android/bcb.rst @@ -0,0 +1,100 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Android Bootloader Control Block (BCB) +====================================== + +The purpose behind this file is to: + +* give an overview of BCB w/o duplicating public documentation +* describe the main BCB use-cases which concern U-Boot +* reflect current support status in U-Boot +* mention any relevant U-Boot build-time tunables +* precisely exemplify one or more use-cases + +Additions and fixes are welcome! + +Overview +-------- + +Bootloader Control Block (BCB) is a well established term/acronym in +the Android namespace which refers to a location in a dedicated raw +(i.e. FS-unaware) flash (e.g. eMMC) partition, usually called ``misc``, +which is used as media for exchanging messages between Android userspace +(particularly recovery [1]_) and an Android-capable bootloader. + +On higher level, BCB provides a way to implement a subset of Android +Bootloader Requirements [2]_, amongst which are: + +* Android-specific bootloader flow [3]_ +* Get the "reboot reason" (and act accordingly) [4]_ +* Get/pass a list of commands from/to recovery [1]_ +* TODO + + +'bcb'. Shell command overview +----------------------------- + +The ``bcb`` command provides a CLI to facilitate the development of the +requirements enumerated above. Below is the command's help message:: + + => bcb + bcb - Load/set/clear/test/dump/store Android BCB fields + + Usage: + bcb load - load BCB from mmc : + bcb set - set BCB to + bcb clear [] - clear BCB or all fields + bcb test - test BCB against + bcb dump - dump BCB + bcb store - store BCB back to mmc + + Legend: + - MMC device index containing the BCB partition + - MMC partition index or name containing the BCB + - one of {command,status,recovery,stage,reserved} + - the binary operator used in 'bcb test': + '=' returns true if matches the string stored in + '~' returns true if matches a subset of 's string + - string/text provided as input to bcb {set,test} + NOTE: any ':' character in will be replaced by line feed + during 'bcb set' and used as separator by upper layers + + +'bcb'. Example of getting reboot reason +--------------------------------------- + +.. code-block:: bash + + if bcb load 1 misc; then + # valid BCB found + if bcb test command = bootonce-bootloader; then + bcb clear command; bcb store; + # do the equivalent of AOSP ${fastbootcmd} + # i.e. call fastboot + else if bcb test command = boot-recovery; then + bcb clear command; bcb store; + # do the equivalent of AOSP ${recoverycmd} + # i.e. do anything required for booting into recovery + else + # boot Android OS normally + fi + else + # corrupted/non-existent BCB + # report error or boot non-Android OS (platform-specific) + fi + + +Enable on your board +-------------------- + +The following Kconfig options must be enabled:: + + CONFIG_PARTITIONS=y + CONFIG_MMC=y + CONFIG_BCB=y + +.. [1] https://android.googlesource.com/platform/bootable/recovery +.. [2] https://source.android.com/devices/bootloader +.. [3] https://patchwork.ozlabs.org/patch/746835/ + ("[U-Boot,5/6] Initial support for the Android Bootloader flow") +.. [4] https://source.android.com/devices/bootloader/boot-reason diff --git a/doc/android/bcb.txt b/doc/android/bcb.txt deleted file mode 100644 index 7b7177cacf..0000000000 --- a/doc/android/bcb.txt +++ /dev/null @@ -1,89 +0,0 @@ -Android Bootloader Control Block (BCB) - -The purpose behind this file is to: - - give an overview of BCB w/o duplicating public documentation - - describe the main BCB use-cases which concern U-Boot - - reflect current support status in U-Boot - - mention any relevant U-Boot build-time tunables - - precisely exemplify one or more use-cases - -Additions and fixes are welcome! - - -1. OVERVIEW ---------------------------------- -Bootloader Control Block (BCB) is a well established term/acronym in -the Android namespace which refers to a location in a dedicated raw -(i.e. FS-unaware) flash (e.g. eMMC) partition, usually called "misc", -which is used as media for exchanging messages between Android userspace -(particularly recovery [1]) and an Android-capable bootloader. - -On higher level, BCB provides a way to implement a subset of Android -Bootloader Requirements [2], amongst which are: - - Android-specific bootloader flow [3] - - Get the "reboot reason" (and act accordingly) [4] - - Get/pass a list of commands from/to recovery [1] - - TODO - - -2. 'BCB'. SHELL COMMAND OVERVIEW ------------------------------------ -The 'bcb' command provides a CLI to facilitate the development of the -requirements enumerated above. Below is the command's help message: - -=> bcb -bcb - Load/set/clear/test/dump/store Android BCB fields - -Usage: -bcb load - load BCB from mmc : -bcb set - set BCB to -bcb clear [] - clear BCB or all fields -bcb test - test BCB against -bcb dump - dump BCB -bcb store - store BCB back to mmc - -Legend: - - MMC device index containing the BCB partition - - MMC partition index or name containing the BCB - - one of {command,status,recovery,stage,reserved} - - the binary operator used in 'bcb test': - '=' returns true if matches the string stored in - '~' returns true if matches a subset of 's string - - string/text provided as input to bcb {set,test} - NOTE: any ':' character in will be replaced by line feed - during 'bcb set' and used as separator by upper layers - - -3. 'BCB'. EXAMPLE OF GETTING REBOOT REASON ------------------------------------ -if bcb load 1 misc; then - # valid BCB found - if bcb test command = bootonce-bootloader; then - bcb clear command; bcb store; - # do the equivalent of AOSP ${fastbootcmd} - # i.e. call fastboot - else if bcb test command = boot-recovery; then - bcb clear command; bcb store; - # do the equivalent of AOSP ${recoverycmd} - # i.e. do anything required for booting into recovery - else - # boot Android OS normally - fi -else - # corrupted/non-existent BCB - # report error or boot non-Android OS (platform-specific) -fi - - -4. ENABLE ON YOUR BOARD ------------------------------------ -The following Kconfig options must be enabled: -CONFIG_PARTITIONS=y -CONFIG_MMC=y -CONFIG_BCB=y - -[1] https://android.googlesource.com/platform/bootable/recovery -[2] https://source.android.com/devices/bootloader -[3] https://patchwork.ozlabs.org/patch/746835/ - ("[U-Boot,5/6] Initial support for the Android Bootloader flow") -[4] https://source.android.com/devices/bootloader/boot-reason diff --git a/doc/android/fastboot-protocol.txt b/doc/android/fastboot-protocol.rst similarity index 82% rename from doc/android/fastboot-protocol.txt rename to doc/android/fastboot-protocol.rst index e9e7166a26..e723659e49 100644 --- a/doc/android/fastboot-protocol.txt +++ b/doc/android/fastboot-protocol.rst @@ -1,12 +1,13 @@ -FastBoot Version 0.4 ----------------------- +.. SPDX-License-Identifier: GPL-2.0+ + +FastBoot Version 0.4 +==================== The fastboot protocol is a mechanism for communicating with bootloaders over USB. It is designed to be very straightforward to implement, to allow it to be used across a wide range of devices and from hosts running Linux, Windows, or OSX. - Basic Requirements ------------------ @@ -66,31 +67,33 @@ Transport and Framing Example Session --------------- -Host: "getvar:version" request version variable +.. code-block:: none + + Host: "getvar:version" request version variable -Client: "OKAY0.4" return version "0.4" + Client: "OKAY0.4" return version "0.4" -Host: "getvar:nonexistant" request some undefined variable + Host: "getvar:nonexistant" request some undefined variable -Client: "OKAY" return value "" + Client: "OKAY" return value "" -Host: "download:00001234" request to send 0x1234 bytes of data + Host: "download:00001234" request to send 0x1234 bytes of data -Client: "DATA00001234" ready to accept data + Client: "DATA00001234" ready to accept data -Host: < 0x1234 bytes > send data + Host: < 0x1234 bytes > send data -Client: "OKAY" success + Client: "OKAY" success -Host: "flash:bootloader" request to flash the data to the bootloader + Host: "flash:bootloader" request to flash the data to the bootloader -Client: "INFOerasing flash" indicate status / progress - "INFOwriting flash" - "OKAY" indicate success + Client: "INFOerasing flash" indicate status / progress + "INFOwriting flash" + "OKAY" indicate success -Host: "powerdown" send a command + Host: "powerdown" send a command -Client: "FAILunknown command" indicate failure + Client: "FAILunknown command" indicate failure Command Reference @@ -105,6 +108,8 @@ Command Reference specification. OEM-specific commands should not begin with a lowercase letter, to prevent incompatibilities with future specs. +.. code-block:: none + "getvar:%s" Read a config/version variable from the bootloader. The variable contents will be returned after the OKAY response. @@ -139,16 +144,14 @@ Command Reference "powerdown" Power off the device. - - Client Variables ---------------- -The "getvar:%s" command is used to read client variables which +The ``getvar:%s`` command is used to read client variables which represent various information about the device and the software on it. -The various currently defined names are: +The various currently defined names are:: version Version of FastBoot protocol supported. It should be "0.3" for this document. diff --git a/doc/android/fastboot.txt b/doc/android/fastboot.rst similarity index 79% rename from doc/android/fastboot.txt rename to doc/android/fastboot.rst index 9de13223f8..de3f6c37d7 100644 --- a/doc/android/fastboot.txt +++ b/doc/android/fastboot.rst @@ -1,12 +1,12 @@ -================ +.. SPDX-License-Identifier: GPL-2.0+ + Android Fastboot ================ Overview -======== +-------- -The protocol that is used over USB and UDP is described in -``doc/android/fastboot-protocol.txt``. +The protocol that is used over USB and UDP is described in [1]_. The current implementation supports the following standard commands: @@ -22,25 +22,23 @@ The current implementation supports the following standard commands: The following OEM commands are supported (if enabled): -- oem format - this executes ``gpt write mmc %x $partitions`` +- ``oem format`` - this executes ``gpt write mmc %x $partitions`` Support for both eMMC and NAND devices is included. Client installation -=================== +------------------- The counterpart to this is the fastboot client which can be found in Android's ``platform/system/core`` repository in the fastboot folder. It runs on Windows, Linux and OSX. The fastboot client is -part of the Android SDK Platform-Tools and can be downloaded from: - -https://developer.android.com/studio/releases/platform-tools +part of the Android SDK Platform-Tools and can be downloaded from [2]_. Board specific -============== +-------------- USB configuration ------------------ +^^^^^^^^^^^^^^^^^ The fastboot gadget relies on the USB download gadget, so the following options must be configured: @@ -57,7 +55,7 @@ supported by the fastboot client. The list of vendor IDs supported can be found in the fastboot client source code. General configuration ---------------------- +^^^^^^^^^^^^^^^^^^^^^ The fastboot protocol requires a large memory buffer for downloads. This buffer should be as large as possible for a @@ -67,46 +65,46 @@ may be overridden on the fastboot command line using ``-l`` and ``-s``. Fastboot environment variables -============================== +------------------------------ Partition aliases ------------------ +^^^^^^^^^^^^^^^^^ Fastboot partition aliases can also be defined for devices where GPT -limitations prevent user-friendly partition names such as "boot", "system" -and "cache". Or, where the actual partition name doesn't match a standard +limitations prevent user-friendly partition names such as ``boot``, ``system`` +and ``cache``. Or, where the actual partition name doesn't match a standard partition name used commonly with fastboot. The current implementation checks aliases when accessing partitions by name (flash_write and erase functions). To define a partition alias -add an environment variable similar to: +add an environment variable similar to:: -``fastboot_partition_alias_=`` + fastboot_partition_alias_= -for example: +for example:: -``fastboot_partition_alias_boot=LNX`` + fastboot_partition_alias_boot=LNX Variable overrides ------------------- +^^^^^^^^^^^^^^^^^^ Variables retrived through ``getvar`` can be overridden by defining environment variables of the form ``fastboot.``. These are looked up first so can be used to override values which would otherwise be returned. Using this mechanism you can also return types for NAND filesystems, as the fully parameterised variable is looked -up, e.g. +up, e.g.:: -``fastboot.partition-type:boot=jffs2`` + fastboot.partition-type:boot=jffs2 Boot command ------------- +^^^^^^^^^^^^ -When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set then -that will be executed in place of ``bootm ``. +When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set +then that will be executed in place of ``bootm ``. Partition Names -=============== +--------------- The Fastboot implementation in U-Boot allows to write images into disk partitions. Target partitions are referred on the host computer by @@ -115,11 +113,11 @@ their names. For GPT/EFI the respective partition name is used. For MBR the partitions are referred by generic names according to the -following schema: +following schema:: - + -Example: ``hda3``, ``sdb1``, ``usbda1`` +Example: ``hda3``, ``sdb1``, ``usbda1``. The device type is as follows: @@ -135,7 +133,7 @@ controller, SD/MMC controller) or disk index. The partition index starts from ``1`` and describes the partition number on the particular device. Writing Partition Table -======================= +----------------------- Fastboot also allows to write the partition table to the media. This can be done by writing the respective partition table image to a special target @@ -148,34 +146,26 @@ configuration options: CONFIG_FASTBOOT_MBR_NAME In Action -========= +--------- -Enter into fastboot by executing the fastboot command in U-Boot for either USB: - -:: +Enter into fastboot by executing the fastboot command in U-Boot for either USB:: => fastboot usb 0 -or UDP: - -:: +or UDP:: => fastboot udp link up on port 0, speed 100, full duplex Using ethernet@4a100000 device Listening for fastboot command on 192.168.0.102 -On the client side you can fetch the bootloader version for instance: - -:: +On the client side you can fetch the bootloader version for instance:: $ fastboot getvar version-bootloader version-bootloader: U-Boot 2019.07-rc4-00240-g00c9f2a2ec Finished. Total time: 0.005s -or initiate a reboot: - -:: +or initiate a reboot:: $ fastboot reboot @@ -184,9 +174,7 @@ and once the client comes back, the board should reset. You can also specify a kernel image to boot. You have to either specify the an image in Android format *or* pass a binary kernel and let the fastboot client wrap the Android suite around it. On OMAP for instance you -take zImage kernel and pass it to the fastboot client: - -:: +take zImage kernel and pass it to the fastboot client:: $ fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0 mem=128M" boot zImage creating boot image... @@ -197,9 +185,7 @@ take zImage kernel and pass it to the fastboot client: OKAY [ -0.000s] finished. total time: 2.766s -and on the U-Boot side you should see: - -:: +and on the U-Boot side you should see:: Starting download of 1847296 bytes ........................................................ @@ -212,3 +198,9 @@ and on the U-Boot side you should see: OK Starting kernel ... + +References +---------- + +.. [1] :doc:`fastboot-protocol` +.. [2] https://developer.android.com/studio/releases/platform-tools diff --git a/doc/android/index.rst b/doc/android/index.rst new file mode 100644 index 0000000000..225d6f125a --- /dev/null +++ b/doc/android/index.rst @@ -0,0 +1,14 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Android-specific doc +==================== + +.. toctree:: + :maxdepth: 2 + + ab + avb2 + bcb + boot-image + fastboot-protocol + fastboot diff --git a/doc/index.rst b/doc/index.rst index 206a04590f..cd98be6cc5 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -86,6 +86,18 @@ organized in a vendor subdirectory. board/index +Android-specific doc +-------------------- + +These books provide information about booting the Android OS from U-Boot, +manipulating Android images from U-Boot shell and discusses other +Android-specific features available in U-Boot. + +.. toctree:: + :maxdepth: 2 + + android/index + Indices and tables ================== diff --git a/test/py/tests/test_android/test_avb.py b/test/py/tests/test_android/test_avb.py index 20ccaf6712..a04a7ff264 100644 --- a/test/py/tests/test_android/test_avb.py +++ b/test/py/tests/test_android/test_avb.py @@ -8,7 +8,7 @@ This tests Android Verified Boot 2.0 support in U-boot: For additional details about how to build proper vbmeta partition -check doc/android/avb2.txt +check doc/android/avb2.rst For configuration verification: - Corrupt boot partition and check for failure From patchwork Fri Jan 24 15:53:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228879 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=mnQcwKYb; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843cl2YVlz9sRW for ; Sat, 25 Jan 2020 02:55:03 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 49C6081853; Fri, 24 Jan 2020 16:54:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mnQcwKYb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9A82C81812; Fri, 24 Jan 2020 16:54:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) (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 EA45381813 for ; Fri, 24 Jan 2020 16:54:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lj1-x244.google.com with SMTP id a13so2987193ljm.10 for ; Fri, 24 Jan 2020 07:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vl5EUJ7acGy7+YheOX1vs+T2L9itJiIJt/fCLAC5ttk=; b=mnQcwKYbZWMI+spcBJp+DD6GFgg8PjCPhCvR0cSI0m6Yh+HR7q6ujsrCT5rluLITTT O4YeDVENhYMondrglb7mbhnUnPOfa6lcsgPZRsfpdbig41tEJ7wxTg3xZbil8QDTg6pB 5oudXhDWIpFS86v0H5fL8y78pQcniOb/mrlSmk8k+QFEH2sF3DbrkgmHty6wfwnMYNiM OBUJbMOU39sNxIy6fAUteTKkUMjUeXbQb7vKJuMPnbi1y8XU8q5WfOq5UlVrgKi9SwWm NtDzJrrLz7g7+0q7N05UhPXMQ35jfPd32scGlzY92CbjiyA3WLMAmDmhuiFw5oVhRtl0 WuHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vl5EUJ7acGy7+YheOX1vs+T2L9itJiIJt/fCLAC5ttk=; b=PVDv+MZiJPsocUdHwOaGE62JaVElk04rsdh2RJdv141ATlgVe7RIzF6YIUhyGVP6sC igRqMpzjzg4AoOTQvPzGH0HY5Uf4w7EunPxtHHUbmMUGfX4dSTPgzeyY3lZTRjZaFqJK lrVf7gckNa9T31HpXx4jBAI/WLZiC9KXJJDE1zY6sZTkUdHGW18ymoPa2y+cFo8Hmwac rtfnRtZHr+k49VeM/GQNjJ2/GlN7nO051HF4e0Ybsr6UK6Ck+v7XZZCb3vG5+tJF1JOe oBZMq7tE32CLaCatYUx7d0pn/laOgTWbRaOk8Tq27I5TqcCW7gplAYfaopmyyCj5IH1P kkMg== X-Gm-Message-State: APjAAAWKpieXhz9YG3VoaVqtURcjqoSJYWIkGaEW3TALE58zKd17dUA6 mHG/f8d18gen+AToZsLmAVb3ySNn03w= X-Google-Smtp-Source: APXvYqx8gS0HPPEVAohpColNhffHF0TZDUZ/rSFLh9Cdhud1ZVaCkCxDYBRUyU3DpskDPnk9Xe2Zag== X-Received: by 2002:a2e:b4f6:: with SMTP id s22mr2503358ljm.218.1579881239976; Fri, 24 Jan 2020 07:53:59 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id a28sm2933696lfg.86.2020.01.24.07.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:53:59 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 06/10] test/py: android: Add test for abootimg Date: Fri, 24 Jan 2020 17:53:45 +0200 Message-Id: <20200124155349.12927-7-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Unit test for 'abootimg' command. Right now it covers dtb/dtbo functionality in Android Boot Image v2, which was added recently. Running test: $ ./test/py/test.py --bd sandbox --build -k test_abootimg shows that 1/1 tests passes successfully. Signed-off-by: Sam Protsenko --- configs/sandbox_defconfig | 1 + test/py/tests/test_android/test_abootimg.py | 159 ++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 test/py/tests/test_android/test_abootimg.py diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index fc018bdd2c..790dcb0592 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -25,6 +25,7 @@ CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y +CONFIG_CMD_ABOOTIMG=y # CONFIG_CMD_ELF is not set CONFIG_CMD_ASKENV=y CONFIG_CMD_GREPENV=y diff --git a/test/py/tests/test_android/test_abootimg.py b/test/py/tests/test_android/test_abootimg.py new file mode 100644 index 0000000000..43a7099c46 --- /dev/null +++ b/test/py/tests/test_android/test_abootimg.py @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2020 +# Author: Sam Protsenko + +# Test U-Boot's "abootimg" commands. + +import os +import pytest +import u_boot_utils + +""" +These tests rely on disk image (boot.img), which is automatically created by +the test from the stored hex dump. This is done to avoid the dependency on the +most recent mkbootimg tool from AOSP/master. Here is the list of commands which +was used to generate the boot.img and obtain compressed hex dump from it: + + $ echo '/dts-v1/; / { model = "x1"; compatible = "y1,z1"; };' > test1.dts + $ echo '/dts-v1/; / { model = "x2"; compatible = "y2,z2"; };' > test2.dts + $ dtc test1.dts > dt1.dtb + $ dtc test2.dts > dt2.dtb + $ cat dt1.dtb dt2.dtb > dtb.img + $ echo 'kernel payload' > kernel + $ echo 'ramdisk payload' > ramdisk.img + $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img \ + --cmdline "cmdline test" --dtb ./dtb.img \ + --os_version R --os_patch_level 2019-06-05 \ + --header_version 2 --output boot.img + $ gzip -9 boot.img + $ xxd -p boot.img.gz > boot.img.gz.hex + +Now one can obtain original boot.img from this hex dump like this: + + $ xxd -r -p boot.img.gz.hex boot.img.gz + $ gunzip -9 boot.img.gz +""" + +# boot.img.gz hex dump +img_hex = """1f8b08084844af5d0203626f6f742e696d670073f47309f2f77451e46700 +820606010106301084501f04181819041838181898803c3346060c909c9b +92939997aa50925a5cc2300a461c3078b2e1793c4b876fd92db97939fb6c +b7762ffff07d345446c1281805e8a0868d81e117a45e111c0d8dc101b253 +8bf25273140a122b73f21353b8460364148c8251300a46c1281801a02831 +3725b3387bb401300a46c1281805a360148c207081f7df5b20550bc41640 +9c03c41a0c90f17fe85400986d82452b6c3680198a192a0ce17c3610ae34 +d4a9820881a70f3873f35352731892f3730b124b32937252a96bb9119ae5 +463a5546f82c1f05a360148c8251300a462e000085bf67f200200000""" +# Expected response for "abootimg dtb_dump" command +dtb_dump_resp="""## DTB area contents (concat format): + - DTB #0: + (DTB)size = 125 + (DTB)model = x1 + (DTB)compatible = y1,z1 + - DTB #1: + (DTB)size = 125 + (DTB)model = x2 + (DTB)compatible = y2,z2""" +# Address in RAM where to load the boot image ('abootimg' looks in $loadaddr) +loadaddr = 0x1000 +# Expected DTB #1 offset from the boot image start address +dtb1_offset = 0x187d +# DTB #1 start address in RAM +dtb1_addr = loadaddr + dtb1_offset + +class AbootimgTestDiskImage(object): + """Disk image used by abootimg tests.""" + + def __init__(self, u_boot_console): + """Initialize a new AbootimgDiskImage object. + + Args: + u_boot_console: A U-Boot console. + + Returns: + Nothing. + """ + + gz_hex = u_boot_console.config.persistent_data_dir + '/boot.img.gz.hex' + gz = u_boot_console.config.persistent_data_dir + '/boot.img.gz' + + filename = 'boot.img' + persistent = u_boot_console.config.persistent_data_dir + '/' + filename + self.path = u_boot_console.config.result_dir + '/' + filename + + with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent): + if os.path.exists(persistent): + u_boot_console.log.action('Disk image file ' + persistent + + ' already exists') + else: + u_boot_console.log.action('Generating ' + persistent) + + f = open(gz_hex, "w") + f.write(img_hex) + f.close() + + cmd = ('xxd', '-r', '-p', gz_hex, gz) + u_boot_utils.run_and_log(u_boot_console, cmd) + + cmd = ('gunzip', '-9', gz) + u_boot_utils.run_and_log(u_boot_console, cmd) + + cmd = ('cp', persistent, self.path) + u_boot_utils.run_and_log(u_boot_console, cmd) + +gtdi = None +@pytest.fixture(scope='function') +def abootimg_disk_image(u_boot_console): + """pytest fixture to provide a AbootimgTestDiskImage object to tests. + This is function-scoped because it uses u_boot_console, which is also + function-scoped. However, we don't need to actually do any function-scope + work, so this simply returns the same object over and over each time.""" + + global gtdi + if not gtdi: + gtdi = AbootimgTestDiskImage(u_boot_console) + return gtdi + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('android_boot_image') +@pytest.mark.buildconfigspec('cmd_abootimg') +@pytest.mark.buildconfigspec('cmd_fdt') +@pytest.mark.requiredtool('xxd') +@pytest.mark.requiredtool('gunzip') +def test_abootimg(abootimg_disk_image, u_boot_console): + """Test the 'abootimg' command.""" + + u_boot_console.log.action('Loading disk image to RAM...') + u_boot_console.run_command('setenv loadaddr 0x%x' % (loadaddr)) + u_boot_console.run_command('host load hostfs - 0x%x %s' % (loadaddr, + abootimg_disk_image.path)) + + u_boot_console.log.action('Testing \'abootimg get ver\'...') + response = u_boot_console.run_command('abootimg get ver') + assert response == "2" + u_boot_console.run_command('abootimg get ver v') + response = u_boot_console.run_command('env print v') + assert response == 'v=2' + + u_boot_console.log.action('Testing \'abootimg get recovery_dtbo\'...') + response = u_boot_console.run_command('abootimg get recovery_dtbo a') + assert response == 'Error: recovery_dtbo_size is 0' + + u_boot_console.log.action('Testing \'abootimg dump dtb\'...') + response = u_boot_console.run_command('abootimg dump dtb').replace('\r', '') + assert response == dtb_dump_resp + + u_boot_console.log.action('Testing \'abootimg get dtb_load_addr\'...') + u_boot_console.run_command('abootimg get dtb_load_addr a') + response = u_boot_console.run_command('env print a') + assert response == 'a=11f00000' + + u_boot_console.log.action('Testing \'abootimg get dtb --index\'...') + u_boot_console.run_command('abootimg get dtb --index=1 dtb1_start') + response = u_boot_console.run_command('env print dtb1_start') + correct_str = "dtb1_start=%x" % (dtb1_addr) + assert response == correct_str + u_boot_console.run_command('fdt addr $dtb1_start') + u_boot_console.run_command('fdt get value v / model') + response = u_boot_console.run_command('env print v') + assert response == 'v=x2' From patchwork Fri Jan 24 15:53:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228880 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VqNj5VJp; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843d10Sjtz9sRW for ; Sat, 25 Jan 2020 02:55:16 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1708D818F2; Fri, 24 Jan 2020 16:54:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VqNj5VJp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B308F81813; Fri, 24 Jan 2020 16:54:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_HELO_NONE, UPPERCASE_50_75 autolearn=no autolearn_force=no version=3.4.2 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) (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 AE577817B6 for ; Fri, 24 Jan 2020 16:54:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lj1-x22e.google.com with SMTP id v17so3029018ljg.4 for ; Fri, 24 Jan 2020 07:54:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PXh6PnnDSEygt8S2hiYLlNfoudVxcPWaRwHO2Zf5AJo=; b=VqNj5VJpZcrM1QUBvmBJanUL3vOmETOQJ6dX/FVF6hXuRKTmZrjecB5wHpaVsnpZQb uIVHG1cuK6o8JNEV42fBekX3ilO7VBehycwFyOM9TI8esLKd7nWPZbhIXbwDvV+dgMld 6o9DEsakzRHsXmWU00515j8Jvy4z6D3d1Wxe9svn6fdOisF463SJ+4dVj2/rrrXpf5d8 u1l9Mp+OR697yjvTEde1dDDIFQFozne3NoTmLR9p+hWasus9M+j8YniMbBgDq7dIJD+m 15jNoeAsJbbKZCxzsDzjqX/RA2Ys3xiigdv92zHOsXQ6PTYD7dG4s/Xc7bobeHEypsST M9Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PXh6PnnDSEygt8S2hiYLlNfoudVxcPWaRwHO2Zf5AJo=; b=UwcuMho4a+uYqJXWrEoKE42vZzMsgznZIBB2l8vTyEzEXdzOR1FvqHKVQSwU5cEqZR jw+nazhr+x+HPOM0t0FNZF15fvYpuV2RNcy4lxrdWjQvKDPRFNNW21fMwzzy4HVspz4g fPL3/mATUgCxB56DrgByWXNuPnGyR+35OND3RKwlh0S2lErIOxD8BJGJcEB/IylfeFCP X3G+E0EhX47MA49y1viYdTgm+c1ncsWKyYMWBYS59FgjqUiAmIynT7bWtNq5DN4JuVH3 cde06thUit7K7jWvOSROeyyyBLobp1OleHZXekKHCr6B8SdQFXGrcgJbB2oU5M2MN0Jc X1TQ== X-Gm-Message-State: APjAAAXHbi+u6QjIsU0l60gwldScBr+xU4rps6SpEoc1ZK5a4+/89SWe dUg6xLGbE+zIGfYCqO+Yq6gbxaBHIZw= X-Google-Smtp-Source: APXvYqyZ3cVF8T7s+wIDdPVeOigMkxlpY/SvSySH1bzxjs7x5o70WxsjyDgmoYDE51EJkm2RHzD9MA== X-Received: by 2002:a2e:a402:: with SMTP id p2mr2687064ljn.143.1579881241496; Fri, 24 Jan 2020 07:54:01 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id y10sm3229856ljm.93.2020.01.24.07.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:54:00 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 07/10] configs: am57xx_evm: Enable Android commands Date: Fri, 24 Jan 2020 17:53:46 +0200 Message-Id: <20200124155349.12927-8-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Enable Android commands that will be needed for Android 10 boot flow implementation, for all AM57x variants. Commands enabled: 1. 'abootimg': - CONFIG_CMD_ABOOTIMG=y 2. 'ab_select': - CONFIG_ANDROID_AB=y - CONFIG_CMD_AB_SELECT=y 3. 'avb': - CONFIG_LIBAVB=y - CONFIG_AVB_VERIFY=y - CONFIG_CMD_AVB=y While at it, resync defconfig files with "make savedefconfig". Signed-off-by: Sam Protsenko --- configs/am57xx_evm_defconfig | 6 ++++++ configs/am57xx_hs_evm_defconfig | 6 ++++++ configs/am57xx_hs_evm_usb_defconfig | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/configs/am57xx_evm_defconfig b/configs/am57xx_evm_defconfig index e429d0e200..f39f553afb 100644 --- a/configs/am57xx_evm_defconfig +++ b/configs/am57xx_evm_defconfig @@ -22,6 +22,8 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y # CONFIG_MISC_INIT_R is not set CONFIG_VERSION_VARIABLE=y CONFIG_BOARD_EARLY_INIT_F=y +CONFIG_AVB_VERIFY=y +CONFIG_ANDROID_AB=y CONFIG_SPL_SYS_MALLOC_SIMPLE=y CONFIG_SPL_SEPARATE_BSS=y CONFIG_SPL_DMA=y @@ -31,11 +33,14 @@ CONFIG_SPL_SPI_LOAD=y CONFIG_SYS_SPI_U_BOOT_OFFS=0x40000 CONFIG_SPL_YMODEM_SUPPORT=y CONFIG_CMD_ADTIMG=y +CONFIG_CMD_ABOOTIMG=y CONFIG_CMD_SPL=y CONFIG_CMD_BCB=y # CONFIG_CMD_FLASH is not set # CONFIG_CMD_SETEXPR is not set +CONFIG_CMD_AB_SELECT=y # CONFIG_CMD_PMIC is not set +CONFIG_CMD_AVB=y CONFIG_OF_CONTROL=y CONFIG_SPL_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="am572x-idk" @@ -102,3 +107,4 @@ CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments" CONFIG_USB_GADGET_VENDOR_NUM=0x0451 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022 +CONFIG_LIBAVB=y diff --git a/configs/am57xx_hs_evm_defconfig b/configs/am57xx_hs_evm_defconfig index bebaae8743..4480f1c84d 100644 --- a/configs/am57xx_hs_evm_defconfig +++ b/configs/am57xx_hs_evm_defconfig @@ -27,6 +27,8 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y # CONFIG_MISC_INIT_R is not set CONFIG_VERSION_VARIABLE=y CONFIG_BOARD_EARLY_INIT_F=y +CONFIG_AVB_VERIFY=y +CONFIG_ANDROID_AB=y CONFIG_SPL_SYS_MALLOC_SIMPLE=y CONFIG_SPL_SEPARATE_BSS=y CONFIG_SPL_DMA=y @@ -34,10 +36,13 @@ CONFIG_SPL_DMA=y CONFIG_SPL_SPI_LOAD=y CONFIG_SYS_SPI_U_BOOT_OFFS=0x40000 CONFIG_CMD_ADTIMG=y +CONFIG_CMD_ABOOTIMG=y CONFIG_CMD_BCB=y # CONFIG_CMD_FLASH is not set # CONFIG_CMD_SETEXPR is not set +CONFIG_CMD_AB_SELECT=y # CONFIG_CMD_PMIC is not set +CONFIG_CMD_AVB=y CONFIG_OF_CONTROL=y CONFIG_SPL_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="am57xx-beagle-x15" @@ -98,3 +103,4 @@ CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments" CONFIG_USB_GADGET_VENDOR_NUM=0x0451 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022 +CONFIG_LIBAVB=y diff --git a/configs/am57xx_hs_evm_usb_defconfig b/configs/am57xx_hs_evm_usb_defconfig index d96640d44f..1e9268f68d 100644 --- a/configs/am57xx_hs_evm_usb_defconfig +++ b/configs/am57xx_hs_evm_usb_defconfig @@ -28,6 +28,8 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y # CONFIG_MISC_INIT_R is not set CONFIG_VERSION_VARIABLE=y CONFIG_BOARD_EARLY_INIT_F=y +CONFIG_AVB_VERIFY=y +CONFIG_ANDROID_AB=y CONFIG_SPL_SYS_MALLOC_SIMPLE=y CONFIG_SPL_SEPARATE_BSS=y CONFIG_SPL_DMA=y @@ -39,10 +41,13 @@ CONFIG_SPL_USB_GADGET=y CONFIG_SPL_DFU=y CONFIG_SPL_YMODEM_SUPPORT=y CONFIG_CMD_ADTIMG=y +CONFIG_CMD_ABOOTIMG=y CONFIG_CMD_BCB=y # CONFIG_CMD_FLASH is not set # CONFIG_CMD_SETEXPR is not set +CONFIG_CMD_AB_SELECT=y # CONFIG_CMD_PMIC is not set +CONFIG_CMD_AVB=y CONFIG_OF_CONTROL=y CONFIG_SPL_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="am57xx-beagle-x15" @@ -105,3 +110,4 @@ CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments" CONFIG_USB_GADGET_VENDOR_NUM=0x0451 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022 +CONFIG_LIBAVB=y From patchwork Fri Jan 24 15:53:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228883 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=b3GASW0S; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843dg5zVvz9sRW for ; Sat, 25 Jan 2020 02:55:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4E5CD81958; Fri, 24 Jan 2020 16:54:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b3GASW0S"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ADA6081844; Fri, 24 Jan 2020 16:54:08 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) (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 D69E681766 for ; Fri, 24 Jan 2020 16:54:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lj1-x242.google.com with SMTP id x14so638671ljd.13 for ; Fri, 24 Jan 2020 07:54:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eFkmc3IZtleTgey5uTgBDAXZLTH6rZzCnmNDa8EJ6po=; b=b3GASW0S0WXHUAh6OWPpKrUwn6u1FbwNPslPqzmMtoPDcs5Yt4P7shS6rtQ3+46s3N FA1G7bzwch2nBbiqYZB+rnHUKaJle79XeZdka8L9rGFk8TPMwH0wn9TCff8n7DRJ759H jN73nEX+zUlZDJ9mnE+IsJXBADrWVZa5sX0avK/ThuvyMnli9axivXW5L3ceG6rIrJLw UfZecngbntj30e4NAecn8cp7U3xdEDYh+wdcaertTYDp2CU45hgSbHg34pNNY5wUnq8H aHzB0ZW3/DyjMBlRGkDz6DSp2s0VUtsxj3rGm59VQfbPjCz3o3QVJNDnMumkyYCwY1Wm gNuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eFkmc3IZtleTgey5uTgBDAXZLTH6rZzCnmNDa8EJ6po=; b=sjQyilRLIX3msAYzYj+vcN2IK6n/t8gPvda7kEIOjYoSVoNGAmL01YB7fgSv085bVr u/TSm0/oGJc16RFYCvl4HBNrJyUVzdCepIuGwcF8wqv+AiuS03N9I3T7V6xn9NzQbz71 /nO0s2baem8LoeZUf3TLnqDfJKfGd44P7cxtPIhvvVJj+Sypl+XIBOtrG5zzDbTeXoBf Bk/Bd066JbHbYRYzyBECGm4QCi/ZCUw7p0x1gYbcxtka5XYHcAu9MMKZjXm/upJT2Kf1 xEHwKX2ejipt3mjjSoP1cCSXV7P4xV8CQqL5dqZ/aCGGiK9ZKGDU+ctJDpoz6eJyvrnZ 05Jg== X-Gm-Message-State: APjAAAWwBepREDt+pmeWJG7qRL14jaY1wlDsCqUBB0PEQqdMB9Q4nOmy B+Ec3LDoinNJ4W7lKkQzRCv/YHZgPHE= X-Google-Smtp-Source: APXvYqwlS/da+kAt5fML02NLQsdECGRqbud4hK+i0+5JWD8w32EK82NLKxBtRpOSuS3X7heYX1Egbg== X-Received: by 2002:a2e:2413:: with SMTP id k19mr2637152ljk.279.1579881242906; Fri, 24 Jan 2020 07:54:02 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id b1sm3595748ljp.72.2020.01.24.07.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:54:02 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 08/10] env: ti: boot: Respect slot_suffix in AVB commands Date: Fri, 24 Jan 2020 17:53:47 +0200 Message-Id: <20200124155349.12927-9-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Signed-off-by: Sam Protsenko --- include/environment/ti/boot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h index 6313f3e328..bfbd76c3af 100644 --- a/include/environment/ti/boot.h +++ b/include/environment/ti/boot.h @@ -63,7 +63,7 @@ "else " \ "echo AVB verification failed.;" \ "exit; fi;" -#define AVB_VERIFY_CMD "avb_verify=avb init 1; avb verify;\0" +#define AVB_VERIFY_CMD "avb_verify=avb init 1; avb verify $slot_suffix;\0" #else #define AVB_VERIFY_CHECK "" #define AVB_VERIFY_CMD "" From patchwork Fri Jan 24 15:53:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228882 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=vAebHFkM; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843dS6HXwz9sRW for ; Sat, 25 Jan 2020 02:55:40 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6684E81965; Fri, 24 Jan 2020 16:54:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vAebHFkM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8CD4081836; Fri, 24 Jan 2020 16:54:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) (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 35C30817C0 for ; Fri, 24 Jan 2020 16:54:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lf1-x141.google.com with SMTP id m30so1428313lfp.8 for ; Fri, 24 Jan 2020 07:54:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nlPnzm6cSfMO4ct9VDzmszW477K2drXi78RPAR/0oTk=; b=vAebHFkMdA5byDfppr/9D4JHCzH9nm2p3XgaTzVqRR7uinq+L2zBtM3QQdLPbrhzHd w/XhlYWhP2CKG0907nUXMvneiZGs2ZQU3wka5T/7shePQ82QFPGsRz96ufIAS1Z7+h2U Wg8aF03dEKcye90pHIod7YmCUNCF3F2AXZo7rjN9OepYYADwpPfMiev5Ik7A/17AkNzQ dwAvVucAHn70lOCn1rp5U+GR9cTBIBe4YL9hWsNHPKQHkKD8OA4XXTa97H/PeVR6YEpz Kqi7jWMqfXZcG9DQGkRJx1Wcrgyc+WAxRrSuQQENB+ljuropXVbQOVE7dPwvGoUnSCSO f0mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nlPnzm6cSfMO4ct9VDzmszW477K2drXi78RPAR/0oTk=; b=I190qAIECgm6S5EVD18ka8ILk+SkISsDRWiZsDQokDMGoTd0Ok5/yDCAUiRu8eJuGq vlu5fiahyVMYvGdeXf1tSe7lrf/qa02PZ+Zn3O/XOiaV8lInmQWIxoPjblBK98zoz4GS xpo7go8Fb4l1GwDB5NwRjuB4uHZM8J/obHCvUtJinQfGMnyjykKyCljy9+kE7TBI9GL4 kuXT+X3XBo2wrTgjLppiS170Rig6y+knwG92fbxlqfqQ22rPWJoF/f8Bjcuj+8OD1O6q lfIrn7npXf+Ri6CdY2kADYGvVoWTv7grBpqVg5jqAc2N+Yr0b9guTRf761uoQgSJeYCs yOVw== X-Gm-Message-State: APjAAAWMgTOqeycsJ00aHUp/YnTlgW++NrJnbbYbR/ArhJBcAYGSi1gy ucZcy1nWueefE2LO+xGwN36SjCiw7Zk= X-Google-Smtp-Source: APXvYqx3gbLh82yBo0Bgk/BfrUIODJrz0vwUSxs3NsFXcMN162vsIyzh9qxP4aQDXoiP8f1bVHbblQ== X-Received: by 2002:a19:5e0a:: with SMTP id s10mr1702655lfb.165.1579881244188; Fri, 24 Jan 2020 07:54:04 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id u23sm2929736lfg.89.2020.01.24.07.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:54:03 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 09/10] env: ti: boot: Boot Android with dynamic partitions Date: Fri, 24 Jan 2020 17:53:48 +0200 Message-Id: <20200124155349.12927-10-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Changes: - use boot.img instead of boot_fit.img - use .dtb from boot.img v2 - implement recovery boot - always boot ramdisk from boot.img, we can't mount system as root now, as system is a logical partition inside of super partition - don't add "skip_initramfs" to cmdline anymore - to boot into recovery, use boot image from recovery partition - prepare partition table: - A/B scheme - use 'super' partition instead of 'system' and 'vendor' - add dtbo partitions - introduce metadata partition Not implemented: reading and applying dtbo blobs from dtbo partition. Signed-off-by: Sam Protsenko --- include/environment/ti/boot.h | 115 +++++++++++++++------------------- 1 file changed, 49 insertions(+), 66 deletions(-) diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h index bfbd76c3af..5a0fc1dc5d 100644 --- a/include/environment/ti/boot.h +++ b/include/environment/ti/boot.h @@ -13,30 +13,14 @@ #define CONSOLEDEV "ttyS2" #endif -#define VBMETA_PART_SIZE (64 * 1024) - -#if defined(CONFIG_LIBAVB) -#define VBMETA_PART \ - "name=vbmeta,size=" __stringify(VBMETA_PART_SIZE) \ - ",uuid=${uuid_gpt_vbmeta};" -#else -#define VBMETA_PART "" -#endif - -#if defined(CONFIG_CMD_AB_SELECT) -#define COMMON_PARTS \ - "name=boot_a,size=20M,uuid=${uuid_gpt_boot_a};" \ - "name=boot_b,size=20M,uuid=${uuid_gpt_boot_b};" \ - "name=system_a,size=1024M,uuid=${uuid_gpt_system_a};" \ - "name=system_b,size=1024M,uuid=${uuid_gpt_system_b};" -#else -#define COMMON_PARTS \ - "name=boot,size=20M,uuid=${uuid_gpt_boot};" \ - "name=system,size=1024M,uuid=${uuid_gpt_system};" -#endif - #ifndef PARTS_DEFAULT -/* Define the default GPT table for eMMC */ +/* + * Default GPT tables for eMMC (Linux and Android). Notes: + * 1. Keep partitions aligned to erase group size (512 KiB) when possible + * 2. Keep partitions in sync with DFU_ALT_INFO_EMMC (see dfu.h) + * 3. Keep 'bootloader' partition (U-Boot proper) start address in sync with + * CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR (see common/spl/Kconfig) + */ #define PARTS_DEFAULT \ /* Linux partitions */ \ "uuid_disk=${uuid_gpt_disk};" \ @@ -49,10 +33,15 @@ "name=bootloader,size=2048K,uuid=${uuid_gpt_bootloader};" \ "name=uboot-env,start=2432K,size=256K,uuid=${uuid_gpt_reserved};" \ "name=misc,size=128K,uuid=${uuid_gpt_misc};" \ - "name=recovery,size=40M,uuid=${uuid_gpt_recovery};" \ - COMMON_PARTS \ - "name=vendor,size=256M,uuid=${uuid_gpt_vendor};" \ - VBMETA_PART \ + "name=boot_a,size=20M,uuid=${uuid_gpt_boot_a};" \ + "name=boot_b,size=20M,uuid=${uuid_gpt_boot_b};" \ + "name=dtbo_a,size=8M,uuid=${uuid_gpt_dtbo_a};" \ + "name=dtbo_b,size=8M,uuid=${uuid_gpt_dtbo_b};" \ + "name=vbmeta_a,size=64K,uuid=${uuid_gpt_vbmeta_a};" \ + "name=vbmeta_b,size=64K,uuid=${uuid_gpt_vbmeta_b};" \ + "name=recovery,size=64M,uuid=${uuid_gpt_recovery};" \ + "name=super,size=2560M,uuid=${uuid_gpt_super};" \ + "name=metadata,size=16M,uuid=${uuid_gpt_metadata};" \ "name=userdata,size=-,uuid=${uuid_gpt_userdata}" #endif /* PARTS_DEFAULT */ @@ -72,7 +61,7 @@ #define CONTROL_PARTITION "misc" #if defined(CONFIG_CMD_AB_SELECT) -#define AB_SELECT \ +#define AB_SELECT_SLOT \ "if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \ "then " \ "echo " CONTROL_PARTITION \ @@ -82,20 +71,14 @@ "echo " CONTROL_PARTITION " partition not found;" \ "exit;" \ "fi;" \ - "setenv slot_suffix _${slot_name};" \ - "if part number mmc ${mmcdev} system${slot_suffix} " \ - "system_part_number; then " \ - "setenv bootargs_ab " \ - "ro root=/dev/mmcblk${mmcdev}p${system_part_number} " \ - "rootwait init=/init skip_initramfs " \ - "androidboot.slot_suffix=${slot_suffix};" \ - "echo A/B cmdline addition: ${bootargs_ab};" \ - "setenv bootargs ${bootargs} ${bootargs_ab};" \ - "else " \ - "echo system${slot_suffix} partition not found;" \ - "fi;" + "setenv slot_suffix _${slot_name};" +#define AB_SELECT_ARGS \ + "setenv bootargs_ab androidboot.slot_suffix=${slot_suffix}; " \ + "echo A/B cmdline addition: ${bootargs_ab};" \ + "setenv bootargs ${bootargs} ${bootargs_ab};" #else -#define AB_SELECT "" +#define AB_SELECT_SLOT "" +#define AB_SELECT_ARGS "" #endif #define FASTBOOT_CMD \ @@ -121,46 +104,46 @@ "setenv mmcroot /dev/mmcblk0p2 rw; " \ "run mmcboot;\0" \ "emmc_android_boot=" \ + "setenv mmcdev 1; " \ + "mmc dev $mmcdev; " \ + "mmc rescan; " \ + AB_SELECT_SLOT \ "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \ CONTROL_PARTITION "; then " \ + "setenv ardaddr -; " \ "if bcb test command = bootonce-bootloader; then " \ - "echo BCB: Bootloader boot...; " \ + "echo Android: Bootloader boot...; " \ "bcb clear command; bcb store; " \ FASTBOOT_CMD \ + "exit; " \ "elif bcb test command = boot-recovery; then " \ - "echo BCB: Recovery boot...; " \ - "echo Warning: recovery is not implemented; " \ - "echo Performing normal boot for now...; " \ - "bcb clear command; bcb store; " \ - "run emmc_android_normal_boot; " \ + "echo Android: Recovery boot...; " \ + "setenv ardaddr $loadaddr;" \ + "setenv apart recovery; " \ "else " \ - "echo BCB: Normal boot requested...; " \ - "run emmc_android_normal_boot; " \ + "echo Android: Normal boot...; " \ + "setenv ardaddr $loadaddr; " \ + "setenv apart boot${slot_suffix}; " \ "fi; " \ "else " \ "echo Warning: BCB is corrupted or does not exist; " \ - "echo Performing normal boot...; " \ - "run emmc_android_normal_boot; " \ - "fi;\0" \ - "emmc_android_normal_boot=" \ - "echo Trying to boot Android from eMMC ...; " \ - "run update_to_fit; " \ + "echo Android: Normal boot...; " \ + "fi; " \ "setenv eval_bootargs setenv bootargs $bootargs; " \ "run eval_bootargs; " \ - "setenv mmcdev 1; " \ "setenv machid fe6; " \ - "mmc dev $mmcdev; " \ - "mmc rescan; " \ AVB_VERIFY_CHECK \ - AB_SELECT \ - "if part start mmc ${mmcdev} boot${slot_suffix} boot_start; " \ - "then " \ - "part size mmc ${mmcdev} boot${slot_suffix} " \ - "boot_size; " \ - "mmc read ${loadaddr} ${boot_start} ${boot_size}; " \ - "bootm ${loadaddr}#${fdtfile}; " \ + AB_SELECT_ARGS \ + "if part start mmc $mmcdev $apart boot_start; then " \ + "part size mmc $mmcdev $apart boot_size; " \ + "mmc read $loadaddr $boot_start $boot_size; " \ + "abootimg get dtb --index=0 dtb_start dtb_size; " \ + "cp.b $dtb_start $fdtaddr $dtb_size; " \ + "fdt addr $fdtaddr; " \ + "bootm $loadaddr $ardaddr $fdtaddr; " \ "else " \ - "echo boot${slot_suffix} partition not found; " \ + "echo $apart partition not found; " \ + "exit; " \ "fi;\0" #ifdef CONFIG_OMAP54XX From patchwork Fri Jan 24 15:53:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 1228884 X-Patchwork-Delegate: lokeshvutla@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=euypVyxT; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4843dt1HQjz9sRW for ; Sat, 25 Jan 2020 02:56:02 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 23EC681974; Fri, 24 Jan 2020 16:54:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="euypVyxT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C1BED817C0; Fri, 24 Jan 2020 16:54:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) (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 9114681819 for ; Fri, 24 Jan 2020 16:54:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=joe.skb7@gmail.com Received: by mail-lj1-x242.google.com with SMTP id j26so2976291ljc.12 for ; Fri, 24 Jan 2020 07:54:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9jgwWuWIjXjqVQ/c4UjeVMi6HqrBn2Yv69RJ4jmXaTI=; b=euypVyxT0GqOb+a9lqFiCEjRdSSTwXOjRysdS8aXeaFwSic0FSu1pIs+euabbiCVkn 0JymyPV8sonyW+YIlS4N/A4atlNMPh4PKcJ/DLioh0Az7KdZ3m23XFbrGkQYYgUo3GNx FU4biwD5SvDzUaR3omHwxAlVxte/ev9K9tuEGPojIvRYNae0ybCd+I2m8fcIdrIEAHpl DaVCJScy08aU0SON5AYt53sTHGgxHpUAdRfafegtbRuqzAo/5Uo8xI6mXWY6XyCUYPDK AYh81ix3ySIztXnBxh+S3/hUJPcnrQpjVGVKaEA4rkGyICLRTOoubjKk4pw1A+EqBViP IPAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9jgwWuWIjXjqVQ/c4UjeVMi6HqrBn2Yv69RJ4jmXaTI=; b=jS0mvmZBGgdD//+O+womSbE5l80B7OQe/zXGx6BZ3YvA6J//AVmy8o0mndNJYcS/Hj 3zmwl7zskpz1q2Z7/71O0JURb1cn+9YAIre+dfnVD0hiTHxOi6BPtFdFaDG1xUEFPbEN eyQbNC+fk3iZQBSb3oqPVtL/rcHD4+JuIGdLoAow2botWh+OG0ZhA8zbFAMzOD9rhnxd m0tVnLEJw3b/fO09xn/WgxIWrdEO4ursNIwGykob3Lvivtr8GAhEpp++sFgGrcTMLpSL qliywUeSpUEbjorMe55Vwv+tBpx9U+WD/11P0ZZMpSglhhjnl1g3i9/tyeIZHgXQ3WpG MUzw== X-Gm-Message-State: APjAAAVF7rYQNVz9CU4wrB85IW0mQo5O6irvVRPgtpz7A9inJlH1tsLj SxtdzyFO0U4PBbMfLb4GhJlCyDfHhQk= X-Google-Smtp-Source: APXvYqxIr3VEn+KcevdDxLvfMv7vxy8m/hvA1gkT1SebFCP4A34Og6lJV69bbJikJcwaBryvrcIEPA== X-Received: by 2002:a2e:884f:: with SMTP id z15mr2727501ljj.46.1579881245540; Fri, 24 Jan 2020 07:54:05 -0800 (PST) Received: from localhost ([2001:67c:2e5c:2011:2e0:4cff:fe68:2882]) by smtp.gmail.com with ESMTPSA id i4sm3809942lji.0.2020.01.24.07.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 07:54:05 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Subject: [PATCH v4 10/10] arm: ti: boot: Use correct dtb and dtbo on Android boot Date: Fri, 24 Jan 2020 17:53:49 +0200 Message-Id: <20200124155349.12927-11-joe.skb7@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200124155349.12927-1-joe.skb7@gmail.com> References: <20200124155349.12927-1-joe.skb7@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Roman Stratiienko , Eugeniu Rosca , Praneeth Bajjuri , Heinrich Schuchardt , Alistair Strachan Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Read correct dtb blob from boot.img/recovery.img and apply correct dtbo blobs from dtbo partition. Signed-off-by: Sam Protsenko --- include/configs/ti_armv7_common.h | 7 +++++ include/environment/ti/boot.h | 43 ++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/include/configs/ti_armv7_common.h b/include/configs/ti_armv7_common.h index a1a053e675..a612bb5b4a 100644 --- a/include/configs/ti_armv7_common.h +++ b/include/configs/ti_armv7_common.h @@ -37,11 +37,18 @@ * seen large trees). We say all of this must be within the first 256MB * as that will normally be within the kernel lowmem and thus visible via * bootm_size and we only run on platforms with 256MB or more of memory. + * + * As a temporary storage for DTBO blobs (which should be applied into DTB + * blob), we use the location 15.5 MB above the ramdisk. If someone wants to + * use ramdisk bigger than 15.5 MB, then DTBO can be loaded and applied to DTB + * blob before loading the ramdisk, as DTBO location is only used as a temporary + * storage, and can be re-used after 'fdt apply' command is done. */ #define DEFAULT_LINUX_BOOT_ENV \ "loadaddr=0x82000000\0" \ "kernel_addr_r=0x82000000\0" \ "fdtaddr=0x88000000\0" \ + "dtboaddr=0x89000000\0" \ "fdt_addr_r=0x88000000\0" \ "rdaddr=0x88080000\0" \ "ramdisk_addr_r=0x88080000\0" \ diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h index 5a0fc1dc5d..523c8fc4fe 100644 --- a/include/environment/ti/boot.h +++ b/include/environment/ti/boot.h @@ -81,6 +81,45 @@ #define AB_SELECT_ARGS "" #endif +/* + * Prepares complete device tree blob for current board (for Android boot). + * + * Boot image or recovery image should be loaded into $loadaddr prior to running + * these commands. The logic of these commnads is next: + * + * 1. Read correct DTB for current SoC/board from boot image in $loadaddr + * to $fdtaddr + * 2. Merge all needed DTBO for current board from 'dtbo' partition into read + * DTB + * 3. User should provide $fdtaddr as 3rd argument to 'bootm' + */ +#define PREPARE_FDT \ + "echo Preparing FDT...; " \ + "if test $board_name = am57xx_evm_reva3; then " \ + "echo \" Reading DTBO partition...\"; " \ + "part start mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_start; " \ + "part size mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_size; " \ + "mmc read ${dtboaddr} ${p_dtbo_start} ${p_dtbo_size}; " \ + "echo \" Reading DTB for AM57x EVM RevA3...\"; " \ + "abootimg get dtb --index=0 dtb_start dtb_size; " \ + "cp.b $dtb_start $fdtaddr $dtb_size; " \ + "fdt addr $fdtaddr; " \ + "echo \" Applying DTBOs for AM57x EVM RevA3...\"; " \ + "adtimg addr $dtboaddr; " \ + "adtimg get dt --index=0 dtbo0_addr; " \ + "fdt apply $dtbo0_addr; " \ + "adtimg get dt --index=1 dtbo1_addr; " \ + "fdt apply $dtbo1_addr; " \ + "elif test $board_name = beagle_x15_revc; then " \ + "echo \" Reading DTB for Beagle X15 RevC...\"; " \ + "abootimg get dtb --index=0 dtb_start dtb_size; " \ + "cp.b $dtb_start $fdtaddr $dtb_size; " \ + "fdt addr $fdtaddr; " \ + "else " \ + "echo Error: Android boot is not supported for $board_name; " \ + "exit; " \ + "fi; " \ + #define FASTBOOT_CMD \ "echo Booting into fastboot ...; " \ "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " @@ -137,9 +176,7 @@ "if part start mmc $mmcdev $apart boot_start; then " \ "part size mmc $mmcdev $apart boot_size; " \ "mmc read $loadaddr $boot_start $boot_size; " \ - "abootimg get dtb --index=0 dtb_start dtb_size; " \ - "cp.b $dtb_start $fdtaddr $dtb_size; " \ - "fdt addr $fdtaddr; " \ + PREPARE_FDT \ "bootm $loadaddr $ardaddr $fdtaddr; " \ "else " \ "echo $apart partition not found; " \