From d03825b504ccf362315142a698bbcbe5b6ab1f8c Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Fri, 14 Dec 2012 20:17:00 +1300 Subject: [PATCH] Add the ability to break into a shell during builds. Change-Id: I87af952d892f8622e4c916085fc896c735a35438 --- README.md | 14 ++++++++++++++ lib/common-functions | 14 ++++++++++++++ lib/img-functions | 6 ++++++ 3 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 5f6e8168..3d8d9d31 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,20 @@ Ramdisk elements support the following files in their element directories: * init : a POSIX shell script fragment that will be appended to the default script executed as the ramdisk is booted (/init) +Debugging elements +------------------ + +Export 'break' to drop to a shell during the image build. Break points can be +set either before or after any of the hook points by exporting +"break=[before|after]-hook-name". Multiple break points can be specified as a +comma-delimited string. Some examples: + +* break=before-block-device-size will break before the block device size hooks + are called. + +* break=after-first-boot,before-pre-install will break after the first-boot + hooks and before the pre-install hooks. + Third party elements -------------------- diff --git a/lib/common-functions b/lib/common-functions index c123c074..09e3222d 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -44,6 +44,20 @@ function generate_hooks () { done } +# Call the supplied break-in routine if the named point is listed in the break +# list. +# $1 the break point. +# $2.. what to call if a break is needed +function check_break () { + if echo "$break" | egrep -e "(,|^)$1(,|$)" -q; then + echo "Starting debug shell. Exit to resume building." >&2 + echo At stage $1 >&2 + shift + "$@" + echo "Resuming" >&2 + fi +} + # Check that a real element has been chosen (prevents foot-guns) function check_element () { [ -d $TMP_HOOKS_PATH ] || generate_hooks diff --git a/lib/img-functions b/lib/img-functions index 111d92d6..945d790c 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -122,7 +122,9 @@ function run_d_in_target() { sudo mkdir $TMP_MOUNT_PATH/tmp/in_target.d sudo mount --bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d sudo mount -o remount,ro,bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d + check_break before-$1 run_in_target bash run_in_target run-parts -v /tmp/in_target.d/$1.d + check_break after-$1 run_in_target bash sudo umount -f $TMP_MOUNT_PATH/tmp/in_target.d sudo rmdir $TMP_MOUNT_PATH/tmp/in_target.d fi @@ -131,12 +133,15 @@ function run_d_in_target() { # Run a directory of hooks outside the target. function run_d() { check_element + check_break before-$1 bash if [ -d ${TMP_HOOKS_PATH}/$1.d ] ; then run-parts ${TMP_HOOKS_PATH}/$1.d fi + check_break after-$1 bash } function prepare_first_boot () { + check_break before-first-boot run_in_target bash if [ -d ${TMP_HOOKS_PATH}/first-boot.d ] ; then sudo cp -t $TMP_MOUNT_PATH/etc/ -a $TMP_HOOKS_PATH/first-boot.d run_in_target mv /etc/rc.local /etc/rc.local.REAL @@ -152,6 +157,7 @@ exit 0 EOF run_in_target chmod 755 /etc/rc.local fi + check_break after-first-boot run_in_target bash } function finalise_base () {