u-boot下ubi 命令使用总结
查看MTD分区表
uBoot> mtdparts
uBoot> mtdparts
device nand0 <pxa3xx_nand-0>, # parts = 4
#: name size offset mask_flags
0: boot 0x000000200000 0x000000000000 0
1: env 0x000000200000 0x000000200000 0
2: UbiVols 0x000007800000 0x000000400000 0
3: Reserved 0x000000400000 0x000007c00000 0
active partition: nand0,0 - (boot) 0x000000200000 @ 0x000000000000
defaults:
mtdids : none
mtdparts: none
激活分区
uBoot> ubi part UbiVols
uBoot> ubi part UbiVols
Creating 1 MTD partitions on "nand0":
0x000000400000-0x000007c00000 : "mtd=2"
UBI: attaching mtd1 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 126976 bytes
UBI: smallest flash I/O unit: 2048
UBI: VID header offset: 2048 (aligned 2048)
UBI: data offset: 4096
UBI: attached mtd1 to ubi0
UBI: MTD device name: "mtd=2"
UBI: MTD device size: 120 MiB
UBI: number of good PEBs: 955
UBI: number of bad PEBs: 5
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 5
UBI: available PEBs: 0
UBI: total number of reserved PEBs: 955
UBI: number of PEBs reserved for bad PEB handling: 9
UBI: max/mean erase counter: 9/0
查看当前激活分区
uBoot> ubi part
uBoot> ubi part
Device 0: nand0, partition UbiVols
Note: 如果当前没有被激活的分区,执行此命令时会出错:
uBoot> ubi part
Error, no UBI device/partition selected!
挂载分区
uBoot> ubimount
Usage:
ubifsmount <volume-name>
- mount 'volume-name' volume
uBoot> ubifsmount Rootfs-1
UBIFS: static UBI volume - read-only mode
UBIFS: mounted UBI device 0, volume 1, name "Rootfs-1"
UBIFS: mounted read-only
UBIFS: file system size: 40632320 bytes (39680 KiB, 38 MiB, 320 LEBs)
UBIFS: journal size: 5586944 bytes (5456 KiB, 5 MiB, 44 LEBs)
UBIFS: media format: w4/r0 (latest is w4/r0)
UBIFS: default compressor: zlib
UBIFS: reserved for root: 0 bytes (0 KiB)
查看分区内容
uBoot> ubifsls
uBoot> ubifsls
<DIR> 3440 Wed Jul 08 03:45:35 2020 bin
<DIR> 3176 Mon Feb 08 06:16:13 2021 dev
<DIR> 680 Thu Feb 25 06:05:37 2021 etc
<DIR> 1696 Tue Feb 02 03:42:45 2021 lib
<DIR> 160 Wed Feb 03 09:35:59 2021 mnt
<DIR> 160 Wed Jul 08 03:45:35 2020 tmp
<DIR> 160 Wed Jul 08 03:45:35 2020 sys
<DIR> 544 Wed Feb 24 05:46:21 2021 var
<DIR> 480 Wed Jul 08 03:45:37 2020 usr
<DIR> 224 Wed Jul 08 03:45:35 2020 home
<LNK> 11 Tue Feb 02 10:10:29 2021 init
<DIR> 160 Wed Jul 08 03:45:35 2020 proc
<DIR> 2032 Sat Feb 20 06:44:31 2021 sbin
<DIR> 232 Wed Jul 08 03:45:35 2020 root
<LNK> 11 Wed Jul 08 03:45:37 2020 linuxrc
259314 Wed Jan 13 07:58:12 2021 v0A030000_10979_10954_x3540.hdr
195056 Wed Jan 13 07:58:12 2021 x3310fw_0_2_8_0_8850.hdr
<DIR> 160 Tue Feb 02 02:37:10 2021 ramfs
1 Wed Jan 13 08:02:52 2021 config.txt
uBoot> ubifsls etc/
341 Tue Feb 02 02:54:24 2021 motd
347 Wed Jul 08 03:45:37 2020 welcome
78 Wed Jul 08 03:45:37 2020 passwd
463 Wed Jul 08 03:45:37 2020 README.txt
304 Tue Feb 02 08:51:25 2021 fstab
27 Wed Jul 08 03:45:37 2020 group
2608 Thu Feb 25 06:05:37 2021 init.sh
103 Tue Feb 02 02:54:16 2021 inittab
查看某个文件
uBoot> ubifsload
uBoot> ubifsload --help
ubifsload - load file from an UBIFS filesystem
Usage:
ubifsload <addr> <filename> [bytes]
- load file 'filename' to address 'addr'
Note: addr 表示RAM的起始地址,根据自己的平台进行指定
具体使用如下, 以查看/etc/init.sh为例:uBoot> ubifsload 0x2000000 etc/init.sh
uBoot> ubifsload 0x2000000 etc/init.sh
Loading file 'etc/init.sh' to addr 0x02000000 with size 2608 (0x00000a30)...
Done
md 0x2000000
uBoot> md 0x2000000
02000000: 622f2123 732f6e69 66690a68 73657420 #!/bin/sh.if tes
02000010: 652d2074 72702f20 762f636f 69737265 t -e /proc/versi
02000020: 740a6e6f 0a6e6568 68636520 6c650a6f on.then. echo.el
02000030: 0a0a6573 736f6820 6d616e74 414d2065 se.. hostname MA
02000040: 4c455652 494c5f4c 0a58554e 4d4f4820 RVELL_LINUX. HOM
......
米尔ST MYD-YA15XC-T开发板——1系统分析
本次的开发板上核心板型号是MYC-YA151C-256N256D-65-I-T,所以从系统中可以看到NAND的分区情况
dev: size erasesize namemtd0: 00200000 00020000 "fsbl"mtd1: 00200000 00020000 "ssbl1"mtd2: 00200000 00020000 "ssbl2"mtd3: 0fa00000 00020000 "UBI"
前面三个是FSBL和两个SSBL,那么就能确定,kernel, dtb, rootfs应该都在UBI分区里面。接下来看下UBI分区里的信息
ubi0Volumes count: 4Logical eraseblock size: 126976 bytes, 124.0 KiBTotal amount of logical eraseblocks: 1996 (253444096 bytes, 241.7 MiB)Amount of available logical eraseblocks: 0 (0 bytes)Maximum count of volumes 128Count of bad physical eraseblocks: 4Count of reserved physical eraseblocks: 36Current maximum erase counter value: 2Minimum input/output unit size: 2048 bytesCharacter device major/minor: 241:0Present volumes: 0, 1, 2, 3
可以看出有四个volume,分别是0,1,2,3。那就依次看下这几个卷
Volume ID: 0 (on ubi0)Type: dynamicAlignment: 1Size: 3 LEBs (380928 bytes, 372.0 KiB)State: OKName: uboot_configCharacter device major/minor: 241:1
可以看出来,vol2是boot,vol3是rootfs。所以从mount命令也可以看出来
root@myir-ya151c-t:~# mountubi0:rootfs on / type ubifs (rw,relatime,assert=read-only,ubi=0,vol=3)devtmpfs on /dev type devtmpfs (rw,relatime,size=54648k,nr_inodes=13662,mode=755)sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)proc on /proc type proc (rw,relatime)securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd)pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)tmpfs on /tmp type tmpfs (rw,nosuid,nodev)fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)/dev/ubi0_2 on /boot type ubifs (rw,relatime,assert=read-only,ubi=0,vol=2)tmpfs on /var/volatile type tmpfs (rw,relatime)tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=24136k,mode=700)
至于0和1,后面来分析。当前配置是nand 256MB的,看下系统还剩下多少空间可以使用
root@myir-ya151c-t:~# df -hFilesystem Size Used Avail Use% Mounted onubi0:rootfs 201M 177M 25M 88% /devtmpfs 54M 0 54M 0% /devtmpfs 118M 64K 118M 1% /dev/shmtmpfs 118M 8.8M 110M 8% /runtmpfs 118M 0 118M 0% /sys/fs/cgrouptmpfs 118M 0 118M 0% /tmp/dev/ubi0_2 15M 11M 3.4M 77% /boottmpfs 118M 136K 118M 1% /var/volatiletmpfs 24M 0 24M 0% /run/user/0
已经被使用了88%,所以只有25MB可以使用,也运行不了多少应用了。对于使用nand来作为产品开发,还需要更深度的对系统优化,后面有时间可以做这方面看看。再看看ram的使用情况
root@myir-ya151c-t:~# freetotal used free shared buff/cache availableMem: 241392 55156 129216 9120 57020 171316Swap: 0 0 0
总共256MB,系统占用后,剩余可以使用的只有130MB左右。那就再看下当前系统默认运行了哪些应用
root@myir-ya151c-t:~# ps -efUID PID PPID C STIME TTY TIME CMDroot 1 0 0 15:50 ? 00:00:05 /sbin/initroot 2 0 0 15:50 ? 00:00:00 [kthreadd]root 3 2 0 15:50 ? 00:00:00 [rcu_gp]root 4 2 0 15:50 ? 00:00:00 [rcu_par_gp]root 6 2 0 15:50 ? 00:00:00 [kworker/0:0H-events_highpri]root 7 2 0 15:50 ? 00:00:00 [kworker/u2:0-events_unbound]root 8 2 0 15:50 ? 00:00:00 [mm_percpu_wq]root 9 2 0 15:50 ? 00:00:01 [ksoftirqd/0]root 10 2 0 15:50 ? 00:00:00 [rcu_preempt]root 11 2 0 15:50 ? 00:00:00 [migration/0]root 12 2 0 15:50 ? 00:00:00 [cpuhp/0]root 13 2 0 15:50 ? 00:00:00 [kdevtmpfs]root 14 2 0 15:50 ? 00:00:00 [netns]root 15 2 0 15:50 ? 00:00:00 [rcu_tasks_kthre]root 16 2 0 15:50 ? 00:00:06 [kworker/0:1-pm]root 17 2 0 15:50 ? 00:00:00 [oom_reaper]root 18 2 0 15:50 ? 00:00:00 [writeback]root 19 2 0 15:50 ? 00:00:00 [kcompactd0]root 87 2 0 15:50 ? 00:00:00 [kblockd]root 88 2 0 15:50 ? 00:00:00 [blkcg_punt_bio]root 89 2 0 15:50 ? 00:00:00 [ata_sff]root 90 2 0 15:50 ? 00:00:00 [edac-poller]root 91 2 0 15:50 ? 00:00:00 [devfreq_wq]root 92 2 0 15:50 ? 00:00:00 [watchdogd]root 93 2 0 15:50 ? 00:00:00 [rpciod]root 94 2 0 15:50 ? 00:00:00 [kworker/u3:0-hci0]root 95 2 0 15:50 ? 00:00:00 [xprtiod]root 96 2 0 15:50 ? 00:00:00 [kswapd0]root 97 2 0 15:50 ? 00:00:00 [nfsiod]root 98 2 0 15:50 ? 00:00:00 [cifsiod]root 99 2 0 15:50 ? 00:00:00 [smb3decryptd]root 100 2 0 15:50 ? 00:00:00 [cifsfileinfoput]root 101 2 0 15:50 ? 00:00:00 [cifsoplockd]root 106 2 0 15:50 ? 00:00:00 [krfcommd]root 107 2 0 15:50 ? 00:00:00 [kstrp]root 118 2 0 15:50 ? 00:00:00 [hwrng]root 119 2 0 15:50 ? 00:00:00 [irq/45-stm_ther]root 124 2 0 15:50 ? 00:00:00 [irq/46-54002000]root 125 2 0 15:50 ? 00:00:00 [54002000.hash-e]root 143 2 0 15:50 ? 00:00:00 [irq/59-5c004000]root 144 2 0 15:50 ? 00:00:00 [irq/60-40013000]root 145 2 0 15:50 ? 00:00:00 [irq/65-5c002000]root 146 2 0 15:50 ? 00:00:00 [irq/67-pmic_irq]root 150 2 0 15:50 ? 00:00:00 [irq/77-4c001000]root 151 2 0 15:50 ? 00:00:00 [irq/78-4c001000]root 152 2 0 15:50 ? 00:00:00 [mlahb:m4@100000]root 154 2 0 15:50 ? 00:00:00 [irq/80-48003000]root 155 2 0 15:50 ? 00:00:00 [irq/81-48003000]root 156 2 0 15:50 ? 00:00:00 [stmmac_wq]root 158 2 0 15:51 ? 00:00:00 [irq/63-0-0028]root 159 2 0 15:51 ? 00:00:00 [ubi_bgt0d]root 161 2 0 15:51 ? 00:00:00 [ubifs_bgt0_3]root 162 2 0 15:51 ? 00:00:00 [ipv6_addrconf]root 618 1 2 15:51 ? 00:00:35 /usr/sbin/rngd -f -r /dev/hwrngrpc 622 1 0 15:51 ? 00:00:00 /usr/sbin/rpcbind -w -froot 629 1 0 15:51 ? 00:00:00 /lib/systemd/systemd-journaldroot 638 2 0 15:51 ? 00:00:00 [ubifs_bgt0_2]root 652 1 0 15:51 ? 00:00:00 /lib/systemd/systemd-udevdsystemd+ 656 1 0 15:51 ? 00:00:01 /lib/systemd/systemd-timesyncdroot 670 2 0 15:51 ? 00:00:00 [irq/22-44009000]root 671 2 0 15:51 ? 00:00:00 [spi0]root 688 1 0 15:51 ? 00:00:00 /sbin/klogd -nroot 692 1 0 15:51 ? 00:00:00 /sbin/syslogd -nmessage+ 698 1 0 15:51 ? 00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-onlyroot 725 2 0 15:51 ? 00:00:00 [irq/42-4c006000]root 726 2 0 15:51 ? 00:00:00 [irq/57-5c000000]root 727 2 0 15:51 ? 00:00:00 [kworker/u2:2-events_unbound]root 730 2 0 15:51 ? 00:00:00 [kworker/u3:2-hci0]root 769 1 0 15:51 ? 00:00:00 /lib/systemd/systemd-logindroot 770 1 0 15:51 ? 00:00:00 /usr/libexec/bluetooth/bluetoothdsystemd+ 771 1 0 15:51 ? 00:00:01 /lib/systemd/systemd-networkdroot 773 1 1 15:51 ? 00:00:17 /usr/sbin/netdata -D -u rootsystemd+ 778 1 0 15:51 ? 00:00:00 /lib/systemd/systemd-resolvedavahi 779 1 0 15:51 ? 00:00:00 avahi-daemon: running [myir-ya151c-t.local]root 780 1 0 15:51 ? 00:00:00 /usr/sbin/iiod64371 781 1 0 15:51 ? 00:00:00 /sbin/ninfod -davahi 782 779 0 15:51 ? 00:00:00 avahi-daemon: chroot helperpulse 784 1 0 15:51 ? 00:00:00 /usr/bin/pulseaudio --system --realtime --disallow-exit --daemonize=no61563 785 1 0 15:51 ? 00:00:00 /sbin/rdisc -f -troot 787 1 0 15:51 ? 00:00:00 /usr/sbin/vsftpdroot 790 1 0 15:51 tty1 00:00:00 /sbin/agetty -o -p -- \u --noclear tty1 linuxroot 791 1 0 15:51 ttySTM0 00:00:00 /bin/login -froot 794 2 0 15:51 ? 00:00:00 [irq/55-40010000]root 796 1 0 15:51 ? 00:00:00 /lib/systemd/systemd --userroot 797 796 0 15:51 ? 00:00:00 (sd-pam)root 802 791 0 15:51 ttySTM0 00:00:00 -shroot 807 1 0 15:51 ? 00:00:00 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --sessionroot 815 1 0 15:51 ? 00:00:00 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --sessionroot 823 1 0 15:51 ? 00:00:00 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --sessionroot 839 2 0 15:51 ? 00:00:00 [kworker/0:1H]root 869 773 2 15:51 ? 00:00:31 /usr/libexec/netdata/plugins.d/apps.plugin 2root 871 773 0 15:51 ? 00:00:08 bash /usr/libexec/netdata/plugins.d/charts.d.plugin 2root 873 773 0 15:51 ? 00:00:05 /usr/bin/python3 /usr/libexec/netdata/plugins.d/python.d.plugin 2root 1043 2 0 15:52 ? 00:00:00 [cfg80211]root 1547 2 0 15:57 ? 00:00:10 [kworker/0:0+events_freezable]root 2057 2 0 16:05 ? 00:00:02 [kworker/0:2-events]root 2379 2 0 16:10 ? 00:00:02 [kworker/0:3-events]root 2688 2 0 16:15 ? 00:00:00 [kworker/0:4-events]
看到有个netdata的python应用在运行,可以关闭看看能节省多少ram出来,其他的bluetooth,ftp不需要的也可以关闭,毕竟板上也没有这些硬件外设。
root@myir-ya151c-t:~# systemctl stop netdataroot@myir-ya151c-t:~# systemctl stop bluetooth
关闭后有20MB,还是有一些优化的空间。
相关问答
MTD是什么意思?说到NANDflash类文件系统,不得不提到之前的Yaffs2以及UBIFS。这两种文件系统都是基于linux的MTD层而实现的。MTD层就是linux对于NANDflashdriver封装的一...
小米路由器ax6s刷梅林固件?第一步:开启ssh,准备免拆机刷qsdk固件,通过env参数启动不同分区的固件。第二步:设置env开启必要的选项,ssh下打以下命令nvramsetflag_last_success=0n...