[TUTS/DEVELOPMENT] Kernel Development - Samsung Galaxy 5 I5500

Kernel Development Tutorials​
Important Links:
Ubuntu - http://www.ubuntu.com/download/ubuntu/download
Sourcery G++ Lite 2011.03-42 for ARM EABI - http://www.codesourcery.com/sgpp/lite/arm/portal/release1802
Stock Samsung Source - https://github.com/dharamg3/kernel_stock_g3 OR https://opensource.samsung.com/
Github for the Tutorials - https://github.com/dharamg3/g3_tuts
Source of Other Kernels to Compare:
G3MOD - Galaxy 3 - https://github.com/dharamg3/G3MOD
FuguMod - Galaxy 3 - https://github.com/sdadier/froyo
I will explain everything Step by Step.
If you got time to learn/develop join in.
If you get some step working and a fellow developer cant get it, please help each other by answering everyone's doubts.I cant reply to each and every query always.
Most of the code is to be run in the terminal. So I wont be mentioning to Open terminal every time.
I would like to thank marcellusbe who was the first one to make a proper custom Kernel for G3, who taught me how to build a kernel, and also lot of other help.
Note:
Please do not post useless messages.
If you dont know coding, please learn that first.
Do not flood my inbox with PM's. I will not respond to PM's regarding Kernel Development. Please post in the thread.
[*]I AM NOT RESPONSIBLE IF YOU HARDBRICK YOUR PHONE, DOING ANY OF THE FOLLOWING STEPS

