]> Git Repo - u-boot.git/blame - arch/arm/lib/image.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[u-boot.git] / arch / arm / lib / image.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
6808ef9a
BC
2/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, [email protected].
6808ef9a
BC
5 */
6
d678a59d 7#include <common.h>
4d72caa5 8#include <image.h>
6808ef9a 9#include <mapmem.h>
401d1c4f 10#include <asm/global_data.h>
cd93d625 11#include <linux/bitops.h>
6808ef9a
BC
12#include <linux/sizes.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16#define LINUX_ARM64_IMAGE_MAGIC 0x644d5241
17
18/* See Documentation/arm64/booting.txt in the Linux kernel */
19struct Image_header {
6becd9de
MY
20 uint32_t code0; /* Executable code */
21 uint32_t code1; /* Executable code */
22 uint64_t text_offset; /* Image load offset, LE */
23 uint64_t image_size; /* Effective Image size, LE */
24 uint64_t flags; /* Kernel flags, LE */
25 uint64_t res2; /* reserved */
26 uint64_t res3; /* reserved */
27 uint64_t res4; /* reserved */
28 uint32_t magic; /* Magic number */
29 uint32_t res5;
6808ef9a
BC
30};
31
7f13b374
MV
32int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
33 bool force_reloc)
6808ef9a 34{
6becd9de
MY
35 struct Image_header *ih;
36 uint64_t dst;
37 uint64_t image_size, text_offset;
6808ef9a 38
6becd9de 39 *relocated_addr = image;
6808ef9a 40
6becd9de 41 ih = (struct Image_header *)map_sysmem(image, 0);
6808ef9a 42
6becd9de
MY
43 if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
44 puts("Bad Linux ARM64 Image magic!\n");
45 return 1;
46 }
6808ef9a 47
6becd9de
MY
48 /*
49 * Prior to Linux commit a2c1d73b94ed, the text_offset field
50 * is of unknown endianness. In these cases, the image_size
51 * field is zero, and we can assume a fixed value of 0x80000.
52 */
53 if (ih->image_size == 0) {
54 puts("Image lacks image_size field, assuming 16MiB\n");
55 image_size = 16 << 20;
56 text_offset = 0x80000;
57 } else {
58 image_size = le64_to_cpu(ih->image_size);
59 text_offset = le64_to_cpu(ih->text_offset);
60 }
6808ef9a 61
6becd9de 62 *size = image_size;
6808ef9a 63
6becd9de
MY
64 /*
65 * If bit 3 of the flags field is set, the 2MB aligned base of the
66 * kernel image can be anywhere in physical memory, so respect
67 * images->ep. Otherwise, relocate the image to the base of RAM
68 * since memory below it is not accessible via the linear mapping.
69 */
7f13b374 70 if (!force_reloc && (le64_to_cpu(ih->flags) & BIT(3)))
6becd9de
MY
71 dst = image - text_offset;
72 else
73 dst = gd->bd->bi_dram[0].start;
6808ef9a 74
6becd9de 75 *relocated_addr = ALIGN(dst, SZ_2M) + text_offset;
6808ef9a 76
6becd9de 77 unmap_sysmem(ih);
6808ef9a 78
6becd9de 79 return 0;
6808ef9a 80}
This page took 0.140576 seconds and 4 git commands to generate.