Loading fs_mgr/fs_mgr_overlayfs.cpp +10 −2 Original line number Diff line number Diff line Loading @@ -144,7 +144,10 @@ bool fs_mgr_overlayfs_enabled(FstabEntry* entry) { if (entry->fs_mgr_flags.logical) { fs_mgr_update_logical_partition(entry); } return fs_mgr_has_shared_blocks(entry->mount_point, entry->blk_device); auto save_errno = errno; auto has_shared_blocks = fs_mgr_has_shared_blocks(entry->mount_point, entry->blk_device); errno = save_errno; return has_shared_blocks; } bool fs_mgr_rm_all(const std::string& path, bool* change = nullptr, int level = 0) { Loading Loading @@ -263,8 +266,10 @@ bool fs_mgr_overlayfs_already_mounted(const std::string& mount_point, bool overl std::vector<std::string> fs_mgr_overlayfs_verity_enabled_list() { std::vector<std::string> ret; auto save_errno = errno; fs_mgr_update_verity_state( [&ret](const std::string& mount_point, int) { ret.emplace_back(mount_point); }); if ((errno == ENOENT) || (errno == ENXIO)) errno = save_errno; return ret; } Loading Loading @@ -837,10 +842,12 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool* return ret; } auto save_errno = errno; Fstab fstab; if (!ReadDefaultFstab(&fstab)) { return false; } errno = save_errno; auto mounts = fs_mgr_candidate_list(&fstab, fs_mgr_mount_point(mount_point)); if (mounts.empty()) return ret; Loading @@ -864,7 +871,8 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool* break; } if (dir.empty()) { errno = ESRCH; if (change && *change) errno = ESRCH; if (errno == EPERM) errno = save_errno; return ret; } Loading fs_mgr/tests/adb-remount-test.sh +260 −163 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ inAdb() { adb devices | grep -v 'List of devices attached' | grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null } [ "USAGE: adb_sh <commands> [ "USAGE: adb_sh <commands> </dev/stdin >/dev/stdout 2>/dev/stderr Returns: true if the command succeeded" ] adb_sh() { Loading Loading @@ -86,7 +86,7 @@ isDebuggable() { fi } [ "USAGE: adb_su <commands> [ "USAGE: adb_su <commands> </dev/stdin >/dev/stdout 2>/dev/stderr Returns: true if the command running as root succeeded" ] adb_su() { Loading Loading @@ -284,23 +284,47 @@ isDebuggable || die "device not a debug build" echo "${GREEN}[ RUN ]${NORMAL} Testing kernel support for overlayfs" >&2 overlayfs_supported=true; adb_wait || die "wait for device failed" adb_sh ls -d /sys/module/overlay </dev/null >/dev/null && echo "${GREEN}[ OK ]${NORMAL} overlay module present" >&2 || die "overlay module not present" ( echo "${ORANGE}[ WARNING ]${NORMAL} overlay module not present" >&2 && false ) || overlayfs_supported=false if ${overlayfs_supported}; then case `adb_sh uname -r </dev/null` in 4.[6789].* | 4.[1-9][0-9]* | [56789].*) adb_su ls /sys/module/overlay/parameters/override_creds </dev/null >/dev/null && echo "${GREEN}[ OK ]${NORMAL} overlay module supports override_creds" >&2 || die "overlay module can not be used on ANDROID" ( echo "${ORANGE}[ WARNING ]${NORMAL} overlay module does not support override_creds" >&2 && false ) || overlayfs_supported=false; ;; *) echo "${GREEN}[ OK ]${NORMAL} overlay module uses callers creds" >&2 ;; esac fi adb_root || die "initial setup" echo "${GREEN}[ RUN ]${NORMAL} Checking current overlayfs status" >&2 # We can not universally use adb enable-verity to ensure device is # in a overlayfs disabled state since it can prevent reboot on # devices that remount the physical content rather than overlayfs. # So lets do our best to surgically wipe the overlayfs state without # having to go through enable-verity transition. reboot=false OVERLAYFS_BACKING="cache mnt/scratch" for d in ${OVERLAYFS_BACKING}; do if adb_sh ls -d /${d}/overlay </dev/null >/dev/null 2>/dev/null; then echo "${ORANGE}[ WARNING ]${NORMAL} /${d}/overlay is setup, wiping" >&2 echo "${ORANGE}[ WARNING ]${NORMAL} /${d}/overlay is setup, surgically wiping" >&2 adb_sh rm -rf /${d}/overlay </dev/null || die "/${d}/overlay wipe" reboot=true Loading @@ -309,9 +333,10 @@ done if ${reboot}; then echo "${ORANGE}[ WARNING ]${NORMAL} rebooting before test" >&2 adb_reboot && adb_wait 2m && adb_wait 2m || die "lost device after reboot after wipe" adb_root || die "reboot after wipe" die "lost device after elevation to root after wipe" fi D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && Loading @@ -320,62 +345,111 @@ D=`adb_sh df -k </dev/null` && echo "${D}" && echo "${ORANGE}[ WARNING ]${NORMAL} overlays present before setup" >&2 || echo "${GREEN}[ OK ]${NORMAL} no overlay present before setup" >&2 adb_sh df -k `adb_sh cat /proc/mounts | overlayfs_needed=true D=`adb_sh cat /proc/mounts </dev/null | skip_administrative_mounts data | cut -s -d' ' -f1` D=`adb_sh df -k ${D} </dev/null` echo "${D}" if [ X"${D}" = X"${D##* 100[%] }" ]; then overlayfs_needed=false elif ! ${overlayfs_supported}; then die "need overlayfs, but do not have it" fi echo "${GREEN}[ RUN ]${NORMAL} disable verity" >&2 T=`adb_date` D=`adb disable-verity 2>&1` H=`adb disable-verity 2>&1` err=${?} if [ ${err} != 0 -o X"${D}" != X"${D##*setup failed}" ]; then echo "${D%?Now reboot your device for settings to take effect}" die -t ${T} "setup for overlay" fi L= D="${H%?Now reboot your device for settings to take effect}" if [ X"${D}" != X"${D##*using overlayfs}" ]; then echo "${GREEN}[ OK ]${NORMAL} using overlayfs" >&2 fi reboot=false if [ X"${D}" != X"${D##*Successfully disabled verity}" ]; then echo "${GREEN}[ OK ]${NORMAL} disabled verity" >&2 reboot=true else echo "${ORANGE}[ WARNING ]${NORMAL} verity already disabled" >&2 if [ ${err} != 0 ]; then echo "${H}" ( [ -n "${L}" ] && echo "${L}" && false ) || die -t "${T}" "disable-verity" fi rebooted=false if [ X"${D}" != X"${H}" -a X"${D}" = X"${D##*using overlayfs}" ]; then echo "${H}" if [ X"${D}" != X"${D##*setup failed}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} overlayfs setup whined" >&2 fi D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && D=`echo "${D}" | grep "^overlay " | true` && D=`echo "${D}" | grep "^overlay "` && [ -n "${D}" ] && ( echo "${H}" && echo "${D}" && true ) && die -t ${T} "overlay takeover unexpected" L= if ${reboot}; then ( echo "${H}" && echo "${D}" ) && die -t ${T} "overlay takeover unexpected at this phase" echo "${GREEN}[ INFO ]${NORMAL} rebooting as requested" >&2 L=`adb_logcat -b all -v nsec -t ${T} 2>&1` adb_reboot && adb_wait 2m || die "reboot after verity disabled failed" die "lost device after reboot requested" adb_root || die "lost device after elevation to root" rebooted=true # re-disable verity to see the setup remarks expected T=`adb_date` H=`adb disable-verity 2>&1` err=${?} D="${H%?Now reboot your device for settings to take effect}" if [ X"${D}" != X"${D##*using overlayfs}" ]; then echo "${GREEN}[ OK ]${NORMAL} using overlayfs" >&2 fi if [ ${err} != 0 ]; then T= fi fi if ${overlayfs_supported} && ${overlayfs_needed} && [ X"${D}" != X"${D##*setup failed}" ]; then echo "${D}" ( [ -n "${L}" ] && echo "${L}" && false ) || die -t "${T}" "setup for overlay" fi if [ X"${D}" != X"${D##*Successfully disabled verity}" ]; then echo "${D}" D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && D=`echo "${D}" | grep "^overlay " | true` && [ -n "${D}" ] && ( echo "${H}" && echo "${D}" ) && ( [ -n "${L}" ] && echo "${L}" && false ) || die -t "${T}" "overlay takeover unexpected" [ -n "${L}" ] && echo "${L}" die -t "${T}" "unexpected report of verity being disabled a second time" elif ${rebooted}; then echo "${GREEN}[ OK ]${NORMAL} verity already disabled" >&2 else echo "${ORANGE}[ WARNING ]${NORMAL} verity already disabled" >&2 fi echo "${GREEN}[ RUN ]${NORMAL} remount" >&2 adb_root && adb remount || ( [ -n "${L}" ] && echo "${L}" && false ) || die -t "${T}" "adb remount failed" D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && D=`echo "${D}" | grep "^overlay "` || ( [ -n "${L}" ] && echo "${L}" && false ) || ( [ -n "${L}" ] && echo "${L}" && false ) ret=${?} uses_dynamic_scratch=false scratch_partition= if ${overlayfs_needed}; then if [ ${ret} != 0 ]; then die -t ${T} "overlay takeover failed" fi echo "${D}" | grep "^overlay .* /system\$" >/dev/null || echo "${ORANGE}[ WARNING ]${NORMAL} overlay takeover not complete" >&2 scratch_partition=scratch if echo "${D}" | grep " /mnt/scratch" >/dev/null; then echo "${BLUE}[ INFO ]${NORMAL} using ${scratch_partition} dynamic partition for overrides" >&2 fi M=`adb_sh cat /proc/mounts | sed -n 's@\([^ ]*\) /mnt/scratch \([^ ]*\) .*@\2 on \1@p'` M=`adb_sh cat /proc/mounts </dev/null | sed -n 's@\([^ ]*\) /mnt/scratch \([^ ]*\) .*@\2 on \1@p'` [ -n "${M}" ] && echo "${BLUE}[ INFO ]${NORMAL} scratch filesystem ${M}" uses_dynamic_scratch=true Loading Loading @@ -403,8 +477,14 @@ echo "${H}" && echo "${D}" | grep "^overlay .* /system\$" >/dev/null || die "overlay takeover after remount" !(adb_sh grep "^overlay " /proc/mounts </dev/null | grep " overlay ro,") && !(adb_sh grep " rw," /proc/mounts </dev/null | skip_administrative_mounts data) || !(adb_sh grep " rw," /proc/mounts </dev/null | skip_administrative_mounts data) || die "remount overlayfs missed a spot (ro)" else if [ ${ret} = 0 ]; then die -t ${T} "unexpected overlay takeover" fi fi # Check something Loading @@ -426,6 +506,7 @@ adb_reboot && adb_wait 2m || die "reboot after override content added failed" if ${overlayfs_needed}; then D=`adb_su df -k </dev/null` && H=`echo "${D}" | head -1` && D=`echo "${D}" | grep "^overlay "` || Loading @@ -437,6 +518,7 @@ adb_su "sed -n '1,/overlay \\/system/p' /proc/mounts" </dev/null | grep -v ' \(squashfs\|ext4\|f2fs\) ' && echo "${ORANGE}[ WARNING ]${NORMAL} overlay takeover after first stage init" >&2 || echo "${GREEN}[ OK ]${NORMAL} overlay takeover in first stage init" >&2 fi B="`adb_cat /system/hello`" || die "re-read system hello after reboot" Loading @@ -452,12 +534,20 @@ check_eq "${A}" "${B}" vendor after reboot echo "${GREEN}[ RUN ]${NORMAL} flash vendor, confirm its content disappears" >&2 [ -n "${ANDROID_PRODUCT_OUT}" ] && H=`adb_sh echo '${HOSTNAME}' </dev/null 2>/dev/null` if [ -z "${ANDROID_PRODUCT_OUT}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} build tree not setup, skipping" elif [ ! -s "${ANDROID_PRODUCT_OUT}/vendor.img" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} vendor image missing, skipping" elif [ "${ANDROID_PRODUCT_OUT}" = "${ANDROID_PRODUCT_OUT%*/${H}}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} wrong vendor image, skipping" else adb reboot-fastboot && fastboot_wait 2m && fastboot flash vendor || ( fastboot reboot && false) || die "fastboot flash vendor" if [ -n "${scratch_paritition}" ]; then fastboot_getvar partition-type:${scratch_partition} raw || ( fastboot reboot && false) || die "fastboot can not see ${scratch_partition} parameters" Loading Loading @@ -486,11 +576,13 @@ echo "${BLUE}[ INFO ]${NORMAL} expect fastboot format ${scratch_partition} t fastboot format ${scratch_partition} && ( fastboot reboot || true) && die "fastboot can format ${scratch_partition}" fi fastboot reboot || die "can not reboot out of fastboot" echo "${ORANGE}[ WARNING ]${NORMAL} adb after fastboot ... waiting 2 minutes" adb_wait 2m || die "did not reboot after flash" if ${overlayfs_needed}; then adb_root && D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && Loading @@ -501,6 +593,7 @@ adb_root && die "overlay system takeover after flash vendor" echo "${D}" | grep "^overlay .* /vendor\$" >/dev/null && die "overlay minus vendor takeover after flash vendor" fi B="`adb_cat /system/hello`" || die "re-read system hello after flash vendor" check_eq "${A}" "${B}" system after flash vendor Loading @@ -509,6 +602,7 @@ adb_root || B="`adb_cat /vendor/hello`" && die "re-read vendor hello after flash vendor" check_eq "cat: /vendor/hello: No such file or directory" "${B}" vendor after flash vendor fi echo "${GREEN}[ RUN ]${NORMAL} remove test content (cleanup)" >&2 Loading @@ -524,6 +618,8 @@ B="`adb_cat /vendor/hello`" && die "re-read vendor hello after rm" check_eq "cat: /vendor/hello: No such file or directory" "${B}" after flash rm if [ -n "${scratch_partition}" ]; then echo "${GREEN}[ RUN ]${NORMAL} test fastboot flash to ${scratch_partition}" >&2 adb reboot-fastboot || Loading Loading @@ -551,5 +647,6 @@ echo "${D}" [ X"${D}" != X"${D##*using overlayfs}" ] && echo "${GREEN}[ OK ]${NORMAL} ${scratch_partition} recreated" >&2 || die -t ${T} "setup for overlayfs" fi echo "${GREEN}[ PASSED ]${NORMAL} adb remount" >&2 Loading
fs_mgr/fs_mgr_overlayfs.cpp +10 −2 Original line number Diff line number Diff line Loading @@ -144,7 +144,10 @@ bool fs_mgr_overlayfs_enabled(FstabEntry* entry) { if (entry->fs_mgr_flags.logical) { fs_mgr_update_logical_partition(entry); } return fs_mgr_has_shared_blocks(entry->mount_point, entry->blk_device); auto save_errno = errno; auto has_shared_blocks = fs_mgr_has_shared_blocks(entry->mount_point, entry->blk_device); errno = save_errno; return has_shared_blocks; } bool fs_mgr_rm_all(const std::string& path, bool* change = nullptr, int level = 0) { Loading Loading @@ -263,8 +266,10 @@ bool fs_mgr_overlayfs_already_mounted(const std::string& mount_point, bool overl std::vector<std::string> fs_mgr_overlayfs_verity_enabled_list() { std::vector<std::string> ret; auto save_errno = errno; fs_mgr_update_verity_state( [&ret](const std::string& mount_point, int) { ret.emplace_back(mount_point); }); if ((errno == ENOENT) || (errno == ENXIO)) errno = save_errno; return ret; } Loading Loading @@ -837,10 +842,12 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool* return ret; } auto save_errno = errno; Fstab fstab; if (!ReadDefaultFstab(&fstab)) { return false; } errno = save_errno; auto mounts = fs_mgr_candidate_list(&fstab, fs_mgr_mount_point(mount_point)); if (mounts.empty()) return ret; Loading @@ -864,7 +871,8 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool* break; } if (dir.empty()) { errno = ESRCH; if (change && *change) errno = ESRCH; if (errno == EPERM) errno = save_errno; return ret; } Loading
fs_mgr/tests/adb-remount-test.sh +260 −163 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ inAdb() { adb devices | grep -v 'List of devices attached' | grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null } [ "USAGE: adb_sh <commands> [ "USAGE: adb_sh <commands> </dev/stdin >/dev/stdout 2>/dev/stderr Returns: true if the command succeeded" ] adb_sh() { Loading Loading @@ -86,7 +86,7 @@ isDebuggable() { fi } [ "USAGE: adb_su <commands> [ "USAGE: adb_su <commands> </dev/stdin >/dev/stdout 2>/dev/stderr Returns: true if the command running as root succeeded" ] adb_su() { Loading Loading @@ -284,23 +284,47 @@ isDebuggable || die "device not a debug build" echo "${GREEN}[ RUN ]${NORMAL} Testing kernel support for overlayfs" >&2 overlayfs_supported=true; adb_wait || die "wait for device failed" adb_sh ls -d /sys/module/overlay </dev/null >/dev/null && echo "${GREEN}[ OK ]${NORMAL} overlay module present" >&2 || die "overlay module not present" ( echo "${ORANGE}[ WARNING ]${NORMAL} overlay module not present" >&2 && false ) || overlayfs_supported=false if ${overlayfs_supported}; then case `adb_sh uname -r </dev/null` in 4.[6789].* | 4.[1-9][0-9]* | [56789].*) adb_su ls /sys/module/overlay/parameters/override_creds </dev/null >/dev/null && echo "${GREEN}[ OK ]${NORMAL} overlay module supports override_creds" >&2 || die "overlay module can not be used on ANDROID" ( echo "${ORANGE}[ WARNING ]${NORMAL} overlay module does not support override_creds" >&2 && false ) || overlayfs_supported=false; ;; *) echo "${GREEN}[ OK ]${NORMAL} overlay module uses callers creds" >&2 ;; esac fi adb_root || die "initial setup" echo "${GREEN}[ RUN ]${NORMAL} Checking current overlayfs status" >&2 # We can not universally use adb enable-verity to ensure device is # in a overlayfs disabled state since it can prevent reboot on # devices that remount the physical content rather than overlayfs. # So lets do our best to surgically wipe the overlayfs state without # having to go through enable-verity transition. reboot=false OVERLAYFS_BACKING="cache mnt/scratch" for d in ${OVERLAYFS_BACKING}; do if adb_sh ls -d /${d}/overlay </dev/null >/dev/null 2>/dev/null; then echo "${ORANGE}[ WARNING ]${NORMAL} /${d}/overlay is setup, wiping" >&2 echo "${ORANGE}[ WARNING ]${NORMAL} /${d}/overlay is setup, surgically wiping" >&2 adb_sh rm -rf /${d}/overlay </dev/null || die "/${d}/overlay wipe" reboot=true Loading @@ -309,9 +333,10 @@ done if ${reboot}; then echo "${ORANGE}[ WARNING ]${NORMAL} rebooting before test" >&2 adb_reboot && adb_wait 2m && adb_wait 2m || die "lost device after reboot after wipe" adb_root || die "reboot after wipe" die "lost device after elevation to root after wipe" fi D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && Loading @@ -320,62 +345,111 @@ D=`adb_sh df -k </dev/null` && echo "${D}" && echo "${ORANGE}[ WARNING ]${NORMAL} overlays present before setup" >&2 || echo "${GREEN}[ OK ]${NORMAL} no overlay present before setup" >&2 adb_sh df -k `adb_sh cat /proc/mounts | overlayfs_needed=true D=`adb_sh cat /proc/mounts </dev/null | skip_administrative_mounts data | cut -s -d' ' -f1` D=`adb_sh df -k ${D} </dev/null` echo "${D}" if [ X"${D}" = X"${D##* 100[%] }" ]; then overlayfs_needed=false elif ! ${overlayfs_supported}; then die "need overlayfs, but do not have it" fi echo "${GREEN}[ RUN ]${NORMAL} disable verity" >&2 T=`adb_date` D=`adb disable-verity 2>&1` H=`adb disable-verity 2>&1` err=${?} if [ ${err} != 0 -o X"${D}" != X"${D##*setup failed}" ]; then echo "${D%?Now reboot your device for settings to take effect}" die -t ${T} "setup for overlay" fi L= D="${H%?Now reboot your device for settings to take effect}" if [ X"${D}" != X"${D##*using overlayfs}" ]; then echo "${GREEN}[ OK ]${NORMAL} using overlayfs" >&2 fi reboot=false if [ X"${D}" != X"${D##*Successfully disabled verity}" ]; then echo "${GREEN}[ OK ]${NORMAL} disabled verity" >&2 reboot=true else echo "${ORANGE}[ WARNING ]${NORMAL} verity already disabled" >&2 if [ ${err} != 0 ]; then echo "${H}" ( [ -n "${L}" ] && echo "${L}" && false ) || die -t "${T}" "disable-verity" fi rebooted=false if [ X"${D}" != X"${H}" -a X"${D}" = X"${D##*using overlayfs}" ]; then echo "${H}" if [ X"${D}" != X"${D##*setup failed}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} overlayfs setup whined" >&2 fi D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && D=`echo "${D}" | grep "^overlay " | true` && D=`echo "${D}" | grep "^overlay "` && [ -n "${D}" ] && ( echo "${H}" && echo "${D}" && true ) && die -t ${T} "overlay takeover unexpected" L= if ${reboot}; then ( echo "${H}" && echo "${D}" ) && die -t ${T} "overlay takeover unexpected at this phase" echo "${GREEN}[ INFO ]${NORMAL} rebooting as requested" >&2 L=`adb_logcat -b all -v nsec -t ${T} 2>&1` adb_reboot && adb_wait 2m || die "reboot after verity disabled failed" die "lost device after reboot requested" adb_root || die "lost device after elevation to root" rebooted=true # re-disable verity to see the setup remarks expected T=`adb_date` H=`adb disable-verity 2>&1` err=${?} D="${H%?Now reboot your device for settings to take effect}" if [ X"${D}" != X"${D##*using overlayfs}" ]; then echo "${GREEN}[ OK ]${NORMAL} using overlayfs" >&2 fi if [ ${err} != 0 ]; then T= fi fi if ${overlayfs_supported} && ${overlayfs_needed} && [ X"${D}" != X"${D##*setup failed}" ]; then echo "${D}" ( [ -n "${L}" ] && echo "${L}" && false ) || die -t "${T}" "setup for overlay" fi if [ X"${D}" != X"${D##*Successfully disabled verity}" ]; then echo "${D}" D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && D=`echo "${D}" | grep "^overlay " | true` && [ -n "${D}" ] && ( echo "${H}" && echo "${D}" ) && ( [ -n "${L}" ] && echo "${L}" && false ) || die -t "${T}" "overlay takeover unexpected" [ -n "${L}" ] && echo "${L}" die -t "${T}" "unexpected report of verity being disabled a second time" elif ${rebooted}; then echo "${GREEN}[ OK ]${NORMAL} verity already disabled" >&2 else echo "${ORANGE}[ WARNING ]${NORMAL} verity already disabled" >&2 fi echo "${GREEN}[ RUN ]${NORMAL} remount" >&2 adb_root && adb remount || ( [ -n "${L}" ] && echo "${L}" && false ) || die -t "${T}" "adb remount failed" D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && D=`echo "${D}" | grep "^overlay "` || ( [ -n "${L}" ] && echo "${L}" && false ) || ( [ -n "${L}" ] && echo "${L}" && false ) ret=${?} uses_dynamic_scratch=false scratch_partition= if ${overlayfs_needed}; then if [ ${ret} != 0 ]; then die -t ${T} "overlay takeover failed" fi echo "${D}" | grep "^overlay .* /system\$" >/dev/null || echo "${ORANGE}[ WARNING ]${NORMAL} overlay takeover not complete" >&2 scratch_partition=scratch if echo "${D}" | grep " /mnt/scratch" >/dev/null; then echo "${BLUE}[ INFO ]${NORMAL} using ${scratch_partition} dynamic partition for overrides" >&2 fi M=`adb_sh cat /proc/mounts | sed -n 's@\([^ ]*\) /mnt/scratch \([^ ]*\) .*@\2 on \1@p'` M=`adb_sh cat /proc/mounts </dev/null | sed -n 's@\([^ ]*\) /mnt/scratch \([^ ]*\) .*@\2 on \1@p'` [ -n "${M}" ] && echo "${BLUE}[ INFO ]${NORMAL} scratch filesystem ${M}" uses_dynamic_scratch=true Loading Loading @@ -403,8 +477,14 @@ echo "${H}" && echo "${D}" | grep "^overlay .* /system\$" >/dev/null || die "overlay takeover after remount" !(adb_sh grep "^overlay " /proc/mounts </dev/null | grep " overlay ro,") && !(adb_sh grep " rw," /proc/mounts </dev/null | skip_administrative_mounts data) || !(adb_sh grep " rw," /proc/mounts </dev/null | skip_administrative_mounts data) || die "remount overlayfs missed a spot (ro)" else if [ ${ret} = 0 ]; then die -t ${T} "unexpected overlay takeover" fi fi # Check something Loading @@ -426,6 +506,7 @@ adb_reboot && adb_wait 2m || die "reboot after override content added failed" if ${overlayfs_needed}; then D=`adb_su df -k </dev/null` && H=`echo "${D}" | head -1` && D=`echo "${D}" | grep "^overlay "` || Loading @@ -437,6 +518,7 @@ adb_su "sed -n '1,/overlay \\/system/p' /proc/mounts" </dev/null | grep -v ' \(squashfs\|ext4\|f2fs\) ' && echo "${ORANGE}[ WARNING ]${NORMAL} overlay takeover after first stage init" >&2 || echo "${GREEN}[ OK ]${NORMAL} overlay takeover in first stage init" >&2 fi B="`adb_cat /system/hello`" || die "re-read system hello after reboot" Loading @@ -452,12 +534,20 @@ check_eq "${A}" "${B}" vendor after reboot echo "${GREEN}[ RUN ]${NORMAL} flash vendor, confirm its content disappears" >&2 [ -n "${ANDROID_PRODUCT_OUT}" ] && H=`adb_sh echo '${HOSTNAME}' </dev/null 2>/dev/null` if [ -z "${ANDROID_PRODUCT_OUT}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} build tree not setup, skipping" elif [ ! -s "${ANDROID_PRODUCT_OUT}/vendor.img" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} vendor image missing, skipping" elif [ "${ANDROID_PRODUCT_OUT}" = "${ANDROID_PRODUCT_OUT%*/${H}}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} wrong vendor image, skipping" else adb reboot-fastboot && fastboot_wait 2m && fastboot flash vendor || ( fastboot reboot && false) || die "fastboot flash vendor" if [ -n "${scratch_paritition}" ]; then fastboot_getvar partition-type:${scratch_partition} raw || ( fastboot reboot && false) || die "fastboot can not see ${scratch_partition} parameters" Loading Loading @@ -486,11 +576,13 @@ echo "${BLUE}[ INFO ]${NORMAL} expect fastboot format ${scratch_partition} t fastboot format ${scratch_partition} && ( fastboot reboot || true) && die "fastboot can format ${scratch_partition}" fi fastboot reboot || die "can not reboot out of fastboot" echo "${ORANGE}[ WARNING ]${NORMAL} adb after fastboot ... waiting 2 minutes" adb_wait 2m || die "did not reboot after flash" if ${overlayfs_needed}; then adb_root && D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && Loading @@ -501,6 +593,7 @@ adb_root && die "overlay system takeover after flash vendor" echo "${D}" | grep "^overlay .* /vendor\$" >/dev/null && die "overlay minus vendor takeover after flash vendor" fi B="`adb_cat /system/hello`" || die "re-read system hello after flash vendor" check_eq "${A}" "${B}" system after flash vendor Loading @@ -509,6 +602,7 @@ adb_root || B="`adb_cat /vendor/hello`" && die "re-read vendor hello after flash vendor" check_eq "cat: /vendor/hello: No such file or directory" "${B}" vendor after flash vendor fi echo "${GREEN}[ RUN ]${NORMAL} remove test content (cleanup)" >&2 Loading @@ -524,6 +618,8 @@ B="`adb_cat /vendor/hello`" && die "re-read vendor hello after rm" check_eq "cat: /vendor/hello: No such file or directory" "${B}" after flash rm if [ -n "${scratch_partition}" ]; then echo "${GREEN}[ RUN ]${NORMAL} test fastboot flash to ${scratch_partition}" >&2 adb reboot-fastboot || Loading Loading @@ -551,5 +647,6 @@ echo "${D}" [ X"${D}" != X"${D##*using overlayfs}" ] && echo "${GREEN}[ OK ]${NORMAL} ${scratch_partition} recreated" >&2 || die -t ${T} "setup for overlayfs" fi echo "${GREEN}[ PASSED ]${NORMAL} adb remount" >&2