]> git.sur5r.net Git - u-boot/blobdiff - common/fb_mmc.c
Merge tag 'signed-rpi-next' of git://github.com/agraf/u-boot
[u-boot] / common / fb_mmc.c
index 2113b6c3723978f31372e1562010e76defb6f800..46f0073dbc239d8c9e3294e914a354ffadbfe719 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2014 Broadcom Corporation.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <config.h>
@@ -49,7 +48,7 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
                /* check for alias */
                strcpy(env_alias_name, "fastboot_partition_alias_");
                strncat(env_alias_name, name, 32);
-               aliased_part_name = getenv(env_alias_name);
+               aliased_part_name = env_get(env_alias_name);
                if (aliased_part_name != NULL)
                        ret = part_get_info_by_name(dev_desc,
                                        aliased_part_name, info);
@@ -84,7 +83,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
        blkcnt = lldiv(blkcnt, info->blksz);
 
        if (blkcnt > info->size) {
-               error("too large for partition: '%s'\n", part_name);
+               pr_err("too large for partition: '%s'\n", part_name);
                fastboot_fail("too large for partition");
                return;
        }
@@ -93,7 +92,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
 
        blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer);
        if (blks != blkcnt) {
-               error("failed writing to device %d\n", dev_desc->devnum);
+               pr_err("failed writing to device %d\n", dev_desc->devnum);
                fastboot_fail("failed writing to device");
                return;
        }
@@ -125,15 +124,15 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
        sector_size = info->blksz;
        hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
        if (hdr_sectors == 0) {
-               error("invalid number of boot sectors: 0");
+               pr_err("invalid number of boot sectors: 0");
                fastboot_fail("invalid number of boot sectors: 0");
                return 0;
        }
 
        /* Read the boot image header */
        res = blk_dread(dev_desc, info->start, hdr_sectors, (void *)hdr);
-       if (res == 0) {
-               error("cannot read header from boot partition");
+       if (res != hdr_sectors) {
+               pr_err("cannot read header from boot partition");
                fastboot_fail("cannot read header from boot partition");
                return 0;
        }
@@ -141,7 +140,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
        /* Check boot header magic string */
        res = android_image_check_header(hdr);
        if (res != 0) {
-               error("bad boot image magic");
+               pr_err("bad boot image magic");
                fastboot_fail("boot partition not initialized");
                return 0;
        }
@@ -162,7 +161,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
                                void *download_buffer,
                                unsigned int download_bytes)
 {
-       u32 hdr_addr;                           /* boot image header address */
+       uintptr_t hdr_addr;                     /* boot image header address */
        struct andr_img_hdr *hdr;               /* boot image header */
        lbaint_t hdr_sectors;                   /* boot image header sectors */
        u8 *ramdisk_buffer;
@@ -179,26 +178,26 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
        /* Get boot partition info */
        res = part_get_info_by_name(dev_desc, BOOT_PARTITION_NAME, &info);
        if (res < 0) {
-               error("cannot find boot partition");
+               pr_err("cannot find boot partition");
                fastboot_fail("cannot find boot partition");
                return -1;
        }
 
        /* Put boot image header in fastboot buffer after downloaded zImage */
-       hdr_addr = (u32)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
+       hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
        hdr = (struct andr_img_hdr *)hdr_addr;
 
        /* Read boot image header */
        hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr);
        if (hdr_sectors == 0) {
-               error("unable to read boot image header");
+               pr_err("unable to read boot image header");
                fastboot_fail("unable to read boot image header");
                return -1;
        }
 
        /* Check if boot image has second stage in it (we don't support it) */
        if (hdr->second_size > 0) {
-               error("moving second stage is not supported yet");
+               pr_err("moving second stage is not supported yet");
                fastboot_fail("moving second stage is not supported yet");
                return -1;
        }
