15AH, San Francisco

California, United States.

Send Your Mail At:

tianyingkejishe@sina.cn

Working Hours

Mon-Sat: 9.30am To 7.00pm

分类标题

Autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et dolore feugait.

分类归档 Linux

【phy】yt8521 phy芯片驱动移植

1、准备驱动文件

2、添加到相应目录

把motorcomm.c、yt8614-phy.h放到Linux的linux-5.19.1/drivers/net/phy/

把motorcomm_phy.h放到Linux的linux-5.19.1/include/linux/

3、修改Makefile

增加:obj-$(CONFIG_MOTORCOMM_PHY) += motorcomm.o

4、修改Kconfig

增加:

config MOTORCOMM_PHY
        tristate "Motorcomm PHYs"
        help
          Enables support for Motorcomm network PHYs.
          Currently supports the YT8511 gigabit PHY.

【安凯】环境搭建

一、配置gcc工具

export PATH="${PATH}:/opt/arm-anykav500-linux-uclibcgnueabi/bin"
临时生效,必须使用绝对路径。

二、libmpfr.so.4: cannot open shared object file: No such file or directory

sudo ln -s /usr/lib/x86_64-linux-gnu/libmpfr.so.6 /usr/lib/x86_64-linux-gnu/libmpfr.so.4

三、yylloc符号错误

……
186
187 extern YYSTYPE yylval;
188 //extern YYLTYPE yylloc;
189 int yyparse (void);
……
1193 /* The lookahead symbol. / 1194 int yychar; 1195 1196 / The semantic value of the lookahead symbol. / 1197 YYSTYPE yylval; 1198 / Location data for the lookahead symbol. / 1199 static YYLTYPE yylloc 1200 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL 1201 = { 1, 1, 1, 1 } 1202 # endif 1203 ; 1204 / Number of syntax errors so far. */
1205 int yynerrs;
1206
……

调整yylloc为局部符号.

【安凯】SDK编译时./mkfs.jffs2打包失败问题

一、报错

./mkfs.jffs2: error while loading shared libraries: liblzo2.so.2: cannot open shared object file: No such file or directory

二、解决方法

sudo apt-get update              //更新源,可以先执行第二步,不能安装则尝试更新源
sudo apt-get install liblzo2-dev:i386

Shell 中 kill 掉指定名称的进程

在 Linux 开发中我们时常会遇到对于之前进程 kill 掉,然后再运行当前进程或程序的情况,此时我们是不知道需要 kill 的进程号的,那么就需要通过一个 shell 命令组合来实现这个需求。

实现方法

如下命令可以实现:

ps a | grep -w nameprocess | grep -v grep| cut -c 1-6 | xargs kill -9

说明:

  • 管道符 “|” 用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入。
  • “ps a” 是查看所有进程的命令。这时检索出的进程将作为下一条命令 “grep“的输入,注意要结束其它程序时,请将上面命令中的 nameprocess 替换成其它程序名,-w ‘nameprocess’ 强制 PATTERN 仅完全匹配字词。
  • “grep -v grep” 是在列出的进程中去除含有关键字 “grep” 的进程。
  • “cut -c 1-6” 是截取输入行的第 1 个字符到第 6 个字符,而这正好是进程号 PID,或者根据自己实际的情况可以调整字符的截取位置。
  • “xargs kill -9” 中的 xargs 命令是用来把前面命令的输出结果(PID)作为 “kill -9” 命令的参数,并执行该命令。
  • “kill -9” 会强行杀掉指定进程,这样就成功清除了同名进程。

其他方法

ps axu|grep nameprocess | awk '{print "kill -9 "}'

【Linux】分区扩容至整个SD卡

一、查看信息

root@somlabs:~# fdisk -l
省略若干


Disk /dev/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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
Disklabel type: dos
Disk identifier: 0x9de2d76a

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk1p0      16384 1628159 1611776  787M 83 Linux

二、操作分区

假如需要扩展分区为mmcblk0p1

root@somlabs:~# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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
Disklabel type: dos
Disk identifier: 0x9de2d76a

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk1p1      16384 1628159 1611776  787M 83 Linux
这里也看到Start扇区也是16384
Command (m for help): d
把这个分区删除
Partition 1 has been deleted.

Command (m for help): p
列出分区信息Disk /dev/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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
Disklabel type: dos
Disk identifier: 0x9de2d76a

Command (m for help): n
新建分区Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
主分区Partition number (1-4, default 1): 1
分区序号,First sector (2048-7745535, default 2048): 16384
这里要使用起始扇区16384这个值Last sector, +sectors or +size{K,M,G,T,P} (16384-7745535, default 7745535):
默认回车取最大,
Created a new partition 1 of type 'Linux' and of size 3.7 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n
不改变文件分区信号??
Command (m for help): w
写入生效
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

三、重启系统

root@somlabs:~# reboot

四、扩容文件系统

resize2fs /dev/mmcblk1p1
resize2fs 1.43.4 (31-Jan-2017)
Filesystem at /dev/mmcblk1p1 is m[  122.795430] EXT4-fs (mmcblk1p1): resizing filesystem from 201472 to 966144 blocks
ounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
[  123.861183] EXT4-fs (mmcblk1p1): resized filesystem to 966144
The filesystem on /dev/mmcblk1p1 is now 966144 (4k) blocks long.

五、查看大小

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       3.7G  499M  3.0G  15% /
devtmpfs         88M     0   88M   0% /dev
tmpfs           248M     0  248M   0% /dev/shm
tmpfs           248M  3.4M  245M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           248M     0  248M   0% /sys/fs/cgroup
tmpfs            50M     0   50M   0% /run/user/0

【Linux】MTD 动态挂载SPI-NOR flash

1、配置psi-nor为驱动模块

 Device Drivers  --->   
   <*> Memory Technology Device (MTD) support  ---> 
     <M>   SPI NOR device support  ---> 

2、进入内核加载

modpro and insmod xxx.ko

spi-nor.ko

【Linux】实现spidev驱动添加

一、功能配置

1、make menuconfig

2、修改设备树

&spi3 {
        status = "okay";
        pinctrl-names = "default";
        pinctrl-0 = <&spi3m1_cs0 &spi3m1_pins>;
        spi_test@00 {
                compatible = "rockchip,rk-spidev";
                reg = <0>;
                spi-max-frequency = <5000000>;
        };
};

3、修改驱动文件

vim spidev.c
增加compatible 匹配设备树参数。

static const struct spi_device_id spidev_spi_ids[] = {
        { .name = "dh2228fv" },
        { .name = "ltc2488" },
        { .name = "sx1301" },
        { .name = "bk4" },
        { .name = "dhcom-board" },
        { .name = "m53cpld" },
        { .name = "spi-petra" },
        { .name = "spi-authenta" },
        { .name = "rk-spidev" },
        {},
};
static const struct of_device_id spidev_dt_ids[] = {
        { .compatible = "rohm,dh2228fv", .data = &spidev_of_check },
        { .compatible = "lineartechnology,ltc2488", .data = &spidev_of_check },
        { .compatible = "semtech,sx1301", .data = &spidev_of_check },
        { .compatible = "lwn,bk4", .data = &spidev_of_check },
        { .compatible = "dh,dhcom-board", .data = &spidev_of_check },
        { .compatible = "menlo,m53cpld", .data = &spidev_of_check },
        { .compatible = "cisco,spi-petra", .data = &spidev_of_check },
        { .compatible = "micron,spi-authenta", .data = &spidev_of_check },
        { .compatible = "rockchip,rk-spidev", .data = &spidev_of_check },
        {},
};

二、测试spidev设备

【IMG】创建和修改镜像内容

一、创建新镜像文件

1、创建镜像文件

使用dd命令创建一个空的镜像文件rootfs.img,每次读取和写入的字节数是1M,大小为1M*2048;大小可根据自己需要保存文件的多少自定义。

$ dd if=/dev/zero of=rootfs.img bs=1M count=2048

2、格式化镜像文件

格式化镜像文件rootfs.img为ext4格式,具体格式化的类型还有ext3、ntfs、fat等格式可自定义。

$ mkfs.ext4 -c rootfs.img  

3、挂载镜像文件

挂载镜像文件rootfs.img到/mnt目录中。具体挂载的目录可以自定义。

$ sudo mount -t ext4 -o loop rootfs.img /mnt

4、拷贝文件到镜像

拷贝需要打包到镜像中的文件到挂载的目录中,此处表示拷贝rootfs/下的所有文件到/mnt目录中(即镜像文件中)。
$ sudo cp -rfp rootfs/* /mnt

5、取消挂载

取消镜像文件的挂载。取消挂载后就表示镜像文件制作完成。

$ sudo umount /mnt

二、修改镜像文件

1、查看镜像分区

fdisk *.img
xiaobao@Newu:~/hdd/tmp$ fdisk AB-small-S-lvm-A03-other-armbian-1.1.100.57.9.img

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk AB-small-S-lvm-A03-other-armbian-1.1.100.57.9.img: 2.77 GiB, 2956984320 bytes, 5775360 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
Disklabel type: dos
Disk identifier: 0x00000000

Device                                             Boot  Start     End Sectors  Size Id Type
AB-small-S-lvm-A03-other-armbian-1.1.100.57.9.img1        8192  530431  522240  255M  c W95 FAT32 (LBA)
AB-small-S-lvm-A03-other-armbian-1.1.100.57.9.img2      532480 5775359 5242880  2.5G 83 Linux

2、挂载分区

sudo mount -o loop,offset=4194304 AB-small-S-lvm-A03-other-armbian-1.1.100.57.9.img /mnt/tmp/

可以看到img文件中有两个分区,第一个分区是从8192开始的,这里需要特别注意,需要转换一下:8192*512=4194304B

3、替换内容

$ sudo cp -rfp rootfs/* /mnt/tmp/

三、硬盘导出镜像工具