1#!/bin/bash 2 3if [ $# != 2 ]; then 4 echo Usage: $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_molly 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=$(awk '/^kernel/ || /^module/ {print $2}' $MENU_LST) 34# For each binary generate an object file in the output directory. 35# The flags to objcopy cause it to place the binary image of the input 36# file into an .rodataIDX section in the generated object file where 37# IDX is a counter incremented for each binary. 38IDX=1 39for BIN in $BINS; do 40 #was SLASH=${BIN////_}, which only replaced slashes, but we need to replace "-" for armv7-m 41 UNDERSCORED=${BIN//-/_} 42 SLASH=${UNDERSCORED////_} 43 BIN_OUT="$OUTPUT_PREFIX/${FILE_PREFIX}_$SLASH" 44 OBJCOPY=$(which arm-linux-gnueabi-objcopy) 45 echo $BIN '->' $BIN_OUT 46 $OBJCOPY -I binary -O elf32-littlearm -B arm --rename-section .data=.rodata$IDX,alloc,load,readonly,data,contents .$BIN $BIN_OUT 47 IDX=$(($IDX+1)) 48 if [ $IDX = 20 ]; then 49 echo Error: linker script cannot handle $IDX modules 50 exit 1 51 fi 52done 53 54 55