Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:edge2:hardware:edge2-boot-flow

This is an old revision of the document!


Edge2 Boot flow

Edge2 have advanced and flexible booting sequence… WIP:

MCU ⇒ BROM ⇒ SPLU-BootOS target

Next information actual for MCU ver: 0x0002

Hardware buttons

WIP:

  • FUNCTION + RESET - oowow mode
  • POWER + RESET - force boot from SD/eMMC.
  • FUNCTION x3 times - flash mode

More detail: hardware-buttons

Bootmode

i2cget -f -y 2 0x18 0x20

bootmode value
spi 0
mmc 1

OOWOW mode

i2cget -f -y 2 0x18 0x92

oowow_mode value
disabled 0
request 1
activated 2
passed 3
rescue 5

Reboot modes by MCU

i2cset -f -y 2 0x18 0x91 value

oowow_mode value
spi 0
mmc 1
default reboot 2

At this moment all modes works same as spi

Boot modes oowow shell usage

WIP:

Set boot mode

~# bootmode
spi
 
~# bootmode mmc
[i] /opt/bootmode spi -> mmc(sd)
 
~# bootmode
mmc
 
~# bootmode spi
[i] /opt/bootmode mmc -> spi

Set oowow mode

~# mcu_oowow_mode set 1
[i] set with 1
 
~# mcu_oowow_mode clean
[i] set with 0
 
~# mcu_oowow_mode && echo activated
0x01
activated
 
~# mcu_oowow_mode clean
[i] set with 0
 
~# mcu_oowow_mode || echo disabled
disabled
 
~# i2cset -f -y 2 0x18 0x92 1
 
~# i2cget -f -y 2 0x18 0x92
0x01

Reboot by MCU

Forced hardware reboot

~# mcu_reboot
 
~# i2cset -f -y 2 0x18 0x91 2

Reboot into OOWOW via i2c command

reboot into oowow
i2cset -f -y 2 0x18 0x92 1
i2cset -f -y 2 0x18 0x91 1

Reboot from SPI flash U-Boot via i2c command

WIP: not works as need

reboot into oowow
i2cset -f -y 2 0x18 0x92 0
i2cset -f -y 2 0x18 0x91 0

SPL stage

SPL boot loader priority: spiemmcsd - hard-coded by MCU and BROM

SPL boot loader priority not same as mcu bootmode. MCU boot mode works only after SPL boot stage passed.

Boot mode mmc logs:

u-boot-spl-mmc.log
U-Boot SPL board init
U-Boot SPL 2017.09 (Sep 15 2022 - 14:38:28)
MCU: bootmode: 1, oowow 3
MCU: oowow 0
board_boot_order: /chosen found, using spl_boot_device()
!!! same-as-spl: 
!!! /mmc@fe2c0000: 
!!! /mmc@fe2e0000: 
!!! /spi@fe2b0000/flash@1: 
Trying to boot from MMC2 :: 0
Card did not respond to voltage select!
mmc_init: -95, time 12
spl: mmc init failed with error: -95
Trying to boot from MMC1 :: 1
Trying fit image at 0x4000 sector

Boot mode spi logs

u-boot-spl-spi.log
U-Boot SPL board init
U-Boot SPL 2017.09 (Sep 15 2022 - 14:38:28)
MCU: bootmode: 0, oowow 3
MCU: oowow 0
board_boot_order: /chosen found, using spl_boot_device()
!!! same-as-spl: 
board_spl_was_booted_from: brom_bootdevice_id 6 maps to '/spi@fe2b0000/flash@1'
+++ /spi@fe2b0000/flash@1: 
!!! /mmc@fe2c0000: 
!!! /mmc@fe2e0000: 
!!! /spi@fe2b0000/flash@1: 
Trying to boot from MTD2 :: 0
Trying fit image at 0x300 sector

Boot OOWOW - hold FUNCTION and short press RESET then release FUNCTION

u-boot-spl-oowow-mode.log
U-Boot SPL board init
U-Boot SPL 2017.09 (Sep 15 2022 - 14:38:28)
MCU: bootmode: 0, oowow 1
MCU: oowow 2
board_boot_order: /chosen found, using spl_boot_device()
!!! same-as-spl: 
+++ /spi@fe2b0000/flash@1: 
!!! /mmc@fe2c0000: 
!!! /mmc@fe2e0000: 
!!! /spi@fe2b0000/flash@1: 
Trying to boot from MTD2 :: 0
Trying fit image at 0x300 sector

