-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
executable file
·596 lines (498 loc) · 24.6 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
#!/usr/bin/python3
import os
import subprocess
import re
import pfw.console
import pfw.shell
import configuration
import pfw.linux.gdb
import qemu
def mkimage( projects_map: dict ):
mkimage_tool = projects_map["uboot"].mkimage
mkimage_tool(
projects_map["kernel"].dirs( ).deploy( "Image" ), "kernel"
, compression = "none", load_addr = "0x53000000"
)
mkimage_tool(
projects_map["xen"].dirs( ).deploy( "boot/xen-" + projects_map["xen"].version( ) ), "kernel"
, compression = "none", load_addr = "0x53000000"
)
mkimage_tool(
projects_map["buildroot"].dirs( ).deploy( "rootfs.ext2" ), "filesystem"
, compression = "none", load_addr = "0x55000000"
)
mkimage_tool(
projects_map["buildroot"].dirs( ).deploy( "rootfs.cpio" ), "ramdisk"
, compression = "none", load_addr = "0x55000000"
)
mkimage_tool(
projects_map["busybox"].dirs( ).deploy( "initramfs.cpio" ), "ramdisk"
, compression = "none", load_addr = "0x55000000"
)
mkimage_tool(
projects_map["busybox"].dirs( ).deploy( "initramfs.cpio.gz" ), "ramdisk"
, compression = "gzip", load_addr = "0x55000000"
)
mkimage_tool(
configuration.value( "uboot_script" ), "script"
, compression = "none", load_addr = "0x65000000"
)
# def mkimage
def mkbootimg( projects_map: dict ):
mkbootimg_tool = projects_map["aosp"].create_android_boot_image
cmdline = qemu.build_kernel_parameters( arch = projects_map["aosp"].config( ).arch( ), debug = True )
# cmdline += " root=/dev/ram rw"
mkbootimg_tool(
header_version = 2,
kernel = projects_map["kernel"].dirs( ).deploy( "Image" ),
ramdisk = projects_map["buildroot"].dirs( ).deploy( "rootfs.cpio" ),
dtb = configuration.value( "dtb_export_path" ),
cmdline = cmdline,
out = os.path.join( configuration.value( "tmp_path" ), "boot_linux.img" ),
base = 0x50000000,
kernel_offset = 0x3000000,
ramdisk_offset = 0x6000000,
dtb_offset = 0x00000000,
)
mkbootimg_tool(
header_version = 2,
kernel = projects_map["aosp"].dirs( ).product( "kernel"),
ramdisk = projects_map["aosp"].dirs( ).experimental( "ramdisk.img"),
dtb = configuration.value( "dtb_export_path" ),
cmdline = cmdline,
out = os.path.join( configuration.value( "tmp_path" ), "boot_aosp.img" ),
base = 0x50000000,
kernel_offset = 0x3000000,
ramdisk_offset = 0x6000000,
dtb_offset = 0x00000000,
)
# def mkbootimg
def prepare_boot( projects_map: dict ):
projects_map["uboot"].build_uboot_script( configuration.value( "uboot_script_source" ), configuration.value( "uboot_script" ) )
mkimage( projects_map )
bootconfig_file: str = None
if projects_map["aosp"].config( ).arch( ) in [ "x86", "x86_64" ]:
bootconfig_file = configuration.value( "android_bootconfig_x86" )
elif projects_map["aosp"].config( ).arch( ) in [ "arm64", "aarch64" ]:
bootconfig_file = configuration.value( "android_bootconfig_arm64" )
projects_map["aosp"].build_ramdisk(
bootconfig = { "tool": projects_map["kernel"].bootconfig, "config": bootconfig_file }
)
mkbootimg( projects_map )
# def prepare_boot
def deploy_boot( projects_map: dict, mount_point: str, pause: bool = False ):
files_list: list = [
# {
# "src": configuration.value( "syslinux_script" ),
# "dest": os.path.join( mount_point, "boot/extlinux/extlinux.conf" )
# },
{
"src": configuration.value( "uboot_script" ) + ".uimg",
"dest": os.path.join( mount_point, "boot/boot.scr" )
},
{
"src": configuration.value( "dtb_export_path" ),
"dest": os.path.join( mount_point, "boot/export.dtb" )
},
{
"src": configuration.value( "dtb_dump_path" ),
"dest": os.path.join( mount_point, "boot/dump.dtb" )
},
{
"src": projects_map["kernel"].dirs( ).deploy( "Image" ),
"dest": os.path.join( mount_point, "boot/kernel-" + projects_map["kernel"].version( ) )
},
{
"src": projects_map["kernel"].dirs( ).deploy( "Image.uimg" ),
"dest": os.path.join( mount_point, "boot/kernel-" + projects_map["kernel"].version( ) + ".uimg" )
},
{
"src": projects_map["xen"].dirs( ).deploy( "boot/xen-" + projects_map["xen"].version( ) ),
"dest": os.path.join( mount_point, "boot/xen-" + projects_map["xen"].version( ) )
},
{
"src": projects_map["xen"].dirs( ).deploy( "boot/xen-" + projects_map["xen"].version( ) + ".uimg" ),
"dest": os.path.join( mount_point, "boot/xen-" + projects_map["xen"].version( ) + ".uimg" )
},
{
"src": projects_map["buildroot"].dirs( ).deploy( "rootfs.cpio" ),
"dest": os.path.join( mount_point, "boot/rootfs-" + projects_map["buildroot"].version( ) + ".cpio" )
},
{
"src": projects_map["buildroot"].dirs( ).deploy( "rootfs.cpio.uimg" ),
"dest": os.path.join( mount_point, "boot/rootfs-" + projects_map["buildroot"].version( ) + ".cpio.uimg" )
},
{
"src": projects_map["busybox"].dirs( ).deploy( "initramfs.cpio" ),
"dest": os.path.join( mount_point, "boot/initramfs-" + projects_map["busybox"].version( ) + ".cpio" )
},
{
"src": projects_map["busybox"].dirs( ).deploy( "initramfs.cpio.uimg" ),
"dest": os.path.join( mount_point, "boot/initramfs-" + projects_map["busybox"].version( ) + ".cpio.uimg" )
},
{
"src": os.path.join( configuration.value( "tmp_path" ), "boot_linux.img" ),
"dest": os.path.join( mount_point, "boot/boot_linux.img" )
},
{
"src": os.path.join( configuration.value( "tmp_path" ), "boot_aosp.img" ),
"dest": os.path.join( mount_point, "boot/boot_aosp.img" )
},
]
for item in files_list:
if False == os.path.exists( item["src"] ):
pfw.console.debug.warning( "file does not exist: ", item["src"] )
continue
pfw.shell.execute( "sudo mkdir -p " + os.path.dirname( item["dest"] ), output = pfw.shell.eOutput.PTY )
pfw.console.debug.trace( "file: '%s' ->\n '%s'" % ( item["src"], item["dest"] ) )
pfw.shell.execute( f"sudo cp " + item["src"] + " " + item["dest"], output = pfw.shell.eOutput.PTY )
if True == pause:
subprocess.Popen(['xdg-open', mount_point])
pfw.console.debug.promt( )
# def deploy_boot
def mkpartition_boot( projects_map: dict ):
mmc: pfw.linux.image2.Partition = pfw.linux.image2.Partition( configuration.value( "boot_partition_image" ), build = True, force = True )
mount_point = mmc.mount( configuration.value( "tmp_path" ), True )
prepare_boot( projects_map )
deploy_boot( projects_map, mount_point, pause = False )
mmc.info( )
mmc.umount( )
# def mkpartition_boot
def mkpartition_rootfs( projects_map: dict ):
rootfs_project = projects_map["rootfs"]
rootfs_project.init( )
rootfs_project.execute( f"mkdir /projects" )
rootfs_project.execute( f"git clone https://xenbits.xen.org/git-http/xen.git /projects/xen" )
rootfs_project.execute( f"cd /projects/xen; git checkout origin/stable-4.15 --track" )
rootfs_project.execute( f"cd /projects/xen; ./configure --disable-docs --disable-stubdom --prefix=/usr/local --libdir=/usr/lib --enable-systemd" )
rootfs_project.execute( f"cd /projects/xen; CC=gcc make -j4 debball" )
rootfs_project.deinit( )
if True == pause:
subprocess.Popen(['xdg-open', mount_point])
pfw.console.debug.promt( )
# def mkpartition_rootfs
def mkdrive_linux( projects_map: dict ):
mkpartition_boot( projects_map )
boot_image = configuration.value( "boot_partition_image" ).file( )
# mkpartition_rootfs( projects_map )
# rootfs_image = projects_map["rootfs"].dirs( ).build( "rootfs.img" )
super_image = projects_map["aosp"].dirs( ).product( "super.img" )
if "arm64" == projects_map["aosp"].config( ).arch( ):
super_image = projects_map["aosp"].dirs( ).experimental( "super.raw" )
projects_map["aosp"].simg_to_img( projects_map["aosp"].dirs( ).product( "super.img" ), super_image )
userdata_image = projects_map["aosp"].dirs( ).product( "userdata.img" )
if "arm64" == projects_map["aosp"].config( ).arch( ):
userdata_image = projects_map["aosp"].dirs( ).experimental( "userdata.raw" )
projects_map["aosp"].simg_to_img( projects_map["aosp"].dirs( ).product( "userdata.img" ), userdata_image )
vbmeta_image = projects_map["aosp"].dirs( ).product( "vbmeta.img" )
vbmeta_system_image = projects_map["aosp"].dirs( ).product( "vbmeta_system.img" )
boot_part_num = 1
partitions = [
pfw.linux.image2.Partition.Description( clone_from = boot_image, label = "boot" ),
# pfw.linux.image2.Partition.Description( clone_from = rootfs_image, label = "rootfs" ),
pfw.linux.image2.Partition.Description( clone_from = super_image, label = "super" ),
pfw.linux.image2.Partition.Description( clone_from = userdata_image, label = "userdata" ),
pfw.linux.image2.Partition.Description( size = pfw.size.SizeGigabyte, label = "cache", fs = "ext4" ),
pfw.linux.image2.Partition.Description( size = pfw.size.SizeGigabyte, label = "metadata", fs = "ext4" ),
pfw.linux.image2.Partition.Description( size = pfw.size.SizeGigabyte, label = "misc", fs = "ext4" ),
pfw.linux.image2.Partition.Description( clone_from = vbmeta_image, label = "vbmeta_a" ),
pfw.linux.image2.Partition.Description( clone_from = vbmeta_system_image, label = "vbmeta_system_a" ),
]
mmc: pfw.linux.image2.Drive = pfw.linux.image2.Drive( configuration.value( "main_drive_image" ) )
mmc.build( partitions, force = True, bootable = boot_part_num )
# def mkdrive_linux
def mkdrive_android( projects_map: dict ):
boot_image = projects_map["aosp"].dirs( ).product( "boot.img" )
vendor_boot_image = projects_map["aosp"].dirs( ).product( "vendor_boot.img" )
bootconfig_image = projects_map["aosp"].dirs( ).product( "vendor-bootconfig.img" )
system_image = projects_map["aosp"].dirs( ).product( "system.img" )
super_image = projects_map["aosp"].dirs( ).product( "super.img" )
if "arm64" == projects_map["aosp"].config( ).arch( ):
super_image = projects_map["aosp"].dirs( ).experimental( "super.raw" )
projects_map["aosp"].simg_to_img( projects_map["aosp"].dirs( ).product( "super.img" ), super_image )
userdata_image = projects_map["aosp"].dirs( ).product( "userdata.img" )
if "arm64" == projects_map["aosp"].config( ).arch( ):
userdata_image = projects_map["aosp"].dirs( ).experimental( "userdata.raw" )
projects_map["aosp"].simg_to_img( projects_map["aosp"].dirs( ).product( "userdata.img" ), userdata_image )
vbmeta_image = projects_map["aosp"].dirs( ).product( "vbmeta.img" )
vbmeta_system_image = projects_map["aosp"].dirs( ).product( "vbmeta_system.img" )
device_0_partitions = [
pfw.linux.image2.Partition.Description( clone_from = boot_image, label = "boot_a" ),
pfw.linux.image2.Partition.Description( clone_from = boot_image, label = "boot_b" ),
pfw.linux.image2.Partition.Description( clone_from = vendor_boot_image, label = "vendor_boot_a" ),
pfw.linux.image2.Partition.Description( clone_from = vendor_boot_image, label = "vendor_boot_b" ),
# pfw.linux.image2.Partition.Description( size = pfw.size.SizeMegabyte, label = "init_boot_a" ),
# pfw.linux.image2.Partition.Description( size = pfw.size.SizeMegabyte, label = "init_boot_b" ),
pfw.linux.image2.Partition.Description( clone_from = vbmeta_image, label = "vbmeta_a" ),
pfw.linux.image2.Partition.Description( clone_from = vbmeta_image, label = "vbmeta_b" ),
pfw.linux.image2.Partition.Description( clone_from = vbmeta_system_image, label = "vbmeta_system_a" ),
pfw.linux.image2.Partition.Description( clone_from = vbmeta_system_image, label = "vbmeta_system_b" ),
pfw.linux.image2.Partition.Description( clone_from = bootconfig_image, label = "bootconfig" ),
pfw.linux.image2.Partition.Description( clone_from = super_image, label = "super" ),
pfw.linux.image2.Partition.Description( clone_from = system_image, label = "system_a" ),
pfw.linux.image2.Partition.Description( clone_from = userdata_image, label = "userdata" ),
pfw.linux.image2.Partition.Description( size = pfw.size.SizeGigabyte, label = "cache", fs = "ext4" ),
pfw.linux.image2.Partition.Description( size = pfw.size.SizeGigabyte, label = "metadata", fs = "ext4" ),
pfw.linux.image2.Partition.Description( size = pfw.size.SizeGigabyte, label = "misc", fs = "ext4" ),
pfw.linux.image2.Partition.Description( size = pfw.size.SizeMegabyte, label = "dummy" ),
]
device_0: pfw.linux.image2.Drive = pfw.linux.image2.Drive( configuration.value( "device_0_image" ) )
device_0.build( device_0_partitions, force = True )
device_1_partitions = [
pfw.linux.image2.Partition.Description( size = pfw.size.SizeMegabyte, label = "dummy" ),
]
device_1: pfw.linux.image2.Drive = pfw.linux.image2.Drive( configuration.value( "device_1_image" ) )
device_1.build( device_1_partitions, force = True )
# def mkdrive_android
def mkdrive( projects_map: dict ):
mkdrive_android( projects_map )
# def mkdrive
def debug( projects_map: dict, **kwargs ):
kw_project_name = kwargs.get( "project_name", "uboot" )
project = projects_map[ kw_project_name ]
if "uboot" == kw_project_name:
file = projects_map[ "uboot" ].dirs( ).product( "u-boot" )
arch = projects_map[ "uboot" ].config( ).arch( )
lib_path = projects_map[ "uboot" ].config( ).compiler_path( "lib" )
src_path = projects_map[ "uboot" ].dirs( ).source( )
pfw.linux.gdb.run(
# arch = arch,
file = file,
# lib_path = lib_path,
# src_path = src_path,
load_symbols = {
# file: [ 0x000000000 ], # in case of "u-boot" "x0" register when enter to "relocate_code" function
# file: [ 0x23ff03000 ], # u-boot v2021.10
file: [ 0x23ff03000 ], # u-boot v2022.07
# projects_map[ "kernel" ].dirs( ).deploy( "vmlinux" ): [ 0x40410800 ], # kernel 5.15 loaded to 0x40410800
# projects_map[ "kernel" ].dirs( ).deploy( "vmlinux" ): [ 0x53010000 ], # kernel 5.15 loaded to 0x40410800
},
break_names = [
### u-boot functions
# "relocate_code",
# "relocate_done",
# "do_bootm",
# "do_bootm_states",
# "bootm_find_other",
# "bootm_find_images",
# "boot_get_ramdisk",
# "select_ramdisk",
# "android_image_load",
# "android_bootloader_boot_kernel",
"boot_jump_linux",
"announce_and_cleanup",
"armv8_switch_to_el2",
### kernel functions
# "primary_entry",
# "__primary_switch",
# "__primary_switched",
# "start_kernel",
# "rest_init",
# "cpu_startup_entry"
],
break_addresses = [
],
break_code = {
# u-boot code
projects_map[ "uboot" ].dirs( ).source( "arch/arm/cpu/armv8/transition.S" ): [ 30 ]
# kernel code
},
none = None
)
elif "kernel" == kw_project_name:
pfw.linux.gdb.run(
# arch = project.config( ).arch( ),
file = project.dirs( ).deploy( "vmlinux" ),
break_names = [
"primary_entry",
"__primary_switch",
"__primary_switched",
"start_kernel",
"rest_init",
"cpu_startup_entry"
],
ex_list = [
# f"add-auto-load-safe-path {project.dirs( ).build( )}",
# f"add-auto-load-safe-path " + project.dirs( ).source( "scripts/gdb/vmlinux-gdb.py" ),
# f"source {project.dirs( ).build( 'vmlinux-gdb.py' )}",
],
none = None
)
# def debug
def build_emulator_parameters( projects_map, **kwargs ):
kw_drive = kwargs.get( "drive", None )
kw_arch = projects_map["aosp"].config( ).arch( )
kw_inet_dump = os.path.join( configuration.value( "tmp_path" ), "eth0_inet_dump_$(date '+%Y-%m-%d_%H:%M:%S').dat" )
# For using qemu-bridge-helper
# https://mike42.me/blog/2019-08-how-to-use-the-qemu-bridge-helper-on-debian-10
kw_qemu_bridge_helper = "/usr/lib/qemu/qemu-bridge-helper"
PARAMETERS = f""
PARAMETERS += f" -serial mon:stdio"
PARAMETERS += f" -nodefaults"
PARAMETERS += f" -no-reboot"
PARAMETERS += f" -d guest_errors"
if "x86" == kw_arch:
PARAMETERS = PARAMETERS + f" -enable-kvm"
PARAMETERS = PARAMETERS + f" -smp cores=2"
PARAMETERS = PARAMETERS + f" -m 8192"
elif "arm64" == kw_arch:
PARAMETERS = PARAMETERS + f" -machine virt"
# PARAMETERS = PARAMETERS + f" -machine virtualization=true"
PARAMETERS = PARAMETERS + f" -cpu cortex-a53"
PARAMETERS = PARAMETERS + f" -smp cores=4"
PARAMETERS = PARAMETERS + f" -m 8192"
IMAGE_DEVICES_MAIN = f"" \
+ f" -drive if=none,index=0,id=main,file={kw_drive}" \
+ f" -device virtio-blk-pci,modern-pio-notify=on,drive=main"
NETWORK_NETDEV_USER = f"" \
+ f" -netdev user,id=eth0_inet,hostfwd=tcp::5550-:5555,ipv6=off" \
+ f" -device virtio-net-pci,netdev=eth0_inet,id=android"
NETWORK_NETDEV_BRIDGE = f"" \
+ f" -netdev bridge,id=eth0_inet,br=virbr0,helper={kw_qemu_bridge_helper}" \
+ f" -device virtio-net-pci,netdev=eth0_inet,id=android"
NETWORK_NETDEV_TAP = f"" \
+ f" -netdev tap,id=eth0_inet,ifname=ethernet_tap,script=no,downscript=no,vhost=on" \
+ f" -device virtio-net-pci-non-transitional,netdev=eth0_inet,id=android"
NETWORK_OBJECT_DUMP = f"" \
+ f" -object filter-dump,id=f1,netdev=eth0_inet,file={kw_inet_dump}" \
NETWORK_NET_USER = f"" \
+ f" -net user" \
+ f" -net nic" \
NETWORK_NET_BRIDGE = f"" \
+ f" -net bridge,br=virbr0,helper={kw_qemu_bridge_helper}" \
+ f" -net nic,model=virtio"
PCI_KBD_MOUSE = f"" \
+ " -device virtio-keyboard-pci" \
+ " -device virtio-mouse-pci"
USB_BUS = f"" \
+ " -usb"
USB_KBD_MOUSE = f"" \
+ " -device usb-kbd" \
+ " -device usb-mouse"
GRAPHIC_DEVICES = f"" \
+ " -display gtk,gl=on,show-cursor=on" \
+ " -device virtio-gpu-gl-pci"
DEVICES_AUDIO_VIRTIO = f"" \
+ " -audiodev alsa,id=snd0,in.dev=default,out.dev=default" \
+ " -device virtio-snd-pci,disable-legacy=on,audiodev=snd0"
DEVICES_AUDIO_INTEL = f"" \
+ " -audiodev alsa,id=snd0,in.dev=default,out.dev=default" \
+ " -device intel-hda" \
+ " -device hda-duplex,audiodev=snd0"
CHAR_DEVICES = f"" \
+ " -device virtio-serial-pci,ioeventfd=off" \
+ " -chardev null,id=forhvc0" \
+ " -device virtconsole,chardev=forhvc0" \
+ " -chardev null,id=forhvc1" \
+ " -device virtconsole,chardev=forhvc1"
OTHER_DEVICES = f"" \
+ " -device nec-usb-xhci,id=xhci" \
+ " -device sdhci-pci" \
+ " -device virtio-rng-pci"
command: str = f" {PARAMETERS}"
command += f" {IMAGE_DEVICES_MAIN}"
command += f" {NETWORK_NETDEV_USER}"
command += f" {GRAPHIC_DEVICES}"
command += f" {DEVICES_AUDIO_VIRTIO}"
command += f" {PCI_KBD_MOUSE}"
# command += f" {USB_BUS}"
# command += f" {USB_KBD_MOUSE}"
# command += f" {CHAR_DEVICES}"
# command += f" {OTHER_DEVICES}"
return command
# def build_emulator_parameters
def start( projects_map: dict, **kwargs ):
kw_mode = kwargs.get( "mode", None )
kw_gdb = kwargs.get( "gdb", False )
kw_drive = kwargs.get( "drive", None )
kw_arch = kwargs.get( "arch", "arm64" )
if None == kw_drive:
if kw_mode in [ "u-boot", "kernel_rd", "aosp-uboot", "aosp-kernel" ]:
kw_drive = configuration.value( "main_drive_image" )
elif kw_mode in [ "kernel_rf" ]:
kw_drive = projects_map["rootfs"].dirs( ).build( "rootfs.img" )
else:
pass
command: str = ""
if kw_mode in [ "aosp-uboot", "aosp-kernel" ]:
command = build_emulator_parameters( projects_map, drive = kw_drive )
elif kw_mode in [ "u-boot", "kernel_rd", "kernel_rf" ]:
command = qemu.build_parameters( arch = kw_arch )
command += f" -drive if=none,index=0,id=main,file={kw_drive}"
command += f" -device virtio-blk-pci,modern-pio-notify,drive=main"
command += f" -netdev user,id=net0,hostfwd=tcp::2222-:22"
command += f" -device virtio-net-device,netdev=net0"
command += f" -device virtio-serial-pci"
command += f" -device nec-usb-xhci,id=xhci"
command += f" -device sdhci-pci"
command += f" -device virtio-rng-pci"
# vc_pipe = "/tmp/virtio_console_chardev.pipe"
# pfw.shell.execute( f"rm {vc_pipe}; mkfifo {vc_pipe}", output = pfw.shell.eOutput.PTY )
# pfw.shell.execute( f"rm {vc_pipe}.in; mkfifo {vc_pipe}.in", output = pfw.shell.eOutput.PTY )
# pfw.shell.execute( f"rm {vc_pipe}.out; mkfifo {vc_pipe}.out", output = pfw.shell.eOutput.PTY )
# command += f" -chardev pipe,id=virtio_console_chardev,path={vc_pipe}"
# command += f" -device virtconsole,chardev=virtio_console_chardev,id=virtio_console"
# command += f" -device virtio-gpu-pci"
# command += f" -device virtio-gpu-gl-pci"
# command += f" -display gtk,gl=on,show-cursor=on"
# command += f" -vga cirrus"
# command += f" -display gtk,show-cursor=on"
else:
pass
kw_args: dict = { }
kw_args["arch"] = kw_arch
kw_args["gdb"] = kw_gdb
if "aosp-uboot" == kw_mode:
if kw_arch in [ "x86", "x86_64" ]:
kw_args["bios"] = projects_map["uboot"].dirs( ).product( "u-boot.rom" )
elif kw_arch in [ "arm", "arm32", "arm64", "aarch64" ]:
kw_args["bios"] = projects_map["uboot"].dirs( ).product( "u-boot.bin" )
elif "aosp-kernel" == kw_mode:
kw_args["kernel"] = projects_map["aosp"].dirs( ).product( "kernel" )
kw_args["initrd"] = projects_map["aosp"].dirs( ).experimental( "ramdisk.img")
kw_args["append"] = "loglevel=7 debug printk.devkmsg=on drm.debug=0x1FF console=ttyAMA0 bootconfig"
kw_args["dtb"] = configuration.value( "dtb_export_path" )
elif "u-boot" == kw_mode:
if kw_arch in [ "x86", "x86_64" ]:
kw_args["bios"] = projects_map["uboot"].dirs( ).product( "u-boot.rom" )
elif kw_arch in [ "arm", "arm32", "arm64", "aarch64" ]:
kw_args["bios"] = projects_map["uboot"].dirs( ).product( "u-boot.bin" )
elif "kernel_rd" == kw_mode:
kw_args["kernel"] = projects_map["kernel"].dirs( ).deploy( "Image" )
kw_args["initrd"] = projects_map["buildroot"].dirs( ).deploy( "rootfs.cpio" )
kw_args["append"] = "loglevel=7 debug printk.devkmsg=on drm.debug=0x1FF console=ttyAMA0"
kw_args["dtb"] = configuration.value( "dtb_export_path" )
elif "kernel_rf" == kw_mode:
kw_args["kernel"] = projects_map["kernel"].dirs( ).deploy( "Image" )
kw_args["append"] = "loglevel=7 debug printk.devkmsg=on drm.debug=0x1FF console=ttyAMA0 init=/bin/bash root=/dev/vda rw"
kw_args["dtb"] = configuration.value( "dtb_export_path" )
else:
pass
qemu.run( command, **kw_args )
# def start
# u-boot: vexpress_ca9x4_defconfig
# kernel: vexpress_defconfig
# busybox: defconfig
# buildroot: qemu_arm_vexpress_defconfig
def run_vexpress_ca9x4( projects_map: dict, **kwargs ):
kw_partition = kwargs.get( "partition", None )
kw_drive = kwargs.get( "drive", None )
command: str = None
parameters: list = [ ]
QEMU_PATH=""
command = f"{QEMU_PATH}qemu-system-arm"
parameters.append( "-machine vexpress-a9" )
parameters.append( "-nographic" )
parameters.append( "-smp 1" )
parameters.append( "-m 256M" )
parameters.append( "-kernel " + os.path.join( projects_map["uboot"].dirs( ).product( ), "u-boot" ) )
parameters.append( "-sd " + kw_drive )
# parameters.append( "-hda " + kw_partition )
# parameters.append( "-drive file= " + kw_drive + ",if=sd,format=raw" )
# parameters.append( "-netdev user,id=eth0" )
# parameters.append( "-device virtio-net-device,netdev=eth0" )
# parameters.append( "-drive file=rootfs.ext4,if=none,format=raw,id=hd0" )
# parameters.append( "-device virtio-blk-device,drive=hd0" )
# parameters.append( "-s -S" )
pfw.shell.execute( command, args = parameters, output = pfw.shell.eOutput.PTY )
# run_vexpress_ca9x4