嵌入式linux开发常用操作

1.ubuntu交叉编译器环境变量设置

vim /etc/profile

export PATH=$PATH:/usr/local/arm/gcc-arm-none-eabi-9-2019-q4-major/bin
export PATH=$PATH:/usr/local/arm/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin

2.常用搜索命令

grep -nR "字符串" path
find path filename

3.ssh远程连接

ssh -p prot root@192.168.2.101
scp -P port xxx root@192.168.2.101:~/

4.挂载ubuntu的/home/learn目录到开发板的/mnt目录

mount -t nfs -o nolock,vers=2 192.168.1.100:/home/learn /mnt

5.内核编程中虚拟地址和物理地址的转换

虚拟地址 转 物理地址:  virt_to_phys( *addr );
物理地址 转 虚拟地址:  phys_to_virt( *addr );

6.设置linux开机自动加载内核模块

#(1).将.ko文件的内核模块存放在指定位置(使用 uname -r 查看内核版本)
cp xxx.ko /lib/modules/内核版本

#(2).建立模块间的依赖关系
cd /lib/modules/内核版本
depmod -a

#(3).在/etc/modules文件末尾加上新增的模块
vim /etc/modules

#增加内容:
xxx.ko

7.uboot启动内核的环境变量设置

# 根文件系统在mmc的第三个分区
# 内核镜像 zImage 在 /boot 目录下
# 设备树文件 xxx.dtb 在 /boot 目录下
setenv bootargs 'console=ttySAC2,115200 root=/dev/mmcblk1p3 rootwait rw'
setenv bootcmd 'mmc dev 1; ext4load mmc 1:3 40007000 /boot/zImage; ext4load mmc 1:3 43000000 /boot/exynos4412-itop-elite.dtb; bootz 40007000 - 43000000;'
saveenv

8.查看cpu、内存、硬盘等内核信息

  • 1).查看当前cpu的运行频率(单位:KHZ)
# 查看当前cpu运行的频率
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq

# 查看当前CPU能运行的最大频率
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq

# 查看当前CPU能运行的最小频率
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
  • 2).查看cpu信息
cat /proc/cpuinfo
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 
# 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数

# 查看物理CPU个数
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l

# 查看每个物理CPU中core的个数(即核数)
cat /proc/cpuinfo| grep "cpu cores"| uniq

# 查看逻辑CPU的个数
cat /proc/cpuinfo| grep "processor"| wc -l

# 查看CPU信息(型号)
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
processor :系统中逻辑处理核的编号。对于单核处理器,则课认为是其CPU编号,对于多核处理器则可以是物理核、或者使用超线程技术虚拟的逻辑核
vendor_id :CPU制造商      
cpu family :CPU产品系列代号
model   :CPU属于其系列中的哪一代的代号
model name:CPU属于的名字及其编号、标称主频
stepping   :CPU属于制作更新版本
cpu MHz   :CPU的实际使用主频
cache size   :CPU二级缓存大小
physical id   :单个CPU的标号
siblings       :单个CPU逻辑物理核数
core id        :当前物理核在其所处CPU中的编号,这个编号不一定连续
cpu cores    :该逻辑核所处CPU的物理核数
apicid          :用来区分不同逻辑核的编号,系统中每个逻辑核的此编号必然不同,此编号不一定连续
fpu             :是否具有浮点运算单元(Floating Point Unit)
fpu_exception  :是否支持浮点计算异常
cpuid level   :执行cpuid指令前,eax寄存器中的值,根据不同的值cpuid指令会返回不同的内容
wp             :表明当前CPU是否在内核态支持对用户空间的写保护(Write Protection)
flags          :当前CPU支持的功能
bogomips   :在系统内核启动时粗略测算的CPU速度(Million Instructions Per Second)
clflush size  :每次刷新缓存的大小单位
cache_alignment :缓存地址对齐单位
address sizes     :可访问地址空间位数
power management :对能源管理的支持,有以下几个可选支持功能:
  • 3).查看内存
#看当前内存大小,已用空间等等
sudo cat /proc/meminfo
  • 4).查看系统运行时间(第一个参数是系统从启动到现在经历的秒数,第二个参数 说的代表cpu空闲的时间)
cat /proc/uptime
  • 5).查看内核IO地址映射(物理内存地址分配情况)
cat /proc/iomem
  • 6).查看内核版本
cat /proc/version
  • 7).查看内核函数
cat /proc/kallsyms
  • 8).查看系统启动参数
cat /proc/cmdline
  • 9).查看硬盘信息
cat /proc/diskstats
  • 10).查看中断
cat /proc/interrupts

9.修改屏幕亮度

echo 128 > /sys/class/backlight/backlight/brightness

10.linux内核input子系统框架

devices
input_allocate_device()
input_register_device()
input_event()
input_sync()
handlers
drivers/input/evdev.c
drivers/tty/vt/keyboard.c
drivers/input/mousedev.c
...
input
drivers/input/input.c
input_allocate_device
input_allocate_device()
input_register_handler
input_register_handler()
input_register_device
input_register_device()
input_handler
.id_table
.name
...
event()
events()
match()
connect()
input_dev
.name
.evbit[]
.keybit[]
.relbit[]
.absbit[]
...
connect
input_handle
input_register_handle()
cdev_init
file_operations

