presentasi u boot

32
Chapter 9. Setting Up the Bootloader 9.5 U-Boot By : Lutfi Rozaqi

Upload: lutfirozaqi

Post on 29-Sep-2015

236 views

Category:

Documents


5 download

DESCRIPTION

Presentasi U Boot untuk menjelaskan bootloader jenis U-Boot

TRANSCRIPT

A Top-Level View of Computer Function and Interconnection

Chapter 9. Setting Up the Bootloader9.5 U-BootBy : Lutfi Rozaqi1U-Boot

U-Boot adalah bootloader yang berbasis dari PPCBoot and ARMBoot.

U-Boot merupakan bootloader untuk target sistem yang fleksibe disebabkan dapat melakukan :

booting kernel menggunakan BOOTP/DHCP, TFTP, dan NFSbooting kernel menggunakan RAM Diskbooting kernel dari CompactFlash

U-Boot juga support pada arsitektur prosesor x86, PowerPC, dan ARM.U-Boot1. Mengkompilasi dan Menginstall U-boot Pertama download dan extract U-Boot di direktori berikut (untuk contoh ini, digunakan U-Boot versi 0.2.0) :

$ cd ${PRJROOT}/bootldr/u-boot-0.2.0

Kemudian buat Makefile dari board yang ingin dijadikan target sistem dan build U-Boot dengan perintah berikut (untuk contoh digunakan board TQM860L ) :

$ make TQM860L_config$ make CROSS_COMPILE=powerpc-linux-Berikut file-file yang dihasilkan dari proses kompilasi di atas :

Lalu copy file-file yang dihasilkan oleh kompilasi U-boot ke direktori ${PRJROOT}/images dengan perintah berikut:$ cp System.map ${PRJROOT}/images/u-boot.System.map-0.2.0$ cp u-boot.bin ${PRJROOT}/images/u-boot.bin-0.2.0$ cp u-boot.srec ${PRJROOT}/images/u-boot.srec-0.2.0Bila anda ingin debug U-Boot, copy juga ELF binary dengan perintah :$ cp u-boot ${PRJROOT}/images/u-boot-0.2.0Lalu install host tool yang dihasilkan oleh build U-Boot dengan perintah :$ cp tools/mkimage ${PREFIX}/bin

2. Booting dengan U-BootSetelah U-boot terinstalasi pada target sistem, anda dapat booting ketika sedang terkoneksi pada target. Berikut contoh output boot :

U-Boot 0.2.0 (Jan 27 2003 - 20:20:21) CPU: XPC860xxZPnnD3 at 80 MHz: 4 kB I-Cache 4 kB D-Cache FEC presentBoard: TQM860LDB0A3-T80.201DRAM: 16 MBFLASH: 8 MBIn: serialOut: serialErr: serialNet: SCC ETHERNET, FEC ETHERNETPCMCIA: No Card foundHit any key to stop autoboot: 5

Pada contoh di atas tertulis bahwa apabila anda tidak menekan tombol apapun pada jangka waktu 5 detik maka booting akan dilakukan secara otomatis oleh U-boot sesuai dengan konfigurasi secara default dari U-Boot.3. Menggunakan Environment Variable dari U-BootSetelah U-Boot bekerja, anda dapat mengkonfigurasinya dengan men-setting environment variable yang tepat. Untuk melihat value dari environment variable gunakan perintah printenv. Berikut contoh variabel environment :

=> printenv bootdelay=5baudrate=115200loads_echo=1serial#= ...ethaddr=00:D0:93:00:05:E3netmask=255.255.255.0ipaddr=192.168.172.10serverip=192.168.172.50clocks_in_mhz=1stdin=serialstdout=serialstderr=serial Environment size: 791/16380 bytesBerikut adalah contoh perintah untuk add beberapa environment variable ke control module :

=> setenv rootpath /home/karim/ctrl-rootfs=> setenv kernel_addr 40100000=> setenv nfscmd setenv bootargs root=/dev/nfs rw nfsroot=\$(serverip):\$(rootpath) ip=\$(ipaddr):\$(serverip):\$(gatewayip):\$(netmask) :\$(hostname) ::off panic=1\;bootm \$(kernel_addr)=> setenv bootcmd run nfscmd

