This howto is only draft! Sometimes i went upgrade this, or make page on my site and post link on it. Also we have a project for automated building, like buildroot and opkg repository for android.
All needed configs in attached file. If you have error on unpack - just rename my.zip in my.tar.bz2 and try to unpack. Please correct me, if needed.
----------------------------------------------------------------------------------------------------------------------------------
All work will be in home directory (/home/xvilka)
create dir build
mkdir build
1. Download the kernel (for android on your version for device) and unpack
make headers_install ARCH=arm INSTALL_HDR_PATH=~/build/kern_h/
For some optimisations you need know, which proccessor (SoC) in your android-system(gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/ARM-Options.html#ARM-Options)
Im have Motorola Milestone - SoC = TI OMAP3430 - ARM Cortex a8 (arch - armv7a)
(en.wikipedia.org/wiki/ARM_architecture)
So, if you have OMAP3430-processor - use the config files with -omap3430 suffix
If you have Quallcomm MSM7200A (HTC Hero) - use the config files with -msm7200a suffix
First, we need to define _XXFLAGS, which contain some optimisation options for your compiler:
export _XXCFLAGS=" -mcpu=cortex-a8 -march=armv7-a -mtune=cortex-a8 -mfpu=vfpv3 -O3 -Os" (if you have Motorola Milestone/Droid or other device with TI OMAP3430)
export _XXCFLAGS=" -march=armv6j -mtune=arm1136jf-s -O3 -Os" (if you have HTC Hero or other device with Quallcomm MSM 7200A)
............................................................................................
If you don't know which chip you have in phone use _XXCFLAGS=" -O3 -Os"
2. Download crosstool-ng (ymorin.is-a-geek.org/dokuwiki/projects/crosstool),
unpack, build (you must have make,install,bash,cut,sed,grep,gcc,awk,bison,flex,automake,libtool,stat,
wget,cvs,patch,tar,gzip,bzip2,lzma,readlink,ncurses)
.configure
make
make install
3. Create directory toolchain-android, and copy config to this
XVilka-crosstool-<suffix>.config in .config
XVilka-uClibc-<suffix>.config in uClibc-0.9.30.2.config (or later version, if available)
and then run:
ct-ng menuconfig
you may change some options, if needed!
(Also use options from XXCFLAGS:
Target options -> Target optimizations ->
Architecture-level equal -march, use armv7-a
Emit assembly for CPU equal -mcpu, use cortex-a8
Tune for cpu equal -mtune, use cortex-a8
Use specific FPU equal -mfpu, use vfpv3
Floating point use hardware, because it built-in TI OMAP3430
Target CFLAGS - use -O3 -Os
) - for the Motorola Milestone/Droid
(Also use options from _XXCFLAGS:
Target options -> Target optimizations ->
Architecture-level equal -march, use armv6j
Emit assembly for CPU equal -mcpu, use nothing
Tune for cpu equal -mtune, use arm1136jf-s
Floating point use software
Target CFLAGS - use -O3 -Os
) - for the HTC Hero
Save in .config
In file uClibs-0.9.30.2.config
edit this strings:
{
UCLIBC_HAS_FLOATS=y
UCLIBC_HAS_FPU=y
# UCLIBC_HAS_SOFT_FLOAT=y
UCLIBC_EXTRA_CFLAGS=" -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=vfpv3 -O3 -Os"
} - for the Motorola Milestone/Droid
{
UCLIBC_HAS_FLOATS=y
#UCLIBC_HAS_FPU=y
UCLIBC_HAS_SOFT_FLOAT=y
UCLIBC_EXTRA_CFLAGS=" -march=armv6j -mtune=arm1136jf-s -O3 -Os"
} - for the HTC Hero
and then run
ct-ng build
4. Ok, done. We have installed cross - toolchain in directory build/x-tools.
And all programs in it with names arm-android-linux-uclibsgnueabi-*
For easy using add this directory in PATH:
PATH=~/build/x-tools/arm-android-linux-uclibcgnueabi/bin:$PATH
so we can run cross-gcc by the command:
arm-android-linux-uclibcgnueabi-gcc
Root directory of target system is:
~/build/x-tools/arm-android-linux-uclibcgnueabi/arm-android-linux-uclibcgnueabi/sys-root
But for the safe - make new root dir and copy files too.
Copy files in ~/build/cross/sys-root
chmod +w sys-root
chmod +w sys-root/usr
5. Building busybox (only static build, but if we have static busybox in any problems with system problems with libs
we can easy use busybox as repair-mode tool)
copy file XVilka-busybox-<suffix>.config in .config
make menuconfig
make ARCH=arm CC="arm-android-linux-uclibcgnueabi-gcc" CROSS_COMPILE="arm-android-linux-uclibcgnueabi-" \
CFLAGS=" -static $_XXFLAGS"
make install CONFIG_PREFIX=~/build/cross/sys-root
Copy ~/build/cross/sys-root/bin/busybox in /system/bin on device
chown root /system/bin/busybox
chmod 755 /system/bin/busybox
ln -s /system/bin/busybox /system/bin/ash
Or in other directory and you can install all programs included in busybox by the command:
busybox --install
7. Building simple but powerful text editor jupp (mirbsd.org/jupp.htm)
chmod +x configure
./configure --prefix=/system/local --disable-curses --disable-termcap --disable-termidx --host=arm-android-linux-uclibcgnueabi ARCH=arm \
CC="arm-android-linux-uclibcgnueabi-gcc" CROSS_COMPILE="arm-android-linux-uclibcgnueabi-" sysconfdir=/system/usr/local/etc sysconfjoesubdir=/joe \
CFLAGS=" -static $_XXFLAGS"
make
arm-android-linux-uclibcgnueabi-strip joe
On device:
copy joe in /system/bin
copy joerc in /system/usr/local/etc/joe
copy jupprc in /system/usr/local/etc/joe
copy jmacsrc in /system/usr/local/etc/joe
copy sintax files in /system/usr/local/etc/joe/syntax
chmod 755 /system/bin/joe
ln -s /system/bin/joe /system/bin/jupp
ln -s /system/bin/joe /system/bin/jmacs
chmod 644 /system/usr/local/etc/joe/joerc
chmod 644 /system/usr/local/etc/joe/jupprc
chmod 644 /system/usr/local/etc/joe/jmacsrc
before running joe we must define TERM
export TERM=ansi
8. How to use dinamic linking and shared libraries
(if we installed programs in local directory in sys-root,
so copy lib from local)
cd ~/build/cross/sys-root
tar -jcf lib.tar.bz2 lib/
And on device:
cd /system/usr/local
busybox tar -xcf /sdcard/lib.tar.bz2
For our programs, wich uses this non-standart library path we may create this script and run your programs by it:
#!/bin/sh
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
exec /usr/bin/local/some_program $*
9. Building libFLAC in shared library, which we can use easy and copy to /system/lib,
which have nothing in NEEDED - just kernel and you, also no any libc (bionic, or uClibc) not used.
Download latest version of libFLAC from the official site, unpack and cd to dir:
./autogen.sh --host=arm --target=arm-android-linux-uclibcgnueabi CC="arm-android-linux-uclibcgnueabi-gcc" \
CXX="arm-android-linux-uclibcgnueabi-g++" STRIP="arm-android-linux-uclibcgnueabi-strip" \
AR="arm-android-linux-uclibcgnueabi-ar" AS="arm-android-linux-uclibcgnueabi-as" LD="arm-android-linux-uclibcgnueabi-ld" \
RANLIB="arm-android-linux-uclibcgnueabi-ranlib" OBJDUMP="arm-android-linux-uclibcgnueabi-objdump" \
NM="arm-android-linux-uclibcgnueabi-nm" CROSS_COMPILE="arm-android-linux-uclibcgnueabi-" \
CFLAGS=" -nodefaultlibs -nostdlib -fPIC $_XXFLAGS" \
CXXFLAGS=" -nodefaultlibs -nostdlib -fPIC $_XXFLAGS" \
LDFLAGS=" -fPIC -static -s -L$HOME/build/cross/sys-root/usr/lib -lm -lc" --prefix="$HOME/build/cross/sys-root/usr" \
--disable-ogg --disable-oggtest --disable-rpath --disable-xmms-plugin --disable-cpplibs --disable-altivec \
--disable-3dnow --disable-thorough-tests --disable-doxygen-docs
cd src/libFLAC
make
cd .libs
arm-android-linux-uclibcgnueabi-ld -shared -s -o libFLAC.so -whole-archive libFLAC.a
And now we have shared library libFLAC.so, lybrary without any dependency, and which we can just copy in /system/lib
on device and use it from any program.
For programming on libFLAC you must see header files of libFLAC
10. Building xvid in shared library, without any dependecy, same as libFLAC.
cd src/build/generic
./configure --host=arm --target=arm-android-linux-uclibcgnueabi CC="arm-android-linux-uclibcgnueabi-gcc" \
CXX="arm-android-linux-uclibcgnueabi-g++" STRIP="arm-android-linux-uclibcgnueabi-strip" \
AR="arm-android-linux-uclibcgnueabi-ar" AS="arm-android-linux-uclibcgnueabi-as" \
LD="arm-android-linux-uclibcgnueabi-ld" RANLIB="arm-android-linux-uclibcgnueabi-ranlib" \
OBJDUMP="arm-android-linux-uclibcgnueabi-objdump" NM="arm-android-linux-uclibcgnueabi-nm" \
CROSS_COMPILE="arm-android-linux-uclibcgnueabi-" \
CFLAGS=" -nodefaultlibs -nostdlib -fPIC $_XXFLAGS" \
CXXFLAGS=" -nodefaultlibs -nostdlib -fPIC $_XXFLAGS" \
LDFLAGS=" -fPIC -static -s -L$HOME/build/cross/sys-root/usr/lib -lm -lc" --prefix="$HOME/build/cross/sys-root/usr"
cd =build
rm-android-linux-uclibcgnueabi-ld -shared -s -o libxvidcore.so -whole-archive libxvidcore.a
So we have libxvidcore.so, which using very-very simple and copy-only-use too.
11. Building nmap
svn co --username guest --password "" svn://svn.insecure.org/nmap/
cd nmap
./configure --host=arm-android-linux-uclibcgnueabi CC="arm-android-linux-uclibcgnueabi-gcc" \
CROSS_COMPILE="arm-android-linux-uclibcgnueabi-" CFLAGS=" -static $_XXFLAGS" \
CXXFLAGS=" -static $_XXFLAGS" \
--prefix="$HOME/build/cross/sys-root/system/usr/local" --with-lua=included --with-pcap=included --with-pcre=included --with-dnet=included
make
make install
12. Building dropbear
./configure --host=arm-android-linux-uclibcgnueabi CC="arm-android-linux-uclibcgnueabi-gcc" \
CROSS_COMPILE="arm-android-linux-uclibcgnueabi-" \
CFLAGS=" -static $_XXFLAGS" \
--prefix="$HOME/build/cross/sys-root/system/usr/local" --disable-zlib
make
make install
copy dbclient, dropbearconvert and dropbearkey in /system/bin
copy dropbear in /system/sbin
chown root on all copied files
chmod 755 on all copied files
Hi, I've been folowing your howto in order to build busybox but when I download the my.zip file I think it's corrupted or something because it's empty and I can't extract the config files. Could you check it please? Thanks in advance
the my.zip file is compressed strangely. I was able to open it using 7-zip then opened the "my" file in there and it showed a bunch of file within it. Can the op look into his archive and see about recompressing it in a more compliant format. It isn't a zip file.
EDIT: Actually forget it. When you download it replace the .zip with .tar.bz2 or you can just append it to the filename probably if the .zip part isn't showing for you. It's a bzip2 compressed tar archive.
shinji257 said:
the my.zip file is compressed strangely. I was able to open it using 7-zip then opened the "my" file in there and it showed a bunch of file within it. Can the op look into his archive and see about recompressing it in a more compliant format. It isn't a zip file.
EDIT: Actually forget it. When you download it replace the .zip with .tar.bz2 or you can just append it to the filename probably if the .zip part isn't showing for you. It's a bzip2 compressed tar archive.
Click to expand...
Click to collapse
worked like a charm. Thanks!!
I would like to thank you for this guide. With it (and a small alteration to my own busybox .config) I was able to build 1.18.5 and 1.19.0.git with network support working finally. The files are a bit bigger for my taste but I'll go back and see if I can get a dynamic build next.
The flash* items (flashcp, flash_lock, flash_unlock, flash_eraseall) will not build unless you get the mtd-utils package from the android repo.
EDIT: It will dynamic build but I came across a roadblock. The uClibc included on my phone already is 0.9.31 and the toolchain built 0.9.30.2 so I'm changing it up a bit... Should be fine though.
Dynamic link reduces from 1.7MB to ~1.0MB
Here is russian version of manual http://wiki.androidfan.ru/Сборка_c_нуля
Also there some updates too: https://www.droid-developers.org/wiki/Toolchain
Easy way to build jupp… if you’ve got Debian, that is.
XVilka said:
7. Building simple but powerful text editor jupp (mirbsd.org/jupp.htm)
Click to expand...
Click to collapse
Thank you very much for liking jupp and publishing him here!
If you’re running Debian on an ARM system, there’s an even easier way to get jupp.
• set up the system for building packages (or login to a Debian porterbox like harris.debian.org and switch into the “sid” chroot): install the build-essential package
• install debhelper and autotools-dev
• install dietlibc-dev (or libklibc-dev, but I tested with dietlibc-dev right now as I cannot install libklibc-dev on the porterbox by myself)
• go to packages.debian.org/source/sid/jupp and figure out the download link to the .dsc file
• download that with “dget”:
Code:
dget -d http://ftp.de.debian.org/debian/pool/main/j/jupp/jupp_3.1.23-1.dsc
(of course, adjust the link; this is the version up to date at the time of this writing)
• extract the package (adjust the name as usual):
Code:
dpkg-source -x jupp_3.1.23-1.dsc
• switch into the source directory:
Code:
cd jupp-3.1.23/
• run a compilation:
Code:
env DEB_BUILD_OPTIONS=diet fakeroot debian/rules binary
(or DEB_BUILD_OPTIONS=klibc)
Now you have in the directories ./debian/jupp/ and ./debian/joe-jupp/ the full build result. Test it by running
Code:
./debian/jupp/usr/bin/jupp
(you can press ^Kq, that is Ctrl-K followed by q, to exit it immediately; remember ^J (Ctrl-J) opens the help).
Now install the following files into their final locations:
• debian/jupp/etc/jupp/* to /etc/jupp/ (including subdirectories)
• debian/jupp/usr/bin/jupp to /usr/bin/jupp
• optionally, debian/joe-jupp/etc/jupp/ to /etc/jupp/ and the symlinks from debian/joe-jupp/usr/bin/ to /usr/bin/
Strictly speaking, for running “jupp”, no other file than the executable is needed, and that can be in any path. It includes a copy of jupprc in the executable, although without syntax highlighting.
If you have to change the paths, look at the file debian/rules (--prefix, --sysconfdir, --mandir although you don’t need the mandir) and debian/jupp.install and debian/joe-jupp.install (install paths) before compiling.
JOE finds the *rc files by looking into a path that is set at compile time (if --sysconfdir=/etc it looks into /etc/joe/ but debian/rules also sets sysconfjoesubdir=/jupp at make time, so it uses /etc/jupp/ instead), a file that’s the basename of the editor command plus “rc”, so /usr/bin/jfoo will let it load jfoorc. The klingon charmap and the syntax files are expected in subdirectories of where the configs (rc files) are.
Hope that helps!
If you want, I’m in the IRC channel #MirBSD and #!/bin/mksh on Freenode IRC network, and can help (but will assume you’re either running Debian/ARM or have your cross compiler set up correctly).
I'm building some common gnu/linux console utilities for my Android phone but so far I have only been able to build them statically, with quite a size penalty. Can someone walk me through the steps or point me to a howto for dynamic compiles using arm shared libraries?
Here's the script(s) I'm using for configuration:
Code:
./configure --host=arm-none-linux-gnueabi \
CC="arm-none-linux-gnueabi-gcc" \
CROSS_COMPILE="arm-none-linux-gnueabi-" \
CFLAGS=" -static $_XXFLAGS" \
for shared:
Code:
./configure --host=arm-none-linux-gnueabi \
CC="arm-none-linux-gnueabi-gcc" \
CROSS_COMPILE="arm-none-linux-gnueabi-" \
--enable-shared=yes --enable-static=no
Do I need to make the libs on my android phone avaiable to my cross-compiler? Google isn't helping me here.
Bump. Anyone?
Never mind on this. I learned that using the cross-compiler supplied by Google is the way to go.
The master branch of SELinux doesn't include native android support,
and the external selinux repo from google is limited and only targets host for tools.
You can make a few edits to get some useful binaries to use on Android on master branch
even though libsepol and libselinux aren't patched for android compliance, the tools are still useful.
dispol for example allows you to dump sepolicy rules for everything, for example you could recreate the supersu.te if you wanted.
checkpolicy allows you to write out a new sepolicy with edits.
getfilecon and setfilecon are very useful for getting contexts and setting contexts.
I only enabled a few binaries, but there are many more you can add by following the examples in the Android.mkby default it builds:
checkmodule
checkpolicy
chkcon
dismod
dispol
getfilecon
sefcontext_compile
setfilecon
I thought id share this here as folks often only use libsepol for sepolicy-inject and as security gets tighter it will be useful to know how to compile for target devices.
dispol is very useful, selecting a file to output to and then choosing option 1 dumps all rules.
also you can see specific rules, such as the filename_trans rule I implemented for Substratum's Interfacer,
allowing it to auto set the contexts on files it creates in /data/system/theme to "theme_data_file"
Select a command:
1) display unconditional AVTAB
2) display conditional AVTAB (entirely)
3) display conditional AVTAB (only ENABLED rules)
4) display conditional AVTAB (only DISABLED rules)
5) display conditional bools
6) display conditional expressions
7) change a boolean value
8) display role transitions
c) display policy capabilities
p) display the list of permissive types
u) display unknown handling setting
F) display filename_trans rules
f) set output file
m) display menu
q) quit
Command ('m' for menu): F
filename_trans rules:
ueventd device :chr_file klog_device __kmsg__
wpa wifi_data_file :dir wpa_socket sockets
interfacer system_data_file :file theme_data_file theme
system_server system_data_file :sock_file system_ndebug_socket ndebugsocket
hostapd wifi_data_file :dir wpa_socket hostapd
hostapd wifi_data_file :dir wpa_socket sockets
Command ('m' for menu): p
permissive sids:
recovery
su
supersu
Command ('m' for menu):
similarly checkpolicy makes it easy to write out a new policy
angler:/ $ checkpolicy /sepolicy -b -d -M -c 30 -o /sdcard/sepolicy.new
checkpolicy: loading policy configuration from /sepolicy
libsepol.policydb_index_others: security: 1 users, 2 roles, 801 types, 0 bools
libsepol.policydb_index_others: security: 1 sens, 1024 cats
libsepol.policydb_index_others: security: 63 classes, 13466 rules, 0 cond rules
checkpolicy: policy configuration loaded
checkpolicy: writing binary representation (version 30) to /sdcard/sepolicy.new
Theres quite a bit of trickery/makefile l33tness going on, so id encourage you to understand/look at this Sexy af Android.mk below, considering this is where most of the magic happens.
Code:
LOCAL_PATH:= $(call my-dir)
libselinux_src_files := \
libselinux/src/audit2why.c \
libselinux/src/avc.c \
libselinux/src/avc_internal.c \
libselinux/src/avc_sidtab.c \
libselinux/src/booleans.c \
libselinux/src/callbacks.c \
libselinux/src/canonicalize_context.c \
libselinux/src/checkAccess.c \
libselinux/src/check_context.c \
libselinux/src/checkreqprot.c \
libselinux/src/compute_av.c \
libselinux/src/compute_create.c \
libselinux/src/compute_member.c \
libselinux/src/compute_relabel.c \
libselinux/src/compute_user.c \
libselinux/src/context.c \
libselinux/src/deny_unknown.c \
libselinux/src/disable.c \
libselinux/src/enabled.c \
libselinux/src/fgetfilecon.c \
libselinux/src/freecon.c \
libselinux/src/freeconary.c \
libselinux/src/fsetfilecon.c \
libselinux/src/get_context_list.c \
libselinux/src/get_default_type.c \
libselinux/src/get_initial_context.c \
libselinux/src/getenforce.c \
libselinux/src/getfilecon.c \
libselinux/src/getpeercon.c \
libselinux/src/init.c \
libselinux/src/is_customizable_type.c \
libselinux/src/label.c \
libselinux/src/label_backends_android.c \
libselinux/src/label_db.c \
libselinux/src/label_file.c \
libselinux/src/label_media.c \
libselinux/src/label_support.c \
libselinux/src/label_x.c \
libselinux/src/lgetfilecon.c \
libselinux/src/load_policy.c \
libselinux/src/lsetfilecon.c \
libselinux/src/mapping.c \
libselinux/src/matchmediacon.c \
libselinux/src/matchpathcon.c \
libselinux/src/policyvers.c \
libselinux/src/procattr.c \
libselinux/src/query_user_context.c \
libselinux/src/regex.c \
libselinux/src/selinux_check_securetty_context.c \
libselinux/src/selinux_config.c \
libselinux/src/selinux_restorecon.c \
libselinux/src/sestatus.c \
libselinux/src/setenforce.c \
libselinux/src/setexecfilecon.c \
libselinux/src/setfilecon.c \
libselinux/src/setrans_client.c \
libselinux/src/seusers.c \
libselinux/src/sha1.c \
libselinux/src/stringrep.c
libselinux_android_srcs := \
libselinux/src/android/android.c \
libselinux/src/android/android_host.c \
common_src_files := \
libsepol/src/assertion.c \
libsepol/src/avrule_block.c \
libsepol/src/avtab.c \
libsepol/src/boolean_record.c \
libsepol/src/booleans.c \
libsepol/src/conditional.c \
libsepol/src/constraint.c \
libsepol/src/context.c \
libsepol/src/context_record.c \
libsepol/src/debug.c \
libsepol/src/ebitmap.c \
libsepol/src/expand.c \
libsepol/src/genbools.c \
libsepol/src/genusers.c \
libsepol/src/handle.c \
libsepol/src/hashtab.c \
libsepol/src/hierarchy.c \
libsepol/src/ibendport_record.c \
libsepol/src/ibendports.c \
libsepol/src/ibpkey_record.c \
libsepol/src/ibpkeys.c \
libsepol/src/iface_record.c \
libsepol/src/interfaces.c \
libsepol/src/kernel_to_cil.c \
libsepol/src/kernel_to_common.c \
libsepol/src/kernel_to_conf.c \
libsepol/src/link.c \
libsepol/src/mls.c \
libsepol/src/module.c \
libsepol/src/module_to_cil.c \
libsepol/src/node_record.c \
libsepol/src/nodes.c \
libsepol/src/polcaps.c \
libsepol/src/policydb.c \
libsepol/src/policydb_convert.c \
libsepol/src/policydb_public.c \
libsepol/src/port_record.c \
libsepol/src/ports.c \
libsepol/src/roles.c \
libsepol/src/services.c \
libsepol/src/sidtab.c \
libsepol/src/symtab.c \
libsepol/src/user_record.c \
libsepol/src/users.c \
libsepol/src/util.c \
libsepol/src/write.c
cil_src_files := \
libsepol/cil/src/cil_binary.c \
libsepol/cil/src/cil_build_ast.c \
libsepol/cil/src/cil.c \
libsepol/cil/src/cil_copy_ast.c \
libsepol/cil/src/cil_find.c \
libsepol/cil/src/cil_fqn.c \
libsepol/cil/src/cil_list.c \
libsepol/cil/src/cil_log.c \
libsepol/cil/src/cil_mem.c \
libsepol/cil/src/cil_parser.c \
libsepol/cil/src/cil_policy.c \
libsepol/cil/src/cil_post.c \
libsepol/cil/src/cil_reset_ast.c \
libsepol/cil/src/cil_resolve_ast.c \
libsepol/cil/src/cil_stack.c \
libsepol/cil/src/cil_strpool.c \
libsepol/cil/src/cil_symtab.c \
libsepol/cil/src/cil_tree.c \
libsepol/cil/src/cil_verify.c
libpcre2_src_files := \
pcre/dist2/src/pcre2_auto_possess.c \
pcre/dist2/src/pcre2_compile.c \
pcre/dist2/src/pcre2_config.c \
pcre/dist2/src/pcre2_context.c \
pcre/dist2/src/pcre2_dfa_match.c \
pcre/dist2/src/pcre2_error.c \
pcre/dist2/src/pcre2_find_bracket.c \
pcre/dist2/src/pcre2_maketables.c \
pcre/dist2/src/pcre2_match.c \
pcre/dist2/src/pcre2_match_data.c \
pcre/dist2/src/pcre2_jit_compile.c \
pcre/dist2/src/pcre2_newline.c \
pcre/dist2/src/pcre2_ord2utf.c \
pcre/dist2/src/pcre2_pattern_info.c \
pcre/dist2/src/pcre2_serialize.c \
pcre/dist2/src/pcre2_string_utils.c \
pcre/dist2/src/pcre2_study.c \
pcre/dist2/src/pcre2_substitute.c \
pcre/dist2/src/pcre2_substring.c \
pcre/dist2/src/pcre2_tables.c \
pcre/dist2/src/pcre2_ucd.c \
pcre/dist2/src/pcre2_valid_utf.c \
pcre/dist2/src/pcre2_xclass.c \
pcre/dist2/src/pcre2_chartables.c
common_cflags := \
-Wall -W -Wundef \
-Wshadow -Wmissing-noreturn \
-Wmissing-format-attribute \
-std=gnu99 -O2 -fpic -fPIC \
-pipe -fno-strict-aliasing \
-D_GNU_SOURCE \
-D__BIONIC__ -DANDROID \
-D__ANDROID__
common_ldlibs := \
-lc
common_includes := \
include \
checkpolicy/ \
libsepol/include/ \
libsepol/src/ \
libsepol/cil/include/ \
libsepol/cil/src/ \
pcre/dist2 \
pcre/include_internal \
pcre/include \
libpcre/dist \
libselinux/src \
libsepol/include/sepol \
libselinux/include \
libselinux/include/selinux \
/usr/include/python2.7 \
/usr/include/python3.* \
/usr/local/include
yacc_flags := -x c -std=gnu89
FIND_HOSTOS := $(shell uname -s)
HOST_NAME := $(shell echo $(FIND_HOSTOS) |sed -e s/L/l/ |sed -e s/D/d/ |sed s/W/w/ )
mkdir-android := $(shell mkdir -vp $(addprefix $(LOCAL_PATH)/libselinux/src/, android))
mkdir-include := $(shell mkdir -vp $(addprefix $(LOCAL_PATH)/include/, openssl private packagelistparser))
get-openssl := $(shell wget -qO - "https://android.googlesource.com/platform/external/boringssl/+archive/master/src/include/openssl.tar.gz" -O - | tar -xz -C include/openssl)
get-private := $(shell wget -qO - "https://android.googlesource.com/platform/system/core/+archive/master/libcutils/include/private.tar.gz" -O - | tar -xz -C include/private)
get-log := $(shell wget -qO - "https://android.googlesource.com/platform/system/core/+archive/master/liblog/include.tar.gz" -O - | tar -xz -C include)
ifeq ($(HOST_NAME),darwin)
cmds := \
$(shell wget -qO - "https://android.googlesource.com/platform/external/selinux/+/master/libselinux/include/selinux/android.h?format=text" | \
base64 -D > libselinux/include/selinux/android.h) \
$(shell wget -qO - "https://android.googlesource.com/platform/external/selinux/+/master/libselinux/src/android/android.c?format=text" | \
base64 -D > libselinux/src/android/android.c) \
$(shell wget -qO - "https://android.googlesource.com/platform/external/selinux/+/master/libselinux/src/android/android_host.c?format=text" | \
base64 -D > libselinux/src/android/android_host.c) \
$(shell wget -qO - "https://android.googlesource.com/platform/system/core/+/master/libpackagelistparser/include/packagelistparser/packagelistparser.h?format=text" | \
base64 -D > include/packagelistparser/packagelistparser.h)
else
cmds := \
$(shell wget -qO - "https://android.googlesource.com/platform/external/selinux/+/master/libselinux/include/selinux/android.h?format=text" | \
base64 -d > libselinux/include/selinux/android.h) \
$(shell wget -qO - "https://android.googlesource.com/platform/external/selinux/+/master/libselinux/src/android/android.c?format=text" | \
base64 -d > libselinux/src/android/android.c) \
$(shell wget -qO - "https://android.googlesource.com/platform/external/selinux/+/master/libselinux/src/android/android_host.c?format=text" | \
base64 -d > libselinux/src/android/android_host.c) \
$(shell wget -qO - "https://android.googlesource.com/platform/system/core/+/master/libpackagelistparser/include/packagelistparser/packagelistparser.h?format=text" | \
base64 -d > include/packagelistparser/packagelistparser.h)
endif
libselinux_prepare := $(mkdir-android) $(mkdir-include) $(get-openssl) $(get-private) $(get-log) $(cmds)
checkpolicy_prepare := \
$(shell flex -o checkpolicy/lex.yy.c -l checkpolicy/policy_scan.l) \
$(shell yacc -vd checkpolicy/policy_parse.y -o checkpolicy/y.tab.c) \
$(shell bison -vd checkpolicy/policy_parse.y --defines=checkpolicy/policy_parse.h -o checkpolicy/policy_parse.c)
##
# libpcre2.a
#
include $(CLEAR_VARS)
LOCAL_MODULE := libpcre2
LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_SRC_FILES := $(libpcre2_src_files)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
include $(BUILD_STATIC_LIBRARY)
##
# cil_lexer.a
#
include $(CLEAR_VARS)
LOCAL_MODULE := cil_lexer
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_CFLAGS := $(yacc_flags) $(common_cflags)
LOCAL_SRC_FILES := libsepol/cil/src/cil_lexer.l
include $(BUILD_STATIC_LIBRARY)
##
# libsepol.a
#
include $(CLEAR_VARS)
LOCAL_MODULE := libsepol
LOCAL_MODULE_TAGES := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_CFLAGS := $(common_cflags)
LOCAL_SRC_FILES := $(common_src_files)
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
include $(BUILD_STATIC_LIBRARY)
##
# chkcon
#
include $(CLEAR_VARS)
LOCAL_MODULE := chkcon
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_CFLAGS := $(common_cflags)
LOCAL_SRC_FILES := libsepol/utils/chkcon.c
LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_MODULE_CLASS := EXECUTABLES
include $(BUILD_EXECUTABLE)
##
# libselinux_static
#
include $(CLEAR_VARS)
LOCAL_MODULE := libselinux_static
LOCAL_MODULE_TAGS := optional
LOCAL_WHOLE_STATIC_LIBRARIES := libpcre2
LOCAL_CFLAGS := -std=gnu89 -DAUDITD_LOG_TAG=1003 -DUSE_PCRE2 $(common_cflags)
LOCAL_STATIC_LIBRARIES := libpcre2
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_SRC_FILES := $(libselinux_prepare) $(libselinux_src_files) $(libselinux_android_srcs)
include $(BUILD_STATIC_LIBRARY)
##
# sefcontext_compile
#
include $(CLEAR_VARS)
LOCAL_MODULE := sefcontext_compile
LOCAL_CFLAGS += -Wall -Werror -DUSE_PCRE2 -DNO_PERSISTENTLY_STORED_PATTERNS $(common_cflags)
LOCAL_STATIC_LIBRARIES := libselinux_static libpcre2 libsepol
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_SRC_FILES := libselinux/utils/sefcontext_compile.c
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
##
# getfilecon
#
include $(CLEAR_VARS)
LOCAL_MODULE := getfilecon
LOCAL_CFLAGS += -Wall -Werror -DUSE_PCRE2 -DNO_PERSISTENTLY_STORED_PATTERNS $(common_cflags)
LOCAL_STATIC_LIBRARIES := libselinux_static libpcre2 libsepol
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_SRC_FILES := libselinux/utils/getfilecon.c
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
##
# setfilecon
#
include $(CLEAR_VARS)
LOCAL_MODULE := setfilecon
LOCAL_CFLAGS += -Wall -Werror -DUSE_PCRE2 -DNO_PERSISTENTLY_STORED_PATTERNS $(common_cflags)
LOCAL_STATIC_LIBRARIES := libselinux_static libpcre2 libsepol
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_SRC_FILES := libselinux/utils/setfilecon.c
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
##
# checkpolicy
#
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(checkpolicy_prepare) \
checkpolicy/lex.yy.c \
checkpolicy/y.tab.c \
checkpolicy/checkpolicy.c \
checkpolicy/module_compiler.c \
checkpolicy/parse_util.c \
checkpolicy/policy_define.c \
checkpolicy/queue.c
LOCAL_MODULE := checkpolicy
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_CFLAGS := $(yacc_flags) $(common_cflags)
LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_CFLAGS += -std=gnu99 -fpic -fPIC
LOCAL_YACCFLAGS := -v
include $(BUILD_EXECUTABLE)
##
# checkmodule
#
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(checkpolicy_prepare) \
checkpolicy/lex.yy.c \
checkpolicy/y.tab.c \
checkpolicy/checkmodule.c \
checkpolicy/module_compiler.c \
checkpolicy/parse_util.c \
checkpolicy/policy_define.c \
checkpolicy/queue.c
LOCAL_MODULE := checkmodule
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_CFLAGS := $(yacc_flags) $(common_cflags)
LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_CFLAGS += -std=gnu99 -fpic -fPIC
LOCAL_YACCFLAGS := -v
include $(BUILD_EXECUTABLE)
##
# dispol
#
include $(CLEAR_VARS)
LOCAL_MODULE := dispol
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_SRC_FILES := checkpolicy/test/dispol.c
LOCAL_CFLAGS := $(yacc_flags) $(common_cflags)
LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_CFLAGS += -std=gnu99 -fpic -fPIC
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
##
# dismod
#
include $(CLEAR_VARS)
LOCAL_MODULE := dismod
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_SRC_FILES := checkpolicy/test/dismod.c
LOCAL_CFLAGS := $(yacc_flags) $(common_cflags)
LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_CFLAGS += -std=gnu99 -fpic -fPIC
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
theres a submodule for libpcre2 so you'll have to use git clone --recursive, AKA
git clone --recursive https://github.com/Surge1223/selinux.git selinux-master
or ideally, just clone SELinux master and cherry-pick the 3 commits that allow building for target devices
then building also depends on the NDK build system reading the jni/Application.mk first, before Android.mk so the NDK build command is
$NDK/ndk-build APP_PROJECT_PATH=. APPLICATION_BULID_SCRIPT=Application.mk
Click to expand...
Click to collapse
The main purpose of me posting this here is so that in the future, if it becomes necessary to create/build tools to deal with the additional restrictions on Android, this can serve as a starting point on building.
No I dont plan on posting binaries. If you're in this thread and you can't use the NDK, then you need to up your game son.
Good job @Surge1223!
Sent from my Samsung Galaxy S8+ using XDA Labs
Great work! @Surge1223
This is an interesting thread
Kudos Surge, subscribed
I compiled the Xiaomi poco M3 kernel from
https://github.com/MiCode/Xiaomi_Kernel_OpenSource
on branch
lime-q-oss
with commands
export ARCH=arm64 && export SUBARCH=arm64
export CROSS_COMPILE=/opt/aosp_prebuilts/aarch64-linux-android-4.9/bin/aarch64-linux-android-
export DTC_EXT=
make ARCH=arm64 CC=clang CLANG_TRIPLE=aarch64-linux-gnu- vendor/citrus-perf_defconfig
make ARCH=arm64 CC=clang CLANG_TRIPLE=aarch64-linux-gnu- EXTRA_CFLAGS="-I $PWD/techpack/display/pll/ -I $PWD/techpack/camera/drivers/cam_sensor_module/cam_cci/ -I $PWD/techpack/camera/drivers/cam_req_mgr -DSDCARDFS_VERSION= -I $PWD/" -j$(nproc --all)
I unpacked the original boot.img from the official ROM from the xiaomi's website, which is the exact ROM I have on my phone:
unpackbootimg -i boot.img -o boot_img_unpacked
Then I repacked with the new kernel:
mkbootimg --kernel "$SCRIPT_DIR/devices/$DEVICE/kernel/k/arch/arm64/boot/Image" \
--ramdisk boot.img-ramdisk \
--dtb boot.img-dtb \
--cmdline "$(< boot.img-cmdline)" \
--base "$(< boot.img-base)" \
--kernel_offset "$(< boot.img-kernel_offset)" \
--ramdisk_offset "$(< boot.img-ramdisk_offset)" \
--tags_offset "$(< boot.img-tags_offset)" \
--dtb_offset "$(< boot.img-dtb_offset)" \
--os_version "$(< boot.img-os_version)" \
--os_patch_level "$(< boot.img-os_patch_level)" \
--pagesize "$(< boot.img-pagesize)" \
--header_version "$(< boot.img-header_version)" \
--hashtype "$(< boot.img-hashtype)" \
--board "$(< boot.img-board)" \
--ramdisk_offset "$(< boot.img-ramdisk_offset)" \
-o ../boot.img
then the phone won't boot. I repacked with the official kernel from boot.img just to see if my repacking method was working, and with the original kernel, it boots. So the problem is probably on the kernel.
Do I have to update some offset? Like, is the dtb offset the same in this kernel as in the official one? I don't know why the dtb offset since the dtb is also in the ramdisk. How do I know if the dtb is being picked from inside the kernel or from the ramdisk?
One thing to notice is that my phone is on Android 11, which uses 4.19.113 while my kernel is 4.19.95 (the latest available on xiaomi's website), which I think was meant for Android 10. However, I think I should at least boot, even if with an older kernel. At least see some error.
I tried fastboot oem enable uart but this option is not supported by the Poco M3, so I guess there's no way to debug over usb like in the Pixel phones. Is there any way to know what's happening? I found some methods for debugging but they all require a kernel that at least boots, but I don't even know if mine is booting. Maybe it is but can't start any graphics?
I made a docker container that facilitates downloading, hacking the kernel and etc: https://github.com/lucaszanella/and...tree/18fbd933094f8ad6e63e65b2795ce80c377f8dc6 so if anyone wants to try, I'd be really glad. I'm working on tutorials to bring more people to kernel hacking, that's why I bought the Poco M3.
I run linux ok based on qemu + kvm.I test many Linux distribution(ubuntu、rocky、anolios、opensuse),All of them run ok。
But when I run windows(I tried many different versions of window arm64 version),it will appear BOSD before enter installation UI,I'll appreciate it if anyone can help me
below is my command to start windows
taskset f /data/data/com.termux/files/usr/bin/qemu-system-aarch64 \
-M virt \
-vnc 127.0.0.1:1 -monitor vc \
-cpu host \
-enable-kvm \
-m 10G \
-bios QEMU_EFI.fd \
-device VGA \
-device nec-usb-xhci \
-device usb-kbd \
-device usb-mouse \
-cdrom 22478.1000.211008-1414.RS_PRERELEASE_CLIENTMULTI_A64FRE_ZH-CN.ISO \
-device usb-storage,drive=drivers \
-drive if=none,id=drivers,readonly=on,file=Drivers.vhdx \
-device virtio-blk,drive=system \
-drive if=none,id=system,format=qcow2,file=win10.qcow2 \
-boot order=cd \
-serial stdio
Click to expand...
Click to collapse
below is my bsod
KVM (Kernel Virtual Machine) on Samsung Galaxy A6 (Exynos 7870)
I have an Galaxy A6 which has the Exynos 7870 CPU. I downloaded the kernel source from the Samsung source page, and when I typed make menuconfig it has the Virtualization option. So does that mean the CPU itself support KVM? Thanks! I just...
forum.xda-developers.com
my kernel version is 4.14.186+
my chip is MTK MT6891