Commit e04350d2991ed628587e94b5b6d89c24f439e172

Authored by Steve Rae
Committed by Tom Rini
1 parent dedf37bb61

disk: part_efi: clarify lbaint_t usage

- update the comments regarding lbaint_t usage
- cleanup casting of values related to the lbaint_t type
- cleanup of a type that requires a u64

Tested on little endian ARMv7 and ARMv8 configurations

Signed-off-by: Steve Rae <srae@broadcom.com>

Showing 3 changed files with 30 additions and 28 deletions Side-by-side Diff

... ... @@ -199,8 +199,9 @@
199 199 (part_num == which_part) &&
200 200 (is_extended(pt->sys_ind) == 0)) {
201 201 info->blksz = 512;
202   - info->start = ext_part_sector + le32_to_int (pt->start4);
203   - info->size = le32_to_int (pt->size4);
  202 + info->start = (lbaint_t)(ext_part_sector +
  203 + le32_to_int(pt->start4));
  204 + info->size = (lbaint_t)le32_to_int(pt->size4);
204 205 switch(dev_desc->if_type) {
205 206 case IF_TYPE_IDE:
206 207 case IF_TYPE_SATA:
... ... @@ -6,13 +6,9 @@
6 6 */
7 7  
8 8 /*
9   - * Problems with CONFIG_SYS_64BIT_LBA:
10   - *
11   - * struct disk_partition.start in include/part.h is sized as ulong.
12   - * When CONFIG_SYS_64BIT_LBA is activated, lbaint_t changes from ulong to uint64_t.
13   - * For now, it is cast back to ulong at assignment.
14   - *
15   - * This limits the maximum size of addressable storage to < 2 Terra Bytes
  9 + * NOTE:
  10 + * when CONFIG_SYS_64BIT_LBA is not defined, lbaint_t is 32 bits; this
  11 + * limits the maximum size of addressable storage to < 2 Terra Bytes
16 12 */
17 13 #include <asm/unaligned.h>
18 14 #include <common.h>
... ... @@ -43,8 +39,8 @@
43 39  
44 40 static int pmbr_part_valid(struct partition *part);
45 41 static int is_pmbr_valid(legacy_mbr * mbr);
46   -static int is_gpt_valid(block_dev_desc_t * dev_desc, unsigned long long lba,
47   - gpt_header * pgpt_head, gpt_entry ** pgpt_pte);
  42 +static int is_gpt_valid(block_dev_desc_t *dev_desc, u64 lba,
  43 + gpt_header *pgpt_head, gpt_entry **pgpt_pte);
48 44 static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
49 45 gpt_header * pgpt_head);
50 46 static int is_pte_valid(gpt_entry * pte);
51 47  
... ... @@ -169,10 +165,10 @@
169 165 return -1;
170 166 }
171 167  
172   - /* The ulong casting limits the maximum disk size to 2 TB */
173   - info->start = (u64)le64_to_cpu(gpt_pte[part - 1].starting_lba);
  168 + /* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */
  169 + info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba);
174 170 /* The ending LBA is inclusive, to calculate size, add 1 to it */
175   - info->size = ((u64)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1)
  171 + info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1
176 172 - info->start;
177 173 info->blksz = dev_desc->blksz;
178 174  
179 175  
... ... @@ -279,12 +275,14 @@
279 275 gpt_h->header_crc32 = cpu_to_le32(calc_crc32);
280 276  
281 277 if (dev_desc->block_write(dev_desc->dev,
282   - le32_to_cpu(gpt_h->last_usable_lba) + 1,
  278 + (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba)
  279 + + 1,
283 280 pte_blk_cnt, gpt_e) != pte_blk_cnt)
284 281 goto err;
285 282  
286 283 if (dev_desc->block_write(dev_desc->dev,
287   - le32_to_cpu(gpt_h->my_lba), 1, gpt_h) != 1)
  284 + (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1,
  285 + gpt_h) != 1)
288 286 goto err;
289 287  
290 288 debug("GPT successfully written to block device!\n");
... ... @@ -298,9 +296,10 @@
298 296 int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
299 297 disk_partition_t *partitions, int parts)
300 298 {
301   - u32 offset = (u32)le32_to_cpu(gpt_h->first_usable_lba);
302   - ulong start;
303   - u32 last_usable_lba = (u32)le32_to_cpu(gpt_h->last_usable_lba);
  299 + lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba);
  300 + lbaint_t start;
  301 + lbaint_t last_usable_lba = (lbaint_t)
  302 + le64_to_cpu(gpt_h->last_usable_lba);
