[Pdbg] [PATCH 02/13] libpdbg: Map external device trees read-write by default
Alistair Popple
alistair at popple.id.au
Thu Jan 16 12:24:36 AEDT 2020
Reviewed-by: Alistair Popple <alistair at popple.id.au>
On Wednesday, 15 January 2020 4:18:50 PM AEDT Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
> libpdbg/dtb.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
> index 53f4393..18b5a6f 100644
> --- a/libpdbg/dtb.c
> +++ b/libpdbg/dtb.c
> @@ -220,13 +220,16 @@ static void bmc_target(struct pdbg_dtb *dtb)
> }
>
> /* Opens a dtb at the given path */
> -static void *mmap_dtb(char *file)
> +static void *mmap_dtb(char *file, bool readonly)
> {
> int fd;
> void *dtb;
> struct stat statbuf;
>
> - fd = open(file, O_RDONLY);
> + if (readonly)
> + fd = open(file, O_RDONLY);
> + else
> + fd = open(file, O_RDWR);
> if (fd < 0) {
> pdbg_log(PDBG_ERROR, "Unable to open dtb file '%s'\n", file);
> return NULL;
> @@ -237,7 +240,10 @@ static void *mmap_dtb(char *file)
> goto fail;
> }
>
> - dtb = mmap(NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
> + if (readonly)
> + dtb = mmap(NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
> + else
> + dtb = mmap(NULL, statbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED,
fd,
> 0); if (dtb == MAP_FAILED) {
> pdbg_log(PDBG_ERROR, "Failed top mmap file '%s'\n", file);
> goto fail;
> @@ -281,11 +287,11 @@ void pdbg_default_dtb(struct pdbg_dtb *dtb, void
> *system_fdt)
>
> fdt = getenv("PDBG_BACKEND_DTB");
> if (fdt)
> - dtb->backend = mmap_dtb(fdt);
> + dtb->backend = mmap_dtb(fdt, false);
>
> fdt = getenv("PDBG_DTB");
> if (fdt)
> - dtb->system = mmap_dtb(fdt);
> + dtb->system = mmap_dtb(fdt, false);
>
> if (dtb->backend && dtb->system)
> return;
More information about the Pdbg
mailing list