/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Simon Burge.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
if (check_elf32(mappedbfile, osb.st_size) != 0)
errx(1, "No ELF header in %s", bootfile);
for (i = 0; i < X_NSYMS; i++) {
if (findoff_elf32(mappedbfile, osb.st_size, nl[i].n_value, &offsets[i]) != 0)
errx(1, "Couldn't find offset for %s in %s", nl[i].n_name, bootfile);
#ifdef DEBUG
printf("%s is at offset %#x in %s\n", nl[i].n_name, offsets[i], bootfile);
#endif
}
/* read the exec header */
i = read(ifd, (char *)&ehdr, sizeof(ehdr));
if ((i != sizeof(ehdr)) ||
(memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0) ||
(ehdr.e_ident[EI_CLASS] != ELFCLASS32)) {
errx(1, "No ELF header in %s", kernel);
}
nsegs = highaddr = 0;
lowaddr = UINT_MAX;
for (i = 0; i < ehdr.e_phnum; i++) {
if (lseek(ifd, (off_t) ehdr.e_phoff + i * sizeof(phdr), 0) < 0)
err(1, "%s", kernel);
if (read(ifd, &phdr, sizeof(phdr)) != sizeof(phdr))
err(1, "%s", kernel);
if (phdr.p_type != PT_LOAD)
continue;
printf("load section %d at addr 0x%08x, file offset %8d, length %8d\n",
i, phdr.p_paddr, phdr.p_offset, phdr.p_filesz);
printf("max kernelsize = %ld\n", NLVAR(X_MAXKERNEL_SIZE));
printf("compressed size = %ld\n", destlen);
if (destlen > NLVAR(X_MAXKERNEL_SIZE))
errx(1, "kernel %s is too big, "
"increase KERNELSIZE to at least %ld",
kernel, destlen);