Re: [U-Boot] [PATCH v2 2/4] fastboot: add support for writing MBR

2016-09-18 Thread Simon Glass
On 9 September 2016 at 02:27, Petr Kulhavy  wrote:
> Add special target "mbr" (otherwise configurable via CONFIG_FASTBOOT_MBR_NAME)
> to write MBR partition table.
> Partitions are now searched using the generic function which finds any
> partiiton by name. For MBR the partition names hda1, sda1, etc. are used.
>
> Signed-off-by: Petr Kulhavy 
> Reviewed-by: Tom Rini 
> ---
> v1: initial
> v2: no change
>
>  README  |  7 +++
>  common/fb_mmc.c | 40 ++--
>  disk/part_dos.c | 20 
>  doc/README.android-fastboot | 37 +
>  include/part.h  | 23 +++
>  5 files changed, 121 insertions(+), 6 deletions(-)

Reviewed-by: Simon Glass 
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 2/4] fastboot: add support for writing MBR

2016-09-12 Thread Steve Rae
On Fri, Sep 9, 2016 at 1:27 AM, Petr Kulhavy  wrote:
> Add special target "mbr" (otherwise configurable via CONFIG_FASTBOOT_MBR_NAME)
> to write MBR partition table.
> Partitions are now searched using the generic function which finds any
> partiiton by name. For MBR the partition names hda1, sda1, etc. are used.
>
> Signed-off-by: Petr Kulhavy 
> Reviewed-by: Tom Rini 
> ---
> v1: initial
> v2: no change
>
>  README  |  7 +++
>  common/fb_mmc.c | 40 ++--
>  disk/part_dos.c | 20 
>  doc/README.android-fastboot | 37 +
>  include/part.h  | 23 +++
>  5 files changed, 121 insertions(+), 6 deletions(-)
>
> diff --git a/README b/README
> index 30d7ee3..f6ef8b8 100644
> --- a/README
> +++ b/README
> @@ -1682,6 +1682,13 @@ The following options need to be configured:
> "fastboot flash" command line matches this value.
> Default is GPT_ENTRY_NAME (currently "gpt") if undefined.
>
> +   CONFIG_FASTBOOT_MBR_NAME
> +   The fastboot "flash" command supports writing the downloaded
> +   image to DOS MBR.
> +   This occurs when the "partition name" specified on the
> +   "fastboot flash" command line matches this value.
> +   If not defined the default value "mbr" is used.
> +
>  - Journaling Flash filesystem support:
> CONFIG_JFFS2_NAND, CONFIG_JFFS2_NAND_OFF, 
> CONFIG_JFFS2_NAND_SIZE,
> CONFIG_JFFS2_NAND_DEV
> diff --git a/common/fb_mmc.c b/common/fb_mmc.c
> index a0a4a83..4bc68a7 100644
> --- a/common/fb_mmc.c
> +++ b/common/fb_mmc.c
> @@ -14,15 +14,20 @@
>  #include 
>  #include 
>
> -#ifndef CONFIG_FASTBOOT_GPT_NAME
> +#if defined(CONFIG_EFI_PARTITION) && !defined(CONFIG_FASTBOOT_GPT_NAME)
>  #define CONFIG_FASTBOOT_GPT_NAME GPT_ENTRY_NAME
>  #endif
>
> +
> +#if defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_FASTBOOT_MBR_NAME)
> +#define CONFIG_FASTBOOT_MBR_NAME "mbr"
> +#endif
> +
>  struct fb_mmc_sparse {
> struct blk_desc *dev_desc;
>  };
>
> -static int part_get_info_efi_by_name_or_alias(struct blk_desc *dev_desc,
> +static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
> const char *name, disk_partition_t *info)
>  {
> int ret;
> @@ -103,6 +108,7 @@ void fb_mmc_flash_write(const char *cmd, void 
> *download_buffer,
> return;
> }
>
> +#ifdef CONFIG_EFI_PARTITION
> if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
> printf("%s: updating MBR, Primary and Backup GPT(s)\n",
>__func__);
> @@ -114,14 +120,36 @@ void fb_mmc_flash_write(const char *cmd, void 
> *download_buffer,
> }
> if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
> printf("%s: writing GPT partitions failed\n", 
> __func__);
> -   fastboot_fail(
> - "writing GPT partitions failed");
> +   fastboot_fail("writing GPT partitions failed");
> return;
> }
> printf(" success\n");
> fastboot_okay("");
> return;
> -   } else if (part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info)) {
> +   }
> +#endif
> +
> +#ifdef CONFIG_DOS_PARTITION
> +   if (strcmp(cmd, CONFIG_FASTBOOT_MBR_NAME) == 0) {
> +   printf("%s: updating MBR\n", __func__);
> +   if (is_valid_dos_buf(download_buffer)) {
> +   printf("%s: invalid MBR - refusing to write to 
> flash\n",
> +  __func__);
> +   fastboot_fail("invalid MBR partition");
> +   return;
> +   }
> +   if (write_mbr_partition(dev_desc, download_buffer)) {
> +   printf("%s: writing MBR partition failed\n", 
> __func__);
> +   fastboot_fail("writing MBR partition failed");
> +   return;
> +   }
> +   printf(" success\n");
> +   fastboot_okay("");
> +   return;
> +   }
> +#endif
> +
> +   if (part_get_info_by_name_or_alias(dev_desc, cmd, &info)) {
> error("cannot find partition: '%s'\n", cmd);
> fastboot_fail("cannot find partition");
> return;
> @@ -172,7 +200,7 @@ void fb_mmc_erase(const char *cmd)
> return;
> }
>
> -   ret = part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info);
> +   ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info);
> if (ret) {
> error("cannot find partition: '%s'", cmd);
> fastboot_fail("cannot find partition");
> diff --git a/disk/part_dos.c b/dis