Lines Matching refs:gpt_h
91 static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba, in validate_gpt_header() argument
98 if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE_UBOOT) { in validate_gpt_header()
101 le64_to_cpu(gpt_h->signature), in validate_gpt_header()
107 memcpy(&crc32_backup, &gpt_h->header_crc32, sizeof(crc32_backup)); in validate_gpt_header()
108 memset(&gpt_h->header_crc32, 0, sizeof(gpt_h->header_crc32)); in validate_gpt_header()
110 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in validate_gpt_header()
111 le32_to_cpu(gpt_h->header_size)); in validate_gpt_header()
113 memcpy(&gpt_h->header_crc32, &crc32_backup, sizeof(crc32_backup)); in validate_gpt_header()
125 if (le64_to_cpu(gpt_h->my_lba) != lba) { in validate_gpt_header()
127 le64_to_cpu(gpt_h->my_lba), in validate_gpt_header()
136 if (le64_to_cpu(gpt_h->first_usable_lba) > lastlba) { in validate_gpt_header()
138 le64_to_cpu(gpt_h->first_usable_lba), lastlba); in validate_gpt_header()
141 if (le64_to_cpu(gpt_h->last_usable_lba) > lastlba) { in validate_gpt_header()
143 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
148 LBAF "\n", le64_to_cpu(gpt_h->first_usable_lba), in validate_gpt_header()
149 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
154 static int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e) in validate_gpt_entries() argument
160 le32_to_cpu(gpt_h->num_partition_entries) * in validate_gpt_entries()
161 le32_to_cpu(gpt_h->sizeof_partition_entry)); in validate_gpt_entries()
163 if (calc_crc32 != le32_to_cpu(gpt_h->partition_entry_array_crc32)) { in validate_gpt_entries()
166 le32_to_cpu(gpt_h->partition_entry_array_crc32), in validate_gpt_entries()
174 static void prepare_backup_gpt_header(gpt_header *gpt_h) in prepare_backup_gpt_header() argument
180 val = le64_to_cpu(gpt_h->my_lba); in prepare_backup_gpt_header()
181 gpt_h->my_lba = gpt_h->alternate_lba; in prepare_backup_gpt_header()
182 gpt_h->alternate_lba = cpu_to_le64(val); in prepare_backup_gpt_header()
183 gpt_h->partition_entry_lba = in prepare_backup_gpt_header()
184 cpu_to_le64(le64_to_cpu(gpt_h->last_usable_lba) + 1); in prepare_backup_gpt_header()
185 gpt_h->header_crc32 = 0; in prepare_backup_gpt_header()
187 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in prepare_backup_gpt_header()
188 le32_to_cpu(gpt_h->header_size)); in prepare_backup_gpt_header()
189 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in prepare_backup_gpt_header()
372 gpt_header *gpt_h, gpt_entry *gpt_e) in write_gpt_table() argument
374 const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries in write_gpt_table()
385 le32_to_cpu(gpt_h->num_partition_entries) * in write_gpt_table()
386 le32_to_cpu(gpt_h->sizeof_partition_entry)); in write_gpt_table()
387 gpt_h->partition_entry_array_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
389 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in write_gpt_table()
390 le32_to_cpu(gpt_h->header_size)); in write_gpt_table()
391 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
394 if (blk_dwrite(dev_desc, 1, 1, gpt_h) != 1) in write_gpt_table()
397 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), in write_gpt_table()
401 prepare_backup_gpt_header(gpt_h); in write_gpt_table()
403 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) in write_gpt_table()
407 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, in write_gpt_table()
408 gpt_h) != 1) in write_gpt_table()
420 gpt_header *gpt_h, gpt_entry *gpt_e, in gpt_fill_pte() argument
423 lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba); in gpt_fill_pte()
425 le64_to_cpu(gpt_h->last_usable_lba); in gpt_fill_pte()
436 size_t hdr_start = gpt_h->my_lba; in gpt_fill_pte()
439 size_t pte_start = gpt_h->partition_entry_lba; in gpt_fill_pte()
441 gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry / in gpt_fill_pte()
475 gpt_e[i].ending_lba = gpt_h->last_usable_lba; in gpt_fill_pte()
586 int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, in gpt_fill_header() argument
589 gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE_UBOOT); in gpt_fill_header()
590 gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1); in gpt_fill_header()
591 gpt_h->header_size = cpu_to_le32(sizeof(gpt_header)); in gpt_fill_header()
592 gpt_h->my_lba = cpu_to_le64(1); in gpt_fill_header()
593 gpt_h->alternate_lba = cpu_to_le64(dev_desc->lba - 1); in gpt_fill_header()
594 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in gpt_fill_header()
595 gpt_h->partition_entry_lba = in gpt_fill_header()
597 gpt_h->first_usable_lba = in gpt_fill_header()
598 cpu_to_le64(le64_to_cpu(gpt_h->partition_entry_lba) + 32); in gpt_fill_header()
599 gpt_h->num_partition_entries = cpu_to_le32(GPT_ENTRY_NUMBERS); in gpt_fill_header()
600 gpt_h->sizeof_partition_entry = cpu_to_le32(sizeof(gpt_entry)); in gpt_fill_header()
601 gpt_h->header_crc32 = 0; in gpt_fill_header()
602 gpt_h->partition_entry_array_crc32 = 0; in gpt_fill_header()
604 if (uuid_str_to_bin(str_guid, gpt_h->disk_guid.b, UUID_STR_FORMAT_GUID)) in gpt_fill_header()
613 gpt_header *gpt_h; in gpt_restore() local
618 gpt_h = malloc_cache_aligned(size); in gpt_restore()
619 if (gpt_h == NULL) { in gpt_restore()
623 memset(gpt_h, 0, size); in gpt_restore()
630 free(gpt_h); in gpt_restore()
636 ret = gpt_fill_header(dev_desc, gpt_h, str_disk_guid, parts_count); in gpt_restore()
641 ret = gpt_fill_pte(dev_desc, gpt_h, gpt_e, partitions, parts_count); in gpt_restore()
646 ret = write_gpt_table(dev_desc, gpt_h, gpt_e); in gpt_restore()
650 free(gpt_h); in gpt_restore()
785 gpt_header *gpt_h; in is_valid_gpt_buf() local
789 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in is_valid_gpt_buf()
791 if (validate_gpt_header(gpt_h, GPT_PRIMARY_PARTITION_TABLE_LBA, in is_valid_gpt_buf()
796 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in is_valid_gpt_buf()
798 if (validate_gpt_entries(gpt_h, gpt_e)) in is_valid_gpt_buf()
806 gpt_header *gpt_h; in write_mbr_and_gpt_partitions() local
816 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in write_mbr_and_gpt_partitions()
820 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in write_mbr_and_gpt_partitions()
822 gpt_e_blk_cnt = BLOCK_CNT((le32_to_cpu(gpt_h->num_partition_entries) * in write_mbr_and_gpt_partitions()
823 le32_to_cpu(gpt_h->sizeof_partition_entry)), in write_mbr_and_gpt_partitions()
838 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
844 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
852 prepare_backup_gpt_header(gpt_h); in write_mbr_and_gpt_partitions()
855 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
863 lba = le64_to_cpu(gpt_h->my_lba); in write_mbr_and_gpt_partitions()
865 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()