summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoy Cho <joy.cho@hardkernel.com>2017-09-29 05:11:21 +0300
committerJoy Cho <joy.cho@hardkernel.com>2017-12-28 04:11:41 +0300
commitd36d5ec783b0f735e308a73aa72af1dddb675583 (patch)
treef48e785f852a1fb7b396ce5c4dbbef8a2aebe5c5
parent56b7ab5076c1f8d3696da6f16e04d83d8f8d2f18 (diff)
downloadu-boot-d36d5ec783b0f735e308a73aa72af1dddb675583.tar.xz
cmd: Introduce cfgload command to load boot.ini
Change-Id: I3c41b9678493135c45d69fa681ddf6a4ac8a59ef
-rw-r--r--cmd/Kconfig10
-rw-r--r--cmd/Makefile2
-rw-r--r--cmd/cfgload.c136
-rw-r--r--configs/odroidn1_defconfig5
4 files changed, 153 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index c80ac364ea..8364917bc6 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1275,4 +1275,14 @@ config CMD_UBIFS
help
UBIFS is a file system for flash devices which works on top of UBI.
+menu "ODROID commands"
+
+config CMD_ODROID_CFGLOAD
+ bool "cfgload command - load boot.ini from FAT partition"
+ depends on TARGET_ODROIDN1
+ help
+ cfgload support
+
+endmenu
+
endmenu
diff --git a/cmd/Makefile b/cmd/Makefile
index bd231f24d8..7ff80b2eb9 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -147,6 +147,8 @@ obj-$(CONFIG_CMD_PMIC) += pmic.o
obj-$(CONFIG_CMD_REGULATOR) += regulator.o
obj-$(CONFIG_CMD_BLOB) += blob.o
+
+obj-$(CONFIG_CMD_ODROID_CFGLOAD) += cfgload.o
endif # !CONFIG_SPL_BUILD
# core command
diff --git a/cmd/cfgload.c b/cmd/cfgload.c
new file mode 100644
index 0000000000..caaf5b7bb2
--- /dev/null
+++ b/cmd/cfgload.c
@@ -0,0 +1,136 @@
+/*
+ * ODROID cfgload command to load boot.ini from FAT partiton
+ *
+ * Copyright (C) 2015 Hardkernel Co,. Ltd
+ * Dongjin Kim <tobetter@gmail.com>
+ *
+ * This driver has been modified to support ODROID-N1.
+ * Modified by Joy Cho <joycho78@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <linux/errno.h>
+#include <malloc.h>
+#include <linux/ctype.h> /* isalpha, isdigit */
+#include <linux/sizes.h>
+
+#ifdef CONFIG_HUSH_PARSER
+#include <cli_hush.h>
+#endif
+
+#define BOOTINI_MAGIC "ODROIDN1-UBOOT-CONFIG"
+#define SZ_BOOTINI SZ_64K
+
+/* Nothing to proceed with zero size string or comment.
+ *
+ * FIXME: Do we really need to strip the line start with '#' or ';',
+ * since any U-boot command does not start with punctuation character.
+ */
+static int valid_command(const char* p)
+{
+ char *q;
+
+ for (q = (char*)p; *q; q++) {
+ if (isblank(*q)) continue;
+ if (isalnum(*q)) return 1;
+ if (ispunct(*q))
+ return (*q != '#') && (*q != ';');
+ }
+
+ return !(p == q);
+}
+
+/* Read boot.ini from FAT partition
+ */
+static char* read_cfgload(void)
+{
+ char cmd[128];
+ unsigned long filesize;
+ char *p;
+ char *tmp;
+
+ tmp = getenv("loadaddr");
+ if (NULL == tmp)
+ p = (char *)CONFIG_SYS_LOAD_ADDR;
+ else
+ p = (char *)simple_strtoul(tmp, NULL, 16);
+
+ setenv("filesize", "0");
+
+ sprintf(cmd, "fatload mmc 0:1 0x%p boot.ini", (void *)p);
+ run_command(cmd, 0);
+
+ filesize = getenv_ulong("filesize", 16, 0);
+ if (0 == filesize) {
+ printf("cfgload: no boot.ini or empty file\n");
+ return NULL;
+ }
+
+ if (filesize > SZ_BOOTINI) {
+ printf("boot.ini: 'boot.ini' exceeds %d, size=%ld\n",
+ SZ_BOOTINI, filesize);
+ return NULL;
+ }
+
+ /* Terminate the read buffer with '\0' to be treated as string */
+ *(char *)(p + filesize) = '\0';
+
+ /* Scan MAGIC string, readed boot.ini must start with exact magic string.
+ * Otherwise, we will not proceed at all.
+ */
+ while (*p) {
+ char *s = strsep(&p, "\n");
+ if (!valid_command(s))
+ continue;
+
+ /* MAGIC string is discovered, return the buffer address of next to
+ * proceed the commands.
+ */
+ if (!strncmp(s, BOOTINI_MAGIC, sizeof(BOOTINI_MAGIC)))
+ return memcpy(malloc(filesize), p, filesize);
+ }
+
+ printf("cfgload: MAGIC NAME, %s, is not found!!\n", BOOTINI_MAGIC);
+
+ return NULL;
+}
+
+static int do_load_cfgload(cmd_tbl_t *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ char *p;
+ char *cmd;
+
+ p = read_cfgload();
+ if (NULL == p)
+ return 0;
+
+ printf("cfgload: applying boot.ini...\n");
+
+ while (p) {
+ cmd = strsep(&p, "\n");
+ if (!valid_command(cmd))
+ continue;
+
+ printf("cfgload: %s\n", cmd);
+
+#ifndef CONFIG_HUSH_PARSER
+ run_command(cmd, 0);
+#else
+ parse_string_outer(cmd, FLAG_PARSE_SEMICOLON
+ | FLAG_EXIT_FROM_LOOP);
+#endif
+ }
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ cfgload, 1, 0, do_load_cfgload,
+ "read 'boot.ini' from FAT partiton",
+ "\n"
+ " - read boot.ini from the first partiton treated as FAT partiton"
+);
diff --git a/configs/odroidn1_defconfig b/configs/odroidn1_defconfig
index 7a5289b95b..d7bcf4d3f5 100644
--- a/configs/odroidn1_defconfig
+++ b/configs/odroidn1_defconfig
@@ -524,6 +524,11 @@ CONFIG_CMD_FS_GENERIC=y
# CONFIG_CMD_UBI is not set
#
+# ODROID commands
+#
+CONFIG_CMD_ODROID_CFGLOAD=y
+
+#
# Partition Types
#
CONFIG_PARTITIONS=y