Dalam contoh ini, U-Boot di-setting untuk boot kernel pada alamat 0x40100000 dan mount target sistem rootfilesystem menggunakan NFS. Berikut bagaimana contoh bagaimana nfscmd seteleh dibaca oleh U-Boot :

=> printenv nfscmdnfs2cmd=setenv bootargs root=/dev/nfs rw nfsroot=$(serverip):$(rootpath)ip=$(ipaddr):$(serverip):$(gatewayip):$(netmask):$(hostname)::off panic=1;bootm $(kernel_addr)Agar setting-an variabel environment tetap ada, maka environment variable harus di-save pada flash. Berikut perintah yang digunakan dan contoh hasil proses perintah :

=> saveenvSaving Enviroment to Flash...Un-Protected 1 sectorsErasing Flash.... doneErased 1 sectorsWriting to Flash... doneProtected 1 sectors

Apabila ingin menghapus variabel, gunakan command setenv pada variabel tanpa menyediakan value. Berikut contohnya :

=> setenv RAMDisk_addr 40500000=> printenv RAMDisk_addrRAMDisk_addr=40500000 => setenv RAMDisk_addr=> printenv RAMDisk_addr## Error: "RAMDisk_addr" not defined 4. Membuat Boot ScriptU-Boot variable environment dapat digunakan untuk membuat bootscript. Bootscript sebenarnya variable environment yang berisi beberapa perulangan command dari U-Boot. Dengan mengkombinasikan command run dan operator ; , anda dapat menjalankan bootscript.

=> run OTHER_BOOT_SCRIPT

Script adalah fitur dari U-Boot yang sangat berguna dan anda harus menggunakannya ketika anda ingin menjalankan beberapa task di U-Boot secara otomatis. 5. Menyiapkan Binary ImagesSebab flash tidak dibuat seperti filesystem dan tidak membawa file header apapun, image binary yang di-download ke target harus membawa header untuk U-Boot untuk mengenali isinya dan tahu bagaimana untuk me-load-nya. Kegunaan mkimage yang diinstalasi tadi di-package dengan U-Boot untuk hal ini. Dia membawa informasi yang dibutuhkan oleh U-Boot untuk binary image ketika meng-attach checksum unutk verifikasi.

Contoh bagaimana membuat U-Boot image dari kernel 2.4.18 yang dikompilasi untuk control module :

$ cd ${PRJROOT}/images$ mkimage -n '2.4.18 Control Module' \> -A ppc -O linux -T kernel -C gzip -a 00000000 -e 00000000 \> -d vmlinux-2.4.18.gz vmlinux-2.4.18.imgImage Name: 2.4.18 Control ModuleCreated: Wed Feb 5 14:19:08 2003Image Type: PowerPC Linux Kernel Image (gzip compressed)Data Size: 530790 Bytes = 518.35 kB = 0.51 MBLoad Address: 0x00000000Entry Point: 0x00000000RAM disk image dapat diproses dengan cara yang sama, berikut contohnya :

$ mkimage -n 'RAM disk' \> -A ppc -O linux -T ramdisk -C gzip \> -d initrd.bin initrd.bootImage Name: RAM diskCreated: Wed Feb 5 14:20:35 2003Image Type: PowerPC Linux RAMDisk Image (gzip compressed)Data Size: 470488 Bytes = 459.46 kB = 0.45 MBLoad Address: 0x00000000Entry Point: 0x00000000

Kita juga dapat membuat multi-type image yang menggabungkan kernel image dan RAM disk. Dalam hal ini, file-file yang dimasukkan harus di-list secara bersamaan menggunakan colon separator, berikut contohnya :

