Skip to content

Commit 66056c1

Browse files
fyin1acrnsi
authored andcommitted
dm: bzimage loader: get linux bzimage setup_sects from header
According to $(LINUX_SRC)/Documentation/x86/boot.txt, the header of bzimage has setup sector number in offset 0x1f1. We don't need to scan the SETUP_SIG and detect the setup sector number actually which is not documented in x86 boot protocol. Tracked-On: #3619 Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent fc3d19b commit 66056c1

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

devicemodel/core/sw_load_bzimage.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ struct _zeropage {
7676
uint8_t pad2[0x8]; /* 0x1e9 */
7777

7878
struct {
79-
uint8_t hdr_pad1[0x1f]; /* 0x1f1 */
79+
uint8_t setup_sects; /* 0x1f1 */
80+
uint8_t hdr_pad1[0x1e]; /* 0x1f2 */
8081
uint8_t loader_type; /* 0x210 */
8182
uint8_t load_flags; /* 0x211 */
8283
uint8_t hdr_pad2[0x2]; /* 0x212 */
@@ -103,27 +104,17 @@ static size_t kernel_size;
103104
static int
104105
acrn_get_bzimage_setup_size(struct vmctx *ctx)
105106
{
106-
uint32_t *tmp, location = 1024, setup_sectors;
107-
int size = -1;
107+
struct _zeropage *kernel_load = (struct _zeropage *)
108+
(ctx->baseaddr + KERNEL_LOAD_OFF(ctx));
108109

109-
tmp = (uint32_t *)(ctx->baseaddr + KERNEL_LOAD_OFF(ctx)) + 1024/4;
110-
while (*tmp != SETUP_SIG && location < 0x8000) {
111-
tmp++;
112-
location += 4;
110+
/* For backwards compatibility, if the setup_sects field
111+
* is 0, the real value is 4.
112+
*/
113+
if (kernel_load->hdr.setup_sects == 0) {
114+
kernel_load->hdr.setup_sects = 4;
113115
}
114116

115-
/* setup size must be at least 1024 bytes and small than 0x8000 */
116-
if (location < 0x8000 && location > 1024) {
117-
setup_sectors = (location + 511) / 512;
118-
size = setup_sectors*512;
119-
printf("SW_LOAD: found setup sig @ 0x%08x, "
120-
"setup_size is 0x%08x\n",
121-
location, size);
122-
} else
123-
printf("SW_LOAD ERR: could not get setup "
124-
"size in kernel %s\n",
125-
kernel_path);
126-
return size;
117+
return (kernel_load->hdr.setup_sects + 1) * 512;
127118
}
128119

129120
int

0 commit comments

Comments
 (0)