From patchwork Sat Apr 11 00:36:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2158 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775867830; bh=vu+UuXsjT/kwCvM0OF8XAMBDBMUWVGHnRysQQVyZQQI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=LVPZ0yqA+7yzdyvmUvHrj/yH7Z0lq6LwNrc+JFwjUPvgM1qy7cGkzY+iDOvDtrWUZ BL2Zb+kgNzQWJb0Mf7XR3O5yoWsShg3rTolfCgfzJ/AWhge+phHc1FFun0CGdyBuJD oizhL7jjKKyU/zNFqPOuxXJp/eZhrHiu2FIJIaUFPfmsjPEjJ/btSblo/0iacuuDLq YdyM2Rt93RcrRQM/fbPeiplk4GTcK3zuwrWMPg12Y6e125WxIJyslFp7NXDpr/zIl7 8z6fTtkQF/irquKtZW5wRX4Aijx1hYgrfG0DM9hBgEe+gPwfcH6+iK8l+aMnL+LBXo S0lj3fHggMgSQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9B5DB6A446 for ; Fri, 10 Apr 2026 18:37:10 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 6c5s45xX4RVZ for ; Fri, 10 Apr 2026 18:37:10 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775867829; bh=vu+UuXsjT/kwCvM0OF8XAMBDBMUWVGHnRysQQVyZQQI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=kbI5ToHvNvOeKcPz1gxoVYi/xJse0johyVr4xtgGREyrB6YF9fy+jDQutfZNGd1Ho j+j9zxbDLfMyUZWHMHHq17x/1GmqFUDDPfVrnQ6NTA5HP4xaVeayLdSVmPZaIbuyYt L0wF9BCy9p3hwEMVjKRol/WSzG7gvRfjo77XwYg1QttLStwvnoCQbTZKARG4qaWG+T aJtIkXxQaMbwEWnnv5aXVbkrcTB9vzIbNlsg2gPBqfo2Iyf6U9SPcIvjMElnJ0Kqgy vCtPsMtZ5dgXl/sAKbWT5UHu1x8vu75IF0jUM3bKGZYImbc67oc1MBVapd1YDM9krT ZD3uzt4Jbg4+Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 432176A434 for ; Fri, 10 Apr 2026 18:37:09 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775867825; bh=r3dNsy+gn0xB5oE2FIkYkq82NOH7taPK2MzQrvXO4+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsBakkxgB7Vwx5Mnhqeymv5JcTGBJUPjJsSdg0CFOxww7a/F0YSln+N8WZOOxR+zn Ao0YvD4/bT1aSnsMBBe354oDAtxxIs3/tayulD9uHprRgvqZxKJKq2Z+ldinD4QSqi Ew9fRKo3Q27g3fy5tNQtso8D14uIVKL0QuYB/vHrY2De9u5onmhN+S8UOnGXhZlXZi /iB1U6D0IYAXHF4FX7NuFxDurJ0CXyR3hqN9wkOmTs2ybrZ78t1VSAYvUU0R1m0Igp 5jNYkKz1BvZZ0qrnXrstui8lMDd384QofUSLAKCSxCCNY9bg569eyTYCUhUCv8MOT5 nZm0/pEZUIbtQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 83BC66A429; Fri, 10 Apr 2026 18:37:05 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id eANq4s2bRLuL; Fri, 10 Apr 2026 18:37:05 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775867821; bh=xEjCQBrMWNIdUmwX2XZ0LI/TAsZ+ITQ/3obWEKJpvwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f3vjBuz843iPexiay7dl/gfHVyodWr8mIYJZRE6RtCVS++mz+ARTXJrewnvwoUYbX Qljoq1INzp0VXLD30gNJ3Izde2tYjGxaRHonYCKlVEquqrabXXKsYvQIVXssnzh4dn y6AFK8QdywDFEjvriYER5Axwz4wn6tqmh0/HhxWPAEBcqv8q/1I5mwfEFS9fn8plVL vjPyrha93JmK0xy8N/8mHNQDeESG8CEjA2cyDuEpVTsgalHcv1GI6+bVqq1jTJG4b2 AXiL1Vd2uPcgMnAGd92HPcW6S3HMmoS1sMv2i+iQD5gD1+oA2UEoiEnUmLyse4HkRW ck863YlmMPwWQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A0F4B6A42B; Fri, 10 Apr 2026 18:37:01 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 10 Apr 2026 18:36:34 -0600 Message-ID: <20260411003647.2592586-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411003647.2592586-1-sjg@u-boot.org> References: <20260411003647.2592586-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: PX556J556OAVY2CT2W5Y4JUO2ZHD2MWO X-Message-ID-Hash: PX556J556OAVY2CT2W5Y4JUO2ZHD2MWO X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 2/8] ext4l: Use struct udevice for block I/O instead of blk_desc List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 --- fs/ext4l/ext4_uboot.h | 14 ++++++++++-- fs/ext4l/interface.c | 11 +++++---- fs/ext4l/support.c | 53 +++++++++++++++++++++++-------------------- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 24402f21790..2ca7f018bc8 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -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__ */ diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index d854c310be3..893f71c1f1c 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -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. diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 4025d291fec..cd7c0b4b802 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -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;