/* VasEBoot-setup.c - make VAS_EBOOT usable */ /* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef VAS_EBOOT_SETUP_SPARC64 #include #include #include #else #include #include #endif #include #include #include #include #include #include #include #include #include #include "progname.h" #include #include #include #include #include #include /* On SPARC this program fills in various fields inside of the 'boot' and 'core' * image files. * * The 'boot' image needs to know the OBP path name of the root * device. It also needs to know the initial block number of * 'core' (which is 'diskboot' concatenated with 'kernel' and * all the modules, this is created by VasEBoot-mkimage). This resulting * 'boot' image is 512 bytes in size and is placed in the second block * of a partition. * * The initial 'diskboot' block acts as a loader for the actual VAS_EBOOT * kernel. It contains the loading code and then a block list. * * The block list of 'core' starts at the end of the 'diskboot' image * and works it's way backwards towards the end of the code of 'diskboot'. * * We patch up the images with the necessary values and write out the * result. */ #ifdef VAS_EBOOT_SETUP_SPARC64 #define VasEBoot_target_to_host16(x) VasEBoot_be_to_cpu16(x) #define VasEBoot_target_to_host32(x) VasEBoot_be_to_cpu32(x) #define VasEBoot_target_to_host64(x) VasEBoot_be_to_cpu64(x) #define VasEBoot_host_to_target16(x) VasEBoot_cpu_to_be16(x) #define VasEBoot_host_to_target32(x) VasEBoot_cpu_to_be32(x) #define VasEBoot_host_to_target64(x) VasEBoot_cpu_to_be64(x) #elif defined (VAS_EBOOT_SETUP_BIOS) #define VasEBoot_target_to_host16(x) VasEBoot_le_to_cpu16(x) #define VasEBoot_target_to_host32(x) VasEBoot_le_to_cpu32(x) #define VasEBoot_target_to_host64(x) VasEBoot_le_to_cpu64(x) #define VasEBoot_host_to_target16(x) VasEBoot_cpu_to_le16(x) #define VasEBoot_host_to_target32(x) VasEBoot_cpu_to_le32(x) #define VasEBoot_host_to_target64(x) VasEBoot_cpu_to_le64(x) #else #error Complete this #endif static void write_rootdev (VasEBoot_device_t root_dev, char *boot_img, VasEBoot_uint64_t first_sector) { #ifdef VAS_EBOOT_SETUP_BIOS { VasEBoot_uint8_t *boot_drive; void *kernel_sector; boot_drive = (VasEBoot_uint8_t *) (boot_img + VAS_EBOOT_BOOT_MACHINE_BOOT_DRIVE); kernel_sector = (boot_img + VAS_EBOOT_BOOT_MACHINE_KERNEL_SECTOR); /* FIXME: can this be skipped? */ *boot_drive = 0xFF; VasEBoot_set_unaligned64 (kernel_sector, VasEBoot_cpu_to_le64 (first_sector)); } #endif #ifdef VAS_EBOOT_SETUP_SPARC64 { void *kernel_byte; kernel_byte = (boot_img + VAS_EBOOT_BOOT_AOUT_HEADER_SIZE + VAS_EBOOT_BOOT_MACHINE_KERNEL_BYTE); VasEBoot_set_unaligned64 (kernel_byte, VasEBoot_cpu_to_be64 (first_sector << VAS_EBOOT_DISK_SECTOR_BITS)); } #endif } #ifdef VAS_EBOOT_SETUP_SPARC64 #define BOOT_SECTOR 1 #else #define BOOT_SECTOR 0 #endif /* Helper for setup. */ struct blocklists { struct VasEBoot_boot_blocklist *first_block, *block; #ifdef VAS_EBOOT_SETUP_BIOS VasEBoot_uint16_t current_segment; #endif #ifdef VAS_EBOOT_SETUP_SPARC64 VasEBoot_uint64_t gpt_offset; #endif VasEBoot_uint16_t last_length; VasEBoot_disk_addr_t first_sector; }; /* Helper for setup. */ static void save_blocklists (VasEBoot_disk_addr_t sector, unsigned offset, unsigned length, void *data) { struct blocklists *bl = data; struct VasEBoot_boot_blocklist *prev = bl->block + 1; VasEBoot_uint64_t seclen; #ifdef VAS_EBOOT_SETUP_SPARC64 sector -= bl->gpt_offset; #endif VasEBoot_util_info ("saving <%" VAS_EBOOT_HOST_PRIuLONG_LONG ",%u,%u>", (unsigned long long) sector, offset, length); if (bl->first_sector == (VasEBoot_disk_addr_t) -1) { if (offset != 0 || length < VAS_EBOOT_DISK_SECTOR_SIZE) VasEBoot_util_error ("%s", _("the first sector of the core file is not sector-aligned")); bl->first_sector = sector; sector++; length -= VAS_EBOOT_DISK_SECTOR_SIZE; if (!length) return; } if (offset != 0 || bl->last_length != 0) VasEBoot_util_error ("%s", _("non-sector-aligned data is found in the core file")); seclen = (length + VAS_EBOOT_DISK_SECTOR_SIZE - 1) >> VAS_EBOOT_DISK_SECTOR_BITS; if (bl->block != bl->first_block && (VasEBoot_target_to_host64 (prev->start) + VasEBoot_target_to_host16 (prev->len)) == sector) { VasEBoot_uint16_t t = VasEBoot_target_to_host16 (prev->len); t += seclen; prev->len = VasEBoot_host_to_target16 (t); } else { bl->block->start = VasEBoot_host_to_target64 (sector); bl->block->len = VasEBoot_host_to_target16 (seclen); #ifdef VAS_EBOOT_SETUP_BIOS bl->block->segment = VasEBoot_host_to_target16 (bl->current_segment); #endif bl->block--; if (bl->block->len) VasEBoot_util_error ("%s", _("the sectors of the core file are too fragmented")); } bl->last_length = length & (VAS_EBOOT_DISK_SECTOR_SIZE - 1); #ifdef VAS_EBOOT_SETUP_BIOS bl->current_segment += seclen << (VAS_EBOOT_DISK_SECTOR_BITS - 4); #endif } /* Context for setup/identify_partmap. */ struct identify_partmap_ctx { VasEBoot_partition_map_t dest_partmap; VasEBoot_partition_t container; int multiple_partmaps; }; /* Helper for setup. Unlike root_dev, with dest_dev we're interested in the partition map even if dest_dev itself is a whole disk. */ static int identify_partmap (VasEBoot_disk_t disk __attribute__ ((unused)), const VasEBoot_partition_t p, void *data) { struct identify_partmap_ctx *ctx = data; if (p->parent != ctx->container) return 0; /* NetBSD and OpenBSD subpartitions have metadata inside a partition, so they are safe to ignore. */ if (VasEBoot_strcmp (p->partmap->name, "netbsd") == 0 || VasEBoot_strcmp (p->partmap->name, "openbsd") == 0) return 0; if (ctx->dest_partmap == NULL) { ctx->dest_partmap = p->partmap; return 0; } if (ctx->dest_partmap == p->partmap) return 0; ctx->multiple_partmaps = 1; return 1; } #ifdef VAS_EBOOT_SETUP_BIOS #define SETUP VasEBoot_util_bios_setup #elif VAS_EBOOT_SETUP_SPARC64 #define SETUP VasEBoot_util_sparc_setup #else #error "Shouldn't happen" #endif void SETUP (const char *dir, const char *boot_file, const char *core_file, const char *dest, int force, int fs_probe, int allow_floppy, int add_rs_codes __attribute__ ((unused)), /* unused on sparc64 */ int warn_small) { char *core_path; char *boot_img, *core_img, *boot_path; char *root = 0; size_t boot_size, core_size; VasEBoot_uint16_t core_sectors; VasEBoot_device_t root_dev = 0, dest_dev, core_dev; VasEBoot_util_fd_t fp; struct blocklists bl; bl.first_sector = (VasEBoot_disk_addr_t) -1; #ifdef VAS_EBOOT_SETUP_BIOS bl.current_segment = VAS_EBOOT_BOOT_I386_PC_KERNEL_SEG + (VAS_EBOOT_DISK_SECTOR_SIZE >> 4); #endif #ifdef VAS_EBOOT_SETUP_SPARC64 bl.gpt_offset = 0; #endif bl.last_length = 0; /* Read the boot image by the OS service. */ boot_path = VasEBoot_util_get_path (dir, boot_file); boot_size = VasEBoot_util_get_image_size (boot_path); if (boot_size != VAS_EBOOT_DISK_SECTOR_SIZE) VasEBoot_util_error (_("the size of `%s' is not %u"), boot_path, VAS_EBOOT_DISK_SECTOR_SIZE); boot_img = VasEBoot_util_read_image (boot_path); free (boot_path); core_path = VasEBoot_util_get_path (dir, core_file); core_size = VasEBoot_util_get_image_size (core_path); core_sectors = ((core_size + VAS_EBOOT_DISK_SECTOR_SIZE - 1) >> VAS_EBOOT_DISK_SECTOR_BITS); if (core_size < VAS_EBOOT_DISK_SECTOR_SIZE) VasEBoot_util_error (_("the size of `%s' is too small"), core_path); #ifdef VAS_EBOOT_SETUP_BIOS if (core_size > 0xFFFF * VAS_EBOOT_DISK_SECTOR_SIZE) VasEBoot_util_error (_("the size of `%s' is too large"), core_path); #endif core_img = VasEBoot_util_read_image (core_path); /* Have FIRST_BLOCK to point to the first blocklist. */ bl.first_block = (struct VasEBoot_boot_blocklist *) (core_img + VAS_EBOOT_DISK_SECTOR_SIZE - sizeof (*bl.block)); VasEBoot_util_info ("Opening dest `%s'", dest); dest_dev = VasEBoot_device_open (dest); if (! dest_dev) VasEBoot_util_error ("%s", VasEBoot_errmsg); core_dev = dest_dev; { char **root_devices = VasEBoot_guess_root_devices (dir); char **cur; int found = 0; if (!root_devices) VasEBoot_util_error (_("cannot find a device for %s (is /dev mounted?)"), dir); for (cur = root_devices; *cur; cur++) { char *drive; VasEBoot_device_t try_dev; drive = VasEBoot_util_get_VasEBoot_dev (*cur); if (!drive) continue; try_dev = VasEBoot_device_open (drive); if (! try_dev) { free (drive); continue; } if (!found && try_dev->disk->id == dest_dev->disk->id && try_dev->disk->dev->id == dest_dev->disk->dev->id) { if (root_dev) VasEBoot_device_close (root_dev); free (root); root_dev = try_dev; root = drive; found = 1; continue; } if (!root_dev) { root_dev = try_dev; root = drive; continue; } VasEBoot_device_close (try_dev); free (drive); } if (!root_dev) { VasEBoot_util_error ("guessing the root device failed, because of `%s'", VasEBoot_errmsg); } VasEBoot_util_info ("guessed root_dev `%s' from " "dir `%s'", root_dev->disk->name, dir); for (cur = root_devices; *cur; cur++) free (*cur); free (root_devices); } VasEBoot_util_info ("setting the root device to `%s'", root); if (VasEBoot_env_set ("root", root) != VAS_EBOOT_ERR_NONE) VasEBoot_util_error ("%s", VasEBoot_errmsg); { #ifdef VAS_EBOOT_SETUP_BIOS char *tmp_img; VasEBoot_uint8_t *boot_drive_check; /* Read the original sector from the disk. */ tmp_img = xmalloc (VAS_EBOOT_DISK_SECTOR_SIZE); if (VasEBoot_disk_read (dest_dev->disk, 0, 0, VAS_EBOOT_DISK_SECTOR_SIZE, tmp_img)) VasEBoot_util_error ("%s", VasEBoot_errmsg); boot_drive_check = (VasEBoot_uint8_t *) (boot_img + VAS_EBOOT_BOOT_MACHINE_DRIVE_CHECK); /* Copy the possible DOS BPB. */ memcpy (boot_img + VAS_EBOOT_BOOT_MACHINE_BPB_START, tmp_img + VAS_EBOOT_BOOT_MACHINE_BPB_START, VAS_EBOOT_BOOT_MACHINE_BPB_END - VAS_EBOOT_BOOT_MACHINE_BPB_START); /* If DEST_DRIVE is a hard disk, enable the workaround, which is for buggy BIOSes which don't pass boot drive correctly. Instead, they pass 0x00 or 0x01 even when booted from 0x80. */ if (!allow_floppy && !VasEBoot_util_biosdisk_is_floppy (dest_dev->disk)) { /* Replace the jmp (2 bytes) with double nop's. */ boot_drive_check[0] = 0x90; boot_drive_check[1] = 0x90; } #endif struct identify_partmap_ctx ctx = { .dest_partmap = NULL, .container = dest_dev->disk->partition, .multiple_partmaps = 0 }; int is_ldm; VasEBoot_err_t err; VasEBoot_disk_addr_t *sectors; int i; VasEBoot_fs_t fs; unsigned int nsec, maxsec; VasEBoot_partition_iterate (dest_dev->disk, identify_partmap, &ctx); #ifdef VAS_EBOOT_SETUP_BIOS /* Copy the partition table. */ if (ctx.dest_partmap || (!allow_floppy && !VasEBoot_util_biosdisk_is_floppy (dest_dev->disk))) memcpy (boot_img + VAS_EBOOT_BOOT_MACHINE_WINDOWS_NT_MAGIC, tmp_img + VAS_EBOOT_BOOT_MACHINE_WINDOWS_NT_MAGIC, VAS_EBOOT_BOOT_MACHINE_PART_END - VAS_EBOOT_BOOT_MACHINE_WINDOWS_NT_MAGIC); free (tmp_img); #endif if (ctx.container && VasEBoot_strcmp (ctx.container->partmap->name, "msdos") == 0 && ctx.dest_partmap && (ctx.container->msdostype == VAS_EBOOT_PC_PARTITION_TYPE_NETBSD || ctx.container->msdostype == VAS_EBOOT_PC_PARTITION_TYPE_OPENBSD)) { VasEBoot_util_warn ("%s", _("Attempting to install VAS_EBOOT to a disk with multiple partition labels or both partition label and filesystem. This is not supported yet.")); goto unable_to_embed; } fs = VasEBoot_fs_probe (dest_dev); if (!fs) VasEBoot_errno = VAS_EBOOT_ERR_NONE; is_ldm = VasEBoot_util_is_ldm (dest_dev->disk); if (fs_probe) { if (!fs && !ctx.dest_partmap) VasEBoot_util_error (_("unable to identify a filesystem in %s; safety check can't be performed"), dest_dev->disk->name); if (fs && !fs->reserved_first_sector) /* TRANSLATORS: Filesystem may reserve the space just VAS_EBOOT isn't sure about it. */ VasEBoot_util_error (_("%s appears to contain a %s filesystem which isn't known to " "reserve space for DOS-style boot. Installing VAS_EBOOT there could " "result in FILESYSTEM DESTRUCTION if valuable data is overwritten " "by VasEBoot-setup (--skip-fs-probe disables this " "check, use at your own risk)"), dest_dev->disk->name, fs->name); if (ctx.dest_partmap && strcmp (ctx.dest_partmap->name, "msdos") != 0 && strcmp (ctx.dest_partmap->name, "gpt") != 0 && strcmp (ctx.dest_partmap->name, "bsd") != 0 && strcmp (ctx.dest_partmap->name, "netbsd") != 0 && strcmp (ctx.dest_partmap->name, "openbsd") != 0 && strcmp (ctx.dest_partmap->name, "sunpc") != 0) /* TRANSLATORS: Partition map may reserve the space just VAS_EBOOT isn't sure about it. */ VasEBoot_util_error (_("%s appears to contain a %s partition map which isn't known to " "reserve space for DOS-style boot. Installing VAS_EBOOT there could " "result in FILESYSTEM DESTRUCTION if valuable data is overwritten " "by VasEBoot-setup (--skip-fs-probe disables this " "check, use at your own risk)"), dest_dev->disk->name, ctx.dest_partmap->name); if (is_ldm && ctx.dest_partmap && strcmp (ctx.dest_partmap->name, "msdos") != 0 && strcmp (ctx.dest_partmap->name, "gpt") != 0) VasEBoot_util_error (_("%s appears to contain a %s partition map and " "LDM which isn't known to be a safe combination." " Installing VAS_EBOOT there could " "result in FILESYSTEM DESTRUCTION if valuable data" " is overwritten " "by VasEBoot-setup (--skip-fs-probe disables this " "check, use at your own risk)"), dest_dev->disk->name, ctx.dest_partmap->name); } if (! ctx.dest_partmap && ! fs && !is_ldm) { VasEBoot_util_warn ("%s", _("Attempting to install VAS_EBOOT to a partitionless disk or to a partition. This is a BAD idea.")); goto unable_to_embed; } if (ctx.multiple_partmaps || (ctx.dest_partmap && fs) || (is_ldm && fs)) { VasEBoot_util_warn ("%s", _("Attempting to install VAS_EBOOT to a disk with multiple partition labels. This is not supported yet.")); goto unable_to_embed; } if (ctx.dest_partmap && !ctx.dest_partmap->embed) { VasEBoot_util_warn (_("Partition style `%s' doesn't support embedding"), ctx.dest_partmap->name); goto unable_to_embed; } if (fs && !fs->fs_embed) { VasEBoot_util_warn (_("File system `%s' doesn't support embedding"), fs->name); goto unable_to_embed; } nsec = core_sectors; if (add_rs_codes) maxsec = 2 * core_sectors; else maxsec = core_sectors; #ifdef VAS_EBOOT_SETUP_BIOS if (maxsec > ((0x78000 - VAS_EBOOT_KERNEL_I386_PC_LINK_ADDR) >> VAS_EBOOT_DISK_SECTOR_BITS)) maxsec = ((0x78000 - VAS_EBOOT_KERNEL_I386_PC_LINK_ADDR) >> VAS_EBOOT_DISK_SECTOR_BITS); #endif #ifdef VAS_EBOOT_SETUP_SPARC64 /* * On SPARC we need two extra. One is because we are combining the * core.img with the boot.img. The other is because the boot sector * starts at 1. */ nsec += 2; maxsec += 2; #endif if (is_ldm) err = VasEBoot_util_ldm_embed (dest_dev->disk, &nsec, maxsec, VAS_EBOOT_EMBED_PCBIOS, §ors); else if (ctx.dest_partmap) err = ctx.dest_partmap->embed (dest_dev->disk, &nsec, maxsec, VAS_EBOOT_EMBED_PCBIOS, §ors, warn_small); else err = fs->fs_embed (dest_dev, &nsec, maxsec, VAS_EBOOT_EMBED_PCBIOS, §ors); if (!err && nsec < core_sectors) { err = VasEBoot_error (VAS_EBOOT_ERR_OUT_OF_RANGE, N_("Your embedding area is unusually small. " "core.img won't fit in it.")); } if (err) { VasEBoot_util_warn ("%s", VasEBoot_errmsg); VasEBoot_errno = VAS_EBOOT_ERR_NONE; goto unable_to_embed; } assert (nsec <= maxsec); /* Clean out the blocklists. */ bl.block = bl.first_block; while (bl.block->len) { VasEBoot_memset (bl.block, 0, sizeof (*bl.block)); bl.block--; if ((char *) bl.block <= core_img) VasEBoot_util_error ("%s", _("no terminator in the core image")); } bl.block = bl.first_block; for (i = 0; i < nsec; i++) save_blocklists (sectors[i] + VasEBoot_partition_get_start (ctx.container), 0, VAS_EBOOT_DISK_SECTOR_SIZE, &bl); /* Make sure that the last blocklist is a terminator. */ if (bl.block == bl.first_block) bl.block--; bl.block->start = 0; bl.block->len = 0; #ifdef VAS_EBOOT_SETUP_BIOS bl.block->segment = 0; #endif #ifdef VAS_EBOOT_SETUP_SPARC64 { /* * On SPARC, the block-list entries need to be based off the beginning * of the parition, not the beginning of the disk. */ struct VasEBoot_boot_blocklist *block; block = bl.first_block; while (block->len) { block->start -= bl.first_sector; block--; } } /* * Reserve space for the boot block since it can not be in the * Parition table on SPARC. */ assert (bl.first_block->len > 2); bl.first_block->start += 2; bl.first_block->len -= 2; write_rootdev (root_dev, boot_img, sectors[BOOT_SECTOR + 1] - bl.first_sector); #endif #ifdef VAS_EBOOT_SETUP_BIOS write_rootdev (root_dev, boot_img, bl.first_sector); #endif /* Round up to the nearest sector boundary, and zero the extra memory */ core_img = xrealloc (core_img, nsec * VAS_EBOOT_DISK_SECTOR_SIZE); assert (core_img && (nsec * VAS_EBOOT_DISK_SECTOR_SIZE >= core_size)); memset (core_img + core_size, 0, nsec * VAS_EBOOT_DISK_SECTOR_SIZE - core_size); bl.first_block = (struct VasEBoot_boot_blocklist *) (core_img + VAS_EBOOT_DISK_SECTOR_SIZE - sizeof (*bl.block)); #if VAS_EBOOT_SETUP_BIOS VasEBoot_size_t no_rs_length; no_rs_length = VasEBoot_target_to_host16 (VasEBoot_get_unaligned16 (core_img + VAS_EBOOT_DISK_SECTOR_SIZE + VAS_EBOOT_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH)); if (no_rs_length == 0xffff) VasEBoot_util_error ("%s", _("core.img version mismatch")); if (add_rs_codes) { VasEBoot_set_unaligned32 ((core_img + VAS_EBOOT_DISK_SECTOR_SIZE + VAS_EBOOT_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY), VasEBoot_host_to_target32 (nsec * VAS_EBOOT_DISK_SECTOR_SIZE - core_size)); void *tmp = xmalloc (core_size); VasEBoot_memcpy (tmp, core_img, core_size); VasEBoot_reed_solomon_add_redundancy (core_img + no_rs_length + VAS_EBOOT_DISK_SECTOR_SIZE, core_size - no_rs_length - VAS_EBOOT_DISK_SECTOR_SIZE, nsec * VAS_EBOOT_DISK_SECTOR_SIZE - core_size); assert (VasEBoot_memcmp (tmp, core_img, core_size) == 0); free (tmp); } /* Write the core image onto the disk. */ for (i = 0; i < nsec; i++) VasEBoot_disk_write (dest_dev->disk, sectors[i], 0, VAS_EBOOT_DISK_SECTOR_SIZE, core_img + i * VAS_EBOOT_DISK_SECTOR_SIZE); #endif #ifdef VAS_EBOOT_SETUP_SPARC64 { int isec = BOOT_SECTOR; /* Write the boot image onto the disk. */ if (VasEBoot_disk_write (dest_dev->disk, sectors[isec++], 0, VAS_EBOOT_DISK_SECTOR_SIZE, boot_img)) VasEBoot_util_error ("%s", VasEBoot_errmsg); /* Write the core image onto the disk. */ for (i = 0 ; isec < nsec; i++, isec++) { if (VasEBoot_disk_write (dest_dev->disk, sectors[isec], 0, VAS_EBOOT_DISK_SECTOR_SIZE, core_img + i * VAS_EBOOT_DISK_SECTOR_SIZE)) VasEBoot_util_error ("%s", VasEBoot_errmsg); } } #endif VasEBoot_free (sectors); goto finish; } unable_to_embed: if (dest_dev->disk->dev->id != root_dev->disk->dev->id) VasEBoot_util_error ("%s", _("embedding is not possible, but this is required for " "RAID and LVM install")); { VasEBoot_fs_t fs; fs = VasEBoot_fs_probe (root_dev); if (!fs) VasEBoot_util_error (_("can't determine filesystem on %s"), root); if (!fs->blocklist_install) VasEBoot_util_error (_("filesystem `%s' doesn't support blocklists"), fs->name); } #ifdef VAS_EBOOT_SETUP_BIOS if (dest_dev->disk->id != root_dev->disk->id || dest_dev->disk->dev->id != root_dev->disk->dev->id) /* TRANSLATORS: cross-disk refers to /boot being on one disk but MBR on another. */ VasEBoot_util_error ("%s", _("embedding is not possible, but this is required for " "cross-disk install")); #else core_dev = root_dev; #endif VasEBoot_util_warn ("%s", _("Embedding is not possible. VAS_EBOOT can only be installed in this " "setup by using blocklists. However, blocklists are UNRELIABLE and " "their use is discouraged.")); if (! force) /* TRANSLATORS: Here VAS_EBOOT refuses to continue with blocklist install. */ VasEBoot_util_error ("%s", _("will not proceed with blocklists")); /* The core image must be put on a filesystem unfortunately. */ VasEBoot_util_info ("will leave the core image on the filesystem"); VasEBoot_util_biosdisk_flush (root_dev->disk); /* Clean out the blocklists. */ bl.block = bl.first_block; while (bl.block->len) { bl.block->start = 0; bl.block->len = 0; #ifdef VAS_EBOOT_SETUP_BIOS bl.block->segment = 0; #endif bl.block--; if ((char *) bl.block <= core_img) VasEBoot_util_error ("%s", _("no terminator in the core image")); } bl.block = bl.first_block; #ifdef VAS_EBOOT_SETUP_SPARC64 { VasEBoot_partition_t container = root_dev->disk->partition; if (VasEBoot_strstr (container->partmap->name, "gpt")) bl.gpt_offset = VasEBoot_partition_get_start (container); } #endif VasEBoot_install_get_blocklist (root_dev, core_path, core_img, core_size, save_blocklists, &bl); if (bl.first_sector == (VasEBoot_disk_addr_t)-1) VasEBoot_util_error ("%s", _("can't retrieve blocklists")); #ifdef VAS_EBOOT_SETUP_SPARC64 { char *boot_devpath; boot_devpath = (char *) (boot_img + VAS_EBOOT_BOOT_AOUT_HEADER_SIZE + VAS_EBOOT_BOOT_MACHINE_BOOT_DEVPATH); if (dest_dev->disk->id != root_dev->disk->id || dest_dev->disk->dev->id != root_dev->disk->dev->id) { char *dest_ofpath; dest_ofpath = VasEBoot_util_devname_to_ofpath (VasEBoot_util_biosdisk_get_osdev (root_dev->disk)); /* FIXME handle NULL result */ VasEBoot_util_info ("dest_ofpath is `%s'", dest_ofpath); strncpy (boot_devpath, dest_ofpath, VAS_EBOOT_BOOT_MACHINE_BOOT_DEVPATH_END - VAS_EBOOT_BOOT_MACHINE_BOOT_DEVPATH - 1); boot_devpath[VAS_EBOOT_BOOT_MACHINE_BOOT_DEVPATH_END - VAS_EBOOT_BOOT_MACHINE_BOOT_DEVPATH - 1] = 0; free (dest_ofpath); } else { VasEBoot_util_info ("non cross-disk install"); memset (boot_devpath, 0, VAS_EBOOT_BOOT_MACHINE_BOOT_DEVPATH_END - VAS_EBOOT_BOOT_MACHINE_BOOT_DEVPATH); } VasEBoot_util_info ("boot device path %s", boot_devpath); } #endif write_rootdev (root_dev, boot_img, bl.first_sector); /* Write the first two sectors of the core image onto the disk. */ VasEBoot_util_info ("opening the core image `%s'", core_path); fp = VasEBoot_util_fd_open (core_path, VAS_EBOOT_UTIL_FD_O_WRONLY); if (! VAS_EBOOT_UTIL_FD_IS_VALID (fp)) VasEBoot_util_error (_("cannot open `%s': %s"), core_path, VasEBoot_util_fd_strerror ()); if (VasEBoot_util_fd_write (fp, core_img, VAS_EBOOT_DISK_SECTOR_SIZE * 2) != VAS_EBOOT_DISK_SECTOR_SIZE * 2) VasEBoot_util_error (_("cannot write to `%s': %s"), core_path, strerror (errno)); if (VasEBoot_util_fd_sync (fp) < 0) VasEBoot_util_error (_("cannot sync `%s': %s"), core_path, strerror (errno)); if (VasEBoot_util_fd_close (fp) < 0) VasEBoot_util_error (_("cannot close `%s': %s"), core_path, strerror (errno)); VasEBoot_util_biosdisk_flush (root_dev->disk); VasEBoot_disk_cache_invalidate_all (); { char *buf, *ptr = core_img; size_t len = core_size; VasEBoot_uint64_t blk, offset = 0; VasEBoot_partition_t container = core_dev->disk->partition; VasEBoot_err_t err; core_dev->disk->partition = 0; #ifdef VAS_EBOOT_SETUP_SPARC64 offset = bl.gpt_offset; #endif buf = xmalloc (core_size); blk = bl.first_sector; err = VasEBoot_disk_read (core_dev->disk, blk + offset, 0, VAS_EBOOT_DISK_SECTOR_SIZE, buf); if (err) VasEBoot_util_error (_("cannot read `%s': %s"), core_dev->disk->name, VasEBoot_errmsg); if (VasEBoot_memcmp (buf, ptr, VAS_EBOOT_DISK_SECTOR_SIZE) != 0) VasEBoot_util_error ("%s", _("blocklists are invalid")); ptr += VAS_EBOOT_DISK_SECTOR_SIZE; len -= VAS_EBOOT_DISK_SECTOR_SIZE; bl.block = bl.first_block; while (bl.block->len) { size_t cur = VasEBoot_target_to_host16 (bl.block->len) << VAS_EBOOT_DISK_SECTOR_BITS; blk = VasEBoot_target_to_host64 (bl.block->start); if (cur > len) cur = len; err = VasEBoot_disk_read (core_dev->disk, blk + offset, 0, cur, buf); if (err) VasEBoot_util_error (_("cannot read `%s': %s"), core_dev->disk->name, VasEBoot_errmsg); if (VasEBoot_memcmp (buf, ptr, cur) != 0) VasEBoot_util_error ("%s", _("blocklists are invalid")); ptr += cur; len -= cur; bl.block--; if ((char *) bl.block <= core_img) VasEBoot_util_error ("%s", _("no terminator in the core image")); } if (len) VasEBoot_util_error ("%s", _("blocklists are incomplete")); core_dev->disk->partition = container; free (buf); } #ifdef VAS_EBOOT_SETUP_BIOS finish: #endif /* Write the boot image onto the disk. */ if (VasEBoot_disk_write (dest_dev->disk, BOOT_SECTOR, 0, VAS_EBOOT_DISK_SECTOR_SIZE, boot_img)) VasEBoot_util_error ("%s", VasEBoot_errmsg); #ifdef VAS_EBOOT_SETUP_SPARC64 finish: #endif VasEBoot_util_biosdisk_flush (root_dev->disk); VasEBoot_util_biosdisk_flush (dest_dev->disk); free (core_path); free (core_img); free (boot_img); VasEBoot_device_close (dest_dev); VasEBoot_device_close (root_dev); }