11.linux内核pwm子系统框架

core
drivers/pwm/core.c
pwm_samsung
drivers/pwm/pwm-samsung.c
pwm_sysfs
drivers/pwm/sysfs.c
sysfs_class_pwm
/sys/class/pwm/pwmchip0/enable
pwm_chip
.device
.pwm_ops
pwmchip_add
pwmchip_add()
pwm_apply_state
pwm_apply_state()
pwm_request
pwm_request()
pwm_config
pwm_config()
pwm_enable
pwm_enable()
pwm_samsung_probe
samsung_pwm_chip
.ops = &pwm_samsung_ops;
pwm_samsung_request
pwm_samsung_request()
pwm_samsung_config
pwm_samsung_config()
pwm_samsung_enable
pwm_samsung_enable()
pwm_samsung_ops
.request
.enable
.config

12.linux内核i2c驱动框架

i2c_bus_type
drivers/i2c/i2c-core-base.c
.match = i2c_device_match
.probe = i2c_device_probe
i2c_new_device
i2c_new_device()
i2c_client
.i2c_adapter
.flags
.addr
.name
.dev
.irq
i2c_add_driver
i2c_add_driver()
i2c_driver
.id_table
.name
.probe
.remove
attach_adapter()
i2c_add_adapter
i2c_add_adapter()
i2c_algorithm
.master_xfer
.smbus_xfer
.functionality
i2c_adapter
.i2c_algorithm
device_node
/dev/xxx
i2c_devnode
/dev/i2c-%d
i2c_dev
drivers/i2c/i2c-dev.c

13.linux内核framebuffer框架

core
drivers/video/fbdev/core/fbmem.c
fb_info
.fb_var_screeninfo
.fb_fix_screeninfo
.fb_ops
register_framebuffer
register_framebuffer()

14.linux内核usb总线框架

usb_hub_init
usb_register(&hub_driver)
hub_driver.probe()
hub_probe
hub_configure()
hub_irq
hub_irq(struct urb *urb)
kick_hub_wq
kick_hub_wq()
queue_work(hub_wq, &hub->events)
hub_events
NIT_WORK(&hub->events, hub_event)
hub_event
port_event()
hub_port_connect_change
hub_port_connect_change()
hub_port_connect
hub_port_connect()
usb_alloc_dev
drivers/usb/core/usb.c
dev->dev.bus = &usb_bus_type;
hub_port_init
hub_port_init()
hub_set_address
hub_set_address(udev, devnum)
usb_get_device_descriptor
usb_get_device_descriptor()
usb_new_device
usb_new_device(udev)
usb_enumerate_device
drivers/usb/core/config.c
usb_get_configuration(udev)
usb_get_configuration
include/uapi/linux/usb/ch11.h
struct usb_hub_descriptor;
usb_get_descriptor()
usb_parse_configuration()
usb_device_descriptor
.bDescriptorType;
.idVendor;
.idProduct;
.bcdDevice;
.bNumConfigurations
...
usb_config_descriptor
.bLength;
.bDescriptorType;
.wTotalLength;
.bNumInterfaces;
...
usb_interface_descriptor
.bLength;
.bDescriptorType;
.bInterfaceNumber;
.bAlternateSetting;
.bNumEndpoints;
...
usb_endpoint_descriptor
.bLength;
.bDescriptorType;
.bEndpointAddress;
.wMaxPacketSize;
...
device_add
device_add()
usb_bus_type
.name = "usb",
.match = usb_device_match,
.uevent = usb_uevent,
usb_device_match
drivers/usb/core/driver.c
usb_device_match()
usb_interface
include/linux/usb.h
usb_driver
include/linux/usb.h
.id_table
probe()

15.查看usb设备信息:速度

cat /sys/kernel/debug/usb/devices

16.内核函数likelyunlikely

likely(x)代表x是逻辑真(1)的可能性比较大;
unlikely(x)代表x是逻辑假(0)的可能性比较大。

17.配置overlayfs

vim /etc/fstab:

/dev/mmcblk0p1  /boot           vfat    rw                              0       1
# /dev/mmcblk0p3 is misc partition, no filesystem
/dev/mmcblk0p2  /recovery       ext4    defaults                        0       0
/dev/mmcblk0p4  /media/root-ro  ext4    ro,errors=remount-ro,noauto     0       0
/media/root-ro  /               overlay lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir  0       0
/dev/mmcblk0p5  /media/root-rw  ext4    defaults                        0       0
/dev/mmcblk0p6  /opt         ext4       defaults                        0       0
/dev/mmcblk0p7  /data           ext4    defaults                        0       0
# tmpfs         /tmp            tmpfs   nodev,nosuid,size=1G            0       0

18、linux配置静态ip

# 修改ip
sudo vim /etc/network/interfaces.d/eth0
# 重新启动网络服务
sudo /etc/init.d/networking restart

19.后续

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值