diff mbox series

[RFC,01/10] GPT: Add function to get gpt header and partition entries

Message ID 20211125070146.2389-2-sughosh.ganu@linaro.org
State Superseded
Headers show
Series FWU: Add support for FWU Multi Bank Update feature | expand

Commit Message

Sughosh Ganu Nov. 25, 2021, 7:01 a.m. UTC
Add function to get the gpt header and partition entries filled. These
would be used subsequently for multi bank firmware update support on
devices where the images reside on GPT partitions.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
 disk/part_efi.c | 10 ++++++++++
 include/part.h  | 14 ++++++++++++++
 2 files changed, 24 insertions(+)

Comments

Patrick Delaunay Dec. 7, 2021, 3:35 p.m. UTC | #1
Hi Sugosh

On 11/25/21 8:01 AM, Sughosh Ganu wrote:

Add function to get the gpt header and partition entries filled. These
would be used subsequently for multi bank firmware update support on
devices where the images reside on GPT partitions.
 
Signed-off-by: Sughosh Ganu  <mailto:sughosh.ganu@linaro.org>
<sughosh.ganu@linaro.org>
---
 disk/part_efi.c | 10 ++++++++++
 include/part.h  | 14 ++++++++++++++
 2 files changed, 24 insertions(+)
 
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 0ca7effc32..792b9218a9 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -216,6 +216,16 @@ int get_disk_guid(struct blk_desc * dev_desc, char
*guid)
  return 0;
 }
 
