* [master] meta: scripts - relocation script adapted to support big-endian machines
@ 2022-04-01 4:20 Sundeep KOKKONDA
2022-04-01 9:49 ` [OE-core] " Richard Purdie
0 siblings, 1 reply; 3+ messages in thread
From: Sundeep KOKKONDA @ 2022-04-01 4:20 UTC (permalink / raw)
To: openembedded-core; +Cc: rwmacleod, umesh.kalappa0, Sundeep KOKKONDA
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.
The changes made in the script to support big-endian architecture.
Signed-off-by: Sundeep KOKKONDA <sundeep.kokkonda@gmail.com>
---
scripts/relocate_sdk.py | 45 ++++++++++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 10 deletions(-)
mode change 100755 => 100644 scripts/relocate_sdk.py
diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
old mode 100755
new mode 100644
index 8c0fdb986a..513b9343d3
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -30,9 +30,10 @@ else:
old_prefix = re.compile(b("##DEFAULT_INSTALL_DIR##"))
def get_arch():
+ global ei_data
f.seek(0)
e_ident =f.read(16)
- ei_mag0,ei_mag1_3,ei_class = struct.unpack("<B3sB11x", e_ident)
+ ei_mag0,ei_mag1_3,ei_class,ei_data,ei_version = struct.unpack("<B3sBBB9x", e_ident)
if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0:
return 0
@@ -51,11 +52,17 @@ def parse_elf_header():
if arch == 32:
# 32bit
- hdr_fmt = "<HHILLLIHHHHHH"
+ if ei_data == 1: # ei_data = 1, little endian
+ hdr_fmt = "<HHILLLIHHHHHH"
+ else: # ei_data = 0, big endian
+ hdr_fmt = ">HHILLLIHHHHHH"
hdr_size = 52
else:
# 64bit
- hdr_fmt = "<HHIQQQIHHHHHH"
+ if ei_data == 1:
+ hdr_fmt = "<HHIQQQIHHHHHH"
+ else:
+ hdr_fmt = ">HHIQQQIHHHHHH"
hdr_size = 64
e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\
@@ -64,9 +71,15 @@ def parse_elf_header():
def change_interpreter(elf_file_name):
if arch == 32:
- ph_fmt = "<IIIIIIII"
+ if ei_data == 1: # ei_data = 1, little endian
+ ph_fmt = "<IIIIIIII"
+ else: # ei_data = 0, big endian
+ ph_fmt = ">IIIIIIII"
else:
- ph_fmt = "<IIQQQQQQ"
+ if ei_data == 1:
+ ph_fmt = "<IIQQQQQQ"
+ else:
+ ph_fmt = ">IIQQQQQQ"
""" look for PT_INTERP section """
for i in range(0,e_phnum):
@@ -75,7 +88,7 @@ def change_interpreter(elf_file_name):
if arch == 32:
# 32bit
p_type, p_offset, p_vaddr, p_paddr, p_filesz,\
- p_memsz, p_flags, p_align = struct.unpack(ph_fmt, ph_hdr)
+ p_memsz, p_flags, p_align = struct.unpack(ph_fmt, ph_hdr)
else:
# 64bit
p_type, p_flags, p_offset, p_vaddr, p_paddr, \
@@ -105,17 +118,29 @@ def change_interpreter(elf_file_name):
def change_dl_sysdirs(elf_file_name):
if arch == 32:
- sh_fmt = "<IIIIIIIIII"
+ if ei_data == 1: # ei_data = 1, little endian
+ sh_fmt = "<IIIIIIIIII"
+ else: # ei_data = 0, big endian
+ sh_fmt = ">IIIIIIIIII"
else:
- sh_fmt = "<IIQQQQIIQQ"
+ if ei_data == 1:
+ sh_fmt = "<IIQQQQIIQQ"
+ else:
+ sh_fmt = ">IIQQQQIIQQ"
""" read section string table """
f.seek(e_shoff + e_shstrndx * e_shentsize)
sh_hdr = f.read(e_shentsize)
if arch == 32:
- sh_offset, sh_size = struct.unpack("<16xII16x", sh_hdr)
+ if ei_data == 1:
+ sh_offset, sh_size = struct.unpack("<16xII16x", sh_hdr)
+ else:
+ sh_offset, sh_size = struct.unpack(">16xII16x", sh_hdr)
else:
- sh_offset, sh_size = struct.unpack("<24xQQ24x", sh_hdr)
+ if ei_data == 1:
+ sh_offset, sh_size = struct.unpack("<24xQQ24x", sh_hdr)
+ else:
+ sh_offset, sh_size = struct.unpack(">24xQQ24x", sh_hdr)
f.seek(sh_offset)
sh_strtab = f.read(sh_size)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [OE-core] [master] meta: scripts - relocation script adapted to support big-endian machines
2022-04-01 4:20 [master] meta: scripts - relocation script adapted to support big-endian machines Sundeep KOKKONDA
@ 2022-04-01 9:49 ` Richard Purdie
2022-04-05 10:00 ` Sundeep KOKKONDA
0 siblings, 1 reply; 3+ messages in thread
From: Richard Purdie @ 2022-04-01 9:49 UTC (permalink / raw)
To: Sundeep KOKKONDA, openembedded-core; +Cc: rwmacleod, umesh.kalappa0
On Fri, 2022-04-01 at 09:50 +0530, Sundeep KOKKONDA wrote:
> 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.
>
> The changes made in the script to support big-endian architecture.
>
> Signed-off-by: Sundeep KOKKONDA <sundeep.kokkonda@gmail.com>
> ---
> scripts/relocate_sdk.py | 45 ++++++++++++++++++++++++++++++++---------
> 1 file changed, 35 insertions(+), 10 deletions(-)
> mode change 100755 => 100644 scripts/relocate_sdk.py
>
> diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
> old mode 100755
> new mode 100644
> index 8c0fdb986a..513b9343d3
> --- a/scripts/relocate_sdk.py
> +++ b/scripts/relocate_sdk.py
> @@ -30,9 +30,10 @@ else:
> old_prefix = re.compile(b("##DEFAULT_INSTALL_DIR##"))
>
> def get_arch():
> + global ei_data
> f.seek(0)
> e_ident =f.read(16)
> - ei_mag0,ei_mag1_3,ei_class = struct.unpack("<B3sB11x", e_ident)
> + ei_mag0,ei_mag1_3,ei_class,ei_data,ei_version = struct.unpack("<B3sBBB9x", e_ident)
>
> if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0:
> return 0
> @@ -51,11 +52,17 @@ def parse_elf_header():
>
> if arch == 32:
> # 32bit
> - hdr_fmt = "<HHILLLIHHHHHH"
> + if ei_data == 1: # ei_data = 1, little endian
> + hdr_fmt = "<HHILLLIHHHHHH"
> + else: # ei_data = 0, big endian
> + hdr_fmt = ">HHILLLIHHHHHH"
> hdr_size = 52
> else:
> # 64bit
> - hdr_fmt = "<HHIQQQIHHHHHH"
> + if ei_data == 1:
> + hdr_fmt = "<HHIQQQIHHHHHH"
> + else:
> + hdr_fmt = ">HHIQQQIHHHHHH"
> hdr_size = 64
I think we can make the change a bit neater, maybe putting ">" or "<" into the
global variable and then doing something like:
hdr_fmt = endian_prefix + "HHIQQQIHHHHHH"
?
Cheers,
Richard
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [master] meta: scripts - relocation script adapted to support big-endian machines
2022-04-01 9:49 ` [OE-core] " Richard Purdie
@ 2022-04-05 10:00 ` Sundeep KOKKONDA
0 siblings, 0 replies; 3+ messages in thread
From: Sundeep KOKKONDA @ 2022-04-05 10:00 UTC (permalink / raw)
To: openembedded-core
[-- Attachment #1: Type: text/plain, Size: 140 bytes --]
Hello Richard,
Patch updated and resubmitted.
https://lists.openembedded.org/g/openembedded-core/message/164012
Thanks,
Sundeep K.
[-- Attachment #2: Type: text/html, Size: 275 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-05 17:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-01 4:20 [master] meta: scripts - relocation script adapted to support big-endian machines Sundeep KOKKONDA
2022-04-01 9:49 ` [OE-core] " Richard Purdie
2022-04-05 10:00 ` Sundeep KOKKONDA
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox