近期在编译recovery,用了两个周的时间,总算成功了,现小结一下
在同步好cm源码后,在bootloader目录下有cm自带的RWM recovery源码
-----------------------------------------------------------------------------------------
以中兴的V880+为例,编译recovery,需要如下文件
/device/zte/blade/kernel (zte为厂商目录,blade为机型名称,kernel为boot.img提取)
/device/zte/blade/AndroidProducts.mk
/device/zte/blade/AndroidBoard.mk
/device/zte/blade/BoardConfig.mk(设备配置)
/device/zte/blade/device_blade.mk(手机配置文件)
/device/zte/blade/qwerty.kl(手机按键映射)
/device/zte/blade/recovery.fstab(recovery分区表)
/device/zte/blade/recovery_ui.c(recovery按键映射)
------------------------------------------------------------------------------------------
device中的文件齐全,现详解以上文件
1.kernel
此文件为内核文件,包含设备驱动等设备私有文件,可从boot.img和recovery.img文件中提取,此文件最好从官方文件中提取,不然会出现一些乱七八糟的情况,譬如说闪退,黑屏,重启之类的情况
2.AndroidProducts.mk
PRODUCT_MAKEFILES := \
$(LOCAL_DIR)/device_blade.mk
包含device_blade.mk文件
3.AndroidBoard.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET)
4.device_blade.mk
PRODUCT_NAME := zte_blade
PRODUCT_DEVICE := blade
ifeq ($(TARGET_PREBUILT_KERNEL),)
LOCAL_KERNEL := device/zte/blade/kernel
else
LOCAL_KERNEL := $(TARGET_PREBUILT_KERNEL)
endif
PRODUCT_COPY_FILES += \
$(LOCAL_KERNEL):kernel
此文件名称可以随便定义,只要在AndroidProducts.mk中包含名一样就行,
注意:
1)PRODUCT_NAME要保持名称一致
2)后一句要复制kernel到文件夹out下,如果没有这句,则无法生成boot.img文件
5.qwerty.kl
手机按键对应键值,可以在手机里提取
6.recovery.fstab
# mount pointfstypedevice[device2]
/boot mtd boot
/cache yaffs2 cache
/data yaffs2 userdata
/misc mtd misc
/recovery mtd recovery
/sdcard vfat /dev/block/mmcblk0p1 /dev/block/mmcblk0
/system yaffs2system
/sd-ext auto /dev/block/mmcblk0p2
此文件可以在手机上查看,proc/mtd以及mount即可自己对照划分
7.recovery_ui.c
#include <linux/input.h>
#include "recovery_ui.h"
#include "common.h"
#include "extendedcommands.h"
char* MENU_HEADERS[] = { "Use vol keys to highlight and home to select.",
"",
NULL };
char* MENU_ITEMS[] = { "reboot system now",
"apply update from sdcard",
"wipe data/factory reset",
"wipe cache partition",
"install zip from sdcard",
"backup and restore",
"mounts and storage",
"advanced",
"power off",
NULL };
int device_recovery_start() {
return 0;
}
int device_toggle_display(volatile char* key_pressed, int key_code) {
int alt = key_pressed[KEY_LEFTALT] || key_pressed[KEY_RIGHTALT];
if (alt && key_code == KEY_L)
return 1;
// allow toggling of the display if the correct key is pressed, and the display toggle is allowed or the display is currently off
if (ui_get_showing_back_button()) {
return get_allow_toggle_display() && (key_code == KEY_MENU || key_code == KEY_END);
}
return get_allow_toggle_display() && (key_code == KEY_MENU || key_code == KEY_POWER || key_code == KEY_END);
}
int device_reboot_now(volatile char* key_pressed, int key_code) {
return 0;
}
int device_handle_key(int key_code, int visible) {
if (visible) {
switch (key_code) {
case KEY_CAPSLOCK:
case KEY_DOWN:
case KEY_VOLUMEUP:
return HIGHLIGHT_UP;
case KEY_LEFTSHIFT:
case KEY_UP:
case KEY_VOLUMEDOWN:
return HIGHLIGHT_DOWN;
case 62:
return SELECT_ITEM;
case KEY_POWER:
if (ui_get_showing_back_button()) {
return SELECT_ITEM;
}
if (!get_allow_toggle_display())
return GO_BACK;
break;
case KEY_LEFTBRACE:
case KEY_ENTER:
case BTN_MOUSE:
case KEY_CENTER:
case KEY_CAMERA:
case KEY_F21:
case KEY_SEND:
case KEY_HOME:
return SELECT_ITEM;
case KEY_END:
case KEY_BACKSPACE:
case KEY_BACK:
if (!get_allow_toggle_display())
return GO_BACK;
}
}
return NO_ACTION;
}
int device_perform_action(int which) {
return which;
}
int device_wipe_data() {
return 0;
}
此文件为刷入recovery分区后的按键操作文件,自己可以依据手机按键键值文件里对应的按键来写
8.BoardConfig.mk
USE_CAMERA_STUB := false
TARGET_NO_BOOTLOADER := true
TARGET_BOARD_PLATFORM := unknown
TARGET_CPU_ABI := armeabi
TARGET_BOOTLOADER_BOARD_NAME := blade
BOARD_HAS_FLIPPED_SCREEN :=true
BOARD_KERNEL_CMDLINE := androidboot.hardware=blade console=ttyMSM2,115200 g_android.product_id=0x1354 g_android.serial_number=blade-geno
BOARD_KERNEL_BASE := 0x02600000
BOARD_KERNEL_PAGESIZE := 2048
BOARD_UMS_LUNFILE:="/sys/devices/platform/msm_hsusb/gadget/lun0/file"
# fix this up by examining /proc/mtd on a running device
BOARD_BOOTIMAGE_PARTITION_SIZE := 0x00380000
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 0x00480000
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 0x08c60000
BOARD_USERDATAIMAGE_PARTITION_SIZE := 0x105c0000
BOARD_FLASH_BLOCK_SIZE := 131072
TARGET_PREBUILT_KERNEL := device/zte/blade/kernel
BOARD_CUSTOM_RECOVERY_KEYMAPPING:=../../device/zte/blade/recovery_ui.c
================================================================================
上边为device中的需要配置的文件,而为了编译通过,得在vendor中配置一下
vendor/cyanogen/vendorsetup.sh
vendor/cyanogen/products/AndroidProducts.mk
vendor/cyanogen/products/cyanogen_blade.mk
----------------------------------------------------------------------------------
现详解文件的需要的改动
1.vendorsetup.sh
添加如下内容:
add-lunch-combo cyanogen_blade-eng
2.AndroidProducts.mk
增加cyanogen_blade.mk这个文件
3.cyanogen_blade.mk
这个文件可以自己编写,但是一定要注意其中的ProductNAME要保持一致
以上
基本就是在源码的基础上配置自己recovery的必备文件了
======================================================================================
PS:我也是处于探索学习中,如果有发现上边所述有误,请留言指正,不胜感激。