Tag Archives: recovery

Android 9 (P) recovery upgrade Map of ‘@/cache/recovery/block.map’ failed problem analysis guide

Adnroid 9 (P) recovery upgrade Map of ‘@/cache/recovery/block. The Map’ failed problem analysis guide

Android 9 (P) development adaptation guide series blog directory:

Adnroid 9 (P) recovery upgrade Map of ‘@/cache/recovery/block. The Map’ failed problem analysis guide
Android version 9 (P) solve VNDK library: 87. XXX’s ABI has extend CHANGES
; Android 9 (P) is not extended by the SDK API. ; Android 9 (P) is extended to extend Ethernet functions Android 9 (P) ultimate guide to silent installation/uninstallation of App adaptation

introduction
since Android 4.4 will join the Android SELinux, this thing although have security but some puzzling problems in the development of often, this to say today is the problem is due to the SELinux rules lead to the Map of ‘@/cache/recovery/block. The Map’ failed cannot upgrade.
note: this section describes the code in the Android platform P high pass 8953 platform.

The 1. Problem disk
with android version upgrade, the upgrade package is more and more big, when upgrading packages should not be stored in the cache partition, can download updates to the data partition, and then from the upgrade data partition, recently from the load data partition upgrade package upgrade, encountered the following error, the error can be after the defeat of the upgrade in the/cache/recovery/last_log view, specific log is as follows:

[    0.000179] __bionic_open_tzdata: couldn't find any tzdata when looking for Asia/Shanghai!
[    0.000238] Starting recovery (pid 387) on Thu Jan  1 05:28:26 1970
[    0.001760] recovery filesystem table
[    0.001783] =========================
[    0.001789]   0 /vendor ext4 /dev/block/platform/soc/7824900.sdhci/by-name/vendor 0
[    0.001794]   1/ext4 /dev/block/bootdevice/by-name/system 0
[    0.001799]   2 /cache ext4 /dev/block/bootdevice/by-name/cache 0
[    0.001804]   3 /vendor ext4 /dev/block/bootdevice/by-name/vendor 0
[    0.001809]   4 /data ext4 /dev/block/bootdevice/by-name/userdata 0
[    0.001814]   5 /sdcard vfat /dev/block/mmcblk1p1 0
[    0.001819]   6 /boot emmc /dev/block/bootdevice/by-name/boot 0
[    0.001823]   7 /recovery emmc /dev/block/bootdevice/by-name/recovery 0
[    0.001828]   8 /misc emmc /dev/block/bootdevice/by-name/misc 0
[    0.001833]   9 /tmp ramdisk ramdisk 0
[    0.001837]
[    0.003088] I:Boot command: boot-recovery
[    0.003104] I:Got 3 arguments from boot message
[    0.047245] locale is [zh-CN]
[    0.047297] stage is []
[    0.047321] reason is [(null)]
[    0.047981] W:Failed to read max brightness: No such file or directory
[    0.048017] I:Screensaver disabled
[    0.049631] cannot find/open a drm device: No such file or directory
[    0.050030] fb0 reports (possibly inaccurate):
[    0.050049]   vi.bits_per_pixel = 32
[    0.050055]   vi.red.offset   =   0   .length =   8
[    0.050060]   vi.green.offset =   8   .length =   8
[    0.050065]   vi.blue.offset  =  16   .length =   8
[    0.064662] framebuffer: 0 (1920 x 1080)
[    0.515251]           erasing_text: zh (81 x 38 @ 5031)
[    0.527722]        no_command_text: zh (111 x 38 @ 5031)
[    0.538287]             error_text: zh (65 x 38 @ 5031)
[    0.993697]        installing_text: zh (222 x 38 @ 5922)
[    1.023212] SELinux: Loaded file_contexts
[    1.023333] Command: "/sbin/recovery" "--update_package=@/cache/recovery/block.map" "--locale=zh-CN"
[    1.152498] I:Update location: @/cache/recovery/block.map
[    1.152563] Opening update package...
[    1.185800] E:Failed to read /cache/recovery/block.map: No such file or directory
[    1.202350] E:Map of '@/cache/recovery/block.map' failed
[    1.235591] E:failed to map file
[    1.280567] W:Failed to read /sys/class/thermal/thermal_zone53/temp: Invalid argument
[    1.280665] W:Failed to read /sys/class/thermal/thermal_zone52/temp: Invalid argument
[    1.280730] W:Failed to read /sys/class/thermal/thermal_zone51/temp: Invalid argument
[    1.280872] W:Failed to read /sys/class/thermal/thermal_zone49/temp: No such device
[    1.280936] W:Failed to read /sys/class/thermal/thermal_zone48/temp: No such device
[    1.281001] W:Failed to read /sys/class/thermal/thermal_zone47/temp: No such device
[    1.281064] W:Failed to read /sys/class/thermal/thermal_zone46/temp: Invalid argument
[    1.281127] W:Failed to read /sys/class/thermal/thermal_zone45/temp: Invalid argument
[    1.287659] I:current maximum temperature: 90000
[    1.287840] I:@/cache/recovery/block.map
[    1.287866] I:0
[    1.287889] I:time_total: 0
[    1.287911] I:retry: 0
[    1.287933] I:error: 26
[    1.287955] I:uncrypt_time: 0
[    1.287977] I:uncrypt_error: 117
[    1.287999] I:temperature_start: 90000
[    1.288021] I:temperature_end: 90000
[    1.288043] I:temperature_max: 90000
[    1.288065] I:
[    1.288093] Installation aborted.
[    1.303354] Mounted /cache/xxx-recovery
[    1.336868] mkdir /cache/xxx-recovery error[File exists]
[    1.356593] Recovery install reason=update_package result=fail on Thu Jan  1 05:28:27 1970
[    1.356622]  !
[    6.421470] I:Saving locale "zh-CN"

