안드로이드/포팅2014. 4. 13. 18:36

[    3.11328] init: skipping insecure file '/default.prop'
[    3.133259] init: skipping insecure file '/init.rc'

라는 에러 메세지가 나오면서 부팅이 안되면, 이는 다음과 같이 젤리빈(이상버전 동일?)에서 다음과 같이 파일 스탯을 참조하여, owner외에 writable 못하게 막아놓았기 때문이다.

143    char *data;
144    int sz;
145    int fd;
146    struct stat sb;
147
148    data = 0;
149    fd = open(fn, O_RDONLY);
150    if(fd < 0) return 0;
151
152    // for security reasons, disallow world-writable
153    // or group-writable files
154    if (fstat(fd, &sb) < 0) {
155        ERROR("fstat failed for '%s'\n", fn);
156        goto oops;
157    }
158    if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0) {


그럼 간단히, 644 혹은, 655 정도로 파일 퍼미션을 바꿔주면 된다.

Posted by code cat
안드로이드/포팅2014. 4. 1. 09:38

출처: Nathaniel Husted, Augst 19, 2011, "Notes regarding Android OS System Development and Security as of Android 2.3.4"


7 Android Escalation of Privledge Attacks

Two attacks against the Android platform currently exist. These attacks

allow a user-level privledge to gain root privledges on the Android platform.

They both exploit userland vulnerabilities in Android. Some of these exploits

have been fixed, but the fixes depend on the manufacturer10

.

7.1 Rage Against The Cage

The Rage Against The Cage exploit takes advantage of a bug in the adb

code. The adb code on android performs certain actions as root at start up

but then drops root privledges using setuid. The exploit is in that the adb

code does not check if the setuid call succeeds of fails. If the call fails adb will

continue to run as the root user. Rage Against The Cage works by forking

enough children processes to reach the NPROC limit on the machine and

attempts to restart adb while NPROC is maxed. When this happens, the

setuid call will fail in adb and it will continue to run with root privledges.

Details can be found at http://intrepidusgroup.com/insight/2010/

09/android-root-source-code-looking-at-the-c-skills/.


7.2 Exploid

The exploid vulnerability takes advantage of the udev system on Android.

The Google developers removed a large amount of code from udev as it would

be implemented on Linux and moved the code into the init daemon. The

dillema is that the udev code used is susceptible to a bug that existed in

udev prior to 1.4.1 that did not verif that kernel messages it received came

from the kernel. In the Android OS this means that init would receive these

requests and init runs as root. A brief overview of the exploit is as follows:

1. Exploid copies it to a system directory writable to the shell user

2. It then sends a “NETLINK_KOBJECT_UEVENT” message to the

kernel.

3. Copied executable checks to see if it srunning as root..

4. When running as root, remounts system partition as read-write

5. Finally copies /system/bin/sh to /system/bin/rootshell and chmod’s

to 04711 to always run as root.

Details can be found at http://intrepidusgroup.com/insight/2010/

09/android-root-source-code-looking-at-the-c-skills/.


7.3 KillingInTheNameOf

The KillingInTheNameOf exploit is slightly different in that it takes advantage

of google’s custom shmem interface “ashmem”. The program maps the

system properties into a processes adress space. The vulnerability is that

they are not maped as write protected. The vulnerability then finds the

ro.secure property of adb and flips it. That allows any shell started by adb

to run as root. Rough details can be found in http://jon.oberheide.org/

files/bsides11-dontrootrobots.pdf.


7.4 ZimperLich

The ZimperLich follows the same structure as the Exploid vulnerability.

There are two major differences, though. First, ZimperLich attacks the

Zygote process on android and its lack of a check against the failure of setuid.

The Zygote process is the parent process which all Dalvik jails are

forked from. the other difference is that attacking Zygote does not require

a shell with a uid so the ZimperLich attack can be run from an APK. The

source code for ZimperLich can be found at http://c-skills.blogspot.

com/2011/02/zimperlich-sources.html.


7.5 GingerBreak

The GingerBreak exploit works in a similar manner to the Exploid vulnerability.

The difference is that in this case the exploit takes advantage of the

“vold” daemon improperly trusting messages recieved. A buffer underflow attack

is commited that causes and escalation of privledge attack. The attack

was found to work on on a number of devices from Android 2.2 to Android

3.0. The vulnerability is CVE-2011-1823. The very general description can be

found at https://groups.google.com/group/android-security-discuss/

browse\_thread/thread/1ac1582b7307fc5c. Source code for the exploit

can be found at http://c-skills.blogspot.com/2011/04/yummy-yummy-gingerbreak.

html.

This has supposedly been fixed in newer versions of the Android source

11 as of May 2nd.

Posted by code cat
안드로이드/포팅2013. 12. 29. 18:24

 통신사를 끼고 해보진 않아서 생략되는 부분도 있지만, 달리 추가되는 부분도 있다.

그래도 나름 잘 정리해 놓은거 같다.

 

 

'안드로이드 > 포팅' 카테고리의 다른 글

skipping insecure file  (0) 2014.04.13
Android Exploit  (0) 2014.04.01
안드로이드 adb 명령어 리스트  (0) 2013.12.01
안드로이드 settings 데이터 알아보기  (0) 2013.12.01
안드로이드 system 파티션 remount  (0) 2013.11.28
Posted by code cat
안드로이드/포팅2013. 12. 1. 11:03

xda 포럼에서 가져왔는데 링크가...



 adb devices   

 list all connected devices

 adb push <local> <remote>

 copy file/dir to device

 adb pull <remote> [<local>]

 copy file/dir from device

 adb sync [ <directory> ]

 copy host->device only if changed

 adb shell

 run remote shell interactively

 adb shell <command>

 run remote shell command

 adb emu <command>

 run emulator console command

 adb logcat [ <filter-spec> ]

 View device log

 adb forward <local> <remote>

localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)

 forward socket connections forward specs are one of: tcp:<port>

 adb jdwp 

 list PIDs of processes hosting a JDWP transport

 adb install [-l] [-r] [-s] <file> push this package file to the device and install it
 adb uninstall [-k] <package> remove this app package from the device (‘-k’ means keep the data and cache directories)
 adb bugreport return all information from the device that should be included in a bug report.
 adb help show this help message
 adb version show version num
 adb wait-for-device block until device is online
 adb start-server ensure that there is a server running
 adb kill-server

 kill the server if it is running

 adb get-state prints: offline | bootloader | device
 adb get-serialno

 prints: <serial-number>

 adb status-window continuously print device status for a specified device
 adb remount remounts the /system partition on the device read-write
 adb reboot [bootloader|recovery] reboots the device, optionally into the bootloader or recovery program
 adb reboot-bootloader

 reboots the device into the bootloader

 adb root

 restarts the adbd daemon with root permissions

 adb usb  restarts the adbd daemon listening on USB
 adb tcpip <port> 

 restarts the adbd daemon listening on TCP on the specified port




