diff --git a/src/flash/aduc702x.c b/src/flash/aduc702x.c
index 3bffe1112ca3045de55b5e5fba49336d22505769..5b80e0c69da21ec92acb041d350dd71752c2050d 100644
--- a/src/flash/aduc702x.c
+++ b/src/flash/aduc702x.c
@@ -331,7 +331,7 @@ static int aduc702x_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offse
  * working area available. */
 static int aduc702x_write_single(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
 {
-	int x;
+	u32 x;
         u8 b;
 	target_t *target = bank->target;
 	
diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c
index efc604194254dc70675302ea415cb2e4dc9870c6..ebc934273b337b54922ce7700dae8a159d28a71b 100644
--- a/src/flash/at91sam7.c
+++ b/src/flash/at91sam7.c
@@ -937,7 +937,8 @@ static int at91sam7_erase(struct flash_bank_s *bank, int first, int last)
 static int at91sam7_protect(struct flash_bank_s *bank, int set, int first, int last)
 {
 	u32 cmd;
-	u32 sector, pagen;
+	int sector;
+	u32 pagen;
 
 	at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
 
diff --git a/src/flash/cfi.c b/src/flash/cfi.c
index 8f456b15963407ca15d0441670208f409db92b9e..6b777fa8e3d0459aeb73a06bb2800bb8ed08c9e3 100644
--- a/src/flash/cfi.c
+++ b/src/flash/cfi.c
@@ -1113,7 +1113,7 @@ static int cfi_intel_write_block(struct flash_bank_s *bank, u8 *buffer, u32 addr
 	};
 	u8 target_code[4*CFI_MAX_INTEL_CODESIZE];
 	const u32 *target_code_src;
-	int target_code_size;
+	u32 target_code_size;
 	int retval = ERROR_OK;
 
 
@@ -1969,7 +1969,7 @@ int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
 			bufferwsize/=(bank->bus_width / bank->chip_width);
 
 			/* fall back to memory writes */
-			while (count >= bank->bus_width)
+			while (count >= (u32)bank->bus_width)
 			{
 				int fallback;
 				if ((write_p & 0xff) == 0)
@@ -2268,7 +2268,7 @@ static int cfi_probe(struct flash_bank_s *bank)
 
 		LOG_DEBUG("size: 0x%x, interface desc: %i, max buffer write size: %x", 1 << cfi_info->dev_size, cfi_info->interface_desc, (1 << cfi_info->max_buf_write_size));
 
-		if (((1 << cfi_info->dev_size) * bank->bus_width / bank->chip_width) != bank->size)
+		if ((u32)((1 << cfi_info->dev_size) * bank->bus_width / bank->chip_width) != bank->size)
 		{
 			LOG_WARNING("configuration specifies 0x%x size, but a 0x%x size flash was found", bank->size, 1 << cfi_info->dev_size);
 		}
@@ -2361,7 +2361,7 @@ static int cfi_probe(struct flash_bank_s *bank)
 
 		for (i = 0; i < cfi_info->num_erase_regions; i++)
 		{
-			int j;
+			u32 j;
 			for (j = 0; j < (cfi_info->erase_region_info[i] & 0xffff) + 1; j++)
 			{
 				bank->sectors[sector].offset = offset;
diff --git a/src/flash/ecos.c b/src/flash/ecos.c
index 601beb276e0eca405c13f7c0712ab84604115b4f..bc31fdd464f0238a55bda1cb6b2564ba8855e62f 100644
--- a/src/flash/ecos.c
+++ b/src/flash/ecos.c
@@ -328,7 +328,7 @@ static int eCosBoard_flash(ecosflash_flash_bank_t *info, void *data, u32 address
 		return retval;
 
 
-	int i;
+	u32 i;
 	for (i=0; i<len; i+=chunk)
 	{
 		int t=len-i;
diff --git a/src/flash/flash.c b/src/flash/flash.c
index 212b6de776ef508c0297d66ef19472950e26ea2d..3d5e08f8dd52b14be504871553b1d138eb4f9976 100644
--- a/src/flash/flash.c
+++ b/src/flash/flash.c
@@ -346,7 +346,7 @@ static int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cm
 static int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
 	flash_bank_t *p;
-	int i = 0;
+	u32 i = 0;
 	int j = 0;
 	int retval;
 
@@ -726,12 +726,12 @@ static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cm
 	u8 chunk[1024];
 	u32 wrote = 0;
 	u32 cur_size = 0;
-	int chunk_count;
+	u32 chunk_count;
 	char *duration_text;
 	duration_t duration;
 	target_t *target = get_current_target(cmd_ctx);
 	u32 i;
-	int wordsize;
+	u32 wordsize;
 
 	if (argc != 3)
 	{
@@ -1129,7 +1129,7 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank)
 	u8 buffer[1024];
 	int buffer_size = sizeof(buffer);
 	int i;
-	int nBytes;
+	u32 nBytes;
 
 	if (bank->target->state != TARGET_HALTED)
 	{
@@ -1139,12 +1139,12 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank)
 
 	for (i = 0; i < bank->num_sectors; i++)
 	{
-		int j;
+		u32 j;
 		bank->sectors[i].is_erased = 1;
 
 		for (j = 0; j < bank->sectors[i].size; j += buffer_size)
 		{
-			int chunk;
+			u32 chunk;
 			int retval;
 			chunk = buffer_size;
 			if (chunk > (j - bank->sectors[i].size))
diff --git a/src/flash/lpc2000.c b/src/flash/lpc2000.c
index 40f985ba6e25af457b9692d966fd3a699d60b658..465a3ff3696e494106c5c96e363257f74df6bb5c 100644
--- a/src/flash/lpc2000.c
+++ b/src/flash/lpc2000.c
@@ -587,7 +587,7 @@ static int lpc2000_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32
 		else
 		{
 			u8 *last_buffer = malloc(thisrun_bytes);
-			int i;
+			u32 i;
 			memcpy(last_buffer, buffer + bytes_written, bytes_remaining);
 			for (i = bytes_remaining; i < thisrun_bytes; i++)
 				last_buffer[i] = 0xff;
diff --git a/src/flash/lpc2000.h b/src/flash/lpc2000.h
index 976ac91920687387b1b17433a18165896901cd56..c527588cda428c92abe32f3f576269bdce93af13 100644
--- a/src/flash/lpc2000.h
+++ b/src/flash/lpc2000.h
@@ -32,7 +32,7 @@ typedef struct lpc2000_flash_bank_s
 	int cmd51_can_256b;
 	int cmd51_can_8192b;
 	int calc_checksum;
-	int cmd51_max_buffer;
+	u32 cmd51_max_buffer;
 } lpc2000_flash_bank_t;
 
 enum lpc2000_status_codes
diff --git a/src/flash/lpc288x.c b/src/flash/lpc288x.c
index c9cfa45747448e07d103ef70d9e9e782bc3ba8bc..1f47896452856892dc55eba0f2ac54ebfb8bfb58 100644
--- a/src/flash/lpc288x.c
+++ b/src/flash/lpc288x.c
@@ -328,10 +328,11 @@ static int lpc288x_erase(struct flash_bank_s *bank, int first, int last)
 static int lpc288x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
 {
 	u8 page_buffer[FLASH_PAGE_SIZE];
-	u32 i, status, source_offset,dest_offset;
+	u32 status, source_offset,dest_offset;
 	target_t *target = bank->target;
 	u32 bytes_remaining = count;
 	u32 first_sector, last_sector, sector, page;
+	int i;
 	
 	/* probed? halted? */
 	status = lpc288x_system_ready(bank);
diff --git a/src/flash/lpc3180_nand_controller.c b/src/flash/lpc3180_nand_controller.c
index 76134e9a1349d6f6ca302d83fded8fb86b28efb9..c24e30aa1e4a51bc24e03acf2365fb632346f64b 100644
--- a/src/flash/lpc3180_nand_controller.c
+++ b/src/flash/lpc3180_nand_controller.c
@@ -546,7 +546,7 @@ static int lpc3180_write_page(struct nand_device_s *device, u32 page, u8 *data,
 			return ERROR_NAND_OPERATION_NOT_SUPPORTED;
 		}
 		
-		if (data_size > device->page_size)
+		if (data_size > (u32)device->page_size)
 		{
 			LOG_ERROR("data size exceeds page size");
 			return ERROR_NAND_OPERATION_NOT_SUPPORTED;
@@ -681,7 +681,7 @@ static int lpc3180_read_page(struct nand_device_s *device, u32 page, u8 *data, u
 		}
 #endif
 		
-		if (data_size > device->page_size)
+		if (data_size > (u32)device->page_size)
 		{
 			LOG_ERROR("data size exceeds page size");
 			return ERROR_NAND_OPERATION_NOT_SUPPORTED;
@@ -741,7 +741,7 @@ static int lpc3180_read_page(struct nand_device_s *device, u32 page, u8 *data, u
 			target_write_u32(target, 0x200b8000, NAND_CMD_READSTART);
 		}
 		
-		while (page_bytes_done < device->page_size)
+		while (page_bytes_done < (u32)device->page_size)
 		{
 			/* MLC_ECC_AUTO_DEC_REG = dummy */
 			target_write_u32(target, 0x200b8014, 0xaa55aa55);
diff --git a/src/flash/nand.c b/src/flash/nand.c
index d460f72988f752001607f8a966626d7a962b1981..0f8e7d26a3bd00ae46c1734cb0f8e0d217584e81 100644
--- a/src/flash/nand.c
+++ b/src/flash/nand.c
@@ -834,7 +834,7 @@ static int nand_read_page(struct nand_device_s *device, u32 page, u8 *data, u32
 
 int nand_read_page_raw(struct nand_device_s *device, u32 page, u8 *data, u32 data_size, u8 *oob, u32 oob_size)
 {
-	int i;
+	u32 i;
 	
 	if (!device->device)
 		return ERROR_NAND_DEVICE_NOT_PROBED;
@@ -948,7 +948,7 @@ int nand_read_page_raw(struct nand_device_s *device, u32 page, u8 *data, u32 dat
 
 int nand_write_page_raw(struct nand_device_s *device, u32 page, u8 *data, u32 data_size, u8 *oob, u32 oob_size)
 {
-	int i;
+	u32 i;
 	int retval;
 	u8 status;
 	
@@ -1400,7 +1400,7 @@ static int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cm
 
 			if (oob_format & NAND_OOB_SW_ECC)
 			{
-				int i, j;
+				u32 i, j;
 				u8 ecc[3];
 				memset(oob, 0xff, oob_size);
 				for (i = 0, j = 0; i < page_size; i += 256) {
diff --git a/src/flash/ocl.c b/src/flash/ocl.c
index 8f2a54456c836ed08f8f08659227c71b8b9ef46b..ec8c20dcecf4c8b2287d3b11e4c64d95fa04dab7 100644
--- a/src/flash/ocl.c
+++ b/src/flash/ocl.c
@@ -66,8 +66,8 @@ flash_driver_t ocl_flash =
 typedef struct ocl_priv_s
 {
 	arm_jtag_t *jtag_info;
-	int buflen;
-	int bufalign;
+	unsigned int buflen;
+	unsigned int bufalign;
 } ocl_priv_t;
 
 static int ocl_register_commands(struct command_context_s *cmd_ctx)
diff --git a/src/flash/pic32mx.c b/src/flash/pic32mx.c
index 3fa79e5287f318d18e7c23592d50f4bb2d144a1e..87ee15dc3a1e4db07b5624cdaf9c98fc97e71a60 100644
--- a/src/flash/pic32mx.c
+++ b/src/flash/pic32mx.c
@@ -526,7 +526,7 @@ static int pic32mx_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32
 	u32 address = bank->base + offset;
 	u32 bytes_written = 0;
 	u32 status;
-	u32 retval;
+	int retval;
 
 	if (bank->target->state != TARGET_HALTED)
 	{
diff --git a/src/flash/stellaris.c b/src/flash/stellaris.c
index bf268b5867b7ee518e660d4718c52eec69a7970a..b13f894a24e9d596b5bfc9c71426a9df2eb88640 100644
--- a/src/flash/stellaris.c
+++ b/src/flash/stellaris.c
@@ -570,12 +570,12 @@ static int stellaris_erase(struct flash_bank_s *bank, int first, int last)
 		return ERROR_FLASH_OPERATION_FAILED;
 	}	
 	
-	if ((first < 0) || (last < first) || (last >= stellaris_info->num_pages))
+	if ((first < 0) || (last < first) || (last >= (int)stellaris_info->num_pages))
 	{
 		return ERROR_FLASH_SECTOR_INVALID;
 	}
 	
-	if ((first == 0) && (last == (stellaris_info->num_pages-1)))
+	if ((first == 0) && (last == ((int)stellaris_info->num_pages-1)))
 	{
 		return stellaris_mass_erase(bank);
 	}
@@ -821,7 +821,7 @@ static int stellaris_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u3
 	u32 words_remaining = (count / 4);
 	u32 bytes_remaining = (count & 0x00000003);
 	u32 bytes_written = 0;
-	u32 retval;
+	int retval;
 	
 	if (bank->target->state != TARGET_HALTED)
 	{
diff --git a/src/flash/stm32x.c b/src/flash/stm32x.c
index e9a582f26fb2347f38f83e6792778e0d26de1802..2fa49c8934df5ea122f76a64ff01f6fbad6a5935 100644
--- a/src/flash/stm32x.c
+++ b/src/flash/stm32x.c
@@ -603,7 +603,7 @@ static int stm32x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 c
 	u32 address = bank->base + offset;
 	u32 bytes_written = 0;
 	u8 status;
-	u32 retval;
+	int retval;
 	
 	if (bank->target->state != TARGET_HALTED)
 	{
diff --git a/src/flash/str7x.c b/src/flash/str7x.c
index 8d151cf7d6a356b5b400252698e86bd24fac9afa..1d9396beb65e85263f4ceecf9ee081890496f4f2 100644
--- a/src/flash/str7x.c
+++ b/src/flash/str7x.c
@@ -478,7 +478,7 @@ static int str7x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 co
 	u32 address = bank->base + offset;
 	u32 bytes_written = 0;
 	u32 cmd;
-	u32 retval;
+	int retval;
 	u32 check_address = offset;
 	int i;
 	
diff --git a/src/flash/str9x.c b/src/flash/str9x.c
index c1e97dbbe29eb20defdd3ff4336acdb6b6979f0c..45a3fd67789236c9f97f5d424e8d9a916299f931 100644
--- a/src/flash/str9x.c
+++ b/src/flash/str9x.c
@@ -509,7 +509,7 @@ static int str9x_write(struct flash_bank_s *bank,
 	u32 address = bank->base + offset;
 	u32 bytes_written = 0;
 	u8 status;
-	u32 retval;
+	int retval;
 	u32 check_address = offset;
 	u32 bank_adr;
 	int i;
diff --git a/src/flash/str9xpec.c b/src/flash/str9xpec.c
index 0888e3e9ed3d07b7382a9e1ab68a62b28f6f3226..074d751c61b129b8f138c7b5649d6ea4b6e5f2b8 100644
--- a/src/flash/str9xpec.c
+++ b/src/flash/str9xpec.c
@@ -687,8 +687,8 @@ static int str9xpec_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32
 	scan_field_t field;
 	u8 *scanbuf;
 	int i;
-	u32 first_sector = 0;
-	u32 last_sector = 0;
+	int first_sector = 0;
+	int last_sector = 0;
 
 	tap = str9xpec_info->tap;
 
diff --git a/src/flash/tms470.c b/src/flash/tms470.c
index 6a6d830bb39bea7f29c758654ad7f4776674e601..0e48703b965e5fb167aba0608dd94c67b1fe87eb 100644
--- a/src/flash/tms470.c
+++ b/src/flash/tms470.c
@@ -955,7 +955,8 @@ static int tms470_write(struct flash_bank_s *bank, u8 * buffer, u32 offset, u32
 {
 	target_t *target = bank->target;
 	u32 glbctrl, fmbac2, orig_fmregopt, fmbsea, fmbseb, fmmaxpp, fmmstat;
-	int i, result = ERROR_OK;
+	int result = ERROR_OK;
+	u32 i;
 
 	if (target->state != TARGET_HALTED)
 	{