nrhw20: support for nrsw failsave boot of u-boot

This commit is contained in:
Marcel Reichmuth 2018-05-29 16:02:04 +02:00
parent e21b076da4
commit 392db0a2f8
7 changed files with 133 additions and 8 deletions

87
common/main.c Normal file → Executable file
View File

@ -13,6 +13,9 @@
#include <console.h>
#include <version.h>
#include <fs.h>
#include <u-boot/md5.h>
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<PASS_LEN; i++) {
buf[i] = getc();
if (buf[i] == '\r' || buf[i] == '\n') {
buf[i] = 0;
break;
}
}
buf[PASS_LEN-1] = 0;
if (strlen(buf) > 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");
}

4
common/spl/spl.c Normal file → Executable file
View File

@ -18,6 +18,7 @@
#include <malloc.h>
#include <dm/root.h>
#include <linux/compiler.h>
#include <spl_version_autogenerated.h>
DECLARE_GLOBAL_DATA_PTR;
@ -453,7 +454,8 @@ void preloader_console_init(void)
gd->have_console = 1;
puts("\nU-Boot SPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
puts("\n" SPL_VERSION "\n");
puts("U-Boot SPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
U_BOOT_TIME ")\n");
#ifdef CONFIG_SPL_DISPLAY_PRINT
spl_display_print();

31
common/spl/spl_mmc.c Normal file → Executable file
View File

@ -24,11 +24,18 @@ static int mmc_load_legacy(struct mmc *mmc, ulong sector,
u32 image_size_sectors;
unsigned long count;
int ret;
int nm_additional_header_bytes;
int nm_additional_trailer_bytes;
ret = spl_parse_image_header(header);
if (ret)
return ret;
nm_additional_header_bytes = sizeof(struct nm_header) - sizeof(struct image_header);
nm_additional_trailer_bytes = sizeof(__be32);
spl_image.load_addr -= nm_additional_header_bytes;
spl_image.size += nm_additional_header_bytes + nm_additional_trailer_bytes;
/* convert size to sectors - round up */
image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) /
mmc->read_bl_len;
@ -54,21 +61,32 @@ static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
{
const unsigned int START_MAGIC = 0x424c5354;
const unsigned int END_MAGIC = 0x424c454e;
unsigned long count;
struct nm_header *nm_header;
struct image_header *header;
int ret = 0;
__be32* end_tag_position;
header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
sizeof(struct image_header));
nm_header = (struct nm_header *)(CONFIG_SYS_TEXT_BASE -
sizeof(struct nm_header));
/* read image header to find the image size & load address */
count = blk_dread(mmc_get_blk_desc(mmc), sector, 1, header);
count = blk_dread(mmc_get_blk_desc(mmc), sector, 1, nm_header);
debug("hdr read sector %lx, count=%lu\n", sector, count);
if (count == 0) {
ret = -EIO;
goto end;
}
if (be32_to_cpu(nm_header->nm_start_tag) != START_MAGIC) return -1;
if (be32_to_cpu(nm_header->nm_length)>10000000) return -1;
end_tag_position = (__be32*)(((void*)nm_header) + sizeof(struct nm_header) - sizeof(struct image_header) + (be32_to_cpu(nm_header->nm_length)));
header = &(nm_header->header);
if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
image_get_magic(header) == FDT_MAGIC) {
struct spl_load_info load;
@ -84,6 +102,8 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
ret = mmc_load_legacy(mmc, sector, header);
}
if (be32_to_cpu(*end_tag_position) != END_MAGIC) return -1;
end:
if (ret) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
@ -92,6 +112,8 @@ end:
return -1;
}
printf("Found valid u-boot image at sector %ld\n", sector);
return 0;
}
@ -324,6 +346,9 @@ int spl_mmc_load_image(u32 boot_device)
#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR)
err = mmc_load_image_raw_sector(mmc,
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
if (err)
err = mmc_load_image_raw_sector(mmc,
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR_ALTERNATE);
if (!err)
return err;
#endif

4
include/configs/am335x_nrhw20.h Normal file → Executable file
View File

@ -52,7 +52,7 @@
#define LOAD_ADDR "0x83000000"
#define FDT_ADDR "0x82000000"
#define PXE_ADDR "0x82800000"
#define FDT_HIGH_ADDR "0x87000000"
#define FDT_HIGH_ADDR "0x9f000000"
#define INIT_RD_ADDR "0x88000000"
#define CONFIG_EXTRA_ENV_SETTINGS \
@ -64,7 +64,7 @@
"load_addr=" LOAD_ADDR "\0" \
"root_part=1\0" /* Default root partition, overwritten in board file */ \
"defaultconsole=ttyS1\0" /* Default output console */ \
"add_sd_bootargs=setenv bootargs $bootargs root=/dev/mmcblk1p$root_part rootfstype=ext4 " \
"add_sd_bootargs=setenv bootargs $bootargs root=/dev/mmcblk0p$root_part rootfstype=ext4 " \
"console=$defaultconsole,115200 rootwait loglevel=4 ti_cpsw.rx_packet_max=1526\0" \
"add_version_bootargs=setenv bootargs $bootargs\0" \
"fdt_skip_update=yes\0" \

1
include/configs/ti_armv7_common.h Normal file → Executable file
View File

@ -220,6 +220,7 @@
/* RAW SD card / eMMC locations. */
#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR 0x300 /* address 0x60000 */
#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR_ALTERNATE 0x1b00 /* address 0x360000 */
#define CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS 0x200 /* 256 KB */
/* FAT sd card locations. */

8
include/image.h Normal file → Executable file
View File

@ -286,6 +286,14 @@ typedef struct image_header {
uint8_t ih_name[IH_NMLEN]; /* Image Name */
} image_header_t;
typedef struct nm_header {
__be32 nm_start_tag; /* BLST (0x424c5354) */
__be32 nm_version; /* U-boot version number */
__be32 nm_length; /* U-boot image length */
uint8_t reserved[244]; /* Reserved */
struct image_header header;
} nm_header_t;
typedef struct image_info {
ulong start, end; /* start/end of blob */
ulong image_start, image_len; /* start of image within blob, len of image */

6
lib/display_options.c Normal file → Executable file
View File

@ -12,13 +12,15 @@
#include <version.h>
#include <linux/ctype.h>
#include <asm/io.h>
#include <version_autogenerated.h>
int display_options (void)
{
printf ("\n\n%s\n", UBOOT_VERSION);
#if defined(BUILD_TAG)
printf ("\n\n%s, Build: %s\n\n", version_string, BUILD_TAG);
printf ("%s, Build: %s\n\n", version_string, BUILD_TAG);
#else
printf ("\n\n%s\n\n", version_string);
printf ("%s\n\n", version_string);
#endif
return 0;
}