diff mbox series

[02/13] libpdbg: Map external device trees read-write by default

Message ID 20200115051901.17514-3-amitay@ozlabs.org
State Accepted
Headers show
Series Use fdt properties directly | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (8b4611b5d8e7e2279fe4aa80c892fcfe10aa398d)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Amitay Isaacs Jan. 15, 2020, 5:18 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libpdbg/dtb.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Alistair Popple Jan. 16, 2020, 1:24 a.m. UTC | #1
Reviewed-by: Alistair Popple <alistair@popple.id.au>

On Wednesday, 15 January 2020 4:18:50 PM AEDT Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay@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;
diff mbox series

Patch

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;