me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Boot signed userland roots and ARM UEFI guest fixtures

diviocity committed 6 days ago · 0a0ab0a6c21d20a10f1d7195371f339b763a5c79 View patch
Unverified signature 2 files changed +85 -28
tests/busybox/boot.v +77 -23

@@ -1,5 +1,5 @@

1-// v run tests/busybox/boot.v INSTALLED_ROOT VINIX_AMD64_ISO NEW_OUTPUT_DIRECTORY [--shell|--musl]

2-// Run on x86_64 Linux with musl-gcc, bsdtar, GNU tar, xorriso and QEMU installed.

1+// v run tests/busybox/boot.v INSTALLED_ROOT VINIX_ISO NEW_OUTPUT_DIRECTORY [MODE]

2+// For ARM provide AARCH64_EFI_CODE and AARCH64_EFI_VARS, and CROSS_COMPILE for a cross GCC.

33module main

44

55import crypto.sha256

@@ -14,12 +14,22 @@ fn run(argv []string) ! {

1414

1515fn boot_image(root string, iso string, output string, mode string) ! {

1616 shell := mode == '--shell'

17- musl := mode == '--musl'

17+ arm := mode in ['--aarch64-musl', '--aarch64-userland']

18+ userland := mode in ['--userland', '--aarch64-userland']

19+ musl := mode in ['--musl', '--aarch64-musl']

20+ machine := if arm { 'aarch64' } else { 'x86_64' }

21+ loader := '/lib/ld-musl-${machine}.so.1'

1822 if root == '/' || output == root || output.starts_with(root + '/') {

1923 return error('place the output outside a separate BusyBox package root')

2024 }

2125 digest := sha256.sum(os.read_bytes(os.join_path(root, 'bin/busybox'))!).hex()

22- helper := if shell { 'serial-line' } else { 'busybox-probe' }

26+ helper := if userland {

27+ 'userland-check.sh'

28+ } else if shell {

29+ 'serial-line'

30+ } else {

31+ 'busybox-probe'

32+ }

2333 if os.exists(os.join_path(root, 'etc/inittab')) || os.exists(os.join_path(root, helper)) {

2434 return error('use a clean package root without a test helper or inittab')

2535 }

@@ -30,45 +40,88 @@ fn boot_image(root string, iso string, output string, mode string) ! {

3040 os.mkdir_all(os.join_path(additions, 'etc'))!

3141 inittab := if shell {

3242 "com1::respawn:/bin/sh -c '" + r'while printf "vinix> " && line=$(/serial-line); do eval "$line"; done' + "'"

43+ } else if userland {

44+ console := if arm { '/dev/console' } else { '/dev/com1' }

45+ "::sysinit:/bin/sh -c 'exec /bin/sh /userland-check.sh >${console} 2>&1'"

3346 } else {

3447 '::sysinit:/busybox-probe'

3548 }

3649 os.write_file(os.join_path(additions, 'etc/inittab'), inittab + '\n')!

37- source := if shell { 'serial-line.v' } else { 'guest.v' }

38- mut compiler := [@VEXE, '-prod', '-gc', 'none']

3950 mut loader_digest := ''

40- if musl {

41- loader_digest = sha256.sum(os.read_bytes(os.join_path(root, 'lib/ld-musl-x86_64.so.1'))!).hex()

42- specs := os.join_path(root, 'usr/lib/musl-gcc-sysroot.specs')

43- compiler << ['-musl', '-d', 'packaged_musl', '-cc', 'gcc', '-cflags',

44- '--sysroot=' + os.quoted_path(root) + ' -specs=' + os.quoted_path(specs)]

51+ if userland {

52+ os.cp(os.join_path(os.dir(@FILE), '..', 'userland', 'check.sh'), os.join_path(additions, helper))!

53+ } else {

54+ source := if shell { 'serial-line.v' } else { 'guest.v' }

55+ mut compiler := [@VEXE, '-prod', '-gc', 'none']

56+ if musl {

57+ loader_digest = sha256.sum(os.read_bytes(os.join_path(root, loader.trim_left('/')))!).hex()

58+ specs := os.join_path(root, 'usr/lib/musl-gcc-sysroot.specs')

59+ target_cc := if arm { os.getenv('CROSS_COMPILE') + 'gcc' } else { 'gcc' }

60+ if arm { compiler << ['-os', 'linux', '-arch', 'arm64'] }

61+ compiler << ['-musl', '-d', 'packaged_musl', '-cc', target_cc, '-cflags',

62+ '--sysroot=' + os.quoted_path(root) + ' -specs=' + os.quoted_path(specs)]

63+ } else {

64+ compiler << ['-cc', 'musl-gcc', '-cflags', '-static']

65+ }

66+ run([...compiler, '-o', os.join_path(additions, helper), os.join_path(os.dir(@FILE), source)])!

67+ }

68+ boot_files := if arm {

69+ ['boot/limine-uefi-cd.bin', 'EFI/BOOT/BOOTAA64.EFI']

4570 } else {

46- compiler << ['-cc', 'musl-gcc', '-cflags', '-static']

71+ ['boot/limine-bios.sys', 'boot/limine-bios-cd.bin']

4772 }

48- run([...compiler, '-o', os.join_path(additions, helper), os.join_path(os.dir(@FILE), source)])!

49- run(['bsdtar', '-xf', iso, '-C', os.dir(boot), 'boot/vinix', 'boot/limine-bios.sys',

50- 'boot/limine-bios-cd.bin'])!

73+ run(['bsdtar', '-xf', iso, '-C', os.dir(boot), 'boot/vinix', ...boot_files])!

5174 os.write_file(os.join_path(boot, 'limine.conf'), 'timeout: 0\nserial: yes\n/BusyBox\n' +

5275 ' protocol: limine\n kernel_path: boot():/boot/vinix\n resolution: 1024x768x32\n' +

5376 ' kaslr: no\n module_path: boot():/boot/initramfs.tar.gz\n cmdline: vinix.disk=live\n')!

5477 run(['tar', '--format=ustar', '--owner=0', '--group=0', '-czf', os.join_path(boot,

5578 'initramfs.tar.gz'), '-C', root, '.', '-C', additions, './etc', './' + helper])!

5679 test_iso := os.join_path(output, if shell { 'busybox-shell.iso' } else { 'busybox.iso' })

57- run(['xorriso', '-as', 'mkisofs', '-R', '-r', '-b', 'boot/limine-bios-cd.bin', '-no-emul-boot',

58- '-boot-load-size', '4', '-boot-info-table', '-o', test_iso, os.dir(boot)])!

80+ cd_boot := if arm {

81+ ['-e', 'boot/limine-uefi-cd.bin', '-no-emul-boot']

82+ } else {

83+ ['-b', 'boot/limine-bios-cd.bin', '-no-emul-boot', '-boot-load-size', '4', '-boot-info-table']

84+ }

85+ run(['xorriso', '-as', 'mkisofs', '-R', '-r', ...cd_boot, '-o', test_iso, os.dir(boot)])!

5986 if shell {

6087 println('Interactive serial shell image: ${test_iso}')

6188 return

6289 }

6390 log := os.join_path(output, 'serial.log')

64- run(['timeout', '90s', 'qemu-system-x86_64', '-machine', 'q35', '-accel', 'tcg', '-cpu', 'max',

65- '-m', '1024', '-smp', '2', '-vga', 'std', '-cdrom', test_iso, '-boot', 'd', '-nic', 'none',

66- '-display', 'none', '-monitor', 'none', '-serial', 'file:' + log, '-no-reboot'])!

91+ mut emulator := if arm {

92+ code := os.getenv('AARCH64_EFI_CODE')

93+ vars := os.join_path(output, 'vars.fd')

94+ os.cp(os.getenv('AARCH64_EFI_VARS'), vars)!

95+ ['qemu-system-aarch64', '-machine', 'virt', '-device', 'ramfb', '-drive',

96+ 'if=pflash,format=raw,readonly=on,file=' + code, '-drive',

97+ 'if=pflash,format=raw,file=' + vars, '-device', 'virtio-scsi-pci,id=scsi0', '-drive',

98+ 'if=none,id=cd0,media=cdrom,readonly=on,file=' + test_iso, '-device',

99+ 'scsi-cd,drive=cd0,bus=scsi0.0,bootindex=1']

100+ } else {

101+ ['qemu-system-x86_64', '-machine', 'q35', '-vga', 'std', '-cdrom', test_iso, '-boot', 'd']

102+ }

103+ memory := if userland {

104+ '512'

105+ } else if arm {

106+ '384'

107+ } else {

108+ '1024'

109+ }

110+ emulator << ['-accel', 'tcg', '-cpu', 'max', '-m', memory, '-smp', '2', '-nic', 'none', '-display',

111+ 'none', '-monitor', 'none', '-serial', 'file:' + log, '-no-reboot']

112+ run(['timeout', '120s', ...emulator])!

67113 lines := os.read_lines(log)!.map(it.trim_space())

114+ if userland {

115+ if 'VPAC USERLAND GUEST PASS' !in lines {

116+ return error('userland guest verification failed; see ${log}')

117+ }

118+ println('Vinix ${machine} userland checks passed. See ${log}')

119+ return

120+ }

68121 if '${digest} /bin/busybox' !in lines || 'VPAC BUSYBOX GUEST PASS' !in lines {

69122 return error('guest verification failed; see ${log}')

70123 }

71- if musl && '${loader_digest} /lib/ld-musl-x86_64.so.1' !in lines {

124+ if musl && '${loader_digest} ${loader}' !in lines {

72125 return error('guest musl differs from the packaged loader; see ${log}')

73126 }

74127 println('Vinix booted the installed BusyBox ${digest}. See ${log}')

@@ -76,8 +129,9 @@ fn boot_image(root string, iso string, output string, mode string) ! {

76129

77130fn main() {

78131 mode := if os.args.len == 5 { os.args[4] } else { '' }

79- if os.args.len != 4 && mode !in ['--shell', '--musl'] {

80- eprintln('usage: boot.v INSTALLED_ROOT VINIX_AMD64_ISO NEW_OUTPUT_DIRECTORY [--shell|--musl]')

132+ if os.args.len != 4 && mode !in ['--shell', '--musl', '--aarch64-musl', '--userland',

133+ '--aarch64-userland'] {

134+ eprintln('usage: boot.v INSTALLED_ROOT VINIX_ISO NEW_OUTPUT_DIRECTORY [--shell|--musl|--aarch64-musl|--userland|--aarch64-userland]')

81135 exit(2)

82136 }

83137 output := os.abs_path(os.args[3])

tests/busybox/guest.v +8 -5

@@ -37,18 +37,21 @@ fn verify() ! {

3737 return error('${path} must resolve to /bin/busybox')

3838 }

3939 }

40- check(['/bin/busybox', 'uname', '-m'], 'x86_64')!

40+ machine := $if arm64 { 'aarch64' } $else { 'x86_64' }

41+ check(['/bin/busybox', 'uname', '-m'], machine)!

42+ check(['/bin/uname', '-o'], 'Vinix')!

4143 check(['/bin/sh', '-c', r'echo $((6 * 7))'], '42')!

4244 check(['/bin/busybox', 'ash', '-c', r'echo $((3 * 7))'], '21')!

4345 check(['/bin/cat', '/etc/inittab'], '::sysinit:/busybox-probe')!

4446 println(run(['/bin/busybox', 'sha256sum', '/bin/busybox'])!)

4547 $if packaged_musl ? {

46- listing := run(['/lib/ld-musl-x86_64.so.1', '--list', '/busybox-probe'])!

47- if !listing.contains('libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1') {

48+ loader := '/lib/ld-musl-${machine}.so.1'

49+ listing := run([loader, '--list', '/busybox-probe'])!

50+ if !listing.contains('libc.musl-${machine}.so.1 => ${loader}') {

4851 return error('unexpected dynamic dependencies: ${listing}')

4952 }

5053 println(listing)

51- println(run(['/bin/busybox', 'sha256sum', '/lib/ld-musl-x86_64.so.1'])!)

54+ println(run(['/bin/busybox', 'sha256sum', loader])!)

5255 // A freed 256 KiB mapping falls in a retained bucket in the Vinix allocator.

5356 C.malloc_trim(0)

5457 buffer := unsafe { C.malloc(256 * 1024) }

@@ -72,7 +75,7 @@ fn main() {

7275 eprintln('requires a Vinix guest with the probe started directly by init')

7376 exit(2)

7477 }

75- fd := C.open(c'/dev/com1', C.O_WRONLY)

78+ fd := $if arm64 { C.open(c'/dev/console', C.O_WRONLY) } $else { C.open(c'/dev/com1', C.O_WRONLY) }

7679 if fd < 0 || C.dup2(fd, 1) < 0 || C.dup2(fd, 2) < 0 {

7780 exit(2)

7881 }