Changeset View
Changeset View
Standalone View
Standalone View
sys/tools/embed_mfs.sh
Show All 30 Lines | |||||
# $1: kernel filename | # $1: kernel filename | ||||
# $2: MFS image filename | # $2: MFS image filename | ||||
# | # | ||||
mfs_size=`stat -f '%z' $2 2> /dev/null` | mfs_size=`stat -f '%z' $2 2> /dev/null` | ||||
# If we can't determine MFS image size - bail. | # If we can't determine MFS image size - bail. | ||||
[ -z ${mfs_size} ] && echo "Can't determine MFS image size" && exit 1 | [ -z ${mfs_size} ] && echo "Can't determine MFS image size" && exit 1 | ||||
sec_info=`${CROSS_BINUTILS_PREFIX}objdump -h $1 2> /dev/null | grep " oldmfs "` | sec_info=`elfdump -c $1 2> /dev/null | grep -A 5 "sh_name: oldmfs$"` | ||||
emaste: I suspect you want at least the leading space, to avoid a possible false positive elsewhere? | |||||
Done Inline ActionsHow about this: grep -A 5 "sh_name: oldmfs$" ? lwhsu: How about this: `grep -A 5 "sh_name: oldmfs$"` ? | |||||
Done Inline ActionsI seem to have lost my comment, so adding again after accepting: Much better. You might want an explicit egrep or grep -E for the $ though? emaste: I seem to have lost my comment, so adding again after accepting:
Much better. You might want… | |||||
# If we can't find the mfs section within the given kernel - bail. | # If we can't find the mfs section within the given kernel - bail. | ||||
[ -z "${sec_info}" ] && echo "Can't locate mfs section within kernel" && exit 1 | [ -z "${sec_info}" ] && echo "Can't locate mfs section within kernel" && exit 1 | ||||
sec_size=`echo ${sec_info} | awk '{printf("%d", "0x" $3)}' 2> /dev/null` | sec_size=`echo "${sec_info}" | awk '/sh_size/ {print $2}' 2> /dev/null` | ||||
sec_start=`echo ${sec_info} | awk '{printf("%d", "0x" $6)}' 2> /dev/null` | sec_start=`echo "${sec_info}" | awk '/sh_offset/ {print $2}' 2> /dev/null` | ||||
Done Inline Actionsso your delimeter is ' ' and you look for 10th element in the list ? It does not work for me may be we can still use awk here? it should work and easier to read, for example: sec_size=`echo ${sec_info} | grep sh_size | awk '{print $2}' 2> /dev/null` br: so your delimeter is ' ' and you look for 10th element in the list ? It does not work for me… | |||||
Done Inline ActionsI don't like this, either. But I found that sec_info=`elfdump -c $1 2> /dev/null | grep "oldmfs" -A 5` just concatenates all lines into one line thus awk does not work here. I'll try to find a more elegant solution. lwhsu: I don't like this, either. But I found that
```
sec_info=`elfdump -c $1 2> /dev/null | grep… | |||||
Done Inline ActionsYou can simplify the pipeline with something like awk '/sh_size/ {print $2}/ emaste: You can simplify the pipeline with something like `awk '/sh_size/ {print $2}/` | |||||
# If the mfs section size is smaller than the mfs image - bail. | # If the mfs section size is smaller than the mfs image - bail. | ||||
[ ${sec_size} -lt ${mfs_size} ] && echo "MFS image too large" && exit 1 | [ ${sec_size} -lt ${mfs_size} ] && echo "MFS image too large" && exit 1 | ||||
# Dump the mfs image into the mfs section | # Dump the mfs image into the mfs section | ||||
dd if=$2 ibs=8192 of=$1 obs=${sec_start} oseek=1 conv=notrunc 2> /dev/null && \ | dd if=$2 ibs=8192 of=$1 obs=${sec_start} oseek=1 conv=notrunc 2> /dev/null && \ | ||||
echo "MFS image embedded into kernel" && exit 0 | echo "MFS image embedded into kernel" && exit 0 |
I suspect you want at least the leading space, to avoid a possible false positive elsewhere? Also I think it's conventional to put the options before the grep string.
So perhaps grep -A 5 " oldmfs"?