使用Uboot引导vmlinux的简易教程 (uboot 引导 vmlinux)

在嵌入式开发中,Uboot作为一个开源的引导载入程序,其功能不仅仅是引导系统,还可以下载内核代码,配置系统参数,并进行其他关键性操作。在实际项目中,Uboot被广泛使用,特别是在Linux嵌入式开发领域中。

本文将简单介绍如何使用Uboot引导vmlinux。本文概述如下:

1. 准备工作

2. 下载vmlinux

3. 下载交叉编译工具链

4. 编译生成Uboot

5. 编写Uboot脚本

6. 运行Uboot

7. 结论

1. 准备工作

请确保您已经安装了以下开发平台:

• Ubuntu 16.04 64-bit 操作系统

• TFTP和DHCP服务器

• 串口终端

• JTAG调试器

我们将使用这些工具来下载内核代码、交叉编译工具链和Uboot源代码,以及执行Uboot脚本。

2. 下载vmlinux

接下来,请下载你需要引导的内核代码,比如vmlinux。

3. 下载交叉编译工具链

接下来,你需要下载交叉编译工具链,这个工具链可以帮助你将x86或者其他主机编译出来的代码编译成嵌入式设备可执行的代码。

以ARM平台为例,您可能需要下载arm-linux-gcc交叉编译工具链。通过以下命令下载交叉编译工具链:

sudo apt-get install gcc-arm-linux-gnueabi

4. 编译生成Uboot

接下来,请下载一个Uboot源代码。你需要从Uboot的官方网站上下载最新的源代码,并使用交叉编译工具链编译成可执行的二进制文件。

以ARM平台为例,您可以使用以下命令生成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

运行上述命令,就可以在Uboot文件夹下生成一个名为“u-boot.bin”的二进制文件。

5. 编写Uboot脚本

接下来,您需要编写一个Uboot脚本,以便将Uboot拷贝到目标设备上,并引导vmlinux。

一个简单的Uboot脚本可能类似于以下内容:

tftp 0x202300 /tftpboot/u-boot.bin

nand erase 0 80000

nand write 0x202300 0 80000

tftp 0x300000 /tftpboot/vmlinux.bin

bootm 0x300000

请确保你的脚本中的命令正确,检查路径和IP地址是否正确。

6. 运行Uboot

现在,您可以将Uboot二进制文件和Uboot脚本拷贝到目标设备上,并启动目标设备。具体的启动过程因设备而异,可能需要您参考设备手册。

当您成功运行Uboot,并通过它引导vmlinux内核时,屏幕或串口终端上应该显示出Linux内核的启动日志。

7. 结论

以上介绍了如何使用Uboot引导vmlinux内核的简易教程。虽然本文提供的是一个简单的例子,但这可以帮助您在实际嵌入式开发项目中更好地使用Uboot,以便正确引导Linux内核并运行项目。如果需要做更详细和复杂的操作,还需要进一步掌握Uboot的使用和配置。

相关问题拓展阅读:

mkimage制作linux内核映像 即uImage是怎么制作的

bootm命令是用来引导经过u-boot的工具mkimage打包后的kernel image的,什么叫做经过u-boot的工具mkimage打包后的kernel image,这个就要看mkimage的代码,看看它做了些什么,虽然我很希望大家不要偷懒,认真地去看看,但是我知道还是有很多人懒得去做这件,那么我就j将分析mkimage代码后得到的总结告诉大家,mkimage做了些什巧梁么,怎么用这个工具。

mkimage的用法

uboot源代码的tools/目录下有mkimage工具,这个工具可以用来制作不压缩或者压缩的多种可启动映象文件。

mkimage在制作映象文件的时候,是在原来的可执行映象文件的前面加上一个0x40字节的头,记录参数所指定的信息,这样uboot才能识别这个映象是针对哪个CPU体系结构的,哪个OS的,哪种类型,加载内存中的哪个位置, 入口点在内存的那个位置以及映象名是什么

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 ‘arch’

-O ==> set operating system to ‘os’

-T ==> set image type to ‘type’

-C ==> set compression type ‘comp’

-a ==> set load address to ‘addr’ (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)

参数说明:

-A 指定CPU的体系结构:

取值 表示的体系结构

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 指定操作系统类型正缺,可以取以下值:

openbsd、netbsd、freebsd、4_4bsd、linux、svr4、esix、solaris、irix、sco、dell、ncr、lynxos、vxworks、psos、qnx、u-boot、rtems、artos

-T 指定映象类型,可以取以下值举宽辩:

standalone、kernel、ramdisk、multi、firmware、script、filesystem

-C 指定映象压缩方式,可以取以下值:

none 不压缩

gzip 用gzip的压缩方式

bzip2 用bzip2的压缩方式

-a 指定映象在内存中的加载地址,映象下载到内存中时,要按照用mkimage制作映象时,这个参数所指定的地址值来下载

-e 指定映象运行的入口点地址,这个地址就是-a参数指定的值加上0x40(因为前面有个mkimage添加的0x40个字节的头)

-n 指定映象名

-d 指定制作映象的源文件

mkimage

解压内核源码包,编辑Makefile

设置 cross_compile:= ;这个绝对路径既上面2.95.3放到的路径

进入内核文件夹,执行下面命令

# make clean

# make dep

# make

# /bin/arm-linux-objcopy -O binary -S vmlinux linux.bin ;编译器的绝对路径也是上面说到的路径

# gzip linux.bin

下面的比较重要了,主要是u-boot的安装,这个在H9200的手册上说的很不清楚

# 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下的所有文件都复制到uboot下

# /tools/mkimage -A arm -O linux -C gzip -a 0xe 0xd linux.bin.gz uImage;这里的绝对路径是/usr/local/uboot

vmlinux linux.bin linux.bin.gz uImage(uboot制作的image)

mkimage -a -e

-a参数后是内核的运行地址,-e参数后是入口地址。

1)如果我们没用mkimage对内核进行处理的话,那直接把内核下载到0x再运行就行,内核会自解压运行(不过内核运行需要一个tag来传递参数,而这个tag建议是由bootloader提供的,在u-boot下默认是由bootm命令建立的)。

2)如果使用mkimage生成内核镜像文件的话,会在内核的前头加上了64byte的信息,供建立tag之用。bootm命令会首先判断bootm x 这个指定的地址x是否与-a指定的加载地址相同。

(1)如果不同的话会从这个地址开始提取出这个64byte的头部,对其进行分析,然后把去掉头部的内核复制到-a指定的load地址中去运行之

(2)如果相同的话那就让其原封不同的放在那,但-e指定的入口地址会推后64byte,以跳过这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 …

如何直接启动 vmlinuxz

vmlinux是未压缩的内核,vmlinux是ELF文件,即编译出来的最原始的文件。用于kernel-debug,产生system.map符号表,不能用于直接加载,不可以作为启动内核。只是启动过程中的中间媒体vmlinuz是可引导的、压缩的内核。“vm”代表“VirtualMemory”。Linux支持虚拟内存,不像老的操作系统比如DOS有640KB内存的限制以是我在CSDN中看到的,可以使用反汇编查看这个文件:arm-eabi-objdump-dkernel/vmlinux>1.S

关于uboot 引导 vmlinux的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。


数据运维技术 » 使用Uboot引导vmlinux的简易教程 (uboot 引导 vmlinux)