2016년 12월 28일 수요일

Booting BeagleBone Black with Yocto Project or BuildRoot

이번 post는 지난 시간에 이어, Yocto ProjectBuildRootBeagleBone Black에 적용하는 과정을 소개해 보고자 한다. 거의 3년만에 BeagleBone Black을 다시 켜 보는 것 같다 ;)

<목차>
1. Yocto Project Download & Build
2. BuildRoot Download & Build
3. 부팅용 SD card 만들기
4. SD card로 부팅하기 


1. Yocto Project Download & Build
BeagleBone Black을 위한 yocto project를 download한 후, build하는 절차를 소개하면 다음과 같다. 

$ mkdir yocto; cd yocto
$ git clone git://git.yoctoproject.org/poky.git
   => poky  최신 버젼을 내려 받는다.

$ cd poky
$ git checkout -b krogoth-15.0.1 krogoth-15.0.1
   => krogoth-15.0.1 branch로 전환한다.

주의) 현재 Ubuntu 16.04 LTS version을 사용 중인데, poky old version을 사용할 경우, 에러가 발생할 수 있으니, krogoth 이상 버젼을 사용하는 것이 좋을 듯 보인다(물론, 에러를 잡는 방법도 있겠지만 ...)

$ git am ~/yocto-labs/0001-Fix-lab.patch
   => patch(http://free-electrons.com/doc/training/yocto/yocto-labs.tar.xz에 포함되어 있음)를 적용한다.
   => 참고: 이 patch의 용도는 meta-yocto-bsp/conf/machine/beaglebone.conf 파일을 제거하는데 있음. 이는 meta-ti/conf/machine/beaglebone.conf (그림 1.2, 1.3 참조) 내용을 사용하기 위한 조치임.

$ cd ..
$ git clone git://git.yoctoproject.org/meta-ti.git
   => meta-ti를 내려 받는다.
   => 이전 blog에서도 언급했다시피, poky는 yocto reference system으로, 여기에서 직접 내용 수정을 하는 것 보다는, board 관련 전용 meta data(layer)를 만들어 사용하는 것이 일반적인 방법이다. 따라서 meta-ti는 이런 관점에서 만들어 진 것으로 보면 된다.
   => 만일, beagleboard와 유사한 새로운 board를 만들어 사용하는 상황이라면, meta-ti를 수정하여 사용하던지, meta-ti와 유사한 layer를 하나 만들어(복사후, 수정) 사용하면 될 것이다.

$ cd meta-ti

그림 1.1 meta-ti 내용

참고) meta-ti의 각 디렉토리의 내용을 면밀히 살펴볼 필요가 있다.

$ git checkout -b ti2016.03 ti2016.03
   => ti2016.03 branch로 전환한다.
$ git am ~/yocto-labs/0001-Simplify-linux-ti-staging-recipe.patch
   => patch(http://free-electrons.com/doc/training/yocto/yocto-labs.tar.xz에 포함되어 있음)를 적용한다.
   => 이 patch의 목적은 meta-ti/recipes-kernel/linux/linux-ti-staging-4.4/defconfig 내용에 몇가지 linux kernel config를 추가함과 동시에, meta-ti/recipes-kernel/linux/linux-ti-staging-4.4 디렉토리 아래의 불필요한 내용을 제거하는데 있다.

------------------------------------------------------------------------------------------------
chyi@earth:~/BBB/meta-ti/recipes-kernel/linux/linux-ti-staging-4.4$ ls -la
-rw-rw-r-- 1 chyi chyi   38 12월 29 10:56 defconfig      <= 수정
drwxrwxr-x 2 chyi chyi 4096 12월 29 10:56 dra7xx      <= 제거
drwxrwxr-x 2 chyi chyi 4096 12월 29 10:56 k2g-evm   <= 제거 
drwxrwxr-x 2 chyi chyi 4096 12월 29 10:56 keystone   <= 제거
drwxrwxr-x 2 chyi chyi 4096 12월 29 10:56 ti33x         <= 제거 
drwxrwxr-x 2 chyi chyi 4096 12월 29 10:56 ti43x         <= 제거 
------------------------------------------------------------------------------------------------

 그림 1.2 meta-ti/conf/machine/include/ti33x.inc

그림 1.3 meta-ti/conf/machine/beaglebone.conf


$ cd ../poky
$ source oe-init-build-env
   => build를 위한 환경 값을 초기화한다. 끝 부분에 directory를 생략할 경우에는 build 디렉토리가 default로 생성될 것임.

$ cd build
$ cd conf
$ vi local.conf
  => beaglebone을 위한 configuration을 수정한다. 수정하지 않을 경우, qemu(ARM emulator)용 image가 build될 것임.
...
MACHINE ?= "beaglebone"
...
#MACHINE ??= "qemux86"
...
DL_DIR ?= "${TOPDIR}/../../downloads"
...
PACKAGE_CLASSES ?= "package_ipk"
...
~

$ cd ..
$ bitbake core-image-sato
  => X window가 포함된 rootfs를 만드는 build를 시작한다.

그림 1.4 core-image-sato 이미지 build 시작

<결과물>
  => build_bbb/tmp/deploy/images/beaglebone

그림 1.5 build 결과 파일

==============================================================
<여기서 잠깐 1> yocto project에서 kernel 작업하기
Yocto project 상에서 kernel 작업을 수행하는 절차를 간략히 정리해 보면 다음과 같다.

1) kernel build하기
$ bitbake -c menuconfig virtual/kernel
   => kernel menuconfig
   => 다른 terminal 창에 menuconfig가 뜬다. 여기서 kernel config를 조정하자.
   => 수동으로, kernel defconfig로 부터 .config를 만들어 내기 위해서는 "bitbake -c configure virtual/kernel" 명령을 수행하면 될 것 같지만, 이 보다는 상위 디렉토리의 defconfig 파일을 .config로 복사하는 편이 보다 확실하다.

