Lines Matching +full:boot +full:- +full:blks

1 // SPDX-License-Identifier: GPL-2.0+
10 #include <fastboot-internal.h>
12 #include <image-sparse.h>
21 #define BOOT_PARTITION_NAME "boot"
50 * fb_mmc_blk_write() - Write/erase MMC in chunks of FASTBOOT_MAX_BLK_WRITE
63 lbaint_t blks = 0; in fb_mmc_blk_write() local
67 cur_blkcnt = min((int)blkcnt - i, FASTBOOT_MAX_BLK_WRITE); in fb_mmc_blk_write()
72 buffer + (i * block_dev->blksz)); in fb_mmc_blk_write()
79 blks += blks_written; in fb_mmc_blk_write()
81 return blks; in fb_mmc_blk_write()
87 struct fb_mmc_sparse *sparse = info->priv; in fb_mmc_sparse_write()
88 struct blk_desc *dev_desc = sparse->dev_desc; in fb_mmc_sparse_write()
104 lbaint_t blks; in write_raw_image() local
107 blkcnt = ((download_bytes + (info->blksz - 1)) & ~(info->blksz - 1)); in write_raw_image()
108 blkcnt = lldiv(blkcnt, info->blksz); in write_raw_image()
110 if (blkcnt > info->size) { in write_raw_image()
118 blks = fb_mmc_blk_write(dev_desc, info->start, blkcnt, buffer); in write_raw_image()
120 if (blks != blkcnt) { in write_raw_image()
121 pr_err("failed writing to device %d\n", dev_desc->devnum); in write_raw_image()
126 printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz, in write_raw_image()
133 * Read Android boot image header from boot partition.
136 * @param[in] info Boot partition info
137 * @param[out] hdr Where to store read boot image header
139 * @return Boot image header sectors count or 0 on error
146 ulong sector_size; /* boot partition sector size */ in fb_mmc_get_boot_header()
147 lbaint_t hdr_sectors; /* boot image header sectors count */ in fb_mmc_get_boot_header()
150 /* Calculate boot image sectors count */ in fb_mmc_get_boot_header()
151 sector_size = info->blksz; in fb_mmc_get_boot_header()
154 pr_err("invalid number of boot sectors: 0\n"); in fb_mmc_get_boot_header()
155 fastboot_fail("invalid number of boot sectors: 0", response); in fb_mmc_get_boot_header()
159 /* Read the boot image header */ in fb_mmc_get_boot_header()
160 res = blk_dread(dev_desc, info->start, hdr_sectors, (void *)hdr); in fb_mmc_get_boot_header()
162 pr_err("cannot read header from boot partition\n"); in fb_mmc_get_boot_header()
163 fastboot_fail("cannot read header from boot partition", in fb_mmc_get_boot_header()
168 /* Check boot header magic string */ in fb_mmc_get_boot_header()
171 pr_err("bad boot image magic\n"); in fb_mmc_get_boot_header()
172 fastboot_fail("boot partition not initialized", response); in fb_mmc_get_boot_header()
180 * Write downloaded zImage to boot partition and repack it properly.
186 * @return 0 on success or -1 on error
193 uintptr_t hdr_addr; /* boot image header address */ in fb_mmc_update_zimage()
194 struct andr_img_hdr *hdr; /* boot image header */ in fb_mmc_update_zimage()
195 lbaint_t hdr_sectors; /* boot image header sectors */ in fb_mmc_update_zimage()
207 /* Get boot partition info */ in fb_mmc_update_zimage()
210 pr_err("cannot find boot partition\n"); in fb_mmc_update_zimage()
211 fastboot_fail("cannot find boot partition", response); in fb_mmc_update_zimage()
212 return -1; in fb_mmc_update_zimage()
215 /* Put boot image header in fastboot buffer after downloaded zImage */ in fb_mmc_update_zimage()
219 /* Read boot image header */ in fb_mmc_update_zimage()
222 pr_err("unable to read boot image header\n"); in fb_mmc_update_zimage()
223 fastboot_fail("unable to read boot image header", response); in fb_mmc_update_zimage()
224 return -1; in fb_mmc_update_zimage()
227 /* Check if boot image has second stage in it (we don't support it) */ in fb_mmc_update_zimage()
228 if (hdr->second_size > 0) { in fb_mmc_update_zimage()
232 return -1; in fb_mmc_update_zimage()
236 sectors_per_page = hdr->page_size / info.blksz; in fb_mmc_update_zimage()
238 ramdisk_sector_start += DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) * in fb_mmc_update_zimage()
240 ramdisk_sectors = DIV_ROUND_UP(hdr->ramdisk_size, hdr->page_size) * in fb_mmc_update_zimage()
243 /* Read ramdisk and put it in fastboot buffer after boot image header */ in fb_mmc_update_zimage()
248 pr_err("cannot read ramdisk from boot partition\n"); in fb_mmc_update_zimage()
249 fastboot_fail("cannot read ramdisk from boot partition", in fb_mmc_update_zimage()
251 return -1; in fb_mmc_update_zimage()
254 /* Write new kernel size to boot image header */ in fb_mmc_update_zimage()
255 hdr->kernel_size = download_bytes; in fb_mmc_update_zimage()
258 pr_err("cannot writeback boot image header\n"); in fb_mmc_update_zimage()
259 fastboot_fail("cannot write back boot image header", response); in fb_mmc_update_zimage()
260 return -1; in fb_mmc_update_zimage()
265 kernel_sectors = DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) * in fb_mmc_update_zimage()
272 return -1; in fb_mmc_update_zimage()
277 ramdisk_sector_start += DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) * in fb_mmc_update_zimage()
284 return -1; in fb_mmc_update_zimage()
287 puts("........ zImage was updated in boot partition\n"); in fb_mmc_update_zimage()
294 * fastboot_mmc_get_part_info() - Lookup eMMC partion by name
309 return -ENOENT; in fastboot_mmc_get_part_info()
313 return -ENOENT; in fastboot_mmc_get_part_info()
326 * fastboot_mmc_flash_write() - Write image to eMMC for fastboot
340 if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { in fastboot_mmc_flash_write()
351 printf("%s: invalid GPT - refusing to write to flash\n", in fastboot_mmc_flash_write()
372 printf("%s: invalid MBR - refusing to write to flash\n", in fastboot_mmc_flash_write()
432 * fastboot_mmc_flash_erase() - Erase eMMC for fastboot
442 lbaint_t blks, blks_start, blks_size, grp_size; in fastboot_mmc_erase() local
452 if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { in fastboot_mmc_erase()
466 grp_size = mmc->erase_grp_size; in fastboot_mmc_erase()
467 blks_start = (info.start + grp_size - 1) & ~(grp_size - 1); in fastboot_mmc_erase()
469 blks_size = (info.size - (blks_start - info.start)) & in fastboot_mmc_erase()
470 (~(grp_size - 1)); in fastboot_mmc_erase()
477 blks = fb_mmc_blk_write(dev_desc, blks_start, blks_size, NULL); in fastboot_mmc_erase()
479 if (blks != blks_size) { in fastboot_mmc_erase()
480 pr_err("failed erasing from device %d\n", dev_desc->devnum); in fastboot_mmc_erase()