]>
git.proxmox.com Git - mirror_qemu.git/blob - bootdevice.c
f5399df4b76759e6e4c3b68b63aa249b9525fe85
2 * QEMU Boot Device Implement
4 * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO.,LTD.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 #include "sysemu/sysemu.h"
27 typedef struct FWBootEntry FWBootEntry
;
30 QTAILQ_ENTRY(FWBootEntry
) link
;
36 static QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
=
37 QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
39 void check_boot_index(int32_t bootindex
, Error
**errp
)
44 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
45 if (i
->bootindex
== bootindex
) {
46 error_setg(errp
, "The bootindex %d has already been used",
54 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
57 FWBootEntry
*node
, *i
;
63 assert(dev
!= NULL
|| suffix
!= NULL
);
65 node
= g_malloc0(sizeof(FWBootEntry
));
66 node
->bootindex
= bootindex
;
67 node
->suffix
= g_strdup(suffix
);
70 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
71 if (i
->bootindex
== bootindex
) {
72 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
74 } else if (i
->bootindex
< bootindex
) {
77 QTAILQ_INSERT_BEFORE(i
, node
, link
);
80 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
83 DeviceState
*get_boot_device(uint32_t position
)
86 FWBootEntry
*i
= NULL
;
87 DeviceState
*res
= NULL
;
89 if (!QTAILQ_EMPTY(&fw_boot_order
)) {
90 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
91 if (counter
== position
) {
102 * This function returns null terminated string that consist of new line
103 * separated device paths.
105 * memory pointed by "size" is assigned total length of the array in bytes
108 char *get_boot_devices_list(size_t *size
, bool ignore_suffixes
)
114 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
115 char *devpath
= NULL
, *bootpath
;
119 devpath
= qdev_get_fw_dev_path(i
->dev
);
123 if (i
->suffix
&& !ignore_suffixes
&& devpath
) {
124 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
126 bootpath
= g_malloc(bootpathlen
);
127 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
129 } else if (devpath
) {
131 } else if (!ignore_suffixes
) {
133 bootpath
= g_strdup(i
->suffix
);
135 bootpath
= g_strdup("");
139 list
[total
-1] = '\n';
141 len
= strlen(bootpath
) + 1;
142 list
= g_realloc(list
, total
+ len
);
143 memcpy(&list
[total
], bootpath
, len
);
150 if (boot_strict
&& *size
> 0) {
151 list
[total
-1] = '\n';
152 list
= g_realloc(list
, total
+ 5);
153 memcpy(&list
[total
], "HALT", 5);