说明
由于需要用到全志的芯片的orangepi_zero的开源板子做项目,需要定制linux系统,对系统添加内置程序,修改镜像大小和ubuntu系统版本。需要对源码编译生成ubuntu系统镜像。
使用编译环境
编译内核使用的是docke容器,比较方便。封装打包内核生成镜像使用实体机ubuntu16.04 64位。因为打包镜像在docker内运行会出错。
docker地址
docker pull registry.cn-shenzhen.aliyuncs.com/qusir/orangepi_zero:0.2
源码地址
https://github.com/QUSIR/orangepi_h2_linux
依赖项安装
设置dtc编译uboot
运行容器
docker run -it -v /home/orangepi_h2_linux:/data registry.cn-shenzhen.aliyuncs.com/qusir/orangepi_zero:0.2 bash
说明:将orangepi_h2_linux源码目录映射到容器的data文件夹
编译dtc
dtc下载地址 链接:https://pan.baidu.com/s/1sndX30T 密码:c2mw
7z x dtc.7z
cd dtc
make
设置dtc环境变量
export PATH=/data/dtc/:$PATH
设置交叉编译器环境变量
export PATH="$PWD/brandy/gcc-linaro/bin":"$PATH"
编译过程
编译uboot
make CROSS_COMPILE=arm-linux-gnueabi- orangepi_zero_defconfig
编译内核
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- sun8iw7p1smp_linux_defconfig
make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage modules
编译文件生成文件拷贝
cp -rf ./linux-3.4/output/lib/* ./build/lib
cp -rf ./linux-3.4/arch/arm/boot/uImage ./build/uImage
cp -rf ./u-boot-2016.7/u-boot-sunxi-with-spl.bin ./build/uboot
cp -rf ./build/lib/* ../OrangePi-BuildLinux/orange/lib/
cp -rf ./build/uImage ../OrangePi-BuildLinux/orange/
cp -rf ./build/uboot/u-boot-sunxi-with-spl.bin ../OrangePi-BuildLinux/orange/
cp -rf ./build/uboot/boot.scr ../OrangePi-BuildLinux/orange/
依赖项安装
实体机上
apt-get install debootstrap qemu-user-static chroot
生成镜像
./create_image
./image_from_dir linux-trusty orangepi ext4 zero
说明:linux-trust为执行create_imge所生成系统目录,orangepi为生成镜像名称。
镜像定制说明
修改 params.sh文件
# =====================================================
# ==== P A R A M E T E R S ============================
# =====================================================
# *****************************************************
# Set to "yes" to create realy minimal image *
# *****************************************************
ONLY_BASE="no"
# *****************************************************
# Set hostname, user to be created *
# and root and user passwords *
# *****************************************************
HOSTNAME="OrangePizero" #主机名称
USER="orangepi" #用户名
ROOTPASS="orangepi" #root密码
USERPASS="orangepi" #orangepi密码
# *****************************************************
# Set timezone, for default (HOST'S) set _timezone="" *
# *****************************************************
_timezone="Etc/UTC"
#_timezone=""
# *****************************************************
# SET IF YOU WANT TO INSTALL SPECIFIC LANGUAGE, *
# COMMENT FOR DEFAULT (HOST) settings *
# *****************************************************
LANGUAGE="en"
LANG="en_US.UTF-8"
# *****************************************************
# Set the base name of your image. *
# Distro name is automaticaty appended, and the image *
# will be "image_name-distro.img" *
# --------------------------------------------------- *
# IF image_name="", image file won't be created, *
# instalation will be created in local directories *
# linux-$distro & boot-$distro *
# YOU CAN CREATE THE IMAGE LATER RUNNING: *
# sudo ./image_from_dir *
# === IT IS THE RECOMMENDED WAY OF IMAGE CREATION === *
# --------------------------------------------------- *
# IF image_name is BLOCK DEVICE (/dev/sdXn) *
# LINUX filesystem will be created directly on it *
# Partition must exist ! *
# IF _format="" partition will NOT be formated *
# otherwyse it will be formated with specified format *
# *****************************************************
image_name=""
#image_name="minimal"
#image_name="/dev/sdg"
# *****************************************************
# Filesystem type for linux partition *
# If btrfs is selectet, partition will be mounted *
# "compressed" option, you can save some sdcard space *
# --------------------------------------------------- *
# Used when creating the system directly on SDCard or *
# SDCard image file and in "image_from_dir" script *
# *****************************************************
_format="ext4" #文件系统
#_format="btrfs"
# *****************************************************
# SD Card partitions sizes in MB (1024 * 1024 bytes) *
# --------------------------------------------------- *
# If creating on physical sdcard (not image) you can *
# set "linuxsize=0" to use maximum sdcard size *
# --------------------------------------------------- *
# When creating the image with "image_from_dir" script*
# "linuxsize" is calculated from directory size *
# *****************************************************
fatsize=64
linuxsize=800 #生成镜像大小
# *****************************************************
# Select ubuntu/debian distribution and repository *
# === SELECT ONLY ONE distro AND ONE repo === *
# *****************************************************
# === Ubuntu ===
#distro="precise"
#distro="xenial"
distro="trusty" #ubuntu版本
#distro="utopic"
#distro="vivid"
#distro="wily"
#repo="http://ports.ubuntu.com/ubuntu-ports"
repo="http://mirrors.ustc.edu.cn/ubuntu-ports" #ubuntu镜像源
# === Debian ===
#distro="wheezy"
#distro="jessie"
#repo="http://ftp.hr.debian.org/debian"
#raspbian="no"
# === Raspbian ===
#distro="wheezy"
#distro="jessie"
#repo="http://archive.raspbian.org/raspbian"
#raspbian="yes"
# ******************************************************
# If creating the image, you can xz compress the image *
# after creation and make the md5sum file *
# to do that automatically, set _compress="yes" *
# ******************************************************
_compress="no"
# =====================================================
# IF YOU WANT TO HAVE BOOT FILES ON EXT4 PARTITION =
# AND NOT ON SEPARATE FAT16 PARTITION =
# set _boot_on_ext4="yes" and =
# FAT partitin won't be created =
# --------------------------------------------------- =
# DO NOT CHANGE FOR NOW ! =
# =====================================================
_boot_on_ext4="no"
# ^^^^ P A R A M E T E R S ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^