From 3d2698105ed3744405e11f0a0c55d96d23281369 Mon Sep 17 00:00:00 2001 From: Nathan Huckleberry Date: Tue, 7 Feb 2023 01:09:57 +0000 Subject: [PATCH 001/133] Enable HCTR2 for filenames encryption Fix prefix-correlation weakness in filenames encryption by switching to AES-256-HCTR2. Enabling HCTR2 fixes a longstanding known weakness in filenames encryption. Also enable HCTR2 for adoptable storage. Pixel phones don't have an SD card slot. So they can only have adoptable storage through the "Virtual SD Card", which is for testing only. Bug: 265046004 Test: Equivalent changes were tested on P21 since I don't have a P23. Will be tested with storage-qa. Change-Id: I0666eb07c4b93b1bab4da41e3b4f5019ac38c213 --- conf/Android.bp | 4 ++-- device.mk | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/conf/Android.bp b/conf/Android.bp index e9e50ecf..58f11f32 100644 --- a/conf/Android.bp +++ b/conf/Android.bp @@ -37,7 +37,7 @@ genrule { name: "gen_fstab.zuma-hw-encrypt", srcs: ["fstab.zuma.in"], out: ["fstab.zuma"], - cmd: "sed -e s/@fileencryption@/fileencryption=::inlinecrypt_optimized+wrappedkey_v0/" + + cmd: "sed -e s/@fileencryption@/fileencryption=:aes-256-hctr2:inlinecrypt_optimized+wrappedkey_v0/" + " -e s/@inlinecrypt@/inlinecrypt/ " + " -e s/@metadata_encryption@/metadata_encryption=:wrappedkey_v0/ $(in) > $(out)", } @@ -46,7 +46,7 @@ genrule { name: "gen_fstab.zuma-sw-encrypt", srcs: ["fstab.zuma.in"], out: ["fstab.zuma"], - cmd: "sed -e s/@fileencryption@/fileencryption=aes-256-xts/" + + cmd: "sed -e s/@fileencryption@/fileencryption=aes-256-xts:aes-256-hctr2/" + " -e s/@inlinecrypt@// " + " -e s/@metadata_encryption@/metadata_encryption=/ $(in) > $(out)", } diff --git a/device.mk b/device.mk index e4405249..2ebb8197 100644 --- a/device.mk +++ b/device.mk @@ -1134,6 +1134,10 @@ PRODUCT_COPY_FILES += \ # Call deleteAllKeys if vold detects a factory reset PRODUCT_VENDOR_PROPERTIES += ro.crypto.metadata_init_delete_all_keys.enabled?=true +# Use HCTR2 for filenames encryption on adoptable storage. +PRODUCT_PROPERTY_OVERRIDES += \ + ro.crypto.volume.options=aes-256-xts:aes-256-hctr2 + # Hardware Info Collection include hardware/google/pixel/HardwareInfo/HardwareInfo.mk From e2a6eb58b227fd38d66e467214822c2deb06b2d9 Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Wed, 15 Feb 2023 15:26:33 -0800 Subject: [PATCH 002/133] Move thermal utils to hardware/interfaces Bug: b/269370789 Test: m Change-Id: Id813adc99746b171693f983230f9193431f25693 --- usb/usb/Android.bp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index 3e38396e..e252c327 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -56,7 +56,7 @@ cc_binary { static_libs: [ "libpixelusb", "libpixelstats", - "libpixelthermalwrapper", + "libthermalutils", ], export_shared_lib_headers: [ "android.frameworks.stats-V1-ndk", From c97337e9f852f4081ec83f29e732f4b148ff6bdd Mon Sep 17 00:00:00 2001 From: Jayachandran C Date: Fri, 17 Feb 2023 06:28:54 +0000 Subject: [PATCH 003/133] Do not compile AoC audio for aosp and factory builds Fix: 265179406 Fix: 269273333 Test: make Change-Id: I07a78748ff18fb8dd772bdc83e072974f12c70ac --- device.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/device.mk b/device.mk index 0e894aec..eca5cf5e 100644 --- a/device.mk +++ b/device.mk @@ -872,6 +872,7 @@ PRODUCT_PACKAGES_DEBUG += \ PRODUCT_PACKAGES += ShannonRcs +ifeq (,$(filter aosp_% factory_%,$(TARGET_PRODUCT))) #ImsMediaAoc library FEATURE_TYPE := oem_audio SOONG_CONFIG_NAMESPACES += audio_lib @@ -879,6 +880,7 @@ SOONG_CONFIG_audio_lib += \ audio_type SOONG_CONFIG_audio_lib_audio_type := $(FEATURE_TYPE) +endif # ImsMedia PRODUCT_PACKAGES += \ From 5c921504827c5588056e4073b9480c5ac69760d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Wagner?= Date: Tue, 27 Dec 2022 14:18:42 +0000 Subject: [PATCH 004/133] Update Mali DDK to r40 : Sysprop configuration settings Expose DDK's dynamic configuration options through the Android Sysprop interface, following recommendations from Arm's Android Integration Manual. Bug: 261718474 Change-Id: I9549304a70277e00202680885c596bec2dc21bcf --- device.mk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/device.mk b/device.mk index 6942d7f9..443133ef 100644 --- a/device.mk +++ b/device.mk @@ -225,6 +225,12 @@ PRODUCT_VENDOR_PROPERTIES += \ ro.hardware.vulkan=mali endif +# Mali Configuration Properties +# b/221255664 prevents setting PROTECTED_MAX_CORE_COUNT=2 +PRODUCT_VENDOR_PROPERTIES += \ + vendor.mali.protected_max_core_count=1 \ + vendor.mali.protected_tls_max=67108864 \ + vendor.mali.platform_agt_frequency_khz=24576 PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.opengles.aep.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.opengles.aep.xml \ From f60e906395300642e83a4c44d7f8994b6aba7424 Mon Sep 17 00:00:00 2001 From: Sophia Wang Date: Wed, 15 Feb 2023 14:11:20 -0800 Subject: [PATCH 005/133] Zuma:conf Add memlat CPU idle awareness settings Test: cat /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/memlat_cpuidle_state_aware Bug: 269148983 Change-Id: I772c53f95c8c1d7f84c34cfd49397a47db0fdf64 Signed-off-by: Sophia Wang --- conf/init.zuma.rc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 02bee631..ffc3edd2 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -61,6 +61,16 @@ on init chown system system /sys/devices/system/cpu/cpufreq/policy8/sched_pixel/limit_frequency chown system system /sys/devices/system/cpu/cpufreq/policy8/sched_pixel/pmu_limit_enable + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/memlat_cpuidle_state_aware + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010/memlat_cpuidle_state_aware + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu2_memlat@17000010/memlat_cpuidle_state_aware + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu3_memlat@17000010/memlat_cpuidle_state_aware + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu4_memlat@17000010/memlat_cpuidle_state_aware + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu5_memlat@17000010/memlat_cpuidle_state_aware + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/memlat_cpuidle_state_aware + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/memlat_cpuidle_state_aware + chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/memlat_cpuidle_state_aware + chmod 0220 /proc/vendor_sched/set_task_group_bg chmod 0220 /proc/vendor_sched/set_task_group_cam chmod 0220 /proc/vendor_sched/set_task_group_fg @@ -169,6 +179,18 @@ on init write /sys/devices/system/cpu/cpu8/cpufreq/sched_pixel/up_rate_limit_us 500 write /sys/devices/system/cpu/cpu8/cpufreq/sched_pixel/down_rate_limit_us 20000 + + # memlat cpuidle awareness setting + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/memlat_cpuidle_state_aware 2 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010/memlat_cpuidle_state_aware 2 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu2_memlat@17000010/memlat_cpuidle_state_aware 2 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu3_memlat@17000010/memlat_cpuidle_state_aware 2 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu4_memlat@17000010/memlat_cpuidle_state_aware 2 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu5_memlat@17000010/memlat_cpuidle_state_aware 2 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/memlat_cpuidle_state_aware 2 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/memlat_cpuidle_state_aware 2 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/memlat_cpuidle_state_aware 2 + # RT uclamp setting write /proc/sys/kernel/sched_util_clamp_min_rt_default 0 From e86ccf6392799de9526f00c7f70e0aed231c7785 Mon Sep 17 00:00:00 2001 From: Armelle Laine Date: Mon, 13 Feb 2023 22:23:39 +0000 Subject: [PATCH 006/133] Enable Trusty persist storage (TDP) on block-device - Define selinux property for /dev/block/by-name/trusty_persist - Add symlink into init.zuma.rc Bug: 247013568 Test: - Verify that this change is a NOP for devices with TDP already created on top of the legacy f2f2 partition /mnt/vendor/persist/ss - Verify that this change creates a valid symlink on a manually migrated block device Change-Id: I231938e708e5a5d6d64818e184a92acdc0ba37de --- conf/init.zuma.rc | 2 ++ conf/ueventd.zuma.rc | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 6af437f9..b69f4a3e 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -847,6 +847,8 @@ on post-fs-data symlink /mnt/vendor/persist/ss /data/vendor/ss/persist chown root system /data/vendor/ss/persist chmod 0770 /data/vendor/ss/persist + symlink /dev/block/platform/13200000\.ufs/by-name/trusty_persist /data/vendor/ss/persist/0 + chown system system /data/vendor/ss/persist/0 restart storageproxyd diff --git a/conf/ueventd.zuma.rc b/conf/ueventd.zuma.rc index 640c0c01..2616ce2b 100644 --- a/conf/ueventd.zuma.rc +++ b/conf/ueventd.zuma.rc @@ -163,8 +163,9 @@ /dev/bigwave 0660 mediacodec mediadrm # Trusty -/dev/trusty-ipc-dev0 0660 system drmrpc -/dev/trusty-log0 0660 system system +/dev/trusty-ipc-dev0 0660 system drmrpc +/dev/trusty-log0 0660 system system +/dev/block/platform/13200000\.ufs/by-name/trusty_persist 0660 system system # RPMB /dev/sg1 0660 system system From 43f7439f43b9fd974f4e83ce21c1c898e1ba53a2 Mon Sep 17 00:00:00 2001 From: Armelle Laine Date: Tue, 28 Feb 2023 02:44:10 +0000 Subject: [PATCH 007/133] Add metrics to the zuma makefile Bug: 259517277 Test: TBD Change-Id: I4423c4df03a34d68dcec81a1ffc1f00e28fb685b --- device.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/device.mk b/device.mk index 663a92e2..cf26289b 100644 --- a/device.mk +++ b/device.mk @@ -786,11 +786,11 @@ PRODUCT_PACKAGES_DEBUG += trusty-ut-ctrl \ include device/google/gs101/confirmationui/confirmationui.mk # Trusty Metrics Daemon -#PRODUCT_SOONG_NAMESPACES += \ -# vendor/google/trusty/common -# -#PRODUCT_PACKAGES += \ -# trusty_metricsd +PRODUCT_SOONG_NAMESPACES += \ + vendor/google/trusty/common + +PRODUCT_PACKAGES += \ + trusty_metricsd $(call soong_config_set,google_displaycolor,displaycolor_platform,zuma) PRODUCT_PACKAGES += \ From 473839b618c7b5098c0b8fc213470143d6080c80 Mon Sep 17 00:00:00 2001 From: Armelle Laine Date: Tue, 28 Feb 2023 02:47:02 +0000 Subject: [PATCH 008/133] trusty: Add trusty_stats_test Test: /data/nativetest64/vendor/trusty_stats_test/trusty_stats_test Bug: 259517277 Change-Id: I40eba69428df1b577456ab6a79f5ffc634fec9ac --- device.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/device.mk b/device.mk index cf26289b..557afdb1 100644 --- a/device.mk +++ b/device.mk @@ -780,8 +780,10 @@ $(call inherit-product, system/core/trusty/trusty-storage.mk) $(call inherit-product, system/core/trusty/trusty-base.mk) # Trusty unit test tool -PRODUCT_PACKAGES_DEBUG += trusty-ut-ctrl \ - tipc-test +PRODUCT_PACKAGES_DEBUG += \ + trusty-ut-ctrl \ + tipc-test \ + trusty_stats_test \ include device/google/gs101/confirmationui/confirmationui.mk From 286ebed626a73d879fe37f2771a303310d040a43 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Tue, 28 Feb 2023 09:55:08 -0800 Subject: [PATCH 009/133] zuma: conf: set gsa log group to system dumpstate runs as system group, so in order to prepare for it to be readable by dumpstate, we need to change the group to system. Bug: 271125313 Test: ls -l /sys/devices/platform/16490000.gsa-ns/ Change-Id: Ib8f299e99add9cc2f03887cda78f576924c522cd --- conf/init.zuma.rc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 0c56113e..ea43d3e4 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -355,6 +355,10 @@ on init # Big Core: sync more performance is prohibitively bad write /sys/devices/system/cpu/cpu8/mte_tcf_preferred asymm + # Change GSA log group for dumpstate + chown root system /sys/devices/platform/16490000.gsa-ns/log_main + chown root system /sys/devices/platform/16490000.gsa-ns/log_intermediate + on post-fs # Ensure device is ready and start storageproxyd wait /dev/sg1 From 09cb4227bb313274e46b973024ed3820319778e1 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Mon, 27 Feb 2023 14:23:00 -0800 Subject: [PATCH 010/133] dumpstate: add GSA logs to bugreport Add support for reading the GSA logs sysfs file to see the GSA logs in the bugreports we get from dogfooders. Bug: 271125313 Test: adb shell dumpstate Change-Id: I09a2e039451b5eb8b7fa360ba03486bd871fb970 --- dumpstate/Android.bp | 7 +++++++ dumpstate/dump_gsa.sh | 8 ++++++++ dumpstate/item.mk | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 dumpstate/dump_gsa.sh diff --git a/dumpstate/Android.bp b/dumpstate/Android.bp index 6d53152c..7cf17933 100644 --- a/dumpstate/Android.bp +++ b/dumpstate/Android.bp @@ -23,6 +23,13 @@ sh_binary { sub_dir: "dump", } +sh_binary { + name: "dump_gsa.sh", + src: "dump_gsa.sh", + vendor: true, + sub_dir: "dump", +} + cc_binary { name: "android.hardware.dumpstate-service.zuma", srcs: [ diff --git a/dumpstate/dump_gsa.sh b/dumpstate/dump_gsa.sh new file mode 100644 index 00000000..a0d42324 --- /dev/null +++ b/dumpstate/dump_gsa.sh @@ -0,0 +1,8 @@ +#!/vendor/bin/sh + +echo "--- GSA MAIN LOG" +cat /sys/devices/platform/16490000.gsa-ns/log_main + +echo "--- GSA INTERMEDIATE LOG" +cat /sys/devices/platform/16490000.gsa-ns/log_intermediate + diff --git a/dumpstate/item.mk b/dumpstate/item.mk index 00ef3e6d..124fd1c2 100644 --- a/dumpstate/item.mk +++ b/dumpstate/item.mk @@ -1,5 +1,6 @@ PRODUCT_PACKAGES += dump_wlan.sh \ dump_power.sh -PRODUCT_PACKAGES_DEBUG += dump_cma.sh +PRODUCT_PACKAGES_DEBUG += dump_cma.sh \ + dump_gsa.sh From bf70784db13ec1f3e7f2bee8ab9901439ed96e24 Mon Sep 17 00:00:00 2001 From: Shams Pirani Date: Tue, 31 Jan 2023 14:58:54 -0600 Subject: [PATCH 011/133] zuma: Trigger ACPM PI table update on boot Bug: 265042173 Test: Boot device and read PI table from ACPM Change-Id: I0f6a6148254761323ca68717331d6a7b826f7f2f Signed-off-by: Shams Pirani --- conf/init.zuma.rc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 5106e46d..0a057f09 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -531,6 +531,9 @@ on boot chmod 0222 /sys/kernel/debug/tracing/trace_marker write /sys/kernel/debug/tracing/tracing_on 0 + # Trigger TMU to ACPM pi table update + write /sys/module/gs_thermal/parameters/update_acpm_pi_table 1 + # Change permission for A-Box firmware logs file & GPR dump chown audioserver system /sys/devices/platform/17c50000.abox/reset chown audioserver system /sys/devices/platform/17c50000.abox/service From cb40d6cc4a3e3b7cd9292b49b4e547b805e0d581 Mon Sep 17 00:00:00 2001 From: Ziyi Cui Date: Wed, 1 Mar 2023 17:49:56 +0000 Subject: [PATCH 012/133] init: add memlat parameter stall_floor Bug: 232948888 Test: build, flash, gb5 and sjeng test Change-Id: If6d588752daec14853fdf1e515b88ce22355cc60 Signed-off-by: Ziyi Cui --- conf/init.zuma.rc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 836eadee..15da069b 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -308,7 +308,15 @@ on init write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/mem_latency/ratio_ceil 3700 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/mem_latency/ratio_ceil 3700 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/mem_latency/ratio_ceil 3400 - + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/mem_latency/stall_floor 2700 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010/mem_latency/stall_floor 2700 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu2_memlat@17000010/mem_latency/stall_floor 2700 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu3_memlat@17000010/mem_latency/stall_floor 2700 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu4_memlat@17000010/mem_latency/stall_floor 2100 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu5_memlat@17000010/mem_latency/stall_floor 2100 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/mem_latency/stall_floor 2100 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/mem_latency/stall_floor 2100 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/mem_latency/stall_floor 0 # Give pixelstats group access to PCIe link statistics counters chown system system /sys/devices/platform/12100000.pcie/link_stats/complete_timeout_irqs chown system system /sys/devices/platform/12100000.pcie/link_stats/link_down_irqs From 7f475a8f49e5829d0896840061b9e3706d858445 Mon Sep 17 00:00:00 2001 From: Hiroshi Akiyama Date: Sat, 25 Feb 2023 00:54:55 +0000 Subject: [PATCH 013/133] Add logging for BCL IRQ durations to dumpstate Bug: 269752322 Test: adb bugreport Signed-off-by: Hiroshi Akiyama Change-Id: I5a771ddf3f5da5b5c285a1e3217f6b3a62b8a0ff --- dumpstate/dump_power.sh | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/dumpstate/dump_power.sh b/dumpstate/dump_power.sh index bb280859..8c9cdec3 100644 --- a/dumpstate/dump_power.sh +++ b/dumpstate/dump_power.sh @@ -325,3 +325,87 @@ do echo "$a=$val" done +echo "\n------ IRQ Duration Counts ------" +echo "Source\t\t\t\tlt_5ms_cnt\tbt_5ms_to_10ms_cnt\tgt_10ms_cnt\tCode\tCurrent Threshold (uA)\tCurrent Reading (uA)" + +lt=`cat /sys/devices/virtual/pmic/mitigation/irq_dur_cnt/less_than_5ms_count` +bt=`cat /sys/devices/virtual/pmic/mitigation/irq_dur_cnt/between_5ms_to_10ms_count` +gt=`cat /sys/devices/virtual/pmic/mitigation/irq_dur_cnt/greater_than_10ms_count` +lpf_cur_m=`cat /sys/devices/platform/acpm_mfd_bus@15500000/i2c-0/0-001f/s2mpg14-meter/s2mpg14-odpm/iio:device0/lpf_current` +lpf_cur_s=`cat /sys/devices/platform/acpm_mfd_bus@15510000/i2c-1/1-002f/s2mpg15-meter/s2mpg15-odpm/iio:device1/lpf_current` + +lpf_cur_main=(${lpf_cur_m/\\n/;}) +lpf_cur_sub=(${lpf_cur_s/\\n/;}) + +IFS_PRE=$IFS +IFS=$'\n' +lt_a=($lt) +bt_a=($bt) +gt_a=($gt) +IFS=$IFS_PRE + + +for f in `ls /sys/devices/virtual/pmic/mitigation/main_pwrwarn/*` +do + count=`cat $f` + a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/main_pwrwarn\//} + s=${a/main_pwrwarn_threshold/} + arr=(${count//=/ }) + code=${arr[0]} + threshold=${arr[1]} + main_array[$s]="$code\t$threshold" +done + +i=1 +main_current=() +for f in "${main_array[@]}" +do + idx=$i + idx2=$idx+1 + main_current+=(${lpf_cur_main[$idx2]}) + i=$i+2 +done + +for f in `ls /sys/devices/virtual/pmic/mitigation/sub_pwrwarn/*` +do + count=`cat $f` + a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/sub_pwrwarn\//} + s=${a/sub_pwrwarn_threshold/} + arr=(${count//=/ }) + code=${arr[0]}; + threshold=${arr[1]}; + sub_array[$s]="$code\t$threshold" +done +i=1 +sub_current=() +for f in "${sub_array[@]}" +do + idx=$i + idx2=$idx+1 + sub_current+=(${lpf_cur_sub[$idx2]}) + i=$i+2 +done + +rows=${#lt_a[@]} +for i in `seq 0 $rows` +do + n="${lt_a[i]%:*}" + l="${lt_a[i]#*": "}" + b="${bt_a[i]#*": "}" + g="${gt_a[i]#*": "}" + if [ $i -lt 9 ] + then + echo "$n \t\t$l\t\t$b\t\t\t$g" + elif [ $i -ge 9 ] && [ $i -lt 21 ] + then + j=$i-9 + thresh="${main_array[j]}" + current="${main_current[j]}" + echo "$n \t$l\t\t$b\t\t\t$g\t\t$thresh \t\t$current" + else + j=$i-21 + thresh="${sub_array[j]}" + current="${sub_current[j]}" + echo "$n \t$l\t\t$b\t\t\t$g\t\t$thresh \t\t$current" + fi +done From 82efb36664b56864239937d96a3b6e08547b9af9 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 3 Mar 2023 23:01:17 +0000 Subject: [PATCH 014/133] Revert "Temporarily disable KASAN until bugfix is merged into [redacted] kernel." This reverts commit 31743404560f9449979fd500282490c52ed5164e. Reason for revert: Kernel prebuilt with bugfix has landed: ag/21613833 Change-Id: I7c688065783303ca0666f38058fbf853be51e199 --- BoardConfig-common.mk | 3 --- 1 file changed, 3 deletions(-) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index 508d4971..42b24b1a 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -39,9 +39,6 @@ BOARD_KERNEL_CMDLINE += cgroup_disable=memory BOARD_KERNEL_CMDLINE += rcupdate.rcu_expedited=1 rcu_nocbs=all BOARD_KERNEL_CMDLINE += stack_depot_disable=off page_pinner=on BOARD_KERNEL_CMDLINE += swiotlb=1024 -# TODO(pcc): Remove this once the shusky kernel is updated with -# https://android-review.git.corp.google.com/q/topic:%22kasan-mte-sampling-again%22 -BOARD_KERNEL_CMDLINE += kasan=off BOARD_BOOTCONFIG += androidboot.boot_devices=13200000.ufs TARGET_NO_BOOTLOADER := true From 9f8e44550ce41a59240f801c9151bf86c202ee23 Mon Sep 17 00:00:00 2001 From: Kyle Lin Date: Sat, 11 Mar 2023 00:53:56 +0800 Subject: [PATCH 015/133] dsulat: Add dsulat ratio_ceil value Bug: 263261269 Test: build, boot and verify performance/power Change-Id: Iead39fac367ea6884d89e2cb07eed7a50addd924 --- conf/init.zuma.rc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index caaf28ad..700999b5 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -339,6 +339,12 @@ on init write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/mem_latency/stall_floor 2100 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/mem_latency/stall_floor 2100 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/mem_latency/stall_floor 0 + + # Add dsulat governor settings + write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl0 700 + write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl1 1000 + write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl2 3000 + # Give pixelstats group access to PCIe link statistics counters chown system system /sys/devices/platform/12100000.pcie/link_stats/complete_timeout_irqs chown system system /sys/devices/platform/12100000.pcie/link_stats/link_down_irqs From b54a6b227de1c97b012794a1f0aa074660f1ab86 Mon Sep 17 00:00:00 2001 From: Ziyi Cui Date: Thu, 16 Mar 2023 04:33:01 +0000 Subject: [PATCH 016/133] init: fine tune memlat parameter stall_floor Bug: 232948888 Test: build, flash, gb5 and sjeng test Change-Id: I817d52413b62b610d4859e753e4ca9179e04f6a3 Signed-off-by: Ziyi Cui --- conf/init.zuma.rc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 95c0cd9d..03a18f9a 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -330,15 +330,15 @@ on init write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/mem_latency/ratio_ceil 3700 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/mem_latency/ratio_ceil 3700 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/mem_latency/ratio_ceil 3400 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/mem_latency/stall_floor 2700 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010/mem_latency/stall_floor 2700 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu2_memlat@17000010/mem_latency/stall_floor 2700 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu3_memlat@17000010/mem_latency/stall_floor 2700 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu4_memlat@17000010/mem_latency/stall_floor 2100 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu5_memlat@17000010/mem_latency/stall_floor 2100 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/mem_latency/stall_floor 2100 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/mem_latency/stall_floor 2100 - write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/mem_latency/stall_floor 0 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/mem_latency/stall_floor 3000 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010/mem_latency/stall_floor 3000 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu2_memlat@17000010/mem_latency/stall_floor 3000 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu3_memlat@17000010/mem_latency/stall_floor 3000 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu4_memlat@17000010/mem_latency/stall_floor 2400 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu5_memlat@17000010/mem_latency/stall_floor 2400 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/mem_latency/stall_floor 2400 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/mem_latency/stall_floor 2400 + write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/mem_latency/stall_floor 800 # Add dsulat governor settings write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl0 700 From eb06b6db9e36baf2f36a14e23ef3d3c34359b7f8 Mon Sep 17 00:00:00 2001 From: Adam Shih Date: Wed, 22 Mar 2023 11:24:35 +0800 Subject: [PATCH 017/133] Move pixel dumpstate to gs-common Bug: 240530709 Test: adb bugreport Change-Id: I70a1cd1a2a2b78b043f3c7fa8ff47f2fec75e078 --- device.mk | 5 +- dumpstate/Android.bp | 25 -- dumpstate/Dumpstate.cpp | 215 ------------------ dumpstate/Dumpstate.h | 53 ----- ...android.hardware.dumpstate-service.zuma.rc | 5 - ...ndroid.hardware.dumpstate-service.zuma.xml | 9 - dumpstate/service.cpp | 37 --- 7 files changed, 1 insertion(+), 348 deletions(-) delete mode 100644 dumpstate/Dumpstate.cpp delete mode 100644 dumpstate/Dumpstate.h delete mode 100644 dumpstate/android.hardware.dumpstate-service.zuma.rc delete mode 100644 dumpstate/android.hardware.dumpstate-service.zuma.xml delete mode 100644 dumpstate/service.cpp diff --git a/device.mk b/device.mk index ec477ce4..03b76602 100644 --- a/device.mk +++ b/device.mk @@ -32,6 +32,7 @@ include device/google/gs-common/display/dump.mk include device/google/gs-common/gxp/dump.mk include device/google/gs-common/camera/dump.mk include device/google/gs-common/radio/dump.mk +include device/google/gs-common/gear/dumpstate/aidl.mk include device/google/zuma/dumpstate/item.mk @@ -469,10 +470,6 @@ include hardware/google/pixel/rebalance_interrupts/rebalance_interrupts.mk PRODUCT_PACKAGES += \ android.hardware.power.stats-service.pixel -# dumpstate HAL -PRODUCT_PACKAGES += \ - android.hardware.dumpstate-service.zuma - # # Audio HALs # diff --git a/dumpstate/Android.bp b/dumpstate/Android.bp index 7cf17933..ab47899e 100644 --- a/dumpstate/Android.bp +++ b/dumpstate/Android.bp @@ -30,28 +30,3 @@ sh_binary { sub_dir: "dump", } -cc_binary { - name: "android.hardware.dumpstate-service.zuma", - srcs: [ - "Dumpstate.cpp", - "service.cpp", - ], - init_rc: ["android.hardware.dumpstate-service.zuma.rc"], - vintf_fragments: ["android.hardware.dumpstate-service.zuma.xml"], - cflags: [ - "-Wall", - "-Werror", - ], - shared_libs: [ - "libbase", - "libbinder_ndk", - "libcutils", - "libdumpstateutil", - "liblog", - "libutils", - "libdump", - "android.hardware.dumpstate-V1-ndk", - ], - vendor: true, - relative_install_path: "hw", -} diff --git a/dumpstate/Dumpstate.cpp b/dumpstate/Dumpstate.cpp deleted file mode 100644 index 550d95ec..00000000 --- a/dumpstate/Dumpstate.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "dumpstate_device" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include "Dumpstate.h" - -#include "DumpstateUtil.h" - -#define HW_REVISION "ro.boot.hardware.revision" - -using android::os::dumpstate::CommandOptions; -using android::os::dumpstate::DumpFileToFd; -using android::os::dumpstate::PropertiesHelper; -using android::os::dumpstate::RunCommandToFd; - -namespace aidl { -namespace android { -namespace hardware { -namespace dumpstate { - -typedef std::chrono::time_point timepoint_t; - -const char kVerboseLoggingProperty[] = "persist.vendor.verbose_logging_enabled"; - -timepoint_t startSection(int fd, const std::string §ionName) { - ::android::base::WriteStringToFd( - "\n" - "------ Section start: " + sectionName + " ------\n" - "\n", fd); - return std::chrono::steady_clock::now(); -} - -void endSection(int fd, const std::string §ionName, timepoint_t startTime) { - auto endTime = std::chrono::steady_clock::now(); - auto elapsedMsec = std::chrono::duration_cast - (endTime - startTime).count(); - - ::android::base::WriteStringToFd( - "\n" - "------ Section end: " + sectionName + " ------\n" - "Elapsed msec: " + std::to_string(elapsedMsec) + "\n" - "\n", fd); -} - -// Dump data requested by an argument to the "dump" interface, or help info -// if the specified section is not supported. -void Dumpstate::dumpTextSection(int fd, const std::string §ionName) { - bool dumpAll = (sectionName == kAllSections); - std::string dumpFiles; - - // Execute all or designated programs under vendor/bin/dump/ - std::unique_ptr dir(opendir("/vendor/bin/dump"), closedir); - if (!dir) { - ALOGE("Fail To Open Dir vendor/bin/dump/"); - ::android::base::WriteStringToFd("Fail To Open Dir vendor/bin/dump/\n", fd); - return; - } - dirent *entry; - while ((entry = readdir(dir.get())) != nullptr) { - // Skip '.', '..' - if (entry->d_name[0] == '.') { - continue; - } - std::string bin(entry->d_name); - dumpFiles = dumpFiles + " " + bin; - if (dumpAll || sectionName == bin) { - auto startTime = startSection(fd, bin); - RunCommandToFd(fd, "/vendor/bin/dump/"+bin, {"/vendor/bin/dump/"+bin}, CommandOptions::WithTimeout(15).Build()); - endSection(fd, bin, startTime); - if (!dumpAll) { - return; - } - } - } - - if (dumpAll) { - RunCommandToFd(fd, "VENDOR PROPERTIES", {"/vendor/bin/getprop"}); - return; - } - - // An unsupported section was requested on the command line - ::android::base::WriteStringToFd("Unrecognized text section: " + sectionName + "\n", fd); - ::android::base::WriteStringToFd("Try \"" + kAllSections + "\" or one of the following:", fd); - ::android::base::WriteStringToFd(dumpFiles, fd); - ::android::base::WriteStringToFd("\nNote: sections with attachments (e.g. dump_soc) are" - "not avalable from the command line.\n", fd); -} - -void Dumpstate::dumpLogSection(int fd, int fd_bin) -{ - std::string logDir = MODEM_LOG_DIRECTORY; - const std::string logCombined = logDir + "/combined_logs.tar"; - const std::string logAllDir = logDir + "/all_logs"; - - RunCommandToFd(fd, "MKDIR LOG", {"/vendor/bin/mkdir", "-p", logAllDir.c_str()}, CommandOptions::WithTimeout(2).Build()); - - dumpTextSection(fd, kAllSections); - - RunCommandToFd(fd, "TAR LOG", {"/vendor/bin/tar", "cvf", logCombined.c_str(), "-C", logAllDir.c_str(), "."}, CommandOptions::WithTimeout(20).Build()); - RunCommandToFd(fd, "CHG PERM", {"/vendor/bin/chmod", "a+w", logCombined.c_str()}, CommandOptions::WithTimeout(2).Build()); - - std::vector buffer(65536); - ::android::base::unique_fd fdLog(TEMP_FAILURE_RETRY(open(logCombined.c_str(), O_RDONLY | O_CLOEXEC | O_NONBLOCK))); - - if (fdLog >= 0) { - while (1) { - ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fdLog, buffer.data(), buffer.size())); - - if (bytes_read == 0) { - break; - } else if (bytes_read < 0) { - ALOGD("read(%s): %s\n", logCombined.c_str(), strerror(errno)); - break; - } - - ssize_t result = TEMP_FAILURE_RETRY(write(fd_bin, buffer.data(), bytes_read)); - - if (result != bytes_read) { - ALOGD("Failed to write %ld bytes, actually written: %ld", bytes_read, result); - break; - } - } - } - - RunCommandToFd(fd, "RM LOG DIR", { "/vendor/bin/rm", "-r", logAllDir.c_str()}, CommandOptions::WithTimeout(2).Build()); - RunCommandToFd(fd, "RM LOG", { "/vendor/bin/rm", logCombined.c_str()}, CommandOptions::WithTimeout(2).Build()); -} - -ndk::ScopedAStatus Dumpstate::dumpstateBoard(const std::vector<::ndk::ScopedFileDescriptor>& in_fds, - IDumpstateDevice::DumpstateMode in_mode, - int64_t in_timeoutMillis) { - // Unused arguments. - (void) in_timeoutMillis; - (void) in_mode; - - if (in_fds.size() < 1) { - ALOGE("no FDs\n"); - return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT, - "No file descriptor"); - } - - int fd = in_fds[0].get(); - if (fd < 0) { - ALOGE("invalid FD: %d\n", fd); - return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT, - "Invalid file descriptor"); - } - - if (in_fds.size() < 2) { - ALOGE("no FD for dumpstate_board binary\n"); - } else { - int fd_bin = in_fds[1].get(); - dumpLogSection(fd, fd_bin); - } - - return ndk::ScopedAStatus::ok(); -} - -ndk::ScopedAStatus Dumpstate::setVerboseLoggingEnabled(bool in_enable) { - ::android::base::SetProperty(kVerboseLoggingProperty, in_enable ? "true" : "false"); - return ndk::ScopedAStatus::ok(); -} - -ndk::ScopedAStatus Dumpstate::getVerboseLoggingEnabled(bool* _aidl_return) { - *_aidl_return = ::android::base::GetBoolProperty(kVerboseLoggingProperty, false); - return ndk::ScopedAStatus::ok(); -} - -// Since AIDLs that support the dump() interface are automatically invoked during -// bugreport generation and we don't want to generate a second copy of the same -// data that will go into dumpstate_board.txt, this function will only do -// something if it is called with an option, e.g. -// dumpsys android.hardware.dumpstate.IDumpstateDevice/default all -// -// Also, note that sections which generate attachments and/or binary data when -// included in a bugreport are not available through the dump() interface. -binder_status_t Dumpstate::dump(int fd, const char** args, uint32_t numArgs) { - - if (numArgs != 1) { - return STATUS_OK; - } - - dumpTextSection(fd, static_cast(args[0])); - - fsync(fd); - return STATUS_OK; -} - -} // namespace dumpstate -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/dumpstate/Dumpstate.h b/dumpstate/Dumpstate.h deleted file mode 100644 index 787b7747..00000000 --- a/dumpstate/Dumpstate.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace aidl { -namespace android { -namespace hardware { -namespace dumpstate { - -class Dumpstate : public BnDumpstateDevice { - public: - ::ndk::ScopedAStatus dumpstateBoard(const std::vector<::ndk::ScopedFileDescriptor>& in_fds, - IDumpstateDevice::DumpstateMode in_mode, - int64_t in_timeoutMillis) override; - - ::ndk::ScopedAStatus getVerboseLoggingEnabled(bool* _aidl_return) override; - - ::ndk::ScopedAStatus setVerboseLoggingEnabled(bool in_enable) override; - - binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; - - private: - const std::string kAllSections = "all"; - - void dumpTextSection(int fd, std::string const& sectionName); - void dumpLogSection(int fd, int fdModem); - - //bool getVerboseLoggingEnabledImpl(); - //::ndk::ScopedAStatus dumpstateBoardImpl(const int fd, const bool full); -}; - -} // namespace dumpstate -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/dumpstate/android.hardware.dumpstate-service.zuma.rc b/dumpstate/android.hardware.dumpstate-service.zuma.rc deleted file mode 100644 index e73602bb..00000000 --- a/dumpstate/android.hardware.dumpstate-service.zuma.rc +++ /dev/null @@ -1,5 +0,0 @@ -service vendor.dumpstate-default /vendor/bin/hw/android.hardware.dumpstate-service.zuma - class hal - user system - group system shell - interface aidl android.hardware.dumpstate.IDumpstateDevice/default diff --git a/dumpstate/android.hardware.dumpstate-service.zuma.xml b/dumpstate/android.hardware.dumpstate-service.zuma.xml deleted file mode 100644 index 5e51b287..00000000 --- a/dumpstate/android.hardware.dumpstate-service.zuma.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - android.hardware.dumpstate - - IDumpstateDevice - default - - - diff --git a/dumpstate/service.cpp b/dumpstate/service.cpp deleted file mode 100644 index 1953fd67..00000000 --- a/dumpstate/service.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define LOG_TAG "android.hardware.dumpstate-service.zuma" - -#include "Dumpstate.h" - -#include -#include -#include - -using aidl::android::hardware::dumpstate::Dumpstate; - -int main() { - ABinderProcess_setThreadPoolMaxThreadCount(0); - std::shared_ptr dumpstate = ndk::SharedRefBase::make(); - - const std::string instance = std::string() + Dumpstate::descriptor + "/default"; - binder_status_t status = - AServiceManager_addService(dumpstate->asBinder().get(), instance.c_str()); - CHECK_EQ(status, STATUS_OK); - - ABinderProcess_joinThreadPool(); - return EXIT_FAILURE; // Unreachable -} From c438c66fe03679b4791002d46afd83c2dca429b8 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 15 Mar 2023 12:49:48 +0000 Subject: [PATCH 018/133] Fix mali memory protection sysprop names The previous patch did not use the `base_*` prefix, meaning the driver kept using the default configuration. Bug: b/272740524 Test: CtsDeqpTestCases (dEQP-VK.protected_memory.stack.stacksize_*) Change-Id: I87f3e4ce5734ca213c399969f7f4ddec9e62a707 --- device.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/device.mk b/device.mk index 105e12b7..6e2113c9 100644 --- a/device.mk +++ b/device.mk @@ -250,8 +250,8 @@ endif # Mali Configuration Properties # b/221255664 prevents setting PROTECTED_MAX_CORE_COUNT=2 PRODUCT_VENDOR_PROPERTIES += \ - vendor.mali.protected_max_core_count=1 \ - vendor.mali.protected_tls_max=67108864 \ + vendor.mali.base_protected_max_core_count=1 \ + vendor.mali.base_protected_tls_max=67108864 \ vendor.mali.platform_agt_frequency_khz=24576 PRODUCT_COPY_FILES += \ From f199fdd8e125076f381c07993d130e2f35d57981 Mon Sep 17 00:00:00 2001 From: Erik Staats Date: Wed, 29 Mar 2023 14:04:44 +0000 Subject: [PATCH 019/133] zuma: Add UmfwStat Bug: 272323547 Test: Verified UmfwStat tables are dumped in bug report. Change-Id: I2372dcd5c698b711d1bb5b95b1d43beb22192c7d --- conf/ueventd.zuma.rc | 3 +++ device.mk | 1 + 2 files changed, 4 insertions(+) diff --git a/conf/ueventd.zuma.rc b/conf/ueventd.zuma.rc index 80ee743b..ac58f04d 100644 --- a/conf/ueventd.zuma.rc +++ b/conf/ueventd.zuma.rc @@ -143,6 +143,9 @@ # AoC /dev/aoc 0660 system system +# AoC stats (UmfwStat) +/dev/acd-com.google.umfw_stat 0660 system system + # Sensors (USF) /dev/acd-com.google.usf 0660 system system /dev/acd-com.google.usf.non_wake_up 0660 system system diff --git a/device.mk b/device.mk index 105e12b7..3faeef48 100644 --- a/device.mk +++ b/device.mk @@ -33,6 +33,7 @@ include device/google/gs-common/gxp/dump.mk include device/google/gs-common/camera/dump.mk include device/google/gs-common/radio/dump.mk include device/google/gs-common/gear/dumpstate/aidl.mk +include device/google/gs-common/umfw_stat/umfw_stat.mk include device/google/zuma/dumpstate/item.mk From 7038bae086b572038ddb3d7b203b34b9519dd0fe Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 6 Apr 2023 15:18:28 +0000 Subject: [PATCH 020/133] Define mali configuration path explicitly This avoids mali trying to read `/data/data/com.mali.testjava` for its debug config. Bug: b/205779871 Test: manual - reboot device and check the absence of AVC denials Change-Id: I42051ae2c10c6d4fa7c1f9d5f485ff5471e6a287 --- device.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/device.mk b/device.mk index bd48e483..5f4edc3c 100644 --- a/device.mk +++ b/device.mk @@ -251,6 +251,8 @@ endif # Mali Configuration Properties # b/221255664 prevents setting PROTECTED_MAX_CORE_COUNT=2 PRODUCT_VENDOR_PROPERTIES += \ + vendor.mali.platform.config=/vendor/etc/mali/platform.config \ + vendor.mali.debug.config=/vendor/etc/mali/debug.config \ vendor.mali.base_protected_max_core_count=1 \ vendor.mali.base_protected_tls_max=67108864 \ vendor.mali.platform_agt_frequency_khz=24576 From 4a226e1cab8367310ee084488f7f02995a88cad6 Mon Sep 17 00:00:00 2001 From: Evgenii Stepanov Date: Fri, 7 Apr 2023 12:55:38 -0700 Subject: [PATCH 021/133] Revert "[Zuma] set mte_tcf_preferred to sync for little and mid cores" This change interferes with perf measurement. This reverts commit 0a55c41d1579c8bee16f59c739efc02b16dbe317. Bug: 239832365 Test: adb shell 'cat /sys/devices/system/cpu/cpu?/mte_tcf_preferred' should return all "async" Change-Id: I38d9c4271135f438ebb54191442159de21123f88 --- conf/init.zuma.rc | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 09c7dee4..6d5dc42f 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -360,20 +360,6 @@ on init chown system system /sys/devices/platform/13120000.pcie/link_stats/link_recovery_failures chown system system /sys/devices/platform/13120000.pcie/link_stats/link_up_failures - # Write MTE config - # Little Cores: - write /sys/devices/system/cpu/cpu0/mte_tcf_preferred sync - write /sys/devices/system/cpu/cpu1/mte_tcf_preferred sync - write /sys/devices/system/cpu/cpu2/mte_tcf_preferred sync - write /sys/devices/system/cpu/cpu3/mte_tcf_preferred sync - # Mid Cores: - write /sys/devices/system/cpu/cpu4/mte_tcf_preferred sync - write /sys/devices/system/cpu/cpu5/mte_tcf_preferred sync - write /sys/devices/system/cpu/cpu6/mte_tcf_preferred sync - write /sys/devices/system/cpu/cpu7/mte_tcf_preferred sync - # Big Core: sync more performance is prohibitively bad - write /sys/devices/system/cpu/cpu8/mte_tcf_preferred asymm - # Change GSA log group for dumpstate chown root system /sys/devices/platform/16490000.gsa-ns/log_main chown root system /sys/devices/platform/16490000.gsa-ns/log_intermediate From 4491b9d16212faed158dbafe7de91a2429847fd0 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Tue, 11 Apr 2023 22:20:58 +0000 Subject: [PATCH 022/133] remove dump_cma from zuma We will introduce it into gs-common Bug: 276901078 Change-Id: I4664af3502a4ba61605ba2a0f306775b308da595 Signed-off-by: Minchan Kim --- dumpstate/Android.bp | 7 ------- dumpstate/dump_cma.sh | 9 --------- dumpstate/item.mk | 4 +--- 3 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 dumpstate/dump_cma.sh diff --git a/dumpstate/Android.bp b/dumpstate/Android.bp index ab47899e..a7c373e8 100644 --- a/dumpstate/Android.bp +++ b/dumpstate/Android.bp @@ -16,13 +16,6 @@ sh_binary { sub_dir: "dump", } -sh_binary { - name: "dump_cma.sh", - src: "dump_cma.sh", - vendor: true, - sub_dir: "dump", -} - sh_binary { name: "dump_gsa.sh", src: "dump_gsa.sh", diff --git a/dumpstate/dump_cma.sh b/dumpstate/dump_cma.sh deleted file mode 100644 index 63e497e7..00000000 --- a/dumpstate/dump_cma.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/vendor/bin/sh -echo "------ CMA info ------" -for d in $(ls -d /d/cma/*); do - echo --- $d - echo --- count; cat $d/count - echo --- used; cat $d/used - echo --- bitmap; cat $d/bitmap -done - diff --git a/dumpstate/item.mk b/dumpstate/item.mk index 124fd1c2..0edb7f29 100644 --- a/dumpstate/item.mk +++ b/dumpstate/item.mk @@ -1,6 +1,4 @@ PRODUCT_PACKAGES += dump_wlan.sh \ dump_power.sh -PRODUCT_PACKAGES_DEBUG += dump_cma.sh \ - dump_gsa.sh - +PRODUCT_PACKAGES_DEBUG += dump_gsa.sh From 0493c3a35bc69efae46e2dc4ada7c3db53733d4a Mon Sep 17 00:00:00 2001 From: Mahesh Sivasubramanian Date: Sat, 15 Apr 2023 00:30:17 +0000 Subject: [PATCH 023/133] Revert "zuma: Enable SICD after boot" This reverts commit 5cb0ef1f4adfed53b03ff6254a85292d8dee9437. Reason for revert: http://b/270965383 Bug: 278308279 Bug: 270965383 Change-Id: I9bf853c11cb5335306c701d9fd19b4ae72517985 --- conf/init.zuma.rc | 3 --- 1 file changed, 3 deletions(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 02bee631..26909c0f 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -767,9 +767,6 @@ on property:sys.boot_completed=1 # Disable GPU firmware logging write /sys/devices/platform/1f000000.mali/firmware_config/Log\ verbosity/cur 0 -#Enable SICD - write /sys/devices/system/cpu/cpupm/cpupm/sicd 1 - # IMS WiFi Calling service charonservice /system/vendor/bin/charon class main From d6051c9a9126bcf29daadf7764dd0390f63f7617 Mon Sep 17 00:00:00 2001 From: Martin Liu Date: Fri, 14 Apr 2023 01:04:27 +0800 Subject: [PATCH 024/133] adjust watermark level Increase watermark_scale_factor to 200 to better handle burst memory allocation. Bug: 278075546 Test: boot Change-Id: Iaa6fb0f45924b3d73ebd76ae8554b58047f4755a Signed-off-by: Martin Liu --- conf/init.zuma.rc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 91e89c61..63061a0a 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -115,6 +115,9 @@ on init write /sys/block/zram0/comp_algorithm lz77eh write /proc/sys/vm/page-cluster 0 + # Adjust watermark level + write /proc/sys/vm/watermark_scale_factor 200 + # Some user code relies on ro.boot.hardware.revision setprop ro.boot.hardware.revision ${ro.revision} From 68738d356fe1630260129bb854e4b32305e60b7b Mon Sep 17 00:00:00 2001 From: Prasanna Prapancham Date: Thu, 20 Apr 2023 17:36:49 +0000 Subject: [PATCH 025/133] dumpstate: add ln8411 logbuffer into bugreport Test: flash local build and collect bugreport Bug: 277799048 Change-Id: I4847e5e4da50bba6da94ad379e5c4dd5542cb6f6 Signed-off-by: Prasanna Prapancham --- conf/init.zuma.rc | 1 + dumpstate/dump_power.sh | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index d84594e8..4df672b2 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -529,6 +529,7 @@ on early-boot chown system system /dev/logbuffer_pca9468 chown system system /dev/logbuffer_cpm chown system system /dev/logbuffer_wc68 + chown system system /dev/logbuffer_ln8411 chown system system /dev/logbuffer_pcie0 chown system system /dev/logbuffer_pcie1 chown system system /dev/logbuffer_bd diff --git a/dumpstate/dump_power.sh b/dumpstate/dump_power.sh index 8c9cdec3..3fb715e1 100644 --- a/dumpstate/dump_power.sh +++ b/dumpstate/dump_power.sh @@ -120,6 +120,12 @@ then cat "/dev/logbuffer_wc68" fi +if [ -e "/dev/logbuffer_ln8411" ] +then + echo "\n------ LN8411 ------" + cat "/dev/logbuffer_ln8411" +fi + echo "\n------ Battery Health ------" cat "/sys/class/power_supply/battery/health_index_stats" echo "\n------ BMS ------" From 471630b25b1c9c7786c6af0c8c4c961f003b8d49 Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Fri, 21 Apr 2023 17:39:28 +0000 Subject: [PATCH 026/133] Move Widevine drm to gs-common Bug: 277764729 Change-Id: Ibab8fdac0be251ef53d84d2c5cf90f57b9b64235 --- device.mk | 1 + widevine/device.mk | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/device.mk b/device.mk index 5630b047..8f17bb5f 100644 --- a/device.mk +++ b/device.mk @@ -34,6 +34,7 @@ include device/google/gs-common/camera/dump.mk include device/google/gs-common/radio/dump.mk include device/google/gs-common/gear/dumpstate/aidl.mk include device/google/gs-common/umfw_stat/umfw_stat.mk +include device/google/gs-common/widevine/widevine.mk include device/google/zuma/dumpstate/item.mk diff --git a/widevine/device.mk b/widevine/device.mk index f91de716..90181bc2 100644 --- a/widevine/device.mk +++ b/widevine/device.mk @@ -1,6 +1 @@ -PRODUCT_PACKAGES += \ - android.hardware.drm-service.clearkey - --include vendor/widevine/libwvdrmengine/apex/device/device.mk - BOARD_VENDOR_SEPOLICY_DIRS += device/google/zuma-sepolicy/widevine From 14f08b2e49ecc4b476d7f3a0b8e0150923fc3139 Mon Sep 17 00:00:00 2001 From: Kevin DuBois Date: Mon, 24 Apr 2023 23:25:47 +0000 Subject: [PATCH 027/133] device.mk: add gpu_probe service. Adds a service that uploads gpu counter data to Perfetto. Service must be started via "start gpu_probe" and the Perfetto config must request counters via "gpu.counters". Bug: 26766418 Test: see perfetto events produced with this service. Change-Id: I40c3152138bd3eb8252741e187586379ce659ac6 --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index 5630b047..28a50c48 100644 --- a/device.mk +++ b/device.mk @@ -226,6 +226,7 @@ $(call soong_config_set,arm_gralloc,soc,$(TARGET_BOARD_PLATFORM)) include device/google/gs101/neuralnetwork/neuralnetwork.mk +include device/google/gs-common/gpu/gpu.mk PRODUCT_PACKAGES += \ csffw_image_prebuilt__firmware_prebuilt_ttux_mali_csffw.bin \ libGLES_mali \ From a11517ec4870c592c1a6110eb22f84a7bd50e0a7 Mon Sep 17 00:00:00 2001 From: Renato Grottesi Date: Thu, 11 May 2023 10:53:32 +0000 Subject: [PATCH 028/133] Update ArmNN variable name Bug: 278832962 Test: local testing Change-Id: I8dfdc5e4d8640d13547ede926c24aff524f856a0 --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index a82cdfbb..e242143a 100644 --- a/device.mk +++ b/device.mk @@ -970,7 +970,7 @@ PRODUCT_COPY_FILES += \ endif # ARM NN files -ARM_COMPUTE_CL_ENABLE := 1 +ARMNN_COMPUTE_CL_ENABLE := 1 # Vibrator Diag PRODUCT_PACKAGES_DEBUG += \ From df869148bd3e3fe89b10f3dbd25252686f54d14f Mon Sep 17 00:00:00 2001 From: chenkris Date: Mon, 15 May 2023 10:30:03 +0000 Subject: [PATCH 029/133] Remove unused udfps make files Bug: 270657514 Test: make Change-Id: Id1e1c622f440d7076bda7e6833395ba4fdfbf991 --- fingerprint/udfps.mk | 28 ---------------------------- fingerprint/udfps_factory.mk | 22 ---------------------- 2 files changed, 50 deletions(-) delete mode 100644 fingerprint/udfps.mk delete mode 100644 fingerprint/udfps_factory.mk diff --git a/fingerprint/udfps.mk b/fingerprint/udfps.mk deleted file mode 100644 index 61f138f6..00000000 --- a/fingerprint/udfps.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -# Copyright (C) 2020 The Android Open-Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -PRODUCT_COPY_FILES += \ - frameworks/native/data/etc/android.hardware.fingerprint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.fingerprint.xml - -# Include the Goodix AIDL HAL namespaces. -PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/g6_trusty -PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/g6_aidl_trusty - -$(call soong_config_set,fp_hal_feature,biometric_suez_support,true) - -PRODUCT_PACKAGES += \ - android.hardware.biometrics.fingerprint@2.1-service.goodix \ - android.hardware.biometrics.fingerprint-service.goodix diff --git a/fingerprint/udfps_factory.mk b/fingerprint/udfps_factory.mk deleted file mode 100644 index 41aebe08..00000000 --- a/fingerprint/udfps_factory.mk +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright (C) 2020 The Android Open-Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -PRODUCT_PACKAGES += \ - GF_delmar_factory \ - udfps_test - -PRODUCT_PROPERTY_OVERRIDES += \ - gf.debug.dump_data=1 From 91c386c10df3bda4a47f4cdfa083eda2d27ff960 Mon Sep 17 00:00:00 2001 From: Sophia Wang Date: Fri, 12 May 2023 15:42:21 -0700 Subject: [PATCH 030/133] Zuma:conf Add dsulat CPU idle awareness settings Test: cat /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/dsulat_cpuidle_state_aware Bug: 282103584 Change-Id: I78f0c2b69c93e482271241c2c801c0cf74018b76 Signed-off-by: Sophia Wang --- conf/init.zuma.rc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index eed8c673..56437c10 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -355,6 +355,11 @@ on init write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl1 1000 write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl2 3000 + # Add dsulat governor settings + write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/dsulat_cpuidle_state_aware_cl0 2 + write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/dsulat_cpuidle_state_aware_cl1 2 + write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/dsulat_cpuidle_state_aware_cl2 2 + # Give pixelstats group access to PCIe link statistics counters chown system system /sys/devices/platform/12100000.pcie/link_stats/complete_timeout_irqs chown system system /sys/devices/platform/12100000.pcie/link_stats/link_down_irqs From 8659f78485ac520c6eff8b1d826b99105c0a96f0 Mon Sep 17 00:00:00 2001 From: Sophia Wang Date: Tue, 16 May 2023 10:26:13 -0700 Subject: [PATCH 031/133] Zuma:conf Remove dup dsulat ratio_ceil settings Test: cat /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl2 Bug: 282767540 Change-Id: I1479cb2d56a02c9b185f79a7fb3d91c2c56291cb Signed-off-by: Sophia Wang --- conf/init.zuma.rc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 70409c0c..610d6c98 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -350,11 +350,6 @@ on init write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl1 1000 write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl2 3000 - # Add dsulat governor settings - write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl0 700 - write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl1 1000 - write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/ratio_ceil_cl2 3000 - # Add dsulat governor settings write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/dsulat_cpuidle_state_aware_cl0 2 write /sys/class/devfreq/gs_dsulat_devfreq:devfreq_dsu_lat@17000090/dsu_latency/dsulat_cpuidle_state_aware_cl1 2 From 9fe5e6004a63bfaeeb7b78744817eade6ec49c15 Mon Sep 17 00:00:00 2001 From: Mahesh Sivasubramanian Date: Thu, 20 Apr 2023 22:29:20 +0000 Subject: [PATCH 032/133] Revert "Revert "zuma: Enable SICD after boot"" This reverts commit ac3b5c0cf55f890b938600d4ef247f5ffefc5e5c. Reason for revert: Issue addressed by disabling write evicts during core wakeup Bug: 278308279 Change-Id: Ib5c979483a9e28074345443158860f12f6e7ace2 (cherry picked from commit 785167e0d3e5fa6027ae731f92d05b096e95d050) --- conf/init.zuma.rc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 70409c0c..b9fb9188 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -865,6 +865,9 @@ on property:sys.boot_completed=1 # Disable GPU firmware logging write /sys/devices/platform/1f000000.mali/firmware_config/Log\ verbosity/cur 0 + # Enable SICD + write /sys/devices/system/cpu/cpupm/cpupm/sicd 1 + on property:sys.boot_completed=1 && property:persist.sys.device_provisioned=1 && property:ro.boot.flash.locked=1 write /sys/class/power_supply/battery/first_usage_date 0 From af01193f268c108fd61f7f0ecd336de10df3dae0 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Mon, 19 Jun 2023 15:24:26 +0900 Subject: [PATCH 033/133] Mark com.google.face.debug as updatable-via-apex com.google.face.debug interface is provided by the new Faceauth APEX (com.google.android.hardware.biometrics.face). This doesn't mean it's truly updatable individually, but means that the interface implementation can be provided from an APEX even if it's not updatable. Bug: 285442265 Test: atest face_hal_p23_..._trusty_test Change-Id: I712545ccdb82669bbb9756dc56c69193c5abeda0 --- device_framework_matrix_product.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index 0113dbd2..67037c27 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -88,7 +88,7 @@ default - + com.google.face.debug 2 From 31eb0647fe1cae47e1de13dbe9c2e1ca84fb7014 Mon Sep 17 00:00:00 2001 From: Dinesh Yadav Date: Mon, 10 Jul 2023 05:41:49 +0000 Subject: [PATCH 034/133] [Cleanup] Move gxp sepolicies to gs-common for P23 Due to cleanup /gs-common/gxp/dump.mk has been changed to /gs-common/gxp/gxp.mk Bug: 288368306 Change-Id: If56b7188578d7dc0be22faadbebf2133cc4224dc Signed-off-by: Dinesh Yadav --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 84ebafe8..529390af 100644 --- a/device.mk +++ b/device.mk @@ -30,7 +30,7 @@ include device/google/gs-common/soc/freq.mk include device/google/gs-common/gps/dump/log.mk include device/google/gs-common/bcmbt/dump/dumplog.mk include device/google/gs-common/display/dump.mk -include device/google/gs-common/gxp/dump.mk +include device/google/gs-common/gxp/gxp.mk include device/google/gs-common/camera/dump.mk include device/google/gs-common/radio/dump.mk include device/google/gs-common/gear/dumpstate/aidl.mk From 27a7859bb14cca0d71e542848030191f3965f673 Mon Sep 17 00:00:00 2001 From: Renato Grottesi Date: Fri, 23 Jun 2023 13:30:53 +0000 Subject: [PATCH 035/133] Remove settings for old ArmNN HIDL backend Compile ArmNN shim over the support library. Remove settings for the old HIDL backend. The new ones will be in the gs-common folder. Test: Local run of CtsNNAPITestCases Test: Local run of VtsHalNeuralnetworksTargetTest Test: Local run of MLTS Benchmark Bug: 283724775 Change-Id: Ifebef89585539e285fc1b8e827a17896b1cba438 --- BoardConfig-common.mk | 10 ---------- device.mk | 5 ----- 2 files changed, 15 deletions(-) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index 2ddc193e..55befa84 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -358,16 +358,6 @@ BOARD_VNDK_VERSION := current # H/W align restriction of MM IPs BOARD_EXYNOS_S10B_FORMAT_ALIGN := 64 -# NeuralNetworks -GPU_SOURCE_PRESENT := $(wildcard vendor/arm/mali/valhall) -GPU_PREBUILD_PRESENT := $(wildcard vendor/google_devices/zuma/prebuilts/gpu) -ifneq (,$(strip $(GPU_SOURCE_PRESENT) $(GPU_PREBUILD_PRESENT))) -ARMNN_COMPUTE_CL_ENABLE := 1 -else -ARMNN_COMPUTE_CL_ENABLE := 0 -endif -ARMNN_COMPUTE_NEON_ENABLE := 1 - # Boot.img BOARD_RAMDISK_USE_LZ4 := true #BOARD_KERNEL_BASE := 0x80000000 diff --git a/device.mk b/device.mk index 84ebafe8..b07e8a3d 100644 --- a/device.mk +++ b/device.mk @@ -244,8 +244,6 @@ PRODUCT_SOONG_NAMESPACES += \ $(call soong_config_set,pixel_mali,soc,$(TARGET_BOARD_PLATFORM)) $(call soong_config_set,arm_gralloc,soc,$(TARGET_BOARD_PLATFORM)) -include device/google/gs101/neuralnetwork/neuralnetwork.mk - include device/google/gs-common/gpu/gpu.mk PRODUCT_PACKAGES += \ csffw_image_prebuilt__firmware_prebuilt_ttux_mali_csffw.bin \ @@ -986,9 +984,6 @@ PRODUCT_PACKAGES += \ endif -# ARM NN files -ARMNN_COMPUTE_CL_ENABLE := 1 - # Vibrator Diag PRODUCT_PACKAGES_DEBUG += \ diag-vibrator \ From f41cbb6820177c8f389dd6fef4b2f17b9a23c3bd Mon Sep 17 00:00:00 2001 From: Android Culprit Assistant Date: Wed, 12 Jul 2023 20:43:46 +0000 Subject: [PATCH 036/133] Revert "Remove settings for old ArmNN HIDL backend" This revert was created by Android Culprit Assistant. The culprit was identified in the following culprit search session (http://go/aca-get/123b2665-83ef-4fd0-904d-a0d8c5782db9). Change-Id: I81b40e12be7178abaa7991dfecd2f7dbb5ebd48e --- BoardConfig-common.mk | 10 ++++++++++ device.mk | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index 55befa84..2ddc193e 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -358,6 +358,16 @@ BOARD_VNDK_VERSION := current # H/W align restriction of MM IPs BOARD_EXYNOS_S10B_FORMAT_ALIGN := 64 +# NeuralNetworks +GPU_SOURCE_PRESENT := $(wildcard vendor/arm/mali/valhall) +GPU_PREBUILD_PRESENT := $(wildcard vendor/google_devices/zuma/prebuilts/gpu) +ifneq (,$(strip $(GPU_SOURCE_PRESENT) $(GPU_PREBUILD_PRESENT))) +ARMNN_COMPUTE_CL_ENABLE := 1 +else +ARMNN_COMPUTE_CL_ENABLE := 0 +endif +ARMNN_COMPUTE_NEON_ENABLE := 1 + # Boot.img BOARD_RAMDISK_USE_LZ4 := true #BOARD_KERNEL_BASE := 0x80000000 diff --git a/device.mk b/device.mk index b07e8a3d..84ebafe8 100644 --- a/device.mk +++ b/device.mk @@ -244,6 +244,8 @@ PRODUCT_SOONG_NAMESPACES += \ $(call soong_config_set,pixel_mali,soc,$(TARGET_BOARD_PLATFORM)) $(call soong_config_set,arm_gralloc,soc,$(TARGET_BOARD_PLATFORM)) +include device/google/gs101/neuralnetwork/neuralnetwork.mk + include device/google/gs-common/gpu/gpu.mk PRODUCT_PACKAGES += \ csffw_image_prebuilt__firmware_prebuilt_ttux_mali_csffw.bin \ @@ -984,6 +986,9 @@ PRODUCT_PACKAGES += \ endif +# ARM NN files +ARMNN_COMPUTE_CL_ENABLE := 1 + # Vibrator Diag PRODUCT_PACKAGES_DEBUG += \ diag-vibrator \ From 2697e86201128731e756f570c95b6afceacdb705 Mon Sep 17 00:00:00 2001 From: Renato Grottesi Date: Thu, 13 Jul 2023 08:40:59 +0000 Subject: [PATCH 037/133] Revert^2 "Remove settings for old ArmNN HIDL backend" f41cbb6820177c8f389dd6fef4b2f17b9a23c3bd Compile ArmNN shim over the support library. Remove settings for the old HIDL backend. The new ones will be in the gs-common folder. Test: Local run of CtsNNAPITestCases Test: Local run of VtsHalNeuralnetworksTargetTest Test: Local run of MLTS Benchmark Bug: 283724775 Change-Id: I57f807934ca219460a4e589b899f933115718a70 --- BoardConfig-common.mk | 10 ---------- device.mk | 5 ----- 2 files changed, 15 deletions(-) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index 2ddc193e..55befa84 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -358,16 +358,6 @@ BOARD_VNDK_VERSION := current # H/W align restriction of MM IPs BOARD_EXYNOS_S10B_FORMAT_ALIGN := 64 -# NeuralNetworks -GPU_SOURCE_PRESENT := $(wildcard vendor/arm/mali/valhall) -GPU_PREBUILD_PRESENT := $(wildcard vendor/google_devices/zuma/prebuilts/gpu) -ifneq (,$(strip $(GPU_SOURCE_PRESENT) $(GPU_PREBUILD_PRESENT))) -ARMNN_COMPUTE_CL_ENABLE := 1 -else -ARMNN_COMPUTE_CL_ENABLE := 0 -endif -ARMNN_COMPUTE_NEON_ENABLE := 1 - # Boot.img BOARD_RAMDISK_USE_LZ4 := true #BOARD_KERNEL_BASE := 0x80000000 diff --git a/device.mk b/device.mk index 84ebafe8..b07e8a3d 100644 --- a/device.mk +++ b/device.mk @@ -244,8 +244,6 @@ PRODUCT_SOONG_NAMESPACES += \ $(call soong_config_set,pixel_mali,soc,$(TARGET_BOARD_PLATFORM)) $(call soong_config_set,arm_gralloc,soc,$(TARGET_BOARD_PLATFORM)) -include device/google/gs101/neuralnetwork/neuralnetwork.mk - include device/google/gs-common/gpu/gpu.mk PRODUCT_PACKAGES += \ csffw_image_prebuilt__firmware_prebuilt_ttux_mali_csffw.bin \ @@ -986,9 +984,6 @@ PRODUCT_PACKAGES += \ endif -# ARM NN files -ARMNN_COMPUTE_CL_ENABLE := 1 - # Vibrator Diag PRODUCT_PACKAGES_DEBUG += \ diag-vibrator \ From 583ea6c4e03017f4b0a699b4c27b6778bf8bb2f4 Mon Sep 17 00:00:00 2001 From: Akilesh Kailash Date: Mon, 17 Jul 2023 15:58:03 +0000 Subject: [PATCH 038/133] Use lz4 compression instead of gz. Given the benefits of lz4 with respect to install and merge times as well as reduce in CPU usage, it is worth to switch to lz4 Bug: 291594891 Test: OTA Change-Id: Ieee37bc11973d9dc3ef4de1811d67e223afabe8a Signed-off-by: Akilesh Kailash --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 18f68901..cc3c9eb0 100644 --- a/device.mk +++ b/device.mk @@ -600,7 +600,7 @@ include device/google/gs-common/battery_mitigation/bcl.mk $(call inherit-product, $(SRC_TARGET_DIR)/product/emulated_storage.mk) $(call inherit-product, $(SRC_TARGET_DIR)/product/virtual_ab_ota/android_t_baseline.mk) -PRODUCT_VIRTUAL_AB_COMPRESSION_METHOD := gz +PRODUCT_VIRTUAL_AB_COMPRESSION_METHOD := lz4 # Enforce generic ramdisk allow list $(call inherit-product, $(SRC_TARGET_DIR)/product/generic_ramdisk.mk) From c2abed3500ebf5dd80b73578cfd18863069b692d Mon Sep 17 00:00:00 2001 From: Devika Krishnadas Date: Thu, 22 Jun 2023 08:57:51 +0000 Subject: [PATCH 039/133] Use graphics allocator 2 Bug: 287353739 Test: atest VtsHalGraphicsMapperV4_0TargetTest Change-Id: I080045d75273fcf01d9129dee85fdf3c7b801117 Signed-off-by: Devika Krishnadas --- device.mk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/device.mk b/device.mk index c3000de2..b545260e 100644 --- a/device.mk +++ b/device.mk @@ -538,8 +538,7 @@ PRODUCT_PACKAGES += \ com.android.future.usb.accessory PRODUCT_PACKAGES += \ - android.hardware.graphics.mapper@4.0-impl \ - android.hardware.graphics.allocator-V1-service + android.hardware.graphics.allocator-V2-service PRODUCT_PACKAGES += \ android.hardware.memtrack-service.pixel \ From 5c5e1b804f1a5926f7db22cb3e748f6160414e86 Mon Sep 17 00:00:00 2001 From: Priyanka Advani Date: Mon, 24 Jul 2023 19:52:02 +0000 Subject: [PATCH 040/133] Revert "Use graphics allocator 2" Revert submission 23772493-allocator-aidl2 Reason for revert: Probable culprit for b/292565867, b/292569168 Reverted changes: /q/submissionid:23772493-allocator-aidl2 Change-Id: Ib177d152013e8e677a4cfc55cf6256128750591f --- device.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/device.mk b/device.mk index b545260e..c3000de2 100644 --- a/device.mk +++ b/device.mk @@ -538,7 +538,8 @@ PRODUCT_PACKAGES += \ com.android.future.usb.accessory PRODUCT_PACKAGES += \ - android.hardware.graphics.allocator-V2-service + android.hardware.graphics.mapper@4.0-impl \ + android.hardware.graphics.allocator-V1-service PRODUCT_PACKAGES += \ android.hardware.memtrack-service.pixel \ From fb733fd2be6762a2d65c69460d119adeca5a66c8 Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Wed, 12 Jul 2023 15:52:20 -0600 Subject: [PATCH 041/133] zuma: update the thermal dump script path Update the thermal dump script path. Bug: 289146743 Test: Compilation and boot-up test. Change-Id: I692cd56a01cad0ac70286662c3c8e758cb743b34 Signed-off-by: Ram Chandrasekar --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 261cf95e..67075af9 100644 --- a/device.mk +++ b/device.mk @@ -23,7 +23,7 @@ include device/google/gs-common/aoc/aoc.mk include device/google/gs-common/trusty/trusty.mk include device/google/gs-common/pcie/pcie.mk include device/google/gs-common/storage/storage.mk -include device/google/gs-common/thermal/thermal.mk +include device/google/gs-common/thermal/dump/thermal.mk include device/google/gs-common/performance/perf.mk include device/google/gs-common/pixel_metrics/pixel_metrics.mk include device/google/gs-common/soc/freq.mk From cf6402443534e0dc06bbfcafbd22435003fa00ac Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Mon, 31 Jul 2023 11:21:07 -0600 Subject: [PATCH 042/133] zuma: update thermal HAL makefile path update thermal HAL makefile path to the new common folder. Bug: 289146743 Test: Compilation test Change-Id: I0e06df78a422868bb44e12b58881aec5fa37743d Signed-off-by: Ram Chandrasekar --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 67075af9..c97b2bb8 100644 --- a/device.mk +++ b/device.mk @@ -24,6 +24,7 @@ include device/google/gs-common/trusty/trusty.mk include device/google/gs-common/pcie/pcie.mk include device/google/gs-common/storage/storage.mk include device/google/gs-common/thermal/dump/thermal.mk +include device/google/gs-common/thermal/thermal_hal/device.mk include device/google/gs-common/performance/perf.mk include device/google/gs-common/pixel_metrics/pixel_metrics.mk include device/google/gs-common/soc/freq.mk @@ -1058,7 +1059,6 @@ PRODUCT_PACKAGES += \ include device/google/gs101/telephony/pktrouter.mk # Thermal HAL -include hardware/google/pixel/thermal/device.mk PRODUCT_PROPERTY_OVERRIDES += persist.vendor.enable.thermal.genl=true # EdgeTPU From 97280123e81a358de447f8d8b5f9369084af9e66 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Tue, 1 Aug 2023 22:45:17 +0000 Subject: [PATCH 043/133] Allow for the previous version of com.google.face.debug In the 'next' release configuration, we don't allow using unfrozen versions of interfaces, so the previous version is served instead. Once this interface is frozen, this previous version can be removed from the FCM. Test: lunch cheetah-next-userdebug && m Bug: 290265210 Bug: 294127698 Change-Id: Ia9f93c9235fea89eafa66c6b11aeac5497e483bf --- device_framework_matrix_product.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index 72a0220a..33ee5fe2 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -86,7 +86,7 @@ com.google.face.debug - 4 + 3-4 IDebugHost default From a1525938ea39ba0344bd286d32712882ca899aa2 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Tue, 1 Aug 2023 23:25:37 +0000 Subject: [PATCH 044/133] Allow for the previous version of com.google.input In the 'next' release configuration, we don't allow using unfrozen versions of interfaces, so the previous version is served instead. Once this interface is frozen, this previous version can be removed from the FCM. Test: lunch cheetah-next-userdebug && m Bug: 290265210 Bug: 294130026 Change-Id: I662355264e4901f2f99bc0635779ab9b2f9756b9 --- device_framework_matrix_product.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index 33ee5fe2..8d2cc288 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -130,7 +130,7 @@ com.google.input - 2 + 1-2 ITouchContextService default From 5d8da452cba6ba0faabf98ad99c18a62a08f52aa Mon Sep 17 00:00:00 2001 From: Renato Grottesi Date: Mon, 7 Aug 2023 10:11:19 +0000 Subject: [PATCH 045/133] Disable armnn nnapi backend Discontinue maintenance and active support of ArmNN on Pixel phones. Bug: 294459623 Test: Local nnapi_info Test: Presubmit Change-Id: I3eb3f880671bea091ff6c798d8def2f559a5e291 --- device_framework_matrix_product.xml | 8 -------- manifest.xml | 10 ---------- 2 files changed, 18 deletions(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index 8d2cc288..a7915de2 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -11,14 +11,6 @@ default - - android.hardware.neuralnetworks - 1.3 - - IDevice - google-armnn - - android.hardware.radio 1.2 diff --git a/manifest.xml b/manifest.xml index f4c9367e..a71c165d 100644 --- a/manifest.xml +++ b/manifest.xml @@ -12,16 +12,6 @@ android.hardware.boot IBootControl/default - - android.hardware.neuralnetworks - hwbinder - 1.3 - - IDevice - google-armnn - - @1.3::IDevice/google-armnn - com.google.input.algos.spd 2 From 4d8bc4d7440a4644c69d513662727c269d02b2d5 Mon Sep 17 00:00:00 2001 From: Ziyi Cui Date: Thu, 4 May 2023 20:30:53 +0000 Subject: [PATCH 046/133] zuma: Add path reading for StormIRQ Bug: 279486693 Test: Verified the existence of atom and correctness of atom stats adb shell cmd stats print-logs && logcat -b all | grep -i 105043 Change-Id: I429e01b68fa4a22473c0b57dbf63ee6f579c5f18 Signed-off-by: Ziyi Cui --- pixelstats/pixelstats-vendor.zuma.rc | 3 ++- pixelstats/service.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pixelstats/pixelstats-vendor.zuma.rc b/pixelstats/pixelstats-vendor.zuma.rc index d324b6a8..70d875ea 100644 --- a/pixelstats/pixelstats-vendor.zuma.rc +++ b/pixelstats/pixelstats-vendor.zuma.rc @@ -1,6 +1,7 @@ on property:sys.boot_completed=1 start vendor.pixelstats_vendor - +on post-fs-data + chown system system /sys/kernel/metrics/irq/stats_reset service vendor.pixelstats_vendor /vendor/bin/pixelstats-vendor class hal user system diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index d5adf94d..c5b20b42 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -70,6 +70,8 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { }, .ResumeLatencyMetricsPath = "/sys/kernel/metrics/resume_latency/resume_latency_metrics", .LongIRQMetricsPath = "/sys/kernel/metrics/irq/long_irq_metrics", + .StormIRQMetricsPath = "/sys/kernel/metrics/irq/storm_irq_metrics", + .IRQStatsResetPath = "/sys/kernel/metrics/irq/stats_reset", .TempResidencyAndResetPaths = { { "/sys/kernel/metrics/thermal/tr_by_group/tmu/stats", From a6462edbe394dedb2fcb04ebc9c0e65b7e2b8de0 Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Mon, 7 Aug 2023 19:48:05 +0000 Subject: [PATCH 047/133] Usb: Listen to USB sysfs attribute for device state Poll the sysfs attributes that represents usb device state in either of the following states: not attached, powered, default, addressed, configured. The information is useful in detecting non compliant USB cable, which will be supported in later patch sets. This patch lays the ground work to monitor the sysfs attributes in both device and host modes. The thread to poll uevent is re-used to poll sysfs because this serialize type-C port events and usb device state changes, hence prevent potential races. Added a thin abstration layer and a map to keep epoll data so that it's easier to dynamically add/delete files to epoll, which is needed for usb devices in host mode. Bug: 285199434 Test: trigger usb device state changes in device and host mode Change-Id: Ie5389d051deb28dbb486c2f27319b3cc9e89312f --- usb/usb/Usb.cpp | 187 +++++++++++++++++++++++++++++++++++++++++------- usb/usb/Usb.h | 23 ++++++ 2 files changed, 186 insertions(+), 24 deletions(-) diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 74070770..138709ce 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -88,10 +88,15 @@ constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_ac constexpr char kPogoEnableUsb[] = "/sys/devices/platform/google,pogo/enable_usb"; constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type"; constexpr char kIrqHpdCounPath[] = "-0025/irq_hpd_count"; +constexpr char kUdcState[] = "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; +// xhci-hcd-exynos and usb device numbering could vary on different platforms +constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\\.usb/11210000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0"; constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); +#define USB_STATE_MAX_LEN 20 + ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, int64_t in_transactionId) { bool result = true; @@ -942,13 +947,114 @@ enum UeventType matchUeventType(char* str) { return UeventType::UNKNOWN; } -static void uevent_event(uint32_t /*epevents*/, struct data *payload) { +static void unregisterEpollEntry(Usb *usb, std::string name) { + std::map *map; + int fd; + + map = &usb->mEpollEntries; + auto it = map->find(name); + if (it != map->end()) { + ALOGI("epoll unregister %s", name.c_str()); + fd = it->second.payload.fd; + epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL); + close(fd); + map->erase(it); + } +} + +static void unregisterEpollEntries(Usb *usb) { + std::map *map; + std::string name; + + map = &usb->mEpollEntries; + for (auto it = map->begin(); it != map->end();) { + name = it->first; + it++; + unregisterEpollEntry(usb, name); + } +} + +static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags, + void (*func)(uint32_t, struct Usb::payload*)) { + std::map *map; + struct Usb::epollEntry *entry; + struct epoll_event ev; + + map = &usb->mEpollEntries; + if (map->find(name) != map->end()) { + ALOGE("%s already registered", name.c_str()); + unregisterEpollEntry(usb, name); + } + + entry = &(*map)[name]; + entry->payload.fd = fd; + entry->payload.name = name; + entry->payload.usb = usb; + entry->cb = std::bind(func, std::placeholders::_1, &entry->payload); + + ev.events = flags; + ev.data.ptr = (void *)&entry->cb; + + if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) { + ALOGE("epoll_ctl failed; errno=%d", errno); + unregisterEpollEntry(usb, name); + return -1; + } + + ALOGI("epoll register %s", name.c_str()); + + return 0; +} + +static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, + void (*func)(uint32_t, struct Usb::payload*)) { + int fd; + + fd = open(name.c_str(), O_RDONLY); + if (fd < 0) { + ALOGE("Cannot open %s", name.c_str()); + return -1; + } + + return registerEpollEntry(usb, name, fd, flags, func); +} + +static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { + device->latestState.clear(); + device->portResetCount = 0; +} + +static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { + ALOGI("Update USB device state: %s", state); + + device->latestState = state; + + if (!std::strcmp(state, "configured\n")) { + device->portResetCount = 0; + } else if (!std::strcmp(state, "default\n")) { + device->portResetCount++; + } +} + +static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + struct Usb::usbDeviceState *device; + + lseek(payload->fd, 0, SEEK_SET); + n = read(payload->fd, &state, USB_STATE_MAX_LEN); + + updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); +} + +static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; int n; enum UeventType uevent_type = UeventType::UNKNOWN; + std::cmatch match; - n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); + n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN); if (n <= 0) return; if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ @@ -1016,6 +1122,29 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) { pthread_mutex_unlock(&payload->usb->mDisplayPortLock); } break; + } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) { + /* + * Matched strings: + * 1st: entire string + * 2nd: uevent action, either "bind" or "unbind" + * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto + * 4th: usb device number, e.g. 1 for usb1 + * + * The strings are used to composed usb device state path, e.g. + * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state + */ + if (match.size() == 4) { + std::string action = match[1].str(); + std::string id = match[3].str(); + std::string path = "/sys" + match[2].str() + "usb" + id + "/" + + id + "-0:1.0/usb" + id + "-port1/state"; + if (action == "bind") { + registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); + } else if (action == "unbind") { + unregisterEpollEntry(payload->usb, path); + clearUsbDeviceState(&payload->usb->mHostStateMap[path]); + } + } } /* advance to after the next \0 */ while (*cp++) { @@ -1023,37 +1152,46 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) { } } +static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + + lseek(payload->fd, 0, SEEK_SET); + n = read(payload->fd, &state, USB_STATE_MAX_LEN); + + updateUsbDeviceState(&payload->usb->mDeviceState, state); +} + void *work(void *param) { int epoll_fd, uevent_fd; - struct epoll_event ev; int nevents = 0; - struct data payload; + Usb *usb = (Usb *)param; ALOGE("creating thread"); - uevent_fd = uevent_open_socket(64 * 1024, true); - - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed\n"); - return NULL; - } - - payload.uevent_fd = uevent_fd; - payload.usb = (::aidl::android::hardware::usb::Usb *)param; - - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - ev.events = EPOLLIN; - ev.data.ptr = (void *)uevent_event; - epoll_fd = epoll_create(64); if (epoll_fd == -1) { ALOGE("epoll_create failed; errno=%d", errno); + return NULL; + } + usb->mEpollFd = epoll_fd; + + // Monitor uevent + uevent_fd = uevent_open_socket(64 * 1024, true); + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed"); + goto error; + } + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) { + ALOGE("failed to monitor uevent"); goto error; } - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { - ALOGE("epoll_ctl failed; errno=%d", errno); + // Monitor udc state + if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) { + ALOGE("failed to monitor udc state"); goto error; } @@ -1070,14 +1208,15 @@ void *work(void *param) { for (int n = 0; n < nevents; ++n) { if (events[n].data.ptr) - (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events, - &payload); + (*(std::function*)events[n].data.ptr)(events[n].events); } } ALOGI("exiting worker thread"); error: - close(uevent_fd); + unregisterEpollEntries(usb); + + usb->mEpollFd = -1; if (epoll_fd >= 0) close(epoll_fd); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 892d769e..f6bbd695 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -121,6 +121,29 @@ struct Usb : public BnUsb { pthread_mutex_t mDisplayPortLock; // eventfd to signal DisplayPort thread int mDisplayPortEventPipe; + + // USB device state monitoring + struct usbDeviceState { + std::string latestState; + int portResetCount; + }; + struct usbDeviceState mDeviceState; + // Map host device path name to usbDeviceState + std::map mHostStateMap; + + // File monitoring through epoll + int mEpollFd; + struct payload { + int fd; + std::string name; + Usb *usb; + }; + struct epollEntry { + struct payload payload; + std::function cb; + }; + std::map mEpollEntries; + private: pthread_t mPoll; pthread_t mDisplayPortPoll; From 0a569372576a685113bb677e64f01a839924ec6e Mon Sep 17 00:00:00 2001 From: kierancyphus Date: Fri, 5 May 2023 16:12:31 +0800 Subject: [PATCH 048/133] Create liboemservice proxy HAL declaration Test: Manually flash device Bug: 270279779 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c21030d93955f6c9e67f49f18ca0edaea25452e6) Merged-In: If9afb248857e2b3234a3b7a5a80973f1372dc76a Change-Id: If9afb248857e2b3234a3b7a5a80973f1372dc76a --- device_framework_matrix_product.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index a7915de2..df8808d1 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -185,6 +185,13 @@ sced0 + + com.google.pixel.modem.logmasklibrary + + ILiboemserviceProxy + default + + vendor.samsung_slsi.telephony.hardware.radioExternal 1.1 From a4d7d760ec68a316df8a626a99ead2bc02a84b69 Mon Sep 17 00:00:00 2001 From: joonhunshin Date: Fri, 11 Aug 2023 01:30:10 +0000 Subject: [PATCH 049/133] Removing TestRcsApp userdebug application from the system image. RCS has a low priority and will not be used in the future, remove it from the system image. Bug: 295403727 Test: Make sure the TestRcsApp is removed from the system image. Change-Id: I3a8f1f2363bb36418ea12ace6ee145e8114ae51c --- device.mk | 4 ---- 1 file changed, 4 deletions(-) diff --git a/device.mk b/device.mk index 18f68901..6f0a20bc 100644 --- a/device.mk +++ b/device.mk @@ -896,10 +896,6 @@ $(call inherit-product-if-exists, vendor/samsung_slsi/telephony/$(BOARD_USES_SHA PRODUCT_PACKAGES += ShannonIms -#RCS Test Messaging App -PRODUCT_PACKAGES_DEBUG += \ - TestRcsApp - PRODUCT_PACKAGES += ShannonRcs ifeq (,$(filter aosp_% factory_%,$(TARGET_PRODUCT))) From 3850a38f4529d918e869970680da34775d566428 Mon Sep 17 00:00:00 2001 From: kierancyphus Date: Sat, 1 Jul 2023 08:22:32 +0800 Subject: [PATCH 050/133] Example adding new log mask file Test: Flash, fire an event and check to make sure that the new mask is included in storage. Bug: 263307589 Change-Id: I733b75a830eff86a1d6d1a3b02ac4f295599cf58 --- device.mk | 26 ++- radio/Android.bp | 32 --- radio/config/default/Android.bp | 92 +++++++++ radio/config/{ => default}/default.cfg | 0 radio/config/{ => default}/default.nprf | Bin .../config/{ => default}/default_metrics.xml | 0 radio/config/{ => default}/logging.conf | 0 radio/config/empty/Android.bp | 57 ++++++ radio/config/empty/empty.cfg | 1 + radio/config/empty/empty.nprf | Bin 0 -> 8582 bytes radio/config/empty/empty_metrics.xml | 191 ++++++++++++++++++ radio/config/empty/logging.conf | 1 + 12 files changed, 364 insertions(+), 36 deletions(-) create mode 100644 radio/config/default/Android.bp rename radio/config/{ => default}/default.cfg (100%) rename radio/config/{ => default}/default.nprf (100%) rename radio/config/{ => default}/default_metrics.xml (100%) rename radio/config/{ => default}/logging.conf (100%) create mode 100644 radio/config/empty/Android.bp create mode 100644 radio/config/empty/empty.cfg create mode 100644 radio/config/empty/empty.nprf create mode 100644 radio/config/empty/empty_metrics.xml create mode 100644 radio/config/empty/logging.conf diff --git a/device.mk b/device.mk index ede4da0b..e90dcc3d 100644 --- a/device.mk +++ b/device.mk @@ -970,14 +970,32 @@ endif # modem logging binary/configs PRODUCT_PACKAGES += modem_logging_control -# modem logging configs +# PILOT SCENARIOS +PRODUCT_PACKAGES += \ + Pixel_stability.cfg \ + Pixel_stability.nprf + +# Default modem log mask for pixel logger PRODUCT_PACKAGES += \ logging.conf \ default.cfg \ default.nprf \ - default_metrics.xml \ - Pixel_stability.cfg \ - Pixel_stability.nprf + default_metrics.xml + +# Log Masks for logmasklibrary below +# default modem log mask +PRODUCT_PACKAGES += \ + default_modem_log_mask.conf \ + default_modem_log_mask.cfg \ + default_modem_log_mask.nprf \ + default_modem_log_mask.xml + +# Empty modem log mask +PRODUCT_PACKAGES += \ + empty_modem_log_mask.conf \ + empty_modem_log_mask.cfg \ + empty_modem_log_mask.nprf \ + empty_modem_log_mask.xml endif diff --git a/radio/Android.bp b/radio/Android.bp index 54b41efc..e3eb7126 100644 --- a/radio/Android.bp +++ b/radio/Android.bp @@ -24,38 +24,6 @@ package { ], } -prebuilt_etc { - name: "logging.conf", - vendor: true, - proprietary: true, - src: "config/logging.conf", - relative_install_path: "modem" -} - -prebuilt_etc { - name: "default.cfg", - vendor: true, - proprietary: true, - src: "config/default.cfg", - relative_install_path: "modem" -} - -prebuilt_etc { - name: "default.nprf", - vendor: true, - proprietary: true, - src: "config/default.nprf", - relative_install_path: "modem" -} - -prebuilt_etc { - name: "default_metrics.xml", - vendor: true, - proprietary: true, - src: "config/default_metrics.xml", - relative_install_path: "modem" -} - prebuilt_etc { name: "Pixel_stability.cfg", vendor: true, diff --git a/radio/config/default/Android.bp b/radio/config/default/Android.bp new file mode 100644 index 00000000..0a9d4b05 --- /dev/null +++ b/radio/config/default/Android.bp @@ -0,0 +1,92 @@ +// +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: [ + "//device/google/zuma:device_google_zuma_license", + ], +} + +prebuilt_etc { + name: "logging.conf", + vendor: true, + proprietary: true, + src: "logging.conf", + relative_install_path: "modem" +} + +prebuilt_etc { + name: "default.cfg", + vendor: true, + proprietary: true, + src: "default.cfg", + relative_install_path: "modem" +} + +prebuilt_etc { + name: "default.nprf", + vendor: true, + proprietary: true, + src: "default.nprf", + relative_install_path: "modem" +} + +prebuilt_etc { + name: "default_metrics.xml", + vendor: true, + proprietary: true, + src: "default_metrics.xml", + relative_install_path: "modem" +} + +// the mask should also be copied to another folder to be accessible to logmasklibrary + +prebuilt_etc { + name: "default_modem_log_mask.conf", + vendor: true, + proprietary: true, + src: "logging.conf", + relative_install_path: "radio/log_masks/default" +} + +prebuilt_etc { + name: "default_modem_log_mask.cfg", + vendor: true, + proprietary: true, + src: "default.cfg", + relative_install_path: "radio/log_masks/default" +} + +prebuilt_etc { + name: "default_modem_log_mask.nprf", + vendor: true, + proprietary: true, + src: "default.nprf", + relative_install_path: "radio/log_masks/default" +} + +prebuilt_etc { + name: "default_modem_log_mask.xml", + vendor: true, + proprietary: true, + src: "default_metrics.xml", + relative_install_path: "radio/log_masks/default" +} + diff --git a/radio/config/default.cfg b/radio/config/default/default.cfg similarity index 100% rename from radio/config/default.cfg rename to radio/config/default/default.cfg diff --git a/radio/config/default.nprf b/radio/config/default/default.nprf similarity index 100% rename from radio/config/default.nprf rename to radio/config/default/default.nprf diff --git a/radio/config/default_metrics.xml b/radio/config/default/default_metrics.xml similarity index 100% rename from radio/config/default_metrics.xml rename to radio/config/default/default_metrics.xml diff --git a/radio/config/logging.conf b/radio/config/default/logging.conf similarity index 100% rename from radio/config/logging.conf rename to radio/config/default/logging.conf diff --git a/radio/config/empty/Android.bp b/radio/config/empty/Android.bp new file mode 100644 index 00000000..319bc20a --- /dev/null +++ b/radio/config/empty/Android.bp @@ -0,0 +1,57 @@ +// +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: [ + "//device/google/zuma:device_google_zuma_license", + ], +} + +prebuilt_etc { + name: "empty_modem_log_mask.conf", + vendor: true, + proprietary: true, + src: "logging.conf", + relative_install_path: "radio/log_masks/empty" +} + +prebuilt_etc { + name: "empty_modem_log_mask.cfg", + vendor: true, + proprietary: true, + src: "empty.cfg", + relative_install_path: "radio/log_masks/empty" +} + +prebuilt_etc { + name: "empty_modem_log_mask.nprf", + vendor: true, + proprietary: true, + src: "empty.nprf", + relative_install_path: "radio/log_masks/empty" +} + +prebuilt_etc { + name: "empty_modem_log_mask.xml", + vendor: true, + proprietary: true, + src: "empty_metrics.xml", + relative_install_path: "radio/log_masks/empty" +} diff --git a/radio/config/empty/empty.cfg b/radio/config/empty/empty.cfg new file mode 100644 index 00000000..58f9cd39 --- /dev/null +++ b/radio/config/empty/empty.cfg @@ -0,0 +1 @@ +default.nprf,default_metrics.xml \ No newline at end of file diff --git a/radio/config/empty/empty.nprf b/radio/config/empty/empty.nprf new file mode 100644 index 0000000000000000000000000000000000000000..be97f47dec5f1a1e45efd3df7e413f851570df89 GIT binary patch literal 8582 zcmbt(1z1$;x-c;0rbLh~rMp2=5FA3fOLB(L8FD~61Oe%0h!K$%kQhW7q>+-65&@-S zP*T#nV4vsSeV%joIe*N0X3e+O^Ud4!y|3;=5bhsXS04-SG^6XqKW=|uF=9P+^?2gx zW@`@>GBPB>0u7hHwqHmyg?RZ8V`1aw)Zf6uHL%9U(*0W)RR07+5DrDyLTnMX|Buj^ z{sx+$8_dhm*~Rn!5UgZuit%3=z5AcQ+PlI9J#FEhUM`M;Fa%T(0vCkaI=gt-yZwpL z=iNQX;{PrdDgY577TB}ISO!KF4q?K=;=#woGWh?%sG`Mc=mBViRUH9^vl>8QP4 ztBary9CocEP`W8(?O%!6K`nU9^;Jji?o;tEmKWb?_n_CdIxBl$k~l@hCVA%2Or;Qs&8s*4iu3k z9^1i;oWz*bM|Zw=KbVhU5qyg|Wg*v=T=Pnm54>#0>>sM@axSH8t|&^JUDUg@lqL&H zo;UN@22fX)am{y_)40^Y(2{c2*3->jwpYJrlnroA=Aj;+tekdUxWIA|l`4-8R`zv1 zOs?!)q^!P6TfOMsIUI()G;}RD94N~UmQ#-}XK#^m=Z_wiT;jKiM4!WDEj?!xQ~9I) zMQ7wXc(ZSRv8aIEMU8GdLC>7u%@ilFNZg?LY@AyDbiYURQ!}PxI5t|ZqL8T@Dls4>d(oU` zo;8|+7}eMzDNSRpWnLK0GT*S}Lsb(Gt62iF1vqhHGTBbJ4Q8} z$2@)g3xnA^y&UgO>x49>RJgj_dqO|6_cUvL@A8{LS(1Q4Y>mwi!YT;e9?AR58}MIWY9~b$%ZEPkokzW1!u1aI(0$uDC;yeXEmAd3SY#&=A22_TFo~T_<1HZwFmh2O#;88sj2L~QxyH_1u7?- z{savA(RLd)ie)-akEPzXO^nX#Om@#NFvhOynFanD)4OzpIUB8pF7+M-ZDKlyKTkyE z43+9N%o?zHh?jsViv(9E)HJm2%o(ti4nHE%;E7&@Z`)`X877bUZ^S^#p&G#4{bVAa6`ln5I5cXZD&6vDoJF^~+5A%C!bU zpg5pTeoD$KmlZuw%bad9H+0=uk6l7-G-<-;v~7hgIScN%eMp|lThHfXH+n8r$8m>* z(^gz^ZVH&mN?6dstJanZUcc5iG)k7Hx9i=p;4xPEIXp`EzBGnZQs-ua3ZF)GtmU&? zg@g+nWZqM;YK*CK9UPW=ZvxW7`3O3nv~CnwzP)&4n%;6xY-r$7(rGQ4=84L%OSxXd zX*D>U?Mz~=%d3egn7w3M1%c9Kl)2l(yFxNO~B zuiwN)9rJA)!{PdPs&pw2js1>KhI1UC0ke(0nAC*3b1HfHD?C~oHvY0&rkrHp;;-=X zLO3+VKxhkcVp$HKcpP0d{7j|tM4dS%i-iofsTDve(FSil4btUhkq#h+wd2DYr?(lj z%+Yd-&Ae6E3`E&&)aJPI9+=yM?IeQ-$Wap%n`3GR$zZ!?Mkf2%83Fm-6g;O8aCi}6 zEzS`33#?bz^h8kDNRlWwsWT$cdR zC5o^aU=$eP}U!u`^{EUB_z3x?_PO%6(Hvs^=T7nd+`cfQVf$**XLhOGmTRQHSNyb3L`w=_>!$e0YGCF|Q}B>z!<%U#Ur2RA8?q9!X4xGEvGtka)?t_yzF^n~4ZD-o3$U^F2Tt z;O<3^OHf?cD_eXAc88wvCya1n*($bb1IY%73-4~}-Z>nyMYTm(Z~9%BXb5AUNRk1k z!G+YIOchA>rfh!`#%OmRbozM_--X@9&sQRgAOzou-HG$`v*`*J`46=p+v!qek*g9r zZB-&v*F0>P&#|L=7#a(26L`cfLns{=gf~LS)(O`UVz|Ub49HNr(9GsPRO?pVh#9uq zKlvosbFp}jVIX(Kj#sC^s0q zJOm9(wCNs52C|acDECh6G-?V=(~_E5`1{?Sh{wFmJDaB?KsImsU^B#3Zb$!6zRsLc z-T&1@uhbKAQI>E8Hw87+Nx&y*Hknnw48SSEwiexhu+!qVq=L;2MWGC=EI#@1qI?BZ2m0QLr! zI5ieb>NW!|?}lTR%MWGQjMeQDy1t^-wzX#69VJ@trtiU2cCN19mnDw|viai+sb>24 ze&)EftXd=-|Aga6-|YXW7>{2gn#kr}{yeuXeuRreY8M(BUuYPl_p9JM^<%G3+VG5D zTHj1SOh<1}+Q;4y;Q3kFdYOKZuh4rp{_ZxCBUj%l|D@LwmLIRA-9#Czwv$M5=;~dP z{~;Eh!g{1h?#~r@q2GxCy%aQ_Z0Jqg^->6HHIX4dvsz^g!9coyoGjBKD))($k2Q|f z5S55XB!+O2>#3oCj72cU@wg2R$p0iowE}v?T7bNl^6|rn4 zU>?leb>aAK{kN~~QSPLdds}w8KHNOHj`^1JT?b0){+yOie7We1#$v>g%yId!wn>+j z(m~1uU)w&nx6Ym%FRHi@yg{jbk1&w4n4t9R{D2ja`+CCLu#Ik0X+uIu-f4cVm>}=$ zpddU5Jsvjp#KZ4Xq~ zfp>1w%Yt+ReVwefiak5Ay}lZzjlHDe^d0rz1T6&j5-T)Jj=30$H+?c!24wg$W-}h{ zyBnX@TJWTeXqF>}$E$8OJbjv)q~qVKy)wB_J>DSYv#o;JuP}*GU7Go>=Of`uWj(ht zI{lL@@^OAB>mhesd4j-ACi?;V7~EbPFIdtvZF!u)O?tjuM9)W|%<4TgX!#d`yL*h#jzG?KAJ~zYOSWcwrlTMHGczH}(jdORIob5yLnT))st|CQ!fQ6je*(+2z|-n)2z;pV~D(tESER{FwdCIt~4u zNi}&FXOC~5H@dY~ynx$U5O7;oDDJUp;M#Ijh@awHRmw1^cj5Pj~Z!iG-(_u z_eZJTItr{~?opPMm&MSu6ZHX{eUs*SqUn_yox)=<0`L8KjHX_c9#FeAsY|8b2c&mXK) znp506?(xg1<~9&{CrS_)%6$C>otW&$rYzM+s>}~`tN$-$@0!dHLki&hFh%|v1IuY8~Y%R1Nt-l2Q4kSnmESskqHmZH- z^>7${IjTPO&4@K7NkVECG9R(89g*2+Bn!{G3i#8P{(n(&rA2 zz3RqqXTxU5tu*|z9A!I?e^|#2_WDcQcU+h($&sJpXGoucC>!&#j1(e zq1K85ay2M%l{spaIph=$KK>GeLEoBZb8ljz8CM|S6&DpEHopIq!I;;P?`vs*`EUBn1P-bDjutM4)^zL{W(67F3noYTn@`SX z`090K+Sc#$$afHPcqRya%q9=se<4hdGKn4Kp3jd3uQEHr?p-cZI&o*36y$|7=S3v@ zcF|8pE{)H0(QB;HJmD@>Ezg5s`s>X0#^+ZEas%eV#`so_UU`i)$`j60x}ujm*OnB` z3%(xRuUww9+I$%_xAle64Sh)Xf|{-#yq5OtNh(IV9=vLmkp;C5Ix5wakg1$C%tuse zOVm`B=#-M$UOa@Wwx-Kb`W87RIntXhRl56UJ>%54I;f?1V$lO7D^pf=_A6BfKA>1> zAN{cL6;}Xb2Au6qdS3MB!%-DFS`US<3fs}VnIjsBFZpCZ*%4Ay5>`-xu0c7GMGXVT zve?0J_bl(%Xb|QQME^=ed0c2*ZHG)4B(`u@ET70x6x$6X1$Ifk^ND_o8;(QLP8+J8 zQnUHiselaf3Omb{F-zNMKV&`*3nUD-`B)&quOYUGBbZWOPW>kCVwAoc-unqhU_n#> z$~-Y=l=!$Uy;U<2J5wE!TwbnR!DFDH&Ip_-E!GNMTnq;5)+%h{<@gq{$QElC!)IH1 zT}^+55!WN#`Xwymk&oK(EMw~nX1DKGuvoTthd(SOu;)MhfM;3cZf4?MJ<%jY^Nj}% zl;R7bqEP=owrtY0jo!DogTo z5;tq^C*#>Z%6Zb3wnE&F6-$TI07Y<+04r=H@7w$%g|3ro!-_$Z1=*0~VWuC`)mvEL zqzE#(5>9D?8_{RyUFT zMRA14F86uBs@YHz+QxyHFx73QUJxhQdKJ9p)? z6aKc7-W7ORHL^W=->fh&rhD1zBtz)l<+=}c&*CtNZ+prXi;MXJH@RS$IIwUSct3cp)0^txV zz8$WeObp%8pfX7pVHbj03&O2nO02Y$ARm6X#Jp_%>KQB(a}KCGOe% zCIZw)fz)2xK98!o*QFS%rdd&(kudWPPh62rdED$`Jedgahj8!$NaEgWc91X@8}@kI zpc)o%kc=8!51kQ-Wc)xfh|J_UXparj48f+wrmf)be9jM;`W;~}gvT2t<)180Ar3dQ z_?-uk#AGjVscl3)=ttmpM&1G}Pt~|aCU#s>$-B>k#cHv;Yry%7i-`hcm!m!;hA5+X zx^{H>c9Y#Ao|R@ZmC|Gup|gk^HVsH{HndcTX9qN}9|?6td(lFbP~~M%6w1K})#K>C z*%5cjVrH5C!P⩓IcVRc+>N-tF&WEK z?(8EAN#~Ez7#Z%llwNCW;wr2diuBWw!l14thGbU2VH_Ye8cm$5q((eZp-5-DXiOZd zYQg<$$`C@h(yz4$ZLl2Zku{&+zQ}2Ny@P%2eYEK^!u%)L_%^Za2ZA`at4Tyz?Ny4< z&oQ^ow1Gwuz*O}xab#!*aWm3~N9P^mj9tM1fejYEjkwLt9o9q>Dgj_uY%|0!K6Z%g z2aZrmGwhqUhcqiK=*m$!rsiy|Kv$#^rOS*vWSl&?F9K+QP1skLYKU2ZltKR^&_Z&6 zeWjrnp5VWx0yaQNN{dOup$(x387&ibUEhubOyq@GEvNLJCvbFEEQ%ZqjUXBN2yi^! zms5Lt<{QUtx+<&zasE*mSvVRJ1FC@lgp4;AWP0C`m7ul3PIoqy-2LwDB26p3M+tB} z6}00+x4BLJWN810vsU@dZCat$psX~z{HMiLEO_Rxx>X+1Jt=eXV+EoTr#sKHl=Apz zyiTgwjkf{w%S4JgkG%4Ea2xkpnoy=&jurC5JmElt4e4Ws=WKebw1;GX7HBs(J4o_f zkSV>11VU#@ZK_gE9X!F)DU{ktWOVQCj{owf0N?>6kmpUXMbWKc<6Be}JLAIW(rI+I zT5VN+oN2y`b~`jf;i=En4jgg=EOA=ZHf?^bipK&Bv|a!6lDdDDFirjyV&4t0eJTkc zzoJmHwU!>$P1fr`E)$rrJ@<^pCv&y1gtCIVBQF66>YSEiz7$77H>?u5KnztPwrH}g z=4q#$1jh6~0NvjQ4~dPw0F$Hz0qz)z41)B4ZGqf_O}~TNC&eg40t8(AB7;uL=Db1@ zh+z<6vO&$C24BfgUXZ%;$13s37Lip2V)+@{7*PD)|&f$M5@#63-D&Px8*TAO=nX{H^nj z=g(!E_*`1QSbz2A5}4s;_PSV*u9?nG_6~lN)<)|!OUzd+vihEevPg9E{lg(+H4ufT z+&J>PH14{Qr7=En#8trP6|%zHV1<5k;JK1pRvYyiy~uX&^Q$;lim;ouCKS10&&kR2 zOhY+B-r!HSEtrrD)*S#k3lxbw&)!!@kkE+%T_EgC=%btw2`48Iko&7c9P*Sp6_f#( z6!h|N@D7WE4cHD$5J71GIOAY@sx#vgt)0r!-<>3bgo9MGE8HNC(V36H?Z`o|Hscn4EzXcp#y!!q-Q6Era99>q4p`*u>Pr5Mx zTA+}a;q+7!!3TmpD_AFmNk1AWOhhPCRGiCiEAs&E2v#gYqqh_7NPu=5T_$F@Mp@GS z*)>`WzyAa1^$u_o`{6CG;H%h+yfYqU%fbmbl45KS3FY&vmtw;6#=lKcF97cz>_fz# z=5GRdU5se(h<$7RpwC_O1_;0p))u(;I)X?{*xmuW+au?YjC~y;s6~4xgaE@IY)8-! z#5*TnQ#ZcBm)!ARV#8?Ec4unP>nUn`pk{pi>&K zmm+c0CvWL0$PYd|uG+KzcnN3+N7N6rFCy?8puxee_Q4><15KaM3}>rk;qo%M*}891 z<@SpBkfNmiXI1gF$Zb*)y6d{5UYX>UCg4G0B4whyUJl&7KsM48OHsA`I`=}|1|M)V zMF*ekK?Zs#P`eEd9tfpmra{gRR~htx z^tUSi1+X0KLP(yoRQuCiN6Ylz5|1H+4kzE~M=!fXg!=#9-i4xrEM8Zt;x(R8UT>0%alPt9;P)6d2 zWgm)4!&O5Ifu?M1X6Co%_~;bx?e%1!vr3U^<}$VOEJ6$lboC%k8iB9#Rsi$t8PuF4 z9(Fp7yxOsW?+EL`rGG_{w}I}V%Nd~D-Taf(FS1TvuHwAU_Q)Ffx8i;vqbBdrj zpZon9DD*}VW{j!wNic@Eb$&r@N$8hN$Q-Ev%&D8NSgROo)o8JxoLXXCtBQ`G?z$ht9+6f!{| z1Yt01KF$46Ni#K-VN#({m)O0Pry-fxot>vqm(V?`%fZn9&8H-}LS;zhs&!juw5TYV z0)97>d1-dD&Gk8Dx~K^DXQhUhPspMk^Pv~_bMb;Fk<~#+t#@k$U;nsjAEFheUM9)s zU)#?_biUcHvyMgpzLcB&YLRFA={ZNB{I!+2>pmv$|H^#r_ItJ3wW<3LPyGOK4t}C? zH_NED@-9@ze*DTID@$MY!dq#U+w=6-h2V z4T2~-+{{EjusE}3{Nzl^KSGr*GDm732DfQ2#h|OcI4-Sr8iWOg{81uDYzXE*4n)?9 z#xr($=a%g#5J&|xueqG&)NFF%+>!M9u?MK;i>!+yuZ%b|L-9){S)Nmzk&Rhnfrf6 z@vjs2zY@RkpHTeU`8$C9YX1Jeitg{G?|)*)2JjYyS^z))ql*6#-G4LqZ?ON{Sv)}4 a)hzyB2*bk%@M7Ts7ds9XmL|*9(|-X8&Q&`A literal 0 HcmV?d00001 diff --git a/radio/config/empty/empty_metrics.xml b/radio/config/empty/empty_metrics.xml new file mode 100644 index 00000000..4e9e38d2 --- /dev/null +++ b/radio/config/empty/empty_metrics.xml @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/radio/config/empty/logging.conf b/radio/config/empty/logging.conf new file mode 100644 index 00000000..e852dd57 --- /dev/null +++ b/radio/config/empty/logging.conf @@ -0,0 +1 @@ +modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -m /vendor/etc/modem/default.cfg --enable_exmetric --enable_exmetric_internal \ No newline at end of file From d836d5d5ad02c729db581f1c5595c019946e96ab Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Thu, 17 Aug 2023 21:47:27 +0000 Subject: [PATCH 051/133] Enable dimming in gamma space in screenshots for adaptive mode This fixes a flicker during screen rotation Bug: 293560925 Test: Youtube HDR playback Change-Id: Icd7ab0ab7f7d4295785f6840788bb33e327b3bc6 --- device.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/device.mk b/device.mk index ede4da0b..e50feb9d 100644 --- a/device.mk +++ b/device.mk @@ -660,7 +660,8 @@ endif PRODUCT_PROPERTY_OVERRIDES += \ debug.sf.disable_backpressure=0 \ debug.sf.enable_gl_backpressure=1 \ - debug.sf.enable_sdr_dimming=1 + debug.sf.enable_sdr_dimming=1 \ + debug.sf.dim_in_gamma_in_enhanced_screenshots=1 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += debug.sf.use_phase_offsets_as_durations=1 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += debug.sf.late.sf.duration=10500000 From 1582fde39dda9029c10819956dedd720075bc3f1 Mon Sep 17 00:00:00 2001 From: Hsin-Yi Chen Date: Fri, 18 Aug 2023 07:40:53 +0000 Subject: [PATCH 052/133] Revert "Create liboemservice proxy HAL declaration" This reverts commit 0a569372576a685113bb677e64f01a839924ec6e. Bug: 296329753 Reason for revert: broken build Change-Id: I9067e9198abede003357af770c229155310059f6 --- device_framework_matrix_product.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index df8808d1..a7915de2 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -185,13 +185,6 @@ sced0 - - com.google.pixel.modem.logmasklibrary - - ILiboemserviceProxy - default - - vendor.samsung_slsi.telephony.hardware.radioExternal 1.1 From 271c0a629bf62b4e7d9f7f4b40bcd722a6cd4788 Mon Sep 17 00:00:00 2001 From: kierancyphus Date: Tue, 22 Aug 2023 06:25:47 +0000 Subject: [PATCH 053/133] Create liboemservice proxy HAL declaration Test: Manually flash device Bug: 270279779 Change-Id: Ibb042f499cd835680a195e0fd59214e013a1798c --- device_framework_matrix_product.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index a7915de2..df8808d1 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -185,6 +185,13 @@ sced0 + + com.google.pixel.modem.logmasklibrary + + ILiboemserviceProxy + default + + vendor.samsung_slsi.telephony.hardware.radioExternal 1.1 From bd7086e4dab280cd59ba87453d2104df591d3821 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 25 Aug 2023 21:00:07 +0000 Subject: [PATCH 054/133] add comment about persist properties Change-Id: I394cda6db222b5c43b1fed1282b81d8277b7af67 --- device-common.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/device-common.mk b/device-common.mk index 8cb07f43..c887ffea 100644 --- a/device-common.mk +++ b/device-common.mk @@ -49,6 +49,9 @@ PRODUCT_PRODUCT_PROPERTIES += \ # force enable MTE. ifeq (,$(filter %_fullmte,$(TARGET_PRODUCT))) PRODUCT_PRODUCT_PROPERTIES += ro.arm64.memtag.bootctl_supported=1 +# N.B. persist properties in product Makefiles aren't actually persisted to the data +# partition, so they will actually go away if we remove them here, or if the user +# flashes from a normal build to a fullmte build. PRODUCT_PRODUCT_PROPERTIES += persist.arm64.memtag.app.com.android.se=off PRODUCT_PRODUCT_PROPERTIES += persist.arm64.memtag.app.com.google.android.bluetooth=off PRODUCT_PRODUCT_PROPERTIES += persist.arm64.memtag.app.com.android.nfc=off From 867f6722e4889a5928f49d15ead9e5626a5632d9 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Mon, 28 Aug 2023 22:37:29 +0000 Subject: [PATCH 055/133] Expect wifi_ext V2-V3 in the framework manifest The service is now serving and declaring V3. Since V3 is unfrozen, it will be serving V2 on 'next'. So we allow for V2 as well. Test: none Bug: 297910487 Change-Id: I9716a335b65bf0c3ced88be48687d2e5e2fae3ab --- device_framework_matrix_product.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index a7915de2..59cbfff5 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -169,7 +169,7 @@ vendor.google.wifi_ext - 1 + 2-3 IWifiExt default From cabe846a1f3ecf93b75b6f2a9a01ddbfcf585a5b Mon Sep 17 00:00:00 2001 From: RD Babiera Date: Tue, 28 Feb 2023 18:44:07 +0000 Subject: [PATCH 056/133] usb: populate USB aidl hal AltModeData Populates AltModeData within PortStatus with DisplayPort Alt Mode statuses for pin assignment, hpd, link training status, and port partner capability. Test: manual test on device Bug: 277466852 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:24f5f802bd37040e62de4f111b4c4f73c2ae8db4) Change-Id: I52a56f7090ed6dbef6211f19d6350cecac58e4fa --- usb/usb/Usb.cpp | 195 +++++++++++++++++++++++++++++++++++++++++++++--- usb/usb/Usb.h | 16 ++++ 2 files changed, 202 insertions(+), 9 deletions(-) diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 138709ce..93ea07c4 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,7 @@ using aidl::android::frameworks::stats::IStats; using android::base::GetProperty; using android::base::Join; +using android::base::ParseUint; using android::base::Tokenize; using android::base::Trim; using android::hardware::google::pixel::getStatsService; @@ -94,6 +96,8 @@ constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\ constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); +AltModeData::DisplayPortAltModeData constructAltModeData(string hpd, string pin_assignment, + string link_status, string vdo); #define USB_STATE_MAX_LEN 20 @@ -487,6 +491,11 @@ Usb::Usb() ALOGE("mDisplayPortEventPipe eventfd failed: %s", strerror(errno)); abort(); } + mDisplayPortDebounceTimer = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); + if (mDisplayPortDebounceTimer == -1) { + ALOGE("mDisplayPortDebounceTimer timerfd failed: %s", strerror(errno)); + abort(); + } } ScopedAStatus Usb::switchRole(const string& in_portName, const PortRole& in_role, @@ -826,6 +835,118 @@ done: return Status::ERROR; } +/* DisplayPort Helper Functions Start */ + +DisplayPortAltModePinAssignment parsePinAssignmentHelper(string pinAssignments) { + size_t pos = pinAssignments.find("["); + if (pos != string::npos) { + pinAssignments = pinAssignments.substr(pos+1, 1); + if (pinAssignments == "C") { + return DisplayPortAltModePinAssignment::C; + } else if (pinAssignments == "D") { + return DisplayPortAltModePinAssignment::D; + } else if (pinAssignments == "E") { + return DisplayPortAltModePinAssignment::E; + } + } + return DisplayPortAltModePinAssignment::NONE; +} + +LinkTrainingStatus parseLinkTrainingStatusHelper(string linkTrainingStatus) { + linkTrainingStatus = Trim(linkTrainingStatus); + if (linkTrainingStatus == LINK_TRAINING_STATUS_SUCCESS) { + return LinkTrainingStatus::SUCCESS; + } else if (linkTrainingStatus == LINK_TRAINING_STATUS_FAILURE || \ + linkTrainingStatus == LINK_TRAINING_STATUS_FAILURE_SINK) { + return LinkTrainingStatus::FAILURE; + } + return LinkTrainingStatus::UNKNOWN; +} + +bool isDisplayPortPlugHelper(string vdoString) { + unsigned long vdo; + unsigned long receptacleFlag = 1 << DISPLAYPORT_CAPABILITIES_RECEPTACLE_BIT; + + vdoString = Trim(vdoString); + if (ParseUint(vdoString.c_str(), &vdo)) { + /* We check to see if receptacleFlag is 0, meaning that the DP interface is presented on a + * USB-C plug. + */ + return !(vdo & receptacleFlag); + } else { + ALOGE("usbdp: isDisplayPortPlugHelper: errno:%d", errno); + } + + return false; +} + +AltModeData::DisplayPortAltModeData constructAltModeData(string hpd, string pin_assignment, + string link_status, string vdo) { + AltModeData::DisplayPortAltModeData dpData; + + // vdo + if (isDisplayPortPlugHelper(vdo)) { + dpData.cableStatus = DisplayPortAltModeStatus::CAPABLE; + } else { + dpData.partnerSinkStatus = DisplayPortAltModeStatus::CAPABLE; + } + + // hpd, status + if (!strncmp(hpd.c_str(), "1", strlen("1"))) { + dpData.hpd = true; + } + + // pin + dpData.pinAssignment = parsePinAssignmentHelper(pin_assignment); + + // link training + link_status = Trim(link_status); + dpData.linkTrainingStatus = parseLinkTrainingStatusHelper(link_status); + if (dpData.linkTrainingStatus == LinkTrainingStatus::SUCCESS) { + dpData.partnerSinkStatus = dpData.partnerSinkStatus == DisplayPortAltModeStatus::CAPABLE ? \ + DisplayPortAltModeStatus::ENABLED : DisplayPortAltModeStatus::UNKNOWN; + dpData.cableStatus = dpData.cableStatus == DisplayPortAltModeStatus::CAPABLE ? \ + DisplayPortAltModeStatus::ENABLED : DisplayPortAltModeStatus::UNKNOWN; + if (dpData.partnerSinkStatus == DisplayPortAltModeStatus::ENABLED) { + dpData.cableStatus = DisplayPortAltModeStatus::ENABLED; + } + } else if (dpData.linkTrainingStatus == LinkTrainingStatus::FAILURE && + dpData.partnerSinkStatus == DisplayPortAltModeStatus::CAPABLE) { + // 2.0 cable that fails EDID reports not capable, other link training failures assume + // 3.0 cable that fails in all other cases. + dpData.cableStatus = (link_status == LINK_TRAINING_STATUS_FAILURE_SINK) ? \ + DisplayPortAltModeStatus::NOT_CAPABLE : DisplayPortAltModeStatus::CAPABLE; + } + + return dpData; +} + +/* DisplayPort Helper Functions End */ + +// Only care about first port which must support DisplayPortAltMode +Status queryDisplayPortStatus(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + string hpd, pinAssign, linkStatus, vdo; + string path; + AltModeData::DisplayPortAltModeData dpData; + + if (usb->getDisplayPortUsbPathHelper(&path) == Status::ERROR) { + (*currentPortStatus)[0].supportedAltModes.push_back(dpData); + return Status::SUCCESS; + } + + usb->readDisplayPortAttribute("hpd", path, &hpd); + usb->readDisplayPortAttribute("pin_assignment", path, &pinAssign); + usb->readDisplayPortAttribute("vdo", path, &vdo); + usb->readDisplayPortAttribute("link_status", path, &linkStatus); + + // Set DisplayPortAltModeInfo + dpData = constructAltModeData(hpd, pinAssign, linkStatus, vdo); + (*currentPortStatus)[0].supportedAltModes.push_back(dpData); + + return Status::SUCCESS; +} + void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus) { Status status; @@ -844,7 +965,7 @@ void queryVersionHelper(android::hardware::usb::Usb *usb, usb->setupDisplayPortPoll(); } pthread_mutex_unlock(&usb->mDisplayPortLock); - + queryDisplayPortStatus(usb, currentPortStatus); if (usb->mCallback != NULL) { ScopedAStatus ret = usb->mCallback->notifyPortStatusChange(*currentPortStatus, status); @@ -1297,6 +1418,30 @@ Status Usb::getDisplayPortUsbPathHelper(string *path) { return result; } +Status Usb::readDisplayPortAttribute(string attribute, string usb_path, string* value) { + string attrPath; + + if (!strncmp(attribute.c_str(), "hpd", strlen("hpd")) || + !strncmp(attribute.c_str(), "pin_assignment", strlen("pin_assignment"))) { + attrPath = usb_path + attribute; + } else if (!strncmp(attribute.c_str(), "link_status", strlen("link_status"))) { + attrPath = string(kDisplayPortDrmPath) + "link_status"; + } else if (!strncmp(attribute.c_str(), "vdo", strlen("vdo"))) { + attrPath = usb_path + "/../vdo"; + } else { + goto error; + } + + // Read Attribute + if(ReadFileToString(attrPath.c_str(), value)) { + return Status::SUCCESS; + } + +error: + ALOGE("usbdp: Failed to read Type-C attribute %s", attribute.c_str()); + return Status::ERROR; +} + Status Usb::writeDisplayPortAttributeOverride(string attribute, string value) { string attrDrmPath; @@ -1394,15 +1539,28 @@ static int displayPortPollOpenFileHelper(const char *file, int flags) { return fd; } +static int armTimerFdHelper(int fd, int ms) { + struct itimerspec ts; + + ts.it_interval.tv_sec = 0; + ts.it_interval.tv_nsec = 0; + ts.it_value.tv_sec = ms / 1000; + ts.it_value.tv_nsec = (ms % 1000) * 1000000; + + return timerfd_settime(fd, 0, &ts, NULL); +} + void *displayPortPollWork(void *param) { int epoll_fd; - struct epoll_event ev_hpd, ev_pin, ev_orientation, ev_eventfd, ev_link; + struct epoll_event ev_hpd, ev_pin, ev_orientation, ev_eventfd, ev_link, ev_debounce; int nevents = 0; - int hpd_fd, pin_fd, orientation_fd, link_fd; + int hpd_fd, pin_fd, orientation_fd, link_training_status_fd; int file_flags = O_RDONLY; int epoll_flags; bool orientationSet = false; bool pinSet = false; + unsigned long res; + int ret = 0; string displayPortUsbPath, irqHpdCountPath, hpdPath, pinAssignmentPath, orientationPath; string tcpcI2cBus, linkPath; ::aidl::android::hardware::usb::Usb *usb = (::aidl::android::hardware::usb::Usb *)param; @@ -1441,8 +1599,8 @@ void *displayPortPollWork(void *param) { == -1){ goto orientation_fd_error; } - if ((link_fd = displayPortPollOpenFileHelper(linkPath.c_str(), file_flags)) == -1){ - goto link_fd_error; + if ((link_training_status_fd = displayPortPollOpenFileHelper(linkPath.c_str(), file_flags)) == -1){ + goto link_training_status_fd_error; } // Set epoll_event events and flags @@ -1452,11 +1610,13 @@ void *displayPortPollWork(void *param) { ev_orientation.events = epoll_flags; ev_eventfd.events = epoll_flags; ev_link.events = epoll_flags; + ev_debounce.events = epoll_flags; ev_hpd.data.fd = hpd_fd; ev_pin.data.fd = pin_fd; ev_orientation.data.fd = orientation_fd; ev_eventfd.data.fd = usb->mDisplayPortEventPipe; - ev_link.data.fd = link_fd; + ev_link.data.fd = link_training_status_fd; + ev_debounce.data.fd = usb->mDisplayPortDebounceTimer; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, hpd_fd, &ev_hpd) == -1) { ALOGE("usbdp: worker: epoll_ctl failed to add hpd; errno=%d", errno); @@ -1470,10 +1630,14 @@ void *displayPortPollWork(void *param) { ALOGE("usbdp: worker: epoll_ctl failed to add orientation; errno=%d", errno); goto error; } - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, link_fd, &ev_link) == -1) { + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, link_training_status_fd, &ev_link) == -1) { ALOGE("usbdp: worker: epoll_ctl failed to add link status; errno=%d", errno); goto error; } + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, usb->mDisplayPortDebounceTimer, &ev_debounce) == -1) { + ALOGE("usbdp: worker: epoll_ctl failed to add debounce; errno=%d", errno); + goto error; + } if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, usb->mDisplayPortEventPipe, &ev_eventfd) == -1) { ALOGE("usbdp: worker: epoll_ctl failed to add orientation; errno=%d", errno); goto error; @@ -1506,16 +1670,28 @@ void *displayPortPollWork(void *param) { } } usb->writeDisplayPortAttribute("hpd", hpdPath); + armTimerFdHelper(usb->mDisplayPortDebounceTimer, DISPLAYPORT_STATUS_DEBOUNCE_MS); } else if (events[n].data.fd == pin_fd) { if (usb->writeDisplayPortAttribute("pin_assignment", pinAssignmentPath) == Status::SUCCESS) { pinSet = true; + armTimerFdHelper(usb->mDisplayPortDebounceTimer, DISPLAYPORT_STATUS_DEBOUNCE_MS); } } else if (events[n].data.fd == orientation_fd) { if (usb->writeDisplayPortAttribute("orientation", orientationPath) == Status::SUCCESS) { orientationSet = true; + armTimerFdHelper(usb->mDisplayPortDebounceTimer, DISPLAYPORT_STATUS_DEBOUNCE_MS); } + } else if (events[n].data.fd == link_training_status_fd) { + armTimerFdHelper(usb->mDisplayPortDebounceTimer, DISPLAYPORT_STATUS_DEBOUNCE_MS); + } else if (events[n].data.fd == usb->mDisplayPortDebounceTimer) { + std::vector currentPortStatus; + ret = read(usb->mDisplayPortDebounceTimer, &res, sizeof(res)); + ALOGI("usbdp: dp debounce triggered, val:%lu ret:%d", res, ret); + if (ret < 0) + ALOGE("usbdp: debounce read errno:%d", errno); + queryVersionHelper(usb, ¤tPortStatus); } else if (events[n].data.fd == usb->mDisplayPortEventPipe) { uint64_t flag = 0; if (!read(usb->mDisplayPortEventPipe, &flag, sizeof(flag))) { @@ -1537,14 +1713,15 @@ void *displayPortPollWork(void *param) { } error: - close(link_fd); -link_fd_error: + close(link_training_status_fd); +link_training_status_fd_error: close(orientation_fd); orientation_fd_error: close(pin_fd); pin_fd_error: close(hpd_fd); hpd_fd_error: + epoll_ctl(epoll_fd, EPOLL_CTL_DEL, usb->mDisplayPortDebounceTimer, &ev_debounce); epoll_ctl(epoll_fd, EPOLL_CTL_DEL, usb->mDisplayPortEventPipe, &ev_eventfd); close(epoll_fd); epoll_fd_error: diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index f6bbd695..566fc73c 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -29,6 +29,8 @@ // Having a margin of ~3 secs for the directory and other related bookeeping // structures created and uvent fired. #define PORT_TYPE_TIMEOUT 8 +#define DISPLAYPORT_CAPABILITIES_RECEPTACLE_BIT 6 +#define DISPLAYPORT_STATUS_DEBOUNCE_MS 2000 namespace aidl { namespace android { @@ -57,6 +59,11 @@ constexpr char kGadgetName[] = "11210000.dwc3"; #define VBUS_PATH NEW_UDC_PATH "dwc3_exynos_otg_b_sess" #define USB_DATA_PATH NEW_UDC_PATH "usb_data_enabled" +#define LINK_TRAINING_STATUS_UNKNOWN "0" +#define LINK_TRAINING_STATUS_SUCCESS "1" +#define LINK_TRAINING_STATUS_FAILURE "2" +#define LINK_TRAINING_STATUS_FAILURE_SINK "3" + #define DISPLAYPORT_SHUTDOWN_CLEAR 0 #define DISPLAYPORT_SHUTDOWN_SET 1 #define DISPLAYPORT_IRQ_HPD_COUNT_CHECK 3 @@ -81,6 +88,7 @@ struct Usb : public BnUsb { ScopedAStatus resetUsbPort(const string& in_portName, int64_t in_transactionId) override; Status getDisplayPortUsbPathHelper(string *path); + Status readDisplayPortAttribute(string attribute, string usb_path, string* value); Status writeDisplayPortAttributeOverride(string attribute, string value); Status writeDisplayPortAttribute(string attribute, string usb_path); bool determineDisplayPortRetry(string linkPath, string hpdPath); @@ -144,6 +152,14 @@ struct Usb : public BnUsb { }; std::map mEpollEntries; + /* + * eventfd to set DisplayPort framework update debounce timer. Debounce timer is necessary for + * 1) allowing enough time for each sysfs node needed to set HPD high in the drm to populate + * 2) preventing multiple IRQs that trigger link training failures from continuously + * sending notifications to the frameworks layer. + */ + int mDisplayPortDebounceTimer; + private: pthread_t mPoll; pthread_t mDisplayPortPoll; From 5749b85397a6196dec6800a8fdd19ea54c7d4c3d Mon Sep 17 00:00:00 2001 From: Avichal Rakesh Date: Wed, 12 Jul 2023 17:58:33 -0700 Subject: [PATCH 057/133] UsbGadget: Add support for UVC function UVC is a new USB function supported in Android. This CL adds UVC as a valid function and gives it a new pid of 0x4ee[de]. UVC function is guarded by the property `ro.usb.uvc.enabled`. When this property is set to false, UVC won't be considered as a valid gadget function. Bug: 242344221 Test: Manually tested that the UVC function is successfully configured Change-Id: I5c2040a84ee8360b16c955403478d908fe109121 --- usb/gadget/UsbGadget.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/usb/gadget/UsbGadget.cpp b/usb/gadget/UsbGadget.cpp index 70bd801f..c96c6c4d 100644 --- a/usb/gadget/UsbGadget.cpp +++ b/usb/gadget/UsbGadget.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include namespace aidl { @@ -34,6 +36,9 @@ namespace hardware { namespace usb { namespace gadget { +using ::android::base::GetBoolProperty; +using ::android::hardware::google::pixel::usb::kUvcEnabled; + string enabledPath; constexpr char kHsi2cPath[] = "/sys/devices/platform/10cb0000.hsi2c"; constexpr char kI2CPath[] = "/sys/devices/platform/10cb0000.hsi2c/i2c-"; @@ -302,6 +307,28 @@ static Status validateAndSetVidPid(uint64_t functions) { ret = Status(setVidPid("0x18d1", "0x4eec")); } break; + case GadgetFunction::UVC: + if (!(vendorFunctions == "user" || vendorFunctions == "")) { + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = Status::CONFIGURATION_NOT_SUPPORTED; + } else if (!GetBoolProperty(kUvcEnabled, false)) { + ALOGE("UVC function not enabled by config"); + ret = Status::CONFIGURATION_NOT_SUPPORTED; + } else { + ret = Status(setVidPid("0x18d1", "0x4eed")); + } + break; + case GadgetFunction::ADB | GadgetFunction::UVC: + if (!(vendorFunctions == "user" || vendorFunctions == "")) { + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = Status::CONFIGURATION_NOT_SUPPORTED; + } else if (!GetBoolProperty(kUvcEnabled, false)) { + ALOGE("UVC function not enabled by config"); + ret = Status::CONFIGURATION_NOT_SUPPORTED; + } else { + ret = Status(setVidPid("0x18d1", "0x4eee")); + } + break; default: ALOGE("Combination not supported"); ret = Status::CONFIGURATION_NOT_SUPPORTED; From 67cca6916daf433d36800d1dd57f13a68b59fb12 Mon Sep 17 00:00:00 2001 From: Avichal Rakesh Date: Wed, 12 Jul 2023 17:59:07 -0700 Subject: [PATCH 058/133] usb gadget: Add config for UVC in init The UVC gadget requires some setup in configfs before it can be used by the gadget HAL. This CL adds that setup to usb specific init.rc file. Currently, UVC is setup to advertise mjpeg streams at 720p, and 1080p. Bug: 242344221 Test: Manually tested that UVC is correctly set up on boot. Change-Id: I71cf4727fb23744c5aef368c1750784a19ba8c5d --- conf/init.zuma.usb.rc | 159 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/conf/init.zuma.usb.rc b/conf/init.zuma.usb.rc index 136382fe..8ff97433 100644 --- a/conf/init.zuma.usb.rc +++ b/conf/init.zuma.usb.rc @@ -71,6 +71,72 @@ on early-boot # acm function for uwb mkdir /config/usb_gadget/g1/functions/acm.uwb0 + # uvc function + mkdir /config/usb_gadget/g1/functions/uvc.0 + write /config/usb_gadget/g1/functions/uvc.0/function_name "Android Webcam" + write /config/usb_gadget/g1/functions/uvc.0/streaming_maxpacket 3072 + # write /config/usb_gadget/g1/functions/uvc.0/streaming_maxburst 5 + # write /config/usb_gadget/g1/functions/uvc.0/streaming_interval 2 + # setup control params + mkdir /config/usb_gadget/g1/functions/uvc.0/control/header/h + symlink /config/usb_gadget/g1/functions/uvc.0/control/header/h /config/usb_gadget/g1/functions/uvc.0/control/class/fs/h + symlink /config/usb_gadget/g1/functions/uvc.0/control/header/h /config/usb_gadget/g1/functions/uvc.0/control/class/ss/h + # advertise mjpeg streams + mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m + # advertise 720p resolution for webcam encoded as mjpeg + mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/wHeight 720 + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/wWidth 1280 + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMaxVideoFrameBufferSize 1843200 + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwDefaultFrameInterval 333333 + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwFrameInterval "166666 +333333 +416666 +666666" + # advertise 1080p resolution for webcam encoded as mjpeg + mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/wHeight 1080 + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/wWidth 1920 + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMaxVideoFrameBufferSize 4147200 + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwDefaultFrameInterval 333333 + write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwFrameInterval "166666 +333333 +416666 +666666" + # TODO: Add uncompressed streams + # setup streaming params + mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/header/h + symlink /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/m + symlink /config/usb_gadget/g1/functions/uvc.0/streaming/header/h /config/usb_gadget/g1/functions/uvc.0/streaming/class/fs/h + symlink /config/usb_gadget/g1/functions/uvc.0/streaming/header/h /config/usb_gadget/g1/functions/uvc.0/streaming/class/hs/h + symlink /config/usb_gadget/g1/functions/uvc.0/streaming/header/h /config/usb_gadget/g1/functions/uvc.0/streaming/class/ss/h + # remove write permissions for 'others' + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwFrameInterval + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwDefaultFrameInterval + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMaxVideoFrameBufferSize + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMaxBitRate + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMinBitRate + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/wHeight + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/wWidth + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/bmCapabilities + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwFrameInterval + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwDefaultFrameInterval + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMaxVideoFrameBufferSize + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMaxBitRate + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMinBitRate + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/wHeight + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/wWidth + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/bmCapabilities + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bmaControls + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bDefaultFrameIndex + chmod 664 /config/usb_gadget/g1/functions/uvc.0/control/terminal/output/default/bSourceID + chmod 664 /config/usb_gadget/g1/functions/uvc.0/control/header/h/dwClockFrequency + chmod 664 /config/usb_gadget/g1/functions/uvc.0/control/header/h/bcdUVC + chmod 664 /config/usb_gadget/g1/functions/uvc.0/function_name + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming_maxburst + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming_maxpacket + chmod 664 /config/usb_gadget/g1/functions/uvc.0/streaming_interval + # chown file/folder permission chown system system /config/usb_gadget/ chown system system /config/usb_gadget/g1 @@ -135,6 +201,99 @@ on early-boot chown system system /config/usb_gadget/g1/functions/rndis.gs4/protocol chown system system /config/usb_gadget/g1/functions/rndis.gs4/qmult chown system system /config/usb_gadget/g1/functions/rndis.gs4/subclass + chown system system /config/usb_gadget/g1/functions/uvc.0/ + chown system system /config/usb_gadget/g1/functions/uvc.0/control + chown system system /config/usb_gadget/g1/functions/uvc.0/control/bInterfaceNumber + chown system system /config/usb_gadget/g1/functions/uvc.0/control/class + chown system system /config/usb_gadget/g1/functions/uvc.0/control/class/fs + chown system system /config/usb_gadget/g1/functions/uvc.0/control/class/fs/h + chown system system /config/usb_gadget/g1/functions/uvc.0/control/class/ss + chown system system /config/usb_gadget/g1/functions/uvc.0/control/class/ss/h + chown system system /config/usb_gadget/g1/functions/uvc.0/control/header + chown system system /config/usb_gadget/g1/functions/uvc.0/control/header/h + chown system system /config/usb_gadget/g1/functions/uvc.0/control/header/h/bcdUVC + chown system system /config/usb_gadget/g1/functions/uvc.0/control/header/h/dwClockFrequency + chown system system /config/usb_gadget/g1/functions/uvc.0/control/processing + chown system system /config/usb_gadget/g1/functions/uvc.0/control/processing/default + chown system system /config/usb_gadget/g1/functions/uvc.0/control/processing/default/bmControls + chown system system /config/usb_gadget/g1/functions/uvc.0/control/processing/default/bSourceID + chown system system /config/usb_gadget/g1/functions/uvc.0/control/processing/default/bUnitID + chown system system /config/usb_gadget/g1/functions/uvc.0/control/processing/default/iProcessing + chown system system /config/usb_gadget/g1/functions/uvc.0/control/processing/default/wMaxMultiplier + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default/bAssocTerminal + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default/bmControls + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default/bTerminalID + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default/iTerminal + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default/wObjectiveFocalLengthMax + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default/wObjectiveFocalLengthMin + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default/wOcularFocalLength + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/camera/default/wTerminalType + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/output + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/output/default + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/output/default/bAssocTerminal + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/output/default/bSourceID + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/output/default/bTerminalID + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/output/default/iTerminal + chown system system /config/usb_gadget/g1/functions/uvc.0/control/terminal/output/default/wTerminalType + chown system system /config/usb_gadget/g1/functions/uvc.0/function_name + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming_interval + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming_maxburst + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming_maxpacket + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/bInterfaceNumber + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/class + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/class/fs + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/class/fs/h + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/class/hs + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/class/hs/h + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/class/ss + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/class/ss/h + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/color_matching + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/color_matching/default + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/color_matching/default/bColorPrimaries + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/color_matching/default/bMatrixCoefficients + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/color_matching/default/bTransferCharacteristics + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/header + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/header/h + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/bmInfo + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/bStillCaptureMethod + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/bTerminalLink + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/bTriggerSupport + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/bTriggerUsage + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/m + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/bFrameIndex + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/bmCapabilities + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwDefaultFrameInterval + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwFrameInterval + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMaxBitRate + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMaxVideoFrameBufferSize + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMinBitRate + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/wHeight + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/wWidth + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/bFrameIndex + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/bmCapabilities + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwDefaultFrameInterval + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwFrameInterval + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMaxBitRate + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMaxVideoFrameBufferSize + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMinBitRate + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/wHeight + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/wWidth + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bAspectRatioX + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bAspectRatioY + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bDefaultFrameIndex + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bFormatIndex + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bmaControls + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bmFlags + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bmInterlaceFlags + chown system system /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed chown system system /config/usb_gadget/g1/idProduct chown system system /config/usb_gadget/g1/idVendor chown system system /config/usb_gadget/g1/max_speed From d7963d35374bb66decbb355ec93eb550ba26f12d Mon Sep 17 00:00:00 2001 From: Klines Jiang Date: Tue, 22 Aug 2023 03:11:36 +0000 Subject: [PATCH 059/133] [SELinux] Add gyotaku_app doamin to Pixel 2023. Bug: 296836878 Test: Local build and tested pass. Change-Id: I58d9fb298477cc67ec2cd4a308be679e2e75c98d --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index 3ceb4517..d24f0365 100644 --- a/device.mk +++ b/device.mk @@ -39,6 +39,7 @@ include device/google/gs-common/umfw_stat/umfw_stat.mk include device/google/gs-common/widevine/widevine.mk include device/google/gs-common/sota_app/factoryota.mk include device/google/gs-common/misc_writer/misc_writer.mk +include device/google/gs-common/gyotaku_app/gyotaku.mk include device/google/zuma/dumpstate/item.mk From 5aded2ebfe6f3914980a35bb99a3c2fb475fd7f8 Mon Sep 17 00:00:00 2001 From: Hiroshi Akiyama Date: Mon, 22 May 2023 17:35:45 +0000 Subject: [PATCH 060/133] Migrate dump_power.sh contents into cpp for improved speed Bug: 271355543 Test: adb bugreport and check dumpstate_board.txt Change-Id: Ic4e7c1a8198aedc3d2f5b3880ce60aa45843ec2d --- dumpstate/Android.bp | 18 +- dumpstate/dump_power.cpp | 872 +++++++++++++++++++++++++++++++++++++++ dumpstate/dump_power.sh | 421 ------------------- dumpstate/item.mk | 2 +- 4 files changed, 887 insertions(+), 426 deletions(-) create mode 100644 dumpstate/dump_power.cpp delete mode 100644 dumpstate/dump_power.sh diff --git a/dumpstate/Android.bp b/dumpstate/Android.bp index a7c373e8..8960ac43 100644 --- a/dumpstate/Android.bp +++ b/dumpstate/Android.bp @@ -9,11 +9,21 @@ sh_binary { sub_dir: "dump", } -sh_binary { - name: "dump_power.sh", - src: "dump_power.sh", +cc_binary { + name: "dump_power", + srcs: ["dump_power.cpp"], + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], + shared_libs: [ + "libbase", + "libdump", + "libdumpstateutil", + ], vendor: true, - sub_dir: "dump", + relative_install_path: "dump", } sh_binary { diff --git a/dumpstate/dump_power.cpp b/dumpstate/dump_power.cpp new file mode 100644 index 00000000..e7ab364c --- /dev/null +++ b/dumpstate/dump_power.cpp @@ -0,0 +1,872 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "DumpstateUtil.h" + + +void printTitle(const char *msg) { + printf("\n------ %s ------\n", msg); +} + +int getCommandOutput(const char *cmd, std::string *output) { + char buffer[1024]; + FILE *pipe = popen(cmd, "r"); + if (!pipe) { + return -1; + } + + while (fgets(buffer, sizeof buffer, pipe) != NULL) { + *output += buffer; + } + pclose(pipe); + + if (output->back() == '\n') + output->pop_back(); + + return 0; +} + +bool isValidFile(const char *file) { + if (!access(file, R_OK)) { + return false; + } + return true; +} + +bool isUserBuild() { + return ::android::os::dumpstate::PropertiesHelper::IsUserBuild(); +} + +int getFilesInDir(const char *directory, std::vector *files) { + std::string content; + struct dirent *entry; + + DIR *dir = opendir(directory); + if (dir == NULL) + return -1; + + files->clear(); + while ((entry = readdir(dir)) != NULL) + files->push_back(entry->d_name); + closedir(dir); + + sort(files->begin(), files->end()); + return 0; +} + +void dumpPowerStatsTimes() { + const char *title = "Power Stats Times"; + char rBuff[128]; + struct timespec rTs; + struct sysinfo info; + int ret; + + printTitle(title); + + sysinfo(&info); + + const time_t boottime = time(NULL) - info.uptime; + + ret = clock_gettime(CLOCK_REALTIME, &rTs); + if (ret) + return; + + struct tm *nowTime = std::localtime(&rTs.tv_sec); + + std::strftime(rBuff, sizeof(rBuff), "%m/%d/%Y %H:%M:%S", nowTime); + printf("Boot: %s", ctime(&boottime)); + printf("Now: %s\n", rBuff); +} + +int readContentsOfDir(const char* title, const char* directory, const char* strMatch, + bool useStrMatch = false, bool printDirectory = false) { + std::vector files; + std::string content; + std::string fileLocation; + int ret; + + ret = getFilesInDir(directory, &files); + if (ret < 0) + return ret; + + printTitle(title); + for (auto &file : files) { + if (useStrMatch && std::string::npos == std::string(file).find(strMatch)) { + continue; + } + + fileLocation = std::string(directory) + std::string(file); + if (!android::base::ReadFileToString(fileLocation, &content)) { + continue; + } + if (printDirectory) { + printf("\n\n%s\n", fileLocation.c_str()); + } + if (content.back() == '\n') + content.pop_back(); + printf("%s\n", content.c_str()); + } + return 0; +} + +void dumpAcpmStats() { + const char* acpmDir = "/sys/devices/platform/acpm_stats/"; + const char* statsSubStr = "_stats"; + const char* acpmTitle = "ACPM stats"; + readContentsOfDir(acpmTitle, acpmDir, statsSubStr, true, true); +} + +void dumpPowerSupplyStats() { + const char* dumpList[][2] = { + {"CPU PM stats", "/sys/devices/system/cpu/cpupm/cpupm/time_in_state"}, + {"GENPD summary", "/d/pm_genpd/pm_genpd_summary"}, + {"Power supply property battery", "/sys/class/power_supply/battery/uevent"}, + {"Power supply property dc", "/sys/class/power_supply/dc/uevent"}, + {"Power supply property gcpm", "/sys/class/power_supply/gcpm/uevent"}, + {"Power supply property gcpm_pps", "/sys/class/power_supply/gcpm_pps/uevent"}, + {"Power supply property main-charger", "/sys/class/power_supply/main-charger/uevent"}, + {"Power supply property dc-mains", "/sys/class/power_supply/dc-mains/uevent"}, + {"Power supply property tcpm", "/sys/class/power_supply/tcpm-source-psy-8-0025/uevent"}, + {"Power supply property usb", "/sys/class/power_supply/usb/uevent"}, + {"Power supply property wireless", "/sys/class/power_supply/wireless/uevent"}, + }; + + for (const auto &row : dumpList) { + dumpFileContent(row[0], row[1]); + } +} + +void dumpMaxFg() { + const char *maxfgLoc = "/sys/class/power_supply/maxfg"; + + const char *maxfg [][2] = { + {"Power supply property maxfg", "/sys/class/power_supply/maxfg/uevent"}, + {"m5_state", "/sys/class/power_supply/maxfg/m5_model_state"}, + {"maxfg", "/dev/logbuffer_maxfg"}, + {"maxfg", "/dev/logbuffer_maxfg_monitor"}, + }; + + const char *maxfgFlip [][2] = { + {"Power supply property maxfg_base", "/sys/class/power_supply/maxfg_base/uevent"}, + {"Power supply property maxfg_flip", "/sys/class/power_supply/maxfg_flip/uevent"}, + {"m5_state", "/sys/class/power_supply/maxfg_base/m5_model_state"}, + {"maxfg_base", "/dev/logbuffer_maxfg_base"}, + {"maxfg_flip", "/dev/logbuffer_maxfg_flip"}, + {"maxfg_base", "/dev/logbuffer_maxfg_base_monitor"}, + {"maxfg_flip", "/dev/logbuffer_maxfg_flip_monitor"}, + }; + + const char *maxfgHistoryName = "Maxim FG History"; + const char *maxfgHistoryDir = "/dev/maxfg_history"; + + std::string content; + + + if (isValidFile(maxfgLoc)) { + for (const auto &row : maxfg) { + dumpFileContent(row[0], row[1]); + } + } else { + for (const auto &row : maxfgFlip) { + dumpFileContent(row[0], row[1]); + } + } + + if (isValidFile(maxfgHistoryDir)) { + dumpFileContent(maxfgHistoryName, maxfgHistoryDir); + } +} + +void dumpPowerSupplyDock() { + const char* powerSupplyPropertyDockTitle = "Power supply property dock"; + const char* powerSupplyPropertyDockFile = "/sys/class/power_supply/dock/uevent"; + dumpFileContent(powerSupplyPropertyDockTitle, powerSupplyPropertyDockFile); +} + +void dumpLogBufferTcpm() { + const char* logbufferTcpmTitle = "Logbuffer TCPM"; + const char* logbufferTcpmFile = "/dev/logbuffer_tcpm"; + const char* debugTcpmFile = "/sys/kernel/debug/tcpm"; + const char* tcpmLogTitle = "TCPM logs"; + const char* tcpmFile = "/sys/kernel/debug/tcpm"; + const char* tcpmFileAlt = "/sys/kernel/debug/usb/tcpm"; + int retCode; + + dumpFileContent(logbufferTcpmTitle, logbufferTcpmFile); + + retCode = readContentsOfDir(tcpmLogTitle, isValidFile(debugTcpmFile) ? tcpmFile : tcpmFileAlt, + NULL); + if (retCode < 0) + printTitle(tcpmLogTitle); +} + +void dumpTcpc() { + int ret; + const char* max77759TcpcHead = "TCPC"; + const char* i2cSubDirMatch = "i2c-"; + const char* directory = "/sys/devices/platform/10d60000.hsi2c/"; + const char* max77759Tcpc [][2] { + {"registers:", "/i2c-max77759tcpc/registers"}, + {"frs:", "/i2c-max77759tcpc/frs"}, + {"auto_discharge:", "/i2c-max77759tcpc/auto_discharge"}, + {"bcl2_enabled:", "/i2c-max77759tcpc/bcl2_enabled"}, + {"cc_toggle_enable:", "/i2c-max77759tcpc/cc_toggle_enable"}, + {"containment_detection:", "/i2c-max77759tcpc/containment_detection"}, + {"containment_detection_status:", "/i2c-max77759tcpc/containment_detection_status"}, + }; + + std::vector files; + std::string content; + + printTitle(max77759TcpcHead); + + ret = getFilesInDir(directory, &files); + if (ret < 0) { + for (auto &tcpcVal : max77759Tcpc) + printf("%s\n", tcpcVal[0]); + return; + } + + for (auto &file : files) { + for (auto &tcpcVal : max77759Tcpc) { + printf("%s ", tcpcVal[0]); + if (std::string::npos == std::string(file).find(i2cSubDirMatch)) { + continue; + } + + std::string fileName = directory + file + "/" + std::string(tcpcVal[1]); + + if (!android::base::ReadFileToString(fileName, &content)) { + continue; + } + + printf("%s\n", content.c_str()); + } + } +} + +void dumpPdEngine() { + const char* pdEngine [][2] { + {"PD Engine", "/dev/logbuffer_usbpd"}, + {"PPS-google_cpm", "/dev/logbuffer_cpm"}, + {"PPS-dc", "/dev/logbuffer_pca9468"}, + }; + + for (const auto &row : pdEngine) { + dumpFileContent(row[0], row[1]); + } +} + +void dumpWc68() { + const char* wc68Title = "WC68"; + const char* wc68File = "/dev/logbuffer_wc68"; + + dumpFileContent(wc68Title, wc68File); +} + +void dumpLn8411() { + const char* ln8411Title = "LN8411"; + const char* ln8411File = "/dev/logbuffer_ln8411"; + + dumpFileContent(ln8411Title, ln8411File); +} + +void dumpBatteryHealth() { + const char* batteryHealth [][2] { + {"Battery Health", "/sys/class/power_supply/battery/health_index_stats"}, + {"BMS", "/dev/logbuffer_ssoc"}, + {"TTF", "/dev/logbuffer_ttf"}, + {"TTF details", "/sys/class/power_supply/battery/ttf_details"}, + {"TTF stats", "/sys/class/power_supply/battery/ttf_stats"}, + {"aacr_state", "/sys/class/power_supply/battery/aacr_state"}, + {"maxq", "/dev/logbuffer_maxq"}, + {"TEMP/DOCK-DEFEND", "/dev/logbuffer_bd"}, + }; + + for (const auto &row : batteryHealth) { + dumpFileContent(row[0], row[1]); + } +} + +void dumpBatteryDefend() { + const char* defendConfig [][3] { + {"TRICKLE-DEFEND Config", + "/sys/devices/platform/google,battery/power_supply/battery/", "bd_"}, + {"DWELL-DEFEND Config", "/sys/devices/platform/google,charger/", "charge_s"}, + {"TEMP-DEFEND Config", "/sys/devices/platform/google,charger/", "bd_"}, + }; + + std::vector files; + struct dirent *entry; + std::string content; + std::string fileLocation; + + for (auto &config : defendConfig) { + DIR *dir = opendir(config[1]); + if (dir == NULL) + continue; + + printTitle(config[0]); + while ((entry = readdir(dir)) != NULL) { + if (std::string(entry->d_name).find(config[2]) != std::string::npos && + strncmp(config[2], entry->d_name, strlen(config[2])) == 0) { + files.push_back(entry->d_name); + } + } + closedir(dir); + + sort(files.begin(), files.end()); + + for (auto &file : files) { + fileLocation = std::string(config[1]) + std::string(file); + if (!android::base::ReadFileToString(fileLocation, &content)) { + content = "\n"; + } + + printf("%s: %s", file.c_str(), content.c_str()); + + if (content.back() != '\n') + printf("\n"); + } + + files.clear(); + } +} + +void dumpChgUserDebug() { + std::vector files; + struct dirent *entry; + std::string content; + + const char *chgUserDebug [][2] { + {"DC_registers dump", "/sys/class/power_supply/dc-mains/device/registers_dump"}, + {"max77759_chg registers dump", "/d/max77759_chg/registers"}, + {"max77729_pmic registers dump", "/d/max77729_pmic/registers"}, + {"Charging table dump", "/d/google_battery/chg_raw_profile"}, + }; + + const std::string debugfs = "/d/"; + const char *maxFgStrMatch = "maxfg"; + + const char *fgInfo [][2] { + {"fg_model", "fg_model"}, + {"fg_alo_ver", "algo_ver"}, + {"fg_model_ok", "model_ok"}, + {"fg registers", "registers"}, + {"Maxim FG NV RAM", "nv_registers"}, + }; + + if (!isUserBuild()) + return; + + for (auto &row : chgUserDebug) { + dumpFileContent(row[0], row[1]); + } + + for (auto &info : fgInfo) { + DIR *dir = opendir(debugfs.c_str()); + if (dir == NULL) + return; + + printTitle(info[0]); + while ((entry = readdir(dir)) != NULL) + if (std::string(entry->d_name).find(maxFgStrMatch) != std::string::npos) + files.push_back(entry->d_name); + closedir(dir); + + sort(files.begin(), files.end()); + + for (auto &file : files) { + std::string fileDirectory = debugfs + file; + std::string fileLocation = fileDirectory + "/" + std::string(info[1]); + if (!android::base::ReadFileToString(fileLocation, &content)) { + content = "\n"; + } + + printf("%s:\n%s", fileDirectory.c_str(), content.c_str()); + + if (content.back() != '\n') + printf("\n"); + } + files.clear(); + } +} + +void dumpBatteryEeprom() { + const char *title = "Battery EEPROM"; + const char *files[] { + "/sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom", + "/sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom", + "/sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom", + "/sys/devices/platform/10da0000.hsi2c/i2c-7/7-0050/eeprom", + "/sys/devices/platform/10c90000.hsi2c/i2c-7/7-0050/eeprom", + "/sys/devices/platform/10c90000.hsi2c/i2c-6/6-0050/eeprom", + }; + std::string result; + std::string xxdCmd; + + printTitle(title); + for (auto &file : files) { + if (!isValidFile(file)) + continue; + + xxdCmd = "xxd " + std::string(file); + + int ret = getCommandOutput(xxdCmd.c_str(), &result); + if (ret < 0) + return; + + printf("%s\n", result.c_str()); + } +} + +void dumpChargerStats() { + const char *chgStatsTitle = "Charger Stats"; + const char *chgStatsLocation = "/sys/class/power_supply/battery/charge_details"; + const char *chargerStats [][3] { + {"Google Charger", "/sys/kernel/debug/google_charger/", "pps_"}, + {"Google Battery", "/sys/kernel/debug/google_battery/", "ssoc_"}, + }; + std::vector files; + std::string content; + struct dirent *entry; + + dumpFileContent(chgStatsTitle, chgStatsLocation); + + if (!isUserBuild()) + return; + + for (auto &stat : chargerStats) { + DIR *dir = opendir(stat[1]); + if (dir == NULL) + return; + + printTitle(stat[0]); + while ((entry = readdir(dir)) != NULL) + if (std::string(entry->d_name).find(stat[2]) != std::string::npos) + files.push_back(entry->d_name); + closedir(dir); + + sort(files.begin(), files.end()); + + for (auto &file : files) { + std::string fileLocation = std::string(stat[1]) + file; + if (!android::base::ReadFileToString(fileLocation, &content)) { + content = "\n"; + } + + printf("%s: %s", file.c_str(), content.c_str()); + + if (content.back() != '\n') + printf("\n"); + } + files.clear(); + } +} + +void dumpWlcLogs() { + const char *dumpWlcList [][2] { + {"WLC Logs", "/dev/logbuffer_wireless"}, + {"WLC VER", "/sys/class/power_supply/wireless/device/version"}, + {"WLC STATUS", "/sys/class/power_supply/wireless/device/status"}, + {"WLC FW Version", "/sys/class/power_supply/wireless/device/fw_rev"}, + {"RTX", "/dev/logbuffer_rtx"}, + }; + + for (auto &row : dumpWlcList) { + if (!isValidFile(row[1])) + printTitle(row[0]); + dumpFileContent(row[0], row[1]); + } +} + +void dumpGvoteables() { + const char *directory = "/sys/kernel/debug/gvotables/"; + const char *statusName = "/status"; + const char *title = "gvotables"; + std::string content; + std::vector files; + int ret; + + if (!isUserBuild()) + return; + + ret = getFilesInDir(directory, &files); + if (ret < 0) + return; + + printTitle(title); + for (auto &file : files) { + std::string fileLocation = std::string(directory) + file + std::string(statusName); + if (!android::base::ReadFileToString(fileLocation, &content)) { + continue; + } + + printf("%s: %s", file.c_str(), content.c_str()); + + if (content.back() != '\n') + printf("\n"); + } + files.clear(); +} + +void dumpMitigation() { + const char *mitigationList [][2] { + {"Lastmeal" , "/data/vendor/mitigation/lastmeal.txt"}, + {"Thismeal" , "/data/vendor/mitigation/thismeal.txt"}, + }; + + for (auto &row : mitigationList) { + if (!isValidFile(row[1])) + printTitle(row[0]); + dumpFileContent(row[0], row[1]); + } +} + +void dumpMitigationStats() { + int ret; + const char *directory = "/sys/devices/virtual/pmic/mitigation/last_triggered_count/"; + const char *capacityDirectory = "/sys/devices/virtual/pmic/mitigation/last_triggered_capacity/"; + const char *timestampDirectory = + "/sys/devices/virtual/pmic/mitigation/last_triggered_timestamp/"; + const char *voltageDirectory = "/sys/devices/virtual/pmic/mitigation/last_triggered_voltage/"; + const char *capacitySuffix = "_cap"; + const char *timeSuffix = "_time"; + const char *voltageSuffix = "_volt"; + const char *countSuffix = "_count"; + const char *title = "Mitigation Stats"; + + std::vector files; + std::string content; + std::string fileLocation; + std::string source; + std::string subModuleName; + int count; + int soc; + int time; + int voltage; + + ret = getFilesInDir(directory, &files); + if (ret < 0) + return; + + printTitle(title); + printf("Source\t\tCount\tSOC\tTime\tVoltage\n"); + + for (auto &file : files) { + fileLocation = std::string(directory) + std::string(file); + if (!android::base::ReadFileToString(fileLocation, &content)) { + continue; + } + + ret = atoi(android::base::Trim(content).c_str()); + if (ret == -1) + continue; + count = ret; + + subModuleName = std::string(file); + subModuleName.erase(subModuleName.find(countSuffix), strlen(countSuffix)); + + fileLocation = std::string(capacityDirectory) + std::string(subModuleName) + + std::string(capacitySuffix); + if (!android::base::ReadFileToString(fileLocation, &content)) { + continue; + } + ret = atoi(android::base::Trim(content).c_str()); + if (ret == -1) + continue; + soc = ret; + + fileLocation = std::string(timestampDirectory) + std::string(subModuleName) + + std::string(timeSuffix); + if (!android::base::ReadFileToString(fileLocation, &content)) { + continue; + } + ret = atoi(android::base::Trim(content).c_str()); + if (ret == -1) + continue; + time = ret; + + fileLocation = std::string(voltageDirectory) + std::string(subModuleName) + + std::string(voltageSuffix); + if (!android::base::ReadFileToString(fileLocation, &content)) { + continue; + } + ret = atoi(android::base::Trim(content).c_str()); + if (ret == -1) + continue; + voltage = ret; + printf("%s \t%i\t%i\t%i\t%i\n", subModuleName.c_str(), count, soc, time, voltage); + } +} + +void dumpMitigationDirs() { + const int paramCount = 4; + const char *titles[] = { + "Clock Divider Ratio", + "Clock Stats", + "Triggered Level", + "Instruction", + }; + const char *directories[] = { + "/sys/devices/virtual/pmic/mitigation/clock_ratio/", + "/sys/devices/virtual/pmic/mitigation/clock_stats/", + "/sys/devices/virtual/pmic/mitigation/triggered_lvl/", + "/sys/devices/virtual/pmic/mitigation/instruction/", + }; + const char *paramSuffix[] = {"_ratio", "_stats", "_lvl", ""}; + const char *titleRowVal[] = { + "Source\t\tRatio", + "Source\t\tStats", + "Source\t\tLevel", + "", + }; + const int eraseCnt[] = {6, 6, 4, 0}; + const bool useTitleRow[] = {true, true, true, false}; + + std::vector files; + std::string content; + std::string fileLocation; + std::string source; + std::string subModuleName; + std::string readout; + + for (int i = 0; i < paramCount; i++) { + printTitle(titles[i]); + if (useTitleRow[i]) { + printf("%s\n", titleRowVal[i]); + } + + getFilesInDir(directories[i], &files); + + for (auto &file : files) { + fileLocation = std::string(directories[i]) + std::string(file); + if (!android::base::ReadFileToString(fileLocation, &content)) { + continue; + } + + readout = android::base::Trim(content); + + subModuleName = std::string(file); + subModuleName.erase(subModuleName.find(paramSuffix[i]), eraseCnt[i]); + + if (useTitleRow[i]) { + printf("%s \t%s\n", subModuleName.c_str(), readout.c_str()); + } else { + printf("%s=%s\n", subModuleName.c_str(), readout.c_str()); + } + } + } +} + +void dumpIrqDurationCounts() { + const char *title = "IRQ Duration Counts"; + const char *colNames = "Source\t\t\t\tlt_5ms_cnt\tbt_5ms_to_10ms_cnt\tgt_10ms_cnt\tCode" + "\tCurrent Threshold (uA)\tCurrent Reading (uA)\n"; + const int nonOdpmChannelCnt = 9; + const int odpmChCnt = 12; + + enum Duration { + LT_5MS, + BT_5MS_10MS, + GT_10MS, + DUR_MAX, + }; + const char *irqDurDirectories[] = { + "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/less_than_5ms_count", + "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/between_5ms_to_10ms_count", + "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt/greater_than_10ms_count", + }; + + enum PowerWarn { + MAIN, + SUB, + PWRWARN_MAX, + }; + const char *pwrwarnDirectories[] = { + "/sys/devices/virtual/pmic/mitigation/main_pwrwarn/", + "/sys/devices/virtual/pmic/mitigation/sub_pwrwarn/", + }; + + const char *lpfCurrentDirs[] = { + "/sys/devices/platform/acpm_mfd_bus@15500000/i2c-1/1-001f/s2mpg14-meter/" + "s2mpg14-odpm/iio:device1/lpf_current", + "/sys/devices/platform/acpm_mfd_bus@15510000/i2c-0/0-002f/s2mpg15-meter/" + "s2mpg15-odpm/iio:device0/lpf_current", + }; + + bool titlesInitialized = false; + + std::vector channelNames; + std::vector channelData[DUR_MAX]; + std::vector pwrwarnThreshold[PWRWARN_MAX]; + std::vector pwrwarnCode[PWRWARN_MAX]; + std::vector lpfCurrentVals[PWRWARN_MAX]; + std::vector files; + + std::string content; + std::string token; + std::string tokenCh; + std::string fileLocation; + + for (int i = 0; i < DUR_MAX; i++) { + if (!android::base::ReadFileToString(irqDurDirectories[i], &content)) { + return; + } + + std::istringstream tokenStream(content); + + while (std::getline(tokenStream, token, '\n')) { + if (!titlesInitialized) { + tokenCh = token; + tokenCh.erase(tokenCh.find(':'), tokenCh.length()); + channelNames.push_back(tokenCh); + } + + // there is a space after the ':' which needs to be removed + token.erase(0, token.find(':') + 1); + channelData[i].push_back(token); + + } + if (!titlesInitialized) + titlesInitialized = true; + } + + for (int i = 0; i < PWRWARN_MAX; i++) { + getFilesInDir(pwrwarnDirectories[i], &files); + + for (auto &file : files) { + fileLocation = std::string(pwrwarnDirectories[i]) + std::string(file); + if (!android::base::ReadFileToString(fileLocation, &content)) { + continue; + } + + std::string readout; + + readout = android::base::Trim(content); + + std::string readoutThreshold = readout; + readoutThreshold.erase(0, readoutThreshold.find('=') + 1); + + std::string readoutCode = readout; + readoutCode.erase(readoutCode.find('='), readoutCode.length()); + + pwrwarnThreshold[i].push_back(readoutThreshold); + pwrwarnCode[i].push_back(readoutCode); + } + } + + for (int i = 0; i < PWRWARN_MAX; i++) { + if (!android::base::ReadFileToString(lpfCurrentDirs[i], &content)) { + continue; + } + + std::istringstream tokenStream(content); + + bool first = true; + while (std::getline(tokenStream, token, '\n')) { + token.erase(0, token.find(' ')); + if (first) { + first = false; + continue; + } + lpfCurrentVals[i].push_back(token); + } + } + + printTitle(title); + printf("%s", colNames); + + for (uint i = 0; i < channelNames.size(); i++) { + std::string code = ""; + std::string threshold = ""; + std::string current = ""; + std::string ltDataMsg = ""; + std::string btDataMsg = ""; + std::string gtDataMsg = ""; + int pmicSel = 0; + int offset = 0; + std::string channelNameSuffix = " \t"; + if (i >= nonOdpmChannelCnt) { + offset = nonOdpmChannelCnt; + if (i >= (odpmChCnt + nonOdpmChannelCnt)) { + pmicSel = 1; + offset = odpmChCnt + nonOdpmChannelCnt; + } + channelNameSuffix = ""; + + code = pwrwarnCode[pmicSel][i - offset]; + threshold = pwrwarnThreshold[pmicSel][i - offset]; + current = lpfCurrentVals[pmicSel][i - offset]; + } + + if (i < channelData[0].size()) + ltDataMsg = channelData[0][i]; + + if (i < channelData[1].size()) + btDataMsg = channelData[1][i]; + + if (i < channelData[2].size()) + gtDataMsg = channelData[2][i]; + + std::string adjustedChannelName = channelNames[i] + channelNameSuffix; + printf("%s \t%s\t\t%s\t\t\t%s\t\t%s \t%s \t\t%s\n", + adjustedChannelName.c_str(), + ltDataMsg.c_str(), + btDataMsg.c_str(), + gtDataMsg.c_str(), + code.c_str(), + threshold.c_str(), + current.c_str()); + } +} + +int main() { + dumpPowerStatsTimes(); + dumpAcpmStats(); + dumpPowerSupplyStats(); + dumpMaxFg(); + dumpPowerSupplyDock(); + dumpLogBufferTcpm(); + dumpTcpc(); + dumpPdEngine(); + dumpWc68(); + dumpLn8411(); + dumpBatteryHealth(); + dumpBatteryDefend(); + dumpChgUserDebug(); + dumpBatteryEeprom(); + dumpChargerStats(); + dumpWlcLogs(); + dumpGvoteables(); + dumpMitigation(); + dumpMitigationStats(); + dumpMitigationDirs(); + dumpIrqDurationCounts(); +} + diff --git a/dumpstate/dump_power.sh b/dumpstate/dump_power.sh deleted file mode 100644 index 8bf999c8..00000000 --- a/dumpstate/dump_power.sh +++ /dev/null @@ -1,421 +0,0 @@ -#!/vendor/bin/sh -build_type="$(getprop ro.build.type)" -echo "\n------ Power Stats Times ------" -echo -n "Boot: " && /vendor/bin/uptime -s && echo -n "Now: " && date; - -echo "\n------ ACPM stats ------" -for f in /sys/devices/platform/acpm_stats/*_stats ; do - echo "\n\n$f" - cat $f -done - -echo "\n------ CPU PM stats ------" -cat "/sys/devices/system/cpu/cpupm/cpupm/time_in_state" - -echo "\n------ GENPD summary ------" -cat "/d/pm_genpd/pm_genpd_summary" - -echo "\n------ Power supply property battery ------" -cat "/sys/class/power_supply/battery/uevent" -echo "\n------ Power supply property dc ------" -cat "/sys/class/power_supply/dc/uevent" -echo "\n------ Power supply property gcpm ------" -cat "/sys/class/power_supply/gcpm/uevent" -echo "\n------ Power supply property gcpm_pps ------" -cat "/sys/class/power_supply/gcpm_pps/uevent" -echo "\n------ Power supply property main-charger ------" -cat "/sys/class/power_supply/main-charger/uevent" -echo "\n------ Power supply property dc-mains ------" -cat "/sys/class/power_supply/dc-mains/uevent" -echo "\n------ Power supply property tcpm ------" -cat "/sys/class/power_supply/tcpm-source-psy-8-0025/uevent" -echo "\n------ Power supply property usb ------" -cat "/sys/class/power_supply/usb/uevent" -echo "\n------ Power supply property wireless ------" -cat "/sys/class/power_supply/wireless/uevent" - -if [ -d "/sys/class/power_supply/maxfg" ] -then - echo "\n------ Power supply property maxfg ------" - cat "/sys/class/power_supply/maxfg/uevent" - echo "\n------ m5_state ------" - cat "/sys/class/power_supply/maxfg/m5_model_state" - echo "\n------ maxfg ------" - cat "/dev/logbuffer_maxfg" - echo "\n------ maxfg ------" - cat "/dev/logbuffer_maxfg_monitor" -else - echo "\n------ Power supply property maxfg_base ------" - cat "/sys/class/power_supply/maxfg_base/uevent" - echo "\n------ Power supply property maxfg_flip ------" - cat "/sys/class/power_supply/maxfg_flip/uevent" - echo "\n------ m5_state ------" - cat "/sys/class/power_supply/maxfg_base/m5_model_state" - echo "\n------ maxfg_base ------" - cat "/dev/logbuffer_maxfg_base" - echo "\n------ maxfg_flip ------" - cat "/dev/logbuffer_maxfg_flip" - echo "\n------ maxfg_base ------" - cat "/dev/logbuffer_maxfg_base_monitor" - echo "\n------ maxfg_flip ------" - cat "/dev/logbuffer_maxfg_flip_monitor" -fi - -if [ -e "/dev/maxfg_history" ] -then - echo "\n------ Maxim FG History ------" - cat "/dev/maxfg_history" -fi - -if [ -d "/sys/class/power_supply/dock" ] -then - echo "\n------ Power supply property dock ------" - cat "/sys/class/power_supply/dock/uevent" -fi - -if [ -e "/dev/logbuffer_tcpm" ] -then - echo "\n------ Logbuffer TCPM ------" - cat "/dev/logbuffer_tcpm" - if [ -d "/sys/kernel/debug/tcpm" ] - then - echo "\n------ TCPM logs ------" - cat /sys/kernel/debug/tcpm/* - else - echo "\n------ TCPM logs ------" - cat /sys/kernel/debug/usb/tcpm* - fi -fi - -echo "\n------ TCPC ------" -for f in /sys/devices/platform/10d60000.hsi2c/i2c-*/i2c-max77759tcpc -do - echo "registers:" - cat $f/registers - echo "frs:" - cat $f/frs - echo "auto_discharge:" - cat $f/auto_discharge - echo "bc12_enabled:" - cat $f/bc12_enabled - echo "cc_toggle_enable:" - cat $f/cc_toggle_enable - echo "contaminant_detection:" - cat $f/contaminant_detection - echo "contaminant_detection_status:" - cat $f/contaminant_detection_status -done - -echo "\n------ PD Engine ------" -cat "/dev/logbuffer_usbpd" -echo "\n------ PPS-google_cpm ------" -cat "/dev/logbuffer_cpm" -echo "\n------ PPS-dc ------" -cat "/dev/logbuffer_pca9468" - -if [ -e "/dev/logbuffer_wc68" ] -then - echo "\n------ WC68 ------" - cat "/dev/logbuffer_wc68" -fi - -if [ -e "/dev/logbuffer_ln8411" ] -then - echo "\n------ LN8411 ------" - cat "/dev/logbuffer_ln8411" -fi - -echo "\n------ Battery Health ------" -cat "/sys/class/power_supply/battery/health_index_stats" -echo "\n------ BMS ------" -cat "/dev/logbuffer_ssoc" -echo "\n------ TTF ------" -cat "/dev/logbuffer_ttf" -echo "\n------ TTF details ------" -cat "/sys/class/power_supply/battery/ttf_details" -echo "\n------ TTF stats ------" -cat "/sys/class/power_supply/battery/ttf_stats" -echo "\n------ aacr_state ------" -cat "/sys/class/power_supply/battery/aacr_state" -echo "\n------ maxq ------" -cat "/dev/logbuffer_maxq" -echo "\n------ TEMP/DOCK-DEFEND ------" -cat "/dev/logbuffer_bd" - -echo "\n------ TRICKLE-DEFEND Config ------" -cd /sys/devices/platform/google,battery/power_supply/battery/ -for f in `ls bd_*` -do - echo $f: `cat $f` -done - -echo "\n------ DWELL-DEFEND Config ------" -cd /sys/devices/platform/google,charger/ -for f in `ls charge_s*` -do - echo "$f: `cat $f`" -done - -echo "\n------ TEMP-DEFEND Config ------" -cd /sys/devices/platform/google,charger/ -for f in `ls bd_*` -do - echo "$f: `cat $f`" -done - -if [ $build_type = "userdebug" ] -then - echo "\n------ DC_registers dump ------" - cat "/sys/class/power_supply/dc-mains/device/registers_dump" - echo "\n------ max77759_chg registers dump ------" - cat "/d/max77759_chg/registers" - echo "\n------ max77729_pmic registers dump ------" - cat "/d/max77729_pmic/registers" - echo "\n------ Charging table dump ------" - cat "/d/google_battery/chg_raw_profile" - - echo "\n------ fg_model ------" - for f in /d/maxfg* - do - regs=`cat $f/fg_model` - echo $f: - echo "$regs" - done - - echo "\n------ fg_alo_ver ------" - for f in /d/maxfg* - do - regs=`cat $f/algo_ver` - echo $f: - echo "$regs" - done - - echo "\n------ fg_model_ok ------" - for f in /d/maxfg* - do - regs=`cat $f/model_ok` - echo $f: - echo "$regs" - done - - echo "\n------ fg registers ------" - for f in /d/maxfg* - do - regs=`cat $f/registers` - echo $f: - echo "$regs" - done - - echo "\n------ Maxim FG NV RAM ------" - for f in /d/maxfg* - do - regs=`cat $f/nv_registers` - echo $f: - echo "$regs" - done -fi - -echo "\n------ Battery EEPROM ------" -if [ -e "/sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom" ] -then - xxd /sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom -fi - -if [ -e "/sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom" ] -then - xxd /sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom -fi - -if [ -e "/sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom" ] -then - xxd /sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom -fi - -if [ -e "/sys/devices/platform/10da0000.hsi2c/i2c-7/7-0050/eeprom" ] -then - xxd /sys/devices/platform/10da0000.hsi2c/i2c-7/7-0050/eeprom -fi - -if [ -e "/sys/devices/platform/10c90000.hsi2c/i2c-7/7-0050/eeprom" ] -then - xxd /sys/devices/platform/10c90000.hsi2c/i2c-7/7-0050/eeprom -fi - -if [ -e "/sys/devices/platform/10c90000.hsi2c/i2c-6/6-0050/eeprom" ] -then - xxd /sys/devices/platform/10c90000.hsi2c/i2c-6/6-0050/eeprom -fi - -echo "\n------ Charger Stats ------" -cat "/sys/class/power_supply/battery/charge_details" -if [ $build_type = "userdebug" ] -then - echo "\n------ Google Charger ------" - cd /sys/kernel/debug/google_charger/ - for f in `ls pps_*` - do - echo "$f: `cat $f`" - done - echo "\n------ Google Battery ------" - cd /sys/kernel/debug/google_battery/ - for f in `ls ssoc_*` - do - echo "$f: `cat $f`" - done -fi - -echo "\n------ WLC logs ------" -cat "/dev/logbuffer_wireless" -echo "\n------ WLC VER ------" -cat "/sys/class/power_supply/wireless/device/version" -echo "\n------ WLC STATUS ------" -cat "/sys/class/power_supply/wireless/device/status" -echo "\n------ WLC FW Version ------" -cat "/sys/class/power_supply/wireless/device/fw_rev" -echo "\n------ RTX ------" -cat "/dev/logbuffer_rtx" - -if [ $build_type = "userdebug" ] -then - echo "\n------ gvotables ------" - cat /sys/kernel/debug/gvotables/*/status -fi - -echo "\n------ Lastmeal ------" -cat "/data/vendor/mitigation/lastmeal.txt" -echo "\n------ Thismeal ------" -cat "/data/vendor/mitigation/thismeal.txt" -echo "\n------ Mitigation Stats ------" -echo "Source\t\tCount\tSOC\tTime\tVoltage" -for f in `ls /sys/devices/virtual/pmic/mitigation/last_triggered_count/*` -do - count=`cat $f` - a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/last_triggered_count\//} - b=${f/last_triggered_count/last_triggered_capacity} - c=${f/last_triggered_count/last_triggered_timestamp/} - d=${f/last_triggered_count/last_triggered_voltage/} - cnt=`cat $f` - cap=`cat ${b/count/cap}` - ti=`cat ${c/count/time}` - volt=`cat ${d/count/volt}` - echo "${a/_count/} \t$cnt\t$cap\t$ti\t$volt" -done - -echo "\n------ Clock Divider Ratio ------" -echo \"Source\t\tRatio\" -for f in `ls /sys/devices/virtual/pmic/mitigation/clock_ratio/*` -do ratio=`cat $f` - a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/clock_ratio\//} - echo "${a/_ratio/} \t$ratio" -done - -echo "\n------ Clock Stats ------" -echo "Source\t\tStats" -for f in `ls /sys/devices/virtual/pmic/mitigation/clock_stats/*` -do - stats=`cat $f` - a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/clock_stats\//}; - echo "${a/_stats/} \t$stats" -done - -echo "\n------ Triggered Level ------" -echo "Source\t\tLevel" -for f in `ls /sys/devices/virtual/pmic/mitigation/triggered_lvl/*` -do - lvl=`cat $f` - a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/triggered_lvl\//} - echo "${a/_lvl/} \t$lvl" -done - -echo "\n------ Instruction ------" -for f in `ls /sys/devices/virtual/pmic/mitigation/instruction/*` -do - val=`cat $f` - a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/instruction\//} - echo "$a=$val" -done - -echo "\n------ IRQ Duration Counts ------" -echo "Source\t\t\t\tlt_5ms_cnt\tbt_5ms_to_10ms_cnt\tgt_10ms_cnt\tCode\tCurrent Threshold (uA)\tCurrent Reading (uA)" - -lt=`cat /sys/devices/virtual/pmic/mitigation/irq_dur_cnt/less_than_5ms_count` -bt=`cat /sys/devices/virtual/pmic/mitigation/irq_dur_cnt/between_5ms_to_10ms_count` -gt=`cat /sys/devices/virtual/pmic/mitigation/irq_dur_cnt/greater_than_10ms_count` -lpf_cur_m=`cat /sys/devices/platform/acpm_mfd_bus@15500000/i2c-0/0-001f/s2mpg14-meter/s2mpg14-odpm/iio:device0/lpf_current` -lpf_cur_s=`cat /sys/devices/platform/acpm_mfd_bus@15510000/i2c-1/1-002f/s2mpg15-meter/s2mpg15-odpm/iio:device1/lpf_current` - -lpf_cur_main=(${lpf_cur_m/\\n/;}) -lpf_cur_sub=(${lpf_cur_s/\\n/;}) - -IFS_PRE=$IFS -IFS=$'\n' -lt_a=($lt) -bt_a=($bt) -gt_a=($gt) -IFS=$IFS_PRE - - -for f in `ls /sys/devices/virtual/pmic/mitigation/main_pwrwarn/*` -do - count=`cat $f` - a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/main_pwrwarn\//} - s=${a/main_pwrwarn_threshold/} - arr=(${count//=/ }) - code=${arr[0]} - threshold=${arr[1]} - main_array[$s]="$code\t$threshold" -done - -i=1 -main_current=() -for f in "${main_array[@]}" -do - idx=$i - idx2=$idx+1 - main_current+=(${lpf_cur_main[$idx2]}) - i=$i+2 -done - -for f in `ls /sys/devices/virtual/pmic/mitigation/sub_pwrwarn/*` -do - count=`cat $f` - a=${f/\/sys\/devices\/virtual\/pmic\/mitigation\/sub_pwrwarn\//} - s=${a/sub_pwrwarn_threshold/} - arr=(${count//=/ }) - code=${arr[0]}; - threshold=${arr[1]}; - sub_array[$s]="$code\t$threshold" -done -i=1 -sub_current=() -for f in "${sub_array[@]}" -do - idx=$i - idx2=$idx+1 - sub_current+=(${lpf_cur_sub[$idx2]}) - i=$i+2 -done - -rows=${#lt_a[@]} -for i in `seq 0 $rows` -do - n="${lt_a[i]%:*}" - l="${lt_a[i]#*": "}" - b="${bt_a[i]#*": "}" - g="${gt_a[i]#*": "}" - if [ $i -lt 9 ] - then - echo "$n \t\t$l\t\t$b\t\t\t$g" - elif [ $i -ge 9 ] && [ $i -lt 21 ] - then - j=$i-9 - thresh="${main_array[j]}" - current="${main_current[j]}" - echo "$n \t$l\t\t$b\t\t\t$g\t\t$thresh \t\t$current" - else - j=$i-21 - thresh="${sub_array[j]}" - current="${sub_current[j]}" - echo "$n \t$l\t\t$b\t\t\t$g\t\t$thresh \t\t$current" - fi -done diff --git a/dumpstate/item.mk b/dumpstate/item.mk index 0edb7f29..441357a9 100644 --- a/dumpstate/item.mk +++ b/dumpstate/item.mk @@ -1,4 +1,4 @@ PRODUCT_PACKAGES += dump_wlan.sh \ - dump_power.sh + dump_power PRODUCT_PACKAGES_DEBUG += dump_gsa.sh From ad82fe019a213fc2779e66ab5e7f67a1a75c547a Mon Sep 17 00:00:00 2001 From: qinyiyan Date: Mon, 11 Sep 2023 10:10:55 -0700 Subject: [PATCH 061/133] Add Edgetpu Tachyon service to the device_framework_matrix_product.xml. Bug: 299932913 Change-Id: Iaffb2f47e3773df98b61706ef7476916e5687be8 --- device_framework_matrix_product.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index a7915de2..ebaeaa2d 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -104,6 +104,14 @@ default + + com.google.edgetpu.tachyon + 1 + + IComputeService + default + + com.google.hardware.pixel.display 9 From 5f2a60782e25a3f0380741a2d6d8d08f8f51d789 Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Tue, 12 Sep 2023 14:10:46 +0000 Subject: [PATCH 062/133] Cleanup: Remove wait_for_strongbox source code Bug: None Test: Build pass Change-Id: Ib1a07b11269ad5436c087e6caba74ab3e4237682 --- keymaster/Android.bp | 40 ---------------------- keymaster/wait_for_strongbox.cpp | 59 -------------------------------- keymaster/wait_for_strongbox.rc | 9 ----- 3 files changed, 108 deletions(-) delete mode 100644 keymaster/Android.bp delete mode 100644 keymaster/wait_for_strongbox.cpp delete mode 100644 keymaster/wait_for_strongbox.rc diff --git a/keymaster/Android.bp b/keymaster/Android.bp deleted file mode 100644 index 444e4b74..00000000 --- a/keymaster/Android.bp +++ /dev/null @@ -1,40 +0,0 @@ -// -// Copyright (C) 2018 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/zuma:device_google_zuma_license", - ], -} - -cc_binary { - name: "wait_for_strongbox", - init_rc: ["wait_for_strongbox.rc"], - relative_install_path: "hw", - srcs: [ "wait_for_strongbox.cpp" ], - cflags: [ "-Werror", "-Wall" ], - shared_libs: [ - "android.hardware.keymaster@4.0", - "libbase", - "libkeymaster4_1support", - "libutils", - ], - proprietary: true, -} diff --git a/keymaster/wait_for_strongbox.cpp b/keymaster/wait_for_strongbox.cpp deleted file mode 100644 index c0f4094b..00000000 --- a/keymaster/wait_for_strongbox.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - ** Copyright 2018, The Android Open Source Project - ** - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** - ** http://www.apache.org/licenses/LICENSE-2.0 - ** - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - */ - -#include - -#define LOG_TAG "wait_for_strongbox" -#include - -#include - -using android::hardware::keymaster::V4_1::SecurityLevel; -using android::hardware::keymaster::V4_1::support::Keymaster; - -useconds_t kWaitTimeMicroseconds = 1 * 1000; // 1 milliseconds - -int main() { - for (unsigned cycleCount = 0; /* Forever */; ++cycleCount) { - auto keymasters = Keymaster::enumerateAvailableDevices(); - - bool foundStrongBox = false; - bool foundTee = false; - for (auto &dev : keymasters) { - SecurityLevel securityLevel = dev->halVersion().securityLevel; - uint8_t majorVersion = dev->halVersion().majorVersion; - if (securityLevel == SecurityLevel::STRONGBOX && majorVersion == 4) { - foundStrongBox = true; - } - if (securityLevel == SecurityLevel::TRUSTED_ENVIRONMENT && majorVersion == 4) { - foundTee = true; - } - } - - if (foundTee && foundStrongBox) { - return 0; - } - if (cycleCount % 10 == 1) { - if (!foundStrongBox) { - LOG(WARNING) << "Still waiting for StrongBox Keymaster"; - } - if (!foundTee) { - LOG(WARNING) << "Still waiting for TEE Keymaster"; - } - } - usleep(kWaitTimeMicroseconds); - } -} diff --git a/keymaster/wait_for_strongbox.rc b/keymaster/wait_for_strongbox.rc deleted file mode 100644 index c02fc465..00000000 --- a/keymaster/wait_for_strongbox.rc +++ /dev/null @@ -1,9 +0,0 @@ -# Wait for both Trusty and Strongbox HALs to be up -service wait_for_strongbox /vendor/bin/hw/wait_for_strongbox - user root - group root system - priority -20 - ioprio rt 0 - -on late-fs - exec_start wait_for_strongbox From 0184b772a92ce1cd5e0f51b80b1bca9d06c04c3d Mon Sep 17 00:00:00 2001 From: Woody Lin Date: Mon, 4 Sep 2023 09:58:01 +0800 Subject: [PATCH 063/133] init.debug.rc: enable etm/etm2dram when SJTAG is unlocked Enables the debug features required an unlocked SJTAG to the section `on property:ro.vendor.sjtag_ap_is_unlocked=true`, so they can be enabled when 1. PD is available on non-fused device on boot, or 2. PD is available after betterbug acquires it from the corp service. Bug: 299043634 Change-Id: I43f8364d7624af1d98b79afffeb1c6dc8bb6faf0 --- conf/init.check_ap_pd_auth.sh | 15 +++++++++++++++ conf/init.debug.rc | 11 +++++++++++ device.mk | 3 ++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 conf/init.check_ap_pd_auth.sh diff --git a/conf/init.check_ap_pd_auth.sh b/conf/init.check_ap_pd_auth.sh new file mode 100644 index 00000000..8175e754 --- /dev/null +++ b/conf/init.check_ap_pd_auth.sh @@ -0,0 +1,15 @@ +#!/vendor/bin/sh + +# This script sets up `ro.vendor.sjtag_ap_is_unlocked` for the non-fused +# device. For a fused device, this property should be set by +# betterbug->ss-restart-detector when PD is acquired. + +SJTAG_STATUS=0x$(cat /sys/devices/platform/sjtag_ap/interface/status) +SOFT_LOCK_BIT=4 +AUTH_PASS_BIT=8 + +# Unlocked or locked but auth passed. +if test "$((SJTAG_STATUS & (1 << SOFT_LOCK_BIT)))" = 0 -o \ + "$((SJTAG_STATUS & (1 << AUTH_PASS_BIT)))" != 0 ; then + setprop ro.vendor.sjtag_ap_is_unlocked true +fi diff --git a/conf/init.debug.rc b/conf/init.debug.rc index 019a514b..f86f224b 100644 --- a/conf/init.debug.rc +++ b/conf/init.debug.rc @@ -50,3 +50,14 @@ on property:persist.sys.device_provisioned=1 && property:ro.revision=PROTO1.1 start vendor.force_pkvm on property:persist.sys.device_provisioned=1 && property:ro.revision=EVT1.0 start vendor.force_pkvm + +service vendor.check_ap_pd_auth_sh /vendor/bin/init.check_ap_pd_auth.sh + class main + user root + group root system + oneshot + +# Enable etm/etm2dram when ramdump is enabled, and ap-sjtag is unlocked. +on property:ro.boot.ramdump=enabled && property:ro.vendor.sjtag_ap_is_unlocked=true + write /sys/devices/platform/exynos-etm/etm_on 1 + write /sys/devices/platform/etm2dram/arm 1 diff --git a/device.mk b/device.mk index e5920921..08e9ea1b 100644 --- a/device.mk +++ b/device.mk @@ -338,7 +338,8 @@ PRODUCT_COPY_FILES += \ ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) PRODUCT_COPY_FILES += \ - device/google/zuma/conf/init.debug.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.debug.rc + device/google/zuma/conf/init.debug.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.debug.rc \ + device/google/zuma/conf/init.check_ap_pd_auth.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.check_ap_pd_auth.sh PRODUCT_COPY_FILES += \ device/google/zuma/conf/init.freq.userdebug.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.freq.userdebug.rc endif From 05cedc1314cc86b47dcac0372f2923725eb1b833 Mon Sep 17 00:00:00 2001 From: RD Babiera Date: Tue, 19 Sep 2023 19:14:39 +0000 Subject: [PATCH 064/133] usb: enable/disable displayport alt mode through enableUsbData Adds functionality for enabling and disabling DisplayPort Alt Mode on the port through enableUsbData in the USB HAL to comply with USB restrictions for heightened security mode. Test: manual test on device - use enableUsbData dumpsys command to turn off DisplayPort and then turn it back on while connected to a partner sink. Bug: 297208252 Change-Id: I9f071bce802b728f2229abc08efb2204e4c2505a Signed-off-by: RD Babiera --- conf/ueventd.zuma.rc | 3 ++ usb/usb/Usb.cpp | 43 +++++++++++++++++++++++++ usb/usb/Usb.h | 2 ++ usb/usb/android.hardware.usb-service.rc | 2 ++ 4 files changed, 50 insertions(+) diff --git a/conf/ueventd.zuma.rc b/conf/ueventd.zuma.rc index 9f4d2b31..dc2c2d4f 100644 --- a/conf/ueventd.zuma.rc +++ b/conf/ueventd.zuma.rc @@ -239,3 +239,6 @@ /sys/bus/aoc/devices/control udfps_set_clock_source 0220 system system /sys/bus/aoc/devices/control udfps_get_osc_freq 0440 system system /sys/bus/aoc/devices/control udfps_get_disp_freq 0440 system system + +# USB Alt Modes +/sys/devices/platform/10cb0000.hsi2c/i2c-*/*-0025/typec/port0/port0-partner/port0-partner.* mode1/active 0664 system system \ No newline at end of file diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 93ea07c4..bac8dd60 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -105,6 +105,7 @@ ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, int64_t in_transactionId) { bool result = true; std::vector currentPortStatus; + string displayPortPartnerPath; ALOGI("Userspace turn %s USB data signaling. opID:%ld", in_enable ? "on" : "off", in_transactionId); @@ -120,6 +121,27 @@ ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, ALOGE("Gadget cannot be pulled up"); result = false; } + + if (!WriteStringToFile("1", DISPLAYPORT_ACTIVE_PATH)) { + ALOGE("Failed to enable DisplayPort Alt Mode on port"); + } else { + ALOGI("Successfully enabled DisplayPort Alt Mode on port"); + } + + if (getDisplayPortUsbPathHelper(&displayPortPartnerPath) == Status::SUCCESS) { + size_t pos = displayPortPartnerPath.find("/displayport"); + if (pos != string::npos) { + displayPortPartnerPath = displayPortPartnerPath.substr(0, pos) + "/mode1/active"; + } + if (!WriteStringToFile("1", displayPortPartnerPath)) { + ALOGE("Failed to enable DisplayPort Alt Mode on partner at %s", + displayPortPartnerPath.c_str()); + } else { + ALOGI("Successfully enabled DisplayPort Alt Mode on partner at %s", + displayPortPartnerPath.c_str()); + setupDisplayPortPoll(); + } + } } } else { if (!WriteStringToFile("1", ID_PATH)) { @@ -141,6 +163,27 @@ ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, ALOGE("Gadget cannot be pulled down"); result = false; } + + if (getDisplayPortUsbPathHelper(&displayPortPartnerPath) == Status::SUCCESS) { + size_t pos = displayPortPartnerPath.find("/displayport"); + if (pos != string::npos) { + displayPortPartnerPath = displayPortPartnerPath.substr(0, pos) + "/mode1/active"; + } + if (!WriteStringToFile("0", displayPortPartnerPath)) { + ALOGE("Failed to disable DisplayPort Alt Mode on partner at %s", + displayPortPartnerPath.c_str()); + } else { + ALOGI("Successfully disabled DisplayPort Alt Mode on partner at %s", + displayPortPartnerPath.c_str()); + shutdownDisplayPortPoll(true); + } + } + + if (!WriteStringToFile("0", DISPLAYPORT_ACTIVE_PATH)) { + ALOGE("Failed to disable DisplayPort Alt Mode on port"); + } else { + ALOGI("Successfully disabled DisplayPort Alt Mode on port"); + } } if (result) { diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 566fc73c..ad3be974 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -59,6 +59,8 @@ constexpr char kGadgetName[] = "11210000.dwc3"; #define VBUS_PATH NEW_UDC_PATH "dwc3_exynos_otg_b_sess" #define USB_DATA_PATH NEW_UDC_PATH "usb_data_enabled" +#define DISPLAYPORT_ACTIVE_PATH "/sys/class/typec/port0/port0.0/mode1/active" + #define LINK_TRAINING_STATUS_UNKNOWN "0" #define LINK_TRAINING_STATUS_SUCCESS "1" #define LINK_TRAINING_STATUS_FAILURE "2" diff --git a/usb/usb/android.hardware.usb-service.rc b/usb/usb/android.hardware.usb-service.rc index e764ad88..d4db81df 100644 --- a/usb/usb/android.hardware.usb-service.rc +++ b/usb/usb/android.hardware.usb-service.rc @@ -8,6 +8,7 @@ on post-fs chown root system /sys/class/typec/port0/power_role chown root system /sys/class/typec/port0/data_role chown root system /sys/class/typec/port0/port_type + chown root system /sys/class/typec/port0/port0.0/mode1/active chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/contaminant_detection chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/contaminant_detection chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/contaminant_detection @@ -80,6 +81,7 @@ on post-fs chmod 664 /sys/class/typec/port0/power_role chmod 664 /sys/class/typec/port0/data_role chmod 664 /sys/class/typec/port0/port_type + chmod 664 /sys/class/typec/port0/port0.0/mode1/active chmod 664 /sys/devices/platform/11110000.usb/dwc3_exynos_otg_b_sess chmod 664 /sys/devices/platform/11110000.usb/dwc3_exynos_otg_id chmod 664 /sys/devices/platform/11110000.usb/usb_data_enabled From 69e8e28d1e833354d1ba646ff51a6d95478e2aab Mon Sep 17 00:00:00 2001 From: Sergey Volk Date: Wed, 16 Aug 2023 23:41:22 +0000 Subject: [PATCH 065/133] Set owner for dp_hotplug_error_code dp_hotplug_error_code owner needs to be the system user, since HWC needs to be able to write into it, to reset the error code. Test: manual Bug: 283461313 Change-Id: I0866e39f3cd75878628d44b4afaf53df61448213 --- conf/init.zuma.rc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index d4aa490e..ed2f1d07 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -694,6 +694,8 @@ on fs chown system system /sys/class/dqe0/atc/gain_limit chown system system /sys/class/dqe0/atc/lt_calc_ab_shift + chown system system /sys/devices/platform/110f0000.drmdp/drm-displayport/dp_hotplug_error_code + chown system system /sys/devices/platform/19470000.drmdecon/early_wakeup chmod 0660 /sys/devices/platform/19470000.drmdecon/early_wakeup From 873766c6f0c668ba526eaefe18ecc5e51ce87d67 Mon Sep 17 00:00:00 2001 From: RD Babiera Date: Wed, 23 Aug 2023 22:42:35 +0000 Subject: [PATCH 066/133] usb: check for port partner Thunderbolt capability Query the port partner's SVIDs when the DisplayPort driver sysfs is not recognized so that the USB HAL can identify whether or not the port partner supports Thunderbolt. Test: manual verification on device - test to see that cableStatus is set to NOT_CAPABLE on hub that supports Thunderbolt but not DisplayPort Alt Mode. Then verify that device not capable of being a DisplayPort sink but does support Thunderbolt does not trigger this status. Bug: 288150501 Change-Id: Iaba60ecc5510acecee1e1d3241611906c738a263 Signed-off-by: RD Babiera --- usb/usb/Usb.cpp | 55 +++++++++++++++++++++++++++++++++++++++++-------- usb/usb/Usb.h | 3 +++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 93ea07c4..49e7474f 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -921,6 +921,29 @@ AltModeData::DisplayPortAltModeData constructAltModeData(string hpd, string pin_ return dpData; } +Status queryPartnerSvids(std::vector *svids) { + DIR *dp; + + dp = opendir(kDisplayPortUsbPath); + if (dp != NULL) { + struct dirent *ep; + // Iterate through directories for Alt Mode SVIDs + while ((ep = readdir(dp))) { + if (ep->d_type == DT_DIR) { + string svid; + string portPartnerPath = string(kDisplayPortUsbPath) + string(ep->d_name) + "/svid"; + if (ReadFileToString(portPartnerPath, &svid)) { + (*svids).push_back(Trim(svid)); + } + } + } + closedir(dp); + } else { + return Status::ERROR; + } + return Status::SUCCESS; +} + /* DisplayPort Helper Functions End */ // Only care about first port which must support DisplayPortAltMode @@ -930,18 +953,32 @@ Status queryDisplayPortStatus(android::hardware::usb::Usb *usb, string path; AltModeData::DisplayPortAltModeData dpData; + /* + * We check if the DisplayPort Alt Mode sysfs nodes exist. If they don't, then it means that the + * device has not entered Alt Mode with the port partner because of a source/sink role + * incompatibility, pin assignment incompatibility, etc. So, we then check to see if the partner + * supports Thunderbolt and DisplayPort SVIDs. If it supports DisplayPort, then we assume that + * it must be a source device and Thunderbolt should operate similarly; we don't populate the + * DisplayPortAltModeStatus. If it only supports Thunderbolt, then we cannot determine if it is + * sink or source capable, and need to notify the user. + */ if (usb->getDisplayPortUsbPathHelper(&path) == Status::ERROR) { - (*currentPortStatus)[0].supportedAltModes.push_back(dpData); - return Status::SUCCESS; + std::vector svids; + if (queryPartnerSvids(&svids) == Status::SUCCESS) { + if (std::count(svids.begin(), svids.end(), SVID_THUNDERBOLT) && + !std::count(svids.begin(), svids.end(), SVID_DISPLAYPORT)) { + dpData.cableStatus = DisplayPortAltModeStatus::NOT_CAPABLE; + } + } + } else { + usb->readDisplayPortAttribute("hpd", path, &hpd); + usb->readDisplayPortAttribute("pin_assignment", path, &pinAssign); + usb->readDisplayPortAttribute("vdo", path, &vdo); + usb->readDisplayPortAttribute("link_status", path, &linkStatus); + + dpData = constructAltModeData(hpd, pinAssign, linkStatus, vdo); } - usb->readDisplayPortAttribute("hpd", path, &hpd); - usb->readDisplayPortAttribute("pin_assignment", path, &pinAssign); - usb->readDisplayPortAttribute("vdo", path, &vdo); - usb->readDisplayPortAttribute("link_status", path, &linkStatus); - - // Set DisplayPortAltModeInfo - dpData = constructAltModeData(hpd, pinAssign, linkStatus, vdo); (*currentPortStatus)[0].supportedAltModes.push_back(dpData); return Status::SUCCESS; diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 566fc73c..54263820 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -70,6 +70,9 @@ constexpr char kGadgetName[] = "11210000.dwc3"; #define DISPLAYPORT_POLL_WAIT_MS 100 +#define SVID_DISPLAYPORT "ff01" +#define SVID_THUNDERBOLT "8087" + struct Usb : public BnUsb { Usb(); From cdd405ec70e80aa051d1745af8a296a31edb0c33 Mon Sep 17 00:00:00 2001 From: Midas Chien Date: Fri, 22 Sep 2023 15:28:20 +0000 Subject: [PATCH 067/133] display: allow hwcomposer to access DRM module debug file Change the owner and group of the DRM module debug file to system to grant permission for hwcomposer. Bug: 301599195 Test: check HWC can access it Change-Id: I985c402bc2d920a43493dddd73e9470ab0228104 --- conf/init.zuma.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 27609602..75c56078 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -665,6 +665,7 @@ on fs chown system system /sys/devices/platform/exynos-drm/primary-panel/panel_need_handle_idle_exit chown system system /sys/devices/platform/exynos-drm/primary-panel/op_hz chown system system /sys/module/drm/parameters/vblankoffdelay + chown system system /sys/module/drm/parameters/debug chown system system /sys/class/dqe0/atc/ambient_light chown system system /sys/class/dqe0/atc/st chown system system /sys/class/dqe0/atc/en From 290a92d7bba59bd5a1849e705401ebd1ed168942 Mon Sep 17 00:00:00 2001 From: Daeho Jeong Date: Tue, 26 Sep 2023 13:30:24 -0700 Subject: [PATCH 068/133] get more logcat files with similar disk usage for zuma Increase the number of logcat files to 60 and enable file compression to save disk usage at the same time. Bug: 295175795 Test: check logcat files Change-Id: I8208e40092c834ea3a2145d40ed7e384776ad018 Signed-off-by: Daeho Jeong --- device.mk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 2c73565f..fef49dc2 100644 --- a/device.mk +++ b/device.mk @@ -119,9 +119,13 @@ ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) PRODUCT_PROPERTY_OVERRIDES += \ ro.logd.size=1M # b/114766334: persist all logs by default rotating on 30 files of 1MiB +# change to 60 files for zuma PRODUCT_PROPERTY_OVERRIDES += \ logd.logpersistd=logcatd \ - logd.logpersistd.size=30 + logd.logpersistd.size=60 + +PRODUCT_PRODUCT_PROPERTIES += \ + ro.logcat.compress=true endif # From system.property From 447cdc3f6cfa1945b5531d8088e48174ff05b1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 28 Sep 2023 00:29:06 +0000 Subject: [PATCH 069/133] OWNERS: master -> main Change-Id: I195ce8c820676c359075360dc8cf59b98f67f5a0 --- OWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OWNERS b/OWNERS index 1cbf9196..4bdbb973 100644 --- a/OWNERS +++ b/OWNERS @@ -1,2 +1,2 @@ # per-file for Pixel device makefiles, see go/pixel-device-mk-owner-checklist for details. -per-file *.mk=file:device/google/gs-common:master:/OWNERS +per-file *.mk=file:device/google/gs-common:main:/OWNERS From c367051d69112b072e6b75de9ad22474372ebd6f Mon Sep 17 00:00:00 2001 From: guibing Date: Tue, 1 Aug 2023 19:13:39 +0000 Subject: [PATCH 070/133] init: update vendor_sched procfs paths Vendor sched procfs path hierarchy gets updated in kernel. Update the paths in init rc file and task profiles to match the change. Bug: 289151587 Test: pts-tradefed run commandAndExit pts -m PtsPerfWbsTestCases -t com.google.android.perfwbs.pts.SchedulerTest Change-Id: I14d07c4525f4bf60318bca31a89b9130c4236600 --- conf/init.zuma.rc | 220 ++++++++++++++++++++++----------------------- task_profiles.json | 52 +++++------ 2 files changed, 136 insertions(+), 136 deletions(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 2cc2d338..69f8d109 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -24,30 +24,30 @@ on init write /dev/sys/fs/by-name/userdata/data_io_flag 56 write /dev/sys/fs/by-name/userdata/node_io_flag 56 - chown system system /proc/vendor_sched/set_task_group_bg - chown system system /proc/vendor_sched/set_task_group_cam - chown system system /proc/vendor_sched/set_task_group_fg - chown system system /proc/vendor_sched/set_task_group_nnapi - chown system system /proc/vendor_sched/set_task_group_sys - chown system system /proc/vendor_sched/set_task_group_sysbg - chown system system /proc/vendor_sched/set_task_group_ta - chown system system /proc/vendor_sched/set_task_group_rt - chown system system /proc/vendor_sched/set_task_group_sf - chown system system /proc/vendor_sched/set_task_group_dex2oat - chown system system /proc/vendor_sched/set_task_group_cam_power - chown system system /proc/vendor_sched/set_task_group_ota - chown system system /proc/vendor_sched/set_proc_group_bg - chown system system /proc/vendor_sched/set_proc_group_cam - chown system system /proc/vendor_sched/set_proc_group_fg - chown system system /proc/vendor_sched/set_proc_group_nnapi - chown system system /proc/vendor_sched/set_proc_group_sys - chown system system /proc/vendor_sched/set_proc_group_sysbg - chown system system /proc/vendor_sched/set_proc_group_ta - chown system system /proc/vendor_sched/set_proc_group_rt - chown system system /proc/vendor_sched/set_proc_group_sf - chown system system /proc/vendor_sched/set_proc_group_dex2oat - chown system system /proc/vendor_sched/set_proc_group_cam_power - chown system system /proc/vendor_sched/set_proc_group_ota + chown system system /proc/vendor_sched/groups/bg/set_task_group + chown system system /proc/vendor_sched/groups/cam/set_task_group + chown system system /proc/vendor_sched/groups/fg/set_task_group + chown system system /proc/vendor_sched/groups/nnapi/set_task_group + chown system system /proc/vendor_sched/groups/sys/set_task_group + chown system system /proc/vendor_sched/groups/sys_bg/set_task_group + chown system system /proc/vendor_sched/groups/ta/set_task_group + chown system system /proc/vendor_sched/groups/rt/set_task_group + chown system system /proc/vendor_sched/groups/sf/set_task_group + chown system system /proc/vendor_sched/groups/dex2oat/set_task_group + chown system system /proc/vendor_sched/groups/cam_power/set_task_group + chown system system /proc/vendor_sched/groups/ota/set_task_group + chown system system /proc/vendor_sched/groups/bg/set_proc_group + chown system system /proc/vendor_sched/groups/cam/set_proc_group + chown system system /proc/vendor_sched/groups/fg/set_proc_group + chown system system /proc/vendor_sched/groups/nnapi/set_proc_group + chown system system /proc/vendor_sched/groups/sys/set_proc_group + chown system system /proc/vendor_sched/groups/sys_bg/set_proc_group + chown system system /proc/vendor_sched/groups/ta/set_proc_group + chown system system /proc/vendor_sched/groups/rt/set_proc_group + chown system system /proc/vendor_sched/groups/sf/set_proc_group + chown system system /proc/vendor_sched/groups/dex2oat/set_proc_group + chown system system /proc/vendor_sched/groups/cam_power/set_proc_group + chown system system /proc/vendor_sched/groups/ota/set_proc_group chown system system /proc/vendor_sched/prefer_idle_set chown system system /proc/vendor_sched/prefer_idle_clear chown system system /proc/vendor_sched/pmu_poll_enable @@ -75,30 +75,30 @@ on init chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/memlat_cpuidle_state_aware chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010/memlat_cpuidle_state_aware - chmod 0220 /proc/vendor_sched/set_task_group_bg - chmod 0220 /proc/vendor_sched/set_task_group_cam - chmod 0220 /proc/vendor_sched/set_task_group_fg - chmod 0220 /proc/vendor_sched/set_task_group_nnapi - chmod 0220 /proc/vendor_sched/set_task_group_sys - chmod 0220 /proc/vendor_sched/set_task_group_sysbg - chmod 0220 /proc/vendor_sched/set_task_group_ta - chmod 0220 /proc/vendor_sched/set_task_group_rt - chmod 0220 /proc/vendor_sched/set_task_group_sf - chmod 0220 /proc/vendor_sched/set_task_group_dex2oat - chmod 0220 /proc/vendor_sched/set_task_group_cam_power - chmod 0220 /proc/vendor_sched/set_task_group_ota - chmod 0220 /proc/vendor_sched/set_proc_group_bg - chmod 0220 /proc/vendor_sched/set_proc_group_cam - chmod 0220 /proc/vendor_sched/set_proc_group_fg - chmod 0220 /proc/vendor_sched/set_proc_group_nnapi - chmod 0220 /proc/vendor_sched/set_proc_group_sys - chmod 0220 /proc/vendor_sched/set_proc_group_sysbg - chmod 0220 /proc/vendor_sched/set_proc_group_ta - chmod 0220 /proc/vendor_sched/set_proc_group_rt - chmod 0220 /proc/vendor_sched/set_proc_group_sf - chmod 0220 /proc/vendor_sched/set_proc_group_dex2oat - chmod 0220 /proc/vendor_sched/set_proc_group_cam_power - chmod 0220 /proc/vendor_sched/set_proc_group_ota + chmod 0220 /proc/vendor_sched/groups/bg/set_task_group + chmod 0220 /proc/vendor_sched/groups/cam/set_task_group + chmod 0220 /proc/vendor_sched/groups/fg/set_task_group + chmod 0220 /proc/vendor_sched/groups/nnapi/set_task_group + chmod 0220 /proc/vendor_sched/groups/sys/set_task_group + chmod 0220 /proc/vendor_sched/groups/sys_bg/set_task_group + chmod 0220 /proc/vendor_sched/groups/ta/set_task_group + chmod 0220 /proc/vendor_sched/groups/rt/set_task_group + chmod 0220 /proc/vendor_sched/groups/sf/set_task_group + chmod 0220 /proc/vendor_sched/groups/dex2oat/set_task_group + chmod 0220 /proc/vendor_sched/groups/cam_power/set_task_group + chmod 0220 /proc/vendor_sched/groups/ota/set_task_group + chmod 0220 /proc/vendor_sched/groups/bg/set_proc_group + chmod 0220 /proc/vendor_sched/groups/cam/set_proc_group + chmod 0220 /proc/vendor_sched/groups/fg/set_proc_group + chmod 0220 /proc/vendor_sched/groups/nnapi/set_proc_group + chmod 0220 /proc/vendor_sched/groups/sys/set_proc_group + chmod 0220 /proc/vendor_sched/groups/sys_bg/set_proc_group + chmod 0220 /proc/vendor_sched/groups/ta/set_proc_group + chmod 0220 /proc/vendor_sched/groups/rt/set_proc_group + chmod 0220 /proc/vendor_sched/groups/sf/set_proc_group + chmod 0220 /proc/vendor_sched/groups/dex2oat/set_proc_group + chmod 0220 /proc/vendor_sched/groups/cam_power/set_proc_group + chmod 0220 /proc/vendor_sched/groups/ota/set_proc_group chmod 0220 /proc/vendor_sched/prefer_idle_set chmod 0220 /proc/vendor_sched/prefer_idle_clear chmod 0660 /proc/vendor_sched/pmu_poll_enable @@ -164,12 +164,12 @@ on init mkdir /dev/socket/pdx/system/vr/sensors 0775 system system # Boot time 183626384 - write /proc/vendor_sched/ta_uclamp_min 221 - write /proc/vendor_sched/ta_prefer_idle 1 - write /proc/vendor_sched/fg_uclamp_min 221 - write /proc/vendor_sched/fg_prefer_idle 1 - write /proc/vendor_sched/sys_uclamp_min 221 - write /proc/vendor_sched/sys_prefer_idle 1 + write /proc/vendor_sched/groups/ta/uclamp_min 221 + write /proc/vendor_sched/groups/ta/prefer_idle 1 + write /proc/vendor_sched/groups/fg/uclamp_min 221 + write /proc/vendor_sched/groups/fg/prefer_idle 1 + write /proc/vendor_sched/groups/sys/uclamp_min 221 + write /proc/vendor_sched/groups/sys/prefer_idle 1 # governor setting write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor sched_pixel @@ -222,8 +222,8 @@ on init chown system system /dev/cpuset/camera-daemon-mid-high-group/tasks chmod 0664 /dev/cpuset/camera-daemon-mid-high-group/tasks - write /proc/vendor_sched/cam_prefer_idle 1 - write /proc/vendor_sched/cam_uclamp_min 1 + write /proc/vendor_sched/groups/cam/prefer_idle 1 + write /proc/vendor_sched/groups/cam/uclamp_min 1 chown system system /dev/cpuset/cgroup.procs @@ -315,8 +315,8 @@ on init chown system system /dev/bbd_pwrstat # Add a boost for NNAPI HAL - write /proc/vendor_sched/nnapi_prefer_idle 0 - write /proc/vendor_sched/nnapi_uclamp_min 512 + write /proc/vendor_sched/groups/nnapi/prefer_idle 0 + write /proc/vendor_sched/groups/nnapi/uclamp_min 512 # Add memlat governor settings write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/polling_interval 10 @@ -474,32 +474,32 @@ on post-fs-data on zygote-start # For PixelLogger configuration file. chmod 0771 /data/vendor/wifi - write /proc/vendor_sched/ta_uclamp_min 1 - write /proc/vendor_sched/fg_uclamp_min 0 - write /proc/vendor_sched/sys_uclamp_min 0 - write /proc/vendor_sched/ta_preferred_idle_mask_low 0x03f - write /proc/vendor_sched/ta_preferred_idle_mask_mid 0x1f0 - write /proc/vendor_sched/ta_preferred_idle_mask_high 0x1f0 - write /proc/vendor_sched/ta_prefer_idle 1 - write /proc/vendor_sched/fg_preferred_idle_mask_low 0x03f - write /proc/vendor_sched/fg_preferred_idle_mask_mid 0x1f0 - write /proc/vendor_sched/fg_preferred_idle_mask_high 0x1f0 - write /proc/vendor_sched/fg_prefer_idle 1 - write /proc/vendor_sched/sys_preferred_idle_mask_low 0x03f - write /proc/vendor_sched/sys_preferred_idle_mask_mid 0x1f0 - write /proc/vendor_sched/sys_preferred_idle_mask_high 0x1f0 - write /proc/vendor_sched/sys_prefer_idle 1 + write /proc/vendor_sched/groups/ta/uclamp_min 1 + write /proc/vendor_sched/groups/fg/uclamp_min 0 + write /proc/vendor_sched/groups/sys/uclamp_min 0 + write /proc/vendor_sched/groups/ta/preferred_idle_mask_low 0x03f + write /proc/vendor_sched/groups/ta/preferred_idle_mask_mid 0x1f0 + write /proc/vendor_sched/groups/ta/preferred_idle_mask_high 0x1f0 + write /proc/vendor_sched/groups/ta/prefer_idle 1 + write /proc/vendor_sched/groups/fg/preferred_idle_mask_low 0x03f + write /proc/vendor_sched/groups/fg/preferred_idle_mask_mid 0x1f0 + write /proc/vendor_sched/groups/fg/preferred_idle_mask_high 0x1f0 + write /proc/vendor_sched/groups/fg/prefer_idle 1 + write /proc/vendor_sched/groups/sys/preferred_idle_mask_low 0x03f + write /proc/vendor_sched/groups/sys/preferred_idle_mask_mid 0x1f0 + write /proc/vendor_sched/groups/sys/preferred_idle_mask_high 0x1f0 + write /proc/vendor_sched/groups/sys/prefer_idle 1 - write /proc/vendor_sched/bg_ug 0 - write /proc/vendor_sched/sysbg_ug 0 - write /proc/vendor_sched/ota_ug 0 - write /proc/vendor_sched/dex2oat_ug 1 - write /proc/vendor_sched/ta_ug 2 - write /proc/vendor_sched/fg_ug 2 - write /proc/vendor_sched/nnapi_ug 2 - write /proc/vendor_sched/rt_ug 2 - write /proc/vendor_sched/sf_ug 2 - write /proc/vendor_sched/sys_ug 2 + write /proc/vendor_sched/groups/bg/ug 0 + write /proc/vendor_sched/groups/sys_bg/ug 0 + write /proc/vendor_sched/groups/ota/ug 0 + write /proc/vendor_sched/groups/dex2oat/ug 1 + write /proc/vendor_sched/groups/ta/ug 2 + write /proc/vendor_sched/groups/fg/ug 2 + write /proc/vendor_sched/groups/nnapi/ug 2 + write /proc/vendor_sched/groups/rt/ug 2 + write /proc/vendor_sched/groups/sf/ug 2 + write /proc/vendor_sched/groups/sys/ug 2 on post-fs-data @@ -808,15 +808,15 @@ on property:sys.boot_completed=1 write /sys/devices/platform/17000010.devfreq_mif/devfreq/17000010.devfreq_mif/exynos_data/cancel_boot_freq 1 # Restore prefer idle - write /proc/vendor_sched/ta_preferred_idle_mask_low 0x1ff - write /proc/vendor_sched/ta_preferred_idle_mask_mid 0x1ff - write /proc/vendor_sched/ta_preferred_idle_mask_high 0x1ff - write /proc/vendor_sched/fg_preferred_idle_mask_low 0x1ff - write /proc/vendor_sched/fg_preferred_idle_mask_mid 0x1ff - write /proc/vendor_sched/fg_preferred_idle_mask_high 0x1ff - write /proc/vendor_sched/sys_preferred_idle_mask_low 0x1ff - write /proc/vendor_sched/sys_preferred_idle_mask_mid 0x1ff - write /proc/vendor_sched/sys_preferred_idle_mask_high 0x1ff + write /proc/vendor_sched/groups/ta/preferred_idle_mask_low 0x1ff + write /proc/vendor_sched/groups/ta/preferred_idle_mask_mid 0x1ff + write /proc/vendor_sched/groups/ta/preferred_idle_mask_high 0x1ff + write /proc/vendor_sched/groups/fg/preferred_idle_mask_low 0x1ff + write /proc/vendor_sched/groups/fg/preferred_idle_mask_mid 0x1ff + write /proc/vendor_sched/groups/fg/preferred_idle_mask_high 0x1ff + write /proc/vendor_sched/groups/sys/preferred_idle_mask_low 0x1ff + write /proc/vendor_sched/groups/sys/preferred_idle_mask_mid 0x1ff + write /proc/vendor_sched/groups/sys/preferred_idle_mask_high 0x1ff # Setup final cpuset write /dev/cpuset/top-app/cpus 0-8 @@ -828,26 +828,26 @@ on property:sys.boot_completed=1 setprop vendor.powerhal.init 1 # Setup final cpu.uclamp - write /proc/vendor_sched/ta_uclamp_min 1 - write /proc/vendor_sched/fg_uclamp_min 0 - write /proc/vendor_sched/sys_prefer_idle 0 + write /proc/vendor_sched/groups/ta/uclamp_min 1 + write /proc/vendor_sched/groups/fg/uclamp_min 0 + write /proc/vendor_sched/groups/sys/prefer_idle 0 # Set ug group - write /proc/vendor_sched/bg_ug 0 - write /proc/vendor_sched/sysbg_ug 0 - write /proc/vendor_sched/ota_ug 0 - write /proc/vendor_sched/dex2oat_ug 1 - write /proc/vendor_sched/ta_ug 1 + write /proc/vendor_sched/groups/bg/ug 0 + write /proc/vendor_sched/groups/sys_bg/ug 0 + write /proc/vendor_sched/groups/ota/ug 0 + write /proc/vendor_sched/groups/dex2oat/ug 1 + write /proc/vendor_sched/groups/ta/ug 1 # Set bg group throttle write /proc/vendor_sched/ug_bg_group_throttle ${persist.device_config.vendor_system_native.ug_bg_group_throttle:-308} # Set uclamp.max for some groups, which could indicate cpu importance used in scheduling write /proc/vendor_sched/auto_uclamp_max "130 130 130 130 512 512 512 512 670" - write /proc/vendor_sched/bg_uclamp_max 130 - write /proc/vendor_sched/sysbg_uclamp_max 512 - write /proc/vendor_sched/ota_uclamp_max 512 - write /proc/vendor_sched/dex2oat_uclamp_max -2 + write /proc/vendor_sched/groups/bg/uclamp_max 130 + write /proc/vendor_sched/groups/sys_bg/uclamp_max 512 + write /proc/vendor_sched/groups/ota/uclamp_max 512 + write /proc/vendor_sched/groups/dex2oat/uclamp_max -2 write /proc/vendor_sched/uclamp_max_filter_divider 4 write /proc/vendor_sched/uclamp_max_filter_rt 16 @@ -1150,12 +1150,12 @@ on charger # Cancel boot devfreq and uclamp write /sys/devices/platform/17000010.devfreq_mif/devfreq/17000010.devfreq_mif/exynos_data/cancel_boot_freq 1 - write /proc/vendor_sched/ta_uclamp_min 0 - write /proc/vendor_sched/ta_prefer_idle 0 - write /proc/vendor_sched/fg_uclamp_min 0 - write /proc/vendor_sched/fg_prefer_idle 0 - write /proc/vendor_sched/sys_uclamp_min 0 - write /proc/vendor_sched/sys_prefer_idle 0 + write /proc/vendor_sched/groups/ta/uclamp_min 0 + write /proc/vendor_sched/groups/ta/prefer_idle 0 + write /proc/vendor_sched/groups/fg/uclamp_min 0 + write /proc/vendor_sched/groups/fg/prefer_idle 0 + write /proc/vendor_sched/groups/sys/uclamp_min 0 + write /proc/vendor_sched/groups/sys/prefer_idle 0 on property:vendor.disable.bcl.control=1 write /sys/devices/virtual/pmic/mitigation/instruction/enable_mitigation 0 diff --git a/task_profiles.json b/task_profiles.json index 961857de..fda6c3ea 100644 --- a/task_profiles.json +++ b/task_profiles.json @@ -7,8 +7,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_ta", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_ta", + "FilePath": "/proc/vendor_sched/groups/ta/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/ta/set_proc_group", "Value": "", "LogFailures": "false" } @@ -22,8 +22,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_cam", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_cam", + "FilePath": "/proc/vendor_sched/groups/cam/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/cam/set_proc_group", "Value": "", "LogFailures": "false" } @@ -37,8 +37,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_cam_power", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_cam_power", + "FilePath": "/proc/vendor_sched/groups/cam_power/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/cam_power/set_proc_group", "Value": "", "LogFailures": "false" } @@ -52,8 +52,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_dex2oat", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_dex2oat", + "FilePath": "/proc/vendor_sched/groups/dex2oat/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/dex2oat/set_proc_group", "Value": "", "LogFailures": "false" } @@ -67,8 +67,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_ota", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_ota", + "FilePath": "/proc/vendor_sched/groups/ota/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/ota/set_proc_group", "Value": "", "LogFailures": "false" } @@ -121,8 +121,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_bg", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_bg", + "FilePath": "/proc/vendor_sched/groups/bg/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/bg/set_proc_group", "Value": "", "LogFailures": "false" } @@ -136,8 +136,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_sys", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_sys", + "FilePath": "/proc/vendor_sched/groups/sys/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/sys/set_proc_group", "Value": "", "LogFailures": "false" } @@ -151,8 +151,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_fg", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_fg", + "FilePath": "/proc/vendor_sched/groups/fg/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/fg/set_proc_group", "Value": "", "LogFailures": "false" } @@ -166,8 +166,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_ta", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_ta", + "FilePath": "/proc/vendor_sched/groups/ta/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/ta/set_proc_group", "Value": "", "LogFailures": "false" } @@ -181,8 +181,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_nnapi", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_nnapi", + "FilePath": "/proc/vendor_sched/groups/nnapi/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/nnapi/set_proc_group", "Value": "", "LogFailures": "false" } @@ -196,8 +196,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_sysbg", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_sysbg", + "FilePath": "/proc/vendor_sched/groups/sys_bg/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/sys_bg/set_proc_group", "Value": "", "LogFailures": "false" } @@ -219,8 +219,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_sf", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_sf", + "FilePath": "/proc/vendor_sched/groups/sf/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/sf/set_proc_group", "Value": "", "LogFailures": "false" } @@ -242,8 +242,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_rt", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_rt", + "FilePath": "/proc/vendor_sched/groups/rt/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/rt/set_proc_group", "Value": "", "LogFailures": "false" } From 77b0f3fc8c55f7cc934d380c6d295aa5f47ffc5f Mon Sep 17 00:00:00 2001 From: Jing Wang Date: Thu, 28 Sep 2023 21:03:10 +0000 Subject: [PATCH 071/133] Revert "init.debug.rc: enable etm/etm2dram when SJTAG is unlocked" Revert submission 24754347-zuma-etm2dram Reason for revert: b/302352974 Reverted changes: /q/submissionid:24754347-zuma-etm2dram Bug: 302352974 Change-Id: I937658f7c78a97e2c3065a05058353b5cf16e860 Signed-off-by: Jing Wang --- conf/init.check_ap_pd_auth.sh | 15 --------------- conf/init.debug.rc | 11 ----------- device.mk | 3 +-- 3 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 conf/init.check_ap_pd_auth.sh diff --git a/conf/init.check_ap_pd_auth.sh b/conf/init.check_ap_pd_auth.sh deleted file mode 100644 index 8175e754..00000000 --- a/conf/init.check_ap_pd_auth.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/vendor/bin/sh - -# This script sets up `ro.vendor.sjtag_ap_is_unlocked` for the non-fused -# device. For a fused device, this property should be set by -# betterbug->ss-restart-detector when PD is acquired. - -SJTAG_STATUS=0x$(cat /sys/devices/platform/sjtag_ap/interface/status) -SOFT_LOCK_BIT=4 -AUTH_PASS_BIT=8 - -# Unlocked or locked but auth passed. -if test "$((SJTAG_STATUS & (1 << SOFT_LOCK_BIT)))" = 0 -o \ - "$((SJTAG_STATUS & (1 << AUTH_PASS_BIT)))" != 0 ; then - setprop ro.vendor.sjtag_ap_is_unlocked true -fi diff --git a/conf/init.debug.rc b/conf/init.debug.rc index f86f224b..019a514b 100644 --- a/conf/init.debug.rc +++ b/conf/init.debug.rc @@ -50,14 +50,3 @@ on property:persist.sys.device_provisioned=1 && property:ro.revision=PROTO1.1 start vendor.force_pkvm on property:persist.sys.device_provisioned=1 && property:ro.revision=EVT1.0 start vendor.force_pkvm - -service vendor.check_ap_pd_auth_sh /vendor/bin/init.check_ap_pd_auth.sh - class main - user root - group root system - oneshot - -# Enable etm/etm2dram when ramdump is enabled, and ap-sjtag is unlocked. -on property:ro.boot.ramdump=enabled && property:ro.vendor.sjtag_ap_is_unlocked=true - write /sys/devices/platform/exynos-etm/etm_on 1 - write /sys/devices/platform/etm2dram/arm 1 diff --git a/device.mk b/device.mk index fef49dc2..a3f5f1d1 100644 --- a/device.mk +++ b/device.mk @@ -342,8 +342,7 @@ PRODUCT_COPY_FILES += \ ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) PRODUCT_COPY_FILES += \ - device/google/zuma/conf/init.debug.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.debug.rc \ - device/google/zuma/conf/init.check_ap_pd_auth.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.check_ap_pd_auth.sh + device/google/zuma/conf/init.debug.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.debug.rc PRODUCT_COPY_FILES += \ device/google/zuma/conf/init.freq.userdebug.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.freq.userdebug.rc endif From 5aa4f0519f87bfb2a98f1cd655d3d16449d799fb Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Wed, 20 Sep 2023 23:33:14 +0000 Subject: [PATCH 072/133] usb: upgrade stats AIDL to v2 Upgrade stats AIDL to v2 following pixelstats lib. Bug: 297224564 Test: Build Change-Id: Ia9837a8ea568c788a1a6044ff37c05172c019c2d --- usb/usb/Android.bp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index b1e0a9ea..a8842385 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -49,7 +49,7 @@ cc_binary { "android.hardware.usb-V2-ndk", "android.hardware.usb.gadget-V1-ndk", "libcutils", - "android.frameworks.stats-V1-ndk", + "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", "libbinder_ndk", @@ -60,7 +60,7 @@ cc_binary { "libthermalutils", ], export_shared_lib_headers: [ - "android.frameworks.stats-V1-ndk", + "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", ], } From eee0edf9dad342aec5a50b781e5dded1c759ca5e Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Fri, 22 Sep 2023 07:28:07 +0000 Subject: [PATCH 073/133] Add default allow list for VRR small dirty detection The feature will be enabled by the feature flag Bug: 283055450 Test: Build Change-Id: Iefe4553da799f11121197b165c7db58eb169b2d8 --- .../frameworks/base/core/res/res/values/config.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 60563321..d2dbfc71 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -287,4 +287,17 @@ false + + + + + com.google.android.youtube:0.07 + com.spotify.music:0.05 + com.reddit.frontpage:0.07 + com.zhiliaoapp.musically:0.07 + com.bilibili.app.in:0.07 + com.twitter.android:0.07 + From f800b2645cecaa861941a368765e9f760528e388 Mon Sep 17 00:00:00 2001 From: Jenny Ho Date: Wed, 4 Oct 2023 00:46:12 +0800 Subject: [PATCH 074/133] init: add battery persist folder add persist battery folder for BatteryDefender Bug: 303191266 Change-Id: I7e8c1e536510f24572a6c69c460f00d41e652fe4 Signed-off-by: Jenny Ho --- conf/init.zuma.rc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 2cc2d338..e9b3da62 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -640,6 +640,9 @@ on fs mount_all /vendor/etc/fstab.modem --early restorecon_recursive /mnt/vendor/modem_img + # for battery defender + mkdir /mnt/vendor/persist/battery 0700 system system + restorecon_recursive /mnt/vendor/persist restorecon_recursive /mnt/vendor/persist/aoc restorecon_recursive /mnt/vendor/persist/audio From 70ed82576772e0f70b9aacc77dcfeaa22e0c64a9 Mon Sep 17 00:00:00 2001 From: Poomarin Phloyphisut Date: Mon, 4 Sep 2023 15:47:22 +0000 Subject: [PATCH 075/133] pixelstats: add offload_effects sysfs for VendorAudioOffloadedEffectStatsReported Bug: 301046889 Test: Local Test Change-Id: I72e01f52a0b893114e0681b73a27378fd59eb739 --- pixelstats/service.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index 4f7e18b7..44490518 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -97,7 +97,9 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { .CCARatePath = "/sys/devices/platform/audiometrics/cca_count_read_once", .PcmLatencyPath = "/sys/devices/platform/audiometrics/pcm_latency", .PcmCountPath = "/sys/devices/platform/audiometrics/pcm_count", - .TotalCallCountPath = "/sys/devices/platform/audiometrics/call_count" + .TotalCallCountPath = "/sys/devices/platform/audiometrics/call_count", + .OffloadEffectsIdPath = "/sys/devices/platform/audiometrics/offload_effects_id", + .OffloadEffectsDurationPath = "/sys/devices/platform/audiometrics/offload_effects_duration" }; const struct UeventListener::UeventPaths ueventPaths = { From 6ac2b06ae52fbff18ec32e303220f75097c2d7ab Mon Sep 17 00:00:00 2001 From: kierancyphus Date: Wed, 4 Oct 2023 17:48:54 +0800 Subject: [PATCH 076/133] Add Lassen Default Mask to list of masks In this case, there is no metric or trace configuration that we need to add so simply adding a `.conf` file is sufficient. Test: build, flash and run `adb shell find vendor -name *lassen_default*` and ensure that the file is there. Bug: 302435001 Change-Id: Id43fb3f3db86cdbe0c3a24f7a6e0af6fa14ae9d8 --- device.mk | 4 +++ radio/config/lassen_default/Android.bp | 33 ++++++++++++++++++++++++ radio/config/lassen_default/logging.conf | 1 + 3 files changed, 38 insertions(+) create mode 100644 radio/config/lassen_default/Android.bp create mode 100644 radio/config/lassen_default/logging.conf diff --git a/device.mk b/device.mk index fef49dc2..8d4c5eeb 100644 --- a/device.mk +++ b/device.mk @@ -1001,6 +1001,10 @@ PRODUCT_PACKAGES += \ empty_modem_log_mask.nprf \ empty_modem_log_mask.xml +# Lassen default log mask +PRODUCT_PACKAGES += \ + lassen_default.conf + endif # Vibrator Diag diff --git a/radio/config/lassen_default/Android.bp b/radio/config/lassen_default/Android.bp new file mode 100644 index 00000000..35b0715d --- /dev/null +++ b/radio/config/lassen_default/Android.bp @@ -0,0 +1,33 @@ +// +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: [ + "//device/google/zuma:device_google_zuma_license", + ], +} + +prebuilt_etc { + name: "lassen_default.conf", + vendor: true, + proprietary: true, + src: "logging.conf", + relative_install_path: "radio/log_masks/lassen_default" +} diff --git a/radio/config/lassen_default/logging.conf b/radio/config/lassen_default/logging.conf new file mode 100644 index 00000000..69fbd5fe --- /dev/null +++ b/radio/config/lassen_default/logging.conf @@ -0,0 +1 @@ +modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -i 1 --enable_exmetric --enable_exmetric_internal \ No newline at end of file From ccb35c81ff0bbfb013136bae7a572280b196bd1a Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Wed, 20 Sep 2023 21:52:08 +0000 Subject: [PATCH 077/133] Usb: capture and upload Suez metric VendorUsbDataSessionEvent Upload metrics for the last data session that just ends upon data role changes. The change is purely metric collection and does not change any business logic. Bug: 297224564 Test: Trigger metric upload for both host and device mode and verify it by statsd_testdrive Change-Id: I823ae8712b7914cfc7f6c6379acb3749d13c0974 --- usb/usb/Android.bp | 2 +- usb/usb/Usb.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++-- usb/usb/Usb.h | 11 +++++- 3 files changed, 101 insertions(+), 5 deletions(-) diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index a8842385..ef6cdcfc 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -52,7 +52,7 @@ cc_binary { "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", "libbinder_ndk", - + "libprotobuf-cpp-lite", ], static_libs: [ "libpixelusb-aidl", diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 40307af3..3fb1f0df 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -42,6 +42,7 @@ #include "Usb.h" #include +#include #include #include @@ -54,6 +55,9 @@ using android::base::Trim; using android::hardware::google::pixel::getStatsService; using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat; using android::hardware::google::pixel::reportUsbPortOverheat; +using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; +using android::hardware::google::pixel::reportUsbDataSessionEvent; +using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; namespace aidl { namespace android { @@ -98,6 +102,8 @@ void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); AltModeData::DisplayPortAltModeData constructAltModeData(string hpd, string pin_assignment, string link_status, string vdo); +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus); #define USB_STATE_MAX_LEN 20 @@ -957,6 +963,7 @@ void queryVersionHelper(android::hardware::usb::Usb *usb, queryMoistureDetectionStatus(currentPortStatus); queryPowerTransferStatus(currentPortStatus); queryNonCompliantChargerStatus(currentPortStatus); + queryUsbDataSession(usb, currentPortStatus); pthread_mutex_lock(&usb->mDisplayPortLock); if (!usb->mDisplayPortFirstSetupDone && usb->getDisplayPortUsbPathHelper(&displayPortUsbPath) == Status::SUCCESS) { @@ -1052,6 +1059,54 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } +void report_usb_data_session_event(android::hardware::usb::Usb *usb) { + std::vector events; + + if (usb->mDataRole == PortDataRole::DEVICE) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(false /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, &usb->mDeviceState.states, + &usb->mDeviceState.timestamps, &event); + events.push_back(event); + } else if (usb->mDataRole == PortDataRole::HOST) { + bool empty = true; + for (auto &entry : usb->mHostStateMap) { + // Host port will at least get an not_attached event after enablement, + // skip upload if no additional state is added. + if (entry.second.states.size() > 1) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, &entry.second.states, + &entry.second.timestamps, &event); + events.push_back(event); + empty = false; + } + } + // All host ports have no state update, upload an event to reflect it + if (empty && usb->mHostStateMap.size() > 0) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, + &usb->mHostStateMap.begin()->second.states, + &usb->mHostStateMap.begin()->second.timestamps, + &event); + events.push_back(event); + } + } else { + return; + } + + const shared_ptr stats_client = getStatsService(); + if (!stats_client) { + ALOGE("Unable to get AIDL Stats service"); + return; + } + + for (auto &event : events) { + reportUsbDataSessionEvent(stats_client, event); + } +} + struct data { int uevent_fd; ::aidl::android::hardware::usb::Usb *usb; @@ -1141,14 +1196,16 @@ static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, } static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { - device->latestState.clear(); + device->states.clear(); + device->timestamps.clear(); device->portResetCount = 0; } static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { ALOGI("Update USB device state: %s", state); - device->latestState = state; + device->states.push_back(state); + device->timestamps.push_back(std::chrono::steady_clock::now()); if (!std::strcmp(state, "configured\n")) { device->portResetCount = 0; @@ -1168,6 +1225,37 @@ static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); } +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + PortDataRole newDataRole = (*currentPortStatus)[0].currentDataRole; + PowerBrickStatus newPowerBrickStatus = (*currentPortStatus)[0].powerBrickStatus; + + if (newDataRole != usb->mDataRole) { + // Upload metrics for the last non-powerbrick data session that has ended + if (usb->mDataRole != PortDataRole::NONE && !usb->mIsPowerBrickConnected) { + report_usb_data_session_event(usb); + } + + // Set up for the new data session + usb->mDataRole = newDataRole; + usb->mDataSessionStart = std::chrono::steady_clock::now(); + usb->mIsPowerBrickConnected = (newPowerBrickStatus == PowerBrickStatus::CONNECTED); + if (newDataRole == PortDataRole::DEVICE) { + clearUsbDeviceState(&usb->mDeviceState); + } else if (newDataRole == PortDataRole::HOST) { + for (auto &entry : usb->mHostStateMap) { + clearUsbDeviceState(&entry.second); + } + } + } + + // PowerBrickStatus could flip from DISCONNECTED to CONNECTED during the same data + // session when BC1.2 SDP times out and falls back to DCP + if (newPowerBrickStatus == PowerBrickStatus::CONNECTED) { + usb->mIsPowerBrickConnected = true; + } +} + static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; @@ -1263,7 +1351,6 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); } else if (action == "unbind") { unregisterEpollEntry(payload->usb, path); - clearUsbDeviceState(&payload->usb->mHostStateMap[path]); } } } diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 566fc73c..2cb8f2df 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -132,12 +133,20 @@ struct Usb : public BnUsb { // USB device state monitoring struct usbDeviceState { - std::string latestState; + // Usb device state raw strings read from sysfs + std::vector states; + // Timestamps of when the usb device states were captured + std::vector timestamps; int portResetCount; }; struct usbDeviceState mDeviceState; // Map host device path name to usbDeviceState std::map mHostStateMap; + // Cache relevant info for USB data session metrics collection when a session starts, including + // the data role, power brick status and the time when the session starts. + PortDataRole mDataRole; + bool mIsPowerBrickConnected; + std::chrono::steady_clock::time_point mDataSessionStart; // File monitoring through epoll int mEpollFd; From f1a0e753966f9c6d02c3c9a39db47dfe14e79fde Mon Sep 17 00:00:00 2001 From: Poomarin Phloyphisut Date: Mon, 10 Jul 2023 09:45:05 +0000 Subject: [PATCH 078/133] pixelstats: add bt_usage sysfs for VendorAudioBTMediaStatsReported Bug: 280248992 Test: Local Test Change-Id: I47e5c64503155f7102b90ed43fed2143661cf305 --- pixelstats/service.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index 44490518..2426eabe 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -99,7 +99,8 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { .PcmCountPath = "/sys/devices/platform/audiometrics/pcm_count", .TotalCallCountPath = "/sys/devices/platform/audiometrics/call_count", .OffloadEffectsIdPath = "/sys/devices/platform/audiometrics/offload_effects_id", - .OffloadEffectsDurationPath = "/sys/devices/platform/audiometrics/offload_effects_duration" + .OffloadEffectsDurationPath = "/sys/devices/platform/audiometrics/offload_effects_duration", + .BluetoothAudioUsagePath = "/sys/devices/platform/audiometrics/bt_usage" }; const struct UeventListener::UeventPaths ueventPaths = { From 3c42b0fd718a119325d5b850628566670ab010d1 Mon Sep 17 00:00:00 2001 From: Rios Kao Date: Fri, 15 Sep 2023 07:18:12 +0000 Subject: [PATCH 079/133] aidl: enable AIDL AudioHal for zuma by RELEASE_PIXEL_AIDL_AUDIO_HAL Bug: 301180586 Test: build with flag enable Change-Id: Ic799f9a139376eea6c74f8d521d66f5101e50ba6 --- device.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/device.mk b/device.mk index a3f5f1d1..873914ef 100644 --- a/device.mk +++ b/device.mk @@ -1015,7 +1015,11 @@ PRODUCT_PACKAGES += \ # Audio # Audio HAL Server & Default Implementations +ifeq ($(RELEASE_PIXEL_AIDL_AUDIO_HAL),true) +include device/google/gs-common/audio/aidl.mk +else include device/google/gs-common/audio/hidl_zuma.mk +endif ## AoC soong PRODUCT_SOONG_NAMESPACES += \ From f08b6e4d8452cc1f00709b1e224dc5187ecf7a0b Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 11 Oct 2023 20:49:34 -0700 Subject: [PATCH 080/133] zuma: change swap_free_low_percentage to 10 Since LMKD introduced aggressive kill for cached apps, we can change the swap_free_low_percentage back to 10. Bug: 300660611 Change-Id: I688f2559698c7553a7f585cab2693d09d70731f4 Signed-off-by: Minchan Kim --- device.mk | 4 ---- 1 file changed, 4 deletions(-) diff --git a/device.mk b/device.mk index 873914ef..cc8a1826 100644 --- a/device.mk +++ b/device.mk @@ -1160,10 +1160,6 @@ PRODUCT_VENDOR_PROPERTIES += ro.crypto.metadata_init_delete_all_keys.enabled?=tr PRODUCT_PROPERTY_OVERRIDES += \ ro.crypto.volume.options=aes-256-xts:aes-256-hctr2 -# Increase lmkd aggressiveness -PRODUCT_PROPERTY_OVERRIDES += \ - ro.lmk.swap_free_low_percentage=100 - # Hardware Info Collection include hardware/google/pixel/HardwareInfo/HardwareInfo.mk From 352f5117b0946ff85621c9e8a5fbccca3fd06964 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 6 Oct 2023 07:06:10 +0000 Subject: [PATCH 081/133] Update IDisplay to V10 Test: Build pass Bug: 299410182 Change-Id: I27eb14c2ab85cbbdc59db4039314340b20fe6731 Signed-off-by: Leo Chen --- device_framework_matrix_product.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index ab5af7c2..4dd5af4c 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -114,7 +114,7 @@ com.google.hardware.pixel.display - 9 + 10 IDisplay default From e4b0a42691e6864c60440a5c4df8e383a38f5245 Mon Sep 17 00:00:00 2001 From: Jasmine Cha Date: Mon, 16 Oct 2023 16:16:17 +0800 Subject: [PATCH 082/133] audio: remove prescale for BT absolute volume Bug: 302553525 Test: build pass Change-Id: Ie37a90ec57a00347f183bc0882372ce50a18db75 Signed-off-by: Jasmine Cha --- overlay/frameworks/base/core/res/res/values/config.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index d2dbfc71..9a989797 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -300,4 +300,13 @@ com.bilibili.app.in:0.07 com.twitter.android:0.07 + + + 100% + + + 100% + + + 100% From fd59789d148db4a2ba158a8f7469abd1ffa3ff37 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 16 Oct 2023 15:15:32 +0000 Subject: [PATCH 083/133] Enable HDR shader priming in SurfaceFlinger Bug: 295257834 Test: manual - check that HDR shaders are generated after applying Change-Id: I157217a2f86d37dff3eacd7696df121f7b3820d7 --- device.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/device.mk b/device.mk index 873914ef..618aa8fa 100644 --- a/device.mk +++ b/device.mk @@ -294,6 +294,9 @@ PRODUCT_VENDOR_PROPERTIES += \ graphics.gpu.profiler.support=true \ debug.renderengine.backend=skiaglthreaded \ +# b/295257834 Add HDR shaders to SurfaceFlinger's pre-warming cache +PRODUCT_VENDOR_PROPERTIES += ro.surface_flinger.prime_shader_cache.ultrahdr=1 + # GRAPHICS - GPU (end) # #################### From d77b117b40dfb6c8dfa8a5ac35a0435db786e404 Mon Sep 17 00:00:00 2001 From: Jasmine Cha Date: Tue, 17 Oct 2023 15:12:53 +0800 Subject: [PATCH 084/133] audio: fix typo Bug: 305838207 Test: build pass/ recording runtime tuning Change-Id: I9b54b02373fc9a7acb90101941669461079fd60e Signed-off-by: Jasmine Cha --- BoardConfig-common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index b95275d0..7c0ed426 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -241,7 +241,7 @@ $(call soong_config_set,aoc_audio_func,ext_hidl,true) ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) $(call soong_config_set,aoc_audio_func,dump_usecase_data,true) $(call soong_config_set,aoc_audio_func,hal_socket_control,true) -$(call soong_config_set,aoc_audio_func,record_tunning_keys,true) +$(call soong_config_set,aoc_audio_func,record_tuning_keys,true) endif ifneq (,$(filter aosp_%,$(TARGET_PRODUCT))) From 90251c3e31c9a670a76b0aca07aad1be76e2da74 Mon Sep 17 00:00:00 2001 From: Sergey Volk Date: Wed, 23 Aug 2023 18:23:01 +0000 Subject: [PATCH 085/133] Add a sysprop for passing errors between HWC and SF Test: manual Bug: 283461313 Change-Id: Id18e4431d72533ba92b63fc6139abaf1cf7c7b5c --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index 0a06ebe2..9aa84fe9 100644 --- a/device.mk +++ b/device.mk @@ -680,6 +680,7 @@ PRODUCT_DEFAULT_PROPERTY_OVERRIDES += debug.sf.earlyGl.sf.duration=16600000 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += debug.sf.earlyGl.app.duration=16600000 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += debug.sf.frame_rate_multiple_threshold=120 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += debug.sf.treat_170m_as_sRGB=1 +PRODUCT_DEFAULT_PROPERTY_OVERRIDES += debug.sf.hwc_hotplug_error_via_neg_vsync=1 PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.surface_flinger.enable_layer_caching=true PRODUCT_DEFAULT_PROPERTY_OVERRIDES += ro.surface_flinger.set_idle_timer_ms?=80 From a3772510e6116ea2152940ed5acf53f2bad84fea Mon Sep 17 00:00:00 2001 From: Jacky Liu Date: Thu, 19 Oct 2023 17:34:33 +0800 Subject: [PATCH 086/133] Update i2c pathes with new static i2c bus numbers Bug: 305242309 Test: Boot to home Change-Id: I87687b2e3a479a166257ad958ddd07af7967f416 --- conf/init.zuma.rc | 6 +- dumpstate/dump_power.cpp | 13 +- usb/usb/android.hardware.usb-service.rc | 154 +++--------------------- 3 files changed, 19 insertions(+), 154 deletions(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 4e9b096b..45ef4764 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -238,11 +238,7 @@ on init chown system system /sys/class/power_supply/maxfg_base/m5_model_state # Dump eeprom - chown system system /sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom - chown system system /sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom - chown system system /sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom - chown system system /sys/devices/platform/10c90000.hsi2c/i2c-6/6-0050/eeprom - chown system system /sys/devices/platform/10c90000.hsi2c/i2c-7/7-0050/eeprom + chown system system /sys/devices/platform/10c90000.hsi2c/i2c-9/9-0050/eeprom chown system system /dev/battery_history chmod 0644 /dev/battery_history diff --git a/dumpstate/dump_power.cpp b/dumpstate/dump_power.cpp index e7ab364c..eb770fc3 100644 --- a/dumpstate/dump_power.cpp +++ b/dumpstate/dump_power.cpp @@ -151,7 +151,7 @@ void dumpPowerSupplyStats() { {"Power supply property gcpm_pps", "/sys/class/power_supply/gcpm_pps/uevent"}, {"Power supply property main-charger", "/sys/class/power_supply/main-charger/uevent"}, {"Power supply property dc-mains", "/sys/class/power_supply/dc-mains/uevent"}, - {"Power supply property tcpm", "/sys/class/power_supply/tcpm-source-psy-8-0025/uevent"}, + {"Power supply property tcpm", "/sys/class/power_supply/tcpm-source-psy-11-0025/uevent"}, {"Power supply property usb", "/sys/class/power_supply/usb/uevent"}, {"Power supply property wireless", "/sys/class/power_supply/wireless/uevent"}, }; @@ -420,12 +420,7 @@ void dumpChgUserDebug() { void dumpBatteryEeprom() { const char *title = "Battery EEPROM"; const char *files[] { - "/sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom", - "/sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom", - "/sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom", - "/sys/devices/platform/10da0000.hsi2c/i2c-7/7-0050/eeprom", - "/sys/devices/platform/10c90000.hsi2c/i2c-7/7-0050/eeprom", - "/sys/devices/platform/10c90000.hsi2c/i2c-6/6-0050/eeprom", + "/sys/devices/platform/10c90000.hsi2c/i2c-9/9-0050/eeprom", }; std::string result; std::string xxdCmd; @@ -714,9 +709,9 @@ void dumpIrqDurationCounts() { }; const char *lpfCurrentDirs[] = { - "/sys/devices/platform/acpm_mfd_bus@15500000/i2c-1/1-001f/s2mpg14-meter/" + "/sys/devices/platform/acpm_mfd_bus@15500000/i2c-7/7-001f/s2mpg14-meter/" "s2mpg14-odpm/iio:device1/lpf_current", - "/sys/devices/platform/acpm_mfd_bus@15510000/i2c-0/0-002f/s2mpg15-meter/" + "/sys/devices/platform/acpm_mfd_bus@15510000/i2c-8/8-002f/s2mpg15-meter/" "s2mpg15-odpm/iio:device0/lpf_current", }; diff --git a/usb/usb/android.hardware.usb-service.rc b/usb/usb/android.hardware.usb-service.rc index 4fe8d1b6..7619869a 100644 --- a/usb/usb/android.hardware.usb-service.rc +++ b/usb/usb/android.hardware.usb-service.rc @@ -9,76 +9,13 @@ on post-fs chown root system /sys/class/typec/port0/data_role chown root system /sys/class/typec/port0/port_type chown root system /sys/class/typec/port0/port0.0/mode1/active - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/contaminant_detection - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_accessory_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_accessory_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_sink_current - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_sink_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_source_enable - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/update_sdp_enum_timeout - chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/update_sdp_enum_timeout + chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/contaminant_detection + chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_accessory_current + chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_accessory_enable + chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_sink_current + chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_sink_enable + chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_source_enable + chown root system /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/update_sdp_enum_timeout chown root system /sys/devices/platform/110f0000.drmdp/drm-displayport/hpd chown root system /sys/devices/platform/110f0000.drmdp/drm-displayport/irq_hpd chown root system /sys/devices/platform/110f0000.drmdp/drm-displayport/orientation @@ -95,76 +32,13 @@ on post-fs chmod 664 /sys/devices/platform/11110000.usb/dwc3_exynos_otg_b_sess chmod 664 /sys/devices/platform/11110000.usb/dwc3_exynos_otg_id chmod 664 /sys/devices/platform/11110000.usb/usb_data_enabled - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/contaminant_detection - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_accessory_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_accessory_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_sink_current - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_sink_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/usb_limit_source_enable - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-0/0-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-1/1-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-2/2-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-3/3-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-4/4-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-5/5-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-6/6-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-7/7-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-8/8-0025/update_sdp_enum_timeout - chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-9/9-0025/update_sdp_enum_timeout + chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/contaminant_detection + chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_accessory_current + chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_accessory_enable + chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_sink_current + chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_sink_enable + chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/usb_limit_source_enable + chmod 664 /sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0025/update_sdp_enum_timeout chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/hpd chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/irq_hpd chmod 664 /sys/devices/platform/110f0000.drmdp/drm-displayport/orientation From 061526f4abf1d62e7fd51668bbb5a6bceb25c619 Mon Sep 17 00:00:00 2001 From: Jenny Ho Date: Mon, 16 Oct 2023 18:16:23 +0800 Subject: [PATCH 087/133] pixelstats: add gmsr path Bug: 300590097 Change-Id: I413431f41d8cc71727e9473fdf7ba74e2a68d629 Signed-off-by: Jenny Ho --- pixelstats/service.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index 2426eabe..da8545cd 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -100,7 +100,8 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { .TotalCallCountPath = "/sys/devices/platform/audiometrics/call_count", .OffloadEffectsIdPath = "/sys/devices/platform/audiometrics/offload_effects_id", .OffloadEffectsDurationPath = "/sys/devices/platform/audiometrics/offload_effects_duration", - .BluetoothAudioUsagePath = "/sys/devices/platform/audiometrics/bt_usage" + .BluetoothAudioUsagePath = "/sys/devices/platform/audiometrics/bt_usage", + .GMSRPath = "/sys/class/power_supply/maxfg/gmsr" }; const struct UeventListener::UeventPaths ueventPaths = { From 1ed6fd02358731b3e761c87916badac70d7e6e74 Mon Sep 17 00:00:00 2001 From: "Chris.CC Lee" Date: Mon, 23 Oct 2023 09:45:26 +0800 Subject: [PATCH 088/133] Grant the post notification permission to SearchSelector By the legal requirement, Pixel devices shipped in 2024 shall show the default browser/search engine selector. The SearchSelector app provides the selector flow and a non-dismissable notification to comply the requirement. This feature is approved for 24Q1 and is required to cherrypick to selected Pixel devices. Test: Flash a ROM build and validated the permission being granted by default. Bug: 298575926 Bug: 302280560 Change-Id: I86a4d77579039cd76c813103d91e56021ebda361 --- default-permissions.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/default-permissions.xml b/default-permissions.xml index 9175507b..d74b6c47 100644 --- a/default-permissions.xml +++ b/default-permissions.xml @@ -75,6 +75,11 @@ + + + + + From 7730eb106a8a9f1b038591000bcbb7ea5b76b835 Mon Sep 17 00:00:00 2001 From: Orhan Uysal Date: Tue, 24 Oct 2023 10:08:42 +0000 Subject: [PATCH 089/133] Revert "Grant the post notification permission to SearchSelector" Revert submission 25144243-Initial SearchSelector Drop Reason for revert: DroidMonitor-triggered revert due to a breakage, bug b/307486020 Bug: 307486020 Reverted changes: /q/submissionid:25144243-Initial+SearchSelector+Drop Change-Id: I141000a9bc18409652f8824f686793f1e4fdeb3d --- default-permissions.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/default-permissions.xml b/default-permissions.xml index d74b6c47..9175507b 100644 --- a/default-permissions.xml +++ b/default-permissions.xml @@ -75,11 +75,6 @@ - - - - - From 7061bc09aa69bb0bdc9cc9702bff84db28c011ec Mon Sep 17 00:00:00 2001 From: "Chris.CC Lee" Date: Tue, 24 Oct 2023 20:25:00 +0800 Subject: [PATCH 090/133] Grant the post notification permission to SearchSelector By the legal requirement, Pixel devices shipped in 2024 shall show the default browser/search engine selector. The SearchSelector app provides the selector flow and a non-dismissable notification to comply the requirement. This feature is approved for 24Q1 and is required to cherrypick to selected Pixel devices. Test: Flash a ROM build and validated the permission being granted by default. Bug: 298575926 Bug: 302280560 Change-Id: I895b9f0ed3980e31714ae0ee18071dab8b9039ec --- default-permissions.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/default-permissions.xml b/default-permissions.xml index 9175507b..d74b6c47 100644 --- a/default-permissions.xml +++ b/default-permissions.xml @@ -75,6 +75,11 @@ + + + + + From d9e91b754fa1f19f7a2495b84b0af2f63be9624d Mon Sep 17 00:00:00 2001 From: Edgar Arriaga Date: Wed, 25 Oct 2023 20:41:46 +0000 Subject: [PATCH 091/133] Add webview pinning for zuma devices Bug: 307594624 Change-Id: Ia87d5a5ac22382342f56dd655a9e17639cdb54bc --- overlay/frameworks/base/core/res/res/values/config.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index d2dbfc71..81da1973 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -252,6 +252,9 @@ true + + 20971520 + From 9c0fdde694ea4b180a9d6a6c58a4b8ecccf35817 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Wed, 25 Oct 2023 12:31:27 -0700 Subject: [PATCH 092/133] DO NOT MERGE - Run fsck to resolve possible data corruption Cherry-picked from http://ag/25163335. Trigger fsck on mount of /data if the value of ro.preventative_fsck is not equal to the contents of /metadata/vold/preventative_fsck, then set the file to the property to prevent future runs See b/305658663 for context Bug: 305658663 Test: Make sure fsck run after first boot and not after second Change-Id: I1263d2d55fe22d994ae8c8654b1e75ad9e4ddafe Change-Id: Ie6b9fc94752d91e77e8fc48979216917c1fd9ec3 Signed-off-by: Jaegeuk Kim --- device-common.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/device-common.mk b/device-common.mk index ece4678b..a97a76f4 100644 --- a/device-common.mk +++ b/device-common.mk @@ -47,6 +47,10 @@ PRODUCT_PRODUCT_PROPERTIES += \ # Set the max page size to 4096 (b/300367402) PRODUCT_MAX_PAGE_SIZE_SUPPORTED := 4096 +# Trigger fsck on upgrade (305658663) +PRODUCT_PRODUCT_PROPERTIES += \ + ro.preventative_fsck = 1 + # Indicate that the bootloader supports the MTE developer option switch # (MISC_MEMTAG_MODE_MEMTAG_ONCE), with the exception of _fullmte products that # force enable MTE. From 19eb98145d3d3abab65a25f75ccead8c562989f8 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Wed, 25 Oct 2023 12:31:27 -0700 Subject: [PATCH 093/133] DO NOT MERGE - Run fsck to resolve possible data corruption Cherry-picked from http://ag/25163335. Trigger fsck on mount of /data if the value of ro.preventative_fsck is not equal to the contents of /metadata/vold/preventative_fsck, then set the file to the property to prevent future runs See b/305658663 for context Bug: 305658663 Test: Make sure fsck run after first boot and not after second Change-Id: I1263d2d55fe22d994ae8c8654b1e75ad9e4ddafe Change-Id: Ie6b9fc94752d91e77e8fc48979216917c1fd9ec3 Merged-In: Ie6b9fc94752d91e77e8fc48979216917c1fd9ec3 Signed-off-by: Jaegeuk Kim --- device-common.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/device-common.mk b/device-common.mk index 8cb07f43..a260a8ac 100644 --- a/device-common.mk +++ b/device-common.mk @@ -44,6 +44,10 @@ PRODUCT_PRODUCT_PROPERTIES += \ PRODUCT_PRODUCT_PROPERTIES += \ ro.thermal_warmreset = true +# Trigger fsck on upgrade (305658663) +PRODUCT_PRODUCT_PROPERTIES += \ + ro.preventative_fsck = 1 + # Indicate that the bootloader supports the MTE developer option switch # (MISC_MEMTAG_MODE_MEMTAG_ONCE), with the exception of _fullmte products that # force enable MTE. From ee805f1dcc5dd17abc780ea1f6d3d34b82048418 Mon Sep 17 00:00:00 2001 From: Daniel Okazaki Date: Fri, 27 Oct 2023 18:46:12 +0000 Subject: [PATCH 094/133] dump_power: adding defender logs for charger and active time Bug: 306108267 Test: build/flash Test: adb bugreport Change-Id: I3f67e07853334457c74808869df78c323458f2df Signed-off-by: Daniel Okazaki --- dumpstate/dump_power.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dumpstate/dump_power.cpp b/dumpstate/dump_power.cpp index eb770fc3..696cc78a 100644 --- a/dumpstate/dump_power.cpp +++ b/dumpstate/dump_power.cpp @@ -314,10 +314,11 @@ void dumpBatteryHealth() { } void dumpBatteryDefend() { - const char* defendConfig [][3] { + const char* defendConfig [][4] { {"TRICKLE-DEFEND Config", "/sys/devices/platform/google,battery/power_supply/battery/", "bd_"}, {"DWELL-DEFEND Config", "/sys/devices/platform/google,charger/", "charge_s"}, + {"DWELL-DEFEND Time", "/mnt/vendor/persist/battery/", "defender_"}, {"TEMP-DEFEND Config", "/sys/devices/platform/google,charger/", "bd_"}, }; From 44082e91da7d9677c52aeaed79fa03e4c562c08f Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Wed, 25 Oct 2023 12:31:27 -0700 Subject: [PATCH 095/133] Run fsck to resolve possible data corruption Cherry-picked from 19eb98145d3d3abab65a25f75ccead8c562989f8. Trigger fsck on mount of /data if the value of ro.preventative_fsck is not equal to the contents of /metadata/vold/preventative_fsck, then set the file to the property to prevent future runs See b/305658663 for context Bug: 305658663 Test: Make sure fsck run after first boot and not after second Change-Id: Ie6b9fc94752d91e77e8fc48979216917c1fd9ec3 Signed-off-by: Jaegeuk Kim --- device-common.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/device-common.mk b/device-common.mk index 9ea275d1..f197763e 100644 --- a/device-common.mk +++ b/device-common.mk @@ -47,6 +47,10 @@ PRODUCT_PRODUCT_PROPERTIES += \ # Set the max page size to 4096 (b/300367402) PRODUCT_MAX_PAGE_SIZE_SUPPORTED := 4096 +# Trigger fsck on upgrade (305658663) +PRODUCT_PRODUCT_PROPERTIES += \ + ro.preventative_fsck = 1 + # Indicate that the bootloader supports the MTE developer option switch # (MISC_MEMTAG_MODE_MEMTAG_ONCE), with the exception of _fullmte products that # force enable MTE. From 89c02823d2656fb1811b1933a64e7b0842b4f375 Mon Sep 17 00:00:00 2001 From: Will Song Date: Fri, 27 Oct 2023 21:56:19 +0000 Subject: [PATCH 096/133] PREUPLOAD: Enforce jsonlint in preupload Checks syntax and simple brace balances for all JSON files. Test: Edit any json file and try upload Bug: 127794899 Change-Id: Ia302d5aa13328ca4e0c7c2c8b10bf54c2542a1ff --- PREUPLOAD.cfg | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 PREUPLOAD.cfg diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg new file mode 100644 index 00000000..37ebb5e7 --- /dev/null +++ b/PREUPLOAD.cfg @@ -0,0 +1,2 @@ +[Builtin Hooks] +jsonlint = true From da02d1018180c5d180cba8791d3209faffb3ad34 Mon Sep 17 00:00:00 2001 From: Jeff Chang Date: Wed, 1 Nov 2023 06:23:18 +0000 Subject: [PATCH 097/133] Update default allow list for VRR small dirty detection The feature will be enabled by the feature flag Bug: 308742727 Test: Build Change-Id: Ifb11472ca2c500923508cf175db130ab56ed9386 --- overlay/frameworks/base/core/res/res/values/config.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index d2dbfc71..42876f68 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -293,7 +293,9 @@ be between 0 to 1--> - com.google.android.youtube:0.07 + com.tencent.mm:0.07 + com.facebook.katana:0.07 + com.instagram.android:0.07 com.spotify.music:0.05 com.reddit.frontpage:0.07 com.zhiliaoapp.musically:0.07 From c09eb8dc6bf3c3fa8bd28cddab4f3119db72d429 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 6 Nov 2023 08:02:29 +0000 Subject: [PATCH 098/133] zuma: HWC access to panel refresh_ctrl node Bug: 295603692 Test: write the node successfully Change-Id: I7a5e908ec6d253791954d1b2071f3d59871650eb --- conf/init.zuma.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index 45ef4764..a95044bc 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -669,6 +669,7 @@ on fs chown system system /sys/devices/platform/exynos-drm/primary-panel/panel_idle chown system system /sys/devices/platform/exynos-drm/primary-panel/panel_need_handle_idle_exit chown system system /sys/devices/platform/exynos-drm/primary-panel/op_hz + chown system system /sys/devices/platform/exynos-drm/primary-panel/refresh_ctrl chown system system /sys/module/drm/parameters/vblankoffdelay chown system system /sys/module/drm/parameters/debug chown system system /sys/class/dqe0/atc/ambient_light From 5f6d9cc357d3a5c08cf736fc53fbbccf58ebcbd9 Mon Sep 17 00:00:00 2001 From: Jack Wu Date: Fri, 3 Nov 2023 11:37:37 +0800 Subject: [PATCH 099/133] dump_power: fix the problem of not being able to dump properties Bug: 309011602 Test: adb bugreport and check dumpstate_board.txt Change-Id: I8a6251e03bcf16b2c1f4242a724f1949dab75759 Signed-off-by: Jack Wu --- dumpstate/dump_power.cpp | 157 ++++++++++++++++++++++++++------------- 1 file changed, 107 insertions(+), 50 deletions(-) diff --git a/dumpstate/dump_power.cpp b/dumpstate/dump_power.cpp index 696cc78a..e334f58c 100644 --- a/dumpstate/dump_power.cpp +++ b/dumpstate/dump_power.cpp @@ -52,9 +52,20 @@ int getCommandOutput(const char *cmd, std::string *output) { } bool isValidFile(const char *file) { - if (!access(file, R_OK)) { - return false; + FILE *fp = fopen(file, "r"); + if (fp != NULL) { + fclose(fp); + return true; } + return false; +} + +bool isValidDir(const char *directory) { + DIR *dir = opendir(directory); + if (dir == NULL) + return false; + + closedir(dir); return true; } @@ -167,8 +178,8 @@ void dumpMaxFg() { const char *maxfg [][2] = { {"Power supply property maxfg", "/sys/class/power_supply/maxfg/uevent"}, {"m5_state", "/sys/class/power_supply/maxfg/m5_model_state"}, - {"maxfg", "/dev/logbuffer_maxfg"}, - {"maxfg", "/dev/logbuffer_maxfg_monitor"}, + {"maxfg logbuffer", "/dev/logbuffer_maxfg"}, + {"maxfg_monitor logbuffer", "/dev/logbuffer_maxfg_monitor"}, }; const char *maxfgFlip [][2] = { @@ -187,7 +198,7 @@ void dumpMaxFg() { std::string content; - if (isValidFile(maxfgLoc)) { + if (isValidDir(maxfgLoc)) { for (const auto &row : maxfg) { dumpFileContent(row[0], row[1]); } @@ -205,7 +216,9 @@ void dumpMaxFg() { void dumpPowerSupplyDock() { const char* powerSupplyPropertyDockTitle = "Power supply property dock"; const char* powerSupplyPropertyDockFile = "/sys/class/power_supply/dock/uevent"; - dumpFileContent(powerSupplyPropertyDockTitle, powerSupplyPropertyDockFile); + if (isValidFile(powerSupplyPropertyDockFile)) { + dumpFileContent(powerSupplyPropertyDockTitle, powerSupplyPropertyDockFile); + } } void dumpLogBufferTcpm() { @@ -286,14 +299,18 @@ void dumpWc68() { const char* wc68Title = "WC68"; const char* wc68File = "/dev/logbuffer_wc68"; - dumpFileContent(wc68Title, wc68File); + if (isValidFile(wc68File)) { + dumpFileContent(wc68Title, wc68File); + } } void dumpLn8411() { const char* ln8411Title = "LN8411"; const char* ln8411File = "/dev/logbuffer_ln8411"; - dumpFileContent(ln8411Title, ln8411File); + if (isValidFile(ln8411File)) { + dumpFileContent(ln8411Title, ln8411File); + } } void dumpBatteryHealth() { @@ -359,62 +376,102 @@ void dumpBatteryDefend() { } } -void dumpChgUserDebug() { +void printValuesOfDirectory(const char *directory, std::string debugfs, const char *strMatch) { std::vector files; - struct dirent *entry; + auto info = directory; std::string content; + struct dirent *entry; + DIR *dir = opendir(debugfs.c_str()); + if (dir == NULL) + return; - const char *chgUserDebug [][2] { - {"DC_registers dump", "/sys/class/power_supply/dc-mains/device/registers_dump"}, + printTitle((debugfs + std::string(strMatch) + "/" + std::string(info)).c_str()); + while ((entry = readdir(dir)) != NULL) + if (std::string(entry->d_name).find(strMatch) != std::string::npos) + files.push_back(entry->d_name); + closedir(dir); + + sort(files.begin(), files.end()); + + for (auto &file : files) { + std::string fileDirectory = debugfs + file; + std::string fileLocation = fileDirectory + "/" + std::string(info); + if (!android::base::ReadFileToString(fileLocation, &content)) { + content = "\n"; + } + + printf("%s:\n%s", fileDirectory.c_str(), content.c_str()); + + if (content.back() != '\n') + printf("\n"); + } + files.clear(); +} + +void dumpChgUserDebug() { + const char *chgDebugMax77759 [][2] { {"max77759_chg registers dump", "/d/max77759_chg/registers"}, {"max77729_pmic registers dump", "/d/max77729_pmic/registers"}, - {"Charging table dump", "/d/google_battery/chg_raw_profile"}, + }; + const char *chgDebugMax77779 [][2] { + {"max77779_chg registers dump", "/d/max77779_chg/registers"}, + {"max77779_pmic registers dump", "/d/max77779_pmic/registers"}, }; const std::string debugfs = "/d/"; - const char *maxFgStrMatch = "maxfg"; - const char *fgInfo [][2] { - {"fg_model", "fg_model"}, - {"fg_alo_ver", "algo_ver"}, - {"fg_model_ok", "model_ok"}, - {"fg registers", "registers"}, - {"Maxim FG NV RAM", "nv_registers"}, + const char *maxFgDir = "/d/maxfg"; + const char *maxFgStrMatch = "maxfg"; + const char *maxFg77779StrMatch = "max77779fg"; + const char *baseChgDir = "/d/max77759_chg"; + const char *dcRegName = "DC_registers dump"; + const char *dcRegDir = "/sys/class/power_supply/dc-mains/device/registers_dump"; + const char *chgTblName = "Charging table dump"; + const char *chgTblDir = "/d/google_battery/chg_raw_profile"; + + const char *maxFgInfo [] { + "fg_model", + "algo_ver", + "model_ok", + "registers", + "nv_registers", }; - if (!isUserBuild()) + const char *max77779FgInfo [] { + "fg_model", + "algo_ver", + "model_ok", + "registers", + "debug_registers", + }; + + if (isUserBuild()) return; - for (auto &row : chgUserDebug) { - dumpFileContent(row[0], row[1]); + if (isValidFile(dcRegDir)) { + dumpFileContent(dcRegName, dcRegDir); } - for (auto &info : fgInfo) { - DIR *dir = opendir(debugfs.c_str()); - if (dir == NULL) - return; - - printTitle(info[0]); - while ((entry = readdir(dir)) != NULL) - if (std::string(entry->d_name).find(maxFgStrMatch) != std::string::npos) - files.push_back(entry->d_name); - closedir(dir); - - sort(files.begin(), files.end()); - - for (auto &file : files) { - std::string fileDirectory = debugfs + file; - std::string fileLocation = fileDirectory + "/" + std::string(info[1]); - if (!android::base::ReadFileToString(fileLocation, &content)) { - content = "\n"; - } - - printf("%s:\n%s", fileDirectory.c_str(), content.c_str()); - - if (content.back() != '\n') - printf("\n"); + if (isValidDir(baseChgDir)) { + for (auto &row : chgDebugMax77759) { + dumpFileContent(row[0], row[1]); + } + } else { + for (auto &row : chgDebugMax77779) { + dumpFileContent(row[0], row[1]); + } + } + + dumpFileContent(chgTblName, chgTblDir); + + if (isValidDir(maxFgDir)) { + for (auto & directory : maxFgInfo) { + printValuesOfDirectory(directory, debugfs, maxFgStrMatch); + } + } else { + for (auto & directory : max77779FgInfo) { + printValuesOfDirectory(directory, debugfs, maxFg77779StrMatch); } - files.clear(); } } @@ -454,7 +511,7 @@ void dumpChargerStats() { dumpFileContent(chgStatsTitle, chgStatsLocation); - if (!isUserBuild()) + if (isUserBuild()) return; for (auto &stat : chargerStats) { @@ -509,7 +566,7 @@ void dumpGvoteables() { std::vector files; int ret; - if (!isUserBuild()) + if (isUserBuild()) return; ret = getFilesInDir(directory, &files); From 4c7ea96e6bf3c81c3bdee444559250ff1d46edb9 Mon Sep 17 00:00:00 2001 From: Devika Krishnadas Date: Tue, 7 Nov 2023 06:45:50 +0000 Subject: [PATCH 100/133] Revert^2 "Use graphics allocator 2" 5c5e1b804f1a5926f7db22cb3e748f6160414e86 Bug: 287353739 Test: VtsHalGraphicsMapperV4_0TargetTest Change-Id: I8ba05825ea3aba89b907adc11c01268ae425f6ed --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 1c929cb6..e35ce982 100644 --- a/device.mk +++ b/device.mk @@ -544,7 +544,7 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ android.hardware.graphics.mapper@4.0-impl \ - android.hardware.graphics.allocator-V1-service + android.hardware.graphics.allocator-V2-service PRODUCT_PACKAGES += \ android.hardware.memtrack-service.pixel \ From 398ceca7a97c684dc4388e4390c0873d7edd3100 Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Mon, 6 Nov 2023 23:12:46 +0000 Subject: [PATCH 101/133] usb: update incompatible charger warning reason Report COMPLIANCE_WARNING_INPUT_POWER_LIMITED instead of COMPLIANCE_WARNING_OTHER to flag incompatible chargers. The underlying logic that generates the warning remains the same, what's changed is the enum that's being used. The purpose of the change is to have a warning type that better represents what actually happens and free up COMPLIANCE_WARNING_OTHER that was intended to act as a fallback reason code. The flag enable_input_power_limited_warning controls whether to switch to the new enum, while the flag enable_usb_data_compliance_warning controls the new enums that are added as FlaggedApi in the framework. Both flags need to be on to enable the change. Bug: 308700954 Test: manual tests with local flag override Change-Id: I6595706d1b83d533fc2d3e29086773270e045ede --- usb/usb/Android.bp | 10 +++++++++- usb/usb/Usb.cpp | 21 ++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index ef6cdcfc..a67e617e 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -46,21 +46,29 @@ cc_binary { "android.hardware.thermal@2.0", "android.hardware.thermal-V1-ndk", "android.hardware.usb.gadget@1.0", - "android.hardware.usb-V2-ndk", + "android.hardware.usb-V3-ndk", "android.hardware.usb.gadget-V1-ndk", "libcutils", "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", "libbinder_ndk", "libprotobuf-cpp-lite", + "server_configurable_flags", ], static_libs: [ "libpixelusb-aidl", "libpixelstats", "libthermalutils", + "android.hardware.usb.flags-aconfig-c-lib", ], export_shared_lib_headers: [ "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", ], } + +cc_aconfig_library { + name: "android.hardware.usb.flags-aconfig-c-lib", + vendor: true, + aconfig_declarations: "android.hardware.usb.flags-aconfig", +} diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index b755e03c..53a1383e 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -42,10 +42,13 @@ #include "Usb.h" #include +#include #include #include #include +namespace usb_flags = android::hardware::usb::flags; + using aidl::android::frameworks::stats::IStats; using android::base::GetProperty; using android::base::Join; @@ -78,6 +81,7 @@ constexpr char kComplianceWarningBC12[] = "bc12"; constexpr char kComplianceWarningDebugAccessory[] = "debug-accessory"; constexpr char kComplianceWarningMissingRp[] = "missing_rp"; constexpr char kComplianceWarningOther[] = "other"; +constexpr char kComplianceWarningInputPowerLimited[] = "input_power_limited"; constexpr char kStatusPath[] = "-0025/contaminant_detection_status"; constexpr char kSinkLimitEnable[] = "-0025/usb_limit_sink_enable"; constexpr char kSourceLimitEnable[] = "-0025/usb_limit_source_enable"; @@ -361,9 +365,20 @@ Status queryNonCompliantChargerStatus(std::vector *currentPortStatus continue; } if (!strncmp(reason.c_str(), kComplianceWarningOther, - strlen(kComplianceWarningOther))) { - (*currentPortStatus)[i].complianceWarnings.push_back(ComplianceWarning::OTHER); - continue; + strlen(kComplianceWarningOther)) || + !strncmp(reason.c_str(), kComplianceWarningInputPowerLimited, + strlen(kComplianceWarningInputPowerLimited))) { + if (usb_flags::enable_usb_data_compliance_warning() && + usb_flags::enable_input_power_limited_warning()) { + ALOGI("Report through INPUT_POWER_LIMITED warning"); + (*currentPortStatus)[i].complianceWarnings.push_back( + ComplianceWarning::INPUT_POWER_LIMITED); + continue; + } else { + (*currentPortStatus)[i].complianceWarnings.push_back( + ComplianceWarning::OTHER); + continue; + } } } if ((*currentPortStatus)[i].complianceWarnings.size() > 0 && From 9c8f2bdaeb74a23ea6cdade1f169900e8f27958e Mon Sep 17 00:00:00 2001 From: Alan Chen Date: Fri, 10 Nov 2023 10:05:11 +0800 Subject: [PATCH 102/133] Add extensive_logging config file Bug: 302417853 Test: manual, file shows on device Change-Id: I930d93ab5f3275bf39373cea51067b9787286da0 --- device.mk | 7 +++- radio/config/extensive_logging/Android.bp | 33 +++++++++++++++++++ .../extensive_logging/extensive_logging.conf | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 radio/config/extensive_logging/Android.bp create mode 100644 radio/config/extensive_logging/extensive_logging.conf diff --git a/device.mk b/device.mk index 1c929cb6..a2f1bc0e 100644 --- a/device.mk +++ b/device.mk @@ -422,6 +422,10 @@ PRODUCT_PROPERTY_OVERRIDES += \ persist.vendor.verbose_logging_enabled=false endif +# Vendor modem extensive logging default property +PRODUCT_PROPERTY_OVERRIDES += \ + persist.vendor.modem.extensive_logging_enabled=false + # CP Logging properties PRODUCT_PROPERTY_OVERRIDES += \ ro.vendor.sys.modem.logging.loc = /data/vendor/slog \ @@ -987,7 +991,8 @@ PRODUCT_PACKAGES += \ logging.conf \ default.cfg \ default.nprf \ - default_metrics.xml + default_metrics.xml \ + extensive_logging.conf # Log Masks for logmasklibrary below # default modem log mask diff --git a/radio/config/extensive_logging/Android.bp b/radio/config/extensive_logging/Android.bp new file mode 100644 index 00000000..679e4e46 --- /dev/null +++ b/radio/config/extensive_logging/Android.bp @@ -0,0 +1,33 @@ +// +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: [ + "//device/google/zuma:device_google_zuma_license", + ], +} + +prebuilt_etc { + name: "extensive_logging.conf", + vendor: true, + proprietary: true, + src: "extensive_logging.conf", + relative_install_path: "modem" +} diff --git a/radio/config/extensive_logging/extensive_logging.conf b/radio/config/extensive_logging/extensive_logging.conf new file mode 100644 index 00000000..9772cde6 --- /dev/null +++ b/radio/config/extensive_logging/extensive_logging.conf @@ -0,0 +1 @@ +modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -i 0 --enable_exmetric --enable_exmetric_internal --enable_dsp \ No newline at end of file From 74433bdbd33b703fcad4e9cecc58aee1da609ce9 Mon Sep 17 00:00:00 2001 From: Muralidhar Reddy Date: Fri, 3 Nov 2023 04:40:09 +0000 Subject: [PATCH 103/133] [LPA][Zuma] Add notification pregrant Bug: 308699419 Test: manual verification Change-Id: I8529edd2c60e831eaeb7c817bef047bafa7dc890 --- default-permissions.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/default-permissions.xml b/default-permissions.xml index d74b6c47..4dafb5b7 100644 --- a/default-permissions.xml +++ b/default-permissions.xml @@ -150,5 +150,10 @@ + + + + From 5c6e25c1b130d9aaa98f43e747650e9d7f0236f5 Mon Sep 17 00:00:00 2001 From: Jack Wu Date: Fri, 10 Nov 2023 20:10:33 +0800 Subject: [PATCH 104/133] zuma: update AIDL IGoogleBattery manifest version to 3 Bug: 309518527 Test: TH Change-Id: I6f80e0456eb5906feb4a6b0243765cbf6978b051 Signed-off-by: Jack Wu --- device_framework_matrix_product.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index 4dd5af4c..b5128682 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -161,7 +161,7 @@ vendor.google.google_battery - 2 + 2-3 IGoogleBattery default From c55415c1e27b03647e26b02f153092f8a29eacba Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Tue, 14 Nov 2023 20:41:47 +0000 Subject: [PATCH 105/133] usb: update usb hal version to v3 Bug: 308700954 Test: atest vts_treble_vintf_vendor_test Change-Id: I724a170a1403dec7eecbc33d7f532471f09b559f --- usb/usb/android.hardware.usb-service.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb/usb/android.hardware.usb-service.xml b/usb/usb/android.hardware.usb-service.xml index c3f07f52..7ac20679 100644 --- a/usb/usb/android.hardware.usb-service.xml +++ b/usb/usb/android.hardware.usb-service.xml @@ -1,7 +1,7 @@ android.hardware.usb - 2 + 3 IUsb default From 04d1e94d10515f03e66cdfe16a23924e561cb3f3 Mon Sep 17 00:00:00 2001 From: RD Babiera Date: Fri, 10 Nov 2023 22:17:00 +0000 Subject: [PATCH 106/133] usb: reattempt to enter displayport alt mode if driver entry process fails In the kernel, it is possible for the DisplayPort Alt Mode driver to queue an Enter Mode message to the tcpm and have that message be interupted by a Power Role or Vconn swap, which results in the Port Partner never entering Alt Mode. Add a debounce that checks to make sure that the port partner enters Alt Mode when DisplayPort Alt Mode is active on the port. On trigger, reattempt to send Enter Mode through the tcpm up to 2 times. Test: Manual test on device - put device into Preferred Source role, test to see if Alt Mode reentry triggers when original entry is interrupted by PR Swap from monitor. Bug: 308383356 Change-Id: I96563c9900a01e428850e4873371bcdb0225aa07 Signed-off-by: RD Babiera --- usb/usb/Usb.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++--- usb/usb/Usb.h | 11 +++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 53a1383e..e63fa1de 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -560,6 +560,11 @@ Usb::Usb() ALOGE("mDisplayPortDebounceTimer timerfd failed: %s", strerror(errno)); abort(); } + mDisplayPortActivateTimer = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); + if (mDisplayPortActivateTimer == -1) { + ALOGE("mDisplayPortActivateTimer timerfd failed: %s", strerror(errno)); + abort(); + } } ScopedAStatus Usb::switchRole(const string& in_portName, const PortRole& in_role, @@ -1721,6 +1726,10 @@ static int displayPortPollOpenFileHelper(const char *file, int flags) { return fd; } +/* + * armTimerFdHelper - Sets timerfd (fd) to trigger after (ms) milliseconds. + * Setting ms to 0 disarms the timer. + */ static int armTimerFdHelper(int fd, int ms) { struct itimerspec ts; @@ -1733,23 +1742,31 @@ static int armTimerFdHelper(int fd, int ms) { } void *displayPortPollWork(void *param) { + /* USB Payload */ + ::aidl::android::hardware::usb::Usb *usb = (::aidl::android::hardware::usb::Usb *)param; + /* Epoll fields */ int epoll_fd; struct epoll_event ev_hpd, ev_pin, ev_orientation, ev_eventfd, ev_link, ev_debounce; + struct epoll_event ev_activate; int nevents = 0; int hpd_fd, pin_fd, orientation_fd, link_training_status_fd; int file_flags = O_RDONLY; int epoll_flags; + /* DisplayPort link statuses */ bool orientationSet = false; bool pinSet = false; + int activateRetryCount = 0; unsigned long res; int ret = 0; + /* File paths */ string displayPortUsbPath, irqHpdCountPath, hpdPath, pinAssignmentPath, orientationPath; - string tcpcI2cBus, linkPath; - ::aidl::android::hardware::usb::Usb *usb = (::aidl::android::hardware::usb::Usb *)param; + string tcpcI2cBus, linkPath, partnerActivePath, portActivePath; usb->mDisplayPortPollRunning = true; usb->mDisplayPortPollStarting = false; + /*---------- Setup ----------*/ + if (usb->getDisplayPortUsbPathHelper(&displayPortUsbPath) == Status::ERROR) { ALOGE("usbdp: worker: could not locate usb displayport directory"); goto usb_path_error; @@ -1761,6 +1778,9 @@ void *displayPortPollWork(void *param) { orientationPath = "/sys/class/typec/port0/orientation"; linkPath = string(kDisplayPortDrmPath) + "link_status"; + partnerActivePath = displayPortUsbPath + "../mode1/active"; + portActivePath = "/sys/class/typec/port0/port0.0/mode1/active"; + getI2cBusHelper(&tcpcI2cBus); irqHpdCountPath = kI2CPath + tcpcI2cBus + "/" + tcpcI2cBus + kIrqHpdCounPath; ALOGI("usbdp: worker: irqHpdCountPath:%s", irqHpdCountPath.c_str()); @@ -1793,12 +1813,15 @@ void *displayPortPollWork(void *param) { ev_eventfd.events = epoll_flags; ev_link.events = epoll_flags; ev_debounce.events = epoll_flags; + ev_activate.events = epoll_flags; + ev_hpd.data.fd = hpd_fd; ev_pin.data.fd = pin_fd; ev_orientation.data.fd = orientation_fd; ev_eventfd.data.fd = usb->mDisplayPortEventPipe; ev_link.data.fd = link_training_status_fd; ev_debounce.data.fd = usb->mDisplayPortDebounceTimer; + ev_activate.data.fd = usb->mDisplayPortActivateTimer; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, hpd_fd, &ev_hpd) == -1) { ALOGE("usbdp: worker: epoll_ctl failed to add hpd; errno=%d", errno); @@ -1817,7 +1840,11 @@ void *displayPortPollWork(void *param) { goto error; } if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, usb->mDisplayPortDebounceTimer, &ev_debounce) == -1) { - ALOGE("usbdp: worker: epoll_ctl failed to add debounce; errno=%d", errno); + ALOGE("usbdp: worker: epoll_ctl failed to add framework update debounce; errno=%d", errno); + goto error; + } + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, usb->mDisplayPortActivateTimer, &ev_activate) == -1) { + ALOGE("usbdp: worker: epoll_ctl failed to add activate debounce; errno=%d", errno); goto error; } if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, usb->mDisplayPortEventPipe, &ev_eventfd) == -1) { @@ -1825,6 +1852,9 @@ void *displayPortPollWork(void *param) { goto error; } + /* Arm timer to see if DisplayPort Alt Mode Activates */ + armTimerFdHelper(usb->mDisplayPortActivateTimer, DISPLAYPORT_ACTIVATE_DEBOUNCE_MS); + while (!destroyDisplayPortThread) { struct epoll_event events[64]; @@ -1874,6 +1904,33 @@ void *displayPortPollWork(void *param) { if (ret < 0) ALOGE("usbdp: debounce read errno:%d", errno); queryVersionHelper(usb, ¤tPortStatus); + } else if (events[n].data.fd == usb->mDisplayPortActivateTimer) { + string activePartner, activePort; + + if (ReadFileToString(partnerActivePath.c_str(), &activePartner) && + ReadFileToString(portActivePath.c_str(), &activePort)) { + // Retry activate signal when DisplayPort Alt Mode is active on port but not + // partner. + if (!strncmp(activePartner.c_str(), "no", strlen("no")) && + !strncmp(activePort.c_str(), "yes", strlen("yes")) && + activateRetryCount < DISPLAYPORT_ACTIVATE_MAX_RETRIES) { + if (!WriteStringToFile("1", partnerActivePath)) { + ALOGE("usbdp: Failed to activate port partner Alt Mode"); + } else { + ALOGI("usbdp: Attempting to activate port partner Alt Mode"); + } + activateRetryCount++; + armTimerFdHelper(usb->mDisplayPortActivateTimer, + DISPLAYPORT_ACTIVATE_DEBOUNCE_MS); + } else { + ALOGI("usbdp: DisplayPort Alt Mode is active, or disabled on port"); + } + } else { + activateRetryCount++; + armTimerFdHelper(usb->mDisplayPortActivateTimer, + DISPLAYPORT_ACTIVATE_DEBOUNCE_MS); + ALOGE("usbdp: Failed to read active state from port or partner"); + } } else if (events[n].data.fd == usb->mDisplayPortEventPipe) { uint64_t flag = 0; if (!read(usb->mDisplayPortEventPipe, &flag, sizeof(flag))) { @@ -1895,6 +1952,8 @@ void *displayPortPollWork(void *param) { } error: + /* Need to disarm so new threads don't get old event */ + armTimerFdHelper(usb->mDisplayPortActivateTimer, 0); close(link_training_status_fd); link_training_status_fd_error: close(orientation_fd); @@ -1904,6 +1963,7 @@ pin_fd_error: close(hpd_fd); hpd_fd_error: epoll_ctl(epoll_fd, EPOLL_CTL_DEL, usb->mDisplayPortDebounceTimer, &ev_debounce); + epoll_ctl(epoll_fd, EPOLL_CTL_DEL, usb->mDisplayPortActivateTimer, &ev_activate); epoll_ctl(epoll_fd, EPOLL_CTL_DEL, usb->mDisplayPortEventPipe, &ev_eventfd); close(epoll_fd); epoll_fd_error: diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 0b72d6ba..c1e53541 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -32,6 +32,13 @@ #define PORT_TYPE_TIMEOUT 8 #define DISPLAYPORT_CAPABILITIES_RECEPTACLE_BIT 6 #define DISPLAYPORT_STATUS_DEBOUNCE_MS 2000 +/* + * Type-C HAL should wait 2 seconds to reattempt DisplayPort Alt Mode entry to + * allow the port and port partner to settle Role Swaps. + */ +#define DISPLAYPORT_ACTIVATE_DEBOUNCE_MS 2000 +// Number of times the HAL should reattempt to enter DisplayPort Alt Mode +#define DISPLAYPORT_ACTIVATE_MAX_RETRIES 2 namespace aidl { namespace android { @@ -173,6 +180,10 @@ struct Usb : public BnUsb { * sending notifications to the frameworks layer. */ int mDisplayPortDebounceTimer; + /* + * eventfd to monitor whether a connection results in DisplayPort Alt Mode activating. + */ + int mDisplayPortActivateTimer; private: pthread_t mPoll; From 228db5e2a5527b64f6752c312858b9e5ea82d80b Mon Sep 17 00:00:00 2001 From: Jerry Huang Date: Wed, 15 Nov 2023 11:54:27 +0000 Subject: [PATCH 107/133] zuma: add c2.android.av1-dav1d.decoder in media_codecs_performance_c2.xml c2.android.av1-dav1d.decoder is based on dav1d implementation. This dav1d-based sw av1 decoder provides better decoding throughput than the default gav1-based av1 decoder on mid-to-low-tier devices. c2.android.av1.decoder will be deprecate eventually before that we keep both decoders. Bug: 309412792 Test: run cts -m CtsMediaDecoderTestCases -t android.media.decoder.cts.VideoDecoderPerfTest --module-arg CtsMediaDecoderTestCases:instrumentation-arg:codec-prefix:=c2.android.av1.decoder Change-Id: Ib66db8bf037de5ece05047f98bc176a79aca8aa7 --- media_codecs_performance_c2.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/media_codecs_performance_c2.xml b/media_codecs_performance_c2.xml index 924b1c3b..4dcb0b4b 100644 --- a/media_codecs_performance_c2.xml +++ b/media_codecs_performance_c2.xml @@ -171,6 +171,12 @@ + + + + + + From d7b343305d3da89cca0b8eaa18ea4959ded6c197 Mon Sep 17 00:00:00 2001 From: Ruofei Ma Date: Thu, 16 Nov 2023 18:04:53 +0000 Subject: [PATCH 108/133] Enable adaptive playback for BigWave Bug: 309722491 Change-Id: Ibc5a88efc535cc847fbde45541d451ee97c65a1e Signed-off-by: Ruofei Ma --- media_codecs_bo_c2.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/media_codecs_bo_c2.xml b/media_codecs_bo_c2.xml index 4c8c5758..443c27e4 100644 --- a/media_codecs_bo_c2.xml +++ b/media_codecs_bo_c2.xml @@ -29,7 +29,7 @@ - + @@ -44,7 +44,7 @@ - + From 9344919fe5a6831f6042685a03daa055cfef0a26 Mon Sep 17 00:00:00 2001 From: Luis Delgado de Mendoza Date: Tue, 14 Nov 2023 16:05:37 -0800 Subject: [PATCH 109/133] Ueventd changes for new BT channel in zuma Bug: 308452948 Test: Validated locally on husky. Change-Id: I4534d3c007f93e7dbd2ec3ed1f32d30ba8a90ea9 --- conf/ueventd.zuma.rc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/conf/ueventd.zuma.rc b/conf/ueventd.zuma.rc index dc2c2d4f..8564d994 100644 --- a/conf/ueventd.zuma.rc +++ b/conf/ueventd.zuma.rc @@ -155,6 +155,10 @@ /dev/acd-com.google.chre 0660 system system /dev/acd-com.google.chre.non_wake_up 0660 system system +# BT +/dev/acd-com.google.bt 0660 system system +/dev/acd-com.google.bt.non_wake_up 0660 system system + # LWIS /dev/lwis* 0660 system system From 741d0c09d7c1a4d562ddadf239e8f2f27ef9b822 Mon Sep 17 00:00:00 2001 From: kierancyphus Date: Wed, 1 Nov 2023 21:28:16 +0800 Subject: [PATCH 110/133] LogMaskLibrary: Add newlines and fix posix perms Bug:302435001 Test: Manually build, flash, `adb shell ls -l \ /data/vendor/radio` Change-Id: If2696c577e66ee27a042ebe8d6ff61a9e832caec --- conf/init.zuma.rc | 3 +++ radio/config/default/logging.conf | 2 +- radio/config/empty/logging.conf | 2 +- radio/config/lassen_default/logging.conf | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index a95044bc..d1d10a1f 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -409,6 +409,9 @@ on post-fs-data # Modem extended log folder mkdir /data/vendor/radio/extended_logs 0770 radio system + # Log Mask Library Mask storage paths + mkdir /data/vendor/radio/log_masks 777 system system + # Modem MDS log folder mkdir /data/vendor/radio/mds 0771 radio system diff --git a/radio/config/default/logging.conf b/radio/config/default/logging.conf index e852dd57..d4fe05bd 100644 --- a/radio/config/default/logging.conf +++ b/radio/config/default/logging.conf @@ -1 +1 @@ -modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -m /vendor/etc/modem/default.cfg --enable_exmetric --enable_exmetric_internal \ No newline at end of file +modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -m /vendor/etc/modem/default.cfg --enable_exmetric --enable_exmetric_internal diff --git a/radio/config/empty/logging.conf b/radio/config/empty/logging.conf index e852dd57..d4fe05bd 100644 --- a/radio/config/empty/logging.conf +++ b/radio/config/empty/logging.conf @@ -1 +1 @@ -modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -m /vendor/etc/modem/default.cfg --enable_exmetric --enable_exmetric_internal \ No newline at end of file +modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -m /vendor/etc/modem/default.cfg --enable_exmetric --enable_exmetric_internal diff --git a/radio/config/lassen_default/logging.conf b/radio/config/lassen_default/logging.conf index 69fbd5fe..f1c9db8f 100644 --- a/radio/config/lassen_default/logging.conf +++ b/radio/config/lassen_default/logging.conf @@ -1 +1 @@ -modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -i 1 --enable_exmetric --enable_exmetric_internal \ No newline at end of file +modem_logging_control START -o /data/vendor/radio/logs/always-on -n 50 -s 50 -i 1 --enable_exmetric --enable_exmetric_internal From e55232fbacd5e2c46b3c41333178c679900f870a Mon Sep 17 00:00:00 2001 From: Martin Liu Date: Tue, 21 Nov 2023 10:24:32 +0000 Subject: [PATCH 111/133] adjust PCP high level We have observed more reclaiming activities as upstream has changed how PCP high is calculated since 5.15 kernel. Re-align the level back to 5.10 first so we can monitor how it impacts the MM metrics. Bug: 309409009 Test: boot Change-Id: I7ac1eb88a8dae7c823330a2c75aec9547bd5c427 Signed-off-by: Martin Liu --- conf/init.zuma.rc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/init.zuma.rc b/conf/init.zuma.rc index a95044bc..437b9b08 100644 --- a/conf/init.zuma.rc +++ b/conf/init.zuma.rc @@ -119,6 +119,9 @@ on init write /sys/block/zram0/comp_algorithm lz77eh write /proc/sys/vm/page-cluster 0 + # adjust PCP high level + write /proc/sys/vm/percpu_pagelist_high_fraction 430 + # Some user code relies on ro.boot.hardware.revision setprop ro.boot.hardware.revision ${ro.revision} From 251d00eb0e924ef6fb183e03c07122826d1c4f10 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Wed, 22 Nov 2023 11:24:27 +0000 Subject: [PATCH 112/133] Handle empty read from file. Test: run /vendor/bin/dump/dump_power Bug: 312681873 Change-Id: I8c49cf7f0048190f02d35d50984abca361d517f1 --- dumpstate/dump_power.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dumpstate/dump_power.cpp b/dumpstate/dump_power.cpp index e334f58c..9da35450 100644 --- a/dumpstate/dump_power.cpp +++ b/dumpstate/dump_power.cpp @@ -362,7 +362,7 @@ void dumpBatteryDefend() { for (auto &file : files) { fileLocation = std::string(config[1]) + std::string(file); - if (!android::base::ReadFileToString(fileLocation, &content)) { + if (!android::base::ReadFileToString(fileLocation, &content) || content.empty()) { content = "\n"; } From 04d36f987fd65efe722fa14c8f1ddf72c7f85591 Mon Sep 17 00:00:00 2001 From: Tai Kuo Date: Mon, 27 Nov 2023 14:27:27 +0800 Subject: [PATCH 113/133] Remove unused vibrator mk Bug: 246459244 Test: n/a Change-Id: I1b6f5411c38118e72d059c1c93c0a27dce7c1528 --- vibrator/Android.mk | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 vibrator/Android.mk diff --git a/vibrator/Android.mk b/vibrator/Android.mk deleted file mode 100644 index 5b089be2..00000000 --- a/vibrator/Android.mk +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright (C) 2020 The Android Open-Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include $(call first-makefiles-under, $(call my-dir)) From 719c85d06e068809cc42f3a1066c143bdc07b5ab Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 9 Nov 2023 21:03:09 +0800 Subject: [PATCH 114/133] zuma: move bootctrl hal to gs-common Bug: 265063384 Change-Id: I03d2f96928cfa3d2dc8aa15ac285bdef05780bfd Signed-off-by: Jason Chiu --- interfaces/boot/1.0/Android.bp | 66 --- interfaces/boot/1.0/BootControl.cpp | 272 --------- interfaces/boot/1.0/BootControl.h | 59 -- interfaces/boot/1.0/GptUtils.cpp | 199 ------- interfaces/boot/1.0/GptUtils.h | 79 --- .../android.hardware.boot@1.0-service-zuma.rc | 4 - interfaces/boot/1.0/service.cpp | 47 -- interfaces/boot/1.2/Android.bp | 83 --- interfaces/boot/1.2/BootControl.cpp | 501 ---------------- interfaces/boot/1.2/BootControl.h | 88 --- interfaces/boot/1.2/DevInfo.h | 61 -- interfaces/boot/1.2/GptUtils.cpp | 193 ------- interfaces/boot/1.2/GptUtils.h | 79 --- .../android.hardware.boot@1.2-service-zuma.rc | 7 - interfaces/boot/1.2/service.cpp | 50 -- interfaces/boot/aidl/Android.bp | 65 --- interfaces/boot/aidl/BootControl.cpp | 538 ------------------ interfaces/boot/aidl/BootControl.h | 61 -- interfaces/boot/aidl/DevInfo.h | 53 -- interfaces/boot/aidl/GptUtils.cpp | 185 ------ interfaces/boot/aidl/GptUtils.h | 71 --- ...roid.hardware.boot-service.default-zuma.rc | 5 - ...ware.boot-service.default_recovery-zuma.rc | 7 - ...are.boot-service.default_recovery-zuma.xml | 6 - interfaces/boot/aidl/service.cpp | 44 -- 25 files changed, 2823 deletions(-) delete mode 100644 interfaces/boot/1.0/Android.bp delete mode 100644 interfaces/boot/1.0/BootControl.cpp delete mode 100644 interfaces/boot/1.0/BootControl.h delete mode 100644 interfaces/boot/1.0/GptUtils.cpp delete mode 100644 interfaces/boot/1.0/GptUtils.h delete mode 100644 interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc delete mode 100644 interfaces/boot/1.0/service.cpp delete mode 100644 interfaces/boot/1.2/Android.bp delete mode 100644 interfaces/boot/1.2/BootControl.cpp delete mode 100644 interfaces/boot/1.2/BootControl.h delete mode 100644 interfaces/boot/1.2/DevInfo.h delete mode 100644 interfaces/boot/1.2/GptUtils.cpp delete mode 100644 interfaces/boot/1.2/GptUtils.h delete mode 100644 interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc delete mode 100644 interfaces/boot/1.2/service.cpp delete mode 100644 interfaces/boot/aidl/Android.bp delete mode 100644 interfaces/boot/aidl/BootControl.cpp delete mode 100644 interfaces/boot/aidl/BootControl.h delete mode 100644 interfaces/boot/aidl/DevInfo.h delete mode 100644 interfaces/boot/aidl/GptUtils.cpp delete mode 100644 interfaces/boot/aidl/GptUtils.h delete mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc delete mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc delete mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml delete mode 100644 interfaces/boot/aidl/service.cpp diff --git a/interfaces/boot/1.0/Android.bp b/interfaces/boot/1.0/Android.bp deleted file mode 100644 index 5599fafb..00000000 --- a/interfaces/boot/1.0/Android.bp +++ /dev/null @@ -1,66 +0,0 @@ -// -// Copyright (C) 2019 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/zuma:device_google_zuma_license", - ], -} - -cc_binary { - name: "android.hardware.boot@1.0-service-zuma", - defaults: ["hidl_defaults"], - relative_install_path: "hw", - vendor: true, - init_rc: ["android.hardware.boot@1.0-service-zuma.rc"], - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - "service.cpp" - ], - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "android.hardware.boot@1.0", - ], -} - -cc_library { - name: "android.hardware.boot@1.0-impl-zuma", - recovery: true, - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - ], - relative_install_path: "hw", - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "android.hardware.boot@1.0", - ], -} diff --git a/interfaces/boot/1.0/BootControl.cpp b/interfaces/boot/1.0/BootControl.cpp deleted file mode 100644 index 1f155c9d..00000000 --- a/interfaces/boot/1.0/BootControl.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "BootControl.h" -#include "GptUtils.h" - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -namespace { - -#define BOOT_A_PATH "/dev/block/by-name/boot_a" -#define BOOT_B_PATH "/dev/block/by-name/boot_b" - -// slot flags -#define AB_ATTR_PRIORITY_SHIFT 52 -#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) -#define AB_ATTR_ACTIVE_SHIFT 54 -#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) -#define AB_ATTR_RETRY_COUNT_SHIFT (55) -#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) -#define AB_ATTR_SUCCESSFUL (1UL << 58) -#define AB_ATTR_UNBOOTABLE (1UL << 59) - -#define AB_ATTR_MAX_PRIORITY 3UL -#define AB_ATTR_MAX_RETRY_COUNT 3UL - -static std::string getDevPath(uint32_t slot) { - char real_path[PATH_MAX]; - - const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; - - int ret = readlink(path, real_path, sizeof real_path); - if (ret < 0) { - ALOGE("readlink failed for boot device %s\n", strerror(errno)); - return std::string(); - } - - std::string dp(real_path); - // extract /dev/sda.. part - return dp.substr(0, sizeof "/dev/block/sdX" - 1); -} - -static bool isSlotFlagSet(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - return !!(e->attr & flag); -} - -static int setSlotFlag(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return -1; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return -1; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return -1; - } - - e->attr |= flag; - gpt.Sync(); - - return 0; -} - -} - -// Methods from ::android::hardware::boot::V1_0::IBootControl follow. -Return BootControl::getNumberSlots() { - uint32_t slots = 0; - - if (access(BOOT_A_PATH, F_OK) == 0) - slots++; - - if (access(BOOT_B_PATH, F_OK) == 0) - slots++; - - return slots; -} - -Return BootControl::getCurrentSlot() { - char suffix[PROPERTY_VALUE_MAX]; - property_get("ro.boot.slot_suffix", suffix, "_a"); - return std::string(suffix) == "_b" ? 1 : 0; -} - -Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { - if (getNumberSlots() == 0) { - // no slots, just return true otherwise Android keeps trying - _hidl_cb({true, ""}); - return Void(); - } - int ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL); - ret ? _hidl_cb({false, "Failed to set successfull flag"}) : _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - _hidl_cb({false, "failed to load gpt data"}); - return Void(); - } - - gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b"); - gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a"); - if (active_entry == nullptr || inactive_entry == nullptr) { - _hidl_cb({false, "failed to get entries for boot partitions"}); - return Void(); - } - - ALOGV("slot active attributes %lx\n", active_entry->attr); - ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); - - char boot_dev[PROPERTY_VALUE_MAX]; - property_get("ro.boot.bootdevice", boot_dev, ""); - if (boot_dev[0] == '\0') { - _hidl_cb({false, "invalid ro.boot.bootdevice prop"}); - return Void(); - } - - std::string boot_lun_path = std::string("/sys/devices/platform/") + - boot_dev + "/pixel/boot_lun_enabled"; - int fd = open(boot_lun_path.c_str(), O_RDWR); - if (fd < 0) { - // Try old path for kernels < 5.4 - // TODO: remove once kernel 4.19 support is deprecated - std::string boot_lun_path = std::string("/sys/devices/platform/") + - boot_dev + "/attributes/boot_lun_enabled"; - fd = open(boot_lun_path.c_str(), O_RDWR); - if (fd < 0) { - _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"}); - return Void(); - } - } - - // update attributes for active and inactive - inactive_entry->attr &= ~AB_ATTR_ACTIVE; - active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | - (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); - - // - // bBootLunEn - // 0x1 => Boot LU A = enabled, Boot LU B = disable - // 0x2 => Boot LU A = disable, Boot LU B = enabled - // - int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd); - close(fd); - if (ret < 0) { - _hidl_cb({false, "faied to write boot_lun_enabled attribute"}); - return Void(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - gpt.Load(); - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - e->attr |= AB_ATTR_UNBOOTABLE; - - gpt.Sync(); - - _hidl_cb({true, ""}); - return Void(); -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) { - if (getNumberSlots() == 0) - return BoolResult::FALSE; - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - return isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE) ? BoolResult::FALSE : BoolResult::TRUE; -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) { - if (getNumberSlots() == 0) { - // just return true so that we don't we another call trying to mark it as successful - // when there is no slots - return BoolResult::TRUE; - } - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - return isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL) ? BoolResult::TRUE : BoolResult::FALSE; -} - -Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { - _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : ""); - return Void(); -} - -extern "C" IBootControl* HIDL_FETCH_IBootControl(const char*) { - return new BootControl(); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/BootControl.h b/interfaces/boot/1.0/BootControl.h deleted file mode 100644 index eb81cb07..00000000 --- a/interfaces/boot/1.0/BootControl.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::sp; - -struct BootControl : public IBootControl { - // Methods from ::android::hardware::boot::V1_0::IBootControl follow. - Return getNumberSlots() override; - Return getCurrentSlot() override; - Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; - Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; - Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(uint32_t slot) override; - Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; - - // Methods from ::android::hidl::base::V1_0::IBase follow. - -}; - -// FIXME: most likely delete, this is only for passthrough implementations -extern "C" IBootControl* HIDL_FETCH_IBootControl(const char* name); - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/GptUtils.cpp b/interfaces/boot/1.0/GptUtils.cpp deleted file mode 100644 index f8936175..00000000 --- a/interfaces/boot/1.0/GptUtils.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "GptUtils.h" - -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -namespace { - -static int ValidateGptHeader(gpt_header *gpt) -{ - if (gpt->signature != GPT_SIGNATURE) { - ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); - return -1; - } - - if (gpt->header_size != sizeof(gpt_header)) { - ALOGE("invalid gpt header size %u\n", gpt->header_size); - return -1; - } - - if (gpt->entry_size != sizeof(gpt_entry)) { - ALOGE("invalid gpt entry size %u\n", gpt->entry_size); - return -1; - } - - return 0; -} - -} - -GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} - -int GptUtils::Load(void) -{ - fd = open(dev_path.c_str(), O_RDWR); - if (fd < 0) { - ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); - return -1; - } - - int ret = ioctl(fd, BLKSSZGET, &block_size); - if (ret < 0) { - ALOGE("failed to get block size %d\n", errno); - return -1; - } - - // read primary header - lseek64(fd, block_size, SEEK_SET); - ret = read(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to read gpt primary header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_primary)) { - ALOGE("error validating gpt header\n"); - return -1; - } - - // read partition entries - entry_array.resize(gpt_primary.entry_count); - uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = read(fd, entry_array.data(), entries_size); - if (ret < 0) { - ALOGE("failed to read gpt partition entries %d\n", errno); - return -1; - } - - // read gpt back header - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = read(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to read gpt backup header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_backup)) { - ALOGW("error validating gpt backup\n"); // just warn about it, not fail - } - - // Create map - auto get_name = [](const uint16_t *efi_name) { - char name[37] = {}; - for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) - name[i] = efi_name[i]; - return std::string(name); - }; - - for (auto const &e: entry_array) { - if (e.name[0] == 0) - break; // stop at the first partition with no name - std::string s = get_name(e.name); - entries[s] = const_cast(&e); - } - - return 0; -} - -gpt_entry *GptUtils::GetPartitionEntry(std::string name) -{ - return entries.find(name) != entries.end() ? entries[name] : nullptr; -} - -int GptUtils::Sync(void) -{ - if (!fd) - return -1; - - // calculate crc and check if we need to update gpt - gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), - entry_array.size() * sizeof(gpt_entry)); - - // save old crc - uint32_t crc = gpt_primary.crc32; - gpt_primary.crc32 = 0; - - gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); - if (crc == gpt_primary.crc32) - return 0; // nothing to do (no changes) - - ALOGI("updating GPT\n"); - - lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); - int ret = write(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to write gpt primary header %d\n", errno); - return -1; - } - - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt partition entries %d\n", errno); - return -1; - } - - //update GPT backup entries and backup - lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt backup partition entries %d\n", errno); - return -1; - } - - gpt_backup.entries_crc32 = gpt_primary.entries_crc32; - gpt_backup.crc32 = 0; - gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = write(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to write gpt backup header %d\n", errno); - return -1; - } - - fsync(fd); - - return 0; -} - -GptUtils::~GptUtils() -{ - if (fd) { - Sync(); - close(fd); - } -} - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/GptUtils.h b/interfaces/boot/1.0/GptUtils.h deleted file mode 100644 index d969d9d8..00000000 --- a/interfaces/boot/1.0/GptUtils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -#define GPT_SIGNATURE 0x5452415020494645UL - -typedef struct { - uint8_t type_guid[16]; - uint8_t guid[16]; - uint64_t first_lba; - uint64_t last_lba; - uint64_t attr; - uint16_t name[36]; -} __attribute__((packed)) gpt_entry; - -typedef struct { - uint64_t signature; - uint32_t revision; - uint32_t header_size; - uint32_t crc32; - uint32_t reserved; - uint64_t current_lba; - uint64_t backup_lba; - uint64_t first_usable_lba; - uint64_t last_usable_lba; - uint8_t disk_guid[16]; - uint64_t start_lba; - uint32_t entry_count; - uint32_t entry_size; - uint32_t entries_crc32; -} __attribute__((packed)) gpt_header; - -class GptUtils { - public: - GptUtils(const std::string dev_path); - int Load(void); - gpt_entry *GetPartitionEntry(std::string name); - int Sync(void); - ~GptUtils(); - - private: - std::string dev_path; - int fd; - uint32_t block_size; - gpt_header gpt_primary; - gpt_header gpt_backup; - std::vector entry_array; - std::mapentries; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc b/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc deleted file mode 100644 index 7997fded..00000000 --- a/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc +++ /dev/null @@ -1,4 +0,0 @@ -service vendor.boot-hal-1-0 /vendor/bin/hw/android.hardware.boot@1.0-service-zuma - class early_hal - user root - group root diff --git a/interfaces/boot/1.0/service.cpp b/interfaces/boot/1.0/service.cpp deleted file mode 100644 index 9dcd78cc..00000000 --- a/interfaces/boot/1.0/service.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define LOG_TAG "android.hardware.boot@1.0-service" - -#include -#include -#include -#include -#include "BootControl.h" - -using ::android::status_t; - -using ::android::hardware::boot::V1_0::IBootControl; - -using ::android::hardware::boot::V1_0::implementation::BootControl; - -int main (int /* argc */, char * /* argv */ []) { - // This function must be called before you join to ensure the proper - // number of threads are created. The threadpool will never exceed - // size one because of this call. - ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/); - - ::android::sp bootctrl = new BootControl(); - const status_t status = bootctrl->registerAsService(); - if (status != ::android::OK) { - return 1; // or handle error - } - - // Adds this thread to the threadpool, resulting in one total - // thread in the threadpool. We could also do other things, but - // would have to specify 'false' to willJoin in configureRpcThreadpool. - ::android::hardware::joinRpcThreadpool(); - return 1; // joinRpcThreadpool should never return -} diff --git a/interfaces/boot/1.2/Android.bp b/interfaces/boot/1.2/Android.bp deleted file mode 100644 index 90b0c6ed..00000000 --- a/interfaces/boot/1.2/Android.bp +++ /dev/null @@ -1,83 +0,0 @@ -// -// Copyright (C) 2020 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/zuma:device_google_zuma_license", - ], -} - -cc_binary { - name: "android.hardware.boot@1.2-service-zuma", - defaults: ["hidl_defaults"], - relative_install_path: "hw", - vendor: true, - init_rc: ["android.hardware.boot@1.2-service-zuma.rc"], - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - "service.cpp" - ], - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "libtrusty", - "android.hardware.boot@1.0", - "android.hardware.boot@1.1", - "android.hardware.boot@1.2", - ], - static_libs: [ - "libboot_control", - "libbootloader_message_vendor", - "libfstab", - ], -} - -cc_library { - name: "android.hardware.boot@1.2-impl-zuma", - stem: "android.hardware.boot@1.0-impl-1.2-impl-zuma", - recovery: true, - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - ], - relative_install_path: "hw", - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "libtrusty", - "android.hardware.boot@1.0", - "android.hardware.boot@1.1", - "android.hardware.boot@1.2", - ], - static_libs: [ - "libboot_control", - "libbootloader_message_vendor", - "libfstab", - ], -} diff --git a/interfaces/boot/1.2/BootControl.cpp b/interfaces/boot/1.2/BootControl.cpp deleted file mode 100644 index 77820754..00000000 --- a/interfaces/boot/1.2/BootControl.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "BootControl.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "DevInfo.h" -#include "GptUtils.h" - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -using android::bootable::GetMiscVirtualAbMergeStatus; -using android::bootable::InitMiscVirtualAbMessageIfNeeded; -using android::bootable::SetMiscVirtualAbMergeStatus; -using android::hardware::boot::V1_0::BoolResult; -using android::hardware::boot::V1_0::CommandResult; -using android::hardware::boot::V1_1::MergeStatus; - -namespace { - -// clang-format off - -#define BOOT_A_PATH "/dev/block/by-name/boot_a" -#define BOOT_B_PATH "/dev/block/by-name/boot_b" -#define DEVINFO_PATH "/dev/block/by-name/devinfo" - -// slot flags -#define AB_ATTR_PRIORITY_SHIFT 52 -#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) -#define AB_ATTR_ACTIVE_SHIFT 54 -#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) -#define AB_ATTR_RETRY_COUNT_SHIFT (55) -#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) -#define AB_ATTR_SUCCESSFUL (1UL << 58) -#define AB_ATTR_UNBOOTABLE (1UL << 59) - -#define AB_ATTR_MAX_PRIORITY 3UL -#define AB_ATTR_MAX_RETRY_COUNT 3UL - -// clang-format on - -static std::string getDevPath(uint32_t slot) { - char real_path[PATH_MAX]; - - const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; - - int ret = readlink(path, real_path, sizeof real_path); - if (ret < 0) { - ALOGE("readlink failed for boot device %s\n", strerror(errno)); - return std::string(); - } - - std::string dp(real_path); - // extract /dev/sda.. part - return dp.substr(0, sizeof "/dev/block/sdX" - 1); -} - -static bool isSlotFlagSet(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - return !!(e->attr & flag); -} - -static bool setSlotFlag(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - e->attr |= flag; - gpt.Sync(); - - return true; -} - -static bool is_devinfo_valid; -static bool is_devinfo_initialized; -static std::mutex devinfo_lock; -static devinfo_t devinfo; - -static bool isDevInfoValid() { - const std::lock_guard lock(devinfo_lock); - - if (is_devinfo_initialized) { - return is_devinfo_valid; - } - - is_devinfo_initialized = true; - - android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY)); - android::base::ReadFully(fd, &devinfo, sizeof devinfo); - - if (devinfo.magic != DEVINFO_MAGIC) { - return is_devinfo_valid; - } - - uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor; - // only version 3.3+ supports A/B data - if (version >= 0x0003'0003) { - is_devinfo_valid = true; - } - - return is_devinfo_valid; -} - -static bool DevInfoSync() { - if (!isDevInfoValid()) { - return false; - } - - android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY | O_DSYNC)); - return android::base::WriteFully(fd, &devinfo, sizeof devinfo); -} - -static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) { - slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT; - slot_data.unbootable = 0; - slot_data.successful = 0; - slot_data.active = 1; - slot_data.fastboot_ok = 0; -} - -static int blow_otp_AR(bool secure) { - static const char *dev_name = "/dev/trusty-ipc-dev0"; - static const char *otp_name = "com.android.trusty.otp_manager.tidl"; - int fd = 1, ret = 0; - uint32_t cmd = secure? OTP_CMD_write_antirbk_secure_ap : OTP_CMD_write_antirbk_non_secure_ap; - fd = tipc_connect(dev_name, otp_name); - if (fd < 0) { - ALOGI("Failed to connect to OTP_MGR ns TA - is it missing?\n"); - ret = -1; - return ret; - } - - struct otp_mgr_req_base req = { - .command = cmd, - .resp_payload_size = 0, - }; - struct iovec iov[] = { - { - .iov_base = &req, - .iov_len = sizeof(req), - }, - }; - - int rc = tipc_send(fd, iov, 1, NULL, 0); - if (rc != sizeof(req)) { - ALOGI("Send fail! %x\n", rc); - return rc; - } - - struct otp_mgr_rsp_base resp; - rc = read(fd, &resp, sizeof(resp)); - if (rc < 0) { - ALOGI("Read fail! %x\n", rc); - return rc; - } - - if (rc < sizeof(resp)) { - ALOGI("Not enough data! %x\n", rc); - return -EIO; - } - - if (resp.command != (cmd | OTP_RESP_BIT)) { - ALOGI("Wrong command! %x\n", resp.command); - return -EINVAL; - } - - if (resp.result != 0) { - fprintf(stderr, "AR writing error! %x\n", resp.result); - return -EINVAL; - } - - tipc_close(fd); - return 0; -} - -static bool blowAR() { - int ret = blow_otp_AR(true); - if (ret) { - ALOGI("Blow secure anti-rollback OTP failed"); - return false; - } - - ret = blow_otp_AR(false); - if (ret) { - ALOGI("Blow non-secure anti-rollback OTP failed"); - return false; - } - - return true; -} -} // namespace - -// Methods from ::android::hardware::boot::V1_0::IBootControl follow. -Return BootControl::getNumberSlots() { - uint32_t slots = 0; - - if (access(BOOT_A_PATH, F_OK) == 0) - slots++; - - if (access(BOOT_B_PATH, F_OK) == 0) - slots++; - - return slots; -} - -Return BootControl::getCurrentSlot() { - char suffix[PROPERTY_VALUE_MAX]; - property_get("ro.boot.slot_suffix", suffix, "_a"); - return std::string(suffix) == "_b" ? 1 : 0; -} - -Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { - if (getNumberSlots() == 0) { - // no slots, just return true otherwise Android keeps trying - _hidl_cb({true, ""}); - return Void(); - } - - bool ret; - if (isDevInfoValid()) { - auto const slot = getCurrentSlot(); - devinfo.ab_data.slots[slot].successful = 1; - ret = DevInfoSync(); - } else { - ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL); - } - - if (!ret) { - _hidl_cb({false, "Failed to set successful flag"}); - return Void(); - } - - if (!blowAR()) { - ALOGE("Failed to blow anti-rollback counter"); - // Ignore the error, since ABL will re-trigger it on reboot - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - if (isDevInfoValid()) { - auto &active_slot_data = devinfo.ab_data.slots[slot]; - auto &inactive_slot_data = devinfo.ab_data.slots[!slot]; - - inactive_slot_data.active = 0; - DevInfoInitSlot(active_slot_data); - - if (!DevInfoSync()) { - _hidl_cb({false, "Could not update DevInfo data"}); - return Void(); - } - } else { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - _hidl_cb({false, "failed to load gpt data"}); - return Void(); - } - - gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b"); - gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a"); - if (active_entry == nullptr || inactive_entry == nullptr) { - _hidl_cb({false, "failed to get entries for boot partitions"}); - return Void(); - } - - ALOGV("slot active attributes %lx\n", active_entry->attr); - ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); - - // update attributes for active and inactive - inactive_entry->attr &= ~AB_ATTR_ACTIVE; - active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | - (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); - } - - char boot_dev[PROPERTY_VALUE_MAX]; - property_get("ro.boot.bootdevice", boot_dev, ""); - if (boot_dev[0] == '\0') { - _hidl_cb({false, "invalid ro.boot.bootdevice prop"}); - return Void(); - } - - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled"; - int fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - // Try old path for kernels < 5.4 - // TODO: remove once kernel 4.19 support is deprecated - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled"; - fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"}); - return Void(); - } - } - - // - // bBootLunEn - // 0x1 => Boot LU A = enabled, Boot LU B = disable - // 0x2 => Boot LU A = disable, Boot LU B = enabled - // - int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd); - close(fd); - if (ret < 0) { - _hidl_cb({false, "faied to write boot_lun_enabled attribute"}); - return Void(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - slot_data.unbootable = 1; - if (!DevInfoSync()) { - _hidl_cb({false, "Could not update DevInfo data"}); - return Void(); - } - } else { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - gpt.Load(); - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - e->attr |= AB_ATTR_UNBOOTABLE; - - gpt.Sync(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) { - if (getNumberSlots() == 0) - return BoolResult::FALSE; - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - - bool unbootable; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - unbootable = !!slot_data.unbootable; - } else { - unbootable = isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE); - } - - return unbootable ? BoolResult::FALSE : BoolResult::TRUE; -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful( - uint32_t slot) { - if (getNumberSlots() == 0) { - // just return true so that we don't we another call trying to mark it as successful - // when there is no slots - return BoolResult::TRUE; - } - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - - bool successful; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - successful = !!slot_data.successful; - } else { - successful = isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL); - } - - return successful ? BoolResult::TRUE : BoolResult::FALSE; -} - -Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { - _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : ""); - return Void(); -} - -// Methods from ::android::hardware::boot::V1_1::IBootControl follow. -bool BootControl::Init() { - return InitMiscVirtualAbMessageIfNeeded(); -} - -Return BootControl::setSnapshotMergeStatus( - ::android::hardware::boot::V1_1::MergeStatus status) { - return SetMiscVirtualAbMergeStatus(getCurrentSlot(), status); -} - -Return<::android::hardware::boot::V1_1::MergeStatus> BootControl::getSnapshotMergeStatus() { - MergeStatus status; - if (!GetMiscVirtualAbMergeStatus(getCurrentSlot(), &status)) { - return MergeStatus::UNKNOWN; - } - return status; -} - -// Methods from ::android::hardware::boot::V1_2::IBootControl follow. -Return BootControl::getActiveBootSlot() { - if (getNumberSlots() == 0) - return 0; - - if (isDevInfoValid()) - return devinfo.ab_data.slots[1].active ? 1 : 0; - return isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0; -} - -// Methods from ::android::hidl::base::V1_0::IBase follow. - -IBootControl *HIDL_FETCH_IBootControl(const char * /* name */) { - auto module = new BootControl(); - - module->Init(); - - return module; -} - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/BootControl.h b/interfaces/boot/1.2/BootControl.h deleted file mode 100644 index 45b7efad..00000000 --- a/interfaces/boot/1.2/BootControl.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -using ::android::sp; -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; - -struct BootControl : public IBootControl { - bool Init(); - - // Methods from ::android::hardware::boot::V1_0::IBootControl follow. - Return getNumberSlots() override; - Return getCurrentSlot() override; - Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; - Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; - Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful( - uint32_t slot) override; - Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; - - // Methods from ::android::hardware::boot::V1_1::IBootControl follow. - Return setSnapshotMergeStatus( - ::android::hardware::boot::V1_1::MergeStatus status) override; - Return<::android::hardware::boot::V1_1::MergeStatus> getSnapshotMergeStatus() override; - - // Methods from ::android::hardware::boot::V1_2::IBootControl follow. - Return getActiveBootSlot() override; - - // Methods from ::android::hidl::base::V1_0::IBase follow. -}; - -// FIXME: most likely delete, this is only for passthrough implementations -extern "C" IBootControl *HIDL_FETCH_IBootControl(const char *name); - -enum otpmgr_command : uint32_t { - OTP_REQ_SHIFT = 1, - OTP_RESP_BIT = 1, - OTP_CMD_write_antirbk_non_secure_ap = (7 << OTP_REQ_SHIFT), - OTP_CMD_write_antirbk_secure_ap = (8 << OTP_REQ_SHIFT), -}; - -struct otp_mgr_req_base { - uint32_t command; - uint32_t resp_payload_size; - uint8_t handle; -}__packed; - -struct otp_mgr_rsp_base { - uint32_t command; - uint32_t resp_payload_size; - int result; -}__packed; - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/DevInfo.h b/interfaces/boot/1.2/DevInfo.h deleted file mode 100644 index a09a83a2..00000000 --- a/interfaces/boot/1.2/DevInfo.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -// -// definitions taken from ABL code -// - -constexpr uint32_t DEVINFO_MAGIC = 0x49564544; -constexpr size_t DEVINFO_AB_SLOT_COUNT = 2; - -struct devinfo_ab_slot_data_t { - uint8_t retry_count; - uint8_t unbootable : 1; - uint8_t successful : 1; - uint8_t active : 1; - uint8_t fastboot_ok : 1; - uint8_t : 4; - uint8_t unused[2]; -} __attribute__((packed)); - -typedef struct { - devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT]; -} __attribute__((packed)) devinfo_ab_data_t; - -struct devinfo_t { - uint32_t magic; - uint16_t ver_major; - uint16_t ver_minor; - uint8_t unused[40]; - devinfo_ab_data_t ab_data; - uint8_t unused1[72]; // use remaining up to complete 128 bytes -} __attribute__((packed)); - -static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size"); - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/GptUtils.cpp b/interfaces/boot/1.2/GptUtils.cpp deleted file mode 100644 index 25088e79..00000000 --- a/interfaces/boot/1.2/GptUtils.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "GptUtils.h" - -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -namespace { - -static int ValidateGptHeader(gpt_header *gpt) { - if (gpt->signature != GPT_SIGNATURE) { - ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); - return -1; - } - - if (gpt->header_size != sizeof(gpt_header)) { - ALOGE("invalid gpt header size %u\n", gpt->header_size); - return -1; - } - - if (gpt->entry_size != sizeof(gpt_entry)) { - ALOGE("invalid gpt entry size %u\n", gpt->entry_size); - return -1; - } - - return 0; -} - -} // namespace - -GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} - -int GptUtils::Load(void) { - fd = open(dev_path.c_str(), O_RDWR); - if (fd < 0) { - ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); - return -1; - } - - int ret = ioctl(fd, BLKSSZGET, &block_size); - if (ret < 0) { - ALOGE("failed to get block size %d\n", errno); - return -1; - } - - // read primary header - lseek64(fd, block_size, SEEK_SET); - ret = read(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to read gpt primary header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_primary)) { - ALOGE("error validating gpt header\n"); - return -1; - } - - // read partition entries - entry_array.resize(gpt_primary.entry_count); - uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = read(fd, entry_array.data(), entries_size); - if (ret < 0) { - ALOGE("failed to read gpt partition entries %d\n", errno); - return -1; - } - - // read gpt back header - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = read(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to read gpt backup header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_backup)) { - ALOGW("error validating gpt backup\n"); // just warn about it, not fail - } - - // Create map - auto get_name = [](const uint16_t *efi_name) { - char name[37] = {}; - for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i]; - return std::string(name); - }; - - for (auto const &e : entry_array) { - if (e.name[0] == 0) - break; // stop at the first partition with no name - std::string s = get_name(e.name); - entries[s] = const_cast(&e); - } - - return 0; -} - -gpt_entry *GptUtils::GetPartitionEntry(std::string name) { - return entries.find(name) != entries.end() ? entries[name] : nullptr; -} - -int GptUtils::Sync(void) { - if (!fd) - return -1; - - // calculate crc and check if we need to update gpt - gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), - entry_array.size() * sizeof(gpt_entry)); - - // save old crc - uint32_t crc = gpt_primary.crc32; - gpt_primary.crc32 = 0; - - gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); - if (crc == gpt_primary.crc32) - return 0; // nothing to do (no changes) - - ALOGI("updating GPT\n"); - - lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); - int ret = write(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to write gpt primary header %d\n", errno); - return -1; - } - - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt partition entries %d\n", errno); - return -1; - } - - // update GPT backup entries and backup - lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt backup partition entries %d\n", errno); - return -1; - } - - gpt_backup.entries_crc32 = gpt_primary.entries_crc32; - gpt_backup.crc32 = 0; - gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = write(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to write gpt backup header %d\n", errno); - return -1; - } - - fsync(fd); - - return 0; -} - -GptUtils::~GptUtils() { - if (fd) { - Sync(); - close(fd); - } -} - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/GptUtils.h b/interfaces/boot/1.2/GptUtils.h deleted file mode 100644 index a2bed334..00000000 --- a/interfaces/boot/1.2/GptUtils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -#define GPT_SIGNATURE 0x5452415020494645UL - -typedef struct { - uint8_t type_guid[16]; - uint8_t guid[16]; - uint64_t first_lba; - uint64_t last_lba; - uint64_t attr; - uint16_t name[36]; -} __attribute__((packed)) gpt_entry; - -typedef struct { - uint64_t signature; - uint32_t revision; - uint32_t header_size; - uint32_t crc32; - uint32_t reserved; - uint64_t current_lba; - uint64_t backup_lba; - uint64_t first_usable_lba; - uint64_t last_usable_lba; - uint8_t disk_guid[16]; - uint64_t start_lba; - uint32_t entry_count; - uint32_t entry_size; - uint32_t entries_crc32; -} __attribute__((packed)) gpt_header; - -class GptUtils { - public: - GptUtils(const std::string dev_path); - int Load(void); - gpt_entry *GetPartitionEntry(std::string name); - int Sync(void); - ~GptUtils(); - - private: - std::string dev_path; - int fd; - uint32_t block_size; - gpt_header gpt_primary; - gpt_header gpt_backup; - std::vector entry_array; - std::map entries; -}; - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc b/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc deleted file mode 100644 index 4e5f5fe6..00000000 --- a/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc +++ /dev/null @@ -1,7 +0,0 @@ -service vendor.boot-hal-1-2 /vendor/bin/hw/android.hardware.boot@1.2-service-zuma - interface android.hardware.boot@1.0::IBootControl default - interface android.hardware.boot@1.1::IBootControl default - interface android.hardware.boot@1.2::IBootControl default - class early_hal - user root - group root drmrpc diff --git a/interfaces/boot/1.2/service.cpp b/interfaces/boot/1.2/service.cpp deleted file mode 100644 index f07682e9..00000000 --- a/interfaces/boot/1.2/service.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "android.hardware.boot@1.2-service" - -#include -#include -#include -#include - -#include "BootControl.h" - -using ::android::status_t; - -using ::android::hardware::boot::V1_2::IBootControl; - -using ::android::hardware::boot::V1_2::implementation::BootControl; -// using ::android::hardware::boot::implementation::BootControl; - -int main(int /* argc */, char * /* argv */[]) { - // This function must be called before you join to ensure the proper - // number of threads are created. The threadpool will never exceed - // size one because of this call. - ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/); - - ::android::sp bootctrl = new BootControl(); - const status_t status = bootctrl->registerAsService(); - if (status != ::android::OK) { - return 1; // or handle error - } - - // Adds this thread to the threadpool, resulting in one total - // thread in the threadpool. We could also do other things, but - // would have to specify 'false' to willJoin in configureRpcThreadpool. - ::android::hardware::joinRpcThreadpool(); - return 1; // joinRpcThreadpool should never return -} diff --git a/interfaces/boot/aidl/Android.bp b/interfaces/boot/aidl/Android.bp deleted file mode 100644 index 37d2aebe..00000000 --- a/interfaces/boot/aidl/Android.bp +++ /dev/null @@ -1,65 +0,0 @@ -// -// Copyright (C) 2023 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/zuma:device_google_zuma_license", - ], -} - -cc_defaults { - name: "android.hardware.boot-service_common-zuma", - relative_install_path: "hw", - defaults: ["libboot_control_defaults"], - shared_libs: [ - "libbase", - "libbinder_ndk", - "libcutils", - "libz", - "libtrusty", - "android.hardware.boot@1.1", - "android.hardware.boot-V1-ndk", - ], - static_libs: [ - "libboot_control", - "libbootloader_message_vendor", - ], - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - "service.cpp" - ], -} - -cc_binary { - name: "android.hardware.boot-service.default-zuma", - defaults: ["android.hardware.boot-service_common-zuma"], - init_rc: ["android.hardware.boot-service.default-zuma.rc"], - vendor: true, -} - -cc_binary { - name: "android.hardware.boot-service.default_recovery-zuma", - defaults: ["android.hardware.boot-service_common-zuma"], - vintf_fragments: ["android.hardware.boot-service.default_recovery-zuma.xml"], - init_rc: ["android.hardware.boot-service.default_recovery-zuma.rc"], - recovery: true, -} \ No newline at end of file diff --git a/interfaces/boot/aidl/BootControl.cpp b/interfaces/boot/aidl/BootControl.cpp deleted file mode 100644 index 941b0d2b..00000000 --- a/interfaces/boot/aidl/BootControl.cpp +++ /dev/null @@ -1,538 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "BootControl.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "DevInfo.h" -#include "GptUtils.h" - -using HIDLMergeStatus = ::android::bootable::BootControl::MergeStatus; -using ndk::ScopedAStatus; - -using android::bootable::GetMiscVirtualAbMergeStatus; -using android::bootable::InitMiscVirtualAbMessageIfNeeded; -using android::bootable::SetMiscVirtualAbMergeStatus; - -namespace aidl::android::hardware::boot { - -namespace { - -// clang-format off - -#define BOOT_A_PATH "/dev/block/by-name/boot_a" -#define BOOT_B_PATH "/dev/block/by-name/boot_b" -#define DEVINFO_PATH "/dev/block/by-name/devinfo" - -// slot flags -#define AB_ATTR_PRIORITY_SHIFT 52 -#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) -#define AB_ATTR_ACTIVE_SHIFT 54 -#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) -#define AB_ATTR_RETRY_COUNT_SHIFT (55) -#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) -#define AB_ATTR_SUCCESSFUL (1UL << 58) -#define AB_ATTR_UNBOOTABLE (1UL << 59) - -#define AB_ATTR_MAX_PRIORITY 3UL -#define AB_ATTR_MAX_RETRY_COUNT 3UL - -// clang-format on - -static std::string getDevPath(int32_t in_slot) { - char real_path[PATH_MAX]; - - const char *path = in_slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; - - int ret = readlink(path, real_path, sizeof real_path); - if (ret < 0) { - ALOGE("readlink failed for boot device %s\n", strerror(errno)); - return std::string(); - } - - std::string dp(real_path); - // extract /dev/sda.. part - return dp.substr(0, sizeof "/dev/block/sdX" - 1); -} - -static bool isSlotFlagSet(int32_t in_slot, uint64_t flag) { - std::string dev_path = getDevPath(in_slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", in_slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - return !!(e->attr & flag); -} - -static bool setSlotFlag(int32_t in_slot, uint64_t flag) { - std::string dev_path = getDevPath(in_slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", in_slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - e->attr |= flag; - gpt.Sync(); - - return true; -} - -static bool is_devinfo_valid; -static bool is_devinfo_initialized; -static std::mutex devinfo_lock; -static devinfo_t devinfo; - -static bool isDevInfoValid() { - const std::lock_guard lock(devinfo_lock); - - if (is_devinfo_initialized) { - return is_devinfo_valid; - } - - is_devinfo_initialized = true; - - ::android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY)); - ::android::base::ReadFully(fd, &devinfo, sizeof devinfo); - - if (devinfo.magic != DEVINFO_MAGIC) { - return is_devinfo_valid; - } - - uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor; - // only version 3.3+ supports A/B data - if (version >= 0x0003'0003) { - is_devinfo_valid = true; - } - - return is_devinfo_valid; -} - -static bool DevInfoSync() { - if (!isDevInfoValid()) { - return false; - } - - ::android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY | O_DSYNC)); - return ::android::base::WriteFully(fd, &devinfo, sizeof devinfo); -} - -static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) { - slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT; - slot_data.unbootable = 0; - slot_data.successful = 0; - slot_data.active = 1; - slot_data.fastboot_ok = 0; -} - -static int blow_otp_AR(bool secure) { - static const char *dev_name = "/dev/trusty-ipc-dev0"; - static const char *otp_name = "com.android.trusty.otp_manager.tidl"; - int fd = 1, ret = 0; - uint32_t cmd = secure? OTP_CMD_write_antirbk_secure_ap : OTP_CMD_write_antirbk_non_secure_ap; - fd = tipc_connect(dev_name, otp_name); - if (fd < 0) { - ALOGI("Failed to connect to OTP_MGR ns TA - is it missing?\n"); - ret = -1; - return ret; - } - - struct otp_mgr_req_base req = { - .command = cmd, - .resp_payload_size = 0, - }; - struct iovec iov[] = { - { - .iov_base = &req, - .iov_len = sizeof(req), - }, - }; - - size_t rc = tipc_send(fd, iov, 1, NULL, 0); - if (rc != sizeof(req)) { - ALOGI("Send fail! %zx\n", rc); - return rc; - } - - struct otp_mgr_rsp_base resp; - rc = read(fd, &resp, sizeof(resp)); - if (rc < 0) { - ALOGI("Read fail! %zx\n", rc); - return rc; - } - - if (rc < sizeof(resp)) { - ALOGI("Not enough data! %zx\n", rc); - return -EIO; - } - - if (resp.command != (cmd | OTP_RESP_BIT)) { - ALOGI("Wrong command! %x\n", resp.command); - return -EINVAL; - } - - if (resp.result != 0) { - fprintf(stderr, "AR writing error! %x\n", resp.result); - return -EINVAL; - } - - tipc_close(fd); - return 0; -} - -static bool blowAR() { - int ret = blow_otp_AR(true); - if (ret) { - ALOGI("Blow secure anti-rollback OTP failed"); - return false; - } - - ret = blow_otp_AR(false); - if (ret) { - ALOGI("Blow non-secure anti-rollback OTP failed"); - return false; - } - - return true; -} - -static constexpr MergeStatus ToAIDLMergeStatus(HIDLMergeStatus status) { - switch (status) { - case HIDLMergeStatus::NONE: - return MergeStatus::NONE; - case HIDLMergeStatus::UNKNOWN: - return MergeStatus::UNKNOWN; - case HIDLMergeStatus::SNAPSHOTTED: - return MergeStatus::SNAPSHOTTED; - case HIDLMergeStatus::MERGING: - return MergeStatus::MERGING; - case HIDLMergeStatus::CANCELLED: - return MergeStatus::CANCELLED; - } -} - -static constexpr HIDLMergeStatus ToHIDLMergeStatus(MergeStatus status) { - switch (status) { - case MergeStatus::NONE: - return HIDLMergeStatus::NONE; - case MergeStatus::UNKNOWN: - return HIDLMergeStatus::UNKNOWN; - case MergeStatus::SNAPSHOTTED: - return HIDLMergeStatus::SNAPSHOTTED; - case MergeStatus::MERGING: - return HIDLMergeStatus::MERGING; - case MergeStatus::CANCELLED: - return HIDLMergeStatus::CANCELLED; - } -} - -} // namespace - -BootControl::BootControl() { - CHECK(InitMiscVirtualAbMessageIfNeeded()); -} - -ScopedAStatus BootControl::getActiveBootSlot(int32_t* _aidl_return) { - int32_t slots = 0; - getNumberSlots(&slots); - if (slots == 0) { - *_aidl_return = 0; - return ScopedAStatus::ok(); - } - - if (isDevInfoValid()) { - *_aidl_return = devinfo.ab_data.slots[1].active ? 1 : 0; - return ScopedAStatus::ok(); - } - *_aidl_return = isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::getCurrentSlot(int32_t* _aidl_return) { - char suffix[PROPERTY_VALUE_MAX]; - property_get("ro.boot.slot_suffix", suffix, "_a"); - *_aidl_return = std::string(suffix) == "_b" ? 1 : 0; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::getNumberSlots(int32_t* _aidl_return) { - int32_t slots = 0; - - if (access(BOOT_A_PATH, F_OK) == 0) - slots++; - - if (access(BOOT_B_PATH, F_OK) == 0) - slots++; - - *_aidl_return = slots; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::getSnapshotMergeStatus(MergeStatus* _aidl_return) { - HIDLMergeStatus status; - int32_t current_slot = 0; - getCurrentSlot(¤t_slot); - if (!GetMiscVirtualAbMergeStatus(current_slot, &status)) { - *_aidl_return = MergeStatus::UNKNOWN; - return ScopedAStatus::ok(); - } - *_aidl_return = ToAIDLMergeStatus(status); - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::getSuffix(int32_t in_slot, std::string* _aidl_return) { - *_aidl_return = in_slot == 0 ? "_a" : in_slot == 1 ? "_b" : ""; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::isSlotBootable(int32_t in_slot, bool* _aidl_return) { - int32_t slots = 0; - getNumberSlots(&slots); - if (slots == 0) { - *_aidl_return = false; - return ScopedAStatus::ok(); - } - if (in_slot >= slots) - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); - - bool unbootable; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[in_slot]; - unbootable = !!slot_data.unbootable; - } else { - unbootable = isSlotFlagSet(in_slot, AB_ATTR_UNBOOTABLE); - } - - *_aidl_return = unbootable ? false: true; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::isSlotMarkedSuccessful(int32_t in_slot, bool* _aidl_return) { - int32_t slots = 0; - getNumberSlots(&slots); - if (slots == 0) { - // just return true so that we don't we another call trying to mark it as successful - // when there is no slots - *_aidl_return = true; - return ScopedAStatus::ok(); - } - if (in_slot >= slots) - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); - - bool successful; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[in_slot]; - successful = !!slot_data.successful; - } else { - successful = isSlotFlagSet(in_slot, AB_ATTR_SUCCESSFUL); - } - - *_aidl_return = successful ? true : false; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::markBootSuccessful() { - int32_t slots = 0; - getNumberSlots(&slots); - if (slots == 0) { - // no slots, just return true otherwise Android keeps trying - return ScopedAStatus::ok(); - } - - bool ret; - int32_t current_slot = 0; - getCurrentSlot(¤t_slot); - if (isDevInfoValid()) { - auto const slot = current_slot; - devinfo.ab_data.slots[slot].successful = 1; - ret = DevInfoSync(); - } else { - ret = setSlotFlag(current_slot, AB_ATTR_SUCCESSFUL); - } - - if (!ret) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, - "Failed to set successful flag"); - } - - if (!blowAR()) { - ALOGE("Failed to blow anti-rollback counter"); - // Ignore the error, since ABL will re-trigger it on reboot - } - - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::setActiveBootSlot(int32_t in_slot) { - if (in_slot >= 2) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); - } - - if (isDevInfoValid()) { - auto &active_slot_data = devinfo.ab_data.slots[in_slot]; - auto &inactive_slot_data = devinfo.ab_data.slots[!in_slot]; - - inactive_slot_data.active = 0; - DevInfoInitSlot(active_slot_data); - - if (!DevInfoSync()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "Could not update DevInfo data"); - } - } else { - std::string dev_path = getDevPath(in_slot); - if (dev_path.empty()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "Could not get device path for slot"); - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, - "failed to load gpt data"); - } - - gpt_entry *active_entry = gpt.GetPartitionEntry(in_slot == 0 ? "boot_a" : "boot_b"); - gpt_entry *inactive_entry = gpt.GetPartitionEntry(in_slot == 0 ? "boot_b" : "boot_a"); - if (active_entry == nullptr || inactive_entry == nullptr) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "failed to get entries for boot partitions"); - } - - ALOGV("slot active attributes %lx\n", active_entry->attr); - ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); - - // update attributes for active and inactive - inactive_entry->attr &= ~AB_ATTR_ACTIVE; - active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | - (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); - } - - char boot_dev[PROPERTY_VALUE_MAX]; - property_get("ro.boot.bootdevice", boot_dev, ""); - if (boot_dev[0] == '\0') { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "invalid ro.boot.bootdevice prop"); - } - - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled"; - int fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - // Try old path for kernels < 5.4 - // TODO: remove once kernel 4.19 support is deprecated - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled"; - fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "failed to open ufs attr boot_lun_enabled"); - } - } - - // - // bBootLunEn - // 0x1 => Boot LU A = enabled, Boot LU B = disable - // 0x2 => Boot LU A = disable, Boot LU B = enabled - // - int ret = ::android::base::WriteStringToFd(in_slot == 0 ? "1" : "2", fd); - close(fd); - if (ret < 0) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "faied to write boot_lun_enabled attribute"); - } - - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::setSlotAsUnbootable(int32_t in_slot) { - if (in_slot >= 2) - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); - - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[in_slot]; - slot_data.unbootable = 1; - if (!DevInfoSync()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "Could not update DevInfo data"); - } - } else { - std::string dev_path = getDevPath(in_slot); - if (dev_path.empty()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "Could not get device path for slot"); - } - - GptUtils gpt(dev_path); - gpt.Load(); - - gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); - e->attr |= AB_ATTR_UNBOOTABLE; - - gpt.Sync(); - } - - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::setSnapshotMergeStatus(MergeStatus in_status) { - int32_t current_slot = 0; - getCurrentSlot(¤t_slot); - if (!SetMiscVirtualAbMergeStatus(current_slot, ToHIDLMergeStatus(in_status))) - return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, - "Operation failed"); - return ScopedAStatus::ok(); -} - -} // namespace aidl::android::hardware::boot diff --git a/interfaces/boot/aidl/BootControl.h b/interfaces/boot/aidl/BootControl.h deleted file mode 100644 index a54f66d0..00000000 --- a/interfaces/boot/aidl/BootControl.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace aidl::android::hardware::boot { - -class BootControl final : public BnBootControl { - public: - BootControl(); - ::ndk::ScopedAStatus getActiveBootSlot(int32_t* _aidl_return) override; - ::ndk::ScopedAStatus getCurrentSlot(int32_t* _aidl_return) override; - ::ndk::ScopedAStatus getNumberSlots(int32_t* _aidl_return) override; - ::ndk::ScopedAStatus getSnapshotMergeStatus( - ::aidl::android::hardware::boot::MergeStatus* _aidl_return) override; - ::ndk::ScopedAStatus getSuffix(int32_t in_slot, std::string* _aidl_return) override; - ::ndk::ScopedAStatus isSlotBootable(int32_t in_slot, bool* _aidl_return) override; - ::ndk::ScopedAStatus isSlotMarkedSuccessful(int32_t in_slot, bool* _aidl_return) override; - ::ndk::ScopedAStatus markBootSuccessful() override; - ::ndk::ScopedAStatus setActiveBootSlot(int32_t in_slot) override; - ::ndk::ScopedAStatus setSlotAsUnbootable(int32_t in_slot) override; - ::ndk::ScopedAStatus setSnapshotMergeStatus( - ::aidl::android::hardware::boot::MergeStatus in_status) override; -}; - -enum otpmgr_command : uint32_t { - OTP_REQ_SHIFT = 1, - OTP_RESP_BIT = 1, - OTP_CMD_write_antirbk_non_secure_ap = (7 << OTP_REQ_SHIFT), - OTP_CMD_write_antirbk_secure_ap = (8 << OTP_REQ_SHIFT), -}; - -struct otp_mgr_req_base { - uint32_t command; - uint32_t resp_payload_size; - uint8_t handle; -}__packed; - -struct otp_mgr_rsp_base { - uint32_t command; - uint32_t resp_payload_size; - int result; -}__packed; - -} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/DevInfo.h b/interfaces/boot/aidl/DevInfo.h deleted file mode 100644 index aa5f5d37..00000000 --- a/interfaces/boot/aidl/DevInfo.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace aidl::android::hardware::boot { - -// -// definitions taken from ABL code -// - -constexpr uint32_t DEVINFO_MAGIC = 0x49564544; -constexpr size_t DEVINFO_AB_SLOT_COUNT = 2; - -struct devinfo_ab_slot_data_t { - uint8_t retry_count; - uint8_t unbootable : 1; - uint8_t successful : 1; - uint8_t active : 1; - uint8_t fastboot_ok : 1; - uint8_t : 4; - uint8_t unused[2]; -} __attribute__((packed)); - -typedef struct { - devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT]; -} __attribute__((packed)) devinfo_ab_data_t; - -struct devinfo_t { - uint32_t magic; - uint16_t ver_major; - uint16_t ver_minor; - uint8_t unused[40]; - devinfo_ab_data_t ab_data; - uint8_t unused1[72]; // use remaining up to complete 128 bytes -} __attribute__((packed)); - -static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size"); - -} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/GptUtils.cpp b/interfaces/boot/aidl/GptUtils.cpp deleted file mode 100644 index 34dec113..00000000 --- a/interfaces/boot/aidl/GptUtils.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "GptUtils.h" - -#include -#include -#include -#include -#include - -namespace aidl::android::hardware::boot { - -namespace { - -static int ValidateGptHeader(gpt_header *gpt) { - if (gpt->signature != GPT_SIGNATURE) { - ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); - return -1; - } - - if (gpt->header_size != sizeof(gpt_header)) { - ALOGE("invalid gpt header size %u\n", gpt->header_size); - return -1; - } - - if (gpt->entry_size != sizeof(gpt_entry)) { - ALOGE("invalid gpt entry size %u\n", gpt->entry_size); - return -1; - } - - return 0; -} - -} // namespace - -GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} - -int GptUtils::Load(void) { - fd = open(dev_path.c_str(), O_RDWR); - if (fd < 0) { - ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); - return -1; - } - - int ret = ioctl(fd, BLKSSZGET, &block_size); - if (ret < 0) { - ALOGE("failed to get block size %d\n", errno); - return -1; - } - - // read primary header - lseek64(fd, block_size, SEEK_SET); - ret = read(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to read gpt primary header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_primary)) { - ALOGE("error validating gpt header\n"); - return -1; - } - - // read partition entries - entry_array.resize(gpt_primary.entry_count); - uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = read(fd, entry_array.data(), entries_size); - if (ret < 0) { - ALOGE("failed to read gpt partition entries %d\n", errno); - return -1; - } - - // read gpt back header - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = read(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to read gpt backup header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_backup)) { - ALOGW("error validating gpt backup\n"); // just warn about it, not fail - } - - // Create map - auto get_name = [](const uint16_t *efi_name) { - char name[37] = {}; - for (size_t i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i]; - return std::string(name); - }; - - for (auto const &e : entry_array) { - if (e.name[0] == 0) - break; // stop at the first partition with no name - std::string s = get_name(e.name); - entries[s] = const_cast(&e); - } - - return 0; -} - -gpt_entry *GptUtils::GetPartitionEntry(std::string name) { - return entries.find(name) != entries.end() ? entries[name] : nullptr; -} - -int GptUtils::Sync(void) { - if (!fd) - return -1; - - // calculate crc and check if we need to update gpt - gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), - entry_array.size() * sizeof(gpt_entry)); - - // save old crc - uint32_t crc = gpt_primary.crc32; - gpt_primary.crc32 = 0; - - gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); - if (crc == gpt_primary.crc32) - return 0; // nothing to do (no changes) - - ALOGI("updating GPT\n"); - - lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); - int ret = write(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to write gpt primary header %d\n", errno); - return -1; - } - - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt partition entries %d\n", errno); - return -1; - } - - // update GPT backup entries and backup - lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt backup partition entries %d\n", errno); - return -1; - } - - gpt_backup.entries_crc32 = gpt_primary.entries_crc32; - gpt_backup.crc32 = 0; - gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = write(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to write gpt backup header %d\n", errno); - return -1; - } - - fsync(fd); - - return 0; -} - -GptUtils::~GptUtils() { - if (fd) { - Sync(); - close(fd); - } -} - -} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/GptUtils.h b/interfaces/boot/aidl/GptUtils.h deleted file mode 100644 index ec68cf6f..00000000 --- a/interfaces/boot/aidl/GptUtils.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace aidl::android::hardware::boot { - -#define GPT_SIGNATURE 0x5452415020494645UL - -typedef struct { - uint8_t type_guid[16]; - uint8_t guid[16]; - uint64_t first_lba; - uint64_t last_lba; - uint64_t attr; - uint16_t name[36]; -} __attribute__((packed)) gpt_entry; - -typedef struct { - uint64_t signature; - uint32_t revision; - uint32_t header_size; - uint32_t crc32; - uint32_t reserved; - uint64_t current_lba; - uint64_t backup_lba; - uint64_t first_usable_lba; - uint64_t last_usable_lba; - uint8_t disk_guid[16]; - uint64_t start_lba; - uint32_t entry_count; - uint32_t entry_size; - uint32_t entries_crc32; -} __attribute__((packed)) gpt_header; - -class GptUtils { - public: - GptUtils(const std::string dev_path); - int Load(void); - gpt_entry *GetPartitionEntry(std::string name); - int Sync(void); - ~GptUtils(); - - private: - std::string dev_path; - int fd; - uint32_t block_size; - gpt_header gpt_primary; - gpt_header gpt_backup; - std::vector entry_array; - std::map entries; -}; - -} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc b/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc deleted file mode 100644 index f7dccadb..00000000 --- a/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc +++ /dev/null @@ -1,5 +0,0 @@ -service vendor.boot-default /vendor/bin/hw/android.hardware.boot-service.default-zuma - class early_hal - user root - group root drmrpc - diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc b/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc deleted file mode 100644 index d867a5f5..00000000 --- a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc +++ /dev/null @@ -1,7 +0,0 @@ -service vendor.boot-default /system/bin/hw/android.hardware.boot-service.default_recovery-zuma - class early_hal - user root - group root - seclabel u:r:hal_bootctl_default:s0 - interface aidl android.hardware.boot.IBootControl/default - diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml b/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml deleted file mode 100644 index 23ccc4e3..00000000 --- a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - android.hardware.boot - IBootControl/default - - diff --git a/interfaces/boot/aidl/service.cpp b/interfaces/boot/aidl/service.cpp deleted file mode 100644 index 41b6c256..00000000 --- a/interfaces/boot/aidl/service.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "aidl.android.hardware.boot-service.default" - -#include -#include -#include -#include -#include - -#include "BootControl.h" - -using aidl::android::hardware::boot::BootControl; -using aidl::android::hardware::boot::IBootControl; -using ::android::hardware::configureRpcThreadpool; -using ::android::hardware::joinRpcThreadpool; - -int main(int, char* argv[]) { - android::base::InitLogging(argv, android::base::KernelLogger); - ABinderProcess_setThreadPoolMaxThreadCount(0); - std::shared_ptr service = ndk::SharedRefBase::make(); - - const std::string instance = std::string(BootControl::descriptor) + "/default"; - auto status = AServiceManager_addService(service->asBinder().get(), instance.c_str()); - CHECK_EQ(status, STATUS_OK) << "Failed to add service " << instance << " " << status; - LOG(INFO) << "IBootControl AIDL service running..."; - - ABinderProcess_joinThreadPool(); - return EXIT_FAILURE; // should not reach -} From 0c71ce55cc41140c72234f54c912e999df930bad Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Mon, 27 Nov 2023 17:34:32 +0800 Subject: [PATCH 115/133] zuma: move bootctrl service declaration to gs-common Bug: 265063384 Change-Id: Ic37e0e5fc5aa4730afdd9378cf7123f9216fb573 Signed-off-by: Jason Chiu --- device.mk | 5 ----- 1 file changed, 5 deletions(-) diff --git a/device.mk b/device.mk index 10c6839e..ab634a51 100644 --- a/device.mk +++ b/device.mk @@ -924,11 +924,6 @@ PRODUCT_PACKAGES += \ ImsMediaService \ libimsmedia -# Boot Control HAL -PRODUCT_PACKAGES += \ - android.hardware.boot-service.default-zuma\ - android.hardware.boot-service.default_recovery-zuma - # Exynos RIL and telephony # Multi SIM(DSDS) SIM_COUNT := 2 From f16d3f60d2cf6df52e9bdeabebd608187cb66d37 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 9 Nov 2023 21:05:39 +0800 Subject: [PATCH 116/133] zuma: include bootctrl_aidl.mk from gs-common Bug: 265063384 Change-Id: I95cc9feca160004ee1d1c8fdf85da92b894d01d5 Signed-off-by: Jason Chiu --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index ab634a51..bde0a2f9 100644 --- a/device.mk +++ b/device.mk @@ -40,6 +40,7 @@ include device/google/gs-common/widevine/widevine.mk include device/google/gs-common/sota_app/factoryota.mk include device/google/gs-common/misc_writer/misc_writer.mk include device/google/gs-common/gyotaku_app/gyotaku.mk +include device/google/gs-common/bootctrl/bootctrl_aidl.mk include device/google/zuma/dumpstate/item.mk From dc330b5e88cc544493c37465fb52b5abed63a3f0 Mon Sep 17 00:00:00 2001 From: Peter Lin Date: Thu, 30 Nov 2023 07:51:45 +0000 Subject: [PATCH 117/133] Update default color temperature for night light Bug: 302396607 Test: adb shell dumpsys color_display | grep "Color temp" Change-Id: If106f81c0dd2bd81a48e156e1cc75dba4a885aca --- overlay/frameworks/base/core/res/res/values/config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 036f3919..0c741670 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -215,7 +215,7 @@ - 3339 + 4000 true From ea65ca11f6fbb6f13b89ef9ed03015f47ec1cedb Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Tue, 14 Nov 2023 18:49:06 +0000 Subject: [PATCH 118/133] usb: introduce UsbDataSessionMonitor class Migrate the usb data session event functions to the class with the following additional functionalities; - Support detecting gadget soft pulldown (usually done during configfs function switch) and report usb data session correctly. - Support reporting usb data compliance warnings to the class USB by providing getDataComplianceWarnings call. - Use boot_clock instead of steady_clock to measure time correctly in the case of system suspend. UsbDataSessionMonitor is self-contained and can be migrated to pixel usb library after feature maturation. Bug: 297224564 Bug: 296119135 Test: usb data session upload in device and host mode Change-Id: Iba001933e193935d64cf5fd0a1257d02a4274fb1 --- usb/usb/Android.bp | 1 + usb/usb/Usb.cpp | 306 ++++------------------ usb/usb/Usb.h | 34 +-- usb/usb/UsbDataSessionMonitor.cpp | 420 ++++++++++++++++++++++++++++++ usb/usb/UsbDataSessionMonitor.h | 114 ++++++++ 5 files changed, 594 insertions(+), 281 deletions(-) create mode 100644 usb/usb/UsbDataSessionMonitor.cpp create mode 100644 usb/usb/UsbDataSessionMonitor.h diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index a67e617e..858fc472 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -34,6 +34,7 @@ cc_binary { srcs: [ "service.cpp", "Usb.cpp", + "UsbDataSessionMonitor.cpp", ], shared_libs: [ "libbase", diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index e63fa1de..c0813d9e 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -43,7 +42,6 @@ #include #include -#include #include #include @@ -58,9 +56,6 @@ using android::base::Trim; using android::hardware::google::pixel::getStatsService; using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat; using android::hardware::google::pixel::reportUsbPortOverheat; -using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; -using android::hardware::google::pixel::reportUsbDataSessionEvent; -using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; namespace aidl { namespace android { @@ -98,18 +93,22 @@ constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_ac constexpr char kPogoEnableUsb[] = "/sys/devices/platform/google,pogo/enable_usb"; constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type"; constexpr char kIrqHpdCounPath[] = "-0025/irq_hpd_count"; -constexpr char kUdcState[] = "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; -// xhci-hcd-exynos and usb device numbering could vary on different platforms -constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\\.usb/11210000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0"; +constexpr char kUdcUeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3"; +constexpr char kUdcStatePath[] = + "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; +constexpr char kHost1UeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb1/1-0:1.0"; +constexpr char kHost1StatePath[] = "/sys/bus/usb/devices/usb1/1-0:1.0/usb1-port1/state"; +constexpr char kHost2UeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb2/2-0:1.0"; +constexpr char kHost2StatePath[] = "/sys/bus/usb/devices/usb2/2-0:1.0/usb2-port1/state"; +constexpr char kDataRolePath[] = "/sys/devices/platform/11210000.usb/new_data_role"; constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); AltModeData::DisplayPortAltModeData constructAltModeData(string hpd, string pin_assignment, string link_status, string vdo); -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus); - -#define USB_STATE_MAX_LEN 20 ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, int64_t in_transactionId) { @@ -511,11 +510,20 @@ bool switchMode(const string &portName, const PortRole &in_role, struct Usb *usb return roleSwitch; } +void updatePortStatus(android::hardware::usb::Usb *usb) { + std::vector currentPortStatus; + + queryVersionHelper(usb, ¤tPortStatus); +} + Usb::Usb() : mLock(PTHREAD_MUTEX_INITIALIZER), mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), mPartnerLock(PTHREAD_MUTEX_INITIALIZER), mPartnerUp(false), + mUsbDataSessionMonitor(kUdcUeventRegex, kUdcStatePath, kHost1UeventRegex, kHost1StatePath, + kHost2UeventRegex, kHost2StatePath, kDataRolePath, + std::bind(&updatePortStatus, this)), mOverheat(ZoneInfo(TemperatureType::USB_PORT, kThermalZoneForTrip, ThrottlingSeverity::CRITICAL), {ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadPrimary, @@ -1053,6 +1061,18 @@ Status queryDisplayPortStatus(android::hardware::usb::Usb *usb, return Status::SUCCESS; } +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + std::vector warnings; + + usb->mUsbDataSessionMonitor.getComplianceWarnings( + (*currentPortStatus)[0].currentDataRole, &warnings); + (*currentPortStatus)[0].complianceWarnings.insert( + (*currentPortStatus)[0].complianceWarnings.end(), + warnings.begin(), + warnings.end()); +} + void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus) { Status status; @@ -1159,54 +1179,6 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } -void report_usb_data_session_event(android::hardware::usb::Usb *usb) { - std::vector events; - - if (usb->mDataRole == PortDataRole::DEVICE) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(false /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, &usb->mDeviceState.states, - &usb->mDeviceState.timestamps, &event); - events.push_back(event); - } else if (usb->mDataRole == PortDataRole::HOST) { - bool empty = true; - for (auto &entry : usb->mHostStateMap) { - // Host port will at least get an not_attached event after enablement, - // skip upload if no additional state is added. - if (entry.second.states.size() > 1) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, &entry.second.states, - &entry.second.timestamps, &event); - events.push_back(event); - empty = false; - } - } - // All host ports have no state update, upload an event to reflect it - if (empty && usb->mHostStateMap.size() > 0) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, - &usb->mHostStateMap.begin()->second.states, - &usb->mHostStateMap.begin()->second.timestamps, - &event); - events.push_back(event); - } - } else { - return; - } - - const shared_ptr stats_client = getStatsService(); - if (!stats_client) { - ALOGE("Unable to get AIDL Stats service"); - return; - } - - for (auto &event : events) { - reportUsbDataSessionEvent(stats_client, event); - } -} - struct data { int uevent_fd; ::aidl::android::hardware::usb::Usb *usb; @@ -1223,147 +1195,13 @@ enum UeventType matchUeventType(char* str) { return UeventType::UNKNOWN; } -static void unregisterEpollEntry(Usb *usb, std::string name) { - std::map *map; - int fd; - - map = &usb->mEpollEntries; - auto it = map->find(name); - if (it != map->end()) { - ALOGI("epoll unregister %s", name.c_str()); - fd = it->second.payload.fd; - epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL); - close(fd); - map->erase(it); - } -} - -static void unregisterEpollEntries(Usb *usb) { - std::map *map; - std::string name; - - map = &usb->mEpollEntries; - for (auto it = map->begin(); it != map->end();) { - name = it->first; - it++; - unregisterEpollEntry(usb, name); - } -} - -static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags, - void (*func)(uint32_t, struct Usb::payload*)) { - std::map *map; - struct Usb::epollEntry *entry; - struct epoll_event ev; - - map = &usb->mEpollEntries; - if (map->find(name) != map->end()) { - ALOGE("%s already registered", name.c_str()); - unregisterEpollEntry(usb, name); - } - - entry = &(*map)[name]; - entry->payload.fd = fd; - entry->payload.name = name; - entry->payload.usb = usb; - entry->cb = std::bind(func, std::placeholders::_1, &entry->payload); - - ev.events = flags; - ev.data.ptr = (void *)&entry->cb; - - if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) { - ALOGE("epoll_ctl failed; errno=%d", errno); - unregisterEpollEntry(usb, name); - return -1; - } - - ALOGI("epoll register %s", name.c_str()); - - return 0; -} - -static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, - void (*func)(uint32_t, struct Usb::payload*)) { - int fd; - - fd = open(name.c_str(), O_RDONLY); - if (fd < 0) { - ALOGE("Cannot open %s", name.c_str()); - return -1; - } - - return registerEpollEntry(usb, name, fd, flags, func); -} - -static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { - device->states.clear(); - device->timestamps.clear(); - device->portResetCount = 0; -} - -static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { - ALOGI("Update USB device state: %s", state); - - device->states.push_back(state); - device->timestamps.push_back(std::chrono::steady_clock::now()); - - if (!std::strcmp(state, "configured\n")) { - device->portResetCount = 0; - } else if (!std::strcmp(state, "default\n")) { - device->portResetCount++; - } -} - -static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - struct Usb::usbDeviceState *device; - - lseek(payload->fd, 0, SEEK_SET); - n = read(payload->fd, &state, USB_STATE_MAX_LEN); - - updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); -} - -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus) { - PortDataRole newDataRole = (*currentPortStatus)[0].currentDataRole; - PowerBrickStatus newPowerBrickStatus = (*currentPortStatus)[0].powerBrickStatus; - - if (newDataRole != usb->mDataRole) { - // Upload metrics for the last non-powerbrick data session that has ended - if (usb->mDataRole != PortDataRole::NONE && !usb->mIsPowerBrickConnected) { - report_usb_data_session_event(usb); - } - - // Set up for the new data session - usb->mDataRole = newDataRole; - usb->mDataSessionStart = std::chrono::steady_clock::now(); - usb->mIsPowerBrickConnected = (newPowerBrickStatus == PowerBrickStatus::CONNECTED); - if (newDataRole == PortDataRole::DEVICE) { - clearUsbDeviceState(&usb->mDeviceState); - } else if (newDataRole == PortDataRole::HOST) { - for (auto &entry : usb->mHostStateMap) { - clearUsbDeviceState(&entry.second); - } - } - } - - // PowerBrickStatus could flip from DISCONNECTED to CONNECTED during the same data - // session when BC1.2 SDP times out and falls back to DCP - if (newPowerBrickStatus == PowerBrickStatus::CONNECTED) { - usb->mIsPowerBrickConnected = true; - } -} - -static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { +static void uevent_event(uint32_t /*epevents*/, struct data *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; int n; enum UeventType uevent_type = UeventType::UNKNOWN; - std::cmatch match; - n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN); + n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); if (n <= 0) return; if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ @@ -1431,28 +1269,6 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { pthread_mutex_unlock(&payload->usb->mDisplayPortLock); } break; - } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) { - /* - * Matched strings: - * 1st: entire string - * 2nd: uevent action, either "bind" or "unbind" - * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto - * 4th: usb device number, e.g. 1 for usb1 - * - * The strings are used to composed usb device state path, e.g. - * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state - */ - if (match.size() == 4) { - std::string action = match[1].str(); - std::string id = match[3].str(); - std::string path = "/sys" + match[2].str() + "usb" + id + "/" + - id + "-0:1.0/usb" + id + "-port1/state"; - if (action == "bind") { - registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); - } else if (action == "unbind") { - unregisterEpollEntry(payload->usb, path); - } - } } /* advance to after the next \0 */ while (*cp++) { @@ -1460,46 +1276,37 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { } } -static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - - lseek(payload->fd, 0, SEEK_SET); - n = read(payload->fd, &state, USB_STATE_MAX_LEN); - - updateUsbDeviceState(&payload->usb->mDeviceState, state); -} - void *work(void *param) { int epoll_fd, uevent_fd; + struct epoll_event ev; int nevents = 0; - Usb *usb = (Usb *)param; + struct data payload; ALOGE("creating thread"); + uevent_fd = uevent_open_socket(64 * 1024, true); + + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed\n"); + return NULL; + } + + payload.uevent_fd = uevent_fd; + payload.usb = (::aidl::android::hardware::usb::Usb *)param; + + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + ev.events = EPOLLIN; + ev.data.ptr = (void *)uevent_event; + epoll_fd = epoll_create(64); if (epoll_fd == -1) { ALOGE("epoll_create failed; errno=%d", errno); - return NULL; - } - usb->mEpollFd = epoll_fd; - - // Monitor uevent - uevent_fd = uevent_open_socket(64 * 1024, true); - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed"); - goto error; - } - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) { - ALOGE("failed to monitor uevent"); goto error; } - // Monitor udc state - if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) { - ALOGE("failed to monitor udc state"); + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { + ALOGE("epoll_ctl failed; errno=%d", errno); goto error; } @@ -1516,15 +1323,14 @@ void *work(void *param) { for (int n = 0; n < nevents; ++n) { if (events[n].data.ptr) - (*(std::function*)events[n].data.ptr)(events[n].events); + (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events, + &payload); } } ALOGI("exiting worker thread"); error: - unregisterEpollEntries(usb); - - usb->mEpollFd = -1; + close(uevent_fd); if (epoll_fd >= 0) close(epoll_fd); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index c1e53541..4d9ab538 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,10 +19,10 @@ #include #include #include -#include #include #include #include +#include #define UEVENT_MSG_LEN 2048 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. @@ -121,6 +121,8 @@ struct Usb : public BnUsb { // Variable to signal partner coming back online after type switch bool mPartnerUp; + // Report usb data session event and data incompliance warnings + UsbDataSessionMonitor mUsbDataSessionMonitor; // Usb Overheat object for push suez event UsbOverheatEvent mOverheat; // Temperature when connected @@ -143,36 +145,6 @@ struct Usb : public BnUsb { // eventfd to signal DisplayPort thread int mDisplayPortEventPipe; - // USB device state monitoring - struct usbDeviceState { - // Usb device state raw strings read from sysfs - std::vector states; - // Timestamps of when the usb device states were captured - std::vector timestamps; - int portResetCount; - }; - struct usbDeviceState mDeviceState; - // Map host device path name to usbDeviceState - std::map mHostStateMap; - // Cache relevant info for USB data session metrics collection when a session starts, including - // the data role, power brick status and the time when the session starts. - PortDataRole mDataRole; - bool mIsPowerBrickConnected; - std::chrono::steady_clock::time_point mDataSessionStart; - - // File monitoring through epoll - int mEpollFd; - struct payload { - int fd; - std::string name; - Usb *usb; - }; - struct epollEntry { - struct payload payload; - std::function cb; - }; - std::map mEpollEntries; - /* * eventfd to set DisplayPort framework update debounce timer. Debounce timer is necessary for * 1) allowing enough time for each sysfs node needed to set HPD high in the drm to populate diff --git a/usb/usb/UsbDataSessionMonitor.cpp b/usb/usb/UsbDataSessionMonitor.cpp new file mode 100644 index 00000000..77defb30 --- /dev/null +++ b/usb/usb/UsbDataSessionMonitor.cpp @@ -0,0 +1,420 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.usb.aidl-service.UsbDataSessionMonitor" + +#include "UsbDataSessionMonitor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace usb_flags = android::hardware::usb::flags; + +using aidl::android::frameworks::stats::IStats; +using android::base::ReadFileToString; +using android::hardware::google::pixel::getStatsService; +using android::hardware::google::pixel::reportUsbDataSessionEvent; +using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; +using android::hardware::google::pixel::usb::addEpollFd; +using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; + +namespace aidl { +namespace android { +namespace hardware { +namespace usb { + +#define UEVENT_MSG_LEN 2048 +#define USB_STATE_MAX_LEN 20 +#define DATA_ROLE_MAX_LEN 10 + +constexpr char kUdcConfigfsPath[] = "/config/usb_gadget/g1/UDC"; +constexpr char kNotAttachedState[] = "not attached\n"; +constexpr char kAttachedState[] = "attached\n"; +constexpr char kPoweredState[] = "powered\n"; +constexpr char kDefaultState[] = "default\n"; +constexpr char kAddressedState[] = "addressed\n"; +constexpr char kConfiguredState[] = "configured\n"; +constexpr char kSuspendedState[] = "suspended\n"; +const std::set kValidStates = {kNotAttachedState, kAttachedState, kPoweredState, + kDefaultState, kAddressedState, kConfiguredState, + kSuspendedState}; + +static int addEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { + struct epoll_event ev; + + unique_fd fd(open(filePath.c_str(), O_RDONLY)); + + if (fd.get() == -1) { + ALOGI("Cannot open %s", filePath.c_str()); + return -1; + } + + ev.data.fd = fd.get(); + ev.events = EPOLLPRI; + + if (epoll_ctl(epollFd, EPOLL_CTL_ADD, fd.get(), &ev) != 0) { + ALOGE("epoll_ctl failed; errno=%d", errno); + return -1; + } + + fileFd = std::move(fd); + ALOGI("epoll registered %s", filePath.c_str()); + return 0; +} + +static void removeEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { + epoll_ctl(epollFd, EPOLL_CTL_DEL, fileFd.get(), NULL); + fileFd.release(); + + ALOGI("epoll unregistered %s", filePath.c_str()); +} + +UsbDataSessionMonitor::UsbDataSessionMonitor( + const std::string &deviceUeventRegex, const std::string &deviceStatePath, + const std::string &host1UeventRegex, const std::string &host1StatePath, + const std::string &host2UeventRegex, const std::string &host2StatePath, + const std::string &dataRolePath, std::function updatePortStatusCb) { + struct epoll_event ev; + std::string udc; + + unique_fd epollFd(epoll_create(8)); + if (epollFd.get() == -1) { + ALOGE("epoll_create failed; errno=%d", errno); + abort(); + } + + unique_fd ueventFd(uevent_open_socket(64 * 1024, true)); + if (ueventFd.get() == -1) { + ALOGE("uevent_open_socket failed"); + abort(); + } + fcntl(ueventFd, F_SETFL, O_NONBLOCK); + + if (addEpollFd(epollFd, ueventFd)) + abort(); + + if (addEpollFile(epollFd.get(), dataRolePath, mDataRoleFd) != 0) { + ALOGE("monitor data role failed"); + abort(); + } + + /* + * The device state file could be absent depending on the current data role + * and driver architecture. It's ok for addEpollFile to fail here, the file + * will be monitored later when its presence is detected by uevent. + */ + mDeviceState.filePath = deviceStatePath; + mDeviceState.ueventRegex = deviceUeventRegex; + addEpollFile(epollFd.get(), mDeviceState.filePath, mDeviceState.fd); + + mHost1State.filePath = host1StatePath; + mHost1State.ueventRegex = host1UeventRegex; + addEpollFile(epollFd.get(), mHost1State.filePath, mHost1State.fd); + + mHost2State.filePath = host2StatePath; + mHost2State.ueventRegex = host2UeventRegex; + addEpollFile(epollFd.get(), mHost2State.filePath, mHost2State.fd); + + mEpollFd = std::move(epollFd); + mUeventFd = std::move(ueventFd); + mUpdatePortStatusCb = updatePortStatusCb; + + if (ReadFileToString(kUdcConfigfsPath, &udc) && !udc.empty()) + mUdcBind = true; + else + mUdcBind = false; + + if (pthread_create(&mMonitor, NULL, this->monitorThread, this)) { + ALOGE("pthread creation failed %d", errno); + abort(); + } +} + +UsbDataSessionMonitor::~UsbDataSessionMonitor() {} + +void UsbDataSessionMonitor::reportUsbDataSessionMetrics() { + std::vector events; + + if (mDataRole == PortDataRole::DEVICE) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(false /* is_host */, boot_clock::now(), mDataSessionStart, + &mDeviceState.states, &mDeviceState.timestamps, &event); + events.push_back(event); + } else if (mDataRole == PortDataRole::HOST) { + bool empty = true; + for (auto e : {&mHost1State, &mHost2State}) { + /* + * Host port will at least get an not_attached event after enablement, + * skip upload if no additional state is added. + */ + if (e->states.size() > 1) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), + mDataSessionStart, &e->states, &e->timestamps, + &event); + events.push_back(event); + empty = false; + } + } + // All host ports have no state update, upload an event to reflect it + if (empty) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), mDataSessionStart, + &mHost1State.states, &mHost1State.timestamps, &event); + events.push_back(event); + } + } else { + return; + } + + const std::shared_ptr stats_client = getStatsService(); + if (!stats_client) { + ALOGE("Unable to get AIDL Stats service"); + return; + } + + for (auto &event : events) { + reportUsbDataSessionEvent(stats_client, event); + } +} + +void UsbDataSessionMonitor::getComplianceWarnings(const PortDataRole &role, + std::vector *warnings) { + if (!usb_flags::enable_report_usb_data_compliance_warning()) + return; + + if (role != mDataRole || role == PortDataRole::NONE) + return; + + for (auto w : mWarningSet) { + warnings->push_back(w); + } +} + +void UsbDataSessionMonitor::notifyComplianceWarning() { + if (!usb_flags::enable_report_usb_data_compliance_warning()) + return; + + if (mUpdatePortStatusCb) + mUpdatePortStatusCb(); +} + +void UsbDataSessionMonitor::evaluateComplianceWarning() { + std::set newWarningSet; + + // TODO: add heuristics and update newWarningSet + if (mDataRole == PortDataRole::DEVICE && mUdcBind) { + } else if (mDataRole == PortDataRole::HOST) { + } + + if (newWarningSet != mWarningSet) { + mWarningSet = newWarningSet; + notifyComplianceWarning(); + } +} + +void UsbDataSessionMonitor::clearDeviceStateEvents(struct usbDeviceState *deviceState) { + deviceState->states.clear(); + deviceState->timestamps.clear(); +} + +void UsbDataSessionMonitor::handleDeviceStateEvent(struct usbDeviceState *deviceState) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + + lseek(deviceState->fd.get(), 0, SEEK_SET); + n = read(deviceState->fd.get(), &state, USB_STATE_MAX_LEN); + + if (kValidStates.find(state) == kValidStates.end()) { + ALOGE("Invalid state %s", state); + return; + } + + ALOGI("Update USB device state: %s", state); + + deviceState->states.push_back(state); + deviceState->timestamps.push_back(boot_clock::now()); + evaluateComplianceWarning(); +} + +void UsbDataSessionMonitor::handleDataRoleEvent() { + int n; + PortDataRole newDataRole; + char role[DATA_ROLE_MAX_LEN] = {0}; + + lseek(mDataRoleFd.get(), 0, SEEK_SET); + n = read(mDataRoleFd.get(), &role, DATA_ROLE_MAX_LEN); + + ALOGI("Update USB data role %s", role); + + if (!std::strcmp(role, "host")) { + newDataRole = PortDataRole::HOST; + } else if (!std::strcmp(role, "device")) { + newDataRole = PortDataRole::DEVICE; + } else { + newDataRole = PortDataRole::NONE; + } + + if (newDataRole != mDataRole) { + // Upload metrics for the last data session that has ended + if (mDataRole == PortDataRole::HOST || (mDataRole == PortDataRole::DEVICE && mUdcBind)) { + reportUsbDataSessionMetrics(); + } + + // Set up for the new data session + mWarningSet.clear(); + mDataRole = newDataRole; + mDataSessionStart = boot_clock::now(); + + if (newDataRole == PortDataRole::DEVICE) { + clearDeviceStateEvents(&mDeviceState); + } else if (newDataRole == PortDataRole::HOST) { + clearDeviceStateEvents(&mHost1State); + clearDeviceStateEvents(&mHost2State); + } + } +} + +void UsbDataSessionMonitor::updateUdcBindStatus(const std::string &devname) { + std::string function; + bool newUdcBind; + + /* + * /sys/class/udc//function prints out name of currently running USB gadget driver + * Ref: https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-udc + * Empty name string means the udc device is not bound and gadget is pulldown. + */ + if (!ReadFileToString("/sys" + devname + "/function", &function)) + return; + + if (function == "") + newUdcBind = false; + else + newUdcBind = true; + + if (newUdcBind == mUdcBind) + return; + + if (mDataRole == PortDataRole::DEVICE) { + if (mUdcBind && !newUdcBind) { + /* + * Gadget soft pulldown: report metrics as the end of a data session and + * re-evaluate compliance warnings to clear existing warnings if any. + */ + reportUsbDataSessionMetrics(); + evaluateComplianceWarning(); + + } else if (!mUdcBind && newUdcBind) { + // Gadget soft pullup: reset and start accounting for a new data session. + clearDeviceStateEvents(&mDeviceState); + mDataSessionStart = boot_clock::now(); + } + } + + ALOGI("Udc bind status changes from %b to %b", mUdcBind, newUdcBind); + mUdcBind = newUdcBind; +} + +void UsbDataSessionMonitor::handleUevent() { + char msg[UEVENT_MSG_LEN + 2]; + char *cp; + int n; + + n = uevent_kernel_multicast_recv(mUeventFd.get(), msg, UEVENT_MSG_LEN); + if (n <= 0) + return; + if (n >= UEVENT_MSG_LEN) + return; + + msg[n] = '\0'; + msg[n + 1] = '\0'; + cp = msg; + + while (*cp) { + for (auto e : {&mHost1State, &mHost2State}) { + if (std::regex_search(cp, std::regex(e->ueventRegex))) { + if (!strncmp(cp, "bind@", strlen("bind@"))) { + addEpollFile(mEpollFd.get(), e->filePath, e->fd); + } else if (!strncmp(cp, "unbind@", strlen("unbind@"))) { + removeEpollFile(mEpollFd.get(), e->filePath, e->fd); + } + } + } + + // TODO: support bind@ unbind@ to detect dynamically allocated udc device + if (std::regex_search(cp, std::regex(mDeviceState.ueventRegex))) { + if (!strncmp(cp, "change@", strlen("change@"))) { + char *devname = cp + strlen("change@"); + /* + * Udc device emits a KOBJ_CHANGE event on configfs driver bind and unbind. + * TODO: upstream udc driver emits KOBJ_CHANGE event BEFORE unbind is actually + * executed. Add a short delay to get the correct state while working on a fix + * upstream. + */ + usleep(50000); + updateUdcBindStatus(devname); + } + } + /* advance to after the next \0 */ + while (*cp++) { + } + } +} + +void *UsbDataSessionMonitor::monitorThread(void *param) { + UsbDataSessionMonitor *monitor = (UsbDataSessionMonitor *)param; + struct epoll_event events[64]; + int nevents = 0; + + while (true) { + nevents = epoll_wait(monitor->mEpollFd.get(), events, 64, -1); + if (nevents == -1) { + if (errno == EINTR) + continue; + ALOGE("usb epoll_wait failed; errno=%d", errno); + break; + } + + for (int n = 0; n < nevents; ++n) { + if (events[n].data.fd == monitor->mUeventFd.get()) { + monitor->handleUevent(); + } else if (events[n].data.fd == monitor->mDataRoleFd.get()) { + monitor->handleDataRoleEvent(); + } else if (events[n].data.fd == monitor->mDeviceState.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mDeviceState); + } else if (events[n].data.fd == monitor->mHost1State.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mHost1State); + } else if (events[n].data.fd == monitor->mHost2State.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mHost2State); + } + } + } + return NULL; +} + +} // namespace usb +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/usb/usb/UsbDataSessionMonitor.h b/usb/usb/UsbDataSessionMonitor.h new file mode 100644 index 00000000..596f378f --- /dev/null +++ b/usb/usb/UsbDataSessionMonitor.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +namespace aidl { +namespace android { +namespace hardware { +namespace usb { + +using ::aidl::android::hardware::usb::ComplianceWarning; +using ::aidl::android::hardware::usb::PortDataRole; +using ::android::base::boot_clock; +using ::android::base::unique_fd; + +/* + * UsbDataSessionMonitor monitors the usb device state sysfs of 3 different usb devices + * including device mode (udc), host mode high-speed port and host mode super-speed port. It + * reports Suez metrics for each data session and also provides API to query the compliance + * warnings detected in the current usb data session. + */ +class UsbDataSessionMonitor { + public: + /* + * The host mode high-speed port and super-speed port can be assigned to either host1 or + * host2 without affecting functionality. + * + * UeventRegex: name regex of the device that's being monitored. The regex is matched against + * uevent to detect dynamic creation/deletion/change of the device. + * StatePath: usb device state sysfs path of the device, monitored by epoll. + * dataRolePath: path to the usb data role sysfs, monitored by epoll. + * updatePortStatusCb: the callback is invoked when the compliance warings changes. + */ + UsbDataSessionMonitor(const std::string &deviceUeventRegex, const std::string &deviceStatePath, + const std::string &host1UeventRegex, const std::string &host1StatePath, + const std::string &host2UeventRegex, const std::string &host2StatePath, + const std::string &dataRolePath, + std::function updatePortStatusCb); + ~UsbDataSessionMonitor(); + // Returns the compliance warnings detected in the current data session. + void getComplianceWarnings(const PortDataRole &role, std::vector *warnings); + + private: + struct usbDeviceState { + unique_fd fd; + std::string filePath; + std::string ueventRegex; + // Usb device states reported by state sysfs + std::vector states; + // Timestamps of when the usb device states were captured + std::vector timestamps; + }; + + static void *monitorThread(void *param); + void handleUevent(); + void handleDataRoleEvent(); + void handleDeviceStateEvent(struct usbDeviceState *deviceState); + void clearDeviceStateEvents(struct usbDeviceState *deviceState); + void reportUsbDataSessionMetrics(); + void evaluateComplianceWarning(); + void notifyComplianceWarning(); + void updateUdcBindStatus(const std::string &devname); + + pthread_t mMonitor; + unique_fd mEpollFd; + unique_fd mUeventFd; + unique_fd mDataRoleFd; + struct usbDeviceState mDeviceState; + struct usbDeviceState mHost1State; + struct usbDeviceState mHost2State; + std::set mWarningSet; + // Callback function to notify the caller when there's a change in compliance warnings. + std::function mUpdatePortStatusCb; + /* + * Cache relevant info for a USB data session when one starts, including + * the data role and the time when the session starts. + */ + PortDataRole mDataRole; + boot_clock::time_point mDataSessionStart; + /* + * In gadget mode: this indicates whether the udc device is bound to the configfs driver, which + * is done by userspace writing the udc device name to /config/usb_gadget/g1/UDC. When unbound, + * the gadget is in soft pulldown state and is expected not to enumerate. During gadget + * function switch, the udc device usually go through unbind and bind. + */ + bool mUdcBind; +}; + +} // namespace usb +} // namespace hardware +} // namespace android +} // namespace aidl From 65439a058c0699533438651fcd53fa4f1387d4e1 Mon Sep 17 00:00:00 2001 From: Sebastian Pickl Date: Fri, 1 Dec 2023 11:30:35 +0000 Subject: [PATCH 119/133] Revert "zuma: include bootctrl_aidl.mk from gs-common" Revert submission 25477883-gs-common_bootctrl-aidl Reason for revert: breaking builds b/314240126 Bug: 314240126 Reverted changes: /q/submissionid:25477883-gs-common_bootctrl-aidl Change-Id: I126138b048512fe6b2bbb2d8463152974e8f7c0a --- device.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/device.mk b/device.mk index bde0a2f9..ab634a51 100644 --- a/device.mk +++ b/device.mk @@ -40,7 +40,6 @@ include device/google/gs-common/widevine/widevine.mk include device/google/gs-common/sota_app/factoryota.mk include device/google/gs-common/misc_writer/misc_writer.mk include device/google/gs-common/gyotaku_app/gyotaku.mk -include device/google/gs-common/bootctrl/bootctrl_aidl.mk include device/google/zuma/dumpstate/item.mk From ae2cacc6e21266411f22e6d21572f4ee5740d7de Mon Sep 17 00:00:00 2001 From: Sebastian Pickl Date: Fri, 1 Dec 2023 11:30:35 +0000 Subject: [PATCH 120/133] Revert "zuma: move bootctrl service declaration to gs-common" Revert submission 25477883-gs-common_bootctrl-aidl Reason for revert: breaking builds b/314240126 Bug: 314240126 Reverted changes: /q/submissionid:25477883-gs-common_bootctrl-aidl Change-Id: Ib0fb8d03bb4592cfb0c9f5427326193b3ae16da0 --- device.mk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/device.mk b/device.mk index ab634a51..10c6839e 100644 --- a/device.mk +++ b/device.mk @@ -924,6 +924,11 @@ PRODUCT_PACKAGES += \ ImsMediaService \ libimsmedia +# Boot Control HAL +PRODUCT_PACKAGES += \ + android.hardware.boot-service.default-zuma\ + android.hardware.boot-service.default_recovery-zuma + # Exynos RIL and telephony # Multi SIM(DSDS) SIM_COUNT := 2 From 8676a0deff11140c2ba58773cb0dd5e68e8ebfde Mon Sep 17 00:00:00 2001 From: Sebastian Pickl Date: Fri, 1 Dec 2023 11:30:35 +0000 Subject: [PATCH 121/133] Revert "zuma: move bootctrl hal to gs-common" Revert submission 25477883-gs-common_bootctrl-aidl Reason for revert: breaking builds b/314240126 Bug: 314240126 Reverted changes: /q/submissionid:25477883-gs-common_bootctrl-aidl Change-Id: If413155d4a2129c482ae98a128dc05b4aaba5374 --- interfaces/boot/1.0/Android.bp | 66 +++ interfaces/boot/1.0/BootControl.cpp | 272 +++++++++ interfaces/boot/1.0/BootControl.h | 59 ++ interfaces/boot/1.0/GptUtils.cpp | 199 +++++++ interfaces/boot/1.0/GptUtils.h | 79 +++ .../android.hardware.boot@1.0-service-zuma.rc | 4 + interfaces/boot/1.0/service.cpp | 47 ++ interfaces/boot/1.2/Android.bp | 83 +++ interfaces/boot/1.2/BootControl.cpp | 501 ++++++++++++++++ interfaces/boot/1.2/BootControl.h | 88 +++ interfaces/boot/1.2/DevInfo.h | 61 ++ interfaces/boot/1.2/GptUtils.cpp | 193 +++++++ interfaces/boot/1.2/GptUtils.h | 79 +++ .../android.hardware.boot@1.2-service-zuma.rc | 7 + interfaces/boot/1.2/service.cpp | 50 ++ interfaces/boot/aidl/Android.bp | 65 +++ interfaces/boot/aidl/BootControl.cpp | 538 ++++++++++++++++++ interfaces/boot/aidl/BootControl.h | 61 ++ interfaces/boot/aidl/DevInfo.h | 53 ++ interfaces/boot/aidl/GptUtils.cpp | 185 ++++++ interfaces/boot/aidl/GptUtils.h | 71 +++ ...roid.hardware.boot-service.default-zuma.rc | 5 + ...ware.boot-service.default_recovery-zuma.rc | 7 + ...are.boot-service.default_recovery-zuma.xml | 6 + interfaces/boot/aidl/service.cpp | 44 ++ 25 files changed, 2823 insertions(+) create mode 100644 interfaces/boot/1.0/Android.bp create mode 100644 interfaces/boot/1.0/BootControl.cpp create mode 100644 interfaces/boot/1.0/BootControl.h create mode 100644 interfaces/boot/1.0/GptUtils.cpp create mode 100644 interfaces/boot/1.0/GptUtils.h create mode 100644 interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc create mode 100644 interfaces/boot/1.0/service.cpp create mode 100644 interfaces/boot/1.2/Android.bp create mode 100644 interfaces/boot/1.2/BootControl.cpp create mode 100644 interfaces/boot/1.2/BootControl.h create mode 100644 interfaces/boot/1.2/DevInfo.h create mode 100644 interfaces/boot/1.2/GptUtils.cpp create mode 100644 interfaces/boot/1.2/GptUtils.h create mode 100644 interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc create mode 100644 interfaces/boot/1.2/service.cpp create mode 100644 interfaces/boot/aidl/Android.bp create mode 100644 interfaces/boot/aidl/BootControl.cpp create mode 100644 interfaces/boot/aidl/BootControl.h create mode 100644 interfaces/boot/aidl/DevInfo.h create mode 100644 interfaces/boot/aidl/GptUtils.cpp create mode 100644 interfaces/boot/aidl/GptUtils.h create mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc create mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc create mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml create mode 100644 interfaces/boot/aidl/service.cpp diff --git a/interfaces/boot/1.0/Android.bp b/interfaces/boot/1.0/Android.bp new file mode 100644 index 00000000..5599fafb --- /dev/null +++ b/interfaces/boot/1.0/Android.bp @@ -0,0 +1,66 @@ +// +// Copyright (C) 2019 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: [ + "//device/google/zuma:device_google_zuma_license", + ], +} + +cc_binary { + name: "android.hardware.boot@1.0-service-zuma", + defaults: ["hidl_defaults"], + relative_install_path: "hw", + vendor: true, + init_rc: ["android.hardware.boot@1.0-service-zuma.rc"], + srcs: [ + "BootControl.cpp", + "GptUtils.cpp", + "service.cpp" + ], + shared_libs: [ + "libbase", + "liblog", + "libhidlbase", + "libutils", + "libcutils", + "libz", + "android.hardware.boot@1.0", + ], +} + +cc_library { + name: "android.hardware.boot@1.0-impl-zuma", + recovery: true, + srcs: [ + "BootControl.cpp", + "GptUtils.cpp", + ], + relative_install_path: "hw", + shared_libs: [ + "libbase", + "liblog", + "libhidlbase", + "libutils", + "libcutils", + "libz", + "android.hardware.boot@1.0", + ], +} diff --git a/interfaces/boot/1.0/BootControl.cpp b/interfaces/boot/1.0/BootControl.cpp new file mode 100644 index 00000000..1f155c9d --- /dev/null +++ b/interfaces/boot/1.0/BootControl.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "bootcontrolhal" + +#include "BootControl.h" +#include "GptUtils.h" + +#include +#include +#include + +namespace android { +namespace hardware { +namespace boot { +namespace V1_0 { +namespace implementation { + +namespace { + +#define BOOT_A_PATH "/dev/block/by-name/boot_a" +#define BOOT_B_PATH "/dev/block/by-name/boot_b" + +// slot flags +#define AB_ATTR_PRIORITY_SHIFT 52 +#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) +#define AB_ATTR_ACTIVE_SHIFT 54 +#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) +#define AB_ATTR_RETRY_COUNT_SHIFT (55) +#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) +#define AB_ATTR_SUCCESSFUL (1UL << 58) +#define AB_ATTR_UNBOOTABLE (1UL << 59) + +#define AB_ATTR_MAX_PRIORITY 3UL +#define AB_ATTR_MAX_RETRY_COUNT 3UL + +static std::string getDevPath(uint32_t slot) { + char real_path[PATH_MAX]; + + const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; + + int ret = readlink(path, real_path, sizeof real_path); + if (ret < 0) { + ALOGE("readlink failed for boot device %s\n", strerror(errno)); + return std::string(); + } + + std::string dp(real_path); + // extract /dev/sda.. part + return dp.substr(0, sizeof "/dev/block/sdX" - 1); +} + +static bool isSlotFlagSet(uint32_t slot, uint64_t flag) { + std::string dev_path = getDevPath(slot); + if (dev_path.empty()) { + ALOGI("Could not get device path for slot %d\n", slot); + return false; + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + ALOGI("failed to load gpt data\n"); + return false; + } + + gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); + if (e == nullptr) { + ALOGI("failed to get gpt entry\n"); + return false; + } + + return !!(e->attr & flag); +} + +static int setSlotFlag(uint32_t slot, uint64_t flag) { + std::string dev_path = getDevPath(slot); + if (dev_path.empty()) { + ALOGI("Could not get device path for slot %d\n", slot); + return -1; + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + ALOGI("failed to load gpt data\n"); + return -1; + } + + gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); + if (e == nullptr) { + ALOGI("failed to get gpt entry\n"); + return -1; + } + + e->attr |= flag; + gpt.Sync(); + + return 0; +} + +} + +// Methods from ::android::hardware::boot::V1_0::IBootControl follow. +Return BootControl::getNumberSlots() { + uint32_t slots = 0; + + if (access(BOOT_A_PATH, F_OK) == 0) + slots++; + + if (access(BOOT_B_PATH, F_OK) == 0) + slots++; + + return slots; +} + +Return BootControl::getCurrentSlot() { + char suffix[PROPERTY_VALUE_MAX]; + property_get("ro.boot.slot_suffix", suffix, "_a"); + return std::string(suffix) == "_b" ? 1 : 0; +} + +Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { + if (getNumberSlots() == 0) { + // no slots, just return true otherwise Android keeps trying + _hidl_cb({true, ""}); + return Void(); + } + int ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL); + ret ? _hidl_cb({false, "Failed to set successfull flag"}) : _hidl_cb({true, ""}); + return Void(); +} + +Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { + if (slot >= 2) { + _hidl_cb({false, "Invalid slot"}); + return Void(); + } + + std::string dev_path = getDevPath(slot); + if (dev_path.empty()) { + _hidl_cb({false, "Could not get device path for slot"}); + return Void(); + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + _hidl_cb({false, "failed to load gpt data"}); + return Void(); + } + + gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b"); + gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a"); + if (active_entry == nullptr || inactive_entry == nullptr) { + _hidl_cb({false, "failed to get entries for boot partitions"}); + return Void(); + } + + ALOGV("slot active attributes %lx\n", active_entry->attr); + ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); + + char boot_dev[PROPERTY_VALUE_MAX]; + property_get("ro.boot.bootdevice", boot_dev, ""); + if (boot_dev[0] == '\0') { + _hidl_cb({false, "invalid ro.boot.bootdevice prop"}); + return Void(); + } + + std::string boot_lun_path = std::string("/sys/devices/platform/") + + boot_dev + "/pixel/boot_lun_enabled"; + int fd = open(boot_lun_path.c_str(), O_RDWR); + if (fd < 0) { + // Try old path for kernels < 5.4 + // TODO: remove once kernel 4.19 support is deprecated + std::string boot_lun_path = std::string("/sys/devices/platform/") + + boot_dev + "/attributes/boot_lun_enabled"; + fd = open(boot_lun_path.c_str(), O_RDWR); + if (fd < 0) { + _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"}); + return Void(); + } + } + + // update attributes for active and inactive + inactive_entry->attr &= ~AB_ATTR_ACTIVE; + active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | + (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); + + // + // bBootLunEn + // 0x1 => Boot LU A = enabled, Boot LU B = disable + // 0x2 => Boot LU A = disable, Boot LU B = enabled + // + int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd); + close(fd); + if (ret < 0) { + _hidl_cb({false, "faied to write boot_lun_enabled attribute"}); + return Void(); + } + + _hidl_cb({true, ""}); + return Void(); +} + +Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { + if (slot >= 2) { + _hidl_cb({false, "Invalid slot"}); + return Void(); + } + + std::string dev_path = getDevPath(slot); + if (dev_path.empty()) { + _hidl_cb({false, "Could not get device path for slot"}); + return Void(); + } + + GptUtils gpt(dev_path); + gpt.Load(); + + gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); + e->attr |= AB_ATTR_UNBOOTABLE; + + gpt.Sync(); + + _hidl_cb({true, ""}); + return Void(); +} + +Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) { + if (getNumberSlots() == 0) + return BoolResult::FALSE; + if (slot >= getNumberSlots()) + return BoolResult::INVALID_SLOT; + return isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE) ? BoolResult::FALSE : BoolResult::TRUE; +} + +Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) { + if (getNumberSlots() == 0) { + // just return true so that we don't we another call trying to mark it as successful + // when there is no slots + return BoolResult::TRUE; + } + if (slot >= getNumberSlots()) + return BoolResult::INVALID_SLOT; + return isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL) ? BoolResult::TRUE : BoolResult::FALSE; +} + +Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { + _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : ""); + return Void(); +} + +extern "C" IBootControl* HIDL_FETCH_IBootControl(const char*) { + return new BootControl(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.0/BootControl.h b/interfaces/boot/1.0/BootControl.h new file mode 100644 index 00000000..eb81cb07 --- /dev/null +++ b/interfaces/boot/1.0/BootControl.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace android { +namespace hardware { +namespace boot { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +struct BootControl : public IBootControl { + // Methods from ::android::hardware::boot::V1_0::IBootControl follow. + Return getNumberSlots() override; + Return getCurrentSlot() override; + Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; + Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; + Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; + Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override; + Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(uint32_t slot) override; + Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; + + // Methods from ::android::hidl::base::V1_0::IBase follow. + +}; + +// FIXME: most likely delete, this is only for passthrough implementations +extern "C" IBootControl* HIDL_FETCH_IBootControl(const char* name); + +} // namespace implementation +} // namespace V1_0 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.0/GptUtils.cpp b/interfaces/boot/1.0/GptUtils.cpp new file mode 100644 index 00000000..f8936175 --- /dev/null +++ b/interfaces/boot/1.0/GptUtils.cpp @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "bootcontrolhal" + +#include "GptUtils.h" + +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace boot { +namespace V1_0 { +namespace implementation { + +namespace { + +static int ValidateGptHeader(gpt_header *gpt) +{ + if (gpt->signature != GPT_SIGNATURE) { + ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); + return -1; + } + + if (gpt->header_size != sizeof(gpt_header)) { + ALOGE("invalid gpt header size %u\n", gpt->header_size); + return -1; + } + + if (gpt->entry_size != sizeof(gpt_entry)) { + ALOGE("invalid gpt entry size %u\n", gpt->entry_size); + return -1; + } + + return 0; +} + +} + +GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} + +int GptUtils::Load(void) +{ + fd = open(dev_path.c_str(), O_RDWR); + if (fd < 0) { + ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); + return -1; + } + + int ret = ioctl(fd, BLKSSZGET, &block_size); + if (ret < 0) { + ALOGE("failed to get block size %d\n", errno); + return -1; + } + + // read primary header + lseek64(fd, block_size, SEEK_SET); + ret = read(fd, &gpt_primary, sizeof gpt_primary); + if (ret < 0) { + ALOGE("failed to read gpt primary header %d\n", errno); + return -1; + } + + if (ValidateGptHeader(&gpt_primary)) { + ALOGE("error validating gpt header\n"); + return -1; + } + + // read partition entries + entry_array.resize(gpt_primary.entry_count); + uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; + lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); + ret = read(fd, entry_array.data(), entries_size); + if (ret < 0) { + ALOGE("failed to read gpt partition entries %d\n", errno); + return -1; + } + + // read gpt back header + lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); + ret = read(fd, &gpt_backup, sizeof gpt_backup); + if (ret < 0) { + ALOGE("failed to read gpt backup header %d\n", errno); + return -1; + } + + if (ValidateGptHeader(&gpt_backup)) { + ALOGW("error validating gpt backup\n"); // just warn about it, not fail + } + + // Create map + auto get_name = [](const uint16_t *efi_name) { + char name[37] = {}; + for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) + name[i] = efi_name[i]; + return std::string(name); + }; + + for (auto const &e: entry_array) { + if (e.name[0] == 0) + break; // stop at the first partition with no name + std::string s = get_name(e.name); + entries[s] = const_cast(&e); + } + + return 0; +} + +gpt_entry *GptUtils::GetPartitionEntry(std::string name) +{ + return entries.find(name) != entries.end() ? entries[name] : nullptr; +} + +int GptUtils::Sync(void) +{ + if (!fd) + return -1; + + // calculate crc and check if we need to update gpt + gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), + entry_array.size() * sizeof(gpt_entry)); + + // save old crc + uint32_t crc = gpt_primary.crc32; + gpt_primary.crc32 = 0; + + gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); + if (crc == gpt_primary.crc32) + return 0; // nothing to do (no changes) + + ALOGI("updating GPT\n"); + + lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); + int ret = write(fd, &gpt_primary, sizeof gpt_primary); + if (ret < 0) { + ALOGE("failed to write gpt primary header %d\n", errno); + return -1; + } + + lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); + ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); + if (ret < 0) { + ALOGE("failed to write gpt partition entries %d\n", errno); + return -1; + } + + //update GPT backup entries and backup + lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); + ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); + if (ret < 0) { + ALOGE("failed to write gpt backup partition entries %d\n", errno); + return -1; + } + + gpt_backup.entries_crc32 = gpt_primary.entries_crc32; + gpt_backup.crc32 = 0; + gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); + lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); + ret = write(fd, &gpt_backup, sizeof gpt_backup); + if (ret < 0) { + ALOGE("failed to write gpt backup header %d\n", errno); + return -1; + } + + fsync(fd); + + return 0; +} + +GptUtils::~GptUtils() +{ + if (fd) { + Sync(); + close(fd); + } +} + +} // namespace implementation +} // namespace V1_0 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.0/GptUtils.h b/interfaces/boot/1.0/GptUtils.h new file mode 100644 index 00000000..d969d9d8 --- /dev/null +++ b/interfaces/boot/1.0/GptUtils.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace android { +namespace hardware { +namespace boot { +namespace V1_0 { +namespace implementation { + +#define GPT_SIGNATURE 0x5452415020494645UL + +typedef struct { + uint8_t type_guid[16]; + uint8_t guid[16]; + uint64_t first_lba; + uint64_t last_lba; + uint64_t attr; + uint16_t name[36]; +} __attribute__((packed)) gpt_entry; + +typedef struct { + uint64_t signature; + uint32_t revision; + uint32_t header_size; + uint32_t crc32; + uint32_t reserved; + uint64_t current_lba; + uint64_t backup_lba; + uint64_t first_usable_lba; + uint64_t last_usable_lba; + uint8_t disk_guid[16]; + uint64_t start_lba; + uint32_t entry_count; + uint32_t entry_size; + uint32_t entries_crc32; +} __attribute__((packed)) gpt_header; + +class GptUtils { + public: + GptUtils(const std::string dev_path); + int Load(void); + gpt_entry *GetPartitionEntry(std::string name); + int Sync(void); + ~GptUtils(); + + private: + std::string dev_path; + int fd; + uint32_t block_size; + gpt_header gpt_primary; + gpt_header gpt_backup; + std::vector entry_array; + std::mapentries; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc b/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc new file mode 100644 index 00000000..7997fded --- /dev/null +++ b/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc @@ -0,0 +1,4 @@ +service vendor.boot-hal-1-0 /vendor/bin/hw/android.hardware.boot@1.0-service-zuma + class early_hal + user root + group root diff --git a/interfaces/boot/1.0/service.cpp b/interfaces/boot/1.0/service.cpp new file mode 100644 index 00000000..9dcd78cc --- /dev/null +++ b/interfaces/boot/1.0/service.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "android.hardware.boot@1.0-service" + +#include +#include +#include +#include +#include "BootControl.h" + +using ::android::status_t; + +using ::android::hardware::boot::V1_0::IBootControl; + +using ::android::hardware::boot::V1_0::implementation::BootControl; + +int main (int /* argc */, char * /* argv */ []) { + // This function must be called before you join to ensure the proper + // number of threads are created. The threadpool will never exceed + // size one because of this call. + ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/); + + ::android::sp bootctrl = new BootControl(); + const status_t status = bootctrl->registerAsService(); + if (status != ::android::OK) { + return 1; // or handle error + } + + // Adds this thread to the threadpool, resulting in one total + // thread in the threadpool. We could also do other things, but + // would have to specify 'false' to willJoin in configureRpcThreadpool. + ::android::hardware::joinRpcThreadpool(); + return 1; // joinRpcThreadpool should never return +} diff --git a/interfaces/boot/1.2/Android.bp b/interfaces/boot/1.2/Android.bp new file mode 100644 index 00000000..90b0c6ed --- /dev/null +++ b/interfaces/boot/1.2/Android.bp @@ -0,0 +1,83 @@ +// +// Copyright (C) 2020 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: [ + "//device/google/zuma:device_google_zuma_license", + ], +} + +cc_binary { + name: "android.hardware.boot@1.2-service-zuma", + defaults: ["hidl_defaults"], + relative_install_path: "hw", + vendor: true, + init_rc: ["android.hardware.boot@1.2-service-zuma.rc"], + srcs: [ + "BootControl.cpp", + "GptUtils.cpp", + "service.cpp" + ], + shared_libs: [ + "libbase", + "liblog", + "libhidlbase", + "libutils", + "libcutils", + "libz", + "libtrusty", + "android.hardware.boot@1.0", + "android.hardware.boot@1.1", + "android.hardware.boot@1.2", + ], + static_libs: [ + "libboot_control", + "libbootloader_message_vendor", + "libfstab", + ], +} + +cc_library { + name: "android.hardware.boot@1.2-impl-zuma", + stem: "android.hardware.boot@1.0-impl-1.2-impl-zuma", + recovery: true, + srcs: [ + "BootControl.cpp", + "GptUtils.cpp", + ], + relative_install_path: "hw", + shared_libs: [ + "libbase", + "liblog", + "libhidlbase", + "libutils", + "libcutils", + "libz", + "libtrusty", + "android.hardware.boot@1.0", + "android.hardware.boot@1.1", + "android.hardware.boot@1.2", + ], + static_libs: [ + "libboot_control", + "libbootloader_message_vendor", + "libfstab", + ], +} diff --git a/interfaces/boot/1.2/BootControl.cpp b/interfaces/boot/1.2/BootControl.cpp new file mode 100644 index 00000000..77820754 --- /dev/null +++ b/interfaces/boot/1.2/BootControl.cpp @@ -0,0 +1,501 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "bootcontrolhal" + +#include "BootControl.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "DevInfo.h" +#include "GptUtils.h" + +namespace android { +namespace hardware { +namespace boot { +namespace V1_2 { +namespace implementation { + +using android::bootable::GetMiscVirtualAbMergeStatus; +using android::bootable::InitMiscVirtualAbMessageIfNeeded; +using android::bootable::SetMiscVirtualAbMergeStatus; +using android::hardware::boot::V1_0::BoolResult; +using android::hardware::boot::V1_0::CommandResult; +using android::hardware::boot::V1_1::MergeStatus; + +namespace { + +// clang-format off + +#define BOOT_A_PATH "/dev/block/by-name/boot_a" +#define BOOT_B_PATH "/dev/block/by-name/boot_b" +#define DEVINFO_PATH "/dev/block/by-name/devinfo" + +// slot flags +#define AB_ATTR_PRIORITY_SHIFT 52 +#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) +#define AB_ATTR_ACTIVE_SHIFT 54 +#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) +#define AB_ATTR_RETRY_COUNT_SHIFT (55) +#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) +#define AB_ATTR_SUCCESSFUL (1UL << 58) +#define AB_ATTR_UNBOOTABLE (1UL << 59) + +#define AB_ATTR_MAX_PRIORITY 3UL +#define AB_ATTR_MAX_RETRY_COUNT 3UL + +// clang-format on + +static std::string getDevPath(uint32_t slot) { + char real_path[PATH_MAX]; + + const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; + + int ret = readlink(path, real_path, sizeof real_path); + if (ret < 0) { + ALOGE("readlink failed for boot device %s\n", strerror(errno)); + return std::string(); + } + + std::string dp(real_path); + // extract /dev/sda.. part + return dp.substr(0, sizeof "/dev/block/sdX" - 1); +} + +static bool isSlotFlagSet(uint32_t slot, uint64_t flag) { + std::string dev_path = getDevPath(slot); + if (dev_path.empty()) { + ALOGI("Could not get device path for slot %d\n", slot); + return false; + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + ALOGI("failed to load gpt data\n"); + return false; + } + + gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); + if (e == nullptr) { + ALOGI("failed to get gpt entry\n"); + return false; + } + + return !!(e->attr & flag); +} + +static bool setSlotFlag(uint32_t slot, uint64_t flag) { + std::string dev_path = getDevPath(slot); + if (dev_path.empty()) { + ALOGI("Could not get device path for slot %d\n", slot); + return false; + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + ALOGI("failed to load gpt data\n"); + return false; + } + + gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); + if (e == nullptr) { + ALOGI("failed to get gpt entry\n"); + return false; + } + + e->attr |= flag; + gpt.Sync(); + + return true; +} + +static bool is_devinfo_valid; +static bool is_devinfo_initialized; +static std::mutex devinfo_lock; +static devinfo_t devinfo; + +static bool isDevInfoValid() { + const std::lock_guard lock(devinfo_lock); + + if (is_devinfo_initialized) { + return is_devinfo_valid; + } + + is_devinfo_initialized = true; + + android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY)); + android::base::ReadFully(fd, &devinfo, sizeof devinfo); + + if (devinfo.magic != DEVINFO_MAGIC) { + return is_devinfo_valid; + } + + uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor; + // only version 3.3+ supports A/B data + if (version >= 0x0003'0003) { + is_devinfo_valid = true; + } + + return is_devinfo_valid; +} + +static bool DevInfoSync() { + if (!isDevInfoValid()) { + return false; + } + + android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY | O_DSYNC)); + return android::base::WriteFully(fd, &devinfo, sizeof devinfo); +} + +static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) { + slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT; + slot_data.unbootable = 0; + slot_data.successful = 0; + slot_data.active = 1; + slot_data.fastboot_ok = 0; +} + +static int blow_otp_AR(bool secure) { + static const char *dev_name = "/dev/trusty-ipc-dev0"; + static const char *otp_name = "com.android.trusty.otp_manager.tidl"; + int fd = 1, ret = 0; + uint32_t cmd = secure? OTP_CMD_write_antirbk_secure_ap : OTP_CMD_write_antirbk_non_secure_ap; + fd = tipc_connect(dev_name, otp_name); + if (fd < 0) { + ALOGI("Failed to connect to OTP_MGR ns TA - is it missing?\n"); + ret = -1; + return ret; + } + + struct otp_mgr_req_base req = { + .command = cmd, + .resp_payload_size = 0, + }; + struct iovec iov[] = { + { + .iov_base = &req, + .iov_len = sizeof(req), + }, + }; + + int rc = tipc_send(fd, iov, 1, NULL, 0); + if (rc != sizeof(req)) { + ALOGI("Send fail! %x\n", rc); + return rc; + } + + struct otp_mgr_rsp_base resp; + rc = read(fd, &resp, sizeof(resp)); + if (rc < 0) { + ALOGI("Read fail! %x\n", rc); + return rc; + } + + if (rc < sizeof(resp)) { + ALOGI("Not enough data! %x\n", rc); + return -EIO; + } + + if (resp.command != (cmd | OTP_RESP_BIT)) { + ALOGI("Wrong command! %x\n", resp.command); + return -EINVAL; + } + + if (resp.result != 0) { + fprintf(stderr, "AR writing error! %x\n", resp.result); + return -EINVAL; + } + + tipc_close(fd); + return 0; +} + +static bool blowAR() { + int ret = blow_otp_AR(true); + if (ret) { + ALOGI("Blow secure anti-rollback OTP failed"); + return false; + } + + ret = blow_otp_AR(false); + if (ret) { + ALOGI("Blow non-secure anti-rollback OTP failed"); + return false; + } + + return true; +} +} // namespace + +// Methods from ::android::hardware::boot::V1_0::IBootControl follow. +Return BootControl::getNumberSlots() { + uint32_t slots = 0; + + if (access(BOOT_A_PATH, F_OK) == 0) + slots++; + + if (access(BOOT_B_PATH, F_OK) == 0) + slots++; + + return slots; +} + +Return BootControl::getCurrentSlot() { + char suffix[PROPERTY_VALUE_MAX]; + property_get("ro.boot.slot_suffix", suffix, "_a"); + return std::string(suffix) == "_b" ? 1 : 0; +} + +Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { + if (getNumberSlots() == 0) { + // no slots, just return true otherwise Android keeps trying + _hidl_cb({true, ""}); + return Void(); + } + + bool ret; + if (isDevInfoValid()) { + auto const slot = getCurrentSlot(); + devinfo.ab_data.slots[slot].successful = 1; + ret = DevInfoSync(); + } else { + ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL); + } + + if (!ret) { + _hidl_cb({false, "Failed to set successful flag"}); + return Void(); + } + + if (!blowAR()) { + ALOGE("Failed to blow anti-rollback counter"); + // Ignore the error, since ABL will re-trigger it on reboot + } + + _hidl_cb({true, ""}); + return Void(); +} + +Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { + if (slot >= 2) { + _hidl_cb({false, "Invalid slot"}); + return Void(); + } + + if (isDevInfoValid()) { + auto &active_slot_data = devinfo.ab_data.slots[slot]; + auto &inactive_slot_data = devinfo.ab_data.slots[!slot]; + + inactive_slot_data.active = 0; + DevInfoInitSlot(active_slot_data); + + if (!DevInfoSync()) { + _hidl_cb({false, "Could not update DevInfo data"}); + return Void(); + } + } else { + std::string dev_path = getDevPath(slot); + if (dev_path.empty()) { + _hidl_cb({false, "Could not get device path for slot"}); + return Void(); + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + _hidl_cb({false, "failed to load gpt data"}); + return Void(); + } + + gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b"); + gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a"); + if (active_entry == nullptr || inactive_entry == nullptr) { + _hidl_cb({false, "failed to get entries for boot partitions"}); + return Void(); + } + + ALOGV("slot active attributes %lx\n", active_entry->attr); + ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); + + // update attributes for active and inactive + inactive_entry->attr &= ~AB_ATTR_ACTIVE; + active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | + (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); + } + + char boot_dev[PROPERTY_VALUE_MAX]; + property_get("ro.boot.bootdevice", boot_dev, ""); + if (boot_dev[0] == '\0') { + _hidl_cb({false, "invalid ro.boot.bootdevice prop"}); + return Void(); + } + + std::string boot_lun_path = + std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled"; + int fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); + if (fd < 0) { + // Try old path for kernels < 5.4 + // TODO: remove once kernel 4.19 support is deprecated + std::string boot_lun_path = + std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled"; + fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); + if (fd < 0) { + _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"}); + return Void(); + } + } + + // + // bBootLunEn + // 0x1 => Boot LU A = enabled, Boot LU B = disable + // 0x2 => Boot LU A = disable, Boot LU B = enabled + // + int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd); + close(fd); + if (ret < 0) { + _hidl_cb({false, "faied to write boot_lun_enabled attribute"}); + return Void(); + } + + _hidl_cb({true, ""}); + return Void(); +} + +Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { + if (slot >= 2) { + _hidl_cb({false, "Invalid slot"}); + return Void(); + } + + if (isDevInfoValid()) { + auto &slot_data = devinfo.ab_data.slots[slot]; + slot_data.unbootable = 1; + if (!DevInfoSync()) { + _hidl_cb({false, "Could not update DevInfo data"}); + return Void(); + } + } else { + std::string dev_path = getDevPath(slot); + if (dev_path.empty()) { + _hidl_cb({false, "Could not get device path for slot"}); + return Void(); + } + + GptUtils gpt(dev_path); + gpt.Load(); + + gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); + e->attr |= AB_ATTR_UNBOOTABLE; + + gpt.Sync(); + } + + _hidl_cb({true, ""}); + return Void(); +} + +Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) { + if (getNumberSlots() == 0) + return BoolResult::FALSE; + if (slot >= getNumberSlots()) + return BoolResult::INVALID_SLOT; + + bool unbootable; + if (isDevInfoValid()) { + auto &slot_data = devinfo.ab_data.slots[slot]; + unbootable = !!slot_data.unbootable; + } else { + unbootable = isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE); + } + + return unbootable ? BoolResult::FALSE : BoolResult::TRUE; +} + +Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful( + uint32_t slot) { + if (getNumberSlots() == 0) { + // just return true so that we don't we another call trying to mark it as successful + // when there is no slots + return BoolResult::TRUE; + } + if (slot >= getNumberSlots()) + return BoolResult::INVALID_SLOT; + + bool successful; + if (isDevInfoValid()) { + auto &slot_data = devinfo.ab_data.slots[slot]; + successful = !!slot_data.successful; + } else { + successful = isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL); + } + + return successful ? BoolResult::TRUE : BoolResult::FALSE; +} + +Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { + _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : ""); + return Void(); +} + +// Methods from ::android::hardware::boot::V1_1::IBootControl follow. +bool BootControl::Init() { + return InitMiscVirtualAbMessageIfNeeded(); +} + +Return BootControl::setSnapshotMergeStatus( + ::android::hardware::boot::V1_1::MergeStatus status) { + return SetMiscVirtualAbMergeStatus(getCurrentSlot(), status); +} + +Return<::android::hardware::boot::V1_1::MergeStatus> BootControl::getSnapshotMergeStatus() { + MergeStatus status; + if (!GetMiscVirtualAbMergeStatus(getCurrentSlot(), &status)) { + return MergeStatus::UNKNOWN; + } + return status; +} + +// Methods from ::android::hardware::boot::V1_2::IBootControl follow. +Return BootControl::getActiveBootSlot() { + if (getNumberSlots() == 0) + return 0; + + if (isDevInfoValid()) + return devinfo.ab_data.slots[1].active ? 1 : 0; + return isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0; +} + +// Methods from ::android::hidl::base::V1_0::IBase follow. + +IBootControl *HIDL_FETCH_IBootControl(const char * /* name */) { + auto module = new BootControl(); + + module->Init(); + + return module; +} + +} // namespace implementation +} // namespace V1_2 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.2/BootControl.h b/interfaces/boot/1.2/BootControl.h new file mode 100644 index 00000000..45b7efad --- /dev/null +++ b/interfaces/boot/1.2/BootControl.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace android { +namespace hardware { +namespace boot { +namespace V1_2 { +namespace implementation { + +using ::android::sp; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; + +struct BootControl : public IBootControl { + bool Init(); + + // Methods from ::android::hardware::boot::V1_0::IBootControl follow. + Return getNumberSlots() override; + Return getCurrentSlot() override; + Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; + Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; + Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; + Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override; + Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful( + uint32_t slot) override; + Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; + + // Methods from ::android::hardware::boot::V1_1::IBootControl follow. + Return setSnapshotMergeStatus( + ::android::hardware::boot::V1_1::MergeStatus status) override; + Return<::android::hardware::boot::V1_1::MergeStatus> getSnapshotMergeStatus() override; + + // Methods from ::android::hardware::boot::V1_2::IBootControl follow. + Return getActiveBootSlot() override; + + // Methods from ::android::hidl::base::V1_0::IBase follow. +}; + +// FIXME: most likely delete, this is only for passthrough implementations +extern "C" IBootControl *HIDL_FETCH_IBootControl(const char *name); + +enum otpmgr_command : uint32_t { + OTP_REQ_SHIFT = 1, + OTP_RESP_BIT = 1, + OTP_CMD_write_antirbk_non_secure_ap = (7 << OTP_REQ_SHIFT), + OTP_CMD_write_antirbk_secure_ap = (8 << OTP_REQ_SHIFT), +}; + +struct otp_mgr_req_base { + uint32_t command; + uint32_t resp_payload_size; + uint8_t handle; +}__packed; + +struct otp_mgr_rsp_base { + uint32_t command; + uint32_t resp_payload_size; + int result; +}__packed; + +} // namespace implementation +} // namespace V1_2 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.2/DevInfo.h b/interfaces/boot/1.2/DevInfo.h new file mode 100644 index 00000000..a09a83a2 --- /dev/null +++ b/interfaces/boot/1.2/DevInfo.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +namespace android { +namespace hardware { +namespace boot { +namespace V1_2 { +namespace implementation { + +// +// definitions taken from ABL code +// + +constexpr uint32_t DEVINFO_MAGIC = 0x49564544; +constexpr size_t DEVINFO_AB_SLOT_COUNT = 2; + +struct devinfo_ab_slot_data_t { + uint8_t retry_count; + uint8_t unbootable : 1; + uint8_t successful : 1; + uint8_t active : 1; + uint8_t fastboot_ok : 1; + uint8_t : 4; + uint8_t unused[2]; +} __attribute__((packed)); + +typedef struct { + devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT]; +} __attribute__((packed)) devinfo_ab_data_t; + +struct devinfo_t { + uint32_t magic; + uint16_t ver_major; + uint16_t ver_minor; + uint8_t unused[40]; + devinfo_ab_data_t ab_data; + uint8_t unused1[72]; // use remaining up to complete 128 bytes +} __attribute__((packed)); + +static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size"); + +} // namespace implementation +} // namespace V1_2 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.2/GptUtils.cpp b/interfaces/boot/1.2/GptUtils.cpp new file mode 100644 index 00000000..25088e79 --- /dev/null +++ b/interfaces/boot/1.2/GptUtils.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "bootcontrolhal" + +#include "GptUtils.h" + +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace boot { +namespace V1_2 { +namespace implementation { + +namespace { + +static int ValidateGptHeader(gpt_header *gpt) { + if (gpt->signature != GPT_SIGNATURE) { + ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); + return -1; + } + + if (gpt->header_size != sizeof(gpt_header)) { + ALOGE("invalid gpt header size %u\n", gpt->header_size); + return -1; + } + + if (gpt->entry_size != sizeof(gpt_entry)) { + ALOGE("invalid gpt entry size %u\n", gpt->entry_size); + return -1; + } + + return 0; +} + +} // namespace + +GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} + +int GptUtils::Load(void) { + fd = open(dev_path.c_str(), O_RDWR); + if (fd < 0) { + ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); + return -1; + } + + int ret = ioctl(fd, BLKSSZGET, &block_size); + if (ret < 0) { + ALOGE("failed to get block size %d\n", errno); + return -1; + } + + // read primary header + lseek64(fd, block_size, SEEK_SET); + ret = read(fd, &gpt_primary, sizeof gpt_primary); + if (ret < 0) { + ALOGE("failed to read gpt primary header %d\n", errno); + return -1; + } + + if (ValidateGptHeader(&gpt_primary)) { + ALOGE("error validating gpt header\n"); + return -1; + } + + // read partition entries + entry_array.resize(gpt_primary.entry_count); + uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; + lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); + ret = read(fd, entry_array.data(), entries_size); + if (ret < 0) { + ALOGE("failed to read gpt partition entries %d\n", errno); + return -1; + } + + // read gpt back header + lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); + ret = read(fd, &gpt_backup, sizeof gpt_backup); + if (ret < 0) { + ALOGE("failed to read gpt backup header %d\n", errno); + return -1; + } + + if (ValidateGptHeader(&gpt_backup)) { + ALOGW("error validating gpt backup\n"); // just warn about it, not fail + } + + // Create map + auto get_name = [](const uint16_t *efi_name) { + char name[37] = {}; + for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i]; + return std::string(name); + }; + + for (auto const &e : entry_array) { + if (e.name[0] == 0) + break; // stop at the first partition with no name + std::string s = get_name(e.name); + entries[s] = const_cast(&e); + } + + return 0; +} + +gpt_entry *GptUtils::GetPartitionEntry(std::string name) { + return entries.find(name) != entries.end() ? entries[name] : nullptr; +} + +int GptUtils::Sync(void) { + if (!fd) + return -1; + + // calculate crc and check if we need to update gpt + gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), + entry_array.size() * sizeof(gpt_entry)); + + // save old crc + uint32_t crc = gpt_primary.crc32; + gpt_primary.crc32 = 0; + + gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); + if (crc == gpt_primary.crc32) + return 0; // nothing to do (no changes) + + ALOGI("updating GPT\n"); + + lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); + int ret = write(fd, &gpt_primary, sizeof gpt_primary); + if (ret < 0) { + ALOGE("failed to write gpt primary header %d\n", errno); + return -1; + } + + lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); + ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); + if (ret < 0) { + ALOGE("failed to write gpt partition entries %d\n", errno); + return -1; + } + + // update GPT backup entries and backup + lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); + ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); + if (ret < 0) { + ALOGE("failed to write gpt backup partition entries %d\n", errno); + return -1; + } + + gpt_backup.entries_crc32 = gpt_primary.entries_crc32; + gpt_backup.crc32 = 0; + gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); + lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); + ret = write(fd, &gpt_backup, sizeof gpt_backup); + if (ret < 0) { + ALOGE("failed to write gpt backup header %d\n", errno); + return -1; + } + + fsync(fd); + + return 0; +} + +GptUtils::~GptUtils() { + if (fd) { + Sync(); + close(fd); + } +} + +} // namespace implementation +} // namespace V1_2 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.2/GptUtils.h b/interfaces/boot/1.2/GptUtils.h new file mode 100644 index 00000000..a2bed334 --- /dev/null +++ b/interfaces/boot/1.2/GptUtils.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace android { +namespace hardware { +namespace boot { +namespace V1_2 { +namespace implementation { + +#define GPT_SIGNATURE 0x5452415020494645UL + +typedef struct { + uint8_t type_guid[16]; + uint8_t guid[16]; + uint64_t first_lba; + uint64_t last_lba; + uint64_t attr; + uint16_t name[36]; +} __attribute__((packed)) gpt_entry; + +typedef struct { + uint64_t signature; + uint32_t revision; + uint32_t header_size; + uint32_t crc32; + uint32_t reserved; + uint64_t current_lba; + uint64_t backup_lba; + uint64_t first_usable_lba; + uint64_t last_usable_lba; + uint8_t disk_guid[16]; + uint64_t start_lba; + uint32_t entry_count; + uint32_t entry_size; + uint32_t entries_crc32; +} __attribute__((packed)) gpt_header; + +class GptUtils { + public: + GptUtils(const std::string dev_path); + int Load(void); + gpt_entry *GetPartitionEntry(std::string name); + int Sync(void); + ~GptUtils(); + + private: + std::string dev_path; + int fd; + uint32_t block_size; + gpt_header gpt_primary; + gpt_header gpt_backup; + std::vector entry_array; + std::map entries; +}; + +} // namespace implementation +} // namespace V1_2 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc b/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc new file mode 100644 index 00000000..4e5f5fe6 --- /dev/null +++ b/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc @@ -0,0 +1,7 @@ +service vendor.boot-hal-1-2 /vendor/bin/hw/android.hardware.boot@1.2-service-zuma + interface android.hardware.boot@1.0::IBootControl default + interface android.hardware.boot@1.1::IBootControl default + interface android.hardware.boot@1.2::IBootControl default + class early_hal + user root + group root drmrpc diff --git a/interfaces/boot/1.2/service.cpp b/interfaces/boot/1.2/service.cpp new file mode 100644 index 00000000..f07682e9 --- /dev/null +++ b/interfaces/boot/1.2/service.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.boot@1.2-service" + +#include +#include +#include +#include + +#include "BootControl.h" + +using ::android::status_t; + +using ::android::hardware::boot::V1_2::IBootControl; + +using ::android::hardware::boot::V1_2::implementation::BootControl; +// using ::android::hardware::boot::implementation::BootControl; + +int main(int /* argc */, char * /* argv */[]) { + // This function must be called before you join to ensure the proper + // number of threads are created. The threadpool will never exceed + // size one because of this call. + ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/); + + ::android::sp bootctrl = new BootControl(); + const status_t status = bootctrl->registerAsService(); + if (status != ::android::OK) { + return 1; // or handle error + } + + // Adds this thread to the threadpool, resulting in one total + // thread in the threadpool. We could also do other things, but + // would have to specify 'false' to willJoin in configureRpcThreadpool. + ::android::hardware::joinRpcThreadpool(); + return 1; // joinRpcThreadpool should never return +} diff --git a/interfaces/boot/aidl/Android.bp b/interfaces/boot/aidl/Android.bp new file mode 100644 index 00000000..37d2aebe --- /dev/null +++ b/interfaces/boot/aidl/Android.bp @@ -0,0 +1,65 @@ +// +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: [ + "//device/google/zuma:device_google_zuma_license", + ], +} + +cc_defaults { + name: "android.hardware.boot-service_common-zuma", + relative_install_path: "hw", + defaults: ["libboot_control_defaults"], + shared_libs: [ + "libbase", + "libbinder_ndk", + "libcutils", + "libz", + "libtrusty", + "android.hardware.boot@1.1", + "android.hardware.boot-V1-ndk", + ], + static_libs: [ + "libboot_control", + "libbootloader_message_vendor", + ], + srcs: [ + "BootControl.cpp", + "GptUtils.cpp", + "service.cpp" + ], +} + +cc_binary { + name: "android.hardware.boot-service.default-zuma", + defaults: ["android.hardware.boot-service_common-zuma"], + init_rc: ["android.hardware.boot-service.default-zuma.rc"], + vendor: true, +} + +cc_binary { + name: "android.hardware.boot-service.default_recovery-zuma", + defaults: ["android.hardware.boot-service_common-zuma"], + vintf_fragments: ["android.hardware.boot-service.default_recovery-zuma.xml"], + init_rc: ["android.hardware.boot-service.default_recovery-zuma.rc"], + recovery: true, +} \ No newline at end of file diff --git a/interfaces/boot/aidl/BootControl.cpp b/interfaces/boot/aidl/BootControl.cpp new file mode 100644 index 00000000..941b0d2b --- /dev/null +++ b/interfaces/boot/aidl/BootControl.cpp @@ -0,0 +1,538 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "bootcontrolhal" + +#include "BootControl.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DevInfo.h" +#include "GptUtils.h" + +using HIDLMergeStatus = ::android::bootable::BootControl::MergeStatus; +using ndk::ScopedAStatus; + +using android::bootable::GetMiscVirtualAbMergeStatus; +using android::bootable::InitMiscVirtualAbMessageIfNeeded; +using android::bootable::SetMiscVirtualAbMergeStatus; + +namespace aidl::android::hardware::boot { + +namespace { + +// clang-format off + +#define BOOT_A_PATH "/dev/block/by-name/boot_a" +#define BOOT_B_PATH "/dev/block/by-name/boot_b" +#define DEVINFO_PATH "/dev/block/by-name/devinfo" + +// slot flags +#define AB_ATTR_PRIORITY_SHIFT 52 +#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) +#define AB_ATTR_ACTIVE_SHIFT 54 +#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) +#define AB_ATTR_RETRY_COUNT_SHIFT (55) +#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) +#define AB_ATTR_SUCCESSFUL (1UL << 58) +#define AB_ATTR_UNBOOTABLE (1UL << 59) + +#define AB_ATTR_MAX_PRIORITY 3UL +#define AB_ATTR_MAX_RETRY_COUNT 3UL + +// clang-format on + +static std::string getDevPath(int32_t in_slot) { + char real_path[PATH_MAX]; + + const char *path = in_slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; + + int ret = readlink(path, real_path, sizeof real_path); + if (ret < 0) { + ALOGE("readlink failed for boot device %s\n", strerror(errno)); + return std::string(); + } + + std::string dp(real_path); + // extract /dev/sda.. part + return dp.substr(0, sizeof "/dev/block/sdX" - 1); +} + +static bool isSlotFlagSet(int32_t in_slot, uint64_t flag) { + std::string dev_path = getDevPath(in_slot); + if (dev_path.empty()) { + ALOGI("Could not get device path for slot %d\n", in_slot); + return false; + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + ALOGI("failed to load gpt data\n"); + return false; + } + + gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); + if (e == nullptr) { + ALOGI("failed to get gpt entry\n"); + return false; + } + + return !!(e->attr & flag); +} + +static bool setSlotFlag(int32_t in_slot, uint64_t flag) { + std::string dev_path = getDevPath(in_slot); + if (dev_path.empty()) { + ALOGI("Could not get device path for slot %d\n", in_slot); + return false; + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + ALOGI("failed to load gpt data\n"); + return false; + } + + gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); + if (e == nullptr) { + ALOGI("failed to get gpt entry\n"); + return false; + } + + e->attr |= flag; + gpt.Sync(); + + return true; +} + +static bool is_devinfo_valid; +static bool is_devinfo_initialized; +static std::mutex devinfo_lock; +static devinfo_t devinfo; + +static bool isDevInfoValid() { + const std::lock_guard lock(devinfo_lock); + + if (is_devinfo_initialized) { + return is_devinfo_valid; + } + + is_devinfo_initialized = true; + + ::android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY)); + ::android::base::ReadFully(fd, &devinfo, sizeof devinfo); + + if (devinfo.magic != DEVINFO_MAGIC) { + return is_devinfo_valid; + } + + uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor; + // only version 3.3+ supports A/B data + if (version >= 0x0003'0003) { + is_devinfo_valid = true; + } + + return is_devinfo_valid; +} + +static bool DevInfoSync() { + if (!isDevInfoValid()) { + return false; + } + + ::android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY | O_DSYNC)); + return ::android::base::WriteFully(fd, &devinfo, sizeof devinfo); +} + +static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) { + slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT; + slot_data.unbootable = 0; + slot_data.successful = 0; + slot_data.active = 1; + slot_data.fastboot_ok = 0; +} + +static int blow_otp_AR(bool secure) { + static const char *dev_name = "/dev/trusty-ipc-dev0"; + static const char *otp_name = "com.android.trusty.otp_manager.tidl"; + int fd = 1, ret = 0; + uint32_t cmd = secure? OTP_CMD_write_antirbk_secure_ap : OTP_CMD_write_antirbk_non_secure_ap; + fd = tipc_connect(dev_name, otp_name); + if (fd < 0) { + ALOGI("Failed to connect to OTP_MGR ns TA - is it missing?\n"); + ret = -1; + return ret; + } + + struct otp_mgr_req_base req = { + .command = cmd, + .resp_payload_size = 0, + }; + struct iovec iov[] = { + { + .iov_base = &req, + .iov_len = sizeof(req), + }, + }; + + size_t rc = tipc_send(fd, iov, 1, NULL, 0); + if (rc != sizeof(req)) { + ALOGI("Send fail! %zx\n", rc); + return rc; + } + + struct otp_mgr_rsp_base resp; + rc = read(fd, &resp, sizeof(resp)); + if (rc < 0) { + ALOGI("Read fail! %zx\n", rc); + return rc; + } + + if (rc < sizeof(resp)) { + ALOGI("Not enough data! %zx\n", rc); + return -EIO; + } + + if (resp.command != (cmd | OTP_RESP_BIT)) { + ALOGI("Wrong command! %x\n", resp.command); + return -EINVAL; + } + + if (resp.result != 0) { + fprintf(stderr, "AR writing error! %x\n", resp.result); + return -EINVAL; + } + + tipc_close(fd); + return 0; +} + +static bool blowAR() { + int ret = blow_otp_AR(true); + if (ret) { + ALOGI("Blow secure anti-rollback OTP failed"); + return false; + } + + ret = blow_otp_AR(false); + if (ret) { + ALOGI("Blow non-secure anti-rollback OTP failed"); + return false; + } + + return true; +} + +static constexpr MergeStatus ToAIDLMergeStatus(HIDLMergeStatus status) { + switch (status) { + case HIDLMergeStatus::NONE: + return MergeStatus::NONE; + case HIDLMergeStatus::UNKNOWN: + return MergeStatus::UNKNOWN; + case HIDLMergeStatus::SNAPSHOTTED: + return MergeStatus::SNAPSHOTTED; + case HIDLMergeStatus::MERGING: + return MergeStatus::MERGING; + case HIDLMergeStatus::CANCELLED: + return MergeStatus::CANCELLED; + } +} + +static constexpr HIDLMergeStatus ToHIDLMergeStatus(MergeStatus status) { + switch (status) { + case MergeStatus::NONE: + return HIDLMergeStatus::NONE; + case MergeStatus::UNKNOWN: + return HIDLMergeStatus::UNKNOWN; + case MergeStatus::SNAPSHOTTED: + return HIDLMergeStatus::SNAPSHOTTED; + case MergeStatus::MERGING: + return HIDLMergeStatus::MERGING; + case MergeStatus::CANCELLED: + return HIDLMergeStatus::CANCELLED; + } +} + +} // namespace + +BootControl::BootControl() { + CHECK(InitMiscVirtualAbMessageIfNeeded()); +} + +ScopedAStatus BootControl::getActiveBootSlot(int32_t* _aidl_return) { + int32_t slots = 0; + getNumberSlots(&slots); + if (slots == 0) { + *_aidl_return = 0; + return ScopedAStatus::ok(); + } + + if (isDevInfoValid()) { + *_aidl_return = devinfo.ab_data.slots[1].active ? 1 : 0; + return ScopedAStatus::ok(); + } + *_aidl_return = isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0; + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::getCurrentSlot(int32_t* _aidl_return) { + char suffix[PROPERTY_VALUE_MAX]; + property_get("ro.boot.slot_suffix", suffix, "_a"); + *_aidl_return = std::string(suffix) == "_b" ? 1 : 0; + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::getNumberSlots(int32_t* _aidl_return) { + int32_t slots = 0; + + if (access(BOOT_A_PATH, F_OK) == 0) + slots++; + + if (access(BOOT_B_PATH, F_OK) == 0) + slots++; + + *_aidl_return = slots; + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::getSnapshotMergeStatus(MergeStatus* _aidl_return) { + HIDLMergeStatus status; + int32_t current_slot = 0; + getCurrentSlot(¤t_slot); + if (!GetMiscVirtualAbMergeStatus(current_slot, &status)) { + *_aidl_return = MergeStatus::UNKNOWN; + return ScopedAStatus::ok(); + } + *_aidl_return = ToAIDLMergeStatus(status); + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::getSuffix(int32_t in_slot, std::string* _aidl_return) { + *_aidl_return = in_slot == 0 ? "_a" : in_slot == 1 ? "_b" : ""; + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::isSlotBootable(int32_t in_slot, bool* _aidl_return) { + int32_t slots = 0; + getNumberSlots(&slots); + if (slots == 0) { + *_aidl_return = false; + return ScopedAStatus::ok(); + } + if (in_slot >= slots) + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); + + bool unbootable; + if (isDevInfoValid()) { + auto &slot_data = devinfo.ab_data.slots[in_slot]; + unbootable = !!slot_data.unbootable; + } else { + unbootable = isSlotFlagSet(in_slot, AB_ATTR_UNBOOTABLE); + } + + *_aidl_return = unbootable ? false: true; + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::isSlotMarkedSuccessful(int32_t in_slot, bool* _aidl_return) { + int32_t slots = 0; + getNumberSlots(&slots); + if (slots == 0) { + // just return true so that we don't we another call trying to mark it as successful + // when there is no slots + *_aidl_return = true; + return ScopedAStatus::ok(); + } + if (in_slot >= slots) + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); + + bool successful; + if (isDevInfoValid()) { + auto &slot_data = devinfo.ab_data.slots[in_slot]; + successful = !!slot_data.successful; + } else { + successful = isSlotFlagSet(in_slot, AB_ATTR_SUCCESSFUL); + } + + *_aidl_return = successful ? true : false; + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::markBootSuccessful() { + int32_t slots = 0; + getNumberSlots(&slots); + if (slots == 0) { + // no slots, just return true otherwise Android keeps trying + return ScopedAStatus::ok(); + } + + bool ret; + int32_t current_slot = 0; + getCurrentSlot(¤t_slot); + if (isDevInfoValid()) { + auto const slot = current_slot; + devinfo.ab_data.slots[slot].successful = 1; + ret = DevInfoSync(); + } else { + ret = setSlotFlag(current_slot, AB_ATTR_SUCCESSFUL); + } + + if (!ret) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, + "Failed to set successful flag"); + } + + if (!blowAR()) { + ALOGE("Failed to blow anti-rollback counter"); + // Ignore the error, since ABL will re-trigger it on reboot + } + + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::setActiveBootSlot(int32_t in_slot) { + if (in_slot >= 2) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); + } + + if (isDevInfoValid()) { + auto &active_slot_data = devinfo.ab_data.slots[in_slot]; + auto &inactive_slot_data = devinfo.ab_data.slots[!in_slot]; + + inactive_slot_data.active = 0; + DevInfoInitSlot(active_slot_data); + + if (!DevInfoSync()) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + COMMAND_FAILED, "Could not update DevInfo data"); + } + } else { + std::string dev_path = getDevPath(in_slot); + if (dev_path.empty()) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + COMMAND_FAILED, "Could not get device path for slot"); + } + + GptUtils gpt(dev_path); + if (gpt.Load()) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, + "failed to load gpt data"); + } + + gpt_entry *active_entry = gpt.GetPartitionEntry(in_slot == 0 ? "boot_a" : "boot_b"); + gpt_entry *inactive_entry = gpt.GetPartitionEntry(in_slot == 0 ? "boot_b" : "boot_a"); + if (active_entry == nullptr || inactive_entry == nullptr) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + COMMAND_FAILED, "failed to get entries for boot partitions"); + } + + ALOGV("slot active attributes %lx\n", active_entry->attr); + ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); + + // update attributes for active and inactive + inactive_entry->attr &= ~AB_ATTR_ACTIVE; + active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | + (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); + } + + char boot_dev[PROPERTY_VALUE_MAX]; + property_get("ro.boot.bootdevice", boot_dev, ""); + if (boot_dev[0] == '\0') { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + COMMAND_FAILED, "invalid ro.boot.bootdevice prop"); + } + + std::string boot_lun_path = + std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled"; + int fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); + if (fd < 0) { + // Try old path for kernels < 5.4 + // TODO: remove once kernel 4.19 support is deprecated + std::string boot_lun_path = + std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled"; + fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); + if (fd < 0) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + COMMAND_FAILED, "failed to open ufs attr boot_lun_enabled"); + } + } + + // + // bBootLunEn + // 0x1 => Boot LU A = enabled, Boot LU B = disable + // 0x2 => Boot LU A = disable, Boot LU B = enabled + // + int ret = ::android::base::WriteStringToFd(in_slot == 0 ? "1" : "2", fd); + close(fd); + if (ret < 0) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + COMMAND_FAILED, "faied to write boot_lun_enabled attribute"); + } + + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::setSlotAsUnbootable(int32_t in_slot) { + if (in_slot >= 2) + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); + + if (isDevInfoValid()) { + auto &slot_data = devinfo.ab_data.slots[in_slot]; + slot_data.unbootable = 1; + if (!DevInfoSync()) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + COMMAND_FAILED, "Could not update DevInfo data"); + } + } else { + std::string dev_path = getDevPath(in_slot); + if (dev_path.empty()) { + return ScopedAStatus::fromServiceSpecificErrorWithMessage( + COMMAND_FAILED, "Could not get device path for slot"); + } + + GptUtils gpt(dev_path); + gpt.Load(); + + gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); + e->attr |= AB_ATTR_UNBOOTABLE; + + gpt.Sync(); + } + + return ScopedAStatus::ok(); +} + +ScopedAStatus BootControl::setSnapshotMergeStatus(MergeStatus in_status) { + int32_t current_slot = 0; + getCurrentSlot(¤t_slot); + if (!SetMiscVirtualAbMergeStatus(current_slot, ToHIDLMergeStatus(in_status))) + return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, + "Operation failed"); + return ScopedAStatus::ok(); +} + +} // namespace aidl::android::hardware::boot diff --git a/interfaces/boot/aidl/BootControl.h b/interfaces/boot/aidl/BootControl.h new file mode 100644 index 00000000..a54f66d0 --- /dev/null +++ b/interfaces/boot/aidl/BootControl.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +namespace aidl::android::hardware::boot { + +class BootControl final : public BnBootControl { + public: + BootControl(); + ::ndk::ScopedAStatus getActiveBootSlot(int32_t* _aidl_return) override; + ::ndk::ScopedAStatus getCurrentSlot(int32_t* _aidl_return) override; + ::ndk::ScopedAStatus getNumberSlots(int32_t* _aidl_return) override; + ::ndk::ScopedAStatus getSnapshotMergeStatus( + ::aidl::android::hardware::boot::MergeStatus* _aidl_return) override; + ::ndk::ScopedAStatus getSuffix(int32_t in_slot, std::string* _aidl_return) override; + ::ndk::ScopedAStatus isSlotBootable(int32_t in_slot, bool* _aidl_return) override; + ::ndk::ScopedAStatus isSlotMarkedSuccessful(int32_t in_slot, bool* _aidl_return) override; + ::ndk::ScopedAStatus markBootSuccessful() override; + ::ndk::ScopedAStatus setActiveBootSlot(int32_t in_slot) override; + ::ndk::ScopedAStatus setSlotAsUnbootable(int32_t in_slot) override; + ::ndk::ScopedAStatus setSnapshotMergeStatus( + ::aidl::android::hardware::boot::MergeStatus in_status) override; +}; + +enum otpmgr_command : uint32_t { + OTP_REQ_SHIFT = 1, + OTP_RESP_BIT = 1, + OTP_CMD_write_antirbk_non_secure_ap = (7 << OTP_REQ_SHIFT), + OTP_CMD_write_antirbk_secure_ap = (8 << OTP_REQ_SHIFT), +}; + +struct otp_mgr_req_base { + uint32_t command; + uint32_t resp_payload_size; + uint8_t handle; +}__packed; + +struct otp_mgr_rsp_base { + uint32_t command; + uint32_t resp_payload_size; + int result; +}__packed; + +} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/DevInfo.h b/interfaces/boot/aidl/DevInfo.h new file mode 100644 index 00000000..aa5f5d37 --- /dev/null +++ b/interfaces/boot/aidl/DevInfo.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +namespace aidl::android::hardware::boot { + +// +// definitions taken from ABL code +// + +constexpr uint32_t DEVINFO_MAGIC = 0x49564544; +constexpr size_t DEVINFO_AB_SLOT_COUNT = 2; + +struct devinfo_ab_slot_data_t { + uint8_t retry_count; + uint8_t unbootable : 1; + uint8_t successful : 1; + uint8_t active : 1; + uint8_t fastboot_ok : 1; + uint8_t : 4; + uint8_t unused[2]; +} __attribute__((packed)); + +typedef struct { + devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT]; +} __attribute__((packed)) devinfo_ab_data_t; + +struct devinfo_t { + uint32_t magic; + uint16_t ver_major; + uint16_t ver_minor; + uint8_t unused[40]; + devinfo_ab_data_t ab_data; + uint8_t unused1[72]; // use remaining up to complete 128 bytes +} __attribute__((packed)); + +static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size"); + +} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/GptUtils.cpp b/interfaces/boot/aidl/GptUtils.cpp new file mode 100644 index 00000000..34dec113 --- /dev/null +++ b/interfaces/boot/aidl/GptUtils.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "bootcontrolhal" + +#include "GptUtils.h" + +#include +#include +#include +#include +#include + +namespace aidl::android::hardware::boot { + +namespace { + +static int ValidateGptHeader(gpt_header *gpt) { + if (gpt->signature != GPT_SIGNATURE) { + ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); + return -1; + } + + if (gpt->header_size != sizeof(gpt_header)) { + ALOGE("invalid gpt header size %u\n", gpt->header_size); + return -1; + } + + if (gpt->entry_size != sizeof(gpt_entry)) { + ALOGE("invalid gpt entry size %u\n", gpt->entry_size); + return -1; + } + + return 0; +} + +} // namespace + +GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} + +int GptUtils::Load(void) { + fd = open(dev_path.c_str(), O_RDWR); + if (fd < 0) { + ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); + return -1; + } + + int ret = ioctl(fd, BLKSSZGET, &block_size); + if (ret < 0) { + ALOGE("failed to get block size %d\n", errno); + return -1; + } + + // read primary header + lseek64(fd, block_size, SEEK_SET); + ret = read(fd, &gpt_primary, sizeof gpt_primary); + if (ret < 0) { + ALOGE("failed to read gpt primary header %d\n", errno); + return -1; + } + + if (ValidateGptHeader(&gpt_primary)) { + ALOGE("error validating gpt header\n"); + return -1; + } + + // read partition entries + entry_array.resize(gpt_primary.entry_count); + uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; + lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); + ret = read(fd, entry_array.data(), entries_size); + if (ret < 0) { + ALOGE("failed to read gpt partition entries %d\n", errno); + return -1; + } + + // read gpt back header + lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); + ret = read(fd, &gpt_backup, sizeof gpt_backup); + if (ret < 0) { + ALOGE("failed to read gpt backup header %d\n", errno); + return -1; + } + + if (ValidateGptHeader(&gpt_backup)) { + ALOGW("error validating gpt backup\n"); // just warn about it, not fail + } + + // Create map + auto get_name = [](const uint16_t *efi_name) { + char name[37] = {}; + for (size_t i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i]; + return std::string(name); + }; + + for (auto const &e : entry_array) { + if (e.name[0] == 0) + break; // stop at the first partition with no name + std::string s = get_name(e.name); + entries[s] = const_cast(&e); + } + + return 0; +} + +gpt_entry *GptUtils::GetPartitionEntry(std::string name) { + return entries.find(name) != entries.end() ? entries[name] : nullptr; +} + +int GptUtils::Sync(void) { + if (!fd) + return -1; + + // calculate crc and check if we need to update gpt + gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), + entry_array.size() * sizeof(gpt_entry)); + + // save old crc + uint32_t crc = gpt_primary.crc32; + gpt_primary.crc32 = 0; + + gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); + if (crc == gpt_primary.crc32) + return 0; // nothing to do (no changes) + + ALOGI("updating GPT\n"); + + lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); + int ret = write(fd, &gpt_primary, sizeof gpt_primary); + if (ret < 0) { + ALOGE("failed to write gpt primary header %d\n", errno); + return -1; + } + + lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); + ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); + if (ret < 0) { + ALOGE("failed to write gpt partition entries %d\n", errno); + return -1; + } + + // update GPT backup entries and backup + lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); + ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); + if (ret < 0) { + ALOGE("failed to write gpt backup partition entries %d\n", errno); + return -1; + } + + gpt_backup.entries_crc32 = gpt_primary.entries_crc32; + gpt_backup.crc32 = 0; + gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); + lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); + ret = write(fd, &gpt_backup, sizeof gpt_backup); + if (ret < 0) { + ALOGE("failed to write gpt backup header %d\n", errno); + return -1; + } + + fsync(fd); + + return 0; +} + +GptUtils::~GptUtils() { + if (fd) { + Sync(); + close(fd); + } +} + +} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/GptUtils.h b/interfaces/boot/aidl/GptUtils.h new file mode 100644 index 00000000..ec68cf6f --- /dev/null +++ b/interfaces/boot/aidl/GptUtils.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace aidl::android::hardware::boot { + +#define GPT_SIGNATURE 0x5452415020494645UL + +typedef struct { + uint8_t type_guid[16]; + uint8_t guid[16]; + uint64_t first_lba; + uint64_t last_lba; + uint64_t attr; + uint16_t name[36]; +} __attribute__((packed)) gpt_entry; + +typedef struct { + uint64_t signature; + uint32_t revision; + uint32_t header_size; + uint32_t crc32; + uint32_t reserved; + uint64_t current_lba; + uint64_t backup_lba; + uint64_t first_usable_lba; + uint64_t last_usable_lba; + uint8_t disk_guid[16]; + uint64_t start_lba; + uint32_t entry_count; + uint32_t entry_size; + uint32_t entries_crc32; +} __attribute__((packed)) gpt_header; + +class GptUtils { + public: + GptUtils(const std::string dev_path); + int Load(void); + gpt_entry *GetPartitionEntry(std::string name); + int Sync(void); + ~GptUtils(); + + private: + std::string dev_path; + int fd; + uint32_t block_size; + gpt_header gpt_primary; + gpt_header gpt_backup; + std::vector entry_array; + std::map entries; +}; + +} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc b/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc new file mode 100644 index 00000000..f7dccadb --- /dev/null +++ b/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc @@ -0,0 +1,5 @@ +service vendor.boot-default /vendor/bin/hw/android.hardware.boot-service.default-zuma + class early_hal + user root + group root drmrpc + diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc b/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc new file mode 100644 index 00000000..d867a5f5 --- /dev/null +++ b/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc @@ -0,0 +1,7 @@ +service vendor.boot-default /system/bin/hw/android.hardware.boot-service.default_recovery-zuma + class early_hal + user root + group root + seclabel u:r:hal_bootctl_default:s0 + interface aidl android.hardware.boot.IBootControl/default + diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml b/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml new file mode 100644 index 00000000..23ccc4e3 --- /dev/null +++ b/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml @@ -0,0 +1,6 @@ + + + android.hardware.boot + IBootControl/default + + diff --git a/interfaces/boot/aidl/service.cpp b/interfaces/boot/aidl/service.cpp new file mode 100644 index 00000000..41b6c256 --- /dev/null +++ b/interfaces/boot/aidl/service.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "aidl.android.hardware.boot-service.default" + +#include +#include +#include +#include +#include + +#include "BootControl.h" + +using aidl::android::hardware::boot::BootControl; +using aidl::android::hardware::boot::IBootControl; +using ::android::hardware::configureRpcThreadpool; +using ::android::hardware::joinRpcThreadpool; + +int main(int, char* argv[]) { + android::base::InitLogging(argv, android::base::KernelLogger); + ABinderProcess_setThreadPoolMaxThreadCount(0); + std::shared_ptr service = ndk::SharedRefBase::make(); + + const std::string instance = std::string(BootControl::descriptor) + "/default"; + auto status = AServiceManager_addService(service->asBinder().get(), instance.c_str()); + CHECK_EQ(status, STATUS_OK) << "Failed to add service " << instance << " " << status; + LOG(INFO) << "IBootControl AIDL service running..."; + + ABinderProcess_joinThreadPool(); + return EXIT_FAILURE; // should not reach +} From fb463a38fdfa6db8826e2d5b8a51dd0223de6d52 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 9 Nov 2023 21:03:09 +0800 Subject: [PATCH 122/133] zuma: move bootctrl hal to gs-common Bug: 265063384 Change-Id: I25924866d2bad4dbe7c14484caa29bf527f85451 Signed-off-by: Jason Chiu --- interfaces/boot/1.0/Android.bp | 66 --- interfaces/boot/1.0/BootControl.cpp | 272 --------- interfaces/boot/1.0/BootControl.h | 59 -- interfaces/boot/1.0/GptUtils.cpp | 199 ------- interfaces/boot/1.0/GptUtils.h | 79 --- .../android.hardware.boot@1.0-service-zuma.rc | 4 - interfaces/boot/1.0/service.cpp | 47 -- interfaces/boot/1.2/Android.bp | 83 --- interfaces/boot/1.2/BootControl.cpp | 501 ---------------- interfaces/boot/1.2/BootControl.h | 88 --- interfaces/boot/1.2/DevInfo.h | 61 -- interfaces/boot/1.2/GptUtils.cpp | 193 ------- interfaces/boot/1.2/GptUtils.h | 79 --- .../android.hardware.boot@1.2-service-zuma.rc | 7 - interfaces/boot/1.2/service.cpp | 50 -- interfaces/boot/aidl/Android.bp | 65 --- interfaces/boot/aidl/BootControl.cpp | 538 ------------------ interfaces/boot/aidl/BootControl.h | 61 -- interfaces/boot/aidl/DevInfo.h | 53 -- interfaces/boot/aidl/GptUtils.cpp | 185 ------ interfaces/boot/aidl/GptUtils.h | 71 --- ...roid.hardware.boot-service.default-zuma.rc | 5 - ...ware.boot-service.default_recovery-zuma.rc | 7 - ...are.boot-service.default_recovery-zuma.xml | 6 - interfaces/boot/aidl/service.cpp | 44 -- 25 files changed, 2823 deletions(-) delete mode 100644 interfaces/boot/1.0/Android.bp delete mode 100644 interfaces/boot/1.0/BootControl.cpp delete mode 100644 interfaces/boot/1.0/BootControl.h delete mode 100644 interfaces/boot/1.0/GptUtils.cpp delete mode 100644 interfaces/boot/1.0/GptUtils.h delete mode 100644 interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc delete mode 100644 interfaces/boot/1.0/service.cpp delete mode 100644 interfaces/boot/1.2/Android.bp delete mode 100644 interfaces/boot/1.2/BootControl.cpp delete mode 100644 interfaces/boot/1.2/BootControl.h delete mode 100644 interfaces/boot/1.2/DevInfo.h delete mode 100644 interfaces/boot/1.2/GptUtils.cpp delete mode 100644 interfaces/boot/1.2/GptUtils.h delete mode 100644 interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc delete mode 100644 interfaces/boot/1.2/service.cpp delete mode 100644 interfaces/boot/aidl/Android.bp delete mode 100644 interfaces/boot/aidl/BootControl.cpp delete mode 100644 interfaces/boot/aidl/BootControl.h delete mode 100644 interfaces/boot/aidl/DevInfo.h delete mode 100644 interfaces/boot/aidl/GptUtils.cpp delete mode 100644 interfaces/boot/aidl/GptUtils.h delete mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc delete mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc delete mode 100644 interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml delete mode 100644 interfaces/boot/aidl/service.cpp diff --git a/interfaces/boot/1.0/Android.bp b/interfaces/boot/1.0/Android.bp deleted file mode 100644 index 5599fafb..00000000 --- a/interfaces/boot/1.0/Android.bp +++ /dev/null @@ -1,66 +0,0 @@ -// -// Copyright (C) 2019 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/zuma:device_google_zuma_license", - ], -} - -cc_binary { - name: "android.hardware.boot@1.0-service-zuma", - defaults: ["hidl_defaults"], - relative_install_path: "hw", - vendor: true, - init_rc: ["android.hardware.boot@1.0-service-zuma.rc"], - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - "service.cpp" - ], - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "android.hardware.boot@1.0", - ], -} - -cc_library { - name: "android.hardware.boot@1.0-impl-zuma", - recovery: true, - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - ], - relative_install_path: "hw", - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "android.hardware.boot@1.0", - ], -} diff --git a/interfaces/boot/1.0/BootControl.cpp b/interfaces/boot/1.0/BootControl.cpp deleted file mode 100644 index 1f155c9d..00000000 --- a/interfaces/boot/1.0/BootControl.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "BootControl.h" -#include "GptUtils.h" - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -namespace { - -#define BOOT_A_PATH "/dev/block/by-name/boot_a" -#define BOOT_B_PATH "/dev/block/by-name/boot_b" - -// slot flags -#define AB_ATTR_PRIORITY_SHIFT 52 -#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) -#define AB_ATTR_ACTIVE_SHIFT 54 -#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) -#define AB_ATTR_RETRY_COUNT_SHIFT (55) -#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) -#define AB_ATTR_SUCCESSFUL (1UL << 58) -#define AB_ATTR_UNBOOTABLE (1UL << 59) - -#define AB_ATTR_MAX_PRIORITY 3UL -#define AB_ATTR_MAX_RETRY_COUNT 3UL - -static std::string getDevPath(uint32_t slot) { - char real_path[PATH_MAX]; - - const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; - - int ret = readlink(path, real_path, sizeof real_path); - if (ret < 0) { - ALOGE("readlink failed for boot device %s\n", strerror(errno)); - return std::string(); - } - - std::string dp(real_path); - // extract /dev/sda.. part - return dp.substr(0, sizeof "/dev/block/sdX" - 1); -} - -static bool isSlotFlagSet(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - return !!(e->attr & flag); -} - -static int setSlotFlag(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return -1; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return -1; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return -1; - } - - e->attr |= flag; - gpt.Sync(); - - return 0; -} - -} - -// Methods from ::android::hardware::boot::V1_0::IBootControl follow. -Return BootControl::getNumberSlots() { - uint32_t slots = 0; - - if (access(BOOT_A_PATH, F_OK) == 0) - slots++; - - if (access(BOOT_B_PATH, F_OK) == 0) - slots++; - - return slots; -} - -Return BootControl::getCurrentSlot() { - char suffix[PROPERTY_VALUE_MAX]; - property_get("ro.boot.slot_suffix", suffix, "_a"); - return std::string(suffix) == "_b" ? 1 : 0; -} - -Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { - if (getNumberSlots() == 0) { - // no slots, just return true otherwise Android keeps trying - _hidl_cb({true, ""}); - return Void(); - } - int ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL); - ret ? _hidl_cb({false, "Failed to set successfull flag"}) : _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - _hidl_cb({false, "failed to load gpt data"}); - return Void(); - } - - gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b"); - gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a"); - if (active_entry == nullptr || inactive_entry == nullptr) { - _hidl_cb({false, "failed to get entries for boot partitions"}); - return Void(); - } - - ALOGV("slot active attributes %lx\n", active_entry->attr); - ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); - - char boot_dev[PROPERTY_VALUE_MAX]; - property_get("ro.boot.bootdevice", boot_dev, ""); - if (boot_dev[0] == '\0') { - _hidl_cb({false, "invalid ro.boot.bootdevice prop"}); - return Void(); - } - - std::string boot_lun_path = std::string("/sys/devices/platform/") + - boot_dev + "/pixel/boot_lun_enabled"; - int fd = open(boot_lun_path.c_str(), O_RDWR); - if (fd < 0) { - // Try old path for kernels < 5.4 - // TODO: remove once kernel 4.19 support is deprecated - std::string boot_lun_path = std::string("/sys/devices/platform/") + - boot_dev + "/attributes/boot_lun_enabled"; - fd = open(boot_lun_path.c_str(), O_RDWR); - if (fd < 0) { - _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"}); - return Void(); - } - } - - // update attributes for active and inactive - inactive_entry->attr &= ~AB_ATTR_ACTIVE; - active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | - (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); - - // - // bBootLunEn - // 0x1 => Boot LU A = enabled, Boot LU B = disable - // 0x2 => Boot LU A = disable, Boot LU B = enabled - // - int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd); - close(fd); - if (ret < 0) { - _hidl_cb({false, "faied to write boot_lun_enabled attribute"}); - return Void(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - gpt.Load(); - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - e->attr |= AB_ATTR_UNBOOTABLE; - - gpt.Sync(); - - _hidl_cb({true, ""}); - return Void(); -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) { - if (getNumberSlots() == 0) - return BoolResult::FALSE; - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - return isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE) ? BoolResult::FALSE : BoolResult::TRUE; -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) { - if (getNumberSlots() == 0) { - // just return true so that we don't we another call trying to mark it as successful - // when there is no slots - return BoolResult::TRUE; - } - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - return isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL) ? BoolResult::TRUE : BoolResult::FALSE; -} - -Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { - _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : ""); - return Void(); -} - -extern "C" IBootControl* HIDL_FETCH_IBootControl(const char*) { - return new BootControl(); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/BootControl.h b/interfaces/boot/1.0/BootControl.h deleted file mode 100644 index eb81cb07..00000000 --- a/interfaces/boot/1.0/BootControl.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::sp; - -struct BootControl : public IBootControl { - // Methods from ::android::hardware::boot::V1_0::IBootControl follow. - Return getNumberSlots() override; - Return getCurrentSlot() override; - Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; - Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; - Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(uint32_t slot) override; - Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; - - // Methods from ::android::hidl::base::V1_0::IBase follow. - -}; - -// FIXME: most likely delete, this is only for passthrough implementations -extern "C" IBootControl* HIDL_FETCH_IBootControl(const char* name); - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/GptUtils.cpp b/interfaces/boot/1.0/GptUtils.cpp deleted file mode 100644 index f8936175..00000000 --- a/interfaces/boot/1.0/GptUtils.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "GptUtils.h" - -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -namespace { - -static int ValidateGptHeader(gpt_header *gpt) -{ - if (gpt->signature != GPT_SIGNATURE) { - ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); - return -1; - } - - if (gpt->header_size != sizeof(gpt_header)) { - ALOGE("invalid gpt header size %u\n", gpt->header_size); - return -1; - } - - if (gpt->entry_size != sizeof(gpt_entry)) { - ALOGE("invalid gpt entry size %u\n", gpt->entry_size); - return -1; - } - - return 0; -} - -} - -GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} - -int GptUtils::Load(void) -{ - fd = open(dev_path.c_str(), O_RDWR); - if (fd < 0) { - ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); - return -1; - } - - int ret = ioctl(fd, BLKSSZGET, &block_size); - if (ret < 0) { - ALOGE("failed to get block size %d\n", errno); - return -1; - } - - // read primary header - lseek64(fd, block_size, SEEK_SET); - ret = read(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to read gpt primary header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_primary)) { - ALOGE("error validating gpt header\n"); - return -1; - } - - // read partition entries - entry_array.resize(gpt_primary.entry_count); - uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = read(fd, entry_array.data(), entries_size); - if (ret < 0) { - ALOGE("failed to read gpt partition entries %d\n", errno); - return -1; - } - - // read gpt back header - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = read(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to read gpt backup header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_backup)) { - ALOGW("error validating gpt backup\n"); // just warn about it, not fail - } - - // Create map - auto get_name = [](const uint16_t *efi_name) { - char name[37] = {}; - for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) - name[i] = efi_name[i]; - return std::string(name); - }; - - for (auto const &e: entry_array) { - if (e.name[0] == 0) - break; // stop at the first partition with no name - std::string s = get_name(e.name); - entries[s] = const_cast(&e); - } - - return 0; -} - -gpt_entry *GptUtils::GetPartitionEntry(std::string name) -{ - return entries.find(name) != entries.end() ? entries[name] : nullptr; -} - -int GptUtils::Sync(void) -{ - if (!fd) - return -1; - - // calculate crc and check if we need to update gpt - gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), - entry_array.size() * sizeof(gpt_entry)); - - // save old crc - uint32_t crc = gpt_primary.crc32; - gpt_primary.crc32 = 0; - - gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); - if (crc == gpt_primary.crc32) - return 0; // nothing to do (no changes) - - ALOGI("updating GPT\n"); - - lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); - int ret = write(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to write gpt primary header %d\n", errno); - return -1; - } - - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt partition entries %d\n", errno); - return -1; - } - - //update GPT backup entries and backup - lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt backup partition entries %d\n", errno); - return -1; - } - - gpt_backup.entries_crc32 = gpt_primary.entries_crc32; - gpt_backup.crc32 = 0; - gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = write(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to write gpt backup header %d\n", errno); - return -1; - } - - fsync(fd); - - return 0; -} - -GptUtils::~GptUtils() -{ - if (fd) { - Sync(); - close(fd); - } -} - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/GptUtils.h b/interfaces/boot/1.0/GptUtils.h deleted file mode 100644 index d969d9d8..00000000 --- a/interfaces/boot/1.0/GptUtils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -#define GPT_SIGNATURE 0x5452415020494645UL - -typedef struct { - uint8_t type_guid[16]; - uint8_t guid[16]; - uint64_t first_lba; - uint64_t last_lba; - uint64_t attr; - uint16_t name[36]; -} __attribute__((packed)) gpt_entry; - -typedef struct { - uint64_t signature; - uint32_t revision; - uint32_t header_size; - uint32_t crc32; - uint32_t reserved; - uint64_t current_lba; - uint64_t backup_lba; - uint64_t first_usable_lba; - uint64_t last_usable_lba; - uint8_t disk_guid[16]; - uint64_t start_lba; - uint32_t entry_count; - uint32_t entry_size; - uint32_t entries_crc32; -} __attribute__((packed)) gpt_header; - -class GptUtils { - public: - GptUtils(const std::string dev_path); - int Load(void); - gpt_entry *GetPartitionEntry(std::string name); - int Sync(void); - ~GptUtils(); - - private: - std::string dev_path; - int fd; - uint32_t block_size; - gpt_header gpt_primary; - gpt_header gpt_backup; - std::vector entry_array; - std::mapentries; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc b/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc deleted file mode 100644 index 7997fded..00000000 --- a/interfaces/boot/1.0/android.hardware.boot@1.0-service-zuma.rc +++ /dev/null @@ -1,4 +0,0 @@ -service vendor.boot-hal-1-0 /vendor/bin/hw/android.hardware.boot@1.0-service-zuma - class early_hal - user root - group root diff --git a/interfaces/boot/1.0/service.cpp b/interfaces/boot/1.0/service.cpp deleted file mode 100644 index 9dcd78cc..00000000 --- a/interfaces/boot/1.0/service.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define LOG_TAG "android.hardware.boot@1.0-service" - -#include -#include -#include -#include -#include "BootControl.h" - -using ::android::status_t; - -using ::android::hardware::boot::V1_0::IBootControl; - -using ::android::hardware::boot::V1_0::implementation::BootControl; - -int main (int /* argc */, char * /* argv */ []) { - // This function must be called before you join to ensure the proper - // number of threads are created. The threadpool will never exceed - // size one because of this call. - ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/); - - ::android::sp bootctrl = new BootControl(); - const status_t status = bootctrl->registerAsService(); - if (status != ::android::OK) { - return 1; // or handle error - } - - // Adds this thread to the threadpool, resulting in one total - // thread in the threadpool. We could also do other things, but - // would have to specify 'false' to willJoin in configureRpcThreadpool. - ::android::hardware::joinRpcThreadpool(); - return 1; // joinRpcThreadpool should never return -} diff --git a/interfaces/boot/1.2/Android.bp b/interfaces/boot/1.2/Android.bp deleted file mode 100644 index 90b0c6ed..00000000 --- a/interfaces/boot/1.2/Android.bp +++ /dev/null @@ -1,83 +0,0 @@ -// -// Copyright (C) 2020 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/zuma:device_google_zuma_license", - ], -} - -cc_binary { - name: "android.hardware.boot@1.2-service-zuma", - defaults: ["hidl_defaults"], - relative_install_path: "hw", - vendor: true, - init_rc: ["android.hardware.boot@1.2-service-zuma.rc"], - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - "service.cpp" - ], - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "libtrusty", - "android.hardware.boot@1.0", - "android.hardware.boot@1.1", - "android.hardware.boot@1.2", - ], - static_libs: [ - "libboot_control", - "libbootloader_message_vendor", - "libfstab", - ], -} - -cc_library { - name: "android.hardware.boot@1.2-impl-zuma", - stem: "android.hardware.boot@1.0-impl-1.2-impl-zuma", - recovery: true, - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - ], - relative_install_path: "hw", - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "libtrusty", - "android.hardware.boot@1.0", - "android.hardware.boot@1.1", - "android.hardware.boot@1.2", - ], - static_libs: [ - "libboot_control", - "libbootloader_message_vendor", - "libfstab", - ], -} diff --git a/interfaces/boot/1.2/BootControl.cpp b/interfaces/boot/1.2/BootControl.cpp deleted file mode 100644 index 77820754..00000000 --- a/interfaces/boot/1.2/BootControl.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "BootControl.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "DevInfo.h" -#include "GptUtils.h" - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -using android::bootable::GetMiscVirtualAbMergeStatus; -using android::bootable::InitMiscVirtualAbMessageIfNeeded; -using android::bootable::SetMiscVirtualAbMergeStatus; -using android::hardware::boot::V1_0::BoolResult; -using android::hardware::boot::V1_0::CommandResult; -using android::hardware::boot::V1_1::MergeStatus; - -namespace { - -// clang-format off - -#define BOOT_A_PATH "/dev/block/by-name/boot_a" -#define BOOT_B_PATH "/dev/block/by-name/boot_b" -#define DEVINFO_PATH "/dev/block/by-name/devinfo" - -// slot flags -#define AB_ATTR_PRIORITY_SHIFT 52 -#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) -#define AB_ATTR_ACTIVE_SHIFT 54 -#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) -#define AB_ATTR_RETRY_COUNT_SHIFT (55) -#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) -#define AB_ATTR_SUCCESSFUL (1UL << 58) -#define AB_ATTR_UNBOOTABLE (1UL << 59) - -#define AB_ATTR_MAX_PRIORITY 3UL -#define AB_ATTR_MAX_RETRY_COUNT 3UL - -// clang-format on - -static std::string getDevPath(uint32_t slot) { - char real_path[PATH_MAX]; - - const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; - - int ret = readlink(path, real_path, sizeof real_path); - if (ret < 0) { - ALOGE("readlink failed for boot device %s\n", strerror(errno)); - return std::string(); - } - - std::string dp(real_path); - // extract /dev/sda.. part - return dp.substr(0, sizeof "/dev/block/sdX" - 1); -} - -static bool isSlotFlagSet(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - return !!(e->attr & flag); -} - -static bool setSlotFlag(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - e->attr |= flag; - gpt.Sync(); - - return true; -} - -static bool is_devinfo_valid; -static bool is_devinfo_initialized; -static std::mutex devinfo_lock; -static devinfo_t devinfo; - -static bool isDevInfoValid() { - const std::lock_guard lock(devinfo_lock); - - if (is_devinfo_initialized) { - return is_devinfo_valid; - } - - is_devinfo_initialized = true; - - android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY)); - android::base::ReadFully(fd, &devinfo, sizeof devinfo); - - if (devinfo.magic != DEVINFO_MAGIC) { - return is_devinfo_valid; - } - - uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor; - // only version 3.3+ supports A/B data - if (version >= 0x0003'0003) { - is_devinfo_valid = true; - } - - return is_devinfo_valid; -} - -static bool DevInfoSync() { - if (!isDevInfoValid()) { - return false; - } - - android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY | O_DSYNC)); - return android::base::WriteFully(fd, &devinfo, sizeof devinfo); -} - -static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) { - slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT; - slot_data.unbootable = 0; - slot_data.successful = 0; - slot_data.active = 1; - slot_data.fastboot_ok = 0; -} - -static int blow_otp_AR(bool secure) { - static const char *dev_name = "/dev/trusty-ipc-dev0"; - static const char *otp_name = "com.android.trusty.otp_manager.tidl"; - int fd = 1, ret = 0; - uint32_t cmd = secure? OTP_CMD_write_antirbk_secure_ap : OTP_CMD_write_antirbk_non_secure_ap; - fd = tipc_connect(dev_name, otp_name); - if (fd < 0) { - ALOGI("Failed to connect to OTP_MGR ns TA - is it missing?\n"); - ret = -1; - return ret; - } - - struct otp_mgr_req_base req = { - .command = cmd, - .resp_payload_size = 0, - }; - struct iovec iov[] = { - { - .iov_base = &req, - .iov_len = sizeof(req), - }, - }; - - int rc = tipc_send(fd, iov, 1, NULL, 0); - if (rc != sizeof(req)) { - ALOGI("Send fail! %x\n", rc); - return rc; - } - - struct otp_mgr_rsp_base resp; - rc = read(fd, &resp, sizeof(resp)); - if (rc < 0) { - ALOGI("Read fail! %x\n", rc); - return rc; - } - - if (rc < sizeof(resp)) { - ALOGI("Not enough data! %x\n", rc); - return -EIO; - } - - if (resp.command != (cmd | OTP_RESP_BIT)) { - ALOGI("Wrong command! %x\n", resp.command); - return -EINVAL; - } - - if (resp.result != 0) { - fprintf(stderr, "AR writing error! %x\n", resp.result); - return -EINVAL; - } - - tipc_close(fd); - return 0; -} - -static bool blowAR() { - int ret = blow_otp_AR(true); - if (ret) { - ALOGI("Blow secure anti-rollback OTP failed"); - return false; - } - - ret = blow_otp_AR(false); - if (ret) { - ALOGI("Blow non-secure anti-rollback OTP failed"); - return false; - } - - return true; -} -} // namespace - -// Methods from ::android::hardware::boot::V1_0::IBootControl follow. -Return BootControl::getNumberSlots() { - uint32_t slots = 0; - - if (access(BOOT_A_PATH, F_OK) == 0) - slots++; - - if (access(BOOT_B_PATH, F_OK) == 0) - slots++; - - return slots; -} - -Return BootControl::getCurrentSlot() { - char suffix[PROPERTY_VALUE_MAX]; - property_get("ro.boot.slot_suffix", suffix, "_a"); - return std::string(suffix) == "_b" ? 1 : 0; -} - -Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { - if (getNumberSlots() == 0) { - // no slots, just return true otherwise Android keeps trying - _hidl_cb({true, ""}); - return Void(); - } - - bool ret; - if (isDevInfoValid()) { - auto const slot = getCurrentSlot(); - devinfo.ab_data.slots[slot].successful = 1; - ret = DevInfoSync(); - } else { - ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL); - } - - if (!ret) { - _hidl_cb({false, "Failed to set successful flag"}); - return Void(); - } - - if (!blowAR()) { - ALOGE("Failed to blow anti-rollback counter"); - // Ignore the error, since ABL will re-trigger it on reboot - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - if (isDevInfoValid()) { - auto &active_slot_data = devinfo.ab_data.slots[slot]; - auto &inactive_slot_data = devinfo.ab_data.slots[!slot]; - - inactive_slot_data.active = 0; - DevInfoInitSlot(active_slot_data); - - if (!DevInfoSync()) { - _hidl_cb({false, "Could not update DevInfo data"}); - return Void(); - } - } else { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - _hidl_cb({false, "failed to load gpt data"}); - return Void(); - } - - gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b"); - gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a"); - if (active_entry == nullptr || inactive_entry == nullptr) { - _hidl_cb({false, "failed to get entries for boot partitions"}); - return Void(); - } - - ALOGV("slot active attributes %lx\n", active_entry->attr); - ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); - - // update attributes for active and inactive - inactive_entry->attr &= ~AB_ATTR_ACTIVE; - active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | - (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); - } - - char boot_dev[PROPERTY_VALUE_MAX]; - property_get("ro.boot.bootdevice", boot_dev, ""); - if (boot_dev[0] == '\0') { - _hidl_cb({false, "invalid ro.boot.bootdevice prop"}); - return Void(); - } - - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled"; - int fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - // Try old path for kernels < 5.4 - // TODO: remove once kernel 4.19 support is deprecated - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled"; - fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"}); - return Void(); - } - } - - // - // bBootLunEn - // 0x1 => Boot LU A = enabled, Boot LU B = disable - // 0x2 => Boot LU A = disable, Boot LU B = enabled - // - int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd); - close(fd); - if (ret < 0) { - _hidl_cb({false, "faied to write boot_lun_enabled attribute"}); - return Void(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - slot_data.unbootable = 1; - if (!DevInfoSync()) { - _hidl_cb({false, "Could not update DevInfo data"}); - return Void(); - } - } else { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - gpt.Load(); - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - e->attr |= AB_ATTR_UNBOOTABLE; - - gpt.Sync(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) { - if (getNumberSlots() == 0) - return BoolResult::FALSE; - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - - bool unbootable; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - unbootable = !!slot_data.unbootable; - } else { - unbootable = isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE); - } - - return unbootable ? BoolResult::FALSE : BoolResult::TRUE; -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful( - uint32_t slot) { - if (getNumberSlots() == 0) { - // just return true so that we don't we another call trying to mark it as successful - // when there is no slots - return BoolResult::TRUE; - } - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - - bool successful; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - successful = !!slot_data.successful; - } else { - successful = isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL); - } - - return successful ? BoolResult::TRUE : BoolResult::FALSE; -} - -Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { - _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : ""); - return Void(); -} - -// Methods from ::android::hardware::boot::V1_1::IBootControl follow. -bool BootControl::Init() { - return InitMiscVirtualAbMessageIfNeeded(); -} - -Return BootControl::setSnapshotMergeStatus( - ::android::hardware::boot::V1_1::MergeStatus status) { - return SetMiscVirtualAbMergeStatus(getCurrentSlot(), status); -} - -Return<::android::hardware::boot::V1_1::MergeStatus> BootControl::getSnapshotMergeStatus() { - MergeStatus status; - if (!GetMiscVirtualAbMergeStatus(getCurrentSlot(), &status)) { - return MergeStatus::UNKNOWN; - } - return status; -} - -// Methods from ::android::hardware::boot::V1_2::IBootControl follow. -Return BootControl::getActiveBootSlot() { - if (getNumberSlots() == 0) - return 0; - - if (isDevInfoValid()) - return devinfo.ab_data.slots[1].active ? 1 : 0; - return isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0; -} - -// Methods from ::android::hidl::base::V1_0::IBase follow. - -IBootControl *HIDL_FETCH_IBootControl(const char * /* name */) { - auto module = new BootControl(); - - module->Init(); - - return module; -} - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/BootControl.h b/interfaces/boot/1.2/BootControl.h deleted file mode 100644 index 45b7efad..00000000 --- a/interfaces/boot/1.2/BootControl.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -using ::android::sp; -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; - -struct BootControl : public IBootControl { - bool Init(); - - // Methods from ::android::hardware::boot::V1_0::IBootControl follow. - Return getNumberSlots() override; - Return getCurrentSlot() override; - Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; - Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; - Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful( - uint32_t slot) override; - Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; - - // Methods from ::android::hardware::boot::V1_1::IBootControl follow. - Return setSnapshotMergeStatus( - ::android::hardware::boot::V1_1::MergeStatus status) override; - Return<::android::hardware::boot::V1_1::MergeStatus> getSnapshotMergeStatus() override; - - // Methods from ::android::hardware::boot::V1_2::IBootControl follow. - Return getActiveBootSlot() override; - - // Methods from ::android::hidl::base::V1_0::IBase follow. -}; - -// FIXME: most likely delete, this is only for passthrough implementations -extern "C" IBootControl *HIDL_FETCH_IBootControl(const char *name); - -enum otpmgr_command : uint32_t { - OTP_REQ_SHIFT = 1, - OTP_RESP_BIT = 1, - OTP_CMD_write_antirbk_non_secure_ap = (7 << OTP_REQ_SHIFT), - OTP_CMD_write_antirbk_secure_ap = (8 << OTP_REQ_SHIFT), -}; - -struct otp_mgr_req_base { - uint32_t command; - uint32_t resp_payload_size; - uint8_t handle; -}__packed; - -struct otp_mgr_rsp_base { - uint32_t command; - uint32_t resp_payload_size; - int result; -}__packed; - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/DevInfo.h b/interfaces/boot/1.2/DevInfo.h deleted file mode 100644 index a09a83a2..00000000 --- a/interfaces/boot/1.2/DevInfo.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -// -// definitions taken from ABL code -// - -constexpr uint32_t DEVINFO_MAGIC = 0x49564544; -constexpr size_t DEVINFO_AB_SLOT_COUNT = 2; - -struct devinfo_ab_slot_data_t { - uint8_t retry_count; - uint8_t unbootable : 1; - uint8_t successful : 1; - uint8_t active : 1; - uint8_t fastboot_ok : 1; - uint8_t : 4; - uint8_t unused[2]; -} __attribute__((packed)); - -typedef struct { - devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT]; -} __attribute__((packed)) devinfo_ab_data_t; - -struct devinfo_t { - uint32_t magic; - uint16_t ver_major; - uint16_t ver_minor; - uint8_t unused[40]; - devinfo_ab_data_t ab_data; - uint8_t unused1[72]; // use remaining up to complete 128 bytes -} __attribute__((packed)); - -static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size"); - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/GptUtils.cpp b/interfaces/boot/1.2/GptUtils.cpp deleted file mode 100644 index 25088e79..00000000 --- a/interfaces/boot/1.2/GptUtils.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "GptUtils.h" - -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -namespace { - -static int ValidateGptHeader(gpt_header *gpt) { - if (gpt->signature != GPT_SIGNATURE) { - ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); - return -1; - } - - if (gpt->header_size != sizeof(gpt_header)) { - ALOGE("invalid gpt header size %u\n", gpt->header_size); - return -1; - } - - if (gpt->entry_size != sizeof(gpt_entry)) { - ALOGE("invalid gpt entry size %u\n", gpt->entry_size); - return -1; - } - - return 0; -} - -} // namespace - -GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} - -int GptUtils::Load(void) { - fd = open(dev_path.c_str(), O_RDWR); - if (fd < 0) { - ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); - return -1; - } - - int ret = ioctl(fd, BLKSSZGET, &block_size); - if (ret < 0) { - ALOGE("failed to get block size %d\n", errno); - return -1; - } - - // read primary header - lseek64(fd, block_size, SEEK_SET); - ret = read(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to read gpt primary header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_primary)) { - ALOGE("error validating gpt header\n"); - return -1; - } - - // read partition entries - entry_array.resize(gpt_primary.entry_count); - uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = read(fd, entry_array.data(), entries_size); - if (ret < 0) { - ALOGE("failed to read gpt partition entries %d\n", errno); - return -1; - } - - // read gpt back header - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = read(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to read gpt backup header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_backup)) { - ALOGW("error validating gpt backup\n"); // just warn about it, not fail - } - - // Create map - auto get_name = [](const uint16_t *efi_name) { - char name[37] = {}; - for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i]; - return std::string(name); - }; - - for (auto const &e : entry_array) { - if (e.name[0] == 0) - break; // stop at the first partition with no name - std::string s = get_name(e.name); - entries[s] = const_cast(&e); - } - - return 0; -} - -gpt_entry *GptUtils::GetPartitionEntry(std::string name) { - return entries.find(name) != entries.end() ? entries[name] : nullptr; -} - -int GptUtils::Sync(void) { - if (!fd) - return -1; - - // calculate crc and check if we need to update gpt - gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), - entry_array.size() * sizeof(gpt_entry)); - - // save old crc - uint32_t crc = gpt_primary.crc32; - gpt_primary.crc32 = 0; - - gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); - if (crc == gpt_primary.crc32) - return 0; // nothing to do (no changes) - - ALOGI("updating GPT\n"); - - lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); - int ret = write(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to write gpt primary header %d\n", errno); - return -1; - } - - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt partition entries %d\n", errno); - return -1; - } - - // update GPT backup entries and backup - lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt backup partition entries %d\n", errno); - return -1; - } - - gpt_backup.entries_crc32 = gpt_primary.entries_crc32; - gpt_backup.crc32 = 0; - gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = write(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to write gpt backup header %d\n", errno); - return -1; - } - - fsync(fd); - - return 0; -} - -GptUtils::~GptUtils() { - if (fd) { - Sync(); - close(fd); - } -} - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/GptUtils.h b/interfaces/boot/1.2/GptUtils.h deleted file mode 100644 index a2bed334..00000000 --- a/interfaces/boot/1.2/GptUtils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -#define GPT_SIGNATURE 0x5452415020494645UL - -typedef struct { - uint8_t type_guid[16]; - uint8_t guid[16]; - uint64_t first_lba; - uint64_t last_lba; - uint64_t attr; - uint16_t name[36]; -} __attribute__((packed)) gpt_entry; - -typedef struct { - uint64_t signature; - uint32_t revision; - uint32_t header_size; - uint32_t crc32; - uint32_t reserved; - uint64_t current_lba; - uint64_t backup_lba; - uint64_t first_usable_lba; - uint64_t last_usable_lba; - uint8_t disk_guid[16]; - uint64_t start_lba; - uint32_t entry_count; - uint32_t entry_size; - uint32_t entries_crc32; -} __attribute__((packed)) gpt_header; - -class GptUtils { - public: - GptUtils(const std::string dev_path); - int Load(void); - gpt_entry *GetPartitionEntry(std::string name); - int Sync(void); - ~GptUtils(); - - private: - std::string dev_path; - int fd; - uint32_t block_size; - gpt_header gpt_primary; - gpt_header gpt_backup; - std::vector entry_array; - std::map entries; -}; - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc b/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc deleted file mode 100644 index 4e5f5fe6..00000000 --- a/interfaces/boot/1.2/android.hardware.boot@1.2-service-zuma.rc +++ /dev/null @@ -1,7 +0,0 @@ -service vendor.boot-hal-1-2 /vendor/bin/hw/android.hardware.boot@1.2-service-zuma - interface android.hardware.boot@1.0::IBootControl default - interface android.hardware.boot@1.1::IBootControl default - interface android.hardware.boot@1.2::IBootControl default - class early_hal - user root - group root drmrpc diff --git a/interfaces/boot/1.2/service.cpp b/interfaces/boot/1.2/service.cpp deleted file mode 100644 index f07682e9..00000000 --- a/interfaces/boot/1.2/service.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "android.hardware.boot@1.2-service" - -#include -#include -#include -#include - -#include "BootControl.h" - -using ::android::status_t; - -using ::android::hardware::boot::V1_2::IBootControl; - -using ::android::hardware::boot::V1_2::implementation::BootControl; -// using ::android::hardware::boot::implementation::BootControl; - -int main(int /* argc */, char * /* argv */[]) { - // This function must be called before you join to ensure the proper - // number of threads are created. The threadpool will never exceed - // size one because of this call. - ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/); - - ::android::sp bootctrl = new BootControl(); - const status_t status = bootctrl->registerAsService(); - if (status != ::android::OK) { - return 1; // or handle error - } - - // Adds this thread to the threadpool, resulting in one total - // thread in the threadpool. We could also do other things, but - // would have to specify 'false' to willJoin in configureRpcThreadpool. - ::android::hardware::joinRpcThreadpool(); - return 1; // joinRpcThreadpool should never return -} diff --git a/interfaces/boot/aidl/Android.bp b/interfaces/boot/aidl/Android.bp deleted file mode 100644 index 37d2aebe..00000000 --- a/interfaces/boot/aidl/Android.bp +++ /dev/null @@ -1,65 +0,0 @@ -// -// Copyright (C) 2023 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/zuma:device_google_zuma_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/zuma:device_google_zuma_license", - ], -} - -cc_defaults { - name: "android.hardware.boot-service_common-zuma", - relative_install_path: "hw", - defaults: ["libboot_control_defaults"], - shared_libs: [ - "libbase", - "libbinder_ndk", - "libcutils", - "libz", - "libtrusty", - "android.hardware.boot@1.1", - "android.hardware.boot-V1-ndk", - ], - static_libs: [ - "libboot_control", - "libbootloader_message_vendor", - ], - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - "service.cpp" - ], -} - -cc_binary { - name: "android.hardware.boot-service.default-zuma", - defaults: ["android.hardware.boot-service_common-zuma"], - init_rc: ["android.hardware.boot-service.default-zuma.rc"], - vendor: true, -} - -cc_binary { - name: "android.hardware.boot-service.default_recovery-zuma", - defaults: ["android.hardware.boot-service_common-zuma"], - vintf_fragments: ["android.hardware.boot-service.default_recovery-zuma.xml"], - init_rc: ["android.hardware.boot-service.default_recovery-zuma.rc"], - recovery: true, -} \ No newline at end of file diff --git a/interfaces/boot/aidl/BootControl.cpp b/interfaces/boot/aidl/BootControl.cpp deleted file mode 100644 index 941b0d2b..00000000 --- a/interfaces/boot/aidl/BootControl.cpp +++ /dev/null @@ -1,538 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "BootControl.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "DevInfo.h" -#include "GptUtils.h" - -using HIDLMergeStatus = ::android::bootable::BootControl::MergeStatus; -using ndk::ScopedAStatus; - -using android::bootable::GetMiscVirtualAbMergeStatus; -using android::bootable::InitMiscVirtualAbMessageIfNeeded; -using android::bootable::SetMiscVirtualAbMergeStatus; - -namespace aidl::android::hardware::boot { - -namespace { - -// clang-format off - -#define BOOT_A_PATH "/dev/block/by-name/boot_a" -#define BOOT_B_PATH "/dev/block/by-name/boot_b" -#define DEVINFO_PATH "/dev/block/by-name/devinfo" - -// slot flags -#define AB_ATTR_PRIORITY_SHIFT 52 -#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) -#define AB_ATTR_ACTIVE_SHIFT 54 -#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) -#define AB_ATTR_RETRY_COUNT_SHIFT (55) -#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) -#define AB_ATTR_SUCCESSFUL (1UL << 58) -#define AB_ATTR_UNBOOTABLE (1UL << 59) - -#define AB_ATTR_MAX_PRIORITY 3UL -#define AB_ATTR_MAX_RETRY_COUNT 3UL - -// clang-format on - -static std::string getDevPath(int32_t in_slot) { - char real_path[PATH_MAX]; - - const char *path = in_slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; - - int ret = readlink(path, real_path, sizeof real_path); - if (ret < 0) { - ALOGE("readlink failed for boot device %s\n", strerror(errno)); - return std::string(); - } - - std::string dp(real_path); - // extract /dev/sda.. part - return dp.substr(0, sizeof "/dev/block/sdX" - 1); -} - -static bool isSlotFlagSet(int32_t in_slot, uint64_t flag) { - std::string dev_path = getDevPath(in_slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", in_slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - return !!(e->attr & flag); -} - -static bool setSlotFlag(int32_t in_slot, uint64_t flag) { - std::string dev_path = getDevPath(in_slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", in_slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - e->attr |= flag; - gpt.Sync(); - - return true; -} - -static bool is_devinfo_valid; -static bool is_devinfo_initialized; -static std::mutex devinfo_lock; -static devinfo_t devinfo; - -static bool isDevInfoValid() { - const std::lock_guard lock(devinfo_lock); - - if (is_devinfo_initialized) { - return is_devinfo_valid; - } - - is_devinfo_initialized = true; - - ::android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY)); - ::android::base::ReadFully(fd, &devinfo, sizeof devinfo); - - if (devinfo.magic != DEVINFO_MAGIC) { - return is_devinfo_valid; - } - - uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor; - // only version 3.3+ supports A/B data - if (version >= 0x0003'0003) { - is_devinfo_valid = true; - } - - return is_devinfo_valid; -} - -static bool DevInfoSync() { - if (!isDevInfoValid()) { - return false; - } - - ::android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY | O_DSYNC)); - return ::android::base::WriteFully(fd, &devinfo, sizeof devinfo); -} - -static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) { - slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT; - slot_data.unbootable = 0; - slot_data.successful = 0; - slot_data.active = 1; - slot_data.fastboot_ok = 0; -} - -static int blow_otp_AR(bool secure) { - static const char *dev_name = "/dev/trusty-ipc-dev0"; - static const char *otp_name = "com.android.trusty.otp_manager.tidl"; - int fd = 1, ret = 0; - uint32_t cmd = secure? OTP_CMD_write_antirbk_secure_ap : OTP_CMD_write_antirbk_non_secure_ap; - fd = tipc_connect(dev_name, otp_name); - if (fd < 0) { - ALOGI("Failed to connect to OTP_MGR ns TA - is it missing?\n"); - ret = -1; - return ret; - } - - struct otp_mgr_req_base req = { - .command = cmd, - .resp_payload_size = 0, - }; - struct iovec iov[] = { - { - .iov_base = &req, - .iov_len = sizeof(req), - }, - }; - - size_t rc = tipc_send(fd, iov, 1, NULL, 0); - if (rc != sizeof(req)) { - ALOGI("Send fail! %zx\n", rc); - return rc; - } - - struct otp_mgr_rsp_base resp; - rc = read(fd, &resp, sizeof(resp)); - if (rc < 0) { - ALOGI("Read fail! %zx\n", rc); - return rc; - } - - if (rc < sizeof(resp)) { - ALOGI("Not enough data! %zx\n", rc); - return -EIO; - } - - if (resp.command != (cmd | OTP_RESP_BIT)) { - ALOGI("Wrong command! %x\n", resp.command); - return -EINVAL; - } - - if (resp.result != 0) { - fprintf(stderr, "AR writing error! %x\n", resp.result); - return -EINVAL; - } - - tipc_close(fd); - return 0; -} - -static bool blowAR() { - int ret = blow_otp_AR(true); - if (ret) { - ALOGI("Blow secure anti-rollback OTP failed"); - return false; - } - - ret = blow_otp_AR(false); - if (ret) { - ALOGI("Blow non-secure anti-rollback OTP failed"); - return false; - } - - return true; -} - -static constexpr MergeStatus ToAIDLMergeStatus(HIDLMergeStatus status) { - switch (status) { - case HIDLMergeStatus::NONE: - return MergeStatus::NONE; - case HIDLMergeStatus::UNKNOWN: - return MergeStatus::UNKNOWN; - case HIDLMergeStatus::SNAPSHOTTED: - return MergeStatus::SNAPSHOTTED; - case HIDLMergeStatus::MERGING: - return MergeStatus::MERGING; - case HIDLMergeStatus::CANCELLED: - return MergeStatus::CANCELLED; - } -} - -static constexpr HIDLMergeStatus ToHIDLMergeStatus(MergeStatus status) { - switch (status) { - case MergeStatus::NONE: - return HIDLMergeStatus::NONE; - case MergeStatus::UNKNOWN: - return HIDLMergeStatus::UNKNOWN; - case MergeStatus::SNAPSHOTTED: - return HIDLMergeStatus::SNAPSHOTTED; - case MergeStatus::MERGING: - return HIDLMergeStatus::MERGING; - case MergeStatus::CANCELLED: - return HIDLMergeStatus::CANCELLED; - } -} - -} // namespace - -BootControl::BootControl() { - CHECK(InitMiscVirtualAbMessageIfNeeded()); -} - -ScopedAStatus BootControl::getActiveBootSlot(int32_t* _aidl_return) { - int32_t slots = 0; - getNumberSlots(&slots); - if (slots == 0) { - *_aidl_return = 0; - return ScopedAStatus::ok(); - } - - if (isDevInfoValid()) { - *_aidl_return = devinfo.ab_data.slots[1].active ? 1 : 0; - return ScopedAStatus::ok(); - } - *_aidl_return = isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::getCurrentSlot(int32_t* _aidl_return) { - char suffix[PROPERTY_VALUE_MAX]; - property_get("ro.boot.slot_suffix", suffix, "_a"); - *_aidl_return = std::string(suffix) == "_b" ? 1 : 0; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::getNumberSlots(int32_t* _aidl_return) { - int32_t slots = 0; - - if (access(BOOT_A_PATH, F_OK) == 0) - slots++; - - if (access(BOOT_B_PATH, F_OK) == 0) - slots++; - - *_aidl_return = slots; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::getSnapshotMergeStatus(MergeStatus* _aidl_return) { - HIDLMergeStatus status; - int32_t current_slot = 0; - getCurrentSlot(¤t_slot); - if (!GetMiscVirtualAbMergeStatus(current_slot, &status)) { - *_aidl_return = MergeStatus::UNKNOWN; - return ScopedAStatus::ok(); - } - *_aidl_return = ToAIDLMergeStatus(status); - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::getSuffix(int32_t in_slot, std::string* _aidl_return) { - *_aidl_return = in_slot == 0 ? "_a" : in_slot == 1 ? "_b" : ""; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::isSlotBootable(int32_t in_slot, bool* _aidl_return) { - int32_t slots = 0; - getNumberSlots(&slots); - if (slots == 0) { - *_aidl_return = false; - return ScopedAStatus::ok(); - } - if (in_slot >= slots) - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); - - bool unbootable; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[in_slot]; - unbootable = !!slot_data.unbootable; - } else { - unbootable = isSlotFlagSet(in_slot, AB_ATTR_UNBOOTABLE); - } - - *_aidl_return = unbootable ? false: true; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::isSlotMarkedSuccessful(int32_t in_slot, bool* _aidl_return) { - int32_t slots = 0; - getNumberSlots(&slots); - if (slots == 0) { - // just return true so that we don't we another call trying to mark it as successful - // when there is no slots - *_aidl_return = true; - return ScopedAStatus::ok(); - } - if (in_slot >= slots) - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); - - bool successful; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[in_slot]; - successful = !!slot_data.successful; - } else { - successful = isSlotFlagSet(in_slot, AB_ATTR_SUCCESSFUL); - } - - *_aidl_return = successful ? true : false; - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::markBootSuccessful() { - int32_t slots = 0; - getNumberSlots(&slots); - if (slots == 0) { - // no slots, just return true otherwise Android keeps trying - return ScopedAStatus::ok(); - } - - bool ret; - int32_t current_slot = 0; - getCurrentSlot(¤t_slot); - if (isDevInfoValid()) { - auto const slot = current_slot; - devinfo.ab_data.slots[slot].successful = 1; - ret = DevInfoSync(); - } else { - ret = setSlotFlag(current_slot, AB_ATTR_SUCCESSFUL); - } - - if (!ret) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, - "Failed to set successful flag"); - } - - if (!blowAR()) { - ALOGE("Failed to blow anti-rollback counter"); - // Ignore the error, since ABL will re-trigger it on reboot - } - - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::setActiveBootSlot(int32_t in_slot) { - if (in_slot >= 2) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); - } - - if (isDevInfoValid()) { - auto &active_slot_data = devinfo.ab_data.slots[in_slot]; - auto &inactive_slot_data = devinfo.ab_data.slots[!in_slot]; - - inactive_slot_data.active = 0; - DevInfoInitSlot(active_slot_data); - - if (!DevInfoSync()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "Could not update DevInfo data"); - } - } else { - std::string dev_path = getDevPath(in_slot); - if (dev_path.empty()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "Could not get device path for slot"); - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, - "failed to load gpt data"); - } - - gpt_entry *active_entry = gpt.GetPartitionEntry(in_slot == 0 ? "boot_a" : "boot_b"); - gpt_entry *inactive_entry = gpt.GetPartitionEntry(in_slot == 0 ? "boot_b" : "boot_a"); - if (active_entry == nullptr || inactive_entry == nullptr) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "failed to get entries for boot partitions"); - } - - ALOGV("slot active attributes %lx\n", active_entry->attr); - ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); - - // update attributes for active and inactive - inactive_entry->attr &= ~AB_ATTR_ACTIVE; - active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | - (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); - } - - char boot_dev[PROPERTY_VALUE_MAX]; - property_get("ro.boot.bootdevice", boot_dev, ""); - if (boot_dev[0] == '\0') { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "invalid ro.boot.bootdevice prop"); - } - - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled"; - int fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - // Try old path for kernels < 5.4 - // TODO: remove once kernel 4.19 support is deprecated - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled"; - fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "failed to open ufs attr boot_lun_enabled"); - } - } - - // - // bBootLunEn - // 0x1 => Boot LU A = enabled, Boot LU B = disable - // 0x2 => Boot LU A = disable, Boot LU B = enabled - // - int ret = ::android::base::WriteStringToFd(in_slot == 0 ? "1" : "2", fd); - close(fd); - if (ret < 0) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "faied to write boot_lun_enabled attribute"); - } - - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::setSlotAsUnbootable(int32_t in_slot) { - if (in_slot >= 2) - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - INVALID_SLOT, (std::string("Invalid slot ") + std::to_string(in_slot)).c_str()); - - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[in_slot]; - slot_data.unbootable = 1; - if (!DevInfoSync()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "Could not update DevInfo data"); - } - } else { - std::string dev_path = getDevPath(in_slot); - if (dev_path.empty()) { - return ScopedAStatus::fromServiceSpecificErrorWithMessage( - COMMAND_FAILED, "Could not get device path for slot"); - } - - GptUtils gpt(dev_path); - gpt.Load(); - - gpt_entry *e = gpt.GetPartitionEntry(in_slot ? "boot_b" : "boot_a"); - e->attr |= AB_ATTR_UNBOOTABLE; - - gpt.Sync(); - } - - return ScopedAStatus::ok(); -} - -ScopedAStatus BootControl::setSnapshotMergeStatus(MergeStatus in_status) { - int32_t current_slot = 0; - getCurrentSlot(¤t_slot); - if (!SetMiscVirtualAbMergeStatus(current_slot, ToHIDLMergeStatus(in_status))) - return ScopedAStatus::fromServiceSpecificErrorWithMessage(COMMAND_FAILED, - "Operation failed"); - return ScopedAStatus::ok(); -} - -} // namespace aidl::android::hardware::boot diff --git a/interfaces/boot/aidl/BootControl.h b/interfaces/boot/aidl/BootControl.h deleted file mode 100644 index a54f66d0..00000000 --- a/interfaces/boot/aidl/BootControl.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace aidl::android::hardware::boot { - -class BootControl final : public BnBootControl { - public: - BootControl(); - ::ndk::ScopedAStatus getActiveBootSlot(int32_t* _aidl_return) override; - ::ndk::ScopedAStatus getCurrentSlot(int32_t* _aidl_return) override; - ::ndk::ScopedAStatus getNumberSlots(int32_t* _aidl_return) override; - ::ndk::ScopedAStatus getSnapshotMergeStatus( - ::aidl::android::hardware::boot::MergeStatus* _aidl_return) override; - ::ndk::ScopedAStatus getSuffix(int32_t in_slot, std::string* _aidl_return) override; - ::ndk::ScopedAStatus isSlotBootable(int32_t in_slot, bool* _aidl_return) override; - ::ndk::ScopedAStatus isSlotMarkedSuccessful(int32_t in_slot, bool* _aidl_return) override; - ::ndk::ScopedAStatus markBootSuccessful() override; - ::ndk::ScopedAStatus setActiveBootSlot(int32_t in_slot) override; - ::ndk::ScopedAStatus setSlotAsUnbootable(int32_t in_slot) override; - ::ndk::ScopedAStatus setSnapshotMergeStatus( - ::aidl::android::hardware::boot::MergeStatus in_status) override; -}; - -enum otpmgr_command : uint32_t { - OTP_REQ_SHIFT = 1, - OTP_RESP_BIT = 1, - OTP_CMD_write_antirbk_non_secure_ap = (7 << OTP_REQ_SHIFT), - OTP_CMD_write_antirbk_secure_ap = (8 << OTP_REQ_SHIFT), -}; - -struct otp_mgr_req_base { - uint32_t command; - uint32_t resp_payload_size; - uint8_t handle; -}__packed; - -struct otp_mgr_rsp_base { - uint32_t command; - uint32_t resp_payload_size; - int result; -}__packed; - -} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/DevInfo.h b/interfaces/boot/aidl/DevInfo.h deleted file mode 100644 index aa5f5d37..00000000 --- a/interfaces/boot/aidl/DevInfo.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace aidl::android::hardware::boot { - -// -// definitions taken from ABL code -// - -constexpr uint32_t DEVINFO_MAGIC = 0x49564544; -constexpr size_t DEVINFO_AB_SLOT_COUNT = 2; - -struct devinfo_ab_slot_data_t { - uint8_t retry_count; - uint8_t unbootable : 1; - uint8_t successful : 1; - uint8_t active : 1; - uint8_t fastboot_ok : 1; - uint8_t : 4; - uint8_t unused[2]; -} __attribute__((packed)); - -typedef struct { - devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT]; -} __attribute__((packed)) devinfo_ab_data_t; - -struct devinfo_t { - uint32_t magic; - uint16_t ver_major; - uint16_t ver_minor; - uint8_t unused[40]; - devinfo_ab_data_t ab_data; - uint8_t unused1[72]; // use remaining up to complete 128 bytes -} __attribute__((packed)); - -static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size"); - -} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/GptUtils.cpp b/interfaces/boot/aidl/GptUtils.cpp deleted file mode 100644 index 34dec113..00000000 --- a/interfaces/boot/aidl/GptUtils.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "GptUtils.h" - -#include -#include -#include -#include -#include - -namespace aidl::android::hardware::boot { - -namespace { - -static int ValidateGptHeader(gpt_header *gpt) { - if (gpt->signature != GPT_SIGNATURE) { - ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); - return -1; - } - - if (gpt->header_size != sizeof(gpt_header)) { - ALOGE("invalid gpt header size %u\n", gpt->header_size); - return -1; - } - - if (gpt->entry_size != sizeof(gpt_entry)) { - ALOGE("invalid gpt entry size %u\n", gpt->entry_size); - return -1; - } - - return 0; -} - -} // namespace - -GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} - -int GptUtils::Load(void) { - fd = open(dev_path.c_str(), O_RDWR); - if (fd < 0) { - ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); - return -1; - } - - int ret = ioctl(fd, BLKSSZGET, &block_size); - if (ret < 0) { - ALOGE("failed to get block size %d\n", errno); - return -1; - } - - // read primary header - lseek64(fd, block_size, SEEK_SET); - ret = read(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to read gpt primary header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_primary)) { - ALOGE("error validating gpt header\n"); - return -1; - } - - // read partition entries - entry_array.resize(gpt_primary.entry_count); - uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = read(fd, entry_array.data(), entries_size); - if (ret < 0) { - ALOGE("failed to read gpt partition entries %d\n", errno); - return -1; - } - - // read gpt back header - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = read(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to read gpt backup header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_backup)) { - ALOGW("error validating gpt backup\n"); // just warn about it, not fail - } - - // Create map - auto get_name = [](const uint16_t *efi_name) { - char name[37] = {}; - for (size_t i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i]; - return std::string(name); - }; - - for (auto const &e : entry_array) { - if (e.name[0] == 0) - break; // stop at the first partition with no name - std::string s = get_name(e.name); - entries[s] = const_cast(&e); - } - - return 0; -} - -gpt_entry *GptUtils::GetPartitionEntry(std::string name) { - return entries.find(name) != entries.end() ? entries[name] : nullptr; -} - -int GptUtils::Sync(void) { - if (!fd) - return -1; - - // calculate crc and check if we need to update gpt - gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), - entry_array.size() * sizeof(gpt_entry)); - - // save old crc - uint32_t crc = gpt_primary.crc32; - gpt_primary.crc32 = 0; - - gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); - if (crc == gpt_primary.crc32) - return 0; // nothing to do (no changes) - - ALOGI("updating GPT\n"); - - lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); - int ret = write(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to write gpt primary header %d\n", errno); - return -1; - } - - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt partition entries %d\n", errno); - return -1; - } - - // update GPT backup entries and backup - lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt backup partition entries %d\n", errno); - return -1; - } - - gpt_backup.entries_crc32 = gpt_primary.entries_crc32; - gpt_backup.crc32 = 0; - gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = write(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to write gpt backup header %d\n", errno); - return -1; - } - - fsync(fd); - - return 0; -} - -GptUtils::~GptUtils() { - if (fd) { - Sync(); - close(fd); - } -} - -} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/GptUtils.h b/interfaces/boot/aidl/GptUtils.h deleted file mode 100644 index ec68cf6f..00000000 --- a/interfaces/boot/aidl/GptUtils.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace aidl::android::hardware::boot { - -#define GPT_SIGNATURE 0x5452415020494645UL - -typedef struct { - uint8_t type_guid[16]; - uint8_t guid[16]; - uint64_t first_lba; - uint64_t last_lba; - uint64_t attr; - uint16_t name[36]; -} __attribute__((packed)) gpt_entry; - -typedef struct { - uint64_t signature; - uint32_t revision; - uint32_t header_size; - uint32_t crc32; - uint32_t reserved; - uint64_t current_lba; - uint64_t backup_lba; - uint64_t first_usable_lba; - uint64_t last_usable_lba; - uint8_t disk_guid[16]; - uint64_t start_lba; - uint32_t entry_count; - uint32_t entry_size; - uint32_t entries_crc32; -} __attribute__((packed)) gpt_header; - -class GptUtils { - public: - GptUtils(const std::string dev_path); - int Load(void); - gpt_entry *GetPartitionEntry(std::string name); - int Sync(void); - ~GptUtils(); - - private: - std::string dev_path; - int fd; - uint32_t block_size; - gpt_header gpt_primary; - gpt_header gpt_backup; - std::vector entry_array; - std::map entries; -}; - -} // namespace aidl::android::hardware::boot \ No newline at end of file diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc b/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc deleted file mode 100644 index f7dccadb..00000000 --- a/interfaces/boot/aidl/android.hardware.boot-service.default-zuma.rc +++ /dev/null @@ -1,5 +0,0 @@ -service vendor.boot-default /vendor/bin/hw/android.hardware.boot-service.default-zuma - class early_hal - user root - group root drmrpc - diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc b/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc deleted file mode 100644 index d867a5f5..00000000 --- a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.rc +++ /dev/null @@ -1,7 +0,0 @@ -service vendor.boot-default /system/bin/hw/android.hardware.boot-service.default_recovery-zuma - class early_hal - user root - group root - seclabel u:r:hal_bootctl_default:s0 - interface aidl android.hardware.boot.IBootControl/default - diff --git a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml b/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml deleted file mode 100644 index 23ccc4e3..00000000 --- a/interfaces/boot/aidl/android.hardware.boot-service.default_recovery-zuma.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - android.hardware.boot - IBootControl/default - - diff --git a/interfaces/boot/aidl/service.cpp b/interfaces/boot/aidl/service.cpp deleted file mode 100644 index 41b6c256..00000000 --- a/interfaces/boot/aidl/service.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "aidl.android.hardware.boot-service.default" - -#include -#include -#include -#include -#include - -#include "BootControl.h" - -using aidl::android::hardware::boot::BootControl; -using aidl::android::hardware::boot::IBootControl; -using ::android::hardware::configureRpcThreadpool; -using ::android::hardware::joinRpcThreadpool; - -int main(int, char* argv[]) { - android::base::InitLogging(argv, android::base::KernelLogger); - ABinderProcess_setThreadPoolMaxThreadCount(0); - std::shared_ptr service = ndk::SharedRefBase::make(); - - const std::string instance = std::string(BootControl::descriptor) + "/default"; - auto status = AServiceManager_addService(service->asBinder().get(), instance.c_str()); - CHECK_EQ(status, STATUS_OK) << "Failed to add service " << instance << " " << status; - LOG(INFO) << "IBootControl AIDL service running..."; - - ABinderProcess_joinThreadPool(); - return EXIT_FAILURE; // should not reach -} From e555c307b2de4d43c20a158a29326c686022f556 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Mon, 27 Nov 2023 17:34:32 +0800 Subject: [PATCH 123/133] zuma: move bootctrl service declaration to gs-common Bug: 265063384 Change-Id: Ibd98a40b397361146638381c5cfc1c3d2544b18f Signed-off-by: Jason Chiu --- device.mk | 5 ----- 1 file changed, 5 deletions(-) diff --git a/device.mk b/device.mk index 10c6839e..ab634a51 100644 --- a/device.mk +++ b/device.mk @@ -924,11 +924,6 @@ PRODUCT_PACKAGES += \ ImsMediaService \ libimsmedia -# Boot Control HAL -PRODUCT_PACKAGES += \ - android.hardware.boot-service.default-zuma\ - android.hardware.boot-service.default_recovery-zuma - # Exynos RIL and telephony # Multi SIM(DSDS) SIM_COUNT := 2 From 10343c4fbff1fa39283314a6be37efe9dad7a818 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 9 Nov 2023 21:05:39 +0800 Subject: [PATCH 124/133] zuma: include bootctrl_aidl.mk from gs-common Bug: 265063384 Change-Id: Ia17b1506e1ea00b2df34b1ced6bea6d37d6a8a58 Signed-off-by: Jason Chiu --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index ab634a51..bde0a2f9 100644 --- a/device.mk +++ b/device.mk @@ -40,6 +40,7 @@ include device/google/gs-common/widevine/widevine.mk include device/google/gs-common/sota_app/factoryota.mk include device/google/gs-common/misc_writer/misc_writer.mk include device/google/gs-common/gyotaku_app/gyotaku.mk +include device/google/gs-common/bootctrl/bootctrl_aidl.mk include device/google/zuma/dumpstate/item.mk From d120b32a73b2f6d6eacd685b3ecfc1908e7bafd4 Mon Sep 17 00:00:00 2001 From: Ray Chi Date: Tue, 5 Dec 2023 16:36:52 +0800 Subject: [PATCH 125/133] dump_power: add eusb_repeater path to dump registers Bug: 305145476 Test: adb bugreport Change-Id: I96611e7741380661c0277107e8b0763e79cb6c94 --- dumpstate/dump_power.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dumpstate/dump_power.cpp b/dumpstate/dump_power.cpp index 9da35450..a79921b1 100644 --- a/dumpstate/dump_power.cpp +++ b/dumpstate/dump_power.cpp @@ -295,6 +295,15 @@ void dumpPdEngine() { } } +void dumpEusbRepeater() { + const char* dumpTitle = "registers dump of eUSB repeater"; + const char* dumpFile = "/d/eusb_repeater/registers"; + + if (isValidFile(dumpFile)) { + dumpFileContent(dumpTitle, dumpFile); + } +} + void dumpWc68() { const char* wc68Title = "WC68"; const char* wc68File = "/dev/logbuffer_wc68"; @@ -908,6 +917,7 @@ int main() { dumpLogBufferTcpm(); dumpTcpc(); dumpPdEngine(); + dumpEusbRepeater(); dumpWc68(); dumpLn8411(); dumpBatteryHealth(); From 3e5743c5218e79683748c28ff134809583af3203 Mon Sep 17 00:00:00 2001 From: Qian-Hao Huang Date: Tue, 5 Dec 2023 09:36:02 +0000 Subject: [PATCH 126/133] Revert "usb: introduce UsbDataSessionMonitor class" Revert submission 25524752-usbDataSessionMonitor Reason for revert: Test for gs101/gs201 boot blocking issue (b/314904288) Reverted changes: /q/submissionid:25524752-usbDataSessionMonitor Change-Id: I8265d57152460693fe668c2d9d188037dec6e692 --- usb/usb/Android.bp | 1 - usb/usb/Usb.cpp | 306 ++++++++++++++++++---- usb/usb/Usb.h | 34 ++- usb/usb/UsbDataSessionMonitor.cpp | 420 ------------------------------ usb/usb/UsbDataSessionMonitor.h | 114 -------- 5 files changed, 281 insertions(+), 594 deletions(-) delete mode 100644 usb/usb/UsbDataSessionMonitor.cpp delete mode 100644 usb/usb/UsbDataSessionMonitor.h diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index 858fc472..a67e617e 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -34,7 +34,6 @@ cc_binary { srcs: [ "service.cpp", "Usb.cpp", - "UsbDataSessionMonitor.cpp", ], shared_libs: [ "libbase", diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index c0813d9e..e63fa1de 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ #include #include +#include #include #include @@ -56,6 +58,9 @@ using android::base::Trim; using android::hardware::google::pixel::getStatsService; using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat; using android::hardware::google::pixel::reportUsbPortOverheat; +using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; +using android::hardware::google::pixel::reportUsbDataSessionEvent; +using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; namespace aidl { namespace android { @@ -93,22 +98,18 @@ constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_ac constexpr char kPogoEnableUsb[] = "/sys/devices/platform/google,pogo/enable_usb"; constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type"; constexpr char kIrqHpdCounPath[] = "-0025/irq_hpd_count"; -constexpr char kUdcUeventRegex[] = - "/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3"; -constexpr char kUdcStatePath[] = - "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; -constexpr char kHost1UeventRegex[] = - "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb1/1-0:1.0"; -constexpr char kHost1StatePath[] = "/sys/bus/usb/devices/usb1/1-0:1.0/usb1-port1/state"; -constexpr char kHost2UeventRegex[] = - "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb2/2-0:1.0"; -constexpr char kHost2StatePath[] = "/sys/bus/usb/devices/usb2/2-0:1.0/usb2-port1/state"; -constexpr char kDataRolePath[] = "/sys/devices/platform/11210000.usb/new_data_role"; +constexpr char kUdcState[] = "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; +// xhci-hcd-exynos and usb device numbering could vary on different platforms +constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\\.usb/11210000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0"; constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); AltModeData::DisplayPortAltModeData constructAltModeData(string hpd, string pin_assignment, string link_status, string vdo); +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus); + +#define USB_STATE_MAX_LEN 20 ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, int64_t in_transactionId) { @@ -510,20 +511,11 @@ bool switchMode(const string &portName, const PortRole &in_role, struct Usb *usb return roleSwitch; } -void updatePortStatus(android::hardware::usb::Usb *usb) { - std::vector currentPortStatus; - - queryVersionHelper(usb, ¤tPortStatus); -} - Usb::Usb() : mLock(PTHREAD_MUTEX_INITIALIZER), mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), mPartnerLock(PTHREAD_MUTEX_INITIALIZER), mPartnerUp(false), - mUsbDataSessionMonitor(kUdcUeventRegex, kUdcStatePath, kHost1UeventRegex, kHost1StatePath, - kHost2UeventRegex, kHost2StatePath, kDataRolePath, - std::bind(&updatePortStatus, this)), mOverheat(ZoneInfo(TemperatureType::USB_PORT, kThermalZoneForTrip, ThrottlingSeverity::CRITICAL), {ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadPrimary, @@ -1061,18 +1053,6 @@ Status queryDisplayPortStatus(android::hardware::usb::Usb *usb, return Status::SUCCESS; } -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus) { - std::vector warnings; - - usb->mUsbDataSessionMonitor.getComplianceWarnings( - (*currentPortStatus)[0].currentDataRole, &warnings); - (*currentPortStatus)[0].complianceWarnings.insert( - (*currentPortStatus)[0].complianceWarnings.end(), - warnings.begin(), - warnings.end()); -} - void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus) { Status status; @@ -1179,6 +1159,54 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } +void report_usb_data_session_event(android::hardware::usb::Usb *usb) { + std::vector events; + + if (usb->mDataRole == PortDataRole::DEVICE) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(false /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, &usb->mDeviceState.states, + &usb->mDeviceState.timestamps, &event); + events.push_back(event); + } else if (usb->mDataRole == PortDataRole::HOST) { + bool empty = true; + for (auto &entry : usb->mHostStateMap) { + // Host port will at least get an not_attached event after enablement, + // skip upload if no additional state is added. + if (entry.second.states.size() > 1) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, &entry.second.states, + &entry.second.timestamps, &event); + events.push_back(event); + empty = false; + } + } + // All host ports have no state update, upload an event to reflect it + if (empty && usb->mHostStateMap.size() > 0) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, + &usb->mHostStateMap.begin()->second.states, + &usb->mHostStateMap.begin()->second.timestamps, + &event); + events.push_back(event); + } + } else { + return; + } + + const shared_ptr stats_client = getStatsService(); + if (!stats_client) { + ALOGE("Unable to get AIDL Stats service"); + return; + } + + for (auto &event : events) { + reportUsbDataSessionEvent(stats_client, event); + } +} + struct data { int uevent_fd; ::aidl::android::hardware::usb::Usb *usb; @@ -1195,13 +1223,147 @@ enum UeventType matchUeventType(char* str) { return UeventType::UNKNOWN; } -static void uevent_event(uint32_t /*epevents*/, struct data *payload) { +static void unregisterEpollEntry(Usb *usb, std::string name) { + std::map *map; + int fd; + + map = &usb->mEpollEntries; + auto it = map->find(name); + if (it != map->end()) { + ALOGI("epoll unregister %s", name.c_str()); + fd = it->second.payload.fd; + epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL); + close(fd); + map->erase(it); + } +} + +static void unregisterEpollEntries(Usb *usb) { + std::map *map; + std::string name; + + map = &usb->mEpollEntries; + for (auto it = map->begin(); it != map->end();) { + name = it->first; + it++; + unregisterEpollEntry(usb, name); + } +} + +static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags, + void (*func)(uint32_t, struct Usb::payload*)) { + std::map *map; + struct Usb::epollEntry *entry; + struct epoll_event ev; + + map = &usb->mEpollEntries; + if (map->find(name) != map->end()) { + ALOGE("%s already registered", name.c_str()); + unregisterEpollEntry(usb, name); + } + + entry = &(*map)[name]; + entry->payload.fd = fd; + entry->payload.name = name; + entry->payload.usb = usb; + entry->cb = std::bind(func, std::placeholders::_1, &entry->payload); + + ev.events = flags; + ev.data.ptr = (void *)&entry->cb; + + if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) { + ALOGE("epoll_ctl failed; errno=%d", errno); + unregisterEpollEntry(usb, name); + return -1; + } + + ALOGI("epoll register %s", name.c_str()); + + return 0; +} + +static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, + void (*func)(uint32_t, struct Usb::payload*)) { + int fd; + + fd = open(name.c_str(), O_RDONLY); + if (fd < 0) { + ALOGE("Cannot open %s", name.c_str()); + return -1; + } + + return registerEpollEntry(usb, name, fd, flags, func); +} + +static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { + device->states.clear(); + device->timestamps.clear(); + device->portResetCount = 0; +} + +static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { + ALOGI("Update USB device state: %s", state); + + device->states.push_back(state); + device->timestamps.push_back(std::chrono::steady_clock::now()); + + if (!std::strcmp(state, "configured\n")) { + device->portResetCount = 0; + } else if (!std::strcmp(state, "default\n")) { + device->portResetCount++; + } +} + +static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + struct Usb::usbDeviceState *device; + + lseek(payload->fd, 0, SEEK_SET); + n = read(payload->fd, &state, USB_STATE_MAX_LEN); + + updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); +} + +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + PortDataRole newDataRole = (*currentPortStatus)[0].currentDataRole; + PowerBrickStatus newPowerBrickStatus = (*currentPortStatus)[0].powerBrickStatus; + + if (newDataRole != usb->mDataRole) { + // Upload metrics for the last non-powerbrick data session that has ended + if (usb->mDataRole != PortDataRole::NONE && !usb->mIsPowerBrickConnected) { + report_usb_data_session_event(usb); + } + + // Set up for the new data session + usb->mDataRole = newDataRole; + usb->mDataSessionStart = std::chrono::steady_clock::now(); + usb->mIsPowerBrickConnected = (newPowerBrickStatus == PowerBrickStatus::CONNECTED); + if (newDataRole == PortDataRole::DEVICE) { + clearUsbDeviceState(&usb->mDeviceState); + } else if (newDataRole == PortDataRole::HOST) { + for (auto &entry : usb->mHostStateMap) { + clearUsbDeviceState(&entry.second); + } + } + } + + // PowerBrickStatus could flip from DISCONNECTED to CONNECTED during the same data + // session when BC1.2 SDP times out and falls back to DCP + if (newPowerBrickStatus == PowerBrickStatus::CONNECTED) { + usb->mIsPowerBrickConnected = true; + } +} + +static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; int n; enum UeventType uevent_type = UeventType::UNKNOWN; + std::cmatch match; - n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); + n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN); if (n <= 0) return; if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ @@ -1269,6 +1431,28 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) { pthread_mutex_unlock(&payload->usb->mDisplayPortLock); } break; + } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) { + /* + * Matched strings: + * 1st: entire string + * 2nd: uevent action, either "bind" or "unbind" + * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto + * 4th: usb device number, e.g. 1 for usb1 + * + * The strings are used to composed usb device state path, e.g. + * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state + */ + if (match.size() == 4) { + std::string action = match[1].str(); + std::string id = match[3].str(); + std::string path = "/sys" + match[2].str() + "usb" + id + "/" + + id + "-0:1.0/usb" + id + "-port1/state"; + if (action == "bind") { + registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); + } else if (action == "unbind") { + unregisterEpollEntry(payload->usb, path); + } + } } /* advance to after the next \0 */ while (*cp++) { @@ -1276,37 +1460,46 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) { } } +static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + + lseek(payload->fd, 0, SEEK_SET); + n = read(payload->fd, &state, USB_STATE_MAX_LEN); + + updateUsbDeviceState(&payload->usb->mDeviceState, state); +} + void *work(void *param) { int epoll_fd, uevent_fd; - struct epoll_event ev; int nevents = 0; - struct data payload; + Usb *usb = (Usb *)param; ALOGE("creating thread"); - uevent_fd = uevent_open_socket(64 * 1024, true); - - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed\n"); - return NULL; - } - - payload.uevent_fd = uevent_fd; - payload.usb = (::aidl::android::hardware::usb::Usb *)param; - - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - ev.events = EPOLLIN; - ev.data.ptr = (void *)uevent_event; - epoll_fd = epoll_create(64); if (epoll_fd == -1) { ALOGE("epoll_create failed; errno=%d", errno); + return NULL; + } + usb->mEpollFd = epoll_fd; + + // Monitor uevent + uevent_fd = uevent_open_socket(64 * 1024, true); + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed"); + goto error; + } + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) { + ALOGE("failed to monitor uevent"); goto error; } - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { - ALOGE("epoll_ctl failed; errno=%d", errno); + // Monitor udc state + if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) { + ALOGE("failed to monitor udc state"); goto error; } @@ -1323,14 +1516,15 @@ void *work(void *param) { for (int n = 0; n < nevents; ++n) { if (events[n].data.ptr) - (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events, - &payload); + (*(std::function*)events[n].data.ptr)(events[n].events); } } ALOGI("exiting worker thread"); error: - close(uevent_fd); + unregisterEpollEntries(usb); + + usb->mEpollFd = -1; if (epoll_fd >= 0) close(epoll_fd); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 4d9ab538..c1e53541 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,10 +19,10 @@ #include #include #include +#include #include #include #include -#include #define UEVENT_MSG_LEN 2048 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. @@ -121,8 +121,6 @@ struct Usb : public BnUsb { // Variable to signal partner coming back online after type switch bool mPartnerUp; - // Report usb data session event and data incompliance warnings - UsbDataSessionMonitor mUsbDataSessionMonitor; // Usb Overheat object for push suez event UsbOverheatEvent mOverheat; // Temperature when connected @@ -145,6 +143,36 @@ struct Usb : public BnUsb { // eventfd to signal DisplayPort thread int mDisplayPortEventPipe; + // USB device state monitoring + struct usbDeviceState { + // Usb device state raw strings read from sysfs + std::vector states; + // Timestamps of when the usb device states were captured + std::vector timestamps; + int portResetCount; + }; + struct usbDeviceState mDeviceState; + // Map host device path name to usbDeviceState + std::map mHostStateMap; + // Cache relevant info for USB data session metrics collection when a session starts, including + // the data role, power brick status and the time when the session starts. + PortDataRole mDataRole; + bool mIsPowerBrickConnected; + std::chrono::steady_clock::time_point mDataSessionStart; + + // File monitoring through epoll + int mEpollFd; + struct payload { + int fd; + std::string name; + Usb *usb; + }; + struct epollEntry { + struct payload payload; + std::function cb; + }; + std::map mEpollEntries; + /* * eventfd to set DisplayPort framework update debounce timer. Debounce timer is necessary for * 1) allowing enough time for each sysfs node needed to set HPD high in the drm to populate diff --git a/usb/usb/UsbDataSessionMonitor.cpp b/usb/usb/UsbDataSessionMonitor.cpp deleted file mode 100644 index 77defb30..00000000 --- a/usb/usb/UsbDataSessionMonitor.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "android.hardware.usb.aidl-service.UsbDataSessionMonitor" - -#include "UsbDataSessionMonitor.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace usb_flags = android::hardware::usb::flags; - -using aidl::android::frameworks::stats::IStats; -using android::base::ReadFileToString; -using android::hardware::google::pixel::getStatsService; -using android::hardware::google::pixel::reportUsbDataSessionEvent; -using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; -using android::hardware::google::pixel::usb::addEpollFd; -using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; - -namespace aidl { -namespace android { -namespace hardware { -namespace usb { - -#define UEVENT_MSG_LEN 2048 -#define USB_STATE_MAX_LEN 20 -#define DATA_ROLE_MAX_LEN 10 - -constexpr char kUdcConfigfsPath[] = "/config/usb_gadget/g1/UDC"; -constexpr char kNotAttachedState[] = "not attached\n"; -constexpr char kAttachedState[] = "attached\n"; -constexpr char kPoweredState[] = "powered\n"; -constexpr char kDefaultState[] = "default\n"; -constexpr char kAddressedState[] = "addressed\n"; -constexpr char kConfiguredState[] = "configured\n"; -constexpr char kSuspendedState[] = "suspended\n"; -const std::set kValidStates = {kNotAttachedState, kAttachedState, kPoweredState, - kDefaultState, kAddressedState, kConfiguredState, - kSuspendedState}; - -static int addEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { - struct epoll_event ev; - - unique_fd fd(open(filePath.c_str(), O_RDONLY)); - - if (fd.get() == -1) { - ALOGI("Cannot open %s", filePath.c_str()); - return -1; - } - - ev.data.fd = fd.get(); - ev.events = EPOLLPRI; - - if (epoll_ctl(epollFd, EPOLL_CTL_ADD, fd.get(), &ev) != 0) { - ALOGE("epoll_ctl failed; errno=%d", errno); - return -1; - } - - fileFd = std::move(fd); - ALOGI("epoll registered %s", filePath.c_str()); - return 0; -} - -static void removeEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { - epoll_ctl(epollFd, EPOLL_CTL_DEL, fileFd.get(), NULL); - fileFd.release(); - - ALOGI("epoll unregistered %s", filePath.c_str()); -} - -UsbDataSessionMonitor::UsbDataSessionMonitor( - const std::string &deviceUeventRegex, const std::string &deviceStatePath, - const std::string &host1UeventRegex, const std::string &host1StatePath, - const std::string &host2UeventRegex, const std::string &host2StatePath, - const std::string &dataRolePath, std::function updatePortStatusCb) { - struct epoll_event ev; - std::string udc; - - unique_fd epollFd(epoll_create(8)); - if (epollFd.get() == -1) { - ALOGE("epoll_create failed; errno=%d", errno); - abort(); - } - - unique_fd ueventFd(uevent_open_socket(64 * 1024, true)); - if (ueventFd.get() == -1) { - ALOGE("uevent_open_socket failed"); - abort(); - } - fcntl(ueventFd, F_SETFL, O_NONBLOCK); - - if (addEpollFd(epollFd, ueventFd)) - abort(); - - if (addEpollFile(epollFd.get(), dataRolePath, mDataRoleFd) != 0) { - ALOGE("monitor data role failed"); - abort(); - } - - /* - * The device state file could be absent depending on the current data role - * and driver architecture. It's ok for addEpollFile to fail here, the file - * will be monitored later when its presence is detected by uevent. - */ - mDeviceState.filePath = deviceStatePath; - mDeviceState.ueventRegex = deviceUeventRegex; - addEpollFile(epollFd.get(), mDeviceState.filePath, mDeviceState.fd); - - mHost1State.filePath = host1StatePath; - mHost1State.ueventRegex = host1UeventRegex; - addEpollFile(epollFd.get(), mHost1State.filePath, mHost1State.fd); - - mHost2State.filePath = host2StatePath; - mHost2State.ueventRegex = host2UeventRegex; - addEpollFile(epollFd.get(), mHost2State.filePath, mHost2State.fd); - - mEpollFd = std::move(epollFd); - mUeventFd = std::move(ueventFd); - mUpdatePortStatusCb = updatePortStatusCb; - - if (ReadFileToString(kUdcConfigfsPath, &udc) && !udc.empty()) - mUdcBind = true; - else - mUdcBind = false; - - if (pthread_create(&mMonitor, NULL, this->monitorThread, this)) { - ALOGE("pthread creation failed %d", errno); - abort(); - } -} - -UsbDataSessionMonitor::~UsbDataSessionMonitor() {} - -void UsbDataSessionMonitor::reportUsbDataSessionMetrics() { - std::vector events; - - if (mDataRole == PortDataRole::DEVICE) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(false /* is_host */, boot_clock::now(), mDataSessionStart, - &mDeviceState.states, &mDeviceState.timestamps, &event); - events.push_back(event); - } else if (mDataRole == PortDataRole::HOST) { - bool empty = true; - for (auto e : {&mHost1State, &mHost2State}) { - /* - * Host port will at least get an not_attached event after enablement, - * skip upload if no additional state is added. - */ - if (e->states.size() > 1) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), - mDataSessionStart, &e->states, &e->timestamps, - &event); - events.push_back(event); - empty = false; - } - } - // All host ports have no state update, upload an event to reflect it - if (empty) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), mDataSessionStart, - &mHost1State.states, &mHost1State.timestamps, &event); - events.push_back(event); - } - } else { - return; - } - - const std::shared_ptr stats_client = getStatsService(); - if (!stats_client) { - ALOGE("Unable to get AIDL Stats service"); - return; - } - - for (auto &event : events) { - reportUsbDataSessionEvent(stats_client, event); - } -} - -void UsbDataSessionMonitor::getComplianceWarnings(const PortDataRole &role, - std::vector *warnings) { - if (!usb_flags::enable_report_usb_data_compliance_warning()) - return; - - if (role != mDataRole || role == PortDataRole::NONE) - return; - - for (auto w : mWarningSet) { - warnings->push_back(w); - } -} - -void UsbDataSessionMonitor::notifyComplianceWarning() { - if (!usb_flags::enable_report_usb_data_compliance_warning()) - return; - - if (mUpdatePortStatusCb) - mUpdatePortStatusCb(); -} - -void UsbDataSessionMonitor::evaluateComplianceWarning() { - std::set newWarningSet; - - // TODO: add heuristics and update newWarningSet - if (mDataRole == PortDataRole::DEVICE && mUdcBind) { - } else if (mDataRole == PortDataRole::HOST) { - } - - if (newWarningSet != mWarningSet) { - mWarningSet = newWarningSet; - notifyComplianceWarning(); - } -} - -void UsbDataSessionMonitor::clearDeviceStateEvents(struct usbDeviceState *deviceState) { - deviceState->states.clear(); - deviceState->timestamps.clear(); -} - -void UsbDataSessionMonitor::handleDeviceStateEvent(struct usbDeviceState *deviceState) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - - lseek(deviceState->fd.get(), 0, SEEK_SET); - n = read(deviceState->fd.get(), &state, USB_STATE_MAX_LEN); - - if (kValidStates.find(state) == kValidStates.end()) { - ALOGE("Invalid state %s", state); - return; - } - - ALOGI("Update USB device state: %s", state); - - deviceState->states.push_back(state); - deviceState->timestamps.push_back(boot_clock::now()); - evaluateComplianceWarning(); -} - -void UsbDataSessionMonitor::handleDataRoleEvent() { - int n; - PortDataRole newDataRole; - char role[DATA_ROLE_MAX_LEN] = {0}; - - lseek(mDataRoleFd.get(), 0, SEEK_SET); - n = read(mDataRoleFd.get(), &role, DATA_ROLE_MAX_LEN); - - ALOGI("Update USB data role %s", role); - - if (!std::strcmp(role, "host")) { - newDataRole = PortDataRole::HOST; - } else if (!std::strcmp(role, "device")) { - newDataRole = PortDataRole::DEVICE; - } else { - newDataRole = PortDataRole::NONE; - } - - if (newDataRole != mDataRole) { - // Upload metrics for the last data session that has ended - if (mDataRole == PortDataRole::HOST || (mDataRole == PortDataRole::DEVICE && mUdcBind)) { - reportUsbDataSessionMetrics(); - } - - // Set up for the new data session - mWarningSet.clear(); - mDataRole = newDataRole; - mDataSessionStart = boot_clock::now(); - - if (newDataRole == PortDataRole::DEVICE) { - clearDeviceStateEvents(&mDeviceState); - } else if (newDataRole == PortDataRole::HOST) { - clearDeviceStateEvents(&mHost1State); - clearDeviceStateEvents(&mHost2State); - } - } -} - -void UsbDataSessionMonitor::updateUdcBindStatus(const std::string &devname) { - std::string function; - bool newUdcBind; - - /* - * /sys/class/udc//function prints out name of currently running USB gadget driver - * Ref: https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-udc - * Empty name string means the udc device is not bound and gadget is pulldown. - */ - if (!ReadFileToString("/sys" + devname + "/function", &function)) - return; - - if (function == "") - newUdcBind = false; - else - newUdcBind = true; - - if (newUdcBind == mUdcBind) - return; - - if (mDataRole == PortDataRole::DEVICE) { - if (mUdcBind && !newUdcBind) { - /* - * Gadget soft pulldown: report metrics as the end of a data session and - * re-evaluate compliance warnings to clear existing warnings if any. - */ - reportUsbDataSessionMetrics(); - evaluateComplianceWarning(); - - } else if (!mUdcBind && newUdcBind) { - // Gadget soft pullup: reset and start accounting for a new data session. - clearDeviceStateEvents(&mDeviceState); - mDataSessionStart = boot_clock::now(); - } - } - - ALOGI("Udc bind status changes from %b to %b", mUdcBind, newUdcBind); - mUdcBind = newUdcBind; -} - -void UsbDataSessionMonitor::handleUevent() { - char msg[UEVENT_MSG_LEN + 2]; - char *cp; - int n; - - n = uevent_kernel_multicast_recv(mUeventFd.get(), msg, UEVENT_MSG_LEN); - if (n <= 0) - return; - if (n >= UEVENT_MSG_LEN) - return; - - msg[n] = '\0'; - msg[n + 1] = '\0'; - cp = msg; - - while (*cp) { - for (auto e : {&mHost1State, &mHost2State}) { - if (std::regex_search(cp, std::regex(e->ueventRegex))) { - if (!strncmp(cp, "bind@", strlen("bind@"))) { - addEpollFile(mEpollFd.get(), e->filePath, e->fd); - } else if (!strncmp(cp, "unbind@", strlen("unbind@"))) { - removeEpollFile(mEpollFd.get(), e->filePath, e->fd); - } - } - } - - // TODO: support bind@ unbind@ to detect dynamically allocated udc device - if (std::regex_search(cp, std::regex(mDeviceState.ueventRegex))) { - if (!strncmp(cp, "change@", strlen("change@"))) { - char *devname = cp + strlen("change@"); - /* - * Udc device emits a KOBJ_CHANGE event on configfs driver bind and unbind. - * TODO: upstream udc driver emits KOBJ_CHANGE event BEFORE unbind is actually - * executed. Add a short delay to get the correct state while working on a fix - * upstream. - */ - usleep(50000); - updateUdcBindStatus(devname); - } - } - /* advance to after the next \0 */ - while (*cp++) { - } - } -} - -void *UsbDataSessionMonitor::monitorThread(void *param) { - UsbDataSessionMonitor *monitor = (UsbDataSessionMonitor *)param; - struct epoll_event events[64]; - int nevents = 0; - - while (true) { - nevents = epoll_wait(monitor->mEpollFd.get(), events, 64, -1); - if (nevents == -1) { - if (errno == EINTR) - continue; - ALOGE("usb epoll_wait failed; errno=%d", errno); - break; - } - - for (int n = 0; n < nevents; ++n) { - if (events[n].data.fd == monitor->mUeventFd.get()) { - monitor->handleUevent(); - } else if (events[n].data.fd == monitor->mDataRoleFd.get()) { - monitor->handleDataRoleEvent(); - } else if (events[n].data.fd == monitor->mDeviceState.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mDeviceState); - } else if (events[n].data.fd == monitor->mHost1State.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mHost1State); - } else if (events[n].data.fd == monitor->mHost2State.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mHost2State); - } - } - } - return NULL; -} - -} // namespace usb -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/usb/usb/UsbDataSessionMonitor.h b/usb/usb/UsbDataSessionMonitor.h deleted file mode 100644 index 596f378f..00000000 --- a/usb/usb/UsbDataSessionMonitor.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include - -namespace aidl { -namespace android { -namespace hardware { -namespace usb { - -using ::aidl::android::hardware::usb::ComplianceWarning; -using ::aidl::android::hardware::usb::PortDataRole; -using ::android::base::boot_clock; -using ::android::base::unique_fd; - -/* - * UsbDataSessionMonitor monitors the usb device state sysfs of 3 different usb devices - * including device mode (udc), host mode high-speed port and host mode super-speed port. It - * reports Suez metrics for each data session and also provides API to query the compliance - * warnings detected in the current usb data session. - */ -class UsbDataSessionMonitor { - public: - /* - * The host mode high-speed port and super-speed port can be assigned to either host1 or - * host2 without affecting functionality. - * - * UeventRegex: name regex of the device that's being monitored. The regex is matched against - * uevent to detect dynamic creation/deletion/change of the device. - * StatePath: usb device state sysfs path of the device, monitored by epoll. - * dataRolePath: path to the usb data role sysfs, monitored by epoll. - * updatePortStatusCb: the callback is invoked when the compliance warings changes. - */ - UsbDataSessionMonitor(const std::string &deviceUeventRegex, const std::string &deviceStatePath, - const std::string &host1UeventRegex, const std::string &host1StatePath, - const std::string &host2UeventRegex, const std::string &host2StatePath, - const std::string &dataRolePath, - std::function updatePortStatusCb); - ~UsbDataSessionMonitor(); - // Returns the compliance warnings detected in the current data session. - void getComplianceWarnings(const PortDataRole &role, std::vector *warnings); - - private: - struct usbDeviceState { - unique_fd fd; - std::string filePath; - std::string ueventRegex; - // Usb device states reported by state sysfs - std::vector states; - // Timestamps of when the usb device states were captured - std::vector timestamps; - }; - - static void *monitorThread(void *param); - void handleUevent(); - void handleDataRoleEvent(); - void handleDeviceStateEvent(struct usbDeviceState *deviceState); - void clearDeviceStateEvents(struct usbDeviceState *deviceState); - void reportUsbDataSessionMetrics(); - void evaluateComplianceWarning(); - void notifyComplianceWarning(); - void updateUdcBindStatus(const std::string &devname); - - pthread_t mMonitor; - unique_fd mEpollFd; - unique_fd mUeventFd; - unique_fd mDataRoleFd; - struct usbDeviceState mDeviceState; - struct usbDeviceState mHost1State; - struct usbDeviceState mHost2State; - std::set mWarningSet; - // Callback function to notify the caller when there's a change in compliance warnings. - std::function mUpdatePortStatusCb; - /* - * Cache relevant info for a USB data session when one starts, including - * the data role and the time when the session starts. - */ - PortDataRole mDataRole; - boot_clock::time_point mDataSessionStart; - /* - * In gadget mode: this indicates whether the udc device is bound to the configfs driver, which - * is done by userspace writing the udc device name to /config/usb_gadget/g1/UDC. When unbound, - * the gadget is in soft pulldown state and is expected not to enumerate. During gadget - * function switch, the udc device usually go through unbind and bind. - */ - bool mUdcBind; -}; - -} // namespace usb -} // namespace hardware -} // namespace android -} // namespace aidl From 09f98e2ed68e97444a206e1f4beee75fef64e595 Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Fri, 8 Dec 2023 15:35:14 +0000 Subject: [PATCH 127/133] Revert^2 "usb: introduce UsbDataSessionMonitor class" 3e5743c5218e79683748c28ff134809583af3203 Bug: 297224564 Bug: 296119135 Change-Id: I4fc7da8c628292bb2c702c6fd3f059202e6ca82b --- usb/usb/Android.bp | 1 + usb/usb/Usb.cpp | 306 ++++------------------ usb/usb/Usb.h | 34 +-- usb/usb/UsbDataSessionMonitor.cpp | 420 ++++++++++++++++++++++++++++++ usb/usb/UsbDataSessionMonitor.h | 114 ++++++++ 5 files changed, 594 insertions(+), 281 deletions(-) create mode 100644 usb/usb/UsbDataSessionMonitor.cpp create mode 100644 usb/usb/UsbDataSessionMonitor.h diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index a67e617e..858fc472 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -34,6 +34,7 @@ cc_binary { srcs: [ "service.cpp", "Usb.cpp", + "UsbDataSessionMonitor.cpp", ], shared_libs: [ "libbase", diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index e63fa1de..c0813d9e 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -43,7 +42,6 @@ #include #include -#include #include #include @@ -58,9 +56,6 @@ using android::base::Trim; using android::hardware::google::pixel::getStatsService; using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat; using android::hardware::google::pixel::reportUsbPortOverheat; -using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; -using android::hardware::google::pixel::reportUsbDataSessionEvent; -using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; namespace aidl { namespace android { @@ -98,18 +93,22 @@ constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_ac constexpr char kPogoEnableUsb[] = "/sys/devices/platform/google,pogo/enable_usb"; constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type"; constexpr char kIrqHpdCounPath[] = "-0025/irq_hpd_count"; -constexpr char kUdcState[] = "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; -// xhci-hcd-exynos and usb device numbering could vary on different platforms -constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\\.usb/11210000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0"; +constexpr char kUdcUeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3"; +constexpr char kUdcStatePath[] = + "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; +constexpr char kHost1UeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb1/1-0:1.0"; +constexpr char kHost1StatePath[] = "/sys/bus/usb/devices/usb1/1-0:1.0/usb1-port1/state"; +constexpr char kHost2UeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb2/2-0:1.0"; +constexpr char kHost2StatePath[] = "/sys/bus/usb/devices/usb2/2-0:1.0/usb2-port1/state"; +constexpr char kDataRolePath[] = "/sys/devices/platform/11210000.usb/new_data_role"; constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); AltModeData::DisplayPortAltModeData constructAltModeData(string hpd, string pin_assignment, string link_status, string vdo); -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus); - -#define USB_STATE_MAX_LEN 20 ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable, int64_t in_transactionId) { @@ -511,11 +510,20 @@ bool switchMode(const string &portName, const PortRole &in_role, struct Usb *usb return roleSwitch; } +void updatePortStatus(android::hardware::usb::Usb *usb) { + std::vector currentPortStatus; + + queryVersionHelper(usb, ¤tPortStatus); +} + Usb::Usb() : mLock(PTHREAD_MUTEX_INITIALIZER), mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), mPartnerLock(PTHREAD_MUTEX_INITIALIZER), mPartnerUp(false), + mUsbDataSessionMonitor(kUdcUeventRegex, kUdcStatePath, kHost1UeventRegex, kHost1StatePath, + kHost2UeventRegex, kHost2StatePath, kDataRolePath, + std::bind(&updatePortStatus, this)), mOverheat(ZoneInfo(TemperatureType::USB_PORT, kThermalZoneForTrip, ThrottlingSeverity::CRITICAL), {ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadPrimary, @@ -1053,6 +1061,18 @@ Status queryDisplayPortStatus(android::hardware::usb::Usb *usb, return Status::SUCCESS; } +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + std::vector warnings; + + usb->mUsbDataSessionMonitor.getComplianceWarnings( + (*currentPortStatus)[0].currentDataRole, &warnings); + (*currentPortStatus)[0].complianceWarnings.insert( + (*currentPortStatus)[0].complianceWarnings.end(), + warnings.begin(), + warnings.end()); +} + void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus) { Status status; @@ -1159,54 +1179,6 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } -void report_usb_data_session_event(android::hardware::usb::Usb *usb) { - std::vector events; - - if (usb->mDataRole == PortDataRole::DEVICE) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(false /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, &usb->mDeviceState.states, - &usb->mDeviceState.timestamps, &event); - events.push_back(event); - } else if (usb->mDataRole == PortDataRole::HOST) { - bool empty = true; - for (auto &entry : usb->mHostStateMap) { - // Host port will at least get an not_attached event after enablement, - // skip upload if no additional state is added. - if (entry.second.states.size() > 1) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, &entry.second.states, - &entry.second.timestamps, &event); - events.push_back(event); - empty = false; - } - } - // All host ports have no state update, upload an event to reflect it - if (empty && usb->mHostStateMap.size() > 0) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, - &usb->mHostStateMap.begin()->second.states, - &usb->mHostStateMap.begin()->second.timestamps, - &event); - events.push_back(event); - } - } else { - return; - } - - const shared_ptr stats_client = getStatsService(); - if (!stats_client) { - ALOGE("Unable to get AIDL Stats service"); - return; - } - - for (auto &event : events) { - reportUsbDataSessionEvent(stats_client, event); - } -} - struct data { int uevent_fd; ::aidl::android::hardware::usb::Usb *usb; @@ -1223,147 +1195,13 @@ enum UeventType matchUeventType(char* str) { return UeventType::UNKNOWN; } -static void unregisterEpollEntry(Usb *usb, std::string name) { - std::map *map; - int fd; - - map = &usb->mEpollEntries; - auto it = map->find(name); - if (it != map->end()) { - ALOGI("epoll unregister %s", name.c_str()); - fd = it->second.payload.fd; - epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL); - close(fd); - map->erase(it); - } -} - -static void unregisterEpollEntries(Usb *usb) { - std::map *map; - std::string name; - - map = &usb->mEpollEntries; - for (auto it = map->begin(); it != map->end();) { - name = it->first; - it++; - unregisterEpollEntry(usb, name); - } -} - -static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags, - void (*func)(uint32_t, struct Usb::payload*)) { - std::map *map; - struct Usb::epollEntry *entry; - struct epoll_event ev; - - map = &usb->mEpollEntries; - if (map->find(name) != map->end()) { - ALOGE("%s already registered", name.c_str()); - unregisterEpollEntry(usb, name); - } - - entry = &(*map)[name]; - entry->payload.fd = fd; - entry->payload.name = name; - entry->payload.usb = usb; - entry->cb = std::bind(func, std::placeholders::_1, &entry->payload); - - ev.events = flags; - ev.data.ptr = (void *)&entry->cb; - - if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) { - ALOGE("epoll_ctl failed; errno=%d", errno); - unregisterEpollEntry(usb, name); - return -1; - } - - ALOGI("epoll register %s", name.c_str()); - - return 0; -} - -static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, - void (*func)(uint32_t, struct Usb::payload*)) { - int fd; - - fd = open(name.c_str(), O_RDONLY); - if (fd < 0) { - ALOGE("Cannot open %s", name.c_str()); - return -1; - } - - return registerEpollEntry(usb, name, fd, flags, func); -} - -static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { - device->states.clear(); - device->timestamps.clear(); - device->portResetCount = 0; -} - -static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { - ALOGI("Update USB device state: %s", state); - - device->states.push_back(state); - device->timestamps.push_back(std::chrono::steady_clock::now()); - - if (!std::strcmp(state, "configured\n")) { - device->portResetCount = 0; - } else if (!std::strcmp(state, "default\n")) { - device->portResetCount++; - } -} - -static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - struct Usb::usbDeviceState *device; - - lseek(payload->fd, 0, SEEK_SET); - n = read(payload->fd, &state, USB_STATE_MAX_LEN); - - updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); -} - -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus) { - PortDataRole newDataRole = (*currentPortStatus)[0].currentDataRole; - PowerBrickStatus newPowerBrickStatus = (*currentPortStatus)[0].powerBrickStatus; - - if (newDataRole != usb->mDataRole) { - // Upload metrics for the last non-powerbrick data session that has ended - if (usb->mDataRole != PortDataRole::NONE && !usb->mIsPowerBrickConnected) { - report_usb_data_session_event(usb); - } - - // Set up for the new data session - usb->mDataRole = newDataRole; - usb->mDataSessionStart = std::chrono::steady_clock::now(); - usb->mIsPowerBrickConnected = (newPowerBrickStatus == PowerBrickStatus::CONNECTED); - if (newDataRole == PortDataRole::DEVICE) { - clearUsbDeviceState(&usb->mDeviceState); - } else if (newDataRole == PortDataRole::HOST) { - for (auto &entry : usb->mHostStateMap) { - clearUsbDeviceState(&entry.second); - } - } - } - - // PowerBrickStatus could flip from DISCONNECTED to CONNECTED during the same data - // session when BC1.2 SDP times out and falls back to DCP - if (newPowerBrickStatus == PowerBrickStatus::CONNECTED) { - usb->mIsPowerBrickConnected = true; - } -} - -static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { +static void uevent_event(uint32_t /*epevents*/, struct data *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; int n; enum UeventType uevent_type = UeventType::UNKNOWN; - std::cmatch match; - n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN); + n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); if (n <= 0) return; if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ @@ -1431,28 +1269,6 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { pthread_mutex_unlock(&payload->usb->mDisplayPortLock); } break; - } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) { - /* - * Matched strings: - * 1st: entire string - * 2nd: uevent action, either "bind" or "unbind" - * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto - * 4th: usb device number, e.g. 1 for usb1 - * - * The strings are used to composed usb device state path, e.g. - * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state - */ - if (match.size() == 4) { - std::string action = match[1].str(); - std::string id = match[3].str(); - std::string path = "/sys" + match[2].str() + "usb" + id + "/" + - id + "-0:1.0/usb" + id + "-port1/state"; - if (action == "bind") { - registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); - } else if (action == "unbind") { - unregisterEpollEntry(payload->usb, path); - } - } } /* advance to after the next \0 */ while (*cp++) { @@ -1460,46 +1276,37 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { } } -static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - - lseek(payload->fd, 0, SEEK_SET); - n = read(payload->fd, &state, USB_STATE_MAX_LEN); - - updateUsbDeviceState(&payload->usb->mDeviceState, state); -} - void *work(void *param) { int epoll_fd, uevent_fd; + struct epoll_event ev; int nevents = 0; - Usb *usb = (Usb *)param; + struct data payload; ALOGE("creating thread"); + uevent_fd = uevent_open_socket(64 * 1024, true); + + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed\n"); + return NULL; + } + + payload.uevent_fd = uevent_fd; + payload.usb = (::aidl::android::hardware::usb::Usb *)param; + + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + ev.events = EPOLLIN; + ev.data.ptr = (void *)uevent_event; + epoll_fd = epoll_create(64); if (epoll_fd == -1) { ALOGE("epoll_create failed; errno=%d", errno); - return NULL; - } - usb->mEpollFd = epoll_fd; - - // Monitor uevent - uevent_fd = uevent_open_socket(64 * 1024, true); - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed"); - goto error; - } - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) { - ALOGE("failed to monitor uevent"); goto error; } - // Monitor udc state - if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) { - ALOGE("failed to monitor udc state"); + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { + ALOGE("epoll_ctl failed; errno=%d", errno); goto error; } @@ -1516,15 +1323,14 @@ void *work(void *param) { for (int n = 0; n < nevents; ++n) { if (events[n].data.ptr) - (*(std::function*)events[n].data.ptr)(events[n].events); + (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events, + &payload); } } ALOGI("exiting worker thread"); error: - unregisterEpollEntries(usb); - - usb->mEpollFd = -1; + close(uevent_fd); if (epoll_fd >= 0) close(epoll_fd); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index c1e53541..4d9ab538 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,10 +19,10 @@ #include #include #include -#include #include #include #include +#include #define UEVENT_MSG_LEN 2048 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. @@ -121,6 +121,8 @@ struct Usb : public BnUsb { // Variable to signal partner coming back online after type switch bool mPartnerUp; + // Report usb data session event and data incompliance warnings + UsbDataSessionMonitor mUsbDataSessionMonitor; // Usb Overheat object for push suez event UsbOverheatEvent mOverheat; // Temperature when connected @@ -143,36 +145,6 @@ struct Usb : public BnUsb { // eventfd to signal DisplayPort thread int mDisplayPortEventPipe; - // USB device state monitoring - struct usbDeviceState { - // Usb device state raw strings read from sysfs - std::vector states; - // Timestamps of when the usb device states were captured - std::vector timestamps; - int portResetCount; - }; - struct usbDeviceState mDeviceState; - // Map host device path name to usbDeviceState - std::map mHostStateMap; - // Cache relevant info for USB data session metrics collection when a session starts, including - // the data role, power brick status and the time when the session starts. - PortDataRole mDataRole; - bool mIsPowerBrickConnected; - std::chrono::steady_clock::time_point mDataSessionStart; - - // File monitoring through epoll - int mEpollFd; - struct payload { - int fd; - std::string name; - Usb *usb; - }; - struct epollEntry { - struct payload payload; - std::function cb; - }; - std::map mEpollEntries; - /* * eventfd to set DisplayPort framework update debounce timer. Debounce timer is necessary for * 1) allowing enough time for each sysfs node needed to set HPD high in the drm to populate diff --git a/usb/usb/UsbDataSessionMonitor.cpp b/usb/usb/UsbDataSessionMonitor.cpp new file mode 100644 index 00000000..77defb30 --- /dev/null +++ b/usb/usb/UsbDataSessionMonitor.cpp @@ -0,0 +1,420 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.usb.aidl-service.UsbDataSessionMonitor" + +#include "UsbDataSessionMonitor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace usb_flags = android::hardware::usb::flags; + +using aidl::android::frameworks::stats::IStats; +using android::base::ReadFileToString; +using android::hardware::google::pixel::getStatsService; +using android::hardware::google::pixel::reportUsbDataSessionEvent; +using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; +using android::hardware::google::pixel::usb::addEpollFd; +using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; + +namespace aidl { +namespace android { +namespace hardware { +namespace usb { + +#define UEVENT_MSG_LEN 2048 +#define USB_STATE_MAX_LEN 20 +#define DATA_ROLE_MAX_LEN 10 + +constexpr char kUdcConfigfsPath[] = "/config/usb_gadget/g1/UDC"; +constexpr char kNotAttachedState[] = "not attached\n"; +constexpr char kAttachedState[] = "attached\n"; +constexpr char kPoweredState[] = "powered\n"; +constexpr char kDefaultState[] = "default\n"; +constexpr char kAddressedState[] = "addressed\n"; +constexpr char kConfiguredState[] = "configured\n"; +constexpr char kSuspendedState[] = "suspended\n"; +const std::set kValidStates = {kNotAttachedState, kAttachedState, kPoweredState, + kDefaultState, kAddressedState, kConfiguredState, + kSuspendedState}; + +static int addEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { + struct epoll_event ev; + + unique_fd fd(open(filePath.c_str(), O_RDONLY)); + + if (fd.get() == -1) { + ALOGI("Cannot open %s", filePath.c_str()); + return -1; + } + + ev.data.fd = fd.get(); + ev.events = EPOLLPRI; + + if (epoll_ctl(epollFd, EPOLL_CTL_ADD, fd.get(), &ev) != 0) { + ALOGE("epoll_ctl failed; errno=%d", errno); + return -1; + } + + fileFd = std::move(fd); + ALOGI("epoll registered %s", filePath.c_str()); + return 0; +} + +static void removeEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { + epoll_ctl(epollFd, EPOLL_CTL_DEL, fileFd.get(), NULL); + fileFd.release(); + + ALOGI("epoll unregistered %s", filePath.c_str()); +} + +UsbDataSessionMonitor::UsbDataSessionMonitor( + const std::string &deviceUeventRegex, const std::string &deviceStatePath, + const std::string &host1UeventRegex, const std::string &host1StatePath, + const std::string &host2UeventRegex, const std::string &host2StatePath, + const std::string &dataRolePath, std::function updatePortStatusCb) { + struct epoll_event ev; + std::string udc; + + unique_fd epollFd(epoll_create(8)); + if (epollFd.get() == -1) { + ALOGE("epoll_create failed; errno=%d", errno); + abort(); + } + + unique_fd ueventFd(uevent_open_socket(64 * 1024, true)); + if (ueventFd.get() == -1) { + ALOGE("uevent_open_socket failed"); + abort(); + } + fcntl(ueventFd, F_SETFL, O_NONBLOCK); + + if (addEpollFd(epollFd, ueventFd)) + abort(); + + if (addEpollFile(epollFd.get(), dataRolePath, mDataRoleFd) != 0) { + ALOGE("monitor data role failed"); + abort(); + } + + /* + * The device state file could be absent depending on the current data role + * and driver architecture. It's ok for addEpollFile to fail here, the file + * will be monitored later when its presence is detected by uevent. + */ + mDeviceState.filePath = deviceStatePath; + mDeviceState.ueventRegex = deviceUeventRegex; + addEpollFile(epollFd.get(), mDeviceState.filePath, mDeviceState.fd); + + mHost1State.filePath = host1StatePath; + mHost1State.ueventRegex = host1UeventRegex; + addEpollFile(epollFd.get(), mHost1State.filePath, mHost1State.fd); + + mHost2State.filePath = host2StatePath; + mHost2State.ueventRegex = host2UeventRegex; + addEpollFile(epollFd.get(), mHost2State.filePath, mHost2State.fd); + + mEpollFd = std::move(epollFd); + mUeventFd = std::move(ueventFd); + mUpdatePortStatusCb = updatePortStatusCb; + + if (ReadFileToString(kUdcConfigfsPath, &udc) && !udc.empty()) + mUdcBind = true; + else + mUdcBind = false; + + if (pthread_create(&mMonitor, NULL, this->monitorThread, this)) { + ALOGE("pthread creation failed %d", errno); + abort(); + } +} + +UsbDataSessionMonitor::~UsbDataSessionMonitor() {} + +void UsbDataSessionMonitor::reportUsbDataSessionMetrics() { + std::vector events; + + if (mDataRole == PortDataRole::DEVICE) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(false /* is_host */, boot_clock::now(), mDataSessionStart, + &mDeviceState.states, &mDeviceState.timestamps, &event); + events.push_back(event); + } else if (mDataRole == PortDataRole::HOST) { + bool empty = true; + for (auto e : {&mHost1State, &mHost2State}) { + /* + * Host port will at least get an not_attached event after enablement, + * skip upload if no additional state is added. + */ + if (e->states.size() > 1) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), + mDataSessionStart, &e->states, &e->timestamps, + &event); + events.push_back(event); + empty = false; + } + } + // All host ports have no state update, upload an event to reflect it + if (empty) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), mDataSessionStart, + &mHost1State.states, &mHost1State.timestamps, &event); + events.push_back(event); + } + } else { + return; + } + + const std::shared_ptr stats_client = getStatsService(); + if (!stats_client) { + ALOGE("Unable to get AIDL Stats service"); + return; + } + + for (auto &event : events) { + reportUsbDataSessionEvent(stats_client, event); + } +} + +void UsbDataSessionMonitor::getComplianceWarnings(const PortDataRole &role, + std::vector *warnings) { + if (!usb_flags::enable_report_usb_data_compliance_warning()) + return; + + if (role != mDataRole || role == PortDataRole::NONE) + return; + + for (auto w : mWarningSet) { + warnings->push_back(w); + } +} + +void UsbDataSessionMonitor::notifyComplianceWarning() { + if (!usb_flags::enable_report_usb_data_compliance_warning()) + return; + + if (mUpdatePortStatusCb) + mUpdatePortStatusCb(); +} + +void UsbDataSessionMonitor::evaluateComplianceWarning() { + std::set newWarningSet; + + // TODO: add heuristics and update newWarningSet + if (mDataRole == PortDataRole::DEVICE && mUdcBind) { + } else if (mDataRole == PortDataRole::HOST) { + } + + if (newWarningSet != mWarningSet) { + mWarningSet = newWarningSet; + notifyComplianceWarning(); + } +} + +void UsbDataSessionMonitor::clearDeviceStateEvents(struct usbDeviceState *deviceState) { + deviceState->states.clear(); + deviceState->timestamps.clear(); +} + +void UsbDataSessionMonitor::handleDeviceStateEvent(struct usbDeviceState *deviceState) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + + lseek(deviceState->fd.get(), 0, SEEK_SET); + n = read(deviceState->fd.get(), &state, USB_STATE_MAX_LEN); + + if (kValidStates.find(state) == kValidStates.end()) { + ALOGE("Invalid state %s", state); + return; + } + + ALOGI("Update USB device state: %s", state); + + deviceState->states.push_back(state); + deviceState->timestamps.push_back(boot_clock::now()); + evaluateComplianceWarning(); +} + +void UsbDataSessionMonitor::handleDataRoleEvent() { + int n; + PortDataRole newDataRole; + char role[DATA_ROLE_MAX_LEN] = {0}; + + lseek(mDataRoleFd.get(), 0, SEEK_SET); + n = read(mDataRoleFd.get(), &role, DATA_ROLE_MAX_LEN); + + ALOGI("Update USB data role %s", role); + + if (!std::strcmp(role, "host")) { + newDataRole = PortDataRole::HOST; + } else if (!std::strcmp(role, "device")) { + newDataRole = PortDataRole::DEVICE; + } else { + newDataRole = PortDataRole::NONE; + } + + if (newDataRole != mDataRole) { + // Upload metrics for the last data session that has ended + if (mDataRole == PortDataRole::HOST || (mDataRole == PortDataRole::DEVICE && mUdcBind)) { + reportUsbDataSessionMetrics(); + } + + // Set up for the new data session + mWarningSet.clear(); + mDataRole = newDataRole; + mDataSessionStart = boot_clock::now(); + + if (newDataRole == PortDataRole::DEVICE) { + clearDeviceStateEvents(&mDeviceState); + } else if (newDataRole == PortDataRole::HOST) { + clearDeviceStateEvents(&mHost1State); + clearDeviceStateEvents(&mHost2State); + } + } +} + +void UsbDataSessionMonitor::updateUdcBindStatus(const std::string &devname) { + std::string function; + bool newUdcBind; + + /* + * /sys/class/udc//function prints out name of currently running USB gadget driver + * Ref: https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-udc + * Empty name string means the udc device is not bound and gadget is pulldown. + */ + if (!ReadFileToString("/sys" + devname + "/function", &function)) + return; + + if (function == "") + newUdcBind = false; + else + newUdcBind = true; + + if (newUdcBind == mUdcBind) + return; + + if (mDataRole == PortDataRole::DEVICE) { + if (mUdcBind && !newUdcBind) { + /* + * Gadget soft pulldown: report metrics as the end of a data session and + * re-evaluate compliance warnings to clear existing warnings if any. + */ + reportUsbDataSessionMetrics(); + evaluateComplianceWarning(); + + } else if (!mUdcBind && newUdcBind) { + // Gadget soft pullup: reset and start accounting for a new data session. + clearDeviceStateEvents(&mDeviceState); + mDataSessionStart = boot_clock::now(); + } + } + + ALOGI("Udc bind status changes from %b to %b", mUdcBind, newUdcBind); + mUdcBind = newUdcBind; +} + +void UsbDataSessionMonitor::handleUevent() { + char msg[UEVENT_MSG_LEN + 2]; + char *cp; + int n; + + n = uevent_kernel_multicast_recv(mUeventFd.get(), msg, UEVENT_MSG_LEN); + if (n <= 0) + return; + if (n >= UEVENT_MSG_LEN) + return; + + msg[n] = '\0'; + msg[n + 1] = '\0'; + cp = msg; + + while (*cp) { + for (auto e : {&mHost1State, &mHost2State}) { + if (std::regex_search(cp, std::regex(e->ueventRegex))) { + if (!strncmp(cp, "bind@", strlen("bind@"))) { + addEpollFile(mEpollFd.get(), e->filePath, e->fd); + } else if (!strncmp(cp, "unbind@", strlen("unbind@"))) { + removeEpollFile(mEpollFd.get(), e->filePath, e->fd); + } + } + } + + // TODO: support bind@ unbind@ to detect dynamically allocated udc device + if (std::regex_search(cp, std::regex(mDeviceState.ueventRegex))) { + if (!strncmp(cp, "change@", strlen("change@"))) { + char *devname = cp + strlen("change@"); + /* + * Udc device emits a KOBJ_CHANGE event on configfs driver bind and unbind. + * TODO: upstream udc driver emits KOBJ_CHANGE event BEFORE unbind is actually + * executed. Add a short delay to get the correct state while working on a fix + * upstream. + */ + usleep(50000); + updateUdcBindStatus(devname); + } + } + /* advance to after the next \0 */ + while (*cp++) { + } + } +} + +void *UsbDataSessionMonitor::monitorThread(void *param) { + UsbDataSessionMonitor *monitor = (UsbDataSessionMonitor *)param; + struct epoll_event events[64]; + int nevents = 0; + + while (true) { + nevents = epoll_wait(monitor->mEpollFd.get(), events, 64, -1); + if (nevents == -1) { + if (errno == EINTR) + continue; + ALOGE("usb epoll_wait failed; errno=%d", errno); + break; + } + + for (int n = 0; n < nevents; ++n) { + if (events[n].data.fd == monitor->mUeventFd.get()) { + monitor->handleUevent(); + } else if (events[n].data.fd == monitor->mDataRoleFd.get()) { + monitor->handleDataRoleEvent(); + } else if (events[n].data.fd == monitor->mDeviceState.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mDeviceState); + } else if (events[n].data.fd == monitor->mHost1State.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mHost1State); + } else if (events[n].data.fd == monitor->mHost2State.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mHost2State); + } + } + } + return NULL; +} + +} // namespace usb +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/usb/usb/UsbDataSessionMonitor.h b/usb/usb/UsbDataSessionMonitor.h new file mode 100644 index 00000000..596f378f --- /dev/null +++ b/usb/usb/UsbDataSessionMonitor.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +namespace aidl { +namespace android { +namespace hardware { +namespace usb { + +using ::aidl::android::hardware::usb::ComplianceWarning; +using ::aidl::android::hardware::usb::PortDataRole; +using ::android::base::boot_clock; +using ::android::base::unique_fd; + +/* + * UsbDataSessionMonitor monitors the usb device state sysfs of 3 different usb devices + * including device mode (udc), host mode high-speed port and host mode super-speed port. It + * reports Suez metrics for each data session and also provides API to query the compliance + * warnings detected in the current usb data session. + */ +class UsbDataSessionMonitor { + public: + /* + * The host mode high-speed port and super-speed port can be assigned to either host1 or + * host2 without affecting functionality. + * + * UeventRegex: name regex of the device that's being monitored. The regex is matched against + * uevent to detect dynamic creation/deletion/change of the device. + * StatePath: usb device state sysfs path of the device, monitored by epoll. + * dataRolePath: path to the usb data role sysfs, monitored by epoll. + * updatePortStatusCb: the callback is invoked when the compliance warings changes. + */ + UsbDataSessionMonitor(const std::string &deviceUeventRegex, const std::string &deviceStatePath, + const std::string &host1UeventRegex, const std::string &host1StatePath, + const std::string &host2UeventRegex, const std::string &host2StatePath, + const std::string &dataRolePath, + std::function updatePortStatusCb); + ~UsbDataSessionMonitor(); + // Returns the compliance warnings detected in the current data session. + void getComplianceWarnings(const PortDataRole &role, std::vector *warnings); + + private: + struct usbDeviceState { + unique_fd fd; + std::string filePath; + std::string ueventRegex; + // Usb device states reported by state sysfs + std::vector states; + // Timestamps of when the usb device states were captured + std::vector timestamps; + }; + + static void *monitorThread(void *param); + void handleUevent(); + void handleDataRoleEvent(); + void handleDeviceStateEvent(struct usbDeviceState *deviceState); + void clearDeviceStateEvents(struct usbDeviceState *deviceState); + void reportUsbDataSessionMetrics(); + void evaluateComplianceWarning(); + void notifyComplianceWarning(); + void updateUdcBindStatus(const std::string &devname); + + pthread_t mMonitor; + unique_fd mEpollFd; + unique_fd mUeventFd; + unique_fd mDataRoleFd; + struct usbDeviceState mDeviceState; + struct usbDeviceState mHost1State; + struct usbDeviceState mHost2State; + std::set mWarningSet; + // Callback function to notify the caller when there's a change in compliance warnings. + std::function mUpdatePortStatusCb; + /* + * Cache relevant info for a USB data session when one starts, including + * the data role and the time when the session starts. + */ + PortDataRole mDataRole; + boot_clock::time_point mDataSessionStart; + /* + * In gadget mode: this indicates whether the udc device is bound to the configfs driver, which + * is done by userspace writing the udc device name to /config/usb_gadget/g1/UDC. When unbound, + * the gadget is in soft pulldown state and is expected not to enumerate. During gadget + * function switch, the udc device usually go through unbind and bind. + */ + bool mUdcBind; +}; + +} // namespace usb +} // namespace hardware +} // namespace android +} // namespace aidl From 06e99301dd1bf20da055af6484694a9e7115dc73 Mon Sep 17 00:00:00 2001 From: Hungyen Weng Date: Mon, 11 Dec 2023 11:23:40 -0800 Subject: [PATCH 128/133] config: Use carrier config in ROM by default Bug: 314890118 Test: Flash ROM and confirm the carrier config follows the ROM. Change-Id: Iffdb9a3a53e82d86d9917d84a7ce6ac49a3bad2a --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 32610410..92de7e88 100644 --- a/device.mk +++ b/device.mk @@ -191,7 +191,7 @@ PRODUCT_PRODUCT_PROPERTIES += \ # Carrier configuration default location PRODUCT_PROPERTY_OVERRIDES += \ - persist.vendor.radio.config.carrier_config_dir=/mnt/vendor/modem_img/images/default/confpack + persist.vendor.radio.config.carrier_config_dir=/vendor/firmware/carrierconfig PRODUCT_PROPERTY_OVERRIDES += \ telephony.active_modems.max_count=2 From 559da7282a4a5a49fe1ab21b24b1aacd75032b2e Mon Sep 17 00:00:00 2001 From: Kuen-Han Tsai Date: Tue, 12 Dec 2023 14:11:31 +0800 Subject: [PATCH 129/133] usb: enable media-presence polling for SD cards After USB enumeration, some SD card readers do not send signals to the device when the SD card is inserted or removed. To support SD card hotplugging, this patch enables in-kernel media-presence polling, which will check the SD card status every 2 seconds after a SD card reader is attached. Bug: 186479576 Test: SD card insertion/removal and data copy (see b/301566595) Change-Id: I044aeffd9386c0bee6138402e5130c39e1adbc9f Signed-off-by: Kuen-Han Tsai --- conf/init.zuma.usb.rc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf/init.zuma.usb.rc b/conf/init.zuma.usb.rc index 4dff012a..2cbb30b5 100644 --- a/conf/init.zuma.usb.rc +++ b/conf/init.zuma.usb.rc @@ -370,6 +370,8 @@ on boot write sys/module/usbcore/parameters/initial_descriptor_timeout 500 # Use USB Gadget HAL setprop sys.usb.configfs 2 + # Enable in-kernel media-presence polling for SD cards + write /sys/module/block/parameters/events_dfl_poll_msecs 2000 on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && property:sys.usb.configfs=1 write /config/usb_gadget/g1/idProduct 0x4EE7 From 838d9245c02de3a813bfdd9fa4ab227495026f14 Mon Sep 17 00:00:00 2001 From: Wesley Wang Date: Tue, 12 Dec 2023 14:21:41 +0800 Subject: [PATCH 130/133] Grant the post notification permission to Turbo Bug: 293813663 Test: manual and local build verify Change-Id: I9ae27af828b1eeb2b8c2e2397a94e74f2315298a --- default-permissions.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/default-permissions.xml b/default-permissions.xml index 4dafb5b7..582971c7 100644 --- a/default-permissions.xml +++ b/default-permissions.xml @@ -150,6 +150,11 @@ + + + + From 3c8118e0f8d9e419ca05b14db58444c1443beab8 Mon Sep 17 00:00:00 2001 From: Darren Hsu Date: Tue, 12 Dec 2023 23:15:44 +0800 Subject: [PATCH 131/133] powerstats: change TPU DVFS data source from ACPM to TPU kernel ACPM has an issue b/315079424 that reports incorrect TPU DVFS residency. So change the data source from ACPM to TPU kernel. Bug: 310094590 Test: vts-tradefed run vts -m VtsHalPowerStatsTargetTest Change-Id: If4bdaeea510b1a8e72d057a7fbb0dc03f6a6c665 Signed-off-by: Darren Hsu --- powerstats/ZumaCommonDataProviders.cpp | 27 +++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/powerstats/ZumaCommonDataProviders.cpp b/powerstats/ZumaCommonDataProviders.cpp index 9378aee5..dc3f5342 100644 --- a/powerstats/ZumaCommonDataProviders.cpp +++ b/powerstats/ZumaCommonDataProviders.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,7 @@ using aidl::android::hardware::power::stats::GenericStateResidencyDataProvider; using aidl::android::hardware::power::stats::IioEnergyMeterDataProvider; using aidl::android::hardware::power::stats::PixelStateResidencyDataProvider; using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer; +using aidl::android::hardware::power::stats::TpuDvfsStateResidencyDataProvider; // TODO (b/181070764) (b/182941084): // Remove this when Wifi/BT energy consumption models are available or revert before ship @@ -178,17 +180,6 @@ void addDvfsStats(std::shared_ptr p) { path, NS_TO_MS, adpCfgs)); std::vector cfgs; - cfgs.push_back({"TPU", { - std::make_pair("1119MHz", "1119000"), - std::make_pair("1066MHz", "1066000"), - std::make_pair("967MHz", "967000"), - std::make_pair("845MHz", "845000"), - std::make_pair("712MHz", "712000"), - std::make_pair("627MHz", "627000"), - std::make_pair("455MHz", "455000"), - std::make_pair("226MHz", "226000"), - }}); - cfgs.push_back({"AUR", { std::make_pair("1065MHz", "1065000"), std::make_pair("861MHz", "861000"), @@ -201,6 +192,20 @@ void addDvfsStats(std::shared_ptr p) { p->addStateResidencyDataProvider(std::make_unique( path, NS_TO_MS, cfgs)); + + // TPU DVFS + const int TICK_TO_MS = 100; + std::vector freqs = { + "1119000", + "1066000", + "845000", + "712000", + "627000", + "455000", + "226000" + }; + p->addStateResidencyDataProvider(std::make_unique( + "/sys/devices/platform/1a000000.rio/tpu_usage", freqs, TICK_TO_MS)); } void addSoC(std::shared_ptr p) { From 425a781cd1a2015bb4c019fba3716d1d0c798b06 Mon Sep 17 00:00:00 2001 From: Ken Lin Date: Mon, 11 Dec 2023 07:43:17 +0000 Subject: [PATCH 132/133] init: make dumpstate able to read display logbuffer Add logbuffer support for display driver to dump DSI cmd Bug: 291441544 Test: adb root; adb shell dumpsys android.hardware.dumpstate.IDumpstateDevice/default dump_display_logbuffer Change-Id: I74eaa7b3cdd8101909044f173512d41b065a2599 Signed-off-by: Ken Lin --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index bde0a2f9..cadb6e54 100644 --- a/device.mk +++ b/device.mk @@ -31,6 +31,7 @@ include device/google/gs-common/soc/freq.mk include device/google/gs-common/gps/dump/log.mk include device/google/gs-common/bcmbt/dump/dumplog.mk include device/google/gs-common/display/dump.mk +include device/google/gs-common/display_logbuffer/dump.mk include device/google/gs-common/gxp/gxp.mk include device/google/gs-common/camera/dump.mk include device/google/gs-common/radio/dump.mk From e8719790546b747743f40df16b9bf51072c1f57a Mon Sep 17 00:00:00 2001 From: Snehal Date: Wed, 13 Dec 2023 06:47:49 +0000 Subject: [PATCH 133/133] Add trusty code coverage controller daemon Bug: 289523068 Change-Id: I473ac38a5f7b1540aea0b4588bc358f6855ff4b3 --- device.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 5f448565..cf22ae6e 100644 --- a/device.mk +++ b/device.mk @@ -820,11 +820,12 @@ endif $(call inherit-product, system/core/trusty/trusty-storage.mk) $(call inherit-product, system/core/trusty/trusty-base.mk) -# Trusty unit test tool +# Trusty unit test tool and code coverage tool PRODUCT_PACKAGES_DEBUG += \ trusty-ut-ctrl \ tipc-test \ trusty_stats_test \ + trusty-coverage-controller \ include device/google/gs101/confirmationui/confirmationui.mk