Posted by code cat
안드로이드/포팅2013. 12. 1. 08:36

안드로이드에서 settings에 저장되는 여러 값에 대해 궁금하다면 다음과 같이 보면 된다.

우선 settings에 관련된 value들은 db에 저장되는 이는 다음의 위치에 있다.


/data/data/com.android.providers.settings/databases/settings.db


이 db를 접속하려면 console에서 다음과 같이 하자.

#sqlite3 settings.db



그러면 sqlite 콘솔이 뜨는데, 여기서 다음과 같이 해보자.

sqlite>.table



그러면 현재 query가능한 table들이 나온다.

android_metadata system bluetooth_devices secure



여기서 secure의 값들을 보고 싶으면 아래와 같이 하면 된다.

sqlite>select * from system;



해당 sqlite3 명령어에 대해서는 인터넷에 검색하면 잘 나온다.

참고로 sqlite3 에서 나오는 명령어는 .quit이다.


Posted by code cat
안드로이드/포팅2013. 11. 28. 16:59

system 파티션을 RW으로 remount하기 위해서는 다음과 같이 콘솔에서 실행하면 된다.

(system 파티션에 대한 path는 각자 다르니 사용하는 디바이스에 맞추면 된다.)


mount -o rw,remount /dev/block/.../by-name/system


'안드로이드 > 포팅' 카테고리의 다른 글

안드로이드 adb 명령어 리스트  (0) 2013.12.01
안드로이드 settings 데이터 알아보기  (0) 2013.12.01
Android Build System 용어  (0) 2013.10.16
GGLContext 에 대하여  (0) 2013.03.24
pthread_cancel()  (0) 2013.02.04
Posted by code cat
안드로이드/포팅2013. 10. 16. 08:19
Android Build System

Android Build System

Status: Draft   (as of May 18, 2006)

Contents

Objective

The primary goals of reworking the build system are (1) to make dependencies work more reliably, so that when files need to rebuilt, they are, and (2) to improve performance of the build system so that unnecessary modules are not rebuilt, and so doing a top-level build when little or nothing needs to be done for a build takes as little time as possible.

Principles and Use Cases and Policy

Given the above objective, these are the overall principles and use cases that we will support. This is not an exhaustive list.

Multiple Targets

It needs to be possible to build the Android platform for multiple targets. This means:

  • The build system will support building tools for the host platform, both ones that are used in the build process itself, and developer tools like the simulator.
  • The build system will need to be able to build tools on Linux (definitely Goobuntu and maybe Grhat), MacOS, and to some degree on Windows.
  • The build system will need to be able to build the OS on Linux, and in the short-term, MacOS. Note that this is a conscious decision to stop building the OS on Windows. We are going to rely on the emulator there and not attempt to use the simulator. This is a requirement change now that the emulator story is looking brighter.

Non-Recursive Make

To achieve the objectives, the build system will be rewritten to use make non-recursively. For more background on this, read Recursive Make Considered Harmful. For those that don't want PDF, here is the Google translated version.

Rapid Compile-Test Cycles

When developing a component, for example a C++ shared library, it must be possible to easily rebuild just that component, and not have to wait more than a couple seconds for dependency checks, and not have to wait for unneeded components to be built.

Both Environment and Config File Based Settings

To set the target, and other options, some people on the team like to have a configuration file in a directory so they do not have an environment setup script to run, and others want an environment setup script to run so they can run builds in different terminals on the same tree, or switch back and forth in one terminal. We will support both.

Object File Directory / make clean

Object files and other intermediate files will be generated into a directory that is separate from the source tree. The goal is to have make clean be "rm -rf " in the tree root directory. The primary goals of this are to simplify searching the source tree, and to make "make clean" more reliable.

SDK

The SDK will be a tarball that will allow non-OS-developers to write apps. The apps will actually be built by first building the SDK, and then building the apps against that SDK. This will hopefully (1) make writing apps easier for us, because we won't have to rebuild the OS as much, and we can use the standard java-app development tools, and (2) allow us to dog-food the SDK, to help ensure its quality. Cedric has suggested (and I agree) that apps built from the SDK should be built with ant. Stay tuned for more details as we figure out exactly how this will work.

