1 /* 2 * Guest code setup for migration tests 3 * 4 * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates 5 * based on the vhost-user-test.c that is: 6 * Copyright (c) 2014 Virtual Open Systems Sarl. 7 * 8 * This work is licensed under the terms of the GNU GPL, version 2 or later. 9 * See the COPYING file in the top-level directory. 10 * 11 */ 12 13 #include "qemu/osdep.h" 14 15 /* 16 * The boot file modifies memory area in [start_address, end_address) 17 * repeatedly. It outputs a 'B' at a fixed rate while it's still running. 18 */ 19 #include "bootfile.h" 20 #include "i386/a-b-bootblock.h" 21 #include "aarch64/a-b-kernel.h" 22 #include "ppc64/a-b-kernel.h" 23 #include "s390x/a-b-bios.h" 24 25 static char *bootpath; 26 27 void bootfile_delete(void) 28 { 29 if (!bootpath) { 30 return; 31 } 32 unlink(bootpath); 33 g_free(bootpath); 34 bootpath = NULL; 35 } 36 37 char *bootfile_create(const char *arch, const char *dir, bool suspend_me) 38 { 39 unsigned char *content; 40 size_t len; 41 42 bootfile_delete(); 43 bootpath = g_strdup_printf("%s/bootsect", dir); 44 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { 45 /* the assembled x86 boot sector should be exactly one sector large */ 46 g_assert(sizeof(x86_bootsect) == 512); 47 x86_bootsect[SYM_suspend_me - SYM_start] = suspend_me; 48 content = x86_bootsect; 49 len = sizeof(x86_bootsect); 50 } else if (g_str_equal(arch, "s390x")) { 51 content = s390x_elf; 52 len = sizeof(s390x_elf); 53 } else if (strcmp(arch, "ppc64") == 0) { 54 content = ppc64_kernel; 55 len = sizeof(ppc64_kernel); 56 } else if (strcmp(arch, "aarch64") == 0) { 57 content = aarch64_kernel; 58 len = sizeof(aarch64_kernel); 59 g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE); 60 } else { 61 g_assert_not_reached(); 62 } 63 64 FILE *bootfile = fopen(bootpath, "wb"); 65 66 g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1); 67 fclose(bootfile); 68 69 return bootpath; 70 } 71