From aa21f3b6bceeb8c45bbec3e3ddf0356556c4bdc2 Mon Sep 17 00:00:00 2001
From: Patrick Yavitz <pyavitz@gmail.com>
Date: Thu, 10 Oct 2024 10:21:06 -0400
Subject: [PATCH] Add syslinux and script support

This file is deleted by the builder before the patch is applied

Signed-off-by: Patrick Yavitz <pyavitz@gmail.com>
---
 board/spacemit/k1-x/k1-x.env | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 board/spacemit/k1-x/k1-x.env

diff --git a/board/spacemit/k1-x/k1-x.env b/board/spacemit/k1-x/k1-x.env
new file mode 100644
index 00000000..acb1ef7a
--- /dev/null
+++ b/board/spacemit/k1-x/k1-x.env
@@ -0,0 +1,31 @@
+// Common parameter
+earlycon=sbi
+console=ttyS0,115200
+init=/init
+bootdelay=0
+baudrate=115200
+loglevel=8
+stderr=serial
+stdin=serial,usbkbd
+stdout=serial
+
+// SYSLINUX and SCRIPT Support
+autoboot=if test -e ${devtype} ${devnum}:${distro_bootpart} /extlinux/extlinux.conf; then \
+		sysboot ${devtype} ${devnum}:${distro_bootpart} any 0x2000000 /extlinux/extlinux.conf; \
+	elif test -e ${devtype} ${devnum}:${distro_bootpart} /boot/extlinux/extlinux.conf; then \
+		sysboot ${devtype} ${devnum}:${distro_bootpart} any 0x2000000 /boot/extlinux/extlinux.conf; \
+	elif test -e ${devtype} ${devnum}:${distro_bootpart} /boot.scr; then \
+		load ${devtype} ${devnum}:${distro_bootpart} 0x2000000 /boot.scr; source 0x2000000; \
+	elif test -e ${devtype} ${devnum}:${distro_bootpart} /boot/boot.scr; then \
+		load ${devtype} ${devnum}:${distro_bootpart} 0x2000000 /boot/boot.scr; source 0x2000000; \
+	elif test -e nvme 0:1 /extlinux/extlinux.conf; then \
+		sysboot nvme 0:1 any 0x2000000 /extlinux/extlinux.conf; \
+	elif test -e nvme 0:1 /boot/extlinux/extlinux.conf; then \
+		sysboot nvme 0:1 any 0x2000000 /boot/extlinux/extlinux.conf; \
+	elif test -e nvme 0:1 /boot.scr; then \
+		load nvme 0:1 0x2000000 /boot.scr; source 0x2000000; \
+	elif test -e nvme 0:1 /boot/boot.scr; then \
+		load nvme 0:1 0x2000000 /boot/boot.scr; source 0x2000000; \
+	fi;
+
+bootcmd=echo "Loading ..."; run autoboot
-- 
2.39.5

From 9bb50320cc81251c93a21a94fb73cf0a2feb693e Mon Sep 17 00:00:00 2001
From: Patrick Yavitz <pyavitz@gmail.com>
Date: Mon, 4 Nov 2024 10:09:19 -0500
Subject: [PATCH] Add syslinux and script support

Signed-off-by: Patrick Yavitz <pyavitz@gmail.com>
---
 board/spacemit/k1-x/k1x.c | 20 ++++++++++----------
 configs/k1_defconfig      |  3 +++
 include/configs/k1-x.h    | 23 ++++++++++-------------
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/board/spacemit/k1-x/k1x.c b/board/spacemit/k1-x/k1x.c
index 460eea4f..7f59b332 100644
--- a/board/spacemit/k1-x/k1x.c
+++ b/board/spacemit/k1-x/k1x.c
@@ -458,8 +458,8 @@ void _load_env_from_blk(struct blk_desc *dev_desc, const char *dev_name, int dev
 #endif
 	}
 
-	env_set("bootfs_part", simple_itoa(part));
-	env_set("bootfs_devname", dev_name);
+	env_set("distro_bootpart", simple_itoa(part));
+	env_set("devnum", dev_name);
 
 	/*load env.txt and import to uboot*/
 	memset((void *)CONFIG_SPL_LOAD_FIT_ADDRESS, 0, CONFIG_ENV_SIZE);
@@ -662,7 +662,7 @@ void setenv_boot_mode(void)
 	u32 boot_mode = get_boot_mode();
 	switch (boot_mode) {
 	case BOOT_MODE_NAND:
-		env_set("boot_device", "nand");
+		env_set("devtype", "nand");
 		break;
 	case BOOT_MODE_NOR:
 		char *blk_name;
@@ -673,23 +673,23 @@ void setenv_boot_mode(void)
 			return;
 		}
 
-		env_set("boot_device", "nor");
-		env_set("boot_devnum", simple_itoa(blk_index));
+		env_set("devtype", "nor");
+		env_set("devnum", simple_itoa(blk_index));
 		break;
 	case BOOT_MODE_EMMC:
