Skip to contentSkip to conversation

fastboot: add UUU command UCmd and ACmd support

PATCH New Heiko Schocher 1 participant 1 message Feb 10, 2021 USB

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 fastboot: add UUU command UCmd and ACmd support

add support for the UUU commands ACmd and UCmd.

Enable them through the Kconfig option
CONFIG_FASTBOOT_UUU_SUPPORT

base was commit in NXP kernel
9b149c2a2882: ("MLK-18591-3 android: Add FSL android fastboot support")

and ported it to current mainline. Tested this patch on imx6ul based board.

---

azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=60&view=results

Changes in v5:
- add length check in run_acmd as Patrick suggested

Changes in v4:
- fixed missing parts from Sean Anderson patches lost while rebased to tree from lukasz

Changes in v3:
- rebased to https://github.com/lmajewski/u-boot-dfu/commits/testing
as Lukasz mentioned.

Changes in v2:
- remove unused FSL_FASTBOOT option
- add comment from Roman:
do not enable this option per default
add Kconfig comment that enabling this option may introduce a security issue.

 doc/android/fastboot-protocol.rst |  5 +++
 doc/android/fastboot.rst          |  2 +
 drivers/fastboot/Kconfig          |  9 ++++
 drivers/fastboot/fb_command.c     | 68 +++++++++++++++++++++++++++++++
 drivers/usb/gadget/f_fastboot.c   | 17 ++++++++
 include/fastboot.h                |  7 ++++
 6 files changed, 108 insertions(+)
doc/android/fastboot-protocol.rst +5 -0
index e723659e49c..e8cbd7f24ea 100644
@@ -144,6 +144,11 @@ Command Reference
 
   "powerdown"          Power off the device.
 
+  "ucmd"               execute any bootloader command and wait until it
+                       finishs.
+
+  "acmd"               execute any bootloader command, do not wait.
+
 Client Variables
 ----------------
 
doc/android/fastboot.rst +2 -0
index ce513a2a0f2..7611f07038e 100644
@@ -19,6 +19,8 @@ The current implementation supports the following standard commands:
 - ``reboot``
 - ``reboot-bootloader``
 - ``set_active`` (only a stub implementation which always succeeds)
+- ``ucmd`` (if enabled)
+- ``acmd`` (if enabled)
 
 The following OEM commands are supported (if enabled):
 
drivers/fastboot/Kconfig +9 -0
index a17e488714d..2d1836a80e0 100644
@@ -72,6 +72,15 @@ config FASTBOOT_FLASH
 	  the downloaded image to a non-volatile storage device. Define
 	  this to enable the "fastboot flash" command.
 
+config FASTBOOT_UUU_SUPPORT
+	bool "Enable FASTBOOT i.MX UUU special command"
+	default n
+	help
+	  The fastboot protocol includes "UCmd" and "ACmd" command.
+	  Be aware that you provide full access to any U-Boot command,
+	  including working with memory and may open a huge backdoor,
+	  when enabling this option.
+
 choice
 	prompt "Flash provider for FASTBOOT"
 	depends on FASTBOOT_FLASH
drivers/fastboot/fb_command.c +68 -0

86 lines not on this page · raw message

drivers/usb/gadget/f_fastboot.c +17 -0
index 950cc119495..8ba55aab9f8 100644
@@ -494,6 +494,18 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 	do_exit_on_complete(ep, req);
 }
 
+#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
+static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req)
+{
+	/* When usb dequeue complete will be called
+	 *  Need status value before call run_command.
+	 * otherwise, host can't get last message.
+	 */
+	if (req->status == 0)
+		fastboot_acmd_complete();
+}
+#endif
+
 static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 {
 	char *cmdbuf = req->buf;
@@ -532,6 +544,11 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 		case FASTBOOT_COMMAND_REBOOT_RECOVERY:
 			fastboot_func->in_req->complete = compl_do_reset;
 			break;
+#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
+		case FASTBOOT_COMMAND_ACMD:
+			fastboot_func->in_req->complete = do_acmd_complete;
+			break;
+#endif
 		}
 	}
 
include/fastboot.h +7 -0
index 797d7dfd529..57daaf12982 100644
@@ -44,6 +44,10 @@ enum {
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
 	FASTBOOT_COMMAND_OEM_BOOTBUS,
 #endif
+#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
+	FASTBOOT_COMMAND_ACMD,
+	FASTBOOT_COMMAND_UCMD,
+#endif
 
 	FASTBOOT_COMMAND_COUNT
 };
@@ -169,4 +173,7 @@ void fastboot_data_download(const void *fastboot_data,
  */
 void fastboot_data_complete(char *response);
 
+#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
+void fastboot_acmd_complete(void);
+#endif
 #endif /* _FASTBOOT_H_ */
Signature · 1 line
2.29.2