[U-Boot] [PATCH] Add support for offset of a filesystem within a block-device
Hannes Petermaier
oe5hpm at oevsv.at
Thu Mar 6 14:30:35 CET 2014
For clear separation of user's (OS) filesystem to U-Boot and other's
stuff it is now possible to give the filesystem a specific offset and a
specific size.
For full consistency OS storage driver also has to support this and
has to use same offset and size.
Following new parameters has been added to the block_dev_desc_t
structure:
- lba_offset : offset in blocks from which fs is reading/writing
- lba_fs : size in blocks of fs
This two parameters are filled from the underlaying device-driver.
As default they are initialized for giving whole size of block-device
to the filesystem.
In case of mmc-driver a function for modifiying drive geometry is
called 'board_mmc_geometry', this function is implemented as
'__weak', so it can be replaced by a board-specific function, which
can setup suitable offset and size for the filesystem.
This function is responsible for giving reasonable values, e.g.
lba_offset+lba_fs must not exceed available blocks of the device.
Only MMC Driver and FATFS are modified to support this.
Signed-off-by: Hannes Petermaier <oe5hpm at oevsv.at>
---
disk/part_dos.c | 11 ++++++++---
drivers/mmc/mmc.c | 8 ++++++++
fs/fat/fat.c | 5 +++--
fs/fat/fat_write.c | 7 ++++---
include/part.h | 10 +++++++++-
5 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 05c3933..aa38819 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -87,7 +87,8 @@ int test_part_dos (block_dev_desc_t *dev_desc)
{
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
- if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) buffer) != 1)
+ if (dev_desc->block_read(dev_desc->dev, dev_desc->lba_offset, 1,
+ (ulong *)buffer) != 1)
return -1;
if (test_block_type(buffer) != DOS_MBR)
@@ -106,7 +107,9 @@ static void print_partition_extended(block_dev_desc_t *dev_desc,
dos_partition_t *pt;
int i;
- if (dev_desc->block_read(dev_desc->dev, ext_part_sector, 1, (ulong *) buffer) != 1) {
+ if (dev_desc->block_read(dev_desc->dev,
+ ext_part_sector + dev_desc->lba_offset, 1,
+ (ulong *)buffer) != 1) {
printf ("** Can't read partition table on %d:%d **\n",
dev_desc->dev, ext_part_sector);
return;
@@ -169,7 +172,9 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part
dos_partition_t *pt;
int i;
- if (dev_desc->block_read (dev_desc->dev, ext_part_sector, 1, (ulong *) buffer) != 1) {
+ if (dev_desc->block_read(dev_desc->dev,
+ ext_part_sector + dev_desc->lba_offset, 1,
+ (ulong *)buffer) != 1) {
printf ("** Can't read partition table on %d:%d **\n",
dev_desc->dev, ext_part_sector);
return -1;
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 8ab0bc9..4acce73 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -526,6 +526,12 @@ static int mmc_change_freq(struct mmc *mmc)
return 0;
}
+void __weak board_mmc_geometry(struct mmc *mmc)
+{
+ mmc->block_dev.lba_fs = mmc->block_dev.lba;
+ mmc->block_dev.lba_offset = 0;
+}
+
static int mmc_set_capacity(struct mmc *mmc, int part_num)
{
switch (part_num) {
@@ -551,6 +557,8 @@ static int mmc_set_capacity(struct mmc *mmc, int part_num)
mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
+ board_mmc_geometry(mmc);
+
return 0;
}
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 54f42ea..dba0989 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -49,7 +49,8 @@ static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
return -1;
return cur_dev->block_read(cur_dev->dev,
- cur_part_info.start + block, nr_blocks, buf);
+ cur_part_info.start + block + cur_dev->lba_offset,
+ nr_blocks, buf);
}
int fat_set_blk_dev(block_dev_desc_t *dev_desc, disk_partition_t *info)
@@ -97,7 +98,7 @@ int fat_register_device(block_dev_desc_t *dev_desc, int part_no)
}
info.start = 0;
- info.size = dev_desc->lba;
+ info.size = dev_desc->lba_fs;
info.blksz = dev_desc->blksz;
info.name[0] = 0;
info.type[0] = 0;
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 9f5e911..6238a8e 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -31,14 +31,15 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf)
if (!cur_dev || !cur_dev->block_write)
return -1;
- if (cur_part_info.start + block + nr_blocks >
- cur_part_info.start + total_sector) {
+ if (cur_part_info.start + block + nr_blocks + cur_dev->lba_offset >
+ cur_part_info.start + total_sector + cur_dev->lba_offset) {
printf("error: overflow occurs\n");
return -1;
}
return cur_dev->block_write(cur_dev->dev,
- cur_part_info.start + block, nr_blocks, buf);
+ cur_part_info.start + block + cur_dev->lba_offset,
+ nr_blocks, buf);
}
/*
diff --git a/include/part.h b/include/part.h
index 4beb6db..29a227a 100644
--- a/include/part.h
+++ b/include/part.h
@@ -20,7 +20,15 @@ typedef struct block_dev_desc {
#ifdef CONFIG_LBA48
unsigned char lba48; /* device can use 48bit addr (ATA/ATAPI v7) */
#endif
- lbaint_t lba; /* number of blocks */
+ lbaint_t lba_offset; /*
+ * offset from which file-systems
+ * do their work
+ */
+ lbaint_t lba_fs; /*
+ * number of blocks available to the
+ * file-system
+ */
+ lbaint_t lba; /* total number of blocks-available */
unsigned long blksz; /* block size */
int log2blksz; /* for convenience: log2(blksz) */
char vendor [40+1]; /* IDE model, SCSI Vendor */
--
1.7.9.5
More information about the U-Boot
mailing list