+int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
+              gpt_entry **gpt_pte)
+{
+ /* This function validates and fills in the GPT header and PTE's */
+ if (find_valid_gpt(desc, gpt_head, gpt_pte) != 1)
+        return -EINVAL;
+
+ return 0;
+}
+
 void part_print_efi(struct blk_desc *dev_desc)
 {
  ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
diff --git a/include/part.h b/include/part.h
index b66b07a1f0..8e86485b97 100644
--- a/include/part.h
+++ b/include/part.h
@@ -345,6 +345,20 @@ struct part_driver {
 
 #if CONFIG_IS_ENABLED(EFI_PARTITION)
 /* disk/part_efi.c */
+
+/**
+ * get_gpt_hdr_parts() - Get information on the GPT Header and
+ *                       Partition Table Entries
+ *
+ * @param desc - block device descriptor
+ * @param gpt_h - pointer to GPT header representation





gpt_h need to be allocated / DMA alligned by caller

 
+ * @param gpt_e - pointer to GPT partition table entries

 

gpt_e is allocated in this fucntion need to freed by caller





+ *
+ * @return - zero on success, otherwise error
+ */
+int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
+              gpt_entry **gpt_pte);
+
 /**
  * write_gpt_table() - Write the GUID Partition Table to disk
  *

no need to export the low level function "find_valid_gpt"

 

the same services are already provided by part_get_info()  ?


ST Restricted

2 information are used in the serie
 
=> gpt_head->num_partition_entries
=> &gpt_pte[i].partition_type_guid
 
 
type_guid is available in disk_partition,
and num_partition_entries is not needed (replaced by MAX_SEARCH_PARTITIONS)
 
something like:
 
        struct disk_partition info;
 
        for (p = 1; p < MAX_SEARCH_PARTITIONS; p++) {
               if (part_get_info(desc, p, &info))
                       continue;
               => info.type_guid 
        }
 
Regards
 
Patrick
Sughosh Ganu Dec. 8, 2021, 7:40 a.m. UTC | #2
hi Patrick,

On Tue, 7 Dec 2021 at 21:05, Patrick DELAUNAY <patrick.delaunay@foss.st.com>
wrote:

> Hi Sugosh
>
> On 11/25/21 8:01 AM, Sughosh Ganu wrote:
>
> Add function to get the gpt header and partition entries filled. These
>
> would be used subsequently for multi bank firmware update support on
>
> devices where the images reside on GPT partitions.
>
>
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> <sughosh.ganu@linaro.org>
>
> ---
>
>  disk/part_efi.c | 10 ++++++++++
>
>  include/part.h  | 14 ++++++++++++++
>
>  2 files changed, 24 insertions(+)
>
>
>
> diff --git a/disk/part_efi.c b/disk/part_efi.c
>
> index 0ca7effc32..792b9218a9 100644
>
> --- a/disk/part_efi.c
>
> +++ b/disk/part_efi.c
>
> @@ -216,6 +216,16 @@ int get_disk_guid(struct blk_desc * dev_desc, char *guid)
>
>   return 0;
>
>  }
>
>  +int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
>
> +              gpt_entry **gpt_pte)
>
> +{
>
> + /* This function validates and fills in the GPT header and PTE's */
>
> + if (find_valid_gpt(desc, gpt_head, gpt_pte) != 1)
>
> +        return -EINVAL;
>
> +
>
> + return 0;
>
> +}
>
> +
>
>  void part_print_efi(struct blk_desc *dev_desc)
>
>  {
>
>   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
>
> diff --git a/include/part.h b/include/part.h
>
> index b66b07a1f0..8e86485b97 100644
>
> --- a/include/part.h
>
> +++ b/include/part.h
>
> @@ -345,6 +345,20 @@ struct part_driver {
>
>   #if CONFIG_IS_ENABLED(EFI_PARTITION)
>
>  /* disk/part_efi.c */
>
> +
>
> +/**
>
> + * get_gpt_hdr_parts() - Get information on the GPT Header and
>
> + *                       Partition Table Entries
>
> + *
>
> + * @param desc - block device descriptor
>
> + * @param gpt_h - pointer to GPT header representation
>
>
>
> gpt_h need to be allocated / DMA alligned by caller
>
>
Will add this comment to the description.


>
>
> + * @param gpt_e - pointer to GPT partition table entries
>
>
>
> gpt_e is allocated in this fucntion need to freed by caller
>
>
 Will add this comment to the description.

>
>
> + *
>
> + * @return - zero on success, otherwise error
>
> + */
>
> +int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
>
> +              gpt_entry **gpt_pte);
>
> +
>
>  /**
>
>   * write_gpt_table() - Write the GUID Partition Table to disk
>
>   *
>
> no need to export the low level function "find_valid_gpt"
>
>
find_valid_gpt is not being exported. It is defined statically in
part_efi.c. Do i misunderstand your comment?


>
>
> the same services are already provided by part_get_info()  ?
>
> ST Restricted
>
> 2 information are used in the serie
>
>
>
> => gpt_head->num_partition_entries
>
> => &gpt_pte[i].partition_type_guid
>
>
>
>
>
> type_guid is available in disk_partition,
>
> and num_partition_entries is not needed (replaced by MAX_SEARCH_PARTITIONS)
>
>
>
> something like:
>
>
>
>         struct disk_partition info;
>
>
>
>         for (p = 1; p < MAX_SEARCH_PARTITIONS; p++) {
>
>                if (part_get_info(desc, p, &info))
>
>                        continue;
>
>                => info.type_guid
>
>         }
>
>
I had actually explored using part_get_info. But the type_guid field is
actually a char string. While I need the guid value to compare it using
guidcmp. Which is the reason I introduced get_gpt_hdr_parts.

 -sughosh


>
> Regards
>
>
>
> Patrick
>
>
AKASHI Takahiro Dec. 9, 2021, 1:32 a.m. UTC | #3
On Wed, Dec 08, 2021 at 01:10:51PM +0530, Sughosh Ganu wrote:
> hi Patrick,
> 
> On Tue, 7 Dec 2021 at 21:05, Patrick DELAUNAY <patrick.delaunay@foss.st.com>
> wrote:
> 
> > Hi Sugosh
> >
> > On 11/25/21 8:01 AM, Sughosh Ganu wrote:
> >
> > Add function to get the gpt header and partition entries filled. These
> >
> > would be used subsequently for multi bank firmware update support on
> >
> > devices where the images reside on GPT partitions.
> >
> >
> >
> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> <sughosh.ganu@linaro.org>
> >
> > ---
> >
> >  disk/part_efi.c | 10 ++++++++++
> >
> >  include/part.h  | 14 ++++++++++++++
> >
> >  2 files changed, 24 insertions(+)
> >
> >
> >
> > diff --git a/disk/part_efi.c b/disk/part_efi.c
> >
> > index 0ca7effc32..792b9218a9 100644
> >
> > --- a/disk/part_efi.c
> >
> > +++ b/disk/part_efi.c
> >
> > @@ -216,6 +216,16 @@ int get_disk_guid(struct blk_desc * dev_desc, char *guid)
> >
> >   return 0;
> >
> >  }
> >
> >  +int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
> >
> > +              gpt_entry **gpt_pte)
> >
> > +{
> >
> > + /* This function validates and fills in the GPT header and PTE's */
> >
> > + if (find_valid_gpt(desc, gpt_head, gpt_pte) != 1)
> >
> > +        return -EINVAL;
> >
> > +
> >
> > + return 0;
> >
> > +}
> >
> > +
> >
> >  void part_print_efi(struct blk_desc *dev_desc)
> >
> >  {
> >
> >   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
> >
> > diff --git a/include/part.h b/include/part.h
> >
> > index b66b07a1f0..8e86485b97 100644
> >
> > --- a/include/part.h
> >
> > +++ b/include/part.h
> >
> > @@ -345,6 +345,20 @@ struct part_driver {
> >
> >   #if CONFIG_IS_ENABLED(EFI_PARTITION)
> >
> >  /* disk/part_efi.c */
> >
> > +
> >
> > +/**
> >
> > + * get_gpt_hdr_parts() - Get information on the GPT Header and
> >
> > + *                       Partition Table Entries
> >
> > + *
> >
> > + * @param desc - block device descriptor
> >
> > + * @param gpt_h - pointer to GPT header representation
> >
> >
> >
> > gpt_h need to be allocated / DMA alligned by caller
> >
> >
> Will add this comment to the description.
> 
> 
> >
> >
> > + * @param gpt_e - pointer to GPT partition table entries
> >
> >
> >
> > gpt_e is allocated in this fucntion need to freed by caller
> >
> >
>  Will add this comment to the description.
> 
> >
> >
> > + *
> >
> > + * @return - zero on success, otherwise error
> >
> > + */
> >
> > +int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
> >
> > +              gpt_entry **gpt_pte);
> >
> > +
> >
> >  /**
> >
> >   * write_gpt_table() - Write the GUID Partition Table to disk
> >
> >   *
> >
> > no need to export the low level function "find_valid_gpt"
> >
> >
> find_valid_gpt is not being exported. It is defined statically in
> part_efi.c. Do i misunderstand your comment?
> 
> 
> >
> >
> > the same services are already provided by part_get_info()  ?
> >
> > ST Restricted
> >
> > 2 information are used in the serie
> >
> >
> >
> > => gpt_head->num_partition_entries
> >
> > => &gpt_pte[i].partition_type_guid
> >
> >
> >
> >
> >
> > type_guid is available in disk_partition,
> >
> > and num_partition_entries is not needed (replaced by MAX_SEARCH_PARTITIONS)
> >
> >
> >
> > something like:
> >
> >
> >
> >         struct disk_partition info;
> >
> >
> >
> >         for (p = 1; p < MAX_SEARCH_PARTITIONS; p++) {
> >
> >                if (part_get_info(desc, p, &info))
> >
> >                        continue;
> >
> >                => info.type_guid
> >
> >         }
> >
> >
> I had actually explored using part_get_info. But the type_guid field is
> actually a char string. While I need the guid value to compare it using
> guidcmp. Which is the reason I introduced get_gpt_hdr_parts.

Think of using uuid_str_to_bin() if this is the only reason.

-Takahiro Akashi


>  -sughosh
> 
> 
> >
> > Regards
> >
> >
> >
> > Patrick
> >
> >
Sughosh Ganu Dec. 9, 2021, 9 a.m. UTC | #4
On Thu, 9 Dec 2021 at 07:02, AKASHI Takahiro <takahiro.akashi@linaro.org>
wrote:

> On Wed, Dec 08, 2021 at 01:10:51PM +0530, Sughosh Ganu wrote:
> > hi Patrick,
> >
> > On Tue, 7 Dec 2021 at 21:05, Patrick DELAUNAY <
> patrick.delaunay@foss.st.com>
> > wrote:
> >
> > > Hi Sugosh
> > >
> > > On 11/25/21 8:01 AM, Sughosh Ganu wrote:
> > >
> > > Add function to get the gpt header and partition entries filled. These
> > >
> > > would be used subsequently for multi bank firmware update support on
> > >
> > > devices where the images reside on GPT partitions.
> > >
> > >
> > >
> > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> <
> sughosh.ganu@linaro.org>
> > >
> > > ---
> > >
> > >  disk/part_efi.c | 10 ++++++++++
> > >
> > >  include/part.h  | 14 ++++++++++++++
> > >
> > >  2 files changed, 24 insertions(+)
> > >
> > >
> > >
> > > diff --git a/disk/part_efi.c b/disk/part_efi.c
> > >
> > > index 0ca7effc32..792b9218a9 100644
> > >
> > > --- a/disk/part_efi.c
> > >
> > > +++ b/disk/part_efi.c
> > >
> > > @@ -216,6 +216,16 @@ int get_disk_guid(struct blk_desc * dev_desc,
> char *guid)
> > >
> > >   return 0;
> > >
> > >  }
> > >
> > >  +int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
> > >
> > > +              gpt_entry **gpt_pte)
> > >
> > > +{
> > >
> > > + /* This function validates and fills in the GPT header and PTE's */
> > >
> > > + if (find_valid_gpt(desc, gpt_head, gpt_pte) != 1)
> > >
> > > +        return -EINVAL;
> > >
> > > +
> > >
> > > + return 0;
> > >
> > > +}
> > >
> > > +
> > >
> > >  void part_print_efi(struct blk_desc *dev_desc)
> > >
> > >  {
> > >
> > >   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1,
> dev_desc->blksz);
> > >
> > > diff --git a/include/part.h b/include/part.h
> > >
> > > index b66b07a1f0..8e86485b97 100644
> > >
> > > --- a/include/part.h
> > >
> > > +++ b/include/part.h
> > >
> > > @@ -345,6 +345,20 @@ struct part_driver {
> > >
> > >   #if CONFIG_IS_ENABLED(EFI_PARTITION)
> > >
> > >  /* disk/part_efi.c */
> > >
> > > +
> > >
> > > +/**
> > >
> > > + * get_gpt_hdr_parts() - Get information on the GPT Header and
> > >
> > > + *                       Partition Table Entries
> > >
> > > + *
> > >
> > > + * @param desc - block device descriptor
> > >
> > > + * @param gpt_h - pointer to GPT header representation
> > >
> > >
> > >
> > > gpt_h need to be allocated / DMA alligned by caller
> > >
> > >
> > Will add this comment to the description.
> >
> >
> > >
> > >
> > > + * @param gpt_e - pointer to GPT partition table entries
> > >
> > >
> > >
> > > gpt_e is allocated in this fucntion need to freed by caller
> > >
> > >
> >  Will add this comment to the description.
> >
> > >
> > >
> > > + *
> > >
> > > + * @return - zero on success, otherwise error
> > >
> > > + */
> > >
> > > +int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
> > >
> > > +              gpt_entry **gpt_pte);
> > >
> > > +
> > >
> > >  /**
> > >
> > >   * write_gpt_table() - Write the GUID Partition Table to disk
> > >
> > >   *
> > >
> > > no need to export the low level function "find_valid_gpt"
> > >
> > >
> > find_valid_gpt is not being exported. It is defined statically in
> > part_efi.c. Do i misunderstand your comment?
> >
> >
> > >
> > >
> > > the same services are already provided by part_get_info()  ?
> > >
> > > ST Restricted
> > >
> > > 2 information are used in the serie
> > >
> > >
> > >
> > > => gpt_head->num_partition_entries
> > >
> > > => &gpt_pte[i].partition_type_guid
> > >
> > >
> > >
> > >
> > >
> > > type_guid is available in disk_partition,
> > >
> > > and num_partition_entries is not needed (replaced by
> MAX_SEARCH_PARTITIONS)
> > >
> > >
> > >
> > > something like:
> > >
> > >
> > >
> > >         struct disk_partition info;
> > >
> > >
> > >
> > >         for (p = 1; p < MAX_SEARCH_PARTITIONS; p++) {
> > >
> > >                if (part_get_info(desc, p, &info))
> > >
> > >                        continue;
> > >
> > >                => info.type_guid
> > >
> > >         }
> > >
> > >
> > I had actually explored using part_get_info. But the type_guid field is
> > actually a char string. While I need the guid value to compare it using
> > guidcmp. Which is the reason I introduced get_gpt_hdr_parts.
>
> Think of using uuid_str_to_bin() if this is the only reason.
>

Will check if i can use this function. Thanks.

-sughosh


>
> -Takahiro Akashi
>
>
> >  -sughosh
> >
> >
> > >
> > > Regards
> > >
> > >
> > >
> > > Patrick
> > >
> > >
>
diff mbox series

Patch

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 0ca7effc32..792b9218a9 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -216,6 +216,16 @@  int get_disk_guid(struct blk_desc * dev_desc, char *guid)
 	return 0;
 }
 
+int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
+		      gpt_entry **gpt_pte)
+{
+	/* This function validates and fills in the GPT header and PTE's */
+	if (find_valid_gpt(desc, gpt_head, gpt_pte) != 1)
+		return -EINVAL;
+
+	return 0;
+}
+
 void part_print_efi(struct blk_desc *dev_desc)
 {
 	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
diff --git a/include/part.h b/include/part.h
index b66b07a1f0..8e86485b97 100644
--- a/include/part.h
+++ b/include/part.h
@@ -345,6 +345,20 @@  struct part_driver {
 
 #if CONFIG_IS_ENABLED(EFI_PARTITION)
 /* disk/part_efi.c */
+
+/**
+ * get_gpt_hdr_parts() - Get information on the GPT Header and
+ *                       Partition Table Entries
+ *
+ * @param desc - block device descriptor
+ * @param gpt_h - pointer to GPT header representation
+ * @param gpt_e - pointer to GPT partition table entries
+ *
+ * @return - zero on success, otherwise error
+ */
+int get_gpt_hdr_parts(struct blk_desc *desc, gpt_header *gpt_head,
+		      gpt_entry **gpt_pte);
+
 /**
  * write_gpt_table() - Write the GUID Partition Table to disk
  *