@@ -215,8 +214,8 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
        ramdisk_buffer = (u8 *)hdr + (hdr_sectors * info.blksz);
        res = blk_dread(dev_desc, ramdisk_sector_start, ramdisk_sectors,
                        ramdisk_buffer);
-       if (res == 0) {
-               error("cannot read ramdisk from boot partition");
+       if (res != ramdisk_sectors) {
+               pr_err("cannot read ramdisk from boot partition");
                fastboot_fail("cannot read ramdisk from boot partition");
                return -1;
        }
@@ -225,7 +224,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
        hdr->kernel_size = download_bytes;
        res = blk_dwrite(dev_desc, info.start, hdr_sectors, (void *)hdr);
        if (res == 0) {
-               error("cannot writeback boot image header");
+               pr_err("cannot writeback boot image header");
                fastboot_fail("cannot write back boot image header");
                return -1;
        }
@@ -237,7 +236,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
        res = blk_dwrite(dev_desc, kernel_sector_start, kernel_sectors,
                         download_buffer);
        if (res == 0) {
-               error("cannot write new kernel");
+               pr_err("cannot write new kernel");
                fastboot_fail("cannot write new kernel");
                return -1;
        }
@@ -249,7 +248,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
        res = blk_dwrite(dev_desc, ramdisk_sector_start, ramdisk_sectors,
                         ramdisk_buffer);
        if (res == 0) {
-               error("cannot write back original ramdisk");
+               pr_err("cannot write back original ramdisk");
                fastboot_fail("cannot write back original ramdisk");
                return -1;
        }
@@ -268,7 +267,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 
        dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
        if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
-               error("invalid mmc device\n");
+               pr_err("invalid mmc device\n");
                fastboot_fail("invalid mmc device");
                return;
        }
@@ -322,7 +321,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 #endif
 
        if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) {
-               error("cannot find partition: '%s'\n", cmd);
+               pr_err("cannot find partition: '%s'\n", cmd);
                fastboot_fail("cannot find partition");
                return;
        }
@@ -330,6 +329,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
        if (is_sparse_image(download_buffer)) {
                struct fb_mmc_sparse sparse_priv;
                struct sparse_storage sparse;
+               int err;
 
                sparse_priv.dev_desc = dev_desc;
 
@@ -338,13 +338,15 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
                sparse.size = info.size;
                sparse.write = fb_mmc_sparse_write;
                sparse.reserve = fb_mmc_sparse_reserve;
+               sparse.mssg = fastboot_fail;
 
                printf("Flashing sparse image at offset " LBAFU "\n",
                       sparse.start);
 
                sparse.priv = &sparse_priv;
-               write_sparse_image(&sparse, cmd, download_buffer,
-                                  download_bytes);
+               err = write_sparse_image(&sparse, cmd, download_buffer);
+               if (!err)
+                       fastboot_okay("");
        } else {
                write_raw_image(dev_desc, &info, cmd, download_buffer,
                                download_bytes);
@@ -360,21 +362,21 @@ void fb_mmc_erase(const char *cmd)
        struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
 
        if (mmc == NULL) {
-               error("invalid mmc device");
+               pr_err("invalid mmc device");
                fastboot_fail("invalid mmc device");
                return;
        }
 
        dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
        if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
-               error("invalid mmc device");
+               pr_err("invalid mmc device");
                fastboot_fail("invalid mmc device");
                return;
        }
 
        ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info);
        if (ret < 0) {
-               error("cannot find partition: '%s'", cmd);
+               pr_err("cannot find partition: '%s'", cmd);
                fastboot_fail("cannot find partition");
                return;
        }
@@ -393,7 +395,7 @@ void fb_mmc_erase(const char *cmd)
 
        blks = blk_derase(dev_desc, blks_start, blks_size);
        if (blks != blks_size) {
-               error("failed erasing from device %d", dev_desc->devnum);
+               pr_err("failed erasing from device %d", dev_desc->devnum);
                fastboot_fail("failed erasing from device");
                return;
        }