Dependecies

Dependencies should all be automatic. Unless there is a custom tool involved (e.g. the webkit has several), the dependencies for shared and static libraries, .c, .cpp, .h, .java, java libraries, etc., should all work without intervention in the Android.mk file.

Hiding command lines

The default of the build system will be to hide the command lines being executed for make steps. It will be possible to override this by specifying the showcommands pseudo-target, and possibly by setting an environment variable.

Wildcard source files

Wildcarding source file will be discouraged. It may be useful in some scenarios. The default $(wildcard *) will not work due to the current directory being set to the root of the build tree.

Multiple targets in one directory

It will be possible to generate more than one target from a given subdirectory. For example, libutils generates a shared library for the target and a static library for the host.

Makefile fragments for modules

Android.mk is the standard name for the makefile fragments that control the building of a given module. Only the top directory should have a file named "Makefile".

Use shared libraries

Currently, the simulator is not built to use shared libraries. This should be fixed, and now is a good time to do it. This implies getting shared libraries to work on Mac OS.

Nice to Have

These things would be nice to have, and this is a good place to record them, however these are not promises.

Simultaneous Builds

The hope is to be able to do two builds for different combos in the same tree at the same time, but this is a stretch goal, not a requirement. Doing two builds in the same tree, not at the same time must work. (update: it's looking like we'll get the two builds at the same time working)

Deleting headers (or other dependecies)

Problems can arise if you delete a header file that is referenced in ".d" files. The easy way to deal with this is "make clean". There should be a better way to handle it. (from fadden)

One way of solving this is introducing a dependency on the directory. The problem is that this can create extra dependecies and slow down the build. It's a tradeoff.

Multiple builds

General way to perform builds across the set of known platforms. This would make it easy to perform multiple platform builds when testing a change, and allow a wide-scale "make clean". Right now the buildspec.mk or environment variables need to be updated before each build. (from fadden)

Aftermarket Locales and Carrier

We will eventually need to add support for creating locales and carrier customizations to the SDK, but that will not be addressed right now.

Usage

You've read (or scrolled past) all of the motivations for this build system, and you want to know how to use it. This is the place.

Your first build

The Building document describes how do do builds.

build/envsetup.sh functions

If you source the file build/envsetup.sh into your bash environment, . build/envsetup.shyou'll get a few helpful shell functions:
  • printconfig - Prints the current configuration as set by the lunch and choosecombo commands.
  • m - Runs make from the top of the tree. This is useful because you can run make from within subdirectories. If you have the TOP environment variable set, it uses that. If you don't, it looks up the tree from the current directory, trying to find the top of the tree.
  • croot - cd to the top of the tree.
  • sgrep - grep for the regex you provide in all .c, .cpp, .h, .java, and .xml files below the current directory.

Build flavors/types

When building for a particular product, it's often useful to have minor variations on what is ultimately the final release build. These are the currently-defined "flavors" or "types" (we need to settle on a real name for these).

eng This is the default flavor. A plain "make" is the same as "make eng". droid is an alias for eng.
  • Installs modules tagged with: eng, debug, shell_$(TARGET_SHELL), user, and/or development.
  • Installs non-APK modules that have no tags specified.
  • Installs APKs according to the product definition files, in addition to tagged APKs.
  • ro.secure=0
  • ro.debuggable=1
  • ro.kernel.android.checkjni=1
  • adb is enabled by default.
user "make user"

This is the flavor intended to be the final release bits.

  • Installs modules tagged with shell_$(TARGET_SHELL) and user.
  • Installs non-APK modules that have no tags specified.
  • Installs APKs according to the product definition files; tags are ignored for APK modules.
  • ro.secure=1
  • ro.debuggable=0
  • adb is disabled by default.
userdebug "make userdebug"

The same as user, except:

  • Also installs modules tagged with debug.
  • ro.debuggable=1
  • adb is enabled by default.

If you build one flavor and then want to build another, you should run "make installclean" between the two makes to guarantee that you don't pick up files installed by the previous flavor. "make clean" will also suffice, but it takes a lot longer.

More pseudotargets

Sometimes you want to just build one thing. The following pseudotargets are there for your convenience:

  • droid - make droid is the normal build. This target is here because the default target has to have a name.
  • all - make all builds everything make droid does, plus everything whose LOCAL_MODULE_TAGS do not include the "droid" tag. The build server runs this to make sure that everything that is in the tree and has an Android.mk builds.
  • clean-$(LOCAL_MODULE) and clean-$(LOCAL_PACKAGE_NAME) - Let you selectively clean one target. For example, you can type make clean-libutils and it will delete libutils.so and all of the intermediate files, or you can type make clean-Home and it will clean just the Home app.
  • clean - make clean deletes all of the output and intermediate files for this configuration. This is the same as rm -rf out/<configuration>/
  • clobber - make clobber deletes all of the output and intermediate files for all configurations. This is the same as rm -rf out/.
  • dataclean - make dataclean deletes contents of the data directory inside the current combo directory. This is especially useful on the simulator and emulator, where the persistent data remains present between builds.
  • showcommands - showcommands is a modifier target which causes the build system to show the actual command lines for the build steps, instead of the brief descriptions. Most people don't like seeing the actual commands, because they're quite long and hard to read, but if you need to for debugging purposes, you can add showcommands to the list of targets you build. For example make showcommands will build the default android configuration, and make runtime showcommands will build just the runtime, and targets that it depends on, while displaying the full command lines. Please note that there are a couple places where the commands aren't shown here. These are considered bugs, and should be fixed, but they're often hard to track down. Please let android-build-team know if you find any.
  • LOCAL_MODULE - Anything you specify as a LOCAL_MODULE in an Android.mk is made into a pseudotarget. For example, make runtime might be shorthand for make out/linux-x86-debug/system/bin/runtime (which would work), and make libkjs might be shorthand for make out/linux-x86-debug/system/lib/libkjs.so (which would also work).
  • targets - make targets will print a list of all of the LOCAL_MODULE names you can make.

