summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongjin Kim <tobetter@gmail.com>2020-05-19 12:09:27 +0300
committerDongjin Kim <tobetter@gmail.com>2020-05-19 13:49:34 +0300
commitcaada77ccce3bd86ee1c39def62dd2cf92e3504f (patch)
tree3b349cc2c22851233fc52d28823f44002973c61c
parent0fe0614f0cb64160ac353abec0cf3e60120c12f0 (diff)
downloadu-boot-caada77ccce3bd86ee1c39def62dd2cf92e3504f.tar.xz
ODROID-XU3/4: refactroing the command 'cfgload' to use 'source'
Signed-off-by: Dongjin Kim <tobetter@gmail.com> Change-Id: I3f67224ef95e2532643ff9e0684e848759e51c09
-rwxr-xr-xcmd/cfgload.c153
-rw-r--r--cmd/source.c33
2 files changed, 64 insertions, 122 deletions
diff --git a/cmd/cfgload.c b/cmd/cfgload.c
index dae4f6f10b..e05187858f 100755
--- a/cmd/cfgload.c
+++ b/cmd/cfgload.c
@@ -9,139 +9,48 @@
#include <command.h>
#include <errno.h>
#include <malloc.h>
-#include <linux/ctype.h> /* isalpha, isdigit */
#include <linux/sizes.h>
-#ifdef CONFIG_SYS_HUSH_PARSER
-#include <cli_hush.h>
-#endif
-
-#if defined(CONFIG_TARGET_ODROID_XU4)
-#define BOOTINI_MAGIC "ODROIDXU-UBOOT-CONFIG"
-#else
-#error 'BOOTINI_MAGIC' is missing!!!
-#endif
-
-#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 msg[128] = { 0, };
- unsigned long filesize;
- char *p;
-
- p = (char *)simple_strtoul(getenv("loadaddr"), NULL, 16);
- if (NULL == p) {
- p = (char *)CONFIG_SYS_LOAD_ADDR;
- sprintf(msg, "%x", CONFIG_SYS_LOAD_ADDR);
- setenv("loadaddr", msg);
- }
-
- setenv("filesize", "0");
- sprintf(msg, "cfgload addr = 0x%08X, Loading boot.ini from ",
- simple_strtoul(getenv("loadaddr"), NULL, 16));
-
- setenv("msgload", msg);
- run_command("if fatload mmc 0:1 ${loadaddr} boot.ini;" \
- " then echo ${msgload} FAT;" \
- " else if ext4load mmc 0:1 ${loadaddr} /boot.ini;" \
- " then echo ${msgload} ext4 0:1 /boot.ini;" \
- " else if ext4load mmc 0:1 ${loadaddr} /boot/boot.ini;" \
- " then echo ${msgload} ext4 0:1 /boot/boot.ini;" \
- " else if ext4load mmc 0:2 ${loadaddr} /boot/boot.ini;" \
- " then echo ${msgload} ext4 0:2 /boot.ini;" \
- " else if ext4load mmc 0:2 ${loadaddr} /boot.ini;" \
- " then echo ${msgload} ext4 0:2 /boot/boot.ini;" \
- " fi;fi;fi;fi;fi;", 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);
+ int i, n, devno = 0;
+ char* scripts[] = {
+ "/boot.ini",
+ "/boot/boot.ini",
+ "/boot.scr",
+ };
+
+ ulong addr;
+ char cmd[1024];
+
+ if (argc < 2) {
+ addr = CONFIG_SYS_LOAD_ADDR;
+ debug ("* cfgload: default load address = 0x%08lx\n", addr);
+ } else {
+ addr = simple_strtoul(argv[1], NULL, 16);
+ debug ("* cfgload: cmdline image address = 0x%08lx\n", addr);
+ }
-#ifndef CONFIG_SYS_HUSH_PARSER
- run_command(cmd, 0);
-#else
- parse_string_outer(cmd, FLAG_PARSE_SEMICOLON
- | FLAG_EXIT_FROM_LOOP);
-#endif
+ setenv("devtype", "mmc");
+ setenv("devnum", simple_itoa(devno));
+ setenv("devno", simple_itoa(devno));
+
+ for (i = 1; i <= 2; i++) {
+ setenv("partition", simple_itoa(i));
+ for (n = 0; n < ARRAY_SIZE(scripts); n++) {
+ snprintf(cmd, sizeof(cmd),
+ "load mmc %d:%d 0x%08lx %s; source 0x%08lx",
+ devno, i, addr, scripts[n], addr);
+ run_command(cmd, 0);
+ }
}
- return 0;
+ return 1;
}
U_BOOT_CMD(
- cfgload, 1, 0, do_load_cfgload,
+ cfgload, 2, 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/cmd/source.c b/cmd/source.c
index db7ab7e5f4..da23a044a2 100644
--- a/cmd/source.c
+++ b/cmd/source.c
@@ -26,6 +26,25 @@
#include <mpc8xx.h>
#endif
+#if defined(CONFIG_TARGET_ODROID_XU3) || defined(CONFIG_TARGET_ODROID_XU4)
+#include <linux/ctype.h>
+
+static
+int check_odroid_script(ulong addr, char *product)
+{
+ int i;
+ char *buf;
+ char magic[32];
+ int size = snprintf(magic, sizeof(magic), "%s-uboot-config", product);
+
+ buf = map_sysmem(addr, 0);
+ if (strncasecmp(magic, buf, size))
+ return -EINVAL;
+
+ return size;
+}
+#endif
+
int
source (ulong addr, const char *fit_uname)
{
@@ -42,6 +61,9 @@ source (ulong addr, const char *fit_uname)
const void *fit_data;
size_t fit_len;
#endif
+#if defined(CONFIG_TARGET_ODROID_XU3) || defined(CONFIG_TARGET_ODROID_XU4)
+ int size;
+#endif
verify = getenv_yesno ("verify");
@@ -133,8 +155,19 @@ source (ulong addr, const char *fit_uname)
break;
#endif
default:
+#if defined(CONFIG_TARGET_ODROID_XU3) || defined(CONFIG_TARGET_ODROID_XU4)
+ size = check_odroid_script(addr, "ODROIDXU");
+ if (size > 0) {
+ data = (u32*)(addr + size);
+ len = simple_strtoul(getenv("filesize"), NULL, 16) - size;
+ } else {
+ puts ("Wrong image format for \"source\" command\n");
+ return 1;
+ }
+#else
puts ("Wrong image format for \"source\" command\n");
return 1;
+#endif
}
debug ("** Script length: %ld\n", len);