Boot SPL from eMMC:

u-boot-spl-mmc.log
U-Boot SPL board init
U-Boot SPL 2017.09 (Oct 18 2022 - 20:45:10)
Trying to boot from MMC2
Card did not respond to voltage select!
mmc_init: -95, time 12
spl: mmc init failed with error: -95
Trying to boot from MMC1
spl: partition error
Trying fit image at 0x4000 sector

Boot SPL from eMMC boot oowow u-boot from SD:

u-boot-spl-mmc-sd-oowow.log
U-Boot SPL board init
U-Boot SPL 2017.09 (Oct 18 2022 - 20:45:10)
Trying to boot from MMC2
part_get_info_efi: *** ERROR: Invalid GPT ***
...
spl: partition error
Trying fit image at 0x4000 sector

SPI and eMMC boot loaders cleared. Boot SPL and oowow u-boot from SD

u-boot-spl-sd-oowow.log
U-Boot SPL board init
U-Boot SPL 2017.09 (Jul 25 2022 - 10:32:06)
MCU: bootmode: 1, oowow 3
MCU: oowow 0
board_boot_order: /chosen found, using spl_boot_device()
!!! same-as-spl: 
!!! /mmc@fe2c0000: 
!!! /mmc@fe2e0000: 
!!! /spi@fe2b0000/flash@1: 
Trying to boot from MMC2 :: 0
Trying fit image at 0x4000 sector

Boot SPL android u-boot from eMMC:

u-boot-spl-mmc-android.log
U-Boot SPL board init
U-Boot SPL 2017.09-gc060f28d70-220414 #zyf (Apr 18 2022 - 18:13:34)
Failed to set cpub01
Failed to set cpub23
Trying to boot from MMC2
MMC: no card present
mmc_init: -123, time 0
spl: mmc init failed with error: -123
Trying to boot from MMC1
Trying fit image at 0x4000 sector

U-Boot stage

Current u-boot can start OS from USBSDeMMC ⇒ …

oowow spi uboot

boot_targets
kedge2# printenv boot_targets 
boot_targets=usb0 mmc1 mmc0 pxe dhcp fail

mmc uboot

default eMMC u-boot log for Ubuntu images

boot_targets
kedge2# printenv boot_targets 
boot_targets=usb0 mmc1 mmc0 pxe dhcp

SPI Flash partitions table

MTD parts
0x000000000000-0x000000080000 : "bootloader" # 0x03f800 bytes x 2 > 0x000000 0x040000 < 0
0x000000080000-0x0000000a6000 : "bl2e"       # 0x013000 bytes x 2 > 0x080000 0x093000 < 0x00040000
0x0000000a6000-0x0000000c8000 : "bl2x"       # 0x011000 bytes x 2 > 0x0a6000 0x0b7000 < 0x00053000
0x0000000c8000-0x000000148000 : "ddrfip"     # 0x040000 bytes x 2 > 0x0c8000 0x108000 < 0x00064000
0x000000148000-0x000000448000 : "devfip"     # 0x275000 bytes     > 0x148000          < 0x000a4000
0x000000448000-0x000000488000 : "env"        # zero
0x000000488000-0x0000004c8000 : "dtb"        # zero
0x0000004c8000-0x0000006c8000 : "boot"       # zero
0x0000006c8000-0x000002000000 : "user"       # zero

Advanced

MCU registers annotation

MCU version: 02 & 03

0x91 
    0 - reset and boot from spi
    2 - reset and boot from emmc
    1 - reset

0x92 BOOT_FLAG (oowow will check this register about boot mode)
    0 - normal
    1 - press FUNC bootup
    2 - reset from spi bootup
    3 - reset from emmc bootup

U-boot spl

