2022-04-19 01:05:09 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Software partition device (UCLASS_PARTITION)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 Linaro Limited
|
|
|
|
* Author: AKASHI Takahiro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_CATEGORY UCLASS_PARTITION
|
|
|
|
|
2022-07-02 12:07:48 +00:00
|
|
|
#include <common.h>
|
2022-04-19 01:05:09 +00:00
|
|
|
#include <blk.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <log.h>
|
|
|
|
#include <part.h>
|
|
|
|
#include <vsprintf.h>
|
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/lists.h>
|
|
|
|
|
2023-08-13 23:46:44 +00:00
|
|
|
/**
|
|
|
|
* disk_blk_part_validate() - Check whether access to partition is within limits
|
|
|
|
*
|
|
|
|
* @dev: Device (partition udevice)
|
|
|
|
* @start: Start block for the access(from start of partition)
|
|
|
|
* @blkcnt: Number of blocks to access (within the partition)
|
|
|
|
* @return 0 on valid block range, or -ve on error.
|
|
|
|
*/
|
|
|
|
static int disk_blk_part_validate(struct udevice *dev, lbaint_t start, lbaint_t blkcnt)
|
|
|
|
{
|
2023-08-13 23:46:45 +00:00
|
|
|
struct disk_part *part = dev_get_uclass_plat(dev);
|
|
|
|
|
2023-08-13 23:46:44 +00:00
|
|
|
if (device_get_uclass_id(dev) != UCLASS_PARTITION)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
2023-08-13 23:46:45 +00:00
|
|
|
if (start >= part->gpt_part_info.size)
|
|
|
|
return -E2BIG;
|
|
|
|
|
|
|
|
if ((start + blkcnt) > part->gpt_part_info.size)
|
|
|
|
return -ERANGE;
|
|
|
|
|
2023-08-13 23:46:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* disk_blk_part_offset() - Compute offset from start of block device
|
|
|
|
*
|
|
|
|
* @dev: Device (partition udevice)
|
|
|
|
* @start: Start block for the access (from start of partition)
|
|
|
|
* @return Start block for the access (from start of block device)
|
|
|
|
*/
|
|
|
|
static lbaint_t disk_blk_part_offset(struct udevice *dev, lbaint_t start)
|
|
|
|
{
|
|
|
|
struct disk_part *part = dev_get_uclass_plat(dev);
|
|
|
|
|
|
|
|
return start + part->gpt_part_info.start;
|
|
|
|
}
|
|
|
|
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
/*
|
|
|
|
* BLOCK IO APIs
|
|
|
|
*/
|
2023-08-13 23:46:42 +00:00
|
|
|
/**
|
|
|
|
* disk_blk_read() - Read from a block device partition
|
|
|
|
*
|
|
|
|
* @dev: Device to read from (partition udevice)
|
|
|
|
* @start: Start block for the read (from start of partition)
|
|
|
|
* @blkcnt: Number of blocks to read (within the partition)
|
|
|
|
* @buffer: Place to put the data
|
|
|
|
* @return number of blocks read (which may be less than @blkcnt),
|
|
|
|
* or -ve on error. This never returns 0 unless @blkcnt is 0
|
|
|
|
*/
|
2022-10-21 00:22:52 +00:00
|
|
|
unsigned long disk_blk_read(struct udevice *dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, void *buffer)
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
{
|
2023-08-13 23:46:44 +00:00
|
|
|
int ret = disk_blk_part_validate(dev, start, blkcnt);
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
|
2023-08-13 23:46:44 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
|
2023-08-13 23:46:44 +00:00
|
|
|
return blk_read(dev_get_parent(dev), disk_blk_part_offset(dev, start),
|
2023-08-13 23:46:42 +00:00
|
|
|
blkcnt, buffer);
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 23:46:43 +00:00
|
|
|
/**
|
|
|
|
* disk_blk_write() - Write to a block device
|
|
|
|
*
|
2023-08-13 23:46:44 +00:00
|
|
|
* @dev: Device to write to (partition udevice)
|
|
|
|
* @start: Start block for the write (from start of partition)
|
|
|
|
* @blkcnt: Number of blocks to write (within the partition)
|
2023-08-13 23:46:43 +00:00
|
|
|
* @buffer: Data to write
|
|
|
|
* @return number of blocks written (which may be less than @blkcnt),
|
|
|
|
* or -ve on error. This never returns 0 unless @blkcnt is 0
|
|
|
|
*/
|
2022-10-21 00:22:52 +00:00
|
|
|
unsigned long disk_blk_write(struct udevice *dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, const void *buffer)
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
{
|
2023-08-13 23:46:44 +00:00
|
|
|
int ret = disk_blk_part_validate(dev, start, blkcnt);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
|
2023-08-13 23:46:44 +00:00
|
|
|
return blk_write(dev_get_parent(dev), disk_blk_part_offset(dev, start),
|
|
|
|
blkcnt, buffer);
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 23:46:43 +00:00
|
|
|
/**
|
|
|
|
* disk_blk_erase() - Erase part of a block device
|
|
|
|
*
|
2023-08-13 23:46:44 +00:00
|
|
|
* @dev: Device to erase (partition udevice)
|
|
|
|
* @start: Start block for the erase (from start of partition)
|
|
|
|
* @blkcnt: Number of blocks to erase (within the partition)
|
2023-08-13 23:46:43 +00:00
|
|
|
* @return number of blocks erased (which may be less than @blkcnt),
|
|
|
|
* or -ve on error. This never returns 0 unless @blkcnt is 0
|
|
|
|
*/
|
2022-10-21 00:22:52 +00:00
|
|
|
unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt)
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
{
|
2023-08-13 23:46:44 +00:00
|
|
|
int ret = disk_blk_part_validate(dev, start, blkcnt);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
|
2023-08-13 23:46:44 +00:00
|
|
|
return blk_erase(dev_get_parent(dev), disk_blk_part_offset(dev, start),
|
|
|
|
blkcnt);
|
dm: disk: add read/write interfaces with udevice
In include/blk.h, Simon suggested:
===>
/*
* These functions should take struct udevice instead of struct blk_desc,
* but this is convenient for migration to driver model. Add a 'd' prefix
* to the function operations, so that blk_read(), etc. can be reserved for
* functions with the correct arguments.
*/
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *buffer);
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt);
<===
So new interfaces are provided with this patch.
They are expected to be used everywhere in U-Boot at the end.
The exceptions are block device drivers, partition drivers and efi_disk
which should know details of blk_desc structure.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2022-04-19 01:05:16 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 01:05:09 +00:00
|
|
|
UCLASS_DRIVER(partition) = {
|
|
|
|
.id = UCLASS_PARTITION,
|
|
|
|
.per_device_plat_auto = sizeof(struct disk_part),
|
|
|
|
.name = "partition",
|
|
|
|
};
|
2023-08-13 23:46:46 +00:00
|
|
|
|
|
|
|
static const struct blk_ops blk_part_ops = {
|
|
|
|
.read = disk_blk_read,
|
|
|
|
.write = disk_blk_write,
|
|
|
|
.erase = disk_blk_erase,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(blk_partition) = {
|
|
|
|
.name = "blk_partition",
|
|
|
|
.id = UCLASS_PARTITION,
|
|
|
|
.ops = &blk_part_ops,
|
|
|
|
};
|