2017年6月1日 星期四

BeagleBone Black with Gentoo Linux

以下內容,不分Beaglebone Green / Beaglebone Black

1.你需要先準備Gentoo linux的環境 

後段安裝xwindow 可忽略

2.準備toolchain

emerge --ask dev-vcs/git sys-devel/crossdev sys-fs/dosfstools app-arch/lzop
Create an overlay for crossdev
mkdir -p /usr/local/portage/{metadata,profiles}
echo "local_overlay" /usr/local/portage/profiles/repo_name
echo "masters = gentoo" /usr/local/portage/metadata/layout.conf
chown -R portage:portage /usr/local/portage
Edit /etc/portage/make.conf
file
PORTDIR_OVERLAY="/usr/local/portage"
build cross compiler
crossdev -S -P -v -t armv7a-hardfloat-linux-gnueabihf
#test
armv7a-hardfloat-linux-gnueabihf-gcc --version

3.build u-boot 

# I used u-boot-2016.07
wget ftp://ftp.denx.de/pub/u-boot/u-boot-2016.07.tar.bz2
tar xjpf u-boot-latest.tar.bz2
cd /home/u-boot-*
# check configs file
ls ./configs grep am335x
make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux-gnueabihf- am335x_boneblack_defconfig
make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux-gnueabihf-
# install mkimage to make uImage later
install tools/mkimage /usr/local/bin

4.build image

# I follow blog to choose 3.14
git clone -b 3.14 --single-branch https://github.com/beagleboard/linux.git
cd /home/linux
# check version
cat Makefile | head
make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux-gnueabihf- bb.org_defconfig
# If you want disable/enable something
make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux-gnueabihf- menuconfig
make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux-gnueabihf-
make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux-gnueabihf- uImage dtbs LOADADDR=0x82000000
mkdir /home/linux_modules
make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux-gnueabihf- INSTALL_MOD_PATH=../linux_modules modules_install

5.grab file system

links https://www.gentoo.org/downloads/mirrors
# Find Downloads page
# Find something like "Stage 3 ARMv7a | HardFP 2016-05-23 218 MiB"
# After finishing , ctrl+c back to bash
# grab portage
wget http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2
mkdir /home/bbb
mkdir /home/bbb/deploy
tar xjpf stage3-armv7a_hardfp-20160523.tar.bz2 -C /home/bbb/deploy
tar xjpf portage-latest.tar.bz2 -C /home/bbb/deploy/usr/

6.copy file

cp /home/linux/arch/arm/boot/uImage /home/bbb/deploy/boot
cp /home/linux/arch/arm/boot/zImage /home/bbb/deploy/boot
cp /home/linux/arch/arm/boot/dts/am335x-boneblack.dtb /home/bbb/deploy/boot
cp -r /home/linux_modules/lib/modules /home/bbb/deploy/lib
mkdir /home/bbb/deploy/boot/uboot
若要支援Beaglebone Green,需要放入 am335x-bonegreen.dtb

7.config system

edit /homebbb/deploy/etc/fstab
file
/dev/mmcblk0p2      /           ext4            noatime,errors=remount-ro   0 1
/dev/mmcblk0p1      /boot/uboot auto            noatime                     1 2
設定 root password
openssl passwd -1 -salt xyz "passwd"
# copy hash code to /home/bbb/deploy/etc/shadow inside root password
enable ssh 
ln -sf /etc/init.d/sshd /home/bbb/deploy/etc/runlevels/default
edit /home/bbb/deploy/etc/ssh/sshd_config
file
PermitRootLogin yes
PasswordAuthentication yes
因為沒有安裝dhcpcd , 要設定static ip (可跳到步驟10安裝dhcpcd)
edit  /home/bbb/deploy/etc/conf.d/net
file
#config_eth0="<your IP> netmask <your netmask> brd <network broadcast IP>"
config_eth0="192.168.100.5 netmask 255.255.255.0 brd 192.168.100.255"
#routes_eth0="default via <your router IP>"
routes_eth0="default via 192.168.100.1"
#dns_servers_eth0="<nameserver IP> <another nameserver IP>"
dns_servers_eth0=""
設定網卡 eth0
cd /home/bbb/deploy/etc/init.d
ln -s net.lo net.eth0
cd /home/bbb/deploy/etc/runlevels/default
ln -s /etc/init.d/net.eth0
replace hwclock with swclock
cd /home/bbb/deploy/etc/runlevels/boot
unlink hwclock
ln -s /etc/init.d/swclock .
.設定時區 
echo "Asia/Taipei" > ./bbb/deploy/etc/timezone
.設定hostname
edit /home/bbb/deploy/etc/conf.d/hostname
file
hostname="beaglebone-gentoo"

8.打包

