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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
" K. n- d" l, x- s# L; q
Linux内核是由Uboot进行调用的,在执行内核前,需要满足什么条件呢?
% v6 H5 N: S9 k% |0 Z: o8 l% o
% `0 [9 k7 p1 k& b& J1 M我们来看下内核文档Documentation/ARM/booting。内核版本为3.7.6。
1 Y- j# Y; `. \+ N& q
1 C& k5 m  @$ O* k) t4 ~。。。。。。# p3 @5 k' ~' o. I
' p, W, T7 h+ D% i+ @1 D3 L

( U$ C  W3 M- \, r( s: U
5 x6 ^- F* {% S5. Calling the kernel image
0 ^: B$ j- ?# `# b9 K: P- u---------------------------
$ w& t) \- w- J4 a; \: ]% S' f  t
* H! y# z1 r; nExisting boot loaders:        MANDATORY
3 V% Q2 ~% U& oNew boot loaders:        MANDATORY
8 i' h* h/ T/ f( m1 I, e7 \8 K2 i
0 E9 D$ M/ s2 p- M+ M% fThere are two options for calling the kernel zImage.  If the zImage
% ~: C* N) a% D. ?+ Jis stored in flash, and is linked correctly to be run from flash,
* [) m. c- G  Y2 `* h" R9 J2 Gthen it is legal for the boot loader to call the zImage in flash' T( o# Z* ~  w
directly.* @, ]6 s2 z$ {$ q
5 b1 L- C2 h$ {8 R
The zImage may also be placed in system RAM (at any location) and
5 T, O5 K6 `% y6 W# Hcalled there.  Note that the kernel uses 16K of RAM below the image
: }; c! j; g9 J( jto store page tables.  The recommended placement is 32KiB into RAM.6 {- v! S$ N; M4 [

$ w5 P. r+ K0 rIn either case, the following conditions must be met:
0 v6 A) x! ^" F  `4 I
. g$ ^6 N4 X" Y& p; j6 e, K3 J- Quiesce all DMA capable devices so that memory does not get- J; Q8 q, J6 c2 F1 _9 K
  corrupted by bogus network packets or disk data. This will save
8 J) i; c9 S; _. ]& z  A& c  you many hours of debug.
! X' `. Z9 X. \2 V: b- [/ e% V5 F1 {; F7 K# T
- CPU register settings
8 a: M3 I! `$ U2 [3 M- t  r0 = 0,5 e3 u/ V! I  D7 t* y
  r1 = machine type number discovered in (3) above.( s* k7 k' D6 F& q( ~/ F+ s9 G3 a
  r2 = physical address of tagged list in system RAM, or' @5 u6 X" _( u  F) S/ l3 [
       physical address of device tree block (dtb) in system RAM
' J0 a" B$ q  S% f- O; _* v. I. p3 S, ~4 G' q$ ?- q. ?
- CPU mode
3 c5 ^; `: u( K0 P( U, C- c/ V  All forms of interrupts must be disabled (IRQs and FIQs)2 Y9 X+ z3 A9 w5 l/ g
0 s3 h3 c0 o+ p+ B
  For CPUs which do not include the ARM virtualization extensions, the2 H# p6 s* ^6 T( p' K; q: ~
  CPU must be in SVC mode.  (A special exception exists for Angel)8 [( J- ?7 w) X3 P5 S: ~( w

1 L% @! o0 F. I' [  S' K* C2 E  CPUs which include support for the virtualization extensions can be$ q( d0 U! Z* q. a0 v& i# B
  entered in HYP mode in order to enable the kernel to make full use of" Q) a" A1 n: o% c7 H: x
  these extensions.  This is the recommended boot method for such CPUs," c* l/ |/ v, l! l; _
  unless the virtualisations are already in use by a pre-installed
9 K- C- P% G, V  hypervisor.
( x* S) e# z% D- q, h' I: ?4 N! k, R
6 e$ {; C, g; y% J( A! j' \& ^, c9 Z2 Z  If the kernel is not entered in HYP mode for any reason, it must be
+ j: }0 E! W' }, M0 _  entered in SVC mode.: g. [; P+ r' D

! S& \6 b; E7 y  S5 d5 _3 m. }1 ~% W- Caches, MMUs
6 A, w! K6 a; x% y& p# y  The MMU must be off.
( f: W& g/ U' C9 c+ _1 L  Instruction cache may be on or off." R5 g  l0 I; D, M4 F8 W# u' F
  Data cache must be off.% x: z$ s3 N/ K3 ^+ [
7 J5 e! \  c7 X9 q
  If the kernel is entered in HYP mode, the above requirements apply to
$ H3 h$ t; C9 @  the HYP mode configuration in addition to the ordinary PL1 (privileged
1 v& S5 z! B% p- C1 h  kernel modes) configuration.  In addition, all traps into the
; J5 `8 l* Q: [1 A5 \  hypervisor must be disabled, and PL1 access must be granted for all& h* N, j) F! ]# G  F5 b" g: g5 \
  peripherals and CPU resources for which this is architecturally
  z" Q/ a4 Y) L. k5 v/ ~9 O  possible.  Except for entering in HYP mode, the system configuration% e, N. u% A, d  V
  should be such that a kernel which does not include support for the
& P! P1 J, K$ b* s% @  virtualization extensions can boot correctly without extra help.
* a; G: ^: `9 l: q- c8 J* Z2 s
- The boot loader is expected to call the kernel image by jumping) _; v* n& E1 ~' g& U5 v4 W
  directly to the first instruction of the kernel image.
) P8 S: W/ n$ {+ c7 W: m/ [# b5 P! O  h% m( u  O; m! ~
  On CPUs supporting the ARM instruction set, the entry must be
' c8 P2 Z" }7 M# ~2 g  made in ARM state, even for a Thumb-2 kernel.
/ M; m: d0 c3 m+ G8 g8 d) \2 F6 ]8 l+ t
  On CPUs supporting only the Thumb instruction set such as
3 x( t+ w- ?/ n  Cortex-M class CPUs, the entry must be made in Thumb state.8 l3 Z1 I$ h5 ?; ~2 p# q
* M3 H& r0 W/ _, }, D4 V
+ s3 ~7 J$ m2 [7 B0 y2 s: Q
这里,省略了该文档中不感兴趣的部分。
9 `$ H2 x5 G* T/ [$ N* o$ N# h. ^  C4 M: P; {& T
根据文档,# {4 U) i& z: X1 U  K& [% P% d

: g9 V: \2 U! {% ?, j3 b第一, 必须禁止所有使用DMA的设备。 感觉这个有点多余,Uboot使用的设备,包括网卡之类的,一般都不会使用DMA。
3 v. T- [' B2 N8 \. l. ?/ F8 F2 m" m& [' Y
第二,必须设置r0,r1和r2寄存器为相应的值。这个是由下面的函数调用实现的。" y; i% o  z" v4 h! {- V7 `2 `& B: Z. u
& V/ F$ @4 r! N+ ?: k' u/ e7 M$ m
该函数在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。
! s1 d" l7 {4 F9 ?# F+ f5 @/ S$ l# R, s
    theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
# F2 M9 s& E3 S4 B$ [
! r% I7 ]9 ^) ^, S根据ATPCS的规则,函数的实参将分别传入r0到r3寄存器。这里有正好传入三个参数对应着0,机器码和参数列表的地址。4 A# m# Y  E0 h% u; b5 |
# W4 u8 `; |, s" e5 J: ?
第三,必须禁止中断,并且将CPU置入SVC(管理)模式。这些工作已经由start.S完成了。
. l9 w2 m% v1 Y! L
3 y. l8 d% Y+ f9 @. Q& W9 S6 z第四,必须禁止数据cache和MMU,可以使能或禁止指令cache。这个是由下面的函数调用实现的。
0 o) f, q+ n4 G7 U6 R
. K3 {' i. c" C  b0 n1 q该函数位在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。
& ]' D7 k2 q( C5 S' g0 n# N
& A1 z5 W0 q6 b! v. ?! }下列函数位于:Uboot/cpu/arm920t/cpu.c中。
- t: K5 p$ `) c/ f! w( }
4 w$ [: x  o- ~int cleanup_before_linux (void)8 A; r9 p& I5 P6 t6 k  ?4 o
{
. s2 H$ y% @) w0 u1 ]9 T" t0 d        /*
1 e5 e7 F2 r3 ?9 J* M         * this function is called just before we call linux& U9 h3 [! o5 l$ A5 c
         * it prepares the processor for linux1 z, q6 I# t& F* Q0 X
         *
. B# ?0 Y% q3 D# ?; J# W         * we turn off caches etc ...$ i0 O/ Q+ b. ~& b5 t
         */
$ D/ w8 k% m3 t2 f 8 U! T$ _" [/ N
        unsigned long i;
, W9 L" ^% Y: ^ ) M4 E% s( N- m: x: Z4 P; {- m
        disable_interrupts ();8 i) c$ \5 t; `  D
6 G& L3 b& c- K2 M3 ~1 c
        /* turn off I/D-cache */
4 V0 t4 `+ L5 U, {, N# }        asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));+ |9 v5 v+ M& M- ^
        i &= ~(C1_DC | C1_IC);
/ s9 M8 B- m- n/ t+ E        asm ("mcr p15, 0, %0, c1, c0, 0": :"r" (i));, C( N/ N3 B3 T/ S8 w9 j1 Y
! \. m1 W; ~, e% H
        /* flush I/D-cache */
7 P* Z3 A* f& K        i = 0;
1 c+ f+ k3 g0 ]( f        asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));
1 [/ f# H( _' v, R. H( S5 f1 y . [! _4 N( a0 Z/ q: {
        return (0);
4 O, [. }2 ~# e1 M0 q4 i# M/ C}2 K: F/ F' R; I$ |
) g4 q2 B) W( B% t: z
可以看出该函数禁止了数据和指令cache,同时冲刷了cache。
- K  h1 g- V! Z/ v8 b这里并没有禁止MMU,MMU禁止是在start.S中完成的。
0 \. F* t: j3 K8 A
- e7 d# x! k9 T8 h7 \. j9 P1 ]3 E1 P5 e

( s' E9 D4 k. y1 S
1 i: g+ c) t* }& C4 h2 g+ W. H  N6 M
6 Q$ p6 b2 @" l" f1 `3 D
' K/ |; u+ s/ Q' Q* F9 l% `) X# w9 E* C9 Y5 v$ B) ?( U
. e6 C2 X  l: g4 ^. R! \% r# q2 X

- c' v7 W3 ~. Q1 [& x  G; e

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-11-26 01:30 , Processed in 0.156250 second(s), 23 queries , Gzip On.

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

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

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