1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 Western Digital Corporation or its affiliates.
5 * Atish Patra <atish.patra@wdc.com>
6 * Based on arm/lib/image.c
13 #include <linux/sizes.h>
14 #include <linux/stddef.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 /* ASCII version of "RSC\0x5" defined in Linux kernel */
19 #define LINUX_RISCV_IMAGE_MAGIC 0x05435352
21 struct linux_image_h {
22 uint32_t code0; /* Executable code */
23 uint32_t code1; /* Executable code */
24 uint64_t text_offset; /* Image load offset */
25 uint64_t image_size; /* Effective Image size */
26 uint64_t flags; /* kernel flags (little endian) */
27 uint32_t version; /* version of the header */
28 uint32_t res1; /* reserved */
29 uint64_t res2; /* reserved */
30 uint64_t res3; /* reserved */
31 uint32_t magic; /* Magic number */
32 uint32_t res4; /* reserved */
35 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
38 struct linux_image_h *lhdr;
40 lhdr = (struct linux_image_h *)map_sysmem(image, 0);
42 if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) {
43 puts("Bad Linux RISCV Image magic!\n");
47 if (lhdr->image_size == 0) {
48 puts("Image lacks image_size field, error!\n");
51 *size = lhdr->image_size;
52 *relocated_addr = gd->ram_base + lhdr->text_offset;