狗趴(GodPub),开源硬件学习与实践

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz

【Joytag 香蕉R1学习:三】自己动手组装OpenWrt for R1

2015-2-17 11:21| 发布者: 卓泰科技| 查看: 3481| 评论: 0|原作者: 卓泰科技|来自: 狗趴技术论坛

摘要: 本文讲述如何自己动手组装OpenWrt for R1(Lamobo R1)系统。
尽管已经有香蕉派R1的镜像可以下载,但是本着折腾的原则,自己弄一下貌似也挺有趣。
而且有助于加深对R1启动过程的理解以及便于进一步学习。

在OpenWrt官网各种学习,终于发现一篇适合的文章:
http://wiki.openwrt.org/doc/hardware/soc/soc.allwinner.sunxi
这篇文章(Assembling the SD card image yourself)部分以Cubieboard3为例,讲述了如何自己组装SD卡镜像。因为我们用是BPI R1,所以需要做一些修改,现将修改后的流程记录,以供参考。

SD卡布局

SD layout with 512 byte blocks:
        
NAME start block size
MBR 0 1 block
u-boot-with-spl.bin
16 (8 KB) ~250 KB
FAT 2048 (1 MB) 15 MB
EXT4 32768 (16 MB) rest


用到的文件

另外,就BPI R1而言,我们需要准备如下文件:
(可以先把这些文件下载好,保存到当前工作目录下)
openwrt-sunxi-Lamobo_R1-u-boot-with-spl.bin
openwrt-sunxi-Lamobo_R1-uEnv.txt
openwrt-sunxi-Lamobo_R1-boot.scr 原文中未说明这个这个文件,会系统导致启动不起来
sun7i-a20-lamobo-r1.dtb
openwrt-sunxi-uImage
openwrt-sunxi-root.ext4

硬件

1)装有Linux系统的电脑或者虚拟机 (为了偷懒,我使用的BPI M1)
2)空白的TF以及卡套或者读卡器
3)BPI R1

操作步骤:

1)首先将TF卡插入装有Linux系统的电脑上,
我使用的是usb读卡器,在BPI M1会被识别为/dev/sda

2)Fdisk删除原有分区内容(如有),并保存

3)创建新的分区
# fdisk /dev/sda

(查看当前分区情况)
Command (m for help): p

Disk /dev/sda: 15.9 GB, 15931539456 bytes
64 heads, 32 sectors/track, 15193 cylinders, total 31116288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5452574f

   Device Boot      Start         End      Blocks   Id  System

(创建新分区1)
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-31116287, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31116287, default 31116287): +15M

(创建新分区2)
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2):
Using default value 2
First sector (32768-31116287, default 32768):
Using default value 32768
Last sector, +sectors or +size{K,M,G} (32768-31116287, default 31116287): +240M

(将分区1修改为FAT32格式,原文使用的mkfs.vfat命令)
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

(执行修改)
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 DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

4)查看当前分区情况
# fdisk -l /dev/sda

Disk /dev/sda: 15.9 GB, 15931539456 bytes
64 heads, 32 sectors/track, 15193 cylinders, total 31116288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5452574f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048       32767       15360    c  W95 FAT32 (LBA)
/dev/sda2           32768      524287      245760   83  Linux

5)将SPL以及UBOOT镜像复制到SD卡
# dd if=openwrt-sunxi-Lamobo_R1-u-boot-with-spl.bin of=/dev/sda bs=1024 seek=8

6)创建启动分区 (FAT32)
     原文使用的mkfs.vfat命令,我们已经通过fdisk的t命令进行了修改,所以无需此步骤

7)挂载启动分区
#mount -t vfat /dev/sda1 /mnt

8)复制u-boot环境文件到启动分区
# cp openwrt-sunxi-Lamobo_R1-uEnv.txt /mnt/uEnv.txt

9)复制设备树数据到启动分区
# cp sun7i-a20-lamobo-r1.dtb /mnt/dtb

