summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSundeep KOKKONDA <sundeep.kokkonda@gmail.com>2022-04-05 15:28:19 +0530
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-04-05 22:23:40 +0100
commit601befb6c76835b96e2bb42230a5b7fcdd28d7fc (patch)
treef95a61369309a497da73c09cf96c84d90ff4deff
parent498f9c58c8855eface861aa3fbf6df11d416f015 (diff)
downloadpoky-601befb6c76835b96e2bb42230a5b7fcdd28d7fc.tar.gz
meta: scripts - relocation script adapted to support big-endian machines
relocate_sdk.py was developed for little-endian architures and when tries to install SDK for big-endian machines errors like below will be shown. Error: struct.error: unpack requires a string argument of length 32. SDK could not be set up. Relocate script failed. Abort! Error: IOError: [Errno 22] Invalid argument. SDK could not be set up. Relocate script failed. Abort! To fix this, script is modified to support big-endian architecture. (From OE-Core rev: 7d6f4b1373e4dfafc63702ef2426cd45100f18a3) Signed-off-by: Sundeep KOKKONDA <sundeep.kokkonda@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xscripts/relocate_sdk.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
index 8c0fdb986a..4ed8bfc0d1 100755
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -30,9 +30,16 @@ else:
30old_prefix = re.compile(b("##DEFAULT_INSTALL_DIR##")) 30old_prefix = re.compile(b("##DEFAULT_INSTALL_DIR##"))
31 31
32def get_arch(): 32def get_arch():
33 global endian_prefix
33 f.seek(0) 34 f.seek(0)
34 e_ident =f.read(16) 35 e_ident =f.read(16)
35 ei_mag0,ei_mag1_3,ei_class = struct.unpack("<B3sB11x", e_ident) 36 ei_mag0,ei_mag1_3,ei_class,ei_data,ei_version = struct.unpack("<B3sBBB9x", e_ident)
37
38 # ei_data = 1 for little-endian & 0 for big-endian
39 if ei_data == 1:
40 endian_prefix = '<'
41 else:
42 endian_prefix = '>'
36 43
37 if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0: 44 if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0:
38 return 0 45 return 0
@@ -51,11 +58,11 @@ def parse_elf_header():
51 58
52 if arch == 32: 59 if arch == 32:
53 # 32bit 60 # 32bit
54 hdr_fmt = "<HHILLLIHHHHHH" 61 hdr_fmt = endian_prefix + "HHILLLIHHHHHH"
55 hdr_size = 52 62 hdr_size = 52
56 else: 63 else:
57 # 64bit 64 # 64bit
58 hdr_fmt = "<HHIQQQIHHHHHH" 65 hdr_fmt = endian_prefix + "HHIQQQIHHHHHH"
59 hdr_size = 64 66 hdr_size = 64
60 67
61 e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\ 68 e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\
@@ -64,9 +71,9 @@ def parse_elf_header():
64 71
65def change_interpreter(elf_file_name): 72def change_interpreter(elf_file_name):
66 if arch == 32: 73 if arch == 32:
67 ph_fmt = "<IIIIIIII" 74 ph_fmt = endian_prefix + "IIIIIIII"
68 else: 75 else:
69 ph_fmt = "<IIQQQQQQ" 76 ph_fmt = endian_prefix + "IIQQQQQQ"
70 77
71 """ look for PT_INTERP section """ 78 """ look for PT_INTERP section """
72 for i in range(0,e_phnum): 79 for i in range(0,e_phnum):
@@ -105,17 +112,17 @@ def change_interpreter(elf_file_name):
105 112
106def change_dl_sysdirs(elf_file_name): 113def change_dl_sysdirs(elf_file_name):
107 if arch == 32: 114 if arch == 32:
108 sh_fmt = "<IIIIIIIIII" 115 sh_fmt = endian_prefix + "IIIIIIIIII"
109 else: 116 else:
110 sh_fmt = "<IIQQQQIIQQ" 117 sh_fmt = endian_prefix + "IIQQQQIIQQ"
111 118
112 """ read section string table """ 119 """ read section string table """
113 f.seek(e_shoff + e_shstrndx * e_shentsize) 120 f.seek(e_shoff + e_shstrndx * e_shentsize)
114 sh_hdr = f.read(e_shentsize) 121 sh_hdr = f.read(e_shentsize)
115 if arch == 32: 122 if arch == 32:
116 sh_offset, sh_size = struct.unpack("<16xII16x", sh_hdr) 123 sh_offset, sh_size = struct.unpack(endian_prefix + "16xII16x", sh_hdr)
117 else: 124 else:
118 sh_offset, sh_size = struct.unpack("<24xQQ24x", sh_hdr) 125 sh_offset, sh_size = struct.unpack(endian_prefix + "24xQQ24x", sh_hdr)
119 126
120 f.seek(sh_offset) 127 f.seek(sh_offset)
121 sh_strtab = f.read(sh_size) 128 sh_strtab = f.read(sh_size)