-/*
- * Boot parameters can be relocated if TRUE.
- * Boot parameters must be placed at 0x90000 if FALSE.
- *
- * This will be set to TRUE if bit 6 (0x40) is set in the loader_flags
- * field in a compressed x86 boot format kernel. This will also be set
- * to TRUE if the kernel is an uncompressed ELF32 image.
- *
- * To remote boot w/ the universal network driver and a 16-bit UNDI
- * this must be set to TRUE.
- */
-
-BOOLEAN can_reloc_boot_params = FALSE;
-
-/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-static INTN
-probe_bzImage_boot(CHAR16 *kname)
-{
- EFI_STATUS efi_status;
- UINTN size;
- fops_fd_t fd;
- UINT8 bootsect[512];
-
- DBG_PRT((L"probe_bzImage_boot()\n"));
-
- if (!kname) {
- ERR_PRT((L"kname == %xh", kname));
- free_kmem();
- return -1;
- }
-
- /*
- * Open kernel image.
- */
-
- DBG_PRT((L"opening %s...\n", kname));
-
- efi_status = fops_open(kname, &fd);
-
- if (EFI_ERROR(efi_status)) {
- ERR_PRT((L"Could not open %s.", kname));
- free_kmem();
- return -1;
- }
-
- /*
- * Read boot sector.
- */
-
- DBG_PRT((L"\nreading boot sector...\n"));
-
- size = sizeof bootsect;
- efi_status = fops_read(fd, bootsect, &size);
-
- if (EFI_ERROR(efi_status) || size != sizeof bootsect) {
- ERR_PRT((L"Could not read boot sector from %s.", kname));
- fops_close(fd);
- free_kmem();
- return -1;
- }
-
- /*
- * Verify boot sector signature.
- */
-
- if (bootsect[0x1FE] != 0x55 || bootsect[0x1FF] != 0xAA) {
- ERR_PRT((L"%s is not a bzImage kernel image.\n", kname));
- fops_close(fd);
- free_kmem();
- return -1;
- }
-
- /*
- * Check for out of range setup data size.
- * Will almost always be 7, but we will accept 1 to 64.
- */
-
- DBG_PRT((L"bootsect[1F1h] == %d setup sectors\n", bootsect[0x1F1]));
-
- if (bootsect[0x1F1] < 1 || bootsect[0x1F1] > 64) {
- ERR_PRT((L"%s is not a valid bzImage kernel image.",
- kname));
-
- fops_close(fd);
- free_kmem();
- return -1;
- }
-
- /*
- * Allocate and read setup data.
- */
-
- DBG_PRT((L"reading setup data...\n"));
-
- param_size = (bootsect[0x1F1] + 1) * 512;
- //param_start = alloc(param_size, EfiBootServicesData);
- param_start = alloc(param_size, EfiLoaderData);
-
- DBG_PRT((L"param_size=%d param_start=%x", param_size, param_start));
-
- if (!param_start) {
- ERR_PRT((L"Could not allocate %d bytes of setup data.",
- param_size));
-
- fops_close(fd);
- free_kmem();
- return -1;
- }
-
- CopyMem(param_start, bootsect, sizeof bootsect);
-
- size = param_size - 512;
- efi_status = fops_read(fd, ((UINT8 *)param_start) + 512, &size);
-
- if (EFI_ERROR(efi_status) || size != param_size - 512) {
- ERR_PRT((L"Could not read %d bytes of setup data.",
- param_size - 512));
-
- free(param_start);
- param_start = NULL;
- param_size = 0;
- fops_close(fd);
- free_kmem();
- return -1;
- }
-
- /*
- * Check for setup data signature.
- */
-
- { UINT8 *c = ((UINT8 *)param_start)+514;
- DBG_PRT((L"param_start(c=%x): %c-%c-%c-%c", c, (CHAR16)c[0],(CHAR16) c[1], (CHAR16)c[2], (CHAR16)c[3]));
- }
- if (CompareMem(((UINT8 *)param_start) + 514, "HdrS", 4)) {
- ERR_PRT((L"%s does not have a setup signature.",
- kname));
-
- free(param_start);
- param_start = NULL;
- param_size = 0;
- fops_close(fd);
- free_kmem();
- return -1;
- }
-
- /*
- * Allocate memory for kernel.
- */
-
- if (alloc_kmem(kernel_start, EFI_SIZE_TO_PAGES(kernel_size))) {
- ERR_PRT((L"Could not allocate kernel memory."));
- return -1;
- } else {
- VERB_PRT(3, Print(L"kernel_start: 0x%x kernel_size: %d\n", kernel_start, kernel_size));
- }
-
- /*
- * Now read the rest of the kernel image into memory.
- */
-
- DBG_PRT((L"reading kernel image...\n"));
-
- size = kernel_size;
-
- efi_status = fops_read(fd, kernel_start, &size);
-
- if (EFI_ERROR(efi_status) || size < 0x10000) {
- ERR_PRT((L"Error reading kernel image %s.", kname));
- free(param_start);
- param_start = NULL;
- param_size = 0;
- fops_close(fd);
- free_kmem();
- return -1;
- }
-
- DBG_PRT((L"kernel image read: %d bytes, %d Kbytes\n", size, size / 1024));
-
- /*
- * Boot sector, setup data and kernel image loaded.
- */
-
- fops_close(fd);
- return 0;
-}
-
-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-static INTN
-load_bzImage_boot(CHAR16 *kname, kdesc_t *kd)
-{
- DBG_PRT((L"load_bzImage_boot()\n"));
-
- if (!kname || !kd) {
- ERR_PRT((L"kname=0x%x kd=0x%x", kname, kd));
-
- free(param_start);
- param_start = NULL;
- param_size = 0;
- free_kmem();
- return -1;
- }
-
- kd->kstart = kd->kentry = kernel_start;
- kd->kend = ((UINT8 *)kd->kstart) + kernel_size;
-
- DBG_PRT((L"kstart=0x%x kentry=0x%x kend=0x%x\n", kd->kstart, kd->kentry, kd->kend));
-
- return 0;
-}
-
-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-static loader_ops_t loader_bzImage_boot = {
- NULL,
- L"loader_bzImage_boot",
- &probe_bzImage_boot,
- &load_bzImage_boot
-};
-
-/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
-/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */