aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWesley W. Terpstra <wesley@sifive.com>2017-04-05 14:53:01 -0700
committerWesley W. Terpstra <wesley@sifive.com>2017-04-05 16:11:36 -0700
commitcd558016be4fdc99055814bd1adcfc2962b425c0 (patch)
tree6404740e410c0df2d8bfd5d08289c58a1c1bc441
parentd1200e3a54e9328d37833a4a155c6549c03a654f (diff)
downloadriscv-pk-cd558016be4fdc99055814bd1adcfc2962b425c0.zip
riscv-pk-cd558016be4fdc99055814bd1adcfc2962b425c0.tar.gz
riscv-pk-cd558016be4fdc99055814bd1adcfc2962b425c0.tar.bz2
fdt: support redaction
-rw-r--r--machine/fdt.c18
-rw-r--r--machine/fdt.h4
2 files changed, 13 insertions, 9 deletions
diff --git a/machine/fdt.c b/machine/fdt.c
index d388d04..bd8da74 100644
--- a/machine/fdt.c
+++ b/machine/fdt.c
@@ -10,8 +10,8 @@ static inline uint32_t bswap(uint32_t x)
return z;
}
-static const uint32_t *fdt_scan_helper(
- const uint32_t *lex,
+static uint32_t *fdt_scan_helper(
+ uint32_t *lex,
const char *strings,
struct fdt_scan_node *node,
const struct fdt_cb *cb)
@@ -43,14 +43,17 @@ static const uint32_t *fdt_scan_helper(
break;
}
case FDT_BEGIN_NODE: {
+ uint32_t *lex_next;
if (!last && node && cb->done) cb->done(node, cb->extra);
last = 1;
child.name = (const char *)(lex+1);
if (cb->open) cb->open(&child, cb->extra);
- lex = fdt_scan_helper(
+ lex_next = fdt_scan_helper(
lex + 2 + strlen(child.name)/4,
strings, &child, cb);
- if (cb->close) cb->close(&child, cb->extra);
+ if (cb->close && cb->close(&child, cb->extra) == -1)
+ while (lex != lex_next) *lex++ = bswap(FDT_NOP);
+ lex = lex_next;
break;
}
case FDT_END_NODE: {
@@ -74,7 +77,7 @@ void fdt_scan(uintptr_t fdt, const struct fdt_cb *cb)
bswap(header->last_comp_version) > FDT_VERSION) return;
const char *strings = (const char *)(fdt + bswap(header->off_dt_strings));
- const uint32_t *lex = (const uint32_t *)(fdt + bswap(header->off_dt_struct));
+ uint32_t *lex = (uint32_t *)(fdt + bswap(header->off_dt_struct));
fdt_scan_helper(lex, strings, 0, cb);
}
@@ -229,11 +232,12 @@ static void hart_done(const struct fdt_scan_node *node, void *extra)
}
}
-static void hart_close(const struct fdt_scan_node *node, void *extra)
+static int hart_close(const struct fdt_scan_node *node, void *extra)
{
struct hart_scan *scan = (struct hart_scan *)extra;
if (scan->cpu == node) scan->cpu = 0;
if (scan->controller == node) scan->controller = 0;
+ return 0;
}
void query_harts(uintptr_t fdt)
@@ -337,7 +341,7 @@ struct plic_scan
{
int compat;
uintptr_t reg;
- const uint32_t *int_value;
+ uint32_t *int_value;
int int_len;
int done;
int ndev;
diff --git a/machine/fdt.h b/machine/fdt.h
index 7f44db6..235bb2e 100644
--- a/machine/fdt.h
+++ b/machine/fdt.h
@@ -33,7 +33,7 @@ struct fdt_scan_node {
struct fdt_scan_prop {
const struct fdt_scan_node *node;
const char *name;
- const uint32_t *value;
+ uint32_t *value;
int len; // in bytes of value
};
@@ -41,7 +41,7 @@ struct fdt_cb {
void (*open)(const struct fdt_scan_node *node, void *extra);
void (*prop)(const struct fdt_scan_prop *prop, void *extra);
void (*done)(const struct fdt_scan_node *node, void *extra); // last property was seen
- void (*close)(const struct fdt_scan_node *node, void *extra);
+ int (*close)(const struct fdt_scan_node *node, void *extra); // -1 => delete the node + children
void *extra;
};