fastboot.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  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>
  11. */
  12. #ifndef _FASTBOOT_H_
  13. #define _FASTBOOT_H_
  14. #define FASTBOOT_VERSION "0.4"
  15. /* The 64 defined bytes plus \0 */
  16. #define FASTBOOT_COMMAND_LEN (64 + 1)
  17. #define FASTBOOT_RESPONSE_LEN (64 + 1)
  18. /**
  19. * All known commands to fastboot
  20. */
  21. enum {
  22. FASTBOOT_COMMAND_GETVAR = 0,
  23. FASTBOOT_COMMAND_DOWNLOAD,
  24. #if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
  25. FASTBOOT_COMMAND_FLASH,
  26. FASTBOOT_COMMAND_ERASE,
  27. #endif
  28. FASTBOOT_COMMAND_BOOT,
  29. FASTBOOT_COMMAND_CONTINUE,
  30. FASTBOOT_COMMAND_REBOOT,
  31. FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
  32. FASTBOOT_COMMAND_REBOOT_FASTBOOTD,
  33. FASTBOOT_COMMAND_REBOOT_RECOVERY,
  34. FASTBOOT_COMMAND_SET_ACTIVE,
  35. #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
  36. FASTBOOT_COMMAND_OEM_FORMAT,
  37. #endif
  38. #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_PARTCONF)
  39. FASTBOOT_COMMAND_OEM_PARTCONF,
  40. #endif
  41. #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
  42. FASTBOOT_COMMAND_OEM_BOOTBUS,
  43. #endif
  44. #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
  45. FASTBOOT_COMMAND_ACMD,
  46. FASTBOOT_COMMAND_UCMD,
  47. #endif
  48. FASTBOOT_COMMAND_OEM_COMMAND,
  49. FASTBOOT_COMMAND_COUNT
  50. };
  51. /**
  52. * Reboot reasons
  53. */
  54. enum fastboot_reboot_reason {
  55. FASTBOOT_REBOOT_REASON_BOOTLOADER,
  56. FASTBOOT_REBOOT_REASON_FASTBOOTD,
  57. FASTBOOT_REBOOT_REASON_RECOVERY,
  58. FASTBOOT_REBOOT_REASONS_COUNT
  59. };
  60. /**
  61. * fastboot_response() - Writes a response of the form "$tag$reason".
  62. *
  63. * @tag: The first part of the response
  64. * @response: Pointer to fastboot response buffer
  65. * @format: printf style format string
  66. */
  67. void fastboot_response(const char *tag, char *response,
  68. const char *format, ...)
  69. __attribute__ ((format (__printf__, 3, 4)));
  70. /**
  71. * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
  72. *
  73. * @reason: Pointer to returned reason string
  74. * @response: Pointer to fastboot response buffer
  75. */
  76. void fastboot_fail(const char *reason, char *response);
  77. /**
  78. * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
  79. *
  80. * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
  81. * @response: Pointer to fastboot response buffer
  82. */
  83. void fastboot_okay(const char *reason, char *response);
  84. /**
  85. * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
  86. *
  87. * Set flag which indicates that we should reboot into the bootloader
  88. * following the reboot that fastboot executes after this function.
  89. *
  90. * This function should be overridden in your board file with one
  91. * which sets whatever flag your board specific Android bootloader flow
  92. * requires in order to re-enter the bootloader.
  93. */
  94. //int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason);
  95. int fastboot_set_reboot_flag(void);
  96. /**
  97. * fastboot_set_progress_callback() - set progress callback
  98. *
  99. * @progress: Pointer to progress callback
  100. *
  101. * Set a callback which is invoked periodically during long running operations
  102. * (flash and erase). This can be used (for example) by the UDP transport to
  103. * send INFO responses to keep the client alive whilst those commands are
  104. * executing.
  105. */
  106. void fastboot_set_progress_callback(void (*progress)(const char *msg));
  107. /*
  108. * fastboot_init() - initialise new fastboot protocol session
  109. *
  110. * @buf_addr: Pointer to download buffer, or NULL for default
  111. * @buf_size: Size of download buffer, or zero for default
  112. */
  113. void fastboot_init(void *buf_addr, u32 buf_size);
  114. /**
  115. * fastboot_boot() - Execute fastboot boot command
  116. *
  117. * If ${fastboot_bootcmd} is set, run that command to execute the boot
  118. * process, if that returns, then exit the fastboot server and return
  119. * control to the caller.
  120. *
  121. * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
  122. * the board.
  123. */
  124. void fastboot_boot(void);
  125. /**
  126. * fastboot_handle_command() - Handle fastboot command
  127. *
  128. * @cmd_string: Pointer to command string
  129. * @response: Pointer to fastboot response buffer
  130. *
  131. * Return: Executed command, or -1 if not recognized
  132. */
  133. int fastboot_handle_command(char *cmd_string, char *response);
  134. /**
  135. * fastboot_data_remaining() - return bytes remaining in current transfer
  136. *
  137. * Return: Number of bytes left in the current download
  138. */
  139. u32 fastboot_data_remaining(void);
  140. /**
  141. * fastboot_data_download() - Copy image data to fastboot_buf_addr.
  142. *
  143. * @fastboot_data: Pointer to received fastboot data
  144. * @fastboot_data_len: Length of received fastboot data
  145. * @response: Pointer to fastboot response buffer
  146. *
  147. * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
  148. * response. fastboot_bytes_received is updated to indicate the number
  149. * of bytes that have been transferred.
  150. */
  151. void fastboot_data_download(const void *fastboot_data,
  152. unsigned int fastboot_data_len, char *response);
  153. /**
  154. * fastboot_data_complete() - Mark current transfer complete
  155. *
  156. * @response: Pointer to fastboot response buffer
  157. *
  158. * Set image_size and ${filesize} to the total size of the downloaded image.
  159. */
  160. void fastboot_data_complete(char *response);
  161. #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
  162. void fastboot_acmd_complete(void);
  163. #endif
  164. #endif /* _FASTBOOT_H_ */