aboutsummaryrefslogtreecommitdiff
path: root/tools/relocate-rela.c
diff options
context:
space:
mode:
authorOvidiu Panait <ovpanait@gmail.com>2023-03-11 19:38:35 +0200
committerMichal Simek <michal.simek@amd.com>2023-03-13 11:46:17 +0100
commit424f04fcd9ab7b2c19521605827e2453dd79c3e2 (patch)
treed6daf542cd056c0359e2aece99d40274ae7b3f04 /tools/relocate-rela.c
parent26c8c1bd12617aab0480d0a559194e4e0631e637 (diff)
downloadu-boot-424f04fcd9ab7b2c19521605827e2453dd79c3e2.zip
u-boot-424f04fcd9ab7b2c19521605827e2453dd79c3e2.tar.gz
u-boot-424f04fcd9ab7b2c19521605827e2453dd79c3e2.tar.bz2
tools: relocate-rela: introduce elf16_to_cpu() and elf32_to_cpu()
Add elf16_to_cpu() and elf32_to_cpu() functions that allow to read data in both big-endian and little-endian formats. Reviewed-by: Michal Simek <michal.simek@amd.com> Signed-off-by: Ovidiu Panait <ovpanait@gmail.com> Link: https://lore.kernel.org/r/20230311173838.521804-2-ovpanait@gmail.com Signed-off-by: Michal Simek <michal.simek@amd.com>
Diffstat (limited to 'tools/relocate-rela.c')
-rw-r--r--tools/relocate-rela.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
index 689e2d4..b27c41b 100644
--- a/tools/relocate-rela.c
+++ b/tools/relocate-rela.c
@@ -45,6 +45,7 @@
#endif
static int ei_class;
+static int ei_data;
static uint64_t rela_start, rela_end, text_base, dyn_start;
@@ -61,6 +62,22 @@ static void debug(const char *fmt, ...)
}
}
+static uint16_t elf16_to_cpu(uint16_t data)
+{
+ if (ei_data == ELFDATA2LSB)
+ return le16_to_cpu(data);
+
+ return be16_to_cpu(data);
+}
+
+static uint32_t elf32_to_cpu(uint32_t data)
+{
+ if (ei_data == ELFDATA2LSB)
+ return le32_to_cpu(data);
+
+ return be32_to_cpu(data);
+}
+
static bool supported_rela(Elf64_Rela *rela)
{
uint64_t mask = 0xffffffffULL; /* would be different on 32-bit */
@@ -384,6 +401,9 @@ static int decode_elf(char **argv)
ei_class = e_ident[4];
debug("EI_CLASS(1=32bit, 2=64bit) %d\n", ei_class);
+ ei_data = e_ident[5];
+ debug("EI_DATA(1=little endian, 2=big endian) %d\n", ei_data);
+
if (ei_class == 2)
return decode_elf64(felf, argv);