$ bitbake  virtual/kernel
   => kernel과 module을 build한다.

$ bitbake -c cleansstate virtual/kernel
   => clean build를 하고 싶을 때는 먼저 이 명령을 실행하고, 이어서 bitbake  virtual/kernel 명령을 실행한다.

2) kernel code가 어디에 있는지 확인하기
meta-ti/conf/machine/beaglebone.conf(이 경우는 meta-ti/conf/include/ti33x.inc)에서 아래 내용 파악(kernel recipe에 해당함).
PREFERRED_PROVIDER_virtual/kernel = "linux-ti-staging"

kernel recipe 파일은 meta-ti/recipes-kernel/linux 디렉토리에 있는데, 위의 내용(linux-ti-staging)에 해당하는 것들 중 revision number가 가장 큰 놈을 사용하게 됨.

drwxrwxr-x 3 chyi chyi 4096 12월 28 20:26 linux-ti-staging-4.1
drwxrwxr-x 2 chyi chyi 4096 12월 29 11:27 linux-ti-staging-4.4

kernel patch와 config file(defconfig)은 이 디렉토리(linux-ti-staging-4.4)에 위치하게 됨.

이러한 내용을 안 상태에서, Yocto 내에서 실제  kernel을 build하는 곳을 찾아 보면 다음과 같음.
tmp/work/beaglebone-poky-linux-gnueabi/linux-ti-staging/4.4.19+gitAUTOINC+e581bb1cac-r22a

그림 1.6 kernel source code & build 디렉토리 위치

위의 디렉토리 내용 중, 몇가지 내용을 확인해 보면 다음과 같음.
a) defconfig : kernel config
b) git 디렉토리: Linux source(patch가 있다면 적용된 내용)
c) build 디렉토리: build output이 위치함. 이 디렉토리 아래의 .config가 실제 적용된 kernel config 임.

3) kernel config 변경 후 저장하기
bitbake -c menuconfig virtual/kernel
   => config 변경 후, 저장하면 tmp/work/beaglebone-poky-linux-gnueabi/linux-ti-staging/4.4.19+gitAUTOINC+e581bb1cac-r22a/build/.config가 갱신됨.

bitbake -c savedefconfig virtual/kernel
  => menuconfig에서 변경한 내용(.config)을 같은 디렉토리(build) 아래에 defconfig 파일로 저장(불필요한 내용 제거)한다. 
  => 따라서, 추후 변경한 내용을 반영하여, clean build를 진행하고자 한다면, 이 파일(defconfig)을 meta-ti/recipes-kernel/linux/linux-ti-staging-4.4/defconfig에 복사해 주면 된다.

$ bitbake -c cleansstate virtual/kernel && bitbake virtual/kernel
  => clean build를 진행한다. 앞서 defconfig가 제대로 저장되었다면, 이 내용을 기반으로 .config를 생성한 후, build를 진행하게 된다.

