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 boot flow … see also Edge2 boot sequence

MCU ⇒ BROM ⇒ SPLU-BootOS target

Next information actual for MCU ver: 0x0002

Hardware buttons

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

More detail: hardware-buttons

MCU features

Boot mode

Common boot mode configuration 0x20

boot mode value
spi 0
mmc 1
boot-mode read
i2cget -f -y 2 0x18 0x20

Boot flag

This flag 0x92 will be used one time on next reboot! and not change common boot-mode

boot flag value
disabled 0
OOWOW request 1
boot from SPI 2
boot from eMMC 3
boot-flag read
i2cget -f -y 2 0x18 0x92

boot-flag will be used only one time and after reboot will be masked by ^ 0x50 on SPL stage

boot flag note mask
spl mask 0x50
oowow mask 0xA0

boot-flag value > 10 will be reset to 0 on reboot SPL stage

Reboot mode

We can reboot device by non standard way via MCU 0x91 register with special options.

reboot mode value
SPI 0
normal reboot 1
eMMC 2
reboot-mode read
i2cset -f -y  2 0x18 0x91 value

Device will be rebooted immediately after successful writing to 0x91 MCU register

Only normal reboot == 1 dos not change boot-flag on next reboot!
SPI == 0 will change boot-flag to 2 on next reboot
eMMC == 2 will change boot-flag to 3 on next reboot

See too: mcu-registers-annotation

Boot modes oowow shell usage

WIP:

Boot mode setup examples

## read current boot-mode
 
~# bootmode
spi
 
## setup to MMC
 
~# bootmode mmc
[i] /opt/bootmode spi -> mmc(sd)
 
~# bootmode
mmc
 
## setup to SPI
 
~# 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 examples

Forced hardware reboot

## oowow shell
~# mcu_reboot
 
## common system
~# i2cset -f -y 2 0x18 0x91 1

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

reset and use u-boot from spi flash
i2cset -f -y 2 0x18 0x91 0

In this case U-boot will be started from SPI flash, next booting will in same u-boot prio USB SD eMMC and Rescue OOWOW mode will be last! If u need start oowow please use reboot-into-oowow-via-i2c-command

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: WIP:

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

Advanced

MCU registers annotation

MCU version: 02 & 03

0x91 REBOOT_MODE
    0 - reset and boot from SPI
    1 - reset normal
    2 - reset and boot from eMMC

0x92 BOOT_FLAG
    0 - normal
    1 - press FUNC boot-up
    2 - reset from SPI boot-up
    3 - reset from eMMC boot-up

See too: mcu-features

U-boot spl

WIP:

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_BOOT_FLAG        0x92
#define MCU_I2C_REG_RESET_MODE       0x91
#define MCU_I2C_REG_BOOT_FLAG_NORMAL 0x00
#define MCU_I2C_REG_BOOT_FLAG_FUNC   0x01
#define MCU_I2C_REG_BOOT_FLAG_OOWOW  0x01
#define MCU_I2C_REG_BOOT_FLAG_SPI    0x02
#define MCU_I2C_REG_BOOT_FLAG_EMMC   0x03
#define MCU_I2C_REG_BOOT_FLAG_RESCUE 0x05
#define MCU_I2C_REG_BOOT_FLAG_PASS   0x50
 
