mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1
@ 2016-08-21 20:18 Alexander Kurz
  2016-08-21 20:18 ` [PATCH 2/2] scripts: imx-usb-loader: structured DCD v1 element access Alexander Kurz
  2016-08-22  6:02 ` [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1 Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Alexander Kurz @ 2016-08-21 20:18 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Kurz

Do some cleanup which enables DCDv1 16 bit write access as side effect.

Signed-off-by: Alexander Kurz <akurz@blala.de>
---
 scripts/imx/imx-usb-loader.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 1732497..9f25ca6 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -889,16 +889,11 @@ static int write_dcd_table_old(const struct imx_flash_header *hdr,
 
 		switch (type) {
 		case 1:
-			if (verbose > 1)
-				printf("type=%08x *0x%08x = 0x%08x\n", type, addr, val);
-			err = write_memory(addr, val, 1);
-			if (err < 0)
-				return err;
-			break;
+		case 2:
 		case 4:
 			if (verbose > 1)
 				printf("type=%08x *0x%08x = 0x%08x\n", type, addr, val);
-			err = write_memory(addr, val, 4);
+			err = write_memory(addr, val, type);
 			if (err < 0)
 				return err;
 			break;
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] scripts: imx-usb-loader: structured DCD v1 element access
  2016-08-21 20:18 [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1 Alexander Kurz
@ 2016-08-21 20:18 ` Alexander Kurz
  2016-08-22  6:02 ` [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1 Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Kurz @ 2016-08-21 20:18 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Kurz

DCD v1 elements are encoded little endian.

Signed-off-by: Alexander Kurz <akurz@blala.de>
---
 scripts/imx/imx-usb-loader.c | 19 +++++++++++--------
 scripts/imx/imx.h            |  6 ++++++
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 9f25ca6..db74910 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <libusb.h>
 #include <getopt.h>
+#include <endian.h>
 #include <arpa/inet.h>
 #include <linux/kernel.h>
 
@@ -872,7 +873,6 @@ static int get_dcd_range_old(const struct imx_flash_header *hdr,
 static int write_dcd_table_old(const struct imx_flash_header *hdr,
 			       const unsigned char *file_start, unsigned cnt)
 {
-	unsigned val;
 	unsigned char *dcd_end;
 	unsigned char* dcd;
 	int err = get_dcd_range_old(hdr, file_start, cnt, &dcd, &dcd_end);
@@ -882,23 +882,26 @@ static int write_dcd_table_old(const struct imx_flash_header *hdr,
 	printf("writing DCD table...\n");
 
 	while (dcd < dcd_end) {
-		unsigned type = (dcd[0] << 0) | (dcd[1] << 8) | (dcd[2] << 16) | (dcd[3] << 24);
-		unsigned addr = (dcd[4] << 0) | (dcd[5] << 8) | (dcd[6] << 16) | (dcd[7] << 24);
-		val = (dcd[8] << 0) | (dcd[9] << 8) | (dcd[10] << 16) | (dcd[11] << 24);
-		dcd += 12;
+		struct imx_dcd_rec_v1 *rec = (struct imx_dcd_rec_v1 *) dcd;
+		unsigned type = le32toh(rec->type);
+		dcd += sizeof *rec;
 
 		switch (type) {
 		case 1:
 		case 2:
 		case 4:
 			if (verbose > 1)
-				printf("type=%08x *0x%08x = 0x%08x\n", type, addr, val);
-			err = write_memory(addr, val, type);
+				printf("type=%08x *0x%08x = 0x%08x\n", type,
+					le32toh(rec->addr),
+					le32toh(rec->val));
+			err = write_memory(le32toh(rec->addr),
+					   le32toh(rec->val), type);
 			if (err < 0)
 				return err;
 			break;
 		default:
-			printf("!!!unknown type=%08x *0x%08x = 0x%08x\n", type, addr, val);
+			printf("WARNING: unknown DCD type=%08x ignored\n",
+			       type);
 		}
 	}
 
diff --git a/scripts/imx/imx.h b/scripts/imx/imx.h
index 8db7e7b..64ebdce 100644
--- a/scripts/imx/imx.h
+++ b/scripts/imx/imx.h
@@ -26,6 +26,12 @@ struct imx_boot_data {
 	uint32_t plugin;
 } __attribute__((packed));
 
+struct imx_dcd_rec_v1 {
+	uint32_t type;
+	uint32_t addr;
+	uint32_t val;
+} __attribute__((packed));
+
 #define TAG_IVT_HEADER	0xd1
 #define IVT_VERSION	0x40
 #define TAG_DCD_HEADER	0xd2
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1
  2016-08-21 20:18 [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1 Alexander Kurz
  2016-08-21 20:18 ` [PATCH 2/2] scripts: imx-usb-loader: structured DCD v1 element access Alexander Kurz
@ 2016-08-22  6:02 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2016-08-22  6:02 UTC (permalink / raw)
  To: Alexander Kurz; +Cc: barebox

On Sun, Aug 21, 2016 at 10:18:36PM +0200, Alexander Kurz wrote:
> Do some cleanup which enables DCDv1 16 bit write access as side effect.
> 
> Signed-off-by: Alexander Kurz <akurz@blala.de>
> ---
>  scripts/imx/imx-usb-loader.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
> index 1732497..9f25ca6 100644
> --- a/scripts/imx/imx-usb-loader.c
> +++ b/scripts/imx/imx-usb-loader.c
> @@ -889,16 +889,11 @@ static int write_dcd_table_old(const struct imx_flash_header *hdr,
>  
>  		switch (type) {
>  		case 1:
> -			if (verbose > 1)
> -				printf("type=%08x *0x%08x = 0x%08x\n", type, addr, val);
> -			err = write_memory(addr, val, 1);
> -			if (err < 0)
> -				return err;
> -			break;
> +		case 2:
>  		case 4:
>  			if (verbose > 1)
>  				printf("type=%08x *0x%08x = 0x%08x\n", type, addr, val);
> -			err = write_memory(addr, val, 4);
> +			err = write_memory(addr, val, type);
>  			if (err < 0)
>  				return err;
>  			break;
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-22  6:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-21 20:18 [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1 Alexander Kurz
2016-08-21 20:18 ` [PATCH 2/2] scripts: imx-usb-loader: structured DCD v1 element access Alexander Kurz
2016-08-22  6:02 ` [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1 Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox