最近有一个客户有个需求在使用他们的fota升级的过程中:在recovery模式的升级过程中创建一个名为“/cache/recovery/last_fota_result”文件,添加判断升级的status,若为INSTALL_SUCCES,则往last_fota_result文件写入1,否则写入0。该文件的读写权限为0666。
在alps/bootable/recovery/目录下有一个recovery.cpp文件,我们找到这个文件之后会发现里面有一句static const char *LAST_LOG_FILE = "/cache/recovery/last_log";这个last_log在每次fota升级之后就会出现,我们就可以参照这个文件的生成思路来添加在recovery模式的升级过程中生成“/cache/recovery/last_fota_result”文件的功能:
@@ -123,6 +123,7 @@ static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";
static const char *TEMPORARY_INSTALL_FILE = "/tmp/last_install";
static const char *LAST_KMSG_FILE = "/cache/recovery/last_kmsg";
static const char *LAST_LOG_FILE = "/cache/recovery/last_log";
+static const char *LAST_LOG_FOTA_RESULT_FILE = "/cache/recovery/last_fota_result";
// We will try to apply the update package 5 times at most in case of an I/O error or
// bspatch | imgpatch error.
static const int RETRY_LIMIT = 4;
@@ -467,6 +468,7 @@ static void copy_logs() {
// Always write to pmsg, this allows the OTA logs to be caught in logcat -L
copy_log_file_to_pmsg(TEMPORARY_LOG_FILE, LAST_LOG_FILE);
+ copy_log_file_to_pmsg(TEMPORARY_LOG_FILE, LAST_LOG_FOTA_RESULT_FILE);
copy_log_file_to_pmsg(TEMPORARY_INSTALL_FILE, LAST_INSTALL_FILE);
// We can do nothing for now if there's no /cache partition.
@@ -475,12 +477,15 @@ static void copy_logs() {
}
ensure_path_mounted(LAST_LOG_FILE);
+ ensure_path_mounted(LAST_LOG_FOTA_RESULT_FILE);
ensure_path_mounted(LAST_KMSG_FILE);
rotate_logs(LAST_LOG_FILE, LAST_KMSG_FILE);
+ rotate_logs(LAST_LOG_FOTA_RESULT_FILE, LAST_KMSG_FILE);
// Copy logs to cache so the system can find out what happened.
copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true);
copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false);
+ copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FOTA_RESULT_FILE, false);
copy_log_file(TEMPORARY_INSTALL_FILE, LAST_INSTALL_FILE, false);
save_kernel_log(LAST_KMSG_FILE);
chmod(LOG_FILE, 0600);
@@ -488,6 +493,7 @@ static void copy_logs() {
chmod(LAST_KMSG_FILE, 0600);
chown(LAST_KMSG_FILE, AID_SYSTEM, AID_SYSTEM);
chmod(LAST_LOG_FILE, 0640);
+ chmod(LAST_LOG_FOTA_RESULT_FILE, 0666);
chmod(LAST_INSTALL_FILE, 0644);
sync();
}
@@ -963,6 +969,7 @@ static void choose_recovery_file(Device* device) {
// Add LAST_LOG_FILE + LAST_LOG_FILE.x
add_to_entries(LAST_LOG_FILE);
+ add_to_entries(LAST_LOG_FOTA_RESULT_FILE);
// Add LAST_KMSG_FILE + LAST_KMSG_FILE.x
add_to_entries(LAST_KMSG_FILE);
其实添加不是困难的事情,照着其它文件生成方式添加就行,关键是找到alps/bootable/recovery/recovery.cpp这个文件的位置。
在FOTA升级过程中,客户需要在recovery模式下创建并更新'last_fota_result'文件,根据升级状态写入1或0。通过修改alps/bootable/recovery/recovery.cpp,参照last_log文件的生成方式,添加了生成'last_fota_result'文件的代码,并确保其权限为0666。主要涉及文件操作和权限设置。


被折叠的 条评论
为什么被折叠?



