mirror of https://gitlab.com/qemu-project/dtc.git
libfdt: Add fdt_header_size()
We have a couple of places within libfdt and its tests where we need to find the size of the header, based on the version. Add a helper function for it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
This commit is contained in:
parent
6473a21d8b
commit
0112fda03b
20
libfdt/fdt.c
20
libfdt/fdt.c
|
@ -96,21 +96,33 @@ static int check_block_(uint32_t hdrsize, uint32_t totalsize,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t fdt_header_size_(uint32_t version)
|
||||||
|
{
|
||||||
|
if (version <= 1)
|
||||||
|
return FDT_V1_SIZE;
|
||||||
|
else if (version <= 2)
|
||||||
|
return FDT_V2_SIZE;
|
||||||
|
else if (version <= 3)
|
||||||
|
return FDT_V3_SIZE;
|
||||||
|
else if (version <= 16)
|
||||||
|
return FDT_V16_SIZE;
|
||||||
|
else
|
||||||
|
return FDT_V17_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
int fdt_check_header(const void *fdt)
|
int fdt_check_header(const void *fdt)
|
||||||
{
|
{
|
||||||
size_t hdrsize = FDT_V16_SIZE;
|
size_t hdrsize;
|
||||||
|
|
||||||
if (fdt_magic(fdt) != FDT_MAGIC)
|
if (fdt_magic(fdt) != FDT_MAGIC)
|
||||||
return -FDT_ERR_BADMAGIC;
|
return -FDT_ERR_BADMAGIC;
|
||||||
|
hdrsize = fdt_header_size(fdt);
|
||||||
if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
|
if ((fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION)
|
||||||
|| (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION))
|
|| (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION))
|
||||||
return -FDT_ERR_BADVERSION;
|
return -FDT_ERR_BADVERSION;
|
||||||
if (fdt_version(fdt) < fdt_last_comp_version(fdt))
|
if (fdt_version(fdt) < fdt_last_comp_version(fdt))
|
||||||
return -FDT_ERR_BADVERSION;
|
return -FDT_ERR_BADVERSION;
|
||||||
|
|
||||||
if (fdt_version(fdt) >= 17)
|
|
||||||
hdrsize = FDT_V17_SIZE;
|
|
||||||
|
|
||||||
if ((fdt_totalsize(fdt) < hdrsize)
|
if ((fdt_totalsize(fdt) < hdrsize)
|
||||||
|| (fdt_totalsize(fdt) > INT_MAX))
|
|| (fdt_totalsize(fdt) > INT_MAX))
|
||||||
return -FDT_ERR_TRUNCATED;
|
return -FDT_ERR_TRUNCATED;
|
||||||
|
|
|
@ -244,8 +244,19 @@ fdt_set_hdr_(size_dt_strings);
|
||||||
fdt_set_hdr_(size_dt_struct);
|
fdt_set_hdr_(size_dt_struct);
|
||||||
#undef fdt_set_hdr_
|
#undef fdt_set_hdr_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fdt_header_size - return the size of the tree's header
|
||||||
|
* @fdt: pointer to a flattened device tree
|
||||||
|
*/
|
||||||
|
size_t fdt_header_size_(uint32_t version);
|
||||||
|
static inline size_t fdt_header_size(const void *fdt)
|
||||||
|
{
|
||||||
|
return fdt_header_size_(fdt_version(fdt));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_check_header - sanity check a device tree header
|
* fdt_check_header - sanity check a device tree header
|
||||||
|
|
||||||
* @fdt: pointer to data which might be a flattened device tree
|
* @fdt: pointer to data which might be a flattened device tree
|
||||||
*
|
*
|
||||||
* fdt_check_header() checks that the given buffer contains what
|
* fdt_check_header() checks that the given buffer contains what
|
||||||
|
|
|
@ -44,13 +44,9 @@ static void expand_buf(struct bufstate *buf, int newsize)
|
||||||
|
|
||||||
static void new_header(struct bufstate *buf, int version, const void *fdt)
|
static void new_header(struct bufstate *buf, int version, const void *fdt)
|
||||||
{
|
{
|
||||||
int hdrsize;
|
int hdrsize = fdt_header_size_(version);
|
||||||
|
|
||||||
if (version == 16)
|
if ((version != 16) && (version != 17))
|
||||||
hdrsize = FDT_V16_SIZE;
|
|
||||||
else if (version == 17)
|
|
||||||
hdrsize = FDT_V17_SIZE;
|
|
||||||
else
|
|
||||||
CONFIG("Bad version %d", version);
|
CONFIG("Bad version %d", version);
|
||||||
|
|
||||||
expand_buf(buf, hdrsize);
|
expand_buf(buf, hdrsize);
|
||||||
|
|
Loading…
Reference in New Issue