10)复制内核镜像到启动分区
# cp openwrt-sunxi-uImage /mnt/uImage

11)复制boot.scr文件到启动分区
        原文中并未提及此步骤,根据资料描述(https://github.com/linux-sunxi/u-boot-sunxi/wiki#bootscr-support),u-boot在启动的时候会在第一个分区(FAT/extX格式)寻找/boot.scr或者/boot/boot.scr文件,boot.scr中可以包含用于载入script.bin,kernel,initrd(可选)以及设置内核启动参数的uboot命令。 之前未加载此内容,导致系统无法启动。
# cp openwrt-sunxi-Lamobo_R1-boot.scr /mnt/boot.scr

12)调整根文件系统镜像大小以符合分区大小
# resize2fs openwrt-sunxi-root.ext4 240M

13)创建根文件系统
# dd if=openwrt-sunxi-root.ext4 of=/dev/sda2 bs=128k

14)总结(冲洗缓冲区,并卸载启动分区)
# sync
# umount /mnt

将写好的TF卡插入R1,并上电。
通过串口,我们就会看到熟悉的界面。
关于如何连接串口请参考:《【Joytag 香蕉R1学习】R1初印象并点亮》

参考链接:
http://wiki.openwrt.org/doc/hardware/soc/soc.allwinner.sunxi
http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/
http://wiki.openwrt.org/toh/lamobo/r1
http://linux-sunxi.org/Lamobo_R1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
关于boot.scr

由于原文中并未提及boot.scr的复制
当执行完所有其它操作,将TF卡插入R1并启动时,出如下错误:


对比正常启动过程的dmsg输出
http://wiki.openwrt.org/toh/lamobo/r1
U-Boot SPL 2015.01 (Jan 19 2015 - 01:03:44)
DRAM: 1024 MiB
CPU: 960000000Hz, AXI/AHB/APB: 3/2/2


U-Boot 2015.01 (Jan 19 2015 - 01:03:44) Allwinner Technology

CPU:   Allwinner A20 (SUN7I)
I2C:   ready
DRAM:  1016 MiB
MMC:   SUNXI SD/MMC: 0
*** Warning - bad CRC, using default environment

Reserved 8192kB of RAM for Framebuffer.
In:    serial
Out:   serial
Err:   serial
SCSI:  SUNXI SCSI INIT
SATA link 0 timeout.
AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode
flags: ncq stag pm led clo only pmp pio slum part ccc apst
Net:   dwmac.1c50000
(Re)start USB...
USB0:   USB EHCI 1.00
scanning bus 0 for devices... 1 USB Device(s) found
USB1:   USB EHCI 1.00
scanning bus 1 for devices... 2 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  2  1  0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0...
Found U-Boot script /boot.scr
reading /boot.scr

377 bytes read in 16 ms (22.5 KiB/s)
## Executing script at 43100000
reading uImage
1939536 bytes read in 230 ms (8 MiB/s)
reading dtb
23803 bytes read in 29 ms (800.8 KiB/s)
## Booting kernel from Legacy Image at 42000000 ...
   Image Name:   ARM OpenWrt Linux-3.18.2
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1939472 Bytes = 1.8 MiB
   Load Address: 40008000
   Entry Point:  40008000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
   Loading Kernel Image ... OK
   Using Device Tree in place at 43000000, end 43008cfa

Starting kernel ...
这步应该是找到boot.scr并读取执行。
所以我们在原文的基础上,加入了这项内容。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

原文中使用mkfs.vfat
BPI  M1执行会遇到命令没找到错误

使用如下命令安装即可
apt-get install dosfstools



鲜花

握手

雷人

路过

鸡蛋

相关阅读

相关分类

QQ|Archiver|手机版|狗趴(GodPub) Arduino&Raspberry Pi开源硬件学习与实践[QQ群:20085629]  

GMT+8, 2024-4-27 04:43 , Processed in 0.024746 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

返回顶部