diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2017-12-31 18:47:16 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2017-12-31 18:47:25 +0100 |
commit | 3a96085b999220c4da0c5ef7d1f7ba26b9ddfb98 (patch) | |
tree | 77f1445aae2e6be5135594e95986b3278bbc061c /package/aboot/src/tools/abootconf.c | |
parent | cc28479164b8dc8afd4310716da32f16022f5974 (diff) |
dec-multia: make netboot possible, add aboot bootloader
Diffstat (limited to 'package/aboot/src/tools/abootconf.c')
-rw-r--r-- | package/aboot/src/tools/abootconf.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/package/aboot/src/tools/abootconf.c b/package/aboot/src/tools/abootconf.c new file mode 100644 index 000000000..0d0ae075c --- /dev/null +++ b/package/aboot/src/tools/abootconf.c @@ -0,0 +1,125 @@ +/* + * abootconf.c + * + * This file is part of aboot, the SRM bootloader for Linux/Alpha + * Copyright (C) 1996 Linus Torvalds, David Mosberger, and Michael Schwingen. + * + * This program 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 2 of the + * License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <sys/fcntl.h> + +#include <config.h> + + +const char * prog_name; + +int +main (int argc, char ** argv) +{ + unsigned long sector[512 / sizeof(unsigned long)]; + off_t aboot_pos; + size_t nbytes; + long part = -1; + int disk, i; + + prog_name = argv[0]; + + if (argc != 2 && argc != 3) { + fprintf(stderr, "usage: %s device [partition]\n", prog_name); + exit(1); + } + + if (argc > 2) { + errno = 0; + part = strtol(argv[2], 0, 10); + if (errno == ERANGE) { + fprintf(stderr, "%s: bad partition number %s\n", + prog_name, argv[2]); + exit(1); + } + } + + disk = open(argv[1], part < 0 ? O_RDONLY : O_RDWR); + if (disk < 0) { + perror(argv[1]); + exit(1); + } + + nbytes = read(disk, sector, sizeof(sector)); + if (nbytes != sizeof(sector)) { + if ((long) nbytes < 0) { + perror("read"); + } else { + fprintf(stderr, "%s: short read\n", prog_name); + } + exit(1); + } + + aboot_pos = sector[61] * 512; + + if (lseek(disk, aboot_pos, SEEK_SET) != aboot_pos) { + perror("lseek"); + exit(1); + } + + nbytes = read(disk, sector, sizeof(sector)); + if (nbytes != sizeof(sector)) { + if ((long) nbytes < 0) { + perror("read"); + } else { + fprintf(stderr, "%s: short read\n", prog_name); + } + exit(1); + } + + for (i = 0; i < (int) (sizeof(sector)/sizeof(sector[0])); ++i) { + if (sector[i] == ABOOT_MAGIC) + break; + } + if (i >= (int) (sizeof(sector)/sizeof(sector[0]))) { + fprintf(stderr, "%s: could not find aboot on disk %s\n", + prog_name, argv[1]); + exit(1); + } + + if (part < 0) { + printf("aboot.conf partition currently set to %ld\n", + sector[i + 1]); + exit(0); + } + + if (lseek(disk, aboot_pos, SEEK_SET) != aboot_pos) { + perror("lseek"); + exit(1); + } + + sector[i + 1] = atoi(argv[2]); + + nbytes = write(disk, sector, sizeof(sector)); + if (nbytes != sizeof(sector)) { + if ((long) nbytes < 0) { + perror("write"); + } else { + fprintf(stderr, "%s: short write\n", prog_name); + } + exit(1); + } + return 0; +} |