blob: 9a3d5ba693b936964df93195982e965fbd6e9e78 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Maxime Ripard00e8eb72015-10-15 14:34:13 +02002/*
3 * (C) Copyright 2008 - 2009
4 * Windriver, <www.windriver.com>
5 * Tom Rix <Tom.Rix@windriver.com>
6 *
7 * Copyright 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 *
9 * Copyright 2014 Linaro, Ltd.
10 * Rob Herring <robh@kernel.org>
Maxime Ripard00e8eb72015-10-15 14:34:13 +020011 */
12#ifndef _FASTBOOT_H_
13#define _FASTBOOT_H_
14
Alex Kiernan1df98902018-05-29 15:30:47 +000015#define FASTBOOT_VERSION "0.4"
16
Maxime Ripard00e8eb72015-10-15 14:34:13 +020017/* The 64 defined bytes plus \0 */
Alex Kiernand5aa57c2018-05-29 15:30:53 +000018#define FASTBOOT_COMMAND_LEN (64 + 1)
Maxime Ripard00e8eb72015-10-15 14:34:13 +020019#define FASTBOOT_RESPONSE_LEN (64 + 1)
20
Alex Kiernaned6a41442018-05-29 15:30:41 +000021/**
Alex Kiernand5aa57c2018-05-29 15:30:53 +000022 * All known commands to fastboot
23 */
24enum {
25 FASTBOOT_COMMAND_GETVAR = 0,
26 FASTBOOT_COMMAND_DOWNLOAD,
27#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
28 FASTBOOT_COMMAND_FLASH,
29 FASTBOOT_COMMAND_ERASE,
30#endif
31 FASTBOOT_COMMAND_BOOT,
32 FASTBOOT_COMMAND_CONTINUE,
33 FASTBOOT_COMMAND_REBOOT,
34 FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
35 FASTBOOT_COMMAND_SET_ACTIVE,
36
37 FASTBOOT_COMMAND_COUNT
38};
39
40/**
Alex Kiernaned6a41442018-05-29 15:30:41 +000041 * fastboot_response() - Writes a response of the form "$tag$reason".
42 *
43 * @tag: The first part of the response
44 * @response: Pointer to fastboot response buffer
45 * @format: printf style format string
46 */
47void fastboot_response(const char *tag, char *response,
48 const char *format, ...)
49 __attribute__ ((format (__printf__, 3, 4)));
50
51/**
52 * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
53 *
54 * @reason: Pointer to returned reason string
55 * @response: Pointer to fastboot response buffer
56 */
Alex Kiernan27b69de2018-05-29 15:30:40 +000057void fastboot_fail(const char *reason, char *response);
Alex Kiernaned6a41442018-05-29 15:30:41 +000058
59/**
60 * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
61 *
62 * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
63 * @response: Pointer to fastboot response buffer
64 */
Alex Kiernan27b69de2018-05-29 15:30:40 +000065void fastboot_okay(const char *reason, char *response);
Alex Kiernand5aa57c2018-05-29 15:30:53 +000066
67/**
68 * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
69 *
70 * Set flag which indicates that we should reboot into the bootloader
71 * following the reboot that fastboot executes after this function.
72 *
73 * This function should be overridden in your board file with one
74 * which sets whatever flag your board specific Android bootloader flow
75 * requires in order to re-enter the bootloader.
76 */
Alex Kiernan5512c432018-05-29 15:30:46 +000077int fastboot_set_reboot_flag(void);
Alex Kiernand5aa57c2018-05-29 15:30:53 +000078
79/**
80 * fastboot_set_progress_callback() - set progress callback
81 *
82 * @progress: Pointer to progress callback
83 *
84 * Set a callback which is invoked periodically during long running operations
85 * (flash and erase). This can be used (for example) by the UDP transport to
86 * send INFO responses to keep the client alive whilst those commands are
87 * executing.
88 */
89void fastboot_set_progress_callback(void (*progress)(const char *msg));
90
91/*
92 * fastboot_init() - initialise new fastboot protocol session
93 *
94 * @buf_addr: Pointer to download buffer, or NULL for default
95 * @buf_size: Size of download buffer, or zero for default
96 */
97void fastboot_init(void *buf_addr, u32 buf_size);
98
99/**
100 * fastboot_boot() - Execute fastboot boot command
101 *
102 * If ${fastboot_bootcmd} is set, run that command to execute the boot
103 * process, if that returns, then exit the fastboot server and return
104 * control to the caller.
105 *
106 * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
107 * the board.
108 */
109void fastboot_boot(void);
110
111/**
112 * fastboot_handle_command() - Handle fastboot command
113 *
114 * @cmd_string: Pointer to command string
115 * @response: Pointer to fastboot response buffer
116 *
117 * Return: Executed command, or -1 if not recognized
118 */
119int fastboot_handle_command(char *cmd_string, char *response);
120
121/**
122 * fastboot_data_remaining() - return bytes remaining in current transfer
123 *
124 * Return: Number of bytes left in the current download
125 */
126u32 fastboot_data_remaining(void);
127
128/**
129 * fastboot_data_download() - Copy image data to fastboot_buf_addr.
130 *
131 * @fastboot_data: Pointer to received fastboot data
132 * @fastboot_data_len: Length of received fastboot data
133 * @response: Pointer to fastboot response buffer
134 *
135 * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
136 * response. fastboot_bytes_received is updated to indicate the number
137 * of bytes that have been transferred.
138 */
139void fastboot_data_download(const void *fastboot_data,
140 unsigned int fastboot_data_len, char *response);
141
142/**
143 * fastboot_data_complete() - Mark current transfer complete
144 *
145 * @response: Pointer to fastboot response buffer
146 *
147 * Set image_size and ${filesize} to the total size of the downloaded image.
148 */
149void fastboot_data_complete(char *response);
150
Maxime Ripard00e8eb72015-10-15 14:34:13 +0200151#endif /* _FASTBOOT_H_ */