Add some functions which will help transition to a single firmware directory.

This is the first in three stages of changes to transition from separate
"u-boot" and "coreboot" output directories to a single "firmware"
directory. This change/stage will give scripts a facility to easily be
compatible with both schemes. The second stage will transition all the
scripts to use the mechanism, and then finally the third stage will
switch the directories over. Some additional work may be needed if there
are file name clashes, although those sorts of problems would likely
already be present. These new functions could also optionally be taken back
out after the transition.

This change adds find_fw_component, find_u_boot_component, and
find_coreboot_component functions to common.sh. The first function provides
the bulk of the functionality, while the second and third wrap the first and
pass it parameters appropriate for u-boot or coreboot. The first function
accepts an override which it returns if set, and if not it checks for a file
in each of the directories it's passed in the second parameter one by one and
returns the first one it finds. If it doesn't find any it defaults to the last
one.

BUG=chromium-os:18107
TEST=Modified some u-boot related ebuilds to put some files in the firmware
directory. Ran the ebuilds and verified the files showed up where expected.
Modified the cros_write_firmware.sh script to use these new functions.  Ran
cros_write_firmware and saw it find the files in their new location.
Also verified that the firmware on the target was updated as expected.

Change-Id: Ic664e0e1c4a5b27efc9fb892ff5bd91cf1b5be56
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: http://gerrit.chromium.org/gerrit/5170
Tested-by: Gabe Black <gabeblack@chromium.org>
Reviewed-by: Doug Anderson <dianders@chromium.org>
This commit is contained in:
Gabe Black 2011-08-01 17:50:09 -07:00
parent 9fb286ea02
commit 83d8b824a3

View File

@ -640,3 +640,49 @@ function reinterpret_path_for_chroot() {
echo "${1}"
fi
}
# Find a firmware component using one of a set of prefixes, or an override if
# one is given.
# The first argument is a list of path prefixes which are prepended to the
# component name, relative to the current board's build directory.
# The second argument is the name of the component to look for.
# The third argument is an optional override. If it's a non-empty string, that
# value is returned instead of searching. This makes it a little easier to
# accept overrides in calling scripts.
# The return value is the override if one is set, the first path at which a
# component is found, or the last path searched if none is found. Later checks
# in the calling scripts can identify that the file doesn't exist and handle
# the error appropriately.
function find_fw_component() {
local prefixes=$1
local component=$2
local override=$3
if [ ! -z "${override}" ]; then
echo "${override}"
exit 0
fi
local path=""
for prefix in ${prefixes}; do
path="/build/${BOARD_VARIANT}/${prefix}/${component}"
if [ -e "${path}" ]; then
break
fi
done
echo "${path}"
}
# A wrapper for find_fw_component which provides a set of prefixes which make
# sense for u-boot.
function find_u_boot_component () {
local component=$1
local override=$2
find_fw_component "firmware u-boot" "${component}" "${override}"
}
# A wrapper for find_fw_component which provides a set of prefixes which make
# sense for coreboot.
function find_coreboot_component () {
local component=$1
local override=$2
find_fw_component "firmware coreboot" "${component}" "${override}"
}