linux开发的一些记录

来源:互联网 发布:算法的时间复杂度 编辑:程序博客网 时间:2024/06/06 20:53
+----------------------------------------------------+
+Uboot配置,编译
+----------------------------------------------------+
1.查看uboot顶层makefile文件,查找xxx_config配置选项,确定$ARCH值
2.导出环境变量$ARCH和$CROSS_COMPILE
3.make all


+----------------------------------------------------+
+makefile分析
+----------------------------------------------------+
1.make xxx_config的结果是执行MKCONFIG,在/include/下产生config.mk
ARCH   = ppc
CPU    = mpc85xx
BOARD  = p2020ds
VENDOR = freescale
以及根据/include/config/P2020DS.h生成autoconf.mk
这两个文件被包含于顶层makefile中供编译过程中使用(主要是底层子makefile文)


顶层makefile文件设置并导出$变量,组织uboot文件依赖关系,其中最关键的在uboot的依赖
例如:
GEN_UBOOT = \
UNDEF_SYM=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \
sed  -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
--start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
-Map u-boot.map -o u-boot
$(obj)u-boot: depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds
$(GEN_UBOOT)

$(SUBDIRS) 
$(OBJS) 
$(LIBBOARD) 
$(LIBS) 
$(LDSCRIPT)
这些就是前面makefile文件的结果
其中$(LDSCRIPT)尤其值得注意,回溯查找可以得到在顶层config.mk
ifeq ($(CONFIG_I2C_U_BOOT),y)
LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS)
else
LDFLAGS += -Bstatic -T $(obj)u-boot.lds $(PLATFORM_LDFLAGS)
endif
ifneq ($(TEXT_BASE),)
LDFLAGS += -Ttext $(TEXT_BASE)
endif


注意$(TEXT_BASE)搜索得到
/board/freescale/p2020ds/config.mk


其余的部分都是xxx_config部分




+----------------------------------------------------+
+U-BOOT源码分析
+----------------------------------------------------+
1.查看u-boot.map查找执行入口
 .text          0xeff40000     0x1854 cpu/mpc85xx/start.o
                0xeff40100                _start_of_vectors
                0xeff40004                version_string
                。。。。。。。。。。。。。。。
此处不能确定入口地址确切是那里,因为powerpc构架的cpu复位后取值地址根据设置不同而不同,这里为0xeffffffc
所以查找u-boot.map中此地址
 .resetvec      0xeffffffc        0x4 cpu/mpc85xx/resetvec.o
                0xf0000000                . = 0xf0000000
                0xf0000000                __bss_start = .
查找cpu/mpc85xx/resetvec.s
.section .resetvec,"ax"
b _start_e500
这个文件就一条指令,所以_start_e500就是真正的入口
如何把这条指令放到0xeffffffc的呢,答案就是u-boot.lds为什么是u-boot.lds或者是哪个.lds文件
答案是前面分析的makefile文件$(obj)u-boot.lds


2.确定了执行入口后开始分析代码,这里只列出关键部分,涉及到移植工作
/********************************************/
//部分汇编指令列表
//mfspr r1,DBSR读取特殊功能寄存器DBSR到r1中,注:mf表示读取
//mtspr DBSR,r1写入r1到特殊功能寄存器DBSR中,注:mt表示写入
//li r0,2 加载立即数2到r0中
//lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
//ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
//合起来加载一个32bit数到r2
//注:l表示加载到寄存器,st表示存储寄存器到内存,i表示立即数
//b表示字节,h表示半字,w表示字,z表示清零寄存器其余内容  
//所有计算操作都以指令后第一个作为目标寄存器li 5,12表示立即数12载入寄存器5
//如果操作码没有i立即数,那么所有数字都表示寄存器
//@highest表示常量bit63-bit48, @higher表示常量bit47-bit32
//@h表示常量bit31-bit16, @l表示常量bit15-bit0  
//sc表示系统调用指令
//rfi中断返回
/********************************************/
1.初始化L1 cache
2.初始化interrupt vectors
3.初始化其他一些寄存器
4.建立临时MMU映射,因为E500不能关闭MMU
5.建立栈stack in initial RAM  
6.调用cpu_init_early_f
/**********************************/
//gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
//全局数据,最后一直传递给内核
//设置ccsrbar:setup_ccsrbar();
/**********************************/
7.调用cpu_init_f
/**********************************/
//配置LBC控制器
/**********************************/
8.调用board_init_f 注:不再返回,进入C语言环境 
/**********************************/
//1.顺序调用init_sequence[]函数
//for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
// if ((*init_fnc_ptr) () != 0) {
// hang ();}
//2.填充bd结构体,板级信息,bd包含于gd 
/**********************************/
9.从board_init_f进入start.s的调用relocate_code
10.relocate_code完成后再进入board_init_r
11.board_init_r继续初始化外围硬件和gd结构体 然后进入main_loop (); 