where the key information is as follows:

[    1.185800] E:Failed to read /cache/recovery/block.map: No such file or directory
[    1.202350] E:Map of '@/cache/recovery/block.map' failed
[    1.235591] E:failed to map file

: : : :

130|msm8953_64:/cache/recovery # ls -l
total 448
-rw------- 1 root   root      277 2020-05-12 17:48 block.map
-rw-r--r-- 1 root   root      271 1970-01-02 15:42 last_install
-rw------- 1 system system 368240 1970-01-02 15:42 last_kmsg
-rw------- 1 root   root        5 1970-01-02 15:42 last_locale
-rw------- 1 system system     38 2020-05-12 17:47 uncrypt_file

If does not exist, this is the point.

The 2. Solve problem
we trace the log information before restarting to enter recovery, and check it by logcat-b events | grep avc. The log is shown as follows:

[ 1212.869820@3] type=1400 audit(1209.144:3355): avc: denied { setattr } for pid=4433 comm="Thread-3" name="uncrypt_file" dev="mmcblk0p32" ino=13 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_recovery_file:s0 tclass=file permissive=0
[ 1212.885402@3] type=1400 audit(1212.820:3356): avc: denied { getattr } for pid=4501 comm="uncrypt" path="/data/cache" dev="mmcblk0p65" ino=19 scontext=u:r:uncrypt:s0 tcontext=u:object_r:cache_file:s0 tclass=dir permissive=0
[ 1212.906032@2] watchdogd: watchdogd started (interval 10, margin 20)!
[ 1212.906143@2] watchdogd: Failed to open /dev/watchdog: No such file or directory

it is obvious from the logs that the SELinux permission issue was encountered while working with /data and /cache partitions. (mmcblk0p32 and mmcblk0p65 correspond to cache and data partition respectively), the corresponding relation can be inquired under the terminal by the following way:

130|msm8953_64:/dev/block/by-name # ls  -l | grep cache
lrwxrwxrwx 1 root root 21 1970-01-01 08:00 cache -> /dev/block/mmcblk0p32
msm8953_64:/dev/block/by-name # ls  -l | grep data
lrwxrwxrwx 1 root root 21 1970-01-01 08:00 userdata -> /dev/block/mmcblk0p65
msm8953_64:/dev/block/by-name #

found the root point of the problem, we only need to give the corresponding SELinux authority for the upgraded application and recovery, but the SELinux authority encountered above did not continue, we need to know all the required SELinux authority, then we set SELinux as permissive state, and then upgrade again, we observe the log status:

[   98.295965@1] type=1400 audit(84.812:43): avc: denied { open } for pid=2890 comm="HwBinder:2890_1" path="/sys/module/tvin_hdmirx/parameters/en_4k_2_2k" dev="sysfs" ino=6874 scontext=u:r:system_control:s0 tcontext=u:object_r:sysfs_cec:s0 tclass=file permissive=1
[   98.313718@1] type=1400 audit(98.244:44): avc: denied { remove_name } for pid=4076 comm="Thread-4" name="update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_file:s0 tclass=dir permissive=1
[   98.333696@1] type=1400 audit(98.244:44): avc: denied { remove_name } for pid=4076 comm="Thread-4" name="update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_file:s0 tclass=dir permissive=1
[   98.353378@1] type=1400 audit(98.244:45): avc: denied { unlink } for pid=4076 comm="Thread-4" name="update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[   98.373096@1] type=1400 audit(98.244:45): avc: denied { unlink } for pid=4076 comm="Thread-4" name="update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[   98.392458@1] type=1400 audit(98.304:46): avc: denied { read } for pid=4076 comm="Thread-4" path="/data/cache/update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[   98.618368@2] success set parent gpu_p1_composite rate to 500000000
[   99.302385@1] success set parent gpu_p0_composite rate to 400000000
[  100.074360@1] success set parent gpu_p1_composite rate to 285714285
[  101.234329@3] success set parent gpu_p0_composite rate to 125000000
[  101.344037@0] aml_snd_card_tv aml_snd_tv: I2S playback disable
[  101.344244@0] aml_snd_card_tv aml_snd_tv: IEC958 playback disable
[  120.075238@1] type=1400 audit(98.304:46): avc: denied { read } for pid=4076 comm="Thread-4" path="/data/cache/update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[  120.090346@1] type=1400 audit(120.024:47): avc: denied { setattr } for pid=4076 comm="Thread-4" name="uncrypt_file" dev="mmcblk0p32" ino=13 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_recovery_file:s0 tclass=file permissive=1
[  121.326417@0] success set parent gpu_p1_composite rate to 666666666
[  121.734307@0] success set parent gpu_p0_composite rate to 500000000
[  121.897440@1] BT_RADIO going: off
[  121.897470@1] BCM_BT: going OFF
[  122.342361@2] success set parent gpu_p1_composite rate to 400000000
[  123.438484@0] success set parent gpu_p0_composite rate to 285714285
[  123.556904@1] type=1400 audit(120.024:47): avc: denied { setattr } for pid=4076 comm="Thread-4" name="uncrypt_file" dev="mmcblk0p32" ino=13 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_recovery_file:s0 tclass=file permissive=1
[  123.572107@1] type=1400 audit(123.508:48): avc: denied { getattr } for pid=4211 comm="uncrypt" path="/data/cache" dev="mmcblk0p65" ino=19 scontext=u:r:uncrypt:s0 tcontext=u:object_r:cache_file:s0 tclass=dir permissive=1
[  123.591568@1] type=1400 audit(123.508:48): avc: denied { getattr } for pid=4211 comm="uncrypt" path="/data/cache" dev="mmcblk0p65" ino=19 scontext=u:r:uncrypt:s0 tcontext=u:object_r:cache_file:s0 tclass=dir permissive=1
[  123.610598@1] type=1400 audit(123.508:49): avc: denied { getattr } for pid=4211 comm="uncrypt" path="/data/cache/update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:uncrypt:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[  123.631453@1] type=1400 audit(123.508:49): avc: denied { getattr } for pid=4211 comm="uncrypt" path="/data/cache/update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:uncrypt:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[  123.652217@1] type=1400 audit(123.512:50): avc: denied { read } for pid=4211 comm="uncrypt" name="update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:uncrypt:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[  123.672583@1] type=1400 audit(123.512:50): avc: denied { read } for pid=4211 comm="uncrypt" name="update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:uncrypt:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[  123.689809@1] type=1400 audit(123.512:51): avc: denied { open } for pid=4211 comm="uncrypt" path="/data/cache/update.zip" dev="mmcblk0p65" ino=316 scontext=u:r:uncrypt:s0 tcontext=u:object_r:cache_file:s0 tclass=file permissive=1
[  124.950389@3] success set parent gpu_p1_composite rate to 125000000

