From: Amos Kong <akong@redhat.com>
To: seabios@seabios.org, kevin@koconnor.net
Cc: alex.williamson@redhat.com, Amos Kong <akong@redhat.com>,
dallan@redhat.com, qemu-devel@nongnu.org, gleb@redhat.com
Subject: [Qemu-devel] [SeaBIOS PATCH v2] boot: support strict boot and make it configurable
Date: Wed, 26 Dec 2012 08:55:40 +0800 [thread overview]
Message-ID: <1356483340-12962-1-git-send-email-akong@redhat.com> (raw)
In-Reply-To: <20121225103701.GA6688@t430s.redhat.com>
Current seabios will try to boot from selected devices first,
if they are all failed, seabios will also try to boot from
un-selected devices.
For example:
@ qemu-kvm -boot order=n,menu=on ...
Guest will boot from network first, if it's failed, guest will try to
boot from other un-selected devices (floppy, cdrom, disk) one by one.
We need to make it configurable, seabios user can config it by a rom
file('etc/boot-strict'). 'strict boot' means only boot from user
selected devices.
I added some comments in this patch to explain why we can judge if
device is selected or not by DEFAULT_PRIO(9999). I also added 'selected'
flag in struct bootentry_s and struct bev_s to make it clearer.
If this patch is accepted, I will add a boot option (-boot strict=on)
for qemu.
Signed-off-by: Amos Kong <akong@redhat.com>
---
src/boot.c | 31 ++++++++++++++++++++++++-------
1 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/boot.c b/src/boot.c
index c67cc7f..99ac791 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -92,6 +92,7 @@ find_prio(const char *glob)
int i;
for (i = 0; i < BootorderCount; i++)
if (glob_prefix(glob, Bootorder[i]))
+ // device exists in the Bootorder list loaded from rom file
return i+1;
return -1;
}
@@ -249,12 +250,14 @@ boot_setup(void)
CheckFloppySig = 0;
u32 bootorder = (inb_cmos(CMOS_BIOS_BOOTFLAG2)
| ((inb_cmos(CMOS_BIOS_BOOTFLAG1) & 0xf0) << 4));
+ // reset device priority to default DEFAULT_PRIO(9999)
DefaultFloppyPrio = DefaultCDPrio = DefaultHDPrio
= DefaultBEVPrio = DEFAULT_PRIO;
int i;
for (i=101; i<104; i++) {
u32 val = bootorder & 0x0f;
bootorder >>= 4;
+ // priority of devices selected in bootorder will be changed
switch (val) {
case 1: DefaultFloppyPrio = i; break;
case 2: DefaultHDPrio = i; break;
@@ -280,6 +283,7 @@ struct bootentry_s {
struct drive_s *drive;
};
int priority;
+ int selected;
const char *description;
struct bootentry_s *next;
};
@@ -304,6 +308,9 @@ bootentry_add(int type, int prio, u32 data, const char *desc)
}
be->type = type;
be->priority = prio;
+ // set 'selected' flag according to the priority
+ if (prio != DEFAULT_PRIO)
+ be->selected = 1;
be->data = data;
be->description = desc ?: "?";
dprintf(3, "Registering bootable: %s (type:%d prio:%d data:%x)\n"
@@ -332,6 +339,8 @@ bootentry_add(int type, int prio, u32 data, const char *desc)
}
// Return the given priority if it's set - defaultprio otherwise.
+// This function is called by boot_add_*(), it will only pass
+// DEFAULT_PRIO(9999) for unselected devices as the boot-entry priority.
static inline int defPrio(int priority, int defaultprio) {
return (priority < 0) ? defaultprio : priority;
}
@@ -454,13 +463,14 @@ interactive_bootmenu(void)
struct bev_s {
int type;
u32 vector;
+ int selected;
};
static struct bev_s BEV[20];
static int BEVCount;
static int HaveHDBoot, HaveFDBoot;
static void
-add_bev(int type, u32 vector)
+add_bev(int type, u32 vector, int selected)
{
if (type == IPL_TYPE_HARDDISK && HaveHDBoot++)
return;
@@ -471,6 +481,7 @@ add_bev(int type, u32 vector)
struct bev_s *bev = &BEV[BEVCount++];
bev->type = type;
bev->vector = vector;
+ bev->selected = selected;
}
// Prepare for boot - show menu and run bcvs.
@@ -494,29 +505,29 @@ boot_prep(void)
switch (pos->type) {
case IPL_TYPE_BCV:
call_bcv(pos->vector.seg, pos->vector.offset);
- add_bev(IPL_TYPE_HARDDISK, 0);
+ add_bev(IPL_TYPE_HARDDISK, 0, pos->selected);
break;
case IPL_TYPE_FLOPPY:
map_floppy_drive(pos->drive);
- add_bev(IPL_TYPE_FLOPPY, 0);
+ add_bev(IPL_TYPE_FLOPPY, 0, pos->selected);
break;
case IPL_TYPE_HARDDISK:
map_hd_drive(pos->drive);
- add_bev(IPL_TYPE_HARDDISK, 0);
+ add_bev(IPL_TYPE_HARDDISK, 0, pos->selected);
break;
case IPL_TYPE_CDROM:
map_cd_drive(pos->drive);
// NO BREAK
default:
- add_bev(pos->type, pos->data);
+ add_bev(pos->type, pos->data, pos->selected);
break;
}
pos = pos->next;
}
// If nothing added a floppy/hd boot - add it manually.
- add_bev(IPL_TYPE_FLOPPY, 0);
- add_bev(IPL_TYPE_HARDDISK, 0);
+ add_bev(IPL_TYPE_FLOPPY, 0, 0);
+ add_bev(IPL_TYPE_HARDDISK, 0, 0);
}
@@ -654,6 +665,12 @@ do_boot(int seq_nr)
// Boot the given BEV type.
struct bev_s *ie = &BEV[seq_nr];
+
+ int strict = romfile_loadint("etc/boot-strict", 0);
+ // do strict boot, only boot from user selected devices
+ if (strict && !ie->selected)
+ boot_fail();
+
switch (ie->type) {
case IPL_TYPE_FLOPPY:
printf("Booting from Floppy...\n");
--
1.7.1
next prev parent reply other threads:[~2012-12-26 0:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-19 7:22 [Qemu-devel] [PATCH] don't boot from un-selected devices Amos Kong
2012-12-19 7:24 ` [Qemu-devel] [Resend][Seabios PATCH] " Amos Kong
2012-12-19 7:38 ` Gerd Hoffmann
2012-12-19 8:12 ` Amos Kong
2012-12-19 9:32 ` Gleb Natapov
2012-12-25 3:58 ` Amos Kong
2012-12-25 6:37 ` Gleb Natapov
2012-12-25 10:37 ` Amos Kong
2012-12-26 0:55 ` Amos Kong [this message]
2013-01-09 4:00 ` [Qemu-devel] [SeaBIOS PATCH v2] boot: support strict boot and make it configurable Kevin O'Connor
2013-01-09 5:03 ` Amos Kong
2013-01-12 22:01 ` Kevin O'Connor
2013-01-09 5:17 ` [Qemu-devel] [SeaBIOS PATCH v3] boot: add a new type to halt booting Amos Kong
2012-12-25 15:59 ` [Qemu-devel] [Resend][Seabios PATCH] don't boot from un-selected devices Ronen Hod
2012-12-25 17:15 ` Gleb Natapov
2012-12-19 16:39 ` Kevin O'Connor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1356483340-12962-1-git-send-email-akong@redhat.com \
--to=akong@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=dallan@redhat.com \
--cc=gleb@redhat.com \
--cc=kevin@koconnor.net \
--cc=qemu-devel@nongnu.org \
--cc=seabios@seabios.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).