minix/usr.bin/mkimage/mkimage.c
Thomas Veerman a209c3ae12 Fix a ton of compiler warnings
This patch fixes most of current reasons to generate compiler warnings.
The changes consist of:
 - adding missing casts
 - hiding or unhiding function declarations
 - including headers where missing
 - add __UNCONST when assigning a const char * to a char *
 - adding missing return statements
 - changing some types from unsigned to signed, as the code seems to want
   signed ints
 - converting old-style function definitions to current style (i.e.,
   void func(param1, param2) short param1, param2; {...} to
   void func (short param1, short param2) {...})
 - making the compiler silent about signed vs unsigned comparisons. We
   have too many of those in the new libc to fix.

A number of bugs in the test set were fixed. These bugs were never
triggered with our old libc. Consequently, these tests are now forced to
link with the new libc or they will generate errors (in particular tests 43
and 55).

Most changes in NetBSD libc are limited to moving aroudn "#ifndef __minix"
or stuff related to Minix-specific things (code in sys-minix or gen/minix).
2011-11-14 10:07:49 +00:00

120 lines
2.3 KiB
C

/*
* Update physical addresses of boot services
*/
#include <sys/param.h>
#include <err.h>
#include <fcntl.h>
#include <gelf.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <unistd.h>
#include <getopt.h>
#define BOOTPROG_LOAD_START 0x05000000ULL
int nflag = 0;
int stack_kbytes[] = {
/* ds rs pm sched vfs memory log tty mfs vm pfs init */
16, 8125, 32, 32, 16, 8, 32, 16, 128, 128, 128, 64
};
static void usage(void);
GElf_Addr
update_paddr(int nr, char *fname, GElf_Addr startaddr)
{
int i, fd;
Elf *e;
size_t n;
GElf_Phdr phdr;
GElf_Addr endaddr = 0;
if ((fd = open(fname, O_RDWR, 0)) < 0)
err(EX_NOINPUT, "open \"%s\" failed", fname);
if ((e = elf_begin(fd, ELF_C_RDWR, NULL)) == NULL)
errx(EX_SOFTWARE, "elf_begin() failed: %s.", elf_errmsg(-1));
if (elf_kind(e) != ELF_K_ELF)
errx(EX_DATAERR, "\"%s\" is not an ELF object.", fname);
if (elf_getphdrnum(e, &n) != 0)
errx(EX_DATAERR, "elf_getphdrnum() failed: %s.", elf_errmsg(-1));
for (i = 0; i < n; i++) {
if (gelf_getphdr(e, i, &phdr) != &phdr)
errx(EX_SOFTWARE, "getphdr() failed: %s.",
elf_errmsg(-1));
if (phdr.p_type == PT_LOAD) {
phdr.p_paddr = startaddr + phdr.p_vaddr;
endaddr = round_page(phdr.p_paddr + phdr.p_memsz)
+ round_page(stack_kbytes[nr] * 1024);
if (gelf_update_phdr(e, i, &phdr) < 0)
errx(EX_SOFTWARE,
"gelf_update_phdr failed: %s.",
elf_errmsg(-1));
}
}
if (elf_update(e, ELF_C_WRITE) < 0)
errx(EX_SOFTWARE, "elf_update failed: %s.", elf_errmsg(-1));
(void) elf_end(e);
(void) close(fd);
return endaddr;
}
int
main(int argc, char **argv)
{
int i, ch;
GElf_Addr startaddr;
startaddr = BOOTPROG_LOAD_START;
while ((ch = getopt(argc, argv, "n")) != -1) {
switch (ch) {
case 'n':
nflag = 1;
break;
case '?':
default:
usage();
exit(EX_USAGE);
}
}
argc -= optind;
argv += optind;
if (argc < 1)
usage();
if (elf_version(EV_CURRENT) == EV_NONE)
errx(EX_SOFTWARE, "ELF library intialization failed: %s",
elf_errmsg(-1));
startaddr = BOOTPROG_LOAD_START;
for (i = 0; i < argc; i++) {
startaddr = update_paddr(i, argv[i], startaddr);
}
exit(EX_OK);
}
static void
usage(void)
{
(void) fprintf(stderr, "usage: %s [-n] elf1 elf2...\n", getprogname());
}