#!/bin/sh # $NetBSD$ # Convert a kernel to an U-Boot image. usage="$0 [-z][-e entry_point] kernel image" # XXXXX: # The u-boot has some problems before version 1.1.5. This version change # the max gunzip size to 8MByte from 4Mbyte. Also call ntohl() as entry # point address. # If you use 1.1.4 and older version then: # must specify '-e entry_point' if your machine works little endian. # And # don't specify -z if your kernel size over 4M. # Image header structure (U-Boot use BigEndian). # uint32_t ih_magic : Image Header Magic Number # uint32_t ih_hcrc : Image Header CRC Checksum # uint32_t ih_time : Image Creation Timestamp # uint32_t ih_size : Image Data Size # uint32_t ih_load : Data Load Address # uint32_t ih_ep : Entry Point Address # uint32_t ih_dcrc : Image Data CRC Checksum # uint8_t ih_os : Operating System # uint8_t ih_arch : CPU architecure # uint8_t ih_type : Image Type # uint8_t ih_comp : Compression Type # uint8_t ih_name[32] : Image Name ih_magic=0x27051956 # U-Boot magic number ih_os=2 # NetBSD ih_type=2 # Standalone Program: 1, OS Kernel Image: 2 ih_comp=0 # No: 0, gzip: 1 args=`getopt e:z $*` if [ $? -ne 0 ]; then echo usage: ${usage} 1>&2 exit 2 fi set -- $args while [ $# -gt 2 ]; do case "$1" in -e) ih_ep=$2; shift ;; -z) ih_comp=1 ;; --) shift; break ;; esac shift done if [ $# -ne 2 ]; then echo usage: ${usage} 1>&2 exit 1 fi kernel=$1; shift output=$1; shift : ${OBJDUMP=objdump} : ${OBJCOPY=objcopy} # set CPU architecure (ih_arc) case "${MACHINE}" in evbarm) ih_arch=2 ;; evbmips) ih_arch=5 ;; evbppc) ih_arch=7 ;; evbm68k) ih_arch=12 ;; esac # set Data Load Address(ih_load)/Image Data Size(ih_size) start=`${OBJDUMP} -f ${kernel} | awk '/start address/ { print $NF }'` ih_load=`printf "%d" ${start}` if [ -z ${ih_ep} ]; then # set Entry Point Address(ih_ep) ih_ep=${ih_load} fi ${OBJCOPY} -O binary ${kernel} ${kernel}.bin.$$ data_file=${kernel}.bin if [ ${ih_comp} -eq 1 ]; then gzip -9cn ${kernel}.bin.$$ > ${kernel}.bin.gz.$$ data_file=${kernel}.bin.gz fi ih_size=`/bin/ls -l ${data_file}.$$ | awk '{ print $5 }'` ih_hcrc=0 ih_time=`date +%s` gzip -cn ${data_file}.$$ > ${data_file}.gz.$$ ih_dcrc=0x`gzip -lv ${data_file}.gz.$$ | tail -n1 | awk '{ print $2 }'` dir=`pwd` ih_name="NetBSD "`sh ${S}/conf/osrelease.sh`" ("`basename ${dir}`")" # Create temporarily header printf "%d\n%d\n%d\n%d\n%d\n%d\n%d\n" ${ih_magic} ${ih_hcrc} ${ih_time} \ ${ih_size} ${ih_load} ${ih_ep} ${ih_dcrc} | awk '{ printf "%c", int($0 / 256 / 256 / 256) % 256; printf "%c", int($0 / 256 / 256 ) % 256; printf "%c", int($0 / 256 ) % 256; printf "%c", int($0 ) % 256; } ' > ${output}.hdr.$$ printf "%d\n%d\n%d\n%d\n" ${ih_os} ${ih_arch} ${ih_type} ${ih_comp} | awk '{ printf "%c", $0 }' >> ${output}.hdr.$$ printf "%-31s\0" "${ih_name}" >> ${output}.hdr.$$ # Calculate header CRC gzip -c ${output}.hdr.$$ > ${output}.hdr.gz.$$ ih_hcrc=0x`gzip -lv ${output}.hdr.gz.$$ | tail -n1 | awk '{ print $2 }'` # Create header printf "%d\n%d\n%d\n%d\n%d\n%d\n%d\n" ${ih_magic} ${ih_hcrc} ${ih_time} \ ${ih_size} ${ih_load} ${ih_ep} ${ih_dcrc} | awk '{ printf "%c", int($0 / 256 / 256 / 256) % 256; printf "%c", int($0 / 256 / 256 ) % 256; printf "%c", int($0 / 256 ) % 256; printf "%c", int($0 ) % 256; } ' > ${output} printf "%d\n%d\n%d\n%d\n" ${ih_os} ${ih_arch} ${ih_type} ${ih_comp} | awk '{ printf "%c", $0 }' >> ${output} printf "%-31s\0" "${ih_name}" >> ${output} cat ${data_file}.$$ >> ${output} rm -f ${kernel}.bin.$$ ${kernel}.bin.gz.$$ ${kernel}.bin.gz.gz.$$ \ ${output}.hdr.$$ ${output}.hdr.gz.$$ exit