summaryrefslogtreecommitdiffstats
path: root/scripts/relocate_sdk.py
diff options
context:
space:
mode:
authorJason Wessel <jason.wessel@windriver.com>2013-02-12 05:08:23 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-02-12 13:11:22 +0000
commitc160a982551f5d6186081daa8fa20682fd7fae17 (patch)
treeff2c9804ca9beb718d593fe9a64a780d8e0262d8 /scripts/relocate_sdk.py
parent7d023f3b5fd2b562fcdde3c991cf49f35263d1ff (diff)
downloadpoky-c160a982551f5d6186081daa8fa20682fd7fae17.tar.gz
relocate_sdk.py: allow relocate_sdk.py to work with python 2.4.x
Avoid the chicken / egg problem of an SDK that provides a working python but requires that version of python to extract itself. The RHEL 5.x systems and some other enterprise Linux systems ship with python 2.4.x as the default python. We need to at least be able to extract work executables even if we never use the the host provided python again. (From OE-Core rev: e1d42db8749b0b965ddc6cfba4f3b93ee96ed4f4) Signed-off-by: Jason Wessel <jason.wessel@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/relocate_sdk.py')
-rwxr-xr-xscripts/relocate_sdk.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
index 45d2c241c3..1d7bbb3849 100755
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -55,22 +55,22 @@ def parse_elf_header():
55 55
56 if arch == 32: 56 if arch == 32:
57 # 32bit 57 # 32bit
58 hdr_struct = struct.Struct("<HHILLLIHHHHHH") 58 hdr_fmt = "<HHILLLIHHHHHH"
59 hdr_size = 52 59 hdr_size = 52
60 else: 60 else:
61 # 64bit 61 # 64bit
62 hdr_struct = struct.Struct("<HHIQQQIHHHHHH") 62 hdr_fmt = "<HHIQQQIHHHHHH"
63 hdr_size = 64 63 hdr_size = 64
64 64
65 e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\ 65 e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\
66 e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum, e_shstrndx =\ 66 e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum, e_shstrndx =\
67 hdr_struct.unpack(elf_header[16:hdr_size]) 67 struct.unpack(hdr_fmt, elf_header[16:hdr_size])
68 68
69def change_interpreter(elf_file_name): 69def change_interpreter(elf_file_name):
70 if arch == 32: 70 if arch == 32:
71 ph_struct = struct.Struct("<IIIIIIII") 71 ph_fmt = "<IIIIIIII"
72 else: 72 else:
73 ph_struct = struct.Struct("<IIQQQQQQ") 73 ph_fmt = "<IIQQQQQQ"
74 74
75 """ look for PT_INTERP section """ 75 """ look for PT_INTERP section """
76 for i in range(0,e_phnum): 76 for i in range(0,e_phnum):
@@ -79,11 +79,11 @@ def change_interpreter(elf_file_name):
79 if arch == 32: 79 if arch == 32:
80 # 32bit 80 # 32bit
81 p_type, p_offset, p_vaddr, p_paddr, p_filesz,\ 81 p_type, p_offset, p_vaddr, p_paddr, p_filesz,\
82 p_memsz, p_flags, p_align = ph_struct.unpack(ph_hdr) 82 p_memsz, p_flags, p_align = struct.unpack(ph_fmt, ph_hdr)
83 else: 83 else:
84 # 64bit 84 # 64bit
85 p_type, p_flags, p_offset, p_vaddr, p_paddr, \ 85 p_type, p_flags, p_offset, p_vaddr, p_paddr, \
86 p_filesz, p_memsz, p_align = ph_struct.unpack(ph_hdr) 86 p_filesz, p_memsz, p_align = struct.unpack(ph_fmt, ph_hdr)
87 87
88 """ change interpreter """ 88 """ change interpreter """
89 if p_type == 3: 89 if p_type == 3:
@@ -104,9 +104,9 @@ def change_interpreter(elf_file_name):
104 104
105def change_dl_sysdirs(): 105def change_dl_sysdirs():
106 if arch == 32: 106 if arch == 32:
107 sh_struct = struct.Struct("<IIIIIIIIII") 107 sh_fmt = "<IIIIIIIIII"
108 else: 108 else:
109 sh_struct = struct.Struct("<IIQQQQIIQQ") 109 sh_fmt = "<IIQQQQIIQQ"
110 110
111 """ read section string table """ 111 """ read section string table """
112 f.seek(e_shoff + e_shstrndx * e_shentsize) 112 f.seek(e_shoff + e_shstrndx * e_shentsize)
@@ -127,7 +127,7 @@ def change_dl_sysdirs():
127 sh_hdr = f.read(e_shentsize) 127 sh_hdr = f.read(e_shentsize)
128 128
129 sh_name, sh_type, sh_flags, sh_addr, sh_offset, sh_size, sh_link,\ 129 sh_name, sh_type, sh_flags, sh_addr, sh_offset, sh_size, sh_link,\
130 sh_info, sh_addralign, sh_entsize = sh_struct.unpack(sh_hdr) 130 sh_info, sh_addralign, sh_entsize = struct.unpack(sh_fmt, sh_hdr)
131 131
132 name = sh_strtab[sh_name:sh_strtab.find("\0", sh_name)] 132 name = sh_strtab[sh_name:sh_strtab.find("\0", sh_name)]
133 133
@@ -181,7 +181,7 @@ def change_dl_sysdirs():
181 181
182# MAIN 182# MAIN
183if len(sys.argv) < 4: 183if len(sys.argv) < 4:
184 exit(-1) 184 sys.exit(-1)
185 185
186new_prefix = sys.argv[1] 186new_prefix = sys.argv[1]
187new_dl_path = sys.argv[2] 187new_dl_path = sys.argv[2]
@@ -196,14 +196,14 @@ for e in executables_list:
196 196
197 try: 197 try:
198 f = open(e, "r+b") 198 f = open(e, "r+b")
199 except IOError as ioex: 199 except IOError, ioex:
200 if ioex.errno == errno.ETXTBSY: 200 if ioex.errno == errno.ETXTBSY:
201 print("Could not open %s. File used by another process.\nPlease "\ 201 print("Could not open %s. File used by another process.\nPlease "\
202 "make sure you exit all processes that might use any SDK "\ 202 "make sure you exit all processes that might use any SDK "\
203 "binaries." % e) 203 "binaries." % e)
204 else: 204 else:
205 print("Could not open %s: %s(%d)" % (e, ioex.strerror, ioex.errno)) 205 print("Could not open %s: %s(%d)" % (e, ioex.strerror, ioex.errno))
206 exit(-1) 206 sys.exit(-1)
207 207
208 arch = get_arch() 208 arch = get_arch()
209 if arch: 209 if arch: