内核通识——arch目录简介(与架构相关的目录)

以下内容源于朱有鹏嵌入式课程的学习与整理,如有侵权请告知删除。

一、内核代码的分类

内核代码可以划分为以下三个分类:

(1)arch目录:全是cpu架构有关的代码。

(2)drivers目录:该目录下全是硬件的驱动。

(3)其他内容:这些代码与硬件无关,因此系统移植和驱动开发的时候这些代码几乎不用关注。

二、arch目录简介

其中arch目录下有许多目录,因为我们开发板采用ARM芯片,所以这里重点讲解arch/arm目录。

xjh@ubuntu:~/android-kernel-samsung-dev$ ls
arch     COPYING.txt  Documentation  fs       ipc     lib          mm      REPORTING-BUGS  security  usr
block    CREDITS      drivers        include  Kbuild  MAINTAINERS  net     samples         sound     virt
COPYING  crypto       firmware       init     kernel  Makefile     README  scripts         tools
xjh@ubuntu:~/android-kernel-samsung-dev$ cd arch/
xjh@ubuntu:~/android-kernel-samsung-dev/arch$ ls
alpha  avr32     cris  h8300  Kconfig  m68k       microblaze  mn10300  powerpc  score  sparc  x86
arm    blackfin  frv   ia64   m32r     m68knommu  mips        parisc   s390     sh     um     xtensa
xjh@ubuntu:~/android-kernel-samsung-dev/arch$ cd arm/
xjh@ubuntu:~/android-kernel-samsung-dev/arch/arm$ ls
boot           mach-clps711x    mach-iop33x    mach-mx1       mach-orion5x   mach-s3c64xx   mach-u300       plat-omap
common         mach-cns3xxx     mach-ixp2000   mach-mx2       mach-pnx4008   mach-s5p6440   mach-ux500      plat-orion
configs        mach-davinci     mach-ixp23xx   mach-mx25      mach-pxa       mach-s5p6442   mach-versatile  plat-pxa
include        mach-dove        mach-ixp4xx    mach-mx3       mach-realview  mach-s5pc100   mach-vexpress   plat-s3c24xx
Kconfig        mach-ebsa110     mach-kirkwood  mach-mx5       mach-rpc       mach-s5pv210   mach-w90x900    plat-s5p
Kconfig.debug  mach-ep93xx      mach-ks8695    mach-mxc91231  mach-s3c2400   mach-sa1100    Makefile        plat-samsung
Kconfig-nommu  mach-footbridge  mach-l7200     mach-netx      mach-s3c2410   mach-shark     mm              plat-spear
kernel         mach-gemini      mach-lh7a40x   mach-nomadik   mach-s3c2412   mach-shmobile  nwfpe           plat-stmp3xxx
lib            mach-h720x       mach-loki      mach-ns9xxx    mach-s3c2416   mach-spear3xx  oprofile        plat-versatile
mach-aaec2000  mach-integrator  mach-mmp       mach-nuc93x    mach-s3c2440   mach-spear6xx  plat-iop        tools
mach-at91      mach-iop13xx     mach-msm       mach-omap1     mach-s3c2443   mach-stmp378x  plat-mxc        vfp
mach-bcmring   mach-iop32x      mach-mv78xx0   mach-omap2     mach-s3c24a0   mach-stmp37xx  plat-nomadik
xjh@ubuntu:~/android-kernel-samsung-dev/arch/arm$ 

(1)/arch/arm/mach-xxx

  • mach-xxx目录表示使用xxx这个芯片作为cpu的的开发板,比如/arch/arm/mach-s5pv210目录里面,都是一些用s5pv210作为主芯片的开发板。
  • 而mach-xx目录里面的一个mach-yy.c文件,则定义了一个开发板。比如/arch/arm/mach-s5pv210目录中,有mach-smdkc110.c、mach-smdkv210.c、mach-x210.c等文件。

(2)/arch/arm/plat-xxx

  • plat是platform的缩写,含义是平台。
  • plat可以理解为SoC,这个plat目录下都是SoC里面的一些硬件(内部外设)相关的代码。
  • 在内核中把SoC内部外设相关的硬件操作代码就叫做平台设备驱动

(3)/arch/arm/include

  • 这个include目录中的所有代码都是架构相关的头文件。

三、补充说明

(1)不同版本的内核,某个文件存放的位置可能不同。

(2)头文件目录include有好几个,使用时要注意具体是哪个。

//内核通用头文件
x210_kernel/include  
      
//架构相关的头文件
x210_kernel/arch/arm/include        
x210_kernel/arch/arm/include/asm
x210_kernel/arch/arm/include/asm/mach
x210_kernel/arch/arm/mach-s5pv210/include/mach
x210_kernel/arch/arm/plat-s5p/include/plat

(3)内核中包含头文件时有一些格式。

#include <linux/kernel.h>  //x210_kernel/include/linux/kernel.h
#include <asm/mach/arch.h>//x210_kernel/arch/arm/include/asm/mach/arch.h
#include <asm/setup.h>    //x210_kernel/arch/arm/include/asm/setup.h
#include <plat/s5pv210.h> //x210_kernel/arch/arm/plat-s5p/include/plat/s5pv210.h

(4)有时候我们需要包含某个头文件时可能并不是直接包含它,而是包含一个包含着它的头文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天糊土

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值