From 4bf92b541af628d899ea1dadf9147baa3482967a Mon Sep 17 00:00:00 2001 From: Dmitrii Merkurev Date: Fri, 21 Nov 2025 11:53:31 +0100 Subject: fastboot: blk: introduce fastboot block flashing support Introduce fastboot block flashing functions and helpers to be shared with the MMC implementation. The write logic comes from the mmc implementation, while the partition lookup is much simpler and could be extended. For the erase logic, allmost no block drivers exposes the erase operation, except mmc & virtio, so in order to allow erasiong any partition a soft-erase logic has been added to write zero-ed buffers in a loop. Signed-off-by: Dmitrii Merkurev Reviewed-by: Mattijs Korpershoek Tested-by: Mattijs Korpershoek Signed-off-by: Neil Armstrong Link: https://lore.kernel.org/r/20251121-topic-fastboot-blk-v7-1-9589d902fc91@linaro.org Signed-off-by: Mattijs Korpershoek --- include/fb_block.h | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 include/fb_block.h (limited to 'include') diff --git a/include/fb_block.h b/include/fb_block.h new file mode 100644 index 00000000000..189c708e2f0 --- /dev/null +++ b/include/fb_block.h @@ -0,0 +1,105 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2024 The Android Open Source Project + */ + +#ifndef _FB_BLOCK_H_ +#define _FB_BLOCK_H_ + +struct blk_desc; +struct disk_partition; + +/** + * fastboot_block_get_part_info() - Lookup block partition by name + * + * @part_name: Named partition to lookup + * @dev_desc: Pointer to returned blk_desc pointer + * @part_info: Pointer to returned struct disk_partition + * @response: Pointer to fastboot response buffer + * Return: 0 on success, -ve on error + */ +int fastboot_block_get_part_info(const char *part_name, + struct blk_desc **dev_desc, + struct disk_partition *part_info, + char *response); + +/** + * fastboot_block_raw_erase() - Erase raw block device partition + * + * @dev_desc: Block device we're going write to + * @info: Partition we're going write to + * @part_name: Name of partition we're going write to + * @alignment: erase start and size alignment, specify 0 to ignore + * @response: Pointer to fastboot response buffer + */ +void fastboot_block_raw_erase(struct blk_desc *dev_desc, struct disk_partition *info, + const char *part_name, uint alignment, char *response); + +/** + * fastboot_block_raw_erase_disk() - Erase raw block device + * + * @dev_desc: Block device we're going write to + * @disk_name: Name of disk we're going write to + * @response: Pointer to fastboot response buffer + */ +void fastboot_block_raw_erase_disk(struct blk_desc *dev_desc, const char *disk_name, + char *response); + +/** + * fastboot_block_erase() - Erase partition on block device for fastboot + * + * @part_name: Named partition to erase + * @response: Pointer to fastboot response buffer + */ +void fastboot_block_erase(const char *part_name, char *response); + +/** + * fastboot_block_write_raw_disk() - Write raw image to block device + * + * @dev_desc: Block device we're going write to + * @disk_name: Name of disk we're going write to + * @buffer: Downloaded buffer pointer + * @download_bytes: Size of content on downloaded buffer pointer + * @response: Pointer to fastboot response buffer + */ +void fastboot_block_write_raw_disk(struct blk_desc *dev_desc, const char *disk_name, + void *buffer, u32 download_bytes, char *response); + +/** + * fastboot_block_write_raw_image() - Write raw image to block device partition + * + * @dev_desc: Block device we're going write to + * @info: Partition we're going write to + * @part_name: Name of partition we're going write to + * @buffer: Downloaded buffer pointer + * @download_bytes: Size of content on downloaded buffer pointer + * @response: Pointer to fastboot response buffer + */ +void fastboot_block_write_raw_image(struct blk_desc *dev_desc, + struct disk_partition *info, const char *part_name, + void *buffer, u32 download_bytes, char *response); + +/** + * fastboot_block_write_sparse_image() - Write sparse image to block device partition + * + * @dev_desc: Block device we're going write to + * @info: Partition we're going write to + * @part_name: Name of partition we're going write to + * @buffer: Downloaded buffer pointer + * @response: Pointer to fastboot response buffer + */ +void fastboot_block_write_sparse_image(struct blk_desc *dev_desc, struct disk_partition *info, + const char *part_name, void *buffer, char *response); + +/** + * fastboot_block_flash_write() - Write image to block device for fastboot + * + * @part_name: Named partition to write image to + * @download_buffer: Pointer to image data + * @download_bytes: Size of image data + * @response: Pointer to fastboot response buffer + */ +void fastboot_block_flash_write(const char *part_name, void *download_buffer, + u32 download_bytes, char *response); + +#endif // _FB_BLOCK_H_ -- cgit v1.2.3