nbhw16: fixed auto boot for sdprod script

nbhw16: added nbsw style u-boot environment settings
nbhw16: added factory reset and recovery boot support via reset button
nbhw16: set hardware version on kernel command line
nbhw16: removed dummy u-boot partition
This commit is contained in:
Marcel Reichmuth 2016-07-11 16:16:43 +02:00
parent 705d166512
commit d799d21b6e
4 changed files with 129 additions and 9 deletions

View File

@ -56,6 +56,7 @@ DECLARE_GLOBAL_DATA_PTR;
#define NETBIRD_GPIO_EN_GPS_ANT GPIO_TO_PIN(2, 24)
#define NETBIRD_GPIO_LED_A GPIO_TO_PIN(1, 14)
#define NETBIRD_GPIO_LED_B GPIO_TO_PIN(1, 15)
#define NETBIRD_GPIO_RESET_BUTTON GPIO_TO_PIN(1, 13)
#if defined(CONFIG_SPL_BUILD) || \
(defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH))
@ -214,6 +215,81 @@ err_free_gpio:
#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
#define REQUEST_AND_CLEAR_GPIO(N) request_and_set_gpio(N, #N, 0);
int check_reset_button(void)
{
int counter = 0;
int ret;
ret = gpio_request(NETBIRD_GPIO_RESET_BUTTON, "reset button");
if (ret < 0) {
printf("Unable to request reset button gpio\n");
return -1;
}
ret = gpio_direction_input(NETBIRD_GPIO_RESET_BUTTON);
if (ret < 0) {
printf("Unable to set reset button as input\n");
return -1;
}
/* Check if reset button is pressed for at least 3 seconds */
do {
if (gpio_get_value(NETBIRD_GPIO_RESET_BUTTON) != 0) break;
udelay(100000); /* 100ms */
counter++;
if (counter==30) {/* Indicate factory reset threshold */
/* let LED blink up once */
gpio_set_value(NETBIRD_GPIO_LED_B, 1);
udelay(400000); /* 400ms */
gpio_set_value(NETBIRD_GPIO_LED_B, 0);
} else if (counter==150) { /* Indicate recovery boot threshold */
/* let LED blink up twice */
gpio_set_value(NETBIRD_GPIO_LED_B, 1);
udelay(400000); /* 400ms */
gpio_set_value(NETBIRD_GPIO_LED_B, 0);
udelay(400000); /* 400ms */
gpio_set_value(NETBIRD_GPIO_LED_B, 1);
udelay(400000); /* 400ms */
gpio_set_value(NETBIRD_GPIO_LED_B, 0);
}
} 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 = getenv("bootargs");
if (bootargs==0) bootargs="";
printf("Do factory reset during boot...\n");
strncpy(new_bootargs, bootargs, sizeof(new_bootargs));
strncat(new_bootargs, " factory-reset", sizeof(new_bootargs));
setenv("bootargs", new_bootargs);
printf("bootargs = %s\n", new_bootargs);
return 1;
} else { /* Boot into recovery for duration > 15s */
/* set consoledev to external port */
setenv("consoledev", "ttyO0");
printf("Booting recovery image...\n");
/* Set bootcmd to run recovery */
setenv("bootcmd", "run recovery");
return 0;
}
return 0;
}
/*
* Basic board specific setup. Pinmux has been handled already.
*/
@ -233,7 +309,8 @@ int board_init(void)
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_PWR_GSM);
mdelay(1200);
gpio_set_value(NETBIRD_GPIO_PWR_GSM, 0);
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_LED_A);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_LED_A);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_LED_B);
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_PHY_N);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_WLAN_EN);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_BT_EN);
@ -334,6 +411,7 @@ static void set_mac_address(int index, uchar mac[6])
*/
int board_eth_init(bd_t *bis)
{
int hw_ver, hw_rev;
int rv, n = 0;
uint8_t mac_addr0[6] = {02,00,00,00,00,01};
uint8_t mac_addr1[6] = {02,00,00,00,00,02};
@ -355,13 +433,25 @@ int board_eth_init(bd_t *bis)
bd_get_mac_address(1, mac_addr1, sizeof(mac_addr1));
set_mac_address(1, mac_addr1);
/* add active root partition to environment */
boot_partition = bd_get_boot_partition();
if (boot_partition > 1) {
boot_partition = 0;
}
/* mmcblk0p1 => u-boot, mmcblk0p2 => root0 so +2 */
setenv_ulong("root_part", boot_partition + 2);
/* mmcblk0p1 => root0, mmcblk0p2 => root1 so +1 */
setenv_ulong("root_part", boot_partition + 1);
/* add hardware versions to environment */
if (bd_get_hw_version(&hw_ver, &hw_rev)==0) {
char hw_versions[128];
char new_env[256];
snprintf(hw_versions, sizeof(hw_versions), "CP=%d.%d", hw_ver, hw_rev);
snprintf(new_env, sizeof(new_env), "setenv bootargs $bootargs %s", hw_versions);
setenv("add_version_bootargs", new_env);
}
check_reset_button();
writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;

View File

@ -160,7 +160,7 @@ static u8 try_partition_read(void)
partition_count++;
if (((partition.flags & BD_Partition_Flags_Active) != 0) &&
(i > 0)) {
boot_partition = i - 1; /* The first one is a dummy partition for u-boot */
boot_partition = i;
}
}
}
@ -211,3 +211,30 @@ int bd_get_mac_address(uint index, u8 *mac, u32 len)
else
return -1;
}
int bd_get_hw_version(int* pVer, int* pRev)
{
u8 bdCpHwVer = 0;
u8 bdCpHwRev = 0;
if (bd_board_info == 0) {
puts("Board info not valid, can not get hw version\n");
return -1;
}
/* Hardware version/revision */
if ( !BD_GetUInt8( bd_board_info, BD_Hw_Ver, 0, &bdCpHwVer) ) {
printf("no Hw version found\n");
return -1;
}
/* Hardware version/revision */
if ( !BD_GetUInt8( bd_board_info, BD_Hw_Rel, 0, &bdCpHwRev) ) {
printf("no Hw release found\n");
return -1;
}
*pVer = bdCpHwVer;
*pRev = bdCpHwRev;
return 0;
}

