diff --git a/board/nm/netbird/board.c b/board/nm/netbird/board.c index 2fa606b459..e48a880df7 100644 --- a/board/nm/netbird/board.c +++ b/board/nm/netbird/board.c @@ -326,6 +326,35 @@ int board_init(void) #ifdef CONFIG_BOARD_LATE_INIT int board_late_init(void) { +#if !defined(CONFIG_SPL_BUILD) + int hw_ver, hw_rev; + int boot_partition; + + if (read_eeprom() < 0) + puts("Could not get board ID.\n"); + + /* add active root partition to environment */ + boot_partition = bd_get_boot_partition(); + if (boot_partition > 1) { + boot_partition = 0; + } + + /* 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(); + +#endif + #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG int rc; char *name = NULL; @@ -411,48 +440,22 @@ 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}; __maybe_unused struct ti_am_eeprom *header; - int boot_partition; - #if !defined(CONFIG_SPL_BUILD) #ifdef CONFIG_DRIVER_TI_CPSW cpsw_data.mdio_div = 0x3E; - if (read_eeprom() < 0) - puts("Could not get board ID.\n"); - bd_get_mac_address(0, mac_addr0, sizeof(mac_addr0)); set_mac_address(0, mac_addr0); 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 => 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; cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII; diff --git a/common/main.c b/common/main.c index 2116a9e0a2..9688c25f6e 100644 --- a/common/main.c +++ b/common/main.c @@ -13,6 +13,9 @@ #include #include +#include +#include + DECLARE_GLOBAL_DATA_PTR; /* @@ -20,6 +23,83 @@ DECLARE_GLOBAL_DATA_PTR; */ __weak void show_boot_progress(int val) {} + +#ifdef CONFIG_NM_LOGIN + +/**************************************************************************** + * check if ubootpwd exists in data partition and perform a login, + * otherwise continue booting + */ +int login (void) +{ + #define PASS_LEN 256 + char stored[16]; + char buf[PASS_LEN], entered[16]; + int res, i, tries; + loff_t actread; + + puts("\nautoboot has been stopped, press 'e' to enter: "); + + for (i=0; i<=4096; i++) { + buf[0] = getc(); + if (buf[0] == 'e' || buf[0] == '\n') { + puts("e"); + break; + } + if (i == 4096) return 0; + } + puts("\n"); + + memset(stored, 0x0, sizeof(stored)); + + if (fs_set_blk_dev("mmc", "1:3", FS_TYPE_EXT) != 0) { + puts("Error, can not set blk devicet"); + return 1; + } + + res = fs_read("/root/boot/bootpass", (ulong)stored, 0, sizeof(stored), &actread); + if ((res!=0) || (actread != sizeof(stored))) { + /* no file or md5 hash found */ + puts("Login succeeded\n\n"); + return 1; + } + + for (tries = 1; ; tries++) { + puts("\nEnter password: "); + + buf[0] = 0; + for (i=0; i 0) { + puts("\n"); + md5((unsigned char*) buf, strlen(buf), (unsigned char *)entered); + if (memcmp(stored, entered, 16) == 0) { + break; + } else { + puts("Login incorrect\n"); + if (tries == 3) { + return 0; + } + } + } + } + + /* succeeded */ + puts("Login succeeded\n\n"); + return 1; +} + +#endif /* CONIFG_NM_LOGIN */ + +/****************************************************************************/ + static void run_preboot_environment_command(void) { #ifdef CONFIG_PREBOOT @@ -65,6 +145,13 @@ void main_loop(void) autoboot_command(s); +#ifdef CONFIG_NM_LOGIN + if (!login()) { + puts ("Login failed, resetting...\n"); + do_reset (NULL, 0, 0, NULL); + } +#endif + cli_loop(); panic("No CLI available"); } diff --git a/configs/am335x_nbhw16_defconfig b/configs/am335x_nbhw16_defconfig index 59210f3534..008783e566 100644 --- a/configs/am335x_nbhw16_defconfig +++ b/configs/am335x_nbhw16_defconfig @@ -7,9 +7,8 @@ CONFIG_FIT=y CONFIG_SYS_EXTRA_OPTIONS="EMMC_BOOT" CONFIG_HUSH_PARSER=y CONFIG_AUTOBOOT_KEYED=y -CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n" -CONFIG_AUTOBOOT_DELAY_STR="d" -CONFIG_AUTOBOOT_STOP_STR=" " +CONFIG_AUTOBOOT_PROMPT="Press s to abort autoboot in %d seconds\n" +CONFIG_AUTOBOOT_STOP_STR="s" CONFIG_CMD_BOOTZ=y # CONFIG_CMD_IMLS is not set CONFIG_CMD_ASKENV=y diff --git a/include/configs/am335x_netbird.h b/include/configs/am335x_netbird.h index 10299b1b3d..ef8a0e98d7 100644 --- a/include/configs/am335x_netbird.h +++ b/include/configs/am335x_netbird.h @@ -28,6 +28,8 @@ # define CONFIG_LZO #endif +#define CONFIG_NM_LOGIN + #define CONFIG_SYS_BOOTM_LEN (16 << 20) #define MACH_TYPE_TIAM335EVM 3589 /* Until the next sync */