1*e7c364b6SAndroid Build Coastguard WorkerThe Recovery Image 2*e7c364b6SAndroid Build Coastguard Worker================== 3*e7c364b6SAndroid Build Coastguard Worker 4*e7c364b6SAndroid Build Coastguard WorkerQuick turn-around testing 5*e7c364b6SAndroid Build Coastguard Worker------------------------- 6*e7c364b6SAndroid Build Coastguard Worker 7*e7c364b6SAndroid Build Coastguard Worker* Devices using recovery-as-boot (e.g. Pixels, which set BOARD\_USES\_RECOVERY\_AS\_BOOT) 8*e7c364b6SAndroid Build Coastguard Worker 9*e7c364b6SAndroid Build Coastguard Worker # After setting up environment and lunch. 10*e7c364b6SAndroid Build Coastguard Worker m -j bootimage 11*e7c364b6SAndroid Build Coastguard Worker adb reboot bootloader 12*e7c364b6SAndroid Build Coastguard Worker 13*e7c364b6SAndroid Build Coastguard Worker # Pixel devices don't support booting into recovery mode with `fastboot boot`. 14*e7c364b6SAndroid Build Coastguard Worker fastboot flash boot 15*e7c364b6SAndroid Build Coastguard Worker 16*e7c364b6SAndroid Build Coastguard Worker # Manually choose `Recovery mode` from bootloader menu. 17*e7c364b6SAndroid Build Coastguard Worker 18*e7c364b6SAndroid Build Coastguard Worker* Devices with a separate recovery image (e.g. Nexus) 19*e7c364b6SAndroid Build Coastguard Worker 20*e7c364b6SAndroid Build Coastguard Worker # After setting up environment and lunch. 21*e7c364b6SAndroid Build Coastguard Worker mm -j && m ramdisk-nodeps && m recoveryimage-nodeps 22*e7c364b6SAndroid Build Coastguard Worker adb reboot bootloader 23*e7c364b6SAndroid Build Coastguard Worker 24*e7c364b6SAndroid Build Coastguard Worker # To boot into the new recovery image without flashing the recovery partition: 25*e7c364b6SAndroid Build Coastguard Worker fastboot boot $ANDROID_PRODUCT_OUT/recovery.img 26*e7c364b6SAndroid Build Coastguard Worker 27*e7c364b6SAndroid Build Coastguard WorkerRunning the tests 28*e7c364b6SAndroid Build Coastguard Worker----------------- 29*e7c364b6SAndroid Build Coastguard Worker 30*e7c364b6SAndroid Build Coastguard Worker # After setting up environment and lunch. 31*e7c364b6SAndroid Build Coastguard Worker mmma -j bootable/recovery 32*e7c364b6SAndroid Build Coastguard Worker 33*e7c364b6SAndroid Build Coastguard Worker # Running the tests on device (under normal boot). 34*e7c364b6SAndroid Build Coastguard Worker adb root 35*e7c364b6SAndroid Build Coastguard Worker adb sync data 36*e7c364b6SAndroid Build Coastguard Worker 37*e7c364b6SAndroid Build Coastguard Worker # 32-bit device 38*e7c364b6SAndroid Build Coastguard Worker adb shell /data/nativetest/recovery_unit_test/recovery_unit_test 39*e7c364b6SAndroid Build Coastguard Worker 40*e7c364b6SAndroid Build Coastguard Worker # Or 64-bit device 41*e7c364b6SAndroid Build Coastguard Worker adb shell /data/nativetest64/recovery_unit_test/recovery_unit_test 42*e7c364b6SAndroid Build Coastguard Worker 43*e7c364b6SAndroid Build Coastguard WorkerRunning the manual tests 44*e7c364b6SAndroid Build Coastguard Worker------------------------ 45*e7c364b6SAndroid Build Coastguard Worker 46*e7c364b6SAndroid Build Coastguard Worker`recovery-refresh` and `recovery-persist` executables exist only on systems without 47*e7c364b6SAndroid Build Coastguard Worker/cache partition. And we need to follow special steps to run tests for them. 48*e7c364b6SAndroid Build Coastguard Worker 49*e7c364b6SAndroid Build Coastguard Worker- Execute the test on an A/B device first. The test should fail but it will log 50*e7c364b6SAndroid Build Coastguard Worker some contents to pmsg. 51*e7c364b6SAndroid Build Coastguard Worker 52*e7c364b6SAndroid Build Coastguard Worker- Reboot the device immediately and run the test again. The test should save the 53*e7c364b6SAndroid Build Coastguard Worker contents of pmsg buffer into /data/misc/recovery/inject.txt. Test will pass if 54*e7c364b6SAndroid Build Coastguard Worker this file has expected contents. 55*e7c364b6SAndroid Build Coastguard Worker 56*e7c364b6SAndroid Build Coastguard WorkerUsing `adb` under recovery 57*e7c364b6SAndroid Build Coastguard Worker-------------------------- 58*e7c364b6SAndroid Build Coastguard Worker 59*e7c364b6SAndroid Build Coastguard WorkerWhen running recovery image from debuggable builds (i.e. `-eng` or `-userdebug` build variants, or 60*e7c364b6SAndroid Build Coastguard Worker`ro.debuggable=1` in `/prop.default`), `adbd` service is enabled and started by default, which 61*e7c364b6SAndroid Build Coastguard Workerallows `adb` communication. A device should be listed under `adb devices`, either in `recovery` or 62*e7c364b6SAndroid Build Coastguard Worker`sideload` state. 63*e7c364b6SAndroid Build Coastguard Worker 64*e7c364b6SAndroid Build Coastguard Worker $ adb devices 65*e7c364b6SAndroid Build Coastguard Worker List of devices attached 66*e7c364b6SAndroid Build Coastguard Worker 1234567890abcdef recovery 67*e7c364b6SAndroid Build Coastguard Worker 68*e7c364b6SAndroid Build Coastguard WorkerAlthough `/system/bin/adbd` is built from the same code base as the one in the normal boot, only a 69*e7c364b6SAndroid Build Coastguard Workersubset of `adb` commands are meaningful under recovery, such as `adb root`, `adb shell`, `adb push`, 70*e7c364b6SAndroid Build Coastguard Worker`adb pull` etc. Since Android Q, `adb shell` no longer requires manually mounting `/system` from 71*e7c364b6SAndroid Build Coastguard Workerrecovery menu. 72*e7c364b6SAndroid Build Coastguard Worker 73*e7c364b6SAndroid Build Coastguard Worker## Troubleshooting 74*e7c364b6SAndroid Build Coastguard Worker 75*e7c364b6SAndroid Build Coastguard Worker### `adb devices` doesn't show the device. 76*e7c364b6SAndroid Build Coastguard Worker 77*e7c364b6SAndroid Build Coastguard Worker $ adb devices 78*e7c364b6SAndroid Build Coastguard Worker List of devices attached 79*e7c364b6SAndroid Build Coastguard Worker 80*e7c364b6SAndroid Build Coastguard Worker * Ensure `adbd` is built and running. 81*e7c364b6SAndroid Build Coastguard Worker 82*e7c364b6SAndroid Build Coastguard WorkerBy default, `adbd` is always included into recovery image, as `/system/bin/adbd`. `init` starts 83*e7c364b6SAndroid Build Coastguard Worker`adbd` service automatically only in debuggable builds. This behavior is controlled by the recovery 84*e7c364b6SAndroid Build Coastguard Workerspecific `/init.rc`, whose source code is at `bootable/recovery/etc/init.rc`. 85*e7c364b6SAndroid Build Coastguard Worker 86*e7c364b6SAndroid Build Coastguard WorkerThe best way to confirm a running `adbd` is by checking the serial output, which shows a service 87*e7c364b6SAndroid Build Coastguard Workerstart log as below. 88*e7c364b6SAndroid Build Coastguard Worker 89*e7c364b6SAndroid Build Coastguard Worker [ 18.961986] c1 1 init: starting service 'adbd'... 90*e7c364b6SAndroid Build Coastguard Worker 91*e7c364b6SAndroid Build Coastguard Worker * Ensure USB gadget has been enabled. 92*e7c364b6SAndroid Build Coastguard Worker 93*e7c364b6SAndroid Build Coastguard WorkerIf `adbd` service has been started but device not shown under `adb devices`, use `lsusb(8)` (on 94*e7c364b6SAndroid Build Coastguard Workerhost) to check if the device is visible to the host. 95*e7c364b6SAndroid Build Coastguard Worker 96*e7c364b6SAndroid Build Coastguard Worker`bootable/recovery/etc/init.rc` disables Android USB gadget (via sysfs) as part of the `fs` action 97*e7c364b6SAndroid Build Coastguard Workertrigger, and will only re-enable it in debuggable builds (the `on property` rule will always run 98*e7c364b6SAndroid Build Coastguard Worker_after_ `on fs`). 99*e7c364b6SAndroid Build Coastguard Worker 100*e7c364b6SAndroid Build Coastguard Worker on fs 101*e7c364b6SAndroid Build Coastguard Worker write /sys/class/android_usb/android0/enable 0 102*e7c364b6SAndroid Build Coastguard Worker 103*e7c364b6SAndroid Build Coastguard Worker # Always start adbd on userdebug and eng builds 104*e7c364b6SAndroid Build Coastguard Worker on property:ro.debuggable=1 105*e7c364b6SAndroid Build Coastguard Worker write /sys/class/android_usb/android0/enable 1 106*e7c364b6SAndroid Build Coastguard Worker start adbd 107*e7c364b6SAndroid Build Coastguard Worker 108*e7c364b6SAndroid Build Coastguard WorkerIf device is using [configfs](https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt), 109*e7c364b6SAndroid Build Coastguard Workercheck if configfs has been properly set up in init rc scripts. See the [example 110*e7c364b6SAndroid Build Coastguard Workerconfiguration](https://android.googlesource.com/device/google/wahoo/+/master/init.recovery.hardware.rc) 111*e7c364b6SAndroid Build Coastguard Workerfor Pixel 2 devices. Note that the flag set via sysfs (i.e. the one above) is no-op when using 112*e7c364b6SAndroid Build Coastguard Workerconfigfs. 113*e7c364b6SAndroid Build Coastguard Worker 114*e7c364b6SAndroid Build Coastguard Worker### `adb devices` shows the device, but in `unauthorized` state. 115*e7c364b6SAndroid Build Coastguard Worker 116*e7c364b6SAndroid Build Coastguard Worker $ adb devices 117*e7c364b6SAndroid Build Coastguard Worker List of devices attached 118*e7c364b6SAndroid Build Coastguard Worker 1234567890abcdef unauthorized 119*e7c364b6SAndroid Build Coastguard Worker 120*e7c364b6SAndroid Build Coastguard Workerrecovery image doesn't honor the USB debugging toggle and the authorizations added under normal boot 121*e7c364b6SAndroid Build Coastguard Worker(because such authorization data stays in /data, which recovery doesn't mount), nor does it support 122*e7c364b6SAndroid Build Coastguard Workerauthorizing a host device under recovery. We can use one of the following options instead. 123*e7c364b6SAndroid Build Coastguard Worker 124*e7c364b6SAndroid Build Coastguard Worker * **Option 1 (Recommended):** Authorize a host device with adb vendor keys. 125*e7c364b6SAndroid Build Coastguard Worker 126*e7c364b6SAndroid Build Coastguard WorkerFor debuggable builds, an RSA keypair can be used to authorize a host device that has the private 127*e7c364b6SAndroid Build Coastguard Workerkey. The public key, defined via `PRODUCT_ADB_KEYS`, will be copied to `/adb_keys`. When starting 128*e7c364b6SAndroid Build Coastguard Workerthe host-side `adbd`, make sure the filename (or the directory) of the matching private key has been 129*e7c364b6SAndroid Build Coastguard Workeradded to `$ADB_VENDOR_KEYS`. 130*e7c364b6SAndroid Build Coastguard Worker 131*e7c364b6SAndroid Build Coastguard Worker $ export ADB_VENDOR_KEYS=/path/to/adb/private/key 132*e7c364b6SAndroid Build Coastguard Worker $ adb kill-server 133*e7c364b6SAndroid Build Coastguard Worker $ adb devices 134*e7c364b6SAndroid Build Coastguard Worker 135*e7c364b6SAndroid Build Coastguard Worker`-user` builds filter out `PRODUCT_ADB_KEYS`, so no `/adb_keys` will be included there. 136*e7c364b6SAndroid Build Coastguard Worker 137*e7c364b6SAndroid Build Coastguard WorkerNote that this mechanism applies to both of normal boot and recovery modes. 138*e7c364b6SAndroid Build Coastguard Worker 139*e7c364b6SAndroid Build Coastguard Worker * **Option 2:** Allow `adbd` to connect without authentication. 140*e7c364b6SAndroid Build Coastguard Worker * bootloader is unlocked (`ro.boot.verifiedbootstate` is `orange`) or debuggable build. 141*e7c364b6SAndroid Build Coastguard Worker * `ro.adb.secure` has a value of `0`. 142*e7c364b6SAndroid Build Coastguard Worker 143*e7c364b6SAndroid Build Coastguard WorkerBoth of the two conditions need to be satisfied. Although `ro.adb.secure` is a runtime property, its 144*e7c364b6SAndroid Build Coastguard Workervalue is set at build time (written into `/prop.default`). It defaults to `1` on `-user` builds, and 145*e7c364b6SAndroid Build Coastguard Worker`0` for other build variants. The value is overridable via `PRODUCT_DEFAULT_PROPERTY_OVERRIDES`. 146*e7c364b6SAndroid Build Coastguard Worker 147*e7c364b6SAndroid Build Coastguard WorkerLocalization of the background texts 148*e7c364b6SAndroid Build Coastguard Worker------------------------------------ 149*e7c364b6SAndroid Build Coastguard Worker 150*e7c364b6SAndroid Build Coastguard WorkerThe recovery image supports localization of several background texts, e.g. installing, error, 151*e7c364b6SAndroid Build Coastguard Workerfactory reset warnings, etc. For devices using `xxhdpi` and `xxxhdpi`, the build system generates 152*e7c364b6SAndroid Build Coastguard Workerthese localization images dynamically since android-10 when building the recovery image. While 153*e7c364b6SAndroid Build Coastguard Workerthe static images under res-*dpi/images/ is used for other display resolutions and as a 154*e7c364b6SAndroid Build Coastguard Workerbackup. 155*e7c364b6SAndroid Build Coastguard Worker 156*e7c364b6SAndroid Build Coastguard WorkerCheck the invocation of the image_generator tool in the [makefile]. And the detailed usage of the 157*e7c364b6SAndroid Build Coastguard Workerimage_generator is documented [here](./tools/image_generator/README.md). 158*e7c364b6SAndroid Build Coastguard Worker 159*e7c364b6SAndroid Build Coastguard Worker[makefile]: https://android.googlesource.com/platform/build/+/refs/heads/master/core/Makefile#1800 160