Android compiling script analysis on s5pv210 Development Board-[based on x210 Development Board]

Source: Internet
Author: User

MK script analysis
The source code and comments are as follows:

#! /Bin/sh
#
# Description: Build Android script.
# Authors: Jianjun Jiang-jerryjianjun@gmail.com
# Version: 0.01
# Notes: None
#

Export android_java_home =/usr/lib/JVM/Java-6-sun/
# Java compilation environment declaration. If JDK is manually installed and environment variables are declared according to the previous steps, this statement can be omitted.
Source_dir = $ (CD 'dirname $ 0'; PWD) # Use the script command to find the current directory. /mK: Execute the script with a warning. Use source_dir = $ (PWD) directly.

Tools_dir =$ {source_dir}/tools/# tools directory
Release_dir =$ {source_dir}/out/release/# Release directory of the final generated image file
Target_dir =$ {source_dir}/out/target/product/smdkv210/
# Target directory of the image file
Bootloader_uboot_config = smdkv210single_config
# Uboot configuration script
Bootloader_xboot_config = arm-mpad # xboot configuration script
Android_kernel_config = s5pv210_android_defconfig
# Android Kernel configuration script
Initrd_kernel_config = s5pv210_initrd_defconfig
# Linux Kernel configuration script
Filesystem_config = PRODUCT-full_smdkv210-eng
# Specify the target project name

Setup_environment () # Set the Environment Variable Function and create the image release directory and target directory in the android source directory.
{
CD $ {source_dir };
Mkdir-p $ {release_dir} | return 1;
Mkdir-p $ {target_dir} | return 1;
}

Build_bootloader_uboot () # compile uboot. We use xboot instead of uboot.
{
CD $ {source_dir}/uboot | return 1
Make distclean | return 1;
Make $ {bootloader_uboot_config} | return 1;
Make

./Mkmovi
./Mkheader Bootstrap. Bin
./Mkheader u-boot.bin
CP-V $ {source_dir}/uboot/Bootstrap. Bin $ {release_dir}
CP-V $ {source_dir}/uboot/u-boot.bin $ {release_dir}

Echo ""> & 2
Echo "pai_^ uboot path: $ {release_dir}/Bootstrap. bin"> & 2
Echo "cmd_^ uboot path: $ {release_dir}/u-boot.bin"> & 2
Return 0
}

Build_bootloader_xboot () # compile xboot
{
If [! -F $ {release_dir}/zimage-initrd]; then
# Xboot packages the Linux kernel. Therefore, the Linux Kernel File must exist.
Echo "not found kernel zimage-initrd, please build kernel first"> & 2
Return 1
Fi

If [! -F $ {release_dir}/zimage-android]; then
# Xboot packages the android kernel. Therefore, the android Kernel File must exist.
Echo "not found kernel zimage-android, please build kernel first"> & 2
Return 1
Fi

# Copy zimage-initrd and zimage-android to xboot's romdisk directory
CP-V $ {release_dir}/zimage-initrd $ {source_dir}/xboot/src/ARCH/ARM/Mach-mpad/romdisk/boot | return 1;
CP-V $ {release_dir}/zimage-android $ {source_dir}/xboot/src/ARCH/ARM/Mach-mpad/romdisk/boot | return 1;

# Compiler xboot
CD $ {source_dir}/xboot | return 1
Make target =$ {bootloader_xboot_config} cross =/usr/local/ARM/arm-none-eabi-2010-09-51/bin/ARM-None-Eabi-clean | return 1;
Make target =$ {bootloader_xboot_config} cross =/usr/local/ARM/arm-none-eabi-2010-09-51/bin/ARM-None-Eabi-| return 1;

# Rm zimage-initrd and zimage-android
Rm-fr $ {source_dir}/xboot/src/ARCH/ARM/Mach-mpad/romdisk/boot/zimage-initrd
Rm-fr $ {source_dir}/xboot/src/ARCH/ARM/Mach-mpad/romdisk/boot/zimage-android

# Copy xboot. bin to release directory
CP-V $ {source_dir}/xboot/output/xboot. Bin $ {release_dir}

Echo ""> & 2
Echo "pai_^ xboot path: $ {release_dir}/xboot. bin"> & 2
Return 0
}