cd /home/bbb/deploy
tar cvzpf ../deploy.tar.gz .
format microSD & copy file to microSD
mkdir /mnt/sdcard
./mksd-am335x.sh /dev/sdb /home/u-boot-2014.07/MLO u-boot-2014.07/u-boot.img /home/linux/arch/arm/boot/uImage /home/bbb/deploy.tar.gz
note1 因為原腳本sfdisk指令無效 http://unix.stackexchange.com/questions/242124/sfdisk-doesnt-work-anymore , 修改過sfdisk那段
note2 雖然/home/linux/arch/arm/boot/uImage 在這邊沒有作用 , 但我沒刻意修改這部分 
note3 如果出現 bad interpreter: No such file or directory , 請emerge --ask dos2unix 下載tool , 接著輸入 dos2unix mksd-am335x.sh 將檔案轉換
mksd-am335x.sh
#!/bin/bash
if [[ -z $1 || -z $2 || -z $3 || -z $4 ]]
then
    echo "mksd-am335x Usage:"
    echo "  mksd-am335x <device> <MLO> <u-boot.img> <uImage> <rootfs tar.gz >"
    echo "  Example: mksd-am335x /dev/sdc MLO u-boot.img uImage nfs.tar.gz"
    exit
fi
if ! [[ -e $2 ]]
then
    echo "Incorrect MLO location!"
    exit
fi
if ! [[ -e $3 ]]
then
    echo "Incorrect u-boot.img location!"
    exit
fi
if ! [[ -e $4 ]]
then
    echo "Incorrect uImage location!"
    exit
fi
if ! [[ -e $5 ]]
then
    echo "Incorrect rootfs location!"
    exit
fi
echo "All data on "$1" now will be destroyed! Continue? [y/n]"
read ans
if ! [ $ans == 'y' ]
then
    exit
fi
echo "[Partitioning $1...]"
DRIVE=$1
dd if=/dev/zero of=$DRIVE bs=1024 count=1024
      
SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`
      
#echo DISK SIZE - $SIZE bytes
#echo CYLINDERS - $CYLINDERS
#{
#echo ,9,0x0C,*
#echo ,,,-
#} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
  
wipefs --all $DRIVE
{
echo ",$((9*63*255)),0x0c,*"
echo ",,,-"
} | sfdisk $DRIVE
echo "[Making filesystems...]"
mkfs.vfat -F 32 -n boot "$1"1 &> /dev/null
# the "-T small" is so I have enough inodes for portage
mkfs.ext4 -L rootfs -T small "$1"2 &> /dev/null
echo "[Copying files...]"
mount "$1"/mnt/sdcard
cp $2 /mnt/sdcard/MLO
cp $3 /mnt/sdcard/u-boot.img
umount "$1"1
mount "$1"/mnt/sdcard
tar zxvf $5 -C /mnt/sdcard
chmod 755 /mnt/sdcard
umount "$1"2
echo "[Done]"

9. boot from microSD

SD卡插入 , 按住靠近SD卡插槽的按鈕 , 啟動電源 , 等LED亮即可放開手

 10. 在host PC新增package到target arm(以dhcpcd為例)

#cross build package and save into /usr/armv7a-hardfloat-linux-gnueabihf/package
armv7a-hardfloat-linux-gnueabihf-emerge --buildpkg --oneshot net-misc/dhcpcd
# 切換到bbb的filesystem路徑
cd /home/bbb/deploy
#install package
ROOT=$PWD/ armv7a-hardfloat-linux-gnueabihf-emerge --ask --usepkgonly --oneshot net-misc/dhcpcd
#enable dhcpcd
ln -sf /etc/init.d/dhcpcd /home/bbb/deploy/etc/runlevels/default
edit  /home/bbb/deploy/etc/conf.d/net
file
#config_eth0="<your IP> netmask <your netmask> brd <network broadcast IP>"
config_eth0="dhcp"
#dns_servers_eth0="<nameserver IP> <another nameserver IP>"
dns_servers_eth0=""
可以安裝qemu在x86電腦上測試arm
#install qemu host side
emerge --ask app-emulation/qemu
#build qemu arm package
QEMU_USER_TARGETS="arm" QEMU_SOFTMMU_TARGETS="arm" USE="static-user static-libs" emerge --ask --buildpkg --oneshot qemu
#install qemu arm filesystem side
cd /home/bbb/deploy && ROOT=$PWD/ emerge --ask --usepkgonly --oneshot --nodeps qemu
#chroot to arm filesystem
/etc/init.d/qemu-binfmt start && cd /home/bbb/deploy && chroot . /bin/bash --login
#test dhcpcd
(chroot arm) ~# dhcpcd

11. 在host PC移除target arm的package(以dhcpcd為例)

# 切換到bbb的filesystem路徑
cd /home/bbb/deploy
#uninstall package
ROOT=$PWD/ armv7a-hardfloat-linux-gnueabihf-emerge -C net-misc/dhcpcd

沒有留言:

張貼留言

NoSQL Redis intro

Redis是一個使用ANSI C編寫的開源、支援網路、基於記憶體、可選永續性的鍵值對儲存資料庫。 支援rdb 及aof 兩種儲存方式 From  https://zh.wikipedia.org/wiki/Redis Redis 目前擁有兩種資料...