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
12 #include <linux/sizes.h>
13 #include <linux/stddef.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 /* ASCII version of "RISCV" defined in Linux kernel */
18 #define LINUX_RISCV_IMAGE_MAGIC 0x5643534952
20 struct linux_image_h {
21 uint32_t code0; /* Executable code */
22 uint32_t code1; /* Executable code */
23 uint64_t text_offset; /* Image load offset */
24 uint64_t image_size; /* Effective Image size */
25 uint64_t res1; /* reserved */
26 uint64_t res2; /* reserved */
27 uint64_t res3; /* reserved */
28 uint64_t magic; /* Magic number */
29 uint32_t res4; /* reserved */
30 uint32_t res5; /* reserved */
33 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
36 struct linux_image_h *lhdr;
38 lhdr = (struct linux_image_h *)map_sysmem(image, 0);
40 if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) {
41 puts("Bad Linux RISCV Image magic!\n");
45 if (lhdr->image_size == 0) {
46 puts("Image lacks image_size field, error!\n");
49 *size = lhdr->image_size;
50 *relocated_addr = gd->ram_base + lhdr->text_offset;