#!/bin/sh # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # $Source: src/build/tools/hb $ # # OpenPOWER HostBoot Project # # Contributors Listed Below - COPYRIGHT 2011,2017 # [+] International Business Machines Corp. # # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing # permissions and limitations under the License. # # IBM_PROLOG_END_TAG execute_in_sandbox() { [ -z "${SANDBOXBASE}" ] && echo "Missing SANDBOXBASE." && exit 1 [ -z "${SANDBOXROOT}" ] && echo "Missing SANDBOXROOT." && exit 1 [ -z "${SANDBOXNAME}" ] && echo "Missing SANDBOXNAME." && exit 1 if [ ! -d "${SANDBOXBASE}" ]; then echo "Sandbox does not exist. Create with 'hb simsetup." exit 1 fi SANDBOXRC="${SANDBOXROOT}/hbsandboxrc" WORKON_CMD="workon -rc ${SANDBOXRC} -sb ${SANDBOXNAME} -m $2 " echo $1 > ${SANDBOXBASE}/src/sandbox_execute_cmd chmod 700 ${SANDBOXBASE}/src/sandbox_execute_cmd ${WORKON_CMD} -c ./sandbox_execute_cmd if [ $? -ne 0 ]; then echo "Sandbox cmd failed" rm ${SANDBOXBASE}/src/sandbox_execute_cmd exit 1 fi rm ${SANDBOXBASE}/src/sandbox_execute_cmd } needs_machine_variable() { MACHINE=${MACHINE:-$DEFAULT_MACHINE} export MACHINE echo "Setting up for Machine = $MACHINE" } hb_helptext() { echo "Hostboot Utility Script" case $1 in workon) echo " Topic 'workon'" echo echo " Usage:" echo " hb workon" echo echo " Sources necessary environment files for building hostboot" echo " and begins a new shell. The workon may be left via 'exit'." echo echo " Environment Variables:" echo " SHELL: The shell program to launch." echo echo " See also:" echo " customrc" ;; fipssetup) echo " Topic 'fipssetup'" echo echo " Usage:" echo " hb fipssetup" echo echo " Creates a simics workspace (FSP sandbox) in the directed" echo " location." echo echo " FSP backing build are chosen as directed" echo " by the CI test files (src/build/citest/etc)." echo echo " Environment Variables:" echo " SANDBOXROOT: Root directory of where the sandboxes" echo " should go." echo " SANDBOXNAME: Desired name of the hostboot sandbox." ;; simsetup) echo " Topic 'simsetup'" echo echo " Usage:" echo " hb simsetup" echo echo " Creates a simics workspace (FSP sandbox) in the directed" echo " location and initializes simics as well as executing any" echo " hostboot specific workarounds." echo echo " FSP backing build and workarounds are chosen as directed" echo " by the CI test files (src/build/citest/etc)." echo echo " Environment Variables:" echo " SANDBOXROOT: Root directory of where the sandboxes" echo " should go." echo " SANDBOXNAME: Desired name of the hostboot sandbox." ;; prime) echo " Topic 'prime'" echo echo " Usage:" echo " hb prime" echo " hb prime --test" echo echo " Copies hostboot images and simics scripts into the" echo " simics workspace." echo echo " Options:" echo " --test : Copy test images (as opposed to non-test)." echo " --secureboot : Build a secure pnor with proper signing" echo echo " See also:" echo " simsetup" ;; startsimics) echo " Topic 'startsimics'" echo echo " Usage:" echo " hb startsimics " echo echo " Enters the simics workspace and starts simics using the" echo " start_simics utility. Any options are passed directly to" echo " the start_simics script." echo echo " Requires the hostboot image to be 'prime'd into the workspace." echo echo " Environment Variables:" echo " MACHINE: Alternate simics machine type (default NIMBUS)" echo " SIMICSOPTIONS: Additional options to always pass to the" echo " start simics script, such as '-nre'." echo echo " See also:" echo " simsetup, prime" ;; rsync) echo " Topic 'rsync'" echo echo " Usage:" echo " hb rsync " echo echo " Synchronizes an entire Hostboot repository with another" echo " directory. This can be useful for creating a backup of" echo " the repository or for pushing it to a remote host, such" echo " as a pool machine where simics is executed." echo echo " Options:" echo " --force : Skip user prompt for RSYNCDIR confirmation (reserve for cronjobs)." echo echo " Environment Variables:" echo " RSYNCHOST: (optional) remote host to rsync to." echo " RSYNCDIR: Destination directory of the rsync." echo echo " The trailing slash on RSYNCDIR, or lack thereof, has" echo " meaning to rsync. Specifically /.../foo will create a new" echo " directory called 'foo' with the contents of your repository" echo " in it, while /.../foo/ will create a subdirectory within foo" echo " by the name of your repository's directory name." ;; objsizes) echo " Topic 'objsizes'" echo echo " Usage:" echo " hb objsizes" echo echo " Reads the ELF header information from all of the hostboot" echo " modules and generates a CSV output of the sizes of the text" echo " and data sections of the modules." ;; copyright_check) echo " Topic 'copyright_check'" echo echo " Usage:" echo " hb copyright_check" echo echo " Executes addCopyright in validate mode against the most" echo " recent commit in your repository to ensure the prologs are" echo " all added properly." ;; errlparser) echo " Topic 'errlparser'" echo echo " Usage:" echo " hb errlparser" echo echo " Prepares a copy of FipS errl tool that is hostboot aware," echo " places it in simics directory." ;; cachesync) echo " Topic 'cachesync'" echo echo " Usage:" echo " hb cachesync" echo echo " Synchronizes the repository's binary file cache with the" echo " project repository." ;; cacheadd) echo " Topic 'cacheadd'" echo echo " Usage:" echo " hb cacheadd [--local] \"\"" echo echo " Inserts a file into the project binary file cache." echo echo " Options:" echo " --local: Indicates file should be put only in local cache." ;; customrc) echo " Topic 'customrc'" echo echo " Setting up this file in the root of your repository gives a" echo " convienient way to create default environment variables for" echo " the 'hb' script and your hostboot workon environment. Some" echo " of the hb sub-commands require environment variables assigned" echo " and they should be done through this 'customrc' file. You" echo " may also use this as a place to source other files you need" echo " for your environment, such as setting up 'git'." echo echo " The 'customrc' file is in the .gitignore file and should" echo " NEVER be committed to git. These are your own custom " echo " settings." echo echo " The minimal example 'customrc' file is as follows:" echo " #!/bin/sh" echo " export SANDBOXROOT=~/sandboxes" echo " export SANDBOXNAME=hostboot" echo echo " See also:" echo " All other sub-commands." ;; *) echo " Usage:" echo " hb " echo " hb help [|]" echo echo " Available Commands:" echo " workon, simsetup, prime, startsimics, rsync, objsizes," echo " copyright_check, errlparser, cachesync, cacheadd, fipssetup" echo echo " Additional Help Topics:" echo " customrc" echo echo " For initial setup:" echo " 1) Create customrc file." echo " 2) hb workon" echo " 3) hb simsetup" echo " 4) Create images (edit code, make, etc.)." echo " 5) hb prime [--test]" echo " 6) hb startsimics" echo " 7) Return to step 4 until satisfied." ;; esac } hb_workon() { if [ -n "${HOSTBOOT_INSIDE_WORKON}" ]; then echo "Already in a workon." exit 1 else export HOSTBOOT_INSIDE_WORKON=1 echo "Setting environment variables..." . ./env.bash echo "Spawning new shell (${SHELL})..." ${SHELL} && exit 0 fi } hb_prime() { [ -z "${SANDBOXBASE}" ] && echo "Missing SANDBOXBASE." && exit 1 [ -z "${PROJECT_ROOT}" ] && echo "Missing PROJECT_ROOT." && exit 1 if [ ! -d "${SANDBOXBASE}" ]; then echo "Sandbox does not exist. Create with 'hb simsetup." exit 1 fi # Prevent error message in cases where SANDBOXBASE is set but hb simsetup # is not performed. Example seen in cronjob scripts if [[ -f ${SANDBOXBASE}/rc_files/sb.conf ]] && [[ -f ${PROJECT_ROOT}/src/build/citest/etc/bbuild ]]; then SBDRIVER=`cat ${SANDBOXBASE}/rc_files/sb.conf | \ grep "backing_build" | awk '{ print $3 }'` DRIVER=`cat ${PROJECT_ROOT}/src/build/citest/etc/bbuild` if [ ${SBDRIVER} != ${DRIVER} ]; then echo "ERROR: Driver mismatch between sandbox and src/build/citest/etc/bbuild." echo "Sandbox at ${SBDRIVER}" echo "Update sandbox with 'hb simsetup'." exit 1 fi fi hbDistribute --hb-standalone $* } hb_fipssetup() { [ -z "${SANDBOXBASE}" ] && echo "Missing SANDBOXBASE." && exit 1 [ -z "${SANDBOXROOT}" ] && echo "Missing SANDBOXROOT." && exit 1 [ -z "${SANDBOXNAME}" ] && echo "Missing SANDBOXNAME." && exit 1 [ -z "${PROJECT_ROOT}" ] && echo "Missing PROJECT_ROOT." && exit 1 SANDBOXRC="${SANDBOXROOT}/hbsandboxrc" DRIVER=`cat ${PROJECT_ROOT}/src/build/citest/etc/bbuild` if [ -d "${SANDBOXBASE}" ]; then echo "Removing old sandbox." mksb -rc ${SANDBOXRC} -dir ${SANDBOXROOT} -undo $SANDBOXNAME fi if [ ! -d "${SANDBOXROOT}" ]; then echo "Creating sandbox root directory." mkdir -p ${SANDBOXROOT} fi if [ ! -d "${DRIVER}" ]; then echo "ERROR: Backing build in src/build/citest/etc/bbuild not found!" exit 1 fi echo "Creating new sandbox." mksb -rc ${SANDBOXRC} -dir ${SANDBOXROOT} -back $DRIVER \ -sb ${SANDBOXNAME} -m ppc echo "Running workarounds (presimsetup)." cp ${PROJECT_ROOT}/src/build/citest/etc/workarounds.presimsetup \ ${SANDBOXBASE}/src execute_in_sandbox "export BACKING_BUILD=\$bb && \ ./workarounds.presimsetup" "ppc" rm ${SANDBOXBASE}/src/workarounds.presimsetup } hb_simsetup() { hb_fipssetup DRIVER=`cat ${PROJECT_ROOT}/src/build/citest/etc/bbuild` needs_machine_variable execute_in_sandbox "start_simics -no_start -machine ${MACHINE}" "ppc" echo "Running workarounds (postsimsetup)." cp ${PROJECT_ROOT}/src/build/citest/etc/workarounds.postsimsetup ${SANDBOXBASE}/src execute_in_sandbox "export BACKING_BUILD=\$bb && ./workarounds.postsimsetup" "ppc" rm ${SANDBOXBASE}/src/workarounds.postsimsetup # Put a starter copy of errl to simics directory; refresh w/ "hb errlparser" cd ${SANDBOXBASE}/simics ln -sf ${DRIVER}/obj/x86.nfp/errl/nfp/tool/errl } hb_startsimics() { [ -z "${SANDBOXBASE}" ] && echo "Missing SANDBOXBASE." && exit 1 [ -z "${PROJECT_ROOT}" ] && echo "Missing PROJECT_ROOT." && exit 1 if [ ! -d "${SANDBOXBASE}" ]; then echo "Sandbox does not exist. Create with 'hb simsetup." exit 1 fi SBDRIVER=`cat ${SANDBOXBASE}/rc_files/sb.conf | \ grep "backing_build" | awk '{ print $3 }'` DRIVER=`cat ${PROJECT_ROOT}/src/build/citest/etc/bbuild` if [ ${SBDRIVER} != ${DRIVER} ]; then echo "Driver mismatch between sandbox and src/build/citest/etc/bbuild." echo "Sandbox at ${SBDRIVER}" echo "Update sandbox with 'hb simsetup'." exit 1 fi needs_machine_variable # Force simics into Secure Mode export SECURITY_HW_POLICY="1" execute_in_sandbox \ "start_simics -machine ${MACHINE} ${SIMICSOPTIONS} $*" "ppc" } hb_rsync_call() { if [ -z "${RSYNCHOST}" ]; then rsync -av --delete ${PROJECT_ROOT}/ ${RSYNCDIR} else rsync -zav --delete ${PROJECT_ROOT}/ ${RSYNCHOST}:${RSYNCDIR} fi } hb_rsync_helper() { if [ -n "${RSYNCHOST}" ]; then echo -n "${RSYNCHOST}:" fi echo "${RSYNCDIR} does not look like a hostboot repo and is not empty" read -r -p "rsync will clear out ${RSYNCDIR} then copy files into it, is this correct? [y/N] " response case $response in [yY][eE][sS]|[yY]) hb_rsync_call ;; *) echo "hb rsync cancelled" ;; esac } hb_rsync() { [ -z "${PROJECT_ROOT}" ] && echo "Missing PROJECT_ROOT." && exit 1 [ -z "${RSYNCDIR}" ] && echo "Missing RSYNCDIR." && exit 1 # Parse arguments case $1 in "--force") hb_rsync_call ;; *) # Check destination directory, if not empty check if looks like # a hostboot repository, otherwise proceed # If remote directory if [ -n "${RSYNCHOST}" ]; then if [ "$(ssh ${RSYNCHOST} 'if [ "$(ls -A '${RSYNCDIR}')" ]; then echo 1; fi')" ]; then # Remote check for hb and .git if [ "$(ssh ${RSYNCHOST} 'if [ -f '${RSYNCDIR}/hb' -a -d '${RSYNCDIR}/.git' ]; then echo 1; fi')" ]; then hb_rsync_call; else hb_rsync_helper; fi else hb_rsync_call; fi # Local check for emptiness elif [ "$(ls -A ${RSYNCDIR})" ]; then # Local check for hb and .git if [ -f ${RSYNCDIR}/hb -a -d ${RSYNCDIR}/.git ]; then hb_rsync_call; else hb_rsync_helper; fi else hb_rsync_call; fi esac } hb_objsizes() { [ -z "${PROJECT_ROOT}" ] && echo "Missing PROJECT_ROOT." && exit 1 echo "Object,Text Size,RO Data Size,Data Size" objdump -h ${PROJECT_ROOT}/img/*.elf ${PROJECT_ROOT}/img/*.so | \ grep -e ".elf" -e ".so:" -e ".text " -e ".rodata" -e ".data " | \ sed "s/.so:.*/.so/" | \ sed "s/.elf:.*/.elf/" | \ sed 's/.*\.text *\([0-9a-f]*\).*/,0x\1/' | \ sed 's/.*\.rodata *\([0-9a-f]*\).*/,0x\1/' | \ sed 's/.*\.data *\([0-9a-f]*\).*/,0x\1/' | \ sed "N ; N ; N ; s/\n//g" | \ xargs -n1 perl -e 'printf "%s,%d,%d,%d\n", map { 0 == hex $_ ? $_ : hex $_ } split /\,/,shift;' | \ sed "s/.*\///" } hb_copyright_check() { git diff HEAD~1 --name-only | xargs addCopyright validate } hb_errlparser() { [ -z "${SANDBOXBASE}" ] && echo "Missing SANDBOXBASE." && exit 1 [ -z "${SANDBOXROOT}" ] && echo "Missing SANDBOXROOT." && exit 1 [ -z "${SANDBOXNAME}" ] && echo "Missing SANDBOXNAME." && exit 1 [ -z "${PROJECT_ROOT}" ] && echo "Missing PROJECT_ROOT." && exit 1 DRIVER=`cat ${PROJECT_ROOT}/src/build/citest/etc/bbuild` # sanity checks if [ ! -f ${DRIVER}/src/makefile ]; then echo "Cannot reach backing build: $DRIVER. You may need tokens." exit 1 fi ${PROJECT_ROOT}/src/build/citest/build-errl-parsers return $? } hb_cachesync() { [ -z "${PROJECT_ROOT}" ] && echo "Missing PROJECT_ROOT." && exit 1 rsync -av /gsa/ausgsa/projects/h/hostboot/.binary_cache/ \ ${PROJECT_ROOT}/.git/hb_cache failure=0 for files in ${PROJECT_ROOT}/.git/hb_cache/data/*; do echo "`basename $files` $files" | sha1sum --check >> /dev/null if [ $? -ne 0 ]; then echo "Failed SHA1 verification! $files" failure=1 fi done exit $failure } hb_cacheadd() { [ -z "${PROJECT_ROOT}" ] && echo "Missing PROJECT_ROOT." && exit 1 CACHE_PATH=/gsa/ausgsa/projects/h/hostboot/.binary_cache/ FILE=$1 shift if [ $FILE == "--local" ]; then echo "Adding as local copy." CACHE_PATH=${PROJECT_ROOT}/.git/hb_cache/ FILE=$1 shift fi MESSAGE=$* [ ! -e "${FILE}" ] && echo "File $FILE does not exist." && exit 1 [ -z "${MESSAGE}" ] && echo "No message given." && exit 1 FILE_BASE=`basename $FILE` SHA1SUM=`sha1sum -b $FILE | sed 's/ .*//'` echo $FILE $SHA1SUM cp $FILE $CACHE_PATH/data/$SHA1SUM echo $SHA1SUM : `whoami` : `date` : $MESSAGE \ >> $CACHE_PATH/files/$FILE_BASE echo "Added $FILE_BASE as $SHA1SUM" } if [ 0 -eq $# ]; then hb_helptext exit 1 fi FIRST_PARAM=$1 shift case ${FIRST_PARAM} in workon) hb_workon $* ;; prime) hb_prime $* ;; fipssetup) hb_fipssetup $* ;; simsetup) hb_simsetup $* ;; startsimics) hb_startsimics $* ;; rsync) hb_rsync $* ;; objsizes) hb_objsizes $* ;; copyright_check) hb_copyright_check $* ;; errlparser) hb_errlparser $* ;; cachesync) hb_cachesync $* ;; cacheadd) hb_cacheadd $* ;; *) hb_helptext $* exit 1 ;; esac