Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages Zircon's emulator needs (Include ZBI) #122

Open
elliott10 opened this issue Aug 1, 2020 · 0 comments
Open

Packages Zircon's emulator needs (Include ZBI) #122

elliott10 opened this issue Aug 1, 2020 · 0 comments
Labels
analysis Investigation and analysis

Comments

@elliott10
Copy link
Collaborator

elliott10 commented Aug 1, 2020

We know how to run Fuchsia to the graphical interface with emulator FEMU:

fuchsia/prebuilt/third_party/aemu/linux-x64/emulator \
-gpu swiftshader_indirect -fuchsia \
-kernel fuchsia/out/default/multiboot.bin -initrd /tmp/tmp_fuchsia/fuchsia-ssh.zbi -m 8192 -serial stdio \
-vga none -machine q35 -enable-kvm -net none \
-drive file=/tmp/tmp_fuchsia/fvm.blk,format=raw,if=none,id=vdisk -device virtio-blk-pci,drive=vdisk \
-append "kernel.serial=legacy"

Emulator needs a lot of file packages to start up the system: multiboot.bin, fvm.blk, fuchsia-ssh.zbi.
Let's explore how to generate these file packages.
By tracking Fuchsia's compilation, I figured it out.

Multiboot: fuchsia/out/default/multiboot.bin

Multiboot-compatible ELF kernel image. kernel bzImage type file

../../prebuilt/third_party/clang/linux-x64/bin/clang++ -o ./multiboot.bin.debug -Wl,-T,../../zircon/kernel/target/pc/multiboot/multiboot.ld -fuse-ld=lld -Wl,-z,combreloc -Wl,-z,relro -Wl,-z,now -Wl,-z,text -Wl,--pack-dyn-relocs=relr --target=x86_64-fuchsia -mcx16 -march=x86-64 -fcrash-diagnostics-dir=clang-crashreports -fcolor-diagnostics -Wl,--color-diagnostics -Wl,-z,max-page-size=4096 -fdebug-prefix-map=/mnt/SSD/xly/fuchsia/fuchsia/out/default.zircon=. -fdebug-prefix-map=/mnt/SSD/xly/fuchsia/fuchsia/out=.. -fdebug-prefix-map=/mnt/SSD/xly/fuchsia/fuchsia=../.. -no-canonical-prefixes -O2 -g3 -Wl,--icf=all -ffunction-sections -Wl,--gc-sections -fdata-sections -fno-exceptions -fno-rtti -m32 -mregparm=3 -fno-pic -Wl,--no-pie -nostdlib -static -Wl,--no-pie -noprofilelib -fno-sanitize-link-runtime -fno-exceptions -Wl,-Map,./multiboot.map -Wl,--start-group @'./multiboot.rsp'  -Wl,--end-group
|
V
../../prebuilt/third_party/clang/linux-x64/bin/llvm-objcopy --strip-sections  ./multiboot.bin.debug  ./multiboot.bin

Drive file: fvm.blk

fuchsia/out/default/obj/build/images/fvm.blk

host_x64/fvm obj/build/images/fvm.blk create --slice 8388608 --blob obj/build/images/blob.blk --data obj/build/images/data.blk

host_x64/blobfs --depfile --json-output blobs.json --compress obj/build/images/blob.blk create --manifest obj/build/images/blob.manifest
# blob.blk is blob type file, include files in the  blob.manifest

host_x64/minfs --depfile obj/build/images/data.blk create
# data.blk is empty, and it's encrypted data type

Ramdisk initrd: fuchsia-ssh.zbi

A Zircon Boot Image (ZBI) contains the kernel image and a RAM disk for the boot filesystem.

../../prebuilt/third_party/clang/linux-x64/bin/clang++ -o kernel-x64-clang/obj/kernel/image -Wl,-T,../../zircon/kernel/image.ld -Wl,--just-symbols,@kernel-x64-clang/gen/kernel/zircon.elf.rsp -fuse-ld=lld -Wl,-z,combreloc -Wl,-z,relro -Wl,-z,now -Wl,-z,text -Wl,--pack-dyn-relocs=relr --target=x86_64-fuchsia -mcx16 -march=x86-64 -fcrash-diagnostics-dir=clang-crashreports -fcolor-diagnostics -Wl,--color-diagnostics -Wl,-z,max-page-size=4096 -fdebug-prefix-map=fuchsia/out/default.zircon=. -fdebug-prefix-map=fuchsia/fuchsia/out=.. -fdebug-prefix-map=fuchsia=../.. -no-canonical-prefixes -O2 -g3 -Wl,--icf=all -fno-exceptions -fno-rtti -nostdlib -static -Wl,--no-pie -noprofilelib -fno-sanitize-link-runtime -fno-exceptions -fdata-sections -ffunction-sections -Wl,--gc-sections -fdata-sections -Wl,--build-id=none -Wl,-defsym,KERNEL_BASE=0xffffffff80100000 -Wl,-defsym,SMP_MAX_CPUS=32 -Wl,-defsym,BOOT_HEADER_SIZE=0x50 -Wl,-Map,kernel-x64-clang/obj/kernel/image.map -Wl,--start-group @'kernel-x64-clang/obj/kernel/image.rsp'  -Wl,--end-group 
# **Kernel** image
|
V
cd out/default.zircon ; ../../prebuilt/third_party/clang/linux-x64/bin/llvm-objcopy -O binary kernel-x64-clang/obj/kernel/image kernel-x64-clang/kernel.zbi
|
V
# kernel.zbi and files in various manifests and some specific files with --entry parameter
|
V
host_x64/zbi --output=fuchsia.zbi --depfile=fuchsia.zbi.d --complete=x64 --compressed=zstd obj/build/images/boot.manifest ../default.zircon/kernel-x64-clang/kernel.zbi obj/src/devices/bin/driver_manager/driver_manager.manifest obj/src/devices/devices.manifest obj/src/power/shutdown-shim/shutdown-shim.manifest obj/src/sys/bootstrap/root_manifests.manifest obj/src/sys/component_manager/component_manager_bootfs.manifest obj/src/security/policy/component_manager_policy.manifest --entry=config/devmgr=obj/build/images/devmgr_config.txt --entry=config/zxcrypt=obj/build/images/zxcrypt_config.txt --type=cmdline --entry=console.shell=true --entry=kernel.enable-debugging-syscalls=true --entry=kernel.enable-serial-syscalls=true --entry=netsvc.all-features=true --entry=netsvc.disable=false --entry=kernel.oom.behavior=reboot --entry=virtcon.hide-on-boot
# fuchsia/out/default/fuchsia.zbi

ZBI package

How to show contents of a zbi package:

host_x64/zbi -t -v input.zbi

How to decompless a zbi package:

host_x64/zbi --extract --output-dir=obj/build/images/fuchsia.zbi/bootfs --json-output=fuchsia.zbi.json fuchsia.zbi
# OR
host_x64/zbi -x -D fuchsia.zbi/bootfs input_fuchsia.zbi

How to merge a zbi package and a folder into a new zbi package:

host_x64/zbi -o output.zbi input.zbi input_dir/
@wangrunji0408 wangrunji0408 added the analysis Investigation and analysis label Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis Investigation and analysis
Projects
None yet
Development

No branches or pull requests

2 participants