Skip to content

Commit e35de00

Browse files
andyrosskartben
authored andcommitted
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 <[email protected]>
1 parent 3c0269f commit e35de00

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

soc/mediatek/mt8xxx/gen_img.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
FILE_MAGIC = 0xe463be95
2323

24-
DRAM_START = 0x60000000
25-
DRAM_END = 0x61100000
26-
2724
elf_file = sys.argv[1]
2825
out_file = sys.argv[2]
2926

@@ -32,7 +29,6 @@
3229
sram = bytearray()
3330
dram = bytearray()
3431

35-
3632
# Returns the offset of a segment within the sram region, or -1 if it
3733
# doesn't appear to be SRAM. SRAM is mapped differently for different
3834
# SOCs, but it's always a <=1M region in 0x4xxxxxxx. Just use what we
@@ -50,16 +46,24 @@ def sram_off(addr):
5046
assert off < 0x100000
5147
return off
5248

49+
# Similar heuristics: current platforms put DRAM either at 0x60000000
50+
# or 0x90000000 with no more than 16M of range
51+
def dram_off(addr):
52+
if (addr >> 28 not in [6, 9]) or (addr & 0x0f000000 != 0):
53+
return -1
54+
return addr & 0xffffff
55+
5356
for seg in ef.iter_segments():
5457
h = seg.header
5558
if h.p_type == "PT_LOAD":
5659
soff = sram_off(h.p_paddr)
60+
doff = dram_off(h.p_paddr)
5761
if soff >= 0:
5862
buf = sram
5963
off = soff
60-
elif h.p_paddr in range(DRAM_START, DRAM_END):
64+
elif doff >= 0:
6165
buf = dram
62-
off = h.p_paddr - DRAM_START
66+
off = doff
6367
else:
6468
print(f"Invalid PT_LOAD address {h.p_paddr:x}")
6569
sys.exit(1)
@@ -79,9 +83,6 @@ def sram_off(addr):
7983
if sym.name == "mtk_adsp_boot_entry":
8084
boot_vector = sym.entry['st_value']
8185

82-
assert len(dram) < DRAM_END - DRAM_START
83-
assert (sram_off(boot_vector) >= 0) or (DRAM_START <= boot_vector < DRAM_END)
84-
8586
of = open(out_file, "wb")
8687
of.write(struct.pack("<III", FILE_MAGIC, len(sram), boot_vector))
8788
of.write(sram)

soc/mediatek/mt8xxx/mtk_adsp_load.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2023 The ChromiumOS Authors
33
# SPDX-License-Identifier: Apache-2.0
44
import ctypes
5+
import os
56
import sys
67
import mmap
78
import time
@@ -61,7 +62,8 @@ def mappings():
6162
maps = { n : (regs[2*i], regs[2*i+1]) for i, n in enumerate(rnames) }
6263
for i, ph in enumerate(struct.unpack(">II", readfile(path + "memory-region"))):
6364
for rmem in glob("/proc/device-tree/reserved-memory/*/"):
64-
if struct.unpack(">I", readfile(rmem + "phandle"))[0] == ph:
65+
phf = rmem + "phandle"
66+
if os.path.exists(phf) and struct.unpack(">I", readfile(phf))[0] == ph:
6567
(addr, sz) = struct.unpack(">QQ", readfile(rmem + "reg"))
6668
maps[f"dram{i}"] = (addr, sz)
6769
break
@@ -80,6 +82,9 @@ def __init__(self, maps):
8082
r.freeze()
8183
self.cfg = r
8284

85+
def logrange(self):
86+
return range(0x700000, 0x800000)
87+
8388
def stop(self):
8489
self.cfg.RESET_SW |= 8 # Set RUNSTALL: halt CPU
8590
self.cfg.RESET_SW |= 3 # Set low two bits: "BRESET|DRESET"
@@ -106,6 +111,9 @@ def __init__(self, maps):
106111
self.sec.ALTVECSEL = 0x0c
107112
self.sec.freeze()
108113

114+
def logrange(self):
115+
return range(0x700000, 0x800000)
116+
109117
def stop(self):
110118
self.cfg.IO_CONFIG |= (1<<31) # Set RUNSTALL to stop core
111119
time.sleep(0.1)
@@ -125,10 +133,10 @@ def start(self, boot_vector):
125133
# stream at 0x60700000 -- the top of the linkable region of
126134
# existing SOF firmware, before the heap. Nothing uses this
127135
# currently. Will be replaced by winstream very soon.
128-
def log():
136+
def log(dev):
129137
msg = b''
130138
dram = maps["dram1"]
131-
for i in range(0x700000, 0x800000):
139+
for i in dev.logrange():
132140
x = dram[i]
133141
if x == 0:
134142
sys.stdout.buffer.write(msg)
@@ -210,10 +218,10 @@ def main():
210218
for i in range(len(dram), mmio["dram1"][1]):
211219
maps["dram1"][i] = 0
212220
dev.start(boot_vector)
213-
log()
221+
log(dev)
214222

215223
elif sys.argv[1] == "log":
216-
log()
224+
log(dev)
217225

218226
elif sys.argv[1] == "dump":
219227
sz = mmio[sys.argv[2]][1]

0 commit comments

Comments
 (0)