mirror of https://github.com/hak5/openwrt-owl.git
kernel/3.10: add separate rootfs partition parser
Signed-off-by: Gabor Juhos <juhosg@openwrt.org> SVN-Revision: 38110owl
parent
d89bea92b3
commit
daec7ad768
|
@ -1935,6 +1935,7 @@ CONFIG_MTD_ROOTFS_SPLIT=y
|
|||
CONFIG_MTD_SPLIT=y
|
||||
# CONFIG_MTD_SPLIT_FIRMWARE is not set
|
||||
CONFIG_MTD_SPLIT_FIRMWARE_NAME="firmware"
|
||||
# CONFIG_MTD_SPLIT_SQUASHFS_ROOT is not set
|
||||
# CONFIG_MTD_SST25L is not set
|
||||
# CONFIG_MTD_SWAP is not set
|
||||
# CONFIG_MTD_TESTS is not set
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
|
||||
* Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
*/
|
||||
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/magic.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/partitions.h>
|
||||
#include <linux/byteorder/generic.h>
|
||||
|
||||
#include "mtdsplit.h"
|
||||
|
||||
static int
|
||||
mtdsplit_parse_squashfs(struct mtd_info *master,
|
||||
struct mtd_partition **pparts,
|
||||
struct mtd_part_parser_data *data)
|
||||
{
|
||||
struct mtd_partition *part;
|
||||
struct mtd_info *parent_mtd;
|
||||
size_t part_offset;
|
||||
size_t squashfs_len;
|
||||
int err;
|
||||
|
||||
err = mtd_get_squashfs_len(master, 0, &squashfs_len);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
parent_mtd = mtdpart_get_master(master);
|
||||
part_offset = mtdpart_get_offset(master);
|
||||
|
||||
part = kzalloc(sizeof(*part), GFP_KERNEL);
|
||||
if (!part) {
|
||||
pr_alert("unable to allocate memory for \"%s\" partition\n",
|
||||
ROOTFS_SPLIT_NAME);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
part->name = ROOTFS_SPLIT_NAME;
|
||||
part->offset = mtd_roundup_to_eb(part_offset + squashfs_len,
|
||||
parent_mtd) - part_offset;
|
||||
part->size = master->size - part->offset;
|
||||
|
||||
*pparts = part;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct mtd_part_parser mtdsplit_squashfs_parser = {
|
||||
.owner = THIS_MODULE,
|
||||
.name = "squashfs-split",
|
||||
.parse_fn = mtdsplit_parse_squashfs,
|
||||
.type = MTD_PARSER_TYPE_ROOTFS,
|
||||
};
|
||||
|
||||
static int
|
||||
mtdsplit_squashfs_init(void)
|
||||
{
|
||||
return register_mtd_parser(&mtdsplit_squashfs_parser);
|
||||
}
|
||||
|
||||
subsys_initcall(mtdsplit_squashfs_init);
|
|
@ -0,0 +1,83 @@
|
|||
--- a/drivers/mtd/mtdpart.c
|
||||
+++ b/drivers/mtd/mtdpart.c
|
||||
@@ -435,14 +435,12 @@ static struct mtd_part *allocate_partiti
|
||||
if (slave->offset == MTDPART_OFS_APPEND)
|
||||
slave->offset = cur_offset;
|
||||
if (slave->offset == MTDPART_OFS_NXTBLK) {
|
||||
- slave->offset = cur_offset;
|
||||
- if (mtd_mod_by_eb(cur_offset, master) != 0) {
|
||||
- /* Round up to next erasesize */
|
||||
- slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
|
||||
+ /* Round up to next erasesize */
|
||||
+ slave->offset = mtd_roundup_to_eb(cur_offset, master);
|
||||
+ if (slave->offset != cur_offset)
|
||||
printk(KERN_NOTICE "Moving partition %d: "
|
||||
"0x%012llx -> 0x%012llx\n", partno,
|
||||
(unsigned long long)cur_offset, (unsigned long long)slave->offset);
|
||||
- }
|
||||
}
|
||||
if (slave->offset == MTDPART_OFS_RETAIN) {
|
||||
slave->offset = cur_offset;
|
||||
@@ -996,6 +994,24 @@ int mtd_is_partition(const struct mtd_in
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtd_is_partition);
|
||||
|
||||
+struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd)
|
||||
+{
|
||||
+ if (!mtd_is_partition(mtd))
|
||||
+ return (struct mtd_info *)mtd;
|
||||
+
|
||||
+ return PART(mtd)->master;
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(mtdpart_get_master);
|
||||
+
|
||||
+uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
|
||||
+{
|
||||
+ if (!mtd_is_partition(mtd))
|
||||
+ return 0;
|
||||
+
|
||||
+ return PART(mtd)->offset;
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(mtdpart_get_offset);
|
||||
+
|
||||
/* Returns the size of the entire flash chip */
|
||||
uint64_t mtd_get_device_size(const struct mtd_info *mtd)
|
||||
{
|
||||
--- a/include/linux/mtd/partitions.h
|
||||
+++ b/include/linux/mtd/partitions.h
|
||||
@@ -90,6 +90,8 @@ int mtd_is_partition(const struct mtd_in
|
||||
int mtd_add_partition(struct mtd_info *master, char *name,
|
||||
long long offset, long long length);
|
||||
int mtd_del_partition(struct mtd_info *master, int partno);
|
||||
+struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
|
||||
+uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
|
||||
uint64_t mtd_get_device_size(const struct mtd_info *mtd);
|
||||
extern void __weak arch_split_mtd_part(struct mtd_info *master,
|
||||
const char *name, int offset, int size);
|
||||
--- a/include/linux/mtd/mtd.h
|
||||
+++ b/include/linux/mtd/mtd.h
|
||||
@@ -331,6 +331,24 @@ static inline uint32_t mtd_mod_by_eb(uin
|
||||
return do_div(sz, mtd->erasesize);
|
||||
}
|
||||
|
||||
+static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
|
||||
+{
|
||||
+ if (mtd_mod_by_eb(sz, mtd) == 0)
|
||||
+ return sz;
|
||||
+
|
||||
+ /* Round up to next erase block */
|
||||
+ return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
|
||||
+}
|
||||
+
|
||||
+static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
|
||||
+{
|
||||
+ if (mtd_mod_by_eb(sz, mtd) == 0)
|
||||
+ return sz;
|
||||
+
|
||||
+ /* Round down to the start of the current erase block */
|
||||
+ return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
|
||||
+}
|
||||
+
|
||||
static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
|
||||
{
|
||||
if (mtd->writesize_shift)
|
|
@ -0,0 +1,30 @@
|
|||
--- a/drivers/mtd/Kconfig
|
||||
+++ b/drivers/mtd/Kconfig
|
||||
@@ -37,6 +37,17 @@ config MTD_UIMAGE_SPLIT
|
||||
depends on MTD_SPLIT_FIRMWARE
|
||||
default y
|
||||
|
||||
+comment "Rootfs partition parsers"
|
||||
+
|
||||
+config MTD_SPLIT_SQUASHFS_ROOT
|
||||
+ bool "Squashfs based root partition parser"
|
||||
+ select MTD_SPLIT
|
||||
+ default n
|
||||
+ help
|
||||
+ This provides a parsing function which allows to detect the
|
||||
+ offset and size of the unused portion of a rootfs partition
|
||||
+ containing a squashfs.
|
||||
+
|
||||
config MTD_SPLIT
|
||||
def_bool n
|
||||
help
|
||||
--- a/drivers/mtd/Makefile
|
||||
+++ b/drivers/mtd/Makefile
|
||||
@@ -7,6 +7,7 @@ obj-$(CONFIG_MTD) += mtd.o
|
||||
mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o mtdchar.o
|
||||
|
||||
mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
|
||||
+mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
|
||||
|
||||
obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
|
||||
obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
|
Loading…
Reference in New Issue