External Linux kernel module compilation for Android - Android Q&A, Help & Troubleshooting

Hi All,
I am trying to compile a driver as a loadable module but whenever I adb shell into my phone and do an insmod test.ko I get the error message insmod: failed to load /data/local/tmp/test.ko: Exec format error. Grep'ing dmesg I find the following log: test: no symbol version for module_layout`.
I've done quite a bit of googling and reading the linux kbuild documentation txt files to no avail, so if someone knows the answer it'd be fab
What I've done so far is this:
I have an Qualcomm Aurora checkout and in the kernel directory I type the following
Code:
cp arch/arm64/configs/gemini_user_defconfig .config [B]# Has CONFIG_MODVERSIONS enabled[/B]
yes "" | make oldconfig ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make prepare ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make scripts ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make modules ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
I have my PATH set to point to /MyAOSBDir/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin so I pick up the correct toolchain.
At this point appears to be well. In my kernel directory I have Module.symvers, so I appear to be set.
Now to the directory I have set up outside of this build tree with a dummy test... The Makefile looks like this:
Code:
KERNEL_DIR:=/solomon-build/MiNote2AOSB/kernel/
obj-m += test.o
PWD := $(shell pwd)
.PHONY: all
all:
$(MAKE) M=$(PWD) ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -C $(KERNEL_DIR) modules V=1
clean:
$(MAKE) M=$(PWD) -C $(KERNEL_DIR) clean
The driver is just a dummy:
Code:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye world\n");
}
module_init(hello_start);
module_exit(hello_end);
I do make "make all" at the comment line and get this output:
Code:
make M=/solomon-build/build_mxt_kmod ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -C /solomon-build/MiNote2AOSB/kernel/ modules V=1
make[1]: Entering directory `/solomon-build/MiNote2AOSB/kernel'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \
echo >&2; \
echo >&2 " ERROR: Kernel configuration is invalid."; \
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
mkdir -p /solomon-build/build_mxt_kmod/.tmp_versions ; rm -f /solomon-build/build_mxt_kmod/.tmp_versions/*
make -f ./scripts/Makefile.build obj=/solomon-build/build_mxt_kmod
./scripts/gcc-wrapper.py aarch64-linux-android-gcc -Wp,-MD,/solomon-build/build_mxt_kmod/.test.o.d -nostdinc -isystem /solomon-build/MiNote2AOSB/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x-google/include -I./arch/arm64/include -Iarch/arm64/include/generated -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mgeneral-regs-only -fno-pic -fno-delete-null-pointer-checks -Os -Wno-maybe-uninitialized --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(test)" -D"KBUILD_MODNAME=KBUILD_STR(test)" -c -o /solomon-build/build_mxt_kmod/.tmp_test.o /solomon-build/build_mxt_kmod/test.c
(cat /dev/null; echo kernel//solomon-build/build_mxt_kmod/test.ko;) > /solomon-build/build_mxt_kmod/modules.order
make -f ./scripts/Makefile.modpost
find /solomon-build/build_mxt_kmod/.tmp_versions -name '*.mod' | xargs -r grep -h '\.ko$' | sort -u | sed 's/\.ko$/.o/' | scripts/mod/modpost -m -i ./Module.symvers -I /solomon-build/build_mxt_kmod/Module.symvers -o /solomon-build/build_mxt_kmod/Module.symvers -S -E -w -s -T -
./scripts/gcc-wrapper.py aarch64-linux-android-gcc -Wp,-MD,/solomon-build/build_mxt_kmod/.test.mod.o.d -nostdinc -isystem /solomon-build/MiNote2AOSB/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x-google/include -I./arch/arm64/include -Iarch/arm64/include/generated -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mgeneral-regs-only -fno-pic -fno-delete-null-pointer-checks -Os -Wno-maybe-uninitialized --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(test.mod)" -D"KBUILD_MODNAME=KBUILD_STR(test)" -DMODULE -c -o /solomon-build/build_mxt_kmod/test.mod.o /solomon-build/build_mxt_kmod/test.mod.c
aarch64-linux-android-ld -EL -r -T ./scripts/module-common.lds --build-id --fix-cortex-a53-843419 -o /solomon-build/build_mxt_kmod/test.ko /solomon-build/build_mxt_kmod/test.o /solomon-build/build_mxt_kmod/test.mod.o
make[1]: Leaving directory `/solomon-build/MiNote2AOSB/kernel'
So, there are no messages saying there is a missing Module.symvers, so that's good, and I do get a built .ko file.
What I don't understand is the message "ERROR: Kernel configuration is invalid". The files it is talking about exist, so I know they have been created in my kernel build.
Anyway, trying to insmod this onto the phone gives the message I mentioned previously. If I cat Module.symvers I see:
Code:
0xff924338 backlight_force_update drivers/video/backlight/backlight EXPORT_SYMBOL
0x30254daf test_iosched_register block/test-iosched EXPORT_SYMBOL
<snip>
0xdd502540 backlight_device_unregister drivers/video/backlight/backlight EXPORT_SYMBOL
0x9939eba0 backlight_unregister_notifier drivers/video/backlight/backlight EXPORT_SYMBOL
So no symbol module_layout in the file, and thus no CRC, which is what I presume is creating the error message?
Any clues would be much appreciated, thank you.
Oh I should also mention that the module and kernel vermagic match:
Code:
# modinfo /data/local/tmp/test.ko
filename: /data/local/tmp/test.ko
depends:
vermagic: 3.18.20-mytestkernel-perf-g671c431-dirty SMP preempt mod_unload modversions aarch64
# uname -a
Linux localhost 3.18.20-mytestkernel-perf-g671c431-dirty #1 SMP PREEMPT Mon Jun 5 15:46:13 BST 2017 aarch64

Related

[Q] init_module 'hello.ko' failed (Exec format error) in android emulator