Install Ubuntu(x86/x64)​
1. Install a virtual machine software.(VMware/Virtualbox)
2. Create a new Virtual Machine.
3. Use Ubuntu ISO to install. Download from here - http://www.ubuntu.com/download/ubuntu/download - I use Ubuntu 10.10 x86
4. Allocate enough space for the Virtual machine as the source is itself around 500mb for Kernel. And if you are like me, then you will want to keep backups at each stage.
5. Recommended RAM is 1GB.
6. Let Ubuntu be installed (VMware and Virtualbox have Easy Install which installs Ubuntu itself)
Logging In As Root​
1. When Ubuntu first boots, login with the username and password you mentioned while installing.
2. Open Terminal
3. Use following command.(Always the code after $/# is the one to be used. The one before that just specifies [email protected]:~)
## Anything after ## is a comment by me.
Code:
[email protected]:~$ sudo passwd
[sudo] password for dharammaniar: ## Enter password which you used to login.
Enter new UNIX password: ## Enter Password for root(it can be same as your prev password)
Retype new UNIX password: ## Re-Enter Password for root
passwd: password updated successfully
[email protected]:~$ su
Password: ## Enter the root password
[email protected]:/home/dharammaniar#
4. Once you get the last line as above means you now have root access.
5. Now logout from this user and login with username as root
6. On starting Terminal now, you should get
Code:
[email protected]:~#
Setting Up Build Environment​
1. You should always be running as root.
2. Go To System->Administration->Synaptic Package Manager
3. Search for ncurses-devel
4. Install libncurses5-dev.
5. Go to http://www.codesourcery.com/sgpp/lite/arm/portal/release1802
6. Download IA32 GNU/Linux Installer. Keep the arm-2011.03-42-arm-none-eabi.bin file on the desktop.(I like to keep everything on the desktop for faster access)
7. Run code and select NO
Code:
dpkg-reconfigure -plow dash
8. Run Installer using code
Code:
apt-get install ia32-libs ## FOR THOSE WHO HAVE x64 Ubuntu installed
/bin/sh /root/Desktop/arm-2011.03-42-arm-none-eabi.bin ## THANKS TO cdesai for the tip :)
9. Do the usual Next Next Next Next.Dont change any paths.Install as typical.
10. Wait till it is installing
11. Wait more
12. Still waiting
13. Again Next -> Done.
14. You now have the development environment ready.
Downloading Sources​
1. Download Samsung Source from https://opensource.samsung.com/ or https://github.com/dharamg3/kernel_stock_g3
2. If you download from https://opensource.samsung.com/ then you will not have the initramfs.
3. To get stock initramfs, you need to extract it from one of the stock kernel(I will explain it later).

Extracting initramfs from zImage​Based on script from mizch - http://forum.xda-developers.com/showthread.php?t=901152​
Download Files from the attachments.
1. Extract files from initramfs-utils.zip to /bin/
2. Make a folder on the Desktop named unpack.
3. Extract the repack-zImage.sh file from repack-zImage.v6.zip in the unpack folder on Desktop.
4. Add your zImage from which you want to extract initramfs in the unpack folder.
5. Run Command
Code:
cd /root/Desktop/unpack
sh repack-zImage.sh -u
6. You will get the unpacked zImage in the same folder which will contain the initramfs folder also.
Note: To make things simple, i use a script to unpack.
Download from attachment.
Add this unpack.sh file to your unpack folder and run it by double clicking
Building Kernel​
1. Download Source as mentioned in the above tutorial.
2. Create a folder on the Desktop. I have named it g3.
3. Add initramfs folder and Kernel folder in that folder.
4. Run Code to make initramfs.cpio
Code:
cd initramfs
find . -print0 | cpio --null -ov --format=newc > ../initramfs.cpio
5. You can also use the script named initramfs.sh from attachments. Copy it to the g3 folder and run it by double clicking.
6. By doing step 4 or 5 you will get initramfs.cpio in the g3 folder.
7. Next you need to do is modify the makefile in Kernel folder.
Original is
Code:
ARCH := arm
CROSS_COMPILE := /opt/toolchains/arm-2009q3/bin/arm-none-linux-gnueabi-
Change to
Code:
ARCH := arm
CROSS_COMPILE := /root/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-
8. Now you need the configuration file.
9. Copy the apollo_rev_02_android_defconfig file from /Kernel/arch/arm/configs to /Kernel/
10. Rename it to .config (Note: It should be only .config and not apollo_rev_02_android_defconfig.config)
11. Now in Terminal run the following code.
Code:
cd /root/Desktop/g3/Kernel
make menuconfig
12. You will get a GUI menu.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
13. Go to General Setup
14. Next go to Initramfs source file(s)
15. Press Enter and give path as
Code:
../initramfs.cpio
16. Exit from menuconfig
17. Enter Code
Code:
make
OR
Code:
make -j4 ## THIS ONE ONLY IF YOU GOT A GOOD CPU THAT SUPPORTS MULTI-THREADING :)
18. Building will start. There will be many warnings. Ignore them.
19. After building is finished, you will get zImage at /Kernel/arch/arm/boot/
20. Add this zImage to a test.tar(attachment) using Total Commander.
21. Flash as One Package in Odin.
22. Enjoy
Note: This is the stock kernel and supports only rfs filesystem. So before flashing it, please change filesystem to rfs and then flash.

Kernel Basics​
The Kernel is basically divided into 2 parts.
The Kernel and the initramfs.Those are the two folders in your g3folder.
initramfs
initramfs is a root filesystem which is embedded into the kernel and loaded at an early stage of the boot process. It is the successor of initrd. It provides early userspace which lets you do things that the kernel can't easily do by itself during the boot process.

GIT Commits​
I will commit my source every time i make a tutorial. You can check out all the commits on my github for the tutorials - https://github.com/dharamg3/g3_tuts
Fixed Sound Click Bug During Calls - https://github.com/dharamg3/g3_tuts/commit/2f623a5fb88062deb5dbc7d8d1040c05f43b3d91
1% Battery MOD - https://github.com/dharamg3/g3_tuts/commit/f5259a58f14351ccffee49e9fc235b9670369b90
Voodoo Sound v10 - https://github.com/dharamg3/g3_tuts/commit/0bb0f9a538fdb59138e0bcc957d33aa15fd39155
ADB Root and BusyBox - https://github.com/dharamg3/g3_tuts/commit/57424d6a122e6ff219165fd718de8555029a1079
FileSystem Support - https://github.com/dharamg3/g3_tuts/commit/5db762b1402f7775af4ef7da395d5c9d0b99ed0f

Kernel Modding - Part 1​
PLEASE DONT ASK HOW OR WHY ANY PART IS DONE. I WILL EXPLAIN ALL THAT I KNOW. BUT SOME PART OF THIS HAS BEEN DONE BY TRIAL AND ERROR METHOD, WHEREAS SOME PART MAYBE OUT OF MY SCOPE OF KNOWLEDGE.
Removing The Sound Click Bug During Calls
We all know that this is the most basic bug found out in the Kernel of Samsung. The clicking sound we get during calls. Many of you may complain that this bug is solved in the newer ROM's, but remember we are building from the original Samsung Source, which is modified in the newer kernel's. We dont have those modifications so here it goes, the Sound Click Bug.
We to find out this bug you need to check the dmesg when you are in a call.
It shows you that there is some sound routing done during the call. So you know that this is something related to the sound driver.
Now the sound driver for Galaxy 3 is the wm8994 driver, which is present at Kernel/sound/soc/codecs/
So the changes to be made are in the file wm8994.c
In the function static int wm8994_resume(struct platform_device *pdev)
Originally the code was
Code:
if (wm8994_power == 0) {
audio_power(1); /* Board Specific function */
wm8994_power = 1;
}
wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
wm8994_enable_path(codec, wm8994_curr_path);
After editing the code is
Code:
if (wm8994_power == 0) {
audio_power(1); /* Board Specific function */
wm8994_power = 1;
wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
wm8994_enable_path(codec, wm8994_curr_path);
}
1% Battery MOD
The battery driver for galaxy 3 is found at Kernel/drivers/power/
The file to be added is s5p6442_battery.c
The Samsung battery driver originally divides battery in the following Steps:
100,90,80,70,60,50,40,30,20,15,5,3,1
If you look at the source code, you should be able to find that out easily.
We need to make it return each value in between also so that we get the 1% MOD that is required.
So now, the original code was
Code:
if (bat_vol > batt_full)
{
int temp = (batt_max - batt_full);
if (bat_vol > (batt_full + temp) ||
s3c_bat_info.bat_info.batt_is_full)
bat_level = 100;
else
bat_level = 90;
#ifdef __CHECK_CHG_CURRENT__
if (s3c_bat_info.bat_info.charging_enabled) {
check_chg_current(bat_ps);
if (!s3c_bat_info.bat_info.batt_is_full)
bat_level = 90;
}
#endif /* __CHECK_CHG_CURRENT__ */
dev_dbg(dev, "%s: (full)level = %d\n", __func__, bat_level );
}
else if (batt_full >= bat_vol && bat_vol > batt_almost)
{
int temp = (batt_full - batt_almost) / 2;
if (bat_vol > (batt_almost + 86))
bat_level = 80;
else
bat_level = 70;
dev_dbg(dev, "%s: (almost)level = %d\n", __func__, bat_level);
}
else if (batt_almost >= bat_vol && bat_vol > batt_high)
{
int temp = (batt_almost - batt_high) / 2;
if (bat_vol > (batt_high + 62))
bat_level = 60;
else
bat_level = 50;
dev_dbg(dev, "%s: (high)level = %d\n", __func__, bat_level );
}
else if (batt_high >= bat_vol && bat_vol > batt_medium)
{
int temp = (batt_high - batt_medium) / 2;
if (bat_vol > (batt_medium + 26))
bat_level = 40;
else
bat_level = 30;
dev_dbg(dev, "%s: (med)level = %d\n", __func__, bat_level);
}
else if (batt_medium >= bat_vol && bat_vol > batt_low)
{
int temp = (batt_medium - batt_low) / 2;
if (bat_vol > (batt_low + 50))
bat_level = 20;
else
bat_level = 15;
dev_dbg(dev, "%s: (low)level = %d\n", __func__, bat_level);
}
else if (batt_low >= bat_vol && bat_vol > batt_critical)
{
bat_level = 5;
dev_dbg(dev, "%s: (cri)level = %d, vol = %d\n", __func__,
bat_level, bat_vol);
}
else if (batt_critical >= bat_vol && bat_vol > batt_min)
{
bat_level = 3;
dev_info(dev, "%s: (min)level = %d, vol = %d\n", __func__,
bat_level, bat_vol);
}
else if (batt_min >= bat_vol && bat_vol > batt_off)
{
bat_level = 1;
dev_info(dev, "%s: (off)level = %d, vol = %d\n", __func__,
bat_level, bat_vol);
}
else if (batt_off >= bat_vol)
{
bat_level = 0;
dev_info(dev, "%s: (off)level = %d, vol = %d", __func__,
bat_level, bat_vol);
}
We need to edit it to make
Code:
if (bat_vol > batt_full)
{
int temp = (batt_max - batt_full);
if (bat_vol > (batt_full + temp) ||
s3c_bat_info.bat_info.batt_is_full)
bat_level = 100;
else
{
bat_level = 90 + (((bat_vol - batt_full) *10) / temp);
}
#ifdef __CHECK_CHG_CURRENT__
if (s3c_bat_info.bat_info.charging_enabled) {
check_chg_current(bat_ps);
if (!s3c_bat_info.bat_info.batt_is_full)
bat_level = 90;
}
#endif /* __CHECK_CHG_CURRENT__ */
dev_dbg(dev, "%s: (full)level = %d\n", __func__, bat_level );
}
else if (batt_full >= bat_vol && bat_vol > batt_almost)
{
int temp = (batt_full - batt_almost) / 2;
bat_level = 70 + (((bat_vol - batt_almost) *10) / temp);
dev_dbg(dev, "%s: (almost)level = %d\n", __func__, bat_level);
}
else if (batt_almost >= bat_vol && bat_vol > batt_high)
{
int temp = (batt_almost - batt_high) / 2;
bat_level = 50 + (((bat_vol - batt_high) *10) / temp);
dev_dbg(dev, "%s: (high)level = %d\n", __func__, bat_level );
}
else if (batt_high >= bat_vol && bat_vol > batt_medium)
{
int temp = (batt_high - batt_medium) / 2;
bat_level = 30 + (((bat_vol - batt_medium) *10) / temp);
dev_dbg(dev, "%s: (med)level = %d\n", __func__, bat_level);
}
else if (batt_medium >= bat_vol && bat_vol > batt_low)
{
int temp = (batt_medium - batt_low) / 2;
bat_level = 15 + ((( bat_vol - batt_low) *5) / temp);
dev_dbg(dev, "%s: (low)level = %d\n", __func__, bat_level);
}
else if (batt_low >= bat_vol && bat_vol > batt_critical)
{
bat_level = 5;
dev_dbg(dev, "%s: (cri)level = %d, vol = %d\n", __func__,
bat_level, bat_vol);
}
else if (batt_critical >= bat_vol && bat_vol > batt_min)
{
bat_level = 3;
dev_info(dev, "%s: (min)level = %d, vol = %d\n", __func__,
bat_level, bat_vol);
}
else if (batt_min >= bat_vol && bat_vol > batt_off)
{
bat_level = 1;
dev_info(dev, "%s: (off)level = %d, vol = %d\n", __func__,
bat_level, bat_vol);
}
else if (batt_off >= bat_vol)
{
bat_level = 0;
dev_info(dev, "%s: (off)level = %d, vol = %d", __func__,
bat_level, bat_vol);
}
and also we need to change the Total ADC count
Originally
Code:
#define ADC_TOTAL_COUNT 20
Change it to
Code:
#define ADC_TOTAL_COUNT 100
Voodoo Sound Driver
The Sound Driver for Galaxy 3 is the wm8994 Wolfson Microelectronics Codec.
The WM8994 is a highly integrated ultra-low power hi-fi CODEC designed for smartphones and other portable devices rich in multimedia features.
Features
Hi-Fi 24-bit 4-channel DAC and 2-channel ADC
100dB SNR during stereo DAC playback (‘A’ weighted)
Smart MIC interface
- Power, clocking and data input for up to four digital MICs
- High performance analogue MIC interface
- MIC activity monitor & interrupt allows processor to sleep
1W stereo / 2W mono class D/AB speaker driver
Capless class W headphone drivers
- Integrated charge pump
- 6mW total power for DAC playback to headphones
4 line outputs (single-ended or differential)
BTL earpiece driver
Digital audio interfaces for multi-processor architecture
- Asynchronous stereo duplex sample rate conversion
- Powerful mixing and digital loopback functions
ReTune™ Mobile 5-band, 6-channel parametric EQ
Programmable dynamic range controller
Dual FLL provides all necessary clocks
- Self-clocking modes allows processor to sleep
- All standard sample rates from 8kHz to 96kHz
Active noise reduction circuits
- DC offset correction removes pops and clicks
- Ground loop noise cancellation
Integrated LDO regulators
72-ball W-CSP package (4.511mm x 4.023mm x 0.7mm)
The Voodoo Driver is developed by supercurio.
The changes to be made for the voodoo driver are at sound/soc/codec/
The Changes are as the following Commit. (Please ignore the /Kernel/scripts part....I forgot to do a make clean -i before commiting )
RootADB and BusyBox
Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components:
A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
A daemon, which runs as a background process on each emulator or device instance.
You can find the adb tool in <sdk>/platform-tools/.
RootADB gives you root access while performing adb functions.
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system.
BusyBox has been written with size-optimization and limited resources in mind. It is also extremely modular so you can easily include or exclude commands (or features) at compile time. This makes it easy to customize your embedded systems. To create a working system, just add some device nodes in /dev, a few configuration files in /etc, and a Linux kernel.
The Changes to be made for these are in the initramfs.
These can be found in this Commit.

Kernel Modding - Part 2​
PLEASE DONT ASK HOW OR WHY ANY PART IS DONE. I WILL EXPLAIN ALL THAT I KNOW. BUT SOME PART OF THIS HAS BEEN DONE BY TRIAL AND ERROR METHOD, WHEREAS SOME PART MAYBE OUT OF MY SCOPE OF KNOWLEDGE.
File System Support: rfs/ext2/ext3/ext4
RFS
SAMSUNG RFS (Robust File System) is an embedded flash file system that uses SAMSUNG OneNAND flash memory as storage on any consumer electronic devices.
SAMSUNG RFS runs in the Linux kernel and is fully compatible with FAT file system standards (FAT16/32).
EXT2
http://en.wikipedia.org/wiki/Ext2
EXT3
http://en.wikipedia.org/wiki/Ext3
EXT4
http://en.wikipedia.org/wiki/Ext4
[DEV] Debate: ext2 vs ext3 vs ext4 : http://forum.xda-developers.com/showthread.php?t=800353
[REF] Information About Filesystems : http://forum.xda-developers.com/showthread.php?t=1058095
The changes to be done are as in the commit.

Reserved

Reserved

Reserved

Too many reserved post as usual (all you need is one post to explain all )
Anyways I'll make videos on this soon..
all the users need to know is to install Ubuntu by themself.. everything else will be covered in the video.

well, i intend to add everything here...including where to mod, which code and stuff...

nice to see your post.... XD
dharam can you post some information about overlocking and undervolt?i need it indeed

dxdiag32 said:
nice to see your post.... XD
dharam can you post some information about overlocking and undervolt?i need it indeed
Click to expand...
Click to collapse
everything will come in time...

Thks man, i have never known how to make a kernal before
Sent from my GT-I5801 using XDA App

I hav one question. This tutorial wil b in general or this is specifically for g3?

rudolf895 said:
Too many reserved post as usual (all you need is one post to explain all )
Anyways I'll make videos on this soon..
all the users need to know is to install Ubuntu by themself.. everything else will be covered in the video.
Click to expand...
Click to collapse
the big advantage of having multiple posts reserved is that you can have som kind of directory on the first post linking to the sections in the other posts, this is of big use in a massive theme like kernel development. also i do not see why nobody does this here as of now, always they reserve multiple posts and nobody links them in first post, what makes the use of them obsolete...

vikraam said:
I hav one question. This tutorial wil b in general or this is specifically for g3?
Click to expand...
Click to collapse
well, specifically for g3...the basic steps are same for all phones, but the code and stuff will be more specific for g3...

dharamg3 said:
well, specifically for g3...the basic steps are same for all phones, but the code and stuff will be more specific for g3...
Click to expand...
Click to collapse
I wud like to thank u a million times. Thanq very very much

Hey first a great Karnel now How to make one!!! good going!!! Thanks Mate

Related

[Q] {Q} How can I unpack Boot.img

I want to unpack a Boot.img file to have a look at the Kernel coding. I have been at Google-ing this for about an hour and need some help. I am using windows but could use Ubuntu if need be.
Help would be much appreciated!!!
first of all by unpacking boot.img you won't see actual kernel coding.. it will merely 0.05% give you some idea about coding stuff here..
ketut released some tools which you can find in his kernel thread [not cf-root thread]..
if you wan't code then you will have to download kernel sources from github or samsung site.. and play at own risks
Okay, it looks like I am going to install Ubuntu. I was just hoping there was some way to do it within Windows without running a V.M. or Dual boot.
yes there are two ways of installing it with wubi installer to install within windows.. and one creating separate partition of ext4 to dual boot..
wubi installer seems to be what you are looking for
I am currently looking here https://github.com/ilarrain/kernel_galaxyace/blob/gingerbread/arch/arm/mach-msm/acpuclock.c and trying to understand the references to the frequency table. I want to understand why the table goes to 1036800 (like the CM7 Kernel) but is limited to 902400. It would help if I had the CM7 Kernel source for reference. Do you know where that can be found?
I am pretty sure this is what I need to be looking at:
#ifdef CONFIG_CPU_FREQ_MSM
static struct cpufreq_frequency_table freq_table[20];
static void __init cpufreq_table_init(void)
{
unsigned int i;
unsigned int freq_cnt = 0;
/* Construct the freq_table table from acpu_freq_tbl since the
* freq_table values need to match frequencies specified in
* acpu_freq_tbl and acpu_freq_tbl needs to be fixed up during init.
*/
for (i = 0; acpu_freq_tbl.a11clk_khz != 0
&& freq_cnt < ARRAY_SIZE(freq_table)-1; i++) {
if (acpu_freq_tbl.use_for_scaling) {
freq_table[freq_cnt].index = freq_cnt;
freq_table[freq_cnt].frequency
= acpu_freq_tbl.a11clk_khz;
freq_cnt++;
}
}
/* freq_table not big enough to store all usable freqs. */
BUG_ON(acpu_freq_tbl.a11clk_khz != 0);
freq_table[freq_cnt].index = freq_cnt;
freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END;
pr_info("%d scaling frequencies supported.\n", freq_cnt);
}
#endif
-SGA- said:
I am currently looking here https://github.com/ilarrain/kernel_galaxyace/blob/gingerbread/arch/arm/mach-msm/acpuclock.c and trying to understand the references to the frequency table. I want to understand why the table goes to 1036800 (like the CM7 Kernel) but is limited to 902400. It would help if I had the CM7 Kernel source for reference. Do you know where that can be found?
I am pretty sure this is what I need to be looking at:
#ifdef CONFIG_CPU_FREQ_MSM
static struct cpufreq_frequency_table freq_table[20];
static void __init cpufreq_table_init(void)
{
unsigned int i;
unsigned int freq_cnt = 0;
/* Construct the freq_table table from acpu_freq_tbl since the
* freq_table values need to match frequencies specified in
* acpu_freq_tbl and acpu_freq_tbl needs to be fixed up during init.
*/
for (i = 0; acpu_freq_tbl.a11clk_khz != 0
&& freq_cnt < ARRAY_SIZE(freq_table)-1; i++) {
if (acpu_freq_tbl.use_for_scaling) {
freq_table[freq_cnt].index = freq_cnt;
freq_table[freq_cnt].frequency
= acpu_freq_tbl.a11clk_khz;
freq_cnt++;
}
}
/* freq_table not big enough to store all usable freqs. */
BUG_ON(acpu_freq_tbl.a11clk_khz != 0);
freq_table[freq_cnt].index = freq_cnt;
freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END;
pr_info("%d scaling frequencies supported.\n", freq_cnt);
}
#endif
Click to expand...
Click to collapse
Why not cooper_initramfs ?
Herpderp Adreno + Tegra.
Well..For the history,To unpack boot.img,you need to use cygwin.Here is complete instruction on doing this thing freeyourandroid.com

Collision detection issue

New to the forums, short introduction? Hi. Next on the agenda I'd like to apologize for this not being in the development forum, but as I'm a new user I was unable to post there.
As for my issue I'm working on a game, it's very basic right now and I'm working on an editor.
(Terribly sorry about this part. Turns out I don't have privileges for image links quite yet. Hope I get there soon! )
So far for rectangles I use the Menu button -> Objects -> Rectangles; Drag and drop to create a shape, press Ok. Drawing multiple rectangles from the map array works perfectly fine, but collision is another story. The most recent object I create HAS collision, if I create a new object, the previous object loses it. e.g. I create 100 rectangles, 1st - 99th don't collide. I have coding experience, asked multiple people. All have been stumped on something that seems like it'd be simple.
The saving:
Code:
if (confirmMode && touchX > (startX + endX) / 2
&& touchX < (startX + endX) / 2 + tileSize * 20
&& touchY < (startY + endY) / 2
&& touchY > (startY + endY) / 2 - tileSize * 10) {
map.add(key, startX);
map.add(key + 1, startY);
map.add(key + 2, endX);
map.add(key + 3, endY);
key += 4;
confirmMode = rectMode = circleMode = false;
}
The reading:
Code:
while (i < key) {
canvas.drawRect(map.get(i), map.get(i + 1), map.get(i + 2),
map.get(i + 3), red);
if (playerX > map.get(i) && playerX < map.get(i + 2)
&& playerY > map.get(i + 1) && playerY < map.get(i + 3))
allowed = 0;
else
allowed = 1;
i += 4;
}
i = 0;
Love, a stranger.

[q] [help] compiling recovery

Hello guys. i have been trying to compile cwm recovery for my phone. its using msm7627a board. am using the prebuilt kernel. i succeded compiling but when i flash its not displaying anything. i tried to see whats wrong , from the recovery log i found the frame buffer /dev/graphics is not available. Everything else works i can do a backup from ROM manager, even keystrokes work..adb shell works .. just the display not working..any ideas. ????
i also realise some other devices are not loaded.
how can i make the fb0 graphics loaded or any other fix.. ???
for those who have access to the source code ..
Code:
.................................................................................part of the concerned ui code..........................................................
int gr_init(void)
{
gglInit(&gr_context);
GGLContext *gl = gr_context;
gr_init_font();
gr_vt_fd = open("/dev/tty0", O_RDWR | O_SYNC);
if (gr_vt_fd < 0) {
// This is non-fatal; post-Cupcake kernels don't have tty0.
perror("can't open /dev/tty0");
}
else
{
if (ioctl(gr_vt_fd, KDSETMODE, (void*) KD_GRAPHICS)) {
// However, if we do open tty0, we expect the ioctl to work.
perror("failed KDSETMODE to KD_GRAPHICS on tty0");
gr_exit();
return -1;
}
}
gr_fb_fd = get_framebuffer(gr_framebuffer); // this is the call that fails because it tries opening /dev/graphics/fb0 which does then exists
if (gr_fb_fd < 0) {
gr_exit();
perror("cant get framebuffer");
return -1;
}
get_memory_surface(&gr_mem_surface);
fprintf(stderr, "framebuffer: fd %d (%d x %d)\n",
gr_fb_fd, gr_framebuffer[0].width, gr_framebuffer[0].height);
/* start with 0 as front (displayed) and 1 as back (drawing) */
gr_active_fb = 0;
set_active_framebuffer(0);
gl->colorBuffer(gl, &gr_mem_surface);
gl->activeTexture(gl, 0);
gl->enable(gl, GGL_BLEND);
gl->blendFunc(gl, GGL_SRC_ALPHA, GGL_ONE_MINUS_SRC_ALPHA);
gr_fb_blank(true);
gr_fb_blank(false);
return 0;
}
............................................................code,.........................................................

How to go about patching the kernel to get EHCI(USB 2.0) devices to behave like xHCI?

Basically, there has been an app ported to Android that allows even unrooted(stock) devices to deliver a bootrom exploit to the Nintendo Switch via USB-OTG and a USB cable (or C-to-C). USB 3.0 (xHCI) devices have no issues and deliver the exploit just fine. Apparently it is not even a USB 2.0 problem but rather how the EHCI performs, as certain USB 2.0 phones actually have the xHCI controller and can run the exploit just fine. What happens is that although it can detect the connected Switch in Tegra Recovery Mode, it just doesn't do anything and gives an error in the logs, "SUMBITURB failed".
On Linux desktop systems it is similar, but the exploit can still work with a kernel patch provided by a hacking group that discovered the exploit in the first place:
Code:
--- linux-4.14.27/drivers/usb/host/ehci-hcd.c.old 2018-04-17 18:00:00.000000000 +0000
+++ linux-4.14.27/drivers/usb/host/ehci-hcd.c 2018-04-17 18:00:00.000000000 +0000
@@ -873,14 +873,6 @@
INIT_LIST_HEAD (&qtd_list);
switch (usb_pipetype (urb->pipe)) {
- case PIPE_CONTROL:
- /* qh_completions() code doesn't handle all the fault cases
- * in multi-TD control transfers. Even 1KB is rare anyway.
- */
- if (urb->transfer_buffer_length > (16 * 1024))
- return -EMSGSIZE;
- /* FALLTHROUGH */
- /* case PIPE_BULK: */
default:
if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
return -ENOMEM;
The author of the Android port had also written a Python "hotpatch" script for desktop Linux systems:
Code:
#!/usr/bin/env python3
import os
"""
Cursed Code.
This code literally patches your kernel memory, proceed at your own risk.
Tested on Ubuntu 17.10 and Arch, x86_64. Should work on other distros, maybe even other architectures!
Run fusee-launcher.py with the "--override-checks" argument.
If you'd rather patch your drivers properly:
https://github.com/fail0verflow/shofel2/blob/master/linux-ehci-enable-large-ctl-xfers.patch
"""
ksyms = {
line[2]: int(line[0], 16)
for line in
map(lambda l: l.strip().split(),
open("/proc/kallsyms", "r").readlines())}
print(hex(ksyms["ehci_urb_enqueue"]))
patch_c = """
#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/pgtable.h>
static u32 ORIG_MAX = 16*1024;
static u32 NEW_MAX = 0x1000000;
/* borrowed from MUSL because I'm lazy AF */
static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
{
uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3];
uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3];
for (h+=3, k-=3; k; k--, hw = hw<<8 | *++h)
if (hw == nw) return (char *)h-3;
return 0;
}
static pte_t* (*lookup_addr)(unsigned long, unsigned int*) = (void *) PLACE2;
static void set_addr_rw(unsigned long addr) {
unsigned int level;
pte_t *pte = lookup_addr(addr, &level);
set_pte_atomic(pte, pte_mkwrite(*pte));
}
int init_module(void) {
void * ehci_urb_enqueue_start = (void *) PLACEHOLDER;
u32 * patch_addr;
printk(KERN_INFO "Patch module loaded\\n");
patch_addr = (u32 *) fourbyte_memmem(ehci_urb_enqueue_start, 0x400, (void *)&ORIG_MAX);
if (patch_addr == NULL) {
printk(KERN_INFO "Failed to find patch site :(\\n");
return -1;
}
printk(KERN_INFO "patch_addr: 0x%px\\n", patch_addr);
set_addr_rw((unsigned long)patch_addr);
*patch_addr = NEW_MAX;
printk(KERN_INFO "Patching done!\\n");
return -1;
}
""".replace("PLACEHOLDER", hex(ksyms["ehci_urb_enqueue"])).replace("PLACE2", hex(ksyms["lookup_address"]))
makefile = """
obj-m += patch.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
"""
with open("patch.c", "w") as patchfile:
patchfile.write(patch_c)
with open("Makefile", "w") as mf:
mf.write(makefile)
os.system("make")
print("About to insert patch module, 'Operation not permitted' means it probably worked, check dmesg output.")
os.system("insmod patch.ko")
I tried to see if running it in Termux would do anything but I got the following error:
Code:
0x0
Traceback (most recent call last):
File "ehci_patch.py", line 70, in <module>
" " ".replace("PLACEHOLDER", hex(ksyms["ehci_urb_enqueue"])).replace("PLACE2" hex(ksyms["lookup_address"]))
KeyError: 'lookup_address'
I know that script isn't meant for use on Android anyway but maybe it can lead to a solution. The author of it does not know how to go about it at this time either, but believes an entire recompile of the kernel would be necessary. I am hoping that something like a systemless Magisk module would be the easiest solution for users but do not know if that is possible. I am only guessing it might be possible to create a Magisk module because of audio drivers like VIPER4Android. If indeed a custom kernel is needed, does anyone know how to go about it? It could be difficult to implement for everyone because not everyone has a device where the source to the kernel is available, etc. I am willing, however, to test anything on my tablet which is USB 2.0 and gives the error in the app. Any advice for how to go about this will be greatly appreciated.
I feel ya man, i need this stuff too. NXLoader doesn't work on my Galaxy Grand Prime (G530T) and i really need it to Dx

Use Accelerate Kit to calculate PI number

Prerequisites
Android Studio 3.6
Android SDK
Kotlin 1.3.72
Required knowledge
C programming language
Multithreading programming
Integration steps
Add the native build support to your build.gradle file
Code:
externalNativeBuild {
cmake {
cppFlags ""
arguments "-DANDROID_STL=c++_shared"
}
}
ndk {
abiFilters "arm64-v8a","armeabi-v7a"
}
Download the SDK package from this link and decompress it
Copy the header files in the SDK to the resource library.
In the /app directory in the Android Studio project, create an include folder. Copy the files in the /include directory of the SDK to the newly created include folder.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Copy the .so files in the SDK to the resource library.
Create a libs folder in the /app directory and create arm64-v8a folder and armeabi-v7a folder in /app/libs directory.
Copy the libdispatch.so and libBlockRuntime.so in lib64 directory of the SDK to libs/arm64-v8a directory of Android Studio.
Copy the libdispatch.so and libBlockRuntime.so in the lib directory of the SDK to the libs/armeabi-v7a directory of Android Studio.
Create or modify the CMakeLists.txt file in the app/src/main/cpp directory as follows
Code:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
target_include_directories(
native-lib
PRIVATE
${CMAKE_SOURCE_DIR}/../../../include)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
add_library(
dispatch
SHARED
IMPORTED)
set_target_properties(
dispatch
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libdispatch.so)
add_library(
BlocksRuntime
SHARED
IMPORTED)
set_target_properties(
BlocksRuntime
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libBlocksRuntime.so)
add_custom_command(
TARGET native-lib POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libdispatch.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libBlocksRuntime.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/
)
target_compile_options(native-lib PRIVATE -fblocks)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
dispatch
BlocksRuntime
# Links the target library to the log library
# included in the NDK.
${log-lib} )
From Android Studio, select Build → Linked C++ projects
Download the NDK if not configured and install it then sync with your projects
PI Formula
We will use the two below formula to calculate PI number
Nilakantha series
Coding steps
Open your application class and add the below code to load the native library when the application is created
Code:
companion object {
// Used to load the 'native-lib' library on application startup.
init {
System.loadLibrary("native-lib")
}
}
On your demo activity, remember to add the external functions as below
Code:
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
private external fun doubleFromJNI(): Double
private external fun doubleFromJNI2(): Double
Then defined these functions in app/src/main/native-lib.cpp as below ( I will explain the dispatch functions later)
Code:
extern "C"
JNIEXPORT jdouble JNICALL
Java_com_pushdemo_jp_huawei_activity_AccelerateDemoActivity_doubleFromJNI(JNIEnv *env,
jobject thiz) {
dispatch_autostat_enable(env);
return dispatch1();
}
extern "C"
JNIEXPORT jdouble JNICALL
Java_com_pushdemo_jp_huawei_activity_AccelerateDemoActivity_doubleFromJNI2(JNIEnv *env,
jobject thiz) {
dispatch_autostat_enable(env);
return dispatch2();
}
For each formula, we will implement each function to calculate and divide them into subthread to execute to save time
For Nilakantha series, we will divide into 2 subthreads, and values of i set as follows:
[2, 6, 10, 14, ...]
[4, 8, 12, 16, ...]
Code:
double calcPiByStep(long start, long end, int step)
{
double total = 0.0;
int sign;
for (long i = start; i <= end; i += step)
{
long frag = i * (i + 1) * (i + 2);
sign = i % 4 == 0 ? -1 : 1;
double val = 4.0 * sign / frag;
total += val;
}
return total;
}
Then we will implement the dispatch1 function to summarize the result. First, create the concurrent queue, the serial queue, and the group queue. Then asynchronously add the subtask calcPiByStep to the concurrent queue, and associate the subtask with the group queue.
Code:
double dispatch1()
{
int i;
int step = 4;
long start = 2;
long limit = 1000000000;
__block double pi_total = 3;
dispatch_queue_t concurr_q = dispatch_queue_create("concurrent", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t serial_q = dispatch_queue_create("serial", DISPATCH_QUEUE_SERIAL);
dispatch_group_t group = dispatch_group_create();
for (i = 0; i < step; i += 2) {
dispatch_group_async(group, concurr_q, ^{
double pi = calcPiByStep(start + i, limit, step);
dispatch_sync(serial_q, ^{
pi_total += pi;
});
});
}
dispatch_wait(group, DISPATCH_TIME_FOREVER);
dispatch_release(group);
dispatch_release(serial_q);
return pi_total;
} 
For Gregory and Leibniz series, we will divide into 4 subthreads, and values of i set as follows:
[0, 4, 8, 12, ...]
[1, 5, 9, 13, ...]
[2, 6, 10, 14, ...]
[3, 7, 11, 15, ...]
Code:
double calcPiByStep2(long start, long end, int step)
{
double total = 0.0;
int sign;
for (long i = start; i <= end; i+= step)
{
long frag = 2 * i + 1;
sign = i % 2 == 0 ? 1 : -1;
total += 4.0 * sign / frag;
}
return total;
}
Then we will execute 4 subthreads concurrently as below
Code:
double dispatch2() {
__block double pi = 0;
int mod = 4;
int i = 0;
long limit = 1000000000;
dispatch_queue_t serial = dispatch_queue_create("serial", DISPATCH_QUEUE_SERIAL);
dispatch_apply(mod, DISPATCH_APPLY_AUTO, ^(size_t i) {
double _sum = calcPiByStep2(i, limit, mod);
dispatch_sync(serial, ^{
pi += _sum;
});
});
dispatch_release(serial);
return pi;
}
Result
For HMS devices, the result is quite fast. It took around 1.7 seconds to execute the dispatch1 and 1.4 seconds to execute the dispatch2
But for non-HMS devices, the calculation took longer times: around 6.7 seconds for dispatch1 and 3.5 seconds for dispatch2
Conclusion
The performance depends on the chipset. For HMS devices (using Kirin chip), the performance is good but for non-HMS devices (using other chip), the performance needs to be improved.

Categories

Resources