summaryrefslogtreecommitdiff
path: root/drivers/fastboot
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2023-05-08 14:31:04 -0400
committerTom Rini <[email protected]>2023-05-08 14:31:04 -0400
commit11910550b65e6072b9542d462c0aa93f4ca81836 (patch)
tree8308c98ffad76d9693654a28090b03f270a7d250 /drivers/fastboot
parent9876c8c147144db2c120fcc9ffa6de27f6894441 (diff)
parentf1d33a44ca04fdca241c1d89fd79e2e56c930c7e (diff)
Merge branch 'master' into next
Diffstat (limited to 'drivers/fastboot')
-rw-r--r--drivers/fastboot/Kconfig14
-rw-r--r--drivers/fastboot/fb_common.c33
-rw-r--r--drivers/fastboot/fb_mmc.c19
3 files changed, 59 insertions, 7 deletions
diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index eefa34779c4..a3df9aa3d0f 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -4,6 +4,13 @@ config FASTBOOT
bool
imply ANDROID_BOOT_IMAGE
imply CMD_FASTBOOT
+ help
+ Fastboot is a protocol used in Android devices for
+ communicating between the device and a computer during
+ the bootloader stage. It allows the user to flash the
+ device firmware and unlock the bootloader.
+ More information about the protocol and usecases:
+ https://android.googlesource.com/platform/system/core/+/refs/heads/master/fastboot/
config USB_FUNCTION_FASTBOOT
bool "Enable USB fastboot gadget"
@@ -28,6 +35,13 @@ config UDP_FUNCTION_FASTBOOT_PORT
help
The fastboot protocol requires a UDP port number.
+config TCP_FUNCTION_FASTBOOT
+ depends on NET
+ select FASTBOOT
+ bool "Enable fastboot protocol over TCP"
+ help
+ This enables the fastboot protocol over TCP.
+
if FASTBOOT
config FASTBOOT_BUF_ADDR
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 57b6182c46a..621146bc6b0 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -15,7 +15,7 @@
#include <command.h>
#include <env.h>
#include <fastboot.h>
-#include <net/fastboot.h>
+#include <net.h>
/**
* fastboot_buf_addr - base address of the fastboot download buffer
@@ -157,6 +157,37 @@ void fastboot_boot(void)
}
/**
+ * fastboot_handle_boot() - Shared implementation of system reaction to
+ * fastboot commands
+ *
+ * Making desceisions about device boot state (stay in fastboot, reboot
+ * to bootloader, reboot to OS, etc).
+ */
+void fastboot_handle_boot(int command, bool success)
+{
+ if (!success)
+ return;
+
+ switch (command) {
+ case FASTBOOT_COMMAND_BOOT:
+ fastboot_boot();
+ net_set_state(NETLOOP_SUCCESS);
+ break;
+
+ case FASTBOOT_COMMAND_CONTINUE:
+ net_set_state(NETLOOP_SUCCESS);
+ break;
+
+ case FASTBOOT_COMMAND_REBOOT:
+ case FASTBOOT_COMMAND_REBOOT_BOOTLOADER:
+ case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
+ case FASTBOOT_COMMAND_REBOOT_RECOVERY:
+ do_reset(NULL, 0, 0, NULL);
+ break;
+ }
+}
+
+/**
* fastboot_set_progress_callback() - set progress callback
*
* @progress: Pointer to progress callback
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index a06c590234f..9d25c402028 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -287,7 +287,7 @@ static void fb_mmc_boot_ops(struct blk_desc *dev_desc, void *buffer,
*/
static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
struct disk_partition *info,
- struct andr_img_hdr *hdr,
+ struct andr_boot_img_hdr_v0 *hdr,
char *response)
{
ulong sector_size; /* boot partition sector size */
@@ -296,7 +296,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
/* Calculate boot image sectors count */
sector_size = info->blksz;
- hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
+ hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_boot_img_hdr_v0), sector_size);
if (hdr_sectors == 0) {
pr_err("invalid number of boot sectors: 0\n");
fastboot_fail("invalid number of boot sectors: 0", response);
@@ -313,8 +313,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
}
/* Check boot header magic string */
- res = android_image_check_header(hdr);
- if (res != 0) {
+ if (!is_android_boot_image_header(hdr)) {
pr_err("bad boot image magic\n");
fastboot_fail("boot partition not initialized", response);
return 0;
@@ -338,7 +337,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
char *response)
{
uintptr_t hdr_addr; /* boot image header address */
- struct andr_img_hdr *hdr; /* boot image header */
+ struct andr_boot_img_hdr_v0 *hdr; /* boot image header */
lbaint_t hdr_sectors; /* boot image header sectors */
u8 *ramdisk_buffer;
u32 ramdisk_sector_start;
@@ -361,7 +360,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
/* Put boot image header in fastboot buffer after downloaded zImage */
hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
- hdr = (struct andr_img_hdr *)hdr_addr;
+ hdr = (struct andr_boot_img_hdr_v0 *)hdr_addr;
/* Read boot image header */
hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response);
@@ -371,6 +370,14 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
return -1;
}
+ /* Check if boot image header version is 2 or less */
+ if (hdr->header_version > 2) {
+ pr_err("zImage flashing supported only for boot images v2 and less\n");
+ fastboot_fail("zImage flashing supported only for boot images v2 and less",
+ response);
+ return -EOPNOTSUPP;
+ }
+
/* Check if boot image has second stage in it (we don't support it) */
if (hdr->second_size > 0) {
pr_err("moving second stage is not supported yet\n");