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