How to add another component to the build - Android.mk templates

You have a new library, a new app, or a new executable. For each of the common types of modules, there is a corresponding file in the templates directory. It will usually be enough to copy one of these, and fill in your own values. Some of the more esoteric values are not included in the templates, but are instead just documented here, as is the documentation on using custom tools to generate files.

Mostly, you can just look for the TODO comments in the templates and do what it says. Please remember to delete the TODO comments when you're done to keep the files clean. The templates have minimal documentation in them, because they're going to be copied, and when that gets stale, the copies just won't get updated. So read on...

Apps

Use the templates/apps file.

This template is pretty self-explanitory. See the variables below for more details.

Java Libraries

Use the templates/java_library file.

The interesting thing here is the value of LOCAL_MODULE, which becomes the name of the jar file. (Actually right now, we're not making jar files yet, just directories of .class files, but the directory is named according to what you put in LOCAL_MODULE). This name will be what goes in the LOCAL_JAVA_LIBRARIES variable in modules that depend on your java library.

C/C++ Executables

Use the templates/executable file, or the templates/executable_host file.

This template has a couple extra options that you usually don't need. Please delete the ones you don't need, and remove the TODO comments. It makes the rest of them easier to read, and you can always refer back to the templates if you need them again later.

By default, on the target these are built into /system/bin, and on the host, they're built into /host/bin. These can be overridden by setting LOCAL_MODULE_PATH. See Putting targets elsewhere for more.

Shared Libraries

Use the templates/shared_library file, or the templates/shared_library_host file.

Remember that on the target, we use shared libraries, and on the host, we use static libraries, since executable size isn't as big an issue, and it simplifies distribution in the SDK.

Static Libraries

Use the templates/static_library file, or the templates/static_library_host file.

Remember that on the target, we use shared libraries, and on the host, we use static libraries, since executable size isn't as big an issue, and it simplifies distribution in the SDK.

Using Custom Tools

If you have a tool that generates source files for you, it's possible to have the build system get the dependencies correct for it. Here are a couple of examples. $@ is the make built-in variable for "the current target." The red parts are the parts you'll need to change.

You need to put this after you have declared LOCAL_PATH and LOCAL_MODULE, because the $(local-intermediates-dir) and $(local-host-intermediates-dir) macros use these variables to determine where to put the files.

Example 1

Here, there is one generated file, called chartables.c, which doesn't depend on anything. And is built by the tool built to $(HOST_OUT_EXECUTABLES)/dftables. Note on the second to last line that a dependency is created on the tool.

intermediates:= $(local-intermediates-dir)
GEN := $(intermediates)/chartables.c
$(GEN): PRIVATE_CUSTOM_TOOL = $(HOST_OUT_EXECUTABLES)/dftables $@
$(GEN): $(HOST_OUT_EXECUTABLES)/dftables
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
Example 2

Here as a hypothetical example, we use use cat as if it were to transform a file. Pretend that it does something useful. Note how we use a target-specific variable called PRIVATE_INPUT_FILE to store the name of the input file.

intermediates:= $(local-intermediates-dir)
GEN := $(intermediates)/file.c
$(GEN): PRIVATE_INPUT_FILE := $(LOCAL_PATH)/input.file
$(GEN): PRIVATE_CUSTOM_TOOL = cat $(PRIVATE_INPUT_FILE) > $@
$(GEN): $(LOCAL_PATH)/file.c
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
Example 3

If you have several files that are all similar in name, and use the same tool, you can combine them. (here the *.lut.h files are the generated ones, and the *.cpp files are the input files)

intermediates:= $(local-intermediates-dir)
GEN := $(addprefix $(intermediates)/kjs/, \
            array_object.lut.h \
            bool_object.lut.h \
        )
$(GEN): PRIVATE_CUSTOM_TOOL = perl libs/WebKitLib/WebKit/JavaScriptCore/kjs/create_hash_table $< -i > $@
$(GEN): $(intermediates)/%.lut.h : $(LOCAL_PATH)/%.cpp
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)

Platform specific conditionals

Sometimes you need to set flags specifically for different platforms. Here is a list of which values the different build-system defined variables will be set to and some examples.

For a device build, TARGET_OS is linux (we're using linux!), and TARGET_ARCH is arm.

For a simulator build, TARGET_OS and TARGET_ARCH are set to the same as HOST_OS and HOST_ARCH are on your platform. TARGET_PRODUCT is the name of the target hardware/product you are building for. The value sim is used for the simulator. We haven't thought through the full extent of customization that will happen here, but likely there will be additional UI configurations specified here as well.

HOST_OS
linux
darwin
(cygwin)
HOST_ARCH
x86
HOST_BUILD_TYPE
release
debug
TARGET_OS
linux
darwin
(cygwin)
TARGET_ARCH
arm
x86
TARGET_BUILD_TYPE
release
debug
TARGET_PRODUCT
sim
dream
sooner

Some Examples

ifeq ($(TARGET_BUILD_TYPE),release)
LOCAL_CFLAGS += -DNDEBUG=1
endif

# from libutils
ifeq ($(TARGET_OS),linux)
# Use the futex based mutex and condition variable
# implementation from android-arm because it's shared mem safe
LOCAL_SRC_FILES += futex_synchro.c
LOCAL_LDLIBS += -lrt -ldl
endif

Putting modules elsewhere

If you have modules that normally go somewhere, and you need to have them build somewhere else, read this. One use of this is putting files on the root filesystem instead of where they normally go in /system. Add these lines to your Android.mk:

LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)