304 303 int i, k;
305 304 size_t efiname_len, dosname_len;
306 305 #ifdef CONFIG_PARTITION_UUIDS
... ... @@ -364,7 +363,8 @@
364 363 gpt_e[i].partition_name[k] =
365 364 (efi_char16_t)(partitions[i].name[k]);
366 365  
367   - debug("%s: name: %s offset[%d]: 0x%x size[%d]: 0x" LBAF "\n",
  366 + debug("%s: name: %s offset[%d]: 0x" LBAF
  367 + " size[%d]: 0x" LBAF "\n",
368 368 __func__, partitions[i].name, i,
369 369 offset, i, partitions[i].size);
370 370 }
371 371  
... ... @@ -488,12 +488,12 @@
488 488 * Description: returns 1 if valid, 0 on error.
489 489 * If valid, returns pointers to PTEs.
490 490 */
491   -static int is_gpt_valid(block_dev_desc_t * dev_desc, unsigned long long lba,
492   - gpt_header * pgpt_head, gpt_entry ** pgpt_pte)
  491 +static int is_gpt_valid(block_dev_desc_t *dev_desc, u64 lba,
  492 + gpt_header *pgpt_head, gpt_entry **pgpt_pte)
493 493 {
494 494 u32 crc32_backup = 0;
495 495 u32 calc_crc32;
496   - unsigned long long lastlba;
  496 + u64 lastlba;
497 497  
498 498 if (!dev_desc || !pgpt_head) {
499 499 printf("%s: Invalid Argument(s)\n", __func__);
... ... @@ -501,7 +501,8 @@
501 501 }
502 502  
503 503 /* Read GPT Header from device */
504   - if (dev_desc->block_read(dev_desc->dev, lba, 1, pgpt_head) != 1) {
  504 + if (dev_desc->block_read(dev_desc->dev, (lbaint_t)lba, 1, pgpt_head)
  505 + != 1) {
505 506 printf("*** ERROR: Can't read GPT header ***\n");
506 507 return 0;
507 508 }
... ... @@ -540,7 +541,7 @@
540 541 }
541 542  
542 543 /* Check the first_usable_lba and last_usable_lba are within the disk. */
543   - lastlba = (unsigned long long)dev_desc->lba;
  544 + lastlba = (u64)dev_desc->lba;
544 545 if (le64_to_cpu(pgpt_head->first_usable_lba) > lastlba) {
545 546 printf("GPT: first_usable_lba incorrect: %llX > %llX\n",
546 547 le64_to_cpu(pgpt_head->first_usable_lba), lastlba);
... ... @@ -548,7 +549,7 @@
548 549 }
549 550 if (le64_to_cpu(pgpt_head->last_usable_lba) > lastlba) {
550 551 printf("GPT: last_usable_lba incorrect: %llX > %llX\n",
551   - (u64) le64_to_cpu(pgpt_head->last_usable_lba), lastlba);
  552 + le64_to_cpu(pgpt_head->last_usable_lba), lastlba);
552 553 return 0;
553 554 }
554 555  
... ... @@ -625,7 +626,7 @@
625 626 /* Read GPT Entries from device */
626 627 blk_cnt = BLOCK_CNT(count, dev_desc);
627 628 if (dev_desc->block_read (dev_desc->dev,
628   - le64_to_cpu(pgpt_head->partition_entry_lba),
  629 + (lbaint_t)le64_to_cpu(pgpt_head->partition_entry_lba),
629 630 (lbaint_t) (blk_cnt), pte)
630 631 != blk_cnt) {
631 632  
... ... @@ -947,7 +947,7 @@
947 947  
948 948 total_sector = bs.total_sect;
949 949 if (total_sector == 0)
950   - total_sector = cur_part_info.size;
  950 + total_sector = (int)cur_part_info.size; /* cast of lbaint_t */
951 951  
952 952 if (mydata->fatsize == 32)
953 953 mydata->fatlength = bs.fat32_length;