]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/prelink-riscv.c
2 * Copyright (C) 2017 Andes Technology
3 * Chih-Mao Chen <cmchen@andestech.com>
5 * SPDX-License-Identifier: GPL-2.0+
7 * Statically process runtime relocations on RISC-V ELF images
8 * so that it can be directly executed when loaded at LMA
9 * without fixup. Both RV32 and RV64 are supported.
12 #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
13 #error "Only little-endian host is supported"
27 #include <sys/types.h>
42 #ifndef R_RISCV_RELATIVE
43 #define R_RISCV_RELATIVE 3
48 #define die(fmt, ...) \
50 fprintf(stderr, "%s: " fmt "\n", argv0, ## __VA_ARGS__); \
54 #define PRELINK_INC_BITS 32
55 #include "prelink-riscv.inc"
56 #undef PRELINK_INC_BITS
58 #define PRELINK_INC_BITS 64
59 #include "prelink-riscv.inc"
60 #undef PRELINK_INC_BITS
62 int main(int argc
, const char *const *argv
)
67 fprintf(stderr
, "Usage: %s <u-boot>\n", argv0
);
71 int fd
= open(argv
[1], O_RDWR
, 0);
74 die("Cannot open %s: %s", argv
[1], strerror(errno
));
78 if (fstat(fd
, &st
) < 0)
79 die("Cannot stat %s: %s", argv
[1], strerror(errno
));
82 mmap(0, st
.st_size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
84 if (data
== MAP_FAILED
)
85 die("Cannot mmap %s: %s", argv
[1], strerror(errno
));
89 unsigned char *e_ident
= (unsigned char *)data
;
91 if (memcmp(e_ident
, ELFMAG
, SELFMAG
) != 0)
92 die("Invalid ELF file %s", argv
[1]);
94 bool is64
= e_ident
[EI_CLASS
] == ELFCLASS64
;