For executables and libraries, you need to also specify a LOCAL_UNSTRIPPED_PATH location, because on target builds, we keep the unstripped executables so GDB can find the symbols.

Look in config/envsetup.make for all of the variables defining places to build things.

FYI: If you're installing an executable to /sbin, you probably also want to set LOCAL_FORCE_STATIC_EXCUTABLE := true in your Android.mk, which will force the linker to only accept static libraries.

Android.mk variables

These are the variables that you'll commonly see in Android.mk files, listed alphabetically.

But first, a note on variable naming:

LOCAL_ASSET_FILES

In Android.mk files that include $(BUILD_PACKAGE) set this to the set of files you want built into your app. Usually:

LOCAL_ASSET_FILES += $(call find-subdir-assets)

This will probably change when we switch to ant for the apps' build system.

LOCAL_CC

If you want to use a different C compiler for this module, set LOCAL_CC to the path to the compiler. If LOCAL_CC is blank, the appropriate default compiler is used.

LOCAL_CXX

If you want to use a different C++ compiler for this module, set LOCAL_CXX to the path to the compiler. If LOCAL_CXX is blank, the appropriate default compiler is used.

LOCAL_CFLAGS

If you have additional flags to pass into the C or C++ compiler, add them here. For example:

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1

LOCAL_CPPFLAGS

If you have additional flags to pass into only the C++ compiler, add them here. For example:

LOCAL_CPPFLAGS += -ffriend-injection

LOCAL_CPPFLAGS is guaranteed to be after LOCAL_CFLAGS on the compile line, so you can use it to override flags listed in LOCAL_CFLAGS.

LOCAL_CPP_EXTENSION

If your C++ files end in something other than ".cpp", you can specify the custom extension here. For example:

LOCAL_CPP_EXTENSION := .cc

Note that all C++ files for a given module must have the same extension; it is not currently possible to mix different extensions.

LOCAL_NO_DEFAULT_COMPILER_FLAGS

Normally, the compile line for C and C++ files includes global include paths and global cflags. If LOCAL_NO_DEFAULT_COMPILER_FLAGS is non-empty, none of the default includes or flags will be used when compiling C and C++ files in this module. LOCAL_C_INCLUDES, LOCAL_CFLAGS, and LOCAL_CPPFLAGS will still be used in this case, as will any DEBUG_CFLAGS that are defined for the module.

LOCAL_COPY_HEADERS

This will be going away.

The set of files to copy to the install include tree. You must also supply LOCAL_COPY_HEADERS_TO.

This is going away because copying headers messes up the error messages, and may lead to people editing those headers instead of the correct ones. It also makes it easier to do bad layering in the system, which we want to avoid. We also aren't doing a C/C++ SDK, so there is no ultimate requirement to copy any headers.

LOCAL_COPY_HEADERS_TO

This will be going away.

The directory within "include" to copy the headers listed in LOCAL_COPY_HEADERS to.

This is going away because copying headers messes up the error messages, and may lead to people editing those headers instead of the correct ones. It also makes it easier to do bad layering in the system, which we want to avoid. We also aren't doing a C/C++ SDK, so there is no ultimate requirement to copy any headers.

LOCAL_C_INCLUDES

Additional directories to instruct the C/C++ compilers to look for header files in. These paths are rooted at the top of the tree. Use LOCAL_PATH if you have subdirectories of your own that you want in the include paths. For example:

LOCAL_C_INCLUDES += extlibs/zlib-1.2.3
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src

You should not add subdirectories of include to LOCAL_C_INCLUDES, instead you should reference those files in the #include statement with their subdirectories. For example:

#include <utils/KeyedVector.h>
not #include <KeyedVector.h>

There are some components that are doing this wrong, and should be cleaned up.

LOCAL_MODULE_TAGS

Set LOCAL_MODULE_TAGS to any number of whitespace-separated tags. If the tag list is empty or contains droid, the module will get installed as part of a make droid. Modules with the tag shell_$(TARGET_SHELL) will also be installed. Otherwise, it will only get installed by running make <your-module> or with the make all pseudotarget.

LOCAL_REQUIRED_MODULES

Set LOCAL_REQUIRED_MODULES to any number of whitespace-separated module names, like "libblah" or "Email". If this module is installed, all of the modules that it requires will be installed as well. This can be used to, e.g., ensure that necessary shared libraries or providers are installed when a given app is installed.

LOCAL_FORCE_STATIC_EXECUTABLE

If your executable should be linked statically, set LOCAL_FORCE_STATIC_EXECUTABLE:=true. There is a very short list of libraries that we have in static form (currently only libc). This is really only used for executables in /sbin on the root filesystem.

LOCAL_GENERATED_SOURCES

Files that you add to LOCAL_GENERATED_SOURCES will be automatically generated and then linked in when your module is built. See the Custom Tools template makefile for an example.

LOCAL_JAVACFLAGS

If you have additional flags to pass into the javac compiler, add them here. For example:

