Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 |
| 4 | * Raymond Lo, lo@routefree.com |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Support for harddisk partitions. |
| 10 | * |
| 11 | * To be compatible with LinuxPPC and Apple we use the standard Apple |
| 12 | * SCSI disk partitioning scheme. For more information see: |
| 13 | * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92 |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame^] | 17 | #include <blk.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 18 | #include <command.h> |
| 19 | #include <ide.h> |
Simon Glass | cf92e05 | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 20 | #include <memalign.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 21 | #include "part_dos.h" |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame^] | 22 | #include <part.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 23 | |
Adam Ford | 1811a92 | 2018-02-06 12:43:56 -0600 | [diff] [blame] | 24 | #ifdef CONFIG_HAVE_BLOCK_DEVICE |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 25 | |
Darwin Dingel | 4a36be9 | 2014-06-06 15:48:26 +1200 | [diff] [blame] | 26 | #define DOS_PART_DEFAULT_SECTOR 512 |
| 27 | |
Paul Emge | 232e2f4 | 2019-07-08 16:37:03 -0700 | [diff] [blame] | 28 | /* should this be configurable? It looks like it's not very common at all |
| 29 | * to use large numbers of partitions */ |
| 30 | #define MAX_EXT_PARTS 256 |
| 31 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 32 | /* Convert char[4] in little endian format to the host format integer |
| 33 | */ |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 34 | static inline unsigned int le32_to_int(unsigned char *le32) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 35 | { |
| 36 | return ((le32[3] << 24) + |
| 37 | (le32[2] << 16) + |
| 38 | (le32[1] << 8) + |
| 39 | le32[0] |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | static inline int is_extended(int part_type) |
| 44 | { |
| 45 | return (part_type == 0x5 || |
| 46 | part_type == 0xf || |
| 47 | part_type == 0x85); |
| 48 | } |
| 49 | |
Heinrich Schuchardt | 25801ac | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 50 | static int get_bootable(dos_partition_t *p) |
Rob Herring | 40e0e56 | 2012-08-23 11:31:43 +0000 | [diff] [blame] | 51 | { |
Heinrich Schuchardt | 25801ac | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 52 | int ret = 0; |
| 53 | |
| 54 | if (p->sys_ind == 0xef) |
| 55 | ret |= PART_EFI_SYSTEM_PARTITION; |
| 56 | if (p->boot_ind == 0x80) |
| 57 | ret |= PART_BOOTABLE; |
| 58 | return ret; |
Rob Herring | 40e0e56 | 2012-08-23 11:31:43 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 61 | static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector, |
Stephen Warren | e2e9b37 | 2012-10-08 08:14:40 +0000 | [diff] [blame] | 62 | int part_num, unsigned int disksig) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 63 | { |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 64 | lbaint_t lba_start = ext_part_sector + le32_to_int (p->start4); |
| 65 | lbaint_t lba_size = le32_to_int (p->size4); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 66 | |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 67 | printf("%3d\t%-10" LBAFlength "u\t%-10" LBAFlength |
| 68 | "u\t%08x-%02x\t%02x%s%s\n", |
Stephen Warren | e2e9b37 | 2012-10-08 08:14:40 +0000 | [diff] [blame] | 69 | part_num, lba_start, lba_size, disksig, part_num, p->sys_ind, |
Rob Herring | 40e0e56 | 2012-08-23 11:31:43 +0000 | [diff] [blame] | 70 | (is_extended(p->sys_ind) ? " Extd" : ""), |
Heinrich Schuchardt | 25801ac | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 71 | (get_bootable(p) ? " Boot" : "")); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 72 | } |
| 73 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 74 | static int test_block_type(unsigned char *buffer) |
| 75 | { |
Egbert Eich | 9d956e0 | 2013-04-09 05:46:14 +0000 | [diff] [blame] | 76 | int slot; |
| 77 | struct dos_partition *p; |
Heinrich Schuchardt | 34856b0 | 2019-10-15 20:43:42 +0200 | [diff] [blame] | 78 | int part_count = 0; |
Egbert Eich | 9d956e0 | 2013-04-09 05:46:14 +0000 | [diff] [blame] | 79 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 80 | if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) || |
| 81 | (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) { |
| 82 | return (-1); |
| 83 | } /* no DOS Signature at all */ |
Egbert Eich | 9d956e0 | 2013-04-09 05:46:14 +0000 | [diff] [blame] | 84 | p = (struct dos_partition *)&buffer[DOS_PART_TBL_OFFSET]; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 85 | |
Heinrich Schuchardt | 34856b0 | 2019-10-15 20:43:42 +0200 | [diff] [blame] | 86 | /* Check that the boot indicators are valid and count the partitions. */ |
| 87 | for (slot = 0; slot < 4; ++slot, ++p) { |
| 88 | if (p->boot_ind != 0 && p->boot_ind != 0x80) |
| 89 | break; |
| 90 | if (p->sys_ind) |
| 91 | ++part_count; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * If the partition table is invalid or empty, |
| 96 | * check if this is a DOS PBR |
| 97 | */ |
| 98 | if (slot != 4 || !part_count) { |
| 99 | if (!strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET], |
| 100 | "FAT", 3) || |
| 101 | !strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET], |
| 102 | "FAT32", 5)) |
| 103 | return DOS_PBR; /* This is a DOS PBR and not an MBR */ |
| 104 | } |
| 105 | if (slot == 4) |
| 106 | return DOS_MBR; /* This is an DOS MBR */ |
| 107 | |
| 108 | /* This is neither a DOS MBR nor a DOS PBR */ |
| 109 | return -1; |
| 110 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 111 | |
Simon Glass | 084bf4c | 2016-02-29 15:26:04 -0700 | [diff] [blame] | 112 | static int part_test_dos(struct blk_desc *dev_desc) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 113 | { |
Fabio Estevam | 3ea0520 | 2017-10-04 13:29:57 -0300 | [diff] [blame] | 114 | #ifndef CONFIG_SPL_BUILD |
Faiz Abbas | 7aed3d3 | 2019-09-04 20:10:12 +0530 | [diff] [blame] | 115 | ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, |
| 116 | DIV_ROUND_UP(dev_desc->blksz, sizeof(legacy_mbr))); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 117 | |
Peter Jones | ff98cb9 | 2017-09-13 18:05:25 -0400 | [diff] [blame] | 118 | if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) |
Stephen Warren | d1efb64 | 2012-10-05 13:17:40 +0000 | [diff] [blame] | 119 | return -1; |
| 120 | |
Peter Jones | ff98cb9 | 2017-09-13 18:05:25 -0400 | [diff] [blame] | 121 | if (test_block_type((unsigned char *)mbr) != DOS_MBR) |
Stephen Warren | d1efb64 | 2012-10-05 13:17:40 +0000 | [diff] [blame] | 122 | return -1; |
| 123 | |
Peter Jones | ff98cb9 | 2017-09-13 18:05:25 -0400 | [diff] [blame] | 124 | if (dev_desc->sig_type == SIG_TYPE_NONE && |
| 125 | mbr->unique_mbr_signature != 0) { |
| 126 | dev_desc->sig_type = SIG_TYPE_MBR; |
| 127 | dev_desc->mbr_sig = mbr->unique_mbr_signature; |
| 128 | } |
Fabio Estevam | 3ea0520 | 2017-10-04 13:29:57 -0300 | [diff] [blame] | 129 | #else |
| 130 | ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); |
| 131 | |
| 132 | if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1) |
| 133 | return -1; |
| 134 | |
| 135 | if (test_block_type(buffer) != DOS_MBR) |
| 136 | return -1; |
| 137 | #endif |
Peter Jones | ff98cb9 | 2017-09-13 18:05:25 -0400 | [diff] [blame] | 138 | |
Stephen Warren | d1efb64 | 2012-10-05 13:17:40 +0000 | [diff] [blame] | 139 | return 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* Print a partition that is relative to its Extended partition table |
| 143 | */ |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 144 | static void print_partition_extended(struct blk_desc *dev_desc, |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 145 | lbaint_t ext_part_sector, |
| 146 | lbaint_t relative, |
Stephen Warren | e2e9b37 | 2012-10-08 08:14:40 +0000 | [diff] [blame] | 147 | int part_num, unsigned int disksig) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 148 | { |
Eric Nelson | dec049d | 2012-03-03 12:02:20 +0000 | [diff] [blame] | 149 | ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 150 | dos_partition_t *pt; |
| 151 | int i; |
| 152 | |
Paul Emge | 232e2f4 | 2019-07-08 16:37:03 -0700 | [diff] [blame] | 153 | /* set a maximum recursion level */ |
| 154 | if (part_num > MAX_EXT_PARTS) |
| 155 | { |
| 156 | printf("** Nested DOS partitions detected, stopping **\n"); |
| 157 | return; |
| 158 | } |
| 159 | |
Simon Glass | 2a981dc | 2016-02-29 15:25:52 -0700 | [diff] [blame] | 160 | if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) { |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 161 | printf ("** Can't read partition table on %d:" LBAFU " **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 162 | dev_desc->devnum, ext_part_sector); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 163 | return; |
| 164 | } |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 165 | i=test_block_type(buffer); |
Stephen Warren | d1efb64 | 2012-10-05 13:17:40 +0000 | [diff] [blame] | 166 | if (i != DOS_MBR) { |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 167 | printf ("bad MBR sector signature 0x%02x%02x\n", |
| 168 | buffer[DOS_PART_MAGIC_OFFSET], |
| 169 | buffer[DOS_PART_MAGIC_OFFSET + 1]); |
| 170 | return; |
| 171 | } |
Stephen Warren | d1efb64 | 2012-10-05 13:17:40 +0000 | [diff] [blame] | 172 | |
Stephen Warren | e2e9b37 | 2012-10-08 08:14:40 +0000 | [diff] [blame] | 173 | if (!ext_part_sector) |
| 174 | disksig = le32_to_int(&buffer[DOS_PART_DISKSIG_OFFSET]); |
| 175 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 176 | /* Print all primary/logical partitions */ |
| 177 | pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); |
| 178 | for (i = 0; i < 4; i++, pt++) { |
| 179 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 180 | * fdisk does not show the extended partitions that |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 181 | * are not in the MBR |
| 182 | */ |
| 183 | |
| 184 | if ((pt->sys_ind != 0) && |
| 185 | (ext_part_sector == 0 || !is_extended (pt->sys_ind)) ) { |
Stephen Warren | e2e9b37 | 2012-10-08 08:14:40 +0000 | [diff] [blame] | 186 | print_one_part(pt, ext_part_sector, part_num, disksig); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* Reverse engr the fdisk part# assignment rule! */ |
| 190 | if ((ext_part_sector == 0) || |
| 191 | (pt->sys_ind != 0 && !is_extended (pt->sys_ind)) ) { |
| 192 | part_num++; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /* Follows the extended partitions */ |
| 197 | pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); |
| 198 | for (i = 0; i < 4; i++, pt++) { |
| 199 | if (is_extended (pt->sys_ind)) { |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 200 | lbaint_t lba_start |
| 201 | = le32_to_int (pt->start4) + relative; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 202 | |
Stephen Warren | 304b571 | 2012-10-08 08:14:38 +0000 | [diff] [blame] | 203 | print_partition_extended(dev_desc, lba_start, |
| 204 | ext_part_sector == 0 ? lba_start : relative, |
Stephen Warren | e2e9b37 | 2012-10-08 08:14:40 +0000 | [diff] [blame] | 205 | part_num, disksig); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /* Print a partition that is relative to its Extended partition table |
| 214 | */ |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 215 | static int part_get_info_extended(struct blk_desc *dev_desc, |
| 216 | lbaint_t ext_part_sector, lbaint_t relative, |
| 217 | int part_num, int which_part, |
Simon Glass | 0528979 | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 218 | struct disk_partition *info, uint disksig) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 219 | { |
Eric Nelson | dec049d | 2012-03-03 12:02:20 +0000 | [diff] [blame] | 220 | ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 221 | dos_partition_t *pt; |
| 222 | int i; |
Darwin Dingel | 4a36be9 | 2014-06-06 15:48:26 +1200 | [diff] [blame] | 223 | int dos_type; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 224 | |
Paul Emge | 232e2f4 | 2019-07-08 16:37:03 -0700 | [diff] [blame] | 225 | /* set a maximum recursion level */ |
| 226 | if (part_num > MAX_EXT_PARTS) |
| 227 | { |
| 228 | printf("** Nested DOS partitions detected, stopping **\n"); |
| 229 | return -1; |
| 230 | } |
| 231 | |
Simon Glass | 2a981dc | 2016-02-29 15:25:52 -0700 | [diff] [blame] | 232 | if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) { |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 233 | printf ("** Can't read partition table on %d:" LBAFU " **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 234 | dev_desc->devnum, ext_part_sector); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 235 | return -1; |
| 236 | } |
| 237 | if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 || |
| 238 | buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) { |
| 239 | printf ("bad MBR sector signature 0x%02x%02x\n", |
| 240 | buffer[DOS_PART_MAGIC_OFFSET], |
| 241 | buffer[DOS_PART_MAGIC_OFFSET + 1]); |
| 242 | return -1; |
| 243 | } |
| 244 | |
Patrick Delaunay | b331cd6 | 2017-01-27 11:00:42 +0100 | [diff] [blame] | 245 | #if CONFIG_IS_ENABLED(PARTITION_UUIDS) |
Stephen Warren | d27b5f9 | 2012-09-21 09:51:00 +0000 | [diff] [blame] | 246 | if (!ext_part_sector) |
| 247 | disksig = le32_to_int(&buffer[DOS_PART_DISKSIG_OFFSET]); |
| 248 | #endif |
| 249 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 250 | /* Print all primary/logical partitions */ |
| 251 | pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); |
| 252 | for (i = 0; i < 4; i++, pt++) { |
| 253 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 254 | * fdisk does not show the extended partitions that |
| 255 | * are not in the MBR |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 256 | */ |
Daniel Mack | 78f4ca7 | 2009-09-28 11:40:38 +0200 | [diff] [blame] | 257 | if (((pt->boot_ind & ~0x80) == 0) && |
| 258 | (pt->sys_ind != 0) && |
wdenk | 7f70e85 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 259 | (part_num == which_part) && |
Shawn Guo | 8f7102c | 2017-11-02 16:46:34 +0800 | [diff] [blame] | 260 | (ext_part_sector == 0 || is_extended(pt->sys_ind) == 0)) { |
Darwin Dingel | 4a36be9 | 2014-06-06 15:48:26 +1200 | [diff] [blame] | 261 | info->blksz = DOS_PART_DEFAULT_SECTOR; |
Steve Rae | e04350d | 2014-05-26 11:52:23 -0700 | [diff] [blame] | 262 | info->start = (lbaint_t)(ext_part_sector + |
| 263 | le32_to_int(pt->start4)); |
| 264 | info->size = (lbaint_t)le32_to_int(pt->size4); |
Petr Kulhavy | da2ee24 | 2016-09-09 10:27:17 +0200 | [diff] [blame] | 265 | part_set_generic_name(dev_desc, part_num, |
| 266 | (char *)info->name); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 267 | /* sprintf(info->type, "%d, pt->sys_ind); */ |
Ben Whitten | 192bc69 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 268 | strcpy((char *)info->type, "U-Boot"); |
Heinrich Schuchardt | 25801ac | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 269 | info->bootable = get_bootable(pt); |
Patrick Delaunay | b331cd6 | 2017-01-27 11:00:42 +0100 | [diff] [blame] | 270 | #if CONFIG_IS_ENABLED(PARTITION_UUIDS) |
Stephen Warren | d27b5f9 | 2012-09-21 09:51:00 +0000 | [diff] [blame] | 271 | sprintf(info->uuid, "%08x-%02x", disksig, part_num); |
| 272 | #endif |
Dalon Westergreen | f0fb4fa | 2017-02-10 17:15:34 -0800 | [diff] [blame] | 273 | info->sys_ind = pt->sys_ind; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | /* Reverse engr the fdisk part# assignment rule! */ |
| 278 | if ((ext_part_sector == 0) || |
| 279 | (pt->sys_ind != 0 && !is_extended (pt->sys_ind)) ) { |
| 280 | part_num++; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /* Follows the extended partitions */ |
| 285 | pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); |
| 286 | for (i = 0; i < 4; i++, pt++) { |
| 287 | if (is_extended (pt->sys_ind)) { |
Stefan Monnier | d29892b | 2015-08-25 15:24:13 -0400 | [diff] [blame] | 288 | lbaint_t lba_start |
| 289 | = le32_to_int (pt->start4) + relative; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 290 | |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 291 | return part_get_info_extended(dev_desc, lba_start, |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 292 | ext_part_sector == 0 ? lba_start : relative, |
Stephen Warren | d27b5f9 | 2012-09-21 09:51:00 +0000 | [diff] [blame] | 293 | part_num, which_part, info, disksig); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 294 | } |
| 295 | } |
Darwin Dingel | 4a36be9 | 2014-06-06 15:48:26 +1200 | [diff] [blame] | 296 | |
| 297 | /* Check for DOS PBR if no partition is found */ |
| 298 | dos_type = test_block_type(buffer); |
| 299 | |
| 300 | if (dos_type == DOS_PBR) { |
| 301 | info->start = 0; |
| 302 | info->size = dev_desc->lba; |
| 303 | info->blksz = DOS_PART_DEFAULT_SECTOR; |
| 304 | info->bootable = 0; |
Ben Whitten | 192bc69 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 305 | strcpy((char *)info->type, "U-Boot"); |
Patrick Delaunay | b331cd6 | 2017-01-27 11:00:42 +0100 | [diff] [blame] | 306 | #if CONFIG_IS_ENABLED(PARTITION_UUIDS) |
Darwin Dingel | 4a36be9 | 2014-06-06 15:48:26 +1200 | [diff] [blame] | 307 | info->uuid[0] = 0; |
| 308 | #endif |
| 309 | return 0; |
| 310 | } |
| 311 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 312 | return -1; |
| 313 | } |
| 314 | |
Simon Glass | 084bf4c | 2016-02-29 15:26:04 -0700 | [diff] [blame] | 315 | void part_print_dos(struct blk_desc *dev_desc) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 316 | { |
Stephen Warren | e2e9b37 | 2012-10-08 08:14:40 +0000 | [diff] [blame] | 317 | printf("Part\tStart Sector\tNum Sectors\tUUID\t\tType\n"); |
| 318 | print_partition_extended(dev_desc, 0, 0, 1, 0); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 321 | int part_get_info_dos(struct blk_desc *dev_desc, int part, |
Simon Glass | 0528979 | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 322 | struct disk_partition *info) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 323 | { |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 324 | return part_get_info_extended(dev_desc, 0, 0, 1, part, info, 0); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Petr Kulhavy | b6dd69a | 2016-09-09 10:27:16 +0200 | [diff] [blame] | 327 | int is_valid_dos_buf(void *buf) |
| 328 | { |
| 329 | return test_block_type(buf) == DOS_MBR ? 0 : -1; |
| 330 | } |
| 331 | |
| 332 | int write_mbr_partition(struct blk_desc *dev_desc, void *buf) |
| 333 | { |
| 334 | if (is_valid_dos_buf(buf)) |
| 335 | return -1; |
| 336 | |
| 337 | /* write MBR */ |
| 338 | if (blk_dwrite(dev_desc, 0, 1, buf) != 1) { |
| 339 | printf("%s: failed writing '%s' (1 blks at 0x0)\n", |
| 340 | __func__, "MBR"); |
| 341 | return 1; |
| 342 | } |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 347 | U_BOOT_PART_TYPE(dos) = { |
| 348 | .name = "DOS", |
| 349 | .part_type = PART_TYPE_DOS, |
Petr Kulhavy | 87b8530 | 2016-09-09 10:27:15 +0200 | [diff] [blame] | 350 | .max_entries = DOS_ENTRY_NUMBERS, |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 351 | .get_info = part_get_info_ptr(part_get_info_dos), |
Simon Glass | 084bf4c | 2016-02-29 15:26:04 -0700 | [diff] [blame] | 352 | .print = part_print_ptr(part_print_dos), |
| 353 | .test = part_test_dos, |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 354 | }; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 355 | |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 356 | #endif |