hi ,
I am working on my project for android kernel module development i am getting error
like
insmod: init_module 'hello.ko' failed (Exec format error) in android
after performing all process as described below
First we must retrieve and copy the kernel config from our device.
$ cd /path/to/android-sdk/tools
$ ./adk pull /proc/config.gz
$ gunzip ./config.gz
$ cp config /path/to/kernel/.config
changed config file as
CONFIG_MODULES=y
then current config is like this
CONFIG_MODULES=y
CONFIG_MODULE_FORCE_LOAD=y
CONFIG_MODULE_UNLOAD=y
CONFIG_MODULE_FORCE_UNLOAD=y
CONFIG_MODVERSIONS=y
CONFIG_MODULE_SRCVERSION_ALL=y
Next we have to prepare our kernel source for our module.
$ cd /path/to/kernel
$ export ARCH=arm
$ export CROSS_COMPILE=/path/to/android-ndk/toolchains/arm-eabi-4.4.3/prebuilt/linux-x86/bin/arm-eabi-
$ make
then zimage is created and loaded it into emulator succefully.
PREPARING MODULE FOR COMPILATION
i created a Makefile to cross-compile our kernel module. The contents of your Makefile is:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 29
EXTRAVERSION = -00054-gef9c64a
obj-m += hello.o
KDIR=~/Sukha_android/goldfish/
PWD := $(shell pwd)
default:
make -C $(KDIR) ARCH=arm CROSS_COMPILE=~/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- SUBDIRS=$(PWD) modules
clean:
make -C $(KDIR) ARCH=arm CROSS_COMPILE=~/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- SUBDIRS=$(PWD) clean
My Hello.c is :
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
MODULE_LICENSE("GPL");
MODULE_AUTHOR("suhas, 2012");
MODULE_DESCRIPTION("Demo module");
int init_module(void)
{
printk("<1>Hello world\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}
COMPILING AND INSTALLING MODULE
$ cd /path/to/module/src
$ make
$ cd /path/to/android-sdk/tools/
$ ./adb push /path/to/module/src/hello.ko /data
RUNNING YOUR MODULE
$ cd /path/to/android-sdk/
$ ./adb shell
$ su
# insmod /data/hello.ko
then getting error
insmod: init_module 'hello.ko' failed (Exec format error) in android
after :
dmesg:
unknown relocation: 27 when insmod
occured please help me i ts very important for me.
Regards,
Suhas
I guess it should be a ".so" file and not ".ko"..
Sent from my GT-S5830 using Tapatalk
suhascomp.143 said:
dmesg:
unknown relocation: 27 when insmod
Click to expand...
Click to collapse
Try to add EXTRA_CFLAGS=-fno-pic compilation option inside your mod makefile.

[Q] Need help for executing a script

HI, I'm trying to extract initramfs from zImage by following this excellent thread:
http://forum.xda-developers.com/showthread.php?t=901152
I have followed carefully all the steps but i am getting the following error while executing the extraction script :
# sh repack-zImage.sh -u
repack-zImage.sh: 99: Syntax error: "(" unexpected
How can i resolve this please.
here is the sript :
Code:
#!/bin/bash
version="Version 6, by mizch <[email protected]>
Time-stamp: <2011-05-03 20:14:30 hcz>
Please refer to the thread on http://www.xda-developers.com for
questions and remarks about this program."
# Copyright (C) 2011 by Heike C. Zimmerer <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License. For
# details see <http://www.gnu.org/licenses/>.
### Preparation:
# You should have received cpio_set0 along with this program.
# Copy it into /usr/local/bin.
#
# The program will run without this (and emit an info message about
# using the normal cpio). However, the compession result of the
# initramfs will be smaller and consistent if you use it.
### What the program does:
usage(){
echo "\
Usage: $pname [-v] -u|-p|-z [<file name, default: zImage>]
Function: [Un]Pack a zImage (for modification, mainly of the initramfs)
Opts:
-u unpack an Image
-p pack an image from a directory structure created by
a previous unpack
-z create <file name>.tar from <file name> (simple tar, nothing fancy)
--version print version info
--help print this help
Play with the following three options to get best compression results:
-s use standard cpio (default: uses cpio_set0 if available)
-g use gen_init_cpio instead of cpio/cpio_set0 (ignores -s)
-r don't reorder initramfs according to the original layout
Debugging:
-v verbose (show commands and results as they are executed)
-x script debug (set -x)
Options to help nail down which modified part causes booting to fail.
Lower numbers override higher numbered options:
-1 Use original piggy.gz+piggy_trailer
-2 Use original piggy.gz
-3 Use original piggy
-4 Use original initramfs(_gz)+part3
-5 Use original initramfs_cpio"
exit $1
}
### Graphical display of the unpack process:
#
# Each of the indented items on the same level is derived from the
# single item one level higher.
#
# zImage
# (split)
# +---- decompression_code
# +---- piggy.gz+piggy_trailer
# (split)
# +---- piggy.gz
# | (gunzip)
# | +---- piggy
# | ===== either (compressed initramfs) ====
# | |
# | (split via gunzip limits)
# | +---- kernel.img
# | +---- initramfs_gz+part3
# | (split)
# | +---- initramfs.cpio.gz
# | | (gunzip)
# | | +---- initramfs.cpio
# | | (cpio -i)
# | | +---- initramfs/
# | +---- padding3
# | +---- part3
# | ===== or (uncompressed initramfs) =====
# | |
# | (split at "0707")
# | +---- kernel.img
# | +---- initramfs+part3
# | (split after "TRAILER!!!")
# | +---- initramfs.cpio
# | | (cpio -i)
# | | +---- initramfs/
# | +---- padding3
# | +---- part3
# +---- padding_piggy
# +---- piggy_trailer
#
#
pname="${0##*/}"
args=("[email protected]")
cur_dir="$(pwd)"
# file names:
decompression_code="decompression_code"
piggy_gz_piggy_trailer="piggy.gz+piggy_trailer"
piggy="piggy"
piggy_gz="piggy.gz"
padding_piggy="padding_piggy"
piggy_trailer="piggy_trailer"
ramfs_gz_part3="initramfs.cpio+part3"
ramfs_cpio_gz="initramfs.cpio.gz"
padding3="padding3"
part3="part3"
kernel_img="kernel.img"
ramfs_cpio="initramfs.cpio"
ramfs_dir="initramfs"
sizes="sizes"
ramfs_part3="ramfs+part3"
ramfs_list="initramfs_list"
cpio_t="cpio-t"
cpio="cpio_set0"
# We dup2 stderr to 3 so an error path is always available (even
# during commands where stderr is redirected to /dev/null). If option
# -v is set, we dup2 sterr to 9 also so commands (and some of their
# results if redirected to &9) are printed also.
exec 9>/dev/null # kill diagnostic ouput (will be >&2 if -v)
exec 3>&2 # an always open error channel
#
########### Start of functions
#
# Emit an error message and abort
fatal(){
# Syntax: fatal <string ...>
# Output error message, then abort
echo >&3
echo >&3 "$pname: $*"
kill $$
exit 1
}
# Execute a command, displaying the command if -v:
cmd(){
# Syntax: cmd <command> <args...>
# Execute <command>, echo command line if -v
echo >&9 "$*"
"[email protected]"
}
# Execute a required command, displaying the command if -v, abort on
# error:
rqd(){
# Syntax: cmd <command> <args...>
# Execute <command>, echo commandline if -v, abort on error
cmd "[email protected]" || fatal "$* failed."
}
relpath(){
# Syntax: relpath <absolute_path>
# Function: print a path below $cur_dir as relative path on stdout
if [ "${1#$cur_dir}" != "$1" ]; then
echo -n ".${1#$cur_dir}"
else # not below cur_dir
echo -n "$1"
fi
}
findByteSequence(){
# Syntax: findByteSequence <fname> [<string, default: gzip header>]
# Returns: position (offset) on stdout, empty string if nothing found
file="$1"
local opt
if [ "$2" = "lzma" ]; then
srch=$'\x5d....\xff\xff\xff\xff\xff'
opt=
else
srch="${2:-$'\x1f\x8b\x08'}" # Default: search for gzip header
opt="-F"
fi
pos=$(LC_ALL=C grep $opt -a --byte-offset -m 1 --only-matching -e "$srch" -- "$file")
echo ${pos%%:*}
}
getFileSize(){
# Syntax: getFileSize <file>
# Returns size of the file on stdout.
# Aborts if file doesn't exist.
rqd stat -c %s "$1"
}
recordPackingFileSize()(
# Syntax: recordPackingFileSize <file-var> ...
#
# dump out a file size from the packing directory for debugging.
# Note that the whole function is running in a subshell, so we can
# cd here.
rqd cd "$packing"
for file in "[email protected]"; do
eval local fnam=\$$file
local size=$(getFileSize "$fnam")
printf 'size_%s=%d # %#x\n' $file $size $size
done >> "$sizes"
)
recordFileSize(){
# Syntax: recordFileSize <file-var> ...
# Dump a file size from the current directory into $sizes for
# later sourcing as a shell script.
for file in "[email protected]"; do
eval local fnam=\$$file
local size=$(getFileSize "$fnam")
printf 'size_%s=%d # %#x\n' $file $size $size
done >> "$sizes"
}
recordVars(){
# Syntax dumpVar <var-name>
# Dumps var into file $sizes for later sourcing as a shell script
for var in "[email protected]"; do
eval printf '"%s=\"%s\"\n"' $var \$$var \$$var
done >> "$sizes"
}
checkNUL(){
# Syntax: checkNUL file offset
# Returns true (0) if byte there is 0x0.
[ "$(rqd 2>/dev/null dd if="$1" skip=$2 bs=1 count=1)" = $'\0' ]
}
# We can tell from the magic number where the start of a gzipped
# section is. We cannot tell its exact end. We could only know the
# end if we could get at the kernel's zeropage variables - which we
# can't since their position varies between versions and
# architectures. The following function separates the gzipped part
# from trailing bytes (which can be possibly garbage, but who knows?)
# via successive aproximation.
gunzipWithTrailer(){
# Syntax gunzipWithTrailer <file> <gzip name, sans .gz> <padding> <trailer>
#
# <file>: the input file
# <gzip name, sans .gz>, <padding>, <trailer>:
# The output files. For the gzipped part, both the
# compressed and the uncompressed output is generated, so we have
# 4 output files.
local file="$1"
local gz_result="$2.gz"
local result="$2"
local padding="$3"
local trailer="$4"
local tmpfile="/tmp/gunzipWithTrailer.$$.gz"
local original_size=$(getFileSize "$file")
local d=$(( (original_size+1) / 2))
local direction fini at_min=0
local results_at_min=()
local size=$d
local at_min=0
echo "Separating gzipped part from trailer in '$(relpath "$file")'"
echo -n "Trying size: $size"
while :; do
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
cmd gunzip >/dev/null 2>&1 -c "$tmpfile"
res=$?
if [ "$d" -eq 1 ]; then
: $((at_min++))
results_at_min[$size]=1
[ "$at_min" -gt 3 ] && break
fi
d=$(((d+1)/2))
case $res in
# 1: too small
1) size=$((size+d)); direction="↑";;
# 2: trailing garbage
2) size=$((size-d)); direction="↓";;
# OK
0) break;;
*) fatal "gunzip returned $res while checking '$(relpath "$file")'";;
esac
echo -n " $size"
done
if [ "$at_min" -gt 3 ]; then
echo -e "\ngunzip result is oscillating between 'too small' and 'too large' at size: ${!results_at_min[*]}"
echo -n "Trying lower nearby values: "
fini=
for ((d=1; d < 30; d++)); do
: $((size--))
echo -n " $size"
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
if cmd gunzip >/dev/null 2>&1 -c "$tmpfile"; then
echo -n " - OK"
fini=1
break
fi
done
[ -z "$fini" ] && fatal 'oscillating gunzip result, giving up.'
fi
# We've found the end of the gzipped part. This is not the real
# end since gzip allows for some trailing padding to be appended
# before it barfs. First, go back until we find a non-null
# character:
echo -ne "\npadding check (may take some time): "
real_end=$((size-1))
while checkNUL "$file" $real_end; do
: $((real_end--))
done
# Second, try if gunzip still succeeds. If not, add trailing
# null(s) until it succeeds:
while :; do
rqd dd if="$file" of="$tmpfile" bs=$real_end count=1 2>/dev/null
gunzip >/dev/null 2>&1 -c "$tmpfile"
case $? in
# 1: too small
1) : $((real_end++));;
*) break;;
esac
done
real_next_start=$size
# Now, skip NULs forward until we reach a non-null byte. This is
# considered as being the start of the next part.
while checkNUL "$file" $real_next_start; do
: $((real_next_start++))
done
echo $((real_next_start - real_end))
echo
rm "$tmpfile"
# Using the numbers we got so far, create the output files which
# reflect the parts we've found so far:
rqd dd 2>&9 if="$file" of="$gz_result" bs=$real_end count=1
rqd dd 2>&9 if="$file" of="$padding" skip=$real_end bs=1 count=$((real_next_start - real_end))
rqd dd 2>&9 if="$file" of="$trailer" bs=$real_next_start skip=1
rqd gunzip -c "$gz_result" > "$result"
}
# See the comment for gunzipWithTrailer (above) for what this function
# does:
unlzmaWithTrailer(){
# Syntax unlzmaWithTrailer <file> <gzip name, sans .gz> <padding> <trailer>
#
# <file>: the input file
# <gzip name, sans .gz>, <padding>, <trailer>:
# The output files. For the lzma'd part, both the
# compressed and the uncompressed output is generated, so we have
# 4 output files.
local file="$1"
local gz_result="$2.gz"
local result="$2"
local padding="$3"
local trailer="$4"
local tmpfile="/tmp/unlzmaWithTrailer.$$.gz"
local original_size=$(getFileSize "$file")
local d=$(( (original_size+1) / 2))
local direction fini at_min=0
local results_at_min=()
local size=$d
local at_min=
echo "Separating lzma'd part from trailer in '$(relpath "$file")'"
echo -n "Trying size: $size"
while :; do
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
cmd unlzma >/dev/null 2>&1 -S '' -c "$tmpfile"
res=$?
if [ "$d" -eq 1 ] && [ "$res" -eq 1 ]; then
at_min=yes # we're 1 below the result
fi
d=$(((d+1)/2))
case $res in
# 1: too small
1) size=$((size+d)); direction="↑";;
# 0: too large (or OK if d==1)
0) if [ "$at_min" ]; then
break
fi
size=$((size-d)); direction="↓";;
*) fatal "unlzma returned $res while checking '$(relpath "$file")'";;
esac
echo -n " $size"
done
# Now, skip NULs forward until we reach a non-null byte. This is
# considered as being the start of the next part.
echo
echo -n "Detecting padding: "
real_end="$size"
real_next_start="$size"
while checkNUL "$file" $real_next_start; do
: $((real_next_start++))
done
echo $((real_next_start - real_end))
echo
rm "$tmpfile"
# Using the numbers we got so far, create the output files which
# reflect the parts we've found so far:
rqd dd 2>&9 if="$file" of="$gz_result" bs=$real_end count=1
rqd dd 2>&9 if="$file" of="$padding" skip=$real_end bs=1 count=$((real_next_start - real_end))
rqd dd 2>&9 if="$file" of="$trailer" bs=$real_next_start skip=1
rqd unlzma -c -S '' "$gz_result" > "$result"
}
padTo(){
# Syntax: padTo <file> <size>
# Pads <file> to <size> with trailung 0x0s
# Does nothing if file matches size.
# Aborts if <file> too large for the operation.
local size=$(getFileSize "$1")
local tmp="/tmp/$pname.$$.zeroes"
if [ "$size" -eq "$2" ]; then
echo "$(relpath "$1"): size matches ($size)"
elif [ "$size" -gt "$2" ]; then
fatal "Size of '$(relpath "$1")' too large ($size > $2) (+$((size - $2)))"
else
echo "Padding '$(relpath "$1")' to $2 bytes (+$(($2 - size)))"
rqd dd 2>&9 if=/dev/zero of="$tmp" count=1 bs=$(($2 - size))
rqd cat "$tmp" >> "$1"
rqd rm -f "$tmp"
fi
}
padToMod(){
# Syntax: padTo <modulo> <file>
# Pads <file> until (size mod <modulo>) == 0.
local modulo=$1
local file="$2"
local size=$(getFileSize "$file")
local rest=$((size % modulo))
if [ "$rest" -ne 0 ]; then
padTo "$file" $((size + modulo - rest))
fi
}
buildZImageTar(){
# Syntax: buildZImageTar <path>
# Generates tarred file from <path> into the same directory.
# The file in the archive doesn't contain the path.
# Also copies the result to /home/Shared if it detects
# that it is running at home.
local dir="${1%/*}"/
[ "$dir" = "$1/" ] && dir="$(pwd)/"
(
cd "$dir"
rqd tar cf zImage.tar zImage
)
echo "Generated file: '$(relpath "${dir}$zImage.tar")'"
if [ "$HOSTNAME:$USER" = "Xelzbrot:hcz" ]; then
cp "${dir}zImage.tar" /home/Shared
echo "also copied to '/home/Shared'."
fi
}
reorderInitramfsList(){
# This is some black magic to get about the same compression
# result as the original initramfs.cpio. We reorder the files in
# our initramfs (which is to be created) so that they appear in
# the same order as in the original initramfs.
#
# Syntax: reorderInitramfsList <initramfs_list_file> <reordering_template_file>
#
# Reorders <initramfs_list_file> so that enries are in the order
# given by <reordering_template_file> (which comes from cpio -t).
# Files in <initramfs_list_file> but not in
# <reordering_template_file> are moved in sorted order to the end.
# Comments and empty lines are discarded. The result is written
# to <initramfs_list_file>.
#echo >&2 "Reordering initramfs list"
initramfs_list_file="$1"
reordering_template_file="$2"
declare -A ramfs_entries # make it an associative array
while read line; do
set -- $line
[ $# -eq 0 ] && continue # skip empty lines
[[ "$1" = \#* ]] && continue # skip comments
ramfs_entries["$2"]="$line" # else remember line, indexed by path
done < "$initramfs_list_file"
echo "# reordered ramfs entries" > "$initramfs_list_file"
# now spit the lines out in the order given by the reordering_template_file:
while read path; do
echo "${ramfs_entries["$path"]}"
unset ramfs_entries["$path"] # remove written lines from the array
done < "$reordering_template_file" >> "$initramfs_list_file"
# if there are any files left, append them in sorted order so directories
# come first:
for line in "${ramfs_entries[@]}"; do
echo "$line"
done \
| sort >> "$initramfs_list_file"
}
pack(){
if ! find >/dev/null 2>&1 "$unpacked" "$unpacked/$ramfs" "$unpacked/$sizes" -maxdepth 0; then
fatal "\
This does not look like a directory where a
previous unpack has been done."
fi
# create packing direcory
rqd mkdir -p "$packing"
sizes="$packing/sizes"
echo "# Packing sizes" > "$sizes"
# cd to unpacking directory (original and modified parts)
rqd cd "$unpacked"
# read in file size at the time of unpicking
rqd source sizes
if [ "$opt_1" ]; then
rqd cp "$piggy_gz_piggy_trailer" "$packing"
else
if [ "$opt_2" ]; then
rqd cp "$piggy_gz" "$packing"
else
if [ "$opt_3" ]; then
rqd cp "$piggy" "$packing"
compress_list=("$packing/$piggy") # compress it as a single file
else
if [ "$opt_4" ]; then
rqd cp "$ramfs_gz_part3" "$packing"
else
if [ "$opt_5" ]; then
rqd cp "$ramfs_cpio" "$packing"
else
echo "Generating initramfs"
if ! which >/dev/null "$cpio"; then
if [ -n "$compressed" ]; then
echo "Info: '$cpio' not found, using normal cpio."
echo " This only means that your compressed initramfs will be slightly larger"
echo " and its size will differ from invocation to invocation."
fi
cpio="cpio"
fi
for ftime in "" "-a" "-m"; do
find "$ramfs_dir" -exec touch $ftime -d @0 {} \;
done
rqd gen_initramfs_list.sh -u squash -g squash "$ramfs_dir" > "$packing/$ramfs_list"
cp "$packing/$ramfs_list" "$packing/$ramfs_list.orig"
if [ -z "$opt_r" ]; then
# reorder so files are arranged as in original initramfs:
reorderInitramfsList "$packing/$ramfs_list" "$cpio_t"
else
# sort so directories come before their content:
sort < "$cpio_t" > "$packing/$cpio_t.sorted"
reorderInitramfsList "$packing/$ramfs_list" "packing/$cpio_t.sorted"
fi
if [ -z "$opt_g" ]; then
# No -g: Use our own cpio routine
(
rqd cd "$ramfs_dir"
# extract the file names from our
# (possibly reordered) initramfs list
# and pass them to cpio:
while read line; do
set -- $line
[ $# -eq 0 ] && continue # skip empty lines
[[ "$1" = \#* ]] && continue # skip comments
echo "${2#/}"
done < "$packing/$ramfs_list" \
| rqd "$cpio" -H newc -R root:root -o > "$packing/$ramfs_cpio"
)
else
# -g set: use gen_init_cpio (from kernel tree)
rqd gen_init_cpio "$packing/$ramfs_list" > "$packing/$ramfs_cpio"
fi
recordPackingFileSize ramfs_cpio
fi # opt_5
if [ "$compressed" = "gz" ]; then
echo "Creating gzip compressed initramfs"
rqd gzip -8 < "$packing/$ramfs_cpio" > "$packing/$ramfs_cpio_gz"
padTo "$packing/$ramfs_cpio_gz" "$((size_ramfs_cpio_gz + size_padding3))"
rqd cat "$packing/$ramfs_cpio_gz" "$part3" > "$packing/$ramfs_gz_part3"
recordPackingFileSize ramfs_cpio_gz ramfs_gz_part3
elif [ "$compressed" = "lzma" ]; then
echo "Creating lzma compressed initramfs"
rqd lzma -9 < "$packing/$ramfs_cpio" > "$packing/$ramfs_cpio_gz"
padTo "$packing/$ramfs_cpio_gz" "$((size_ramfs_cpio_gz + size_padding3))"
rqd cat "$packing/$ramfs_cpio_gz" "$part3" > "$packing/$ramfs_gz_part3"
recordPackingFileSize ramfs_cpio_gz ramfs_gz_part3
else
echo "initramfs is not compressed"
fi
fi # opt_4
echo "Assembling piggy"
if [ -n "$compressed" ]; then
rqd cat "$kernel_img" "$packing/$ramfs_gz_part3" > "$packing/$piggy"
compress_list=("$packing/$piggy") # compress it as a single file
else
#touch "$packing/$padding3"
#padTo "$packing/$padding3" "$size_padding3"
padTo "$packing/$ramfs_cpio" $((size_ramfs_cpio + size_padding3))
# compress parts seperately (yields better compression results):
cat "$kernel_img" "$packing/$ramfs_cpio" "$part3" > "$packing/$piggy"
recordPackingFileSize "piggy"
compress_list=("$packing/$piggy")
fi
fi # opt_3
echo "Creating piggy.gz"
target_size=$((size_piggy_gz + size_padding_piggy))
# At first, use gzip -9 for compressing since it delivers
# better results with zImages most of the time:
rqd gzip -n -9 -c "${compress_list[@]}" > "$packing/$piggy_gz"
size1=$(getFileSize "$packing/$piggy_gz")
if [ "$size1" -gt "$target_size" ]; then
# too large. Try if we can get better results with
# gzip -8. If not, barf and abort:
rqd gzip -8 -n -c "${compress_list[@]}" > "$packing/$piggy_gz"
size2=$(getFileSize "$packing/$piggy_gz")
if [ "$size2" -gt "$target_size" ]; then
fatal "\
piggy.gz too large (gzip -9: +$((size1-target_size)), gzip -8: +$((size2-target_size)))
You might want to try a different combination of the -g, -r and -s options."
fi
fi
padTo "$packing/$piggy_gz" "$((size_piggy_gz + size_padding_piggy))"
recordPackingFileSize "piggy_gz"
fi # opt_2
echo "Assembling $zImage"
rqd cat "$packing/$piggy_gz" "$piggy_trailer" > "$packing/$piggy_gz_piggy_trailer"
fi # opt_1
rqd cat "$decompression_code" "$packing/$piggy_gz_piggy_trailer" \
> "$packing/$zImage"
echo "Successfully created '$(relpath "$packing/$zImage")'"
recordPackingFileSize zImage
buildZImageTar "$packing/$zImage"
}
unpack()(
[ -d "$unpacked" ] && echo "\
Warning: there is aready an unpacking directory. If you have files added on
your own there, the repacking result may not reflect the result of the
current unpacking process."
rqd mkdir -p "$unpacked"
rqd cd "$unpacked"
sizes="$unpacked/sizes"
echo "# Unpacking sizes" > "$sizes"
piggy_start=$(findByteSequence "$cur_dir/$zImage")
if [ -z "$piggy_start" ]; then
fatal "Can't find a gzip header in file '$zImage'"
fi
rqd dd 2>&9 if="$cur_dir/$zImage" bs="$piggy_start" count=1 of="$decompression_code"
rqd dd 2>&9 if="$cur_dir/$zImage" bs="$piggy_start" skip=1 of="$piggy_gz_piggy_trailer"
recordFileSize decompression_code piggy_gz_piggy_trailer
gunzipWithTrailer "$piggy_gz_piggy_trailer" \
"$piggy" "$padding_piggy" "$piggy_trailer"
recordFileSize "piggy" "piggy_gz" "padding_piggy" "piggy_trailer"
ramfs_gz_start=$( findByteSequence "$piggy" lzma)
if [ -n "$ramfs_gz_start" ]; then
echo "Found lzma compressed ramdisk."
compressed=lzma
else
ramfs_gz_start=$( findByteSequence "$piggy")
if [ -n "$ramfs_gz_start" ]; then
echo "Found gzip compressed ramdisk."
compressed=gz
fi
fi
if [ "$compressed" ]; then
rqd dd 2>&9 if="$piggy" of="$kernel_img" bs="$ramfs_gz_start" count=1
rqd dd 2>&9 if="$piggy" of="$ramfs_gz_part3" bs="$ramfs_gz_start" skip=1
if [ "$compressed" = "gz" ]; then
rqd gunzipWithTrailer "$ramfs_gz_part3" "$ramfs_cpio" "$padding3" "$part3"
else
rqd unlzmaWithTrailer "$ramfs_gz_part3" "$ramfs_cpio" "$padding3" "$part3"
fi
recordFileSize "kernel_img" "ramfs_cpio_gz" "padding3" "ramfs_gz_part3" "ramfs_cpio" "part3"
recordVars compressed
else
echo "Found uncompressed ramdisk."
compressed=""
initrd_start=$(findByteSequence "$piggy" "0707")
[ -z "$initrd_start" ] && fatal "Cannot find cpio header"
rqd dd 2>&9 if="$piggy" of="$kernel_img" bs="$initrd_start" count=1
rqd dd 2>&9 if="$piggy" of="$ramfs_part3" bs="$initrd_start" skip=1
initrd_end=$(findByteSequence "$ramfs_part3" "TRAILER!!!")
[ -z "$initrd_end" ] && fatal "Cannot find cpio trailer"
initrd_end=$((initrd_end + 10)) # skip trailer length
initrd_end=$(( (initrd_end | 0x1ff) + 1)) # round up to block size (512)
rqd dd 2>&9 if="$ramfs_part3" of="$ramfs_cpio" bs="$initrd_end" count=1
real_next_start=$initrd_end
echo -n "Detecting padding (may take some time): "
while checkNUL "$ramfs_part3" $real_next_start; do
: $((real_next_start++))
done
padding3_len=$((real_next_start - initrd_end))
echo $padding3_len
rqd dd 2>&9 if="$ramfs_part3" of="$padding3" skip="$initrd_end" count="$padding3_len" bs=1
rqd dd 2>&9 if="$ramfs_part3" of="$part3" bs="$real_next_start" skip=1
recordFileSize "kernel_img" "padding3" "ramfs_part3" "ramfs_cpio" "part3"
recordVars compressed
fi
echo "Unpacking initramfs"
rqd cpio -t < "$ramfs_cpio" > "$cpio_t"
rqd mkdir -p "$ramfs_dir"
(
rqd cd "$ramfs_dir"
rqd cpio -i -m --no-absolute-filenames -d -u < "../$ramfs_cpio"
)
echo
echo "Success."
echo "The unpacked files and the initramfs directory are in '$(relpath "$unpacked")'."
)
#### start of main program
while getopts xv12345sgrpuhtz-: argv; do
case $argv in
p|u|z|1|2|3|4|5|t|r|g) eval opt_$argv=1;;
v) exec 9>&2; opt_v=1;;
s) cpio="cpio";;
x) set -x;;
-) if [ "$OPTARG" = "version" ]; then
echo "$pname $version"
exit 0
else
usage
fi;;
h|-) usage;;
*) fatal "Illegal option";;
esac
done
shift $((OPTIND-1))
zImage="${1:-zImage}"
unpacked="$cur_dir/${zImage}_unpacked"
packing="$cur_dir/${zImage}_packing"
shift
if [ -n "$*" ]; then
fatal "Excess arguments: '$*'"
fi
if [ -n "$opt_z" ]; then
buildZImageTar "$zImage"
fi
if [ -n "$opt_u" ]; then
[ -f "$zImage" ] || fatal "file '$zImage': not found"
unpack
fi
if [ -n "$opt_p" ]; then
pack
fi
#if [ -n "$opt_t" ]; then # for testing
# reorderInitramfsList "$packing/$ramfs_list" "$unpacked/$cpio_t"
#fi
if [ -z "$opt_p$opt_u$opt_z$opt_t" ]; then
echo >&2 "$pname: Need at least one of -u, -p, or -z."
echo >&2 "$pname: Type '$pname --help' for usage info."
exit 1
fi
exit
Solved. (by using bash instead of sh)..