-		env_set("boot_device", "mmc");
-		env_set("boot_devnum", simple_itoa(MMC_DEV_EMMC));
+		env_set("devtype", "mmc");
+		env_set("devnum", simple_itoa(MMC_DEV_EMMC));
 		break;
 	case BOOT_MODE_SD:
-		env_set("boot_device", "mmc");
-		env_set("boot_devnum", simple_itoa(MMC_DEV_SD));
+		env_set("devtype", "mmc");
+		env_set("devnum", simple_itoa(MMC_DEV_SD));
 		break;
 	case BOOT_MODE_USB:
 		// for fastboot image download and run test
 		env_set("bootcmd", CONFIG_BOOTCOMMAND);
 		break;
 	default:
-		env_set("boot_device", "");
+		env_set("devtype", "");
 		break;
 	}
 }
diff --git a/configs/k1_defconfig b/configs/k1_defconfig
index 8db91b1e..63ac72b5 100644
--- a/configs/k1_defconfig
+++ b/configs/k1_defconfig
@@ -43,6 +43,8 @@ CONFIG_AUTOBOOT_STOP_STR=" "
 CONFIG_AUTOBOOT_KEYED_CTRLC=y
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="bootm 0x11000000"
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="usb start; nvme scan; nvme part"
 CONFIG_LOGLEVEL=7
 CONFIG_SPL_LOGLEVEL=1
 # CONFIG_SYS_DEVICE_NULLDEV is not set
@@ -288,3 +290,4 @@ CONFIG_PRINT_TIMESTAMP=y
 # CONFIG_SPL_SHA256 is not set
 CONFIG_ZSTD=y
 # CONFIG_HEXDUMP is not set
+CONFIG_OF_LIBFDT_OVERLAY=y
diff --git a/include/configs/k1-x.h b/include/configs/k1-x.h
index 8d27fe9d..c7f42bbc 100644
--- a/include/configs/k1-x.h
+++ b/include/configs/k1-x.h
@@ -84,11 +84,6 @@
 #define TLV_CODE_EEPROM_I2C_INDEX	0x81
 #define TLV_CODE_EEPROM_PIN_GROUP	0x82
 
-// #define RAMDISK_LOAD_ADDR		(CONFIG_FASTBOOT_BUF_ADDR + CONFIG_FASTBOOT_BUF_SIZE)
-// #define DTB_LOAD_ADDR		(CONFIG_FASTBOOT_BUF_ADDR + CONFIG_FASTBOOT_BUF_SIZE * 2)
-#define RAMDISK_LOAD_ADDR		0x21000000
-#define DTB_LOAD_ADDR			0x31000000
-
 // for those has NOT been through test procedure(ATE)
 #define SVT_DRO_DEFAULT_VALUE	(120)
 
@@ -142,6 +137,11 @@ struct boot_storage_op
 #define BOOT_TARGET_DEVICES(func) \
 	func(QEMU, qemu, na)
 
+#define KERNEL_ADDR_R		__stringify(0x10000000)
+#define RAMDISK_ADDR_R		__stringify(0x21000000)
+#define FDT_ADDR_R		__stringify(0x31000000)
+#define FDTOVERLAY_ADDR_R	__stringify(0x01000000)
+
 #include <config_distro_bootcmd.h>
 
 #define BOOTENV_DEV_QEMU(devtypeu, devtypel, instance) \
@@ -167,16 +167,13 @@ struct boot_storage_op
 /*if env not use for spl, please define to board/spacemit/k1-x/k1-x.env */
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	"stdout_flash=serial,vidconsole\0" \
-	"kernel_comp_addr_r=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
-	"kernel_comp_size=" __stringify(CONFIG_FASTBOOT_BUF_SIZE) "\0" \
-	"kernel_addr_r=" __stringify(CONFIG_FASTBOOT_BUF_ADDR) "\0" \
-	"ramdisk_addr=" __stringify(RAMDISK_LOAD_ADDR) "\0" \
-	"dtb_addr=" __stringify(DTB_LOAD_ADDR) "\0" \
 	"scriptaddr=0x2c100000\0" \
 	"pxefile_addr_r=0x0c200000\0" \
-	"splashimage=" __stringify(CONFIG_FASTBOOT_BUF_ADDR) "\0" \
-	"splashpos=m,m\0" \
-	"splashfile=bianbu.bmp\0" \
+	"fdt_addr_r=" FDT_ADDR_R "\0" \
+	"kernel_addr_r=" KERNEL_ADDR_R "\0" \
+	"ramdisk_addr_r=" RAMDISK_ADDR_R "\0" \
+	"fdtoverlay_addr_r=" FDTOVERLAY_ADDR_R "\0" \
+	"fdtfile=spacemit/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
 	BOOTENV_DEVICE_CONFIG
 
 
-- 
2.39.5