提交 6fb4efc6 编写于 作者: M Mark A. Greer 提交者: Paul Mackerras

[POWERPC] Add flatdevtree source

Add the latest version of the flatdevtree code and corresponding glue.

A phandle table now tracks values returned by ft_find_device().
The value returned by ft_find_device() is a phandle which is really
an index into the phandle table.  The phandle table contains the address
of the corresponding node.  When the flat dt is edited/moved, the node
pointers in the phandle table are updated accordingly so no phandles kept
by the caller become stale.
Signed-off-by: NMark A. Greer <mgreer@mvista.com>
Signed-off-by: NPaul Mackerras <paulus@samba.org>
上级 c888554b
......@@ -40,7 +40,8 @@ zliblinuxheader := zlib.h zconf.h zutil.h
$(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) \
$(addprefix $(obj)/,$(zlibheader))
src-wlib := string.S stdio.c main.c div64.S $(zlib)
src-wlib := string.S stdio.c main.c flatdevtree.c flatdevtree_misc.c div64.S \
$(zlib)
src-plat := of.c
src-boot := crt0.S $(src-wlib) $(src-plat) empty.c
......
此差异已折叠。
......@@ -17,7 +17,7 @@
#ifndef FLATDEVTREE_H
#define FLATDEVTREE_H
#include "types.h"
#include "flatdevtree_env.h"
/* Definitions used by the flattened device tree */
#define OF_DT_HEADER 0xd00dfeed /* marker */
......@@ -43,4 +43,64 @@ struct boot_param_header {
u32 dt_strings_size; /* size of the DT strings block */
};
struct ft_reserve {
u64 start;
u64 len;
};
struct ft_region {
char *start;
unsigned long size;
};
enum ft_rgn_id {
FT_RSVMAP,
FT_STRUCT,
FT_STRINGS,
FT_N_REGION
};
#define FT_MAX_DEPTH 50
struct ft_cxt {
struct boot_param_header *bph;
int max_size; /* maximum size of tree */
int isordered; /* everything in standard order */
void *(*realloc)(void *, unsigned long);
char *str_anchor;
char *p; /* current insertion point in structs */
struct ft_region rgn[FT_N_REGION];
void *genealogy[FT_MAX_DEPTH+1];
char **node_tbl;
unsigned int node_max;
unsigned int nodes_used;
};
int ft_begin_node(struct ft_cxt *cxt, const char *name);
void ft_end_node(struct ft_cxt *cxt);
void ft_begin_tree(struct ft_cxt *cxt);
void ft_end_tree(struct ft_cxt *cxt);
void ft_nop(struct ft_cxt *cxt);
int ft_prop(struct ft_cxt *cxt, const char *name,
const void *data, unsigned int sz);
int ft_prop_str(struct ft_cxt *cxt, const char *name, const char *str);
int ft_prop_int(struct ft_cxt *cxt, const char *name, unsigned int val);
void ft_begin(struct ft_cxt *cxt, void *blob, unsigned int max_size,
void *(*realloc_fn)(void *, unsigned long));
int ft_open(struct ft_cxt *cxt, void *blob, unsigned int max_size,
unsigned int max_find_device,
void *(*realloc_fn)(void *, unsigned long));
int ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size);
void ft_dump_blob(const void *bphp);
void ft_merge_blob(struct ft_cxt *cxt, void *blob);
void *ft_find_device(struct ft_cxt *cxt, const char *srch_path);
void *ft_find_descendent(struct ft_cxt *cxt, void *top, const char *srch_path);
int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
void *buf, const unsigned int buflen);
int ft_set_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
const void *buf, const unsigned int buflen);
#endif /* FLATDEVTREE_H */
/*
* This file adds the header file glue so that the shared files
* flatdevicetree.[ch] can compile and work in the powerpc bootwrapper.
*
* strncmp & strchr copied from <file:lib/strings.c>
* Copyright (C) 1991, 1992 Linus Torvalds
*
* Maintained by: Mark A. Greer <mgreer@mvista.com>
*/
#ifndef _PPC_BOOT_FLATDEVTREE_ENV_H_
#define _PPC_BOOT_FLATDEVTREE_ENV_H_
#include <stdarg.h>
#include <stddef.h>
#include "types.h"
#include "string.h"
#include "stdio.h"
#include "ops.h"
#define be16_to_cpu(x) (x)
#define cpu_to_be16(x) (x)
#define be32_to_cpu(x) (x)
#define cpu_to_be32(x) (x)
#define be64_to_cpu(x) (x)
#define cpu_to_be64(x) (x)
static inline int strncmp(const char *cs, const char *ct, size_t count)
{
signed char __res = 0;
while (count) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
count--;
}
return __res;
}
static inline char *strchr(const char *s, int c)
{
for (; *s != (char)c; ++s)
if (*s == '\0')
return NULL;
return (char *)s;
}
#endif /* _PPC_BOOT_FLATDEVTREE_ENV_H_ */
/*
* This file does the necessary interface mapping between the bootwrapper
* device tree operations and the interface provided by shared source
* files flatdevicetree.[ch].
*
* Author: Mark A. Greer <mgreer@mvista.com>
*
* 2006 (c) MontaVista Software, Inc. This file is licensed under
* the terms of the GNU General Public License version 2. This program
* is licensed "as is" without any warranty of any kind, whether express
* or implied.
*/
#include <stddef.h>
#include "flatdevtree.h"
#include "ops.h"
static struct ft_cxt cxt;
static void *ft_finddevice(const char *name)
{
return ft_find_device(&cxt, name);
}
static int ft_getprop(const void *phandle, const char *propname, void *buf,
const int buflen)
{
return ft_get_prop(&cxt, phandle, propname, buf, buflen);
}
static int ft_setprop(const void *phandle, const char *propname,
const void *buf, const int buflen)
{
return ft_set_prop(&cxt, phandle, propname, buf, buflen);
}
static void ft_pack(void)
{
ft_end_tree(&cxt);
}
static unsigned long ft_addr(void)
{
return (unsigned long)cxt.bph;
}
int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device)
{
dt_ops.finddevice = ft_finddevice;
dt_ops.getprop = ft_getprop;
dt_ops.setprop = ft_setprop;
dt_ops.ft_pack = ft_pack;
dt_ops.ft_addr = ft_addr;
return ft_open(&cxt, dt_blob, max_size, max_find_device,
platform_ops.realloc);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册