+==================================================+
+如何解压出uboot和kernel
+==================================================+
./ltib -m prep -p u-boot
./ltib -m prep -p kernel
./ltib -m prep -p busybox




+==================================================+
+设备树相关知识
+==================================================+
1.构建二进制设备树
dtc -O dtb -o p2020_my.dtb -b 0 p2020ds.dts


2.逆向回溯为dts
dtc -O dts -I dtb p2020_my.dtb >p2020ds.dts


2.设备树二进制文件格式
+----------------------------------------------------------------+
|OF_DT_BEGIN_NODE|NODE_NAME /0 |PROPRETY          |OF_DT_END_NODE|   
|      TAG       |             |                  |   TAG        |
+----------------------------------------------------------------+
                               /                   \
             _________________/                     \__________________________
            /------------------------------------------------------------------\
            |OF_DT_PROPRETY|size in byte|offset in string|proprety value|......|                       
            |     TAG      |of proprety |proprety name   |              |      |
            +------------------------------------------------------------------+
            
            


3.bitbake 如何解压出uboot
$ bitbake -c clean u-boot
$ bitbake -c patch u-boot


+-----------------------------------------------+
+linux加载nfs几点注意事项
+-----------------------------------------------+ 
1.根文件系统路径设置要正确
nfsroot=xxx.xxx.xxx.xxx:/opt/AM1808/filesystem/rootfs
这个rootfs其实是根文件系统内的比如arago.ext2,它挂载到/opt/AM1808/filesystem下的


2.网络驱动要正确
如果驱动或者网络硬件有问题则无法正确加载,还有种情况比如uboot的tftp都正常
但是启动内核的时候PHY的ID没配对导致无法检测到PHY也属于网络硬件问题


3.以上2种情况打印的信息不同,如果文件路径或系统不对则提示“无法挂载文件系统”
如果网络有问题则直接提示找不到PYH等


4.根文件系统一定要做好的文件系统挂载到某个目录下而不是一堆文件在某个目录里   




