From 999f86b92b8efe89976e8196a19350a9822e0ca7 Mon Sep 17 00:00:00 2001
From: drath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Date: Thu, 12 Apr 2007 13:27:23 +0000
Subject: [PATCH] - correctly mask out bits that aren't part of a copied buffer
 - fixed arm926ej-s CP15 register access handling - correctly identify SYSCLK
 source in LPC3180 NAND flash controller driver

git-svn-id: svn://svn.berlios.de/openocd/trunk@139 b42882b7-edfa-0310-969c-e2dbd0fdcd60
---
 src/flash/lpc3180_nand_controller.c | 2 +-
 src/helper/binarybuffer.c           | 6 ++++++
 src/target/arm926ejs.c              | 4 ++--
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/flash/lpc3180_nand_controller.c b/src/flash/lpc3180_nand_controller.c
index aae5cbbfb..2ef6f40b6 100644
--- a/src/flash/lpc3180_nand_controller.c
+++ b/src/flash/lpc3180_nand_controller.c
@@ -150,7 +150,7 @@ float lpc3180_cycle_time(lpc3180_nand_controller_t *lpc3180_info)
 	/* determine current SYSCLK (13'MHz or main oscillator) */ 
 	target_read_u32(target, 0x40004050, &sysclk_ctrl);
 	
-	if (sysclk_ctrl & 1)
+	if ((sysclk_ctrl & 1) == 0)
 		sysclk = lpc3180_info->osc_freq;
 	else
 		sysclk = 13000;
diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c
index 7d41dc73a..acc8237eb 100644
--- a/src/helper/binarybuffer.c
+++ b/src/helper/binarybuffer.c
@@ -101,6 +101,12 @@ u8* buf_cpy(u8 *from, u8 *to, int size)
 
 	for (i = 0; i < num_bytes; i++)
 		to[i] = from[i];
+	
+	/* mask out bits that don't belong to the buffer */	
+	if (size % 8)
+	{
+		to[size / 8] &= (0xff >> (8 - (size % 8)));
+	}
 
 	return to;
 }
diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c
index 78d128de7..ecabfcd69 100644
--- a/src/target/arm926ejs.c
+++ b/src/target/arm926ejs.c
@@ -158,7 +158,7 @@ int arm926ejs_read_cp15(target_t *target, u32 address, u32 *value)
 	{
 		jtag_add_dr_scan(4, fields, -1);
 		jtag_execute_queue();
-	} while ((access & 1) != 1);
+	} while (buf_get_u32(&access, 0, 1) != 1);
 
 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
 	DEBUG("addr: 0x%x value: %8.8x", address, *value);
@@ -234,7 +234,7 @@ int arm926ejs_write_cp15(target_t *target, u32 address, u32 value)
 	{
 		jtag_add_dr_scan(4, fields, -1);
 		jtag_execute_queue();
-	} while (access != 1);
+	} while (buf_get_u32(&access, 0, 1) != 1);
 
 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
 	DEBUG("addr: 0x%x value: %8.8x", address, value);
-- 
GitLab