[U-Boot] [PATCH 14/30] dm: part: Convert partition API use to linker lists

Bin Meng bmeng.cn at gmail.com
Tue Feb 16 15:25:43 CET 2016


Hi Simon,

On Mon, Feb 15, 2016 at 10:16 AM, Simon Glass <sjg at chromium.org> wrote:
> We can use linker lists instead of explicitly declaring each function.
> This makes the code shorter by avoiding switch() statements and lots of
> header file declarations.
>
> While this does clean up the code it introduces a few code issues with SPL.
> SPL never needs to print partition information since this all happens from
> commands. SPL mostly doesn't need to obtain information about a partition
> either, except in a few cases. Add these cases so that the code will be
> dropped from each partition driver when not needed. This avoids code bloat.
>
> I think this is still a win, since it is not a bad thing to be explicit
> about which features are used in SPL. But others may like to weigh in.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>  disk/part.c       | 184 +++++++++++++++++-------------------------------------
>  disk/part_amiga.c |  16 +++--
>  disk/part_dos.c   |   9 ++-
>  disk/part_efi.c   |  10 ++-
>  disk/part_iso.c   |  16 +++--
>  disk/part_mac.c   |  16 +++--
>  include/part.h    |  79 ++++++++++++++---------
>  7 files changed, 157 insertions(+), 173 deletions(-)
>

[snip]

