From 186f9c130faa3e228b0db7f45de359748f78b1c3 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Wed, 5 Jun 2013 14:51:05 +0200 Subject: ac14xx: fix a potential NULL deref in diagnostics getenv() immediately after setenv() may perfectly legally return NULL, so make sure to not deference an invalid pointer when creating diagnostic output Signed-off-by: Gerhard Sittig --- board/ifm/ac14xx/ac14xx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'board/ifm/ac14xx/ac14xx.c') diff --git a/board/ifm/ac14xx/ac14xx.c b/board/ifm/ac14xx/ac14xx.c index 7442591..f200b45 100644 --- a/board/ifm/ac14xx/ac14xx.c +++ b/board/ifm/ac14xx/ac14xx.c @@ -209,6 +209,7 @@ static int read_eeprom(void) int mac_read_from_eeprom(void) { const u8 *mac; + const char *mac_txt; if (read_eeprom()) { printf("I2C EEPROM read failed.\n"); @@ -230,8 +231,11 @@ int mac_read_from_eeprom(void) if (mac && is_valid_ether_addr(mac)) { eth_setenv_enetaddr("ethaddr", mac); - printf("DIAG: %s() MAC value [%s]\n", - __func__, getenv("ethaddr")); + mac_txt = getenv("ethaddr"); + if (mac_txt) + printf("DIAG: MAC value [%s]\n", mac_txt); + else + printf("DIAG: failed to setup MAC env\n"); } return 0; -- cgit v1.1 From b5992e77effcf15cbd50753fd85033a3f9887825 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Wed, 5 Jun 2013 14:51:06 +0200 Subject: ac14xx: cleanup comments in the board support fix typos, minor rephrasing, remove obsolete notes and TODO items Signed-off-by: Gerhard Sittig --- board/ifm/ac14xx/ac14xx.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'board/ifm/ac14xx/ac14xx.c') diff --git a/board/ifm/ac14xx/ac14xx.c b/board/ifm/ac14xx/ac14xx.c index f200b45..d45b7b2 100644 --- a/board/ifm/ac14xx/ac14xx.c +++ b/board/ifm/ac14xx/ac14xx.c @@ -37,7 +37,7 @@ static void gpio_configure(void) /* * out_be32(&gpioregs->gpdir, 0xC2293020); - * workaround for a hardware affect: configure direction in pieces, + * workaround for a hardware effect: configure direction in pieces, * setting all outputs at once drops the reset line too low and * makes us lose the MII connection (breaks ethernet for us) */ @@ -330,8 +330,7 @@ int misc_init_r(void) gpio_configure(); /* - * check the GPIO keyboard, - * enforced start of the recovery when + * enforce the start of the recovery system when * - the appropriate keys were pressed * - a previous installation was aborted or has failed * - "some" external software told us to @@ -339,13 +338,8 @@ int misc_init_r(void) want_recovery = 0; keys = gpio_querykbd(); printf("GPIO keyboard status [0x%08X]\n", keys); - /* XXX insist in the _exact_ combination? */ if ((keys & GPIOKEY_BITS_RECOVERY) == GPIOKEY_BITS_RECOVERY) { printf("GPIO keyboard requested RECOVERY\n"); - /* XXX TODO - * refine the logic to detect the first keypress, and - * wait to recheck IF it was the recovery combination? - */ want_recovery = 1; } s = getenv("install_in_progress"); -- cgit v1.1 From 527a1c71fbe264be9b37c3c2a9d992ea1ee91390 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Wed, 5 Jun 2013 14:51:07 +0200 Subject: ac14xx: minor improvement in diagnostics - minor rewording of diagnostics output - make diagnostics optional and off by default Signed-off-by: Gerhard Sittig --- board/ifm/ac14xx/ac14xx.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'board/ifm/ac14xx/ac14xx.c') diff --git a/board/ifm/ac14xx/ac14xx.c b/board/ifm/ac14xx/ac14xx.c index d45b7b2..c8e88cc 100644 --- a/board/ifm/ac14xx/ac14xx.c +++ b/board/ifm/ac14xx/ac14xx.c @@ -23,6 +23,10 @@ #include #endif +static int eeprom_diag; +static int mac_diag; +static int gpio_diag; + DECLARE_GLOBAL_DATA_PTR; static void gpio_configure(void) @@ -126,8 +130,6 @@ static u32 gpio_querykbd(void) /* excerpt from the recovery's hw_info.h */ -static int eeprom_diag = 1; - struct __attribute__ ((__packed__)) eeprom_layout { char magic[3]; /** 'ifm' */ u8 len[2]; /** content length without magic/len fields */ @@ -231,11 +233,13 @@ int mac_read_from_eeprom(void) if (mac && is_valid_ether_addr(mac)) { eth_setenv_enetaddr("ethaddr", mac); - mac_txt = getenv("ethaddr"); - if (mac_txt) - printf("DIAG: MAC value [%s]\n", mac_txt); - else - printf("DIAG: failed to setup MAC env\n"); + if (mac_diag) { + mac_txt = getenv("ethaddr"); + if (mac_txt) + printf("DIAG: MAC value [%s]\n", mac_txt); + else + printf("DIAG: failed to setup MAC env\n"); + } } return 0; @@ -337,29 +341,31 @@ int misc_init_r(void) */ want_recovery = 0; keys = gpio_querykbd(); - printf("GPIO keyboard status [0x%08X]\n", keys); + if (gpio_diag) + printf("GPIO keyboard status [0x%02X]\n", keys); if ((keys & GPIOKEY_BITS_RECOVERY) == GPIOKEY_BITS_RECOVERY) { - printf("GPIO keyboard requested RECOVERY\n"); + printf("detected recovery request (keyboard)\n"); want_recovery = 1; } s = getenv("install_in_progress"); if ((s != NULL) && (*s != '\0')) { - printf("previous installation aborted, running RECOVERY\n"); + printf("previous installation has not completed\n"); want_recovery = 1; } s = getenv("install_failed"); if ((s != NULL) && (*s != '\0')) { - printf("previous installation FAILED, running RECOVERY\n"); + printf("previous installation has failed\n"); want_recovery = 1; } s = getenv("want_recovery"); if ((s != NULL) && (*s != '\0')) { - printf("running RECOVERY according to the request\n"); + printf("detected recovery request (environment)\n"); want_recovery = 1; } - - if (want_recovery) + if (want_recovery) { + printf("enforced start of the recovery system\n"); setenv("bootcmd", "run recovery"); + } /* * boot the recovery system without waiting; boot the -- cgit v1.1 From 14d4c5f39ed24df2fba6e60d1e1c89f66d419345 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Wed, 5 Jun 2013 14:51:08 +0200 Subject: ac14xx: re-order the recovery condition checks re-order the conditions which make the recovery system startup: combine those conditions which were explicitly initiated (key press, software request) and those which post-process error conditions (installer issues) Signed-off-by: Gerhard Sittig --- board/ifm/ac14xx/ac14xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'board/ifm/ac14xx/ac14xx.c') diff --git a/board/ifm/ac14xx/ac14xx.c b/board/ifm/ac14xx/ac14xx.c index c8e88cc..dc2aff0 100644 --- a/board/ifm/ac14xx/ac14xx.c +++ b/board/ifm/ac14xx/ac14xx.c @@ -336,8 +336,8 @@ int misc_init_r(void) /* * enforce the start of the recovery system when * - the appropriate keys were pressed - * - a previous installation was aborted or has failed * - "some" external software told us to + * - a previous installation was aborted or has failed */ want_recovery = 0; keys = gpio_querykbd(); @@ -347,6 +347,11 @@ int misc_init_r(void) printf("detected recovery request (keyboard)\n"); want_recovery = 1; } + s = getenv("want_recovery"); + if ((s != NULL) && (*s != '\0')) { + printf("detected recovery request (environment)\n"); + want_recovery = 1; + } s = getenv("install_in_progress"); if ((s != NULL) && (*s != '\0')) { printf("previous installation has not completed\n"); @@ -357,11 +362,6 @@ int misc_init_r(void) printf("previous installation has failed\n"); want_recovery = 1; } - s = getenv("want_recovery"); - if ((s != NULL) && (*s != '\0')) { - printf("detected recovery request (environment)\n"); - want_recovery = 1; - } if (want_recovery) { printf("enforced start of the recovery system\n"); setenv("bootcmd", "run recovery"); -- cgit v1.1