From ec2a9a0c7ac5d981862093b47be2d24c36518ecd Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 30 Nov 2023 22:25:57 +0800 Subject: [PATCH] gs-common: bootctrl: integrate blowAR() for gs101 & zuma Common bootcontrol use zuma version for the base, and blowAR() can't be used by gs101. So we need to port ag/18743149 into common bootcontrol. Bug: 313615120 Change-Id: I25febde96a56279e6592a6d7740be9a2e385543b Signed-off-by: Jason Chiu --- bootctrl/1.2/BootControl.cpp | 23 ++++++++++++++++++++++- bootctrl/aidl/BootControl.cpp | 22 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/bootctrl/1.2/BootControl.cpp b/bootctrl/1.2/BootControl.cpp index 4e72805..ff02013 100644 --- a/bootctrl/1.2/BootControl.cpp +++ b/bootctrl/1.2/BootControl.cpp @@ -50,6 +50,8 @@ namespace { #define BOOT_B_PATH "/dev/block/by-name/boot_b" #define DEVINFO_PATH "/dev/block/by-name/devinfo" +#define BLOW_AR_PATH "/sys/kernel/boot_control/blow_ar" + // slot flags #define AB_ATTR_PRIORITY_SHIFT 52 #define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) @@ -230,7 +232,7 @@ static int blow_otp_AR(bool secure) { return 0; } -static bool blowAR() { +static bool blowAR_zuma() { int ret = blow_otp_AR(true); if (ret) { ALOGI("Blow secure anti-rollback OTP failed"); @@ -245,6 +247,25 @@ static bool blowAR() { return true; } + +static bool blowAR_gs101() { + android::base::unique_fd fd(open(BLOW_AR_PATH, O_WRONLY | O_DSYNC)); + return android::base::WriteStringToFd("1", fd); +} + +static bool blowAR() { + char platform[PROPERTY_VALUE_MAX]; + property_get("ro.boot.hardware.platform", platform, ""); + + if (std::string(platform) == "gs101") { + return blowAR_gs101(); + } else if (std::string(platform) == "gs201" || std::string(platform) == "zuma") { + return blowAR_zuma(); + } + + return true; +} + } // namespace // Methods from ::android::hardware::boot::V1_0::IBootControl follow. diff --git a/bootctrl/aidl/BootControl.cpp b/bootctrl/aidl/BootControl.cpp index 0221514..e771845 100644 --- a/bootctrl/aidl/BootControl.cpp +++ b/bootctrl/aidl/BootControl.cpp @@ -47,6 +47,8 @@ namespace { #define BOOT_B_PATH "/dev/block/by-name/boot_b" #define DEVINFO_PATH "/dev/block/by-name/devinfo" +#define BLOW_AR_PATH "/sys/kernel/boot_control/blow_ar" + // slot flags #define AB_ATTR_PRIORITY_SHIFT 52 #define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) @@ -227,7 +229,7 @@ static int blow_otp_AR(bool secure) { return 0; } -static bool blowAR() { +static bool blowAR_zuma() { int ret = blow_otp_AR(true); if (ret) { ALOGI("Blow secure anti-rollback OTP failed"); @@ -243,6 +245,24 @@ static bool blowAR() { return true; } +static bool blowAR_gs101() { + ::android::base::unique_fd fd(open(BLOW_AR_PATH, O_WRONLY | O_DSYNC)); + return ::android::base::WriteStringToFd("1", fd); +} + +static bool blowAR() { + char platform[PROPERTY_VALUE_MAX]; + property_get("ro.boot.hardware.platform", platform, ""); + + if (std::string(platform) == "gs101") { + return blowAR_gs101(); + } else if (std::string(platform) == "gs201" || std::string(platform) == "zuma") { + return blowAR_zuma(); + } + + return true; +} + static constexpr MergeStatus ToAIDLMergeStatus(HIDLMergeStatus status) { switch (status) { case HIDLMergeStatus::NONE: