2019-05-07 00:49:39 +00:00
|
|
|
// 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>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <image.h>
|
2019-05-07 00:49:39 +00:00
|
|
|
#include <mapmem.h>
|
|
|
|
#include <errno.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2019-05-07 00:49:39 +00:00
|
|
|
#include <linux/sizes.h>
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2019-10-09 17:34:17 +00:00
|
|
|
/* ASCII version of "RSC\0x5" defined in Linux kernel */
|
|
|
|
#define LINUX_RISCV_IMAGE_MAGIC 0x05435352
|
2019-05-07 00:49:39 +00:00
|
|
|
|
|
|
|
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 */
|
2019-10-09 17:34:17 +00:00
|
|
|
uint64_t flags; /* kernel flags (little endian) */
|
|
|
|
uint32_t version; /* version of the header */
|
|
|
|
uint32_t res1; /* reserved */
|
2019-05-07 00:49:39 +00:00
|
|
|
uint64_t res2; /* reserved */
|
|
|
|
uint64_t res3; /* reserved */
|
2019-10-09 17:34:17 +00:00
|
|
|
uint32_t magic; /* Magic number */
|
2019-05-07 00:49:39 +00:00
|
|
|
uint32_t res4; /* 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;
|
|
|
|
}
|