u-boot/arch/arm/mach-rockchip/spl-boot-order.c
/* khadas mcu part begin */
#define MCU_I2C_BUS_NUM         2
#define MCU_I2C_CHIP_ADDR       0x18
#define MCU_I2C_REG_BOOT_MODE   0x20
#define MCU_I2C_REG_BOOT_MODE_SPI   0x00
#define MCU_I2C_REG_BOOT_MODE_MMC   0x01
#define MCU_I2C_REG_OOWOW_MODE  0x92
#define MCU_I2C_REG_OOWOW_MODE_NONE    0x00
#define MCU_I2C_REG_OOWOW_MODE_ACTIVE  0x01
#define MCU_I2C_REG_OOWOW_MODE_PASS    0x02
#define MCU_I2C_REG_LED  0x89
/* khadas mcu part end */
 
void board_boot_order(u32 *spl_boot_list)
{
	const void *blob = gd->fdt_blob;
	int chosen_node = fdt_path_offset(blob, "/chosen");
	int idx = 0;
	int elem;
	int boot_device;
	int node;
	const char *conf;
 
/* khadas mcu part begin */
	uchar mcu_boot_mode;
	uchar mcu_oowow_mode;
	uchar mcu_led_normal = 8; /* white breath */
	uchar mcu_led_oowow  = 1; /* white solid */
	int ret;
	struct udevice *bus;
	struct udevice *dev;
 
	ret = uclass_first_device(UCLASS_I2C, &bus);
	if (ret) goto mcu_skip;
	ret = i2c_get_chip(bus, MCU_I2C_CHIP_ADDR, 1, &dev);
	if (ret) goto mcu_skip;
	ret = dm_i2c_read(dev, MCU_I2C_REG_BOOT_MODE, &mcu_boot_mode, 1);
	ret = dm_i2c_read(dev, MCU_I2C_REG_OOWOW_MODE, &mcu_oowow_mode, 1);
	printf("MCU: bootmode: %d, oowow %d\n", mcu_boot_mode, mcu_oowow_mode);
	// reset oowow mode
	if ( mcu_oowow_mode != 0 ) {
		mcu_oowow_mode = mcu_oowow_mode == 1 ? 2 : 0;
		ret = dm_i2c_write(dev, MCU_I2C_REG_OOWOW_MODE, &mcu_oowow_mode, 1);
		printf("MCU: oowow %d\n", mcu_oowow_mode);
		ret = dm_i2c_write(dev, MCU_I2C_REG_LED, &mcu_led_oowow, 1);
	} else {
		ret = dm_i2c_write(dev, MCU_I2C_REG_LED, &mcu_led_normal, 1);
	}
mcu_skip:
/* khadas mcu part end */
 
	if (chosen_node < 0) {
		debug("%s: /chosen not found, using spl_boot_device()\n",
		      __func__);
		spl_boot_list[0] = spl_boot_device();
		return;
	}
 
	printf("%s: /chosen found, using spl_boot_device()\n", __func__);
 
	for (elem = 0;
	     (conf = fdt_stringlist_get(blob, chosen_node,
					"u-boot,spl-boot-order", elem, NULL));
	     elem++) {
		const char *alias;
 
		printf("!!! %s: \n", conf);
 
		/* Handle the case of 'same device the SPL was loaded from' */
		if (strncmp(conf, "same-as-spl", 11) == 0) {
			if (mcu_oowow_mode)
			    conf = "/spi@fe2b0000/flash@1";
			else if (mcu_boot_mode == MCU_I2C_REG_BOOT_MODE_MMC)
			    continue;
			else
			    conf = board_spl_was_booted_from();
 
			printf("+++ %s: \n", conf);
			if (!conf)
				continue;
		}
 
		/* First check if the list element is an alias */
		alias = fdt_get_alias(blob, conf);
		if (alias)
			conf = alias;
 
		/* Try to resolve the config item (or alias) as a path */
		node = fdt_path_offset(blob, conf);
		if (node < 0) {
			debug("%s: could not find %s in FDT", __func__, conf);
			continue;
		}
 
		/* Try to map this back onto SPL boot devices */
		boot_device = spl_node_to_boot_device(node);
		if (boot_device < 0) {
			debug("%s: could not map node @%x to a boot-device\n",
			      __func__, node);
			continue;
		}
 
		spl_boot_list[idx++] = boot_device;
	}
 
	/* If we had no matches, fall back to spl_boot_device */
	if (idx == 0)
		spl_boot_list[0] = spl_boot_device();
}
#endif
Last modified: 2023/05/15 21:48 by hyphop