Build_kernel () # compile the kernel
{
CD $ {source_dir}/kernel | return 1

Make $ {initrd_kernel_config} | return 1
# Compile the Linux Kernel
Make-J $ {threads} | return 1
# After compilation, rename the image zimage to zimage-initrd.
Dd If =$ {source_dir}/kernel/ARCH/ARM/boot/zimage of =$ {release_dir}/zimage-initrd BS = 2048 COUNT = 8192 Conv = sync;

Make $ {android_kernel_config} | return 1
# Compile the android Kernel
Make-J $ {threads} | return 1
# After compilation, rename the image zimage to zimage-android.
Dd If =$ {source_dir}/kernel/ARCH/ARM/boot/zimage of =$ {release_dir}/zimage-android BS = 2048 COUNT = 8192 Conv = sync;

Echo ""> & 2
Echo "pai_^ initrd kernel path: $ {release_dir}/zimage-initrd"> & 2
Echo "pai_^ Android kernel path: $ {release_dir}/zimage-android"> & 2

Return 0
}

Build_system () # compile the android File System
{
CD $ {source_dir} | return 1
Make-J $ {threads }$ {filesystem_config} | return 1

# Create Android. IMG. cpio
Rm-fr $ {target_dir}/cpio_list $ {target_dir}/Android. IMG. cpio ||{ return 1 ;}
$ Tools_dir/gen_initramfs_list.sh $ {target_dir}/root >$ {target_dir}/cpio_list | {return 1 ;}
$ Tools_dir/gen_init_cpio $ {target_dir}/cpio_list >$ {target_dir}/Android. IMG. cpio | {return 1 ;}

# Create data.tar
CD $ {target_dir}/Data | {echo "error: cocould not enter the $ {target_dir}/data directory."; return 1 ;}
Rm-fr $ {target_dir}/data.tar | {return 1 ;}
Tar CVF $ {target_dir}/data.tar./* | {return 1 ;}
# Package all files generated in the data directory ***/

# Create system.tar
CD $ {target_dir}/system | {echo "error: cocould not enter the $ {target_dir}/system directory."; return 1 ;}
Rm-fr $ {target_dir}/system.tar | {return 1 ;}
Tar CVF $ {target_dir}/system.tar./* | {return 1 ;}
# Package all files generated in the system directory ***/

CP-AV $ {target_dir}/installed-files.txt $ {release_dir}/| return 1;
CP-AV $ {target_dir}/installed-files.txt $ {release_dir}/| return 1;
CP-AV $ {target_dir}/Android. IMG. cpio $ {release_dir}/| return 1;
CP-AV $ {target_dir}/system. IMG $ {release_dir}/| return 1;
CP-AV $ {target_dir}/system.tar $ {release_dir}/| return 1;
CP-AV $ {target_dir}/userdata. IMG $ {release_dir}/| return 1;
CP-AV $ {target_dir}/data.tar $ {release_dir}/| return 1;

Echo ""> & 2
Echo "pai_^ System Path: $ {release_dir}/system.tar"> & 2
Return 0
}

