blob: 88d54a5cb54f0fcdc9fbd2d252d3d77069fcfbb9 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _RECOVERY_BOOTLOADER_H
18#define _RECOVERY_BOOTLOADER_H
19
Yabin Cui6faf0262016-06-09 14:09:39 -070020#include <stddef.h>
21
22// Spaces used by misc partition are as below:
23// 0 - 2K Bootloader Message
24// 2K - 16K Used by Vendor's bootloader
25// 16K - 64K Used by uncrypt and recovery to store wipe_package for A/B devices
26// Note that these offsets are admitted by bootloader,recovery and uncrypt, so they
27// are not configurable without changing all of them.
28static const size_t BOOTLOADER_MESSAGE_OFFSET_IN_MISC = 0;
29static const size_t WIPE_PACKAGE_OFFSET_IN_MISC = 16 * 1024;
30
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080031/* Bootloader Message
32 *
33 * This structure describes the content of a block in flash
34 * that is used for recovery and the bootloader to talk to
35 * each other.
36 *
37 * The command field is updated by linux when it wants to
38 * reboot into recovery or to update radio or bootloader firmware.
39 * It is also updated by the bootloader when firmware update
40 * is complete (to boot into recovery for any final cleanup)
41 *
42 * The status field is written by the bootloader after the
43 * completion of an "update-radio" or "update-hboot" command.
44 *
45 * The recovery field is only written by linux and used
46 * for the system to send a message to recovery or the
47 * other way around.
Doug Zongkerc87bab12013-11-25 13:53:25 -080048 *
49 * The stage field is written by packages which restart themselves
50 * multiple times, so that the UI can reflect which invocation of the
51 * package it is. If the value is of the format "#/#" (eg, "1/3"),
52 * the UI will add a simple indicator of that status.
David Zeuthend85ae792015-09-02 15:49:58 -040053 *
54 * The slot_suffix field is used for A/B implementations where the
55 * bootloader does not set the androidboot.ro.boot.slot_suffix kernel
56 * commandline parameter. This is used by fs_mgr to mount /system and
57 * other partitions with the slotselect flag set in fstab. A/B
58 * implementations are free to use all 32 bytes and may store private
59 * data past the first NUL-byte in this field.
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080060 */
61struct bootloader_message {
62 char command[32];
63 char status[32];
Doug Zongkerc87bab12013-11-25 13:53:25 -080064 char recovery[768];
65
66 // The 'recovery' field used to be 1024 bytes. It has only ever
67 // been used to store the recovery command line, so 768 bytes
68 // should be plenty. We carve off the last 256 bytes to store the
69 // stage string (for multistage packages) and possible future
70 // expansion.
71 char stage[32];
David Zeuthend85ae792015-09-02 15:49:58 -040072 char slot_suffix[32];
73 char reserved[192];
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080074};
75
76/* Read and write the bootloader command from the "misc" partition.
77 * These return zero on success.
78 */
79int get_bootloader_message(struct bootloader_message *out);
80int set_bootloader_message(const struct bootloader_message *in);
81
Yabin Cui6faf0262016-06-09 14:09:39 -070082#ifdef __cplusplus
83
84#include <string>
85
86bool read_wipe_package(size_t size, std::string* out);
87#endif
88
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080089#endif