2015年3月22日星期二
北京华环电子:任晓亮
嵌入式系统制作:
uboot启动zImage(go)和uImage(bootm)分析
1.bootm加载linux镜像是加载uIamge,uIamge是由mkimage制作而来,和zIamge的差异是uIamge是zIamge压缩过的,bootm需要先对uIamge解压,解压地址为内核入口地址。当解压完成时uIamge和zIamge几乎是相同的,具体差异可以论述。uboot目前只能支持uImage启动,不支持zImage启动
2.bootm解压过程
---------------------------------------------------------------------------
## Booting image at 08808000 ...
Image Name: Linux-2.6.14.7
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 989172 Bytes = 966 kB
Load Address: 08008000
Entry Point: 08008000
Verifying Checksum ... OK
OK uboot bootm命令对uIamge的解压操作
---------------------------------------------------------------------------
Starting kernel ...
传递内核参数将控制权交给arch\arm\boot\compressed]head.S
----------------------------------------------------------------------------
如mx1ADS班子内存的起始地址为0x0800_0000,通过tftp 下载到0x0800_8000 +offset ,offset大于0x80_0000,即tftp0x0880_8000 然后bootm 0x0880_8000 即将0x0880_8000处的uIamge解压,解压地址即为mkimage 设置的kernel入口地址0x0800_8000。
zImage和uImage的区别 一、vmlinuz
vmlinuz 是可引导的、压缩的内核。“vm”代表“Virtual Memory”。Linux 支持虚拟内存,不像老的操作系统比如DOS有640KB内存的限制。Linux能够使用硬盘空间作为虚拟内存,因此得名“vm”。
vmlinuz 的建立有两种方式。一是编译内核时通过“make zImage”创建,然后通过:“cp/usr/src/linux-2.4/arch/i386/linux/boot/zImage/boot/vmlinuz”产生。zImage适用于 小内核的情况,它的存在是为了向后的兼容性。
二 是内核编译时通过命令make bzImage创建,然后通过:“cp/usr/src/linux-2.4/arch/i386/linux/boot/bzImage /boot/vmlinuz”产生。bzImage是压缩的内核映像,需要注意,bzImage不是用bzip2压缩的,bzImage中的bz容易引起误解,bz表示“big zImage”。 bzImage中的b是“big”意思。 zImage(vmlinuz)和bzImage(vmlinuz)都是用gzip压缩的。它们不仅是一个压缩文件,而且在这两个文件的开头部分内嵌有 gzip解压缩代码。所以你不能用gunzip 或 gzip –dc解包vmlinuz。
二、 initrd-x.x.x.img
initrd是“initial ramdisk”的简写。initrd一般被用来临时的引导硬件到实际内核vmlinuz能够接管并继续引导的状态。
initrd 映象文件是使用mkinitrd创建的。mkinitrd实用程序能够创建initrd映象文件。这个命令是RedHat专有的。其它Linux发行版或 许有相应的命令。这是个很方便的实用程序。具体情况请看帮助:manmkinitrd下面的命令创建initrd映象文件。
最后生成的内核镜象有两种zImage以及uImage。其中zImage下载到 目标板中后,可以直接用uboot的 命令go来 进行直接跳转。这时候内核直接解压启动。但是无法挂载文件系统,因为go命令没有将内核需要的相关的启动参数传递给内核。传递启动参数我们必须使用命令bootm来进行跳 转。Bootm命 令跳转只处理uImage的 镜象。
uboot源代码的tools/目录下 有mkimage工具,这个工具可以用来制作不压缩或者压缩的多种可启动映象文件。
mkimage在制作映象文件的时候,是在原来的可执行映象文件的前面加上一个0x40字节的头, 记录参数所指定的信息,这样uboot才 能识别这个映象是针对哪个CPU体 系结构的,哪个OS的, 哪种类型,加载内存中的哪个位置,入口点在内存的那个位置以及映象名是什么
用法如下:
./mkimage -A arch -O os -T type -C comp -a addr -e ep -n name -ddata_file[:data_file...] image
-A ==> set architecture to 'arch'
-O ==> set operating system to 'os'
-T ==> set image type to 'type'
-C ==> set compression type 'comp'
-a ==> set load address to 'addr' (hex)
-e ==> set entry point to 'ep' (hex)
-n ==> set image name to 'name'
-d ==> use image data from 'datafile'
-x ==> set XIP (execute in place)
参数说明:
-A 指定CPU的体系结构:
取值表示的体 系结构
alpha Alpha
arm A RM
x86 Intel x86
ia64 IA64
mips MIPS
mips64 MIPS 64 Bit
ppc PowerPC
s390 IBM S390
sh SuperH
sparc SPARC
sparc64 SPARC 64 Bit
m68k MC68000
-O 指定操作系统类 型,可以取以下值:
openbsd、netbsd、freebsd、4_4bsd、linux、svr4、esix、solaris、irix、sco、dell、ncr、lynxos、vxworks、psos、qnx、u-boot、rtems、artos
-T 指定映象类型, 可以取以下值:
standalone、kernel、ramdisk、multi、firmware、script、filesystem
-C 指定映象压缩方 式,可以取以下值:
none 不 压缩
gzip 用gzip的压缩方式
bzip2 用bzip2的压缩方 式
-a 指 定映象在内存中的加载地址,映象下载到内存中时,要按照用mkimage制作映象时,这个参数所指定的地址值来下载
-e 指定映象运行的 入口点地址,这个地址就是-a参 数指定的值加上0x40(因 为前面有个mkimage添 加的0x40个 字节的头)
-n 指定映象名
-d 指定制作映象的源文件
我在编译时用到的命令如下:
# make zImage //生成zImage镜象
#/usr/local/arm/k9uboot/tools/mkimage -n 'Linux 2.4.27'-A arm -O linux -T
kernel -C none -a 0x20007fc0 -e 0x20008000 -d zImage uImage
内核镜象已经准备好了,这个时候我们就要来准备文件系统了。由于时间缘故,本人暂时采用的是其他 人已经好的文件系统k9.img.gz。这个时候我们要做的是,自己写一个简单hello.c的程序,编译通过后加入到该文件系统中,然后下载到目标板中运行。
先编写hello.c;
编译:
#/usr/local/arm/2.95.3/bin/arm-linux-gcc –o start-hellohello.c
编译后生成可执行文件start-hello
下面我们就必须把该执行文件加入到文件系统中去,步骤如下:
#gunzipk9.img.gz //解 压缩
#mount –o loop k9.img /mnt/new_disk //挂载
#cp start-hello/mnt/new_disk //将文件拷贝到文件系统中
#cd /mnt/new_disk
#umount /mnt/new_disk //卸 载
#gzip –c –v9 k9.img >k9.img.gz //压缩生成最终的文件系统
下面我们就要下载内核以及准备好文件系统了,这边先说明我 的内存分配情况如下:
Flash:
0x10000000 ――― 0x10020000 boot
0x10020000 ――― 0x10040000 uboot
0x10040000 ――― 0x10060000 ubootenv
0x10060000 ――― 0x10200000 kernel
0x10200000 ――― 0x11000000 ramdisk
Sdram:
0x20007fc0 ――― 0x20a00000 kernel
0x20a00000 ――― ramdisk
Loadb 通过串口下载数据到ram中
cp.b 拷贝ram中的数据到flash中。
将kernel以及文件系统ramdisk下载完 毕之后,我们还需要设置uboot的 环境变量,这样uboot才 能够在上电启动的时候启动内核等操作。环境变量设置如下:
Set cpfltoram cp.b 10200000 20a0000018ffff //拷贝文件系统到ram中
Set boot bootm20007fc0 //启动kernel
Set bootcmd run cpfltoker\;run cpfltoram\;runboot //uboot复位的执行指令
Set cpfltoker cp.b 10060000 20007fc0f4fff //拷贝内核到ram中
Set bootargs root=/dev/ram rw initrd=0x20a00000,4M init=/linuxrcconsole=ttyS0,11520
0,mem=32m //uboot传 递给内核的启动参数
设置完毕后,saveenv把 环境变量存储起来。
学习心得:zImage 和uImage 都是生成的可执行内核镜像文件
2者在u-boot中启动的方式分别是 go addr 与 bootm addr 来实现启动过程的
即对于zImage是通过 go 来进行引导 而uImage是通过bootm来进行引导的
zImage 和 uImage 2者的关系 是 uImage 是zImage通过mkimage (u--boot下面tools下的工具)来生成的
结果是后者比前者在头部多了64个byte,这多余的64 个byte是用来通知给u-boot用的;将相关信息告知u-boot;
这样做的结果在u-boot引导内核时存在2个地址:loadaddress 和entry address 2者的差值刚好是0x40(64byte)的大小
这样在使用bootm loadaddress 时u-boot会根据相应的loadaddress进行调整,有2中情况;
1)、当loadaddress与mkimage时传送的一致时:
那么在加载 ldr pc,entry address时,会选择mkinage 时的entry地址;即pc=loadaddress + 4;然后由pc来控制流程跳转倒ram中去执行;
2)、当loadaddress与mkimage时传送的不一致时:
那么,u-bbot会进行地址比较 后,将当前的loadaddress减去64byte后,将真正的内核映像(去掉64byte头部的内核)拷贝倒预先制定的loadaddress,然后 直接从这个loadaddress来引导内核运行;
总结,那么上面2中情况实际区别呢?其实就是最终代码执行时,如果地址与mkinage时指定的 不符,那么u-boot将进行去头后,拷贝内核代码,直接执行;而如果不处理,则会将 loadaddress+0x40来执行内核;
通过tftp服务来下载 zImage或者uImage;
loadb 在tftp不成功的情况下使用 串口来下载内核 希望不要用这个方法
cp【.b\.w\.l】 完成 内存之间 内存向flash之间进行拷贝
最后可以设置 bootcmd 环境变量可以实现 u-boot自动引导内核启动
至于文件系统的2中方式:ramdisk 以及nfs 推荐开发者使用nfs 方便修改;
当使用ramdisk时,
#gunzipk9.img.gz //解压缩
#mount –o loop k9.img /mnt/new_disk //挂 载
#umount/mnt/new_disk //卸载
#gzip –c –v9 k9.img >k9.img.gz //压 缩生成最终的文件系统
这四条命令不要忘记,对于你来说多么强大
不要你去再建立根文件系统。
Uboot 参数设置
http://www.cnblogs.com/StevenZhan/p/Booting_Linux_from_QSPI_Flash_1024Mbit.html
Introduction
This solution documents the steps required to prepare an Arrow SoCKit evaluationboard to boot from QSPI. There are a few broad steps that are required.
· Prepare the boot files
· Write the boot files to the QSPI serial flash.
· Configure the board to boot from QSPI.
This Solution assumes you have a suitable Linux host available to developthe boot files for the SoCKit target. It is also important to note that this solution requiresthat you have the 3.9 release of the linux kernel and the 2013.01.01 release ofu-boot.Prepare the Boot files
1. The preloader (u-boot-spl)
Creating a preloader is shown in detail in the Arrow SoC Workshop Software Lab InstructionsGuide. You can download these materials at
http://www.arrownac.com/solutions/sockit/ under the Getting Started Tab.
Please refer to Module 3 for exact stepson how to create a preloader. The preloader can be modified to boot from QSPI.
To modify the preloader for QSPI do the following:
1. Open the bsp-editor and select the settings.bsp file ofthe existing preloader.
2. Check the checkbox next to BOOT_FROM_QSPI. Uncheck thecheckbox next to BOOT_FROM_SDMMC
3. Press the Generate button. Press exit.
4. Use make to build the executable as shown in the WorkshopSoftware Lab Instructions Guide Module 3.
5. Navigate to the /software/spl_bsp/uboot_socfpga/spldirectory
6. Create the bootable preloader. At the prompt type'mkpimage -o preloader_with_header_qspi.img u-boot-spl.bin'
7. Copy preloader_with_header_qspi.img to a folder where youwill gather all the bootable files.
2. Clone the Yocto Project git Tree
The instructions for cloning the Yocto Project git trees and buildingYocto Project are:
· git clone http://git.rocketboards.org/poky-socfpga.git
· cd poky-socfpga/
· git checkout -b <your_branch_name_goes_here>origin/danny-altera
· source ./altera-init build
· bitbake u-boot altera-image-minimal
· copy altera-image-minimal-socfpga_cyclone5-<builddate>.rootfs.jffs2 from poky-socfpga/build/tmp/deploy/images to a folderwhere you will gather all the bootable files
· copy socfpga_cyclone5-<build date>.dtb frompoky-socfpga/build/tmp/deploy/images to a folder where you will gather all thebootable files
· rename the files to remove the build date.
3. Modify u-boot to support Qspi
This section presents instructions on how to recompile u-boot. It assumesthat you have manually downloaded the build toolchain.
· open new shell. cdpoky-socfpga/build/tmp/work/armv7ahf-vfp-neon-poky-linux-gnueabi/u-boot-altera-2013.01.01-r0/git
· exportCROSS_COMPILE=~/gcc-linaro-arm-linux-gnueabihf-4.7-2012.11-20121123_linux/bin/arm-linux-gnueabihf-
· modifypoky-socfpga/build/tmp/work/armv7ahf-vfp-neon-poky-linux-gnueabi/u-boot-altera-2013.01.01-r0/git/board/altera/socfpga/build.h.as shown in the two bullets below
· #define CONFIG_PRELOADER_BOOT_FROM_QSPI (1)
· #define CONFIG_PRELOADER_BOOT_FROM_SDMMC (0)
· modifypoky-socfpga/build2/tmp/work/armv7ahf-vfp-neon-poky-linux-gnueabi/u-boot-altera-2013.01.01-r0/git/include/configs/socfpga_common.has shown in the three bullets below
· change #define CONFIG_BOOTCOMMAND "run mmcload; runmmcboot" to #define CONFIG_BOOTCOMMAND "run qspiload; runqspiboot"
· change #define CONFIG_BAUDRATE 115200 to #defineCONFIG_BAUDRATE 57600
· rebuild u-boot; make clean; make all
· copy u-boot.img frompoky-socfpga/build/tmp/work/armv7ahf-vfp-neon-poky-linux-gnueabi/u-boot-altera-2013.01.01-r0/gitto a folder where you will gather all the bootable files
4. Build the Linux kernel
This section presents instructions onhow to clone the Linux kernel git tree and compile the Linux kernel. It assumesthat you have manually downloaded the build toolchain.
Booting from Qspi is supported by the linux kernel 3.9 and later. Sincethe Yocto distribution of the kernel is 3.8 please do the following.
· git clone http://git.rocketboards.org/linux-socfpga.git
· cd linux-socfpga
· git checkout -b <your_branch_name_goes_here>socfpga-3.9
· exportCROSS_COMPILE=~/gcc-linaro-arm-linux-gnueabihf-4.7-2012.11-20121123_linux/bin/arm-linux-gnueabihf-
· make ARCH=arm socfpga_defconfig
· make ARCH=arm zImage LOADADDR=0x8000
· copy zImage from linux-socfpga/arch/arm/boot to a folderwhere you will gather all the bootable files
Write the Boot files to the QSPI serial flash
The Qspi requires the followingarrangement in order to boot.
There are two ways to achieve this. Thefirst uses the u-boot sf utility. The second uses the linux mtd_debug utility
1. u-boot sf utility
· obtain an SD card with a sockit_20130421.img (u-bootversion 2012.10, linux version 3.7) bootable image
· copy the five files that you have gathered on your hostto the fat32 partition of the SD card (partition 1)
· boot the SoCKit using theSD card. hit any key to stop autoboot of u-boot
· type 'fatls mmc 0:1' at the prompt to view all the fileson the fat32 partition of the SD card
· sf probe to intialise the QSPI controller
· fatload mmc 0:1 0x2000000 preloader_with_header.img
· sf erase 0x0000 0x10000
· sf write 0x2000000 0x0000 0x10000
· fatload mmc 0:1 0x2000000 u-boot.img
· sf erase 0x60000 0x40000
· sf write 0x2000000 0x60000 0x40000
· fatload mmc 0:1 0x2000000 socfpga_cyclone5.dtb
· sf erase 0x50000 0x10000
· sf write 0x2000000 0x50000 0x10000
· fatload mmc 0:1 0x2000000 zImage
· sf erase 0xa0000 0x400000
· sf write 0x2000000 0xa0000 0x400000
· fatload mmc 0:1 0x2000000altera-image-minimal-socfpga_cyclone5.rootfs.jffs2
· sf erase 0x800000 0xe00000
· sf write 0x2000000 0x800000 0xe00000
2. linux mtd_debug utility
· obtain an SD card that has u-boot 2013.01.01 and linux3.9
· boot the SoCKit to thelinux prompt. login as root
· create a password. use the 'passwd' command. set thepassword to be root
· use ifconfig to determine the targets ip address
· open a shell, on your linux host.
· cd to the directory where you have gathered the bootablefiles
· use scp to copy the files to the target.
· scp * root@<target ip address>:/home/root
· on the target use the mtd utility to write the bootablefiles to QSPI
· cd to the /hziome/root directory
· ls -al to get the exact length of each of the bootablefiles
· flash_erase /dev/mtd0 0 0
· flash_erase /dev/mtd1 0 0
· mtd_debug write /dev/mtd0 0 0x10000preloader_with_header.img
· mtd_debug write /dev/mtd0 0x50000<size-of-socfpga_cyclone5.dtb> socfpga_cyclone5.dtb
· mtd_debug write /dev/mtd0 0x60000<size-of-u-boot.img> u-boot.img
· mtd_debug write /dev/mtd0 0xa0000 <size-of-zImage>zImage
· flashcp altera-image-minimal-socfpga_cyclone5.jffs2/dev/mtd1
Configure the SoCKit board to boot from QSPI serial flash
· power down the SoCKit when thelast file has been written to QSPI
· change the BOOTSEL jumpers to '111'
· power the SoCKit on
· login as root; root
qspiboot=
echo Copying Linux from QSPI flash toRAM... &&
sf probe 0 0 0 &&
sf read ${loadbit_addr} 0xC00000 ${bitstream_size}&& 0x100000 0x3DBAFC
mw 0xF8007080 0x30800100 0x4 &&
fpga load 0 ${loadbit_addr}${bitstream_size} &&
sf read 0x3000000 0x100000 ${kernel_size}&&
sf read 0x2A00000 0x600000${devicetree_size} &&
echo Copying ramdisk... &&
sf read 0x2000000 0x620000 ${ramdisk_size}&&
bootm 0x3000000 0x2000000 0x2A00000
///
zynq-uboot> sf erase 0x100000 ${kernel_size}
SF: Successfully erased 5242880 bytes @0x100000
zynq-uboot> fatload mmc 0 0x3000000 ${kernel_image}
reading uImage
3488184 bytes read in 477 ms (7 MiB/s)
zynq-uboot> sf write 0x3000000 0x100000${kernel_size}
SF: program success 5242880 bytes @0x100000
zynq-uboot> fatload mmc 0 0x2A00000 ${devicetree_image}
reading devicetree.dtb
9283 bytes read in 15 ms (603.5 KiB/s)
zynq-uboot> sf erase 0x600000 ${devicetree_size}
SF: Successfully erased 131072 bytes @0x600000
zynq-uboot> echo ${devicetree_size}
0x20000
zynq-uboot> sf write 0x2A00000 0x600000 ${devicetree_size}
SF: program success 131072 bytes @ 0x600000
zynq-uboot> fatload mmc 0 0x2000000 ${uramdisk_image}
reading uramdisk.image.gz
5044192 bytes read in 682 ms (7.1 MiB/s)
zynq-uboot> sf erase 0x620000 ${ramdisk_size}
SF: Successfully erased 6160384 bytes @0x620000
zynq-uboot> sf write 0x2000000 0x620000${ramdisk_size}
SF: program success 6160384 bytes @0x620000
zynq-uboot>
linux 启动SD格式化
# mount
可以看到最后一行的设备号
/dev/mmcblk0 on /media/60C5-3EC0 type vfat(rw,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,flush)
umount这个sd卡
# umount /dev/mmcblk0
下面上场的是fdisk工具。
# fdisk /dev/mmcblk0
fdisk命令都是非常简单的。
WARNING: DOS-compatible mode is deprecated. It'sstrongly recommended to
switch off the mode (command 'c') and changedisplay units to
sectors (command 'u').
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partitiontable
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
先P,看看sd卡的分区现状。
然后d,删除原分区
n,创建分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-62528, default 1): 1
Last cylinder, +cylinders or +size{K,M,G}(1-62528, default 62528): +1500M
t,指定分区类型,
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L
0 Empty 24 NECDOS 81 Minix / old Linbf Solaris
1 FAT12 39 Plan9 82 Linux swap /So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIXusr 40 Venix80286 84 OS/2 hidden C: c6 DRDOS/sec(FAT-
4 FAT16<32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFSvolume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOSaccess
a OS/2 Boot Manag 51 OnTrack DM6 Aux94 Amoeba BBT e3 DOSR/O
b W95FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Auxa0 IBM Thinkpad hi eb BeOSfs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI(FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 DarwinUFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD orSys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 NovellNetware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb BootWizard hid fe LANstep
1c Hidden W95 FAT3 80 OldMinix be Solarisboot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 6
Changed system type of partition 1 to 6 (FAT16)
这样就分好了第一个分区,并且指定了分区为fat16。
第二个,我试做分区为linux分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (48002-62528, default 48002):
Using default value 48002
Last cylinder, +cylinders or +size{K,M,G}(48002-62528, default 62528):
Using default value 62528
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 83
Command (m for help): p
Disk /dev/mmcblk0: 2048 MB, 2048917504 bytes
4 heads, 16 sectors/track, 62528 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Sector size (logical/physical): 512 bytes / 512bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x6f20736b
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 1 48001 1536024 6 FAT16
/dev/mmcblk0p2 48002 62528 464864 83 Linux
好了,把分区信息写入磁盘。
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: If you have created or modified any DOS6.x
partitions, please see the fdisk manual page foradditional
information.
Syncing disks.
下面开始格式化。
首先是fat16分区
#mkdosfs /dev/mmcblk0p1
然后是linux分区
#mkfs.ext3 /dev/mmcblk0p2
Ubuntu14.04 安装32位库
方法一:
sudo apt-get install libc6:i386
sudo -i
cd /etc/apt/sources.list.d
echo "debhttp://archive.ubuntu.com/ubuntu/ raring main restricted universemultiverse" >ia32-libs-raring.list
apt-get update
apt-get install ia32-libs
rm /ia32-libs-raring.list
apt-get update
exit
sudo apt-get install gcc-multilib
方法二:
On 64 bits linux systems you'll need theia32-libs package
With the latestDebian (multiarch), you need this:
dpkg --add-architecture i386
aptitude update
aptitude install libstdc++6:i386 libgcc1:i386 zlib1g:i386libncurses5:i386
Ubuntu14.04 安装X11VNC 远程桌面:
主要目的:利用命令行开启远程服务器图形界面,然后再用vnc远客到服务端的x11vnc(我的服务端桌面用的xfce所以采用x11vnc,如果你的是gnome或者kde,则需采用vnc4server)
配置过程:
1:安装x11vnc
sudo apt-get install x11vnc
2:为x11vnc设置密码
sudo x11vnc -storepasswd 需要设置的密码
3:如果愿意每次手动远程启动x11vnc则不用往下看了
4:sudo x11vnc-storepasswd in /etc/x11vnc.pass
5:sudo cp~/.vnc/passwd /etc/x11vnc.pass (认为你是非root的其它管理员)
6:sudo vim/etc/init/x11vnc.conf (如果没有这个文件则创建一个)
7:把以下代码复制到x11vnc.conf(这样你就不用每次都要去手动启用了)
start on login-session-start
script
x11vnc -display :0 -auth/var/run/lightdm/root/:0 -forever -bg -o /var/log/x11vnc.log -rfbauth/etc/x11vnc.pass -rfbport 5900
end script
Linux内存管理:
在前面我们讲解了kmalloc申请连续物理内存的操作,以及原理和基础cache . 在内核中还有另外一个接口函数那就是vmalloc,申请一片连续的虚拟地址空间,但不保证物理空间连续,实际上我们会想到用户空间的malloc,malloc它是标准的glibc封装的一个函数,最终实现是通过系统调用brk和mmap来实现,以后在分析它的实现过程. 它就是申请连续的虚拟空间,但是不保证物理内存的连续,当然用户程序也不怎么关心这个问题,只所以会关心物理内存的连续性一般是由于设备驱动的使用,或者DMA. 但是vmalloc申请效率比较低,还会造成TLB抖动. 一般内核里常用kmalloc. 除非特殊需求,比如要获取大块内存时,实例就是当ko模块加载到内核运行时,即需要vmalloc.
释放函数:vfree
参考内核 3.8.13
这里是说32位的处理器,即最大寻址4G虚拟空间,(当然现在已经64位比较普及了,后续补上吧)而虚拟地址到物理地址的转化往往需要硬件的支持才能提高效率,即MMU。
当然前提需要os先建立页表PT. 在linux内核,这4G空间并不是完全给用户空间使用在高端0xC0000000 (3G开始)留给内核空间使用(x86默认配置,默认0-16M(DMA),16M-896M(Normal),896M-1G(128M)作为高端内存分配区域),当然这个区域也是可是配置的.).
kmalloc函数返回的是虚拟地址(线性地址). kmalloc特殊之处在于它分配的内存是物理上连续的,这对于要进行DMA的设备十分重要. 而用vmalloc分配的内存只是线性地址连续,物理地址不一定连续,不能直接用于DMA。我们可以参考一个图:(它是arm 32架构的内核虚拟地址分配图)