Lines Matching +full:boot +full:- +full:blks

1 // SPDX-License-Identifier: GPL-2.0+
32 * efi_crc32() - EFI version of crc32 function
34 * @len - length of buf
36 * Description: Returns EFI-style CRC32 value for @buf
61 c = pte->partition_name[i] & 0xff; in print_efiname()
73 return p->attributes.fields.legacy_bios_bootable || in is_bootable()
74 !memcmp(&(p->partition_type_guid), &system_guid, in is_bootable()
85 if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE_UBOOT) { in validate_gpt_header()
88 le64_to_cpu(gpt_h->signature), in validate_gpt_header()
90 return -1; in validate_gpt_header()
94 memcpy(&crc32_backup, &gpt_h->header_crc32, sizeof(crc32_backup)); in validate_gpt_header()
95 memset(&gpt_h->header_crc32, 0, sizeof(gpt_h->header_crc32)); in validate_gpt_header()
98 le32_to_cpu(gpt_h->header_size)); in validate_gpt_header()
100 memcpy(&gpt_h->header_crc32, &crc32_backup, sizeof(crc32_backup)); in validate_gpt_header()
106 return -1; in validate_gpt_header()
112 if (le64_to_cpu(gpt_h->my_lba) != lba) { in validate_gpt_header()
114 le64_to_cpu(gpt_h->my_lba), in validate_gpt_header()
116 return -1; in validate_gpt_header()
123 if (le64_to_cpu(gpt_h->first_usable_lba) > lastlba) { in validate_gpt_header()
125 le64_to_cpu(gpt_h->first_usable_lba), lastlba); in validate_gpt_header()
126 return -1; in validate_gpt_header()
128 if (le64_to_cpu(gpt_h->last_usable_lba) > lastlba) { in validate_gpt_header()
130 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
131 return -1; in validate_gpt_header()
135 LBAF "\n", le64_to_cpu(gpt_h->first_usable_lba), in validate_gpt_header()
136 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
147 le32_to_cpu(gpt_h->num_partition_entries) * in validate_gpt_entries()
148 le32_to_cpu(gpt_h->sizeof_partition_entry)); in validate_gpt_entries()
150 if (calc_crc32 != le32_to_cpu(gpt_h->partition_entry_array_crc32)) { in validate_gpt_entries()
153 le32_to_cpu(gpt_h->partition_entry_array_crc32), in validate_gpt_entries()
155 return -1; in validate_gpt_entries()
167 val = le64_to_cpu(gpt_h->my_lba); in prepare_backup_gpt_header()
168 gpt_h->my_lba = gpt_h->alternate_lba; in prepare_backup_gpt_header()
169 gpt_h->alternate_lba = cpu_to_le64(val); in prepare_backup_gpt_header()
170 gpt_h->partition_entry_lba = in prepare_backup_gpt_header()
171 cpu_to_le64(le64_to_cpu(gpt_h->last_usable_lba) + 1); in prepare_backup_gpt_header()
172 gpt_h->header_crc32 = 0; in prepare_backup_gpt_header()
175 le32_to_cpu(gpt_h->header_size)); in prepare_backup_gpt_header()
176 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in prepare_backup_gpt_header()
186 * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
190 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in get_disk_guid()
198 if (is_gpt_valid(dev_desc, dev_desc->lba - 1, in get_disk_guid()
202 return -EINVAL; in get_disk_guid()
209 guid_bin = gpt_head->disk_guid.b; in get_disk_guid()
217 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in part_print_efi()
227 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_print_efi()
238 debug("%s: gpt-entry at %p\n", __func__, gpt_pte); in part_print_efi()
245 for (i = 0; i < le32_to_cpu(gpt_head->num_partition_entries); i++) { in part_print_efi()
275 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in part_get_info_efi()
281 return -1; in part_get_info_efi()
288 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_get_info_efi()
292 return -1; in part_get_info_efi()
299 if (part > le32_to_cpu(gpt_head->num_partition_entries) || in part_get_info_efi()
300 !is_pte_valid(&gpt_pte[part - 1])) { in part_get_info_efi()
304 return -1; in part_get_info_efi()
308 info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba); in part_get_info_efi()
310 info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1 in part_get_info_efi()
311 - info->start; in part_get_info_efi()
312 info->blksz = dev_desc->blksz; in part_get_info_efi()
314 sprintf((char *)info->name, "%s", in part_get_info_efi()
315 print_efiname(&gpt_pte[part - 1])); in part_get_info_efi()
316 strcpy((char *)info->type, "U-Boot"); in part_get_info_efi()
317 info->bootable = is_bootable(&gpt_pte[part - 1]); in part_get_info_efi()
319 uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid, in part_get_info_efi()
323 uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, in part_get_info_efi()
324 info->type_guid, UUID_STR_FORMAT_GUID); in part_get_info_efi()
328 info->start, info->size, info->name); in part_get_info_efi()
337 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz); in part_test_efi()
342 return -1; in part_test_efi()
349 * @param dev_desc - block device descriptor
351 * @return - zero on success, otherwise error
356 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, p_mbr, 1, dev_desc->blksz); in set_protective_mbr()
359 return -1; in set_protective_mbr()
362 /* Read MBR to backup boot code if it exists */ in set_protective_mbr()
364 pr_err("** Can't read from device %d **\n", dev_desc->devnum); in set_protective_mbr()
365 return -1; in set_protective_mbr()
368 /* Clear all data in MBR except of backed up boot code */ in set_protective_mbr()
369 memset((char *)p_mbr + MSDOS_MBR_BOOT_CODE_SIZE, 0, sizeof(*p_mbr) - in set_protective_mbr()
373 p_mbr->signature = MSDOS_MBR_SIGNATURE; in set_protective_mbr()
374 p_mbr->partition_record[0].sys_ind = EFI_PMBR_OSTYPE_EFI_GPT; in set_protective_mbr()
375 p_mbr->partition_record[0].start_sect = 1; in set_protective_mbr()
376 p_mbr->partition_record[0].nr_sects = (u32) dev_desc->lba - 1; in set_protective_mbr()
381 dev_desc->devnum); in set_protective_mbr()
382 return -1; in set_protective_mbr()
391 const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries in write_gpt_table()
395 debug("max lba: %x\n", (u32) dev_desc->lba); in write_gpt_table()
402 le32_to_cpu(gpt_h->num_partition_entries) * in write_gpt_table()
403 le32_to_cpu(gpt_h->sizeof_partition_entry)); in write_gpt_table()
404 gpt_h->partition_entry_array_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
407 le32_to_cpu(gpt_h->header_size)); in write_gpt_table()
408 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
414 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), in write_gpt_table()
420 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) in write_gpt_table()
424 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, in write_gpt_table()
432 printf("** Can't write to device %d **\n", dev_desc->devnum); in write_gpt_table()
433 return -1; in write_gpt_table()
440 lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba); in gpt_fill_pte()
442 le64_to_cpu(gpt_h->last_usable_lba); in gpt_fill_pte()
453 size_t hdr_start = gpt_h->my_lba; in gpt_fill_pte()
456 size_t pte_start = gpt_h->partition_entry_lba; in gpt_fill_pte()
458 gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry / in gpt_fill_pte()
459 dev_desc->blksz; in gpt_fill_pte()
480 return -1; in gpt_fill_pte()
487 return -1; in gpt_fill_pte()
490 if ((i == parts - 1) && (size == 0)) in gpt_fill_pte()
492 gpt_e[i].ending_lba = gpt_h->last_usable_lba; in gpt_fill_pte()
494 gpt_e[i].ending_lba = cpu_to_le64(offset - 1); in gpt_fill_pte()
504 return -1; in gpt_fill_pte()
524 return -1; in gpt_fill_pte()
573 offset_blks = offset_bytes / dev_desc->blksz; in partition_entries_offset()
582 config_offset = fdtdec_get_config_int(gd->fdt_blob, in partition_entries_offset()
583 "u-boot,efi-partition-entries-offset", in partition_entries_offset()
584 -EINVAL); in partition_entries_offset()
585 if (config_offset != -EINVAL) { in partition_entries_offset()
587 offset_blks = offset_bytes / dev_desc->blksz; in partition_entries_offset()
606 gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE_UBOOT); in gpt_fill_header()
607 gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1); in gpt_fill_header()
608 gpt_h->header_size = cpu_to_le32(sizeof(gpt_header)); in gpt_fill_header()
609 gpt_h->my_lba = cpu_to_le64(1); in gpt_fill_header()
610 gpt_h->alternate_lba = cpu_to_le64(dev_desc->lba - 1); in gpt_fill_header()
611 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in gpt_fill_header()
612 gpt_h->partition_entry_lba = in gpt_fill_header()
614 gpt_h->first_usable_lba = in gpt_fill_header()
615 cpu_to_le64(le64_to_cpu(gpt_h->partition_entry_lba) + 32); in gpt_fill_header()
616 gpt_h->num_partition_entries = cpu_to_le32(GPT_ENTRY_NUMBERS); in gpt_fill_header()
617 gpt_h->sizeof_partition_entry = cpu_to_le32(sizeof(gpt_entry)); in gpt_fill_header()
618 gpt_h->header_crc32 = 0; in gpt_fill_header()
619 gpt_h->partition_entry_array_crc32 = 0; in gpt_fill_header()
621 if (uuid_str_to_bin(str_guid, gpt_h->disk_guid.b, UUID_STR_FORMAT_GUID)) in gpt_fill_header()
622 return -1; in gpt_fill_header()
638 return -1; in gpt_restore()
648 return -1; in gpt_restore()
697 return -1; in gpt_verify_headers()
699 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in gpt_verify_headers()
703 return -1; in gpt_verify_headers()
725 if (i == gpt_head->num_partition_entries) { in gpt_verify_partitions()
727 return -1; in gpt_verify_partitions()
734 debug("%s: part: %2d name - GPT: %16s, ENV: %16s ", in gpt_verify_partitions()
738 sizeof(partitions->name))) { in gpt_verify_partitions()
741 return -1; in gpt_verify_partitions()
745 gpt_part_size = le64_to_cpu(gpt_e[i].ending_lba) - in gpt_verify_partitions()
747 debug("size(LBA) - GPT: %8llu, ENV: %8llu ", in gpt_verify_partitions()
753 if ((i == parts - 1) && (partitions[i].size == 0)) in gpt_verify_partitions()
759 return -1; in gpt_verify_partitions()
763 * Start address is optional - check only if provided in gpt_verify_partitions()
772 debug("start LBA - GPT: %8llu, ENV: %8llu\n", in gpt_verify_partitions()
780 return -1; in gpt_verify_partitions()
794 dev_desc->blksz); in is_valid_gpt_buf()
796 dev_desc->lba)) in is_valid_gpt_buf()
797 return -1; in is_valid_gpt_buf()
800 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in is_valid_gpt_buf()
801 dev_desc->blksz); in is_valid_gpt_buf()
803 return -1; in is_valid_gpt_buf()
817 return -1; in write_mbr_and_gpt_partitions()
821 dev_desc->blksz); in write_mbr_and_gpt_partitions()
824 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in write_mbr_and_gpt_partitions()
825 dev_desc->blksz); in write_mbr_and_gpt_partitions()
826 gpt_e_blk_cnt = BLOCK_CNT((le32_to_cpu(gpt_h->num_partition_entries) * in write_mbr_and_gpt_partitions()
827 le32_to_cpu(gpt_h->sizeof_partition_entry)), in write_mbr_and_gpt_partitions()
834 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
843 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
848 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
851 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
859 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
862 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
867 lba = le64_to_cpu(gpt_h->my_lba); in write_mbr_and_gpt_partitions()
870 printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n", in write_mbr_and_gpt_partitions()
889 if (part->sys_ind == EFI_PMBR_OSTYPE_EFI_GPT && in pmbr_part_valid()
890 get_unaligned_le32(&part->start_sect) == 1UL) { in pmbr_part_valid()
909 if (!mbr || le16_to_cpu(mbr->signature) != MSDOS_MBR_SIGNATURE) in is_pmbr_valid()
913 if (pmbr_part_valid(&mbr->partition_record[i])) { in is_pmbr_valid()
921 * is_gpt_valid() - tests one GPT header and PTEs for validity
939 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, mbr, 1, dev_desc->blksz); in is_gpt_valid()
953 if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba)) in is_gpt_valid()
956 if (dev_desc->sig_type == SIG_TYPE_NONE) { in is_gpt_valid()
958 if (memcmp(&pgpt_head->disk_guid, &empty, sizeof(empty))) { in is_gpt_valid()
959 dev_desc->sig_type = SIG_TYPE_GUID; in is_gpt_valid()
960 memcpy(&dev_desc->guid_sig, &pgpt_head->disk_guid, in is_gpt_valid()
962 } else if (mbr->unique_mbr_signature != 0) { in is_gpt_valid()
963 dev_desc->sig_type = SIG_TYPE_MBR; in is_gpt_valid()
964 dev_desc->mbr_sig = mbr->unique_mbr_signature; in is_gpt_valid()
987 * @gpt - GPT header
1005 count = le32_to_cpu(pgpt_head->num_partition_entries) * in alloc_read_gpt_entries()
1006 le32_to_cpu(pgpt_head->sizeof_partition_entry); in alloc_read_gpt_entries()
1009 (u32) le32_to_cpu(pgpt_head->num_partition_entries), in alloc_read_gpt_entries()
1010 (u32) le32_to_cpu(pgpt_head->sizeof_partition_entry), in alloc_read_gpt_entries()
1026 blk = le64_to_cpu(pgpt_head->partition_entry_lba); in alloc_read_gpt_entries()
1038 * @gpt_entry - Pointer to a single Partition Table Entry
1052 * The GUID Partition Type != Unused Entry (ALL-ZERO) in is_pte_valid()
1056 if (memcmp(pte->partition_type_guid.b, unused_guid.b, in is_pte_valid()