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

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz

【Joytag 香蕉R1学习:七】OpenWrt for R1 组装脚本

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

摘要: 本文实现了两个简单的脚本,用于自动组装OpenWrt for R1(Lamobo R1)系统。
自从着手弄这个R1,做了一系列尝试
【Joytag 香蕉R1学习】R1初印象并点亮
【Joytag 香蕉R1学习】让R1路由器工作起来(小白文,慎入)
【Joytag 香蕉R1学习】自己动手组装OpenWrt for R1
【Joytag 香蕉R1学习】让新系统(OpenWrt for R1)上网
【Joytag 香蕉R1学习】OpenWrt for R1有线路由, Telnet,SSH, LuCI
【Joytag 香蕉R1学习】OpenWrt for R1:设置主机名、时区、LED


存在的问题

实际操作过程中,发现几个问题,
一:因为操作过程进行了各种测试,难免各种操作互相影响
这也许不影响使用,但是写教程则会不那么严谨。
(比如说安装LuCI后,我随手就重启了,那么不重启R1的话uHTTPd是否真的需要手动启动呢?)
类似这样的问题很多。

二:因为使用的是trunk镜像,那么当镜像更新,而我们这个OpenWrt for R1却没有更新内核等相关内容
那么安装一些内核相关的软件包时,会出现无法安装的情况。

三:好吧,有时候胡乱操作,彻底崩溃了,又忘记自己都干什么了。从头做起,一步一步,似魔鬼的爪牙。。。

所以,将最最麻烦的操作,【Joytag 香蕉R1学习】自己动手组装OpenWrt for R1 ,做成脚本,这样我们就可以随时获得一个崭新的镜像了,然后就可以从头开搞了。

OpenWrt for R1 组装脚本

为了节省下载文件的时间,我将操作分成两个脚本:
1)getfiles.sh (获取所需的文件)
  1. wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/uboot-sunxi-Lamobo_R1/openwrt-sunxi-Lamobo_R1-u-boot-with-spl.bin
  2. wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/uboot-sunxi-Lamobo_R1/openwrt-sunxi-Lamobo_R1-uEnv.txt
  3. wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/uboot-sunxi-Lamobo_R1/openwrt-sunxi-Lamobo_R1-boot.scr
  4. wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/sun7i-a20-lamobo-r1.dtb
  5. wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/openwrt-sunxi-uImage
  6. wget http://downloads.openwrt.org/snapshots/trunk/sunxi/generic/openwrt-sunxi-root.ext4
复制代码

