  
  	return 0;
 diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
-index 63fdb74..ffdf93c 100644
+index 33c4a93..e6c4f01 100644
 --- a/drivers/mtd/cfi_flash.c
 +++ b/drivers/mtd/cfi_flash.c
-@@ -1393,11 +1393,7 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
+@@ -1392,6 +1392,13 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
+ #else
  	while (cnt >= info->portwidth) {
  		cword.w32 = 0;
- 
--		/* Kubos: Need to make sure to keep the watchdog alive during the write process */
--		if( cnt % 1000 == 0)
--		{
--			hw_watchdog_force();
--		}
-+		WATCHDOG_RESET(1000);
- 
++
++#ifdef CONFIG_AT91SAM9G20ISIS
++		WATCHDOG_RESET_COUNT(1000);
++#else
++		WATCHDOG_RESET();
++#endif
++
  		for (i = 0; i < info->portwidth; i++) {
  			flash_add_byte (info, &cword, *src++);
+ 		}
 diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
-index d7772b4..40cfd12 100644
---- a/fs/ext4/ext4fs.c
-+++ b/fs/ext4/ext4fs.c
-@@ -76,10 +76,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
- 		int blockend = blocksize;
- 		int skipfirst = 0;
- 
--		if (i % 1000 == 0)
--		{
--			hw_watchdog_force();
--		}
-+		WATCHDOG_RESET(1000);
- 
- 		blknr = read_allocated_block(&(node->inode), i);
- 		if (blknr < 0)
-diff --git a/include/common.h b/include/common.h
-index a8d833b..39739ce 100644
---- a/include/common.h
-+++ b/include/common.h
-@@ -95,6 +95,8 @@ typedef volatile unsigned char	vu_char;
- #define CONFIG_SYS_SUPPORT_64BIT_DATA
- #endif
- 
-+/*#define DEBUG 1*/
-+
- #ifdef DEBUG
- #define _DEBUG	1
- #else
-diff --git a/include/watchdog.h b/include/watchdog.h
-index 2f2102b..3771e8e 100644
---- a/include/watchdog.h
-+++ b/include/watchdog.h
-@@ -41,6 +41,7 @@ int init_func_watchdog_reset(void);
- 		#define WATCHDOG_RESET bl hw_watchdog_reset
- 	#else
- 		extern void hw_watchdog_reset(void);
-+		extern void hw_watchdog_reset(int val);
- 		extern void hw_watchdog_force(void);
- 
- 		#define WATCHDOG_RESET hw_watchdog_reset
-diff --git a/lib/crc32.c b/lib/crc32.c
-index f3a835a..38e55b8 100644
---- a/lib/crc32.c
-+++ b/lib/crc32.c
-@@ -234,9 +234,6 @@ uint32_t ZEXPORT crc32_wd (uint32_t crc,
- #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
- 	const unsigned char *end, *curr;
- 	int chunk;
--	int count = 0;
--
--	hw_watchdog_force();
- 
- 	curr = buf;
- 	end = buf + len;
-@@ -246,11 +243,11 @@ uint32_t ZEXPORT crc32_wd (uint32_t crc,
- 			chunk = chunk_sz;
- 		crc = crc32 (crc, curr, chunk);
- 		curr += chunk;
-+#ifdef CONFIG_AT91SAM9G20ISIS
-+		WATCHDOG_RESET(10);
-+#else
- 		WATCHDOG_RESET ();
--		if(count++ % 10 == 0)
--		{
--			hw_watchdog_force();
--		}
-+#endif
- 	}
- #else
- 	crc = crc32 (crc, buf, len);
-diff --git a/lib/sha1.c b/lib/sha1.c
-index d6887cb..471046a 100644
---- a/lib/sha1.c
-+++ b/lib/sha1.c
-@@ -315,7 +315,6 @@ void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
- #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
- 	const unsigned char *end, *curr;
- 	int chunk;
--	int count = 0;
- #endif
- 
- 	sha1_starts (&ctx);
-@@ -323,18 +322,18 @@ void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
- #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
- 	curr = input;
- 	end = input + ilen;
--	hw_watchdog_force();
- 	while (curr < end) {
- 		chunk = end - curr;
- 		if (chunk > chunk_sz)
- 			chunk = chunk_sz;
- 		sha1_update (&ctx, curr, chunk);
- 		curr += chunk;
-+#ifdef CONFIG_AT91SAM9G20ISIS
-+		WATCHDOG_RESET(5);
-+#else
- 		WATCHDOG_RESET ();
--		if(count++ % 5 == 0)
--		{
--			hw_watchdog_force();
--		}
-+#endif
-+	}
- 	}
- #else
- 	sha1_update (&ctx, input, ilen);
--- 
-2.7.4
-
-
-From 68914a8794614b272ee933215dbf8345c72d8ba0 Mon Sep 17 00:00:00 2001
-From: Catherine <catherine@kubos.co>
-Date: Mon, 27 Feb 2017 14:23:36 -0600
-Subject: [PATCH 08/10] C doesn't allow function overloading
-
----
- board/kubos/at91sam9g20isis/at91sam9g20isis.c | 4 ++--
- drivers/mmc/gen_atmel_mci.c                   | 6 +++++-
- drivers/mtd/cfi_flash.c                       | 6 +++++-
- fs/ext4/ext4fs.c                              | 6 +++++-
- include/watchdog.h                            | 7 ++++++-
- lib/crc32.c                                   | 2 +-
- lib/sha1.c                                    | 2 +-
- 7 files changed, 25 insertions(+), 8 deletions(-)
-
-diff --git a/board/kubos/at91sam9g20isis/at91sam9g20isis.c b/board/kubos/at91sam9g20isis/at91sam9g20isis.c
-index 4e544c8..b50768d 100644
---- a/board/kubos/at91sam9g20isis/at91sam9g20isis.c
-+++ b/board/kubos/at91sam9g20isis/at91sam9g20isis.c
-@@ -104,7 +104,7 @@ void hw_watchdog_init(void)
- 	at91_set_pio_output(AT91_PIO_PORTA, 30, 1);
- }
- 
--void hw_watchdog_reset(int val)
-+void hw_watchdog_reset_count(int val)
- {
- 	int i = 0;
- 
-@@ -127,7 +127,7 @@ void hw_watchdog_reset(int val)
- 
- void hw_watchdog_reset()
- {
--	hw_watchdog_reset(100000);
-+	hw_watchdog_reset_count(100000);
- }
- 
- 
-diff --git a/drivers/mmc/gen_atmel_mci.c b/drivers/mmc/gen_atmel_mci.c
-index f064da7..46abcc2 100644
---- a/drivers/mmc/gen_atmel_mci.c
-+++ b/drivers/mmc/gen_atmel_mci.c
-@@ -281,7 +281,11 @@ mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
- 				block_count++) {
- 			word_count = 0;
- 
--			WATCHDOG_RESET(1000);
-+#ifdef CONFIG_AT91SAM9G20ISIS
-+			WATCHDOG_RESET_COUNT(1000);
-+#else
-+            WATCHDOG_RESET();
-+#endif
- 
- 			do {
- 				status = mci_data_op(mci, ioptr, error_flags);
-diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
-index ffdf93c..e9e5671 100644
---- a/drivers/mtd/cfi_flash.c
-+++ b/drivers/mtd/cfi_flash.c
-@@ -1393,7 +1393,11 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
- 	while (cnt >= info->portwidth) {
- 		cword.w32 = 0;
- 
--		WATCHDOG_RESET(1000);
-+#ifdef CONFIG_AT91SAM9G20ISIS
-+            WATCHDOG_RESET_COUNT(1000);
-+#else
-+            WATCHDOG_RESET();
-+#endif
- 
- 		for (i = 0; i < info->portwidth; i++) {
- 			flash_add_byte (info, &cword, *src++);
-diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
-index 40cfd12..98247b0 100644
---- a/fs/ext4/ext4fs.c
-+++ b/fs/ext4/ext4fs.c
-@@ -76,7 +76,11 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
- 		int blockend = blocksize;
- 		int skipfirst = 0;
- 
--		WATCHDOG_RESET(1000);
-+#ifdef CONFIG_AT91SAM9G20ISIS
-+            WATCHDOG_RESET_COUNT(1000);
-+#else
-+            WATCHDOG_RESET();
-+#endif
- 
- 		blknr = read_allocated_block(&(node->inode), i);
- 		if (blknr < 0)
-diff --git a/include/watchdog.h b/include/watchdog.h
-index 3771e8e..686ed4c 100644
---- a/include/watchdog.h
-+++ b/include/watchdog.h
-@@ -41,10 +41,15 @@ int init_func_watchdog_reset(void);
- 		#define WATCHDOG_RESET bl hw_watchdog_reset
- 	#else
- 		extern void hw_watchdog_reset(void);
--		extern void hw_watchdog_reset(int val);
- 		extern void hw_watchdog_force(void);
- 
- 		#define WATCHDOG_RESET hw_watchdog_reset
-+
-+        #ifdef CONFIG_AT91SAM9G20ISIS
-+            extern void hw_watchdog_reset_count(int val);
-+
-+            #define WATCHDOG_RESET_COUNT hw_watchdog_reset_count
-+        #endif
- 	#endif /* __ASSEMBLY__ */
- #else
- 	/*
-diff --git a/lib/crc32.c b/lib/crc32.c
-index 38e55b8..8993c5c 100644
---- a/lib/crc32.c
-+++ b/lib/crc32.c
-@@ -244,7 +244,7 @@ uint32_t ZEXPORT crc32_wd (uint32_t crc,
- 		crc = crc32 (crc, curr, chunk);
- 		curr += chunk;
- #ifdef CONFIG_AT91SAM9G20ISIS
--		WATCHDOG_RESET(10);
-+		WATCHDOG_RESET_COUNT(10);
- #else
- 		WATCHDOG_RESET ();
- #endif
-diff --git a/lib/sha1.c b/lib/sha1.c
-index 471046a..9f1d9b4 100644
---- a/lib/sha1.c
-+++ b/lib/sha1.c
-@@ -329,7 +329,7 @@ void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
- 		sha1_update (&ctx, curr, chunk);
- 		curr += chunk;
- #ifdef CONFIG_AT91SAM9G20ISIS
--		WATCHDOG_RESET(5);
-+		WATCHDOG_RESET_COUNT(5);
- #else
- 		WATCHDOG_RESET ();
- #endif
--- 
-2.7.4
-
-
-From 2f1863170f588287c08dfe8bc796c387584c68ad Mon Sep 17 00:00:00 2001
-From: Catherine <catherine@kubos.co>
-Date: Mon, 27 Feb 2017 14:26:35 -0600
-Subject: [PATCH 09/10] Fixing typo
-
----
- lib/sha1.c | 1 -
- 1 file changed, 1 deletion(-)
-
-diff --git a/lib/sha1.c b/lib/sha1.c
-index 9f1d9b4..9f79509 100644
---- a/lib/sha1.c
-+++ b/lib/sha1.c
-@@ -334,7 +334,6 @@ void sha1_csum_wd(const unsigned char *input, unsigned int ilen,
- 		WATCHDOG_RESET ();
- #endif
- 	}
--	}
- #else
- 	sha1_update (&ctx, input, ilen);
- #endif
--- 
-2.7.4
-
-
-From cfc02354fad728927fa9d9e2214171a6292a1fb0 Mon Sep 17 00:00:00 2001
-From: Catherine <catherine@kubos.co>
-Date: Mon, 27 Feb 2017 14:33:35 -0600
-Subject: [PATCH 10/10] Adding missing includes
-
----
- drivers/mmc/gen_atmel_mci.c | 1 +
- fs/ext4/ext4fs.c            | 1 +
- 2 files changed, 2 insertions(+)
-
-diff --git a/drivers/mmc/gen_atmel_mci.c b/drivers/mmc/gen_atmel_mci.c
-index 46abcc2..61b9b48 100644
---- a/drivers/mmc/gen_atmel_mci.c
-+++ b/drivers/mmc/gen_atmel_mci.c
-@@ -13,6 +13,7 @@
- #include <mmc.h>
- #include <part.h>
- #include <malloc.h>
-+#include <watchdog.h>
- #include <asm/io.h>
- #include <linux/errno.h>
- #include <asm/byteorder.h>
-diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
-index 98247b0..eb921a9 100644
+index 3078737..a19bfb4 100644
 --- a/fs/ext4/ext4fs.c
 +++ b/fs/ext4/ext4fs.c
 @@ -26,6 +26,7 @@

 	ret = ext4fs_mount(0);
 	if (!ret) {
-		printf("ERROR: Could not mount upgrade partition. ext4fs mount err - %d\n", ret);
+		error("Could not mount upgrade partition. ext4fs mount err - %d\n", ret);
 
 		return -1;
 	}
 

From 8edb977848e4d3a2d78c500bc0560d5cebfe498b Mon Sep 17 00:00:00 2001
From: Catherine <catherine@kubos.co>
Date: Wed, 15 Feb 2017 16:52:01 -0600
Subject: [PATCH 1/2] Initial file upgrade process - zImage only

---
 board/kubos/at91sam9g20isis/at91sam9g20isis.c |  19 ---
