找回密码
 注册
关于网站域名变更的通知
查看: 272|回复: 1
打印 上一主题 下一主题

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

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-6-10 16:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x

2 [4 D& j* P" \6 l1 ~5 |4 ^& [Linux内核是由Uboot进行调用的,在执行内核前,需要满足什么条件呢?
7 h# e- K2 C. Y6 q+ T' q' Z# J  M
- ?/ q' t( G9 N/ q" M6 O9 ]我们来看下内核文档Documentation/ARM/booting。内核版本为3.7.6。
4 e# N0 h4 E# _7 a# @# _( t6 J& T  g' n  \+ c
。。。。。。  z- t/ L" l: l8 Q1 m7 v- L

) i8 g+ G  h) P& l& h* k+ D# _5 C: L7 a
+ |  L2 `3 m  U
5. Calling the kernel image
/ a; k. @% q! s# b9 {9 T---------------------------+ ]) i4 E" v9 F- K" @) {  _

% l1 W5 [( L9 u$ D2 j. q' _: TExisting boot loaders:        MANDATORY! v, x$ ~- l% i
New boot loaders:        MANDATORY) I5 q; M7 m0 e+ G
9 r6 R) H9 X1 }  [3 f: Y: F
There are two options for calling the kernel zImage.  If the zImage
  @& S: F7 Z0 `" _" Iis stored in flash, and is linked correctly to be run from flash,+ `5 u4 A; o, p4 [- \
then it is legal for the boot loader to call the zImage in flash6 p9 |. I* h: k8 U
directly.' E) F8 L, `" ^5 H

9 Q* H' `  V2 [- ^9 l0 [The zImage may also be placed in system RAM (at any location) and
7 ?) z( d4 ?+ W( mcalled there.  Note that the kernel uses 16K of RAM below the image
* I* i6 ~" a7 A( K; Eto store page tables.  The recommended placement is 32KiB into RAM.2 {  w, T& {/ @1 R

  c. Q  ^5 ~# vIn either case, the following conditions must be met:
' E; S  E+ K" w+ q# G6 e" ], ]9 s
% P1 U8 o. Q# w- Quiesce all DMA capable devices so that memory does not get5 n2 A- ]* L# ^5 _4 q5 C
  corrupted by bogus network packets or disk data. This will save. M3 a2 l4 |* Y8 b0 N5 t
  you many hours of debug.
6 l9 N3 \' H7 L& ?4 q9 u% c2 m4 x3 O0 c9 O/ I
- CPU register settings- B/ R0 b1 |; k9 o- [
  r0 = 0,4 f, s* `6 a! T9 ^* i2 b
  r1 = machine type number discovered in (3) above.+ a: c, q# Q- J! W
  r2 = physical address of tagged list in system RAM, or
# \2 d5 G8 P2 t' T! B8 j       physical address of device tree block (dtb) in system RAM5 j, y7 E# ?, _6 b

+ r  C# Y. b2 f2 E/ \- CPU mode
. Q2 [1 p3 _# g6 e  All forms of interrupts must be disabled (IRQs and FIQs)
! O- x) [3 i9 A% t7 }5 T* J* p: m' b" x2 `
  For CPUs which do not include the ARM virtualization extensions, the
4 H% W- w( w- D3 u1 x  CPU must be in SVC mode.  (A special exception exists for Angel)# G# f+ R: ]8 P. a7 v

/ T* L6 R' L% J5 f( E  CPUs which include support for the virtualization extensions can be
* L4 B6 b. A6 u  entered in HYP mode in order to enable the kernel to make full use of
' S& p3 q9 f- |  these extensions.  This is the recommended boot method for such CPUs,$ \. g6 p& Q) W4 u$ y  ]
  unless the virtualisations are already in use by a pre-installed
$ B$ i' R% d2 \+ C6 S5 X% Z: \, o  hypervisor.
8 ]% H6 W/ Y; @" w3 w% N: v" y! L( |1 B
  If the kernel is not entered in HYP mode for any reason, it must be% U& }. W! e2 V! c8 o4 j
  entered in SVC mode.
5 F* L% k9 e, I# \; Y" Z
- Q6 C* N6 @2 w( G* {4 c- Caches, MMUs
/ W  O7 Y5 W4 t( \5 W  The MMU must be off.
; b& V, Z  K7 Y. j  Instruction cache may be on or off.
/ h* |& }! I% H' ?8 `7 A4 s% J5 S  Data cache must be off.2 r; ]7 K0 b5 j$ R0 m5 o: I
, c3 ^7 _: G3 S3 G
  If the kernel is entered in HYP mode, the above requirements apply to
& F( U( G( E- z+ B' r3 W  the HYP mode configuration in addition to the ordinary PL1 (privileged
, H  ^% G# s# `# v. T  kernel modes) configuration.  In addition, all traps into the9 |8 j6 h/ B' U+ A& S' S
  hypervisor must be disabled, and PL1 access must be granted for all# @, W: n! D- [! ^  U
  peripherals and CPU resources for which this is architecturally
  Y; @: `. v: q0 T- ]  possible.  Except for entering in HYP mode, the system configuration/ s6 x  b& j, e) j6 g
  should be such that a kernel which does not include support for the6 j( d4 j+ s8 G% a8 R9 T; M
  virtualization extensions can boot correctly without extra help.: Y! ]! e+ I" r
* u0 |4 C' C+ P- W
- The boot loader is expected to call the kernel image by jumping# i$ ?& P- g+ c1 L$ {7 p
  directly to the first instruction of the kernel image.& K( _2 F$ Y8 v: T# {, R) j
- ]9 s' `1 @' @- P7 ~
  On CPUs supporting the ARM instruction set, the entry must be
7 m5 K! h7 ~) U9 B( k4 B. A  made in ARM state, even for a Thumb-2 kernel.' O4 K' Z$ `- ^. v! E
) E9 [9 G' r5 s; V# Z8 `% S
  On CPUs supporting only the Thumb instruction set such as
& O8 d# |. m% E5 k9 O  Cortex-M class CPUs, the entry must be made in Thumb state.0 @3 m* G" C' v* k- [9 Y
  X3 C& ^; b; I- Y  Q5 l3 h$ M9 b
. k) T& J4 {7 ~5 F& M. ]2 P+ H! u
这里,省略了该文档中不感兴趣的部分。
* H  h( a: a$ e
; y# C" T. j! G" l6 m- y; y1 p+ Y根据文档,
, @; E4 K8 q& P! g0 q* o
& Q2 J0 H+ C+ e. P+ S; d3 w' z第一, 必须禁止所有使用DMA的设备。 感觉这个有点多余,Uboot使用的设备,包括网卡之类的,一般都不会使用DMA。4 C2 @. I5 k: A$ J. `

; X, d' [. c0 x1 B! z5 C; T第二,必须设置r0,r1和r2寄存器为相应的值。这个是由下面的函数调用实现的。' l& N8 a: C6 x/ U0 B+ F+ ]
7 V, O) t5 \9 |. D: p+ F2 O- i8 A
该函数在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。
' m! q, b' \# K8 d7 B5 k3 f6 r+ {0 O$ n4 L  j
    theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
( c" K) X% Z( U( f2 ^* E" b: }4 l8 M0 z
根据ATPCS的规则,函数的实参将分别传入r0到r3寄存器。这里有正好传入三个参数对应着0,机器码和参数列表的地址。
4 i. d5 _0 Q. L0 {, N# w, v
- d: Z9 h3 n4 h) t第三,必须禁止中断,并且将CPU置入SVC(管理)模式。这些工作已经由start.S完成了。
+ {" x6 G4 ^8 q& {5 j
% J8 X) f; o* p% }第四,必须禁止数据cache和MMU,可以使能或禁止指令cache。这个是由下面的函数调用实现的。! V! N$ }. \& _& `& l1 @* \0 P' P* H

7 \+ V  O  X; T1 }0 q$ \- Y( C$ r该函数位在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。: @+ s9 b6 k% r% l- j
; H( {/ u0 q# k# L8 [
下列函数位于:Uboot/cpu/arm920t/cpu.c中。
6 }8 c% F) A+ j( P* ]) C8 Q7 F1 D8 ]! s- _$ ]
int cleanup_before_linux (void)
) K0 U# S" j( U! h1 Y{& v) L) T3 K! ~/ Y5 i: t
        /*
, d8 o  ]! N1 B0 x! t4 p6 ?9 k! t         * this function is called just before we call linux
( n% O5 J% h$ X: I         * it prepares the processor for linux
" {6 B' \% ^- o# j) |         *  ]4 b1 C. T" H; W
         * we turn off caches etc .../ p% ?5 T! z  ]) ~, \  D) W& X
         */6 x! G7 g: g8 A" [1 G2 \% A

3 U7 c% v$ Z) g  z6 b6 T* K        unsigned long i;
' _! x2 `4 z6 K" O
* t& B3 m* W' b8 J        disable_interrupts ();
; G' |' ]4 ]  s
! J- X6 c/ H; Z        /* turn off I/D-cache */
, V: |: n! V5 \        asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
7 R0 J3 i; Q3 r$ G        i &= ~(C1_DC | C1_IC);
% Y2 p& N5 P8 z, }  j' P        asm ("mcr p15, 0, %0, c1, c0, 0": :"r" (i));
$ A% W$ M/ [' G/ c0 l * s: s+ Q; n0 F& E; O% l
        /* flush I/D-cache */  }/ Z! d1 U& r& j
        i = 0;& {2 L: g2 X/ \5 i* ]8 f+ z2 p
        asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));
2 ]; k8 x% s* h' S0 Q+ @
8 k( ]1 S9 m" {! ~        return (0);
9 D+ Y4 z4 C5 D  r* `3 c}
  ^! e. r7 ?0 J* ?7 ~. @) y
7 J- ~1 G2 b: L* \3 S可以看出该函数禁止了数据和指令cache,同时冲刷了cache。8 R  @9 v" j/ @2 u; O# z
这里并没有禁止MMU,MMU禁止是在start.S中完成的。8 `) n2 V) s/ e5 \

' U8 K) k# y* {- I5 J2 K1 X& T! b; E1 h

" D( D: u$ y$ x" f% T' x8 {5 u3 G) y: T+ N! s& [5 n% q/ C8 D  z7 y4 v

) l1 ^7 u: N9 x
2 l! e% o- t+ `3 L, R4 O
) r  C  i, k! t. p) W# f
: g* R. @; a1 n5 ]7 ~
4 W0 U; g# Z+ }# ^6 c( t2 U2 T

该用户从未签到

2#
发表于 2020-6-10 19:05 | 只看该作者
ARM平台下Uboot启动Linux内核前的必备条件
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-11-25 20:04 , Processed in 0.171875 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表