• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2019 Western Digital Corporation or its affiliates.
4  * Authors:
5  *	Atish Patra <atish.patra@wdc.com>
6  * Based on arm/lib/image.c
7  */
8 
9 #include <common.h>
10 #include <mapmem.h>
11 #include <errno.h>
12 #include <linux/sizes.h>
13 #include <linux/stddef.h>
14 
15 DECLARE_GLOBAL_DATA_PTR;
16 
17 /* ASCII version of "RSC\0x5" defined in Linux kernel */
18 #define LINUX_RISCV_IMAGE_MAGIC 0x05435352
19 
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	flags;		/* kernel flags (little endian) */
26 	uint32_t	version;	/* version of the header */
27 	uint32_t	res1;		/* reserved */
28 	uint64_t	res2;		/* reserved */
29 	uint64_t	res3;		/* reserved */
30 	uint32_t	magic;		/* Magic number */
31 	uint32_t	res4;		/* reserved */
32 };
33 
booti_setup(ulong image,ulong * relocated_addr,ulong * size,bool force_reloc)34 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
35 		bool force_reloc)
36 {
37 	struct linux_image_h *lhdr;
38 
39 	lhdr = (struct linux_image_h *)map_sysmem(image, 0);
40 
41 	if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) {
42 		puts("Bad Linux RISCV Image magic!\n");
43 		return -EINVAL;
44 	}
45 
46 	if (lhdr->image_size == 0) {
47 		puts("Image lacks image_size field, error!\n");
48 		return -EINVAL;
49 	}
50 	*size = lhdr->image_size;
51 	*relocated_addr = gd->ram_base + lhdr->text_offset;
52 
53 	unmap_sysmem(lhdr);
54 
55 	return 0;
56 }
57