RISCV: image: Add booti support
authorAtish Patra <atish.patra@wdc.com>
Tue, 7 May 2019 00:49:39 +0000 (17:49 -0700)
committerAndes <uboot@andestech.com>
Thu, 9 May 2019 08:47:52 +0000 (16:47 +0800)
This patch adds booti support for RISC-V Linux kernel. The existing
bootm method will also continue to work as it is.

It depends on the following kernel patch which adds the header to the
flat Image. Gzip compressed Image (Image.gz) support is not enabled with
this patch.

https://patchwork.kernel.org/patch/10925543/

Tested on HiFive Unleashed and QEMU.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Tested-by: Karsten Merker <merker@debian.org>
Reviewed-by: Marek Vasut <marek.vasut@gmail.com>
arch/riscv/lib/Makefile
arch/riscv/lib/image.c [new file with mode: 0644]
cmd/Kconfig
cmd/booti.c

index 1c332db436a9db87de191e31c482a59e528d6dfa..6ae6ebbeafdac85a973c558e8eb6245ee007eec0 100644 (file)
@@ -7,6 +7,7 @@
 # Rick Chen, Andes Technology Corporation <rick@andestech.com>
 
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o
 obj-$(CONFIG_CMD_GO) += boot.o
 obj-y  += cache.o
 obj-$(CONFIG_RISCV_RDTIME) += rdtime.o
diff --git a/arch/riscv/lib/image.c b/arch/riscv/lib/image.c
new file mode 100644 (file)
index 0000000..d063beb
--- /dev/null
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Western Digital Corporation or its affiliates.
+ * Authors:
+ *     Atish Patra <atish.patra@wdc.com>
+ * Based on arm/lib/image.c
+ */
+
+#include <common.h>
+#include <mapmem.h>
+#include <errno.h>
+#include <linux/sizes.h>
+#include <linux/stddef.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* ASCII version of "RISCV" defined in Linux kernel */
+#define LINUX_RISCV_IMAGE_MAGIC 0x5643534952
+
+struct linux_image_h {
+       uint32_t        code0;          /* Executable code */
+       uint32_t        code1;          /* Executable code */
+       uint64_t        text_offset;    /* Image load offset */
+       uint64_t        image_size;     /* Effective Image size */
+       uint64_t        res1;           /* reserved */
+       uint64_t        res2;           /* reserved */
+       uint64_t        res3;           /* reserved */
+       uint64_t        magic;          /* Magic number */
+       uint32_t        res4;           /* reserved */
+       uint32_t        res5;           /* reserved */
+};
+
+int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
+               bool force_reloc)
+{
+       struct linux_image_h *lhdr;
+
+       lhdr = (struct linux_image_h *)map_sysmem(image, 0);
+
+       if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) {
+               puts("Bad Linux RISCV Image magic!\n");
+               return -EINVAL;
+       }
+
+       if (lhdr->image_size == 0) {
+               puts("Image lacks image_size field, error!\n");
+               return -EINVAL;
+       }
+       *size = lhdr->image_size;
+       *relocated_addr = gd->ram_base + lhdr->text_offset;
+
+       unmap_sysmem(lhdr);
+
+       return 0;
+}
index 069e0ea7300bb0010b5b6e41e9163150c480e3fd..4e11e0f404c88b8f357491d03b00e7e6d776156c 100644 (file)
@@ -223,7 +223,7 @@ config CMD_BOOTZ
 
 config CMD_BOOTI
        bool "booti"
-       depends on ARM64
+       depends on ARM64 || RISCV
        default y
        help
          Boot an AArch64 Linux Kernel image from memory.
index 04353b68eccc0d73d62c44128016da883fd9a5c5..c36b0235df8c79aea703a3bacdbda1c636858fac 100644 (file)
@@ -77,7 +77,11 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        bootm_disable_interrupts();
 
        images.os.os = IH_OS_LINUX;
+#ifdef CONFIG_RISCV_SMODE
+       images.os.arch = IH_ARCH_RISCV;
+#elif CONFIG_ARM64
        images.os.arch = IH_ARCH_ARM64;
+#endif
        ret = do_bootm_states(cmdtp, flag, argc, argv,
 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
                              BOOTM_STATE_RAMDISK |
@@ -92,7 +96,7 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #ifdef CONFIG_SYS_LONGHELP
 static char booti_help_text[] =
        "[addr [initrd[:size]] [fdt]]\n"
-       "    - boot arm64 Linux Image stored in memory\n"
+       "    - boot Linux 'Image' stored at 'addr'\n"
        "\tThe argument 'initrd' is optional and specifies the address\n"
        "\tof an initrd in memory. The optional parameter ':size' allows\n"
        "\tspecifying the size of a RAW initrd.\n"
@@ -107,5 +111,5 @@ static char booti_help_text[] =
 
 U_BOOT_CMD(
        booti,  CONFIG_SYS_MAXARGS,     1,      do_booti,
-       "boot arm64 Linux Image image from memory", booti_help_text
+       "boot Linux kernel 'Image' format from memory", booti_help_text
 );