Gen_update_bin () # Use genromfs to package the generated image file into update. Bin.
{
# Check image files
If [! -F $ {release_dir}/xboot. Bin]; then
# Update. Bin contains xboot. Bin
Echo "not found bootloader xboot. Bin, please build bootloader"> & 2
Return 1
Fi

If [! -F $ {release_dir}/zimage-initrd]; then
# Update. Bin contains zimage-initrd
Echo "not found kernel zimage-initrd, please build kernel first"> & 2
Return 1
Fi

If [! -F $ {release_dir}/zimage-android]; then
# Update. Bin contains zimage-android
Echo "not found kernel zimage-android, please build kernel first"> & 2
Return 1
Fi

If [! -F $ {release_dir}/system.tar]; then
#Update.binwith system.tar
Echo "not found system.tar, please build system"> & 2
Return 1
Fi

If [! -F $ {release_dir}/data.tar]; then
#Update.binincludes data.tar
Echo "not found data.tar, please build system"> & 2
Return 1
Fi

Rm-fr $ {release_dir}/tmp | return 1;
Rm-fr $ {release_dir}/update. Bin | return 1;
Mkdir-p $ {release_dir}/tmp | return 1;

# Copy image files
CP $ {release_dir}/xboot. Bin $ {release_dir}/tmp /;
CP $ {release_dir}/zimage-initrd $ {release_dir}/tmp /;
CP $ {release_dir}/zimage-android $ {release_dir}/tmp /;
CP $ {release_dir}/system.tar $ {release_dir}/tmp /;
CP $ {release_dir}/data.tar $ {release_dir}/tmp /;

# Create md5sum.txt
CD $ {release_dir}/tmp /;
Find.-Type F-print | while read line; do
If [$ line! = 0]; then
Md5sum $ {Line }>> md5sum.txt
Fi
Done

# Genromfs
# Package with genromfs
Genromfs-v-d $ {release_dir}/tmp/-F $ {release_dir}/update. Bin | return 1;

CD $ {source_dir} | return 1
Rm-fr $ {release_dir}/tmp | return 1;
Return 0;
}

Threads = 4; #4-core compilation is used by default. To use single-core compilation, add-J1 when executing the script.
Uboot = no; # No compilation by default
Xboot = no;
Kernel = no;
System = no;
Update = no;

If [-Z $1]; then # If the script is executed without parameters, compile all
Uboot = Yes
Xboot = Yes
Kernel = Yes
System = Yes
Update = Yes
Fi

While ["$1"]; do # detect the image file to be compiled through the WHILE LOOP
Case "$1" in
-J = *) # Number of Cores Used for compilation
X = $1
Threads =$ {X #-j =}
;;
-U | -- uboot)
# Uboot Compilation
Uboot = Yes
;;
-X | -- xboot)
# Compile xboot
Xboot = Yes
;;
-K | -- kernel)
# Compile Kernel
Kernel = Yes
;;
-S | -- System)
# Compiling Android system
System = Yes
;;
-U | -- Update)
# Package all images
Update = Yes
;;
-A | -- all)
# Compile all files
Uboot = Yes
Xboot = Yes
Kernel = Yes
System = Yes
Update = Yes
;;
-H | -- Help)
# Help Information
Cat> & 2 <EOF
Usage:./mK [Option]
Build script for compile the source of telechips project.

-J = N using n threads when building Source Project (example:-j = 16)
-U, -- uboot build bootloader uboot from source file
-X, -- xboot build bootloader xboot from source file
-K, -- kernel build kernel from source file and using default Config File
-S, -- System Build File System from source file
-U, -- Update Gen update package update. Bin
-A, -- all build all, include anything
-H, -- help display this help and exit
EOF
Exit 0
;;
*)
Echo "build. sh: unrecognised option $1"> & 2
Exit 1
;;
Esac # End mark of the case statement. Note that the case is the opposite.
Shift # Parameters entered when the script is executed in shift mode
Done

Setup_environment | Exit 1 # The first execution command of the script, which sets the compiling environment variable

If ["$ {kernel}" = Yes]; then # compile the kernel
Build_kernel | Exit 1
Fi

If ["$ {system}" = Yes]; then # compile the Android system
Build_system | Exit 1
Fi

If ["$ {uboot}" = Yes]; then # compile uboot
Build_bootloader_uboot | Exit 1
Fi

If ["$ {xboot}" = Yes]; then # compile xboot
Build_bootloader_xboot | Exit 1
Fi

If ["$ {update}" = Yes]; then # package the image file
Gen_update_bin | Exit 1
Fi

Exit 0 # exit the script file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.