ADD: [nrhw18] added hwreset command for reset button testing
BugzID: 57382
This commit is contained in:
parent
489a002d17
commit
099d95a569
|
|
@ -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 <nbhw.h>
|
|
||||||
#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 */
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#include <fdt_support.h>
|
#include <fdt_support.h>
|
||||||
#include <dm.h>
|
#include <dm.h>
|
||||||
#include <wdt.h>
|
#include <wdt.h>
|
||||||
|
#include <console.h> /* ctrlc */
|
||||||
|
|
||||||
#include <asm/gpio.h>
|
#include <asm/gpio.h>
|
||||||
|
|
||||||
|
|
@ -645,7 +646,34 @@ static int check_reset_button(void)
|
||||||
|
|
||||||
return 0;
|
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)
|
int misc_init_r(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -280,6 +280,11 @@ config CMD_POWEROFF
|
||||||
help
|
help
|
||||||
Poweroff/Shutdown the system
|
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
|
config CMD_SPL
|
||||||
bool "spl export - Export boot information for Falcon boot"
|
bool "spl export - Export boot information for Falcon boot"
|
||||||
depends on SPL
|
depends on SPL
|
||||||
|
|
|
||||||
11
cmd/boot.c
11
cmd/boot.c
|
|
@ -69,3 +69,14 @@ U_BOOT_CMD(
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
#endif
|
#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 */
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ CONFIG_SPL_I2C_SUPPORT=y
|
||||||
CONFIG_HUSH_PARSER=y
|
CONFIG_HUSH_PARSER=y
|
||||||
CONFIG_CMD_BOOTZ=y
|
CONFIG_CMD_BOOTZ=y
|
||||||
# CONFIG_CMD_IMLS is not set
|
# CONFIG_CMD_IMLS is not set
|
||||||
|
CONFIG_CMD_NB_TEST=y
|
||||||
# CONFIG_CMD_FLASH is not set
|
# CONFIG_CMD_FLASH is not set
|
||||||
CONFIG_CMD_MMC=y
|
CONFIG_CMD_MMC=y
|
||||||
CONFIG_CMD_SF=y
|
CONFIG_CMD_SF=y
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue