mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-24 07:46:48 +00:00
kernel: mtdsplit: modify rootfs helpers to provide partition type
Our mtdsplit parsers may want to create partition with name choice based on partition file system (e.g. SquashFS vs. JFFS2). This patch allows passing extra argument pointing to variable that will be set properly. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> SVN-Revision: 48598
This commit is contained in:
parent
704473864e
commit
e1491b341b
@ -70,7 +70,8 @@ static ssize_t mtd_next_eb(struct mtd_info *mtd, size_t offset)
|
||||
return mtd_rounddown_to_eb(offset, mtd) + mtd->erasesize;
|
||||
}
|
||||
|
||||
int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
|
||||
int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset,
|
||||
enum mtdsplit_part_type *type)
|
||||
{
|
||||
u32 magic;
|
||||
size_t retlen;
|
||||
@ -84,25 +85,32 @@ int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
|
||||
if (retlen != sizeof(magic))
|
||||
return -EIO;
|
||||
|
||||
if (le32_to_cpu(magic) != SQUASHFS_MAGIC &&
|
||||
magic != 0x19852003)
|
||||
return -EINVAL;
|
||||
if (le32_to_cpu(magic) == SQUASHFS_MAGIC) {
|
||||
if (type)
|
||||
*type = MTDSPLIT_PART_TYPE_SQUASHFS;
|
||||
return 0;
|
||||
} else if (magic == 0x19852003) {
|
||||
if (type)
|
||||
*type = MTDSPLIT_PART_TYPE_JFFS2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -EINVAL;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtd_check_rootfs_magic);
|
||||
|
||||
int mtd_find_rootfs_from(struct mtd_info *mtd,
|
||||
size_t from,
|
||||
size_t limit,
|
||||
size_t *ret_offset)
|
||||
size_t *ret_offset,
|
||||
enum mtdsplit_part_type *type)
|
||||
{
|
||||
size_t offset;
|
||||
int err;
|
||||
|
||||
for (offset = from; offset < limit;
|
||||
offset = mtd_next_eb(mtd, offset)) {
|
||||
err = mtd_check_rootfs_magic(mtd, offset);
|
||||
err = mtd_check_rootfs_magic(mtd, offset, type);
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
|
@ -18,17 +18,25 @@
|
||||
|
||||
#define ROOTFS_SPLIT_NAME "rootfs_data"
|
||||
|
||||
enum mtdsplit_part_type {
|
||||
MTDSPLIT_PART_TYPE_UNK = 0,
|
||||
MTDSPLIT_PART_TYPE_SQUASHFS,
|
||||
MTDSPLIT_PART_TYPE_JFFS2,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_MTD_SPLIT
|
||||
int mtd_get_squashfs_len(struct mtd_info *master,
|
||||
size_t offset,
|
||||
size_t *squashfs_len);
|
||||
|
||||
int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset);
|
||||
int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset,
|
||||
enum mtdsplit_part_type *type);
|
||||
|
||||
int mtd_find_rootfs_from(struct mtd_info *mtd,
|
||||
size_t from,
|
||||
size_t limit,
|
||||
size_t *ret_offset);
|
||||
size_t *ret_offset,
|
||||
enum mtdsplit_part_type *type);
|
||||
|
||||
#else
|
||||
static inline int mtd_get_squashfs_len(struct mtd_info *master,
|
||||
@ -38,7 +46,8 @@ static inline int mtd_get_squashfs_len(struct mtd_info *master,
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
|
||||
static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset,
|
||||
enum mtdsplit_part_type *type)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -46,7 +55,8 @@ static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
|
||||
static inline int mtd_find_rootfs_from(struct mtd_info *mtd,
|
||||
size_t from,
|
||||
size_t limit,
|
||||
size_t *ret_offset)
|
||||
size_t *ret_offset,
|
||||
enum mtdsplit_part_type *type)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ static int mtdsplit_parse_brnimage(struct mtd_info *master,
|
||||
|
||||
for (rootfs_offset = 0; rootfs_offset < master->size;
|
||||
rootfs_offset += BRNIMAGE_ALIGN_BYTES) {
|
||||
ret = mtd_check_rootfs_magic(master, rootfs_offset);
|
||||
ret = mtd_check_rootfs_magic(master, rootfs_offset, NULL);
|
||||
if (!ret)
|
||||
break;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ static int mtdsplit_parse_eva(struct mtd_info *master,
|
||||
if (rootfs_offset >= master->size)
|
||||
return -EINVAL;
|
||||
|
||||
err = mtd_check_rootfs_magic(master, rootfs_offset);
|
||||
err = mtd_check_rootfs_magic(master, rootfs_offset, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -93,8 +93,8 @@ mtdsplit_fit_parse(struct mtd_info *mtd, struct mtd_partition **pparts,
|
||||
}
|
||||
|
||||
/* Search for the rootfs partition after the FIT image */
|
||||
ret = mtd_find_rootfs_from(mtd, fit_offset + fit_size,
|
||||
mtd->size, &rootfs_offset);
|
||||
ret = mtd_find_rootfs_from(mtd, fit_offset + fit_size, mtd->size,
|
||||
&rootfs_offset, NULL);
|
||||
if (ret) {
|
||||
pr_info("no rootfs found after FIT image in \"%s\"\n",
|
||||
mtd->name);
|
||||
|
@ -58,8 +58,8 @@ static int mtdsplit_parse_lzma(struct mtd_info *master,
|
||||
if (t)
|
||||
return -EINVAL;
|
||||
|
||||
err = mtd_find_rootfs_from(master, master->erasesize,
|
||||
master->size, &rootfs_offset);
|
||||
err = mtd_find_rootfs_from(master, master->erasesize, master->size,
|
||||
&rootfs_offset, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -56,7 +56,7 @@ static int mtdsplit_parse_seama(struct mtd_info *master,
|
||||
return -EINVAL;
|
||||
|
||||
/* Check for the rootfs right after Seama entity with a kernel. */
|
||||
err = mtd_check_rootfs_magic(master, kernel_ent_size);
|
||||
err = mtd_check_rootfs_magic(master, kernel_ent_size, NULL);
|
||||
if (!err) {
|
||||
rootfs_offset = kernel_ent_size;
|
||||
} else {
|
||||
@ -67,7 +67,7 @@ static int mtdsplit_parse_seama(struct mtd_info *master,
|
||||
* Start the search from an arbitrary offset.
|
||||
*/
|
||||
err = mtd_find_rootfs_from(master, SEAMA_MIN_ROOTFS_OFFS,
|
||||
master->size, &rootfs_offset);
|
||||
master->size, &rootfs_offset, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ static int mtdsplit_parse_tplink(struct mtd_info *master,
|
||||
return -EINVAL;
|
||||
|
||||
/* Find the rootfs after the kernel. */
|
||||
err = mtd_check_rootfs_magic(master, kernel_size);
|
||||
err = mtd_check_rootfs_magic(master, kernel_size, NULL);
|
||||
if (!err) {
|
||||
rootfs_offset = kernel_size;
|
||||
} else {
|
||||
@ -131,7 +131,7 @@ static int mtdsplit_parse_tplink(struct mtd_info *master,
|
||||
* Start the search from an arbitrary offset.
|
||||
*/
|
||||
err = mtd_find_rootfs_from(master, TPLINK_MIN_ROOTFS_OFFS,
|
||||
master->size, &rootfs_offset);
|
||||
master->size, &rootfs_offset, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
@ -147,10 +147,8 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
|
||||
rf_part = 1;
|
||||
|
||||
/* find the roots after the uImage */
|
||||
ret = mtd_find_rootfs_from(master,
|
||||
uimage_offset + uimage_size,
|
||||
master->size,
|
||||
&rootfs_offset);
|
||||
ret = mtd_find_rootfs_from(master, uimage_offset + uimage_size,
|
||||
master->size, &rootfs_offset, NULL);
|
||||
if (ret) {
|
||||
pr_debug("no rootfs after uImage in \"%s\"\n",
|
||||
master->name);
|
||||
@ -164,7 +162,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
|
||||
uimage_part = 1;
|
||||
|
||||
/* check rootfs presence at offset 0 */
|
||||
ret = mtd_check_rootfs_magic(master, 0);
|
||||
ret = mtd_check_rootfs_magic(master, 0, NULL);
|
||||
if (ret) {
|
||||
pr_debug("no rootfs before uImage in \"%s\"\n",
|
||||
master->name);
|
||||
|
Loading…
Reference in New Issue
Block a user