#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_boot_flag;
	uchar mcu_led_normal = 8; /* white breath */
	uchar mcu_led_reset  = 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_BOOT_FLAG, &mcu_boot_flag, 1);
	printf("MCU: boot mode 0x20: %d, flag 0x92: %d\n",
                          mcu_boot_mode, mcu_boot_flag);
	// reset boot flag
	if ( mcu_boot_flag != 0 ) {
		mcu_boot_flag = mcu_boot_flag > 10 ? 0 : mcu_boot_flag ^ MCU_I2C_REG_BOOT_FLAG_PASS;
		dm_i2c_write(dev, MCU_I2C_REG_BOOT_FLAG, &mcu_boot_flag, 1);
		printf("MCU: boot flag < %d\n", mcu_boot_flag);
		if ( mcu_boot_flag != 0 )
		    dm_i2c_write(dev, MCU_I2C_REG_LED, &mcu_led_reset, 1);
	} else {
		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) {
 
			// /mmc@fe2c0000 - SD
			// /mmc@fe2e0000 - EMMC
 
			mcu_boot_flag &= 0x0F; // restore original flag
			if (mcu_boot_flag == 1 || mcu_boot_flag == 2 || mcu_boot_flag == 5)
			    conf = "/spi@fe2b0000/flash@1";
			else if (mcu_boot_flag == 3)
			    conf = "/mmc@fe2e0000";
			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

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

Uboot

uboot-info
Info: UBOOT_COMPRESSION: lzma
FIT description: FIT Image with ATF/OP-TEE/U-Boot/MCU
Created:         Mon Jul 17 14:59:34 2023
 Image 0 (uboot)
  Description:  U-Boot
  Created:      Mon Jul 17 14:59:34 2023
  Type:         Standalone Program
  Compression:  lzma compressed
  Data Size:    430151 Bytes = 420.07 KiB = 0.41 MiB
  Architecture: AArch64
  Load Address: 0x00200000
  Entry Point:  unavailable
  Hash algo:    sha256
  Hash value:   72065bbc30ae3f4bcd548f6ff2a7b9dd1a629f09a2b192ee530eab82ec6d1b32
 Image 1 (atf-1)
  Description:  ARM Trusted Firmware
  Created:      Mon Jul 17 14:59:34 2023
  Type:         Firmware
  Compression:  lzma compressed
  Data Size:    47147 Bytes = 46.04 KiB = 0.04 MiB
  Architecture: AArch64
  Load Address: 0x00040000
  Hash algo:    sha256
  Hash value:   65a97025c2150f2ed0fb746a438612a3f1521d8305e14ccd5807bd58b2e7fe9c
 Image 2 (atf-2)
  Description:  ARM Trusted Firmware
  Created:      Mon Jul 17 14:59:34 2023
  Type:         Firmware
  Compression:  uncompressed
  Data Size:    28672 Bytes = 28.00 KiB = 0.03 MiB
  Architecture: AArch64
  Load Address: 0x000f0000
  Hash algo:    sha256
  Hash value:   6a00298af819b30f482d5ba9e53d6fa6bb2719007f69ff985e23e06d4f9d439f
 Image 3 (atf-3)
  Description:  ARM Trusted Firmware
  Created:      Mon Jul 17 14:59:34 2023
  Type:         Firmware
  Compression:  uncompressed
  Data Size:    20480 Bytes = 20.00 KiB = 0.02 MiB
  Architecture: AArch64
  Load Address: 0xff100000
  Hash algo:    sha256
  Hash value:   33280a39887591959dcb20ad42140a5eeed61fde49b7a38cc44172cd8f1a9dc7
 Image 4 (atf-4)
  Description:  ARM Trusted Firmware
  Created:      Mon Jul 17 14:59:34 2023
  Type:         Firmware
  Compression:  uncompressed
  Data Size:    8192 Bytes = 8.00 KiB = 0.01 MiB
  Architecture: AArch64
  Load Address: 0xff001000
  Hash algo:    sha256
  Hash value:   2301cf73be91bb638ecd9c296d6674b9d52696a3825745070c92e21e79c8be24
 Image 5 (optee)
  Description:  OP-TEE
  Created:      Mon Jul 17 14:59:34 2023
  Type:         Firmware
  Compression:  lzma compressed
  Data Size:    177774 Bytes = 173.61 KiB = 0.17 MiB
  Architecture: AArch64
  Load Address: 0x08400000
  Hash algo:    sha256
  Hash value:   1fcfe45105750e2fcd47a14b54c80d66a8b2f7ad3a166b699d2bb5b0e2a3ed69
 Image 6 (fdt)
  Description:  U-Boot dtb
  Created:      Mon Jul 17 14:59:34 2023
  Type:         Flat Device Tree
  Compression:  uncompressed
  Data Size:    8262 Bytes = 8.07 KiB = 0.01 MiB
  Architecture: AArch64
  Hash algo:    sha256
  Hash value:   5648101b8ee7ec2a390f0a072eb27f47724d40e2f76d8dc2be624e6114b84d67
 Default Configuration: 'conf'
 Configuration 0 (conf)
  Description:  rk3588s-khadas-edge2
  Kernel:       unavailable
  Firmware:     atf-1
  FDT:          fdt
  Loadables:    uboot
                atf-2
                atf-3
                atf-4
                optee
-rw-rw-r-- 1 master master 725504 Jul 17 14:59 u-boot-cmp.itb
Info: pack uboot.img okay!
Info: Generating uboot-sd.img ... 0x4000 == 16384 > u-boot.itb
Last modified: 2023/07/17 03:04 by hyphop