$ mkimage -n '2.4.18 Ctrl and Initrd' \> -A ppc -O linux -T multi -C gzip -a 00000000 -e 00000000 \> -d vmlinux-2.4.18.gz:initrd.bin \> vmlinux-2.4.18-initrd.imgImage Name: 2.4.18 Ctrl and InitrdCreated: Wed Feb 5 14:23:29 2003Image Type: PowerPC Linux Multi-File Image (gzip compressed)Data Size: 1001292 Bytes = 977.82 kB = 0.95 MBLoad Address: 0x00000000Entry Point: 0x00000000Contents: Image 0: 530790 Bytes = 518 kB = 0 MB Image 1: 470488 Bytes = 459 kB = 0 MB

Setelah menyiapkan image dengan mkimage, image siap digunakan oleh U-Boot dan dapat di-download ke target.U-Boot menerima binary image dengan bermacam-macam cara, salah satunya menggunakan image dengan format S-Record dari Motorola. Bila ingin menggunakan format ini, anda harus mengkonversi image yang dihasilkan oleh command mkimage ke format S-Record. Berikut contohnya :

$ powerpc-linux-objcopy -I binary -O srec \> vmlinux-2.4.18-initrd.img vmlinux-2.4.18-initrd.srec6. Booting menggunakan BOOTP/DHCP, TFTP, dan NFSApabila anda telah menkonfigurasi server untuk menyediakan target dengan service DHCP, TFTP, dan NFS, anda dapat boot target sistem anda. Berikut contoh boot ke target sistem :

=> bootp BOOTP broadcast 1DHCP client bound to address 192.168.172.10ARP broadcast 1TFTP from server 192.168.172.50; our IP address is 192.168.172.10Filename '/home/karim/vmlinux-2.4.18.img'.Load address: 0x100000Loading: ################################################### ...doneBytes transferred = 530854 (819a6 hex)Command bootp menghasilkan request yang disahut oleh server DHCP. Menggunakan sahutan dari server DHCP, U-Boot mengkontak server TFTP dan memperoleh file image vmlinux-2.4.18.img yang diletakkan pada alamat 0x00100000 di RAM. Anda dapat memeriksa informasi header image menggunakkan command iminfo, berikut contohnya :

=> imi 00100000 ## Checking Image at 00100000 ... Image Name: 2.4.18 Control Module Created: 2003-02-05 19:19:08 UTC Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 530790 Bytes = 518.3 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OKSeperti yang terterea pada contoh di atas, informasi yang dicetak oleh iminfo pada target sama dengan yang dicetak mkinfo pada host. String ok menyatakan bahwa image telah di-download dan kita dapat mem-boot-nya , berikut contohnya :

=> bootm 00100000 ## Booting image at 00100000 ... Image Name: 2.4.18 Control Module Created: 2003-02-05 19:19:08 UTC Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 530790 Bytes = 518.3 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OK Uncompressing Kernel Image ... OKLinux version 2.4.18 (karim@Teotihuacan) (gcc version 2.95.3 20010315 ...On node 0 totalpages: 4096zone(0): 4096 pages.zone(1): 0 pages.zone(2): 0 pages.Kernel command line: root=/dev/nfs rw nfsroot= ...Decrementer Frequency: 5000000Calibrating delay loop... 79.66 BogoMIPS ...VFS: Cannot open root device "" or 02:00Please append a correct "root=" boot optionKernel panic: VFS: Unable to mount root fs on 02:00 Rebooting in 180 seconds..Dalam hal ini kernel panic terjadi disebabkan karena tidak dapat menemukan root filesystem. Untuk menyelesaikan masalah ini, kita harus menggunakan variabel environment untuk membuat boot script untuk memberikan boot option yang tepat ke kernel. Berikut contohnya :

=> setenv bootpnfs bootp\; setenv kernel_addr 00100000\; run nfscmd=> printenv bootpnfsbootpnfs=bootp; setenv kernel_addr 00100000; run nfscmd=> setenv bootcmd run bootpnfs=> printenv bootcmdbootcmd=run bootpnfs

