Lines Matching +full:boot +full:- +full:blks
5 * SPDX-License-Identifier: GPL-2.0+
29 * efi_crc32() - EFI version of crc32 function
31 * @len - length of buf
33 * Description: Returns EFI-style CRC32 value for @buf
58 c = pte->partition_name[i] & 0xff; in print_efiname()
70 return p->attributes.fields.legacy_bios_bootable || in is_bootable()
71 !memcmp(&(p->partition_type_guid), &system_guid, in is_bootable()
75 #define FACTORY_UNKNOWN_LBA (0xffffffff - 34)
83 if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE) { in validate_gpt_header()
84 if (le64_to_cpu(gpt_h->signature) != 0) in validate_gpt_header()
87 le64_to_cpu(gpt_h->signature), in validate_gpt_header()
89 return -1; in validate_gpt_header()
93 memcpy(&crc32_backup, &gpt_h->header_crc32, sizeof(crc32_backup)); in validate_gpt_header()
94 memset(&gpt_h->header_crc32, 0, sizeof(gpt_h->header_crc32)); in validate_gpt_header()
97 le32_to_cpu(gpt_h->header_size)); in validate_gpt_header()
99 memcpy(&gpt_h->header_crc32, &crc32_backup, sizeof(crc32_backup)); in validate_gpt_header()
105 return -1; in validate_gpt_header()
111 if (le64_to_cpu(gpt_h->my_lba) != lba) { in validate_gpt_header()
113 le64_to_cpu(gpt_h->my_lba), in validate_gpt_header()
115 return -1; in validate_gpt_header()
122 if (le64_to_cpu(gpt_h->first_usable_lba) > lastlba) { in validate_gpt_header()
124 le64_to_cpu(gpt_h->first_usable_lba), lastlba); in validate_gpt_header()
125 return -1; in validate_gpt_header()
127 if (le64_to_cpu(gpt_h->last_usable_lba) > lastlba) { in validate_gpt_header()
128 if (le64_to_cpu(gpt_h->last_usable_lba) == FACTORY_UNKNOWN_LBA) { in validate_gpt_header()
131 gpt_h->last_usable_lba = lastlba - 34; in validate_gpt_header()
139 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
140 return -1; in validate_gpt_header()
144 LBAF "\n", le64_to_cpu(gpt_h->first_usable_lba), in validate_gpt_header()
145 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
156 le32_to_cpu(gpt_h->num_partition_entries) * in validate_gpt_entries()
157 le32_to_cpu(gpt_h->sizeof_partition_entry)); in validate_gpt_entries()
159 if (calc_crc32 != le32_to_cpu(gpt_h->partition_entry_array_crc32)) { in validate_gpt_entries()
162 le32_to_cpu(gpt_h->partition_entry_array_crc32), in validate_gpt_entries()
164 return -1; in validate_gpt_entries()
176 val = le64_to_cpu(gpt_h->my_lba); in prepare_backup_gpt_header()
177 gpt_h->my_lba = gpt_h->alternate_lba; in prepare_backup_gpt_header()
178 gpt_h->alternate_lba = cpu_to_le64(val); in prepare_backup_gpt_header()
179 gpt_h->partition_entry_lba = in prepare_backup_gpt_header()
180 cpu_to_le64(le64_to_cpu(gpt_h->last_usable_lba) + 1); in prepare_backup_gpt_header()
181 gpt_h->header_crc32 = 0; in prepare_backup_gpt_header()
184 le32_to_cpu(gpt_h->header_size)); in prepare_backup_gpt_header()
185 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in prepare_backup_gpt_header()
195 * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
199 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in get_disk_guid()
207 if (is_gpt_valid(dev_desc, dev_desc->lba - 1, in get_disk_guid()
211 return -EINVAL; in get_disk_guid()
218 guid_bin = gpt_head->disk_guid.b; in get_disk_guid()
226 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in part_print_efi()
236 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_print_efi()
247 debug("%s: gpt-entry at %p\n", __func__, gpt_pte); in part_print_efi()
254 for (i = 0; i < le32_to_cpu(gpt_head->num_partition_entries); i++) { in part_print_efi()
288 gpt_head = memalign(ARCH_DMA_MINALIGN, dev_desc->blksz); in part_get_info_efi()
294 if (gpt_head && (gpt_head->last_usable_lba + 0x22) != dev_desc->lba) { in part_get_info_efi()
303 return -1; in part_get_info_efi()
310 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_get_info_efi()
314 return -1; in part_get_info_efi()
321 if (part > le32_to_cpu(gpt_head->num_partition_entries) || in part_get_info_efi()
322 !is_pte_valid(&gpt_pte[part - 1])) { in part_get_info_efi()
325 return -1; in part_get_info_efi()
329 info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba); in part_get_info_efi()
331 info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1 in part_get_info_efi()
332 - info->start; in part_get_info_efi()
333 info->blksz = dev_desc->blksz; in part_get_info_efi()
335 sprintf((char *)info->name, "%s", in part_get_info_efi()
336 print_efiname(&gpt_pte[part - 1])); in part_get_info_efi()
337 strcpy((char *)info->type, "U-Boot"); in part_get_info_efi()
338 info->bootable = is_bootable(&gpt_pte[part - 1]); in part_get_info_efi()
340 uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid, in part_get_info_efi()
344 uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, in part_get_info_efi()
345 info->type_guid, UUID_STR_FORMAT_GUID); in part_get_info_efi()
349 info->start, info->size, info->name); in part_get_info_efi()
363 for (i = 0; i < gpt_head->num_partition_entries; i++) { in gpt_entry_modify()
368 if (gpt_pte[i - 1].ending_lba <= (dev_desc->lba - 0x22)) in gpt_entry_modify()
371 gpt_pte[i - 1].ending_lba = dev_desc->lba - 0x41; in gpt_entry_modify()
373 le32_to_cpu(gpt_head->num_partition_entries) * in gpt_entry_modify()
374 le32_to_cpu(gpt_head->sizeof_partition_entry)); in gpt_entry_modify()
375 gpt_head->partition_entry_array_crc32 = calc_crc32; in gpt_entry_modify()
389 return -1; in part_efi_repair()
391 gpt_head->header_crc32 = 0; in part_efi_repair()
392 gpt_head->my_lba = dev_desc->lba - 1; in part_efi_repair()
393 gpt_head->alternate_lba = 1; in part_efi_repair()
394 gpt_head->partition_entry_lba = dev_desc->lba - 0x21; in part_efi_repair()
395 gpt_head->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in part_efi_repair()
398 le32_to_cpu(gpt_head->header_size)); in part_efi_repair()
399 gpt_head->header_crc32 = calc_crc32; in part_efi_repair()
400 if (blk_dwrite(dev_desc, dev_desc->lba - 1, 1, gpt_head) != 1) { in part_efi_repair()
402 return -1; in part_efi_repair()
404 count = le32_to_cpu(gpt_head->num_partition_entries) * in part_efi_repair()
405 le32_to_cpu(gpt_head->sizeof_partition_entry); in part_efi_repair()
406 blk = le64_to_cpu(gpt_head->partition_entry_lba); in part_efi_repair()
411 return -1; in part_efi_repair()
415 gpt_head->header_crc32 = 0; in part_efi_repair()
416 gpt_head->my_lba = 1; in part_efi_repair()
417 gpt_head->alternate_lba = dev_desc->lba - 1; in part_efi_repair()
418 gpt_head->partition_entry_lba = 0x2; in part_efi_repair()
419 gpt_head->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in part_efi_repair()
422 le32_to_cpu(gpt_head->header_size)); in part_efi_repair()
423 gpt_head->header_crc32 = calc_crc32; in part_efi_repair()
426 return -1; in part_efi_repair()
428 count = le32_to_cpu(gpt_head->num_partition_entries) * in part_efi_repair()
429 le32_to_cpu(gpt_head->sizeof_partition_entry); in part_efi_repair()
430 blk = le64_to_cpu(gpt_head->partition_entry_lba); in part_efi_repair()
435 return -1; in part_efi_repair()
447 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz); in part_test_efi()
453 return -1; in part_test_efi()
465 h_gpt_head = memalign(ARCH_DMA_MINALIGN, dev_desc->blksz); in part_test_efi()
467 b_gpt_head = memalign(ARCH_DMA_MINALIGN, dev_desc->blksz); in part_test_efi()
471 backup_gpt_valid = is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_test_efi()
475 (le64_to_cpu(h_gpt_head->last_usable_lba) in part_test_efi()
493 ret = -1; in part_test_efi()
511 * @param dev_desc - block device descriptor
513 * @return - zero on success, otherwise error
523 return -1; in set_protective_mbr()
526 /* Read MBR to backup boot code if it exists */ in set_protective_mbr()
528 pr_err("** Can't read from device %d **\n", dev_desc->devnum); in set_protective_mbr()
529 return -1; in set_protective_mbr()
533 p_mbr->signature = MSDOS_MBR_SIGNATURE; in set_protective_mbr()
534 p_mbr->partition_record[0].sys_ind = EFI_PMBR_OSTYPE_EFI_GPT; in set_protective_mbr()
535 p_mbr->partition_record[0].start_sect = 1; in set_protective_mbr()
536 p_mbr->partition_record[0].nr_sects = (u32) dev_desc->lba - 1; in set_protective_mbr()
541 dev_desc->devnum); in set_protective_mbr()
542 return -1; in set_protective_mbr()
551 const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries in write_gpt_table()
555 debug("max lba: %x\n", (u32) dev_desc->lba); in write_gpt_table()
562 le32_to_cpu(gpt_h->num_partition_entries) * in write_gpt_table()
563 le32_to_cpu(gpt_h->sizeof_partition_entry)); in write_gpt_table()
564 gpt_h->partition_entry_array_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
567 le32_to_cpu(gpt_h->header_size)); in write_gpt_table()
568 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
574 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), in write_gpt_table()
580 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) in write_gpt_table()
584 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, in write_gpt_table()
592 printf("** Can't write to device %d **\n", dev_desc->devnum); in write_gpt_table()
593 return -1; in write_gpt_table()
600 lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba); in gpt_fill_pte()
602 le64_to_cpu(gpt_h->last_usable_lba); in gpt_fill_pte()
613 size_t hdr_start = gpt_h->my_lba; in gpt_fill_pte()
616 size_t pte_start = gpt_h->partition_entry_lba; in gpt_fill_pte()
618 gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry / in gpt_fill_pte()
619 dev_desc->blksz; in gpt_fill_pte()
640 return -1; in gpt_fill_pte()
647 return -1; in gpt_fill_pte()
650 if ((i == parts - 1) && (size == 0)) in gpt_fill_pte()
652 gpt_e[i].ending_lba = gpt_h->last_usable_lba; in gpt_fill_pte()
654 gpt_e[i].ending_lba = cpu_to_le64(offset - 1); in gpt_fill_pte()
664 return -1; in gpt_fill_pte()
684 return -1; in gpt_fill_pte()
733 offset_blks = offset_bytes / dev_desc->blksz; in partition_entries_offset()
742 config_offset = fdtdec_get_config_int(gd->fdt_blob, in partition_entries_offset()
743 "u-boot,efi-partition-entries-offset", in partition_entries_offset()
744 -EINVAL); in partition_entries_offset()
745 if (config_offset != -EINVAL) { in partition_entries_offset()
747 offset_blks = offset_bytes / dev_desc->blksz; in partition_entries_offset()
766 gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE); in gpt_fill_header()
767 gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1); in gpt_fill_header()
768 gpt_h->header_size = cpu_to_le32(sizeof(gpt_header)); in gpt_fill_header()
769 gpt_h->my_lba = cpu_to_le64(1); in gpt_fill_header()
770 gpt_h->alternate_lba = cpu_to_le64(dev_desc->lba - 1); in gpt_fill_header()
771 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in gpt_fill_header()
772 gpt_h->partition_entry_lba = in gpt_fill_header()
774 gpt_h->first_usable_lba = in gpt_fill_header()
775 cpu_to_le64(le64_to_cpu(gpt_h->partition_entry_lba) + 32); in gpt_fill_header()
776 gpt_h->num_partition_entries = cpu_to_le32(GPT_ENTRY_NUMBERS); in gpt_fill_header()
777 gpt_h->sizeof_partition_entry = cpu_to_le32(sizeof(gpt_entry)); in gpt_fill_header()
778 gpt_h->header_crc32 = 0; in gpt_fill_header()
779 gpt_h->partition_entry_array_crc32 = 0; in gpt_fill_header()
781 if (uuid_str_to_bin(str_guid, gpt_h->disk_guid.b, UUID_STR_FORMAT_GUID)) in gpt_fill_header()
782 return -1; in gpt_fill_header()
798 return -1; in gpt_restore()
808 return -1; in gpt_restore()
832 * gpt_convert_efi_name_to_char() - convert u16 string to char string
866 return -1; in gpt_verify_headers()
868 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in gpt_verify_headers()
872 return -1; in gpt_verify_headers()
894 if (i == gpt_head->num_partition_entries) { in gpt_verify_partitions()
896 return -1; in gpt_verify_partitions()
903 debug("%s: part: %2d name - GPT: %16s, ENV: %16s ", in gpt_verify_partitions()
907 sizeof(partitions->name))) { in gpt_verify_partitions()
910 return -1; in gpt_verify_partitions()
914 gpt_part_size = le64_to_cpu(gpt_e[i].ending_lba) - in gpt_verify_partitions()
916 debug("size(LBA) - GPT: %8llu, ENV: %8llu ", in gpt_verify_partitions()
922 if ((i == parts - 1) && (partitions[i].size == 0)) in gpt_verify_partitions()
928 return -1; in gpt_verify_partitions()
932 * Start address is optional - check only if provided in gpt_verify_partitions()
941 debug("start LBA - GPT: %8llu, ENV: %8llu\n", in gpt_verify_partitions()
949 return -1; in gpt_verify_partitions()
963 dev_desc->blksz); in is_valid_gpt_buf()
965 if ((le64_to_cpu(gpt_h->alternate_lba) + 1) in is_valid_gpt_buf()
966 != cpu_to_le64(dev_desc->lba) && in is_valid_gpt_buf()
967 le64_to_cpu(gpt_h->last_usable_lba) != FACTORY_UNKNOWN_LBA) { in is_valid_gpt_buf()
970 return -1; in is_valid_gpt_buf()
974 dev_desc->lba)) in is_valid_gpt_buf()
975 return -1; in is_valid_gpt_buf()
978 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in is_valid_gpt_buf()
979 dev_desc->blksz); in is_valid_gpt_buf()
981 return -1; in is_valid_gpt_buf()
995 return -1; in write_mbr_and_gpt_partitions()
999 dev_desc->blksz); in write_mbr_and_gpt_partitions()
1002 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in write_mbr_and_gpt_partitions()
1003 dev_desc->blksz); in write_mbr_and_gpt_partitions()
1004 gpt_e_blk_cnt = BLOCK_CNT((le32_to_cpu(gpt_h->num_partition_entries) * in write_mbr_and_gpt_partitions()
1005 le32_to_cpu(gpt_h->sizeof_partition_entry)), in write_mbr_and_gpt_partitions()
1012 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
1021 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
1026 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
1029 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
1037 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
1040 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
1045 lba = le64_to_cpu(gpt_h->my_lba); in write_mbr_and_gpt_partitions()
1048 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
1067 if (part->sys_ind == EFI_PMBR_OSTYPE_EFI_GPT && in pmbr_part_valid()
1068 get_unaligned_le32(&part->start_sect) == 1UL) { in pmbr_part_valid()
1089 * In sd-update card, we use RKPARM partition in bootloader to load in is_pmbr_valid()
1090 * firmware, and use MS-DOS partition in recovery to update system. in is_pmbr_valid()
1092 * partition. So in new sd-update card, we write the MS-DOS partition in is_pmbr_valid()
1099 if (!mbr || le16_to_cpu(mbr->signature) != MSDOS_MBR_SIGNATURE) in is_pmbr_valid()
1103 if (pmbr_part_valid(&mbr->partition_record[i])) { in is_pmbr_valid()
1111 * is_gpt_valid() - tests one GPT header and PTEs for validity
1129 /* Re-use pte if it's not NULL */ in is_gpt_valid()
1133 ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz); in is_gpt_valid()
1147 if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba)) in is_gpt_valid()
1150 if (dev_desc->sig_type == SIG_TYPE_NONE) { in is_gpt_valid()
1152 if (memcmp(&pgpt_head->disk_guid, &empty, sizeof(empty))) { in is_gpt_valid()
1153 dev_desc->sig_type = SIG_TYPE_GUID; in is_gpt_valid()
1154 memcpy(&dev_desc->guid_sig, &pgpt_head->disk_guid, in is_gpt_valid()
1156 } else if (mbr->unique_mbr_signature != 0) { in is_gpt_valid()
1157 dev_desc->sig_type = SIG_TYPE_MBR; in is_gpt_valid()
1158 dev_desc->mbr_sig = mbr->unique_mbr_signature; in is_gpt_valid()
1182 * @gpt - GPT header
1200 count = le32_to_cpu(pgpt_head->num_partition_entries) * in alloc_read_gpt_entries()
1201 le32_to_cpu(pgpt_head->sizeof_partition_entry); in alloc_read_gpt_entries()
1204 (u32) le32_to_cpu(pgpt_head->num_partition_entries), in alloc_read_gpt_entries()
1205 (u32) le32_to_cpu(pgpt_head->sizeof_partition_entry), in alloc_read_gpt_entries()
1221 blk = le64_to_cpu(pgpt_head->partition_entry_lba); in alloc_read_gpt_entries()
1233 * @gpt_entry - Pointer to a single Partition Table Entry
1247 * The GUID Partition Type != Unused Entry (ALL-ZERO) in is_pte_valid()
1251 if (memcmp(pte->partition_type_guid.b, unused_guid.b, in is_pte_valid()