本文转载自:http://blog.csdn.net/tfslovexizi/article/details/73835594

之前看到过一个人写了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盘升级功能【转】相关推荐

  1. imx6 android4.4 Recovery添加从U盘升级功能

    Platform: imx6 OS: Android 4.4 device/fsl 目录: [plain] view plaincopy diff --git a/common/recovery/An ...

  2. RK3229平台Android6.0系统添加广升OTA升级功能

    添加脚本: build/core/FotaInfo.sh #!/bin/bash#********Do not modify this file. If you want modify this fi ...

  3. RT-thread应用讲解——通过U盘升级程序固件

    RT-thread应用讲解--通过U盘升级程序固件 目录 RT-thread应用讲解--通过U盘升级程序固件 前言 一.挂载U盘 二.使能OTA 三.U盘升级代码 四.运行测试 五.结束语 前言 我前 ...

  4. Thinkpad 预装win8 UEFI+GPE 安装Ubuntu双系统 与win8中Lenovo recovery 制作恢复启动盘

    折腾了好久终于把这事搞定了,在这里告诫下大家,在完全摸清楚这些底细之前最好先别急着动手.当然,做什么事都应该这样. 分清楚UEFT/GPG和BIOS/MBR 每一种启动项对应一种分区方式,在BIOS启 ...

  5. HAL库U盘升级 STM32F407 CUBEMX:FATFS + USB_HOST + USB_OTG_FS

    一.测试平台: MCU:STM32F407VET6 固件库:CUBEMX IDE:MDK 二.实验目的: 将U盘里面的bin文件插入要升级的设备,通过BootLoader来进行升级 在这是用板载的LE ...

  6. stm32 U盘升级 bootloader程序 基于stm32f407 将升级包下载到U盘中,插入到设备中,完成对主程序的升级

    stm32 U盘升级 bootloader程序 基于stm32f407 将升级包下载到U盘中,插入到设备中,完成对主程序的升级,无需上位机操作. 清单: u盘升级的bootloader源码. YID: ...

  7. KT142A语音芯片IC的固件升级方法详细描述,PC升级和U盘升级

    目录 一.简介 2.1第1步--连接电脑通过USB线 2.2第2步--双击我们提供的批处理download.bat 3.1将升级文件拷贝至设备[U盘或者TF卡] 四.注意细节 一.简介 KT142A4 ...

  8. STM32F4通过U盘升级程序

    昨天的文章中介绍F4系列单片机的内部Flash读写,包括之前文章中介绍了FatFS文件系统读写U盘的操作.本篇文章就是将两者结合,实现F4系列单片机程序的U盘升级. 首先对内部Flash空间进行划分, ...

  9. 计算机里找不到网络映射盘,怎么win10上添加网络映射盘_win10添加网络映射盘的方法...

    工作中经常会使用到电脑,好多网友留言说怎么win10上添加网络映射盘?映射网络驱动一般是在局域网中有用,可以把分机的共享的那个盘符映射到主机的版电脑上,这样主机可以权直接地调用分机的共享文件.默认情况 ...

最新文章

  1. 洛谷【P2257】YY的GCD
  2. 自定义Android带图片的按钮
  3. linux配置redis服务,Linux下安装Redis并设置相关服务
  4. php a链接怎么传id_PHP函数参数的传递
  5. 华硕主板专用Ghost Win11 64位专业体验版 V2021.08
  6. opencv打开的图片应用于nn.Conv2d()(二)
  7. Tomcat - SSL操作大全
  8. 自定义页面hashmap 方便调用
  9. 龙芯 linux 网页flash,FlashPlayer - 龙芯开源社区
  10. python excel 设置行高与列宽
  11. 关于transition过渡的详解
  12. 车联网智能终端GB/T 32960国标协议规范 、国标新能源车联网终端GB/T32960标准T-BOX应用
  13. 2014校园招聘_腾讯2014校园招聘
  14. Shape 文件格式解释
  15. win8访问不了服务器共享文件夹,如何解决Win8局域网无法访问共享文件夹的问题...
  16. 函数调用之特殊三位数
  17. java虚拟机JVM内存不够,OutOfMemorry Error
  18. APIView与序列化组件使用
  19. 实现斐波拉契的三种方法
  20. I/O设备的概念和分类、I/O控制器及其I/O控制方式

热门文章

  1. 用python和ffmpeg批量合成bilibili缓存的m4s成mp4
  2. Navicat因导入的sql文件中时间数据类型有参数而报错的原因(例:datetime(3))
  3. 微信小程序登录注册功能(超详细)
  4. vivado生成mig_Vivado 2015.1 MIG生成DDR4控制器例化问题求助!(急)
  5. mysql在windows安装和卸载步骤,以及相关问题的解决记录
  6. css span文字下划线
  7. 怎么防止服务器被入侵?
  8. 最新计算机ppt,计算机应用基础(最新版)ppt课件
  9. ubuntu12.04 GX编译环境搭建
  10. java开发的微信公众号服务端生产环境中的两个大坑