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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
8 W9 Y: @7 P3 u7 F8 m' R
Linux内核是由Uboot进行调用的,在执行内核前,需要满足什么条件呢?8 I) E5 b6 m7 t4 V( F. q1 i
7 ^7 B  o9 F# n5 x& _
我们来看下内核文档Documentation/ARM/booting。内核版本为3.7.6。2 F  C0 n3 c& L' H8 v, y5 K

3 d+ G9 a- F$ B/ ?8 _。。。。。。
. s9 E8 x3 A# ?4 U4 V
( l9 I+ t0 F1 X2 h" q; D
/ i5 i$ c5 B( K1 Y
' r& _2 f% s7 _+ e& @5. Calling the kernel image& i- b7 x1 ]7 \2 c- b
---------------------------4 j; L% J& E) M
) n' P& w, |7 U; u# @- V2 P  Q
Existing boot loaders:        MANDATORY
; a3 r+ L( D- }! _6 nNew boot loaders:        MANDATORY
( \0 ^6 v9 m# X; Z3 j4 k. |2 p" E( `# d7 R: S6 |
There are two options for calling the kernel zImage.  If the zImage
7 E+ z+ C2 V4 _, K: e$ c  D- bis stored in flash, and is linked correctly to be run from flash,$ l6 _. [, _; O& }
then it is legal for the boot loader to call the zImage in flash" \8 p! @, H0 x' A
directly.# \; H8 A! m! q

: u. k0 R5 O6 r7 N2 A6 SThe zImage may also be placed in system RAM (at any location) and* Q/ W" M- q- V
called there.  Note that the kernel uses 16K of RAM below the image
1 n- x% e( @' ?. v4 m; H) \, l$ mto store page tables.  The recommended placement is 32KiB into RAM.: o0 Y0 T: u. u
& N+ w0 c/ q4 F* U; B+ P
In either case, the following conditions must be met:$ f, E4 G; X( l; |

& |, `% h" T, w6 A- Quiesce all DMA capable devices so that memory does not get
' N7 r" |( _- {8 a/ n) H* m( h* _  corrupted by bogus network packets or disk data. This will save
" W' |/ X) z- w7 f  you many hours of debug.
) Z3 x+ x; P0 I( |! t8 C6 D: X( H* ^% o! W9 ]2 m
- CPU register settings
) K  c( V3 p3 T' }, c+ l  r0 = 0,
3 i! n; s. l( L5 R6 }2 g/ E  r1 = machine type number discovered in (3) above.
/ n& q3 e6 I4 b% ~% T  r2 = physical address of tagged list in system RAM, or* ^8 f$ ~3 Q% @) |. A% d" L2 D$ m
       physical address of device tree block (dtb) in system RAM
: f. w, O# ?7 A' v; n% [  Q4 k7 _1 i+ K! F9 s# ^9 v; l( _; O- z  n
- CPU mode
& m: b% b; P' m/ z% E, |7 j  All forms of interrupts must be disabled (IRQs and FIQs)* P( f' ^- M+ m8 o
; E0 i, m6 v5 x/ i( B) F* M
  For CPUs which do not include the ARM virtualization extensions, the
. \+ w, [; `; D; s  CPU must be in SVC mode.  (A special exception exists for Angel)
" b; c! X2 E( u! U# h' \3 A3 ?! w1 f
  CPUs which include support for the virtualization extensions can be
& P1 K# o$ O- _, e' T6 e- ^  T% z# P  entered in HYP mode in order to enable the kernel to make full use of
1 H! o; J( f% U, K% k* R: C  these extensions.  This is the recommended boot method for such CPUs,
$ w! O" Y2 y" y3 s# N' b0 `2 z  unless the virtualisations are already in use by a pre-installed
! |: r& C. v+ p* A- f; Q& s; \  hypervisor.
/ i+ h4 K, v, c' s1 h2 r0 \' G
/ m0 R0 W' N# U9 y3 Y9 O. ?, O6 {  If the kernel is not entered in HYP mode for any reason, it must be
# ~) x8 c2 N0 X1 m1 R9 c+ k: S. L  entered in SVC mode.; D% d" P- l8 B+ _! C
5 j  p  |% h& A! C. b! z
- Caches, MMUs" K' {" V+ `2 ]' ]" W  D
  The MMU must be off.
& F+ }, w; U- [' b0 L3 j  Instruction cache may be on or off.
* Z; |1 E$ G. V  Data cache must be off.
2 z8 q: d0 }8 r6 G' p/ c0 G- C; ^) m5 r$ G- r$ R  H- F- B3 Y# u
  If the kernel is entered in HYP mode, the above requirements apply to) [5 \3 k) K: \$ d' t. ]" |. J, a
  the HYP mode configuration in addition to the ordinary PL1 (privileged
* A  |8 O  r1 H! j1 a5 h+ R  kernel modes) configuration.  In addition, all traps into the2 s, ^% t3 e0 l( k% ^& c
  hypervisor must be disabled, and PL1 access must be granted for all; A; `( T0 n( S% h) i
  peripherals and CPU resources for which this is architecturally
+ p8 K" \- X+ ?: ~  possible.  Except for entering in HYP mode, the system configuration8 U3 x+ v: f! W) l& [5 O
  should be such that a kernel which does not include support for the9 p3 N0 F: [$ W8 G; l9 ~
  virtualization extensions can boot correctly without extra help.
3 M+ s& D9 U( z5 i+ v) X+ O* I9 p9 Z$ Z8 _
- The boot loader is expected to call the kernel image by jumping
# x1 P! G  p8 c5 P0 f# f  directly to the first instruction of the kernel image.
5 u5 I3 P# |. E' A; i. Y. e) q& Y  p' x7 B6 h, K- J5 S! H8 i
  On CPUs supporting the ARM instruction set, the entry must be
* P1 X. O8 k9 s8 P  made in ARM state, even for a Thumb-2 kernel.
4 V4 _" A) v3 b7 X; ~. G
' A" C1 k8 z! A3 W; _; K5 q; B7 F4 R  On CPUs supporting only the Thumb instruction set such as
4 x" n, B# p3 K" v2 t  Cortex-M class CPUs, the entry must be made in Thumb state.
, n4 q, A# @$ Q8 c
! b8 d& O7 b8 n: F/ E
# w. Y7 ^; }+ c7 X这里,省略了该文档中不感兴趣的部分。8 {( o- f( X5 @5 B7 S! B+ y+ K
0 Z. e( D, l) G9 a; H
根据文档,
! Y/ E- N: o- h- b: j/ V; V# ]* ~6 v) w, q
第一, 必须禁止所有使用DMA的设备。 感觉这个有点多余,Uboot使用的设备,包括网卡之类的,一般都不会使用DMA。$ X  A3 ?5 Q7 E5 g- [  J# _
" e. o0 Z7 F( Q2 [8 ^, z" Q
第二,必须设置r0,r1和r2寄存器为相应的值。这个是由下面的函数调用实现的。+ h' B$ B6 E) g: w5 Y2 R# G

: {% Z# y- @# ^0 u& B. P  G7 q该函数在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。& |: [( t: b( [+ r
* ?) h* {% D3 ~' w
    theKernel (0, bd->bi_arch_number, bd->bi_boot_params);8 `$ p, d0 h/ H! e3 a
  c% ?# ?. t3 X2 ]
根据ATPCS的规则,函数的实参将分别传入r0到r3寄存器。这里有正好传入三个参数对应着0,机器码和参数列表的地址。
! k3 j5 R9 l. ]4 p2 W% Q% M8 R
第三,必须禁止中断,并且将CPU置入SVC(管理)模式。这些工作已经由start.S完成了。" E% X- x# ]7 c0 k
: ?. x) w" I6 n
第四,必须禁止数据cache和MMU,可以使能或禁止指令cache。这个是由下面的函数调用实现的。5 R, K" p% K3 U2 l8 @* ]6 h5 N- W& T
( q$ ?  e7 T& b6 l3 ]8 \! I, B$ G2 \
该函数位在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。, i  Y6 v: e' ^

5 W8 v4 w  v$ m* r, z: J( n* ]! }下列函数位于:Uboot/cpu/arm920t/cpu.c中。. v7 @9 m" m; }% A' F  W
+ {0 T- L. D* D' @: Y( r# }! m
int cleanup_before_linux (void)9 E7 c' \5 q/ f) ?
{
+ s# M; a5 @) W: m- [9 K        /*
% X, \  S6 `( Y+ h) B. g         * this function is called just before we call linux% M3 C/ h  N/ K% ^
         * it prepares the processor for linux
: c* \8 j; k& ?1 T) |         *
. v1 [2 O& q. n2 K. ]         * we turn off caches etc ...
  D0 N. r# E! k" B6 S: O# v" \         */: ?6 O4 i: p3 u

/ L+ B& }6 g! \3 ~1 X+ {. C/ L        unsigned long i;
3 E; H# j; r- V. H( h
; o" u- O, E4 a* w, V, O4 z        disable_interrupts ();: d" x+ ~0 P' m+ T, d  U
+ e3 O" R# E( `! @; g" V
        /* turn off I/D-cache */
8 K0 ^+ ?, Y! F" |        asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));0 @+ j- i! U0 ^( s
        i &= ~(C1_DC | C1_IC);$ U0 S& r" a. ]" y6 a
        asm ("mcr p15, 0, %0, c1, c0, 0": :"r" (i));4 j9 n6 h7 E2 w; q, m
+ Z3 d8 g- O1 ]
        /* flush I/D-cache */
, f( B7 i* o) U( d' R        i = 0;4 v1 R" t" j2 l" f
        asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));
  K4 M' h, ]. _/ O! P# W
) p" \8 [0 o3 C( T$ m& n        return (0);% s, a1 v5 A0 N* Y4 r  I* }* ?8 Z: }, M
}
  d5 i2 `- N2 H2 I- W) Y+ v; Z8 g( F- k, l
可以看出该函数禁止了数据和指令cache,同时冲刷了cache。# U: q" }9 D* m' p8 k
这里并没有禁止MMU,MMU禁止是在start.S中完成的。3 v- \& G9 A  A- e; b

, C% J) Q+ }  N5 u0 F( b: w! h. v5 a; z% m/ |7 l
" q$ K& A1 N" C& ?9 D9 Z9 B/ E3 y1 j9 y

$ h) T. g- B) f8 l: b8 L8 d  v3 b9 `/ |: t9 j$ _4 F

( \8 P. M  e( G3 ^$ S0 ~! N5 P; y* f1 u- F8 U' Y, e

: K8 L8 k$ p. L  n7 b3 Z2 t- g5 t" ]' _( |$ v+ n* G

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-10-27 03:14 , Processed in 0.140625 second(s), 23 queries , Gzip On.

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

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

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