Skip to content

Commit bc74112

Browse files
gongleiareikraxel
authored andcommitted
bootdevice: move bootdevice related code to new file bootdevice.c
Signed-off-by: Gonglei <[email protected]> Reviewed-by: Gerd Hoffmann <[email protected]> Signed-off-by: Gerd Hoffmann <[email protected]>
1 parent b1d28ec commit bc74112

File tree

4 files changed

+145
-118
lines changed

4 files changed

+145
-118
lines changed

Makefile.target

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ endif #CONFIG_BSD_USER
127127
# System emulator target
128128
ifdef CONFIG_SOFTMMU
129129
obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o ioport.o numa.o
130-
obj-y += qtest.o
130+
obj-y += qtest.o bootdevice.o
131131
obj-y += hw/
132132
obj-$(CONFIG_FDT) += device_tree.o
133133
obj-$(CONFIG_KVM) += kvm-all.o

bootdevice.c

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* QEMU Boot Device Implement
3+
*
4+
* Copyright (c) 2014 HUAWEI TECHNOLOGIES CO.,LTD.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "sysemu/sysemu.h"
26+
27+
typedef struct FWBootEntry FWBootEntry;
28+
29+
struct FWBootEntry {
30+
QTAILQ_ENTRY(FWBootEntry) link;
31+
int32_t bootindex;
32+
DeviceState *dev;
33+
char *suffix;
34+
};
35+
36+
static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
37+
QTAILQ_HEAD_INITIALIZER(fw_boot_order);
38+
39+
void add_boot_device_path(int32_t bootindex, DeviceState *dev,
40+
const char *suffix)
41+
{
42+
FWBootEntry *node, *i;
43+
44+
if (bootindex < 0) {
45+
return;
46+
}
47+
48+
assert(dev != NULL || suffix != NULL);
49+
50+
node = g_malloc0(sizeof(FWBootEntry));
51+
node->bootindex = bootindex;
52+
node->suffix = g_strdup(suffix);
53+
node->dev = dev;
54+
55+
QTAILQ_FOREACH(i, &fw_boot_order, link) {
56+
if (i->bootindex == bootindex) {
57+
fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
58+
exit(1);
59+
} else if (i->bootindex < bootindex) {
60+
continue;
61+
}
62+
QTAILQ_INSERT_BEFORE(i, node, link);
63+
return;
64+
}
65+
QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
66+
}
67+
68+
DeviceState *get_boot_device(uint32_t position)
69+
{
70+
uint32_t counter = 0;
71+
FWBootEntry *i = NULL;
72+
DeviceState *res = NULL;
73+
74+
if (!QTAILQ_EMPTY(&fw_boot_order)) {
75+
QTAILQ_FOREACH(i, &fw_boot_order, link) {
76+
if (counter == position) {
77+
res = i->dev;
78+
break;
79+
}
80+
counter++;
81+
}
82+
}
83+
return res;
84+
}
85+
86+
/*
87+
* This function returns null terminated string that consist of new line
88+
* separated device paths.
89+
*
90+
* memory pointed by "size" is assigned total length of the array in bytes
91+
*
92+
*/
93+
char *get_boot_devices_list(size_t *size, bool ignore_suffixes)
94+
{
95+
FWBootEntry *i;
96+
size_t total = 0;
97+
char *list = NULL;
98+
99+
QTAILQ_FOREACH(i, &fw_boot_order, link) {
100+
char *devpath = NULL, *bootpath;
101+
size_t len;
102+
103+
if (i->dev) {
104+
devpath = qdev_get_fw_dev_path(i->dev);
105+
assert(devpath);
106+
}
107+
108+
if (i->suffix && !ignore_suffixes && devpath) {
109+
size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
110+
111+
bootpath = g_malloc(bootpathlen);
112+
snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
113+
g_free(devpath);
114+
} else if (devpath) {
115+
bootpath = devpath;
116+
} else if (!ignore_suffixes) {
117+
assert(i->suffix);
118+
bootpath = g_strdup(i->suffix);
119+
} else {
120+
bootpath = g_strdup("");
121+
}
122+
123+
if (total) {
124+
list[total-1] = '\n';
125+
}
126+
len = strlen(bootpath) + 1;
127+
list = g_realloc(list, total + len);
128+
memcpy(&list[total], bootpath, len);
129+
total += len;
130+
g_free(bootpath);
131+
}
132+
133+
*size = total;
134+
135+
if (boot_strict && *size > 0) {
136+
list[total-1] = '\n';
137+
list = g_realloc(list, total + 5);
138+
memcpy(&list[total], "HALT", 5);
139+
*size = total + 5;
140+
}
141+
return list;
142+
}

include/sysemu/sysemu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ extern int no_shutdown;
130130
extern int semihosting_enabled;
131131
extern int old_param;
132132
extern int boot_menu;
133+
extern bool boot_strict;
133134
extern uint8_t *boot_splash_filedata;
134135
extern size_t boot_splash_filedata_size;
135136
extern uint8_t qemu_extra_params_fw[2];

