2 * Copyright 2014 Broadcom Corporation.
4 * SPDX-License-Identifier: GPL-2.0+
11 /* The 64 defined bytes plus the '\0' */
12 #define RESPONSE_LEN (64 + 1)
14 static char *response_str;
16 static void fastboot_resp(const char *s)
18 strncpy(response_str, s, RESPONSE_LEN);
19 response_str[RESPONSE_LEN - 1] = '\0';
22 static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
23 const char *part_name, void *buffer,
24 unsigned int download_bytes)
29 /* determine number of blocks to write */
30 blkcnt = ((download_bytes + (info->blksz - 1)) & ~(info->blksz - 1));
31 blkcnt = blkcnt / info->blksz;
33 if (blkcnt > info->size) {
34 error("too large for partition: '%s'\n", part_name);
35 fastboot_resp("FAILtoo large for partition");
39 puts("Flashing Raw Image\n");
41 blks = dev_desc->block_write(dev_desc->dev, info->start, blkcnt,
44 error("failed writing to device %d\n", dev_desc->dev);
45 fastboot_resp("FAILfailed writing to device");
49 printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
51 fastboot_resp("OKAY");
54 void fb_mmc_flash_write(const char *cmd, void *download_buffer,
55 unsigned int download_bytes, char *response)
58 block_dev_desc_t *dev_desc;
59 disk_partition_t info;
61 /* initialize the response buffer */
62 response_str = response;
64 dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
65 if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
66 error("invalid mmc device\n");
67 fastboot_resp("FAILinvalid mmc device");
71 ret = get_partition_info_efi_by_name(dev_desc, cmd, &info);
73 error("cannot find partition: '%s'\n", cmd);
74 fastboot_resp("FAILcannot find partition");
78 write_raw_image(dev_desc, &info, cmd, download_buffer,