> diff --git a/disk/part_amiga.c b/disk/part_amiga.c
> index 5702c95..0f569f0 100644
> --- a/disk/part_amiga.c
> +++ b/disk/part_amiga.c
> @@ -207,7 +207,7 @@ struct bootcode_block *get_bootcode(struct blk_desc *dev_desc)
>   * Test if the given partition has an Amiga partition table/Rigid
>   * Disk block
>   */
> -int test_part_amiga(struct blk_desc *dev_desc)
> +static int test_part_amiga(struct blk_desc *dev_desc)
>  {
>      struct rigid_disk_block *rdb;
>      struct bootcode_block *bootcode;
> @@ -291,8 +291,8 @@ static struct partition_block *find_partition(struct blk_desc *dev_desc,
>  /*
>   * Get info about a partition
>   */
> -int get_partition_info_amiga(struct blk_desc *dev_desc, int part,
> -                            disk_partition_t *info)
> +static int get_partition_info_amiga(struct blk_desc *dev_desc, int part,
> +                                   disk_partition_t *info)
>  {
>      struct partition_block *p = find_partition(dev_desc, part-1);
>      struct amiga_part_geometry *g;
> @@ -319,7 +319,7 @@ int get_partition_info_amiga(struct blk_desc *dev_desc, int part,
>      return 0;
>  }
>
> -void print_part_amiga(struct blk_desc *dev_desc)
> +static void print_part_amiga(struct blk_desc *dev_desc)
>  {
>      struct rigid_disk_block *rdb;
>      struct bootcode_block *boot;
> @@ -379,4 +379,12 @@ void print_part_amiga(struct blk_desc *dev_desc)
>      }
>  }
>
> +U_BOOT_PART_TYPE(amiga) = {
> +       .name           = "AMIGA",
> +       .part_type      = PART_TYPE_AMIGA,
> +       .get_info       = get_partition_info_amiga,
> +       .print          = print_part_amiga,
> +       .test           = test_part_amiga,
> +};
> +
>  #endif
> diff --git a/disk/part_dos.c b/disk/part_dos.c
> index ea0315c..7567ed3 100644
> --- a/disk/part_dos.c
> +++ b/disk/part_dos.c
> @@ -87,7 +87,7 @@ static int test_block_type(unsigned char *buffer)
>  }
>
>
> -int test_part_dos(struct blk_desc *dev_desc)
> +static int test_part_dos(struct blk_desc *dev_desc)
>  {
>         ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
>
> @@ -295,5 +295,12 @@ int get_partition_info_dos(struct blk_desc *dev_desc, int part,
>         return get_partition_info_extended(dev_desc, 0, 0, 1, part, info, 0);
>  }
>
> +U_BOOT_PART_TYPE(dos) = {
> +       .name           = "DOS",
> +       .part_type      = PART_TYPE_DOS,
> +       .get_info       = part_get_info_ptr(get_partition_info_dos),

Does this compile?

> +       .print          = part_print_ptr(print_part_dos),

and this?

> +       .test           = test_part_dos,
> +};
>
>  #endif
> diff --git a/disk/part_efi.c b/disk/part_efi.c
> index 7bd840f..6f80877 100644
> --- a/disk/part_efi.c
> +++ b/disk/part_efi.c
> @@ -319,7 +319,7 @@ int get_partition_info_efi_by_name(struct blk_desc *dev_desc,
>         return -2;
>  }
>
> -int test_part_efi(struct blk_desc *dev_desc)
> +static int test_part_efi(struct blk_desc *dev_desc)
>  {
>         ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
>
> @@ -953,4 +953,12 @@ static int is_pte_valid(gpt_entry * pte)
>                 return 1;
>         }
>  }
> +
> +U_BOOT_PART_TYPE(efi) = {
> +       .name           = "EFI",
> +       .part_type      = PART_TYPE_EFI,
> +       .get_info       = part_get_info_ptr(get_partition_info_efi),
> +       .print          = part_print_ptr(print_part_efi),

and these?

> +       .test           = test_part_efi,
> +};
>  #endif
> diff --git a/disk/part_iso.c b/disk/part_iso.c
> index 2984df5..1d72d23 100644
> --- a/disk/part_iso.c
> +++ b/disk/part_iso.c
> @@ -217,14 +217,13 @@ found:
>         return 0;
>  }
>
> -int get_partition_info_iso(struct blk_desc *dev_desc, int part_num,
> -                          disk_partition_t *info)
> +static int get_partition_info_iso(struct blk_desc *dev_desc, int part_num,
> +                                 disk_partition_t *info)
>  {
>         return(get_partition_info_iso_verb(dev_desc, part_num, info, 1));
>  }
>
> -
> -void print_part_iso(struct blk_desc *dev_desc)
> +static void print_part_iso(struct blk_desc *dev_desc)
>  {
>         disk_partition_t info;
>         int i;
> @@ -241,11 +240,18 @@ void print_part_iso(struct blk_desc *dev_desc)
>         } while (get_partition_info_iso_verb(dev_desc,i,&info,0)!=-1);
>  }
>
> -int test_part_iso(struct blk_desc *dev_desc)
> +static int test_part_iso(struct blk_desc *dev_desc)
>  {
>         disk_partition_t info;
>
>         return(get_partition_info_iso_verb(dev_desc,0,&info,0));
>  }
>
> +U_BOOT_PART_TYPE(iso) = {
> +       .name           = "ISO",
> +       .part_type      = PART_TYPE_ISO,
> +       .get_info       = get_partition_info_iso,
> +       .print          = print_part_iso,
> +       .test           = test_part_iso,
> +};
>  #endif
> diff --git a/disk/part_mac.c b/disk/part_mac.c
> index ae83495..3fb3b16 100644
> --- a/disk/part_mac.c
> +++ b/disk/part_mac.c
> @@ -40,7 +40,7 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,
>  /*
>   * Test for a valid MAC partition
>   */
> -int test_part_mac(struct blk_desc *dev_desc)
> +static int test_part_mac(struct blk_desc *dev_desc)
>  {
>         ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
>         ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
> @@ -64,8 +64,7 @@ int test_part_mac(struct blk_desc *dev_desc)
>         return (0);
>  }
>
> -
> -void print_part_mac(struct blk_desc *dev_desc)
> +static void print_part_mac(struct blk_desc *dev_desc)
>  {
>         ulong i, n;
>         ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
> @@ -214,8 +213,8 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,
>         /* NOTREACHED */
>  }
>
> -int get_partition_info_mac(struct blk_desc *dev_desc, int part,
> -                          disk_partition_t *info)
> +static int get_partition_info_mac(struct blk_desc *dev_desc, int part,
> +                                 disk_partition_t *info)
>  {
>         ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
>         ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
> @@ -238,4 +237,11 @@ int get_partition_info_mac(struct blk_desc *dev_desc, int part,
>         return (0);
>  }
>
> +U_BOOT_PART_TYPE(mac) = {
> +       .name           = "MAC",
> +       .part_type      = PART_TYPE_MAC,
> +       .get_info       = get_partition_info_mac,
> +       .print          = print_part_mac,
> +       .test           = test_part_mac,
> +};
>  #endif

[snip]

Regards,
Bin


More information about the U-Boot mailing list