From 46e037980bdcbd4d7cb73cbf67763d8fc7b75493 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Wed, 6 Apr 2016 15:56:49 -0700 Subject: [PATCH] init: write bootloader message directly. Bug: 27176738 Change-Id: I8c95a193f3436c0893d5103760b700f3052888db --- init/Android.mk | 1 + init/builtins.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/init/Android.mk b/init/Android.mk index d8b574f2a..4827fa34b 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -83,6 +83,7 @@ LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED) LOCAL_STATIC_LIBRARIES := \ libinit \ + libbootloader_message_writer \ libfs_mgr \ libfec \ libfec_rs \ diff --git a/init/builtins.cpp b/init/builtins.cpp index 1fddc6314..c8780bb53 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -450,14 +451,10 @@ exit_success: } static int wipe_data_via_recovery() { - mkdir("/cache/recovery", 0700); - int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0600); - if (fd >= 0) { - write(fd, "--wipe_data\n", strlen("--wipe_data\n") + 1); - write(fd, "--reason=wipe_data_via_recovery\n", strlen("--reason=wipe_data_via_recovery\n") + 1); - close(fd); - } else { - ERROR("could not open /cache/recovery/command\n"); + const std::vector options = {"--wipe_data", "--reason=wipe_data_via_recovery"}; + std::string err; + if (!write_bootloader_message(options, &err)) { + ERROR("failed to set bootloader message: %s", err.c_str()); return -1; } android_reboot(ANDROID_RB_RESTART2, 0, "recovery");