7. echo "FAILED"
else
echo "SUCCESSFUL"
fi
}
###### Function to check whether an application exists
check_program() {
for cmd in "$@"
do
which ${cmd} > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo
echo "Cannot find command "${cmd}""
echo
exit 1
fi
done
}
if [ $# -ne 5 ]
then
echo
echo 'Usage: create-ubifs.sh [page_size_in_bytes] [pages_per_block] [partition_size_in_bytes]
[blocks_per_device] [path_to_rootfs]'
echo
exit
fi
page_size_in_bytes=$1
echo "Page size [$page_size_in_bytes]bytes."
pages_per_block=$2
echo "Pages per block [$pages_per_block]"
partition_size_in_bytes=$3
echo "File-system partition size [$partition_size_in_bytes]bytes."
blocks_per_device=$4
echo "Blocks per device [$blocks_per_device]"
path_to_rootfs=$5
# wear_level_reserved_blocks is 1% of total blcoks per device
wear_level_reserved_blocks=`expr $blocks_per_device / 100`
echo "Reserved blocks for wear level [$wear_level_reserved_blocks]"
#logical_erase_block_size is physical erase block size minus 2 pages for UBI
logical_pages_per_block=`expr $pages_per_block - 2`
8. logical_erase_block_size=`expr $page_size_in_bytes * $logical_pages_per_block`
echo "Logical erase block size [$logical_erase_block_size]bytes."
#Block size = page_size * pages_per_block
block_size=`expr $page_size_in_bytes * $pages_per_block`
echo "Block size [$block_size]bytes."
#physical blocks on a partition = partition size / block size
partition_physical_blocks=`expr $partition_size_in_bytes / $block_size`
echo "Physical blocks in a partition [$partition_physical_blocks]"
#Logical blocks on a partition = physical blocks on a partitiion - reserved for wear level
patition_logical_blocks=`expr $partition_physical_blocks - $wear_level_reserved_blocks`
echo "Logical blocks in a partition [$patition_logical_blocks]"
#File-system volume = Logical blocks in a partition * Logical erase block size
fs_vol_size=`expr $patition_logical_blocks * $logical_erase_block_size`
echo "File-system volume [$fs_vol_size]bytes."
echo
echo "Generating configuration file..."
echo "[rootfs-volume]" > $config_file
echo "mode=ubi" >> $config_file
echo "image=rootfs_ubifs.img" >> $config_file
echo "vol_id=0" >> $config_file
echo "vol_size=$fs_vol_size" >> $config_file
echo "vol_type=dynamic" >> $config_file
echo "vol_name=system" >> $config_file
echo
# Note: Check necessary program for installation
#echo -n "Checking necessary program for installation......"
#check_program mkfs.ubifs ubinize
#echo "Done"
#Generate ubifs image
echo -n "Generating ubifs..."
./mkfs.ubifs -x lzo -m $page_size_in_bytes -e $logical_erase_block_size -c $patition_logical_blocks -o
rootfs_ubifs.img -d $path_to_rootfs
check_result
echo -n "Generating ubi image out of the ubifs..."
./ubinize -o ubi.img -m $page_size_in_bytes -p $block_size -s $page_size_in_bytes $config_file -v
check_result
rm -f rootfs_ubifs.img
rm -f $config_file
12. LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
# Tell it to build an APK
include $(BUILD_PACKAGE)
(5)编译一个依赖于静态 Java 库(static.jar)的应用程序
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# List of static libraries to include in the package
LOCAL_STATIC_JAVA_LIBRARIES := static-library
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
# Tell it to build an APK
include $(BUILD_PACKAGE)
(6)编译一个需要用平台的 key 签名的应用程序
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_CERTIFICATE := platform
# Tell it to build an APK
include $(BUILD_PACKAGE)
(7)编译一个需要用特定 key 前面的应用程序
LOCAL_PATH := $(call my-dir)
13. include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_CERTIFICATE := vendor/example/certs/app
# Tell it to build an APK
include $(BUILD_PACKAGE)
(8)添加一个预编译应用程序
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Module name should match apk name to be installed.
LOCAL_MODULE := LocalModuleName
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
(9)添加一个静态 JAVA 库
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Any libraries that this library depends on
LOCAL_JAVA_LIBRARIES := android.test.runner
# The name of the jar file to create
LOCAL_MODULE := sample
# Build a static jar file.
include $(BUILD_STATIC_JAVA_LIBRARY)
(10)Android.mk 的编译模块中间可以定义相关的编译内容,也就是指定相关的变量如下:
LOCAL_AAPT_FLAGS
LOCAL_ACP_UNAVAILABLE
27. android 目标平台可以正常启动,但是启动过程中的 android 字符没有显示出来,这个是 linux 内核配
置 的 问 题
打 开 内 核 framebuffer 控 制 台 即 可 。
(1)make menuconifg 后 选 择 Device Drivers->Graphics support->Console display driver
support->Framebuffer Console support
然 后 打 开 相 关 的 几 个 配 置 选 项 即 可 。
(2) 直 接 修 改 内 核 配 置 文 件 , 如 下 :
CONFIG_FRAMEBUFFER_CONSOLE=y
CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
CONFIG_FONTS=y
CONFIG_FONT_8x8=y
CONFIG_FONT_8x16=y
CONFIG_FONT_6x11=y
# CONFIG_FONT_7x14 is not set
# CONFIG_FONT_PEARL_8x8 is not set
# CONFIG_FONT_ACORN_8x8 is not set
# CONFIG_FONT_MINI_4x6 is not set
# CONFIG_FONT_SUN8x16 is not set
# CONFIG_FONT_SUN12x22 is not set
# CONFIG_FONT_10x18 is not set
(3)android 启 动 过 程 中 的 android 字 符 显 示 在 源 代 码 的 system/core/init.c 中 , 如 下 :
if( load_565rle_image(INIT_IMAGE_FILE) ) {
fd = open("/dev/tty0", O_WRONLY);
if (fd >= 0) {
const char *msg;
msg = "n"
"n"
"n"
"n"
"n"
"n"
"n" // console is 40 cols x 30 lines
"n"
"n"
"n"
"n"
"n"
"n"
"n"
" A N D R O I D ";
write(fd, msg, strlen(msg));
close(fd);
}
}
52. android 系统开发(六)-HAL 层开发基础
Android HAL 层,即硬件抽象层,是 Google 响应厂家“希望不公开源码”的要求推出的新概念
1,源代码和目标位置
源代码: /hardware/libhardware 目录,该目录的目录结构如下:
/hardware/libhardware/hardware.c 编译成 libhardware.so,目标位置为/system/lib 目录
/hardware/libhardware/include/hardware 目录下包含如下头文件:
hardware.h 通用硬件模块头文件
copybit.h copybit 模块头文件
gralloc.h gralloc 模块头文件
lights.h 背光模块头文件
overlay.h overlay 模块头文件
qemud.h qemud 模块头文件
sensors.h 传感器模块头文件
/hardware/libhardware/modules 目录下定义了很多硬件模块
这些硬件模块都编译成 xxx.xxx.so,目标位置为/system/lib/hw 目录
2,HAL 层的实现方式
JNI->通用硬件模块->硬件模块->内核驱动接口
具体一点:JNI->libhardware.so->xxx.xxx.so->kernel
具体来说: android frameworks 中 JNI 调用 /hardware/libhardware/hardware.c 中定义的 hw_get_module 函数
来获取硬件模块,
然后调用硬件模块中的方法,硬件模块中的方法直接调用内核接口完成相关功能
3,通用硬件模块(libhardware.so)
(1)头文件为:/hardware/libhardware/include/hardware/hardware.h
头文件中主要定义了通用硬件模块结构体 hw_module_t,声明了 JNI 调用的接口函数 hw_get_module
hw_module_t 定义如下:
typedef struct hw_module_t {
/** tag must be initialized to HARDWARE_MODULE_TAG */
uint32_t tag;
/** major version number for the module */
uint16_t version_major;
/** minor version number of the module */
uint16_t version_minor;
/** Identifier of module */
const char *id;
/** Name of this module */
const char *name;
/** Author/owner/implementor of the module */
const char *author;
53. /** Modules methods */
struct hw_module_methods_t* methods; //硬件模块的方法
/** module's dso */
void* dso;
/** padding to 128 bytes, reserved for future use */
uint32_t reserved[32-7];
} hw_module_t;
硬件模块方法结构体 hw_module_methods_t 定义如下:
typedef struct hw_module_methods_t {
/** Open a specific device */
int (*open)(const struct hw_module_t* module, const char* id,
struct hw_device_t** device);
} hw_module_methods_t;
只定义了一个 open 方法,其中调用的设备结构体参数 hw_device_t 定义如下:
typedef struct hw_device_t {
/** tag must be initialized to HARDWARE_DEVICE_TAG */
uint32_t tag;
/** version number for hw_device_t */
uint32_t version;
/** reference to the module this device belongs to */
struct hw_module_t* module;
/** padding reserved for future use */
uint32_t reserved[12];
/** Close this device */
int (*close)(struct hw_device_t* device);
} hw_device_t;
hw_get_module 函数声明如下:
int hw_get_module(const char *id, const struct hw_module_t **module);
参数 id 为模块标识,定义在/hardware/libhardware/include/hardware 目录下的硬件模块头文件中,
参数 module 是硬件模块地址,定义了/hardware/libhardware/include/hardware/hardware.h 中
(2)hardware.c 中主要是定义了 hw_get_module 函数如下:
#define HAL_LIBRARY_PATH "/system/lib/hw"
static const char *variant_keys[] = {
"ro.hardware",
"ro.product.board",
54. "ro.board.platform",
"ro.arch"
};
static const int HAL_VARIANT_KEYS_COUNT =
(sizeof(variant_keys)/sizeof(variant_keys[0]));
int hw_get_module(const char *id, const struct hw_module_t **module)
{
int status;
int i;
const struct hw_module_t *hmi = NULL;
char prop[PATH_MAX];
char path[PATH_MAX];
for (i=0 ; i<HAL_VARIANT_KEYS_COUNT+1 ; i++)
{
if (i < HAL_VARIANT_KEYS_COUNT)
{
if (property_get(variant_keys[i], prop, NULL) == 0)
{
continue;
}
snprintf(path, sizeof(path), "%s/%s.%s.so",
HAL_LIBRARY_PATH, id, prop);
}
else
{
snprintf(path, sizeof(path), "%s/%s.default.so",
HAL_LIBRARY_PATH, id);
}
if (access(path, R_OK))
{
continue;
}
/* we found a library matching this id/variant */
break;
}
status = -ENOENT;
if (i < HAL_VARIANT_KEYS_COUNT+1) {
/* load the module, if this fails, we're doomed, and we should not try
* to load a different variant. */
status = load(id, path, module);
}
return status;
}