LOCAL_JAVACFLAGS += -Xlint:deprecation

LOCAL_JAVA_LIBRARIES

When linking Java apps and libraries, LOCAL_JAVA_LIBRARIES specifies which sets of java classes to include. Currently there are two of these: core and framework. In most cases, it will look like this:

LOCAL_JAVA_LIBRARIES := core framework

Note that setting LOCAL_JAVA_LIBRARIES is not necessary (and is not allowed) when building an APK with "include $(BUILD_PACKAGE)". The appropriate libraries will be included automatically.

LOCAL_LDFLAGS

You can pass additional flags to the linker by setting LOCAL_LDFLAGS. Keep in mind that the order of parameters is very important to ld, so test whatever you do on all platforms.

LOCAL_LDLIBS

LOCAL_LDLIBS allows you to specify additional libraries that are not part of the build for your executable or library. Specify the libraries you want in -lxxx format; they're passed directly to the link line. However, keep in mind that there will be no dependency generated for these libraries. It's most useful in simulator builds where you want to use a library preinstalled on the host. The linker (ld) is a particularly fussy beast, so it's sometimes necessary to pass other flags here if you're doing something sneaky. Some examples:

LOCAL_LDLIBS += -lcurses -lpthread
LOCAL_LDLIBS += -Wl,-z,origin

LOCAL_NO_MANIFEST

If your package doesn't have a manifest (AndroidManifest.xml), then set LOCAL_NO_MANIFEST:=true. The common resources package does this.

LOCAL_PACKAGE_NAME

LOCAL_PACKAGE_NAME is the name of an app. For example, Dialer, Contacts, etc. This will probably change or go away when we switch to an ant-based build system for the apps.

LOCAL_PATH

The directory your Android.mk file is in. You can set it by putting the following as the first line in your Android.mk:

LOCAL_PATH := $(my-dir)

The my-dir macro uses the MAKEFILE_LIST variable, so you must call it before you include any other makefiles. Also, consider that any subdirectories you inlcude might reset LOCAL_PATH, so do your own stuff before you include them. This also means that if you try to write several include lines that reference LOCAL_PATH, it won't work, because those included makefiles might reset LOCAL_PATH.

LOCAL_POST_PROCESS_COMMAND

For host executables, you can specify a command to run on the module after it's been linked. You might have to go through some contortions to get variables right because of early or late variable evaluation:

module := $(HOST_OUT_EXECUTABLES)/$(LOCAL_MODULE)
LOCAL_POST_PROCESS_COMMAND := /Developer/Tools/Rez -d __DARWIN__ -t APPL\
       -d __WXMAC__ -o $(module) Carbon.r

LOCAL_PREBUILT_EXECUTABLES

When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), set these to executables that you want copied. They're located automatically into the right bin directory.

LOCAL_PREBUILT_LIBS

When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), set these to libraries that you want copied. They're located automatically into the right lib directory.

LOCAL_SHARED_LIBRARIES

These are the libraries you directly link against. You don't need to pass transitively included libraries. Specify the name without the suffix:

LOCAL_SHARED_LIBRARIES := \
    libutils \
    libui \
    libaudio \
    libexpat \
    libsgl

LOCAL_SRC_FILES

The build system looks at LOCAL_SRC_FILES to know what source files to compile -- .cpp .c .y .l .java. For lex and yacc files, it knows how to correctly do the intermediate .h and .c/.cpp files automatically. If the files are in a subdirectory of the one containing the Android.mk, prefix them with the directory name:

LOCAL_SRC_FILES := \
    file1.cpp \
    dir/file2.cpp

LOCAL_STATIC_LIBRARIES

These are the static libraries that you want to include in your module. Mostly, we use shared libraries, but there are a couple of places, like executables in sbin and host executables where we use static libraries instead.

LOCAL_STATIC_LIBRARIES := \
    libutils \
    libtinyxml

LOCAL_MODULE

LOCAL_MODULE is the name of what's supposed to be generated from your Android.mk. For exmample, for libkjs, the LOCAL_MODULE is "libkjs" (the build system adds the appropriate suffix -- .so .dylib .dll). For app modules, use LOCAL_PACKAGE_NAME instead of LOCAL_MODULE. We're planning on switching to ant for the apps, so this might become moot.

LOCAL_MODULE_PATH

Instructs the build system to put the module somewhere other than what's normal for its type. If you override this, make sure you also set LOCAL_UNSTRIPPED_PATH if it's an executable or a shared library so the unstripped binary has somewhere to go. An error will occur if you forget to.

See Putting modules elsewhere for more.

LOCAL_UNSTRIPPED_PATH

Instructs the build system to put the unstripped version of the module somewhere other than what's normal for its type. Usually, you override this because you overrode LOCAL_MODULE_PATH for an executable or a shared library. If you overrode LOCAL_MODULE_PATH, but not LOCAL_UNSTRIPPED_PATH, an error will occur.

See Putting modules elsewhere for more.

LOCAL_WHOLE_STATIC_LIBRARIES

These are the static libraries that you want to include in your module without allowing the linker to remove dead code from them. This is mostly useful if you want to add a static library to a shared library and have the static library's content exposed from the shared library.

LOCAL_WHOLE_STATIC_LIBRARIES := \
    libsqlite3_android

LOCAL_YACCFLAGS

Any flags to pass to invocations of yacc for your module. A known limitation here is that the flags will be the same for all invocations of YACC for your module. This can be fixed. If you ever need it to be, just ask.

