Lines Matching refs:gpt_h

78 static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba,  in validate_gpt_header()  argument
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()
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()
97 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, 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()
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()
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()
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()
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()
141 static int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e) in validate_gpt_entries() argument
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()
161 static void prepare_backup_gpt_header(gpt_header *gpt_h) in prepare_backup_gpt_header() argument
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()
174 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, 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()
389 gpt_header *gpt_h, gpt_entry *gpt_e) in write_gpt_table() argument
391 const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries 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()
406 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, 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()
411 if (blk_dwrite(dev_desc, 1, 1, gpt_h) != 1) in write_gpt_table()
414 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), in write_gpt_table()
418 prepare_backup_gpt_header(gpt_h); 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()
425 gpt_h) != 1) in write_gpt_table()
437 gpt_header *gpt_h, gpt_entry *gpt_e, in gpt_fill_pte() argument
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()
492 gpt_e[i].ending_lba = gpt_h->last_usable_lba; in gpt_fill_pte()
603 int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, in gpt_fill_header() argument
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()
630 gpt_header *gpt_h; in gpt_restore() local
635 gpt_h = malloc_cache_aligned(size); in gpt_restore()
636 if (gpt_h == NULL) { in gpt_restore()
640 memset(gpt_h, 0, size); in gpt_restore()
647 free(gpt_h); in gpt_restore()
653 ret = gpt_fill_header(dev_desc, gpt_h, str_disk_guid, parts_count); in gpt_restore()
658 ret = gpt_fill_pte(dev_desc, gpt_h, gpt_e, partitions, parts_count); in gpt_restore()
663 ret = write_gpt_table(dev_desc, gpt_h, gpt_e); in gpt_restore()
667 free(gpt_h); in gpt_restore()
789 gpt_header *gpt_h; in is_valid_gpt_buf() local
793 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in is_valid_gpt_buf()
795 if (validate_gpt_header(gpt_h, GPT_PRIMARY_PARTITION_TABLE_LBA, in is_valid_gpt_buf()
800 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in is_valid_gpt_buf()
802 if (validate_gpt_entries(gpt_h, gpt_e)) in is_valid_gpt_buf()
810 gpt_header *gpt_h; in write_mbr_and_gpt_partitions() local
820 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in write_mbr_and_gpt_partitions()
824 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * 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()
842 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
848 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
856 prepare_backup_gpt_header(gpt_h); in write_mbr_and_gpt_partitions()
859 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
867 lba = le64_to_cpu(gpt_h->my_lba); in write_mbr_and_gpt_partitions()
869 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()