2
2
# Copyright 2023 The ChromiumOS Authors
3
3
# SPDX-License-Identifier: Apache-2.0
4
4
import ctypes
5
+ import os
5
6
import sys
6
7
import mmap
7
8
import time
@@ -61,7 +62,8 @@ def mappings():
61
62
maps = { n : (regs [2 * i ], regs [2 * i + 1 ]) for i , n in enumerate (rnames ) }
62
63
for i , ph in enumerate (struct .unpack (">II" , readfile (path + "memory-region" ))):
63
64
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 :
65
67
(addr , sz ) = struct .unpack (">QQ" , readfile (rmem + "reg" ))
66
68
maps [f"dram{ i } " ] = (addr , sz )
67
69
break
@@ -80,6 +82,9 @@ def __init__(self, maps):
80
82
r .freeze ()
81
83
self .cfg = r
82
84
85
+ def logrange (self ):
86
+ return range (0x700000 , 0x800000 )
87
+
83
88
def stop (self ):
84
89
self .cfg .RESET_SW |= 8 # Set RUNSTALL: halt CPU
85
90
self .cfg .RESET_SW |= 3 # Set low two bits: "BRESET|DRESET"
@@ -106,6 +111,9 @@ def __init__(self, maps):
106
111
self .sec .ALTVECSEL = 0x0c
107
112
self .sec .freeze ()
108
113
114
+ def logrange (self ):
115
+ return range (0x700000 , 0x800000 )
116
+
109
117
def stop (self ):
110
118
self .cfg .IO_CONFIG |= (1 << 31 ) # Set RUNSTALL to stop core
111
119
time .sleep (0.1 )
@@ -125,10 +133,10 @@ def start(self, boot_vector):
125
133
# stream at 0x60700000 -- the top of the linkable region of
126
134
# existing SOF firmware, before the heap. Nothing uses this
127
135
# currently. Will be replaced by winstream very soon.
128
- def log ():
136
+ def log (dev ):
129
137
msg = b''
130
138
dram = maps ["dram1" ]
131
- for i in range ( 0x700000 , 0x800000 ):
139
+ for i in dev . logrange ( ):
132
140
x = dram [i ]
133
141
if x == 0 :
134
142
sys .stdout .buffer .write (msg )
@@ -210,10 +218,10 @@ def main():
210
218
for i in range (len (dram ), mmio ["dram1" ][1 ]):
211
219
maps ["dram1" ][i ] = 0
212
220
dev .start (boot_vector )
213
- log ()
221
+ log (dev )
214
222
215
223
elif sys .argv [1 ] == "log" :
216
- log ()
224
+ log (dev )
217
225
218
226
elif sys .argv [1 ] == "dump" :
219
227
sz = mmio [sys .argv [2 ]][1 ]
0 commit comments