vl.c

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,12 @@ int ctrl_grab = 0;
180180
unsigned int nb_prom_envs = 0;
181181
const char *prom_envs[MAX_PROM_ENVS];
182182
int boot_menu;
183-
static bool boot_strict;
183+
bool boot_strict;
184184
uint8_t *boot_splash_filedata;
185185
size_t boot_splash_filedata_size;
186186
uint8_t qemu_extra_params_fw[2];
187187

188188
int icount_align_option;
189-
typedef struct FWBootEntry FWBootEntry;
190-
191-
struct FWBootEntry {
192-
QTAILQ_ENTRY(FWBootEntry) link;
193-
int32_t bootindex;
194-
DeviceState *dev;
195-
char *suffix;
196-
};
197-
198-
static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
199-
QTAILQ_HEAD_INITIALIZER(fw_boot_order);
200189

201190
int nb_numa_nodes;
202191
int max_numa_nodeid;
@@ -1246,111 +1235,6 @@ static void restore_boot_order(void *opaque)
12461235
g_free(normal_boot_order);
12471236
}
12481237

1249-
void add_boot_device_path(int32_t bootindex, DeviceState *dev,
1250-
const char *suffix)
1251-
{
1252-
FWBootEntry *node, *i;
1253-
1254-
if (bootindex < 0) {
1255-
return;
1256-
}
1257-
1258-
assert(dev != NULL || suffix != NULL);
1259-
1260-
node = g_malloc0(sizeof(FWBootEntry));
1261-
node->bootindex = bootindex;
1262-
node->suffix = g_strdup(suffix);
1263-
node->dev = dev;
1264-
1265-
QTAILQ_FOREACH(i, &fw_boot_order, link) {
1266-
if (i->bootindex == bootindex) {
1267-
fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
1268-
exit(1);
1269-
} else if (i->bootindex < bootindex) {
1270-
continue;
1271-
}
1272-
QTAILQ_INSERT_BEFORE(i, node, link);
1273-
return;
1274-
}
1275-
QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
1276-
}
1277-
1278-
DeviceState *get_boot_device(uint32_t position)
1279-
{
1280-
uint32_t counter = 0;
1281-
FWBootEntry *i = NULL;
1282-
DeviceState *res = NULL;
1283-
1284-
if (!QTAILQ_EMPTY(&fw_boot_order)) {
1285-
QTAILQ_FOREACH(i, &fw_boot_order, link) {
1286-
if (counter == position) {
1287-
res = i->dev;
1288-
break;
1289-
}
1290-
counter++;
1291-
}
1292-
}
1293-
return res;
1294-
}
1295-
1296-
/*
1297-
* This function returns null terminated string that consist of new line
1298-
* separated device paths.
1299-
*
1300-
* memory pointed by "size" is assigned total length of the array in bytes
1301-
*
1302-
*/
1303-
char *get_boot_devices_list(size_t *size, bool ignore_suffixes)
1304-
{
1305-
FWBootEntry *i;
1306-
size_t total = 0;
1307-
char *list = NULL;
1308-
1309-
QTAILQ_FOREACH(i, &fw_boot_order, link) {
1310-
char *devpath = NULL, *bootpath;
1311-
size_t len;
1312-
1313-
if (i->dev) {
1314-
devpath = qdev_get_fw_dev_path(i->dev);
1315-
assert(devpath);
1316-
}
1317-
1318-
if (i->suffix && !ignore_suffixes && devpath) {
1319-
size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
1320-
1321-
bootpath = g_malloc(bootpathlen);
1322-
snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
1323-
g_free(devpath);
1324-
} else if (devpath) {
1325-
bootpath = devpath;
1326-
} else if (!ignore_suffixes) {
1327-
assert(i->suffix);
1328-
bootpath = g_strdup(i->suffix);
1329-
} else {
1330-
bootpath = g_strdup("");
1331-
}
1332-
1333-
if (total) {
1334-
list[total-1] = '\n';
1335-
}
1336-
len = strlen(bootpath) + 1;
1337-
list = g_realloc(list, total + len);
1338-
memcpy(&list[total], bootpath, len);
1339-
total += len;
1340-
g_free(bootpath);
1341-
}
1342-
1343-
*size = total;
1344-
1345-
if (boot_strict && *size > 0) {
1346-
list[total-1] = '\n';
1347-
list = g_realloc(list, total + 5);
1348-
memcpy(&list[total], "HALT", 5);
1349-
*size = total + 5;
1350-
}
1351-
return list;
1352-
}
1353-
13541238
static QemuOptsList qemu_smp_opts = {
13551239
.name = "smp-opts",
13561240
.implied_opt_name = "cpus",

0 commit comments

Comments
 (0)