20161220_jeffrey - silenceuncrio/diary GitHub Wiki
- 0920 - review
-
0930 - 解析
burn the rootfs to NAND
流程 - 0935 - flash_erase /dev/mtd9 0 0
- 0940 - ubiformat /dev/mtd9
- 0945 - ubiattach /dev/ubi_ctrl -m 9
- 0950 - ubimkvol /dev/ubi1 -Nrootfs -m
- 1020 - mkdir -p /mnt/mtd9
- 1025 - mount -t ubifs ubi1:rootfs /mnt/mtd9
- 1040 - tar -jxv -C /mnt/mtd9 -f images/core-image-minimal-imx6ulevk.tar.bz2
- 1055 - umount /mnt/mtd9
- 1120 - http://www.linux-mtd.infradead.org/doc/ubi.html
- 1350 - mfgtool - ucl2.xml - 讓 rootfs_a, rootfs_b, config_a 和 config_b 跟 ubi device 的關係先固定下來
-
1450 - 使用
ubiattach -m 5
來 attach MTD device 5 (mtd5) to UBI 之後可看到 ubimkvol 的效果 -
1530 - 再次的開機 除了
ubi0
看不到其他的 ubi device - 1555 - 需要一個地方來做 ubiattach 的動作
-
1700 - 修改
/etc/rc.local
-
1715 - 根據 uboot env 來決定到底是要 attach
config_a
或config_b
-
1815 - patch
<u-boot-fw-utils>/tools/env/fw_env.config
- 1835 - git commit
review
解析一下 burn the rootfs to NAND
的流程 - rootfs partition = mtd9
- Erasing rootfs partition
flash_erase /dev/mtd9 0 0
- ubiformat
ubiformat /dev/mtd9
- Attaching UBI partition
ubiattach /dev/ubi_ctrl -m 9
- create UBI volumes for UBI device number 1
ubimkvol /dev/ubi1 -Nrootfs -m
mkdir -p /mnt/mtd9
mount -t ubifs ubi1:rootfs /mnt/mtd9
- writting rootfs
tar -jxv -C /mnt/mtd9 -f images/core-image-minimal-imx6ulevk.tar.bz2
- Unmounting rootfs partition
umount /mnt/mtd9
flash_erase /dev/mtd9 0 0
root@M300:~# flash_erase --help
Usage: flash_erase [options] MTD_DEVICE <start offset> <block count>
Erase blocks of the specified MTD device.
Specify a count of 0 to erase to end of device.
-j, --jffs2 format the device for jffs2
-N, --noskipbad don't skip bad blocks
-u, --unlock unlock sectors before erasing
-q, --quiet do not display progress messages
--silent same as --quiet
--help display this help and exit
--version output version information and exit
flash_erase /dev/mtd9 0 0
- Erase all blocks of
/dev/mtd9
ubiformat /dev/mtd9
root@M300:~# ubiformat --help
ubiformat version 1.5.1 - a tool to format MTD devices and flash UBI images
Usage: ubiformat <MTD device node file name> [-s <bytes>] [-O <offs>] [-n]
[-Q <num>] [-f <file>] [-S <bytes>] [-e <value>] [-x <num>] [-y] [-q] [-v] [-h]
[--sub-page-size=<bytes>] [--vid-hdr-offset=<offs>] [--no-volume-table]
[--flash-image=<file>] [--image-size=<bytes>] [--erase-counter=<value>]
[--image-seq=<num>] [--ubi-ver=<num>] [--yes] [--quiet] [--verbose]
[--help] [--version]
Example 1: ubiformat /dev/mtd0 -y - format MTD device number 0 and do
not ask questions.
Example 2: ubiformat /dev/mtd0 -q -e 0 - format MTD device number 0,
be quiet and force erase counter value 0.
-s, --sub-page-size=<bytes> minimum input/output unit used for UBI
headers, e.g. sub-page size in case of NAND
flash (equivalent to the minimum input/output
unit size by default)
-O, --vid-hdr-offset=<offs> offset if the VID header from start of the
physical eraseblock (default is the next
minimum I/O unit or sub-page after the EC
header)
-n, --no-volume-table only erase all eraseblock and preserve erase
counters, do not write empty volume table
-f, --flash-image=<file> flash image file, or '-' for stdin
-S, --image-size=<bytes> bytes in input, if not reading from file
-e, --erase-counter=<value> use <value> as the erase counter value for all
eraseblocks
-x, --ubi-ver=<num> UBI version number to put to EC headers
(default is 1)
-Q, --image-seq=<num> 32-bit UBI image sequence number to use
(by default a random number is picked)
-y, --yes assume the answer is "yes" for all question
this program would otherwise ask
-q, --quiet suppress progress percentage information
-v, --verbose be verbose
-h, -?, --help print help message
-V, --version print program version
ubiformat /dev/mtd9
- format MTD device number 9
ubiattach /dev/ubi_ctrl -m 9
root@M300:~# ubiattach --help
ubiattach version 1.5.1 - a tool to attach MTD device to UBI.
Usage: ubiattach [<UBI control device node file name>]
[-m <MTD device number>] [-d <UBI device number>] [-p <path to device>]
[--mtdn=<MTD device number>] [--devn=<UBI device number>]
[--dev-path=<path to device>]
[--max-beb-per1024=<maximum bad block number per 1024 blocks>]
UBI control device defaults to /dev/ubi_ctrl if not supplied.
Example 1: ubiattach -p /dev/mtd0 - attach /dev/mtd0 to UBI
Example 2: ubiattach -m 0 - attach MTD device 0 (mtd0) to UBI
Example 3: ubiattach -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI
and create UBI device number 3 (ubi3)
Example 4: ubiattach -m 1 -b 25 - attach /dev/mtd1 to UBI and reserve
25*C/1024 eraseblocks for bad block handling, where C is the flash
is total flash chip eraseblocks count, that is flash chip size in
eraseblocks (including bad eraseblocks). E.g., if the flash chip
has 4096 PEBs, 100 will be reserved.
-d, --devn=<number> the number to assign to the newly created UBI device
(assigned automatically if this is not specified)
-p, --dev-path=<path> path to MTD device node to attach
-m, --mtdn=<number> MTD device number to attach (alternative method, e.g
if the character device node does not exist)
-O, --vid-hdr-offset VID header offset (do not specify this unless you really
know what you are doing, the default should be optimal)
-b, --max-beb-per1024 maximum expected bad block number per 1024 eraseblock.
The default value is correct for most NAND devices.
Allowed range is 0-768, 0 means the default kernel value.
-h, --help print help message
-V, --version print program version
ubiattach /dev/ubi_ctrl -m 9
- attach MTD device 9 (mtd9) to UBI
ubimkvol /dev/ubi1 -Nrootfs -m
root@M300:~# ubimkvol --help
ubimkvol version 1.5.1 - a tool to create UBI volumes.
Usage: ubimkvol <UBI device node file name> [-h] [-a <alignment>] [-n <volume ID>] [-N <name>]
[-s <bytes>] [-S <LEBs>] [-t <static|dynamic>] [-V] [-m]
[--alignment=<alignment>][--vol_id=<volume ID>] [--name=<name>]
[--size=<bytes>] [--lebs=<LEBs>] [--type=<static|dynamic>] [--help]
[--version] [--maxavsize]
Example: ubimkvol /dev/ubi0 -s 20MiB -N config_data - create a 20 Megabytes volume
named "config_data" on UBI device /dev/ubi0.
-a, --alignment=<alignment> volume alignment (default is 1)
-n, --vol_id=<volume ID> UBI volume ID, if not specified, the volume ID
will be assigned automatically
-N, --name=<name> volume name
-s, --size=<bytes> volume size volume size in bytes, kilobytes (KiB)
or megabytes (MiB)
-S, --lebs=<LEBs count> alternative way to give volume size in logical
eraseblocks
-m, --maxavsize set volume size to maximum available size
-t, --type=<static|dynamic> volume type (dynamic, static), default is dynamic
-h, -?, --help print help message
-V, --version print program version
ubimkvol /dev/ubi1 -Nrootfs -m
- create a volume named "rootfs" on UBI device /dev/ubi1
UBI device /dev/ubi1
應該是做完 ubiattach /dev/ubi_ctrl -m 9
後產生的
這邊的 volume type 就可以指定 read-only 或 read-write
參考 http://www.linux-mtd.infradead.org/doc/ubi.html
There are 2 types of UBI volumes - dynamic volumes and static volumes. Static volumes are read-only and their contents are protected by CRC-32 checksums, while dynamic volumes are read-write and the upper layers (e.g., a file-system) are responsible for ensuring data integrity.
mkdir -p /mnt/mtd9
參考 https://www.busybox.net/downloads/BusyBox.html
mkdir
mkdir [OPTIONS] DIRECTORY...
Create DIRECTORY
Options:
-m Mode
-p No error if exists; make parent directories as needed
mkdir -p /mnt/mtd9
- create derectory /mnt/mtd9, no error if exists, make parent directories as needed
mount -t ubifs ubi1:rootfs /mnt/mtd9
參考 https://www.busybox.net/downloads/BusyBox.html
mount
mount [flags] DEVICE NODE [-o OPT,OPT]
Mount a filesystem. Filesystem autodetection requires /proc.
Options:
-a Mount all filesystems in fstab
-f Dry run
-i Don't run mount helper
-r Read-only mount
-w Read-write mount (default)
-t FSTYPE Filesystem type
-O OPT Mount only filesystems with option OPT (-a only)
-o OPT:
loop Ignored (loop devices are autodetected)
[a]sync Writes are [a]synchronous
[no]atime Disable/enable updates to inode access times
[no]diratime Disable/enable atime updates to directories
[no]relatime Disable/enable atime updates relative to modification time
[no]dev (Dis)allow use of special device files
[no]exec (Dis)allow use of executable files
[no]suid (Dis)allow set-user-id-root programs
[r]shared Convert [recursively] to a shared subtree
[r]slave Convert [recursively] to a slave subtree
[r]private Convert [recursively] to a private subtree
[un]bindable Make mount point [un]able to be bind mounted
bind Bind a directory to an additional location
move Relocate an existing mount point
remount Remount a mounted filesystem, changing its flags
ro/rw Read-only/read-write mount
There are EVEN MORE flags that are specific to each filesystem You'll have to see the written documentation for those filesystems
解析一下參數
- -t FSTYPE = ubifs - Filesystem type = ubifs
- DEVICE = ubi1:rootfs
- NODE = /mnt/mtd9
tar -jxv -C /mnt/mtd9 -f images/core-image-minimal-imx6ulevk.tar.bz2
root@M300:/# tar --help
Usage: tar [OPTION...] [FILE]...
GNU 'tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.
...
Main operation mode:
...
-x, --extract, --get extract files from an archive
...
Device selection and switching:
...
-f, --file=ARCHIVE use archive file or device ARCHIVE
...
Compression options:
...
-j, --bzip2 filter the archive through bzip2
...
Local file selection:
...
-C, --directory=DIR change to directory DIR
...
Informative output:
...
-v, --verbose verbosely list files processed
...
tar -jxv -C /mnt/mtd9 -f images/core-image-minimal-imx6ulevk.tar.bz2
- extract files from an archive
- use archive file - images/core-image-minimal-imx6ulevk.tar.bz2
- filter the archive through bzip2
- change to directory
/mnt/mtd9
- verbosely list files processed
umount /mnt/mtd9
參考 https://www.busybox.net/downloads/BusyBox.html
umount
umount [flags] FILESYSTEM|DIRECTORY
Unmount file systems
Options:
-a Unmount all file systems
-r Try to remount devices as read-only if mount is busy
-l Lazy umount (detach filesystem)
-f Force umount (i.e., unreachable NFS server)
-d Free loop device if it has been used
study http://www.linux-mtd.infradead.org/doc/ubi.html
感覺 rootfs 要改成 read-only 這件事要放後面一點
先就最新的 nand flash layout
修改 mfgtool - ucl2.xml - 讓 rootfs_a, rootfs_b, config_a 和 config_b 跟 ubi device 的關係先固定下來
<UCL>
<CFG>
<STATE name="BootStrap" dev="MX6SL" vid="15A2" pid="0063"/>
<STATE name="BootStrap" dev="MX6D" vid="15A2" pid="0061"/>
<STATE name="BootStrap" dev="MX6Q" vid="15A2" pid="0054"/>
<STATE name="BootStrap" dev="MX6SX" vid="15A2" pid="0071"/>
<STATE name="BootStrap" dev="MX6UL" vid="15A2" pid="007D"/>
<STATE name="BootStrap" dev="MX7D" vid="15A2" pid="0076"/>
<STATE name="Updater" dev="MSC" vid="066F" pid="37FF"/>
</CFG>
<LIST name="NAND Flash" desc="Choose NAND as media">
<CMD state="BootStrap" type="boot"
body="BootStrap" file ="firmware/u-boot.imx">Loading U-boot</CMD>
<CMD state="BootStrap" type="load"
file="firmware/zImage" address="0x80800000"
loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE" >Loading Kernel.</CMD>
<CMD state="BootStrap" type="load"
file="firmware/%initramfs%" address="0x83800000"
loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE">Loading Initramfs.</CMD>
<CMD state="BootStrap" type="load"
file="firmware/zImage-imx6ul-%6uldtb%-%nanddtb%.dtb" address="0x83000000"
loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE">Loading device tree.</CMD>
<CMD state="BootStrap" type="jump" > Jumping to OS image. </CMD>
<!--burn the uboot to NAND: -->
<CMD state="Updater" type="push"
body="$ mount -t debugfs debugfs /sys/kernel/debug">Mounting debugfs</CMD>
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd0 0 0">Erasing Boot partition</CMD>
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd1 0 0">Erasing Boot env partition</CMD>
<CMD state="Updater" type="push"
body="send" file="files/u-boot.imx" ifdev="MX6UL">Sending u-boot.bin</CMD>
<CMD state="Updater" type="push"
body="$ kobs-ng init -x -v --chip_0_device_path=/dev/mtd0 $FILE">Flashing Bootloader</CMD>
<!--burn the kernel to NAND: -->
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd2 0 0">Erasing Kernel partition</CMD>
<CMD state="Updater" type="push"
body="send" file="files/zImage">Sending kernel zImage</CMD>
<CMD state="Updater" type="push"
body="$ nandwrite -p /dev/mtd2 -p $FILE">Flashing Kernel</CMD>
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd3 0 0">Erasing dtb partition</CMD>
<CMD state="Updater" type="push"
body="send" file="files/zImage-imx6ul-14x14-evk.dtb">Sending Device Tree file</CMD>
<CMD state="Updater" type="push"
body="$ nandwrite -p /dev/mtd3 -p $FILE">Flashing dtb</CMD>
<!--prepare all ubi device: -->
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd4 0 0">Erasing rootfs_a partition</CMD>
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd5 0 0">Erasing config_a partition</CMD>
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd9 0 0">Erasing rootfs_b partition</CMD>
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd10 0 0">Erasing config_b partition</CMD>
<CMD state="Updater" type="push"
body="$ ubiformat /dev/mtd4"/>
<CMD state="Updater" type="push"
body="$ ubiformat /dev/mtd5"/>
<CMD state="Updater" type="push"
body="$ ubiformat /dev/mtd9"/>
<CMD state="Updater" type="push"
body="$ ubiformat /dev/mtd10"/>
<CMD state="Updater" type="push"
body="$ ubiattach /dev/ubi_ctrl -m 4">Attaching UBI partition - /dev/ubi0</CMD>
<CMD state="Updater" type="push"
body="$ ubiattach /dev/ubi_ctrl -m 5">Attaching UBI partition - /dev/ubi1</CMD>
<CMD state="Updater" type="push"
body="$ ubiattach /dev/ubi_ctrl -m 9">Attaching UBI partition - /dev/ubi2</CMD>
<CMD state="Updater" type="push"
body="$ ubiattach /dev/ubi_ctrl -m 10">Attaching UBI partition - /dev/ubi3</CMD>
<CMD state="Updater" type="push"
body="$ ubimkvol /dev/ubi0 -N rootfs_a -m"/>
<CMD state="Updater" type="push"
body="$ ubimkvol /dev/ubi1 -N config_a -m"/>
<CMD state="Updater" type="push"
body="$ ubimkvol /dev/ubi2 -N rootfs_b -m"/>
<CMD state="Updater" type="push"
body="$ ubimkvol /dev/ubi3 -N config_b -m"/>
<!--burn the rootfs_a to NAND: -->
<CMD state="Updater" type="push"
body="$ mkdir -p /mnt/rootfs_a"/>
<CMD state="Updater" type="push"
body="$ mount -t ubifs ubi0:rootfs_a /mnt/rootfs_a"/>
<CMD state="Updater" type="push"
body="pipe tar -jxv -C /mnt/rootfs_a" file="files/core-image-minimal-imx6ulevk.tar.bz2">Sending and writting rootfs_a</CMD>
<CMD state="Updater" type="push"
body="frf">Finishing rootfs write</CMD>
<CMD state="Updater" type="push"
body="$ umount /mnt/rootfs_a">Unmounting rootfs_a partition</CMD>
<CMD state="Updater" type="push"
body="$ echo Update Complete!">Done</CMD>
</LIST>
</UCL>
mfgtool 燒錄... ok
開機進 uboot 需要修改 bootargs root
為 ubi0:rootfs_a
開機進 linux
root@M300:~# ubinfo -a
UBI version: 1
Count of UBI devices: 1
UBI control device major/minor: 10:60
Present UBI devices: ubi0
ubi0
Volumes count: 1
Logical eraseblock size: 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks: 767 (97390592 bytes, 92.9 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes 128
Count of bad physical eraseblocks: 1
Count of reserved physical eraseblocks: 39
Current maximum erase counter value: 1
Minimum input/output unit size: 2048 bytes
Character device major/minor: 249:0
Present volumes: 0
Volume ID: 0 (on ubi0)
Type: dynamic
Alignment: 1
Size: 724 LEBs (91930624 bytes, 87.7 MiB)
State: OK
Name: rootfs_a
Character device major/minor: 249:1
shit!
不能這樣玩
不過發現只要使用 ubiattach -m 5
來 attach MTD device 5 (mtd5) to UBI 之後
root@M300:~# ubiattach -m 5
UBI device number 1, total 128 LEBs (16252928 bytes, 15.5 MiB), available 0 LEBs (0 bytes), LEB size 126976 bytes (124.0 KiB)
就可以看到 config_a
了
root@M300:~# ubinfo -a
UBI version: 1
Count of UBI devices: 2
UBI control device major/minor: 10:60
Present UBI devices: ubi0, ubi1
ubi0
Volumes count: 1
Logical eraseblock size: 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks: 767 (97390592 bytes, 92.9 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes 128
Count of bad physical eraseblocks: 1
Count of reserved physical eraseblocks: 39
Current maximum erase counter value: 1
Minimum input/output unit size: 2048 bytes
Character device major/minor: 249:0
Present volumes: 0
Volume ID: 0 (on ubi0)
Type: dynamic
Alignment: 1
Size: 724 LEBs (91930624 bytes, 87.7 MiB)
State: OK
Name: rootfs_a
Character device major/minor: 249:1
===================================
ubi1
Volumes count: 1
Logical eraseblock size: 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks: 128 (16252928 bytes, 15.5 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes 128
Count of bad physical eraseblocks: 0
Count of reserved physical eraseblocks: 40
Current maximum erase counter value: 1
Minimum input/output unit size: 2048 bytes
Character device major/minor: 248:0
Present volumes: 0
Volume ID: 0 (on ubi1)
Type: dynamic
Alignment: 1
Size: 84 LEBs (10665984 bytes, 10.2 MiB)
State: OK
Name: config_a
Character device major/minor: 248:1
要注意的是如果我再次的開機
除了 ubi0
一樣看不到其他的 ubi device
如果這一次使用 ubiattach -m 9
來 attach MTD device 9 (mtd9) to UBI 之後
root@M300:~# ubiattach -m 9
UBI device number 1, total 767 LEBs (97390592 bytes, 92.9 MiB), available 0 LEBs (0 bytes), LEB size 126976 bytes (124.0 KiB)
那 ubi1
這個 device 就跟 MTD device 9 綁在一起了
root@M300:~# ubinfo -a
UBI version: 1
Count of UBI devices: 2
UBI control device major/minor: 10:60
Present UBI devices: ubi0, ubi1
ubi0
Volumes count: 1
Logical eraseblock size: 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks: 767 (97390592 bytes, 92.9 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes 128
Count of bad physical eraseblocks: 1
Count of reserved physical eraseblocks: 39
Current maximum erase counter value: 1
Minimum input/output unit size: 2048 bytes
Character device major/minor: 249:0
Present volumes: 0
Volume ID: 0 (on ubi0)
Type: dynamic
Alignment: 1
Size: 724 LEBs (91930624 bytes, 87.7 MiB)
State: OK
Name: rootfs_a
Character device major/minor: 249:1
===================================
ubi1
Volumes count: 1
Logical eraseblock size: 126976 bytes, 124.0 KiB
Total amount of logical eraseblocks: 767 (97390592 bytes, 92.9 MiB)
Amount of available logical eraseblocks: 0 (0 bytes)
Maximum count of volumes 128
Count of bad physical eraseblocks: 1
Count of reserved physical eraseblocks: 39
Current maximum erase counter value: 1
Minimum input/output unit size: 2048 bytes
Character device major/minor: 248:0
Present volumes: 0
Volume ID: 0 (on ubi1)
Type: dynamic
Alignment: 1
Size: 724 LEBs (91930624 bytes, 87.7 MiB)
State: OK
Name: rootfs_b
Character device major/minor: 248:1
這是一個性質
要注意
研究一下 /etc/rc.local
我需要一個地方來做 ubiattach 的動作
參考目前的開機訊息
...
Running local boot scripts (/etc/rc.local)Crash dump mode:Dump latest 100 items to crash.log.
Crash dump mode:Dump latest 100 items to crash.log.
### module <system> init
### module <syslog> init
### module <switch> init
### module <wanst> init
### module <lan> init
### module <dhcpc> init
### module <firewall> init
### module <firewall6> init
### module <dns6> init
### module <web> init
### module <virtual-server> init
### module <nat> init
### module <dhcp> init
### module <sntp> init
### module <ssh> init
### module <ipsec> init
### module <pppoe_client> init
### module <ddns> init
### module <ipv6lan> init
### module <dhcp6c> init
### module <alarm> init
### module <lte> init
### module <com> init
### module <vcom> init
### module <openvpn> init
### module <netmon> init
### module <connmgr> init
.
Freescale i.MX Release Distro 3.14.52-1.1.1 M300 /dev/ttymxc0
M300 login:
看一下目前的 /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# by Ariel Chang
# Update: 2016/7/28
UBOOT_VER=$(sed -e '/.*ubootver/!d' -e 's/.*ubootver=\(.*\)/\1/' -e 's/\(\([^ ]*\) \)\{1\}.*/\2/' /proc/cmdline)
MAC=$(sed -e '/.*ethaddr/!d' -e 's/.*ethaddr=\(.*\)/\1/' -e 's/\(\([^ ]*\) \)\{1\}.*/\2/' /proc/cmdline)
HW_MCSV=$(sed -e '/.*mcsv/!d' -e 's/.*mcsv=\(.*\)/\1/' -e 's/\(\([^ ]*\) \)\{1\}.*/\2/' /proc/cmdline)
SERIALNO=$(sed -e '/.*serialNo/!d' -e 's/.*serialNo=\(.*\)/\1/' -e 's/\(\([^ ]*\) \)\{1\}.*/\2/' /proc/cmdline)
if [ "$UBOOT_VER" = "" ]; then
UBOOT_VER="123456"
fi
if [ "$MAC" = "" ]; then
MAC="12:34:56:78:9a:bc"
fi
if [ "$HW_MCSV" = "" ]; then
HW_MCSV="012C123456789012"
fi
if [ "$SERIALNO" = "" ]; then
SERIALNO=""
fi
/bin/mkdir -p /tmp/etc
echo "UBOOT_VER"=$UBOOT_VER > /tmp/etc/sysinfo.txt
echo "MAC"=$MAC >> /tmp/etc/sysinfo.txt
echo "HW_MCSV"=$HW_MCSV >> /tmp/etc/sysinfo.txt
echo "SERIALNO"=$SERIALNO >> /tmp/etc/sysinfo.txt
export PATH=$PATH:/usr/sbin/icos
export CONFDIR=/etc/icos
/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0
# Enable forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# ==========================================================================
# | set printk level
# ==========================================================================
/bin/echo 1 > /proc/sys/kernel/printk
# [ -f /etc/sysctl.conf ] && sysctl -p -e >&-
# ==========================================================================
# | mkdir /mnt/data/icos for icos data storage (/etc/icos)
# | mkdir /mnt/data/etc for other app data storage
# ==========================================================================
/bin/mkdir -p /mnt/data/icos
/bin/mkdir -p /mnt/data/etc
/sbin/ifconfig eth1 0.0.0.0
/sbin/ifconfig eth0 0.0.0.0
/usr/sbin/brctl addbr lan
/usr/sbin/brctl addif lan eth0
ifconfig lan 192.168.1.1
ifconfig lan up
if [ -d "/home/log" ]; then
TIME=$(date +"%Y%m%d%H%M")
cd /home; tar zcf log-${TIME}.tgz log
fi
# Ariel: icospromsg need to before icosconfig for share memory init
modprobe cryptodev
/usr/sbin/seqcmdd -C /var/seqcmdd/ipt_cmd &
/usr/sbin/icospromsg &
/usr/sbin/icosconfig bootinit
/usr/sbin/rs485 --enable > /dev/null 2>&1
/usr/sbin/read_modem &
/usr/sbin/icos/gpio_button.sh \
--click "reboot" \
--hold "heartbeat_all_led.sh; rm -rf /etc/icos/* ; reboot" \
--active-low 1 \
--hold-exit 5 0 &
# Ariel: make icos watch dog to be the last one
/usr/sbin/icoswdog -T 300 &
修改 /etc/rc.local
#!/bin/sh -e
...
# ==========================================================================
# | set printk level
# ==========================================================================
/bin/echo 1 > /proc/sys/kernel/printk
# [ -f /etc/sysctl.conf ] && sysctl -p -e >&-
ubiattach -m 5
/bin/mkdir -p /mnt/data
mount -t ubifs ubi1:config_a /mnt/data
# ==========================================================================
# | mkdir /mnt/data/icos for icos data storage (/etc/icos)
# | mkdir /mnt/data/etc for other app data storage
# ==========================================================================
/bin/mkdir -p /mnt/data/icos
/bin/mkdir -p /mnt/data/etc
...
多了下述的敘述
ubiattach -m 5
/bin/mkdir -p /mnt/data
mount -t ubifs ubi1:config_a /mnt/data
存檔
把目前的 /mnt/data
刪掉 - rm -rf /mnt/data
重開機
觀察 mount 資訊
root@M300:/mnt/data# mount
rootfs on / type rootfs (rw)
ubi0:rootfs_a on / type ubifs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=91208k,nr_inodes=22802,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /var/volatile type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
ubi1:config_a on /mnt/data type ubifs (rw,relatime)
發現多了 /mnt/data
這個 mountpoint
ubi1:config_a on /mnt/data type ubifs (rw,relatime)
這樣一來 icos data storage 和 other app data storage 就會存到 MTD device 5 (mtd5) 去了
...
# ==========================================================================
# | mkdir /mnt/data/icos for icos data storage (/etc/icos)
# | mkdir /mnt/data/etc for other app data storage
# ==========================================================================
/bin/mkdir -p /mnt/data/icos
/bin/mkdir -p /mnt/data/etc
...
/etc/rc.local
裡的 ubiattach 敘述要根據 uboot env 來決定到底是要 attach config_a
或 config_b
ubiattach -m 5
/bin/mkdir -p /mnt/data
mount -t ubifs ubi1:config_a /mnt/data
我們需要 fw_printenv
想辦法搞定 u-boot-fw-utils
recipe
目前是少了 <u-boot-fw-utils>/configs/mx6ul_14x14_evk_nand_defconfig
利用 patch 的方式加上 <u-boot-fw-utils>/configs/mx6ul_14x14_evk_nand_defconfig
先產生需要的 patch file
- bitbake u-boot-fw-utils -c devshell
- quilt new add_mx6ul_14x14_evk_nand_config.patch
- quilt add configs/mx6ul_14x14_evk_nand_defconfig
- copy mx6ul_14x14_evk_nand_defconfig from
- quilt refresh
新增 fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils
資料夾
新增 fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/files
資料夾
- 把剛剛產生的 patch file
add_mx6ul_14x14_evk_nand_config.patch
放進來
新增 /fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/u-boot-fw-utils_2015.01.bbappend
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI_append = " \
file://add_mx6ul_14x14_evk_nand_config.patch \
"
bitbake u-boot-fw-utils -c clean
bitbake u-boot-fw-utils
確認無誤之後
修改 fsl-release-bsp/build_small/conf/local.conf
...
IMAGE_INSTALL_append += " nfs-utils tar bzip2 u-boot-fw-utils"
...
加入 u-boot-fw-utils
recipe
順便 patch 一下 <u-boot-fw-utils>/tools/env/fw_env.config
modify.fw_env.config.patch
Index: git/tools/env/fw_env.config
===================================================================
--- git.orig/tools/env/fw_env.config
+++ git/tools/env/fw_env.config
@@ -5,18 +5,5 @@
# Futhermore, if the Flash sector size is ommitted, this value is assumed to
# be the same as the Environment size, which is valid for NOR and SPI-dataflash
-# NOR example
-# MTD device name Device offset Env. size Flash sector size Number of sectors
-/dev/mtd1 0x0000 0x4000 0x4000
-/dev/mtd2 0x0000 0x4000 0x4000
-
-# MTD SPI-dataflash example
-# MTD device name Device offset Env. size Flash sector size Number of sectors
-#/dev/mtd5 0x4200 0x4200
-#/dev/mtd6 0x4200 0x4200
-
-# NAND example
-#/dev/mtd0 0x4000 0x4000 0x20000 2
-
-# Block device example
-#/dev/mmcblk0 0xc0000 0x20000
+# MTD device name Device offset Env. size Flash sector size
+/dev/mtd1 0x00000000 0x00100000 0x00100000
這樣的好處是我們可以在 rootfs 裡直接產生我們需要的 /etc/fw_env.config
➜ core-image-minimal git:(nandflash) ✗ find . -name "fw_*"
./1.0-r0/rootfs/sbin/fw_printenv
./1.0-r0/rootfs/sbin/fw_setenv
./1.0-r0/rootfs/etc/fw_env.config
➜ core-image-minimal git:(nandflash) ✗ cat 1.0-r0/rootfs/etc/fw_env.config
# Configuration file for fw_(printenv/setenv) utility.
# Up to two entries are valid, in this case the redundant
# environment sector is assumed present.
# Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash.
# Futhermore, if the Flash sector size is ommitted, this value is assumed to
# be the same as the Environment size, which is valid for NOR and SPI-dataflash
# MTD device name Device offset Env. size Flash sector size
/dev/mtd1 0x00000000 0x00100000 0x00100000
mfgtool flash... ok
開機進 uboot 需要修改 bootargs root
為 ubi0:rootfs_a
開機進 linux
fw_printenv
和 fw_setenv
都有了
root@M300:~# fw_
fw_printenv fw_setenv
root@M300:~# fw_printenv
active_firmware=a
baudrate=115200
bootargs=console=ttymxc0,115200 ubi.mtd=4 root=ubi0:rootfs_a rootfstype=ubifs mtdparts=gpmi-nand:3m(boot),1m(boot_env),10m(kernel_a),2m(dtb_a),96m(rootfs_a),16m(config_a),4m(misc),10m(kernel_b),2m(dtb_b),96m(rootfs_b),-(config_b)
bootcmd=saveenv;nand read ${loadaddr} ${kernel_a_addr} 0x800000;nand read ${fdt_addr} ${dtb_a_addr} 0x100000;bootz ${loadaddr} - ${fdt_addr}
bootcmd_mfg=run mfgtool_args;bootz ${loadaddr} ${initrd_addr} ${fdt_addr};
bootdelay=3
console=ttymxc0
dtb_a_addr=0x00E00000
dtb_b_addr=0x08E00000
ethact=FEC1
ethprime=FEC
fdt_addr=0x83000000
fdt_high=0xffffffff
initrd_addr=0x83800000
initrd_high=0xffffffff
kernel_a_addr=0x00400000
kernel_b_addr=0x08400000
loadaddr=0x80800000
mfgtool_args=setenv bootargs console=${console},${baudrate} rdinit=/linuxrc g_mass_storage.stall=0 g_mass_storage.removable=1 g_mass_storage.idVendor=0x066F g_mass_storage.idProduct=0x37FF g_mass_storage.iSerialNumber="" mtdparts=gpmi-nand:3m(boot),1m(boot_env),10m(kernel_a),2m(dtb_a),96m(rootfs_a),16m(config_a),4m(misc),10m(kernel_b),2m(dtb_b),96m(rootfs_b),-(config_b)
panel=TFT43AB
rootfs_a_mtd=4
rootfs_b_mtd=9
fw_printenv
動作也正常
做一下 git commit
看一下 log - git log -p -1
commit c9eccb99c39eb686e2937c1f5a090182eafbb313
Author: Jeffrey Lee <[email protected]>
Date: Tue Dec 20 18:28:35 2016 +0800
patch for u-boot-fw-utils since we need access uboot env from linux
diff --git a/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/files/add_mx6ul_14x14_evk_nand_co
nfig.patch b/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/files/add_mx6ul_14x14_evk_nand_co
nfig.patch
new file mode 100644
index 0000000..ff75262
--- /dev/null
+++ b/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/files/add_mx6ul_14x14_evk_nand_config.pa
tch
@@ -0,0 +1,10 @@
+Index: git/configs/mx6ul_14x14_evk_nand_defconfig
+===================================================================
+--- /dev/null
++++ git/configs/mx6ul_14x14_evk_nand_defconfig
+@@ -0,0 +1,5 @@
++CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6ul_14x14_evk/imximage.cfg,MX6UL,SYS_BOOT_NAND"
++CONFIG_ARM=y
++CONFIG_TARGET_MX6UL_14X14_EVK=y
++CONFIG_DM=y
++CONFIG_DM_THERMAL=y
diff --git a/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/files/modify.fw_env.config.patch b/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/files/modify.fw_env.config.patch
new file mode 100644
index 0000000..a1109c2
--- /dev/null
+++ b/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/files/modify.fw_env.config.patch
@@ -0,0 +1,25 @@
+Index: git/tools/env/fw_env.config
+===================================================================
+--- git.orig/tools/env/fw_env.config
++++ git/tools/env/fw_env.config
+@@ -5,18 +5,5 @@
+ # Futhermore, if the Flash sector size is ommitted, this value is assumed to
+ # be the same as the Environment size, which is valid for NOR and SPI-dataflash
+
+-# NOR example
+-# MTD device name Device offset Env. size Flash sector size Number of sectors
+-/dev/mtd1 0x0000 0x4000 0x4000
+-/dev/mtd2 0x0000 0x4000 0x4000
+-
+-# MTD SPI-dataflash example
+-# MTD device name Device offset Env. size Flash sector size Number of sectors
+-#/dev/mtd5 0x4200 0x4200
+-#/dev/mtd6 0x4200 0x4200
+-
+-# NAND example
+-#/dev/mtd0 0x4000 0x4000 0x20000 2
+-
+-# Block device example
+-#/dev/mmcblk0 0xc0000 0x20000
++# MTD device name Device offset Env. size Flash sector size
++/dev/mtd1 0x00000000 0x00100000 0x00100000
diff --git a/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/u-boot-fw-utils_2015.01.bbappend b/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/u-boot-fw-utils_2015.01.bbappend
new file mode 100644
index 0000000..7567773
--- /dev/null
+++ b/fsl-release-bsp/sources/meta-proscend/recipes-bsp/u-boot-fw-utils/u-boot-fw-utils_2015.01.bbappend
@@ -0,0 +1,6 @@
+FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
+
+SRC_URI_append = " \
+ file://add_mx6ul_14x14_evk_nand_config.patch \
+ file://modify.fw_env.config.patch \
+"