[Pdbg] [PATCH 12/13] libpdbg: Add a check if device tree is writeable

Amitay Isaacs amitay at ozlabs.org
Wed Jan 15 16:19:00 AEDT 2020


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 libpdbg/device.c |  3 +++
 libpdbg/dtb.c    | 20 ++++++++++++++++++++
 libpdbg/target.h |  1 +
 3 files changed, 24 insertions(+)

diff --git a/libpdbg/device.c b/libpdbg/device.c
index 6c11836..f1c1f6b 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -327,6 +327,9 @@ bool pdbg_target_set_property(struct pdbg_target *target, const char *name, cons
 	size_t len;
 	int ret;
 
+	if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt))
+		return false;
+
 	p = pdbg_target_property(target, name, &len);
 	if (!p)
 		return false;
diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
index 6fdce00..6e05663 100644
--- a/libpdbg/dtb.c
+++ b/libpdbg/dtb.c
@@ -411,6 +411,26 @@ void *pdbg_system_fdt(void)
 	return pdbg_dtb.system.fdt;
 }
 
+static bool is_fdt_mapped(void *fdt, struct pdbg_mfile *mfile)
+{
+	if (mfile->fdt == fdt && mfile->fd != -1 && mfile->len != -1) {
+		return true;
+	}
+
+	return false;
+}
+
+bool pdbg_fdt_is_writeable(void *fdt)
+{
+	bool ok;
+
+	ok = is_fdt_mapped(fdt, &pdbg_dtb.system);
+	if (!ok)
+		ok = is_fdt_mapped(fdt, &pdbg_dtb.backend);
+
+	return ok;
+}
+
 static void close_dtb(struct pdbg_mfile *mfile)
 {
 	if (mfile->fd != -1 && mfile->len != -1 && mfile->fdt) {
diff --git a/libpdbg/target.h b/libpdbg/target.h
index 1c08363..2ecdfce 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -79,6 +79,7 @@ extern struct list_head target_classes;
 
 struct pdbg_dtb *pdbg_default_dtb(void *system_fdt);
 const char *pdbg_get_backend_option(void);
+bool pdbg_fdt_is_writeable(void *fdt);
 
 struct chipop *pib_to_chipop(struct pdbg_target *target);
 bool target_is_virtual(struct pdbg_target *target);
-- 
2.21.1



More information about the Pdbg mailing list