Commit a49a064fbac5c2508eda795c539de0087e8010fa
Committed by
Ye Li
1 parent
e5df956bb2
Exists in
smarc_8mm-imx_v2019.04_4.19.35_1.1.0
and in
1 other branch
MLK-22711-2: fastboot: emmc: update bootloader to offset 0 for RevC QXP chip
ROM update emmc offset to 0. previous B0 is 32K. Signed-off-by: Frank Li <Frank.Li@nxp.com> (cherry picked from commit b642241380227b97f0fa434e3d38dc746adbd9e0) (cherry picked from commit 2065bf0a12180f73eb918d09dbe809c10077b033)
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
drivers/fastboot/fb_fsl/fb_fsl_partitions.c
1 | // SPDX-License-Identifier: GPL-2.0+ | 1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | 2 | /* |
3 | * Copyright 2019 NXP | 3 | * Copyright 2019 NXP |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <asm/mach-imx/sys_proto.h> | 6 | #include <asm/mach-imx/sys_proto.h> |
7 | #include <fb_fsl.h> | 7 | #include <fb_fsl.h> |
8 | #include <fastboot.h> | 8 | #include <fastboot.h> |
9 | #include <mmc.h> | 9 | #include <mmc.h> |
10 | #include <android_image.h> | 10 | #include <android_image.h> |
11 | #include <asm/bootm.h> | 11 | #include <asm/bootm.h> |
12 | #include <nand.h> | 12 | #include <nand.h> |
13 | #include <part.h> | 13 | #include <part.h> |
14 | #include <sparse_format.h> | 14 | #include <sparse_format.h> |
15 | #include <image-sparse.h> | 15 | #include <image-sparse.h> |
16 | #include <image.h> | 16 | #include <image.h> |
17 | #include <asm/mach-imx/boot_mode.h> | 17 | #include <asm/mach-imx/boot_mode.h> |
18 | #include <asm/arch/sys_proto.h> | 18 | #include <asm/arch/sys_proto.h> |
19 | #include <asm/setup.h> | 19 | #include <asm/setup.h> |
20 | #include <environment.h> | 20 | #include <environment.h> |
21 | #ifdef CONFIG_DM_SCSI | 21 | #ifdef CONFIG_DM_SCSI |
22 | #include <scsi.h> | 22 | #include <scsi.h> |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #if defined(CONFIG_FASTBOOT_LOCK) | 25 | #if defined(CONFIG_FASTBOOT_LOCK) |
26 | #include "fastboot_lock_unlock.h" | 26 | #include "fastboot_lock_unlock.h" |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #ifdef CONFIG_IMX_TRUSTY_OS | 29 | #ifdef CONFIG_IMX_TRUSTY_OS |
30 | #include "u-boot/sha256.h" | 30 | #include "u-boot/sha256.h" |
31 | #include <trusty/libtipc.h> | 31 | #include <trusty/libtipc.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | 34 | ||
35 | #ifndef TRUSTY_OS_MMC_BLKS | 35 | #ifndef TRUSTY_OS_MMC_BLKS |
36 | #define TRUSTY_OS_MMC_BLKS 0x7FF | 36 | #define TRUSTY_OS_MMC_BLKS 0x7FF |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #define MEK_8QM_EMMC 0 | 39 | #define MEK_8QM_EMMC 0 |
40 | 40 | ||
41 | enum { | 41 | enum { |
42 | PTN_GPT_INDEX = 0, | 42 | PTN_GPT_INDEX = 0, |
43 | PTN_TEE_INDEX, | 43 | PTN_TEE_INDEX, |
44 | #ifdef CONFIG_FLASH_MCUFIRMWARE_SUPPORT | 44 | #ifdef CONFIG_FLASH_MCUFIRMWARE_SUPPORT |
45 | PTN_MCU_OS_INDEX, | 45 | PTN_MCU_OS_INDEX, |
46 | #endif | 46 | #endif |
47 | PTN_ALL_INDEX, | 47 | PTN_ALL_INDEX, |
48 | PTN_BOOTLOADER_INDEX, | 48 | PTN_BOOTLOADER_INDEX, |
49 | }; | 49 | }; |
50 | 50 | ||
51 | struct fastboot_ptentry g_ptable[MAX_PTN]; | 51 | struct fastboot_ptentry g_ptable[MAX_PTN]; |
52 | unsigned int g_pcount; | 52 | unsigned int g_pcount; |
53 | 53 | ||
54 | static ulong bootloader_mmc_offset(void) | 54 | static ulong bootloader_mmc_offset(void) |
55 | { | 55 | { |
56 | if (is_imx8mq() || is_imx8mm() || (is_imx8() && is_soc_rev(CHIP_REV_A))) | 56 | if (is_imx8mq() || is_imx8mm() || (is_imx8() && is_soc_rev(CHIP_REV_A))) |
57 | return 0x8400; | 57 | return 0x8400; |
58 | else if (is_imx8qm()) { | 58 | else if (is_imx8qm() || (is_imx8qxp() && !is_soc_rev(CHIP_REV_B))) { |
59 | if (MEK_8QM_EMMC == fastboot_devinfo.dev_id) | 59 | if (MEK_8QM_EMMC == fastboot_devinfo.dev_id) |
60 | /* target device is eMMC boot0 partition, bootloader offset is 0x0 */ | 60 | /* target device is eMMC boot0 partition, bootloader offset is 0x0 */ |
61 | return 0x0; | 61 | return 0x0; |
62 | else | 62 | else |
63 | /* target device is SD card, bootloader offset is 0x8000 */ | 63 | /* target device is SD card, bootloader offset is 0x8000 */ |
64 | return 0x8000; | 64 | return 0x8000; |
65 | } else if (is_imx8mn()) { | 65 | } else if (is_imx8mn()) { |
66 | /* target device is eMMC boot0 partition, bootloader offset is 0x0 */ | 66 | /* target device is eMMC boot0 partition, bootloader offset is 0x0 */ |
67 | if (env_get_ulong("emmc_dev", 10, 2) == fastboot_devinfo.dev_id) | 67 | if (env_get_ulong("emmc_dev", 10, 2) == fastboot_devinfo.dev_id) |
68 | return 0; | 68 | return 0; |
69 | else | 69 | else |
70 | return 0x8000; | 70 | return 0x8000; |
71 | } | 71 | } |
72 | else if (is_imx8()) | 72 | else if (is_imx8()) |
73 | return 0x8000; | 73 | return 0x8000; |
74 | else | 74 | else |
75 | return 0x400; | 75 | return 0x400; |
76 | } | 76 | } |
77 | 77 | ||
78 | bool bootloader_gpt_overlay(void) | 78 | bool bootloader_gpt_overlay(void) |
79 | { | 79 | { |
80 | return (g_ptable[PTN_GPT_INDEX].partition_id == g_ptable[PTN_BOOTLOADER_INDEX].partition_id && | 80 | return (g_ptable[PTN_GPT_INDEX].partition_id == g_ptable[PTN_BOOTLOADER_INDEX].partition_id && |
81 | bootloader_mmc_offset() < ANDROID_GPT_END); | 81 | bootloader_mmc_offset() < ANDROID_GPT_END); |
82 | } | 82 | } |
83 | 83 | ||
84 | /** | 84 | /** |
85 | @mmc_dos_partition_index: the partition index in mbr. | 85 | @mmc_dos_partition_index: the partition index in mbr. |
86 | @mmc_partition_index: the boot partition or user partition index, | 86 | @mmc_partition_index: the boot partition or user partition index, |
87 | not related to the partition table. | 87 | not related to the partition table. |
88 | */ | 88 | */ |
89 | static int _fastboot_parts_add_ptable_entry(int ptable_index, | 89 | static int _fastboot_parts_add_ptable_entry(int ptable_index, |
90 | int mmc_dos_partition_index, | 90 | int mmc_dos_partition_index, |
91 | int mmc_partition_index, | 91 | int mmc_partition_index, |
92 | const char *name, | 92 | const char *name, |
93 | const char *fstype, | 93 | const char *fstype, |
94 | struct blk_desc *dev_desc, | 94 | struct blk_desc *dev_desc, |
95 | struct fastboot_ptentry *ptable) | 95 | struct fastboot_ptentry *ptable) |
96 | { | 96 | { |
97 | disk_partition_t info; | 97 | disk_partition_t info; |
98 | 98 | ||
99 | if (part_get_info(dev_desc, | 99 | if (part_get_info(dev_desc, |
100 | mmc_dos_partition_index, &info)) { | 100 | mmc_dos_partition_index, &info)) { |
101 | debug("Bad partition index:%d for partition:%s\n", | 101 | debug("Bad partition index:%d for partition:%s\n", |
102 | mmc_dos_partition_index, name); | 102 | mmc_dos_partition_index, name); |
103 | return -1; | 103 | return -1; |
104 | } | 104 | } |
105 | ptable[ptable_index].start = info.start; | 105 | ptable[ptable_index].start = info.start; |
106 | ptable[ptable_index].length = info.size; | 106 | ptable[ptable_index].length = info.size; |
107 | ptable[ptable_index].partition_id = mmc_partition_index; | 107 | ptable[ptable_index].partition_id = mmc_partition_index; |
108 | ptable[ptable_index].partition_index = mmc_dos_partition_index; | 108 | ptable[ptable_index].partition_index = mmc_dos_partition_index; |
109 | strncpy(ptable[ptable_index].name, (const char *)info.name, | 109 | strncpy(ptable[ptable_index].name, (const char *)info.name, |
110 | sizeof(ptable[ptable_index].name) - 1); | 110 | sizeof(ptable[ptable_index].name) - 1); |
111 | 111 | ||
112 | #ifdef CONFIG_PARTITION_UUIDS | 112 | #ifdef CONFIG_PARTITION_UUIDS |
113 | strcpy(ptable[ptable_index].uuid, (const char *)info.uuid); | 113 | strcpy(ptable[ptable_index].uuid, (const char *)info.uuid); |
114 | #endif | 114 | #endif |
115 | #ifdef CONFIG_ANDROID_AB_SUPPORT | 115 | #ifdef CONFIG_ANDROID_AB_SUPPORT |
116 | if (!strcmp((const char *)info.name, FASTBOOT_PARTITION_SYSTEM_A) || | 116 | if (!strcmp((const char *)info.name, FASTBOOT_PARTITION_SYSTEM_A) || |
117 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_SYSTEM_B) || | 117 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_SYSTEM_B) || |
118 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_OEM_A) || | 118 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_OEM_A) || |
119 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_VENDOR_A) || | 119 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_VENDOR_A) || |
120 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_OEM_B) || | 120 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_OEM_B) || |
121 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_VENDOR_B) || | 121 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_VENDOR_B) || |
122 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_DATA)) | 122 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_DATA)) |
123 | #else | 123 | #else |
124 | if (!strcmp((const char *)info.name, FASTBOOT_PARTITION_SYSTEM) || | 124 | if (!strcmp((const char *)info.name, FASTBOOT_PARTITION_SYSTEM) || |
125 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_DATA) || | 125 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_DATA) || |
126 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_DEVICE) || | 126 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_DEVICE) || |
127 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_CACHE)) | 127 | !strcmp((const char *)info.name, FASTBOOT_PARTITION_CACHE)) |
128 | #endif | 128 | #endif |
129 | strcpy(ptable[ptable_index].fstype, "ext4"); | 129 | strcpy(ptable[ptable_index].fstype, "ext4"); |
130 | else | 130 | else |
131 | strcpy(ptable[ptable_index].fstype, "raw"); | 131 | strcpy(ptable[ptable_index].fstype, "raw"); |
132 | return 0; | 132 | return 0; |
133 | } | 133 | } |
134 | 134 | ||
135 | static int _fastboot_parts_load_from_ptable(void) | 135 | static int _fastboot_parts_load_from_ptable(void) |
136 | { | 136 | { |
137 | int i; | 137 | int i; |
138 | 138 | ||
139 | /* mmc boot partition: -1 means no partition, 0 user part., 1 boot part. | 139 | /* mmc boot partition: -1 means no partition, 0 user part., 1 boot part. |
140 | * default is no partition, for emmc default user part, except emmc*/ | 140 | * default is no partition, for emmc default user part, except emmc*/ |
141 | int boot_partition = FASTBOOT_MMC_NONE_PARTITION_ID; | 141 | int boot_partition = FASTBOOT_MMC_NONE_PARTITION_ID; |
142 | int user_partition = FASTBOOT_MMC_NONE_PARTITION_ID; | 142 | int user_partition = FASTBOOT_MMC_NONE_PARTITION_ID; |
143 | 143 | ||
144 | struct mmc *mmc; | 144 | struct mmc *mmc; |
145 | struct blk_desc *dev_desc; | 145 | struct blk_desc *dev_desc; |
146 | struct fastboot_ptentry ptable[MAX_PTN]; | 146 | struct fastboot_ptentry ptable[MAX_PTN]; |
147 | 147 | ||
148 | /* sata case in env */ | 148 | /* sata case in env */ |
149 | if (fastboot_devinfo.type == DEV_SATA) { | 149 | if (fastboot_devinfo.type == DEV_SATA) { |
150 | #ifdef CONFIG_DM_SCSI | 150 | #ifdef CONFIG_DM_SCSI |
151 | int sata_device_no = fastboot_devinfo.dev_id; | 151 | int sata_device_no = fastboot_devinfo.dev_id; |
152 | puts("flash target is SATA\n"); | 152 | puts("flash target is SATA\n"); |
153 | scsi_scan(false); | 153 | scsi_scan(false); |
154 | dev_desc = blk_get_dev("scsi", sata_device_no); | 154 | dev_desc = blk_get_dev("scsi", sata_device_no); |
155 | #else /*! CONFIG_SATA*/ | 155 | #else /*! CONFIG_SATA*/ |
156 | puts("SATA isn't buildin\n"); | 156 | puts("SATA isn't buildin\n"); |
157 | return -1; | 157 | return -1; |
158 | #endif /*! CONFIG_SATA*/ | 158 | #endif /*! CONFIG_SATA*/ |
159 | } else if (fastboot_devinfo.type == DEV_MMC) { | 159 | } else if (fastboot_devinfo.type == DEV_MMC) { |
160 | int mmc_no = fastboot_devinfo.dev_id; | 160 | int mmc_no = fastboot_devinfo.dev_id; |
161 | 161 | ||
162 | printf("flash target is MMC:%d\n", mmc_no); | 162 | printf("flash target is MMC:%d\n", mmc_no); |
163 | mmc = find_mmc_device(mmc_no); | 163 | mmc = find_mmc_device(mmc_no); |
164 | 164 | ||
165 | if (mmc == NULL) { | 165 | if (mmc == NULL) { |
166 | printf("invalid mmc device %d\n", mmc_no); | 166 | printf("invalid mmc device %d\n", mmc_no); |
167 | return -1; | 167 | return -1; |
168 | } | 168 | } |
169 | 169 | ||
170 | /* Force to init mmc */ | 170 | /* Force to init mmc */ |
171 | mmc->has_init = 0; | 171 | mmc->has_init = 0; |
172 | if (mmc_init(mmc)) | 172 | if (mmc_init(mmc)) |
173 | printf("MMC card init failed!\n"); | 173 | printf("MMC card init failed!\n"); |
174 | 174 | ||
175 | dev_desc = blk_get_dev("mmc", mmc_no); | 175 | dev_desc = blk_get_dev("mmc", mmc_no); |
176 | if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { | 176 | if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { |
177 | printf("** Block device MMC %d not supported\n", | 177 | printf("** Block device MMC %d not supported\n", |
178 | mmc_no); | 178 | mmc_no); |
179 | return -1; | 179 | return -1; |
180 | } | 180 | } |
181 | 181 | ||
182 | /* multiple boot paritions for eMMC 4.3 later */ | 182 | /* multiple boot paritions for eMMC 4.3 later */ |
183 | if (mmc->part_config != MMCPART_NOAVAILABLE) { | 183 | if (mmc->part_config != MMCPART_NOAVAILABLE) { |
184 | boot_partition = FASTBOOT_MMC_BOOT_PARTITION_ID; | 184 | boot_partition = FASTBOOT_MMC_BOOT_PARTITION_ID; |
185 | user_partition = FASTBOOT_MMC_USER_PARTITION_ID; | 185 | user_partition = FASTBOOT_MMC_USER_PARTITION_ID; |
186 | } | 186 | } |
187 | } else { | 187 | } else { |
188 | printf("Can't setup partition table on this device %d\n", | 188 | printf("Can't setup partition table on this device %d\n", |
189 | fastboot_devinfo.type); | 189 | fastboot_devinfo.type); |
190 | return -1; | 190 | return -1; |
191 | } | 191 | } |
192 | 192 | ||
193 | memset((char *)ptable, 0, | 193 | memset((char *)ptable, 0, |
194 | sizeof(struct fastboot_ptentry) * (MAX_PTN)); | 194 | sizeof(struct fastboot_ptentry) * (MAX_PTN)); |
195 | /* GPT */ | 195 | /* GPT */ |
196 | strcpy(ptable[PTN_GPT_INDEX].name, FASTBOOT_PARTITION_GPT); | 196 | strcpy(ptable[PTN_GPT_INDEX].name, FASTBOOT_PARTITION_GPT); |
197 | ptable[PTN_GPT_INDEX].start = ANDROID_GPT_OFFSET / dev_desc->blksz; | 197 | ptable[PTN_GPT_INDEX].start = ANDROID_GPT_OFFSET / dev_desc->blksz; |
198 | ptable[PTN_GPT_INDEX].length = ANDROID_GPT_SIZE / dev_desc->blksz; | 198 | ptable[PTN_GPT_INDEX].length = ANDROID_GPT_SIZE / dev_desc->blksz; |
199 | ptable[PTN_GPT_INDEX].partition_id = user_partition; | 199 | ptable[PTN_GPT_INDEX].partition_id = user_partition; |
200 | ptable[PTN_GPT_INDEX].flags = FASTBOOT_PTENTRY_FLAGS_UNERASEABLE; | 200 | ptable[PTN_GPT_INDEX].flags = FASTBOOT_PTENTRY_FLAGS_UNERASEABLE; |
201 | strcpy(ptable[PTN_GPT_INDEX].fstype, "raw"); | 201 | strcpy(ptable[PTN_GPT_INDEX].fstype, "raw"); |
202 | 202 | ||
203 | #ifndef CONFIG_ARM64 | 203 | #ifndef CONFIG_ARM64 |
204 | /* Trusty OS */ | 204 | /* Trusty OS */ |
205 | strcpy(ptable[PTN_TEE_INDEX].name, FASTBOOT_PARTITION_TEE); | 205 | strcpy(ptable[PTN_TEE_INDEX].name, FASTBOOT_PARTITION_TEE); |
206 | ptable[PTN_TEE_INDEX].start = 0; | 206 | ptable[PTN_TEE_INDEX].start = 0; |
207 | ptable[PTN_TEE_INDEX].length = TRUSTY_OS_MMC_BLKS; | 207 | ptable[PTN_TEE_INDEX].length = TRUSTY_OS_MMC_BLKS; |
208 | ptable[PTN_TEE_INDEX].partition_id = TEE_HWPARTITION_ID; | 208 | ptable[PTN_TEE_INDEX].partition_id = TEE_HWPARTITION_ID; |
209 | strcpy(ptable[PTN_TEE_INDEX].fstype, "raw"); | 209 | strcpy(ptable[PTN_TEE_INDEX].fstype, "raw"); |
210 | #endif | 210 | #endif |
211 | 211 | ||
212 | /* Add mcu_os partition if we support mcu firmware image flash */ | 212 | /* Add mcu_os partition if we support mcu firmware image flash */ |
213 | #ifdef CONFIG_FLASH_MCUFIRMWARE_SUPPORT | 213 | #ifdef CONFIG_FLASH_MCUFIRMWARE_SUPPORT |
214 | strcpy(ptable[PTN_MCU_OS_INDEX].name, FASTBOOT_MCU_FIRMWARE_PARTITION); | 214 | strcpy(ptable[PTN_MCU_OS_INDEX].name, FASTBOOT_MCU_FIRMWARE_PARTITION); |
215 | ptable[PTN_MCU_OS_INDEX].start = ANDROID_MCU_FIRMWARE_START / dev_desc->blksz; | 215 | ptable[PTN_MCU_OS_INDEX].start = ANDROID_MCU_FIRMWARE_START / dev_desc->blksz; |
216 | ptable[PTN_MCU_OS_INDEX].length = ANDROID_MCU_FIRMWARE_SIZE / dev_desc->blksz; | 216 | ptable[PTN_MCU_OS_INDEX].length = ANDROID_MCU_FIRMWARE_SIZE / dev_desc->blksz; |
217 | ptable[PTN_MCU_OS_INDEX].flags = FASTBOOT_PTENTRY_FLAGS_UNERASEABLE; | 217 | ptable[PTN_MCU_OS_INDEX].flags = FASTBOOT_PTENTRY_FLAGS_UNERASEABLE; |
218 | ptable[PTN_MCU_OS_INDEX].partition_id = user_partition; | 218 | ptable[PTN_MCU_OS_INDEX].partition_id = user_partition; |
219 | strcpy(ptable[PTN_MCU_OS_INDEX].fstype, "raw"); | 219 | strcpy(ptable[PTN_MCU_OS_INDEX].fstype, "raw"); |
220 | #endif | 220 | #endif |
221 | 221 | ||
222 | strcpy(ptable[PTN_ALL_INDEX].name, FASTBOOT_PARTITION_ALL); | 222 | strcpy(ptable[PTN_ALL_INDEX].name, FASTBOOT_PARTITION_ALL); |
223 | ptable[PTN_ALL_INDEX].start = 0; | 223 | ptable[PTN_ALL_INDEX].start = 0; |
224 | ptable[PTN_ALL_INDEX].length = dev_desc->lba; | 224 | ptable[PTN_ALL_INDEX].length = dev_desc->lba; |
225 | ptable[PTN_ALL_INDEX].partition_id = user_partition; | 225 | ptable[PTN_ALL_INDEX].partition_id = user_partition; |
226 | strcpy(ptable[PTN_ALL_INDEX].fstype, "device"); | 226 | strcpy(ptable[PTN_ALL_INDEX].fstype, "device"); |
227 | 227 | ||
228 | /* Bootloader */ | 228 | /* Bootloader */ |
229 | strcpy(ptable[PTN_BOOTLOADER_INDEX].name, FASTBOOT_PARTITION_BOOTLOADER); | 229 | strcpy(ptable[PTN_BOOTLOADER_INDEX].name, FASTBOOT_PARTITION_BOOTLOADER); |
230 | ptable[PTN_BOOTLOADER_INDEX].start = | 230 | ptable[PTN_BOOTLOADER_INDEX].start = |
231 | bootloader_mmc_offset() / dev_desc->blksz; | 231 | bootloader_mmc_offset() / dev_desc->blksz; |
232 | ptable[PTN_BOOTLOADER_INDEX].length = | 232 | ptable[PTN_BOOTLOADER_INDEX].length = |
233 | ANDROID_BOOTLOADER_SIZE / dev_desc->blksz; | 233 | ANDROID_BOOTLOADER_SIZE / dev_desc->blksz; |
234 | ptable[PTN_BOOTLOADER_INDEX].partition_id = boot_partition; | 234 | ptable[PTN_BOOTLOADER_INDEX].partition_id = boot_partition; |
235 | ptable[PTN_BOOTLOADER_INDEX].flags = FASTBOOT_PTENTRY_FLAGS_UNERASEABLE; | 235 | ptable[PTN_BOOTLOADER_INDEX].flags = FASTBOOT_PTENTRY_FLAGS_UNERASEABLE; |
236 | strcpy(ptable[PTN_BOOTLOADER_INDEX].fstype, "raw"); | 236 | strcpy(ptable[PTN_BOOTLOADER_INDEX].fstype, "raw"); |
237 | 237 | ||
238 | int tbl_idx; | 238 | int tbl_idx; |
239 | int part_idx = 1; | 239 | int part_idx = 1; |
240 | int ret; | 240 | int ret; |
241 | for (tbl_idx = PTN_BOOTLOADER_INDEX + 1; tbl_idx < MAX_PTN; tbl_idx++) { | 241 | for (tbl_idx = PTN_BOOTLOADER_INDEX + 1; tbl_idx < MAX_PTN; tbl_idx++) { |
242 | ret = _fastboot_parts_add_ptable_entry(tbl_idx, | 242 | ret = _fastboot_parts_add_ptable_entry(tbl_idx, |
243 | part_idx++, | 243 | part_idx++, |
244 | user_partition, | 244 | user_partition, |
245 | NULL, | 245 | NULL, |
246 | NULL, | 246 | NULL, |
247 | dev_desc, ptable); | 247 | dev_desc, ptable); |
248 | if (ret) | 248 | if (ret) |
249 | break; | 249 | break; |
250 | } | 250 | } |
251 | for (i = 0; i < tbl_idx; i++) | 251 | for (i = 0; i < tbl_idx; i++) |
252 | fastboot_flash_add_ptn(&ptable[i]); | 252 | fastboot_flash_add_ptn(&ptable[i]); |
253 | 253 | ||
254 | return 0; | 254 | return 0; |
255 | } | 255 | } |
256 | 256 | ||
257 | void fastboot_load_partitions(void) | 257 | void fastboot_load_partitions(void) |
258 | { | 258 | { |
259 | g_pcount = 0; | 259 | g_pcount = 0; |
260 | _fastboot_parts_load_from_ptable(); | 260 | _fastboot_parts_load_from_ptable(); |
261 | } | 261 | } |
262 | 262 | ||
263 | /* | 263 | /* |
264 | * Android style flash utilties */ | 264 | * Android style flash utilties */ |
265 | void fastboot_flash_add_ptn(struct fastboot_ptentry *ptn) | 265 | void fastboot_flash_add_ptn(struct fastboot_ptentry *ptn) |
266 | { | 266 | { |
267 | if (g_pcount < MAX_PTN) { | 267 | if (g_pcount < MAX_PTN) { |
268 | memcpy(g_ptable + g_pcount, ptn, sizeof(struct fastboot_ptentry)); | 268 | memcpy(g_ptable + g_pcount, ptn, sizeof(struct fastboot_ptentry)); |
269 | g_pcount++; | 269 | g_pcount++; |
270 | } | 270 | } |
271 | } | 271 | } |
272 | 272 | ||
273 | void fastboot_flash_dump_ptn(void) | 273 | void fastboot_flash_dump_ptn(void) |
274 | { | 274 | { |
275 | unsigned int n; | 275 | unsigned int n; |
276 | for (n = 0; n < g_pcount; n++) { | 276 | for (n = 0; n < g_pcount; n++) { |
277 | struct fastboot_ptentry *ptn = g_ptable + n; | 277 | struct fastboot_ptentry *ptn = g_ptable + n; |
278 | printf("idx %d, ptn %d name='%s' start=%d len=%d\n", | 278 | printf("idx %d, ptn %d name='%s' start=%d len=%d\n", |
279 | n, ptn->partition_index, ptn->name, ptn->start, ptn->length); | 279 | n, ptn->partition_index, ptn->name, ptn->start, ptn->length); |
280 | } | 280 | } |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | struct fastboot_ptentry *fastboot_flash_find_ptn(const char *name) | 284 | struct fastboot_ptentry *fastboot_flash_find_ptn(const char *name) |
285 | { | 285 | { |
286 | unsigned int n; | 286 | unsigned int n; |
287 | 287 | ||
288 | for (n = 0; n < g_pcount; n++) { | 288 | for (n = 0; n < g_pcount; n++) { |
289 | /* Make sure a substring is not accepted */ | 289 | /* Make sure a substring is not accepted */ |
290 | if (strlen(name) == strlen(g_ptable[n].name)) { | 290 | if (strlen(name) == strlen(g_ptable[n].name)) { |
291 | if (0 == strcmp(g_ptable[n].name, name)) | 291 | if (0 == strcmp(g_ptable[n].name, name)) |
292 | return g_ptable + n; | 292 | return g_ptable + n; |
293 | } | 293 | } |
294 | } | 294 | } |
295 | 295 | ||
296 | return 0; | 296 | return 0; |
297 | } | 297 | } |
298 | 298 | ||
299 | int fastboot_flash_find_index(const char *name) | 299 | int fastboot_flash_find_index(const char *name) |
300 | { | 300 | { |
301 | struct fastboot_ptentry *ptentry = fastboot_flash_find_ptn(name); | 301 | struct fastboot_ptentry *ptentry = fastboot_flash_find_ptn(name); |
302 | if (ptentry == NULL) { | 302 | if (ptentry == NULL) { |
303 | printf("cannot get the partion info for %s\n",name); | 303 | printf("cannot get the partion info for %s\n",name); |
304 | fastboot_flash_dump_ptn(); | 304 | fastboot_flash_dump_ptn(); |
305 | return -1; | 305 | return -1; |
306 | } | 306 | } |
307 | return ptentry->partition_index; | 307 | return ptentry->partition_index; |
308 | } | 308 | } |
309 | 309 | ||
310 | struct fastboot_ptentry *fastboot_flash_get_ptn(unsigned int n) | 310 | struct fastboot_ptentry *fastboot_flash_get_ptn(unsigned int n) |
311 | { | 311 | { |
312 | if (n < g_pcount) | 312 | if (n < g_pcount) |
313 | return g_ptable + n; | 313 | return g_ptable + n; |
314 | else | 314 | else |
315 | return 0; | 315 | return 0; |
316 | } | 316 | } |
317 | 317 | ||
318 | unsigned int fastboot_flash_get_ptn_count(void) | 318 | unsigned int fastboot_flash_get_ptn_count(void) |
319 | { | 319 | { |
320 | return g_pcount; | 320 | return g_pcount; |
321 | } | 321 | } |
322 | 322 | ||
323 | bool fastboot_parts_is_raw(struct fastboot_ptentry *ptn) | 323 | bool fastboot_parts_is_raw(struct fastboot_ptentry *ptn) |
324 | { | 324 | { |
325 | if (ptn) { | 325 | if (ptn) { |
326 | if (!strncmp(ptn->name, FASTBOOT_PARTITION_BOOTLOADER, | 326 | if (!strncmp(ptn->name, FASTBOOT_PARTITION_BOOTLOADER, |
327 | strlen(FASTBOOT_PARTITION_BOOTLOADER))) | 327 | strlen(FASTBOOT_PARTITION_BOOTLOADER))) |
328 | return true; | 328 | return true; |
329 | #ifdef CONFIG_ANDROID_AB_SUPPORT | 329 | #ifdef CONFIG_ANDROID_AB_SUPPORT |
330 | else if (!strncmp(ptn->name, FASTBOOT_PARTITION_GPT, | 330 | else if (!strncmp(ptn->name, FASTBOOT_PARTITION_GPT, |
331 | strlen(FASTBOOT_PARTITION_GPT)) || | 331 | strlen(FASTBOOT_PARTITION_GPT)) || |
332 | !strncmp(ptn->name, FASTBOOT_PARTITION_BOOT_A, | 332 | !strncmp(ptn->name, FASTBOOT_PARTITION_BOOT_A, |
333 | strlen(FASTBOOT_PARTITION_BOOT_A)) || | 333 | strlen(FASTBOOT_PARTITION_BOOT_A)) || |
334 | !strncmp(ptn->name, FASTBOOT_PARTITION_BOOT_B, | 334 | !strncmp(ptn->name, FASTBOOT_PARTITION_BOOT_B, |
335 | strlen(FASTBOOT_PARTITION_BOOT_B))) | 335 | strlen(FASTBOOT_PARTITION_BOOT_B))) |
336 | return true; | 336 | return true; |
337 | #else | 337 | #else |
338 | else if (!strncmp(ptn->name, FASTBOOT_PARTITION_BOOT, | 338 | else if (!strncmp(ptn->name, FASTBOOT_PARTITION_BOOT, |
339 | strlen(FASTBOOT_PARTITION_BOOT))) | 339 | strlen(FASTBOOT_PARTITION_BOOT))) |
340 | return true; | 340 | return true; |
341 | #endif | 341 | #endif |
342 | #if defined(CONFIG_FASTBOOT_LOCK) | 342 | #if defined(CONFIG_FASTBOOT_LOCK) |
343 | else if (!strncmp(ptn->name, FASTBOOT_PARTITION_FBMISC, | 343 | else if (!strncmp(ptn->name, FASTBOOT_PARTITION_FBMISC, |
344 | strlen(FASTBOOT_PARTITION_FBMISC))) | 344 | strlen(FASTBOOT_PARTITION_FBMISC))) |
345 | return true; | 345 | return true; |
346 | #endif | 346 | #endif |
347 | else if (!strncmp(ptn->name, FASTBOOT_PARTITION_MISC, | 347 | else if (!strncmp(ptn->name, FASTBOOT_PARTITION_MISC, |
348 | strlen(FASTBOOT_PARTITION_MISC))) | 348 | strlen(FASTBOOT_PARTITION_MISC))) |
349 | return true; | 349 | return true; |
350 | } | 350 | } |
351 | 351 | ||
352 | return false; | 352 | return false; |
353 | } | 353 | } |
354 | 354 | ||
355 | static bool is_exist(char (*partition_base_name)[16], char *buffer, int count) | 355 | static bool is_exist(char (*partition_base_name)[16], char *buffer, int count) |
356 | { | 356 | { |
357 | int n; | 357 | int n; |
358 | 358 | ||
359 | for (n = 0; n < count; n++) { | 359 | for (n = 0; n < count; n++) { |
360 | if (!strcmp(partition_base_name[n],buffer)) | 360 | if (!strcmp(partition_base_name[n],buffer)) |
361 | return true; | 361 | return true; |
362 | } | 362 | } |
363 | return false; | 363 | return false; |
364 | } | 364 | } |
365 | 365 | ||
366 | /*get partition base name from gpt without "_a/_b"*/ | 366 | /*get partition base name from gpt without "_a/_b"*/ |
367 | int fastboot_parts_get_name(char (*partition_base_name)[16]) | 367 | int fastboot_parts_get_name(char (*partition_base_name)[16]) |
368 | { | 368 | { |
369 | int n = 0; | 369 | int n = 0; |
370 | int count = 0; | 370 | int count = 0; |
371 | char *ptr1, *ptr2; | 371 | char *ptr1, *ptr2; |
372 | char buffer[20]; | 372 | char buffer[20]; |
373 | 373 | ||
374 | for (n = 0; n < g_pcount; n++) { | 374 | for (n = 0; n < g_pcount; n++) { |
375 | strcpy(buffer,g_ptable[n].name); | 375 | strcpy(buffer,g_ptable[n].name); |
376 | ptr1 = strstr(buffer, "_a"); | 376 | ptr1 = strstr(buffer, "_a"); |
377 | ptr2 = strstr(buffer, "_b"); | 377 | ptr2 = strstr(buffer, "_b"); |
378 | if (ptr1 != NULL) { | 378 | if (ptr1 != NULL) { |
379 | *ptr1 = '\0'; | 379 | *ptr1 = '\0'; |
380 | if (!is_exist(partition_base_name,buffer,count)) { | 380 | if (!is_exist(partition_base_name,buffer,count)) { |
381 | strcpy(partition_base_name[count++],buffer); | 381 | strcpy(partition_base_name[count++],buffer); |
382 | } | 382 | } |
383 | } else if (ptr2 != NULL) { | 383 | } else if (ptr2 != NULL) { |
384 | *ptr2 = '\0'; | 384 | *ptr2 = '\0'; |
385 | if (!is_exist(partition_base_name,buffer,count)) { | 385 | if (!is_exist(partition_base_name,buffer,count)) { |
386 | strcpy(partition_base_name[count++],buffer); | 386 | strcpy(partition_base_name[count++],buffer); |
387 | } | 387 | } |
388 | } else { | 388 | } else { |
389 | strcpy(partition_base_name[count++],buffer); | 389 | strcpy(partition_base_name[count++],buffer); |
390 | } | 390 | } |
391 | } | 391 | } |
392 | return count; | 392 | return count; |
393 | } | 393 | } |
394 | 394 | ||
395 | bool fastboot_parts_is_slot(void) | 395 | bool fastboot_parts_is_slot(void) |
396 | { | 396 | { |
397 | char slot_suffix[2][5] = {"_a","_b"}; | 397 | char slot_suffix[2][5] = {"_a","_b"}; |
398 | int n; | 398 | int n; |
399 | 399 | ||
400 | for (n = 0; n < g_pcount; n++) { | 400 | for (n = 0; n < g_pcount; n++) { |
401 | if (strstr(g_ptable[n].name, slot_suffix[0]) || | 401 | if (strstr(g_ptable[n].name, slot_suffix[0]) || |
402 | strstr(g_ptable[n].name, slot_suffix[1])) | 402 | strstr(g_ptable[n].name, slot_suffix[1])) |
403 | return true; | 403 | return true; |
404 | } | 404 | } |
405 | return false; | 405 | return false; |
406 | } | 406 | } |
407 | 407 | ||
408 | 408 |