From: Simon Glass <sjg@chromium.org>
The blk_dread() and blk_dwrite() functions take a struct blk_desc,
but this is a legacy interface meant to be replaced by blk_read() and
blk_write() which take a struct udevice.
Convert ext4l's block I/O layer to store a struct udevice pointer
instead of struct blk_desc, and use blk_read() / blk_write() for
block device access in support.c. The blk_desc is obtained from the
udevice via dev_get_uclass_plat() for the block size. The probe path
obtains the udevice from the blk_desc's bdev field.
Tidy up the code style in the read/write functions while here.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
fs/ext4l/ext4_uboot.h | 14 ++++++++++--
fs/ext4l/interface.c | 11 +++++----
fs/ext4l/support.c | 53 +++++++++++++++++++++++--------------------
3 files changed, 47 insertions(+), 31 deletions(-)
@@ -263,8 +263,18 @@ void ext4l_msg_init(void);
void ext4l_print_msgs(void);
void ext4l_record_msg(const char *msg, int len);
-/* ext4l interface functions (interface.c) */
-struct blk_desc *ext4l_get_blk_dev(void);
+/**
+ * ext4l_get_blk() - Get the current block device
+ *
+ * Return: Block udevice, or NULL if not mounted
+ */
+struct udevice *ext4l_get_blk(void);
+
+/**
+ * ext4l_get_partition() - Get the current partition info
+ *
+ * Return: Partition info pointer, or NULL if not mounted
+ */
struct disk_partition *ext4l_get_partition(void);
#endif /* __EXT4_UBOOT_H__ */
@@ -31,7 +31,7 @@ static struct blk_desc *ext4l_dev_desc;
static struct disk_partition ext4l_part;
/* Global block device tracking for buffer I/O */
-static struct blk_desc *ext4l_blk_dev;
+static struct udevice *ext4l_blk_dev;
static struct disk_partition ext4l_partition;
static int ext4l_mounted;
@@ -42,11 +42,11 @@ static int ext4l_open_dirs;
static struct super_block *ext4l_sb;
/**
- * ext4l_get_blk_dev() - Get the current block device
+ * ext4l_get_blk() - Get the current block device
*
* Return: Block device descriptor or NULL if not mounted
*/
-struct blk_desc *ext4l_get_blk_dev(void)
+struct udevice *ext4l_get_blk(void)
{
if (!ext4l_mounted)
return NULL;
@@ -123,7 +123,8 @@ int ext4l_statfs(struct fs_statfs *stats)
* @blk_dev: Block device descriptor
* @partition: Partition info (can be NULL for whole disk)
*/
-void ext4l_set_blk_dev(struct blk_desc *blk_dev, struct disk_partition *partition)
+void ext4l_set_blk_dev(struct udevice *blk_dev,
+ struct disk_partition *partition)
{
ext4l_blk_dev = blk_dev;
if (partition)
@@ -408,7 +409,7 @@ int ext4l_probe(struct blk_desc *fs_dev_desc,
memcpy(&ext4l_part, fs_partition, sizeof(ext4l_part));
/* Set block device for buffer I/O */
- ext4l_set_blk_dev(fs_dev_desc, fs_partition);
+ ext4l_set_blk_dev(fs_dev_desc->bdev, fs_partition);
/*
* Test if device supports writes by writing back the same data.
@@ -10,6 +10,7 @@
*/
#include <blk.h>
+#include <dm.h>
#include <membuf.h>
#include <part.h>
#include <malloc.h>
@@ -500,26 +501,28 @@ void free_buffer_head(struct buffer_head *bh)
*/
int ext4l_read_block(sector_t block, size_t size, void *buffer)
{
- struct blk_desc *blk_dev;
struct disk_partition *part;
- lbaint_t sector;
- lbaint_t sector_count;
- unsigned long n;
+ lbaint_t sector, count;
+ struct blk_desc *desc;
+ struct udevice *blk;
+ ulong n;
- blk_dev = ext4l_get_blk_dev();
+ blk = ext4l_get_blk();
part = ext4l_get_partition();
- if (!blk_dev)
+ if (!blk)
return -EIO;
+ desc = dev_get_uclass_plat(blk);
+
/* Convert block to sector */
- sector = (block * size) / blk_dev->blksz + part->start;
- sector_count = size / blk_dev->blksz;
+ sector = (block * size) / desc->blksz + part->start;
+ count = size / desc->blksz;
- if (sector_count == 0)
- sector_count = 1;
+ if (count == 0)
+ count = 1;
- n = blk_dread(blk_dev, sector, sector_count, buffer);
- if (n != sector_count)
+ n = blk_read(blk, sector, count, buffer);
+ if (n != count)
return -EIO;
return 0;
@@ -534,26 +537,28 @@ int ext4l_read_block(sector_t block, size_t size, void *buffer)
*/
int ext4l_write_block(sector_t block, size_t size, void *buffer)
{
- struct blk_desc *blk_dev;
struct disk_partition *part;
- lbaint_t sector;
- lbaint_t sector_count;
- unsigned long n;
+ lbaint_t sector, count;
+ struct blk_desc *desc;
+ struct udevice *blk;
+ ulong n;
- blk_dev = ext4l_get_blk_dev();
+ blk = ext4l_get_blk();
part = ext4l_get_partition();
- if (!blk_dev)
+ if (!blk)
return -EIO;
+ desc = dev_get_uclass_plat(blk);
+
/* Convert block to sector */
- sector = (block * size) / blk_dev->blksz + part->start;
- sector_count = size / blk_dev->blksz;
+ sector = (block * size) / desc->blksz + part->start;
+ count = size / desc->blksz;
- if (sector_count == 0)
- sector_count = 1;
+ if (count == 0)
+ count = 1;
- n = blk_dwrite(blk_dev, sector, sector_count, buffer);
- if (n != sector_count)
+ n = blk_write(blk, sector, count, buffer);
+ if (n != count)
return -EIO;
return 0;