<여기서 잠깐 2> yocto project 외부에서 kernel 작업하기 - manual building
Yocto 내에서 kernel  관련 작업을 진행하는 것은 솔직히 매우 불편하다. 따라서 위에서 사용하는 kernel source & cross-toolchain을 별도로 내려 받아 작업하는 방법을 소개해 보도록 하겠다.

1) Yocto에서 사용하는 cross-toolchain 준비하기
conf/local.conf에서 아래 내용을 수정(64bit Host PC 기준)한다. 이후 아래 명령을 수행한다.
SDKMACHINE = "x86_64"

$ source oe-init-build-env build
$ bitbake -c populate_sdk core-image-sato
   => sdk installer를 build한다. 이것도 시간이 매우 오래 걸림.
   => build가 성공하면, 아래 위치에 sdk installer가 위치하게 될 것임.
tmp/deploy/sdk/poky-glibc-x86_64-core-image-minimal-armv7ahf-neon-toolchain-2.1.1.sh

이 script를 실행하여, 아래와 같이 yocto toolchain을 설치(/opt/poky/2.1.1 디렉토리 아래)하도록 하자.
그림 1.7 Yocto toolchain 설치

이 명령 실행 결과, 아래 위치에 toolchain이 설치되었다.
---------------------------------------------------------------------------------------------------------------
chyi@earth:/opt/poky/2.1.1$ ls -la
합계 64
drwxr-xr-x 3 root root  4096 12월 29 15:38 .
drwxr-xr-x 3 root root  4096 12월 29 15:37 ..
-rw-r--r-- 1 root root  3893 12월 29 15:38 environment-setup-armv7ahf-neon-poky-linux-gnueabi
-rw-r--r-- 1 root root 44645 12월 29 15:38 site-config-armv7ahf-neon-poky-linux-gnueabi
drwxr-xr-x 4 root root  4096 12월 29 15:28 sysroots
-rw-r--r-- 1 root root   121 12월 29 15:38 version-armv7ahf-neon-poky-linux-gnueabi
---------------------------------------------------------------------------------------------------------------

아래 3절에서 실제로 kernel을 build하기 전에 toolchain path를 지정해 주어야 하는데, 이때 녹색으로 표시된 명령이 사용되게 된다.

2) linux kernel source 내려 받기(Yocto에서 사용하는 내용과 동일한 version)
kernel source를 내려 받기 위해서는 kernel recipe 파일을 먼저 확인해 보아야 한다.
meta-ti/recipes-kernel/linux/linux-ti-staging_4.4.bb

그림 1.8 kernel recipe 파일 내용

위의 내용을 토대로 kernel을 내려 받은 후, branch를 변경(위의 recipe에 표시된 대로) 하도록 하자.
git clone git://git.ti.com/ti-linux-kernel/ti-linux-kernel.git
$ cd ti-linux-kernel
$ git checkout -b ti-lsk-linux-4.4.y origin/ti-lsk-linux-4.4.y

