hc
2023-12-06 d38611ca164021d018c1b23eee65bbebc09c63e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*************************************************************************
   > File Name: rkboot_control.h
   > Author: jkand.huang
   > Mail: jkand.huang@rock-chips.com
   > Created Time: Wed 09 Jan 2019 02:57:43 PM CST
 ************************************************************************/
 
#ifndef _RKBOOT_CONTROL_H
#define _RKBOOT_CONTROL_H
 
#define AB_SLOT_NUM  2
 
/* Magic for the A/B struct when serialized. */
#define AVB_AB_MAGIC "\0AB0"
#define AVB_AB_MAGIC_LEN 4
 
/* Versioning for the on-disk A/B metadata - keep in sync with avbtool. */
#define AVB_AB_MAJOR_VERSION 1
#define AVB_AB_MINOR_VERSION 0
 
/* Size of AvbABData struct. */
#define AVB_AB_DATA_SIZE 32
 
/* Maximum values for slot data */
#define AVB_AB_MAX_PRIORITY 15
#define AVB_AB_MAX_TRIES_REMAINING 7
 
#define MISC_OFFSET 2048
#define MISC_OFFSET_CMDLINE 4096
#define MISC_PARTITION_NMAE "/dev/block/by-name/misc"
 
#define CMDLINE_LENGTH 2048
 
#define CMD_WIPE_USERDATA "cmd_wipe_userdata"
 
/*
struct rk_ab {
    unsigned char magic[AB_MAGIC_LEN];
    unsigned int version;
    int last_boot;
    int use_a;
    int use_b;
    int current_boot;
    unsigned char reserved[12];
    unsigned int crc32;
};
*/
 
typedef struct AvbABSlotData {
    /* Slot priority. Valid values range from 0 to AVB_AB_MAX_PRIORITY,
     * both inclusive with 1 being the lowest and AVB_AB_MAX_PRIORITY
     * being the highest. The special value 0 is used to indicate the
     * slot is unbootable.
     */
    unsigned char priority;//0,14,15
 
    /* Number of times left attempting to boot this slot ranging from 0
     * to AVB_AB_MAX_TRIES_REMAINING.
     */
    unsigned char tries_remaining;//7--,成功启动,设为0
 
    /* Non-zero if this slot has booted successfully, 0 otherwise. */
    unsigned char successful_boot;//0,1
 
    /* Reserved for future use. */
    unsigned char reserved[1];
}AvbABSlotData;
 
/* Struct used for recording A/B metadata.
 *
 * When serialized, data is stored in network byte-order.
 */
typedef struct AvbABData {
    /* Magic number used for identification - see AVB_AB_MAGIC. */
    unsigned char magic[AVB_AB_MAGIC_LEN];
 
    /* Version of on-disk struct - see AVB_AB_{MAJOR,MINOR}_VERSION. */
    unsigned char version_major; //AVB_AB_MAJOR_VERSION
    unsigned char version_minor; //AVB_AB_MINOR_VERSION
 
    /* Padding to ensure |slots| field start eight bytes in. */
    unsigned char reserved1[2];
 
    /* Per-slot metadata. */
    AvbABSlotData slots[2];
 
    /* Reserved for future use. */
    unsigned char last_boot;//默认a,上一次成功启动slot的标志位,0-->a,1-->b
    unsigned char reserved2[11];
 
    /* CRC32 of all 28 bytes preceding this field. */
    unsigned int crc32;
}AvbABData;
 
int setSlotActivity();
int setSlotSucceed();
int readMisc(struct AvbABData *info);
void display(struct AvbABData info);
 
bool wipe_userdata(bool auto_reboot);
#endif