Apabila anda menggunakan command boot sekarang, U-Boot akan boot seluruhnya dari network. U-Boot akan download kernel melalui TFTP dan mount root filesystem pada NFS. Apabila anda ingin save variabel environment yang baru di-set, gunakan command saveenv sebelum reboot sistem, blia tidak melakukannya maka anda harus set ulang variabel yang sama pada reboot selanjutnya.7. Download Binary Image ke FlashBooting dari network memang baik apabila digunakkan untuk testing dan pengembangan embedded system. Tetapi dalam produksi, target harus memiliki kernel yang tersimpan di flash. Sebelum anda dapat meng-copy kernel image, anda harus memilih flash region dan menghapus flash region untuk kernel yang akan diisikan. Berikut contohnya :

=> erase 40100000 401FFFFFErase Flash from 0x40100000 to 0x401fffff........ doneErased 8 sectors

Cara yang paling simpel untuk menginstalasi kernel ke flash pada target adalah pertama download kernel ke RAM lalu copy kernel ke flash. Anda dapat menggunakan command tftpboot untuk download kernel dari host ke RAM, berikut contohnya :

=> tftpboot 00100000 /home/karim/vmlinux-2.4.18.img ARP broadcast 1TFTP from server 192.168.172.50; our IP address is 192.168.172.10Filename '/home/karim/vmlinux-2.4.18.img'.Load address: 0x100000Loading: ################################################### ...doneBytes transferred = 530854 (819a6 hex)Di samping tftpboot, anda juga dapat menggunakan command loadb untuk download image ke target, berikut contohnya :

=loadb 00100000## Ready for binary (kermit) download ...>Pada step ini, U-Boot tertunda dan anda harus menggunakan terminal emulator ke host untuk mengirim image file ke target. Dalam hal ini, U-Boot diharapkan untuk download data tergantung oleh kermit binary protocol, dan anda harus mengguanklan kermit untuk download binary image ke U-Boot. Setelah proses transfer selesai, U-Boot akan menghasilkan :

## Total Size = 0x000819a6 = 530854 Bytes## Start Addr = 0x00100000

Setelah image berada di RAM, anda dapat meng-copy-nya ke flash :

=> cp.b 00100000 40100000 $(filesize)Copy to Flash... done=> imi 40100000 ## Checking Image at 40100000 ... Image Name: 2.4.18 Control Module Created: 2003-02-05 19:19:08 UTC Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 530790 Bytes = 518.3 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OKSelain itu, daripada anda harus download image dulu ke RAM menggunakkan tftpboot ataun loadb lalu meng-copy ke flash, anda dapat download image secara langsung menggunakan loads. Dalam hal ini, host mengirim image ke target dalam format S-Record. Tetapi dibandingkan kedua metode di atas, men-download S-Record file sangat lambat. Untuk download file S-Record, anda membutuhkan cu terminal emulator untuk transfer ke target, karena terminal emulator lain tidak cocok dengan U-Boot ketika download file jenis ini. Berikut contoh command yang digunakan ketika terkoneksi melalui cu :

=> loads 40100000 ## Ready for S-Record download ...~>vmlinux-2.4.18.srec 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... ... ...176 33177 33178 33179 33180 33181[file transfer complete][connected] ## First Load Addr = 0x40100000## Last Load Addr = 0x401819A5## Total Size = 0x000819A6 = 530854 Bytes## Start Addr = 0x000000008. Booting Menggunakan RAM DiskLangkah pertama dalam booting dari RAM adalah download RAM Disk dari host dan install RAM Disk pada target flash. Banyak command yang sama dengan yang telah diperlihatakan pada bab sebelumnya. Berikut contohnya :

=> tftpboot 00100000 /home/karim/initrd.boot ARP broadcast 1TFTP from server 192.168.172.50; our IP address is 192.168.172.10Filename '/home/karim/initrd.boot'.Load address: 0x100000Loading: ################################################### ...doneBytes transferred = 470552 (72e18 hex)=> imi 00100000 ## Checking Image at 00100000 ... Image Name: RAM disk Created: 2003-02-05 19:20:35 UTC Image Type: PowerPC Linux RAMDisk Image (gzip compressed) Data Size: 470488 Bytes = 459.5 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OK=> printenv filesize filesize=72e18=> imi 40200000 ## Checking Image at 40200000 ... Bad Magic Number=> erase 40200000 402FFFFF Erase Flash from 0x40200000 to 0x402fffff........ doneErased 8 sectors=> cp.b 00100000 40200000 $(filesize) Copy to Flash... done=> imi 40200000 ## Checking Image at 40200000 ... Image Name: RAM disk Created: 2003-02-05 19:20:35 UTC Image Type: PowerPC Linux RAMDisk Image (gzip compressed) Data Size: 470488 Bytes = 459.5 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OKDisebabkan pada contoh kernel telah terinstalasi, boot dapat dilakukan pada kernel yang tersedia di flash dangan RAM Disk yang baru diinstalasi :

