blob: b8b4c3522c8608982e5c503e8d8a2e5d0dfa69fe [file] [log] [blame]
Channagoud Kadabif8aa7632015-11-12 14:27:01 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
jianzhou894cb182019-09-16 16:54:51 +08005 * Copyright (c) 2015-2018, 2020, The Linux Foundation. All rights reserved.
Channagoud Kadabif8aa7632015-11-12 14:27:01 -08006 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 * * Neither the name of The Linux Foundation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*/
32
33#ifndef __FASTBOOT_CMDS_H__
34#define __FASTBOOT_CMDS_H__
35
36#include <Library/BaseLib.h>
37#include <Library/DebugLib.h>
Channagoud Kadabif8aa7632015-11-12 14:27:01 -080038#include <Library/LinuxLoaderLib.h>
Jeevan Shriram17f173d2017-10-24 22:11:07 -070039#include <Library/MemoryAllocationLib.h>
Vijay Kumar Pendotic3e0a4f2016-08-27 03:31:40 +053040#include <Library/PartitionTableUpdate.h>
jianzhou894cb182019-09-16 16:54:51 +080041#include <Protocol/EFIKernelInterface.h>
Channagoud Kadabif8aa7632015-11-12 14:27:01 -080042
Jeevan Shriram17f173d2017-10-24 22:11:07 -070043#define ENDPOINT_IN 0x01
44#define ENDPOINT_OUT 0x81
Channagoud Kadabif8aa7632015-11-12 14:27:01 -080045
lijuangcf689542018-06-05 10:25:29 +080046#define MAX_WRITE_SIZE (1024 * 1024)
Jeevan Shriram17f173d2017-10-24 22:11:07 -070047#define MAX_RSP_SIZE 64
48#define ERASE_BUFF_SIZE 256 * 1024
49#define ERASE_BUFF_BLOCKS 256 * 2
50#define USB_BUFFER_SIZE 1024 * 1024 * 16
51#define VERSION_STR_LEN 96
52#define FASTBOOT_STRING_MAX_LENGTH 256
Channagoud Kadabif8aa7632015-11-12 14:27:01 -080053#define FASTBOOT_COMMAND_MAX_LENGTH 64
Jeevan Shriram17f173d2017-10-24 22:11:07 -070054#define MAX_GET_VAR_NAME_SIZE 32
55#define SIGACTUAL 4096
Vijay Kumar Pendotic3e0a4f2016-08-27 03:31:40 +053056#define SLOT_SUFFIX_ARRAY_SIZE 10
57#define SLOT_ATTR_SIZE 32
58#define ATTR_RESP_SIZE 4
Vijay Kumar Pendoti39a1fc52016-10-05 17:36:14 +053059#define MAX_FASTBOOT_COMMAND_SIZE 64
Jeevan Shriram17f173d2017-10-24 22:11:07 -070060#define RECOVERY_WIPE_DATA \
61 "recovery\n--wipe_data\n--reason=MasterClearConfirm\n--locale=en_US\n"
Channagoud Kadabif8aa7632015-11-12 14:27:01 -080062
Mayank Grovera2d6d012018-04-25 12:37:39 +053063/* Fs detection macros and definitions */
64#define RAW_FS_STR "raw"
Mayank Groverc904eba2018-05-02 17:39:23 +053065#define EXT_FS_STR "ext4"
66#define F2FS_FS_STR "f2fs"
67#define FS_SUPERBLOCK_OFFSET 0x400
68#define EXT_MAGIC_OFFSET_SB 0x38
69#define EXT_FS_MAGIC 0xEF53
70#define F2FS_MAGIC_OFFSET_SB 0x0
71#define F2FS_FS_MAGIC 0xF2F52010
72
Mayank Grovere7c93072018-11-27 16:05:54 +053073/* Divide allocatable free Memory to 3/4th */
74#define EFI_FREE_MEM_DIVISOR(BYTES) (((BYTES) * 3) / 4)
75/* 64MB */
76#define MIN_BUFFER_SIZE (67108864)
77/* 1.5GB */
78#define MAX_BUFFER_SIZE (1610612736)
79
Mayank Groverc904eba2018-05-02 17:39:23 +053080typedef enum FsSignature {
81 EXT_FS_SIGNATURE = 1,
82 F2FS_FS_SIGNATURE,
83 UNKNOWN_FS_SIGNATURE
84} FS_SIGNATURE;
Mayank Grovera2d6d012018-04-25 12:37:39 +053085
Channagoud Kadabif8aa7632015-11-12 14:27:01 -080086typedef void (*fastboot_cmd_fn) (const char *, void *, unsigned);
87
88/* Fastboot Command descriptor */
89struct FastbootCmdDesc {
Jeevan Shriram17f173d2017-10-24 22:11:07 -070090 CHAR8 *name;
91 fastboot_cmd_fn cb;
Channagoud Kadabif8aa7632015-11-12 14:27:01 -080092};
93
94/* Fastboot Variable list */
Jeevan Shriram17f173d2017-10-24 22:11:07 -070095typedef struct _FASTBOOT_VAR {
Channagoud Kadabif8aa7632015-11-12 14:27:01 -080096 struct _FASTBOOT_VAR *next;
97 CONST CHAR8 *name;
98 CONST CHAR8 *value;
99} FASTBOOT_VAR;
100
101/* Partition info fastboot variable */
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700102struct GetVarPartitionInfo {
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800103 const CHAR8 part_name[MAX_GET_VAR_NAME_SIZE];
104 CHAR8 getvar_size_str[MAX_GET_VAR_NAME_SIZE];
105 CHAR8 getvar_type_str[MAX_GET_VAR_NAME_SIZE];
106 CHAR8 size_response[MAX_RSP_SIZE];
107 CHAR8 type_response[MAX_RSP_SIZE];
108};
109
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800110/* Fastboot State */
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700111typedef enum {
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800112 ExpectCmdState,
113 ExpectDataState,
114 FastbootStateMax
115} ANDROID_FASTBOOT_STATE;
116
117/* Data structure to store the command list */
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700118typedef struct _FASTBOOT_CMD {
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800119 struct _FASTBOOT_CMD *next;
120 CONST CHAR8 *prefix;
121 UINT32 prefix_len;
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700122 VOID (*handle) (CONST CHAR8 *arg, VOID *data, UINT32 sz);
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800123} FASTBOOT_CMD;
124
125/* Returns the number of bytes left in the
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700126 * download. You must be expecting a download to
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800127 * call this function
128 */
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700129UINTN GetXfrSize (VOID);
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800130
131/* Registers commands and publishes Variables */
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700132EFI_STATUS
133FastbootEnvSetup (VOID *xfer_buffer, UINT32 max);
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800134
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700135/* register a command handler
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800136 * - command handlers will be called if their prefix matches
137 * - they are expected to call fastboot_okay() or fastboot_fail()
138 * to indicate success/failure before returning
139 */
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700140VOID
141FastbootRegister (CONST CHAR8 *prefix,
142 VOID (*handle) (CONST CHAR8 *arg, VOID *data, UINT32 size));
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800143
144/* Only callable from within a command handler
145 * One of thse functions must be called to be a valid command
146 */
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700147VOID
148FastbootOkay (CONST CHAR8 *result);
149VOID
150FastbootFail (CONST CHAR8 *reason);
151VOID
152FastbootInfo (CONST CHAR8 *Info);
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800153
154/* Initializes the Fastboot App */
155EFI_STATUS
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700156FastbootCmdsInit (VOID);
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800157
158/* Uninitializes the Fastboot App */
159EFI_STATUS
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700160FastbootCmdsUnInit (VOID);
161
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800162/* Called when a message/download data passed to the app */
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700163VOID
164DataReady (IN UINT64 Size, IN VOID *Data);
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800165
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700166BOOLEAN FastbootFatal (VOID);
167VOID PartitionDump (VOID);
Channagoud Kadabib854cc42016-02-24 17:55:09 -0800168
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700169VOID *FastbootDloadBuffer (VOID);
Channagoud Kadabib854cc42016-02-24 17:55:09 -0800170
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700171ANDROID_FASTBOOT_STATE FastbootCurrentState (VOID);
Channagoud Kadabib854cc42016-02-24 17:55:09 -0800172
Jeevan Shriram17f173d2017-10-24 22:11:07 -0700173EFI_STATUS
174UpdateDevInfo (CHAR16 *Pname, CHAR8 *ImgVersion);
175VOID
176GetDevInfo (DeviceInfo **DevinfoPtr);
jianzhou894cb182019-09-16 16:54:51 +0800177BOOLEAN IsFlashSplitNeeded (VOID);
178BOOLEAN FlashComplete (VOID);
179BOOLEAN IsDisableParallelDownloadFlash (VOID);
180BOOLEAN IsUseMThreadParallel (VOID);
181VOID ThreadSleep (TimeDuration Delay);
Channagoud Kadabif8aa7632015-11-12 14:27:01 -0800182#endif