이후, kernel 관련 patch가 있다면, 이를 모두 적용한다.
patch 파일 위치: meta-ti/recipes-kernel/linux/linux-ti-staging-4.4
$ git am meta-ti/recipes-kernel/linux/linux-ti-staging-4.4/*.patch

3) kernel build 하기
자, 그럼 이제 부터 kernel을 build해 보도록 하자. 먼저, yocto에 정의되어 있는 defconfig를 .config로 복사해 온다.
$ cp meta-ti/recipes-kernel/linux/linux-ti-staging-4.4/defconfig  ti-linux-kernel/.config
$ make ARCH=arm menuconfig

다음으로, 앞서 2절에서 만들어 둔, 아래 명령을 실행하여 toolchain path를 설정하자.

source /opt/poky/2.1.1/environment-setup-armv7ahf-neon-poky-linux-gnueabi
   => 이 파일의 내용을 살펴 보면, export 명령을 써서 compile 환경을 지정하는 것 밖에 없다. 
   => ARM gcc 명이 arm-poky-linux-gnueabi-gcc 인 것을 알 수 있다.
   => 위 명령을 실행하거나, (익히 알고 있는 것 처럼)개별적으로 설정해 주거나 하면 될 것이다.

주의) 이걸 먼저 설정할 경우,  menuconfig가 안되는 문제가 있었다.

마지막으로 kernel, module, dtb file을 build해 보면 된다.
make LOCALVERSION= -j8 zImage
   => kernel을 build한다.

make LOCALVERSION= -j8 modules
   => kernel module을 build한다.

make am335x-boneblack.dtb
   => dtb file을 생성한다.

Tip) bitbake -c devshell virtual/kernel 명령을 실행하면, kernel source directory(tmp/work-shared/beaglebone/kernel-source)로 이동한 상태에서 새로운 terminal 창이 뜨게 되는데, 이 상태에서 kernel build를 하려면, 앞서 설명한 바와 같이 toolchain path를 지정하고, make 명령을 불러 주면 된다.
source /opt/poky/2.1.1/environment-setup-armv7ahf-neon-poky-linux-gnueabi
make -j8 zImage
$ make -j8 modules
make am335x-boneblack.dtb

<여기서 잠깐 3> yocto project 내부/외부에서 u-boot 작업하기
Yocto project에서 u-boot bootloader를 별도로 build하는 절차를 소개하면 다음과 같다.

1) 내부에서 작업하기
bitbake virtual/bootloader
  => u-boot을 build하기

bitbake -c cleansstate virtual/bootloader
  => build한 내용을 clean하기

u-boot 설정과 관련한 내용은 그림 1.2(meta-ti/conf/machine/include/ti33x.inc)를 참조하면 된다.

PREFERRED_PROVIDER_virtual/bootloader = "u-boot-ti-staging"

2) 외부에서 작업하기
위의 내용을 토대로 u-boot recipe 파일을 찾아 보면 다음과 같다.

chyi@earth:~/IoT/BBB/yocto_fe/meta-ti/recipes-bsp/u-boot$ ls -la
합계 24
drwxrwxr-x  2 chyi chyi 4096 12월 29 11:16 .
drwxrwxr-x 47 chyi chyi 4096 12월 28 20:27 ..
-rw-rw-r--  1 chyi chyi  492 12월 28 20:27 u-boot-ti-staging_2014.07.bb
-rw-rw-r--  1 chyi chyi 2621 12월 28 20:27 u-boot-ti-staging_2015.07.bb
-rw-rw-r--  1 chyi chyi 3203 12월 28 20:27 u-boot-ti-staging_2016.05.bb

그림 1.9 u-boot recipe 파일 내용

위의 u-boot recipe 파일 내용을 참조하여, u-boot source를 download한 후, build를 진행해 보도록 하자.

$ git clone git://git.ti.com/ti-u-boot/ti-u-boot.git
  => u-boot source를 내려 받는다.
$ cd ti-u-boot
git checkout -b ti-u-boot-2016.05 2f757e5b2c6b260c647a8a1bb295537f07c3a8b9
   => branch를 ti-u-boot-2016.05로 변경한다.

source /opt/poky/2.1.1/environment-setup-armv7ahf-neon-poky-linux-gnueabi
   => yotco toolchain path를 지정한다.

make am335x_boneblack_config
   => beaglebone black용 configuration을 적용한다.

make -j8
   => compile을 한다.
  ------------------------------------------------------------------
  ...
  MKIMAGE u-boot.img
  CC      spl/drivers/usb/musb-new/musb_host.o
  CC      spl/drivers/usb/musb-new/musb_uboot.o
  LD      spl/lib/built-in.o
  LD      spl/drivers/watchdog/built-in.o
  CC      spl/drivers/usb/musb-new/musb_dsps.o
  LD      spl/drivers/usb/musb-new/built-in.o
  LD      spl/drivers/built-in.o
  LD      spl/u-boot-spl
  OBJCOPY spl/u-boot-spl-nodtb.bin
  COPY    spl/u-boot-spl.bin
  MKIMAGE MLO
------------------------------------------------------------------

$ make distclean
  => build 이전 초기 상태로 만들고자 할 때  사용함.

==============================================================

2. BuildRoot Download & Build
다음으로, BeagleBoard를 위한 BuildRoot source code를 내려 받아 build해 보도록 하자. 우선 아래 site에서 buildroot-2014.08.tar.gz를 내려 받도록 하자. 최신 BuildRoot로도 가능할 듯 보이나, 편의상 아래 site의 내용을 사용하기로 하자.



$ ~/IoT/BBB
$ tar xvzf buildroot-2014.08.tar.gz
$ cd buildroot-2014.08
make beaglebone_defconfig
   => beaglebone을 configuration을 적용한다.

make menuconfig
   => 편의상, 아래 세가지 내용을 수정(변경)한다.

   --------------------------------------------------------------
   Toolchain --->
            C library (glibc)  ---> 

   Kernel --->

             Kernel binary format (uImage)  --->

   Filesystem images --->

             ext2/3/4 variant (ext4)  --->
  --------------------------------------------------------------

$ make
   => build를 진행한다.

<결과물>
그림 2.1 Buildroot build 결과 파일 


3. 부팅용 SD card 만들기
지금 부터는 앞서 1, 2절에서 만든 image를 SD card에 복사하여, 부팅 가능하도록 만드는 과정을 정리해 보도록 하겠다.
먼저 아래 그림과 같이 micro SD card(4GB) 1개와 card reader(Ubuntu에서 동작 가능하도록 하기 위해 필요함)를 준비하기로 하자.


그림 3.1 microSD(우측) 카드와 card readder(USB type)


$ sudo fdisk /dev/sdb    <= fdisk를 시작, 사전에 dmesg로 SD card 장치를 확인해 두자.

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p   <= 현재 파티션 정보를 출력하자.
Disk /dev/sdb: 3.7 GiB, 3965190144 bytes, 7744512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x61d9b02b

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1  *     8192 6963199 6955008  3.3G 83 Linux

Command (m for help): d     <= 기존에 만들어져 있는 파티션을 제거하자.
Selected partition 1
Partition 1 has been deleted.

Command (m for help): p
Disk /dev/sdb: 3.7 GiB, 3965190144 bytes, 7744512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x61d9b02b

Command (m for help): n   <= 새로운 첫번째 파티션(크기: 32MB)을 만들자.
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-7744511, default 2048): <Enter>
Last sector, +sectors or +size{K,M,G,T,P} (2048-7744511, default 7744511): +32M

Created a new partition 1 of type 'Linux' and of size 32 MiB.

Command (m for help): p
Disk /dev/sdb: 3.7 GiB, 3965190144 bytes, 7744512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x61d9b02b

Device     Boot Start   End Sectors Size Id Type
/dev/sdb1        2048 67583   65536  32M 83 Linux

Command (m for help): n   <= 나머지 영역 전체를 사용하는 두번째 파티션을 만들자.
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (67584-7744511, default 67584):
Last sector, +sectors or +size{K,M,G,T,P} (67584-7744511, default 7744511): <Enter>

Created a new partition 2 of type 'Linux' and of size 3.7 GiB.

Command (m for help): p
Disk /dev/sdb: 3.7 GiB, 3965190144 bytes, 7744512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x61d9b02b

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048   67583   65536   32M 83 Linux
/dev/sdb2       67584 7744511 7676928  3.7G 83 Linux

Command (m for help): a   <= 첫번째 파티션을 bootable(active) 상태로 설정하자.
Partition number (1,2, default 2): 1

The bootable flag on partition 1 is enabled now.

Command (m for help): t     <= 첫번째 파티션의 type을 Win95 FAT32로 변경하자.
Partition number (1,2, default 2): 1
Partition type (type L to list all types): c

Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.

Command (m for help): p
Disk /dev/sdb: 3.7 GiB, 3965190144 bytes, 7744512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x61d9b02b

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1  *     2048   67583   65536   32M  c W95 FAT32 (LBA)
/dev/sdb2       67584 7744511 7676928  3.7G 83 Linux

Command (m for help): w    <= 지금까지 설정한 내용을 저장하고 fdisk를 종료하자.
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

$ sudo mkfs.vfat -n "BOOT" /dev/sdb1   <= 첫번째 파티션을 DOS format(vfat) 하자.
mkfs.fat 3.0.28 (2015-05-16)

$ sudo mkfs.ext4 -L "ROOT" /dev/sdb2   <= 두번째 파티션을 ext4 format 하자.
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 959616 4k blocks and 240000 inodes
Filesystem UUID: 8f110843-fb0d-422e-89a9-7a3ea8a3494c
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                          
Writing inode tables: done                          
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done


$ sudo mount /dev/sdb1 /media/chyi/BOOT/   <= 첫번째 파티션을 mount 한다.
$ sudo mount /dev/sdb2 /media/chyi/ROOT/   <= 두번째 파티션을 mount 한다.


$ cd  .../poky/build_bbb/tmp/deploy/images/beaglebone
   => yocto의 output 디렉토리로 이동한다.
   => yocto 대신, buildroot의 결과물(outout/images 디렉토리)을 이용해도 된다.

$ sudo cp ./MLO /media/chyi/BOOT/
$ sudo cp u-boot.img /media/chyi/BOOT/
$ sudo cp ./uImage /media/chyi/BOOT/
$ sudo cp ./am335x-boneblack.dtb /media/chyi/BOOT/
$ sudo tar -xf ./core-image-sato-beaglebone.tar.bz2 -C /media/chyi/ROOT/

주의) core-image-sato-beaglebone.tar.bz2 내(boot/ 디렉토리)에는 이미 uImage와 dtb file이 포함되어 있으나, 여기서는 편의상 첫번째 파티션에 uImage, dtb 파일을 복사하고, 이 파일을 이용하여 부팅하도록 하겠다.

$ ls -l /media/chyi/BOOT/
합계 5776
-rwxr-xr-x 1 root root   69868 12월 27 18:11 MLO
-rwxr-xr-x 1 root root  403156 12월 27 18:11 u-boot.img
-rwxr-xr-x 1 root root 5405096 12월 27 18:12 uImage
-rwxr-xr-x 1 root root   31516 12월 27 18:12 am335x-boneblack.dtb

$ sudo vi /media/chyi/BOOT/uEnv.txt
   => u-boot setenv 설정을 대신하여, uEnv.txt 파일을 만들도록 하자.


bootargs=console=ttyO0,115200n8 root=/dev/mmcblk0p2 mem=128M rootwait
bootcmd=mmc rescan; fatload mmc 0 0x82000000 uImage;  fatload mmc 0 0x80f00000 am335x-boneblack.dtb; bootm 0x82000000 - 0x80f00000
uenvcmd=boot

참고) u-boot 환경 변수는 setenv 명령으로 지정할 수 있으나, 위와 같이 uEnv.txt 파일을 이용하여 지정할 수도 있다. 이 경우, 이미 setenv로 지정된 동일한 환경 변수가 있다면, uEnv.txt의 내용으로 overring된다.

=== 여기서 잠깐 ! u-boot 명령 소개================================================
fatload mmc 0:1 0x82000000 uImage
  => fatload는 SD card 상의 FAT file system으로 format된 파티션으로 부터 file을 읽어드리는 명령임.
  => 사용법: fatload <interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]
  => 0:1은 first device의 first partition을 의미함(partition은 1부터 시작함)
  => 정리하자면, 이 명령은 mmc device의 첫번째 partition에 있는 uImage 파일을 RAM의 0x82000000 번지로 loading함을 의미함.

bootm 0x82000000 - 0x80f00000
   => bootm명령 사용법: bootm [address of kernel] [address of ramdisk: filesize] paddress of dtb]
   => RAM에 올려져 있는 kernel(uImage), ramdisk rootfs, dtb 등을 이용하여 실제 booting을 시도하는 명령임.
   => ramdisk rootfs는 사용하지 않으므로, 그 자리에 '-' 를 대신 입력해 준다. 안그러면, dtb를 ramdisk로 오해할 수 있으니 ...
========================================================================

$ sudo umount /dev/sdb1
$ sudo umount /dev/sdb2
   => 앞서 실행한 mount 명령을 해제한다.


4. SD card로 부팅하기
3절에서 준비한 SD card를 BeagleBone Black에 삽입한 후, 부팅을 시도해 보도록 하자.

그림 4.1 microSD card를 장착한 BeagleBone Black


그림 4.2 SD card를 이용하여 부팅하는 모습 


그림 4.3 부팅 후, ps 실행 모습 

참고) BeagleBone Black는 eMMC(MMC1), microSD(MMC0), UART, USB 등으로 부팅이 가능하다. 자세한 사항은 참고 문헌 [3]을 참조하기 바란다.

그림 4.4 BeagleBone Boot Configuration


이상으로 Yocto Project와 BuildRoot를 BeagleBone Black에 적용하는 과정을 간략히 정리해 보았다. BeagleBone Black에 관한 추가 사항은 이전 post 내용(2년전에 올린 내용이긴 하지만)을  참조해 보기 바란다.



References
1. Using Yocto Project with BeagleBone Black, PACKT Publishing.
2. http://processors.wiki.ti.com/index.php/AM335x_U-Boot_User's_Guide
3. BeagleBone Black System Reference Manual, beagleboard.org
4. yocto-labs.pdf - Free Electrons.
5. http://www.jumpnowtek.com/beaglebone/Working-on-the-BeagleBone-kernel.html

Slowboot

댓글 5개: