android5.1 Recovery添加从U盘升级功能

2024-03-26 18:58

本文主要是介绍android5.1 Recovery添加从U盘升级功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

之前看到过一个人写了4.4上添加U盘升级功能的博客http://blog.csdn.net/kris_fei/article/details/50311885,写得挺好。

我们在5.1上也要做同样的功能,具体修改如下:

diff --git a/bootable/recovery/Android.mk b/bootable/recovery/Android.mk
old mode 100644
new mode 100755
index 5a1f479..8b21040
--- a/bootable/recovery/Android.mk
+++ b/bootable/recovery/Android.mk
@@ -39,7 +39,8 @@ LOCAL_SRC_FILES := \
     asn1_decoder.cpp \
     verifier.cpp \
     adb_install.cpp \
-    fuse_sdcard_provider.c
+    fuse_sdcard_provider.c \
+    fuse_udisk_provider.c
 
 LOCAL_MODULE := recovery
 
diff --git a/bootable/recovery/default_device.cpp b/bootable/recovery/default_device.cpp
old mode 100644
new mode 100755
index d92aaf5..f4b10ee
--- a/bootable/recovery/default_device.cpp
+++ b/bootable/recovery/default_device.cpp
@@ -33,6 +33,8 @@ static const char* ITEMS[] =  {"reboot system now",
                                "power down",
                                "view recovery logs",
                                "apply update from sdcard",
+                               "apply update from udisk",
                                NULL };
 
 class DefaultDevice : public Device {
@@ -73,6 +75,8 @@ class DefaultDevice : public Device {
           case 5: return SHUTDOWN;
           case 6: return READ_RECOVERY_LASTLOG;
           case 7: return APPLY_EXT;
+          case 8: return APPLY_FROM_UDISK;
           default: return NO_ACTION;
         }
     }
diff --git a/bootable/recovery/device.h b/bootable/recovery/device.h
old mode 100644
new mode 100755
index 8ff4ec0..82a3708
--- a/bootable/recovery/device.h
+++ b/bootable/recovery/device.h
@@ -64,8 +64,8 @@ class Device {
     //   - do nothing (kNoAction)
     //   - invoke a specific action (a menu position: any non-negative number)
     virtual int HandleMenuKey(int key, int visible) = 0;
-
-    enum BuiltinAction { NO_ACTION, REBOOT, APPLY_EXT,
+    enum BuiltinAction { NO_ACTION, REBOOT, APPLY_EXT,APPLY_FROM_UDISK,
                          APPLY_CACHE,   // APPLY_CACHE is deprecated; has no effect
                          APPLY_ADB_SIDELOAD, WIPE_DATA, WIPE_CACHE,
                          REBOOT_BOOTLOADER, SHUTDOWN, READ_RECOVERY_LASTLOG };
diff --git a/bootable/recovery/etc/init.rc b/bootable/recovery/etc/init.rc
old mode 100644
new mode 100755
index c78a44a..0fcc49f
--- a/bootable/recovery/etc/init.rc
+++ b/bootable/recovery/etc/init.rc
@@ -20,6 +20,7 @@ on init
     symlink /system/etc /etc
 
     mkdir /sdcard
+    mkdir /udisk
     mkdir /system
     mkdir /data
     mkdir /cache
diff --git a/bootable/recovery/fuse_udisk_provider.c b/bootable/recovery/fuse_udisk_provider.c
new file mode 100755
index 0000000..789a6eb
--- /dev/null
+++ b/bootable/recovery/fuse_udisk_provider.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2014 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 <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <pthread.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "fuse_sideload.h"
+
+struct file_data {
+    int fd;  // the underlying sdcard file
+
+    uint64_t file_size;
+    uint32_t block_size;
+};
+
+static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32_t fetch_size) {
+    struct file_data* fd = (struct file_data*)cookie;
+
+    if (lseek(fd->fd, block * fd->block_size, SEEK_SET) < 0) {
+        return -EIO;
+    }
+
+    while (fetch_size > 0) {
+        ssize_t r = read(fd->fd, buffer, fetch_size);
+        if (r < 0) {
+            if (r != -EINTR) {
+                return -EIO;
+            }
+            r = 0;
+        }
+        fetch_size -= r;
+        buffer += r;
+    }
+
+    return 0;
+}
+
+static void close_file(void* cookie) {
+    struct file_data* fd = (struct file_data*)cookie;
+    close(fd->fd);
+}
+
+struct token {
+    pthread_t th;
+    const char* path;
+    int result;
+};
+
+static void* run_udisk_fuse(void* cookie) {
+    struct token* t = (struct token*)cookie;
+
+    struct stat sb;
+    if (stat(t->path, &sb) < 0) {
+        t->result = -1;
+        return NULL;
+    }
+
+    struct file_data fd;
+    struct provider_vtab vtab;
+
+    fd.fd = open(t->path, O_RDONLY);
+    if (fd.fd < 0) {
+        t->result = -1;
+        return NULL;
+    }
+    fd.file_size = sb.st_size;
+    fd.block_size = 65536;
+
+    vtab.read_block = read_block_file;
+    vtab.close = close_file;
+
+    t->result = run_fuse_sideload(&vtab, &fd, fd.file_size, fd.block_size);
+    return NULL;
+}
+
+// How long (in seconds) we wait for the fuse-provided package file to
+// appear, before timing out.
+#define UDISK_INSTALL_TIMEOUT 10
+
+void* start_udisk_fuse(const char* path) {
+    struct token* t = malloc(sizeof(struct token));
+
+    t->path = path;
+    pthread_create(&(t->th), NULL, run_udisk_fuse, t);
+
+    struct stat st;
+    int i;
+    for (i = 0; i < UDISK_INSTALL_TIMEOUT; ++i) {
+        if (stat(FUSE_SIDELOAD_HOST_PATHNAME, &st) != 0) {
+            if (errno == ENOENT && i < UDISK_INSTALL_TIMEOUT-1) {
+                sleep(1);
+                continue;
+            } else {
+                return NULL;
+            }
+        }
+    }
+
+    // The installation process expects to find the sdcard unmounted.
+    // Unmount it with MNT_DETACH so that our open file continues to
+    // work but new references see it as unmounted.
+    umount2("/udisk", MNT_DETACH);
+
+    return t;
+}
+
+void finish_udisk_fuse(void* cookie) {
+    if (cookie == NULL) return;
+    struct token* t = (struct token*)cookie;
+
+    // Calling stat() on this magic filename signals the fuse
+    // filesystem to shut down.
+    struct stat st;
+    stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st);
+
+    pthread_join(t->th, NULL);
+    free(t);
+}
diff --git a/bootable/recovery/fuse_udisk_provider.h b/bootable/recovery/fuse_udisk_provider.h
new file mode 100755
index 0000000..3313e9b
--- /dev/null
+++ b/bootable/recovery/fuse_udisk_provider.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#ifndef __FUSE_UDISK_PROVIDER_H
+#define __FUSE_UDISK_PROVIDER_H
+
+void* start_udisk_fuse(const char* path);
+void finish_udisk_fuse(void* token);
+
+#endif
diff --git a/bootable/recovery/recovery.cpp b/bootable/recovery/recovery.cpp
old mode 100644
new mode 100755
index 693ef19..b88364d
--- a/bootable/recovery/recovery.cpp
+++ b/bootable/recovery/recovery.cpp
@@ -47,6 +47,8 @@ extern "C" {
 #include "minadbd/adb.h"
 #include "fuse_sideload.h"
 #include "fuse_sdcard_provider.h"
+#include "fuse_udisk_provider.h"
 }
 
 struct selabel_handle *sehandle;
