mirror of
https://github.com/flatcar/scripts.git
synced 2026-02-08 17:21:39 +01:00
Merge branch 'master' of ssh://gitrw.chromium.org:9222/crosutils
This commit is contained in:
commit
4d6d093a77
@ -10,7 +10,7 @@ import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))
|
||||
from cros_build_lib import RunCommand, Info, Warning
|
||||
from cros_build_lib import RunCommand, Info, Warning, ReinterpretPathForChroot
|
||||
|
||||
_KVM_PID_FILE = '/tmp/harness_pid'
|
||||
_SCRIPTS_DIR = os.path.join(os.path.dirname(__file__), '..')
|
||||
@ -18,6 +18,7 @@ _FULL_VDISK_SIZE = 6072
|
||||
_FULL_STATEFULFS_SIZE = 2048
|
||||
|
||||
global base_image_path
|
||||
global board
|
||||
global target_image_path
|
||||
|
||||
_VERIFY_SUITE = 'suite_Smoke'
|
||||
@ -106,9 +107,11 @@ class VirtualAUTest(unittest.TestCase, AUTest):
|
||||
Info('Qemu image not found, creating one.')
|
||||
RunCommand(['%s/image_to_vm.sh' % _SCRIPTS_DIR,
|
||||
'--full',
|
||||
'--from %s' % os.path.dirname(base_image_path),
|
||||
'--from %s' % ReinterpretPathForChroot(
|
||||
os.path.dirname(base_image_path)),
|
||||
'--vdisk_size %s' % _FULL_VDISK_SIZE,
|
||||
'--statefulfs_size %s' % _FULL_STATEFULFS_SIZE,
|
||||
'--board %s' % board,
|
||||
'--test_image'], enter_chroot=True)
|
||||
else:
|
||||
Info('Using existing VM image')
|
||||
@ -153,6 +156,8 @@ if __name__ == '__main__':
|
||||
help='path to the base image.')
|
||||
parser.add_option('-t', '--target_image',
|
||||
help='path to the target image')
|
||||
parser.add_option('-r', '--board',
|
||||
help='board for the images')
|
||||
# Set the usage to include flags.
|
||||
parser.set_usage(parser.format_help())
|
||||
# Parse existing sys.argv so we can pass rest to unittest.main.
|
||||
@ -160,6 +165,7 @@ if __name__ == '__main__':
|
||||
|
||||
base_image_path = options.base_image
|
||||
target_image_path = options.target_image
|
||||
board = options.board
|
||||
|
||||
if not base_image_path:
|
||||
parser.error('Need path to base image for vm.')
|
||||
@ -167,4 +173,7 @@ if __name__ == '__main__':
|
||||
if not target_image_path:
|
||||
parser.error('Need path to target image to update with.')
|
||||
|
||||
if not board:
|
||||
parser.error('Need board to convert base image to vm.')
|
||||
|
||||
unittest.main()
|
||||
|
||||
14
bin/loman.py
14
bin/loman.py
@ -11,17 +11,7 @@ import optparse
|
||||
import os
|
||||
import xml.etree.ElementTree as ElementTree
|
||||
|
||||
from cros_build_lib import Die
|
||||
|
||||
|
||||
def _FindRepoDir():
|
||||
cwd = os.getcwd()
|
||||
while cwd != '/':
|
||||
repo_dir = os.path.join(cwd, '.repo')
|
||||
if os.path.isdir(repo_dir):
|
||||
return repo_dir
|
||||
cwd = os.path.dirname(cwd)
|
||||
return None
|
||||
from cros_build_lib import Die, FindRepoDir
|
||||
|
||||
|
||||
def _ReadManifest(manifest, err_not_found=False):
|
||||
@ -96,7 +86,7 @@ class LocalManifest:
|
||||
|
||||
|
||||
def main(argv):
|
||||
repo_dir = _FindRepoDir()
|
||||
repo_dir = FindRepoDir()
|
||||
if not repo_dir:
|
||||
Die("Unable to find repo dir.")
|
||||
|
||||
|
||||
@ -751,7 +751,7 @@ fi
|
||||
|
||||
print_time_elapsed
|
||||
|
||||
echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
|
||||
echo "To copy to USB keyfob, do something like:"
|
||||
echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX"
|
||||
echo "To convert to VMWare image, INSIDE the chroot, do something like:"
|
||||
echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}"
|
||||
|
||||
@ -57,7 +57,7 @@ extract_partition_to_temp_file() {
|
||||
local filename="$1"
|
||||
local partition="$2"
|
||||
local temp_file=$(mktemp /tmp/generate_update_payload.XXXXXX)
|
||||
|
||||
|
||||
local offset=$(partoffset "${filename}" ${partition}) # 512-byte sectors
|
||||
local length=$(partsize "${filename}" ${partition}) # 512-byte sectors
|
||||
local bs=512
|
||||
@ -99,6 +99,7 @@ DEFINE_boolean old_style "$FLAGS_TRUE" "Generate an old-style .gz full update."
|
||||
DEFINE_string output "" "Output file"
|
||||
DEFINE_boolean patch_kernel "$FLAGS_FALSE" "Whether or not to patch the kernel \
|
||||
with the patch from the stateful partition (default: false)"
|
||||
DEFINE_string private_key "" "Path to private key in .pem format."
|
||||
|
||||
# Parse command line
|
||||
FLAGS "$@" || exit 1
|
||||
@ -128,7 +129,7 @@ fi
|
||||
|
||||
if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then
|
||||
echo "Generating a delta update"
|
||||
|
||||
|
||||
# Sanity check that the real generator exists:
|
||||
GENERATOR="$(dirname "$0")/../platform/update_engine/delta_generator"
|
||||
[ -x "$GENERATOR" ] || die "$GENERATOR doesn't exist, or isn't executable"
|
||||
@ -144,42 +145,42 @@ if [ "$DELTA" -eq "$FLAGS_TRUE" ]; then
|
||||
md5sum "$SRC_KERNEL"
|
||||
echo md5sum of src root:
|
||||
md5sum "$SRC_ROOT"
|
||||
|
||||
|
||||
DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2)
|
||||
if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then
|
||||
patch_kernel "$FLAGS_image" "$DST_KERNEL"
|
||||
fi
|
||||
DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3)
|
||||
|
||||
|
||||
SRC_MNT=$(mktemp -d /tmp/src_root.XXXXXX)
|
||||
sudo mount -o loop,ro "$SRC_ROOT" "$SRC_MNT"
|
||||
|
||||
DST_MNT=$(mktemp -d /tmp/src_root.XXXXXX)
|
||||
sudo mount -o loop,ro "$DST_ROOT" "$DST_MNT"
|
||||
|
||||
|
||||
sudo "$GENERATOR" \
|
||||
-new_dir "$DST_MNT" -new_image "$DST_ROOT" -new_kernel "$DST_KERNEL" \
|
||||
-old_dir "$SRC_MNT" -old_image "$SRC_ROOT" -old_kernel "$SRC_KERNEL" \
|
||||
-out_file "$FLAGS_output"
|
||||
|
||||
-out_file "$FLAGS_output" -private_key "$FLAGS_private_key"
|
||||
|
||||
trap - INT TERM EXIT
|
||||
cleanup noexit
|
||||
echo "Done generating delta."
|
||||
else
|
||||
echo "Generating full update"
|
||||
|
||||
|
||||
trap cleanup INT TERM EXIT
|
||||
DST_KERNEL=$(extract_partition_to_temp_file "$FLAGS_image" 2)
|
||||
if [ "$FLAGS_patch_kernel" -eq "$FLAGS_TRUE" ]; then
|
||||
patch_kernel "$FLAGS_image" "$DST_KERNEL"
|
||||
fi
|
||||
DST_ROOT=$(extract_partition_to_temp_file "$FLAGS_image" 3)
|
||||
|
||||
|
||||
GENERATOR="$(dirname "$0")/mk_memento_images.sh"
|
||||
|
||||
CROS_GENERATE_UPDATE_PAYLOAD_CALLED=1 "$GENERATOR" "$DST_KERNEL" "$DST_ROOT"
|
||||
mv "$(dirname "$DST_KERNEL")/update.gz" "$FLAGS_output"
|
||||
|
||||
|
||||
trap - INT TERM EXIT
|
||||
cleanup noexit
|
||||
echo "Done generating full update."
|
||||
|
||||
@ -21,8 +21,7 @@ eval set -- "${FLAGS_ARGV}"
|
||||
|
||||
# Check on the board that they are trying to set up.
|
||||
if [ -z "$FLAGS_board" ] ; then
|
||||
echo "Error: --board required."
|
||||
exit 1
|
||||
die "Error: --board required."
|
||||
fi
|
||||
|
||||
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
|
||||
|
||||
@ -263,14 +263,7 @@ else
|
||||
echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..."
|
||||
cp -f "${SRC_IMAGE}" "${FLAGS_to}"
|
||||
|
||||
echo "Done. To copy to a USB drive, outside the chroot, do something like:"
|
||||
echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M"
|
||||
echo "Done. To copy to a USB drive, do something like:"
|
||||
echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M oflag=sync"
|
||||
echo "where /dev/sdX is the entire drive."
|
||||
if [ ${INSIDE_CHROOT} -eq 1 ]
|
||||
then
|
||||
example=$(basename "${FLAGS_to}")
|
||||
echo "NOTE: Since you are currently inside the chroot, and you'll need to"
|
||||
echo "run dd outside the chroot, the path to the USB image will be"
|
||||
echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)."
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -136,3 +136,36 @@ def Info(message):
|
||||
"""
|
||||
print >> sys.stderr, (
|
||||
Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message))
|
||||
|
||||
|
||||
def FindRepoDir():
|
||||
"""Returns the nearest higher-level repo dir from the cwd."""
|
||||
cwd = os.getcwd()
|
||||
while cwd != '/':
|
||||
repo_dir = os.path.join(cwd, '.repo')
|
||||
if os.path.isdir(repo_dir):
|
||||
return repo_dir
|
||||
cwd = os.path.dirname(cwd)
|
||||
return None
|
||||
|
||||
|
||||
def ReinterpretPathForChroot(path):
|
||||
"""Returns reinterpreted path from outside the chroot for use inside.
|
||||
|
||||
Keyword arguments:
|
||||
path: The path to reinterpret. Must be in src tree.
|
||||
"""
|
||||
root_path = os.path.join(FindRepoDir(), '..')
|
||||
|
||||
path_abs_path = os.path.abspath(path)
|
||||
root_abs_path = os.path.abspath(root_path)
|
||||
|
||||
# Strip the repository root from the path and strip first /.
|
||||
relative_path = path_abs_path.replace(root_abs_path, '')[1:]
|
||||
|
||||
if relative_path == path_abs_path:
|
||||
raise Exception('Error: path is outside your src tree, cannot reinterpret.')
|
||||
|
||||
new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path)
|
||||
return new_path
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user