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;
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;
#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,
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;
}
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;
}
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;
}
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;
}
/* 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);
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;
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 {
* 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;
}
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 {
* 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;
}
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);
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);