* [PATCH 01/26] nvme: use barebox-appropriate 64-bit type for timeouts
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 02/26] nvme: fix buffer advancement when chunking due to max_hw_sectors Ahmad Fatoum
` (24 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The unsigned timeout that is used across the nvme support is in terms of
jiffies in Linux, where unsigned as type makes sense.
barebox has no jiffies though and we use the parameter to hold a nanosecond
time duration instead, which already overflows for ADMIN_TIMEOUT and
SHUTDOWN_TIMEOUT (60s and 5s, respectively) as they exceed the ~4s max.
Switch over to passing ktime_t around to fix this.
Fixes: aedcb568afe4 ("drivers: Import a very basic NVME implementation from Linux")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/nvme/host/core.c | 2 +-
drivers/nvme/host/nvme.h | 4 ++--
drivers/nvme/host/pci.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index fcc21677638a..98731ffe7cb2 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -8,7 +8,7 @@ int __nvme_submit_sync_cmd(struct nvme_ctrl *ctrl,
struct nvme_command *cmd,
union nvme_result *result,
void *buffer, unsigned bufflen,
- unsigned timeout, int qid)
+ ktime_t timeout, int qid)
{
return ctrl->ops->submit_sync_cmd(ctrl, cmd, result, buffer, bufflen,
timeout, qid);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 90121bd7a3e0..11942140ce32 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -77,7 +77,7 @@ struct nvme_ctrl_ops {
union nvme_result *result,
void *buffer,
unsigned bufflen,
- unsigned timeout, int qid);
+ ktime_t timeout, int qid);
};
static inline bool nvme_ctrl_ready(struct nvme_ctrl *ctrl)
@@ -120,7 +120,7 @@ int __nvme_submit_sync_cmd(struct nvme_ctrl *ctrl,
struct nvme_command *cmd,
union nvme_result *result,
void *buffer, unsigned bufflen,
- unsigned timeout, int qid);
+ ktime_t timeout, int qid);
int nvme_submit_sync_cmd(struct nvme_ctrl *ctrl,
struct nvme_command *cmd,
void *buffer, unsigned bufflen);
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 672c4cc2331a..765821aa0a65 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -384,7 +384,7 @@ static int nvme_pci_submit_sync_cmd(struct nvme_ctrl *ctrl,
union nvme_result *result,
void *buffer,
unsigned int buffer_len,
- unsigned timeout, int qid)
+ ktime_t timeout, int qid)
{
struct nvme_dev *dev = to_nvme_dev(ctrl);
struct nvme_queue *nvmeq = &dev->queues[qid];
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 02/26] nvme: fix buffer advancement when chunking due to max_hw_sectors
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 01/26] nvme: use barebox-appropriate 64-bit type for timeouts Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 03/26] nvme: allow flush opcode Ahmad Fatoum
` (23 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
max_hw_sectors can be derived by reading from the NVMe driver and
controls how many sectors to maximally read/write at once.
Bigger reads/writes were split by doing the operation in a loop.
However, only the first iteration of the loop worked, because the buffer
was advanced by the _block_ count and not the _byte_ count.
Fix this by advancing by advancing by number of bytes instead.
Fixes: aedcb568afe4 ("drivers: Import a very basic NVME implementation from Linux")
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/nvme/host/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 98731ffe7cb2..21aeda78ebfb 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -328,7 +328,7 @@ static int nvme_submit_sync_rw(struct nvme_ns *ns, struct nvme_command *cmnd,
break;
num_blocks -= chunk;
- buffer += chunk;
+ buffer += chunk << ns->lba_shift;
block += chunk;
}
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 03/26] nvme: allow flush opcode
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 01/26] nvme: use barebox-appropriate 64-bit type for timeouts Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 02/26] nvme: fix buffer advancement when chunking due to max_hw_sectors Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 04/26] nvme: honor namespace block size for I/O Ahmad Fatoum
` (22 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The NVMe flush opcode was already wired as block_device_ops::flush,
but it was doomed to fail as without a DMA direction set,
nvme_pci_submit_sync_cmd() would early exit with -EINVAL.
As the command isn't DMAng any data, set dma_dir to DMA_NONE to get the
flush command flushed.
Fixes: aedcb568afe4 ("drivers: Import a very basic NVME implementation from Linux")
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/nvme/host/pci.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 765821aa0a65..6343af25026b 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -414,6 +414,9 @@ static int nvme_pci_submit_sync_cmd(struct nvme_ctrl *ctrl,
break;
case NVME_QID_IO:
switch (cmd->rw.opcode) {
+ case nvme_cmd_flush:
+ dma_dir = DMA_NONE;
+ break;
case nvme_cmd_write:
dma_dir = DMA_TO_DEVICE;
break;
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 04/26] nvme: honor namespace block size for I/O
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (2 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 03/26] nvme: allow flush opcode Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 05/26] bootscan: fix detection of GPT Ahmad Fatoum
` (21 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The translation inside nvme_block_nr() is a no-op for 512-byte sectors
as it expands to a right shift by (9 - 9) == 0.
For other sector sizes, it will mangle the block number, which is wrong:
block_device_ops already have blocks as units and NVMe registers the
block device with blockbits == ns->lba_shift, so the unit coming from the
block layer is already correct.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/nvme/host/core.c | 2 +-
drivers/nvme/host/nvme.h | 5 -----
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 21aeda78ebfb..345707ecfeaf 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -293,7 +293,7 @@ static void nvme_setup_rw(struct nvme_ns *ns, struct nvme_command *cmnd,
sector_t block, blkcnt_t num_block)
{
cmnd->rw.nsid = cpu_to_le32(ns->head->ns_id);
- cmnd->rw.slba = cpu_to_le64(nvme_block_nr(ns, block));
+ cmnd->rw.slba = cpu_to_le64(block);
cmnd->rw.length = cpu_to_le16(num_block - 1);
cmnd->rw.control = 0;
cmnd->rw.dsmgmt = 0;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 11942140ce32..cb259b5216f1 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -89,11 +89,6 @@ static inline bool nvme_ctrl_ready(struct nvme_ctrl *ctrl)
return val & NVME_CSTS_RDY;
}
-static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector)
-{
- return (sector >> (ns->lba_shift - 9));
-}
-
static inline void nvme_end_request(struct nvme_request *rq, __le16 status,
union nvme_result result)
{
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 05/26] bootscan: fix detection of GPT
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (3 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 04/26] nvme: honor namespace block size for I/O Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 06/26] block: clarify that writebuffer_io_len returns sector counts Ahmad Fatoum
` (20 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The "EFI PART" magic string identifying the GPT starts at the second
LBA. As an LBA is at least 512 byte in size, allocating only that many
bytes means the code below checking for a GPT will never succeed.
Bump up the buffer size to FILE_TYPE_SAFE_BUFSIZE to fix this for 512
byte sectors. Support for larger sectors will be added separately.
While at it, also make use of cdev_read's return value, which indicates
the number of bytes actually read into the buffer.
Fixes: ef5dac9c2bf7 ("Implement bootloader spec support for barebox")
Fixes: 718ae461eb38 ("common: bootscan: add scan_disk callback")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/bootscan.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/common/bootscan.c b/common/bootscan.c
index faaceaa22152..1c865c6b1382 100644
--- a/common/bootscan.c
+++ b/common/bootscan.c
@@ -85,7 +85,8 @@ int boot_scan_cdev(struct bootscanner *scanner,
bool autodiscover)
{
int ret, found = 0;
- void *buf = xzalloc(512);
+ size_t bufsize, readsize;
+ void *buf;
enum filetype type, filetype;
const char *rootpath;
@@ -96,14 +97,20 @@ int boot_scan_cdev(struct bootscanner *scanner,
return 0;
}
- ret = cdev_read(cdev, buf, 512, 0, 0);
+ bufsize = FILE_TYPE_SAFE_BUFSIZE;
+
+ buf = xzalloc(bufsize);
+
+ ret = cdev_read(cdev, buf, bufsize, 0, 0);
if (ret < 0) {
free(buf);
return ret;
}
- type = file_detect_partition_table(buf, 512);
- filetype = file_detect_type(buf, 512);
+ readsize = ret;
+
+ type = file_detect_partition_table(buf, readsize);
+ filetype = file_detect_type(buf, readsize);
free(buf);
if (type == filetype_mbr || type == filetype_gpt) {
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 06/26] block: clarify that writebuffer_io_len returns sector counts
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (4 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 05/26] bootscan: fix detection of GPT Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 07/26] block: fix wrong type for discard_start/size byte ranges Ahmad Fatoum
` (19 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
It's not immediately clear whether len is the block count or the byte
count and indeed the two callsites of writebuffer_io_len() interpret it
differently.
In preparation for fixing that, adjust return type and function name to
reflect that number of blocks is the unit.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/block.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/common/block.c b/common/block.c
index beb7e7b14fdd..96f48ba7aa41 100644
--- a/common/block.c
+++ b/common/block.c
@@ -29,7 +29,7 @@ struct chunk {
#define BUFSIZE (PAGE_SIZE * 16)
-static int writebuffer_io_len(struct block_device *blk, struct chunk *chunk)
+static blkcnt_t writebuffer_io_nblocks(struct block_device *blk, struct chunk *chunk)
{
return min_t(blkcnt_t, blk->rdbufsize, blk->num_blocks - chunk->block_start);
}
@@ -55,7 +55,7 @@ static void blk_stats_record_erase(struct block_device *blk, blkcnt_t count) { }
static int chunk_flush(struct block_device *blk, struct chunk *chunk)
{
- size_t len;
+ blkcnt_t len;
int ret;
if (!chunk->dirty)
@@ -64,7 +64,7 @@ static int chunk_flush(struct block_device *blk, struct chunk *chunk)
if (!blk->ops->write)
return 0;
- len = writebuffer_io_len(blk, chunk);
+ len = writebuffer_io_nblocks(blk, chunk);
ret = blk->ops->write(blk, chunk->data, chunk->block_start, len);
if (ret < 0)
return ret;
@@ -171,7 +171,7 @@ static struct chunk *get_chunk(struct block_device *blk)
static int block_cache(struct block_device *blk, sector_t block)
{
struct chunk *chunk;
- size_t len;
+ blkcnt_t len;
int ret;
chunk = get_chunk(blk);
@@ -183,7 +183,7 @@ static int block_cache(struct block_device *blk, sector_t block)
dev_vdbg(blk->dev, "%s: %llu to %d\n", __func__, chunk->block_start,
chunk->num);
- len = writebuffer_io_len(blk, chunk);
+ len = writebuffer_io_nblocks(blk, chunk);
if (chunk->block_start * BLOCKSIZE(blk) >= blk->discard_start &&
chunk->block_start * BLOCKSIZE(blk) + len
<= blk->discard_start + blk->discard_size) {
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 07/26] block: fix wrong type for discard_start/size byte ranges
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (5 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 06/26] block: clarify that writebuffer_io_len returns sector counts Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 08/26] block: fix discard zeroing too little memory Ahmad Fatoum
` (18 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
When these members were first added, they were loff_t, but then later on
erroneously changed to sector_t/blkcnt_t.
The way they are used is still bogus and will be fixed in the follow-up
commit.
No functional change.
Fixes: 130fbc7f6c67 ("block: use 64-bit types for sector offset and count on all platforms")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/block.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/block.h b/include/block.h
index aeb8e990937b..fa916f8d4ee7 100644
--- a/include/block.h
+++ b/include/block.h
@@ -51,8 +51,8 @@ struct block_device {
int rdbufsize;
int blkmask;
- sector_t discard_start;
- blkcnt_t discard_size;
+ loff_t discard_start;
+ loff_t discard_size;
struct list_head buffered_blocks;
struct list_head idle_blocks;
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 08/26] block: fix discard zeroing too little memory
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (6 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 07/26] block: fix wrong type for discard_start/size byte ranges Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 09/26] block: use logical block size for reparse checks Ahmad Fatoum
` (17 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Discard ranges are stored as cdev byte ranges, while
writebuffer_io_nblocks() returns a number of logical blocks.
block_cache() mixes these units up when checking whether a cache chunk
falls inside the most recent discard range.
This bug resulted in a cache hit for discarded data zeroing only the
logical block count in bytes. A 16-block chunk cleared 16 bytes instead of
16 logical blocks, leaving stale data in the rest of the cache buffer.
Fixes: e488952b9d ("block: Implement discard_range")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/block.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/block.c b/common/block.c
index 96f48ba7aa41..f4b2a692407a 100644
--- a/common/block.c
+++ b/common/block.c
@@ -185,9 +185,9 @@ static int block_cache(struct block_device *blk, sector_t block)
len = writebuffer_io_nblocks(blk, chunk);
if (chunk->block_start * BLOCKSIZE(blk) >= blk->discard_start &&
- chunk->block_start * BLOCKSIZE(blk) + len
+ (chunk->block_start + len) * BLOCKSIZE(blk)
<= blk->discard_start + blk->discard_size) {
- memset(chunk->data, 0, len);
+ memset(chunk->data, 0, len << blk->blockbits);
list_add(&chunk->list, &blk->buffered_blocks);
return 0;
}
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 09/26] block: use logical block size for reparse checks
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (7 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 08/26] block: fix discard zeroing too little memory Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 10/26] block: require lower bound of sector size to be 512 bytes Ahmad Fatoum
` (16 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
A reparse of the partition table at close time is queued if the two
first sectors are written.
In preparation for allowing non-512-byte sectors, replace the hardcoded
512-byte sector size with the block size encoded into the block device.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/block.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/block.c b/common/block.c
index f4b2a692407a..20ec3665d900 100644
--- a/common/block.c
+++ b/common/block.c
@@ -326,7 +326,7 @@ static ssize_t block_op_write(struct cdev *cdev, const void *buf, size_t count,
* written to LBA1, so LBA1 must change as well when the partioning
* is changed.
*/
- if (offset < 2 * SECTOR_SIZE)
+ if (offset < 2 * BLOCKSIZE(blk))
blk->need_reparse = true;
if (offset & mask) {
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 10/26] block: require lower bound of sector size to be 512 bytes
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (8 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 09/26] block: use logical block size for reparse checks Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 11/26] filetype: don't hardcode sector size in file_detect_partition_table Ahmad Fatoum
` (15 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Various places around barebox implicitly assume 512 byte sectors. We are
going to generalize that to be able to support larger block sizes as
newer storage media can have 4k sectors.
As sector sizes below 512 bytes seem only relevant for historic floppy
disks and the like, define MIN_SECTOR_SHIFT/SIZE to that sector size and
refuse registering a block device that has a smaller sector size, so we do
not need to replicate that check in the users of blockdevice_register().
The new MIN_SECTOR_SHIFT/SIZE macros are added to make it easier in
future to differentiate between valid sanity checks like what's added
here and hardcoded sector assumptions that should be fixed.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/block.c | 2 +-
include/disks.h | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/common/block.c b/common/block.c
index 20ec3665d900..9d3865626555 100644
--- a/common/block.c
+++ b/common/block.c
@@ -471,7 +471,7 @@ int blockdevice_register(struct block_device *blk)
dev_dbg(blk->dev, "rdbufsize: %d blockbits: %d blkmask: 0x%08x\n",
blk->rdbufsize, blk->blockbits, blk->blkmask);
- if (!blk->rdbufsize) {
+ if (!blk->rdbufsize || blk->blockbits < MIN_SECTOR_SHIFT) {
pr_warn("block size of %u not supported\n", BLOCKSIZE(blk));
return -ENOSYS;
}
diff --git a/include/disks.h b/include/disks.h
index a3673d1e276f..93f8bb2b7c26 100644
--- a/include/disks.h
+++ b/include/disks.h
@@ -8,6 +8,13 @@
struct block_device;
+/** Minimum size of one sector in bytes */
+#define MIN_SECTOR_SIZE 512
+
+/** Minimum size of one sector in bit shift */
+#define MIN_SECTOR_SHIFT 9
+
+
/** Size of one sector in bytes */
#define SECTOR_SIZE 512
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 11/26] filetype: don't hardcode sector size in file_detect_partition_table
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (9 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 10/26] block: require lower bound of sector size to be 512 bytes Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 12/26] block: define helpers for non-512-byte sector support Ahmad Fatoum
` (14 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The GPT is identified by the second LBA starting with "EFI PART".
file_detect_partition_table() checks for that, but implicitly assumes LBA
size to be 512 byte, which precludes using it to detect partitions
tables on block device with e.g. 4K block sizes.
In preparation for fixing that, adapt file_detect_partition_table() to
always take a sector size.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/createnv.c | 2 +-
common/bootscan.c | 3 ++-
common/filetype.c | 16 +++++++++-------
common/partitions.c | 4 ++--
common/partitions/efi.c | 3 ++-
include/filetype.h | 3 ++-
6 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/commands/createnv.c b/commands/createnv.c
index df03664be112..0c74637a114c 100644
--- a/commands/createnv.c
+++ b/commands/createnv.c
@@ -77,7 +77,7 @@ static int do_createnv(int argc, char *argv[])
goto err;
}
- filetype = file_detect_partition_table(buf, 2 * SECTOR_SIZE);
+ filetype = file_detect_partition_table(buf, 2 * SECTOR_SIZE, SECTOR_SIZE);
switch (filetype) {
case filetype_gpt:
diff --git a/common/bootscan.c b/common/bootscan.c
index 1c865c6b1382..5b70024a75aa 100644
--- a/common/bootscan.c
+++ b/common/bootscan.c
@@ -4,6 +4,7 @@
#include <driver.h>
#include <xfuncs.h>
#include <block.h>
+#include <disks.h>
#include <fs.h>
#include <linux/stat.h>
#include <linux/err.h>
@@ -109,7 +110,7 @@ int boot_scan_cdev(struct bootscanner *scanner,
readsize = ret;
- type = file_detect_partition_table(buf, readsize);
+ type = file_detect_partition_table(buf, readsize, SECTOR_SIZE);
filetype = file_detect_type(buf, readsize);
free(buf);
diff --git a/common/filetype.c b/common/filetype.c
index 80b7e1d98ce0..01cef7f1fbb7 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -157,16 +157,16 @@ static inline int pmbr_part_valid(const uint8_t *buf)
* Validity depends on three things:
* 1) MSDOS signature is in the last two bytes of the MBR
* 2) One partition of type 0xEE is found
- * 3) EFI GPT signature is at offset 512
+ * 3) EFI GPT signature is at the next logical block
*/
-static int is_gpt_valid(const uint8_t *buf)
+static int is_gpt_valid(const uint8_t *buf, unsigned int sector_size)
{
int i;
if (get_unaligned_le16(&buf[BS_55AA]) != 0xAA55)
return 0;
- if (strncmp(&buf[512], "EFI PART", 8))
+ if (strncmp(buf + sector_size, "EFI PART", 8))
return 0;
buf += MBR_Table;
@@ -268,19 +268,21 @@ enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
return filetype_mbr;
}
-enum filetype file_detect_partition_table(const void *_buf, size_t bufsize)
+enum filetype file_detect_partition_table(const void *_buf,
+ size_t bufsize,
+ unsigned int sector_size)
{
const u8 *buf8 = _buf;
enum filetype type;
- if (bufsize < 512)
+ if (bufsize < MIN_SECTOR_SIZE || sector_size < MIN_SECTOR_SIZE)
return filetype_unknown;
/*
* EFI GPT need to be detected before MBR otherwise
* we will detect a MBR
*/
- if (bufsize >= 520 && is_gpt_valid(buf8))
+ if (bufsize >= sector_size + 8 && is_gpt_valid(buf8, sector_size))
return filetype_gpt;
type = is_fat_or_mbr(buf8, NULL);
@@ -468,7 +470,7 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if (bufsize < 512)
return filetype_unknown;
- type = file_detect_partition_table(_buf, bufsize);
+ type = file_detect_partition_table(_buf, bufsize, SECTOR_SIZE);
if (type != filetype_unknown)
return type;
diff --git a/common/partitions.c b/common/partitions.c
index 40f4c629e1ac..ff977516aa1f 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -97,7 +97,7 @@ static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
struct partition_parser *parser;
/* first new partition table as EFI GPT */
- type = file_detect_partition_table(buf, SECTOR_SIZE * 2);
+ type = file_detect_partition_table(buf, SECTOR_SIZE * 2, SECTOR_SIZE);
list_for_each_entry(parser, &partition_parser_list, list) {
if (parser->type == type)
@@ -108,7 +108,7 @@ static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
* so if EFI GPT not enable take it as MBR
* useful for compatibility
*/
- type = file_detect_partition_table(buf, SECTOR_SIZE);
+ type = file_detect_partition_table(buf, SECTOR_SIZE, SECTOR_SIZE);
if (type == filetype_fat && !is_fat_boot_sector(buf))
type = filetype_mbr;
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 674f920743d3..4847f88fa551 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -505,7 +505,8 @@ static int find_valid_gpt(struct efi_partition_desc *epd, void *buf)
lastlba = last_lba(blk);
if (force_gpt) {
/* This will be added to the EFI Spec. per Intel after v1.02. */
- if (file_detect_partition_table(buf, SECTOR_SIZE * 2) != filetype_gpt)
+ if (file_detect_partition_table(buf, SECTOR_SIZE * 2,
+ SECTOR_SIZE) != filetype_gpt)
goto fail;
}
diff --git a/include/filetype.h b/include/filetype.h
index 759ef9c2a343..2fd0e2217729 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -81,7 +81,8 @@ struct cdev;
const char *file_type_to_string(enum filetype f);
const char *file_type_to_short_string(enum filetype f);
-enum filetype file_detect_partition_table(const void *_buf, size_t bufsize);
+enum filetype file_detect_partition_table(const void *_buf, size_t bufsize,
+ unsigned int sector_size);
enum filetype file_detect_compression_type(const void *_buf, size_t bufsize);
enum filetype file_detect_fs_type(const void *_buf, size_t bufsize);
enum filetype file_detect_type(const void *_buf, size_t bufsize);
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 12/26] block: define helpers for non-512-byte sector support
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (10 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 11/26] filetype: don't hardcode sector size in file_detect_partition_table Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 13/26] bootscan: use block size for partition table probe Ahmad Fatoum
` (13 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Instead of opencoding the checks at the various direct and indirect (via
cdev API) block device users that are going to be switched away from
hardcoding the 512 byte sector assumption, define some helpers.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/block.c | 11 +++++++++++
include/block.h | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/common/block.c b/common/block.c
index 9d3865626555..5f509bfb9df3 100644
--- a/common/block.c
+++ b/common/block.c
@@ -14,6 +14,7 @@
#include <range.h>
#include <bootargs.h>
#include <file-list.h>
+#include <linux/log2.h>
LIST_HEAD(block_device_list);
EXPORT_SYMBOL(block_device_list);
@@ -53,6 +54,16 @@ static void blk_stats_record_write(struct block_device *blk, blkcnt_t count) { }
static void blk_stats_record_erase(struct block_device *blk, blkcnt_t count) { }
#endif
+int block_size_bits(struct device *dev, unsigned block_size)
+{
+ if (block_size < MIN_SECTOR_SIZE || !is_power_of_2(block_size)) {
+ dev_err(dev, "unsupported block size %u\n", block_size);
+ return -ENOTSUPP;
+ }
+
+ return ffs(block_size) - 1;
+}
+
static int chunk_flush(struct block_device *blk, struct chunk *chunk)
{
blkcnt_t len;
diff --git a/include/block.h b/include/block.h
index fa916f8d4ee7..9a0102db1565 100644
--- a/include/block.h
+++ b/include/block.h
@@ -3,6 +3,7 @@
#define __BLOCK_H
#include <driver.h>
+#include <disks.h>
#include <linux/list.h>
#include <linux/types.h>
@@ -68,6 +69,28 @@ struct block_device {
#define BLOCKSIZE(blk) (1u << (blk)->blockbits)
+int block_size_bits(struct device *dev, unsigned block_size);
+
+static inline u64 blockdevice_size(const struct block_device *blk)
+{
+ return blk->num_blocks << blk->blockbits;
+}
+
+static inline blkcnt_t
+blockdevice_round_nblocks(const struct block_device *blk, u64 nbytes)
+{
+ if (nbytes == 0)
+ return 0;
+
+ return (((u64)nbytes - 1) >> blk->blockbits) + 1;
+}
+
+static inline u64
+blockdevice_round_block_nbytes(const struct block_device *blk, u64 nbytes)
+{
+ return blockdevice_round_nblocks(blk, nbytes) << blk->blockbits;
+}
+
extern struct list_head block_device_list;
#define for_each_block_device(bdev) list_for_each_entry(bdev, &block_device_list, list)
@@ -126,4 +149,15 @@ static inline struct block_device *cdev_get_block_device(const struct cdev *cdev
return cdev_is_block_device(cdev) ? cdev->priv : NULL;
}
+static inline unsigned cdev_blockbits(const struct cdev *cdev)
+{
+ struct block_device *bdev = cdev_get_block_device(cdev);
+ return bdev ? bdev->blockbits : SECTOR_SHIFT;
+}
+
+static inline unsigned cdev_blocksize(const struct cdev *cdev)
+{
+ return 1u << cdev_blockbits(cdev);
+}
+
#endif /* __BLOCK_H */
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 13/26] bootscan: use block size for partition table probe
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (11 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 12/26] block: define helpers for non-512-byte sector support Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 14/26] ramdisk: validate exported sector size Ahmad Fatoum
` (12 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
With 4k byte sectors, LBA1, which would contain the GPT magic string
would start at offset 4096, which is well outside the 2048 bytes that
FILE_TYPE_SAFE_BUFSIZE expands to.
Fix this by always reading at least the first two LBAs with the block
size reported by the block device.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/bootscan.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/common/bootscan.c b/common/bootscan.c
index 5b70024a75aa..60eeb06b65c2 100644
--- a/common/bootscan.c
+++ b/common/bootscan.c
@@ -8,6 +8,7 @@
#include <fs.h>
#include <linux/stat.h>
#include <linux/err.h>
+#include <linux/minmax.h>
#include <mtd/ubi-user.h>
#include <uapi/spec/dps.h>
@@ -86,6 +87,7 @@ int boot_scan_cdev(struct bootscanner *scanner,
bool autodiscover)
{
int ret, found = 0;
+ unsigned int blocksize;
size_t bufsize, readsize;
void *buf;
enum filetype type, filetype;
@@ -98,7 +100,8 @@ int boot_scan_cdev(struct bootscanner *scanner,
return 0;
}
- bufsize = FILE_TYPE_SAFE_BUFSIZE;
+ blocksize = cdev_blocksize(cdev);
+ bufsize = max_t(size_t, FILE_TYPE_SAFE_BUFSIZE, 2 * blocksize);
buf = xzalloc(bufsize);
@@ -110,7 +113,7 @@ int boot_scan_cdev(struct bootscanner *scanner,
readsize = ret;
- type = file_detect_partition_table(buf, readsize, SECTOR_SIZE);
+ type = file_detect_partition_table(buf, readsize, blocksize);
filetype = file_detect_type(buf, readsize);
free(buf);
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 14/26] ramdisk: validate exported sector size
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (12 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 13/26] bootscan: use block size for partition table probe Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 15/26] efi: block: fix sector size mismatch in block device registration and ops Ahmad Fatoum
` (11 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
ramdisk_init() currently accepts arbitrary sector sizes, including
sizes smaller than 512 bytes and non-power-of-two.
Make use of the new block_size_bits() to trigger an error message when
this occurs and while at it, also fix the memory leaks if the function
fails.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/block/ramdisk.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/drivers/block/ramdisk.c b/drivers/block/ramdisk.c
index 6f3c9348058a..f6f1c4cda963 100644
--- a/drivers/block/ramdisk.c
+++ b/drivers/block/ramdisk.c
@@ -3,12 +3,12 @@
#include <ramdisk.h>
#include <block.h>
+#include <disks.h>
#include <driver.h>
#include <fs.h>
#include <string.h>
#include <xfuncs.h>
#include <linux/align.h>
-#include <linux/log2.h>
struct ramdisk {
struct block_device blk;
@@ -101,39 +101,55 @@ static struct cdev_operations ramdisk_ops = {
struct ramdisk *ramdisk_init(int sector_size)
{
+ struct device *dev;
struct ramdisk *ramdisk;
struct block_device *blk;
- int ret;
+ int blockbits, ret;
+
ramdisk = xzalloc(sizeof(*ramdisk));
+ dev = &ramdisk->dev;
- dev_set_name(&ramdisk->dev, "ramdisk");
- ramdisk->dev.id = DEVICE_ID_DYNAMIC;
+ dev_set_name(dev, "ramdisk");
+ dev->id = DEVICE_ID_DYNAMIC;
- ret = register_device(&ramdisk->dev);
+ ret = register_device(dev);
if (ret)
- return NULL;
+ goto free_ramdisk;
+
+ blockbits = block_size_bits(dev, sector_size);
+ if (blockbits < 0)
+ goto unregister_device;
blk = &ramdisk->blk;
- blk->dev = &ramdisk->dev;
+ blk->dev = dev;
blk->type = BLK_TYPE_VIRTUAL;
blk->cdev.size = 0;
- blk->cdev.name = xstrdup(dev_name(&ramdisk->dev));
+ blk->cdev.name = xstrdup(dev_name(dev));
blk->cdev.dev = blk->dev;
blk->cdev.ops = &ramdisk_ops;
blk->cdev.priv = ramdisk;
blk->cdev.flags |= DEVFS_IS_BLOCK_DEV;
- blk->blockbits = ilog2(sector_size);
+ blk->blockbits = blockbits;
ret = devfs_create(&blk->cdev);
if (ret)
- return NULL;
+ goto free_cdev_name;
INIT_LIST_HEAD(&blk->buffered_blocks);
INIT_LIST_HEAD(&blk->idle_blocks);
return ramdisk;
+
+free_cdev_name:
+ free(blk->cdev.name);
+unregister_device:
+ unregister_device(dev);
+free_ramdisk:
+ free(ramdisk);
+
+ return NULL;
}
struct block_device *ramdisk_get_block_device(struct ramdisk *ramdisk)
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 15/26] efi: block: fix sector size mismatch in block device registration and ops
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (13 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 14/26] ramdisk: validate exported sector size Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 16/26] efi: loader: disk: report block device size in Block I/O Ahmad Fatoum
` (10 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
efi_bio_read/efi_bio_write use a hardcoded 512 byte multiplier for the
block sizes, while registration happens with whatever block size the EFI
Block I/O protocol had reported.
Drop the hardcoded 512 byte sector sizes and while at it, use
block_size_bits(), so invalid block sizes are rejected early.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/block/efi-block-io.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/block/efi-block-io.c b/drivers/block/efi-block-io.c
index 8955a8c2b585..5f38409fb76d 100644
--- a/drivers/block/efi-block-io.c
+++ b/drivers/block/efi-block-io.c
@@ -34,7 +34,7 @@ static int efi_bio_read(struct block_device *blk, void *buffer, sector_t block,
efi_status_t efiret;
efiret = priv->protocol->read(priv->protocol, priv->media_id,
- block, num_blocks * 512, buffer);
+ block, num_blocks << blk->blockbits, buffer);
if (EFI_ERROR(efiret))
return -efi_errno(efiret);
@@ -49,7 +49,7 @@ static int efi_bio_write(struct block_device *blk,
efi_status_t efiret;
efiret = priv->protocol->write(priv->protocol, priv->media_id,
- block, num_blocks * 512, (void *)buffer);
+ block, num_blocks << blk->blockbits, (void *)buffer);
if (EFI_ERROR(efiret))
return -efi_errno(efiret);
@@ -115,7 +115,7 @@ static bool is_bio_usbdev(struct efi_device *efidev)
static int efi_bio_probe(struct efi_device *efidev)
{
bool is_usbdev;
- int instance;
+ int blockbits, instance;
struct efi_bio_priv *priv;
struct efi_block_io_media *media;
struct device *dev = &efidev->dev;
@@ -124,13 +124,22 @@ static int efi_bio_probe(struct efi_device *efidev)
BS->handle_protocol(efidev->handle, &efi_block_io_protocol_guid,
(void **)&priv->protocol);
- if (!priv->protocol)
+ if (!priv->protocol) {
+ free(priv);
return -ENODEV;
+ }
+
+
+ media = priv->protocol->media;
+ blockbits = block_size_bits(dev, media->block_size);
+ if (blockbits < 0) {
+ free(priv);
+ return blockbits;
+ }
dev->priv = priv;
devinfo_add(dev, efi_bio_print_info);
- media = priv->protocol->media;
if (__is_defined(DEBUG))
efi_bio_print_info(dev);
priv->dev = &efidev->dev;
@@ -147,7 +156,7 @@ static int efi_bio_probe(struct efi_device *efidev)
priv->blk.cdev.name = xasprintf("disk%d", instance);
}
- priv->blk.blockbits = ffs(media->block_size) - 1;
+ priv->blk.blockbits = blockbits;
priv->blk.num_blocks = media->last_block + 1;
priv->blk.ops = &efi_bio_ops;
priv->blk.dev = &efidev->dev;
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 16/26] efi: loader: disk: report block device size in Block I/O
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (14 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 15/26] efi: block: fix sector size mismatch in block device registration and ops Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 17/26] efi: loader: file: report cdev block size in file info Ahmad Fatoum
` (9 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
So far we hardcoded 512 byte block sizes in what we report. This didn't
matter much as we didn't support other block sizes, but when we do soon,
we either need to do block size translation or pass devices as-is.
We will go with the second option, so drop the hardcoded 512-byte sector
sizes.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
efi/loader/protocols/disk.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/efi/loader/protocols/disk.c b/efi/loader/protocols/disk.c
index 5494f9197cb4..5c5447acca20 100644
--- a/efi/loader/protocols/disk.c
+++ b/efi/loader/protocols/disk.c
@@ -22,6 +22,7 @@
#include <malloc.h>
#include <bootsource.h>
#include <block.h>
+#include <disks.h>
#include <fs.h>
const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID;
@@ -194,6 +195,7 @@ static efi_status_t efi_disk_add_cdev(efi_handle_t parent,
struct efi_disk_obj *diskobj;
struct efi_object *handle;
const efi_guid_t *esp_guid = NULL;
+ unsigned int blockbits = cdev_blockbits(cdev);
int score = 0;
efi_status_t ret;
@@ -251,9 +253,9 @@ static efi_status_t efi_disk_add_cdev(efi_handle_t parent,
diskobj->media.removable_media = removable;
diskobj->media.media_present = true;
diskobj->media.read_only = cdev->flags & DEVFS_PARTITION_READONLY;
- diskobj->media.block_size = 512;
- diskobj->media.io_align = 512;
- diskobj->media.last_block = cdev->size / diskobj->media.block_size - 1;
+ diskobj->media.block_size = diskobj->media.io_align = 1u << blockbits;
+ diskobj->media.last_block = (cdev->size >> blockbits) - 1;
+ diskobj->blockbits = blockbits;
diskobj->ops = block_io_disk_template;
diskobj->ops.media = &diskobj->media;
@@ -380,7 +382,6 @@ static efi_status_t efi_disk_register(void *data)
return ret;
}
- disk->blockbits = bdev->blockbits;
ndisks++;
/* Partitions show up as block devices in EFI */
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 17/26] efi: loader: file: report cdev block size in file info
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (15 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 16/26] efi: loader: disk: report block device size in Block I/O Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 18/26] partitions: use byte offset for first partition policy Ahmad Fatoum
` (8 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In a similar vein to the changes to the block I/O protocol, also adapt
the file protocol, so EFI_FILE_SYSTEM_INFO reports the actual block
size.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
efi/loader/protocols/file.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/efi/loader/protocols/file.c b/efi/loader/protocols/file.c
index 0796b3f0c26a..ea7b0df82ea8 100644
--- a/efi/loader/protocols/file.c
+++ b/efi/loader/protocols/file.c
@@ -24,6 +24,7 @@
#include <wchar.h>
#include <string.h>
#include <libfile.h>
+#include <block.h>
#include <disks.h>
#include <charset.h>
#include <malloc.h>
@@ -743,7 +744,7 @@ static efi_status_t EFIAPI efi_file_get_info(struct efi_file_handle *file,
* space. The volume size is the best upper bound we have.
*/
info->free_space = info->volume_size;
- info->block_size = SECTOR_SIZE;
+ info->block_size = cdev_blocksize(fh->fs->cdev);
/*
* TODO: The volume label is not available in barebox.
*/
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 18/26] partitions: use byte offset for first partition policy
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (16 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 17/26] efi: loader: file: report cdev block size in file info Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 19/26] partitions: dos: allocate correctly sized buffer for dos_partition_desc Ahmad Fatoum
` (7 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
global.partitions.first_usable_lba was added to keep some initial free
space for the bootloader image before partitions begin.
As the name suggests, the unit is sectors, which is not so useful, the
next most common sector size after 512 is 4K, so the default 8 MiB
partition offset becomes 64M, which is quite a bit of waste.
Replace it with global.partitions.first_partition_offset, which has a
unit of bytes instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
.../migration-guides/migration-master.rst | 11 ++++++
common/partitions.c | 37 +++++++++----------
common/partitions/efi.c | 2 +-
include/partitions.h | 2 +-
4 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/Documentation/migration-guides/migration-master.rst b/Documentation/migration-guides/migration-master.rst
index 455863357d1d..d2499fb799bd 100644
--- a/Documentation/migration-guides/migration-master.rst
+++ b/Documentation/migration-guides/migration-master.rst
@@ -6,3 +6,14 @@ ARCH=arm64
Use of ``ARCH=arm`` for 64-bit ARM builds is deprecated and now emits
a warning. Users should change build scripts to use ``ARCH=arm64``
instead when targetting ARMv8.
+
+global.partitions.first_usable_lba removed
+------------------------------------------
+
+The ``global.partitions.first_usable_lba`` variable has been removed.
+Use ``global.partitions.first_partition_offset`` instead.
+
+The new variable is a byte offset used by free-space searches for new
+partitions, for example ``parted mkpart_size``. The default is
+``8388608`` bytes (8 MiB). To keep an old configuration, multiply the
+old ``first_usable_lba`` value by 512.
diff --git a/common/partitions.c b/common/partitions.c
index ff977516aa1f..8637b54b1708 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -22,6 +22,7 @@
#include <magicvar.h>
static LIST_HEAD(partition_parser_list);
+static uint64_t first_partition_offset = SZ_8M;
/**
* Register one partition on the given block device
@@ -203,12 +204,12 @@ bool partition_is_free(struct partition_desc *pdesc, uint64_t start, uint64_t si
int partition_find_free_space(struct partition_desc *pdesc, uint64_t sectors, uint64_t *start)
{
struct partition *p;
- uint64_t min_sec = PARTITION_ALIGN_SECTORS;
+ uint64_t align = PARTITION_ALIGN_SECTORS;
+ uint64_t min_sec;
- if (min_sec < partition_first_usable_lba())
- min_sec = partition_first_usable_lba();
+ min_sec = max(align, partition_first_usable_lba(pdesc->blk));
- min_sec = ALIGN(min_sec, PARTITION_ALIGN_SECTORS);
+ min_sec = ALIGN(min_sec, align);
if (partition_is_free(pdesc, min_sec, sectors)) {
*start = min_sec;
@@ -216,7 +217,7 @@ int partition_find_free_space(struct partition_desc *pdesc, uint64_t sectors, ui
}
list_for_each_entry(p, &pdesc->partitions, list) {
- uint64_t s = ALIGN(p->first_sec + p->size, PARTITION_ALIGN_SECTORS);
+ uint64_t s = ALIGN(p->first_sec + p->size, align);
if (partition_is_free(pdesc, s, sectors)) {
*start = s;
@@ -245,9 +246,9 @@ int partition_create(struct partition_desc *pdesc, const char *name,
return -EINVAL;
}
- if (lba_start < partition_first_usable_lba()) {
+ if (lba_start < partition_first_usable_lba(pdesc->blk)) {
pr_err("partition starts before first usable lba: %llu < %llu\n",
- lba_start, partition_first_usable_lba());
+ lba_start, partition_first_usable_lba(pdesc->blk));
return -EINVAL;
}
@@ -424,21 +425,19 @@ loff_t cdev_unallocated_space(struct cdev *cdev)
return start;
}
-static uint64_t first_usable_dma = SZ_8M / SECTOR_SIZE;
-
-uint64_t partition_first_usable_lba(void)
+sector_t partition_first_usable_lba(const struct block_device *blk)
{
- return first_usable_dma;
+ return blockdevice_round_nblocks(blk, first_partition_offset);
}
-static int set_first_usable_lba(struct param_d *p, void *priv)
+static int set_first_partition_offset(struct param_d *p, void *priv)
{
- if (first_usable_dma < 1) {
- pr_err("Minimum is 1\n");
+ if (first_partition_offset < MIN_SECTOR_SIZE) {
+ pr_err("Minimum is 512 bytes\n");
return -EINVAL;
}
- if (first_usable_dma % (SZ_1M / SECTOR_SIZE))
+ if (first_partition_offset % SZ_1M)
pr_warn("recommended to align to 1MiB\n");
return 0;
@@ -449,12 +448,12 @@ static int partitions_init(void)
struct param_d *p = NULL;
if (IS_ENABLED(CONFIG_GLOBALVAR))
- p = dev_add_param_uint64(&global_device, "partitions.first_usable_lba",
- set_first_usable_lba, NULL,
- &first_usable_dma, "%llu", NULL);
+ p = dev_add_param_uint64(&global_device, "partitions.first_partition_offset",
+ set_first_partition_offset, NULL,
+ &first_partition_offset, "%llu", NULL);
return PTR_ERR_OR_ZERO(p);
}
core_initcall(partitions_init);
-BAREBOX_MAGICVAR(global.partitions.first_usable_lba, "first usable LBA used for creating partitions");
+BAREBOX_MAGICVAR(global.partitions.first_partition_offset, "byte offset used by free-space searches for new partitions");
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 4847f88fa551..295c26a5a491 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -690,7 +690,7 @@ static __maybe_unused struct partition_desc *efi_partition_create_table(struct b
gpt_header *gpt;
unsigned int num_partition_entries = 128;
unsigned int gpt_size = (sizeof(gpt_entry) * num_partition_entries) / SECTOR_SIZE;
- unsigned int first_usable_lba = partition_first_usable_lba();
+ unsigned int first_usable_lba = partition_first_usable_lba(blk);
partition_desc_init(&epd->pd, blk);
diff --git a/include/partitions.h b/include/partitions.h
index f73d028e2951..398813eca58c 100644
--- a/include/partitions.h
+++ b/include/partitions.h
@@ -71,6 +71,6 @@ int partition_remove(struct partition_desc *pdesc, int num);
void partition_table_free(struct partition_desc *pdesc);
bool partition_is_free(struct partition_desc *pdesc, uint64_t start, uint64_t size);
int partition_find_free_space(struct partition_desc *pdesc, uint64_t sectors, uint64_t *start);
-uint64_t partition_first_usable_lba(void);
+sector_t partition_first_usable_lba(const struct block_device *blk);
#endif /* __PARTITIONS_PARSER_H__ */
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 19/26] partitions: dos: allocate correctly sized buffer for dos_partition_desc
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (17 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 18/26] partitions: use byte offset for first partition policy Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 20/26] partition: support non-512 byte sectors Ahmad Fatoum
` (6 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
512 bytes is likely more than was ever required for this struct.
Allocate instead exactly as many bytes as needed.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/partitions/dos.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index ce2e21357d52..1526b97dec67 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -318,7 +318,7 @@ static void dos_partition_free(struct partition_desc *pd)
static __maybe_unused struct partition_desc *dos_partition_create_table(struct block_device *blk)
{
- struct dos_partition_desc *dpd = xzalloc(512);
+ struct dos_partition_desc *dpd = xzalloc(sizeof(*dpd));
partition_desc_init(&dpd->pd, blk);
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 20/26] partition: support non-512 byte sectors
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (18 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 19/26] partitions: dos: allocate correctly sized buffer for dos_partition_desc Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 21/26] fs: fat: fix garbage read when writing with bigger block size Ahmad Fatoum
` (5 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Partition parsing still mixed LBAs with hardcoded 512-byte sectors
all over the place.
Carry the block device logical block size through all read paths.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/partitions.c | 55 +++++++++++++++++++++++++++--------------
common/partitions/dos.c | 4 +--
common/partitions/efi.c | 21 ++++++----------
include/partitions.h | 2 +-
4 files changed, 47 insertions(+), 35 deletions(-)
diff --git a/common/partitions.c b/common/partitions.c
index 8637b54b1708..617c2770eadf 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -36,10 +36,10 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
char *partition_name;
int ret;
struct cdev *cdev;
- struct devfs_partition partinfo = {
- .offset = part->first_sec * SECTOR_SIZE,
- .size = part->size * SECTOR_SIZE,
- };
+ struct devfs_partition partinfo = {};
+
+ partinfo.offset = part->first_sec * BLOCKSIZE(blk);
+ partinfo.size = part->size * BLOCKSIZE(blk);
partition_name = xasprintf("%s.%d", blk->cdev.name, part->num);
@@ -92,24 +92,26 @@ static int remove_one_partition(struct block_device *blk, int no)
return ret;
}
-static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
+static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf,
+ unsigned int blocksize)
{
enum filetype type;
struct partition_parser *parser;
/* first new partition table as EFI GPT */
- type = file_detect_partition_table(buf, SECTOR_SIZE * 2, SECTOR_SIZE);
+ type = file_detect_partition_table(buf, blocksize * 2, blocksize);
list_for_each_entry(parser, &partition_parser_list, list) {
if (parser->type == type)
return parser;
}
- /* if not parser found search for old one
- * so if EFI GPT not enable take it as MBR
- * useful for compatibility
+ /* If no parser found search for old one, so if EFI GPT i
+ * not enabled, probe for MBR. useful for compatibility.
+ * 512 is hardcoded here as the MBR detection is not
+ * block-size dependent.
*/
- type = file_detect_partition_table(buf, SECTOR_SIZE, SECTOR_SIZE);
+ type = file_detect_partition_table(buf, 512, 512);
if (type == filetype_fat && !is_fat_boot_sector(buf))
type = filetype_mbr;
@@ -150,9 +152,11 @@ struct partition_desc *partition_table_read(struct block_device *blk)
struct partition_parser *parser;
struct partition_desc *pdesc = NULL;
uint8_t *buf;
+ unsigned int blocksize;
int ret;
- buf = malloc(2 * SECTOR_SIZE);
+ blocksize = BLOCKSIZE(blk);
+ buf = malloc(2 * blocksize);
ret = block_read(blk, buf, 0, 2);
if (ret != 0) {
@@ -160,7 +164,7 @@ struct partition_desc *partition_table_read(struct block_device *blk)
goto err;
}
- parser = partition_parser_get_by_filetype(buf);
+ parser = partition_parser_get_by_filetype(buf, blocksize);
if (!parser)
goto err;
@@ -187,7 +191,7 @@ bool partition_is_free(struct partition_desc *pdesc, uint64_t start, uint64_t si
{
struct partition *p;
- if (start < PARTITION_ALIGN_SECTORS)
+ if (start < partition_align_lba(pdesc->blk))
return false;
if (start + size >= pdesc->blk->num_blocks)
@@ -204,7 +208,7 @@ bool partition_is_free(struct partition_desc *pdesc, uint64_t start, uint64_t si
int partition_find_free_space(struct partition_desc *pdesc, uint64_t sectors, uint64_t *start)
{
struct partition *p;
- uint64_t align = PARTITION_ALIGN_SECTORS;
+ uint64_t align = partition_align_lba(pdesc->blk);
uint64_t min_sec;
min_sec = max(align, partition_first_usable_lba(pdesc->blk));
@@ -371,19 +375,25 @@ static int fuzz_partition_table_parser(struct block_device *ramdisk)
struct partition *part;
int rc = 0;
struct partition_parser *parser;
- u8 buf[2 * SECTOR_SIZE] __aligned(8);
+ u8 *buf;
+ unsigned int blocksize;
+
+ blocksize = BLOCKSIZE(ramdisk);
+ buf = malloc(2 * blocksize);
+ if (!buf)
+ return 0;
rc = block_read(ramdisk, buf, 0, 2);
if (rc != 0)
- return 0;
+ goto out;
- parser = partition_parser_get_by_filetype(buf);
+ parser = partition_parser_get_by_filetype(buf, blocksize);
if (!parser)
- return 0;
+ goto out;
pdesc = parser->parse(buf, ramdisk);
if (!pdesc)
- return 0;
+ goto out;
pdesc->parser = parser;
@@ -394,6 +404,8 @@ static int fuzz_partition_table_parser(struct block_device *ramdisk)
partition_table_free(pdesc);
+out:
+ free(buf);
return 0;
}
fuzz_test_ramdisk("partitions", fuzz_partition_table_parser);
@@ -430,6 +442,11 @@ sector_t partition_first_usable_lba(const struct block_device *blk)
return blockdevice_round_nblocks(blk, first_partition_offset);
}
+sector_t partition_align_lba(const struct block_device *blk)
+{
+ return blockdevice_round_nblocks(blk, PARTITION_ALIGN_SIZE);
+}
+
static int set_first_partition_offset(struct param_d *p, void *priv)
{
if (first_partition_offset < MIN_SECTOR_SIZE) {
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 1526b97dec67..e5286cb6eb1f 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -60,7 +60,7 @@ static inline int is_extended_partition(struct partition *p)
static void *read_mbr(struct block_device *blk)
{
- void *buf = xmalloc(SECTOR_SIZE);
+ void *buf = xmalloc(BLOCKSIZE(blk));
int ret;
ret = block_read(blk, buf, 0, 1);
@@ -126,7 +126,7 @@ static int dos_get_disk_signature(struct param_d *p, void *_priv)
static void dos_extended_partition(struct block_device *blk, struct dos_partition_desc *dpd,
struct partition *partition, uint32_t signature)
{
- uint8_t *buf = xmalloc(SECTOR_SIZE);
+ uint8_t *buf = xmalloc(BLOCKSIZE(blk));
uint32_t ebr_sector = partition->first_sec;
struct partition_entry *table = (struct partition_entry *)&buf[0x1be];
unsigned partno = 4;
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 295c26a5a491..33d9a1df9e83 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -199,19 +199,20 @@ static gpt_entry *alloc_read_gpt_entries(struct block_device *blk,
{
u32 count = 0;
gpt_entry *pte = NULL;
- unsigned long from, size;
+ unsigned long from;
+ blkcnt_t size;
int ret;
count = compute_partitions_entries_size(pgpt_head);
if (!count)
return NULL;
- pte = calloc(count, 1);
+ pte = calloc(blockdevice_round_block_nbytes(blk, count), 1);
if (!pte)
return NULL;
from = le64_to_cpu(pgpt_head->partition_entry_lba);
- size = count / GPT_BLOCK_SIZE;
+ size = blockdevice_round_nblocks(blk, count);
ret = block_read(blk, pte, from, size);
if (ret) {
free(pte);
@@ -220,12 +221,6 @@ static gpt_entry *alloc_read_gpt_entries(struct block_device *blk,
return pte;
}
-static inline unsigned short bdev_logical_block_size(struct block_device
-*bdev)
-{
- return SECTOR_SIZE;
-}
-
/**
* alloc_read_gpt_header(): Allocates GPT header, reads into it from disk
* @state
@@ -239,7 +234,7 @@ static gpt_header *alloc_read_gpt_header(struct block_device *blk,
u64 lba)
{
gpt_header *gpt;
- unsigned ssz = bdev_logical_block_size(blk);
+ unsigned ssz = BLOCKSIZE(blk);
int ret;
gpt = calloc(ssz, 1);
@@ -286,7 +281,7 @@ static int is_gpt_valid(struct block_device *blk, u64 lba,
}
if (le32_to_cpu((*gpt)->header_size) < sizeof(struct _gpt_header) ||
- le32_to_cpu((*gpt)->header_size) > bdev_logical_block_size(blk))
+ le32_to_cpu((*gpt)->header_size) > BLOCKSIZE(blk))
goto fail;
/* Check the GUID Partition Table CRC */
@@ -505,8 +500,8 @@ static int find_valid_gpt(struct efi_partition_desc *epd, void *buf)
lastlba = last_lba(blk);
if (force_gpt) {
/* This will be added to the EFI Spec. per Intel after v1.02. */
- if (file_detect_partition_table(buf, SECTOR_SIZE * 2,
- SECTOR_SIZE) != filetype_gpt)
+ if (file_detect_partition_table(buf, 2 * BLOCKSIZE(blk),
+ BLOCKSIZE(blk)) != filetype_gpt)
goto fail;
}
diff --git a/include/partitions.h b/include/partitions.h
index 398813eca58c..7eb8b1e6e228 100644
--- a/include/partitions.h
+++ b/include/partitions.h
@@ -58,7 +58,6 @@ struct partition_parser {
};
#define PARTITION_ALIGN_SIZE SZ_1M
-#define PARTITION_ALIGN_SECTORS (PARTITION_ALIGN_SIZE >> SECTOR_SHIFT)
void partition_desc_init(struct partition_desc *pd, struct block_device *blk);
int partition_parser_register(struct partition_parser *p);
@@ -72,5 +71,6 @@ void partition_table_free(struct partition_desc *pdesc);
bool partition_is_free(struct partition_desc *pdesc, uint64_t start, uint64_t size);
int partition_find_free_space(struct partition_desc *pdesc, uint64_t sectors, uint64_t *start);
sector_t partition_first_usable_lba(const struct block_device *blk);
+sector_t partition_align_lba(const struct block_device *blk);
#endif /* __PARTITIONS_PARSER_H__ */
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 21/26] fs: fat: fix garbage read when writing with bigger block size
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (19 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 20/26] partition: support non-512 byte sectors Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 22/26] fs: fat: support larger block device sectors Ahmad Fatoum
` (4 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
fs->win has the size of the biggest supported sector, but regardless,
only the first 512 bytes were actually zeroed.
Extend the zeroing to cover the whole buffer.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
fs/fat/ff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/fat/ff.c b/fs/fat/ff.c
index c8d57ce50054..89b4f9fa5de7 100644
--- a/fs/fat/ff.c
+++ b/fs/fat/ff.c
@@ -292,7 +292,7 @@ int sync ( /* 0: successful, -EIO: failed */
if (fs->fs_type == FS_FAT32 && fs->fsi_flag) {
fs->winsect = 0;
/* Create FSInfo structure */
- memset(fs->win, 0, 512);
+ memset(fs->win, 0, SS(fs));
ST_WORD(fs->win+BS_55AA, 0xAA55);
ST_DWORD(fs->win+FSI_LeadSig, 0x41615252);
ST_DWORD(fs->win+FSI_StrucSig, 0x61417272);
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 22/26] fs: fat: support larger block device sectors
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (20 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 21/26] fs: fat: fix garbage read when writing with bigger block size Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 23/26] usb-storage: preserve READ CAPACITY sector size Ahmad Fatoum
` (3 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The FAT filesystem implementation already has variable sector size support,
but we kept _MAX_SS fixed at the minimum of 512 bytes, which disabled it.
Further, the glue between the filesystem and the cdev layer still hardcoded
512-byte.
Set _MAX_SS as 4096 and fix the glue to be able to use the underlying
block device's block size.
PBL is kept at the existing fixed 512-byte sector size.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
fs/fat/diskio.h | 9 ++++++++
fs/fat/fat-diskio.c | 10 ++++++++-
fs/fat/fat.c | 51 +++++++++++++++++++++++++++++++++------------
fs/fat/ffconf.h | 6 +++++-
4 files changed, 61 insertions(+), 15 deletions(-)
diff --git a/fs/fat/diskio.h b/fs/fat/diskio.h
index 57626d2fbd7b..04a587e3bc47 100644
--- a/fs/fat/diskio.h
+++ b/fs/fat/diskio.h
@@ -14,6 +14,7 @@
#define _USE_IOCTL 1 /* 1: Use disk_ioctl fucntion */
+#include "disks.h"
#include "integer.h"
@@ -42,6 +43,14 @@ DRESULT disk_write (FATFS *fatfs, const BYTE*, DWORD, BYTE);
#endif
DRESULT disk_ioctl (FATFS *fatfs, BYTE, void*);
+#if IN_PROPER
+unsigned int disk_sector_size(FATFS *fat);
+#else
+static inline unsigned int disk_sector_size(FATFS *fat)
+{
+ return SECTOR_SIZE;
+}
+#endif
/* Disk Status Bits (DSTATUS) */
diff --git a/fs/fat/fat-diskio.c b/fs/fat/fat-diskio.c
index aa16d3bdc44b..6ba18993b870 100644
--- a/fs/fat/fat-diskio.c
+++ b/fs/fat/fat-diskio.c
@@ -23,7 +23,15 @@ DWORD get_fattime(void)
DRESULT disk_ioctl (FATFS *fat, BYTE command, void *buf)
{
- return 0;
+ switch (command) {
+ case GET_SECTOR_SIZE:
+ *(WORD *)buf = disk_sector_size(fat);
+ return RES_OK;
+ case CTRL_SYNC:
+ return RES_OK;
+ default:
+ return RES_PARERR;
+ }
}
WCHAR ff_convert(WCHAR src, UINT dir)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 93d1e08b8456..0402db1d945a 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -25,6 +25,8 @@
#include <linux/ctype.h>
#include <xfuncs.h>
#include <fcntl.h>
+#include <block.h>
+#include <linux/sizes.h>
#include "ff.h"
#include "integer.h"
#include "diskio.h"
@@ -36,33 +38,44 @@ struct fat_priv {
/* ---------------------------------------------------------------*/
+unsigned int disk_sector_size(FATFS *fat)
+{
+ struct fat_priv *priv = fat->userdata;
+
+ return cdev_blocksize(priv->cdev);
+}
+
DRESULT disk_read(FATFS *fat, BYTE *buf, DWORD sector, BYTE count)
{
struct fat_priv *priv = fat->userdata;
+ unsigned int sector_size = disk_sector_size(fat);
+ size_t len = count * sector_size;
int ret;
debug("%s: sector: %ld count: %d\n", __func__, sector, count);
- ret = cdev_read(priv->cdev, buf, count << 9, (loff_t)sector * 512, 0);
- if (ret != count << 9)
- return ret;
+ ret = cdev_read(priv->cdev, buf, len, (loff_t)sector * sector_size, 0);
+ if (ret != len)
+ return RES_ERROR;
- return 0;
+ return RES_OK;
}
DRESULT disk_write(FATFS *fat, const BYTE *buf, DWORD sector, BYTE count)
{
struct fat_priv *priv = fat->userdata;
+ unsigned int sector_size = disk_sector_size(fat);
+ size_t len = count * sector_size;
int ret;
debug("%s: buf: %p sector: %ld count: %d\n",
__func__, buf, sector, count);
- ret = cdev_write(priv->cdev, buf, count << 9, (loff_t)sector * 512, 0);
- if (ret != count << 9)
- return ret;
+ ret = cdev_write(priv->cdev, buf, len, (loff_t)sector * sector_size, 0);
+ if (ret != len)
+ return RES_ERROR;
- return 0;
+ return RES_OK;
}
/* ---------------------------------------------------------------*/
@@ -342,14 +355,27 @@ static int fat_stat(struct device *dev, const char *filename, struct stat *s)
static int fat_probe(struct device *dev)
{
struct fs_device *fsdev = dev_to_fs_device(dev);
- struct fat_priv *priv = xzalloc(sizeof(struct fat_priv));
+ struct fat_priv *priv;
+ unsigned int blocksize;
int ret;
- dev->priv = priv;
-
ret = fsdev_open_cdev(fsdev);
if (ret)
- goto err_open;
+ return ret;
+
+ /*
+ * No need to cleanup fsdev_open_cdev(), only way to invoke this
+ * probe function is via mount() and that will already take care
+ * of calling fs_remove for us.
+ */
+ blocksize = cdev_blocksize(fsdev->cdev);
+ if (blocksize > SZ_4K) {
+ dev_err(dev, "FAT on %u-byte block devices is unsupported\n",
+ blocksize);
+ return -ENOSYS;
+ }
+
+ priv = dev->priv = xzalloc(sizeof(struct fat_priv));
priv->cdev = fsdev->cdev;
fsdev->sb.s_casefold = true;
@@ -362,7 +388,6 @@ static int fat_probe(struct device *dev)
return 0;
err_mount:
-err_open:
free(priv);
return ret;
diff --git a/fs/fat/ffconf.h b/fs/fat/ffconf.h
index abf7d1e92e0b..b7dbf39efbf7 100644
--- a/fs/fat/ffconf.h
+++ b/fs/fat/ffconf.h
@@ -103,7 +103,11 @@
/* Number of volumes (logical drives) to be used. */
-#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
+#if IN_PROPER
+#define _MAX_SS 4096 /* 512, 1024, 2048 or 4096 */
+#else
+#define _MAX_SS 512
+#endif
/* Maximum sector size to be handled.
/ Always set 512 for memory card and hard disk but a larger value may be
/ required for on-board flash memory, floppy disk and optical disk.
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 23/26] usb-storage: preserve READ CAPACITY sector size
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (21 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 22/26] fs: fat: support larger block device sectors Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 24/26] fuzz: add 4K-sector partition ramdisk target Ahmad Fatoum
` (2 subsequent siblings)
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
READ CAPACITY reports the logical sector size, but as the common block and
partition support used to be incompatible with non-512-byte sectors, it
just warned about non-512-byte media and forced SECTOR_SHIFT anyway.
Remove the hardcoded SECTOR_SHIFT/SECTOR_SIZE instances to gain support
for 4K-sectors and more.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/usb/storage/usb.c | 44 +++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index b3116dc6e6c2..a991a589dd48 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -11,6 +11,7 @@
#include <init.h>
#include <malloc.h>
#include <dma.h>
+#include <disks.h>
#include <errno.h>
#include <scsi.h>
#include <linux/usb/usb.h>
@@ -150,6 +151,22 @@ static int usb_stor_test_unit_ready(struct us_blk_dev *usb_blkdev, u64 timeout_n
return ret ? -ENODEV : 0;
}
+static int usb_stor_set_capacity(struct us_blk_dev *usb_blkdev, sector_t lba,
+ unsigned int sector_size)
+{
+ struct device *dev = &usb_blkdev->us->pusb_dev->dev;
+ int blockbits;
+
+ blockbits = block_size_bits(dev, sector_size);
+ if (blockbits < 0)
+ return blockbits;
+
+ usb_blkdev->blk.blockbits = blockbits;
+ usb_blkdev->blk.num_blocks = lba + 1;
+
+ return 0;
+}
+
static int read_capacity_16(struct us_blk_dev *usb_blkdev)
{
struct device *dev = &usb_blkdev->us->pusb_dev->dev;
@@ -186,10 +203,7 @@ static int read_capacity_16(struct us_blk_dev *usb_blkdev)
goto fail;
}
- usb_blkdev->blk.blockbits = SECTOR_SHIFT;
- usb_blkdev->blk.num_blocks = lba + 1;
-
- ret = sector_size;
+ ret = usb_stor_set_capacity(usb_blkdev, lba, sector_size);
fail:
dma_free(data);
return ret;
@@ -222,13 +236,7 @@ static int read_capacity_10(struct us_blk_dev *usb_blkdev)
dev_dbg(dev, "LBA (10) = 0x%llx w/ sector size = %u\n",
lba, sector_size);
- if (sector_size != SECTOR_SIZE)
- dev_warn(dev, "Support only %d bytes sectors\n", SECTOR_SIZE);
-
- usb_blkdev->blk.num_blocks = lba + 1;
- usb_blkdev->blk.blockbits = SECTOR_SHIFT;
-
- ret = SECTOR_SIZE;
+ ret = usb_stor_set_capacity(usb_blkdev, lba, sector_size);
fail:
dma_free(data);
return ret;
@@ -237,6 +245,7 @@ static int read_capacity_10(struct us_blk_dev *usb_blkdev)
static int usb_stor_io_16(struct us_blk_dev *usb_blkdev, u8 opcode,
sector_t start, u8 *data, u16 blocks)
{
+ u32 bytes = (u32)blocks << usb_blkdev->blk.blockbits;
u8 cmd[16];
memset(cmd, 0, sizeof(cmd));
@@ -244,13 +253,14 @@ static int usb_stor_io_16(struct us_blk_dev *usb_blkdev, u8 opcode,
put_unaligned_be64(start, &cmd[2]);
put_unaligned_be32(blocks, &cmd[10]);
- return usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), data,
- blocks * SECTOR_SIZE, 10, 0);
+ return usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), data, bytes,
+ 10, 0);
}
static int usb_stor_io_10(struct us_blk_dev *usb_blkdev, u8 opcode,
sector_t start, u8 *data, u16 blocks)
{
+ u32 bytes = (u32)blocks << usb_blkdev->blk.blockbits;
u8 cmd[10];
memset(cmd, 0, sizeof(cmd));
@@ -258,8 +268,8 @@ static int usb_stor_io_10(struct us_blk_dev *usb_blkdev, u8 opcode,
put_unaligned_be32(start, &cmd[2]);
put_unaligned_be16(blocks, &cmd[7]);
- return usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), data,
- blocks * SECTOR_SIZE, 10, 0);
+ return usb_stor_transport(usb_blkdev, cmd, sizeof(cmd), data, bytes,
+ 10, 0);
}
/***********************************************************************
@@ -315,7 +325,7 @@ static int usb_stor_blk_io(struct block_device *disk_dev,
sector_start += n;
sector_count -= n;
- buffer += n * SECTOR_SIZE;
+ buffer += (u32)n << disk_dev->blockbits;
}
return sector_count ? -EIO : 0;
@@ -420,7 +430,6 @@ static int usb_stor_add_blkdev(struct us_data *us, unsigned char lun)
dev_info(dev, "registering as disk%d\n", result);
pblk_dev->blk.cdev.name = basprintf("disk%d", result);
- pblk_dev->blk.blockbits = SECTOR_SHIFT;
pblk_dev->blk.type = BLK_TYPE_USB;
pblk_dev->blk.removable = true;
pblk_dev->blk.rootwait = true;
@@ -631,4 +640,3 @@ static int __init usb_stor_init(void)
return usb_driver_register(&usb_storage_driver);
}
device_initcall(usb_stor_init);
-
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 24/26] fuzz: add 4K-sector partition ramdisk target
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (22 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 23/26] usb-storage: preserve READ CAPACITY sector size Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 25/26] commands: parted: prepare use of non-512-byte sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 26/26] commands: parted: exit if block size if not 512 Ahmad Fatoum
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Make fuzz_test_ramdisk() take the ramdisk sector size so the partition
parser fuzzer can exercise both 512-byte and 4096-byte block devices.
Keep the existing fuzz-partitions target on 512-byte sectors and
add fuzz-partitions-4k for the 4K-sector case.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
Documentation/devel/fuzzing.rst | 1 +
common/partitions.c | 3 ++-
images/Makefile.sandbox | 1 +
include/fuzz.h | 9 +++++----
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/Documentation/devel/fuzzing.rst b/Documentation/devel/fuzzing.rst
index b475fd12fcea..a34d92b97e2e 100644
--- a/Documentation/devel/fuzzing.rst
+++ b/Documentation/devel/fuzzing.rst
@@ -25,6 +25,7 @@ options to crash barebox on detection of memory safety issues::
fuzz-dtb
fuzz-fdt-compatible
fuzz-partitions
+ fuzz-partitions-4k
All fuzzers generated are symlinks to the same barebox executable. barebox
will detect that it was invoked via symlink and switch to fuzzing mode.
diff --git a/common/partitions.c b/common/partitions.c
index 617c2770eadf..617b33460429 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -408,7 +408,8 @@ static int fuzz_partition_table_parser(struct block_device *ramdisk)
free(buf);
return 0;
}
-fuzz_test_ramdisk("partitions", fuzz_partition_table_parser);
+fuzz_test_ramdisk("partitions", fuzz_partition_table_parser, 512);
+fuzz_test_ramdisk("partitions-4k", fuzz_partition_table_parser, 4096);
/**
* cdev_unallocated_space - return unallocated space
diff --git a/images/Makefile.sandbox b/images/Makefile.sandbox
index 210a7bf48ac8..2af83b395f9f 100644
--- a/images/Makefile.sandbox
+++ b/images/Makefile.sandbox
@@ -9,6 +9,7 @@ fuzzer-$(CONFIG_FITIMAGE) += fit
fuzzer-$(CONFIG_OFTREE) += dtb
fuzzer-$(CONFIG_OFTREE) += fdt-compatible
fuzzer-$(CONFIG_PARTITION) += partitions
+fuzzer-$(CONFIG_PARTITION) += partitions-4k
ifeq ($(CONFIG_SANDBOX),y)
diff --git a/include/fuzz.h b/include/fuzz.h
index 4d637f72b176..559e67a09b50 100644
--- a/include/fuzz.h
+++ b/include/fuzz.h
@@ -47,13 +47,14 @@ extern const struct fuzz_test __barebox_fuzz_tests_end;
static __always_unused void * _unused##_func = _func
#endif
-#define fuzz_test_ramdisk(_name, _func) \
- static int _func##_ramdisk(const u8 *data, size_t size) \
+#define fuzz_test_ramdisk(_name, _func, _sector_size) \
+ static int _func##_ramdisk_##_sector_size(const u8 *data, \
+ size_t size) \
{ \
static struct ramdisk *ramdisk; \
int ret; \
if (!ramdisk) \
- ramdisk = ramdisk_init(512); \
+ ramdisk = ramdisk_init(_sector_size); \
if (!ramdisk) \
return -ENODEV; \
ramdisk_setup_ro(ramdisk, data, size); \
@@ -61,7 +62,7 @@ extern const struct fuzz_test __barebox_fuzz_tests_end;
ramdisk_setup_ro(ramdisk, NULL, 0); \
return ret; \
} \
- fuzz_test(_name, _func##_ramdisk)
+ fuzz_test(_name, _func##_ramdisk_##_sector_size)
#define fuzz_test_str(_name, _func) \
static int _func##_str(const u8 *_data, size_t size) \
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 25/26] commands: parted: prepare use of non-512-byte sectors
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (23 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 24/26] fuzz: add 4K-sector partition ramdisk target Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 26/26] commands: parted: exit if block size if not 512 Ahmad Fatoum
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Switching parted to create non-512-byte sectors needs a bit more effort
than just switching out all hardcoded SECTOR_SIZE/SHIFT.
Nevertheless, pick these low hanging fruit and defer the rest to some
unknown point in the future.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/createnv.c | 11 ++++++-----
commands/parted.c | 14 +++++++-------
common/partitions/efi.c | 6 +++---
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/commands/createnv.c b/commands/createnv.c
index 0c74637a114c..6083ab7c2c8f 100644
--- a/commands/createnv.c
+++ b/commands/createnv.c
@@ -69,15 +69,16 @@ static int do_createnv(int argc, char *argv[])
goto err;
}
- buf = xzalloc(2 * SECTOR_SIZE);
+ buf = xzalloc(2 * BLOCKSIZE(blk));
- ret = cdev_read(cdev, buf, 2 * SECTOR_SIZE, 0, 0);
+ ret = cdev_read(cdev, buf, 2 * BLOCKSIZE(blk), 0, 0);
if (ret < 0) {
printf("Cannot read from %s: %pe\n", cdev->name, ERR_PTR(ret));
goto err;
}
- filetype = file_detect_partition_table(buf, 2 * SECTOR_SIZE, SECTOR_SIZE);
+ filetype = file_detect_partition_table(buf, 2 * BLOCKSIZE(blk),
+ BLOCKSIZE(blk));
switch (filetype) {
case filetype_gpt:
@@ -108,7 +109,7 @@ static int do_createnv(int argc, char *argv[])
}
}
- size >>= SECTOR_SHIFT;
+ size = blockdevice_round_nblocks(blk, size);
ret = partition_find_free_space(pdesc, size, &start);
if (ret) {
@@ -123,7 +124,7 @@ static int do_createnv(int argc, char *argv[])
}
printf("Will create a barebox environment partition of size %llu bytes on %s\n",
- size << SECTOR_SHIFT, cdev->name);
+ size * BLOCKSIZE(blk), cdev->name);
if (!force) {
char c;
diff --git a/commands/parted.c b/commands/parted.c
index dd79def62a3e..3f531faaef3f 100644
--- a/commands/parted.c
+++ b/commands/parted.c
@@ -109,15 +109,15 @@ static int do_print(struct block_device *blk, int argc, char *argv[])
}
printf("Disk /dev/%s: %s\n", blk->cdev.name,
- size_human_readable(blk->num_blocks << SECTOR_SHIFT));
+ size_human_readable(blockdevice_size(blk)));
printf("Partition Table: %s\n", pdesc->parser->name);
printf("Number Start End Size Name\n");
list_for_each_entry(part, &pdesc->partitions, list) {
- uint64_t start = part->first_sec << SECTOR_SHIFT;
- uint64_t size = part->size << SECTOR_SHIFT;
- uint64_t end = start + size - SECTOR_SIZE;
+ uint64_t start = part->first_sec << blk->blockbits;
+ uint64_t size = part->size << blk->blockbits;
+ uint64_t end = start + size - BLOCKSIZE(blk);
printf(" %3d %10llu%-3s %10llu%-3s %10llu%-3s %-36s\n",
part->num,
@@ -162,7 +162,7 @@ static int do_mkpart(struct block_device *blk, int argc, char *argv[])
start = ALIGN(start, SZ_1M);
/* convert to LBA */
- start >>= SECTOR_SHIFT;
+ start = blockdevice_round_nblocks(blk, start);
if (!strcmp(argv[4], "max")) {
/* gpt requires 34 blocks at the end */
@@ -182,7 +182,7 @@ static int do_mkpart(struct block_device *blk, int argc, char *argv[])
end *= mult;
/* convert to LBA */
- end >>= SECTOR_SHIFT;
+ end >>= blk->blockbits;
/*
* When unit is >= KB then subtract one sector for user
@@ -235,7 +235,7 @@ static int do_mkpart_size(struct block_device *blk, int argc, char *argv[])
size = ALIGN(size, PARTITION_ALIGN_SIZE);
/* convert to LBA */
- size >>= SECTOR_SHIFT;
+ size = blockdevice_round_nblocks(blk, size);
pdesc = pdesc_get(blk);
if (!pdesc)
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 33d9a1df9e83..18a8c4d56632 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -689,7 +689,7 @@ static __maybe_unused struct partition_desc *efi_partition_create_table(struct b
partition_desc_init(&epd->pd, blk);
- epd->gpt = xzalloc(SECTOR_SIZE);
+ epd->gpt = xzalloc(BLOCKSIZE(blk));
gpt = epd->gpt;
gpt->signature = cpu_to_le64(GPT_HEADER_SIGNATURE);
@@ -851,12 +851,12 @@ static int __efi_partition_write(struct efi_partition_desc *epd, bool primary)
uint64_t my_lba, partition_entry_lba;
int ret;
- gpt = xmemdup(epd->gpt, SECTOR_SIZE);
+ gpt = xmemdup(epd->gpt, BLOCKSIZE(blk));
count = le32_to_cpu(gpt->num_partition_entries) *
le32_to_cpu(gpt->sizeof_partition_entry);
- size = count / GPT_BLOCK_SIZE;
+ size = blockdevice_round_nblocks(blk, count);
if (primary) {
my_lba = 1;
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread* [PATCH 26/26] commands: parted: exit if block size if not 512
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
` (24 preceding siblings ...)
2026-06-26 8:42 ` [PATCH 25/26] commands: parted: prepare use of non-512-byte sectors Ahmad Fatoum
@ 2026-06-26 8:42 ` Ahmad Fatoum
25 siblings, 0 replies; 27+ messages in thread
From: Ahmad Fatoum @ 2026-06-26 8:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
While the partition parser can now deal with non-512-byte block sizes,
the partition writer still needs some more love beyond just replacing
SECTOR_SIZE/SECTOR_SHIFT.
Until that is afforded, exit with a descriptive error message.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/createnv.c | 7 +++++++
commands/parted.c | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/commands/createnv.c b/commands/createnv.c
index 6083ab7c2c8f..5d9dc5732c8a 100644
--- a/commands/createnv.c
+++ b/commands/createnv.c
@@ -69,6 +69,13 @@ static int do_createnv(int argc, char *argv[])
goto err;
}
+ if (BLOCKSIZE(blk) != SECTOR_SIZE) {
+ printf("parted: device has block size of %u, but only 512 currently supported\n",
+ BLOCKSIZE(blk));
+ ret = -ENOTSUPP;
+ goto err;
+ }
+
buf = xzalloc(2 * BLOCKSIZE(blk));
ret = cdev_read(cdev, buf, 2 * BLOCKSIZE(blk), 0, 0);
diff --git a/commands/parted.c b/commands/parted.c
index 3f531faaef3f..829796748827 100644
--- a/commands/parted.c
+++ b/commands/parted.c
@@ -392,6 +392,13 @@ static int do_parted(int argc, char *argv[])
goto err;
}
+ if (BLOCKSIZE(blk) != SECTOR_SIZE) {
+ printf("parted: device has block size of %u, but only 512 currently supported\n",
+ BLOCKSIZE(blk));
+ ret = -ENOTSUPP;
+ goto err;
+ }
+
argc -= 2;
argv += 2;
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread