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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
7 \) C, ?, d4 p; x" ]6 I5 O
Linux内核是由Uboot进行调用的,在执行内核前,需要满足什么条件呢?1 k( t+ N- l: Z/ F8 h4 M

/ E% [" }1 o  c  a/ F" b0 Z" s& @7 y我们来看下内核文档Documentation/ARM/booting。内核版本为3.7.6。! d/ |2 S7 T  P$ R" b6 J& z7 T

# |6 v; L5 _$ w6 \- k。。。。。。6 }' x/ @# g3 l1 X
2 d0 }, a; h1 U0 g# x

4 n) x  G4 L+ c) K
6 i, Y! k6 R3 v5. Calling the kernel image
; m  j6 e0 i$ O$ R---------------------------8 Y( ^' |* Z* d( n( v

* w. ]* J: {8 \  H7 U: bExisting boot loaders:        MANDATORY
  I7 R" U$ V# V( M: J9 q; WNew boot loaders:        MANDATORY% N2 ?+ g0 _3 a- I, ]: f
! M) ~. q' K: [- a4 x8 Z
There are two options for calling the kernel zImage.  If the zImage
* M9 Q7 u$ m; b) a, T% xis stored in flash, and is linked correctly to be run from flash,
. h+ `" r  @" \5 ^, {! R3 Bthen it is legal for the boot loader to call the zImage in flash1 v! Y9 a' A2 d+ A0 f+ k! J( f
directly.
& p# o& r% K9 E% A) j# a# q  q4 F
The zImage may also be placed in system RAM (at any location) and
0 S# ~6 C  G8 O( o/ Fcalled there.  Note that the kernel uses 16K of RAM below the image9 ?4 v6 z- E6 O  C
to store page tables.  The recommended placement is 32KiB into RAM./ z; {$ u0 H. U  @4 L# r# ~

; P8 {9 K9 a0 MIn either case, the following conditions must be met:
* P+ u8 B+ x! J, w0 @9 C  q- b1 v
2 B( W2 O: U5 {- Quiesce all DMA capable devices so that memory does not get/ L5 f" I0 m+ D; k4 m* F' m5 k0 M, I
  corrupted by bogus network packets or disk data. This will save
4 q. }0 E8 e0 e  B, _  you many hours of debug.( K* B) I( ~4 j; v

5 n3 p3 X% t* o4 j2 A- CPU register settings2 N2 P2 g0 N( s# G: [" Q9 `0 q' q
  r0 = 0,3 H) I" w( ~: P" v: q
  r1 = machine type number discovered in (3) above.% [0 h% Z; o) R5 t0 U
  r2 = physical address of tagged list in system RAM, or" \% I; X' f/ s% y
       physical address of device tree block (dtb) in system RAM
3 D$ z+ b7 t0 b6 t6 h7 Z3 m& F6 P) e: i3 k8 _# q
- CPU mode
5 m/ B; M. a" `  i$ L  All forms of interrupts must be disabled (IRQs and FIQs)( M  ]9 K4 a) |4 j8 N4 j
' G: X. o' [  W2 i1 Y0 B# y- r, B
  For CPUs which do not include the ARM virtualization extensions, the
  M  }- \6 b2 ^9 a, q  CPU must be in SVC mode.  (A special exception exists for Angel)
- N7 z$ n) p7 k, _; V! T9 v, e% I- L" [2 M# `* `  V5 H
  CPUs which include support for the virtualization extensions can be
9 X) `$ a* _% A$ q# T  entered in HYP mode in order to enable the kernel to make full use of
" h" `$ ]' H7 u" j+ Z  these extensions.  This is the recommended boot method for such CPUs," P! ?" Y! r3 m% z4 e& h3 q/ Z
  unless the virtualisations are already in use by a pre-installed
7 J1 Y( \& O5 ?. C, O' S  hypervisor.- p3 H7 K( N$ {

+ l4 B1 P; R- n3 O( g( {# [0 a9 r  If the kernel is not entered in HYP mode for any reason, it must be6 E- g' [4 k. w/ b
  entered in SVC mode.( g) \$ A% A0 b# p1 a5 j! P
( i( v/ ?% \3 Q: X( m' ?# B
- Caches, MMUs6 C# _* X% B0 D9 Z! M
  The MMU must be off.# [6 `' v/ s6 d: E" I# K% a- p
  Instruction cache may be on or off.
7 [. n7 M: @& b0 e7 p  Data cache must be off.
# r* U0 x( p/ V5 v- J2 g4 h" p" o
  If the kernel is entered in HYP mode, the above requirements apply to
7 J/ L/ V( k7 F! V9 P7 M  the HYP mode configuration in addition to the ordinary PL1 (privileged$ [: W# t! a- A* J
  kernel modes) configuration.  In addition, all traps into the
2 p& p4 R+ i7 @% ^  hypervisor must be disabled, and PL1 access must be granted for all
3 ?& H$ R/ @4 p6 W9 D+ _- v  peripherals and CPU resources for which this is architecturally
& L+ D9 L3 m4 A$ Y. D* h7 h  possible.  Except for entering in HYP mode, the system configuration
8 C' t# r; V& H  should be such that a kernel which does not include support for the/ c. o# D1 L7 e  b* \
  virtualization extensions can boot correctly without extra help.
& S& y: d0 L3 W5 t/ ^2 p- U* v  u4 _8 K; n* B* h9 f
- The boot loader is expected to call the kernel image by jumping2 ]0 ^, Y. r2 x
  directly to the first instruction of the kernel image.' h  A: ~" ^/ o# C6 f8 I

2 q, P5 f( S: w; r4 p  On CPUs supporting the ARM instruction set, the entry must be! A; L2 z/ g7 v. D0 {# P/ k# i3 L
  made in ARM state, even for a Thumb-2 kernel." ^; V( j) `' K, f" Z
& k1 _+ G4 t: [
  On CPUs supporting only the Thumb instruction set such as
$ f: [: ^8 D) x% ^+ B9 k6 }  Cortex-M class CPUs, the entry must be made in Thumb state.
7 c1 P3 ^2 I* c1 F# P9 K. {2 _5 i+ l( a* M% n1 \

0 E6 E3 k8 r1 Z$ G4 r7 w这里,省略了该文档中不感兴趣的部分。
; z  Q1 t3 K' F' U4 y% l
$ M! H7 ^9 g4 u) v9 F# {/ M根据文档,0 z, ?8 `& |) H, O( l- c
4 F. \- [  e# k, }0 @4 v
第一, 必须禁止所有使用DMA的设备。 感觉这个有点多余,Uboot使用的设备,包括网卡之类的,一般都不会使用DMA。  N; q. ]! g% r8 U5 m

% s; C% \+ N" ]# W7 c第二,必须设置r0,r1和r2寄存器为相应的值。这个是由下面的函数调用实现的。  p# S  E/ J5 G, l- S, H
4 ~; Z/ J2 s& C+ e" H& b3 _5 H: @; x) ~) M
该函数在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。* F6 _/ J/ d7 U% N, M  K/ Y# a

& S$ I- b2 o2 g4 \' }4 ]    theKernel (0, bd->bi_arch_number, bd->bi_boot_params);1 G2 I& B: i  F; M6 x
, ^( }7 D, |) k+ `. K
根据ATPCS的规则,函数的实参将分别传入r0到r3寄存器。这里有正好传入三个参数对应着0,机器码和参数列表的地址。
* G& F( \8 Z1 U7 c3 ^
1 u7 D7 T5 e* X6 I  p2 R5 I: ^, D第三,必须禁止中断,并且将CPU置入SVC(管理)模式。这些工作已经由start.S完成了。$ M/ U& p! Z" f1 m  ~9 ~

" t" \( H% t$ i) I第四,必须禁止数据cache和MMU,可以使能或禁止指令cache。这个是由下面的函数调用实现的。1 J8 u" ?4 H+ f- Y! F

- u: V& x' [  l" i该函数位在Uboot/lib_arm/armlinux.c的do_bootm_linux函数中被调用。
. C1 t. w/ I+ Y/ ^2 O" ^* }1 r) J" ^7 J7 J2 E6 s1 \
下列函数位于:Uboot/cpu/arm920t/cpu.c中。  I  u) C+ `7 ?3 V8 r* ]

( T) S4 s7 @, t- z( lint cleanup_before_linux (void)
" O- \4 P, T4 l. t5 Y  h{5 ]) _; s6 X7 i/ w" f2 C: }) @5 Z2 q
        /*
4 q! i: i/ e& _5 I# p  C5 |7 J         * this function is called just before we call linux
1 i9 M- G: L$ W         * it prepares the processor for linux
/ V; r: v( C3 Y! G7 O: F         *
! Q+ Q. d& N) {8 Z& @( e$ l8 x: k         * we turn off caches etc ...
/ X! u: {- Q- m+ O* }9 U" [0 n         */) `9 p% B3 S/ v9 O3 D8 @
' b2 j2 `) l+ W2 y
        unsigned long i;3 \' ]9 x% t& Q( H! i

( e: J* E2 f9 H' ?) F' |9 @        disable_interrupts ();' _: f0 Z/ J: c. k2 N1 @* B

9 I2 Q- a7 R( \        /* turn off I/D-cache */0 D  ?$ G* b; L2 F) ^
        asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));2 q1 h% W' i% E$ D$ T; I
        i &= ~(C1_DC | C1_IC);
' }3 A% U8 a8 ~" c) X        asm ("mcr p15, 0, %0, c1, c0, 0": :"r" (i));0 _% R  {7 x( ^, ~
6 Y0 i5 F5 y# ^( W
        /* flush I/D-cache */9 X: X9 G4 }4 ]2 x! y
        i = 0;- R2 C, |+ p% X. P) r+ P2 f
        asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i));+ _, Z( Y( M0 F1 Z
* n: b$ j" v1 ?. F' _% n
        return (0);
+ {; g! _0 q5 P}9 F' Q- o; N2 O  i
5 F; j! u) j% }( \$ r7 j2 `& z2 T
可以看出该函数禁止了数据和指令cache,同时冲刷了cache。% S* {0 g' D' }4 T* ~8 e" s
这里并没有禁止MMU,MMU禁止是在start.S中完成的。
. L3 O* y& C* w
' Q; O: N: u. q1 T
4 E' d# `, E# R! ?
$ G! u+ z: }3 h8 e5 S( x/ s
4 ?4 q8 p# c' h8 J' `! o
% _. J* J* u8 L2 I! I1 K0 F% Q) i% _" E( }& K; T! }+ Z
* ^8 q: D2 `" F
3 ~7 ]1 n7 c6 F. M$ G) X3 q4 t

6 F( `/ C! ]7 W( r

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-11-25 21:13 , Processed in 0.171875 second(s), 24 queries , Gzip On.

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

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

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