[Q] dbtTool fails to build dt.img

Code:
[B]28.0.A.7.24[/B]/kernel$ dtbToolCM -o dt.img -s 2048 -p ./scripts/dtc/ ./arch/arm/boot/dts/
DTB combiner:
Input directory: './arch/arm/boot/dts/'
Output file: 'dt.img'
Found file: apq8094-v1-kitakami_karin_windy.dtb ... skip, failed to scan for 'qcom,msm-id = <' tag
Found file: apq8094-v2.1-kitakami_karin_windy.dtb ... skip, failed to scan for 'qcom,msm-id = <' tag
Found file: apq8094-v2.0-kitakami_karin_windy.dtb ... skip, failed to scan for 'qcom,msm-id = <' tag
=> [COLOR="Red"]Found 0 unique DTB(s)[/COLOR]
The kernel is built before without errors.
I got 2 warnings from the make kitakami_defconfig:
Code:
warning: (PCI_MSM && AMD_IOMMU) selects PCI_MSI which has [COLOR="red"]unmet direct dependencies (PCI && ARCH_SUPPORTS_MSI)[/COLOR]
warning: (ARCH_MSM) selects DEVFREQ_GOV_MSM_BW_HWMON which has [COLOR="red"]unmet direct dependencies (PM_DEVFREQ && (ARCH_MSM_KRAIT || ARCH_MSM_BIMC_BWMON))[/COLOR]
Should I bother? make runs fine...
Code:
[B]make V=1 dtbs[/B]
make -f scripts/Makefile.build obj=scripts/basic
rm -f .tmp_quiet_recordmcount
make -f /home/rest/android/28.0.A.7.24/kernel/scripts/Makefile.asm-generic \
src=asm obj=arch/arm64/include/generated/asm
make -f /home/rest/android/28.0.A.7.24/kernel/scripts/Makefile.asm-generic \
src=uapi/asm obj=arch/arm64/include/generated/uapi/asm
make -f scripts/Makefile.build obj=scripts
make -f scripts/Makefile.build obj=scripts/dtc
make -f scripts/Makefile.build obj=scripts/genksyms
make -f scripts/Makefile.build obj=scripts/mod
mkdir -p scripts/mod/
/home/rest/android/28.0.A.7.24/kernel/scripts/[I][COLOR="Magenta"]gcc-wrapper.py[/COLOR][/I] /home/rest/android/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc -Wp,-MD,scripts/mod/.devicetable-offsets.s.d -nostdinc -isystem /home/rest/android/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x-google/include -I/home/rest/android/28.0.A.7.24/kernel/arch/arm64/include -Iarch/arm64/include/generated -Iinclude -I/home/rest/android/28.0.A.7.24/kernel/arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I/home/rest/android/28.0.A.7.24/kernel/include/uapi -Iinclude/generated/uapi -include /home/rest/android/28.0.A.7.24/kernel/include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -Wno-maybe-uninitialized -mgeneral-regs-only -Wframe-larger-than=2048 -fstack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -DCC_HAVE_ASM_GOTO -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(devicetable_offsets)" -D"KBUILD_MODNAME=KBUILD_STR(devicetable_offsets)" -fverbose-asm -S -o scripts/mod/devicetable-offsets.s scripts/mod/devicetable-offsets.c
(set -e; echo "#ifndef __DEVICEVTABLE_OFFSETS_H__"; echo "#define __DEVICEVTABLE_OFFSETS_H__"; echo "/*"; echo " * DO NOT MODIFY."; echo " *"; echo " * This file was generated by Kbuild"; echo " *"; echo " */"; echo ""; sed -ne "/^->/{s:->#\(.*\):/* */:; s:^->\([^ ]*\) [\$#]*\([-0-9]*\) \(.*\):#define /* */:; s:^->\([^ ]*\) [\$#]*\([^ ]*\) \(.*\):#define /* */:; s:->::; p;}" scripts/mod/devicetable-offsets.s; echo ""; echo "#endif" ) > scripts/mod/devicetable-offsets.h
gcc -Wp,-MD,scripts/mod/.file2alias.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -c -o scripts/mod/file2alias.o scripts/mod/file2alias.c
gcc -o scripts/mod/modpost scripts/mod/modpost.o scripts/mod/file2alias.o scripts/mod/sumversion.o
make -f scripts/Makefile.build obj=scripts/selinux
make -f scripts/Makefile.build obj=scripts/selinux/genheaders
make -f scripts/Makefile.build obj=scripts/selinux/mdp
make -f scripts/Makefile.build obj=arch/arm64/boot/dts dtbs
make[1]: [COLOR="Red"]Nothing to be done for 'dtbs'.[/COLOR]
make -f scripts/Makefile.build obj=arch/arm64/boot/dts/qcom dtbs
make[1]: [COLOR="red"]Nothing to be done for 'dtbs'.[/COLOR]
I am on Debian testing. Python 2.7.10
looking into .apq8094-v2.1-kitakami_karin_windy.dtb.dts.tmp in directory 28.0.A.7.24/kernel/arch/arm/boot/dts/ I find e.g.
Code:
qcom,msm-id = <253 0x10000>;
.
It does not make it into apq8094-v1-kitakami_karin_windy.dtb
Any hints how I could proceed to the dt.img?
I needed a newer dbtTool
and an additional -2 on the commandline to use the newer QC table of device tree.
http://forum.xda-developers.com/showthread.php?p=52279145 post #79
I use DooMLoRDs dtbToolCM.
Maybe the SONY documentation is for pre-2015 devices here.
Now I have built my first boot.img
... and my tablet bootloops :crying:

Help with compiling / porting MultiRom / TWRP for Aquaris E5?

I would like to have a dual boot (Android / Ubuntu Touch) on an Aquaris E5 HD phone ( the Ubuntu Touch variant can be flashed with stock Android and vice versa, see mibqyyo.com/en-articles/2015/09/16/ubuntu-android-installation-process-for-bq-aquaris-e4-5-and-e5 ). ((sorry for the links, new user))
Unfortunately, the instructions from wiki.ubuntu.com/Touch/DualBootInstallation do not work with this phone anymore: it seems that the software in those instructions relies on the device having custom ClockworkMod (CWM) recovery -- and, it seems ClockworkMod does not support this device anymore, if it ever did ( see askubuntu.com/questions/666070/cant-install-ubuntu-touch-dual-boot-on-mobile-stuck-in-waiting-for-device/776357 ).
The only other option I could see for dual boot is MultiROM Manager, unfortunately it fails with "This is unsupported device (Aquaris_E5_HD)!"
However, it is possible to root this phone using a TeamWin Recovery Project (TWRP) custom recovery image ( v3.0.2-0, see mibqyyo.com/comunidad/discussion/77467/how-to-root-a-bq-aquaris-e5-hd-phone ), which seemingly does support this phone. Furthermore, from twrp.me/devices/bqaquarise5hd.html there is a reference to:
Device Tree / files: github.com/TeamWin/android_device_bq_vegetahd - and from there:
Kernel source available on: github.com/bq/aquaris-E5
So, I thought - maybe it would be possible to port / build MultiROM from source, with support for this device? I tried something, and maybe I even got part of the way - unfortunately I cannot get the build to complete, so I hope I can get some assistance here. I will outline the steps I did below. First of all, I use this as my PC:
Code:
$ uname -a
Linux MYPC 4.2.0-38-generic #45~14.04.1-Ubuntu SMP Thu Jun 9 09:27:51 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/issue
Ubuntu 14.04.4 LTS \n \l
Then I looked at github.com/Tasssadar/multirom/wiki/Porting-MultiROM:
Prerequisites
* Android 4.1+ tree
* TWRP ported to your device. There are guides on the internet on how to do that.
* Kernel sources
Downloading sources
Just clone TWRP, MultiROM and libbootimg repos into your Android Tree, the commands would look something like this: [...]
Click to expand...
Click to collapse
I was somewhat puzzled about what this "Android Tree" is, but eventually I guessed it is the Android Open Source Project (AOSP) source code. So, I looked and did this:
source.android.com/source/initializing.html
(Note: http removed from links in code below, because I'm a new user and cannot post links):
Code:
cd /tmp
wget archive.ubuntu.com/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jre-headless_8u45-b14-1_amd64.deb
wget archive.ubuntu.com/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jre_8u45-b14-1_amd64.deb
wget archive.ubuntu.com/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jdk_8u45-b14-1_amd64.deb
sudo dpkg -i openjdk-8-jre-headless_8u45-b14-1_amd64.deb
sudo dpkg -i openjdk-8-jre_8u45-b14-1_amd64.deb
sudo dpkg -i openjdk-8-jdk_8u45-b14-1_amd64.deb
sudo apt-get -f install
# already have libgl1-mesa-dev-lts-wily mesa-common-dev-lts-wily
# so removed libgl1-mesa-dev from list below:
sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
libxml2-utils xsltproc unzip
sudo apt-get autoremove --purge
wget -S -O - source.android.com/source/51-android.rules | sed "s/<username>/$USER/" | sudo tee >/dev/null /etc/udev/rules.d/51-android.rules
# for the aquaris:
echo "SUBSYSTEM==\"usb\", ATTRidVendor==\"2a47\", ATTRidProduct==\"201d\", MODE=\"0600\", OWNER=\"$USER\"" \
| sudo tee -a /etc/udev/rules.d/51-android.rules
sudo udevadm control --reload-rules
then
source.android.com/source/downloading.html
Code:
mkdir ~/bin
PATH=~/bin:$PATH
curl storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
cd /path/to/src
mkdir AOSP
cd AOSP
repo init -u android.googlesource.com/platform/manifest -b android-4.1.2_r2.1 2>&1 | tee repo.log
repo sync
Note that here, I took the `4.1+` requirement quite literally, so just chose to checkout the last 4.1 branch, `4.1.2_r2.1`.
Also, repo sync took 14+ hours to complete, for my PC+Internet connection combo (!)
With that done, I have this in the directory:
Code:
AOSP$ ls
abi cts docs hardware ndk prebuilts
bionic dalvik external libcore packages repo.log
bootable development frameworks libnativehelper pdk sdk
build device gdk Makefile prebuilt system
Now, at this point, we should be running build/envsetup.sh and lunch; however, that will cause only the default Google devices (Nexus etc) to be recognized. So, here I did cloned the "device tree" (I guess) into the "Android tree":
Code:
AOSP$ mkdir device/bq
AOSP$ git clone github.com/TeamWin/android_device_bq_vegetahd device/bq/vegetahd
AOSP$ chmod +x device/bq/vegetahd/vendorsetup.sh
AOSP$ ls device/bq/vegetahd/
AndroidBoard.mk BoardConfig.mk kernel omni_vegetahd.mk recovery
AndroidProducts.mk device.mk mkbootimg.mk README.md vendorsetup.sh
AOSP$ ls device/samsung/crespo # for comparison
Android.mk full_crespo.mk libsensors recovery
AndroidProducts.mk gps.conf libstagefrighthw recovery.fstab [...]
vendorsetup.sh
and also cloned the Omnirom TWRP recovery sources (note that if you just mv bootable/recovery bootable/old.recovery, then the builds process may also pick some of those files up, so that directory should be deleted, as guides elsewhere recommend):
Code:
AOSP$ rm -rf bootable/recovery
cd bootable
git clone https://github.com/omnirom/android_bootable_recovery.git recovery-twrp
cd ..
Since build/envsetup.sh should be running the vendorsetup.sh when it finds them, after running it, the Aquaris device should be visible:
Code:
AOSP$ source build/envsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/bq/vegetahd/vendorsetup.sh # ***
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/armv7-a/vendorsetup.sh
including device/moto/wingray/vendorsetup.sh
including device/samsung/crespo/vendorsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/ti/panda/vendorsetup.sh
including sdk/bash_completion/adb.bash
AOSP$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. full-eng
2. full_x86-eng
3. vbox_x86-eng
4. full_grouper-userdebug
5. omni_vegetahd-eng # ***
6. mini_armv7a_neon-userdebug
7. mini_armv7a-userdebug
8. full_wingray-userdebug
9. full_crespo-userdebug
10. full_maguro-userdebug
11. full_panda-userdebug
Which would you like? [full-eng] 5
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.1.2
TARGET_PRODUCT=omni_vegetahd
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.2.0-38-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_BUILD_TYPE=release
BUILD_ID=JZO54M
OUT_DIR=out
============================================
Now, it seems that for such an old version like 4.1.2_r2.1, there is no mka command (not found), which should otherwise be ran at this point - however, I can run make instead of it.
Also because it's so old, I get "You are attempting to build with the incorrect version of java. Your version is: openjdk version "1.8.0_45-internal". The correct version is: Java SE 1.6.", which it so happens, I have - but I have to set environment variables. So here I run:
Code:
AOSP$ export RECOVERY_VARIANT=twrp
AOSP$ ANDROID_PRE_BUILD_PATHS=/path/to/jdk1.6.0_45/bin \
ANDROID_JAVA_TOOLCHAIN=/path/to/jdk1.6.0_45/bin \
JAVA_HOME=/path/to/jdk1.6.0_45 \
PATH=/path/to/jdk1.6.0_45/bin:$PATH \
make -j3 recoveryimage
...
target thumb C: adbd <= system/core/adb/log_service.c
make: *** No rule to make target `out/target/product/vegetahd/obj/EXECUTABLES/recovery_intermediates/recovery', needed by `out/target/product/vegetahd/recovery.img'. Stop.
make: *** Waiting for unfinished jobs....
target thumb C: adbd <= system/core/adb/utils.c
... but as you can see, it fails. This was for the Omnirom sources of TWRP recovery.
Then I thought of going back to the Multirom porting, and so did this:
Code:
AOSP$ rm -r bootable/recovery-twrp
git clone github.com/Tasssadar/Team-Win-Recovery-Project.git bootable/recovery
git clone github.com/Tasssadar/multirom.git system/extras/multirom
git clone github.com/Tasssadar/libbootimg.git system/extras/libbootimg
cd system/extras/multirom
git submodule update --init
cd ../../..
Then I checked the touchpad from adb shell as root:
Code:
cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="mtk-tpd"
P: Phys=
S: Sysfs=/devices/virtual/input/input3
U: Uniq=
H: Handlers=mouse0 event3 cpufreq
B: PROP=2
B: EV=b
B: KEY=10 0 0 0 0 0 0 0 400 0 0 0 0 1000 40000000 100000 0 0 0
B: ABS=6630000 1000003
... so definitely "type b"; then by doing `find /sys | grep uevent` and comparing as in the porting guide, I put together this file as device/bq/vegetahd/mr_init_devices.c:
Code:
#include <stdlib.h>
// These are paths to folders in /sys which contain "uevent" file
// need to init this device.
// MultiROM needs to init framebuffer, mmc blocks, input devices,
// some ADB-related stuff and USB drives, if OTG is supported
// You can use * at the end to init this folder and all its subfolders
const char *mr_init_devices[] =
{
"/sys/devices/platform/mtkfb.0/graphics/fb0",
"/sys/devices/platform/mtkfb.0",
"/sys/devices/platform/mtk-msdc.0",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0boot0",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0boot1",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0rpmb",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p2",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p3",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p4",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p5",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p6",
"/sys/devices/platform/mtk-msdc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p7",
"/sys/devices/platform/mtk-msdc.1",
"/sys/devices/platform/mtk-msdc.1/mmc_host/mmc1",
"/sys/devices/platform/mtk-msdc.1/mmc_host/mmc1/mmc1:0007",
"/sys/devices/platform/mtk-msdc.1/mmc_host/mmc1/mmc1:0007/block/mmcblk1/mmcblk1p1",
"/sys/devices/platform/mtk-msdc.1/mmc_host/mmc1/mmc1:0007/block/mmcblk1",
"/sys/bus/mmc/uevent",
"/sys/bus/mmc/drivers/mmcblk/uevent",
"/sys/bus/sdio/uevent",
"/sys/devices/virtual/input/*",
"/sys/devices/virtual/misc/uinput",
"/sys/devices/platform/mtk-tpd",
"/sys/devices/platform/mtk-kpd",
"/sys/devices/platform/mtk-kpd/input/input0",
"/sys/devices/platform/mtk-kpd/input/input0/event0",
"/sys/devices/platform/mtk-kpd/misc/mtk-kpd",
// for adb
"/sys/devices/virtual/tty/ptmx",
"/sys/devices/virtual/misc/android_adb",
"/sys/devices/virtual/android_usb/android0/f_adb",
"/sys/bus/usb",
NULL // must be NULL-terminated
}
Then I inspected boot.img of the stock Android firmware:
Code:
$ /path/to/bootimg_tools/boot_info /path/to/bq/2.1.0_20151104-0859_E5HD_bq-FW/boot.img
Page size: 2048 (0x00000800)
Kernel size: 3747904 (0x00393040)
Ramdisk size: 615529 (0x00096469)
Second size: 0 (0x00000000)
Board name: fbcdadc
Command line: ''
Base address: 2147483648 (0x80000000)
... and also did:
Code:
mkdir device/bq/vegetahd/mrom-infos/
wget raw.githubusercontent.com/Tasssadar/device_asus_grouper/cm-10.2-mrom/mrom_infos/ubuntu_touch.txt -O device/bq/vegetahd/mrom-infos/ubuntu_touch.txt
... and confirmed paths, and could finally add this to device/bq/vegetahd/BoardConfig.mk :
Code:
#MultiROM config. MultiROM also uses parts of TWRP config
MR_INPUT_TYPE := type_b
MR_INIT_DEVICES := device/bq/vegetahd/mr_init_devices.c
MR_RD_ADDR := 0x82500000
MR_DPI := hdpi
MR_DPI_FONT := 216
MR_FSTAB := device/bq/vegetahd/recovery/etc/twrp.fstab
MR_KEXEC_MEM_MIN := 0x85000000
MR_INFOS := device/bq/vegetahd/mrom_infos
Here, if I run ... make ... (after first exiting the old terminal shell, and repeating envsetup.sh / lunch in a new one), I get "build/core/base_rules.mk:103: *** user tag detected on new module - user tags are only supported on legacy modules. Stop." So, I did these changes:
Code:
# bootable/recovery/Android.mk:
LOCAL_MODULE := recovery
LOCAL_MODULE_TAGS := optional # add
# bootable/recovery/tests/Android.mk:
LOCAL_MODULE := asn1_decoder_test
LOCAL_MODULE_TAGS := optional # add
Then, a ... make ... at this point fails with: "make: *** No rule to make target `out/target/product/vegetahd/system/xbin/busybox', needed by `out/target/product/vegetahd/obj/SHARED_LIBRARIES/libbmlutils_intermediates/teamwin'. Stop.".
Here I found "[DEV]How to compile TWRP touch recovery - Pg. 150 | Android Development and Hacking" ( forum.xda-developers.com/showthread.php?p=65556586 ), and I downloaded busybox.zip from that page - and did:
Code:
AOSP$ unzip busybox.zip
AOSP$ mv busybox external/
Now, the ... make ... at this point is a bit funny, because it will exit not reporting an error, as if it finished:
Code:
AOSP$ ANDROID_PRE_BUILD_PATHS=/path/to/jdk1.6.0_45/bin \
ANDROID_JAVA_TOOLCHAIN=/path/to/jdk1.6.0_45/bin \
JAVA_HOME=/path/to/jdk1.6.0_45 \
PATH=/path/to/jdk1.6.0_45/bin:$PATH \
make -j3 recoveryimage
...
GEN include/usage_compressed.h
GEN include/applet_tables.h
HOSTCC applets/usage_pod
GEN include/bbconfigopts.h
CC applets/applets.o
LD applets/built-in.o
make[1]: Leaving directory `/media/Data1/src/AOSP/external/busybox'
AOSP$
But here it is apparently just done with applets in busybox! So, I try running ... make ... again, and get:
Code:
external/busybox/android/librpc/bindresvport.c:41:13: error: conflicting types for '__set_errno'
bionic/libc/include/errno.h:45:15: note: previous declaration of '__set_errno' was here
This I fix by changing external/selinux/libsepol/include to external/libsepol/include in:
Code:
# external/busybox/Android.mk:
BUSYBOX_C_INCLUDES = \
$(BB_PATH)/include $(BB_PATH)/libbb \
bionic/libc/private \
bionic/libm/include \
bionic/libc \
bionic/libm \
libc/kernel/common \
external/libselinux/include \
external/libsepol/include \
...
... and at this point, ... make ... will fail with:
Code:
external/busybox/android/librpc/pmap_rmt.c:235:8: warning: implicit declaration of function 'inet_makeaddr' [-Wimplicit-function-declaration]
external/busybox/android/librpc/pmap_rmt.c:238:8: warning: implicit declaration of function 'inet_netof' [-Wimplicit-function-declaration]
external/busybox/android/librpc/pmap_rmt.c:235:19: error: incompatible types when assigning to type 'struct in_addr' from type 'int'
Here I found stackoverflow.com/questions/27762475/incompatible-types-when-assigning-to-type-struct-in-addr-from-type-int/27763398, which notes:
The error message is misleading, the function is simply missing from earlier versions of the NDK.
Click to expand...
Click to collapse
So, as a final try, I tried forcing a newer NDK through an environment variable, as in:
Code:
NDK_HOME=/path/to/android-ndk-r10e \
ANDROID_PRE_BUILD_PATHS=/path/to/jdk1.6.0_45/bin \
ANDROID_JAVA_TOOLCHAIN=/path/to/jdk1.6.0_45/bin \
JAVA_HOME=/path/to/jdk1.6.0_45 \
PATH=/path/to/jdk1.6.0_45/bin:$PATH \
make -j3 recoveryimage
... but this fails in exactly the same manner (with "implicit declaration of function 'inet_makeaddr'", etc).
At this point, I really don't know what I should do... Should I:
Try to use the BQ Kernel sources for this device (even if mentioned above, I haven't used them anywhere yet) somewhere (say clone them in the Android tree)? If so - where?
Try to find a busybox for AOSP 4.1.2? If so - what version is OK, and where do I find it?
Try to bump the AOSP repo version up from 4.1.2? If so, what would be the minimum version required so this builds - and would I have to wait 14+ hours again?
... or is there anything else I could try?
Again, I'm mostly interested in building MultiROM and the recovery image (TWRP?) required for it on the Aquaris E5 - but it would be nice to know how to build TWRP proper recovery image as well...
Thanks in advance for any hints...
Me too
I am planning on doing almost the exact same thing you're trying! But I have a few questions:
Have you tried adding --depth 1 to your repo command to reduce the download time?
Have you seen https://forum.xda-developers.com/showthread.php?t=2329228 ? Mainly the local manifest, also to reduce download time
Why do you want to use the lowest version possible? The TWRP device tree is for Android 5.1, so I'll be using that version.

[KERNEL] Has anyone managed to boot 34.3.A.0.217 copyleft kernel?

I am running Ubuntu 16.10 under VirtualBox in a Windows 64-bit machine and trying to build the Sony's open source copyleft kernel for 34.3.A.0.217, which can be downloaded here: https://developer.sonymobile.com/do...rchives/open-source-archive-for-34-3-a-0-217/
-Untouched copyleft source code
-Untouched ramdisk extracted from stock kernel.elf file with this tool: https://forum.xda-developers.com/xp...oot-automatic-repack-stock-kernel-dm-t3301605
-Using AOSP mkbootimg (the new one written in Python: https://android.googlesource.com/platform/system/core/+/nougat-release/mkbootimg/mkbootimg) with arguments specified in README_Xperia (https://github.com/bamsbamx/BMSBMX_kernel_kugo/blob/master/README_Xperia)
Even if the build is succesful and the boot.img file is generated properly, the device gets stuck in SONY logo when flashing it
Any ideas about how can I find the problem?
The following is the build script:
Code:
#!/bin/bash
RED=1
GREEN=2
BLUE=4
colorPrint() {
tput setaf $2
echo $1
tput sgr0
}
colorPrint "Initializing workspace..." $BLUE
#Device config
device=kugo
#Workspace directories
workdir="$(pwd)"
outputfolder=${workdir}/OUTPUT
outputdir=${outputfolder}/${device}
toolchains=${workdir}/toolchains
ramdisk=${workdir}/ramdisks/${device}/ramdisk
export ARCH=arm64
export CROSS_COMPILE=${toolchains}/aarch64-linux-android-4.9-kernel/bin/aarch64-linux-android-
export KBUILD_DIFFCONFIG=kugo_diffconfig
colorPrint "Cleaning previous builds..." $BLUE
rm -rf $outputdir
mkdir -p $outputdir
colorPrint "Configuring kernel..." $BLUE
make msm-perf_defconfig O=$outputdir
colorPrint "Building kernel..." $BLUE
time make -j8 O=$outputdir 2>&1
if [ ! -f $outputdir/arch/arm64/boot/Image.gz-dtb ]; then
colorPrint "ERROR: kernel image not found. Kernel build failed" $RED
exit 1
fi
if [ ! -e $outputdir/ramdisk.cpio.gz ]; then
colorPrint "ERROR: ramdisk image file not found. Compression failed" $RED
exit 1
fi
colorPrint "Packaging boot image file" $BLUE
${workdir}/utils/mkqcdtbootimg \
--kernel $outputdir/arch/arm64/boot/Image.gz-dtb \
--ramdisk $outputdir/ramdisk.cpio.gz \
--base 0x20000000 \
--ramdisk_offset 0x02000000 \
--pagesize 2048 \
--tags_offset 0x01E00000 \
--cmdline "androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 zram.backend=z3fold earlyprintk" \
--output $outputdir/boot.img
if [ ! -f $outputdir/boot.img ]; then
colorPrint "ERROR: boot image file not found. boot packaging failed" $RED
exit 1
fi
colorPrint "DONE" $GREEN
colorPrint "boot image file can be found at ${outputdir}/boot.img" $GREEN

Categories

Resources