LOCAL_YACCFLAGS := -p kjsyy

Implementation Details

You should never have to touch anything in the config directory unless you're adding a new platform, new tools, or adding new features to the build system. In general, please consult with the build system owner(s) (android-build-team) before you go mucking around in here. That said, here are some notes on what's going on under the hood.

Environment Setup / buildspec.mk Versioning

In order to make easier for people when the build system changes, when it is necessary to make changes to buildspec.mk or to rerun the environment setup scripts, they contain a version number in the variable BUILD_ENV_SEQUENCE_NUMBER. If this variable does not match what the build system expects, it fails printing an error message explaining what happened. If you make a change that requires an update, you need to update two places so this message will be printed.

  • In config/envsetup.make, increment the CORRECT_BUILD_ENV_SEQUENCE_NUMBER definition.
  • In buildspec.mk.default, update the BUILD_ENV_SEQUENCE_DUMBER definition to match the one in config/envsetup.make
The scripts automatically get the value from the build system, so they will trigger the warning as well.

Additional makefile variables

You probably shouldn't use these variables. Please consult android-build-team before using them. These are mostly there for workarounds for other issues, or things that aren't completely done right.

LOCAL_ADDITIONAL_DEPENDENCIES

If your module needs to depend on anything else that isn't actually built in to it, you can add those make targets to LOCAL_ADDITIONAL_DEPENDENCIES. Usually this is a workaround for some other dependency that isn't created automatically.

LOCAL_BUILT_MODULE

When a module is built, the module is created in an intermediate directory then copied to its final location. LOCAL_BUILT_MODULE is the full path to the intermediate file. See LOCAL_INSTALLED_MODULE for the path to the final installed location of the module.

LOCAL_HOST

Set by the host_xxx.make includes to tell base_rules.make and the other includes that we're building for the host. Kenneth did this as part of openbinder, and I would like to clean it up so the rules, includes and definitions aren't duplicated for host and target.

LOCAL_INSTALLED_MODULE

The fully qualified path name of the final location of the module. See LOCAL_BUILT_MODULE for the location of the intermediate file that the make rules should actually be constructing.

LOCAL_REPLACE_VARS

Used in some stuff remaining from the openbinder for building scripts with particular values set,

LOCAL_SCRIPTS

Used in some stuff remaining from the openbinder build system that we might find handy some day.

LOCAL_MODULE_CLASS

Which kind of module this is. This variable is used to construct other variable names used to locate the modules. See base_rules.make and envsetup.make.

LOCAL_MODULE_NAME

Set to the leaf name of the LOCAL_BUILT_MODULE. I'm not sure, but it looks like it's just used in the WHO_AM_I variable to identify in the pretty printing what's being built.

LOCAL_MODULE_SUFFIX

The suffix that will be appended to LOCAL_MODULE to form LOCAL_MODULE_NAME. For example, .so, .a, .dylib.

LOCAL_STRIP_MODULE

Calculated in base_rules.make to determine if this module should actually be stripped or not, based on whether LOCAL_STRIPPABLE_MODULE is set, and whether the combo is configured to ever strip modules. With Iliyan's stripping tool, this might change.

LOCAL_STRIPPABLE_MODULE

Set by the include makefiles if that type of module is strippable. Executables and shared libraries are.

LOCAL_SYSTEM_SHARED_LIBRARIES

Used while building the base libraries: libc, libm, libdl. Usually it should be set to "none," as it is in $(CLEAR_VARS). When building these libraries, it's set to the ones they link against. For example, libc, libstdc++ and libdl don't link against anything, and libm links against libc. Normally, when the value is none, these libraries are automatically linked in to executables and libraries, so you don't need to specify them manually.

'안드로이드 > 포팅' 카테고리의 다른 글

안드로이드 settings 데이터 알아보기  (0) 2013.12.01
안드로이드 system 파티션 remount  (0) 2013.11.28
GGLContext 에 대하여  (0) 2013.03.24
pthread_cancel()  (0) 2013.02.04
안드로이드 젤리빈 소스 다운로  (0) 2012.10.03
Posted by code cat
안드로이드/포팅2013. 3. 24. 16:15

아래는 recovery UI 에 사용되는 GGLContext 의 구조체이다.