=> bootm 40100000 40200000 ## Booting image at 40100000 ... Image Name: 2.4.18 Control Module Created: 2003-02-05 19:19:08 UTC Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 530790 Bytes = 518.3 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OK Uncompressing Kernel Image ... OK## Loading RAMDisk Image at 40200000 ... Image Name: RAM disk Created: 2003-02-05 19:20:35 UTC Image Type: PowerPC Linux RAMDisk Image (gzip compressed) Data Size: 470488 Bytes = 459.5 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OK Loading Ramdisk to 00f2c000, end 00f9edd8 ... OKLinux version 2.4.18 (karim@Teotihuacan) (gcc version 2.95.3 20010 ...On node 0 totalpages: 4096zone(0): 4096 pages.zone(1): 0 pages.zone(2): 0 pages.Kernel command line:Decrementer Frequency: 5000000Calibrating delay loop... 79.66 BogoMIPS ...RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize ...RAMDISK: Compressed image found at block 0 ...VFS: Mounted root (ext2 filesystem). ...9. Booting dari CompactFlash Sebelum booting kernel dari CF card menggunakan U-Boot, anda perlu partisi yang layak dan mem-populate CF card. Gunakan pdisk atau fdisk pada partisi media CF, tergantung pada host anda. Disebabkan U-Boot tidak mengenali disk filesystem apapun, anda membutuhkan beberapa partisi kecil untuk binary image dan satu partisi besar untuk root filesystem.

Untuk contoh digunakan CF card dengan kapasitas 32 MB dengan tiga partisi menggunakan fdisk : dua 2 MB partisi untuk satu kernel yang stabil dan satu kernel untuk eksperimen dan satu 30 MB partisi untuk root filesystem.Untuk copy kernel ke masing-masing partisi mereka, digunakkan command dd. Berikut contohnya :

# dd if=vmlinux-2.4.18.img of=/dev/sda11036+1 records in1036+1 records out# dd if=vmlinux-2.4.18-preempt.img of=/dev/sda21040+1 records in1040+1 records out

Dalam contoh /dev/sda3 diformat menggunakan mke2fs, di-mount pada /mnt/cf dan meng-copy-kan root filesystem pada pada CF card. Setelah itu, masukkan CF card di PCMCIA port menggunakan CF-to-PCMCIA adapter, dan berikut output U-Boot pada saat startup:

U-Boot 0.2.0 (Jan 27 2003 - 20:20:21) CPU: XPC860xxZPnnD3 at 80 MHz: 4 kB I-Cache 4 kB D-Cache FEC presentBoard: TQM860LDB0A3-T80.201DRAM: 16 MBFLASH: 8 MBIn: serialOut: serialErr: serialNet: SCC ETHERNET, FEC ETHERNETPCMCIA: 3.3V card found: SunDisk SDP 5/3 0.6 Fixed Disk Card IDE interface [silicon] [unique] [single] [sleep] [standby] [idle] [low power]Bus 0: OK Device 0: Model: SanDisk SDCFB-32 Firm: vde 1.10 Ser#: 163194D0310 Type: Removable Hard Disk Capacity: 30.6 MB = 0.0 GB (62720 x 512)Hit any key to stop autoboot: 5