View File

@ -12,5 +12,6 @@
int bd_read(int bus_addr, int dev_addr);
u8 bd_get_boot_partition(void);
int bd_get_mac_address(uint index, u8 *mac_address, u32 len);
int bd_get_hw_version(int* pVer, int* pRev);
#endif /* __BOARD_DESCRIPTOR_H */

View File

@ -57,12 +57,14 @@
"ext4load mmc 1:$root_part $fdt_addr /boot/am335x-nbhw16.dtb && setenv bootargs $bootargs rw;\0" \
"sdprod=ext4load mmc 1:$root_part $kernel_addr /boot/$kernel_image && " \
"ext4load mmc 1:$root_part $fdt_addr /boot/$fdt_image && setenv bootargs $bootargs ro;\0" \
"sdboot=if mmc dev 1; then " \
"echo Copying Linux from SD to RAM... && " \
"run sdprod || run sdbringup && " \
"run add_sd_bootargs && run add_version_bootargs && bootz $kernel_addr - $fdt_addr; " \
"fi\0" \
"sdboot=if mmc dev 1; then echo Copying Linux from SD to RAM...; "\
"if test -e mmc 1:$root_part /boot/$kernel_image; then run sdprod; " \
"else run sdbringup; fi; " \
"run add_sd_bootargs; run add_version_bootargs; " \
"bootz $kernel_addr - $fdt_addr; fi\0" \
"bootcmd=run sdboot\0" \
"ipaddr=192.168.1.1\0" \
"serverip=192.168.1.254\0" \
"recovery=tftpboot $kernel_addr recovery-image; tftpboot $fdt_addr recovery-dtb; setenv bootargs rdinit=/etc/preinit console=ttyO0,115200 debug; bootz $kernel_addr - $fdt_addr\0"
#endif