2013년 9월 25일 수요일

Bootrom & Bootloader

Bootrom

Bootrom (or Boot ROM) is a small piece of mask ROM or write-protected flash embedded inside the processor chip. It contains the very first code which is executed by the processor on power-on or reset. Depending on the configuration of some strap pins or internal fuses it may decide from where to load the next part of the code to be executed and how or whether to verify it for correctness or validity. Sometimes it may contain additional functionality, possibly usable by user code during or after booting. Some examples:
  • iPhone boot ROM. Embedded in the mask ROM and can't be modified. Loads the next stage boot loader from flash or USB (in DFU mode) and verifies its signature using built-in RSA implementation. Also provides accelerated decryption functions for the next stage bootloader.
  • TI's OMAP4 boot ROM. Can load user code from flash (NOR, NAND, OneNAND), external memory, SD/MMC, USB or UART. Boot order and options are set by strap (SYSBOOT) pins. Provides some functionality for later stages (cache/TLB management etc.)
  • NXP's LPCxxxx series Boot ROM. Placed in a hidden portion of the internal flash which is mapped at 0 on power-on. Implements CRP (code read protection), ISP (In-System Programming) which allows to upload and flash new code over UART. If a valid user code is in flash (needs to have proper checksum), maps it to 0 and jumps to it. A part of bootrom remains mapped to provide IAP (In-Application Programming) and some other services.

Bootloader

Bootloader is responsible for finding and loading the final OS or firmware which is supposed to run on the chip. One main difference from bootrom is that it's usually in writable flash and can be replaced or upgraded.
Sometimes bootrom can perform the job of the bootloader. For example, OMAP's bootrom is complex enough (it can parse FAT32!) that you can probably have it load and start a Linux kernel directly.
However, in many cases a separate bootloader is used, either because the bootrom is not capable enough (or absent), or because extra flexibility is needed. It can be very simple (load kernel from a fixed flash location in RAM and jump to it), or can be much more complicated. For example, U-Boot is a like a mini-OS by itself - it has a console, some commands, allows you break the boot process and e.g. modify the kernel command line arguments or even load the kernel from a different location (SD/MMC or USB), run some tests and so on.
Bootloaders are usually used when you have a more or less complex OS which may need some set up before it can be started. Smaller microcontrollers like NXP's LPC series usually use a monolithic firmware so they can get by without it (however, there may be custom bootloaders for them too).
On the very simplest chips there may be no boot ROM or boot loader at all - they just try to fetch and execute instructions from a fixed startup address. In fact, most x86 chips to this day work like this - they just start executing code at FFFFFFF0 with the expectation that the chipset has mapped the BIOS flash chip there. Here, you can say that BIOS is the bootloader (though it also provides services to the OS, similar to bootrom).

How to build Nexus 7 2013

조만간 Nexus 7 2013 버전을 만져 볼 수 있을 것 같습니다.

몇 가지 테스트를 위해 Binary Build가 필요할 듯하여 소스 인출 및 build 방법을 정리해 봅니다.

Tag를 확인해 보니 android-4.3_r3.1까지 보입니다.
 * [new tag]         android-4.3_r2.1_ -> android-4.3_r2.1_
 * [new tag]         android-4.3_r2.1__ -> android-4.3_r2.1__
 * [new tag]         android-4.3_r2.2 -> android-4.3_r2.2
 * [new tag]         android-4.3_r2.3 -> android-4.3_r2.3
 * [new tag]         android-4.3_r2_ -> android-4.3_r2_
 * [new tag]         android-4.3_r3 -> android-4.3_r3
 * [new tag]         android-4.3_r3.1 -> android-4.3_r3.1

