diff --git a/fs_mgr/fs_mgr_remount.cpp b/fs_mgr/fs_mgr_remount.cpp index 631273457..5c4008cce 100644 --- a/fs_mgr/fs_mgr_remount.cpp +++ b/fs_mgr/fs_mgr_remount.cpp @@ -263,35 +263,43 @@ int main(int argc, char* argv[]) { // Check verity and optionally setup overlayfs backing. auto reboot_later = false; + auto uses_overlayfs = fs_mgr_overlayfs_valid() != OverlayfsValidResult::kNotSupported; for (auto it = partitions.begin(); it != partitions.end();) { auto& entry = *it; auto& mount_point = entry.mount_point; if (fs_mgr_is_verity_enabled(entry)) { - LOG(WARNING) << "Verity enabled on " << mount_point; - if (can_reboot && - (android::base::GetProperty("ro.boot.vbmeta.devices_state", "") != "locked")) { + retval = VERITY_PARTITION; + if (android::base::GetProperty("ro.boot.vbmeta.devices_state", "") != "locked") { if (AvbOps* ops = avb_ops_user_new()) { auto ret = avb_user_verity_set( ops, android::base::GetProperty("ro.boot.slot_suffix", "").c_str(), false); avb_ops_user_free(ops); if (ret) { - if (fs_mgr_overlayfs_valid() == OverlayfsValidResult::kNotSupported) { - retval = VERITY_PARTITION; + LOG(WARNING) << "Disable verity for " << mount_point; + reboot_later = can_reboot; + if (reboot_later) { // w/o overlayfs available, also check for dedupe - reboot_later = true; - ++it; - continue; + if (!uses_overlayfs) { + ++it; + continue; + } + reboot(false); } - reboot(false); } else if (fs_mgr_set_blk_ro(entry.blk_device, false)) { fec::io fh(entry.blk_device.c_str(), O_RDWR); - if (fh && fh.set_verity_status(false)) reboot_later = true; + if (fh && fh.set_verity_status(false)) { + LOG(WARNING) << "Disable verity for " << mount_point; + reboot_later = can_reboot; + if (reboot_later && !uses_overlayfs) { + ++it; + continue; + } + } } } } LOG(ERROR) << "Skipping " << mount_point; - retval = VERITY_PARTITION; it = partitions.erase(it); continue; } @@ -318,7 +326,8 @@ int main(int argc, char* argv[]) { } // Mount overlayfs. - if (!fs_mgr_overlayfs_mount_all(&partitions)) { + errno = 0; + if (!fs_mgr_overlayfs_mount_all(&partitions) && errno) { retval = BAD_OVERLAY; PLOG(ERROR) << "Can not mount overlayfs for partitions"; } @@ -346,11 +355,15 @@ int main(int argc, char* argv[]) { break; } if ((mount_point == "/") && (rentry.mount_point == "/system")) { - if (blk_device != "/dev/root") blk_device = rentry.blk_device; + blk_device = rentry.blk_device; mount_point = "/system"; break; } } + if (blk_device == "/dev/root") { + auto from_fstab = GetEntryForMountPoint(&fstab, mount_point); + if (from_fstab) blk_device = from_fstab->blk_device; + } fs_mgr_set_blk_ro(blk_device, false); // Now remount! diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh index a6baf1d32..bd5a4fe58 100755 --- a/fs_mgr/tests/adb-remount-test.sh +++ b/fs_mgr/tests/adb-remount-test.sh @@ -48,6 +48,7 @@ NORMAL="${ESCAPE}[0m" TMPDIR=${TMPDIR:-/tmp} print_time=false start_time=`date +%s` +ACTIVE_SLOT= ## ## Helper Functions @@ -77,6 +78,7 @@ inAdb() { wc -l | grep '^1$' >/dev/null fi } + [ "USAGE: inRecovery Returns: true if device is in recovery mode" ] @@ -221,15 +223,23 @@ format_duration() { Returns: waits until the device has returned for adb or optional timeout" ] adb_wait() { + local ret if [ -n "${1}" ]; then echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} "${CR}" timeout --preserve-status --signal=KILL ${1} adb wait-for-device 2>/dev/null - local ret=${?} + ret=${?} echo -n " ${CR}" - return ${ret} else adb wait-for-device + ret=${?} fi + if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then + local active_slot=`get_active_slot` + if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then + echo "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" >&2 + fi + fi + return ${ret} } [ "USAGE: usb_status > stdout @@ -254,33 +264,50 @@ usb_status() { Returns: waits until the device has returned for fastboot or optional timeout" ] fastboot_wait() { + local ret # fastboot has no wait-for-device, but it does an automatic # wait and requires (even a nonsensical) command to do so. if [ -n "${1}" ]; then echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} "${CR}" timeout --preserve-status --signal=KILL ${1} fastboot wait-for-device >/dev/null 2>/dev/null - local ret=${?} + ret=${?} echo -n " ${CR}" ( exit ${ret} ) else fastboot wait-for-device >/dev/null 2>/dev/null fi || inFastboot + ret=${?} + if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then + local active_slot=`get_active_slot` + if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then + echo "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" >&2 + fi + fi + return ${ret} } [ "USAGE: recovery_wait [timeout] Returns: waits until the device has returned for recovery or optional timeout" ] recovery_wait() { + local ret if [ -n "${1}" ]; then echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} "${CR}" timeout --preserve-status --signal=KILL ${1} adb wait-for-recovery 2>/dev/null - local ret=${?} + ret=${?} echo -n " ${CR}" - return ${ret} else adb wait-for-recovery + ret=${?} fi + if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then + local active_slot=`get_active_slot` + if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then + echo "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" >&2 + fi + fi + return ${ret} } [ "any_wait [timeout] @@ -326,7 +353,7 @@ adb_unroot() { [ root != "`adb_sh echo '${USER}' /dev/stderr Returns: true if var output matches expected" ] fastboot_getvar() { @@ -350,6 +377,19 @@ fastboot_getvar() { echo ${O} >&2 } +[ "USAGE: get_active_slot >/dev/stdout + +Returns: with a or b string reporting active slot" ] +get_active_slot() { + if inAdb || inRecovery; then + get_property ro.boot.slot_suffix | tr -d _ + elif inFastboot; then + fastboot_getvar current-slot 2>&1 | sed -n 's/current-slot: //p' + else + false + fi +} + [ "USAGE: restore Do nothing: should be redefined when necessary. Called after cleanup. @@ -583,6 +623,9 @@ fi BUILD_DESCRIPTION=`get_property ro.build.description` [ -z "${BUILD_DESCRIPTION}" ] || echo "${BLUE}[ INFO ]${NORMAL} ${BUILD_DESCRIPTION}" >&2 +ACTIVE_SLOT=`get_active_slot` +[ -z "${ACTIVE_SLOT}" ] || + echo "${BLUE}[ INFO ]${NORMAL} active slot is ${ACTIVE_SLOT}" >&2 # Report existing partition sizes adb_sh ls -l /dev/block/by-name/ /dev/null | @@ -1031,13 +1074,7 @@ else check_eq "${A}" "${B}" system after flash vendor adb_root || die "adb root" - B="`adb_cat /vendor/hello`" && - if ${is_userspace_fastboot} || ! ${overlayfs_needed}; then - die "re-read /vendor/hello after flash vendor" - else - echo "${ORANGE}[ WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2 - echo "${ORANGE}[ WARNING ]${NORMAL} re-read /vendor/hello after flash vendor" >&2 - fi + B="`adb_cat /vendor/hello`" if ${is_userspace_fastboot} || ! ${overlayfs_needed}; then check_eq "cat: /vendor/hello: No such file or directory" "${B}" \ vendor content after flash vendor