diff --git a/scripts/elf_helper.py b/scripts/elf_helper.py index 48adb54bf20..44b53162e2e 100644 --- a/scripts/elf_helper.py +++ b/scripts/elf_helper.py @@ -353,6 +353,19 @@ def analyze_typedef(die): type_env[die.offset] = type_env[type_offset] +def unpack_pointer(elf, data, offset): + endian_code = "<" if elf.little_endian else ">" + if elf.elfclass == 32: + size_code = "I" + size = 4 + else: + size_code = "Q" + size = 8 + + return struct.unpack(endian_code + size_code, + data[offset:offset + size])[0] + + def addr_deref(elf, addr): for section in elf.iter_sections(): start = section['sh_addr'] @@ -361,14 +374,15 @@ def addr_deref(elf, addr): if start <= addr < end: data = section.data() offset = addr - start - return struct.unpack("I", - data[offset:offset + 4])[0] + return unpack_pointer(elf, data, offset) return 0 def device_get_api_addr(elf, addr): - return addr_deref(elf, addr + 4) + # Read device->driver API + offset = 4 if elf.elfclass == 32 else 8 + return addr_deref(elf, addr + offset) def get_filename_lineno(die): diff --git a/scripts/gen_kobject_list.py b/scripts/gen_kobject_list.py index 1e2cdd2be25..e891472130e 100755 --- a/scripts/gen_kobject_list.py +++ b/scripts/gen_kobject_list.py @@ -200,7 +200,17 @@ def write_gperf_table(fp, eh, objs, static_begin, static_end): initialized = static_begin <= obj_addr < static_end is_driver = obj_type.startswith("K_OBJ_DRIVER_") - byte_str = struct.pack("I", obj_addr) + if "CONFIG_64BIT" in syms: + format_code = "Q" + else: + format_code = "I" + + if eh.little_endian: + endian = "<" + else: + endian = ">" + + byte_str = struct.pack(endian + format_code, obj_addr) fp.write("\"") for byte in byte_str: val = "\\x%02x" % byte diff --git a/scripts/process_gperf.py b/scripts/process_gperf.py index 921f0ac9bf2..ac46fc7726c 100755 --- a/scripts/process_gperf.py +++ b/scripts/process_gperf.py @@ -49,8 +49,8 @@ def reformat_str(match_obj): # Nip quotes addr_str = addr_str[1:-1] - addr_vals = [0, 0, 0, 0] - ctr = 3 + addr_vals = [0, 0, 0, 0, 0, 0, 0 , 0] + ctr = 7 i = 0 while True: @@ -74,7 +74,7 @@ def reformat_str(match_obj): ctr -= 1 - return "(char *)0x%02x%02x%02x%02x" % tuple(addr_vals) + return "(char *)0x%02x%02x%02x%02x%02x%02x%02x%02x" % tuple(addr_vals) def process_line(line, fp): @@ -97,9 +97,9 @@ def process_line(line, fp): warn("gperf %s is not tested, versions %s through %s supported" % (v, v_lo, v_hi)) - # Replace length lookups with constant len of 4 since we're always + # Replace length lookups with constant len since we're always # looking at pointers - line = re.sub(r'lengthtable\[key\]', r'4', line) + line = re.sub(r'lengthtable\[key\]', r'sizeof(void *)', line) # Empty wordlist entries to have NULLs instead of "" line = re.sub(r'[{]["]["][}]', r'{}', line)