master
c 79 lines 2.14 KB
Raw
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 "loongarch64/a-b-kernel.h"
23 #include "ppc64/a-b-kernel.h"
24 #include "s390x/a-b-bios.h"
25
26 static char *bootpath;
27
28 void bootfile_delete(void)
29 {
30 if (!bootpath) {
31 return;
32 }
33 unlink(bootpath);
34 g_free(bootpath);
35 bootpath = NULL;
36 }
37
38 char *bootfile_create(const char *arch, const char *dir, bool suspend_me)
39 {
40 unsigned char *content;
41 size_t len;
42
43 bootfile_delete();
44 bootpath = g_strdup_printf("%s/bootsect", dir);
45 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
46 /* the assembled x86 boot sector should be exactly one sector large */
47 g_assert(sizeof(x86_bootsect) == 512);
48 x86_bootsect[SYM_suspend_me - SYM_start] = suspend_me;
49 content = x86_bootsect;
50 len = sizeof(x86_bootsect);
51 } else if (g_str_equal(arch, "s390x")) {
52 content = s390x_elf;
53 len = sizeof(s390x_elf);
54 } else if (strcmp(arch, "ppc64") == 0) {
55 content = ppc64_kernel;
56 len = sizeof(ppc64_kernel);
57 } else if (strcmp(arch, "aarch64") == 0) {
58 content = aarch64_kernel;
59 len = sizeof(aarch64_kernel);
60 g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
61 } else if (strcmp(arch, "loongarch64") == 0) {
62 content = loongarch64_kernel;
63 len = sizeof(loongarch64_kernel);
64 } else {
65 g_assert_not_reached();
66 }
67
68 FILE *bootfile = fopen(bootpath, "wb");
69
70 g_assert_cmpint(fwrite(content, len, 1, bootfile), ==, 1);
71 fclose(bootfile);
72
73 return bootpath;
74 }
75
76 char *bootfile_get(void)
77 {
78 return bootpath;
79 }