@@ -75,6 +77,8 @@ static const char *LAST_INSTALL_FILE = "/cache/recovery/last_install";
 static const char *LOCALE_FILE = "/cache/recovery/last_locale";
 static const char *CACHE_ROOT = "/cache";
 static const char *SDCARD_ROOT = "/sdcard";
+static const char *UDISK_ROOT = "/udisk";
 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";
@@ -267,6 +271,15 @@ set_sdcard_update_bootloader_message() {
     set_bootloader_message(&boot);
 }
 
+static void
+set_udisk_update_bootloader_message() {
+    struct bootloader_message boot;
+    memset(&boot, 0, sizeof(boot));
+    strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
+    strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
+    set_bootloader_message(&boot);
+}
 // read from kernel log into buffer and write out to file
 static void
 save_kernel_log(const char *destination) {
@@ -893,6 +906,44 @@ prompt_and_wait(Device* device, int status) {
                     }
                 }
                 break;
+            case Device::APPLY_FROM_UDISK: {
+                ensure_path_mounted(UDISK_ROOT);
+                char* path = browse_directory(UDISK_ROOT, device);
+                if (path == NULL) {
+                  
+                    break;
+                }
+                set_udisk_update_bootloader_message();
+                void* token = start_udisk_fuse(path);
+
+                int status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, &wipe_cache,
+                                             TEMPORARY_INSTALL_FILE, false);
+
+                finish_udisk_fuse(token);
+                ensure_path_unmounted(UDISK_ROOT);        
+                if (status == INSTALL_SUCCESS && wipe_cache) {
+                   
+                    if (erase_volume("/cache")) {
+                       
+                    } else {
+                        ui->Print("Cache wipe complete.\n");
+                    }
+                }
+
+                if (status >= 0) {
+                    if (status != INSTALL_SUCCESS) {
+                        ui->SetBackground(RecoveryUI::ERROR);
+                        ui->Print("Installation aborted.\n");
+                    } else if (!ui->IsTextVisible()) {
+                        return Device::NO_ACTION;  // reboot if logs aren't visible
+                    } else {
+                        ui->Print("\nInstall from udisk complete.\n");
+                    }
+                }
+                break;
+            }
+
         }
     }
 }
