kernel: mtdsplit_uimage: read extralen from device tree
An "openwrt,padding" property in device tree can replace two device specific parsers. Signed-off-by: Bjørn Mork <bjorn@mork.no>
This commit is contained in:
parent
dd5ac0546c
commit
76ea7a91cf
1 changed files with 14 additions and 10 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
#include <linux/byteorder/generic.h>
|
#include <linux/byteorder/generic.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
|
#include <dt-bindings/mtd/partitions/uimage.h>
|
||||||
|
|
||||||
#include "mtdsplit.h"
|
#include "mtdsplit.h"
|
||||||
|
|
||||||
|
@ -28,14 +29,6 @@
|
||||||
*/
|
*/
|
||||||
#define MAX_HEADER_LEN 96
|
#define MAX_HEADER_LEN 96
|
||||||
|
|
||||||
#define IH_MAGIC 0x27051956 /* Image Magic Number */
|
|
||||||
#define IH_NMLEN 32 /* Image Name Length */
|
|
||||||
|
|
||||||
#define IH_OS_LINUX 5 /* Linux */
|
|
||||||
|
|
||||||
#define IH_TYPE_KERNEL 2 /* OS Kernel Image */
|
|
||||||
#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Legacy format image header,
|
* Legacy format image header,
|
||||||
* all data in network byte order (aka natural aka bigendian).
|
* all data in network byte order (aka natural aka bigendian).
|
||||||
|
@ -76,6 +69,15 @@ read_uimage_header(struct mtd_info *mtd, size_t offset, u_char *buf,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void uimage_parse_dt(struct mtd_info *master, int *extralen)
|
||||||
|
{
|
||||||
|
struct device_node *np = mtd_get_of_node(master);
|
||||||
|
|
||||||
|
if (!np || !of_device_is_compatible(np, "openwrt,uimage"))
|
||||||
|
return;
|
||||||
|
of_property_read_u32(np, "openwrt,padding", extralen);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __mtdsplit_parse_uimage - scan partition and create kernel + rootfs parts
|
* __mtdsplit_parse_uimage - scan partition and create kernel + rootfs parts
|
||||||
*
|
*
|
||||||
|
@ -97,7 +99,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
|
||||||
size_t rootfs_size = 0;
|
size_t rootfs_size = 0;
|
||||||
int uimage_part, rf_part;
|
int uimage_part, rf_part;
|
||||||
int ret;
|
int ret;
|
||||||
int extralen;
|
int extralen = 0;
|
||||||
enum mtdsplit_part_type type;
|
enum mtdsplit_part_type type;
|
||||||
|
|
||||||
nr_parts = 2;
|
nr_parts = 2;
|
||||||
|
@ -111,6 +113,8 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
|
||||||
goto err_free_parts;
|
goto err_free_parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uimage_parse_dt(master, &extralen);
|
||||||
|
|
||||||
/* find uImage on erase block boundaries */
|
/* find uImage on erase block boundaries */
|
||||||
for (offset = 0; offset < master->size; offset += master->erasesize) {
|
for (offset = 0; offset < master->size; offset += master->erasesize) {
|
||||||
struct uimage_header *header;
|
struct uimage_header *header;
|
||||||
|
@ -121,7 +125,6 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
|
||||||
if (ret)
|
if (ret)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
extralen = 0;
|
|
||||||
ret = find_header(buf, MAX_HEADER_LEN, &extralen);
|
ret = find_header(buf, MAX_HEADER_LEN, &extralen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
|
pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
|
||||||
|
@ -247,6 +250,7 @@ mtdsplit_uimage_parse_generic(struct mtd_info *master,
|
||||||
|
|
||||||
static const struct of_device_id mtdsplit_uimage_of_match_table[] = {
|
static const struct of_device_id mtdsplit_uimage_of_match_table[] = {
|
||||||
{ .compatible = "denx,uimage" },
|
{ .compatible = "denx,uimage" },
|
||||||
|
{ .compatible = "openwrt,uimage" },
|
||||||
{},
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue