1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2008 - 2009
4 * Windriver, <www.windriver.com>
9 * Copyright 2014 Linaro, Ltd.
16 #include <net/fastboot.h>
19 * fastboot_buf_addr - base address of the fastboot download buffer
21 void *fastboot_buf_addr;
24 * fastboot_buf_size - size of the fastboot download buffer
26 u32 fastboot_buf_size;
29 * fastboot_progress_callback - callback executed during long operations
31 void (*fastboot_progress_callback)(const char *msg);
34 * fastboot_response() - Writes a response of the form "$tag$reason".
36 * @tag: The first part of the response
37 * @response: Pointer to fastboot response buffer
38 * @format: printf style format string
40 void fastboot_response(const char *tag, char *response,
41 const char *format, ...)
45 strlcpy(response, tag, FASTBOOT_RESPONSE_LEN);
47 va_start(args, format);
48 vsnprintf(response + strlen(response),
49 FASTBOOT_RESPONSE_LEN - strlen(response) - 1,
56 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
58 * @reason: Pointer to returned reason string
59 * @response: Pointer to fastboot response buffer
61 void fastboot_fail(const char *reason, char *response)
63 fastboot_response("FAIL", response, "%s", reason);
67 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
69 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
70 * @response: Pointer to fastboot response buffer
72 void fastboot_okay(const char *reason, char *response)
75 fastboot_response("OKAY", response, "%s", reason);
77 fastboot_response("OKAY", response, NULL);
81 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
83 * Set flag which indicates that we should reboot into the bootloader
84 * following the reboot that fastboot executes after this function.
86 * This function should be overridden in your board file with one
87 * which sets whatever flag your board specific Android bootloader flow
88 * requires in order to re-enter the bootloader.
90 int __weak fastboot_set_reboot_flag(void)
96 * fastboot_get_progress_callback() - Return progress callback
98 * Return: Pointer to function called during long operations
100 void (*fastboot_get_progress_callback(void))(const char *)
102 return fastboot_progress_callback;
106 * fastboot_boot() - Execute fastboot boot command
108 * If ${fastboot_bootcmd} is set, run that command to execute the boot
109 * process, if that returns, then exit the fastboot server and return
110 * control to the caller.
112 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
115 void fastboot_boot(void)
119 s = env_get("fastboot_bootcmd");
121 run_command(s, CMD_FLAG_ENV);
123 static char boot_addr_start[20];
124 static char *const bootm_args[] = {
125 "bootm", boot_addr_start, NULL
128 snprintf(boot_addr_start, sizeof(boot_addr_start) - 1,
129 "0x%p", fastboot_buf_addr);
130 printf("Booting kernel at %s...\n\n\n", boot_addr_start);
132 do_bootm(NULL, 0, 2, bootm_args);
135 * This only happens if image is somehow faulty so we start
136 * over. We deliberately leave this policy to the invocation
137 * of fastbootcmd if that's what's being run
139 do_reset(NULL, 0, 0, NULL);
144 * fastboot_set_progress_callback() - set progress callback
146 * @progress: Pointer to progress callback
148 * Set a callback which is invoked periodically during long running operations
149 * (flash and erase). This can be used (for example) by the UDP transport to
150 * send INFO responses to keep the client alive whilst those commands are
153 void fastboot_set_progress_callback(void (*progress)(const char *msg))
155 fastboot_progress_callback = progress;
159 * fastboot_init() - initialise new fastboot protocol session
161 * @buf_addr: Pointer to download buffer, or NULL for default
162 * @buf_size: Size of download buffer, or zero for default
164 void fastboot_init(void *buf_addr, u32 buf_size)
166 fastboot_buf_addr = buf_addr ? buf_addr :
167 (void *)CONFIG_FASTBOOT_BUF_ADDR;
168 fastboot_buf_size = buf_size ? buf_size : CONFIG_FASTBOOT_BUF_SIZE;
169 fastboot_set_progress_callback(NULL);