+-------------------------------------------+
+构建根文件系统
+-------------------------------------------+
1.dd if=/dev/zero of=ramdisk bs=1M count=64
2.mkfs.ext2 ramdisk
3.sudo mount -o loop ramdisk ./temp_fs
4.cp -bdrv rootfs ./temp_fs (cp -av rootfs/* ./temp_fs)
5.sudo umount ./temp_fs
6.gzip -v9 ramdisk
7.mkimage -n 'uboot ext2 ramdisk rootfs' -A ppc -O linux -T ramdisk -C gzip -d ramdisk.gz rootfs.ext2.gz.uboot   


+-------------------------------------------+
+构建最小根文件系统
+-------------------------------------------+  
1.静态设备文件 /dev/console /dev/null
2.init进程(来自busybox或者其它)
3.配置文件 /etc/inittab
4.配置文件中指定的程序
5.C库

注:linux内核配置需要支持这些文件系统及ramdisk等,制作的ramdisk大小需要与内核配置大小一致,busybox最好静态链接否则C库一定要拷对



+-------------------------------------------+
+构建最小根文件系统执行过程
+-------------------------------------------+   
1.配置编译busybox
./ltib -m prep -p bustbox
make menuconfig
make                 
也需要$ARCH和$CROSS_COMPILE,否则需要修改makefile或者配置选项 
如果途中提示错误,一般是重复定义,根据提示错误前一段查找到是那一段指令错误,重新make menuconfig去除此选项
make CONFIG_PREFIX=xxx install


2.进入CONFIG_PREFIX=xxx目录创建/dev目录并创建/dev/console /dev/null文件
mkdir dev
cd dev
sudo mknod console c 5 1
sudo mknod null c 1 3 


3.建立lib目录
mkdir lib
cp -d *.so* ./xxx


4.建立配置文件
mkdir etc
cd etc
gedit inittab
#添加启动命令
console::askfirst:-/bin/sh
#busybox init可识别的inittab动作 
sysinit 为init提供初始化命令脚本的路径
respawn 每当相应的进程终止执行立刻重新启动
askfirst 类似respawn,不过重新启动前显示提示确认
wait 告诉init进程必须等到相应进程完成后才能继续执行
once 仅执行一次,而且不会等待完成
ctrlaltdel 当ctrl-alt-delete键按下后执行相应进程
shutdown 关闭系统前执行相应进程
restart 当init重新启动时执行相应进程


+-------------------------------------------+
+增加最小根文件系统
+-------------------------------------------+
1.自动挂载proc文件系统
gedit inittab
添加::sysyinit:/etc/init.d/rcS


mkdir /etc/init.d
cd /etc/init.d
gedit rcS
添加
mount -a
chmod +x /etc/init.d/rcS


cd /etc
gedit fstab
添加
proc            /proc       proc    defaults          0       0


2.增加mdev自动创建设备文件
#增加挂载的文件系统/etc/fstab
tmpfs           /tmp        tmpfs    defaults          0       0
sysfs           /sys        sysfs    defaults          0       0
tmpfs           /dev        tmpfs    defaults          0       0
#增加的动作/etc/init.d/rcS
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
#增加/etc/mdev.conf文件否则报错,这个文件是规则文件


+-------------------------------------------+
+设备节点与驱动设备模型
+-------------------------------------------+
1./dev下设备节点来自手动创建和udev(mdev)创建
2./sys/class下所有创建的目录且包含dev属性文件(major:minor)创建的时候都会产生事件通知udev守护进程
3.udev守护进程收到后查找规则创建/dev/xxx设备节点






+-------------------------------------------+
+截自P2020说明文档
+-------------------------------------------+
Overview
--------
P2020RDB is a Low End Dual core platform supporting the P2020 processor
of QorIQ series. P2020 is an e500 based dual core SOC.


Building U-boot
-----------
To build the u-boot for P2020RDB:
make P2020RDB_config
make


NOR Flash Banks
-----------
RDB board for P2020 has two flash banks. They are both present on boot.


Booting by default is always from the boot bank at 0xef00_0000.


Memory Map
----------
0xef00_0000 - 0xef7f_ffff Alernate bank8MB
0xe800_0000 - 0xefff_ffff Boot bank8MB


0xef78_0000 - 0xef7f_ffff Alternate u-boot address512KB
0xeff8_0000 - 0xefff_ffff Boot u-boot address512KB


Switch settings to boot from the NOR flash banks
------------------------------------------------
SW4[8]=0 default NOR Flash bank
SW4[8]=1 Alternate NOR Flash bank


Flashing Images
---------------
To place a new u-boot image in the alternate flash bank and then boot
with that new image temporarily, use this:
tftp 1000000 u-boot.bin
erase ef780000 ef7fffff
cp.b 1000000 ef780000 80000


Now to boot from the alternate bank change the SW4[8] from 0 to 1.


To program the image in the boot flash bank:
tftp 1000000 u-boot.bin
protect off all
erase eff80000 ffffffff
cp.b 1000000 eff80000 80000


Using the Device Tree Source File
---------------------------------
To create the DTB (Device Tree Binary) image file,
use a command similar to this:


dtc -b 0 -f -I dts -O dtb p2020rdb.dts > p2020rdb.dtb


Likely, that .dts file will come from here;


linux-2.6/arch/powerpc/boot/dts/p2020rdb.dts


Booting Linux
-------------
Place a linux uImage in the TFTP disk area.


tftp 1000000 uImage.p2020rdb
tftp 2000000 rootfs.ext2.gz.uboot
tftp c00000 p2020rdb.dtb
bootm 1000000 2000000 c00000


Implementing AMP(Asymmetric MultiProcessing)
---------------------------------------------
1. Build kernel image for core0:


a. $ make 85xx/p1_p2_rdb_defconfig


b. $ make menuconfig
  - un-select "Processor support"->
"Symetric multi-processing support"


c. $ make uImage


d. $ cp arch/powerpc/boot/uImage /tftpboot/uImage.core0


2. Build kernel image for core1:


a. $ make 85xx/p1_p2_rdb_defconfig


b. $ make menuconfig
  - Un-select "Processor support"->
"Symetric multi-processing support"
  - Select "Advanced setup" ->
"Prompt for advanced kernel configuration options"
- Select
"Set physical address where the kernel is loaded"
and set it to 0x20000000, asssuming core1 will
start from 512MB.
- Select "Set custom page offset address"
- Select "Set custom kernel base address"
- Select "Set maximum low memory"
  - "Exit" and save the selection.


c. $ make uImage


d. $ cp arch/powerpc/boot/uImage /tftpboot/uImage.core1


3. Create dtb for core0:


$ dtc -I dts -O dtb -f -b 0
arch/powerpc/boot/dts/p2020rdb_camp_core0.dts >
/tftpboot/p2020rdb_camp_core0.dtb


4. Create dtb for core1:


$ dtc -I dts -O dtb -f -b 1
arch/powerpc/boot/dts/p2020rdb_camp_core1.dts >
/tftpboot/p2020rdb_camp_core1.dtb


5. Bring up two cores separately:


a. Power on the board, under u-boot prompt:
=> setenv <serverip>
=> setenv <ipaddr>
=> setenv bootargs root=/dev/ram rw console=ttyS0,115200
b. Bring up core1's kernel first:
=> setenv bootm_low 0x20000000
=> setenv bootm_size 0x10000000
=> tftp 21000000 uImage.core1
=> tftp 22000000 ramdiskfile
=> tftp 20c00000 p2020rdb_camp_core1.dtb
=> interrupts off
=> bootm start 21000000 22000000 20c00000
=> bootm loados
=> bootm ramdisk
=> bootm fdt
=> fdt boardsetup
=> fdt chosen $initrd_start $initrd_end
=> bootm prep
=> cpu 1 release $bootm_low - $fdtaddr -
c. Bring up core0's kernel(on the same u-boot console):
=> setenv bootm_low 0
=> setenv bootm_size 0x20000000
=> tftp 1000000 uImage.core0
=> tftp 2000000 ramdiskfile
=> tftp c00000 p2020rdb_camp_core0.dtb
=> bootm 1000000 2000000 c00000


Please note only core0 will run u-boot, core1 starts kernel directly
after "cpu release" command is issued.


+-------------------------------------------+
+PCI和PCIE的使用过程
+-------------------------------------------+
1.系统上电启动内核后执行到PCI和PCIE部分会自动检测总线上的器件,方法不同PCIE是读功能号是否为0
2.系统探测PCI或者PCIE的BAR范围大小,方法是写入0xffffffff然后回读,判断大小后分配总线基址,写入PCI或者PCIE基址寄存器
3.注意分配的是总线地址\=物理地址\=内核虚拟地址,物理地址经过ioremap可以得到内核可访问的虚拟地址,总线地址是PCIE设备相应读写事务比较地址用的
4.物理地址可以从/sys/bus/pci/xxxx:xx:xx/resource中得到


+-------------------------------------------+
+内核逻辑地址,物理地址和总线地址
+-------------------------------------------+
1.内核逻辑地址指的是3G->4G的内核空间地址,这个地址和内存的物理地址存在一个固定的偏移,内核逻辑地址=内存物理地址+OFFSET
2.物理地址指的是CPU总线的地址,比如访问内存或者一些外围设备的地址,或者说是CPU地址数据总线的地址
3.总线地址指的是PCI总线,IIC总线等等访问设备的地址
4.逻辑地址和物理地址可以通过宏转换或者ioremap来链接
5.总线地址和物理地址的关系与具体的平台相关,ARM和X86上相同,而PPC则不同
6.CPU访问PCI空间,虚拟地址经过MMU转换成物理地址,然后再映射成总线地址才能访问到设备

7.mmap和ioremap都是针对物理地址,通过建立叶表,在虚拟空间直接访问物理地址




+-------------------------------------------------+

+更换apt-get源

+-------------------------------------------------+

Ubuntu的默认源是美国的,所以下载起来特别慢,作为天朝的用户,自然要更换为天朝的源了。
国内有很多源可用,有些大学和公司也在维护着一些源,网上有很多可用的。
有个简单的办法:将/etc/apt/sources.list的us.archive 全部替换为cn.archive即可

然后执行sudo apt-get update才能使用



+-------------------------------------+

+ubuntu12.04 ROOT账户登录

+-------------------------------------+

当我们使用root权限时,一般都使用sudo命令进行。那么当我们安装完毕Ubuntu12.04时,root账户的默认密码是什么呢?在安装Ubuntu 12.04时并没有设置root的密码,登录的时候也没有使用root账户。当我们使用root权限时,一般都使用sudo命令进行。那么当我们安装完毕Ubuntu 12.04时,root账户的默认密码是什么呢?其实这个答案很简单:root账户没有密码。所以,如果你想使用root帐户登录,您必须首先启用的帐户,并重新设置或添加一个新的密码。下面的步骤会告诉你如何做到这一点。首先我们要先打开终端,执行:sudo passwd -u root # 来启用我们的root账户,如果你后悔了可以执行 sudo passwd -l root 来重新lock root用户。注意:sudo执行时输入的密码都是你当前用户的密码,不是root的密码。而且要保证你的用户具备了这种权限,配置文件在/etc/sudoers中。然后给root创建一个密码:sudo passwd root #看准提示进行输入,root的密码最好和其他用户的密码不同,不然会遇到一些麻烦。现在root用户也不被禁用了,也有密码了,那么如何使用root进行登录呢?执行如下命令: sudo sh -c ‘echo “greeter-show-manual-login=true” >> /etc/lightdm/lightdm.conf #这样是让lightdm可以手动输入root用户进行登录。执行完毕后重启,登录时点击lightdm下的登录按钮,输入root和密码即可使用root登录。
                                             
0 0
原创粉丝点击