soc/mtk_adsp: Update gen_img.py address space rules
New platform has different mappings. Auto-detect rather than parse dts or similar, as this is is really just a simple format for testing. Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
parent
3c0269f4f6
commit
e35de00f86
2 changed files with 23 additions and 14 deletions
|
@ -21,9 +21,6 @@ import elftools.elf.sections
|
||||||
|
|
||||||
FILE_MAGIC = 0xe463be95
|
FILE_MAGIC = 0xe463be95
|
||||||
|
|
||||||
DRAM_START = 0x60000000
|
|
||||||
DRAM_END = 0x61100000
|
|
||||||
|
|
||||||
elf_file = sys.argv[1]
|
elf_file = sys.argv[1]
|
||||||
out_file = sys.argv[2]
|
out_file = sys.argv[2]
|
||||||
|
|
||||||
|
@ -32,7 +29,6 @@ ef = elftools.elf.elffile.ELFFile(open(elf_file, "rb"))
|
||||||
sram = bytearray()
|
sram = bytearray()
|
||||||
dram = bytearray()
|
dram = bytearray()
|
||||||
|
|
||||||
|
|
||||||
# Returns the offset of a segment within the sram region, or -1 if it
|
# Returns the offset of a segment within the sram region, or -1 if it
|
||||||
# doesn't appear to be SRAM. SRAM is mapped differently for different
|
# doesn't appear to be SRAM. SRAM is mapped differently for different
|
||||||
# SOCs, but it's always a <=1M region in 0x4xxxxxxx. Just use what we
|
# SOCs, but it's always a <=1M region in 0x4xxxxxxx. Just use what we
|
||||||
|
@ -50,16 +46,24 @@ def sram_off(addr):
|
||||||
assert off < 0x100000
|
assert off < 0x100000
|
||||||
return off
|
return off
|
||||||
|
|
||||||
|
# Similar heuristics: current platforms put DRAM either at 0x60000000
|
||||||
|
# or 0x90000000 with no more than 16M of range
|
||||||
|
def dram_off(addr):
|
||||||
|
if (addr >> 28 not in [6, 9]) or (addr & 0x0f000000 != 0):
|
||||||
|
return -1
|
||||||
|
return addr & 0xffffff
|
||||||
|
|
||||||
for seg in ef.iter_segments():
|
for seg in ef.iter_segments():
|
||||||
h = seg.header
|
h = seg.header
|
||||||
if h.p_type == "PT_LOAD":
|
if h.p_type == "PT_LOAD":
|
||||||
soff = sram_off(h.p_paddr)
|
soff = sram_off(h.p_paddr)
|
||||||
|
doff = dram_off(h.p_paddr)
|
||||||
if soff >= 0:
|
if soff >= 0:
|
||||||
buf = sram
|
buf = sram
|
||||||
off = soff
|
off = soff
|
||||||
elif h.p_paddr in range(DRAM_START, DRAM_END):
|
elif doff >= 0:
|
||||||
buf = dram
|
buf = dram
|
||||||
off = h.p_paddr - DRAM_START
|
off = doff
|
||||||
else:
|
else:
|
||||||
print(f"Invalid PT_LOAD address {h.p_paddr:x}")
|
print(f"Invalid PT_LOAD address {h.p_paddr:x}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -79,9 +83,6 @@ for sec in ef.iter_sections():
|
||||||
if sym.name == "mtk_adsp_boot_entry":
|
if sym.name == "mtk_adsp_boot_entry":
|
||||||
boot_vector = sym.entry['st_value']
|
boot_vector = sym.entry['st_value']
|
||||||
|
|
||||||
assert len(dram) < DRAM_END - DRAM_START
|
|
||||||
assert (sram_off(boot_vector) >= 0) or (DRAM_START <= boot_vector < DRAM_END)
|
|
||||||
|
|
||||||
of = open(out_file, "wb")
|
of = open(out_file, "wb")
|
||||||
of.write(struct.pack("<III", FILE_MAGIC, len(sram), boot_vector))
|
of.write(struct.pack("<III", FILE_MAGIC, len(sram), boot_vector))
|
||||||
of.write(sram)
|
of.write(sram)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# Copyright 2023 The ChromiumOS Authors
|
# Copyright 2023 The ChromiumOS Authors
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
import ctypes
|
import ctypes
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import mmap
|
import mmap
|
||||||
import time
|
import time
|
||||||
|
@ -61,7 +62,8 @@ def mappings():
|
||||||
maps = { n : (regs[2*i], regs[2*i+1]) for i, n in enumerate(rnames) }
|
maps = { n : (regs[2*i], regs[2*i+1]) for i, n in enumerate(rnames) }
|
||||||
for i, ph in enumerate(struct.unpack(">II", readfile(path + "memory-region"))):
|
for i, ph in enumerate(struct.unpack(">II", readfile(path + "memory-region"))):
|
||||||
for rmem in glob("/proc/device-tree/reserved-memory/*/"):
|
for rmem in glob("/proc/device-tree/reserved-memory/*/"):
|
||||||
if struct.unpack(">I", readfile(rmem + "phandle"))[0] == ph:
|
phf = rmem + "phandle"
|
||||||
|
if os.path.exists(phf) and struct.unpack(">I", readfile(phf))[0] == ph:
|
||||||
(addr, sz) = struct.unpack(">QQ", readfile(rmem + "reg"))
|
(addr, sz) = struct.unpack(">QQ", readfile(rmem + "reg"))
|
||||||
maps[f"dram{i}"] = (addr, sz)
|
maps[f"dram{i}"] = (addr, sz)
|
||||||
break
|
break
|
||||||
|
@ -80,6 +82,9 @@ class MT8195():
|
||||||
r.freeze()
|
r.freeze()
|
||||||
self.cfg = r
|
self.cfg = r
|
||||||
|
|
||||||
|
def logrange(self):
|
||||||
|
return range(0x700000, 0x800000)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.cfg.RESET_SW |= 8 # Set RUNSTALL: halt CPU
|
self.cfg.RESET_SW |= 8 # Set RUNSTALL: halt CPU
|
||||||
self.cfg.RESET_SW |= 3 # Set low two bits: "BRESET|DRESET"
|
self.cfg.RESET_SW |= 3 # Set low two bits: "BRESET|DRESET"
|
||||||
|
@ -106,6 +111,9 @@ class MT818x():
|
||||||
self.sec.ALTVECSEL = 0x0c
|
self.sec.ALTVECSEL = 0x0c
|
||||||
self.sec.freeze()
|
self.sec.freeze()
|
||||||
|
|
||||||
|
def logrange(self):
|
||||||
|
return range(0x700000, 0x800000)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.cfg.IO_CONFIG |= (1<<31) # Set RUNSTALL to stop core
|
self.cfg.IO_CONFIG |= (1<<31) # Set RUNSTALL to stop core
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
@ -125,10 +133,10 @@ class MT818x():
|
||||||
# stream at 0x60700000 -- the top of the linkable region of
|
# stream at 0x60700000 -- the top of the linkable region of
|
||||||
# existing SOF firmware, before the heap. Nothing uses this
|
# existing SOF firmware, before the heap. Nothing uses this
|
||||||
# currently. Will be replaced by winstream very soon.
|
# currently. Will be replaced by winstream very soon.
|
||||||
def log():
|
def log(dev):
|
||||||
msg = b''
|
msg = b''
|
||||||
dram = maps["dram1"]
|
dram = maps["dram1"]
|
||||||
for i in range(0x700000, 0x800000):
|
for i in dev.logrange():
|
||||||
x = dram[i]
|
x = dram[i]
|
||||||
if x == 0:
|
if x == 0:
|
||||||
sys.stdout.buffer.write(msg)
|
sys.stdout.buffer.write(msg)
|
||||||
|
@ -210,10 +218,10 @@ def main():
|
||||||
for i in range(len(dram), mmio["dram1"][1]):
|
for i in range(len(dram), mmio["dram1"][1]):
|
||||||
maps["dram1"][i] = 0
|
maps["dram1"][i] = 0
|
||||||
dev.start(boot_vector)
|
dev.start(boot_vector)
|
||||||
log()
|
log(dev)
|
||||||
|
|
||||||
elif sys.argv[1] == "log":
|
elif sys.argv[1] == "log":
|
||||||
log()
|
log(dev)
|
||||||
|
|
||||||
elif sys.argv[1] == "dump":
|
elif sys.argv[1] == "dump":
|
||||||
sz = mmio[sys.argv[2]][1]
|
sz = mmio[sys.argv[2]][1]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue