新聞中心
在嵌入式開(kāi)發(fā)中,Uboot作為一個(gè)開(kāi)源的引導(dǎo)載入程序,其功能不僅僅是引導(dǎo)系統(tǒng),還可以下載內(nèi)核代碼,配置系統(tǒng)參數(shù),并進(jìn)行其他關(guān)鍵性操作。在實(shí)際項(xiàng)目中,Uboot被廣泛使用,特別是在Linux嵌入式開(kāi)發(fā)領(lǐng)域中。

本文將簡(jiǎn)單介紹如何使用Uboot引導(dǎo)vmlinux。本文概述如下:
1. 準(zhǔn)備工作
2. 下載vmlinux
3. 下載交叉編譯工具鏈
4. 編譯生成Uboot
5. 編寫(xiě)Uboot腳本
6. 運(yùn)行Uboot
7. 結(jié)論
1. 準(zhǔn)備工作
請(qǐng)確保您已經(jīng)安裝了以下開(kāi)發(fā)平臺(tái):
? Ubuntu 16.04 64-bit 操作系統(tǒng)
? TFTP和DHCP服務(wù)器
? 串口終端
? JTAG調(diào)試器
我們將使用這些工具來(lái)下載內(nèi)核代碼、交叉編譯工具鏈和Uboot源代碼,以及執(zhí)行Uboot腳本。
2. 下載vmlinux
接下來(lái),請(qǐng)下載你需要引導(dǎo)的內(nèi)核代碼,比如vmlinux。
3. 下載交叉編譯工具鏈
接下來(lái),你需要下載交叉編譯工具鏈,這個(gè)工具鏈可以幫助你將x86或者其他主機(jī)編譯出來(lái)的代碼編譯成嵌入式設(shè)備可執(zhí)行的代碼。
以ARM平臺(tái)為例,您可能需要下載arm-linux-gcc交叉編譯工具鏈。通過(guò)以下命令下載交叉編譯工具鏈:
sudo apt-get install gcc-arm-linux-gnueabi
4. 編譯生成Uboot
接下來(lái),請(qǐng)下載一個(gè)Uboot源代碼。你需要從Uboot的官方網(wǎng)站上下載最新的源代碼,并使用交叉編譯工具鏈編譯成可執(zhí)行的二進(jìn)制文件。
以ARM平臺(tái)為例,您可以使用以下命令生成Uboot:
$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm distclean
$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm mx6ull_14x14_evk_defconfig
$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm
運(yùn)行上述命令,就可以在Uboot文件夾下生成一個(gè)名為“u-boot.bin”的二進(jìn)制文件。
5. 編寫(xiě)Uboot腳本
接下來(lái),您需要編寫(xiě)一個(gè)Uboot腳本,以便將Uboot拷貝到目標(biāo)設(shè)備上,并引導(dǎo)vmlinux。
一個(gè)簡(jiǎn)單的Uboot腳本可能類(lèi)似于以下內(nèi)容:
tftp 0x202300 /tftpboot/u-boot.bin
nand erase 0 80000
nand write 0x202300 0 80000
tftp 0x300000 /tftpboot/vmlinux.bin
bootm 0x300000
請(qǐng)確保你的腳本中的命令正確,檢查路徑和IP地址是否正確。
6. 運(yùn)行Uboot
現(xiàn)在,您可以將Uboot二進(jìn)制文件和Uboot腳本拷貝到目標(biāo)設(shè)備上,并啟動(dòng)目標(biāo)設(shè)備。具體的啟動(dòng)過(guò)程因設(shè)備而異,可能需要您參考設(shè)備手冊(cè)。
當(dāng)您成功運(yùn)行Uboot,并通過(guò)它引導(dǎo)vmlinux內(nèi)核時(shí),屏幕或串口終端上應(yīng)該顯示出Linux內(nèi)核的啟動(dòng)日志。
7. 結(jié)論
以上介紹了如何使用Uboot引導(dǎo)vmlinux內(nèi)核的簡(jiǎn)易教程。雖然本文提供的是一個(gè)簡(jiǎn)單的例子,但這可以幫助您在實(shí)際嵌入式開(kāi)發(fā)項(xiàng)目中更好地使用Uboot,以便正確引導(dǎo)Linux內(nèi)核并運(yùn)行項(xiàng)目。如果需要做更詳細(xì)和復(fù)雜的操作,還需要進(jìn)一步掌握Uboot的使用和配置。
成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián),建站經(jīng)驗(yàn)豐富以策略為先導(dǎo)10多年以來(lái)專(zhuān)注數(shù)字化網(wǎng)站建設(shè),提供企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),響應(yīng)式網(wǎng)站制作,設(shè)計(jì)師量身打造品牌風(fēng)格,熱線:028-86922220mkimage制作linux內(nèi)核映像 即uImage是怎么制作的
bootm命令是用來(lái)引導(dǎo)經(jīng)過(guò)u-boot的工具mkimage打包后的kernel image的,什么叫做經(jīng)過(guò)u-boot的工具mkimage打包后的kernel image,這個(gè)就要看mkimage的代碼,看看它做了些什么,雖然我很希望大家不要偷懶,認(rèn)真地去看看,但是我知道還是有很多人懶得去做這件,那么我就j將分析mkimage代碼后得到的總結(jié)告訴大家,mkimage做了些什巧梁么,怎么用這個(gè)工具。
mkimage的用法
uboot源代碼的tools/目錄下有mkimage工具,這個(gè)工具可以用來(lái)制作不壓縮或者壓縮的多種可啟動(dòng)映象文件。
mkimage在制作映象文件的時(shí)候,是在原來(lái)的可執(zhí)行映象文件的前面加上一個(gè)0x40字節(jié)的頭,記錄參數(shù)所指定的信息,這樣uboot才能識(shí)別這個(gè)映象是針對(duì)哪個(gè)CPU體系結(jié)構(gòu)的,哪個(gè)OS的,哪種類(lèi)型,加載內(nèi)存中的哪個(gè)位置, 入口點(diǎn)在內(nèi)存的那個(gè)位置以及映象名是什么
root@Glym:/tftpboot# ./mkimage
Usage: ./mkimage -l image
-l ==> list image header information
./mkimage -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file image
-A ==> set architecture to ‘a(chǎn)rch’
-O ==> set operating system to ‘os’
-T ==> set image type to ‘type’
-C ==> set compression type ‘comp’
-a ==> set load address to ‘a(chǎn)ddr’ (hex)
-e ==> set entry point to ‘ep’ (hex)
-n ==> set image name to ‘name’
-d ==> use image data from ‘datafile’
-x ==> set XIP (execute in place)
參數(shù)說(shuō)明:
-A 指定CPU的體系結(jié)構(gòu):
取值 表示的體系結(jié)構(gòu)
alpha Alpha
arm ARM
x86 Intel x86
ia64 IA64
mips MIPS
mips64 MIPS 64 Bit
ppc PowerPC
s390 IBM S390
sh SuperH
sparc SPARC
sparc64 SPARC 64 Bit
m68k MC68000
-O 指定操作系統(tǒng)類(lèi)型正缺,可以取以下值:
openbsd、netbsd、freebsd、4_4bsd、linux、svr4、esix、solaris、irix、sco、dell、ncr、lynxos、vxworks、psos、qnx、u-boot、rtems、artos
-T 指定映象類(lèi)型,可以取以下值舉寬辯:
standalone、kernel、ramdisk、multi、firmware、script、filesystem
-C 指定映象壓縮方式,可以取以下值:
none 不壓縮
gzip 用gzip的壓縮方式
bzip2 用bzip2的壓縮方式
-a 指定映象在內(nèi)存中的加載地址,映象下載到內(nèi)存中時(shí),要按照用mkimage制作映象時(shí),這個(gè)參數(shù)所指定的地址值來(lái)下載
-e 指定映象運(yùn)行的入口點(diǎn)地址,這個(gè)地址就是-a參數(shù)指定的值加上0x40(因?yàn)榍懊嬗袀€(gè)mkimage添加的0x40個(gè)字節(jié)的頭)
-n 指定映象名
-d 指定制作映象的源文件
mkimage
解壓內(nèi)核源碼包,編輯Makefile
設(shè)置 cross_compile:= ;這個(gè)絕對(duì)路徑既上面2.95.3放到的路徑
進(jìn)入內(nèi)核文件夾,執(zhí)行下面命令
# make clean
# make dep
# make
# /bin/arm-linux-objcopy -O binary -S vmlinux linux.bin ;編譯器的絕對(duì)路徑也是上面說(shuō)到的路徑
# gzip linux.bin
下面的比較重要了,主要是u-boot的安裝,這個(gè)在H9200的手冊(cè)上說(shuō)的很不清楚
# tar xzvf u-boot-1.0.0.tar.gz ;解壓u-boot
# cd u-boot-1.0.0
# make distclean
# make at91rm9200dk_config
# make all
然后在/usr/local下建立uboot文件夾將u-boot-1.0.0下的所有文件都復(fù)制到uboot下
# /tools/mkimage -A arm -O linux -C gzip -a 0xe 0xd linux.bin.gz uImage;這里的絕對(duì)路徑是/usr/local/uboot
vmlinux linux.bin linux.bin.gz uImage(uboot制作的image)
mkimage -a -e
-a參數(shù)后是內(nèi)核的運(yùn)行地址,-e參數(shù)后是入口地址。
1)如果我們沒(méi)用mkimage對(duì)內(nèi)核進(jìn)行處理的話,那直接把內(nèi)核下載到0x再運(yùn)行就行,內(nèi)核會(huì)自解壓運(yùn)行(不過(guò)內(nèi)核運(yùn)行需要一個(gè)tag來(lái)傳遞參數(shù),而這個(gè)tag建議是由bootloader提供的,在u-boot下默認(rèn)是由bootm命令建立的)。
2)如果使用mkimage生成內(nèi)核鏡像文件的話,會(huì)在內(nèi)核的前頭加上了64byte的信息,供建立tag之用。bootm命令會(huì)首先判斷bootm xxxx 這個(gè)指定的地址xxxx是否與-a指定的加載地址相同。
(1)如果不同的話會(huì)從這個(gè)地址開(kāi)始提取出這個(gè)64byte的頭部,對(duì)其進(jìn)行分析,然后把去掉頭部的內(nèi)核復(fù)制到-a指定的load地址中去運(yùn)行之
(2)如果相同的話那就讓其原封不同的放在那,但-e指定的入口地址會(huì)推后64byte,以跳過(guò)這64byte的頭部。
QUESTIONS
1. I have built a vmlinux image but I can boot it.
2: The mkimage tool, ARMboot’s tftp command, and the bootm command require
certain load and entry addresses. I’m confused which ones to chose.
ANSWERS
1. I have built a vmlinux image but I can boot it.
ARMboot is designed to boot Images as created by the mkimage tool, that
comes with ARMboot and is automatically built, too. You cannot directly load
the vmlinux image, as it expects a number of prerequisits such as special
register contents etc.
2. The mkimage tool, ARMboot’s tftp command, and the bootm command require
certain load and entry addresses. I’m confused which ones to chose.
—-
Well, there are 3 different addresses:
1. Kernel Load Address. This is the address, where the kernel was linked
to when you built the vmlinux and can be found in arch/arm/Makefile.
The default for it is:
ifeq ($(CONFIG_CPU_32),y)
PROCESSOR = armv
TEXTADDR = 0xC
LDSCRIPT = arch/arm/vmlinux-armv.lds.in
endif
Provide this as “-a” parameter to mkimage.
2. Kernel Entry Point. This is the address, where ARMboot jumps to to
enter the Kernel. It usually is the same as the kernel load address.
Provide this as “-e” parameter to mkimage.
3. The Network Download Address. This is where you download the mkimage
File. This address MUST BE different to the Kernel Load Address, and
should be sufficiently far away to allow ARMboot to relocate the
image to the final Kernel Load Address. Loading to the 5th MB
within the RAM is usually a good idea, eg. if the RAM begins at
0xc, you can do this:
LART # tftp clinux.img
ARP broadcast 1
eth addr: 00:02:03:04:05:06
TFTP from server 192.168.1.1; our IP address is 192.168.1.2
Filename ‘image.img’.
Load address: 0xc
Loading:
##################################################################done
Bytes transferred =(8a7d4 hex)
LART # bootm c
Image Name: Linux 2.4.18
Created: Mon Jun 24 12:00:
Image Type: ARM Linux Kernel Image (gzip compressed)
Data Size:Bytes = 553 kB = 0 MB
Load Address: 0xc
Entry Point: 0xc
Verifying Checksum … OK
Loading Kernel Image … OK
Starting kernel …
如何直接啟動(dòng) vmlinuxz
vmlinux是未壓縮的內(nèi)核,vmlinux是ELF文件,即編譯出來(lái)的最原始的文件。用于kernel-debug,產(chǎn)生system.map符號(hào)表,不能用于直接加載,不可以作為啟動(dòng)內(nèi)核。只是啟動(dòng)過(guò)程中的中間媒體vmlinuz是可引導(dǎo)的、壓縮的內(nèi)核。“vm”代表“VirtualMemory”。Linux支持虛擬內(nèi)存,不像老的操作系統(tǒng)比如DOS有640KB內(nèi)存的限制以是我在CSDN中看到的,可以使用反匯編查看這個(gè)文件:arm-eabi-objdump-dkernel/vmlinux>1.S
關(guān)于uboot 引導(dǎo) vmlinux的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
成都網(wǎng)站建設(shè)選創(chuàng)新互聯(lián)(?:028-86922220),專(zhuān)業(yè)從事成都網(wǎng)站制作設(shè)計(jì),高端小程序APP定制開(kāi)發(fā),成都網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣等一站式服務(wù)。
分享標(biāo)題:使用Uboot引導(dǎo)vmlinux的簡(jiǎn)易教程(uboot引導(dǎo)vmlinux)
轉(zhuǎn)載注明:http://fisionsoft.com.cn/article/dhdchep.html


咨詢
建站咨詢
