[Pdbg] [PATCH v2 4/4] libpdbg: Improve the logic for writability of fdt
Amitay Isaacs
amitay at ozlabs.org
Thu Feb 27 15:25:28 AEDT 2020
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libpdbg/dtb.c | 22 ++++++++--------------
libpdbg/target.h | 1 +
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
index 57502c1..165378b 100644
--- a/libpdbg/dtb.c
+++ b/libpdbg/dtb.c
@@ -63,10 +63,12 @@ static struct pdbg_dtb pdbg_dtb = {
.backend = {
.fd = -1,
.len = -1,
+ .readonly = true,
},
.system = {
.fd = -1,
.len = -1,
+ .readonly = true,
},
};
@@ -270,6 +272,7 @@ static void mmap_dtb(char *file, bool readonly, struct pdbg_mfile *mfile)
.fd = fd,
.len = statbuf.st_size,
.fdt = dtb,
+ .readonly = readonly,
};
return;
@@ -408,24 +411,15 @@ done:
return dtb;
}
-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;
+ if (pdbg_dtb.system.fdt == fdt)
+ return !pdbg_dtb.system.readonly;
- ok = is_fdt_mapped(fdt, &pdbg_dtb.system);
- if (!ok)
- ok = is_fdt_mapped(fdt, &pdbg_dtb.backend);
+ if (pdbg_dtb.backend.fdt == fdt)
+ return !pdbg_dtb.backend.readonly;
- return ok;
+ return false;
}
static void close_dtb(struct pdbg_mfile *mfile)
diff --git a/libpdbg/target.h b/libpdbg/target.h
index fffdc49..6e826fc 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -60,6 +60,7 @@ struct pdbg_mfile {
int fd;
ssize_t len;
void *fdt;
+ bool readonly;
};
struct pdbg_dtb {
--
2.24.1
More information about the Pdbg
mailing list