All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
To: u-boot@lists.denx.de
Subject: [PATCH v5 3/3] fastboot: Add default fastboot_set_reboot_flag implementation
Date: Tue, 28 Jul 2020 23:35:34 +0300	[thread overview]
Message-ID: <37005f03951452cbcf1d2a82b740c63b7803829b.1595967224.git.roman.kovalivskyi@globallogic.com> (raw)
In-Reply-To: <cover.1595967223.git.roman.kovalivskyi@globallogic.com>

Default implementation of fastboot_set_reboot_flag function that depends
on "bcb" commands could be used in general case if there are no need to
make any platform-specific implementation, otherwise it could be
disabled via Kconfig option FASTBOOT_USE_BCB_SET_REBOOT_FLAG.

Please note that FASTBOOT_USE_BCB_SET_REBOOT_FLAG is mutually exclusive
with some platforms which already have their own implementation of this
function.

Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 drivers/fastboot/Kconfig       | 12 ++++++++++
 drivers/fastboot/Makefile      |  1 +
 drivers/fastboot/fb_bcb_impl.c | 43 ++++++++++++++++++++++++++++++++++
 include/fastboot.h             |  9 +++++++
 4 files changed, 65 insertions(+)
 create mode 100644 drivers/fastboot/fb_bcb_impl.c

diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index d4436dfc9173..4352ba67a713 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -165,6 +165,18 @@ config FASTBOOT_CMD_OEM_FORMAT
 	  relies on the env variable partitions to contain the list of
 	  partitions as required by the gpt command.
 
+config FASTBOOT_USE_BCB_SET_REBOOT_FLAG
+	bool "Use BCB by fastboot to set boot reason"
+	depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \
+	  !TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM
+	default y
+	help
+	  Fastboot could implement setting of reboot reason in a generic fashion
+	  via BCB commands. BCB commands are able to write reboot reason into
+	  command field of boot control block. In general case it is sufficient
+	  implementation if your platform supports BCB commands and doesn't
+	  require any specific reboot reason handling.
+
 endif # FASTBOOT
 
 endmenu
diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
index 048af5aa8234..2b2c390fe4de 100644
--- a/drivers/fastboot/Makefile
+++ b/drivers/fastboot/Makefile
@@ -5,3 +5,4 @@ obj-y += fb_getvar.o
 obj-y += fb_command.o
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o
 obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o
+obj-$(CONFIG_FASTBOOT_USE_BCB_SET_REBOOT_FLAG) += fb_bcb_impl.o
diff --git a/drivers/fastboot/fb_bcb_impl.c b/drivers/fastboot/fb_bcb_impl.c
new file mode 100644
index 000000000000..89ec3601b6f6
--- /dev/null
+++ b/drivers/fastboot/fb_bcb_impl.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2020 GlobalLogic.
+ * Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
+ */
+
+#include <common.h>
+#include <fastboot.h>
+
+/**
+ * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
+ *
+ * Set flag which indicates that we should reboot into the bootloader
+ * following the reboot that fastboot executes after this function.
+ *
+ * This function should be overridden in your board file with one
+ * which sets whatever flag your board specific Android bootloader flow
+ * requires in order to re-enter the bootloader.
+ */
+int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
+{
+	char cmd[64];
+
+	if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
+		return -EINVAL;
+
+	snprintf(cmd, sizeof(cmd), "bcb load %d misc",
+		 CONFIG_FASTBOOT_FLASH_MMC_DEV);
+
+	if (run_command(cmd, 0))
+		return -ENODEV;
+
+	snprintf(cmd, sizeof(cmd), "bcb set command %s",
+		 fastboot_boot_cmds[reason]);
+
+	if (run_command(cmd, 0))
+		return -ENOEXEC;
+
+	if (run_command("bcb store", 0))
+		return -EIO;
+
+	return 0;
+}
diff --git a/include/fastboot.h b/include/fastboot.h
index b86b508e69fd..8e9ee80907df 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -52,6 +52,15 @@ enum fastboot_reboot_reason {
 	FASTBOOT_REBOOT_REASONS_COUNT
 };
 
+/**
+ * BCB boot commands
+ */
+static const char * const fastboot_boot_cmds[] = {
+	[FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader",
+	[FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot",
+	[FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery"
+};
+
 /**
  * fastboot_response() - Writes a response of the form "$tag$reason".
  *
-- 
2.17.1

      parent reply	other threads:[~2020-07-28 20:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28 20:35 [PATCH v5 0/3] Add support for booting into userspace fastboot Roman Kovalivskyi
2020-07-28 20:35 ` [PATCH v5 1/3] fastboot: Extend fastboot_set_reboot_flag with reboot reason Roman Kovalivskyi
2020-07-28 20:35 ` [PATCH v5 2/3] fastboot: Add support for 'reboot fastboot' command Roman Kovalivskyi
2020-07-28 20:35 ` Roman Kovalivskyi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37005f03951452cbcf1d2a82b740c63b7803829b.1595967224.git.roman.kovalivskyi@globallogic.com \
    --to=roman.kovalivskyi@globallogic.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.