summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorGabe Black <gabeblack@chromium.org>2011-06-23 16:14:23 -0700
committerSimon Glass <sjg@chromium.org>2011-08-29 10:39:36 -0700
commit9f69764d2e4354de05775a874e71e096b180f14b (patch)
tree4fa30172df51365c36454b43d240150ebeb80d02 /arch
parent48e15702fe3a3d32abfc38f839af21db7a0b7a5f (diff)
Clean up the i386 zimage code in preparation to extend it.
This change cleans up some formatting issues in the zimage handling code, and converts it from using offsets added to a base pointer to using the available structure definitions which were already being included. BUG=chrome-os-partner:3906 TEST=Successfully boot into chromeos on Alex. Change-Id: I2790d28355ca262f114c1538c3a64802d52ccea5 Signed-off-by: Gabe Black <gabeblack@google.com> Reviewed-on: http://gerrit.chromium.org/gerrit/3217 Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-by: Stefan Reinauer <reinauer@google.com> Tested-by: Gabe Black <gabeblack@chromium.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/include/asm/zimage.h21
-rw-r--r--arch/x86/lib/zimage.c97
2 files changed, 57 insertions, 61 deletions
diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
index b6266e456a5..ba08e58e126 100644
--- a/arch/x86/include/asm/zimage.h
+++ b/arch/x86/include/asm/zimage.h
@@ -27,27 +27,6 @@
/* linux i386 zImage/bzImage header. Offsets relative to
* the start of the image */
-#define CMD_LINE_MAGIC_OFF 0x020 /* Magic 0xa33f if the offset below is valid */
-#define CMD_LINE_OFFSET_OFF 0x022 /* Offset to comandline */
-#define SETUP_SECTS_OFF 0x1F1 /* The size of the setup in sectors */
-#define ROOT_FLAGS_OFF 0x1F2 /* If set, the root is mounted readonly */
-#define VID_MODE_OFF 0x1FA /* Video mode control */
-#define ROOT_DEV_OFF 0x1FC /* Default root device number */
-#define BOOT_FLAG_OFF 0x1FE /* 0xAA55 magic number */
-#define HEADER_OFF 0x202 /* Magic signature "HdrS" */
-#define VERSION_OFF 0x206 /* Boot protocol version supported */
-#define REALMODE_SWTCH_OFF 0x208 /* Boot loader hook (see below) */
-#define START_SYS_OFF 0x20C /* Points to kernel version string */
-#define TYPE_OF_LOADER_OFF 0x210 /* Boot loader identifier */
-#define LOADFLAGS_OFF 0x211 /* Boot protocol option flags */
-#define SETUP_MOVE_SIZE_OFF 0x212 /* Move to high memory size (used with hooks) */
-#define CODE32_START_OFF 0x214 /* Boot loader hook (see below) */
-#define RAMDISK_IMAGE_OFF 0x218 /* initrd load address (set by boot loader) */
-#define RAMDISK_SIZE_OFF 0x21C /* initrd size (set by boot loader) */
-#define HEAP_END_PTR_OFF 0x224 /* Free memory after setup end */
-#define CMD_LINE_PTR_OFF 0x228 /* 32-bit pointer to the kernel command line */
-
-
#define HEAP_FLAG 0x80
#define BIG_KERNEL_FLAG 0x01
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index cc4b40e64c9..9f20fdb0ff2 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2011 The Chromium OS Authors.
* (C) Copyright 2002
* Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
*
@@ -86,19 +87,22 @@ void *load_zimage(char *image, unsigned long kernel_size,
unsigned long initrd_addr, unsigned long initrd_size,
int auto_boot)
{
- void *setup_base;
+ struct boot_params *setup_base;
int setup_size;
int bootproto;
int big_image;
void *load_address;
- struct setup_header *hdr = (struct setup_header *)(image + SETUP_SECTS_OFF);
+ struct boot_params *params = (struct boot_params *)image;
+ struct setup_header *hdr = &params->hdr;
- setup_base = (void*)DEFAULT_SETUP_BASE; /* base address for real-mode segment */
+ /* base address for real-mode segment */
+ setup_base = (struct boot_params *)DEFAULT_SETUP_BASE;
if (KERNEL_MAGIC != hdr->boot_flag) {
- printf("Error: Invalid Boot Flag (found 0x%04x, expected 0x%04x)\n",
- hdr->boot_flag, KERNEL_MAGIC);
+ printf("Error: Invalid Boot Flag "
+ "(found 0x%04x, expected 0x%04x)\n",
+ hdr->boot_flag, KERNEL_MAGIC);
return 0;
} else {
printf("Valid Boot Flag\n");
@@ -133,52 +137,63 @@ void *load_zimage(char *image, unsigned long kernel_size,
big_image = (bootproto >= 0x0200) && (hdr->loadflags & BIG_KERNEL_FLAG);
/* Determine load address */
- load_address = (void*)(big_image ? BZIMAGE_LOAD_ADDR : ZIMAGE_LOAD_ADDR);
+ if (big_image) {
+ load_address = (void *)BZIMAGE_LOAD_ADDR;
+ } else {
+ load_address = (void *)ZIMAGE_LOAD_ADDR;
+ }
/* load setup */
- printf("Moving Real-Mode Code to 0x%8.8lx (%d bytes)\n", (ulong)setup_base, setup_size);
+ printf("Moving Real-Mode Code to 0x%8.8lx (%d bytes)\n",
+ (ulong)setup_base, setup_size);
memmove(setup_base, image, setup_size);
printf("Using boot protocol version %x.%02x\n",
(bootproto & 0xff00) >> 8, bootproto & 0xff);
if (bootproto == 0x0100) {
-
- *(u16*)(setup_base + CMD_LINE_MAGIC_OFF) = COMMAND_LINE_MAGIC;
- *(u16*)(setup_base + CMD_LINE_OFFSET_OFF) = COMMAND_LINE_OFFSET;
+ setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC;
+ setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET;
/* A very old kernel MUST have its real-mode code
* loaded at 0x90000 */
if ((u32)setup_base != 0x90000) {
/* Copy the real-mode kernel */
- memmove((void*)0x90000, setup_base, setup_size);
+ memmove((void *)0x90000, setup_base, setup_size);
/* Copy the command line */
- memmove((void*)0x99000, setup_base+COMMAND_LINE_OFFSET,
- COMMAND_LINE_SIZE);
+ memmove((void *)0x99000,
+ (u8 *)setup_base + COMMAND_LINE_OFFSET,
+ COMMAND_LINE_SIZE);
- setup_base = (void*)0x90000; /* Relocated */
+ /* Relocated */
+ setup_base = (struct boot_params *)0x90000;
}
/* It is recommended to clear memory up to the 32K mark */
- memset((void*)0x90000 + setup_size, 0, SETUP_MAX_SIZE-setup_size);
+ memset((u8 *)0x90000 + setup_size, 0,
+ SETUP_MAX_SIZE - setup_size);
}
/* We are now setting up the real-mode version of the header */
- hdr = (struct setup_header *)(setup_base + SETUP_SECTS_OFF);
+ hdr = &setup_base->hdr;
if (bootproto >= 0x0200) {
hdr->type_of_loader = 8;
- if (hdr->setup_sects >= 15)
- printf("Linux kernel version %s\n", (char *)
- (setup_base + (hdr->kernel_version + 0x200)));
- else
- printf("Setup Sectors < 15 - Cannot print kernel version.\n");
+ if (hdr->setup_sects >= 15) {
+ printf("Linux kernel version %s\n",
+ (char *)setup_base +
+ hdr->kernel_version + 0x200);
+ } else {
+ printf("Setup Sectors < 15 - "
+ "Cannot print kernel version.\n");
+ }
if (initrd_addr) {
- printf("Initial RAM disk at linear address 0x%08lx, size %ld bytes\n",
- initrd_addr, initrd_size);
+ printf("Initial RAM disk at linear address 0x%08lx, "
+ "size %ld bytes\n",
+ initrd_addr, initrd_size);
hdr->ramdisk_image = initrd_addr;
hdr->ramdisk_size = initrd_size;
@@ -191,11 +206,11 @@ void *load_zimage(char *image, unsigned long kernel_size,
}
if (bootproto >= 0x0202) {
- hdr->cmd_line_ptr = (u32)setup_base + COMMAND_LINE_OFFSET;
+ hdr->cmd_line_ptr =
+ (uintptr_t)setup_base + COMMAND_LINE_OFFSET;
} else if (bootproto >= 0x0200) {
-
- *(u16*)(setup_base + CMD_LINE_MAGIC_OFF) = COMMAND_LINE_MAGIC;
- *(u16*)(setup_base + CMD_LINE_OFFSET_OFF) = COMMAND_LINE_OFFSET;
+ setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC;
+ setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET;
hdr->setup_move_size = 0x9100;
}
@@ -208,11 +223,11 @@ void *load_zimage(char *image, unsigned long kernel_size,
if (big_image) {
if ((kernel_size) > BZIMAGE_MAX_SIZE) {
- printf("Error: bzImage kernel too big! (size: %ld, max: %d)\n",
- kernel_size, BZIMAGE_MAX_SIZE);
+ printf("Error: bzImage kernel too big! "
+ "(size: %ld, max: %d)\n",
+ kernel_size, BZIMAGE_MAX_SIZE);
return 0;
}
-
} else if ((kernel_size) > ZIMAGE_MAX_SIZE) {
printf("Error: zImage kernel too big! (size: %ld, max: %d)\n",
kernel_size, ZIMAGE_MAX_SIZE);
@@ -220,11 +235,10 @@ void *load_zimage(char *image, unsigned long kernel_size,
}
/* build command line at COMMAND_LINE_OFFSET */
- build_command_line(setup_base + COMMAND_LINE_OFFSET, auto_boot);
-
- printf("Loading %czImage at address 0x%08x (%ld bytes)\n", big_image ? 'b' : ' ',
- (u32)load_address, kernel_size);
+ build_command_line((char *)setup_base + COMMAND_LINE_OFFSET, auto_boot);
+ printf("Loading %czImage at address 0x%08x (%ld bytes)\n",
+ big_image ? 'b' : ' ', (u32)load_address, kernel_size);
memmove(load_address, image + setup_size, kernel_size);
@@ -242,7 +256,8 @@ void boot_zimage(void *setup_base)
regs.xss = regs.xds;
regs.esp = 0x9000;
regs.eflags = 0;
- enter_realmode(((u32)setup_base+SETUP_START_OFFSET)>>4, 0, &regs, &regs);
+ enter_realmode(((u32)setup_base + SETUP_START_OFFSET) >> 4, 0,
+ &regs, &regs);
}
int do_zboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -257,11 +272,12 @@ int do_zboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
/* Setup board for maximum PC/AT Compatibility */
setup_pcat_compatibility();
- if (argc >= 2)
+ if (argc >= 2) {
/* argv[1] holds the address of the bzImage */
s = argv[1];
- else
+ } else {
s = getenv("fileaddr");
+ }
if (s)
bzImage_addr = (void *)simple_strtoul(s, NULL, 16);
@@ -271,12 +287,13 @@ int do_zboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
bzImage_size = simple_strtoul(argv[2], NULL, 16);
/* Lets look for*/
- base_ptr = load_zimage (bzImage_addr, bzImage_size, 0, 0, 0);
+ base_ptr = load_zimage(bzImage_addr, bzImage_size, 0, 0, 0);
- if (NULL == base_ptr) {
+ if (!base_ptr) {
printf ("## Kernel loading failed ...\n");
} else {
- printf ("## Transferring control to Linux (at address %08x) ...\n",
+ printf ("## Transferring control to Linux "
+ "(at address %08x) ...\n",
(u32)base_ptr);
/* we assume that the kernel is in place */