Untuk mengambil kernel image dari partisi pada media CF digunakan command diskboot. Berikut contohnya :=> diskboot 00400000 0:1 Loading from IDE device 0, partition 1: Name: hda1 Type: U-Boot Image Name: 2.4.18 Control Module Created: 2003-02-05 19:19:08 UTC Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 530790 Bytes = 518.3 kB Load Address: 00000000 Entry Point: 00000000 => imi 00400000 ## Checking Image at 00400000 ... Image Name: 2.4.18 Control Module Created: 2003-02-05 19:19:08 UTC Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 530790 Bytes = 518.3 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OK Setelah kernel diambil, anda dapat menggunakan command bootm untuk boot kernel tersebut. Boot juga dapat diotomtisasi dengan men-setting variabel environment autostart ke yes, sehingga diskboot akan secara otomatis boot kernel yang diambil. Berikut contohnya :

=> setenv autostart yes => disk 00400000 0:1 Loading from IDE device 0, partition 1: Name: hda1 Type: U-Boot Image Name: 2.4.18 Control Module Created: 2003-02-05 19:19:08 UTC Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 530790 Bytes = 518.3 kB Load Address: 00000000 Entry Point: 00000000Automatic boot of image at addr 0x00400000 ...## Booting image at 00400000 ... Image Name: 2.4.18 Control Module Created: 2003-02-05 19:19:08 UTC Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 530790 Bytes = 518.3 kB Load Address: 00000000 Entry Point: 00000000 Verifying Checksum ... OK Uncompressing Kernel Image ... OKLinux version 2.4.18 (karim@Teotihuacan) (gcc version 2.95.3 ...On node 0 totalpages: 4096 ...10. Meng-update U-BootSecara prinsipnya, untuk update U-Boot kita harus download versi barunya ke target, menghapus firmware versi yang lama, dan meng-copy versi barunya.Berikut contoh cara update U-Boot :

Download U-Boot image ke RAM menggunakan TFTP :

=> tftp 00100000 /home/karim/u-boot.bin-0.2.0ARP broadcast 1TFTP from server 192.168.172.50; our IP address is 192.168.172.10Filename '/home/karim/u-boot.bin-0.2.0'.Load address: 0x100000Loading: #################################doneBytes transferred = 166532 (28a84 hex)

Atau apabila anda tidak memilki TFTP server yang telah di set up, anda dapat gunakan terminal emulator untuk mengirim image :

=> loadb 00100000## Ready for binary (kermit) download ... ## Start Addr = 0x00100000

Sekarang, unprotect flash region (daerah flash) dimana U-Boot ditempatkan sehingga anda dapat menghapusnya (dalam contoh ini, U-boot menempati dareah (region) dari 0x40000000 hingga 0x4003FFFF):

=> protect off 40000000 4003FFFFUn-Protected 5 sectors

Hapus image bootloader yang ada sebelumnya :

=> erase 40000000 4003FFFFErase Flash from 0x40000000 to 0x4003ffff... doneErased 5 sectors

Copy bootloader versi baru ke tempatnya :

=> cp.b 00100000 40000000 $(filesize)Copy to Flash... Done

Hapus variable environment filesize :

=> setenv filesize

Simpan variable environment :

=> saveenvSaving Enviroment to Flash...Un-Protected 1 sectorsErasing Flash.... doneErased 1 sectorsWriting to Flash... doneProtected 1 sectors

Pada step ini image bootloader versi baru telah diinstall dan siap digunakan. Tetapi anda masih tetap menggunakan U-Boot versi lama pada saat sebelum anda memberi command reset untuk restart sistem. Hal ini bertujuan agar apabila terjadi problem pada saat update anda dapat membenahi problem tersebut. Setelah semua step diatas dilakukan, anda dapat restart system :

=> reset U-Boot 0.2.0 (Jan 27 2003 - 20:20:21) CPU: XPC860xxZPnnD3 at 80 MHz: 4 kB I-Cache 4 kB D-Cache FEC presentBoard: TQM860LDB0A3-T80.201DRAM: 16 MBFLASH: 8 MBIn: serialOut: serialErr: serialNet: SCC ETHERNET, FEC ETHERNETPCMCIA: No Card foundHit any key to stop autoboot: 5TERIMA KASIH