diff --git a/device/qcom/slm753/recovery.fstab b/device/qcom/slm753/recovery.fstab
index 161a8a8..5632b77 100755
--- a/device/qcom/slm753/recovery.fstab
+++ b/device/qcom/slm753/recovery.fstab
@@ -31,6 +31,8 @@
 /dev/block/bootdevice/by-name/cache        /cache          ext4    noatime,nosuid,nodev,barrier=1,data=ordered                     wait,check
 /dev/block/bootdevice/by-name/userdata     /data           ext4    noatime,nosuid,nodev,barrier=1,data=ordered,noauto_da_alloc     wait,check
 /dev/block/mmcblk1p1                              /sdcard           vfat    nosuid,nodev,barrier=1,data=ordered,nodelalloc                  wait

+/dev/block/sda1                              /udisk           vfat    nosuid,nodev,barrier=1,data=ordered,nodelalloc                  wait
 /dev/block/bootdevice/by-name/boot         /boot           emmc    defaults                                                        defaults
 /dev/block/bootdevice/by-name/recovery     /recovery       emmc    defaults                                                        defaults
 /dev/block/bootdevice/by-name/misc         /misc           emmc    defaults                                                        defaults

好,代码处理OK,全编译验证通过。有问题可以沟通。


这篇关于android5.1 Recovery添加从U盘升级功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/849533

相关文章

C++11第三弹:lambda表达式 | 新的类功能 | 模板的可变参数

🌈个人主页: 南桥几晴秋 🌈C++专栏: 南桥谈C++ 🌈C语言专栏: C语言学习系列 🌈Linux学习专栏: 南桥谈Linux 🌈数据结构学习专栏: 数据结构杂谈 🌈数据库学习专栏: 南桥谈MySQL 🌈Qt学习专栏: 南桥谈Qt 🌈菜鸡代码练习: 练习随想记录 🌈git学习: 南桥谈Git 🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈�

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time

Spring框架5 - 容器的扩展功能 (ApplicationContext)

private static ApplicationContext applicationContext;static {applicationContext = new ClassPathXmlApplicationContext("bean.xml");} BeanFactory的功能扩展类ApplicationContext进行深度的分析。ApplicationConext与 BeanF

JavaFX应用更新检测功能(在线自动更新方案)

JavaFX开发的桌面应用属于C端,一般来说需要版本检测和自动更新功能,这里记录一下一种版本检测和自动更新的方法。 1. 整体方案 JavaFX.应用版本检测、自动更新主要涉及一下步骤: 读取本地应用版本拉取远程版本并比较两个版本如果需要升级,那么拉取更新历史弹出升级控制窗口用户选择升级时,拉取升级包解压,重启应用用户选择忽略时,本地版本标志为忽略版本用户选择取消时,隐藏升级控制窗口 2.

macOS升级后SVN升级

问题 svn: error: The subversion command line tools are no longer provided by Xcode. 解决 sudo chown -R $(whoami) /usr/local/Cellar brew install svn

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

Spring+MyBatis+jeasyui 功能树列表

java代码@EnablePaging@RequestMapping(value = "/queryFunctionList.html")@ResponseBodypublic Map<String, Object> queryFunctionList() {String parentId = "";List<FunctionDisplay> tables = query(parent

PostgreSQL核心功能特性与使用领域及场景分析

PostgreSQL有什么优点? 开源和免费 PostgreSQL是一个开源的数据库管理系统,可以免费使用和修改。这降低了企业的成本,并为开发者提供了一个活跃的社区和丰富的资源。 高度兼容 PostgreSQL支持多种操作系统(如Linux、Windows、macOS等)和编程语言(如C、C++、Java、Python、Ruby等),并提供了多种接口(如JDBC、ODBC、ADO.NET等

寻迹模块TCRT5000的应用原理和功能实现(基于STM32)

目录 概述 1 认识TCRT5000 1.1 模块介绍 1.2 电气特性 2 系统应用 2.1 系统架构 2.2 STM32Cube创建工程 3 功能实现 3.1 代码实现 3.2 源代码文件 4 功能测试 4.1 检测黑线状态 4.2 未检测黑线状态 概述 本文主要介绍TCRT5000模块的使用原理,包括该模块的硬件实现方式,电路实现原理,还使用STM32类

nginx介绍及常用功能

什么是nginx nginx跟Apache一样,是一个web服务器(网站服务器),通过HTTP协议提供各种网络服务。 Apache:重量级的,不支持高并发的服务器。在Apache上运行数以万计的并发访问,会导致服务器消耗大量内存。操作系统对其进行进程或线程间的切换也消耗了大量的CPU资源,导致HTTP请求的平均响应速度降低。这些都决定了Apache不可能成为高性能WEB服务器  nginx: