From patchwork Tue Nov 12 08:14:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 1193359 X-Patchwork-Delegate: ykai007@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="jqWNu71v"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47C0vJ5QPCz9sP4 for ; Tue, 12 Nov 2019 19:16:26 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C3BB4C21E31; Tue, 12 Nov 2019 08:16:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EAE0DC21C8B; Tue, 12 Nov 2019 08:16:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AB595C21C8B; Tue, 12 Nov 2019 08:16:17 +0000 (UTC) Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by lists.denx.de (Postfix) with ESMTPS id 46A2EC21C2C for ; Tue, 12 Nov 2019 08:16:17 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id d22so5199588lji.8 for ; Tue, 12 Nov 2019 00:16:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id; bh=Iz9+mXpzUHE4czZLGQhKmfA0gKvCz4WQ4fkLNiPAJDM=; b=jqWNu71vmnfYtceEV67MyzQa094YtE53lOLp+L18IRUnQbaoXgK4zGnM7XRT9uT3Uf Kv5lcSY8zFrWHQjK6ys/ubtINrdzriRgB5ks3ngFlSIT1dLGmDKHTWAyVKm5eGt1f+yH +9uo+k//tODt2vrnlOhgeS2BSUwUOxF7LqeSM= 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; bh=Iz9+mXpzUHE4czZLGQhKmfA0gKvCz4WQ4fkLNiPAJDM=; b=mjFjbMzo7FiXAZlAE+rmzMWflRSK5TjUuAj6UUpuJ91gIOxxlta5hmf7TvEFSngtlf d+bYz8/psLoNuEpf2FrzWJShmRfuEafovaaTKSbbyUHkRv+ix6yhwGzuj3U9O3mDVleq Kx+Qk9f+p2Vx/BPnhc5xqkwvInWmNRKLFc4vqJSkNlRnMBADu2eX2GUgNua9ZsRm1B6L PSITUL/EtUbTmNdMpYw+lL75zsU49SD+3/fiQXndfa/s6Ktv+qLD4FyA13Q8TXsNzaln GRtI/SSR6vtSW3dl5Hw3Mc0jO1CdcQcVF8D/LLyxg3VExLn4lUDMkGdIKL2wPDGInPF5 kqGw== X-Gm-Message-State: APjAAAVdvzkWi7AoG7GZW6m0RC4he1Zn9hSYfoY5ycEP2vWiVu9nvGzW MKwjciUMr1Mu2sRa5wSQLcdmRQ== X-Google-Smtp-Source: APXvYqymX7bYXYMI2RXKUvpqItHJb7R2lPf0f3YFkSTZgqGYxgDRaM9gJwEgfrGTZNuUJrwqeZb6Eg== X-Received: by 2002:a05:651c:1053:: with SMTP id x19mr19123043ljm.39.1573546576292; Tue, 12 Nov 2019 00:16:16 -0800 (PST) Received: from localhost.localdomain (pa-18-161-204.service.infuturo.it. [151.18.161.204]) by smtp.gmail.com with ESMTPSA id j27sm3293630lfh.31.2019.11.12.00.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2019 00:16:14 -0800 (PST) From: Michael Trimarchi To: Philipp Tomsich , Kever Yang Date: Tue, 12 Nov 2019 09:14:10 +0100 Message-Id: <20191112081410.24876-1-michael@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [RFC PATCH] rockchip: tinker: Add boot from capability X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" We need to know from what device we are booting in order to save the enviroment in right place Signed-off-by: Michael Trimarchi --- arch/arm/dts/rk3288-tinker-s-u-boot.dtsi | 1 + arch/arm/mach-rockchip/rk3288/rk3288.c | 46 ++++++++++++++++++++ board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +++++++++++++++++ configs/tinker-rk3288_defconfig | 2 + configs/tinker-s-rk3288_defconfig | 2 + 5 files changed, 92 insertions(+) diff --git a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi index 538593359a..2193127514 100644 --- a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi +++ b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi @@ -10,6 +10,7 @@ chosen { u-boot,spl-boot-order = \ "same-as-spl", &sdmmc, &emmc; + u-boot,spl-boot-device = "/dwmmc@ff0f0000"; }; }; diff --git a/arch/arm/mach-rockchip/rk3288/rk3288.c b/arch/arm/mach-rockchip/rk3288/rk3288.c index 987b4e0d58..002d1508e5 100644 --- a/arch/arm/mach-rockchip/rk3288/rk3288.c +++ b/arch/arm/mach-rockchip/rk3288/rk3288.c @@ -3,6 +3,8 @@ * Copyright (c) 2016 Rockchip Electronics Co., Ltd */ #include +#include +#include #include #include #include @@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { [BROM_BOOTSOURCE_SD] = "/dwmmc@ff0c0000", }; +#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) +const char *spl_decode_boot_device(u32 boot_device) +{ + int i; + static const struct { + u32 boot_device; + const char *ofpath; + } spl_boot_devices_tbl[] = { + { BOOT_DEVICE_MMC2, "/dwmmc@ff0f0000" }, + { BOOT_DEVICE_MMC1, "/dwmmc@ff0c0000" }, + }; + + for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i) + if (spl_boot_devices_tbl[i].boot_device == boot_device) + return spl_boot_devices_tbl[i].ofpath; + + return NULL; +} + +void spl_perform_fixups(struct spl_image_info *spl_image) +{ + void *blob = (void *)gd->fdt_blob; + const char *boot_ofpath; + int chosen; + + if (!blob) + return; + + boot_ofpath = spl_decode_boot_device(spl_image->boot_device); + if (!boot_ofpath) { + pr_err("%s: could not map boot_device to ofpath\n", __func__); + return; + } + + chosen = fdt_find_or_add_subnode(blob, 0, "chosen"); + if (chosen < 0) { + pr_err("%s: could not find/create '/chosen'\n", __func__); + return; + } + fdt_setprop_string(blob, chosen, + "u-boot,spl-boot-device", boot_ofpath); +} +#endif + #ifdef CONFIG_SPL_BUILD static void configure_l2ctlr(void) { diff --git a/board/rockchip/tinker_rk3288/tinker-rk3288.c b/board/rockchip/tinker_rk3288/tinker-rk3288.c index 6c76c3c25c..66a7394d95 100644 --- a/board/rockchip/tinker_rk3288/tinker-rk3288.c +++ b/board/rockchip/tinker_rk3288/tinker-rk3288.c @@ -9,6 +9,34 @@ #include #include +static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV; + +/* + * Select the boot device according to what was set in spl step + */ +static int setup_boottargets(void) +{ + const char *boot_device = + ofnode_get_chosen_prop("u-boot,spl-boot-device"); + + if (!boot_device) { + debug("%s: /chosen/u-boot,spl-boot-device not set\n", + __func__); + return -1; + } + debug("%s: booted from %s\n", __func__, boot_device); + + if (!strcmp(boot_device, "/dwmmc@ff0f0000")) { + /* eMMC boot device */ + tinker_boot_device = 1; + } else { + /* sdcard boot device */ + tinker_boot_device = 0; + } + + return 0; +} + static int get_ethaddr_from_eeprom(u8 *addr) { int ret; @@ -33,3 +61,16 @@ int rk3288_board_late_init(void) return 0; } + +int misc_init_r(void) +{ + setup_boottargets(); + + return 0; +} + +int mmc_get_env_dev(void) +{ + debug("boot device %d\n", tinker_boot_device); + return tinker_boot_device; +} diff --git a/configs/tinker-rk3288_defconfig b/configs/tinker-rk3288_defconfig index c851a93f31..106e24e8ca 100644 --- a/configs/tinker-rk3288_defconfig +++ b/configs/tinker-rk3288_defconfig @@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000 CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000 CONFIG_SYS_MALLOC_F_LEN=0x4000 +CONFIG_SPL_OF_LIBFDT=y # CONFIG_ANDROID_BOOT_IMAGE is not set +CONFIG_MISC_INIT_R=y CONFIG_USE_PREBOOT=y CONFIG_SILENT_CONSOLE=y CONFIG_CONSOLE_MUX=y diff --git a/configs/tinker-s-rk3288_defconfig b/configs/tinker-s-rk3288_defconfig index c851a93f31..106e24e8ca 100644 --- a/configs/tinker-s-rk3288_defconfig +++ b/configs/tinker-s-rk3288_defconfig @@ -13,7 +13,9 @@ CONFIG_DEBUG_UART=y CONFIG_TPL_SYS_MALLOC_F_LEN=0x4000 CONFIG_SPL_SYS_MALLOC_F_LEN=0x4000 CONFIG_SYS_MALLOC_F_LEN=0x4000 +CONFIG_SPL_OF_LIBFDT=y # CONFIG_ANDROID_BOOT_IMAGE is not set +CONFIG_MISC_INIT_R=y CONFIG_USE_PREBOOT=y CONFIG_SILENT_CONSOLE=y CONFIG_CONSOLE_MUX=y