Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-23 Thread Øyvind Harboe
Merged.

Thanks!



-- 
Øyvind Harboe - Can Zylin Consulting help on your project?
US toll free 1-866-980-3434
http://www.zylin.com/
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-20 Thread Michel JAOUEN
Hello,
Ok, for the fix without goto.
I think we can merge it right now, because the orginal implementation creates 
an infinite loop in following case :
For tap that are dynamically enabled in the chain :
- jtag_examine_chain is not executed at tap insertion,
(jtag_examine_chain is executed following jtag arp_init)
- at target examine hasidcode is still false and infinite loop is entered.

Later on, we have to make it work with dynamic enable tap.
Best regards

 

-Original Message-
From: Mathias K. [mailto:kes...@freenet.de] 
Sent: Monday, September 19, 2011 7:01 PM
To: Øyvind Harboe
Cc: Michel JAOUEN; openocd-development@lists.berlios.de
Subject: Re: [Openocd-development] [PATCH] kinetis cpu flash driver

Hello,


i prefer something like this (i don't want to start a goto discussion):

if ( tap-hasidcode  (dap_syssec_filter_data[i].idcode == tap-idcode) )

but we should be sure that idcode is initialized with an invalid value like 
zero but independent of
the hasidcode flag.


Regards,

Mathias


Am 19.09.2011 18:50, schrieb Øyvind Harboe:
 I'll let it cool off for a few days. Please give word if further work
 is required and
 we should submit an updated patch.
 



0001-kinetis-fix-deadlock-on-device-having-hasidcode-fals.patch
Description: 0001-kinetis-fix-deadlock-on-device-having-hasidcode-fals.patch
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-19 Thread Michel JAOUEN
Hello,
I noticed a deadlock on tap initialized with hashidcode to false.
Here is the attached patch.

Best regards


-Original Message-
From: openocd-development-boun...@lists.berlios.de 
[mailto:openocd-development-boun...@lists.berlios.de] On Behalf Of Øyvind Harboe
Sent: Saturday, September 17, 2011 2:25 PM
To: Mathias K.
Cc: openocd-development@lists.berlios.de
Subject: Re: [Openocd-development] [PATCH] kinetis cpu flash driver

Merged.

Thanks!



-- 
Øyvind Harboe - Can Zylin Consulting help on your project?
US toll free 1-866-980-3434
http://www.zylin.com/
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


0001-kinetis-correction-of-deadlock-on-device-having-hasi.patch
Description: 0001-kinetis-correction-of-deadlock-on-device-having-hasi.patch
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-19 Thread Øyvind Harboe
I'll let it cool off for a few days. Please give word if further work
is required and
we should submit an updated patch.

-- 
Øyvind Harboe - Can Zylin Consulting help on your project?
US toll free 1-866-980-3434
http://www.zylin.com/
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-19 Thread Mathias K.
Hello,


i prefer something like this (i don't want to start a goto discussion):

if ( tap-hasidcode  (dap_syssec_filter_data[i].idcode == tap-idcode) )

but we should be sure that idcode is initialized with an invalid value like 
zero but independent of
the hasidcode flag.


Regards,

Mathias


Am 19.09.2011 18:50, schrieb Øyvind Harboe:
 I'll let it cool off for a few days. Please give word if further work
 is required and
 we should submit an updated patch.
 

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-17 Thread Mathias K.
Hello,

i have worked on the issues, please let me know if there was something that i 
have not picked up.


Regards,

Mathias

Am 16.09.2011 10:00, schrieb Øyvind Harboe:
 First of all, overall I think the code looks good!
 
 Some nit-picking below.
 
 The OpenOCD error handling is modeled upon exception handling, report error
 in place and then just propagate errors (exceptions) without changing the 
 return
 value.
 
 
 1. Switch to LOG_ERROR.
 
 +FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
 +{
 +   if (CMD_ARGC  6) {
 +   LOG_WARNING(incomplete flash_bank kinetis configuration %d,
 +   CMD_ARGC);
 +   return ERROR_FLASH_OPERATION_FAILED;
 +   }
 
 
 2. Just return LOG_ERROR()
 
 +static int kinetis_protect(struct flash_bank *bank, int set, int first,
 +  int last)
 +{
 +   struct flash_bank *master_bank = kinetis_get_master_bank(bank);
 +
 +   LOG_WARNING(kinetis_protect not supported yet);
 +
 +   if (bank-target-state != TARGET_HALTED) {
 +   LOG_ERROR(Target not halted);
 +   return ERROR_TARGET_NOT_HALTED;
 +   }
 +
 +   if (master_bank == NULL) {
 +   return ERROR_FLASH_OPERATION_FAILED;
 +   }
 +
 +   return ERROR_OK;
 +}
 
 3. Modify to return error as primary return value and pointer in
 secondary return
 value, then just propagate the return value unchanged upon error.
 
 +static struct flash_bank *kinetis_get_master_bank(struct flash_bank *bank)
 
 4. This fn does not propagate failure:
 
 +static void kinetis_update_bank_info(struct flash_bank *bank)
 +{
 +   struct flash_bank *master_bank = kinetis_get_master_bank(bank);
 +
 +   if (master_bank == NULL) {
 +   return;
 +   }
 +
 
 5. propagate (just return) the error code, do not change it:
 
 +   if (kinetis_ftfl_command(bank, w0, w1, w2) != ERROR_OK) {
 +   return ERROR_FLASH_OPERATION_FAILED;
 +   }
 +
 +
 
 
 
 
 
 
 

From ab35e7489fb125fac84049040ea86776f34cf952 Mon Sep 17 00:00:00 2001
From: Mathias K. kes...@freenet.de
Date: Sat, 17 Sep 2011 10:09:50 +0200
Subject: [PATCH 2/2] kinetis cpu flash driver

Initial release of the freescale kinetis cpu flash driver.
---
 src/flash/nor/Makefile.am |3 +-
 src/flash/nor/drivers.c   |2 +
 src/flash/nor/kinetis.c   |  562 +
 3 files changed, 566 insertions(+), 1 deletions(-)
 create mode 100644 src/flash/nor/kinetis.c

diff --git a/src/flash/nor/Makefile.am b/src/flash/nor/Makefile.am
index d7d66b0..a966826 100644
--- a/src/flash/nor/Makefile.am
+++ b/src/flash/nor/Makefile.am
@@ -32,7 +32,8 @@ NOR_DRIVERS = \
 	tms470.c \
 	virtual.c \
 	fm3.c \
-	dsp5680xx_flash.c
+	dsp5680xx_flash.c \
+	kinetis.c
 
 noinst_HEADERS = \
 	core.h \
diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c
index 5d6e248..a437d84 100644
--- a/src/flash/nor/drivers.c
+++ b/src/flash/nor/drivers.c
@@ -45,6 +45,7 @@ extern struct flash_driver stmsmi_flash;
 extern struct flash_driver em357_flash;
 extern struct flash_driver dsp5680xx_flash;
 extern struct flash_driver fm3_flash;
+extern struct flash_driver kinetis_flash;
 
 /**
  * The list of built-in flash drivers.
@@ -75,6 +76,7 @@ static struct flash_driver *flash_drivers[] = {
 	em357_flash,
 	fm3_flash,
 	dsp5680xx_flash,
+	kinetis_flash,
 	NULL,
 };
 
diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
new file mode 100644
index 000..2613522
--- /dev/null
+++ b/src/flash/nor/kinetis.c
@@ -0,0 +1,562 @@
+/***
+ *   Copyright (C) 2011 by Mathias Kuester  *
+ *   kes...@freenet.de *
+ * *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or *
+ *   (at your option) any later version.   *
+ * *
+ *   This program is distributed in the hope that it will be useful,   *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of*
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *
+ *   GNU General Public License for more details.  *
+ * *
+ *   You should have received a copy of the GNU General Public License *
+ *   along with this program; if not, write to the *
+ *   Free Software Foundation, Inc.,   *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *
+ 

Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-17 Thread Øyvind Harboe
Merged.

Thanks!



-- 
Øyvind Harboe - Can Zylin Consulting help on your project?
US toll free 1-866-980-3434
http://www.zylin.com/
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-16 Thread Øyvind Harboe
First of all, overall I think the code looks good!

Some nit-picking below.

The OpenOCD error handling is modeled upon exception handling, report error
in place and then just propagate errors (exceptions) without changing the return
value.


1. Switch to LOG_ERROR.

+FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
+{
+   if (CMD_ARGC  6) {
+   LOG_WARNING(incomplete flash_bank kinetis configuration %d,
+   CMD_ARGC);
+   return ERROR_FLASH_OPERATION_FAILED;
+   }


2. Just return LOG_ERROR()

+static int kinetis_protect(struct flash_bank *bank, int set, int first,
+  int last)
+{
+   struct flash_bank *master_bank = kinetis_get_master_bank(bank);
+
+   LOG_WARNING(kinetis_protect not supported yet);
+
+   if (bank-target-state != TARGET_HALTED) {
+   LOG_ERROR(Target not halted);
+   return ERROR_TARGET_NOT_HALTED;
+   }
+
+   if (master_bank == NULL) {
+   return ERROR_FLASH_OPERATION_FAILED;
+   }
+
+   return ERROR_OK;
+}

3. Modify to return error as primary return value and pointer in
secondary return
value, then just propagate the return value unchanged upon error.

+static struct flash_bank *kinetis_get_master_bank(struct flash_bank *bank)

4. This fn does not propagate failure:

+static void kinetis_update_bank_info(struct flash_bank *bank)
+{
+   struct flash_bank *master_bank = kinetis_get_master_bank(bank);
+
+   if (master_bank == NULL) {
+   return;
+   }
+

5. propagate (just return) the error code, do not change it:

+   if (kinetis_ftfl_command(bank, w0, w1, w2) != ERROR_OK) {
+   return ERROR_FLASH_OPERATION_FAILED;
+   }
+
+







-- 
Øyvind Harboe - Can Zylin Consulting help on your project?
US toll free 1-866-980-3434
http://www.zylin.com/
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-12 Thread Mathias K.
Hello,

this patch removes the test code used to verify the functionality.


Regards,

Mathias

Am 12.09.2011 16:17, schrieb Mathias K.:
 Hello,
 
 i have done some work on the kinetis cpu flash driver. Erase,write and read 
 protection works.
 
 
 Regards,
 
 Mathias
From 3a4d6a735680b0015de4f07db1b91a1f4112e898 Mon Sep 17 00:00:00 2001
From: Mathias K. kes...@freenet.de
Date: Mon, 12 Sep 2011 21:42:59 +0200
Subject: [PATCH 3/3] remove test code

---
 src/flash/nor/kinetis.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
index 548df57..116363c 100644
--- a/src/flash/nor/kinetis.c
+++ b/src/flash/nor/kinetis.c
@@ -278,8 +278,6 @@ static int kinetis_write(struct flash_bank *bank, uint8_t * buffer,
 		return result;
 	}
 
-	buf[0] = 0;
-
 	if (!(buf[0]  (1  1))) {
 		/* fallback to longword write */
 		fallback = 1;
-- 
1.7.3.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-12 Thread Øyvind Harboe
Please squash the patches together and repost if they do belong in
the same patch.

Thanks!

-- 
Øyvind Harboe - Can Zylin Consulting help on your project?
US toll free 1-866-980-3434
http://www.zylin.com/
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH] kinetis cpu flash driver

2011-09-12 Thread Mathias K.
No problem.

Am 12.09.2011 21:49, schrieb Øyvind Harboe:
 Please squash the patches together and repost if they do belong in
 the same patch.
 
 Thanks!
 

From 1b17ccce801ff322ff5372207d82fb8827b4cbcf Mon Sep 17 00:00:00 2001
From: Mathias K. kes...@freenet.de
Date: Mon, 12 Sep 2011 21:58:49 +0200
Subject: [PATCH 2/2] kinetis cpu flash driver

Initial release of the freescale kinetis cpu flash driver.
---
 src/flash/nor/Makefile.am |3 +-
 src/flash/nor/drivers.c   |2 +
 src/flash/nor/kinetis.c   |  532 +
 3 files changed, 536 insertions(+), 1 deletions(-)
 create mode 100644 src/flash/nor/kinetis.c

diff --git a/src/flash/nor/Makefile.am b/src/flash/nor/Makefile.am
index d7d66b0..a966826 100644
--- a/src/flash/nor/Makefile.am
+++ b/src/flash/nor/Makefile.am
@@ -32,7 +32,8 @@ NOR_DRIVERS = \
 	tms470.c \
 	virtual.c \
 	fm3.c \
-	dsp5680xx_flash.c
+	dsp5680xx_flash.c \
+	kinetis.c
 
 noinst_HEADERS = \
 	core.h \
diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c
index 5d6e248..a437d84 100644
--- a/src/flash/nor/drivers.c
+++ b/src/flash/nor/drivers.c
@@ -45,6 +45,7 @@ extern struct flash_driver stmsmi_flash;
 extern struct flash_driver em357_flash;
 extern struct flash_driver dsp5680xx_flash;
 extern struct flash_driver fm3_flash;
+extern struct flash_driver kinetis_flash;
 
 /**
  * The list of built-in flash drivers.
@@ -75,6 +76,7 @@ static struct flash_driver *flash_drivers[] = {
 	em357_flash,
 	fm3_flash,
 	dsp5680xx_flash,
+	kinetis_flash,
 	NULL,
 };
 
diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
new file mode 100644
index 000..116363c
--- /dev/null
+++ b/src/flash/nor/kinetis.c
@@ -0,0 +1,532 @@
+/***
+ *   Copyright (C) 2011 by Mathias Kuester  *
+ *   kes...@freenet.de *
+ * *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or *
+ *   (at your option) any later version.   *
+ * *
+ *   This program is distributed in the hope that it will be useful,   *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of*
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *
+ *   GNU General Public License for more details.  *
+ * *
+ *   You should have received a copy of the GNU General Public License *
+ *   along with this program; if not, write to the *
+ *   Free Software Foundation, Inc.,   *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *
+ ***/
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include imp.h
+#include helper/binarybuffer.h
+
+static struct flash_bank *kinetis_get_master_bank(struct flash_bank *bank)
+{
+	struct flash_bank *master_bank;
+
+	master_bank = get_flash_bank_by_name_noprobe(bank-name);
+	if (master_bank == NULL) {
+		LOG_ERROR(master flash bank '%s' does not exist,
+			  (char *)bank-driver_priv);
+	}
+
+	return master_bank;
+}
+
+static void kinetis_update_bank_info(struct flash_bank *bank)
+{
+	struct flash_bank *master_bank = kinetis_get_master_bank(bank);
+
+	if (master_bank == NULL) {
+		return;
+	}
+
+	/* update the info we do not have */
+	bank-size = master_bank-size;
+	bank-chip_width = master_bank-chip_width;
+	bank-bus_width = master_bank-bus_width;
+	bank-num_sectors = master_bank-num_sectors;
+	bank-sectors = master_bank-sectors;
+}
+
+FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
+{
+	if (CMD_ARGC  6) {
+		LOG_WARNING(incomplete flash_bank kinetis configuration %d,
+			CMD_ARGC);
+		return ERROR_FLASH_OPERATION_FAILED;
+	}
+
+	LOG_INFO(add flash_bank kinetis %s, bank-name);
+
+	return ERROR_OK;
+}
+
+static int kinetis_protect(struct flash_bank *bank, int set, int first,
+			   int last)
+{
+	struct flash_bank *master_bank = kinetis_get_master_bank(bank);
+
+	LOG_WARNING(kinetis_protect not supported yet);
+
+	if (bank-target-state != TARGET_HALTED) {
+		LOG_ERROR(Target not halted);
+		return ERROR_TARGET_NOT_HALTED;
+	}
+
+	if (master_bank == NULL) {
+		return ERROR_FLASH_OPERATION_FAILED;
+	}
+
+	return ERROR_OK;
+}
+
+static int kinetis_protect_check(struct flash_bank *bank)
+{
+	struct flash_bank *master_bank = kinetis_get_master_bank(bank);
+	uint8_t buffer[4];
+	uint32_t fprot, psize, psec;
+	int result;
+	int i, b;
+
+	if (bank-target-state