2) mksys.sh (将OpenWrt for R1写入SD卡)
  1. if [ $# != 1 ] ; then
  2. echo "usage: $0 disk"
  3. echo " e.g.: $0 /dev/sda"
  4. exit 1;
  5. fi

  6. echo -e "\n#########   Prepare: Partition the disk    ########"

  7. disk=$1

  8. p1=${disk}1
  9. p2=${disk}2

  10. umount $p1
  11. umount $p2

  12. fdisk $1<
  13. p
  14. d
  15. 1
  16. d
  17. p
  18. n
  19. p
  20. 1

  21. +15M
  22. n
  23. p
  24. 2

  25. +240M
  26. t
  27. 1
  28. c
  29. p
  30. w
  31. EOF

  32. echo -e "\n......1) Copy the SPL + U-boot image to the card"
  33. dd if=openwrt-sunxi-Lamobo_R1-u-boot-with-spl.bin of=$disk bs=1024 seek=8

  34. echo -e "\n......2) Create a boot (FAT32) partition"
  35. mkfs.vfat ${disk}1

  36. echo -e "\n......3) Mount the boot partition"
  37. mount -t vfat ${disk}1 /mnt

  38. echo -e "\n......4) Copy the U-Boot environment file uEnv.txt to the boot partition"
  39. cp openwrt-sunxi-Lamobo_R1-uEnv.txt /mnt/uEnv.txt

  40. echo -e "\n......5) Copy the device tree data to the boot partition"
  41. cp sun7i-a20-lamobo-r1.dtb /mnt/dtb

  42. echo -e "\n......6) Copy the kernel image to the boot partition."
  43. cp openwrt-sunxi-uImage /mnt/uImage

  44. echo -e "\n......7) Copen the boot.scr to the boot partition."
  45. cp openwrt-sunxi-Lamobo_R1-boot.scr /mnt/boot.scr

  46. echo -e "\n......8) Resize the root filesystem image to match the partition size."
  47. resize2fs openwrt-sunxi-root.ext4 240M

  48. echo -e "\n......9)  Create the root filesystem."
  49. dd if=openwrt-sunxi-root.ext4 of=${disk}2 bs=128k

  50. echo -e "\n......10) Wrap up (flush buffers and unmount boot partition)."
  51. sync
  52. umount /mnt
  53. echo -e "\n......Finished!"

复制代码
其中:
mkfs.vfat ${disk}1
会对/dev/sda1进行格式化,清除原有内容。

还是有必要的。

使用方法:
将两个文件保存到工作目录,假定为/root/R1
cd /root/R1
chmod 777 getfiles.sh mksys.sh
./getfiles.sh
./mksys.sh /dev/sda      
(*:因为将TF卡插入读卡器连接至香蕉派,所以TF卡被识别为/dev/sda,请务必知道自己要操作的设备,以免对原系统造成破坏)
崭新的系统诞生啦,然后,搞吧。



脚本中需要完善的地方

getfiles.sh
1:可以将两个脚本合二为一,通过命令行参数判断是否需要重新下载文件。
2:获取文件之前,应该先删除本地已有的相关文件
3:对获取情况进行判断。

mksys.sh
1:发现存在分区的TF卡插入读卡器后会自动mount,所以先调用了umount.
完善点的脚本应该先判断mount的情况,再根据情况执行umount,这样就没有错误信息了。

2:正常情况应该先判断disk的分区情况,然后删除所有分区。并重新分区。
(实在是懒得弄了。没有分区去删除,虽然会有错误提示,但是没啥影响)

3:用默认值的情况,fdisk输出不太直观。

4:应该对执行的操作进行一些判断。

5:其它......

好吧,虽然问题多多,但是可用,我们的目的不是为了写一个多么完善的脚本,只是为了方便进一步折腾而已。
基本达成目标。
(之所以这么说,是为了掩盖我小白的本质)

附:./mksys.sh /dev/sda的输出
  1. # ./mksys.sh /dev/sda

  2. #########   Prepare: Partition the disk    ########
  3. umount: /dev/sda1: not mounted
  4. umount: /dev/sda2: not mounted

  5. Command (m for help):
  6. Disk /dev/sda: 15.9 GB, 15931539456 bytes
  7. 64 heads, 32 sectors/track, 15193 cylinders, total 31116288 sectors
  8. Units = sectors of 1 * 512 = 512 bytes
  9. Sector size (logical/physical): 512 bytes / 512 bytes
  10. I/O size (minimum/optimal): 512 bytes / 512 bytes
  11. Disk identifier: 0x5452574f

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

  15. Command (m for help): Partition number (1-4):
  16. Command (m for help): Selected partition 2

  17. Command (m for help):
  18. Disk /dev/sda: 15.9 GB, 15931539456 bytes
  19. 64 heads, 32 sectors/track, 15193 cylinders, total 31116288 sectors
  20. Units = sectors of 1 * 512 = 512 bytes
  21. Sector size (logical/physical): 512 bytes / 512 bytes
  22. I/O size (minimum/optimal): 512 bytes / 512 bytes
  23. Disk identifier: 0x5452574f

  24.    Device Boot      Start         End      Blocks   Id  System

  25. Command (m for help): Partition type:
  26.    p   primary (0 primary, 0 extended, 4 free)
  27.    e   extended
  28. Select (default p): Partition number (1-4, default 1): First sector (2048-31116287, default 2048): Using default value 2048
  29. Last sector, +sectors or +size{K,M,G} (2048-31116287, default 31116287):
  30. Command (m for help): Partition type:
  31.    p   primary (1 primary, 0 extended, 3 free)
  32.    e   extended
  33. Select (default p): Partition number (1-4, default 2): First sector (32768-31116287, default 32768): Using default value 32768
  34. Last sector, +sectors or +size{K,M,G} (32768-31116287, default 31116287):
  35. Command (m for help): Partition number (1-4): Hex code (type L to list codes): Changed system type of partition 1 to c (W95 FAT32 (LBA))

  36. Command (m for help):
  37. Disk /dev/sda: 15.9 GB, 15931539456 bytes
  38. 64 heads, 32 sectors/track, 15193 cylinders, total 31116288 sectors
  39. Units = sectors of 1 * 512 = 512 bytes
  40. Sector size (logical/physical): 512 bytes / 512 bytes
  41. I/O size (minimum/optimal): 512 bytes / 512 bytes
  42. Disk identifier: 0x5452574f

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

  46. Command (m for help): The partition table has been altered!

  47. Calling ioctl() to re-read partition table.

  48. WARNING: If you have created or modified any DOS 6.x
  49. partitions, please see the fdisk manual page for additional
  50. information.
  51. Syncing disks.

  52. ......1) Copy the SPL + U-boot image to the card
  53. 343+1 records in
  54. 343+1 records out
  55. 352244 bytes (352 kB) copied, 0.090026 s, 3.9 MB/s

  56. ......2) Create a boot (FAT32) partition
  57. mkfs.vfat 3.0.13 (30 Jun 2012)

  58. ......3) Mount the boot partition

  59. ......4) Copy the U-Boot environment file uEnv.txt to the boot partition

  60. ......5) Copy the device tree data to the boot partition

  61. ......6) Copy the kernel image to the boot partition.

  62. ......7) Copen the boot.scr to the boot partition.

  63. ......8) Resize the root filesystem image to match the partition size.
  64. resize2fs 1.42.5 (29-Jul-2012)
  65. The filesystem is already 61440 blocks long.  Nothing to do!


  66. ......9)  Create the root filesystem.
  67. 1920+0 records in
  68. 1920+0 records out
  69. 251658240 bytes (252 MB) copied, 31.8408 s, 7.9 MB/s

  70. ......10) Wrap up (flush buffers and unmount boot partition).

  71. ......Finished!
复制代码

鲜花

握手

雷人

路过

鸡蛋

相关阅读

相关分类

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

GMT+8, 2024-4-20 10:06 , Processed in 0.039380 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

返回顶部