forked from ehem/lg-v20-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkdz.h
129 lines (106 loc) · 3.68 KB
/
kdz.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* **********************************************************************
* Copyright (C) 2017-2018 Elliott Mitchell *
* *
* This program is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
*************************************************************************
*$Id$ *
************************************************************************/
#ifndef _KDZ_H_
#define _KDZ_H_
#include <inttypes.h>
#include <unistd.h>
#include <stdbool.h>
#define KDZ_MAGIC_LEN 8
extern const char kdz_file_magic[KDZ_MAGIC_LEN];
#define DZ_MAGIC_LEN 4
extern const char dz_file_magic[DZ_MAGIC_LEN];
extern const char dz_chunk_magic[DZ_MAGIC_LEN];
struct dz_chunk {
char magic[DZ_MAGIC_LEN];
char slice_name[32]; /* name of the slice ("partition") */
char chunk_name[64]; /* name of this chunk */
uint32_t target_size; /* size of target area */
uint32_t data_size; /* amount of compressed data in chunk */
char md5[16]; /* MD5 of uncompressed data */
uint32_t target_addr; /* first block to write */
uint32_t trim_count; /* blocks to TRIM before writing */
uint32_t device; /* flash device Id */
uint32_t crc32; /* CRC32 of uncompressed data */
char pad[372];
};
struct dz_file {
char magic[DZ_MAGIC_LEN];
uint32_t major; /* format major version */
uint32_t minor; /* format minor version */
uint32_t reserved0; /* patch level? */
char device[32]; /* device name */
char version[144]; /* "factoryversion" */
uint32_t chunk_count; /* number of chunks */
char md5[16]; /* MD5 of chunk headers */
uint32_t flag_mmc; /* 256 == managed flash */
uint32_t reserved1;
uint16_t reserved4;
char unknown1[16];
char unknown2[50]; /* A##-M##-C##-U##-0 ? */
char build_type[20]; /* "user"? */
char unknown3[4];
char android_version[10]; /* Android version */
char old_date_code[10]; /* anti-rollback? */
uint32_t reserved5;
uint32_t flag_ufs; /* 256 == UFS and multiple LUNs */
uint64_t unknown5;
char pad[164];
};
struct kdz_chunk {
/* filename */
char name[256];
/* length of file */
uint64_t len;
/* offset of file */
uint64_t off;
};
struct kdz_file {
char *map;
off64_t len;
off64_t off; /* offset of DZ header */
/* uint32_t max_target; ** maximum chunk data payload size */
uint8_t max_device; /* maximum device number */
struct dz_file dz_file;
struct {
uint32_t blksz;
char *map;
off64_t len;
} *devs;
struct {
off64_t zoff; /* offset of Z-stream */
struct dz_chunk dz;
} *chunks;
};
/* verbosity level */
extern int verbose;
/* open a file and load KDZ structure */
extern struct kdz_file *open_kdzfile(const char *filename);
/* close file and deallocate KDZ structure */
extern void close_kdzfile(struct kdz_file *kdz);
/* test for "safe" application */
extern int test_kdzfile(struct kdz_file *kdz);
/* test and report state of device/KDZ */
extern int report_kdzfile(struct kdz_file *kdz);
/* restore GPTs from KDZ file, unless simulate */
extern bool fix_gpts(const struct kdz_file *kdz, const bool simulate);
/* (re)write the named flash slice, unless simulate */
extern int write_kdzfile(const struct kdz_file *kdz, const char *slice_name,
bool simulate);
#endif