20161213_jeffrey - silenceuncrio/diary GitHub Wiki
-
0930 - 目前具備的 tool 已經可以把
u-boot
,kernel
,dtb
和rootfs
燒錄到 nandflash 去 - 0945 - 先來燒錄 uboot
- 1055 - 重開機看看... ok
- 1100 - 來燒錄 linux kernel 吧
- 1115 - 來燒錄 rootfs 吧
- 1305 - 再整理一次燒錄 rootfs 的步驟
-
1320 - Erasing rootfs partition 之前先把後續動作需要的工具放到
/tmp
去 -
1350 - 先做
detach
吧 - 1455 - 跟 winston 聊了一下他是怎麼克服寫 rootfs 這個問題
- 1520 - 新增 uboot 的 ubi command 需要修改 mx6ul_14x14_evk.h
- 1645 - 就算 uboot 有了 ubi 的 command 也沒啥用
- 1710 - winston 提到 uboot 的 ubi command 是為了看目前已使用的大小...
- 1720 - 修改 mx6ul_14x14_evk.h 來達到我們未來的 dual image nand flash 配置
- 1940 - uboot mtdparts 的問題有解
在 fsl-release-bsp/sources/meta-proscend/recipes-core/prosrc/prosrc_0.1.bb
的 RDEPENDS_${PN}
加上 imx-kobs
這個 recipe
build image
在 fsl-release-bsp\build_small\tmp\work\imx6ulevk-poky-linux-gnueabi\core-image-minimal\1.0-r0\rootfs\usr\bin
發現 kobs-ng
正是我們燒錄 u-boot 所需要的 tool
將 image 燒錄到 nand flash 去
目前具備的 tool 已經可以把 u-boot
, kernel
, dtb
和 rootfs
燒錄到 nandflash 去
- kobs-ng
- flash_erase
- nandwrite
- ubiformat
- ubiattach
- ubimkvol
- mkdir
- mount
- umount
- tar
一個一個來
參考 https://github.com/silenceuncrio/diary/wiki/20160620_jeffrey
先來燒錄 uboot
把開發環境上的 images folder 直接掛載到 m300 上的 ~/images
確認 uboot image - u-boot.imx
... ok
root@M300:~/images# ls
...
u-boot.imx
...
Erasing Boot partition - flash_erase /dev/mtd0 0 0
... ok
root@M300:~/images# flash_erase /dev/mtd0 0 0
Erasing 128 Kibyte @ 2460000 -- 56 % complete flash_erase: Skipping bad block at 02480000
Erasing 128 Kibyte @ 3fe0000 -- 100 % complete
Flashing Bootloader - kobs-ng init -x -v --chip_0_device_path=/dev/mtd0 u-boot.imx
... fail
< init -x -v --chip_0_device_path=/dev/mtd0 u-boot.imx
MTD CONFIG:
chip_0_device_path = "/dev/mtd0"
chip_1_device_path = "(null)"
search_exponent = 2
data_setup_time = 80
data_hold_time = 60
address_setup_time = 25
data_sample_time = 6
row_address_size = 3
column_address_size = 2
read_command_code1 = 0
read_command_code2 = 48
boot_stream_major_version = 1
boot_stream_minor_version = 0
boot_stream_sub_version = 0
ncb_version = 3
boot_stream_1_address = 0
boot_stream_2_address = 0
unable to create a temporary file
該不會是漏了 Mounting debugfs
的步驟吧
Mounting debugfs - mount -t debugfs debugfs /sys/kernel/debug
... fail
root@M300:~/images# mount -t debugfs debugfs /sys/kernel/debug
mount: mounting debugfs on /sys/kernel/debug failed: Device or resource busy
mount 到 /tmp/debug
吧... ok
root@M300:~/images# mount -t debugfs debugfs /tmp/debug
再做一次 Flashing Bootloader - kobs-ng init -x -v --chip_0_device_path=/dev/mtd0 u-boot.imx
... fail
< init -x -v --chip_0_device_path=/dev/mtd0 u-boot.imx
MTD CONFIG:
chip_0_device_path = "/dev/mtd0"
chip_1_device_path = "(null)"
search_exponent = 2
data_setup_time = 80
data_hold_time = 60
address_setup_time = 25
data_sample_time = 6
row_address_size = 3
column_address_size = 2
read_command_code1 = 0
read_command_code2 = 48
boot_stream_major_version = 1
boot_stream_minor_version = 0
boot_stream_sub_version = 0
ncb_version = 3
boot_stream_1_address = 0
boot_stream_2_address = 0
unable to create a temporary file
看來要查一下 source code 了
fsl-release-bsp\build_small\tmp\work\cortexa7hf-vfp-neon-poky-linux-gnueabi\imx-kobs\5.3-r0\imx-kobs-5.3\src
main.c
static char *tmp_file = ".tmp_kobs_ng";
static char *padding_1k_in_head(char *file_name)
{
int to, from;
int ret;
int sz = getpagesize();
from = open(file_name, O_RDONLY, S_IRUSR | S_IWUSR);
to = open(tmp_file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (from < 0 || to < 0) {
fprintf(stderr, "unable to create a temporary file\n");
exit(5);
}
/* Padding 1k in the head. */
lseek(to, 1024, SEEK_SET);
do {
/* copy a page each time. */
ret = sendfile(to, from, NULL, sz);
} while (ret > 0);
close(to);
close(from);
/* change to the temporary file. */
return tmp_file;
}
看來應該是 to = open(tmp_file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
出了問題
我不應該在 m300 mount 到開發環境的目錄上做這件事
切換到 /tmp 去
再做一次 Flashing Bootloader - kobs-ng init -x -v --chip_0_device_path=/dev/mtd0 ~/images/u-boot.imx
... ok
<t -x -v --chip_0_device_path=/dev/mtd0 ~/images/u-boot.imx
MTD CONFIG:
chip_0_device_path = "/dev/mtd0"
chip_1_device_path = "(null)"
search_exponent = 2
data_setup_time = 80
data_hold_time = 60
address_setup_time = 25
data_sample_time = 6
row_address_size = 3
column_address_size = 2
read_command_code1 = 0
read_command_code2 = 48
boot_stream_major_version = 1
boot_stream_minor_version = 0
boot_stream_sub_version = 0
ncb_version = 3
boot_stream_1_address = 0
boot_stream_2_address = 0
-- We add the 1k-padding to the uboot.
.tmp_kobs_ng: verifying using key '00000000000000000000000000000000'
.tmp_kobs_ng: is a valid bootstream for key '00000000000000000000000000000000'
mtd: opening: "/dev/mtd0"
mtd: '/dev/mtd0' bad block @ 0x2480000 (MTD)
NFC geometry :
ECC Strength : 4
Page Size in Bytes : 2084
Metadata size : 10
ECC Chunk Size in byte : 512
ECC Chunk count : 4
Block Mark Byte Offset : 2018
Block Mark Bit Offset : 4
====================================================
mtd: opened '/dev/mtd0' - '(null)'
mtd: max_boot_stream_size_in_bytes = 33030144
mtd: boot_stream_size_in_bytes = 413696
mtd: boot_stream_size_in_pages = 202
mtd: #1 0x00100000 - 0x02080000 (0x00165000)
mtd: #2 0x02080000 - 0x04000000 (0x020e5000)
FCB
m_u32Checksum = 0x00000000
m_u32FingerPrint = 0x20424346
m_u32Version = 0x01000000
m_NANDTiming.m_u8DataSetup = 80
m_NANDTiming.m_u8DataHold = 60
m_NANDTiming.m_u8AddressSetup = 25
m_NANDTiming.m_u8DSAMPLE_TIME = 6
m_u32PageDataSize = 2048
m_u32TotalPageSize = 2112
m_u32SectorsPerBlock = 64
m_u32NumberOfNANDs = 0
m_u32TotalInternalDie = 0
m_u32CellType = 0
m_u32EccBlockNEccType = 2
m_u32EccBlock0Size = 512
m_u32EccBlockNSize = 512
m_u32EccBlock0EccType = 2
m_u32MetadataBytes = 10
m_u32NumEccBlocksPerPage = 3
m_u32EccBlockNEccLevelSDK = 0
m_u32EccBlock0SizeSDK = 0
m_u32EccBlockNSizeSDK = 0
m_u32EccBlock0EccLevelSDK = 0
m_u32NumEccBlocksPerPageSDK = 0
m_u32MetadataBytesSDK = 0
m_u32EraseThreshold = 0
m_u32Firmware1_startingPage = 512
m_u32Firmware2_startingPage = 16640
m_u32PagesInFirmware1 = 202
m_u32PagesInFirmware2 = 202
m_u32DBBTSearchAreaStartAddress = 256
m_u32BadBlockMarkerByte = 2018
m_u32BadBlockMarkerStartBit = 4
m_u32BBMarkerPhysicalOffset = 2048
m_u32BCHType = 0
m_NANDTMTiming.m_u32TMTiming2_ReadLatency = 0
m_NANDTMTiming.m_u32TMTiming2_PreambleDelay = 0
m_NANDTMTiming.m_u32TMTiming2_CEDelay = 0
m_NANDTMTiming.m_u32TMTiming2_PostambleDelay = 0
m_NANDTMTiming.m_u32TMTiming2_CmdAddPause = 0
m_NANDTMTiming.m_u32TMTiming2_DataPause = 0
m_NANDTMTiming.m_u32TMSpeed = 0
m_NANDTMTiming.m_u32TMTiming1_BusyTimeout = 0
m_u32DISBBM = 0
m_u32BBMarkerPhysicalOffsetInSpareData = 0
m_u32OnfiSyncEnable = 0
m_NANDONFITiming.m_u32ONFISpeed = 0
m_NANDONFITiming.m_u32ONFITiming_ReadLatency = 0
m_NANDONFITiming.m_u32ONFITiming_CEDelay = 0
m_NANDONFITiming.m_u32ONFITiming_PreambleDelay = 0
m_NANDONFITiming.m_u32ONFITiming_PostambleDelay = 0
m_NANDONFITiming.m_u32ONFITiming_CmdAddPause = 0
m_NANDONFITiming.m_u32ONFITiming_DataPause = 0
m_NANDONFITiming.m_u32ONFITiming_BusyTimeout = 0
m_u32DISBBSearch = 0
m_u32RandomizerEnable = 0
m_u32ReadRetryEnable = 0
m_u32ReadRetrySeqLength = 0
DBBT
m_u32Checksum = 0x00000000
m_u32FingerPrint = 0x54424244
m_u32Version = 0x01000000
m_u32DBBTNumOfPages = 1
BBTN#0
uNAND = 0
uNumberBB = 1
BADBLOCKS:
0x124
Firmware: image #0 @ 0x100000 size 0x65000 - available 0x1f80000
Firmware: image #1 @ 0x2080000 size 0x65000 - available 0x1f80000
-------------- Start to write the [ FCB ] -----
mtd: erasing @0:0x0-0x20000
mtd: Writing FCB0 [ @0:0x0 ] (840) *
mtd: erasing @0:0x20000-0x40000
mtd: Writing FCB1 [ @0:0x20000 ] (840) *
mtd: erasing @0:0x40000-0x60000
mtd: Writing FCB2 [ @0:0x40000 ] (840) *
mtd: erasing @0:0x60000-0x80000
mtd: Writing FCB3 [ @0:0x60000 ] (840) *
mtd_commit_bcb(FCB): status 0
-------------- Start to write the [ DBBT ] -----
mtd: erasing @0:0x80000-0xa0000
mtd: Writing DBBT0 [ @0:0x80000 ] (800) *
mtd: erasing @0:0xa0000-0xc0000
mtd: Writing DBBT1 [ @0:0xa0000 ] (800) *
mtd: erasing @0:0xc0000-0xe0000
mtd: Writing DBBT2 [ @0:0xc0000 ] (800) *
mtd: erasing @0:0xe0000-0x100000
mtd: Writing DBBT3 [ @0:0xe0000 ] (800) *
mtd_commit_bcb(DBBT): status 0
mtd: PUTTING down DBBT0 BBTN0 @0x82000 (0x800)
mtd: PUTTING down DBBT1 BBTN0 @0xa2000 (0x800)
mtd: PUTTING down DBBT2 BBTN0 @0xc2000 (0x800)
mtd: PUTTING down DBBT3 BBTN0 @0xe2000 (0x800)
---------- Start to write the [ .tmp_kobs_ng ]----
mtd: Writting .tmp_kobs_ng: #0 @0: 0x00100000 - 0x00165000
mtd: erasing @0:0x100000-0x120000
mtd: erasing @0:0x120000-0x140000
mtd: erasing @0:0x140000-0x160000
mtd: erasing @0:0x160000-0x180000
mtd: We write one page for save guard. *
mtd: Writting .tmp_kobs_ng: #1 @0: 0x02080000 - 0x020e5000
mtd: erasing @0:0x2080000-0x20a0000
mtd: erasing @0:0x20a0000-0x20c0000
mtd: erasing @0:0x20c0000-0x20e0000
mtd: erasing @0:0x20e0000-0x2100000
mtd: We write one page for save guard. *
重開機看看... ok
再一次
- Erasing Boot partition
flash_erase /dev/mtd0 0 0
- ok
- Flashing Bootloader
kobs-ng init -x -v --chip_0_device_path=/dev/mtd0 ~/images/u-boot.imx
- ok
- 重開機
- ok
來燒錄 linux kernel 吧
一樣是參考 https://github.com/silenceuncrio/diary/wiki/20160620_jeffrey
切到 /tmp
去後確認所需要的 image
mp# ls
etc icos icos_alive icosmib log wdog.pid
root@M300:/tmp# ls ~/images/
...
zImage
...
zImage-imx6ul-14x14-evk.dtb
...
燒錄吧
- Erasing Kernel partition
flash_erase /dev/mtd1 0 0
- Flashing Kernel
nandwrite -p /dev/mtd1 -p ~/images/zImage
- Erasing dtb partition
flash_erase /dev/mtd2 0 0
- Flashing dtb
nandwrite -p /dev/mtd2 -p ~/images/zImage-imx6ul-14x14-evk.dtb
整個過程都很順利
重開機看看... ok
來燒錄 rootfs 吧
- Erasing rootfs partition
flash_erase /dev/mtd3 0 0
- ubiformat
ubiformat /dev/mtd3
- Attaching UBI partition
- ubiattach /dev/ubi_ctrl -m 3
- ubimkvol /dev/ubi0 -Nrootfs -m
- mkdir -p /mnt/mtd3
- mount -t ubifs ubi0:rootfs /mnt/mtd3
- writting rootfs
- tar -jxv -C /mnt/mtd3 - file="files/rootfs_nogpu.tar.bz2
- Finishing rootfs write
- frf
- Unmounting rootfs partition
- umount /mnt/mtd3
發現我沒有 frf
這個 tool
frf
是 mfgtool 的 Command
就先不管它了
再整理一次燒錄 rootfs 的步驟
- Erasing rootfs partition
flash_erase /dev/mtd3 0 0
- ubiformat
ubiformat /dev/mtd3
- Attaching UBI partition
- ubiattach /dev/ubi_ctrl -m 3
- ubimkvol /dev/ubi0 -Nrootfs -m
- mkdir -p /mnt/mtd3
- mount -t ubifs ubi0:rootfs /mnt/mtd3
- writting rootfs
- tar -jxv -C /mnt/mtd3 - file="files/rootfs_nogpu.tar.bz2
- Unmounting rootfs partition
- umount /mnt/mtd3
來吧...
- Erasing rootfs partition
flash_erase /dev/mtd3 0 0
- ok
root@M300:/tmp# flash_erase /dev/mtd3 0 0
Erasing 128 Kibyte @ 7e20000 -- 78 % complete flash_erase: Skipping bad block at 07e40000
Erasing 128 Kibyte @ 96e0000 -- 94 % complete flash_erase: Skipping bad block at 09700000
Erasing 128 Kibyte @ 97e0000 -- 94 % complete flash_erase: Skipping bad block at 09800000
Erasing 128 Kibyte @ 9f60000 -- 99 % complete flash_erase: Skipping bad block at 09f80000
flash_erase: Skipping bad block at 09fa0000
flash_erase: Skipping bad block at 09fc0000
flash_erase: Skipping bad block at 09fe0000
Erasing 128 Kibyte @ 9fe0000 -- 100 % complete
- ubiformat
ubiformat /dev/mtd3
- fail
root@M300:/tmp# ubiformat /dev/mtd3
-sh: ubiformat: command not found
command not found
???
哈哈
rootfs 都被我 erease 掉了...
mfgtool 再燒回去...
Erasing rootfs partition 之前先把後續動作需要的工具放到 /tmp
去
這次把開發環境上的 images folder 掛載到 m300 上的 /tmp/images
把燒錄 rootfs 需要的工具搬到 /tmp/tools
來
- flash_erase
- ubiformat
- ubiattach
- ubimkvol
- mkdir
- mount
- tar
- umount
root@M300:/tmp# cp /usr/sbin/ubiformat tools/
root@M300:/tmp# cp /usr/sbin/ubiattach tools/
root@M300:/tmp# cp /usr/sbin/ubimkvol tools/
root@M300:/tmp# cp /bin/mkdir tools/
root@M300:/tmp# cp /bin/mount tools/
root@M300:/tmp# cp /bin/tar tools/
root@M300:/tmp# cp /bin/umount tools/
來吧
- Erasing rootfs partition
./tools/flash_erase /dev/mtd3 0 0
- ok
- ubiformat
./tools/ubiformat /dev/mtd3
- fail
root@M300:/tmp# ./tools/ubiformat /dev/mtd3
ubiformat: error!: please, first detach mtd3 (/dev/mtd3) from ubi0
shit!
先做 detach
吧
- 把開發環境上的 images folder 掛載到 m300 上的
/tmp/images
- 把燒錄 rootfs 需要的工具搬到
/tmp/tools
來
cp /usr/sbin/ubiformat tools/
cp /usr/sbin/ubiattach tools/
cp /usr/sbin/ubidetach tools/
cp /usr/sbin/ubimkvol tools/
cp /bin/mkdir tools/
cp /bin/mount tools/
cp /bin/tar tools/
cp /bin/umount tools/
- detaching UBI partition
./tools/ubidetach /dev/ubi_ctrl -m 3
- fail
sr/sbin/ubidetach tools/
root@M300:/tmp# ./tools/ubidetach /dev/ubi_ctrl -m 3
ubidetach: error!: cannot detach mtd3
error 16 (Device or resource busy)
先做 Unmounting rootfs partition
- Unmounting rootfs partition
./tools/umount /mnt/mtd3
跟 winston 聊了一下他是怎麼克服寫 rootfs 這個問題
winston 給的一些建議
目前正在 run 的 rootfs 不要去寫 要寫再另外一塊
再告訴 u-boot 下一次開機的 rootfs 是另外一塊
winston 有提到他們的 uboot 有 ubi command 可以用
我也來找一下
要新增 uboot 的 ubi command 需要修改 mx6ul_14x14_evk.h
可以參考 <u-boot-imx>\include\configs\cam_enc_4xx.h
/* UBI and NAND partitioning */
#ifdef CONFIG_CMD_NAND
#define CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
#define CONFIG_CMD_MTDPARTS
#define CONFIG_RBTREE
#define CONFIG_LZO
#define CONFIG_MTD_DEVICE
#define CONFIG_MTD_PARTITIONS
#define MTDIDS_DEFAULT "nand0=gpmi-nand"
#define MTDPARTS_DEFAULT \
"mtdparts=gpmi-nand:128k(bootstrap),1024k(boot),768k(env),-(root)"
#else
#define MTDPARTS_DEFAULT ""
#endif
<u-boot-imx>
是個 path, 可由 bitbake u-boot-imx -c devshell
得知
上 patch 吧
- 由
bitbake u-boot-imx -c devshell
進入<u-boot-imx>
- 建立新的 patch
quilt new add_ubi_commands.patch
- notify Quilt about the files you plan to edit
quilt add include/configs/mx6ul_14x14_evk.h
- 參考
<u-boot-imx>\include\configs\apx4devkit.h
新增 UBI 相關 command - generate the final patch that contains all your modifications
quilt refresh
- copy the patch file and edit your recipe
- copy the patch file from - \patches\add_ubi_commands.patch
- copy the patch file to - fsl-release-bsp\sources\meta-proscend\recipes-bsp\u-boot\files\add_ubi_commands.patch
- edit your recipe - fsl-release-bsp\sources\meta-proscend\recipes-bsp\u-boot\u-boot-imx_2015.04.bbappend
build image...
就算 uboot 有了 ubi 的 command 也沒啥用
=> ubi part
Error, no UBI device/partition selected!
=> mtdparts
mtdids not defined, no default present
行為都跟 winston 熟悉的現象不一樣...
不過還是 commit 吧
commit 35cab0cdb32b8dfb281fe28e9d985b4d0987b393
Author: Jeffrey Lee <[email protected]>
Date: Tue Dec 13 16:51:00 2016 +0800
- prepare the tools for firmware upgrade(include uboot)
- modify "imx6ul-14x14-evk-gpmi-weim.dts" to add ubi commands
(END)
winston 提到 uboot 的 ubi command 是為了看目前已使用的大小...
結果用 df 就搞定了
root@M300:~# df
Filesystem 1024-blocks Used Available Use% Mounted on
rootfs 139800 27872 107092 21% /
ubi0:rootfs 139800 27872 107092 21% /
devtmpfs 91208 4 91204 0% /dev
tmpfs 255220 160 255060 0% /run
tmpfs 255220 196 255024 0% /var/volatile
參考 https://github.com/silenceuncrio/diary/wiki/20160810_jeffrey
修改 mx6ul_14x14_evk.h 來達到我們未來的 dual image nand flash 配置
應該可以偷點懶... 直接進 uboot 透過 setenv 來修改
我需要注意的就兩個變數
- bootargs
- bootcmd
=> printenv bootargs
bootargs=console=ttymxc0,115200 ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs mtdparts=gpmi-nand:64m(boot),16m(kernel),16m(dtb),-(rootfs)
=> printenv bootcmd
bootcmd=nand read ${loadaddr} 0x4000000 0x800000;nand read ${fdt_addr} 0x5000000 0x100000;bootz ${loadaddr} - ${fdt_addr}
先改 bootargs
的 mtdparts
console=ttymxc0,115200 ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs mtdparts=gpmi-nand:64m(boot),16m(kernel),16m(dtb),64m(rootfs),-(others)
...
UBI: scanning is finished
UBI error: vtbl_check: too large reserved_pebs 1236, good PEBs 512
UBI error: vtbl_check: volume table check failed: record 0, error 9
Volume table record 0 dump:
reserved_pebs 1236
alignment 1
data_pad 0
vol_type 1
upd_marker 0
name_len 6
name rootfs
crc 0xa89e1774
UBI error: ubi_attach_mtd_dev: failed to attach mtd3, error -22
UBI error: ubi_init: cannot attach mtd3
snvs_rtc 20cc034.snvs-rtc-lp: setting system clock to 2016-12-13 11:33:46 UTC (1481628826)
UBIFS error (pid 1): ubifs_mount: cannot open "ubi0:rootfs", error -19
VFS: Cannot open root device "ubi0:rootfs" or unknown-block(0,0): error -19
Please append a correct "root=" boot option; here are the available partitions:
1f00 65536 mtdblock0 (driver?)
1f01 16384 mtdblock1 (driver?)
1f02 16384 mtdblock2 (driver?)
1f03 65536 mtdblock3 (driver?)
1f04 98304 mtdblock4 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
random: nonblocking pool is initialized
shit! 等明天再乖乖修改 mx6ul_14x14_evk.h 吧
uboot mtdparts 的問題有解
=> mtdparts
mtdids not defined, no default present
參考 https://read01.com/7DnDR6.html
可以知道我們需要再參考 <u-boot-imx>\include\configs\cam_enc_4xx.h
#define MTDIDS_DEFAULT "nand0=davinci_nand.0"
#define MTDPARTS_DEFAULT \
"mtdparts=" \
"davinci_nand.0:" \
"128k(spl)," \
"384k(UBLheader)," \
"1m(u-boot)," \
"512k(env)," \
"-(ubi)"
根據這個來修改 mx6ul_14x14_evk.h 的話應該就能解掉了
不過我們目前並不需要從 uboot 對 nand flash 做任何燒錄的動作
可以先緩一下