ARM平台下Uboot启动Linux内核前的必备条件

Linux内核是由Uboot进行调用的,在执行内核前,需要满足什么条件呢?

我们来看下内核文档Documentation/arm/booting。内核版本为3.7.6。

。。。。。。


5. Calling the kernel image
---------------------------

Existing boot loaders:        MANDATORY
New boot loaders:        MANDATORY

There are two options for calling the kernel zImage.  If the zImage
is stored in flash, and is linked correctly to be run from flash,
then it is legal for the boot loader to call the zImage in flash
directly.

The zImage may also be placed in system RAM (at any location) and
called there.  Note that the kernel uses 16K of RAM below the image
to store page tables.  The recommended placement is 32KiB into RAM.

In either case, the following conditions must be met:

- Quiesce all DMA capable devices so that memory does not get
  corrupted by bogus network packets or disk data. This will save
  you many hours of debug.

- CPU register settings
  r0 = 0,
  r1 = machine type number discovered in (3) above.
  r2 = physical address of tagged list in system RAM, or
       physical address of device tree block (dtb) in system RAM

- CPU mode
  All forms of interrupts must be disabled (IRQs and FIQs)

  For CPUs which do not include the ARM virtualization extensions, the
  CPU must be in SVC mode.  (A special exception exists for Angel)

  CPUs which include support for the virtualization extensions can be
  entered in HYP mode in order to enable the kernel to make full use of
  these extensions.  This is the recommended boot method for such CPUs,
  unless the virtualisations are already in use by a pre-installed
  hypervisor.

  If the kernel is not entered in HYP mode for any reason, it must be
  entered in SVC mode.

- Caches, MMUs
  The MMU must be off.
  Instruction cache may be on or off.
  Data cache must be off.

  If the kernel is entered in HYP mode, the above requirements apply to
  the HYP mode configuration in addition to the ordinary PL1 (privileged
  kernel modes) configuration.  In addition, all traps into the
  hypervisor must be disabled, and PL1 access must be granted for all
  peripherals and CPU resources for which this is architecturally
  possible.  Except for entering in HYP mode, the system configuration
  should be such that a kernel which does not include support for the
  virtualization extensions can boot correctly without extra help.

- The boot loader is expected to call the kernel image by jumping
  directly to the first instruction of the kernel image.

  On CPUs supporting the ARM instruction set, the entry must be
  made in ARM state, even for a Thumb-2 kernel.

  On CPUs supporting only the Thumb instruction set such as
  Cortex-M class CPUs, the entry must be made in Thumb state.

这里,省略了该文档中不感兴趣的部分。

根据文档,

第一, 必须禁止所有使用DMA的设备。 感觉这个有点多余,Uboot使用的设备,包括网卡之类的,一般都不会使用DMA。

第二,必须设置r0,r1和r2寄存器为相应的值。这个是由下面的函数调用实现的。

该函数在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。

    theKernel (0, bd->bi_arch_number, bd->bi_boot_params);

根据ATPCS的规则,函数的实参将分别传入r0到r3寄存器。这里有正好传入三个参数对应着0,机器码和参数列表的地址。

第三,必须禁止中断,并且将CPU置入SVC(管理)模式。这些工作已经由start.S完成了。

第四,必须禁止数据cache和MMU,可以使能或禁止指令cache。这个是由下面的函数调用实现的。

该函数位在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。

下列函数位于:Uboot/cpu/arm920t/cpu.c中。

int cleanup_before_linux (void)
{
	/*
	 * this function is called just before we call linux
	 * it prepares the processor for linux
	 *
	 * we turn off caches etc ...
	 */

	unsigned long i;

	disable_interrupts ();

	/* turn off I/D-cache */
	asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
	i &= ~(C1_DC | C1_IC);
	asm ("mcr p15, 0, %0, c1, c0, 0": :"r" (i));

	/* flush I/D-cache */
	i = 0;
	asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));

	return (0);
}

可以看出该函数禁止了数据和指令cache,同时冲刷了cache。

这里并没有禁止MMU,MMU禁止是在start.S中完成的。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值