4
4
import subprocess
5
5
import shutil
6
6
import shlex
7
+ import glob
7
8
import time
8
9
import math
9
10
import sys
16
17
except :
17
18
pass
18
19
19
- DEFAULT_TARGET = os .getenv ("RG_TOOL_TARGET" , "odroid-go" )
20
+ TARGETS = ["odroid-go" , "mrgc-g32" , "qtpy-gamer" ]
21
+ for t in glob .glob ("components/retro-go/targets/*.h" ):
22
+ TARGETS .append (os .path .basename (t )[0 :- 2 ])
23
+
24
+ DEFAULT_TARGET = os .getenv ("RG_TOOL_TARGET" , TARGETS [0 ])
20
25
DEFAULT_BAUD = os .getenv ("RG_TOOL_BAUD" , "1152000" )
21
26
DEFAULT_PORT = os .getenv ("RG_TOOL_PORT" , "COM3" )
22
27
PROJECT_NAME = os .getenv ("PROJECT_NAME" , "Retro-Go" ) # os.path.basename(os.getcwd()).title()
@@ -120,8 +125,8 @@ def analyze_profile(frames):
120
125
debug_print ("" )
121
126
122
127
123
- def build_firmware (targets , device_type ):
124
- print ("Building firmware with: %s\n " % " " .join (targets ))
128
+ def build_firmware (apps , device_type ):
129
+ print ("Building firmware with: %s\n " % " " .join (apps ))
125
130
args = [
126
131
sys .executable ,
127
132
"tools/mkfw.py" ,
@@ -133,16 +138,16 @@ def build_firmware(targets, device_type):
133
138
if device_type in ["mrgc-g32" , "esplay" ]:
134
139
args .append ("--esplay" )
135
140
136
- for target in targets :
137
- part = PROJECT_APPS [target ]
138
- args += [str (part [0 ]), str (part [1 ]), str (part [2 ]), target , os .path .join (target , "build" , target + ".bin" )]
141
+ for app in apps :
142
+ part = PROJECT_APPS [app ]
143
+ args += [str (part [0 ]), str (part [1 ]), str (part [2 ]), app , os .path .join (app , "build" , app + ".bin" )]
139
144
140
145
print ("Running: %s" % ' ' .join (shlex .quote (arg ) for arg in args [1 :]))
141
146
subprocess .run (args , check = True )
142
147
143
148
144
- def build_image (targets , device_type ):
145
- print ("Building image with: %s\n " % " " .join (targets ))
149
+ def build_image (apps , device_type ):
150
+ print ("Building image with: %s\n " % " " .join (apps ))
146
151
image_file = ("%s_%s_%s.img" % (PROJECT_NAME , PROJECT_VER , device_type )).lower ()
147
152
image_data = bytearray (b"\xFF " * 0x10000 )
148
153
table_ota = 0
@@ -152,17 +157,17 @@ def build_image(targets, device_type):
152
157
"phy_init, data, phy, 61440, 4096" ,
153
158
]
154
159
155
- for target in targets :
156
- part = PROJECT_APPS [target ]
157
- with open (os .path .join (target , "build" , target + ".bin" ), "rb" ) as f :
160
+ for app in apps :
161
+ part = PROJECT_APPS [app ]
162
+ with open (os .path .join (app , "build" , app + ".bin" ), "rb" ) as f :
158
163
data = f .read ()
159
164
part_size = max (part [2 ], math .ceil (len (data ) / 0x10000 ) * 0x10000 )
160
- table_csv .append ("%s, app, ota_%d, %d, %d" % (target , table_ota , len (image_data ), part_size ))
165
+ table_csv .append ("%s, app, ota_%d, %d, %d" % (app , table_ota , len (image_data ), part_size ))
161
166
table_ota += 1
162
167
image_data += data + b"\xFF " * (part_size - len (data ))
163
168
164
169
try :
165
- cwd = os .path .join (os .getcwd (), list (targets )[0 ])
170
+ cwd = os .path .join (os .getcwd (), list (apps )[0 ])
166
171
subprocess .run ("idf.py bootloader" , stdout = subprocess .DEVNULL , shell = True , check = True , cwd = cwd )
167
172
with open (os .path .join (cwd , "build" , "bootloader" , "bootloader.bin" ), "rb" ) as f :
168
173
bootloader_bin = f .read ()
@@ -182,32 +187,32 @@ def build_image(targets, device_type):
182
187
print ("Saved image '%s' (%d bytes)\n " % (image_file , len (image_data )))
183
188
184
189
185
- def clean_app (target ):
186
- print ("Cleaning up app '%s'..." % target )
190
+ def clean_app (app ):
191
+ print ("Cleaning up app '%s'..." % app )
187
192
try :
188
- os .unlink (os .path .join (target , "sdkconfig" ))
189
- os .unlink (os .path .join (target , "sdkconfig.old" ))
193
+ os .unlink (os .path .join (app , "sdkconfig" ))
194
+ os .unlink (os .path .join (app , "sdkconfig.old" ))
190
195
except :
191
196
pass
192
197
try :
193
- shutil .rmtree (os .path .join (target , "build" ))
198
+ shutil .rmtree (os .path .join (app , "build" ))
194
199
except :
195
200
pass
196
201
print ("Done.\n " )
197
202
198
203
199
- def build_app (target , device_type , with_profiling = False , with_netplay = False ):
204
+ def build_app (app , device_type , with_profiling = False , with_netplay = False ):
200
205
# To do: clean up if any of the flags changed since last build
201
- print ("Building app '%s'" % target )
206
+ print ("Building app '%s'" % app )
202
207
os .putenv ("ENABLE_PROFILING" , "1" if with_profiling else "0" )
203
208
os .putenv ("ENABLE_NETPLAY" , "1" if with_netplay else "0" )
204
209
os .putenv ("PROJECT_VER" , PROJECT_VER )
205
210
os .putenv ("RG_TARGET" , re .sub (r'[^A-Z0-9]' , '_' , device_type .upper ()))
206
- subprocess .run ("idf.py app" , shell = True , check = True , cwd = os .path .join (os .getcwd (), target ))
211
+ subprocess .run ("idf.py app" , shell = True , check = True , cwd = os .path .join (os .getcwd (), app ))
207
212
208
213
try :
209
214
print ("\n Patching esp_image_header_t to skip sha256 on boot... " , end = "" )
210
- with open (os .path .join (target , "build" , target + ".bin" ), "r+b" ) as fp :
215
+ with open (os .path .join (app , "build" , app + ".bin" ), "r+b" ) as fp :
211
216
fp .seek (23 )
212
217
fp .write (b"\0 " )
213
218
print ("done!\n " )
@@ -216,10 +221,10 @@ def build_app(target, device_type, with_profiling=False, with_netplay=False):
216
221
pass
217
222
218
223
219
- def monitor_app (target , port , baudrate = 115200 ):
220
- print ("Starting monitor for app '%s'" % target )
224
+ def monitor_app (app , port , baudrate = 115200 ):
225
+ print ("Starting monitor for app '%s'" % app )
221
226
mon = serial .Serial (port , baudrate = baudrate , timeout = 0 )
222
- elf = os .path .join (target , "build" , target + ".elf" )
227
+ elf = os .path .join (app , "build" , app + ".elf" )
223
228
224
229
mon .setDTR (False )
225
230
mon .setRTS (False )
@@ -287,7 +292,7 @@ def monitor_app(target, port, baudrate=115200):
287
292
"apps" , nargs = "*" , default = "all" , choices = ["all" ] + list (PROJECT_APPS .keys ())
288
293
)
289
294
parser .add_argument (
290
- "--target" , default = DEFAULT_TARGET , choices = [ "odroid-go" , "esp32s2" , "mrgc-g32" , "qtpy-gamer" ] , help = "Device to target"
295
+ "--target" , default = DEFAULT_TARGET , choices = set ( TARGETS ) , help = "Device to target"
291
296
)
292
297
parser .add_argument (
293
298
"--with-netplay" , action = "store_const" , const = True , help = "Build with netplay enabled"
0 commit comments