From 903f79e36b1bc8ff0ef01592935acf7a59af8608 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Mon, 23 Feb 2009 08:51:26 +0100 Subject: [PATCH] Added meaningful error message --- app/tohit/tohit_fn.c | 12 +++++++++++- arch/h8300/generic/libs/boot/boot_fn.c | 2 +- arch/h8300/generic/libs/boot/boot_fn.h | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/tohit/tohit_fn.c b/app/tohit/tohit_fn.c index aefb959..fa47ede 100644 --- a/app/tohit/tohit_fn.c +++ b/app/tohit/tohit_fn.c @@ -8,6 +8,7 @@ #include #include #include "tohit_fn.h" +#include #define DEBUG 0 #define DEBUG_COUNT 0 @@ -341,6 +342,12 @@ const char *cmd_name[] = { [1+TOHIT_RESET] = "RESET" }; +const char *boot_err[] = { + [EBOOT_BLOCKADDR] = "Wrong flash block start/end address", +}; + +#define ARR_SIZE(x) (sizeof(x)/sizeof(x[0])) + int tohit_open4cmd(char *sdev, int baud, int cmd) { @@ -390,7 +397,10 @@ int tohit_cmdrepchk(int fd) return -6; } if (res!=0xAA && res!=0x5a) { - printf("Error in end reply (0x%02X)\n",res); + int err = (int)(signed char)res; + printf("Error in end reply - received 0x%02X == %d (%s)\n", + res, err, + (err < 0 && -err < ARR_SIZE(boot_err)) ? boot_err[-err] : NULL); return -6; } return 0; diff --git a/arch/h8300/generic/libs/boot/boot_fn.c b/arch/h8300/generic/libs/boot/boot_fn.c index 71507f1..c76eced 100644 --- a/arch/h8300/generic/libs/boot/boot_fn.c +++ b/arch/h8300/generic/libs/boot/boot_fn.c @@ -308,7 +308,7 @@ int FlPrepBlk(unsigned long badr, unsigned long len) int bl, blend, res; bl=FlAdr2Blk(badr); blend=FlAdr2Blk(badr+len-1); - if((bl<0)||(blend<0)) return -8; + if((bl<0)||(blend<0)) return -EBOOT_BLOCKADDR; for(;bl<=blend;bl++){ if(FlTest(bl)){ res=FlErase(bl); diff --git a/arch/h8300/generic/libs/boot/boot_fn.h b/arch/h8300/generic/libs/boot/boot_fn.h index 1f1949d..2d8c616 100644 --- a/arch/h8300/generic/libs/boot/boot_fn.h +++ b/arch/h8300/generic/libs/boot/boot_fn.h @@ -1,8 +1,13 @@ #ifndef _boot_fn_H #define _boot_fn_H +#include + #define FLASH_ROW 128 +/* Error codes (returned as negative numbers) */ +#define EBOOT_BLOCKADDR 8 + volatile void FlWait(long n); void wdg_enable(int psel); void wdg_disable(); -- 2.39.2