]> Git Repo - u-boot.git/blobdiff - drivers/fastboot/fb_mmc.c
common: Drop log.h from common header
[u-boot.git] / drivers / fastboot / fb_mmc.c
index 0a335db3a6152b5b7a764ba4820a4b3d4ff26379..b2f8932e1c7a67ca1843b4428a74fc1d33f99e29 100644 (file)
@@ -6,10 +6,14 @@
 #include <config.h>
 #include <common.h>
 #include <blk.h>
+#include <env.h>
 #include <fastboot.h>
 #include <fastboot-internal.h>
 #include <fb_mmc.h>
+#include <flash.h>
 #include <image-sparse.h>
+#include <image.h>
+#include <log.h>
 #include <part.h>
 #include <mmc.h>
 #include <div64.h>
@@ -25,7 +29,7 @@ struct fb_mmc_sparse {
 };
 
 static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
-               const char *name, disk_partition_t *info)
+               const char *name, struct disk_partition *info)
 {
        int ret;
 
@@ -96,9 +100,9 @@ static lbaint_t fb_mmc_sparse_reserve(struct sparse_storage *info,
        return blkcnt;
 }
 
-static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
-               const char *part_name, void *buffer,
-               u32 download_bytes, char *response)
+static void write_raw_image(struct blk_desc *dev_desc,
+                           struct disk_partition *info, const char *part_name,
+                           void *buffer, u32 download_bytes, char *response)
 {
        lbaint_t blkcnt;
        lbaint_t blks;
@@ -128,6 +132,76 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
        fastboot_okay(NULL, response);
 }
 
+#ifdef CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT
+static int fb_mmc_erase_mmc_hwpart(struct blk_desc *dev_desc)
+{
+       lbaint_t blks;
+
+       debug("Start Erasing mmc hwpart[%u]...\n", dev_desc->hwpart);
+
+       blks = fb_mmc_blk_write(dev_desc, 0, dev_desc->lba, NULL);
+
+       if (blks != dev_desc->lba) {
+               pr_err("Failed to erase mmc hwpart[%u]\n", dev_desc->hwpart);
+               return 1;
+       }
+
+       printf("........ erased %lu bytes from mmc hwpart[%u]\n",
+              dev_desc->lba * dev_desc->blksz, dev_desc->hwpart);
+
+       return 0;
+}
+
+static void fb_mmc_boot1_ops(struct blk_desc *dev_desc, void *buffer,
+                            u32 buff_sz, char *response)
+{
+       lbaint_t blkcnt;
+       lbaint_t blks;
+       unsigned long blksz;
+
+       // To operate on EMMC_BOOT1 (mmc0boot0), we first change the hwpart
+       if (blk_dselect_hwpart(dev_desc, 1)) {
+               pr_err("Failed to select hwpart\n");
+               fastboot_fail("Failed to select hwpart", response);
+               return;
+       }
+
+       if (buffer) { /* flash */
+
+               /* determine number of blocks to write */
+               blksz = dev_desc->blksz;
+               blkcnt = ((buff_sz + (blksz - 1)) & ~(blksz - 1));
+               blkcnt = lldiv(blkcnt, blksz);
+
+               if (blkcnt > dev_desc->lba) {
+                       pr_err("Image size too large\n");
+                       fastboot_fail("Image size too large", response);
+                       return;
+               }
+
+               debug("Start Flashing Image to EMMC_BOOT1...\n");
+
+               blks = fb_mmc_blk_write(dev_desc, 0, blkcnt, buffer);
+
+               if (blks != blkcnt) {
+                       pr_err("Failed to write EMMC_BOOT1\n");
+                       fastboot_fail("Failed to write EMMC_BOOT1", response);
+                       return;
+               }
+
+               printf("........ wrote %lu bytes to EMMC_BOOT1\n",
+                      blkcnt * blksz);
+       } else { /* erase */
+               if (fb_mmc_erase_mmc_hwpart(dev_desc)) {
+                       fastboot_fail("Failed to erase EMMC_BOOT1", response);
+                       return;
+               }
+       }
+
+       fastboot_okay(NULL, response);
+}
+#endif
+
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
 /**
  * Read Android boot image header from boot partition.
@@ -139,7 +213,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
  * @return Boot image header sectors count or 0 on error
  */
 static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
-                                      disk_partition_t *info,
+                                      struct disk_partition *info,
                                       struct andr_img_hdr *hdr,
                                       char *response)
 {
@@ -199,7 +273,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
        u32 kernel_sector_start;
        u32 kernel_sectors;
        u32 sectors_per_page;
-       disk_partition_t info;
+       struct disk_partition info;
        int res;
 
        puts("Flashing zImage\n");
@@ -295,12 +369,12 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
  *
  * @part_name: Named partition to lookup
  * @dev_desc: Pointer to returned blk_desc pointer
- * @part_info: Pointer to returned disk_partition_t
+ * @part_info: Pointer to returned struct disk_partition
  * @response: Pointer to fastboot response buffer
  */
 int fastboot_mmc_get_part_info(const char *part_name,
                               struct blk_desc **dev_desc,
-                              disk_partition_t *part_info, char *response)
+                              struct disk_partition *part_info, char *response)
 {
        int r;
 
@@ -335,7 +409,7 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer,
                              u32 download_bytes, char *response)
 {
        struct blk_desc *dev_desc;
-       disk_partition_t info;
+       struct disk_partition info;
 
        dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
        if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
@@ -344,8 +418,21 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer,
                return;
        }
 
+#ifdef CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT
+       if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT1_NAME) == 0) {
+               fb_mmc_boot1_ops(dev_desc, download_buffer,
+                                download_bytes, response);
+               return;
+       }
+#endif
+
 #if CONFIG_IS_ENABLED(EFI_PARTITION)
+#ifndef CONFIG_FASTBOOT_MMC_USER_NAME
        if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
+#else
+       if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0 ||
+           strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) {
+#endif
                printf("%s: updating MBR, Primary and Backup GPT(s)\n",
                       __func__);
                if (is_valid_gpt_buf(dev_desc, download_buffer)) {
@@ -439,7 +526,7 @@ void fastboot_mmc_erase(const char *cmd, char *response)
 {
        int ret;
        struct blk_desc *dev_desc;
-       disk_partition_t info;
+       struct disk_partition info;
        lbaint_t blks, blks_start, blks_size, grp_size;
        struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
 
@@ -456,6 +543,25 @@ void fastboot_mmc_erase(const char *cmd, char *response)
                return;
        }
 
+#ifdef CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT
+       if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT1_NAME) == 0) {
+               /* erase EMMC boot1 */
+               fb_mmc_boot1_ops(dev_desc, NULL, 0, response);
+               return;
+       }
+#endif
+
+#ifdef CONFIG_FASTBOOT_MMC_USER_NAME
+       if (strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) {
+               /* erase EMMC userdata */
+               if (fb_mmc_erase_mmc_hwpart(dev_desc))
+                       fastboot_fail("Failed to erase EMMC_USER", response);
+               else
+                       fastboot_okay(NULL, response);
+               return;
+       }
+#endif
+
        ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info);
        if (ret < 0) {
                pr_err("cannot find partition: '%s'\n", cmd);
This page took 0.028667 seconds and 4 git commands to generate.