Nexus Factory Image (https://developers.google.com/android/nexus/drivers) 버전과
AOSP (http://source.android.com/source/build-numbers.html) source code Tag 를 참조해서 android-4.3_r3를 사용하기로 합니다.


Source Code Tags and Builds


JSR78Dandroid-4.3_r2Nexus 7 (deb)
JSS15Jandroid-4.3_r2.1Jelly Bean version, Nexus 7 (flo/deb)
JSS15Qandroid-4.3_r2.2Latest Jelly Bean version, Nexus 7 (flo/deb)
JLS36Candroid-4.3_r3Latest Jelly Bean version, Nexus 7 (deb)

Nexus 7 (2013) 버전은 Wi-Fi 전용 모델과 LTE 모델이 있습니다.
LTE 모델은 "deb" 를 WiFi 전용 모델은 "flo" 를 사용하면 됩니다.

$ repo init -u https://android.googlesource.com/platform/manifest
$ repo init -t https://android.googlesource.coom/platform/manifest -b android-4.3_r3
$ repo sync

Android Plain source Downlod 이후에 Hardware지원을 위한 Binary를 Download 합니다.

+ kitkat 발표 후 Android 4.4 버전을 위한 binary 도 이미 올라와 있습니다. 

Nexus 7 (Mobile) binaries for Android 4.3.1 (JLS36I)

Hardware ComponentCompanyDownloadMD5 ChecksumSHA-1 Checksum
Audio, SensorsASUSLinkfdaa2bb19f819e6d27a372a1a958960040d4854a61b5b2d2dc6a2c3877382f92d7b5ccf6
NFCBroadcomLink002ccc76c9512447f4641bf7cfaa003eb2a887b02bd78b4730614b7057d3f6dfca490fc8
Graphics, Camera, GPS, Wi-Fi, Bluetooth, Sensors, Media, DRM, DSP, USBQualcommLinka029a7253c7c657d880ddfd0247e2cfbdc5fb716a1c7f897fd3779b445157c99abb10d31
위 표의 Download의 Link를 통해 *.tgz 파일들을 다운로드 받은 후 압축을 해제하면 extract-*.sh 파일들이 나옵니다.

ex) extract-asus-deb.sh, extract-broadcom-deb.sh, extract-qcom-deb.sh

해당 script 를 실행 후  "I ACCEPT" 입력 해 주시면 /vendor 디렉토리가 자동으로 생성됩니다.

$ ./extract-asus-deb.sh [enter]

The license for this software will now be displayed.
You must agree to this license before using this software.

Press Enter to view the license

Type "I ACCEPT" if you agree to the terms of the license: I ACCEPT

vendor/
vendor/asus/
vendor/asus/deb/
vendor/asus/deb/proprietary/
vendor/asus/deb/proprietary/libAKM.so
vendor/asus/deb/proprietary/apns-conf.xml
vendor/asus/deb/proprietary/libacdbdata.so
vendor/asus/deb/BoardConfigVendor.mk
vendor/asus/deb/device-partial.mk
vendor/asus/deb/device-vendor.mk
vendor/asus/deb/BoardConfigPartial.mk

Files extracted successfully.

여기까지 하면 Nexus 7을 빌드할 준비가 되었습니다.

$ cd android-4.3_r3
$ source ./build/envsetup.sh
$ lunch aosp_deb-userdebug
$ make -j<CPU_PROCESSOR_NUM> 

바이너리 빌드 후 다운로드는 fastboot tool을 이용하면 됩니다.
- 참조 : http://source.android.com/source/building-devices.html

Booting into fastboot mode


DeviceKeys
hammerheadPress and hold both Volume Up and Volume Down, then press and hold Power
floPress and hold Volume Down, then press and hold Power
debPress and hold Volume Down, then press and hold Power

Unlocking the bootloader


The bootloader is locked by default. With the device in fastboot mode, the bootloader is unlocked with
$ fastboot oem unlock

The bootloader can be locked back with
$ fastboot oem lock

Flashing a device


Set the device in fastboot mode if necessary (see above).
$ fastboot -w flashall
Note that filesystems created via fastboot on Motorola Xoom aren't working optimally, and it is strongly recommended to re-create them through recovery
$ adb reboot recovery