1#!/bin/bash 2 3if [ $# != 2 ]; then 4 echo Expected $0 menu.lst output_prefix 5 exit 1 6fi 7 8MENU_LST=$1 9OUTPUT_PREFIX=$2 10 11# Prefix prepended to each output file within the directory 12# $OUTPUT_PREFIX (for safety, this means we can clean the directory 13# by removing everything with this prefix) 14FILE_PREFIX=tmp_m5 15 16# Set up output direcotry 17if [ -e $OUTPUT_PREFIX ] && [ ! -d $OUTPUT_PREFIX ]; then 18 echo Error: $OUTPUT_PREFIX exists, but is not a direcotry 19 exit 1 20fi 21 22if [ -d $OUTPUT_PREFIX ]; then 23 echo Cleaning old directory $OUTPUT_PREFIX 24 rm -f $OUTPUT_PREFIX/$FILE_PREFIX* 25fi 26 27if [ ! -d $OUTPUT_PREFIX/ ]; then 28 echo Making output directory $OUTPUT_PREFIX 29 mkdir $OUTPUT_PREFIX 30fi 31 32# Get list of binaries to translate 33BINS=$(grep -e'^kernel' -e'^module' $MENU_LST | awk '{print $2}') 34 35# For each binary generate an object file in the output directory. 36# The flags to objcopy cause it to place the binary image of the input 37# file into an .rodataIDX section in the generated object file where 38# IDX is a counter incremented for each binary. 39IDX=1 40for BIN in $BINS; do 41 SLASH=${BIN////_} 42 BIN_OUT="$OUTPUT_PREFIX/${FILE_PREFIX}_$SLASH" 43 echo $BIN '->' $BIN_OUT 44 objcopy -I binary -O elf64-x86-64 -B i386 --rename-section .data=.rodata$IDX,alloc,load,readonly,data,contents .$BIN $BIN_OUT 45 IDX=$(($IDX+1)) 46 if [ $IDX = 17 ]; then 47 echo Error: linker script cannot handle $IDX modules 48 exit 1 49 fi 50done 51 52 53