summaryrefslogtreecommitdiff
path: root/arch/ppc/boot/utils
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@tango.paulus.ozlabs.org>2002-02-11 20:41:44 +1100
committerPaul Mackerras <paulus@tango.paulus.ozlabs.org>2002-02-11 20:41:44 +1100
commitdb7bfdb0276574b29618179004ced1de8dcf40c0 (patch)
treef65179bd228616f902065bc92a96ad394f4b0097 /arch/ppc/boot/utils
parent0dc68d77428413d0f417df3a378f857a2e798ebf (diff)
Import arch/ppc and include/asm-ppc changes from linuxppc_2_5 tree
Diffstat (limited to 'arch/ppc/boot/utils')
-rw-r--r--arch/ppc/boot/utils/Makefile3
-rw-r--r--arch/ppc/boot/utils/addRamDisk.c203
-rw-r--r--arch/ppc/boot/utils/addSystemMap.c186
-rw-r--r--arch/ppc/boot/utils/mkbugboot.c189
-rw-r--r--arch/ppc/boot/utils/mkevimg488
-rwxr-xr-xarch/ppc/boot/utils/mkimage.wrapper16
-rw-r--r--arch/ppc/boot/utils/mkirimg367
-rw-r--r--arch/ppc/boot/utils/mksimage.c127
-rw-r--r--arch/ppc/boot/utils/mktree.c149
-rw-r--r--arch/ppc/boot/utils/offset4
-rw-r--r--arch/ppc/boot/utils/piggyback.c69
-rw-r--r--arch/ppc/boot/utils/sioffset4
-rw-r--r--arch/ppc/boot/utils/sisize4
-rw-r--r--arch/ppc/boot/utils/size4
14 files changed, 745 insertions, 1068 deletions
diff --git a/arch/ppc/boot/utils/Makefile b/arch/ppc/boot/utils/Makefile
index 3f5f79a39887..c29bbe44a683 100644
--- a/arch/ppc/boot/utils/Makefile
+++ b/arch/ppc/boot/utils/Makefile
@@ -10,7 +10,8 @@ HOSTCFLAGS += -I$(TOPDIR)/arch/$(ARCH)/boot/include
all: dummy
# Simple programs with 1 file and no extra CFLAGS
-UTILS = addnote hack-coff mkprep mksimage mknote piggyback mkpmon mkbugboot
+UTILS = addnote hack-coff mkprep mknote mkbugboot mktree \
+ addSystemMap addRamdDisk
$(UTILS):
$(HOSTCC) $(HOSTCFLAGS) -o $@ $@.c
diff --git a/arch/ppc/boot/utils/addRamDisk.c b/arch/ppc/boot/utils/addRamDisk.c
new file mode 100644
index 000000000000..92a09ebf7c12
--- /dev/null
+++ b/arch/ppc/boot/utils/addRamDisk.c
@@ -0,0 +1,203 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+
+#define ElfHeaderSize (64 * 1024)
+#define ElfPages (ElfHeaderSize / 4096)
+#define KERNELBASE (0xc0000000)
+
+void get4k(FILE *file, char *buf )
+{
+ unsigned j;
+ unsigned num = fread(buf, 1, 4096, file);
+ for ( j=num; j<4096; ++j )
+ buf[j] = 0;
+}
+
+void put4k(FILE *file, char *buf )
+{
+ fwrite(buf, 1, 4096, file);
+}
+
+void death(const char *msg, FILE *fdesc, const char *fname)
+{
+ printf(msg);
+ fclose(fdesc);
+ unlink(fname);
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ char inbuf[4096];
+ FILE *ramDisk = NULL;
+ FILE *inputVmlinux = NULL;
+ FILE *outputVmlinux = NULL;
+ unsigned i = 0;
+ u_int32_t ramFileLen = 0;
+ u_int32_t ramLen = 0;
+ u_int32_t roundR = 0;
+ u_int32_t kernelLen = 0;
+ u_int32_t actualKernelLen = 0;
+ u_int32_t round = 0;
+ u_int32_t roundedKernelLen = 0;
+ u_int32_t ramStartOffs = 0;
+ u_int32_t ramPages = 0;
+ u_int32_t roundedKernelPages = 0;
+ u_int32_t hvReleaseData = 0;
+ u_int32_t eyeCatcher = 0xc8a5d9c4;
+ u_int32_t naca = 0;
+ u_int32_t xRamDisk = 0;
+ u_int32_t xRamDiskSize = 0;
+ if ( argc < 2 ) {
+ printf("Name of RAM disk file missing.\n");
+ exit(1);
+ }
+
+ if ( argc < 3 ) {
+ printf("Name of vmlinux file missing.\n");
+ exit(1);
+ }
+
+ if ( argc < 4 ) {
+ printf("Name of vmlinux output file missing.\n");
+ exit(1);
+ }
+
+ ramDisk = fopen(argv[1], "r");
+ if ( ! ramDisk ) {
+ printf("RAM disk file \"%s\" failed to open.\n", argv[1]);
+ exit(1);
+ }
+ inputVmlinux = fopen(argv[2], "r");
+ if ( ! inputVmlinux ) {
+ printf("vmlinux file \"%s\" failed to open.\n", argv[2]);
+ exit(1);
+ }
+ outputVmlinux = fopen(argv[3], "w+");
+ if ( ! outputVmlinux ) {
+ printf("output vmlinux file \"%s\" failed to open.\n", argv[3]);
+ exit(1);
+ }
+ fseek(ramDisk, 0, SEEK_END);
+ ramFileLen = ftell(ramDisk);
+ fseek(ramDisk, 0, SEEK_SET);
+ printf("%s file size = %d\n", argv[1], ramFileLen);
+
+ ramLen = ramFileLen;
+
+ roundR = 4096 - (ramLen % 4096);
+ if ( roundR ) {
+ printf("Rounding RAM disk file up to a multiple of 4096, adding %d\n", roundR);
+ ramLen += roundR;
+ }
+
+ printf("Rounded RAM disk size is %d\n", ramLen);
+ fseek(inputVmlinux, 0, SEEK_END);
+ kernelLen = ftell(inputVmlinux);
+ fseek(inputVmlinux, 0, SEEK_SET);
+ printf("kernel file size = %d\n", kernelLen);
+ if ( kernelLen == 0 ) {
+ printf("You must have a linux kernel specified as argv[2]\n");
+ exit(1);
+ }
+
+ actualKernelLen = kernelLen - ElfHeaderSize;
+
+ printf("actual kernel length (minus ELF header) = %d\n", actualKernelLen);
+
+ round = actualKernelLen % 4096;
+ roundedKernelLen = actualKernelLen;
+ if ( round )
+ roundedKernelLen += (4096 - round);
+
+ printf("actual kernel length rounded up to a 4k multiple = %d\n", roundedKernelLen);
+
+ ramStartOffs = roundedKernelLen;
+ ramPages = ramLen / 4096;
+
+ printf("RAM disk pages to copy = %d\n", ramPages);
+
+ // Copy 64K ELF header
+ for (i=0; i<(ElfPages); ++i) {
+ get4k( inputVmlinux, inbuf );
+ put4k( outputVmlinux, inbuf );
+ }
+
+ roundedKernelPages = roundedKernelLen / 4096;
+
+ fseek(inputVmlinux, ElfHeaderSize, SEEK_SET);
+
+ for ( i=0; i<roundedKernelPages; ++i ) {
+ get4k( inputVmlinux, inbuf );
+ put4k( outputVmlinux, inbuf );
+ }
+
+ for ( i=0; i<ramPages; ++i ) {
+ get4k( ramDisk, inbuf );
+ put4k( outputVmlinux, inbuf );
+ }
+
+ /* Close the input files */
+ fclose(ramDisk);
+ fclose(inputVmlinux);
+ /* And flush the written output file */
+ fflush(outputVmlinux);
+
+ /* fseek to the hvReleaseData pointer */
+ fseek(outputVmlinux, ElfHeaderSize + 0x24, SEEK_SET);
+ if (fread(&hvReleaseData, 4, 1, outputVmlinux) != 1) {
+ death("Could not read hvReleaseData pointer\n", outputVmlinux, argv[3]);
+ }
+ hvReleaseData = ntohl(hvReleaseData); /* Convert to native int */
+ printf("hvReleaseData is at %08x\n", hvReleaseData);
+
+ /* fseek to the hvReleaseData */
+ fseek(outputVmlinux, ElfHeaderSize + hvReleaseData, SEEK_SET);
+ if (fread(inbuf, 0x40, 1, outputVmlinux) != 1) {
+ death("Could not read hvReleaseData\n", outputVmlinux, argv[3]);
+ }
+ /* Check hvReleaseData sanity */
+ if (memcmp(inbuf, &eyeCatcher, 4) != 0) {
+ death("hvReleaseData is invalid\n", outputVmlinux, argv[3]);
+ }
+ /* Get the naca pointer */
+ naca = ntohl(*((u_int32_t *) &inbuf[0x0c])) - KERNELBASE;
+ printf("naca is at %08x\n", naca);
+
+ /* fseek to the naca */
+ fseek(outputVmlinux, ElfHeaderSize + naca, SEEK_SET);
+ if (fread(inbuf, 0x18, 1, outputVmlinux) != 1) {
+ death("Could not read naca\n", outputVmlinux, argv[3]);
+ }
+ xRamDisk = ntohl(*((u_int32_t *) &inbuf[0x0c]));
+ xRamDiskSize = ntohl(*((u_int32_t *) &inbuf[0x14]));
+ /* Make sure a RAM disk isn't already present */
+ if ((xRamDisk != 0) || (xRamDiskSize != 0)) {
+ death("RAM disk is already attached to this kernel\n", outputVmlinux, argv[3]);
+ }
+ /* Fill in the values */
+ *((u_int32_t *) &inbuf[0x0c]) = htonl(ramStartOffs);
+ *((u_int32_t *) &inbuf[0x14]) = htonl(ramPages);
+
+ /* Write out the new naca */
+ fflush(outputVmlinux);
+ fseek(outputVmlinux, ElfHeaderSize + naca, SEEK_SET);
+ if (fwrite(inbuf, 0x18, 1, outputVmlinux) != 1) {
+ death("Could not write naca\n", outputVmlinux, argv[3]);
+ }
+ printf("RAM Disk of 0x%x pages size is attached to the kernel at offset 0x%08x\n",
+ ramPages, ramStartOffs);
+
+ /* Done */
+ fclose(outputVmlinux);
+ /* Set permission to executable */
+ chmod(argv[3], S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
+
+ return 0;
+}
+
diff --git a/arch/ppc/boot/utils/addSystemMap.c b/arch/ppc/boot/utils/addSystemMap.c
new file mode 100644
index 000000000000..8eaa7a09a310
--- /dev/null
+++ b/arch/ppc/boot/utils/addSystemMap.c
@@ -0,0 +1,186 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <byteswap.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+void xlate( char * inb, char * trb, unsigned len )
+{
+ unsigned i;
+ for ( i=0; i<len; ++i ) {
+ char c = *inb++;
+ char c1 = c >> 4;
+ char c2 = c & 0xf;
+ if ( c1 > 9 )
+ c1 = c1 + 'A' - 10;
+ else
+ c1 = c1 + '0';
+ if ( c2 > 9 )
+ c2 = c2 + 'A' - 10;
+ else
+ c2 = c2 + '0';
+ *trb++ = c1;
+ *trb++ = c2;
+ }
+ *trb = 0;
+}
+
+#define ElfHeaderSize (64 * 1024)
+#define ElfPages (ElfHeaderSize / 4096)
+#define KERNELBASE (0xc0000000)
+
+void get4k( /*istream *inf*/FILE *file, char *buf )
+{
+ unsigned j;
+ unsigned num = fread(buf, 1, 4096, file);
+ for ( j=num; j<4096; ++j )
+ buf[j] = 0;
+}
+
+void put4k( /*ostream *outf*/FILE *file, char *buf )
+{
+ fwrite(buf, 1, 4096, file);
+}
+
+int main(int argc, char **argv)
+{
+ char inbuf[4096];
+ FILE *ramDisk = NULL;
+ FILE *inputVmlinux = NULL;
+ FILE *outputVmlinux = NULL;
+ unsigned i = 0;
+ unsigned long ramFileLen = 0;
+ unsigned long ramLen = 0;
+ unsigned long roundR = 0;
+ unsigned long kernelLen = 0;
+ unsigned long actualKernelLen = 0;
+ unsigned long round = 0;
+ unsigned long roundedKernelLen = 0;
+ unsigned long ramStartOffs = 0;
+ unsigned long ramPages = 0;
+ unsigned long roundedKernelPages = 0;
+ if ( argc < 2 ) {
+ printf("Name of System Map file missing.\n");
+ exit(1);
+ }
+
+ if ( argc < 3 ) {
+ printf("Name of vmlinux file missing.\n");
+ exit(1);
+ }
+
+ if ( argc < 4 ) {
+ printf("Name of vmlinux output file missing.\n");
+ exit(1);
+ }
+
+ ramDisk = fopen(argv[1], "r");
+ if ( ! ramDisk ) {
+ printf("System Map file \"%s\" failed to open.\n", argv[1]);
+ exit(1);
+ }
+ inputVmlinux = fopen(argv[2], "r");
+ if ( ! inputVmlinux ) {
+ printf("vmlinux file \"%s\" failed to open.\n", argv[2]);
+ exit(1);
+ }
+ outputVmlinux = fopen(argv[3], "w");
+ if ( ! outputVmlinux ) {
+ printf("output vmlinux file \"%s\" failed to open.\n", argv[3]);
+ exit(1);
+ }
+ fseek(ramDisk, 0, SEEK_END);
+ ramFileLen = ftell(ramDisk);
+ fseek(ramDisk, 0, SEEK_SET);
+ printf("%s file size = %ld\n", argv[1], ramFileLen);
+
+ ramLen = ramFileLen;
+
+ roundR = 4096 - (ramLen % 4096);
+ if ( roundR ) {
+ printf("Rounding System Map file up to a multiple of 4096, adding %ld\n", roundR);
+ ramLen += roundR;
+ }
+
+ printf("Rounded System Map size is %ld\n", ramLen);
+ fseek(inputVmlinux, 0, SEEK_END);
+ kernelLen = ftell(inputVmlinux);
+ fseek(inputVmlinux, 0, SEEK_SET);
+ printf("kernel file size = %ld\n", kernelLen);
+ if ( kernelLen == 0 ) {
+ printf("You must have a linux kernel specified as argv[2]\n");
+ exit(1);
+ }
+
+ actualKernelLen = kernelLen - ElfHeaderSize;
+
+ printf("actual kernel length (minus ELF header) = %ld\n", actualKernelLen);
+
+ round = actualKernelLen % 4096;
+ roundedKernelLen = actualKernelLen;
+ if ( round )
+ roundedKernelLen += (4096 - round);
+
+ printf("actual kernel length rounded up to a 4k multiple = %ld\n", roundedKernelLen);
+
+ ramStartOffs = roundedKernelLen;
+ ramPages = ramLen / 4096;
+
+ printf("System map pages to copy = %ld\n", ramPages);
+
+ // Copy 64K ELF header
+ for (i=0; i<(ElfPages); ++i) {
+ get4k( inputVmlinux, inbuf );
+ put4k( outputVmlinux, inbuf );
+ }
+
+
+
+ roundedKernelPages = roundedKernelLen / 4096;
+
+ fseek(inputVmlinux, ElfHeaderSize, SEEK_SET);
+
+ {
+ for ( i=0; i<roundedKernelPages; ++i ) {
+ get4k( inputVmlinux, inbuf );
+ if ( i == 0 ) {
+ unsigned long * p;
+ printf("Storing embedded_sysmap_start at 0x3c\n");
+ p = (unsigned long *)(inbuf + 0x3c);
+
+#if (BYTE_ORDER == __BIG_ENDIAN)
+ *p = ramStartOffs;
+#else
+ *p = bswap_32(ramStartOffs);
+#endif
+
+ printf("Storing embedded_sysmap_end at 0x44\n");
+ p = (unsigned long *)(inbuf + 0x44);
+#if (BYTE_ORDER == __BIG_ENDIAN)
+ *p = ramStartOffs + ramFileLen;
+#else
+ *p = bswap_32(ramStartOffs + ramFileLen);
+#endif
+ }
+ put4k( outputVmlinux, inbuf );
+ }
+ }
+
+ {
+ for ( i=0; i<ramPages; ++i ) {
+ get4k( ramDisk, inbuf );
+ put4k( outputVmlinux, inbuf );
+ }
+ }
+
+
+ fclose(ramDisk);
+ fclose(inputVmlinux);
+ fclose(outputVmlinux);
+ /* Set permission to executable */
+ chmod(argv[3], S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
+
+ return 0;
+
+}
+
diff --git a/arch/ppc/boot/utils/mkbugboot.c b/arch/ppc/boot/utils/mkbugboot.c
new file mode 100644
index 000000000000..27a744095d05
--- /dev/null
+++ b/arch/ppc/boot/utils/mkbugboot.c
@@ -0,0 +1,189 @@
+/*
+ * arch/ppc/pp3boot/mkbugboot.c
+ *
+ * Makes a Motorola PPCBUG ROM bootable image which can be flashed
+ * into one of the FLASH banks on a Motorola PowerPlus board.
+ *
+ * Author: Matt Porter <mporter@mvista.com>
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ *
+ * 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.
+ */
+
+#define ELF_HEADER_SIZE 65536
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#ifdef __i386__
+#define cpu_to_be32(x) le32_to_cpu(x)
+#define cpu_to_be16(x) le16_to_cpu(x)
+#else
+#define cpu_to_be32(x) (x)
+#define cpu_to_be16(x) (x)
+#endif
+
+#define cpu_to_le32(x) le32_to_cpu((x))
+unsigned long le32_to_cpu(unsigned long x)
+{
+ return (((x & 0x000000ffU) << 24) |
+ ((x & 0x0000ff00U) << 8) |
+ ((x & 0x00ff0000U) >> 8) |
+ ((x & 0xff000000U) >> 24));
+}
+
+#define cpu_to_le16(x) le16_to_cpu((x))
+unsigned short le16_to_cpu(unsigned short x)
+{
+ return (((x & 0x00ff) << 8) |
+ ((x & 0xff00) >> 8));
+}
+
+/* size of read buffer */
+#define SIZE 0x1000
+
+/* typedef long int32_t; */
+typedef unsigned long uint32_t;
+typedef unsigned short uint16_t;
+typedef unsigned char uint8_t;
+
+/* PPCBUG ROM boot header */
+typedef struct bug_boot_header {
+ uint8_t magic_word[4]; /* "BOOT" */
+ uint32_t entry_offset; /* Offset from top of header to code */
+ uint32_t routine_length; /* Length of code */
+ uint8_t routine_name[8]; /* Name of the boot code */
+} bug_boot_header_t;
+
+#define HEADER_SIZE sizeof(bug_boot_header_t)
+
+uint32_t copy_image(int32_t in_fd, int32_t out_fd)
+{
+ uint8_t buf[SIZE];
+ int n;
+ uint32_t image_size = 0;
+ uint8_t zero = 0;
+
+ lseek(in_fd, ELF_HEADER_SIZE, SEEK_SET);
+
+ /* Copy an image while recording its size */
+ while ( (n = read(in_fd, buf, SIZE)) > 0 )
+ {
+ image_size = image_size + n;
+ write(out_fd, buf, n);
+ }
+
+ /* BUG romboot requires that our size is divisible by 2 */
+ /* align image to 2 byte boundary */
+ if (image_size % 2)
+ {
+ image_size++;
+ write(out_fd, &zero, 1);
+ }
+
+ return image_size;
+}
+
+void write_bugboot_header(int32_t out_fd, uint32_t boot_size)
+{
+ uint8_t header_block[HEADER_SIZE];
+ bug_boot_header_t *bbh = (bug_boot_header_t *)&header_block[0];
+
+ bzero(header_block, HEADER_SIZE);
+
+ /* Fill in the PPCBUG ROM boot header */
+ strncpy(bbh->magic_word, "BOOT", 4); /* PPCBUG magic word */
+ bbh->entry_offset = cpu_to_be32(HEADER_SIZE); /* Entry address */
+ bbh->routine_length= cpu_to_be32(HEADER_SIZE+boot_size+2); /* Routine length */
+ strncpy(bbh->routine_name, "LINUXROM", 8); /* Routine name */
+
+ /* Output the header and bootloader to the file */
+ write(out_fd, header_block, HEADER_SIZE);
+}
+
+uint16_t calc_checksum(int32_t bug_fd)
+{
+ uint32_t checksum_var = 0;
+ uint8_t buf[2];
+ int n;
+
+ /* Checksum loop */
+ while ( (n = read(bug_fd, buf, 2) ) )
+ {
+ checksum_var = checksum_var + *(uint16_t *)buf;
+
+ /* If we carry out, mask it and add one to the checksum */
+ if (checksum_var >> 16)
+ checksum_var = (checksum_var & 0x0000ffff) + 1;
+ }
+
+ return checksum_var;
+}
+
+int main(int argc, char *argv[])
+{
+ int32_t image_fd, bugboot_fd;
+ int argptr = 1;
+ uint32_t kernel_size = 0;
+ uint16_t checksum = 0;
+ uint8_t bugbootname[256];
+
+ if ( (argc != 3) )
+ {
+ fprintf(stderr, "usage: %s <kernel_image> <bugboot>\n",argv[0]);
+ exit(-1);
+ }
+
+ /* Get file args */
+
+ /* kernel image file */
+ if ((image_fd = open( argv[argptr] , 0)) < 0)
+ exit(-1);
+ argptr++;
+
+ /* bugboot file */
+ if ( !strcmp( argv[argptr], "-" ) )
+ bugboot_fd = 1; /* stdout */
+ else
+ if ((bugboot_fd = creat( argv[argptr] , 0755)) < 0)
+ exit(-1);
+ else
+ strcpy(bugbootname, argv[argptr]);
+ argptr++;
+
+ /* Set file position after ROM header block where zImage will be written */
+ lseek(bugboot_fd, HEADER_SIZE, SEEK_SET);
+
+ /* Copy kernel image into bugboot image */
+ kernel_size = copy_image(image_fd, bugboot_fd);
+ close(image_fd);
+
+ /* Set file position to beginning where header/romboot will be written */
+ lseek(bugboot_fd, 0, SEEK_SET);
+
+ /* Write out BUG header/romboot */
+ write_bugboot_header(bugboot_fd, kernel_size);
+
+ /* Close bugboot file */
+ close(bugboot_fd);
+
+ /* Reopen it as read/write */
+ bugboot_fd = open(bugbootname, O_RDWR);
+
+ /* Calculate checksum */
+ checksum = calc_checksum(bugboot_fd);
+
+ /* Write out the calculated checksum */
+ write(bugboot_fd, &checksum, 2);
+
+ return 0;
+}
diff --git a/arch/ppc/boot/utils/mkevimg b/arch/ppc/boot/utils/mkevimg
deleted file mode 100644
index 589b18ebc663..000000000000
--- a/arch/ppc/boot/utils/mkevimg
+++ /dev/null
@@ -1,488 +0,0 @@
-#!/usr/bin/perl
-
-#
-# Copyright (c) 1998-1999 TiVo, Inc.
-# All rights reserved.
-#
-# Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
-# Major syntactic and usability rework.
-#
-# Module name: mkevimg
-#
-# Description:
-# Converts an ELF output file from the linker into the format used by
-# the IBM evaluation board ROM Monitor to load programs from a host
-# onto the evaluation board. The ELF file must be an otherwise execut-
-# able file (with the text and data addresses bound at link time) and
-# have space reserved after the entry point for the load information
-# block:
-#
-# typedef struct boot_block {
-# unsigned long magic; 0x0052504F
-# unsigned long dest; Target address of the image
-# unsigned long num_512blocks; Size, rounded-up, in 512 byte blocks
-# unsigned long debug_flag; Run the debugger or image after load
-# unsigned long entry_point; The image address to jump to after load
-# unsigned long checksum; 32 bit checksum including header
-# unsigned long reserved[2];
-# } boot_block_t;
-#
-#
-
-use File::Basename;
-use Getopt::Std;
-
-#
-# usage()
-#
-# Description:
-# This routine prints out the proper command line usage for this program
-#
-# Input(s):
-# status - Flag determining what usage information will be printed and what
-# the exit status of the program will be after the information is
-# printed.
-#
-# Output(s):
-# N/A
-#
-# Returns:
-# This subroutine does not return.
-#
-
-sub usage {
- my($status);
- $status = $_[0];
-
- printf("Usage: %s [-hlvV] <ELF input file> <Evaluation board output file>\n",
- $program);
-
- if ($status != 0) {
- printf("Try `%s -h' for more information.\n", $program);
- }
-
- if ($status != 1) {
- print(" -c Put checksum in load information block.\n");
- print(" -h Print out this message and exit.\n");
- print(" -l Linux mode; if present, copy 'image' and 'initrd' sections.\n");
- print(" -v Verbose. Print out lots of ELF information.\n");
- print(" -V Print out version information and exit.\n");
- }
-
- exit($status);
-}
-
-#
-# version()
-#
-# Description:
-# This routine prints out program version information
-#
-# Input(s):
-# N/A
-#
-# Output(s):
-# N/A
-#
-# Returns:
-# This subroutine does not return.
-#
-
-sub version {
- print("mkevimg Version 1.1.0\n");
- print("Copyright (c) 1998-1999 TiVo, Inc.\n");
- print("Copyright (c) 1999 Grant Erickson <grant\@lcse.umn.edu>\n");
-
- exit (0);
-}
-
-#
-# file_check()
-#
-# Description:
-# This routine checks an input file to ensure that it exists, is a
-# regular file, and is readable.
-#
-# Input(s):
-# file - Input file to be checked.
-#
-# Output(s):
-# N/A
-#
-# Returns:
-# 0 if the file exists, is a regular file, and is readable, otherwise -1.
-#
-
-sub file_check {
- my($file);
- $file = $_[0];
-
- if (!(-e $file)) {
- printf("The file \"%s\" does not exist.\n", $file);
- return (-1);
- } elsif (!(-f $file)) {
- printf("The file \"%s\" is not a regular file.\n", $file);
- return (-1);
- } elsif (!(-r $file)) {
- printf("The file \"%s\" is not readable.\n", $file);
- return (-1);
- }
-
- return (0);
-}
-
-#
-# decode_options()
-#
-# Description:
-# This routine steps through the command-line arguments, parsing out
-# recognzied options.
-#
-# Input(s):
-# N/A
-#
-# Output(s):
-# N/A
-#
-# Returns:
-# N/A
-#
-
-sub decode_options {
-
- if (!getopts("chlvV")) {
- usage(1);
- }
-
- if ($opt_c) {
- $do_checksum = 1;
- }
-
- if ($opt_h) {
- usage(0);
- }
-
- if ($opt_l) {
- $linux = 1;
- }
-
- if ($opt_V) {
- version();
- exit (0);
- }
-
- if ($opt_v) {
- $verbose = 1;
- }
-
- if (!($ifile = shift(@ARGV))) {
- usage(1);
- }
-
- if (!($ofile = shift(@ARGV))) {
- usage (1);
- }
-
- if (file_check($ifile)) {
- exit(1);
- }
-
-}
-
-#
-# ELF file and section header field numbers
-#
-
-require '../utils/elf.pl';
-
-#
-# Main program body
-#
-
-{
- $program = basename($0);
-
- decode_options();
-
- open(ELF, "<$ifile") || die "Cannot open input file";
-
- $ifilesize = (-s $ifile);
-
- if ($verbose) {
- print("Output file: $ofile\n");
- print("Input file: $ifile, $ifilesize bytes.\n");
- }
-
- if (read(ELF, $ibuf, $ifilesize) != $ifilesize) {
- print("Failed to read input file!\n");
- exit(1);
- }
-
- #
- # Parse ELF header
- #
-
- @eh = unpack("a16n2N5n6", $ibuf);
-
- #
- # Make sure this is actually a PowerPC ELF file.
- #
-
- if (substr($eh[$e_ident], 0, 4) ne "\177ELF") {
- printf("The file \"%s\" is not an ELF file.\n", $ifile);
- exit (1);
- } elsif ($eh[$e_machine] != 20) {
- printf("The file \"%s\" is not a PowerPC ELF file.\n", $ifile);
- exit (1);
- }
-
- if ($verbose) {
- print("File header:\n");
- printf(" Identifier: %s\n", $eh[$e_ident]);
- printf(" Type: %d\n", $eh[$e_type]);
- printf(" Machine: %d\n", $eh[$e_machine]);
- printf(" Version: %d\n", $eh[$e_version]);
- printf(" Entry point: 0x%08x\n", $eh[$e_entry]);
- printf(" Program header offset: 0x%x\n", $eh[$e_phoff]);
- printf(" Section header offset: 0x%x\n", $eh[$e_shoff]);
- printf(" Flags: 0x%08x\n", $eh[$e_flags]);
- printf(" Header size: %d\n", $eh[$e_ehsize]);
- printf(" Program entry size: %d\n", $eh[$e_phentsize]);
- printf(" Program table entries: %d\n", $eh[$e_phnum]);
- printf(" Section header size: %d\n", $eh[$e_shentsize]);
- printf(" Section table entries: %d\n", $eh[$e_shnum]);
- printf(" String table section: %d\n", $eh[$e_shstrndx]);
- }
-
- #
- # Find the section header for the string table.
- #
-
- $strtable_section_offset = $eh[$e_shoff] +
- $eh[$e_shstrndx] * $eh[$e_shentsize];
-
- if ($verbose) {
- printf("String table section header offset: 0x%x\n",
- $strtable_section_offset);
- }
-
- #
- # Find the start of the string table.
- #
-
- @strh = unpack("N10", substr($ibuf, $strtable_section_offset,
- $eh[$e_shentsize]));
-
- if ($verbose) {
- printf("Section name strings start at: 0x%x, %d bytes.\n",
- $strh[$sh_offset], $strh[$sh_size]);
- }
-
- $names = substr($ibuf, $strh[$sh_offset], $strh[$sh_size]);
-
- # Grab each section header and find '.text' and '.bss' sections in
- # particular.
-
- if ($verbose) {
- print("Section headers:\n");
- print("Idx Name Size Address File off Algn\n");
- print("--- ------------------------ -------- -------- -------- ----\n");
- }
-
- $off = $eh[$e_shoff];
-
- for($i = 0; $i < $eh[$e_shnum]; $i++, $off += $eh[$e_shentsize]) {
- @sh = unpack("N10", substr($ibuf, $off, $eh[$e_shentsize]));
-
- # Take the first section name from the array returned by split.
-
- ($name) = split(/\000/, substr($names, $sh[$sh_name]));
-
- if ($verbose) {
- printf("%3d %-24s %8x %08x %08x %4d\n",
- $i, $name, $sh[$sh_size], $sh[$sh_addr],
- $sh[$sh_offset], $sh[$sh_addralign]);
- }
-
- # Attempt to find the .text and .bss sections
-
- if ($name =~ /^\.bss$/) {
- ($bss_addr, $bss_offset, $bss_size) =
- ($sh[$sh_addr], $sh[$sh_offset], $sh[$sh_size]);
-
- } elsif ($name =~ /^\.text$/) {
- ($text_addr, $text_offset, $text_size) =
- ($sh[$sh_addr], $sh[$sh_offset], $sh[$sh_size]);
-
- } elsif ($linux && ($name =~ /^\image$/)) {
- $image_found = 1;
-
- ($image_addr, $image_offset, $image_size) =
- ($sh[$sh_addr], $sh[$sh_offset], $sh[$sh_size]);
-
- } elsif ($linux && ($name =~ /^\initrd$/)) {
- $initrd_found = 1;
-
- ($initrd_addr, $initrd_offset, $initrd_size) =
- ($sh[$sh_addr], $sh[$sh_offset], $sh[$sh_size]);
-
- }
- }
-
- printf("Text section - Address: 0x%08x, Size: 0x%08x\n",
- $text_addr, $text_size);
- printf("Bss section - Address: 0x%08x, Size: 0x%08x\n",
- $bss_addr, $bss_size);
-
- if ($linux) {
- if ($image_found) {
- printf("Image section - Address: 0x%08x, Size: 0x%08x\n",
- $image_addr, $image_size);
- }
-
- if ($initrd_found) {
- printf("Initrd section - Address: 0x%08x, Size: 0x%08x\n",
- $initrd_addr, $initrd_size);
- }
- }
-
- #
- # Open output file
- #
-
- open(BOOT, ">$ofile") || die "Cannot open output file";
-
- #
- # Compute image size
- #
-
- $output_size = $bss_offset - $text_offset + $bss_size;
-
- if ($linux && $image_found) {
- $output_size += $image_size;
- }
-
- if ($linux && $initrd_found) {
- $output_size += $initrd_size;
- }
-
- #
- # Compute size with header
- #
-
- $header = pack("H8N7", "0052504f", 0, 0, 0, 0, 0, 0, 0);
- $num_blocks = ($output_size + length($header) + 511) / 512;
-
- #
- # Write IBM PowerPC evaluation board boot_block_t header
- #
-
- $header = pack("H8N7", "0052504f", $text_addr, $num_blocks, 0,
- $text_addr, 0, 0, 0);
-
-
- $bytes = length($header);
-
- if (($resid = syswrite(BOOT, $header, $bytes)) != $bytes) {
- die("Could not write boot image header to output file.");
- }
-
- printf("Entry point = 0x%08x\n", $text_addr);
- printf("Image size = 0x%08x (%d bytes) (%d blocks).\n",
- $output_size, $output_size, $num_blocks);
-
- #
- # Write image starting after ELF and program headers and
- # continuing to beginning of bss
- #
-
- $bytes = $bss_offset - $text_offset + $bss_size;
-
- if (($resid = syswrite(BOOT, $ibuf, $bytes, $text_offset)) != $bytes) {
- die("Could not write boot image to output file.\n");
- }
-
- #
- # If configured, write out the image and initrd sections as well
- #
-
- if ($linux) {
- if ($image_found) {
- $bytes = $image_size;
- if (($resid = syswrite(BOOT, $ibuf, $bytes, $image_offset)) != $bytes) {
- die("Could not write boot image to output file.\n");
- }
- }
-
- if ($initrd_found) {
- $bytes = $initrd_size;
- if (($resid = syswrite(BOOT, $ibuf, $bytes, $initrd_offset)) != $bytes) {
- die("Could not write boot image to output file.\n");
- }
- }
- }
-
- #
- # Pad to a multiple of 512 bytes
- # If the (size of the boot image mod 512) is between 509 and 511 bytes
- # then the tftp to the Walnut fails. This may be fixed in more recent
- # Walnut bootrom.
- #
-
- $pad_size = 512 - ((length($header) + $output_size) % 512);
- if ($pad_size == 512) {
- $pad_size = 0;
- }
-
- if ($pad_size != 0) {
-
- if ($verbose) {
- print("Padding boot image by an additional $pad_size bytes.\n");
- }
-
- $pad_string = pack("H8","deadbeef") x 128;
-
- syswrite(BOOT, $pad_string, $pad_size) or
- die "Could not pad boot image in output file.\n";
-
- }
-
- #
- # Compute 32 bit checksum over entire file.
- #
-
- if ($do_checksum) {
-
- close(BOOT);
- open(BOOT, "+<$ofile") || die "Cannot open output file";
- undef $/;
- $temp = unpack("%32N*", <BOOT>);
- # Solaris and PPC Linux return 0x80000000 for "-$temp" when $temp
- # is negative. "~($temp - 1)" negates $temp properly.
- $csum = ~($temp - 1);
- printf("Checksum = 0x%08x\r\n", $csum);
-
- #
- # Rewrite IBM PowerPC evaluation board boot_block_t header,
- # this time with the checksum included
- #
-
- $header = pack("H8N7", "0052504f", $text_addr, $num_blocks, 0,
- $text_addr, $csum, 0, 0);
-
- seek(BOOT, 0, 0);
- syswrite(BOOT, $header, length($header)) or
- die("Could not write boot image header to output file.");
-
- }
-
- #
- # Clean-up and leave
- #
-
- close(BOOT);
-
- print("\nBoot image file \"$ofile\" built successfully.\n\n");
-
- exit(0);
-}
diff --git a/arch/ppc/boot/utils/mkimage.wrapper b/arch/ppc/boot/utils/mkimage.wrapper
new file mode 100755
index 000000000000..5483d9790ebe
--- /dev/null
+++ b/arch/ppc/boot/utils/mkimage.wrapper
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+#
+# Build PPCBoot image when `mkimage' tool is available.
+#
+
+MKIMAGE=$(type -path mkimage)
+
+if [ -z "${MKIMAGE}" ]; then
+ # Doesn't exist
+ echo '"mkimage" command not found - PPCBoot images will not be built' >&2
+ exit 0;
+fi
+
+# Call "mkimage" to create PPCBoot image
+${MKIMAGE} "$@"
diff --git a/arch/ppc/boot/utils/mkirimg b/arch/ppc/boot/utils/mkirimg
deleted file mode 100644
index fa1b5bbb0a5a..000000000000
--- a/arch/ppc/boot/utils/mkirimg
+++ /dev/null
@@ -1,367 +0,0 @@
-#!/usr/bin/perl
-#
-# Copyright (c) 1998-1999 TiVo, Inc.
-# Original ELF parsing code.
-#
-# Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
-# Original code from 'mkevimg'.
-#
-# Module name: mkirimg
-#
-# Description:
-# Reads an ELF file and assigns global variables 'imageSect_start',
-# 'imageSect_size', 'initrdSect_start', and 'initrdSect_size' from
-# the "image" and "initrd" section header information. It then
-# rewrites the input ELF file with assigned globals to an output
-# file.
-#
-# An input file, "irSectStart.txt" has the memory address of
-# 'irSectStart'. The irSectStart memory address is used to find
-# the global variables in the ".data" section of the ELF file.
-# The 'irSectStart' and the above global variables are defined
-# in "irSect.c".
-#
-#
-
-use File::Basename;
-use Getopt::Std;
-
-#
-# usage()
-#
-# Description:
-# This routine prints out the proper command line usage for this program
-#
-# Input(s):
-# status - Flag determining what usage information will be printed and what
-# the exit status of the program will be after the information is
-# printed.
-#
-# Output(s):
-# N/A
-#
-# Returns:
-# This subroutine does not return.
-#
-
-sub usage {
- my($status);
- $status = $_[0];
-
- printf("Usage: %s [-hvV] <ELF input file> <Evaluation board output file> <irSectStart.txt file>\n",
- $program);
-
- if ($status != 0) {
- printf("Try `%s -h' for more information.\n", $program);
- }
-
- if ($status != 1) {
- print(" -h Print out this message and exit.\n");
- print(" -v Verbose. Print out lots of ELF information.\n");
- print(" -V Print out version information and exit.\n");
- }
-
- exit($status);
-}
-
-#
-# version()
-#
-# Description:
-# This routine prints out program version information
-#
-# Input(s):
-# N/A
-#
-# Output(s):
-# N/A
-#
-# Returns:
-# This subroutine does not return.
-#
-
-sub version {
- print("mkirimg Version 1.1.0\n");
- print("Copyright (c) 1998-1999 TiVo, Inc.\n");
- print("Copyright (c) 1999 Grant Erickson <grant\@lcse.umn.edu>\n");
-
- exit (0);
-}
-
-#
-# file_check()
-#
-# Description:
-# This routine checks an input file to ensure that it exists, is a
-# regular file, and is readable.
-#
-# Input(s):
-# file - Input file to be checked.
-#
-# Output(s):
-# N/A
-#
-# Returns:
-# 0 if the file exists, is a regular file, and is readable, otherwise -1.
-#
-
-sub file_check {
- my($file);
- $file = $_[0];
-
- if (!(-e $file)) {
- printf("The file \"%s\" does not exist.\n", $file);
- return (-1);
- } elsif (!(-f $file)) {
- printf("The file \"%s\" is not a regular file.\n", $file);
- return (-1);
- } elsif (!(-r $file)) {
- printf("The file \"%s\" is not readable.\n", $file);
- return (-1);
- }
-
- return (0);
-}
-
-#
-# decode_options()
-#
-# Description:
-# This routine steps through the command-line arguments, parsing out
-# recognzied options.
-#
-# Input(s):
-# N/A
-#
-# Output(s):
-# N/A
-#
-# Returns:
-# N/A
-#
-
-sub decode_options {
-
- if (!getopts("hvV")) {
- usage(1);
- }
-
- if ($opt_h) {
- usage(0);
- }
-
- if ($opt_V) {
- version();
- exit (0);
- }
-
- if ($opt_v) {
- $verbose = 1;
- }
-
- if (!($ElfFile = shift(@ARGV))) {
- usage(1);
- }
-
- if (!($OutputFile = shift(@ARGV))) {
- usage (1);
- }
-
- if (!($IrFile = shift(@ARGV))) {
- usage (1);
- }
-
- if (file_check($ElfFile)) {
- exit(1);
- }
-
- if (file_check($IrFile)) {
- exit(1);
- }
-}
-
-#
-# ELF file and section header field numbers
-#
-
-require '../utils/elf.pl';
-
-#
-# Main program body
-#
-
-{
- $program = basename($0);
- decode_options();
-
- open(ELF, "<$ElfFile") || die "Cannot open input file";
- open(OUTPUT, ">$OutputFile") || die "Cannot open output file";
- open(IR, "$IrFile") || die "Cannot open input file";
-
- $ElfFilesize = (-s $ElfFile);
-
- if (read(ELF, $ibuf, $ElfFilesize) != $ElfFilesize) {
- print("Failed to read ELF input file!\n");
- exit(1);
- }
-
- if (read(IR, $irbuf, 8) != 8) {
- print("Failed to read Ir input file!\n");
- exit(1);
- }
-
- #
- # Parse ELF header
- #
-
- @eh = unpack("a16n2N5n6", $ibuf);
-
- #
- # Make sure this is actually a PowerPC ELF file.
- #
-
- if (substr($eh[$e_ident], 0, 4) ne "\177ELF") {
- printf("The file \"%s\" is not an ELF file.\n", $ElfFile);
- exit (1);
- } elsif ($eh[$e_machine] != 20) {
- printf("The file \"%s\" is not a PowerPC ELF file.\n", $ElfFile);
- exit (1);
- }
-
- #
- # Find the section header for the string table.
- #
-
- $strtable_section_offset = $eh[$e_shoff] +
-
- $eh[$e_shstrndx] * $eh[$e_shentsize];
-
- if ($verbose) {
- printf("String table section header offset: 0x%x\n",
- $strtable_section_offset);
- }
-
- #
- # Find the start of the string table.
- #
-
- @strh = unpack("N10", substr($ibuf, $strtable_section_offset,
- $eh[$e_shentsize]));
-
- if ($verbose) {
- printf("Section name strings start at: 0x%x, %d bytes.\n",
- $strh[$sh_offset], $strh[$sh_size]);
- }
-
- $names = substr($ibuf, $strh[$sh_offset], $strh[$sh_size]);
-
- # Grab each section header and find '.data', 'image', and
- # 'initrd' sections in particular.
-
- $off = $eh[$e_shoff];
- $imageFound = 0;
- $initrdFound = 0;
-
- for($i = 0; $i < $eh[$e_shnum]; $i++, $off += $eh[$e_shentsize]) {
- @sh = unpack("N10", substr($ibuf, $off, $eh[$e_shentsize]));
-
- # Take the first section name from the array returned by split.
-
- ($name) = split(/\000/, substr($names, $sh[$sh_name]));
-
- # Attempt to find the .data, image, and initrd sections
-
- if ($name =~ /^\image$/) {
- ($image_addr, $image_offset, $image_size) =
- ($sh[$sh_addr], $sh[$sh_offset], $sh[$sh_size]);
- $imageFound = 1;
-
- } elsif ($name =~ /^\initrd$/) {
- ($initrd_addr, $initrd_offset, $initrd_size) =
- ($sh[$sh_addr], $sh[$sh_offset], $sh[$sh_size]);
- $initrdFound = 1;
-
- } elsif ($name =~ /^\.data$/) {
- ($data_addr, $data_offset, $data_size) =
- ($sh[$sh_addr], $sh[$sh_offset], $sh[$sh_size]);
-
- } elsif ($name =~ /^\.bss$/) {
- ($bss_addr, $bss_offset, $bss_size) =
- ($sh[$sh_addr], $sh[$sh_offset], $sh[$sh_size]);
-
- }
- }
-
- if ($verbose) {
- printf("Data section - Address: 0x%08x, Size: 0x%08x, File Offset 0x%08x\n",
- $data_addr, $data_size, $data_offset);
- printf("Bss section - Address: 0x%08x, Size: 0x%08x, File Offset 0x%08x\n",
- $bss_addr, $bss_size, $bss_offset);
- }
-
- if ($verbose) {
- if ($imageFound) {
- printf("Image section - Address: 0x%08x, Size: 0x%08x\n",
- $image_addr, $image_size);
- } else {
- printf("Image section not found in file: $ElfFile\n");
- }
-
- if ($initrdFound) {
- printf("Initrd section - Address: 0x%08x, Size: 0x%08x\n",
- $initrd_addr, $initrd_size);
- } else {
- printf("Initrd section not found in file: $ElfFile\n");
- }
- }
-
- # get file offset of irSectStart
-
- $irSectStartoffset = hex ($irbuf);
-
- if ($verbose) {
- printf("irSectStartOffset Address: 0x%08x\n", $irSectStartoffset);
- }
-
- # get the offset of global variables
-
- $initialOffset = ($irSectStartoffset - $data_addr) + $data_offset + 4;
-
- # write modified values to OUTPUT file
-
- syswrite(OUTPUT, $ibuf, $initialOffset);
-
- if ($imageFound) {
- $testN = pack ("N2", $bss_addr + $bss_size, $image_size);
- syswrite(OUTPUT, $testN, length($testN));
- printf("Updated symbol \"imageSect_start\" to 0x%08x\n",
- $bss_addr + $bss_size);
- printf("Updated symbol \"imageSect_size\" to 0x%08x\n", $image_size);
- } else {
- syswrite(OUTPUT, $ibuf, 8, $initialOffset);
- }
-
- if ($initrdFound) {
- $testN = pack ("N2", $bss_addr + $bss_size + $image_size, $initrd_size);
- syswrite(OUTPUT, $testN, length($testN));
- printf("Updated symbol \"initrdSect_start\" to 0x%08x\n",
- $bss_addr + $bss_size + $image_size);
- printf("Updated symbol \"initrdSect_size\" to 0x%08x\n", $initrd_size);
- } else {
- syswrite(OUTPUT, $ibuf,8, $initialOffset + 8);
- }
-
- syswrite(OUTPUT, $ibuf, $ElfFilesize - ($initialOffset + 16),
- $initialOffset + 16);
-
- #
- # Clean-up and leave
- #
-
- close (ELF);
- close (OUTPUT);
- close (IR);
-
- exit (0);
-}
-
diff --git a/arch/ppc/boot/utils/mksimage.c b/arch/ppc/boot/utils/mksimage.c
deleted file mode 100644
index 721856a9b382..000000000000
--- a/arch/ppc/boot/utils/mksimage.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * BK Id: SCCS/s.mksimage.c 1.6 05/18/01 15:16:42 cort
- */
-/*
- *
- *
- *
- *
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-
-
-#define SIZE 1024
-#define BLOCK_ALIGN(x) (((x)+SIZE-1)&(~(SIZE-1)))
-
-static void
-die(const char *fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- fputc('\n', stderr);
- exit(1);
-}
-
-static void
-usage(void)
-{
- printf("Usage: mkbinimg <bootstrap> <kernel> <ramdisk> -o <binary>\n");
- exit(1);
-}
-
-static int
-copy_blocks(int ifd, int ofd, unsigned long *offset, unsigned long *size)
-{
- off_t cur;
- int amt;
- unsigned long len = 0;
- char buffer[SIZE];
-
- cur = lseek(ofd, 0, SEEK_CUR);
-
- if (cur % SIZE) {
- cur = BLOCK_ALIGN(cur);
- cur = lseek(ofd, cur, SEEK_SET);
- }
-
- *offset = (unsigned long) cur;
- while((amt = read(ifd, buffer, SIZE)) > 0) {
- write(ofd, buffer, amt);
- len += amt;
- }
- *size = len;
- return 0;
-}
-
-
-int
-main(int argc, char *argv[])
-{
- char *kernel, *loader, *rdimage = NULL;
- unsigned long ld_off, kern_off, rd_off;
- unsigned long ld_size, kern_size, rd_size;
- int fd, ofd, len;
- char buffer[500];
-
- if (argc < 5 && !strcmp(argv[argc-2], "-o"))
- usage();
-
- if (argc > 5)
- rdimage = argv[3];
-
- kernel = argv[2];
- loader = argv[1];
-
- ofd = open(argv[argc-1], (O_RDWR|O_CREAT), 0755);
- if (ofd < 0) {
- die("can't open %s: %s", argv[5], strerror(errno));
- }
-
- ld_off = kern_off = rd_off = 0;
- ld_size = kern_size = rd_size = 0;
- memset(buffer, 0, 500);
- len = 0;
-
- fd = open(loader, O_RDONLY);
- if (fd < 0)
- die("can't open loader: %s", strerror(errno));
-
- copy_blocks(fd, ofd, &ld_off, &ld_size);
- len = sprintf(buffer, "bootloader: %x %x\n", ld_off, ld_size);
- close(fd);
-
- fd = open(kernel, O_RDONLY);
- if (fd < 0)
- die("can't open kernel: %s", strerror(errno));
-
- copy_blocks(fd, ofd, &kern_off, &kern_size);
- len += sprintf(buffer+len, "zimage: %x %x\n", kern_off, kern_size);
- close(fd);
-
- if (rdimage) {
- fd = open(rdimage, O_RDONLY);
- if (fd < 0)
- die("can't get ramdisk: %s", strerror(errno));
-
- copy_blocks(fd, ofd, &rd_off, &rd_size);
- close(fd);
- }
-
- len += sprintf(buffer+len, "initrd: %x %x", rd_off, rd_size);
-
- close(ofd);
-
- printf("%s\n", buffer);
-
- return 0;
-}
-
diff --git a/arch/ppc/boot/utils/mktree.c b/arch/ppc/boot/utils/mktree.c
new file mode 100644
index 000000000000..3b5ae6c3dbad
--- /dev/null
+++ b/arch/ppc/boot/utils/mktree.c
@@ -0,0 +1,149 @@
+/*
+ * BK Id: %F% %I% %G% %U% %#%
+ *
+ * Makes a tree bootable image for IBM Evaluation boards.
+ * Basically, just take a zImage, skip the ELF header, and stuff
+ * a 32 byte header on the front.
+ *
+ * We use htonl, which is a network macro, to make sure we're doing
+ * The Right Thing on an LE machine. It's non-obvious, but it should
+ * work on anything BSD'ish.
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <netinet/in.h>
+
+/* This gets tacked on the front of the image. There are also a few
+ * bytes allocated after the _start label used by the boot rom (see
+ * head.S for details).
+ */
+typedef struct boot_block {
+ unsigned long bb_magic; /* 0x0052504F */
+ unsigned long bb_dest; /* Target address of the image */
+ unsigned long bb_num_512blocks; /* Size, rounded-up, in 512 byte blks */
+ unsigned long bb_debug_flag; /* Run debugger or image after load */
+ unsigned long bb_entry_point; /* The image address to start */
+ unsigned long bb_checksum; /* 32 bit checksum including header */
+ unsigned long reserved[2];
+} boot_block_t;
+
+#define IMGBLK 512
+char tmpbuf[IMGBLK];
+
+int main(int argc, char *argv[])
+{
+ int in_fd, out_fd;
+ int nblks, i;
+ uint cksum, *cp;
+ struct stat st;
+ boot_block_t bt;
+
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s <zImage-file> <boot-image> [entry-point]\n",argv[0]);
+ exit(1);
+ }
+
+ if (stat(argv[1], &st) < 0) {
+ perror("stat");
+ exit(2);
+ }
+
+ nblks = (st.st_size + IMGBLK) / IMGBLK;
+
+ bt.bb_magic = htonl(0x0052504F);
+
+ /* If we have the optional entry point parameter, use it */
+ if (argc == 4)
+ bt.bb_dest = bt.bb_entry_point = htonl(strtoul(argv[3], NULL, 0));
+ else
+ bt.bb_dest = bt.bb_entry_point = htonl(0x500000);
+
+ /* We know these from the linker command.
+ * ...and then move it up into memory a little more so the
+ * relocation can happen.
+ */
+ bt.bb_num_512blocks = htonl(nblks);
+ bt.bb_debug_flag = 0;
+
+ bt.bb_checksum = 0;
+
+ /* To be neat and tidy :-).
+ */
+ bt.reserved[0] = 0;
+ bt.reserved[1] = 0;
+
+ if ((in_fd = open(argv[1], O_RDONLY)) < 0) {
+ perror("zImage open");
+ exit(3);
+ }
+
+ if ((out_fd = open(argv[2], (O_RDWR | O_CREAT | O_TRUNC), 0666)) < 0) {
+ perror("bootfile open");
+ exit(3);
+ }
+
+ cksum = 0;
+ cp = (uint *)&bt;
+ for (i=0; i<sizeof(bt)/sizeof(uint); i++)
+ cksum += *cp++;
+
+ /* Assume zImage is an ELF file, and skip the 64K header.
+ */
+ if (read(in_fd, tmpbuf, IMGBLK) != IMGBLK) {
+ fprintf(stderr, "%s is too small to be an ELF image\n",
+ argv[1]);
+ exit(4);
+ }
+
+ if ((*(uint *)tmpbuf) != htonl(0x7f454c46)) {
+ fprintf(stderr, "%s is not an ELF image\n", argv[1]);
+ exit(4);
+ }
+
+ if (lseek(in_fd, (64 * 1024), SEEK_SET) < 0) {
+ fprintf(stderr, "%s failed to seek in ELF image\n", argv[1]);
+ exit(4);
+ }
+
+ nblks -= (64 * 1024) / IMGBLK;
+
+ /* And away we go......
+ */
+ if (write(out_fd, &bt, sizeof(bt)) != sizeof(bt)) {
+ perror("boot-image write");
+ exit(5);
+ }
+
+ while (nblks-- > 0) {
+ if (read(in_fd, tmpbuf, IMGBLK) < 0) {
+ perror("zImage read");
+ exit(5);
+ }
+ cp = (uint *)tmpbuf;
+ for (i=0; i<sizeof(tmpbuf)/sizeof(uint); i++)
+ cksum += *cp++;
+ if (write(out_fd, tmpbuf, sizeof(tmpbuf)) != sizeof(tmpbuf)) {
+ perror("boot-image write");
+ exit(5);
+ }
+ }
+
+ /* rewrite the header with the computed checksum.
+ */
+ bt.bb_checksum = htonl(cksum);
+ if (lseek(out_fd, 0, SEEK_SET) < 0) {
+ perror("rewrite seek");
+ exit(1);
+ }
+ if (write(out_fd, &bt, sizeof(bt)) != sizeof(bt)) {
+ perror("boot-image rewrite");
+ exit(1);
+ }
+
+ exit(0);
+}
diff --git a/arch/ppc/boot/utils/offset b/arch/ppc/boot/utils/offset
deleted file mode 100644
index 52a1b5546e6f..000000000000
--- a/arch/ppc/boot/utils/offset
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-OFFSET=`$1 -h $2 | grep $3 | grep -v zvmlinux| awk '{print $6}'`
-echo "0x"$OFFSET
diff --git a/arch/ppc/boot/utils/piggyback.c b/arch/ppc/boot/utils/piggyback.c
deleted file mode 100644
index 6edfbaaa092e..000000000000
--- a/arch/ppc/boot/utils/piggyback.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * BK Id: SCCS/s.piggyback.c 1.7 05/18/01 15:17:23 cort
- */
-#include <stdio.h>
-#include <unistd.h>
-
-extern long ce_exec_config[];
-
-int main(int argc, char *argv[])
-{
- int i, cnt, pos, len;
- unsigned int cksum, val;
- unsigned char *lp;
- unsigned char buf[8192];
- if (argc != 2)
- {
- fprintf(stderr, "usage: %s name <in-file >out-file\n",
- argv[0]);
- exit(1);
- }
- fprintf(stdout, "#\n");
- fprintf(stdout, "# Miscellaneous data structures:\n");
- fprintf(stdout, "# WARNING - this file is automatically generated!\n");
- fprintf(stdout, "#\n");
- fprintf(stdout, "\n");
- fprintf(stdout, "\t.data\n");
- fprintf(stdout, "\t.globl %s_data\n", argv[1]);
- fprintf(stdout, "%s_data:\n", argv[1]);
- pos = 0;
- cksum = 0;
- while ((len = read(0, buf, sizeof(buf))) > 0)
- {
- cnt = 0;
- lp = (unsigned char *)buf;
- len = (len + 3) & ~3; /* Round up to longwords */
- for (i = 0; i < len; i += 4)
- {
- if (cnt == 0)
- {
- fprintf(stdout, "\t.long\t");
- }
- fprintf(stdout, "0x%02X%02X%02X%02X", lp[0], lp[1], lp[2], lp[3]);
- val = *(unsigned long *)lp;
- cksum ^= val;
- lp += 4;
- if (++cnt == 4)
- {
- cnt = 0;
- fprintf(stdout, " # %x \n", pos+i-12);
- fflush(stdout);
- } else
- {
- fprintf(stdout, ",");
- }
- }
- if (cnt)
- {
- fprintf(stdout, "0\n");
- }
- pos += len;
- }
- fprintf(stdout, "\t.globl %s_len\n", argv[1]);
- fprintf(stdout, "%s_len:\t.long\t0x%x\n", argv[1], pos);
- fflush(stdout);
- fclose(stdout);
- fprintf(stderr, "cksum = %x\n", cksum);
- exit(0);
-}
-
diff --git a/arch/ppc/boot/utils/sioffset b/arch/ppc/boot/utils/sioffset
deleted file mode 100644
index b5245be6c7b1..000000000000
--- a/arch/ppc/boot/utils/sioffset
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-OFFSET=`grep $1 sImage.map | awk '{print $2}'`
-echo "0x"$OFFSET
diff --git a/arch/ppc/boot/utils/sisize b/arch/ppc/boot/utils/sisize
deleted file mode 100644
index 7e8180125dd4..000000000000
--- a/arch/ppc/boot/utils/sisize
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-OFFSET=`grep $1 sImage.map | awk '{print $3}'`
-echo "0x"$OFFSET
diff --git a/arch/ppc/boot/utils/size b/arch/ppc/boot/utils/size
deleted file mode 100644
index 6c48f8d1468d..000000000000
--- a/arch/ppc/boot/utils/size
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-OFFSET=`$1 -h $2 | grep $3 | grep -v zvmlinux | awk '{print $3}'`
-echo "0x"$OFFSET