diff --git a/board/nm/common/nbhw_reset.c b/board/nm/common/nbhw_reset.c deleted file mode 100644 index 5d80608757..0000000000 --- a/board/nm/common/nbhw_reset.c +++ /dev/null @@ -1,177 +0,0 @@ -/****************************************************************************** - * (c) COPYRIGHT 2015 by NetModule AG, Switzerland. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - *****************************************************************************/ - -#include "config.h" - -#include -#include "board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib.h" -#include "board/mv_ebu/a38x/armada_38x_family/device/mvDeviceRegs.h" -#include "board/mv_ebu/common/mv_hal/gpp/mvGpp.h" -#include "fs.h" -#include "mmc.h" -#include "nbhw_gpio.h" - -struct mbr_partitions { - unsigned char status; - unsigned char chs_first[3]; - unsigned char partition_type; - unsigned char chs_last[3]; - unsigned int lba_first; - unsigned int lba_count; -}; - -struct mbr { - unsigned char res0[446]; - struct mbr_partitions partitions[4]; - unsigned char sig55; - unsigned char sigAA; -} __attribute__ ((packed)); - -int check_reset_button(void) -{ - int counter = 0; - - /* Check if reset button is pressed for at least 3 seconds */ - do { - if (in_reset_button() == 0) break; - udelay(100000); /* 100ms */ - counter++; - - if (counter==30) /* Indicate factory reset threshold */ - { - /* let all green LEDs blink up */ - FPGA_REG(0x0020) = 0x1555; - udelay(400000); /* 400ms */ - FPGA_REG(0x0020) = 0x0001; - } else if (counter==150) { /* Indicate recovery boot threshold */ - /* let all red LEDs blink up */ - FPGA_REG(0x0020) = 0x2aaa; - udelay(400000); /* 400ms */ - FPGA_REG(0x0020) = 0x0001; - } - } while (counter<150); - - if (counter < 30) return 0; /* Don't do anything for duration < 3s */ - - if (counter < 150) /* Do factory reset for duration between 3s and 15s */ - { - char new_bootargs[512]; - char *bootargs = env_get("bootargs"); - - printf("Do factory reset during boot...\n"); - - strncpy(new_bootargs, bootargs, sizeof(new_bootargs)); - strncat(new_bootargs, " factory-reset", sizeof(new_bootargs)); - - env_set("bootargs", new_bootargs); - - printf("bootargs = %s\n", new_bootargs); - - return 1; - } else { /* Boot into recovery for duration > 15s */ - /* Erase data partitions */ - struct mbr m; - struct mbr_partitions p[4]; - struct mmc *mmc = find_mmc_device(0); - void* blankbuf; - int i; - - mmc_init(mmc); - - /* Read MBR */ - if (mmc->block_dev.block_read(0, 0, 1, &m)!=1) goto fail; - flush_cache((ulong)&m, sizeof(m)); - - /* Check for valid mbr */ - if ((m.sig55!=0x55) || (m.sigAA!=0xaa)) goto fail; - memcpy(&p, &m.partitions, sizeof(p)); - - /* Erase data partitions */ - blankbuf = malloc(mmc->erase_grp_size*mmc->write_bl_len); - if (blankbuf) { - memset(blankbuf, 0x00, mmc->erase_grp_size*mmc->write_bl_len); - for (i=2; i<4; i++) { - if (p[i].partition_type) { /* Check, if entry is in use */ - unsigned int begin_unaligned_blocks; - unsigned int end_unaligned_blocks; - unsigned int erase_start_block; - unsigned int erase_num_blocks; - - begin_unaligned_blocks = p[i].lba_first % mmc->erase_grp_size; - begin_unaligned_blocks = (begin_unaligned_blocks) ? mmc->erase_grp_size - begin_unaligned_blocks : 0; - end_unaligned_blocks = (p[i].lba_count-begin_unaligned_blocks) % mmc->erase_grp_size; - erase_start_block = p[i].lba_first+begin_unaligned_blocks; - erase_num_blocks = p[i].lba_count-begin_unaligned_blocks-end_unaligned_blocks; - - printf("Erasing partition %i...\n", i); - - if (begin_unaligned_blocks) { - mmc->block_dev.block_write(0, p[i].lba_first, begin_unaligned_blocks, blankbuf); - } - - if (erase_num_blocks) { - mmc->block_dev.block_erase(0, erase_start_block, erase_num_blocks); - } - - if (end_unaligned_blocks) { - mmc->block_dev.block_write(0, p[i].lba_first+p[i].lba_count-end_unaligned_blocks, end_unaligned_blocks, blankbuf); - } - } - } - free(blankbuf); - } - -fail: - /* set consoledev to external port */ - env_set("consoledev", "ttyS0"); - - printf("Booting recovery image...\n"); - - /* Set bootcmd to run recovery */ - env_set("bootcmd", "run recovery"); - - return 0; - } - return 0; -} - -#ifdef CONFIG_CMD_NB_TEST -/* - * Perform a hardware reset test. The complete test loops until - * interrupted by ctrl-c or by pressed the RESET button. - */ -int do_hwreset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - static u32 gpio_cpu_value = 0x00000000; - - printf(" Press RESET button in hardware reset the board.\n"); - - while (gpio_cpu_value == 0) { - gpio_cpu_value = (in_reset_button() == 0) ? 0 : 1; - - printf("RESET_BTN = %d\n",gpio_cpu_value); - if (ctrlc()) { - putc ('\n'); - return 1; - } - udelay(20*1000); - } - - if (gpio_cpu_value == 1) { - out_ext_reset_en(1); - } - return 1; -} -#endif /* CONFIG_CMD_NB_TEST */ diff --git a/board/nm/nbhw18_v2/board.c b/board/nm/nbhw18_v2/board.c index f81ac5137b..f9d28f2b97 100644 --- a/board/nm/nbhw18_v2/board.c +++ b/board/nm/nbhw18_v2/board.c @@ -18,6 +18,7 @@ #include #include #include +#include /* ctrlc */ #include @@ -645,7 +646,34 @@ static int check_reset_button(void) return 0; } -#endif + +#ifdef CONFIG_CMD_NB_TEST +/* + * Perform a hardware reset test. The complete test loops until + * interrupted by ctrl-c or by pressed the RESET button. + */ +int do_hwreset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + int gpio_cpu_value = 0; + + printf(" Press RESET button for testing or ctrl-c to abort\n"); + + while (gpio_cpu_value == 0) { + gpio_cpu_value = get_button_state() ? 1 : 0; + + printf("RESET_BTN = %d\n",gpio_cpu_value); + if (ctrlc()) { + putc ('\n'); + return 1; + } + udelay(20*1000); + } + + return 1; +} +#endif /* CONFIG_CMD_NB_TEST */ + +#endif /* !defined(CONFIG_SPL_BUILD) */ int misc_init_r(void) { diff --git a/cmd/Kconfig b/cmd/Kconfig index 5a6afab99b..0e6ab93152 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -280,6 +280,11 @@ config CMD_POWEROFF help Poweroff/Shutdown the system +config CMD_NB_TEST + bool "nrhw reset button test" + help + Adds a command to test the reset button + config CMD_SPL bool "spl export - Export boot information for Falcon boot" depends on SPL diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..f5c9becbe3 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -69,3 +69,14 @@ U_BOOT_CMD( "" ); #endif + +#ifdef CONFIG_CMD_NB_TEST + +extern int do_hwreset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + +U_BOOT_CMD( + hwreset, 1, 0, do_hwreset, + "Perform HARD RESET of the CPU", + "" +); +#endif /* CONFIG_CMD_NB_TEST */ diff --git a/configs/armada-385-nbhw18-v2_defconfig b/configs/armada-385-nbhw18-v2_defconfig index 7f807c4c4b..1a7923d6d6 100644 --- a/configs/armada-385-nbhw18-v2_defconfig +++ b/configs/armada-385-nbhw18-v2_defconfig @@ -26,6 +26,7 @@ CONFIG_SPL_I2C_SUPPORT=y CONFIG_HUSH_PARSER=y CONFIG_CMD_BOOTZ=y # CONFIG_CMD_IMLS is not set +CONFIG_CMD_NB_TEST=y # CONFIG_CMD_FLASH is not set CONFIG_CMD_MMC=y CONFIG_CMD_SF=y