this is easy, add the corresponding rules of SELinux, about the study of SELinux you can refer to the blog Android SELinux development guide , here is not to do too much detail about the rules of SELinux, attached modified git commit record:

diff --git a/device/qcom/sepolicy/private/xxxdroid_share_file.te b/device/qcom/sepolicy/private/xxxdroid_share_file.te
index ea24edb..72f043d 100755
--- a/device/qcom/sepolicy/private/xxxdroid_share_file.te
+++ b/device/qcom/sepolicy/private/xxxdroid_share_file.te
@@ -31,5 +31,11 @@ allow PortPlugInit11 xxxdroid_share_file:file { create write setattr relabelfrom
 allow { auth_bpadownload posprintupdate} xxxdroid_share_file:dir { open search write create add_name remove_name setattr relabelfrom relabelto append unlink link rename getattr};
 allow { auth_bpadownload posprintupdate} xxxdroid_share_file:file { create write setattr relabelfrom relabelto append  rename open getattr read lock };
 
-allow {zygote bluetooth} xxxdroid_share_file:file {rw_file_perms};
-allow {zygote bluetooth} xxxdroid_share_file:dir {rw_dir_perms};
+allow {zygote bluetooth uncrypt} xxxdroid_share_file:file {rw_file_perms};
+allow {zygote bluetooth uncrypt} xxxdroid_share_file:dir {rw_dir_perms};
+
+allow system_app cache_file:dir { search add_name remove_name write };
+allow system_app cache_file:file { create getattr open write unlink read };
+
+allow uncrypt cache_file:dir getattr;
+allow uncrypt cache_file:file { open read getattr };

where xxxdroid_share_file.te is the policy file we added. If the child boots really encounter this problem, please add the policy according to the actual situation. Now that you have compiled the policy file, try again. Take a look at the success record of recovery. Check it in /cache/recovery/last_log. It’s too much.

[    0.000181] __bionic_open_tzdata: couldn't find any tzdata when looking for Asia/Shanghai!
[    0.000238] Starting recovery (pid 383) on Fri Jan  2 07:41:18 1970
[    0.001824] recovery filesystem table
[    0.001851] =========================
[    0.001857]   0 /vendor ext4 /dev/block/platform/soc/7824900.sdhci/by-name/vendor 0
[    0.001862]   1/ext4 /dev/block/bootdevice/by-name/system 0
[    0.001867]   2 /cache ext4 /dev/block/bootdevice/by-name/cache 0
[    0.001872]   3 /vendor ext4 /dev/block/bootdevice/by-name/vendor 0
[    0.001877]   4 /data ext4 /dev/block/bootdevice/by-name/userdata 0
[    0.001882]   5 /sdcard vfat /dev/block/mmcblk1p1 0
[    0.001886]   6 /boot emmc /dev/block/bootdevice/by-name/boot 0
[    0.001891]   7 /recovery emmc /dev/block/bootdevice/by-name/recovery 0
[    0.001896]   8 /misc emmc /dev/block/bootdevice/by-name/misc 0
[    0.001901]   9 /tmp ramdisk ramdisk 0
[    0.001905]
[    0.003103] I:Boot command: boot-recovery
[    0.003121] I:Got 3 arguments from boot message
[    0.057346] locale is [zh-CN]
[    0.057379] stage is []
[    0.057385] reason is [(null)]
[    0.057390] W:Failed to read max brightness: No such file or directory
[    0.057395] I:Screensaver disabled
[    0.058859] cannot find/open a drm device: No such file or directory
[    0.059139] fb0 reports (possibly inaccurate):
[    0.059150]   vi.bits_per_pixel = 32
[    0.059156]   vi.red.offset   =   0   .length =   8
[    0.059161]   vi.green.offset =   8   .length =   8
[    0.059166]   vi.blue.offset  =  16   .length =   8
[    0.072937] framebuffer: 0 (1920 x 1080)
[    0.521428]           erasing_text: zh (81 x 38 @ 5031)
[    0.533880]        no_command_text: zh (111 x 38 @ 5031)
[    0.544223]             error_text: zh (65 x 38 @ 5031)
[    0.998365]        installing_text: zh (222 x 38 @ 5922)
[    1.029506] SELinux: Loaded file_contexts
[    1.029631] Command: "/sbin/recovery" "--update_package=@/cache/recovery/block.map" "--locale=zh-CN"
[   88.676745] wrote 129279 blocks; expected 129279
[   88.676811] stashed 0 blocks
[   88.676840] max alloc needed was 4096
[   88.676930] deleting stash 34a21d3b3dc53f7084ea0b7f275c179b3062f9be
[   90.216571] Patching firmware images...
[   90.217492] prepare_partitions: Preparing for primary partition update
[   90.217700] 'apdp' partition not backup - skip safe update
[   90.217744] 'keystore' partition not backup - skip safe update
[   90.217795] 'msadp' partition not backup - skip safe update
[   90.217825] 'mdtp' partition not backup - skip safe update
[   90.217860] 'dsp' partition not backup - skip safe update
[   90.375081] prepare_partitions: Preparing for backup partition update
[   90.543922] prepare_partitions: Finalizing partitions
[   90.601289]
[   90.854443] W:Failed to read /sys/class/thermal/thermal_zone53/temp: Invalid argument
[   90.854541] W:Failed to read /sys/class/thermal/thermal_zone52/temp: Invalid argument
[   90.854606] W:Failed to read /sys/class/thermal/thermal_zone51/temp: Invalid argument
[   90.854752] W:Failed to read /sys/class/thermal/thermal_zone49/temp: No such device
[   90.854818] W:Failed to read /sys/class/thermal/thermal_zone48/temp: No such device
[   90.854883] W:Failed to read /sys/class/thermal/thermal_zone47/temp: No such device
[   90.854946] W:Failed to read /sys/class/thermal/thermal_zone46/temp: Invalid argument
[   90.855009] W:Failed to read /sys/class/thermal/thermal_zone45/temp: Invalid argument
[   90.861607] I:current maximum temperature: 90277
[   90.861798] I:@/cache/recovery/block.map
[   90.861823] I:1
[   90.861846] I:time_total: 89
[   90.861868] I:retry: 0
[   90.861890] I:target_build: 57
[   90.861913] I:bytes_written_system: 1574789120
[   90.861935] I:bytes_stashed_system: 0
[   90.861956] I:bytes_written_vendor: 529526784
[   90.861978] I:bytes_stashed_vendor: 0
[   90.862000] I:uncrypt_time: 20
[   90.862022] I:temperature_start: 90555
[   90.862043] I:temperature_end: 90277
[   90.862065] I:temperature_max: 90555
[   90.862087] I:
[   90.862308] Mounted /cache/xxx-recovery
[   90.882512] mkdir /cache/xxx-recovery error[File exists]
[   90.902829] Recovery install reason=update_package result=success on Fri Jan  2 07:42:48 1970
[   90.902859]  !
[   90.948791] I:Saving locale "zh-CN"

after the successful upgrade /cache/recovery directory structure is as follows:

msm8953_64:/cache/recovery # ls -l
total 448
-rw------- 1 root   root      277 2020-05-12 17:48 block.map
-rw-r--r-- 1 root   root      271 1970-01-02 15:42 last_install
-rw------- 1 system system 368240 1970-01-02 15:42 last_kmsg
-rw------- 1 root   root        5 1970-01-02 15:42 last_locale
-rw-r----- 1 root   root    49067 1970-01-02 15:42 last_log
-rw------- 1 system system     38 2020-05-12 17:47 uncrypt_file

epilogue
ok, I don’t need to say more about this problem, but if you do encounter this problem, make sure you go through the logcat-b events | grep avc to see the problem and then add the corresponding permissions.

write at the end
readers reader friends, upgrade the Android P recovery Map of ‘@/cache/recovery/block. The Map’ failed problem analysis guide already all finished, not what to say. In the end, readers, if this post is helpful to you, follow up with thumb up, and of course, if there are any mistakes or shortcomings, you can also post them.