
export the needed functions for GPT over MTD
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com Reviewed-by: Christophe KERELLO christophe.kerello@st.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v6: - add export function comment in part_efi_int.h
Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None
disk/part_efi.c | 58 +++++++------------------------------------- disk/part_efi_int.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 49 deletions(-) create mode 100644 disk/part_efi_int.h
diff --git a/disk/part_efi.c b/disk/part_efi.c index 23a582a..2d5072c 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -21,22 +21,11 @@ #include <part_efi.h> #include <linux/compiler.h> #include <linux/ctype.h> +#include "part_efi_int.h"
DECLARE_GLOBAL_DATA_PTR;
#ifdef HAVE_BLOCK_DEVICE -/** - * efi_crc32() - EFI version of crc32 function - * @buf: buffer to calculate crc32 of - * @len - length of buf - * - * Description: Returns EFI-style CRC32 value for @buf - */ -static inline u32 efi_crc32(const void *buf, u32 len) -{ - return crc32(0, buf, len); -} - /* * Private function prototypes */ @@ -47,7 +36,6 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, gpt_header *pgpt_head, gpt_entry **pgpt_pte); static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, gpt_header *pgpt_head); -static int is_pte_valid(gpt_entry * pte);
static char *print_efiname(gpt_entry *pte) { @@ -72,8 +60,7 @@ static inline int is_bootable(gpt_entry *p) sizeof(efi_guid_t)); }
-static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba, - lbaint_t lastlba) +int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba, lbaint_t lastlba) { uint32_t crc32_backup = 0; uint32_t calc_crc32; @@ -135,7 +122,7 @@ static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba, return 0; }
-static int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e) +int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e) { uint32_t calc_crc32;
@@ -155,14 +142,8 @@ static int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e) return 0; }
-/* - * prepare_backup_gpt_header() - change primary GPT header to backup GPT header - * - * @param gpt_h - pointer to GPT header (in=primary, out=secondary) - * @param pte_blk_cnt - number of block for size of partition entry array (PTE) - */ -static void prepare_backup_gpt_header(gpt_header *gpt_h, - const int pte_blk_cnt) +void prepare_backup_gpt_header(gpt_header *gpt_h, + const int pte_blk_cnt) { uint32_t calc_crc32; uint64_t val; @@ -180,14 +161,7 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h, }
#if CONFIG_IS_ENABLED(EFI_PARTITION) -/* - * part_print_gpt() - display GUID Partition Table information - * - * @param gpt_head - pointer to GPT header - * @param gpt_pte - pointer to GPT partion entry array - */ -static void part_print_gpt(gpt_header *gpt_head, - gpt_entry *gpt_pte) +void part_print_gpt(gpt_header *gpt_head, gpt_entry *gpt_pte) { int i = 0; char uuid[37]; @@ -221,16 +195,8 @@ static void part_print_gpt(gpt_header *gpt_head, } }
-/* - * part_get_disk_info() - extract partition information for one GPT entry - * - * @param part - index of entry in gpt_pte - * @param blksz - blksize - * @param gpt_pte - pointer to GPT partion entry array - * @param gpt_pte - pointer to disk partition (output) - */ -static void part_get_disk_info(int part, unsigned int blksz, - gpt_entry *gpt_pte, disk_partition_t *info) +void part_get_disk_info(int part, unsigned int blksz, + gpt_entry *gpt_pte, disk_partition_t *info) { /* The 'lbaint_t' casting may limit the maximum disk size to 2 TB */ info->start = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].starting_lba); @@ -989,13 +955,7 @@ static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, return pte; }
-/** - * is_pte_valid(): validates a single Partition Table Entry - * @gpt_entry - Pointer to a single Partition Table Entry - * - * Description: returns 1 if valid, 0 on error. - */ -static int is_pte_valid(gpt_entry * pte) +int is_pte_valid(gpt_entry *pte) { efi_guid_t unused_guid;
diff --git a/disk/part_efi_int.h b/disk/part_efi_int.h new file mode 100644 index 0000000..f381ade --- /dev/null +++ b/disk/part_efi_int.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 STMicroelectronics . + * Patrick Delaunay patrick.delaunay@st.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _DISK_PART_EFI_INT_H +#define _DISK_PART_EFI_INT_H + +/* + * efi_crc32() - EFI version of crc32 function + * @buf: buffer to calculate crc32 of + * @len - length of buf + * + * Description: Returns EFI-style CRC32 value for @buf + */ +static inline u32 efi_crc32(const void *buf, u32 len) +{ + return crc32(0, buf, len); +} + +int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba, lbaint_t lastlba); + +/** + * validate_gpt_entries(): check GPT CRC information + * @param gpt_h - pointer to GPT header + * @param gpt_e - pointer to GPT partion entry array + * + * Description: returns 1 if valid, 0 on error. + */ +int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e); + +/** + * is_pte_valid(): validates a single Partition Table Entry + * @gpt_entry - Pointer to a single Partition Table Entry + * + * Description: returns 1 if valid, 0 on error. + */ +int is_pte_valid(gpt_entry *pte); + +/* + * prepare_backup_gpt_header() - change primary GPT header to backup GPT header + * + * @param gpt_h - pointer to GPT header (in=primary, out=secondary) + * @param pte_blk_cnt - number of block for size of partition entry array (PTE) + */ +void prepare_backup_gpt_header(gpt_header *gpt_h, + const int pte_blk_cnt); + +/* + * part_print_gpt() - display GUID Partition Table information + * + * @param gpt_head - pointer to GPT header + * @param gpt_pte - pointer to GPT partion entry array + */ +void part_print_gpt(gpt_header *gpt_head, gpt_entry *gpt_pte); + +/* + * part_get_disk_info() - extract partition information for one GPT entry + * + * @param part - index of entry in gpt_pte + * @param blksz - blksize + * @param gpt_pte - pointer to GPT partion entry array + * @param gpt_pte - pointer to disk partition (output) + */ +void part_get_disk_info(int part, unsigned int blksz, + gpt_entry *gpt_pte, disk_partition_t *info); + +#endif /* _DISK_PART_EFI_INT_H */