Error with repacking boot.img (Android) - android

I have Nexus 5 with AOSP ROM 4.4.4.
I'm trying to "pull" boot.img from the device, unpack it, edit "init.rc", repack it to boot.img and flash it to the device.
I follow many guides but none of them have the same scenario as I have:
(http://droidcore.blogspot.co.il/2012/12/how-to-edit-initrc-in-android.html and http://www.digitalinternals.com/mobile/android-mmc-mmcblk-partition-layout/259/)
The device partition is mmcblck so from ls -l /dev/block/platform/msm_sdcc.1/by-name/ I got that the boot is /dev/block/mmcblk0p19:
lrwxrwxrwx root root 1971-02-28 21:30 boot ->
/dev/block/mmcblk0p19
I created the boot.img with the command: cat /dev/block/mmcblk0p19 > /mnt/sdcard/boot.img and pull this boot.img to my pc. This boot.img is ~23 MB.
I unmkbootimg the boot.img with the tool in http://droidcore.blogspot.co.il/2012/12/how-to-edit-initrc-in-android.html and got 2 files: initramfs.cpio.gz which is ~500 KB and kernel.gz which is ~8.4 MB. The details I got are:
Kernel size 8405280
Kernel address 0x8000
Ramdisk size 498992
Ramdisk address 0x2900000
Secondary size 0
Secondary address 0xf00000
Kernel tags address 0x2700000
Flash page size 2048
Board name is ""
Command line "console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead
user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1"
Extracting kernel.gz
... Extracting initramfs.cpio.gz ...
All done.
To recompile this image, use:
mkbooting --kernel kernel.gz --ramdisk initramfs.cpio.gz --base 0x26fff00 --cmdline 'console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1' -o new_boot.img
I unpack initramfs.cpio.gz with the command: gunzip -c initramfs.cpio.gz | sudo sh -c 'cd ../ && cpio -i' (from http://www.wiki.xilinx.com/Build+and+Modify+a+Rootfs) and got many files, init.rc among them. I edited this file.
I repack initramfs.cpio.gz with the command: sh -c 'cd ../ && sudo find . | sudo cpio -H newc -o' | gzip -9 > new_initramfs.cpio.gz and got this file ~500KB.
Now I mkbootimg those 2 files with the command: ./mkbooting --kernel kernel.gz --ramdisk initramfs.cpio.gz --base 0x26fff00 --cmdline 'console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1' -o new_boot.img and I got boot.img which is ~8.5 MB
Now flash the boot to the device and the device is stuck on the first screen (not boot up)
My questions are:
What's wrong?
Is that normal that my new boot.img is only 8.5 MB instead of 23 MB (the original)?
Thank you guys!
************* I FOUND THE PROBLEM *************
THE SOLUTION IS:
I used unmkbootimg from here: http://whiteboard.ping.se/Android/Unmkbootimg
After I run unmkbootimg I got this comment:
*** WARNING ****
This image is built using NON-standard mkbootimg!
OFF_KERNEL_ADDR is 0xFD908100
OFF_RAMDISK_ADDR is 0x00200100
OFF_SECOND_ADDR is 0xFE800100
Please modify mkbootimg.c using the above values to build your image.
so I follow the instructions here: https://gist.github.com/jberkel/1087757 and now it works!!!

I can't give the answer to the first question, but if I were you I'd skip step 4&5 and verify whether the unmkbootimg/mkbootimg process is correct. Only after it's verified, I till tackle with the cpio process, and finally the init.rc editing.
For the second question, google's official boot.img is 8.64MB, so I guess there is nothing wrong with the size.

Ubuntu's abootimg worked for me. I used the update (-u) option.

Related

mounting a raw disk in a backup

I trying to get all data from my android phone. I got alot of files named: ".backup".
step 1:
cat userdata_20200107_174037.backup userdata_20200107_174037.backup1 userdata_20200107_174037.backup2 userdata_20200107_174037.backup3 userdata_20200107_174037.backup4 userdata_20200107_174037.backup5 userdata_20200107_174037.backup6 userdata_20200107_174037.backup7 userdata_20200107_174037.backup8 userdata_20200107_174037.backup9 userdata_20200107_174037.backup10 userdata_20200107_174037.backup11 userdata_20200107_174037.backup12 userdata_20200107_174037.backup13 > userdata.img
step 2 if this not works goto step3:
dd if=userdata.img bs=512 skip=1 | gunzip -c | tar xv
gzip: stdin: not in gzip format tar: This does not look like a tar
archive tar: Exiting with failure status due to previous errors
step 3:
simg2img userdata.img userdata_raw.img
Invalid sparse file format at header magi Failed to read sparse file
step 4:
sudo mount -t ext4 -o loop,rw userdata.img /media/phone/
mount: wrong fs type, bad option, bad superblock on /dev/loop8,
missing codepage or helper program, or other error In some cases
useful info is found in syslog - try dmesg | tail or so
i Follow the stack overflow here: https://android.stackexchange.com/questions/141805/how-to-extract-backup-files-created-by-android-stock-recovery
Is there a easy way to backup all data in android ? and how can i do it? hole data include system??
Note:
then i run (file userdata.img) it's data file
and not Android sparse image (file)

Script that will transfer photos from phone camera using adb

Story
I take photos and record videos with my phone camera and keep all of them on my internal storage/sdcard. I periodically back them up on my PC, so I keep these camera photos on PC storage in sync with phone storage.
For years, I've been backing up my phone camera photos to my PC in the following way:
Plug in phone into PC and allow access to phone data
Browse phone storage → DCIM → Camera
Wait several minutes for the system to load a list of ALL photos
Copy only several latest photos which haven't been backed up yet
I figured that waiting several minutes for all photos to load is an unnecessary drag so I downloaded adb platform tools. I've added the folder bin to my Path environment variable (i.e. %USERPROFILE%\Tools\adb-platform-tools_r28.0.3) so that I can seamlessly use adb and not write its full path each time.
The script
I wrote the following script for Git Bash for Windows. It is also compatible with Unix if you change the $userprofile variable. Essentially, the script pulls camera photos between two dates from phone storage to PC.
# Attach device and start deamon process
adb devices
# Initialize needed variables
userprofile=$(echo "$USERPROFILE" | tr "\\" "/") # Windows adjustments
srcFolder="//storage/06CB-C9CE/DCIM/Camera" # Remote folder
dstFolder="$userprofile/Desktop/CameraPhotos" # Local folder
lsFile="$dstFolder/camera-ls.txt"
filenameRegex="2019061[5-9]_.*" # Date from 20190615 to 20190619
# Create dst folder if it doesn't exist
mkdir -p "$dstFolder"
# 1. List contents from src folder
# 2. Filter out file names matching regex
# 3. Write these file names line by line into a ls file
adb shell ls "$srcFolder" | grep -E "$filenameRegex" > "$lsFile"
# Pull files listed in ls file from src to dst folder
while read filename; do
if [ -z "$filename" ]; then continue; fi
adb pull "$srcFolder/$filename" "$dstFolder" # adb: error: ...
done < "$lsFile"
# Clean up
rm "$lsFile"
# Inform the user
echo "Done pulling files to $dstFolder"
The problem
When I run the script (bash adb-pull-camera-photos.sh), everything runs smoothly except for the adb pull command in the while-loop. It gives the following error:
': No such file or directoryemote object '//storage/06CB-C9CE/DCIM/Camera/20190618_124656.jpg
': No such file or directoryemote object '//storage/06CB-C9CE/DCIM/Camera/20190618_204522.jpg
': No such file or directoryemote object '//storage/06CB-C9CE/DCIM/Camera/20190619_225739.jpg
I am not sure why the output is broken. Sometimes when I resize the Git Bash window some of the text goes haywire. This is the actual error text:
adb: error: failed to stat remote object '//storage/06CB-C9CE/DCIM/Camera/20190618_124656.jpg': No such file or directory
adb: error: failed to stat remote object '//storage/06CB-C9CE/DCIM/Camera/20190618_204522.jpg': No such file or directory
adb: error: failed to stat remote object '//storage/06CB-C9CE/DCIM/Camera/20190619_225739.jpg': No such file or directory
I am sure that these files exist in the specified directory on the phone. When I manually execute the failing command in bash, it succeeds with the following output:
$ adb pull "//storage/06CB-C9CE/DCIM/Camera/20190618_124656.jpg" "C:/Users/User/Desktop/CameraPhotos/"
//storage/06CB-C9CE/DCIM/Camera/20190618_124656.jpg: 1 file pulled. 15.4 MB/s (1854453 bytes in 0.115s)
The question
I can't figure out what's wrong with the script. I thought the Windows system might be causing a commotion, because I don't see the reason why the same code works when entered manually, but doesn't work when run in a script. How do I fix this error?
Additional info
Note that I had to use // in the beginning of an absolute path on Windows because Git Bash would interpret / as its own root directory (C:\Program Files\Git).
I've echoed all variables inside the script and got all the correct paths that otherwise work via manual method.
camera-ls.txt file contents
20190618_124656.jpg
20190618_204522.jpg
20190619_225739.jpg
Additional questions
Is it possible to navigate to external sdcard without using its name? I had to use /storage/06CB-C9CE/ because /sdcard/ navigates to internal storage.
Why does tr "\\" "/" give me this error: tr: warning: an unescaped backslash at end of string is not portable?
Windows batch script
Here's a .bat script that can be run by Windows Command Prompt or Windows PowerShell. No Git Bash required.
:: Start deamon of the device attached
adb devices
:: Pull camera files starting from date
set srcFolder=/storage/06CB-C9CE/DCIM/Camera
set dstFolder=%USERPROFILE%\Desktop\CameraPhotos
set lsFile=%USERPROFILE%\Desktop\CameraPhotos\camera-ls.txt
set dateRegex=2019061[5-9]_.*
mkdir %dstFolder%
adb shell ls %srcFolder% | adb shell grep %dateRegex% > %lsFile%
for /F "tokens=*" %%A in (%lsFile%) do adb pull %srcFolder%/%%A %dstFolder%
del %lsFile%
echo Done pulling files to %dstFolder%
Just edit the srcFolder to point to your phone camera folder,
plug a pattern into the dateRegex for matching the date interval and
save it as a file with .bat extension, i.e: adb-pull-camera-photos.bat.
Double-click the file and it will pull filtered photos into CameraPhotos folder on Desktop.
Keep in mind that you still need have adb for Windows on your PC.
The problem was with Windows line delimiters.
Easy fix
Just add the IFS=$'\r\n' above the loop so that the read command knows the actual line delimiter.
IFS=$'\r\n'
while read filename; do
if [ -z "$filename" ]; then continue; fi
adb pull "$srcFolder/$filename" "$dstFolder"
done < "$lsFile"
Explanation
I tried plugging the whole while-loop into the console and it failed with the same error:
$ bash adb-pull-camera-photos.sh
List of devices attached
9889db343047534336 device
tr: warning: an unescaped backslash at end of string is not portable
': No such file or directoryemote object '//storage/06CB-C9CE/DCIM/Camera/20190618_124656.jpg
': No such file or directoryemote object '//storage/06CB-C9CE/DCIM/Camera/20190618_204522.jpg
': No such file or directoryemote object '//storage/06CB-C9CE/DCIM/Camera/20190619_225739.jpg
Done pulling files to C:/Users/User/Desktop/CameraPhotos
This time I started investigating why the output was broken. I remembered that windows uses \r\n as newline, which means Carriage Return + Line Feed, (CR+LF), so some text must have been overwritten.
It was because of broken values stored inside the $filename variable.
This is the loop from the script:
while read filename; do
if [ -z "$filename" ]; then continue; fi
adb pull "$srcFolder/$filename" "$dstFolder"
done < "$lsFile"
Since each iteration of the while-loop reads a line from $lsFile in the following form:
exampleFilename.jpg\r\n
It misinterprets the newline symbols as part of the file name, so adb pull tries to read files with these whitespaces in their names, but fails and it additionally writes a broken output.
Adb Photo Sync
This might not be the answer but might be useful for others looking for android photo/files backup solution.
I use this script on my Windows with git bash. This can be easily used for Linux. A common issue with a long backup process is that it might get interrupted and you might have to restart the entire copy process from start.
This script saves you from this trouble. You can restart the script or interrupt in between but it will resume copy operation from the point it left.
Just change the rfolder => android folder, lfolder => local folder
#!/bin/sh
rfolder=sdcard/DCIM/Camera
lfolder=/f/mylocal/s8-backup/Camera
adb shell ls "$rfolder" > android.files
ls -1 "$lfolder" > local.files
rm -f update.files
touch update.files
while IFS= read -r q; do
# Remove non-printable characters (are not visible on console)
l=$(echo ${q} | sed 's/[^[:print:]]//')
# Populate files to update
if ! grep -q "$l" local.files; then
echo "$l" >> update.files
fi
done < android.files
script_dir=$(pwd)
cd $lfolder
while IFS= read -r q; do
# Remove non-printable characters (are not visible on console)
l=$(echo ${q} | sed 's/[^[:print:]]//')
echo "Get file: $l"
adb pull "$rfolder/$l"
done < "${script_dir}"/update.files

Mount qcow2 image created by Android emulator

I'm trying to mount the userdata-qemu.img.qcow2 file created by the Android emulator. The following procedure does not work:
sudo qemu-nbd -c /dev/nbd0 ~/.android/avd/Pixel_C_API_27.avd/userdata-qemu.img.qcow2
First command runs well, but running
sudo qemu-nbd -c /dev/nbd0 ~/.android/avd/Pixel_C_API_27.avd/userdata-qemu.img.qcow2
results in this output:
Fehler: /dev/nbd0: unbekannte Partitionstabelle
Modell: Unbekannt (unknown)
Festplatte /dev/nbd0: 3146MB
Sektorgröße (logisch/physisch): 512B/512B
Partitionstabelle: unknown
Disk-Flags:
Basically it cannot recognize a partition table in the image file. You may wonder what's the output of
fdisk /dev/nbd0 -l
so here it is:
Medium /dev/nbd0: 3 GiB, 3145728000 Bytes, 6144000 Sektoren
Einheiten: sectors von 1 * 512 = 512 Bytes
Sektorengröße (logisch/physisch): 512 Bytes / 512 Bytes
I/O Größe (minimal/optimal): 512 Bytes / 512 Bytes
As you could expect already, mounting fails of course, since no partitions can be recognized if the partition table itself cannot be recognized either. Thanks for any help!
Edit: I've just found out that the problem must have to do with Android's userdata encryption. As I've never changed any password the encryption password of the emulator's userdata partition would have to be the default one "default_password". How can I decrypt the image to be able to mount it?
You can mount userdata-qemu.img.qcow2 using the following procedure
convert the image to a raw image
qemu-img convert -O raw userdata-qemu.img.qcow2 udata-raw.img
use losetup to setup a loopback device for mounting
sudo losetup -f -P userdata.img
use losetup -l to see what device was setup
losetup -l
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO
/dev/loop0 0 0 0 0 /path/to/userdata.img 0
mount the drive
mkdir /tmp/mnt
sudo mount /dev/loop0 /tmp/mnt
Then ls /tmp/mnt/ gives
app benchmarktest benchmarktest64 lost+found misc nativetest nativetest64

on boot my android phone init .sh script run but not fully

Stack!
This my first question on this, so don't be too hard with me.
I want to run my own .sh script file on boot my android. To get this I rebuild kernel image and before that I add to init.rc file my own service which start after boot complete trigger:
on property:dev.bootcomplete=1
start fota-snoop
start fota-trigger
start startup-prober
start fairnet
the service itself:
service fairnet /system/bin/sh /system/etc/init.fairnet.sh
user root
group root
disabled
oneshot
permissions of /system/etc/init.fairnet.sh is set 644 like others init .sh scripts, and owner is root:root :
-rw-r--r-- root root 280 2018-01-09 01:03 init.fairnet.sh
init.fairnet.sh:
#!/system/bin/sh
insmod /system/lib/modules/xt_HL.ko
lsmod > /system/etc/curlsmod
/system/bin/iptables -t mangle -L > /system/etc/preiptables
/system/bin/iptables -t mangle -A POSTROUTING -o rmnet+ -j TTL --ttl-set 64
/system/bin/iptables -t mangle -L > /system/etc/postiptables
the most funny thing is command of load kernel module works fine, on boot too, but the other strings don't works: output files didn't exist, rule for iptables didn't add. I can't understand why insmod works and other commands don't.
Thanks for reading and sorry for my terrible English.
Problem solved!
SELinux blocked iptables in boot.
dmesg | grep iptables
gives me
<36>[ 39.819005] type=1400 audit(1516096993.541:9): avc: denied { create } for pid=2652 comm="iptables" lport=255 scontext=u:r:init_shell:s0 tcontext=u:r:init_shell:s0 tclass=rawip_socket op_res=-13 ppid=2640 pcomm="sh" tgid=2640 tgcomm="sh"
that means in current /sepolicy don't have rule i need.
For adding that rule i use sepolicy-inject, for build it need /usr/lib/libsepol.a, libsepol1-dev contains it. Also may use builded binaries for all archs (don't work for me, I build my own).
./sepolicy-inject -s init_shell -t init_shell -c rawip_socket -p getopt,create,setopt -P sepolicy -o sepolicy_new
add needed rule and make new sepolicy_new from old sepolicy from device.
Flash device with new sepolicy with new boot.img, I use AIK for Win.
Done! Now after boot my .sh script automatically runs and fully.
Thanks for reading and again sorry for my terrible English.
P.S. My own service I replaced from init.sony.rc to init.qcom.rc, also removed group root and disabled, but I done it only for ideological reasons and that not solve problem.
P.P.S. Change mode from Enforced to Permissive may do the thing, but I don't want to lost SELinux.

How do you create a loadable kernel module for Android?

I know there a number of walkthroughs and tutorials floating around out there which describe this activity, but after having read many of them I still can't get this working. If anyone has the patience to wade through the steps I've taken (posted below) and suggest where I may have gone off track I'd be very appreciative. I've spent about a day and a half staring at make files and reading walkthroughs so literally any suggestions would be helpful.
Environment:
I'm using an Ubuntu 10.04 32 bit vm.
I'm hosting from a 64 bit windows 7
My Core 2 Duo does not have the hardware support for 64 bit VMs so i'm trying to compile against Android 2.1 kernel
I have installed Java 1.5 from the Dapper repo and removed my 1.6 installation
The rest of the tooling has been acquired according the Android dev documentation...
As per Initializing a Build Environment:
Java:
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk
Other required:
$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline5-dev libz-dev libgl1-mesa-dev
$ sudo apt-get install gcc-multilib g++-multilib libc6-i386 libc6-dev-i386
Then from Downloading the Source Tree:
Repo:
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
$ repo init -u https://android.googlesource.com/platform/manifest -b eclair
$ repo sync
$ gpg --import (imported the huge key)
And from Building the System:
Initialize:
$ source build/envsetup.sh
Choose a Target:
$ lunch generic-user
Build the Code:
$ make -j4
Added!
Output of make -j4:
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.1-update1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ECLAIR
============================================
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
Install: out/host/linux-x86/bin/acp
target Generated: libclearsilver-jni <= out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
target Generated: libclearsilver-jni <= out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
host SharedLib: libneo_cs (out/host/linux-x86/obj/lib/libneo_cs.so)
host C++: aapt <= frameworks/base/tools/aapt/AaptAssets.cpp
host C++: aapt <= frameworks/base/tools/aapt/Command.cpp
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; error in opening zip file
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; error in opening zip file
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; cannot read zip file
error: cannot access org.clearsilver.HDF
class file for org.clearsilver.HDF not found
javadoc: error - Class org.clearsilver.HDF not found.
Error: No classes were specified on the command line. Try -help.
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_HDF.h] Error 15
make: *** Waiting for unfinished jobs....
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; cannot read zip file
error: cannot access org.clearsilver.CS
class file for org.clearsilver.CS not found
In file included from frameworks/base/tools/aapt/AaptAssets.h:18,
from frameworks/base/tools/aapt/AaptAssets.cpp:5:
frameworks/base/tools/aapt/ZipFile.h:65: warning: ‘typedef’ was ignored in this declaration
javadoc: error - Class org.clearsilver.CS not found.
Error: No classes were specified on the command line. Try -help.
In file included from frameworks/base/tools/aapt/AaptAssets.h:18,
from frameworks/base/tools/aapt/Main.h:14,
from frameworks/base/tools/aapt/Command.cpp:6:
frameworks/base/tools/aapt/ZipFile.h:65: warning: ‘typedef’ was ignored in this declaration
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_CS.h] Error 15
Added!
So it turns out i've got some problems here. I assume that once i've overcome these issues, i'll have an environment capable of compiling kernel modules. Please do correct me if I'm wrong.
Next I head into my directory containing my module.c file and it's makefile. Contents of makefile below:
obj-m += mymodule.o
CROSS_COMPILE=~/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
KERNEL_DIR ?= /home/<myuser>/WORKING_DIRECTORY
VERSION = v1.1
all:
make -C $(KERNEL_DIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
rm -rf *.c~
rm -rf *.mod*
rm -rf *.o
clean:
make -C $(KERNEL_DIR) M=$(PWD) clean
I have very little experience with make and makefiles, but this looked reasonable to me. My main concern with this file is the KERNEL-DIR variable. I tried a few different values for that variable, but got all sorts of errors where I do not with it's current value. Of course, it could still be wrong, so any comments here are welcome.
So, as far as I know, I should be able to execute make with no args or anything and will figure out what it needs to do. I have tried make, make -f both with and without sudo. All four permutations yield the same results:
make -C /home/<myuser>/WORKING_DIRECTORY M=/home/<myuser>/Desktop/<MyModuleDir> ARCH=arm CROSS_COMPILE=~/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- modules
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.1-update1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ECLAIR
============================================
make[1]: Entering directory `/home/<myuser>/WORKING_DIRECTORY'
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
Available sub-modules:
01-test dumpsys libminui LotsOfApps
20-dns.conf dvz libminzip lowstoragetest
95-configured dx libmp4recognizer_utility lsd
aapt dx-tests libmtdutils LunarLander
acc edify libnativehelper LunarLanderTests
AccountAndSyncSettings Email libneo_cgi MagicSmokeWallpapers
accRuntimeTest EmailTests libneo_cs make_cfst
acp emma libneo_util makedict
adb emmalib libnetutils make_g2g
adbd emulator libocr makekeycodes
add-property-tag emulator-arm libomx_aac_component_lib make_ve_grammar
afar emulator-hw libomx_aacdec_sharedlibrary mediaframeworktest
aidl emulator-tcg libomx_amr_component_lib MediaProvider
AlarmClock EnabledTestApp libomx_amrdec_sharedlibrary mediaserver
AliasActivity etc1tool libomx_amrenc_component_lib memtest
am eventanalyzer libomx_amrenc_sharedlibrary minigzip
android event-log-tags libomx_avc_component_lib mkbootfs
android.core.tests.annotation exc_dump libomx_avcdec_sharedlibrary mkbootimg
android.core.tests.archive ext libomx_baseclass_lib mksdcard
android.core.tests.concurrent Fallback libomx_common_lib mkstubs
android.core.tests.crypto fastboot libomx_m4v_component_lib mkyaffs2image
android.core.tests.dom FixedGridLayout libomx_m4vdec_sharedlibrary Mms
android.core.tests.logging flash_image libomx_mastercore_lib MmsTests
android.core.tests.luni.io FontLab libomx_mp3_component_lib monkey
android.core.tests.luni.lang framework libomx_mp3dec_sharedlibrary monkeyrunner
android.core.tests.luni.net FrameworkPermissionTests libomx_queue_lib mtpd
android.core.tests.luni.util framework-res libomx_sharedlibrary MultiResolution
android.core.tests.math FrameworkTest libop Music
android.core.tests.nio framework-tests libopencore_author MusicTests
android.core.tests.nio_char FrameworkTestTests libopencore_common nc
android.core.tests.prefs fsck_msdos libopencore_download netcfg
android.core.tests.regex fs_config libopencore_downloadreg netperf
android.core.tests.runner fs_get_stats libopencore_mp4local netserver
android.core.tests.security Gallery libopencore_mp4localreg ninepatch
android.core.tests.sql Gallery3D libopencore_net_support NinePatchLab
android.core.tests.text GalleryTests libopencore_player NoShareUidApp
android.core.tests.xml gdbserver libopencore_rtsp NotePad
android.core.tests.xnet genext2fs libopencore_rtspreg NotePadTests
android.cts.dpi GestureBuilder libosclbase opcontrol
android.cts.refapp GL2JNI libosclerror openssl
android.policy GLJNI libosclio OpenWnn
android.policy_mid GlobalSearch liboscllib oprofiled
android.policy_phone GlobalSearchBenchmarks libosclmemory org.eclipse.core.commands_3.4.0.I20080509-2000
androidprefs GlobalSearchPermissionTests libosclproc org.eclipse.equinox.common_3.4.0.v20080421-2006
android.test.runner GlobalSearchTests libosclregcli org.eclipse.jface_3.4.2.M20090107-0800
AndroidTests GlobalTime libosclregserv org-netbeans-api-visual
angeles GoogleContactsProvider libosclutil org-openide-util
ant GoogleContactsProviderTests libpagemap osgi
antlr-2.7.7 google-framework libpassthru_oma1 PackageInstaller
anttasks googlelogin-client libpcap parseStringTest
apicheck GoogleSearch libpixelflinger perm_checker
ApiDemos gpustate libpixelflinger_armv6 perm_checker.conf
ApiDemosReferenceTest gralloc.default libpixelflinger_static Phone
ApiDemosTests groovy-all-1.6.5 libplatform_library_jni PicoTts
apkbuilder grxmlcompile libpng ping
ApplicationsProvider gtest-filepath_test libpopt PinyinIME
applypatch gtest-linked_ptr_test libprotocolenginenode_base PlatformLibraryClient
applypatch_static gtest-message_test libprotocolenginenode_common platform.xml
app_process gtest-options_test libprotocolenginenode_download_common pm
AppWidgetHostTest gtest-port_test libprotocolenginenode_pdl post_trace
AppWidgetProvider gtest_pred_impl_unittest libprotocolenginenode_ps pppd
apriori gtest_prod_test libpv_aac_dec preload
archquery gtest-test-part_test libpvaacffparsernode ProcessTests
asm-3.1 gtest-typed-test2_test libpvaacffrecognizer procmem
atree gtest-typed-test_test libpvaacparser procrank
AudioHardwareRecord gtest_unittest libpvamrffparsernode profile_pid
AudioHardwareRecordLoop gzip libpvamrffrecognizer profile_trace
AudioInRecord HelloActivity libpv_amr_nb_common_lib Provision
backup_helper_test HelloActivityTests libpvamrwbdecoder pvplayer
BackupTest hierarchyviewer libpvauthorengine q2dm
BatteryWaster hist_trace libpv_avc_common_lib q2g
bb2sym Home libpvavcdecoder qemud
bb_dump hosttestlib libpvavifileparser qemu-props
bbprof hprof-conv libpv_config_parser qwerty2.kcm
bison HTMLViewer libpvdecoder_gsmamr qwerty.kcm
Bluetooth icache libpvdownloadinterface racoon
BluetoothChat icudata libpvdownloadmanagernode radiooptions
BluetoothDebug idegen libpvdownloadreginterface read_addr
bmgr ime libpvencoder_gsmamr read_method
bookmarks.xml ImfTest libpvfileoutputnode read_pid
bootanimation ImfTestTests libpvfileparserutils read_trace
Browser imgdiff libpvframemetadatautility recovery
BrowserPowerTests init libpvgendatastruct required_hardware.xml
BrowserTestPlugin input libpvgsmamrparser rgb2565
BrowserTests installd libpv_http_parcom rild
bsdiff invoke_mock_media_player libpvid3parcom rsg-generator
bspatch iptables libpvjitterbuffer RSSReader
btool ip-up-vpn libpvjitterbuffernode run-core-tests
bugreport iself libpvjitterbufferrtp run-core-tests-on-ri
BusinessCard isprelinked libpvlatmpayloadparser safe_iop_test
Calculator jarjar libpvmediadatastruct SampleBrowserPlugin
CalculatorTests jarutils libpvmediainputnode schedtest
Calendar jasmin libpvmedialayernode scp
CalendarProvider jasmin.jar libpvmediaoutputnode screenshot2
CalendarProviderTests javax.obex libpvmf sdklib
CalendarTests jcommon-1.0.12 libpvmfrecognizer sdkmanager
Camera jdiff libpvmimeutils SdkSetup
CameraTests jdwpspy libpvmioaviwavfileinput sdkstats
CertInstaller JETBoy libpvmiofileinput sdkuilib
cfassembler jfreechart-1.0.9 libpvmiofileoutput sdutil
check-lost+found jfreechart-1.0.9-swt libpvmp3 SearchableDictionary
check_prereq junit libpvmp3ff sensors.goldfish
check_stack jython libpvmp3ffparsernode service
check_trace kcm libpvmp3ffrecognizer servicemanager
clearsilver keystore libpvmp4decoder services
cmu2nuance keystore_cli libpvmp4ff Settings
com.android.inputmethod.pinyin.lib KeyStoreTests libpvmp4ffcomposer SettingsProvider
com.example.android.platform_library kxml2-2.3.0 libpvmp4ffcomposernode SettingsTests
commons-compress-1.0 latencytop libpvmp4ffparsernode sh
Compass LatinIME libpvmp4ffrecognizer ShareUidApp
ContactManager Launcher libpvmp4interface showlease
Contacts Launcher2 libpvmp4reginterface showmap
ContactsProvider launchperf libpvomxaudiodecnode showslab
ContactsProviderTests layoutlib libpvomxbasedecnode sig
ContactsTests layoutlib_api libpvomxencnode sig-check
core layoutlib_create libpv_omx_interface sig-create
core-tests layoutlib_utils libpvomx_proxy_lib signapk
CoreTests layoutopt libpvomxvideodecnode SignatureTest
coverage libabi libpvplayer_engine SignatureTestTests
cpueater libacc libpvpvxparser signature-tools
cpufeatures libaes libpvrtsp_cli_eng_node SimpleJNI
crasher libandroidpv libpvrtspinterface SkeletonApp
create_test_dmtrace libandroidpvauthor libpv_rtsp_parcom SkeletonAppTests
cts libandroid_runtime libpvrtspreginterface skia_bench
CtsAccessibilityServiceTestCases libandroid_servers libpvsdpparser skia_gm
CtsAccountManagerTestCases libapplypatch libpvsocketnode SlowSuggestions
CtsAppAccessData libarity libpvstreamingmanagernode SmokeTest
CtsAppSecurityTests libastl libpvthreadmessaging SmokeTestApp
CtsAppTestCases libaudioflinger libpvwav Snake
CtsAppWithData libaudiointerface libpvwavffparsernode SnakeTests
CtsBluetoothTestCases libaudiopolicygeneric libpvwavffrecognizer SoftKeyboard
CtsContentTestCases libbinder librank soslim
cts-dalvik-buildutil libbz libreference-cdma-sms sound
CtsDatabaseTestCases libc libreference-ril SoundRecorder
CtsDelegatingAccessibilityService libcameraservice libril SpammySuggestions
CtsDpiTestCases libcamerastub libRS SpareParts
CtsDpiTestCases2 libc_common librs_jni spec-progress
CtsExampleTestCases libc_debug librtppayloadparser sqlite3
CtsGestureTestCases libclearsilver-jni librtprtcp SRecTest
CtsGraphicsTestCases libc_nomalloc libsafe_iop SRecTestAudio
CtsHardwareTestCases libcolorconvert libsampleplugin ssh
CtsInstrumentationAppDiffCert libcpm libSDL SslLoad
CtsJniTestCases libcrypto libSDLmain stack_dump
CtsLocationTestCases libctest libsimplejni StatusBarTest
CtsMediaTestCases libcts_jni libskia Stk
CtsNetTestCases libctspermission_jni libskiagl strace
CtsOsTestCases libcutils libsonivox stringtemplate
CtsPerformance2TestCases libdb libsoundpool su
CtsPerformance3TestCases libdbus libspeex surfaceflinger
CtsPerformance4TestCases libdbus-tools-common libsqlite svc
CtsPerformance5TestCases libdex libsqlite3_android swing-worker-1.1
CtsPerformanceTestCases libdl libsqlite3_phone_number_utils_test swt
CtsPermission2TestCases libdrm1 libsqlite3_phonetic_string_utils_test system_server
CtsPermissionDeclareApp libdrm1_jni libSR_AcousticModels tcpdump
CtsPermissionTestCases libdrm2 libSR_AcousticState TelephonyProvider
CtsProviderTestCases libdvm libSR_AudioIn telephonytest
CtsSharedUidInstall libebl libSR_Core temp_layoutlib
CtsSharedUidInstallDiffCert libebl_arm libsrec_jni Term
CtsSimpleAppInstall libedify libSR_EventLog test_defs.xml
CtsSimpleAppInstallDiffCert libEGL libSR_G2P TestDeviceSetup
CtsSpeechTestCases libelf libSR_Grammar test-fb-refresh
CtsTargetInstrumentationApp libelfcopy libSR_Nametag test-fb-simple
CtsTelephonyTestCases libembunit libSR_Recognizer test_g2g
CtsTestStubs libemoji libSR_Semproc test-mdp
CtsTextTestCases libESR_Portable libSR_Session test-opengl-codegen
CtsUsePermissionDiffCert libESR_Shared libSR_Vocabulary test-opengl-fillrate
CtsUtilTestCases libETC1 libssl test-opengl-filter
CtsViewTestCases libexif libstagefright test-opengl-finish
CtsWebkitTestCases libexpat libstagefright_omx test-opengl-gl2_basic
CtsWidgetTestCases libext libstdc++ test-opengl-gl_basic
CubeLiveWallpapers libfdlibm libsurfaceflinger test-opengl-gralloc
CustomLocale libFFTEm libsvoxpico test-opengl-linetex
daemonize libfst libsystem_server test-opengl-swapinterval
dalvikvm libft2 libsysutils test-opengl-textures
dasm libgetactualaacconfig libterm test-opengl-tritex
dbus-daemon libgif libtestplugin test-progress
dbus-monitor libgl2jni libthread_db test-progress-new
dbus-send libGLES_android libthreadsafe_callback_ao test_swiarb
ddmlib libGLESv1_CM libtinyxml test_zipfile
ddms libGLESv2 libtomcrypt timeinfo
ddmuilib libgljni libtommath timetest
debuggerd libgoogleclient libttspico toolbox
DensityTest libgtest libttssynthproxy traceview
descGen libgtest_main libui TransformTest
DeskClock libhardware libunz TtsService
Development libhardware_legacy libutil tuttle2.kcm
dexdeps libhost libutils uix
dexdump libicudata-default libvorbisidec updater
dexlist libicudata-eu libwbxml UpgradeExample
dexopt libicudata-jp libwbxml_jni usbtest
dexopt-wrapper libicudata-large libwebcore UserDictionaryProvider
dexpreopt libicudata-us libwnndict VisualizationWallpapers
dex-tools libicui18n libWnnEngDic vm-tests
dhcpcd libicuuc libWnnJpnDic VoiceDialer
dhcpcd-run-hooks libiptc libwpa_client Voiper
dictTest libjavacore libxml2 vold
DisabledTestApp libjni_latinime libxml2wbxml VpnServices
dmtracedump libjni_pinyinime libz wbxmltest
DownloadProvider libjnitest libzipfile wdsclient
draw9patch libjpeg LightingTest webkitmerge
DrmProvider liblog line_endings Wiktionary
droiddoc libm linker WiktionarySimple
dumpeventlog libm4v_config LiveWallpapers xmlwriter
dumpkey libmedia LiveWallpapersPicker yuv420sp2rgb
dump_regions libmedia_jni localize zipalign
DumpRenderTree libmediaplayerservice logcat
dumpstate libmincrypt logwrapper
make[1]: Leaving directory `/home/<myuser>/WORKING_DIRECTORY'
rm -rf *.c~
rm -rf *.mod*
rm -rf *.o
You'll notice a few screwy warnings, but as best as I can tell, they are not real problems. If anyone feels differently about these, please say so.
make[1]: Entering directory `/home/<myuser>/WORKING_DIRECTORY'
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
I guess that last line sounds pretty suspicious but I have no idea what to do about it. Apart from the few strange things i've mentioned, it would appear that this all went smoothly. However, after the whole thing completes, I can't find the *.ko file anywere. I did a ls -alRg | grep *.ko on my home directory and it turns up nothing. I'm stumped. If I can provide any more information or run any tests or try anything differently i'll be checking in frequently.
Sorry for being late, but hope it helps:
http://tthtlc.wordpress.com/2011/12/29/how-to-write-a-kernel-module-on-android-sony-ericsson-xperia-arc-s/
I wrote and tested the code on my Sony Ericsson Xperia Arc S and it works (in general in should work for any Android phone).
Connecting via adb and USB, and “su” to root, the “lsmod” listed all the kernel module (in general, the article at
http://web.archive.org/web/20121106004141/http://developer.sonymobile.com/2011/05/06/how-to-build-a-linux-kernel gave a very good coverage of what to do in Linux kernel compilation for SonyEricsson phone):
lsmod
android_module 654 0 - Live 0x7f007000 (P)
sdio 16532 0 - Live 0x7f000000
“android_module” was the one I had inserted via insmod android_module.ko.
Here’s how to do it:
First the original program was copied from:
http://rechtzeit.wordpress.com/2011/03/21/77/
Or reproduced as follows:
android_module.c:
#include"linux/module.h"
#include"linux/kernel.h"
//replace the "" with angular brackets
int init_module(void)
{
printk(KERN_INFO "Hello android kernel...\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye android kernel...\n");
}
Makefile:
obj-m += android_module.o
all:
make -C /home/tteikhua/android/sony_ericsson_src/58/kernel/ M=$(PWD) modules
clean:
make -C /home/tteikhua/android/sony_ericsson_src/58/kernel/ M=$(PWD) clean
The directory where the kernel is located (“-C” above) is where kernel is located.
And the following command will use the Makefile from above:
ARCH=arm CROSS_COMPILE=/opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi- make
As shown above, the cross compiler I had used is from CodeSourcery.
And after insmod android_module.ko you can see the debugging message in dmesg output:
<6>[11184.063507] Hello android kernel...
<7>[11619.209655] msmrtc_timeremote_set_time: 11/29/2011 10:09:36 (04)
<6>[11619.210418] RPC CALL -- TOD TIME UPDATE: ttick = 404244221
<6>[11619.210418] stamp=52910543933046785, freq = 0
<7>[11619.211578] msmrtc_tod_proc_result: 12/29/2011 10:09:36 (03)
<6>[11619.211578] rs30000048 rs30000048.262144: setting system clock to 2011-12-29 10:09:36 UTC (1325153376)
<6>[11662.112365] device rmnet0 left promiscuous mode
<6>[11662.112579] device rmnet0 entered promiscuous mode
<6>[11669.958221] device rmnet0 left promiscuous mode
<6>[11669.958435] device rmnet0 entered promiscuous mode
<7>[11698.181060] msmrtc_timeremote_set_time: 11/29/2011 10:10:55 (04)
<6>[11698.187622] RPC CALL -- TOD TIME UPDATE: ttick = 406832008
<6>[11698.187652] stamp=52910548228014081, freq = 0
<7>[11698.193939] msmrtc_tod_proc_result: 12/29/2011 10:10:55 (03)
<6>[11698.194030] rs30000048 rs30000048.262144: setting system clock to 2011-12-29 10:10:55 UTC (1325153455)
<6>[11814.442901] bq27520 0-0055: bq27520_handle_soc_worker() capacity=97 (100) flags=0x229 ctrl_status=0x28b soh_state=0x3, valid=1
<6>[11984.057373] Goodbye android kernel...
And the “Goodbye” is when rmmod android_module is executed. In between are debugging message from other components in the kernel.
Final words:
The above are written in 2011, for more modern resources, please refe to the following to get started:
https://source.android.com/docs/core/architecture/kernel/modular-kernels
https://source.android.com/docs/core/architecture/kernel
https://source.android.com/docs/setup/build/building-kernels
https://source.android.com/docs/core/architecture/kernel/loadable-kernel-modules
I think I've red that emulator kernel does not support module, so you must compile also the kernel with modules support.
I hope that this link will help you
There are two things you'll need to do. Firstly, create an emulator kernel that supports loadable kernel modules.
There's a comprehensive post here covering the process of setting up the emulator kernel.
There are 2 parts of the instructions to alter:
I find it easiest to keep the kernel within the repo area (in this case, ~/WORKING_DIRECTORY), like so:
cd ~/WORKING_DIRECTORY
mkdir kernel
cd kernel
git clone git://android.git.kernel.org/kernel/common.git
The branch information is no longer correct, however, so where it says:
git checkout -t origin/android-goldfish-2.6.29 -b goldfish
use this instead:
git checkout -t archive/android-gldfish-2.6.29 -b goldfish
As you've found out, the kernel by default is not configured with loadable module support. Enable before compiling. After, this step:
make ARCH=arm goldfish_defconfig
do this:
make ARCH=arm menuconfig
A text-based menu will show up. Use the Up/Down arrow keys to navigate, Space to select an option, Enter to expand a menu (menus have --->) at the end of the line, and Esc-Esc to go back a menu.
Select "Enable loadable module support" by scrolling down and hitting Space
Hit Esc-Esc to exit, and hit Enter to save the new configuration
Now build. Using your setup, it would be:
make ARCH=arm CROSS_COMPILE=/home/<myuser>/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
Now that that's done you can do the second part, which is making a loadable kernel module. You were almost there, but because you didn't have the kernel source for the emulator, it didn't work. Just take the makefile you have and change KERNEL_DIR to:
KERNEL_DIR ?= /home/<myuser>/WORKING_DIRECTORY/kernel/common

Categories

Resources