204 typedef struct {
205    // immediate rendering
206    void (*pointx)(void *con, const GGLcoord* v, GGLcoord r);
207    void (*linex)(void *con,
208            const GGLcoord* v0, const GGLcoord* v1, GGLcoord width);
209    void (*recti)(void* c, GGLint l, GGLint t, GGLint r, GGLint b);
210    void (*trianglex)(void* c,
211            GGLcoord const* v0, GGLcoord const* v1, GGLcoord const* v2);
212
213    // scissor
214    void (*scissor)(void* c, GGLint x, GGLint y, GGLsizei width, GGLsizei height);
215
216    // Set the textures and color buffers
217    void (*activeTexture)(void* c, GGLuint tmu);
218    void (*bindTexture)(void* c, const GGLSurface* surface);
219    void (*colorBuffer)(void* c, const GGLSurface* surface);
220    void (*readBuffer)(void* c, const GGLSurface* surface);
221    void (*depthBuffer)(void* c, const GGLSurface* surface);
222    void (*bindTextureLod)(void* c, GGLuint tmu, const GGLSurface* surface);
223
224    // enable/disable features
225    void (*enable)(void* c, GGLenum name);
226    void (*disable)(void* c, GGLenum name);
227    void (*enableDisable)(void* c, GGLenum name, GGLboolean en);
228
229    // specify the fragment's color
230    void (*shadeModel)(void* c, GGLenum mode);
231    void (*color4xv)(void* c, const GGLclampx* color);
232    // specify color iterators (16.16)
233    void (*colorGrad12xv)(void* c, const GGLcolor* grad);
234
235    // specify Z coordinate iterators (0.32)
236    void (*zGrad3xv)(void* c, const GGLfixed32* grad);
237
238    // specify W coordinate iterators (16.16)
239    void (*wGrad3xv)(void* c, const GGLfixed* grad);
240
241    // specify fog iterator & color (16.16)
242    void (*fogGrad3xv)(void* c, const GGLfixed* grad);
243    void (*fogColor3xv)(void* c, const GGLclampx* color);
244
245    // specify blending parameters
246    void (*blendFunc)(void* c, GGLenum src, GGLenum dst);
247    void (*blendFuncSeparate)(void* c,  GGLenum src, GGLenum dst,
248                                        GGLenum srcAlpha, GGLenum dstAplha);
249
250    // texture environnement (REPLACE / MODULATE / DECAL / BLEND)
251    void (*texEnvi)(void* c,    GGLenum target,
252                                GGLenum pname,
253                                GGLint param);
254
255    void (*texEnvxv)(void* c, GGLenum target,
256            GGLenum pname, const GGLfixed* params);
257
258    // texture parameters (Wrapping, filter)
259    void (*texParameteri)(void* c,  GGLenum target,
260                                    GGLenum pname,
261                                    GGLint param);
262
263    // texture iterators (16.16)
264    void (*texCoord2i)(void* c, GGLint s, GGLint t);
265    void (*texCoord2x)(void* c, GGLfixed s, GGLfixed t);
266
267    // s, dsdx, dsdy, scale, t, dtdx, dtdy, tscale
268    // This api uses block floating-point for S and T texture coordinates.
269    // All values are given in 16.16, scaled by 'scale'. In other words,
270    // set scale to 0, for 16.16 values.
271    void (*texCoordGradScale8xv)(void* c, GGLint tmu, const int32_t* grad8);
272
273    void (*texGeni)(void* c, GGLenum coord, GGLenum pname, GGLint param);
274
275    // masking
276    void (*colorMask)(void* c,  GGLboolean red,
277                                GGLboolean green,
278                                GGLboolean blue,
279                                GGLboolean alpha);
280
281    void (*depthMask)(void* c, GGLboolean flag);
282
283    void (*stencilMask)(void* c, GGLuint mask);
284
285    // alpha func
286    void (*alphaFuncx)(void* c, GGLenum func, GGLclampx ref);
287
288    // depth func
289    void (*depthFunc)(void* c, GGLenum func);
290
291    // logic op
292    void (*logicOp)(void* c, GGLenum opcode);
293
294    // clear
295    void (*clear)(void* c, GGLbitfield mask);
296    void (*clearColorx)(void* c,
297            GGLclampx r, GGLclampx g, GGLclampx b, GGLclampx a);
298    void (*clearDepthx)(void* c, GGLclampx depth);
299    void (*clearStencil)(void* c, GGLint s);
300
301    // framebuffer operations
302    void (*copyPixels)(void* c, GGLint x, GGLint y,
303            GGLsizei width, GGLsizei height, GGLenum type);
304    void (*rasterPos2x)(void* c, GGLfixed x, GGLfixed y);
305    void (*rasterPos2i)(void* c, GGLint x, GGLint y);
306} GGLContext;
307


Posted by code cat
안드로이드/포팅2013. 2. 4. 15:59

쉽게 요약하자면 C library가 고작 pthread_cancle지원하자고 너무 커지기 때문에 바이오닉 C에서는 지원 안한단다. 대신 pthread_cleanup_push()와 pthread_cleanup_pop()은 지원하니까 적절히 사용하자.

pthread_cancel():

   pthread_cancel() will *not* be supported in Bionic, because doing this would
   involve making the C library significantly bigger for very little benefit.

   Consider that:

     - A proper implementation must insert pthread cancellation checks in a lot
       of different places of the C library. And conformance is very difficult
       to test properly.

     - A proper implementation must also clean up resources, like releasing
       memory, or unlocking mutexes, properly if the cancellation happens in a
       complex function (e.g. inside gethostbyname() or fprintf() + complex
       formatting rules). This tends to slow down the path of many functions.

     - pthread cancellation cannot stop all threads: e.g. it can't do anything
       against an infinite loop

     - pthread cancellation itself has short-comings and isn't very portable
       (see http://advogato.org/person/slamb/diary.html?start=49 for example).

   All of this is contrary to the Bionic design goals. If your code depends on
   thread cancellation, please consider alternatives.

   Note however that Bionic does implement pthread_cleanup_push() and
   pthread_cleanup_pop(), which can be used to handle cleanups that happen when
   a thread voluntarily exits through pthread_exit() or returning from its
   main function.

Posted by code cat
안드로이드/포팅2012. 10. 3. 14:22

repo init -u https://android.googlesource.com/platform/manifest -b android-4.1.1_r1

repo sync


'안드로이드 > 포팅' 카테고리의 다른 글

GGLContext 에 대하여  (0) 2013.03.24
pthread_cancel()  (0) 2013.02.04
안드로이드 아이스크림샌드위치 vs 진저브레드  (0) 2012.04.07
Ubuntu 11.04 에서 jdk6 깔기  (0) 2012.04.05
ramdisk.img 디버깅 방법  (0) 2012.03.18
Posted by code cat