Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. target := aarch64-unknown-none
  2. mode := release
  3. kernel := target/$(target)/$(mode)/aarch64
  4. kernel_qemu_bin := target/$(target)/$(mode)/aarch64_qemu.bin
  5. kernel_crosvm_bin := target/$(target)/$(mode)/aarch64_crosvm.bin
  6. img := target/$(target)/$(mode)/img
  7. vsock_server_path := ../vsock_server
  8. vsock_server_bin := $(vsock_server_path)/target/$(mode)/vsock_server
  9. sysroot := $(shell rustc --print sysroot)
  10. objdump := $(shell find $(sysroot) -name llvm-objdump) --arch-name=aarch64
  11. objcopy := $(shell find $(sysroot) -name llvm-objcopy)
  12. BUILD_ARGS += --target $(target)
  13. ifeq ($(mode), release)
  14. BUILD_ARGS += --release
  15. endif
  16. VSOCK_BUILD_ARGS =
  17. ifeq ($(mode), release)
  18. VSOCK_BUILD_ARGS += --release
  19. endif
  20. .PHONY: kernel clean qemu run env
  21. env:
  22. rustup component add llvm-tools-preview rustfmt
  23. rustup target add $(target)
  24. kernel_qemu:
  25. cargo clean
  26. cargo build $(BUILD_ARGS) --config 'build.rustflags="--cfg platform=\"qemu\""'
  27. kernel_crosvm:
  28. cargo clean
  29. cargo build $(BUILD_ARGS) --config 'build.rustflags="--cfg platform=\"crosvm\""'
  30. $(kernel_qemu_bin): kernel_qemu
  31. aarch64-linux-gnu-objcopy -O binary $(kernel) $(kernel_qemu_bin)
  32. $(kernel_crosvm_bin): kernel_crosvm
  33. aarch64-linux-gnu-objcopy -O binary $(kernel) $(kernel_crosvm_bin)
  34. $(vsock_server_bin):
  35. (cd $(vsock_server_path) && cargo build $(VSOCK_BUILD_ARGS))
  36. asm: kernel
  37. $(objdump) -d $(kernel) | less
  38. sym: kernel
  39. $(objdump) -t $(kernel) | less
  40. header: kernel
  41. $(objdump) -x $(kernel) | less
  42. clean:
  43. cargo clean
  44. # This target is used to test the vsock driver manually. See vsock_server/README.md
  45. # for more information.
  46. qemu-vsock: $(kernel_qemu_bin) $(img)
  47. qemu-system-aarch64 \
  48. $(QEMU_ARGS) \
  49. -machine virt \
  50. -cpu max \
  51. -serial chardev:char0 \
  52. -kernel $(kernel_qemu_bin) \
  53. -global virtio-mmio.force-legacy=false \
  54. -nic none \
  55. -drive file=$(img),if=none,format=raw,id=x0 \
  56. -device vhost-vsock-device,id=virtiosocket0,guest-cid=102 \
  57. -chardev stdio,id=char0,mux=on
  58. qemu: $(kernel_qemu_bin) $(img) $(vsock_server_bin)
  59. $(vsock_server_bin) &
  60. qemu-system-aarch64 \
  61. $(QEMU_ARGS) \
  62. -machine virt \
  63. -cpu max \
  64. -serial chardev:char0 \
  65. -kernel $(kernel_qemu_bin) \
  66. -global virtio-mmio.force-legacy=false \
  67. -nic none \
  68. -drive file=$(img),if=none,format=raw,id=x0 \
  69. -device vhost-vsock-device,id=virtiosocket0,guest-cid=102 \
  70. -device virtio-blk-device,drive=x0 \
  71. -device virtio-gpu-device \
  72. -device virtio-serial,id=virtio-serial0 \
  73. -chardev stdio,id=char0,mux=on \
  74. -device virtconsole,chardev=char0
  75. qemu-pci: $(kernel_qemu_bin) $(img)
  76. $(vsock_server_bin) &
  77. qemu-system-aarch64 \
  78. $(QEMU_ARGS) \
  79. -machine virt \
  80. -cpu max \
  81. -serial chardev:char0 \
  82. -kernel $(kernel_qemu_bin) \
  83. -nic none \
  84. -drive file=$(img),if=none,format=raw,id=x0 \
  85. -device vhost-vsock-pci,id=virtiosocket0,guest-cid=103 \
  86. -device virtio-blk-pci,drive=x0 \
  87. -device virtio-gpu-pci \
  88. -device virtio-serial,id=virtio-serial0 \
  89. -chardev stdio,id=char0,mux=on \
  90. -device virtconsole,chardev=char0
  91. crosvm: $(kernel_crosvm_bin) $(img)
  92. adb shell 'mkdir -p /data/local/tmp/virt_raw'
  93. adb push $(kernel_crosvm_bin) /data/local/tmp/virt_raw/aarch64_example
  94. adb push $(img) /data/local/tmp/virt_raw/disk_img
  95. adb shell "/data/local/tmp/crosvm --log-level=trace --extended-status run --disable-sandbox --serial=stdout,hardware=serial,num=1 --rwdisk=/data/local/tmp/virt_raw/disk_img --bios=/data/local/tmp/virt_raw/aarch64_example"
  96. $(img):
  97. dd if=/dev/zero of=$@ bs=512 count=32
  98. run: qemu