[PATCH v2 4/7] cmd: bcb: Expose 'bcb_write_reboot_reason' to external callers

Roman Kovalivskyi roman.kovalivskyi at globallogic.com
Tue Jan 26 21:54:53 CET 2021


From: Eugeniu Rosca <erosca at de.adit-jv.com>

Fastboot is evolving and beginning with commit [1], the
upstream implementation expects bootloaders to offer support for:
 - reboot-recovery
 - reboot-fastboot

The most natural way to achieve the above is through a set of
pre-defined "reboot reason" strings, written into / read from
the BCB "command" field, e.g.:
 - bootonce-bootloader [2]
 - boot-fastboot [3]
 - boot-recovery [4]

Expose the first 'bcb' API meant to be called by e.g. fastboot stack,
to allow updating the BCB reboot reason via the BCB 'command' field.

[1] https://android.googlesource.com/platform/system/core/+/dea91b4b5354af2
    ("Add fastbootd.")
[2] https://android.googlesource.com/platform/bootable/recovery/+/cba7fa88d8b9
    ("Add 'reboot bootloader' to bootloader_message.")
[3] https://android.googlesource.com/platform/bootable/recovery/+/eee4e260f9f6
    ("recovery: Add "boot-fastboot" command to BCB.")
[4] https://android.googlesource.com/platform/system/core/+/5e98b633a748695f
    ("init: Write the reason in BCB on "reboot recovery"")

Signed-off-by: Eugeniu Rosca <erosca at de.adit-jv.com>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi at globallogic.com>
---
 cmd/bcb.c     | 20 ++++++++++++++++++++
 include/bcb.h | 22 ++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 include/bcb.h

diff --git a/cmd/bcb.c b/cmd/bcb.c
index b9cd20ea3d56..5da3526142ad 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -6,6 +6,7 @@
  */
 
 #include <android_bootloader_message.h>
+#include <bcb.h>
 #include <command.h>
 #include <common.h>
 #include <log.h>
@@ -307,6 +308,25 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
 	return __bcb_store();
 }
 
+int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp)
+{
+	int ret;
+
+	ret = __bcb_load(devnum, partp);
+	if (ret != CMD_RET_SUCCESS)
+		return ret;
+
+	ret = __bcb_set("command", reasonp);
+	if (ret != CMD_RET_SUCCESS)
+		return ret;
+
+	ret = __bcb_store();
+	if (ret != CMD_RET_SUCCESS)
+		return ret;
+
+	return 0;
+}
+
 static struct cmd_tbl cmd_bcb_sub[] = {
 	U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_bcb_load, "", ""),
 	U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 1, do_bcb_set, "", ""),
diff --git a/include/bcb.h b/include/bcb.h
new file mode 100644
index 000000000000..05db5935e0e7
--- /dev/null
+++ b/include/bcb.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Eugeniu Rosca <rosca.eugeniu at gmail.com>
+ *
+ * Android Bootloader Control Block Header
+ */
+
+#ifndef __BCB_H__
+#define __BCB_H__
+
+#include <common.h>
+
+#if CONFIG_IS_ENABLED(CMD_BCB)
+int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp);
+#else
+static inline int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp)
+{
+	return -EOPNOTSUPP;
+}
+#endif
+
+#endif /* __BCB_H__ */
-- 
2.17.1



More information about the U-Boot mailing list