From: Antti Kantee Date: Wed, 10 Feb 2016 15:40:34 +0000 (+0000) Subject: rename genfs to cookfs X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=983c515beb186f731c7842a5d36bfa39fc4128bf;p=osstest%2Frumprun.git rename genfs to cookfs --- diff --git a/app-tools/Makefile b/app-tools/Makefile index 4caf7e3..beb5b6f 100644 --- a/app-tools/Makefile +++ b/app-tools/Makefile @@ -31,7 +31,7 @@ BIN_G+= $(TOOLTUPLE)-$(_CXXVARIANT) CCWRP+= ${CXX} endif BIN_G+= rumprun-bake -BIN_G+= $(TOOLTUPLE)-genfs +BIN_G+= $(TOOLTUPLE)-cookfs STATICBIN= rumprun rumpstop GENS.bin= ${BIN_G:%=${TOOLOBJ}/%} @@ -91,7 +91,7 @@ $(eval $(call templ,cc.in,$(TOOLTUPLE)-${_CCVARIANT})) $(eval $(call templ,cc.in,$(TOOLTUPLE)-${_CXXVARIANT})) $(eval $(call templ,specs-bake.in,specs-bake-$(TOOLTUPLE)-$(PLATFORM))) $(eval $(call templ,rumprun-bake.in,rumprun-bake)) -$(eval $(call templ,genfs.in,$(TOOLTUPLE)-genfs)) +$(eval $(call templ,cookfs.in,$(TOOLTUPLE)-cookfs)) define binwrapper uptool_$1=$(shell echo $1 | tr '[:lower:]' '[:upper:]') diff --git a/app-tools/cookfs.in b/app-tools/cookfs.in new file mode 100644 index 0000000..2e946b5 --- /dev/null +++ b/app-tools/cookfs.in @@ -0,0 +1,229 @@ +#!/usr/bin/env sh + +# +# Copyright (c) 2016 Antti Kantee +# All Rights Reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +# +# Include given files as binary and generate constructor code +# which loads said files to rumpfs. +# + +set -eu + +: ${RUMPRUN_GENFS_CC:=!LIBEXEC_CC!} +: ${RUMPRUN_GENFS_OBJCOPY:=!LIBEXEC_OBJCOPY!} +: ${RUMPRUN_GENFS_INCDIR:=!DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/include} + +usage () +{ + + echo "usage: $0 [-s count] outfile directory ..." + exit 1 +} + +die () +{ + + echo ">> ERROR: $*" 2>&1 + exit 1 +} + +nuketmpdir () +{ + + nukeme="${TMPDIR}" + TMPDIR='' + rm -rf ${nukeme} +} + +TMPDIR=$(mktemp -d /tmp/rumprun-genfs.XXXXXX) +trap nuketmpdir 0 INT TERM +LINKPATH=${TMPDIR}/linkme +LINKPATH_BIN="_binary_$(echo ${LINKPATH} | tr '/.-' '_')" + +STRIPCOUNT=0 +while getopts "s:" opt; do + case "${opt}" in + s) + STRIPCOUNT=${OPTARG} + [ -z "$(echo ${STRIPCOUNT} | tr -d '[0-9]')" ] \ + || die argument to -s must be a non-negative decimal + ;; + *) + usage + ;; + esac +done +shift $((${OPTIND}-1)) + +[ $# -ge 2 ] || usage +OUTFILE="$1" +shift + +checkpaths () +{ + + stripcount=${1} + shift + + for sd in "$@"; do + arg="${sd}" + IFS=/ + set -- ${sd} + unset IFS + while [ "$1" = '.' ]; do shift ; done + [ $# -ge ${stripcount} ] || \ + die cannot remove ${STRIPCOUNT} components from \"${arg}\" + done +} + +processfspath () +{ + + n=$1 + path=$2 + + IFS=/ + set -- ${path} + while [ "$1" = '.' ]; do shift ; done + while [ ${n} -gt 0 ]; do + shift + n=$((${n}-1)) + done + unset IFS + + rpath= + while [ $# -gt 0 ]; do + rpath="${rpath}$1/" + shift + done + + echo ${rpath%/} | sed 's/"/\\"/g' +} + +FILES= +for sd in "$@"; do + checkpaths ${STRIPCOUNT} "$@" + FILES="${FILES} $(find ${sd} -type f)" +done + +makedirlist () +{ + DIRS= + for x in ${FILES}; do + d=$(dirname $x) + [ $d != . ] || continue + DIRS="${DIRS} ${d}" + done + DIRS=$(echo ${DIRS} | xargs -n1 | sort | uniq) + + printf 'static const char *dirlist[] = {\n' + for d in ${DIRS}; do + printf '\t"/%s",\n' $(processfspath ${STRIPCOUNT} $d) + done + printf '};\n\n' +} + +setfilevars () +{ + + case $1 in + /*) + fabs="$1" + ;; + *) + fabs="$(pwd)/$1" + ;; + esac + + fn=$((${fn}+1)) + rf=_rumpfs_f${fn} +} + +makeelfdata () +{ + + fn=0 + LSYM= + for f in ${FILES}; do + setfilevars ${f} + ln -sf ${fabs} ${LINKPATH} + ${RUMPRUN_GENFS_CC} !CFLAGS! !CPPFLAGS! -nostdlib \ + -Wl,-r,-b,binary -o ${TMPDIR}/d${fn}.o ${LINKPATH} + ${RUMPRUN_GENFS_OBJCOPY} \ + --redefine-sym ${LINKPATH_BIN}_start=${rf}_start \ + --redefine-sym ${LINKPATH_BIN}_size=${rf}_size \ + --strip-symbol ${LINKPATH_BIN}_end \ + ${TMPDIR}/d${fn}.o + LSYM="${LSYM} -L ${rf}_start -L ${rf}_size" + + printf 'extern uint8_t %s_start, %s_size;\n' ${rf} ${rf} + done + + printf '\n' + printf 'static struct rumprun_extfile files[] = {\n' + + fn=0 + for f in ${FILES}; do + setfilevars %{f} + printf '\t{ "/%s",\n' $(processfspath ${STRIPCOUNT} "${f}") + printf '\t { (void *)&%s_start,\n' ${rf} + printf '\t (size_t)(uintptr_t)&%s_size} },\n' ${rf} + done + + printf '};\n' +} + +printhead () +{ + + printf '#include \n\n' + printf '#include \n\n' +} + +printtail () +{ + + printf 'static void __attribute__((constructor))\n' + printf 'rumpfs_externatilize(void)\n' + printf '{\n\n' + printf '\trumprun_genfs(dirlist, __arraycount(dirlist),\n' + printf '\t files, __arraycount(files));\n' + printf '}\n' +} + +exec 3>&1 1>${TMPDIR}/constr.c +printhead +makedirlist +makeelfdata +printtail +exec 1>&3 3>&- + +${RUMPRUN_GENFS_CC} !CFLAGS! !CPPFLAGS! -I${RUMPRUN_GENFS_INCDIR} \ + -nostdlib -Wl,-r -o ${TMPDIR}/fin.o ${TMPDIR}/d*.o ${TMPDIR}/constr.c +${RUMPRUN_GENFS_OBJCOPY} ${LSYM} ${TMPDIR}/fin.o ${OUTFILE} + +exit 0 diff --git a/app-tools/genfs.in b/app-tools/genfs.in deleted file mode 100644 index 2e946b5..0000000 --- a/app-tools/genfs.in +++ /dev/null @@ -1,229 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright (c) 2016 Antti Kantee -# All Rights Reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS -# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# - -# -# Include given files as binary and generate constructor code -# which loads said files to rumpfs. -# - -set -eu - -: ${RUMPRUN_GENFS_CC:=!LIBEXEC_CC!} -: ${RUMPRUN_GENFS_OBJCOPY:=!LIBEXEC_OBJCOPY!} -: ${RUMPRUN_GENFS_INCDIR:=!DESTDIR!/rumprun-!MACHINE_GNU_ARCH!/include} - -usage () -{ - - echo "usage: $0 [-s count] outfile directory ..." - exit 1 -} - -die () -{ - - echo ">> ERROR: $*" 2>&1 - exit 1 -} - -nuketmpdir () -{ - - nukeme="${TMPDIR}" - TMPDIR='' - rm -rf ${nukeme} -} - -TMPDIR=$(mktemp -d /tmp/rumprun-genfs.XXXXXX) -trap nuketmpdir 0 INT TERM -LINKPATH=${TMPDIR}/linkme -LINKPATH_BIN="_binary_$(echo ${LINKPATH} | tr '/.-' '_')" - -STRIPCOUNT=0 -while getopts "s:" opt; do - case "${opt}" in - s) - STRIPCOUNT=${OPTARG} - [ -z "$(echo ${STRIPCOUNT} | tr -d '[0-9]')" ] \ - || die argument to -s must be a non-negative decimal - ;; - *) - usage - ;; - esac -done -shift $((${OPTIND}-1)) - -[ $# -ge 2 ] || usage -OUTFILE="$1" -shift - -checkpaths () -{ - - stripcount=${1} - shift - - for sd in "$@"; do - arg="${sd}" - IFS=/ - set -- ${sd} - unset IFS - while [ "$1" = '.' ]; do shift ; done - [ $# -ge ${stripcount} ] || \ - die cannot remove ${STRIPCOUNT} components from \"${arg}\" - done -} - -processfspath () -{ - - n=$1 - path=$2 - - IFS=/ - set -- ${path} - while [ "$1" = '.' ]; do shift ; done - while [ ${n} -gt 0 ]; do - shift - n=$((${n}-1)) - done - unset IFS - - rpath= - while [ $# -gt 0 ]; do - rpath="${rpath}$1/" - shift - done - - echo ${rpath%/} | sed 's/"/\\"/g' -} - -FILES= -for sd in "$@"; do - checkpaths ${STRIPCOUNT} "$@" - FILES="${FILES} $(find ${sd} -type f)" -done - -makedirlist () -{ - DIRS= - for x in ${FILES}; do - d=$(dirname $x) - [ $d != . ] || continue - DIRS="${DIRS} ${d}" - done - DIRS=$(echo ${DIRS} | xargs -n1 | sort | uniq) - - printf 'static const char *dirlist[] = {\n' - for d in ${DIRS}; do - printf '\t"/%s",\n' $(processfspath ${STRIPCOUNT} $d) - done - printf '};\n\n' -} - -setfilevars () -{ - - case $1 in - /*) - fabs="$1" - ;; - *) - fabs="$(pwd)/$1" - ;; - esac - - fn=$((${fn}+1)) - rf=_rumpfs_f${fn} -} - -makeelfdata () -{ - - fn=0 - LSYM= - for f in ${FILES}; do - setfilevars ${f} - ln -sf ${fabs} ${LINKPATH} - ${RUMPRUN_GENFS_CC} !CFLAGS! !CPPFLAGS! -nostdlib \ - -Wl,-r,-b,binary -o ${TMPDIR}/d${fn}.o ${LINKPATH} - ${RUMPRUN_GENFS_OBJCOPY} \ - --redefine-sym ${LINKPATH_BIN}_start=${rf}_start \ - --redefine-sym ${LINKPATH_BIN}_size=${rf}_size \ - --strip-symbol ${LINKPATH_BIN}_end \ - ${TMPDIR}/d${fn}.o - LSYM="${LSYM} -L ${rf}_start -L ${rf}_size" - - printf 'extern uint8_t %s_start, %s_size;\n' ${rf} ${rf} - done - - printf '\n' - printf 'static struct rumprun_extfile files[] = {\n' - - fn=0 - for f in ${FILES}; do - setfilevars %{f} - printf '\t{ "/%s",\n' $(processfspath ${STRIPCOUNT} "${f}") - printf '\t { (void *)&%s_start,\n' ${rf} - printf '\t (size_t)(uintptr_t)&%s_size} },\n' ${rf} - done - - printf '};\n' -} - -printhead () -{ - - printf '#include \n\n' - printf '#include \n\n' -} - -printtail () -{ - - printf 'static void __attribute__((constructor))\n' - printf 'rumpfs_externatilize(void)\n' - printf '{\n\n' - printf '\trumprun_genfs(dirlist, __arraycount(dirlist),\n' - printf '\t files, __arraycount(files));\n' - printf '}\n' -} - -exec 3>&1 1>${TMPDIR}/constr.c -printhead -makedirlist -makeelfdata -printtail -exec 1>&3 3>&- - -${RUMPRUN_GENFS_CC} !CFLAGS! !CPPFLAGS! -I${RUMPRUN_GENFS_INCDIR} \ - -nostdlib -Wl,-r -o ${TMPDIR}/fin.o ${TMPDIR}/d*.o ${TMPDIR}/constr.c -${RUMPRUN_GENFS_OBJCOPY} ${LSYM} ${TMPDIR}/fin.o ${OUTFILE} - -exit 0 diff --git a/lib/librumprunfs_base/Makefile b/lib/librumprunfs_base/Makefile index a5f4b66..9a58e35 100644 --- a/lib/librumprunfs_base/Makefile +++ b/lib/librumprunfs_base/Makefile @@ -12,5 +12,5 @@ dependall: ( cd ${.CURDIR} && \ RUMPRUN_GENFS_CC="${CC}" RUMPRUN_GENFS_OBJCOPY="${OBJCOPY}" \ RUMPRUN_GENFS_INCDIR="${RROBJ}/dest.stage/include" \ - ${RROBJ}/app-tools/${TOOLTUPLE}-genfs \ + ${RROBJ}/app-tools/${TOOLTUPLE}-cookfs \ ${MAKEOBJDIR}/librumprunfs_base.a etc )