From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 51C07C433F5 for ; Tue, 11 Jan 2022 17:58:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1EE8682F91; Tue, 11 Jan 2022 18:58:26 +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=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QriEAPgl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D0C3683055; Tue, 11 Jan 2022 18:58:22 +0100 (CET) Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (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 93F0482EBB for ; Tue, 11 Jan 2022 18:58:19 +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=dsankouski@gmail.com Received: by mail-ed1-x532.google.com with SMTP id o6so70454260edc.4 for ; Tue, 11 Jan 2022 09:58:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ildl/ImrAPxYsdELDVQB9tcYtJwin1UaCvpnG3xLl8c=; b=QriEAPgl8oSYeJeTsWoMEtLjyDrGAgdGYE3meZiFWyrecJnstb3ph1wHIqAv4ETF2P 8j7tTATDLTRDbjnBPLsOwU33umW4K+lCXA6v15W3RPB1WrhL5R/F136J3RMd0Y6EcX1F 1iUjG9X3vGEiPYlzjqsAqs/RowCJiKjlD0v+4qEH+WlYjnRy4EWObYWBT6oWCNWDMuyN AQ58fhp0+Cfxi+4V+EbKOsuDTz5P4erxF+O1iuzhS0tn4xgxP1wQuRM0S3X46i87Za0H +sgPa8t+TUQNccWxpNF7X8yA4LKjClC8XX9bv10O0xdMA6aPlckgPItY8WpzBmmOX6lN 5xDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ildl/ImrAPxYsdELDVQB9tcYtJwin1UaCvpnG3xLl8c=; b=GeSmVM/V4BwRZGNnLVZ5zP4PO0cd+9M8Xgh1rreyRoD/UkuDgx2iYB6YYjjO3fVw36 u2yaasjYQ0G4LEBcFT4mQ3CTXlPJw8keAUTUOJaDxKz6ZFkqQLGZM4uDPqJmEyH9lRw1 cAFtSk1A0baLUkMgb7+9/eIjhY1T9zUdD1YZftfBYw2qxxL4It9WRKYootFbV34aujfz VuW/rtpKcOIVA0T178NlnxOxKtS+QCeqqhdIkdTnOwm4EBYYfh4HrVSAZTccvaenu95I D/AAeWsYDOvYhWnznTt9o6wz/15o3wVU6IJMzWlWjarPzOtypcQnlPR8vMPJeBDrcD3u AF8w== X-Gm-Message-State: AOAM531j5XhOhtBwP84UHCMwKnSq0cgjZuUH3EilJ4CtC/oxD/Cs2Ogc wq7aLvcLC3xtakwFEndO08pllMk3q4DqPg== X-Google-Smtp-Source: ABdhPJwMy88fZ0cWlWoyWSRK/NLDT7+x4p67VuhwI486fXbeaCcJubol4Cr809G4/X8tsd7zfiOfsA== X-Received: by 2002:a05:6402:11c9:: with SMTP id j9mr5356863edw.385.1641923898984; Tue, 11 Jan 2022 09:58:18 -0800 (PST) Received: from localhost.localdomain ([46.216.45.177]) by smtp.gmail.com with ESMTPSA id k16sm3815919ejk.172.2022.01.11.09.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 09:58:18 -0800 (PST) From: Dzmitry Sankouski To: u-boot@lists.denx.de Cc: Dzmitry Sankouski , Ramon Fried , Tom Rini Subject: [PATCH 1/2 v2] soc: sdm845: implement ABL info collecting, add bootcommand and usage doc Date: Tue, 11 Jan 2022 20:58:16 +0300 Message-Id: <20220111175817.5973-2-dsankouski@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220111175817.5973-1-dsankouski@gmail.com> References: <20220111175817.5973-1-dsankouski@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean U-boot is intended to replace linux kernel in android boot image, and it's FIT payload to replace initramfs file. The boot process is similar to boot image with linux: - android bootloader (ABL) unpacks android boot image - ABL sets `linux,initrd-start property` in chosen node in unpacked FDT - ABL sets x0 register to FDT address, and passes control to u-boot - u-boot reads x0 register, and stores it in `abl_fdt_addr` env variable - u-boot reads `linux,initrd-start` property, and stores it in `abl_initrd_start_addr` In this way, u-boot bootcmd relies on `abl_initrd_start_addr` env variable, and boils down to `bootm $abl_initrd_start_addr`. If more control on boot process is desired, pack a boot script in FIT image, and put it to default configuration Signed-off-by: Dzmitry Sankouski Cc: Ramon Fried Cc: Tom Rini --- Changes for v2: - Fix compilation warnings arch/arm/mach-snapdragon/init_sdm845.c | 60 ++++++++++++++++++++---- doc/board/qualcomm/sdm845.rst | 63 +++++++++++++++++++++++++- include/configs/sdm845.h | 5 ++ 3 files changed, 116 insertions(+), 12 deletions(-) diff --git a/arch/arm/mach-snapdragon/init_sdm845.c b/arch/arm/mach-snapdragon/init_sdm845.c index 5f53c21947..417a928b50 100644 --- a/arch/arm/mach-snapdragon/init_sdm845.c +++ b/arch/arm/mach-snapdragon/init_sdm845.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -14,6 +15,14 @@ DECLARE_GLOBAL_DATA_PTR; +static ulong fdt_addr __section(".data"); + +void save_boot_params(ulong r0) +{ + fdt_addr = r0; + save_boot_params_ret(); +} + int dram_init(void) { return fdtdec_setup_mem_size_base(); @@ -29,8 +38,33 @@ __weak int board_init(void) return 0; } -/* Check for vol- and power buttons */ -__weak int misc_init_r(void) +void set_abl_env(void) +{ + const void *fdt_blob; + int node, ret; + ulong initrd_start_prop; + + ret = env_set_addr("abl_fdt_addr", (void *)fdt_addr); + if (ret < 0) { + printf("Failed to set abl device tree address\n"); + return; + } + + fdt_blob = (void *)fdt_addr; + node = fdt_path_offset(fdt_blob, "/chosen"); + if (!node) { + printf("Chosen node not found in device tree at addr: 0x%lx\n", fdt_addr); + return; + } + initrd_start_prop = fdtdec_get_addr(fdt_blob, node, "linux,initrd-start"); + if (!initrd_start_prop) { + printf("linux,initrd-start property is not set\n"); + return; + } + env_set_addr("abl_initrd_start_addr", (void *)initrd_start_prop); +} + +void read_pressed_keys(void) { struct udevice *pon; struct gpio_desc resin; @@ -39,19 +73,19 @@ __weak int misc_init_r(void) ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8998_pon@800", &pon); if (ret < 0) { printf("Failed to find PMIC pon node. Check device tree\n"); - return 0; + return; } node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon), - "key_vol_down"); + "key_vol_down"); if (node < 0) { printf("Failed to find key_vol_down node. Check device tree\n"); - return 0; + return; } if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, - &resin, 0)) { + &resin, 0)) { printf("Failed to request key_vol_down button.\n"); - return 0; + return; } if (dm_gpio_get_value(&resin)) { env_set("key_vol_down", "1"); @@ -64,12 +98,12 @@ __weak int misc_init_r(void) "key_power"); if (node < 0) { printf("Failed to find key_power node. Check device tree\n"); - return 0; + return; } if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, - &resin, 0)) { + &resin, 0)) { printf("Failed to request key_power button.\n"); - return 0; + return; } if (dm_gpio_get_value(&resin)) { env_set("key_power", "1"); @@ -77,6 +111,12 @@ __weak int misc_init_r(void) } else { env_set("key_power", "0"); } +} + +__weak int misc_init_r(void) +{ + set_abl_env(); + read_pressed_keys(); return 0; } diff --git a/doc/board/qualcomm/sdm845.rst b/doc/board/qualcomm/sdm845.rst index cd46cbe9cf..e14fd05118 100644 --- a/doc/board/qualcomm/sdm845.rst +++ b/doc/board/qualcomm/sdm845.rst @@ -13,11 +13,27 @@ SDM845 - hi-end qualcomm chip, introduced in late 2017. Mostly used in flagship phones and tablets of 2018. U-Boot can be used as a replacement for Qualcomm's original ABL (UEFI) bootloader. -It is loaded as an Android boot image through ABL +It's replaces linux kernel in android boot image, and +it's FIT payload replaces initramfs file. The boot process is similar to +boot image with linux: + +- ABL unpacks android boot image +- ABL sets `linux,initrd-start property` in chosen node in unpacked FDT +- ABL sets x0 register to FDT address, and passes control to u-boot +- u-boot reads x0 register, and stores it in `abl_fdt_addr` env variable +- u-boot reads `linux,initrd-start` property, +and stores it in `abl_initrd_start_addr` + +In this way, u-boot bootcmd relies on `abl_initrd_start_addr` env variable, +and boils down to `bootm $abl_initrd_start_addr`. If more control on +boot process is desired, pack a boot script in FIT image, and put it to +default configuration Installation ------------ -First, setup ``CROSS_COMPILE`` for aarch64. Then, build U-Boot for your board:: +Build +^^^^^^^^^^^^^^^^^^^^^^^^ +Setup ``CROSS_COMPILE`` for aarch64 and build U-Boot for your board:: $ export CROSS_COMPILE= $ make _defconfig @@ -25,6 +41,49 @@ First, setup ``CROSS_COMPILE`` for aarch64. Then, build U-Boot for your board:: This will build ``u-boot.bin`` in the configured output directory. +Generate FIT image +^^^^^^^^^^^^^^^^^^^^^^^^ +See doc/uImage.FIT for more details + +Pack android boot image +^^^^^^^^^^^^^^^^^^^^^^^^ +We'll assemble android boot image with ``u-boot.bin`` instead of linux kernel, +and FIT image instead of ``initramfs``. Android bootloader expect gzipped kernel +with appended dtb, so let's mimic linux to satisfy stock bootloader: + +- create dump dtb:: + + workdir=/tmp/prepare_payload + mkdir -p "$workdir" + cd "$workdir" + mock_dtb="$workdir"/payload_mock.dtb + + dtc -I dts -O dtb -o "$mock_dtb" << EOF + /dts-v1/; + / { + memory { + /* We expect the bootloader to fill in the size */ + reg = <0 0 0 0>; + }; + + chosen { }; + }; + EOF + +- gzip u-boot ``gzip u-boot.bin`` +- append dtb to gzipped u-boot: ``cat u-boot.bin.gz "$mock_dtb" > u-boot.bin.gz-dtb`` + +Now we've got everything to build android boot image::: + + mkbootimg --base 0x0 --kernel_offset 0x00008000 \ + --ramdisk_offset 0x02000000 --tags_offset 0x01e00000 \ + --pagesize 4096 --second_offset 0x00f00000 \ + --ramdisk "$fit_image" \ + --kernel u-boot.bin.gz-dtb \ + -o boot.img + +Flash image with your phone's flashing method. + Boards ------------ starqlte diff --git a/include/configs/sdm845.h b/include/configs/sdm845.h index af9ba197d4..cdf0f7e030 100644 --- a/include/configs/sdm845.h +++ b/include/configs/sdm845.h @@ -16,6 +16,11 @@ /* Generic Timer Definitions */ #define COUNTER_FREQUENCY 19000000 +#define CONFIG_EXTRA_ENV_SETTINGS \ + "bootm_size=0x4000000\0" \ + "bootcmd=bootm $abl_initrd_start_addr\0" \ + "bootm_low=0x80000000\0" + /* Size of malloc() pool */ #define CONFIG_SYS_BOOTM_LEN SZ_64M -- 2.20.1