#include <linux/vmalloc.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
+#include <linux/version.h>
#include <linux/byteorder/generic.h>
+#include <linux/of.h>
#include "mtdsplit.h"
* of a valid uImage header if found
*/
static int __mtdsplit_parse_uimage(struct mtd_info *master,
- struct mtd_partition **pparts,
+ const struct mtd_partition **pparts,
struct mtd_part_parser_data *data,
ssize_t (*find_header)(u_char *buf, size_t len))
{
size_t rootfs_size = 0;
int uimage_part, rf_part;
int ret;
+ enum mtdsplit_part_type type;
nr_parts = 2;
parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL);
}
header = (struct uimage_header *)(buf + ret);
- uimage_size = sizeof(*header) + be32_to_cpu(header->ih_size);
+ uimage_size = sizeof(*header) + be32_to_cpu(header->ih_size) + ret;
if ((offset + uimage_size) > master->size) {
pr_debug("uImage exceeds MTD device \"%s\"\n",
master->name);
/* find the roots after the uImage */
ret = mtd_find_rootfs_from(master, uimage_offset + uimage_size,
- master->size, &rootfs_offset, NULL);
+ master->size, &rootfs_offset, &type);
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, NULL);
+ ret = mtd_check_rootfs_magic(master, 0, &type);
if (ret) {
pr_debug("no rootfs before uImage in \"%s\"\n",
master->name);
parts[uimage_part].offset = uimage_offset;
parts[uimage_part].size = uimage_size;
- parts[rf_part].name = ROOTFS_PART_NAME;
+ if (type == MTDSPLIT_PART_TYPE_UBI)
+ parts[rf_part].name = UBI_PART_NAME;
+ else
+ parts[rf_part].name = ROOTFS_PART_NAME;
parts[rf_part].offset = rootfs_offset;
parts[rf_part].size = rootfs_size;
static int
mtdsplit_uimage_parse_generic(struct mtd_info *master,
- struct mtd_partition **pparts,
+ const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
{
return __mtdsplit_parse_uimage(master, pparts, data,
uimage_verify_default);
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+static const struct of_device_id mtdsplit_uimage_of_match_table[] = {
+ { .compatible = "denx,uimage" },
+ {},
+};
+#endif
+
static struct mtd_part_parser uimage_generic_parser = {
.owner = THIS_MODULE,
.name = "uimage-fw",
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+ .of_match_table = mtdsplit_uimage_of_match_table,
+#endif
.parse_fn = mtdsplit_uimage_parse_generic,
.type = MTD_PARSER_TYPE_FIRMWARE,
};
+#define FW_MAGIC_WNR2000V1 0x32303031
#define FW_MAGIC_WNR2000V3 0x32303033
#define FW_MAGIC_WNR2000V4 0x32303034
#define FW_MAGIC_WNR2200 0x32323030
struct uimage_header *header = (struct uimage_header *)buf;
uint8_t expected_type = IH_TYPE_FILESYSTEM;
- switch be32_to_cpu(header->ih_magic) {
+ switch (be32_to_cpu(header->ih_magic)) {
case FW_MAGIC_WNR612V2:
case FW_MAGIC_WNR1000V2:
case FW_MAGIC_WNR1000V2_VC:
+ case FW_MAGIC_WNR2000V1:
case FW_MAGIC_WNR2000V3:
case FW_MAGIC_WNR2200:
case FW_MAGIC_WNDR3700:
static int
mtdsplit_uimage_parse_netgear(struct mtd_info *master,
- struct mtd_partition **pparts,
+ const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
{
return __mtdsplit_parse_uimage(master, pparts, data,
uimage_verify_wndr3700);
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+static const struct of_device_id mtdsplit_uimage_netgear_of_match_table[] = {
+ { .compatible = "netgear,uimage" },
+ {},
+};
+#endif
+
static struct mtd_part_parser uimage_netgear_parser = {
.owner = THIS_MODULE,
.name = "netgear-fw",
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+ .of_match_table = mtdsplit_uimage_netgear_of_match_table,
+#endif
.parse_fn = mtdsplit_uimage_parse_netgear,
.type = MTD_PARSER_TYPE_FIRMWARE,
};
static ssize_t uimage_find_edimax(u_char *buf, size_t len)
{
- struct uimage_header *header;
+ u32 *magic;
- if (len < FW_EDIMAX_OFFSET + sizeof(*header)) {
+ if (len < FW_EDIMAX_OFFSET + sizeof(struct uimage_header)) {
pr_err("Buffer too small for checking Edimax header\n");
return -ENOSPC;
}
- header = (struct uimage_header *)(buf + FW_EDIMAX_OFFSET);
-
- switch be32_to_cpu(header->ih_magic) {
- case FW_MAGIC_EDIMAX:
- break;
- default:
+ magic = (u32 *)buf;
+ if (be32_to_cpu(*magic) != FW_MAGIC_EDIMAX)
return -EINVAL;
- }
- if (header->ih_os != IH_OS_LINUX ||
- header->ih_type != IH_TYPE_FILESYSTEM)
- return -EINVAL;
+ if (!uimage_verify_default(buf + FW_EDIMAX_OFFSET, len))
+ return FW_EDIMAX_OFFSET;
- return FW_EDIMAX_OFFSET;
+ return -EINVAL;
}
static int
mtdsplit_uimage_parse_edimax(struct mtd_info *master,
- struct mtd_partition **pparts,
+ const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
{
return __mtdsplit_parse_uimage(master, pparts, data,
uimage_find_edimax);
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+static const struct of_device_id mtdsplit_uimage_edimax_of_match_table[] = {
+ { .compatible = "edimax,uimage" },
+ {},
+};
+#endif
+
static struct mtd_part_parser uimage_edimax_parser = {
.owner = THIS_MODULE,
.name = "edimax-fw",
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+ .of_match_table = mtdsplit_uimage_edimax_of_match_table,
+#endif
.parse_fn = mtdsplit_uimage_parse_edimax,
.type = MTD_PARSER_TYPE_FIRMWARE,
};