// SPDX-License-Identifier: GPL-2.0-or-later /* Simple utility to make a single-image install kernel with initial ramdisk for Sparc tftpbooting without need to set up nfs.
Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) Pete Zaitcev <zaitcev@yahoo.com> endian fixes for cross-compiles, 2000. Copyright (C) 2011 Sam Ravnborg <sam@ravnborg.org>
staticvoid usage(void)
{ /* fs_img.gz is an image of initial ramdisk. */
fprintf(stderr, "Usage: piggyback bits vmlinux.aout System.map fs_img.gz\n");
fprintf(stderr, "\tKernel image will be modified in place.\n"); exit(1);
}
/* * Find address for start and end in System.map. * The file looks like this: * f0004000 ... _start * f0379f79 ... _end * 1234567890123456 * ^coloumn 1 * There is support for 64 bit addresses too. * * Return 0 if either start or end is not found
*/ staticint get_start_end(constchar *filename, unsignedint *start, unsignedint *end)
{
FILE *map; char buffer[1024];
#define LOOKBACK (128 * 4) #define BUFSIZE 1024 /* * Find the HdrS entry from head_32/head_64. * We check if it is at the beginning of the file (sparc64 case) * and if not we search for it. * When we search do so in steps of 4 as HdrS is on a 4-byte aligned * address (it is on same alignment as sparc instructions) * Return the offset to the HdrS entry (as off_t)
*/ static off_t get_hdrs_offset(int kernelfd, constchar *filename)
{ char buffer[BUFSIZE];
off_t offset; int i;
if (lseek(kernelfd, 0, SEEK_SET) < 0)
die("lseek"); if (read(kernelfd, buffer, BUFSIZE) != BUFSIZE)
die(filename);
if (buffer[40] == 'H' && buffer[41] == 'd' &&
buffer[42] == 'r' && buffer[43] == 'S') { return 40;
} else { /* Find the gokernel label */ /* Decode offset from branch instruction */
offset = ld2(buffer + AOUT_TEXT_OFFSET + 2) << 2; /* Go back 512 bytes so we do not miss HdrS */
offset -= LOOKBACK; /* skip a.out header */
offset += AOUT_TEXT_OFFSET; if (offset < 0) {
errno = -EINVAL;
die("Calculated a negative offset, probably elftoaout generated an invalid image. Did you use a recent elftoaout ?");
} if (lseek(kernelfd, offset, SEEK_SET) < 0)
die("lseek"); if (read(kernelfd, buffer, BUFSIZE) != BUFSIZE)
die(filename);
for (i = 0; i < LOOKBACK; i += 4) { if (buffer[i + 0] == 'H' && buffer[i + 1] == 'd' &&
buffer[i + 2] == 'r' && buffer[i + 3] == 'S') { return offset + i;
}
}
}
fprintf (stderr, "Couldn't find headers signature in %s\n", filename); exit(1);
}
int main(int argc,char **argv)
{ staticchar aout_magic[] = { 0x01, 0x03, 0x01, 0x07 }; char buffer[1024]; unsignedint i, start, end;
off_t offset; struct stat s; int image, tail;
if (argc != 5)
usage(); if (strcmp(argv[1], "64") == 0)
is64bit = 1; if (stat (argv[4], &s) < 0)
die(argv[4]);
if (!get_start_end(argv[3], &start, &end)) {
fprintf(stderr, "Could not determine start and end from %s\n",
argv[3]); exit(1);
} if ((image = open(argv[2], O_RDWR)) < 0)
die(argv[2]); if (read(image, buffer, 512) != 512)
die(argv[2]); if (memcmp(buffer, aout_magic, 4) != 0) {
fprintf (stderr, "Not a.out. Don't blame me.\n"); exit(1);
} /* * We need to fill in values for * sparc_ramdisk_image + sparc_ramdisk_size * To locate these symbols search for the "HdrS" text which appear * in the image a little before the gokernel symbol. * See definition of these in init_32.S
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.