[linux]设置网卡自动连接并设置固定IP

sudo nmcli connection add type wifi ifname wlx7822884b2787 con-name rtlwap ssid rtlwap
sudo nmcli connection modify rtlwap wifi-sec.key-mgmt wpa-psk
sudo nmcli connection modify rtlwap wifi-sec.psk mqdqxyg1qy
sudo nmcli connection modify rtlwap ipv4.addresses 192.168.16.7/24
sudo nmcli connection modify rtlwap ipv4.gateway 192.168.16.1
sudo nmcli connection modify rtlwap ipv4.dns “8.8.4.4,114.114.114.114”
sudo nmcli connection modify rtlwap ipv4.method manual
sudo nmcli connection modify rtlwap connection.autoconnect yes

sudo nmcli connection up rtlwap ifname wlx7822884b2787

[Linux]开机自运行脚本

sudo vi /usr/local/bin/load_module.sh

//skyport的
#!/bin/bash
sleep 1
insmod /home/orangepi/wlanuav.ko rtw_country_code=”CN”
sleep 1
sudo iw dev wlx7822884b2786 set type AP
sleep 2
nmcli dev set wlx7822884b2786 managed no
sleep 2
sudo /usr/sbin/hostapd /usr/sbin/1.config -B
sleep 2
sudo ifconfig wlx7822884b2786 192.168.16.1
sleep 2
sudo openvpn –config /home/orangepi/skyport.ovpn –daemon
sleep 2
echo “autorun init done”

//baseport的

#!/bin/bash
chmod 777 /dev/spidev3.0
sleep 1
insmod /home/orangepi/wlanuav.ko rtw_country_code=”CN”
#sleep 1
#sudo iw dev wlx7822884b2787 set type AP
#sleep 2
#nmcli dev set wlx7822884b2787 managed no
#sleep 2
#sudo /usr/sbin/hostapd /usr/sbin/1.config -B
#sleep 2
#sudo ifconfig wlx7822884b2787 192.168.16.7
sleep 1
sudo openvpn –config /home/orangepi/baseport.ovpn –daemon
sleep 1

sudo chmod +x /usr/local/bin/load_module.sh

sudo vi /etc/rc.local

在 exit 0 之前添加:
——————————–
/usr/local/bin/load_module.sh

while ! ip route | grep -q “default”; do
echo “Waiting for default gateway…”
sleep 1
done

echo “Default gateway is set.”

sudo ip route del default via 192.168.43.1 dev usb0
—————————————–
sudo chmod +x /etc/rc.local

[linux]定时器异步通知

—————————–驱动————————————
/*
*file name: misc_device.c
*/

#include #include #include #include #include #include #include #include #include #include #include #include

#include #include

#include #include

#define MISC_MINOR 255

/* imx6uirq设备结构体 */
struct imx6uirq_dev{
struct fasync_struct *async_queue; /* 异步相关结构体 */
};

struct imx6uirq_dev imx6uirq; /* irq设备 */

// 定义定时器
static struct timer_list my_timer;

void my_timer_handler(struct timer_list *t) {

if(imx6uirq.async_queue)
{
// printk(KERN_INFO “timenow =: %ld\n”, jiffies);
kill_fasync(&imx6uirq.async_queue, SIGIO, POLL_IN); /* 释放SIGIO信号 */

}

mod_timer(&my_timer, jiffies + msecs_to_jiffies(1999));
// 重新启动定时器,例如每2秒触发一次

}

static int my_timer_init(void) {
// 初始化定时器
timer_setup(&my_timer, my_timer_handler, 0);

// 设置定时器的首次触发时间,例如 1 秒后
mod_timer(&my_timer, jiffies + msecs_to_jiffies(1000));

printk(KERN_INFO “定时器模块已初始化。\n”);
return 0;
}

static void my_timer_exit(void) {
// 删除定时器,防止再次触发
del_timer(&my_timer);
printk(KERN_INFO “定时器模块已卸载。\n”);
}

static int hello_open(struct inode *inode, struct file *filp)
{
printk(“misc open!\n”);
return 0;
}

static ssize_t hello_write(struct file *filp, const char __user *buf,size_t cnt, loff_t *offt)
{
int ret = 0;
unsigned char data[16];

printk(“misc write\n”);
ret = copy_from_user(data, buf, cnt);
if(ret != 0)
printk(“hello misc write failed\n”);

return ret;
}

static ssize_t hello_read(struct file *filp, char __user *buf, size_t cnt, loff_t *offt)
{
int ret = 0;
unsigned char data[4] = {0x12, 0x03, 0x56, 0x11};

printk(“misc read\n”);

ret = copy_to_user(buf, &data, sizeof(data));
if(ret != 0)
printk(“hello misc read failed\n”);

return ret;
}

int imx6uirq_fasync(int fd, struct file *filp, int on)
{
return fasync_helper(fd, filp, on, &imx6uirq.async_queue);
}

static int imx6uirq_release(struct inode *inode, struct file *filp)
{
return imx6uirq_fasync(-1, filp, 0);
}

/*
* file operations
*/
struct file_operations hello_fops = {

.owner = THIS_MODULE,
.write = hello_write,
.read = hello_read,
.open = hello_open,
.fasync = imx6uirq_fasync,
.release = imx6uirq_release,
};

/*
* misc description
*/
struct miscdevice hello_misc = {
.minor = MISC_MINOR,
.name = “my-timer”,
.fops = &hello_fops,
};

static int hello_init(void)
{
int ret = 0;

printk(” Hello World enter\n”);

ret = misc_register(&hello_misc);
if(ret != 0)
printk(“hello misc register failed!”);

my_timer_init();
return 0;
}

static void hello_exit(void)
{
my_timer_exit();
printk(” Hello World exit\n “);
misc_deregister(&hello_misc);
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE(“Dual BSD/GPL”);
MODULE_DESCRIPTION(“A simple Hello World Module”);

—————————–应用—————————————–

#include “stdio.h”
#include “unistd.h”
#include “sys/types.h”
#include “sys/stat.h”
#include “fcntl.h”
#include “stdlib.h”
#include “string.h”
#include “poll.h”
#include “sys/select.h”
#include “sys/time.h”
#include “linux/ioctl.h”
#include “signal.h”

static int fd = 0; /* 文件描述符 */

/*
* SIGIO信号处理函数
* @param – signum : 信号值
* @return : 无
*/
static void sigio_signal_func(int signum)
{
int err = 0;
unsigned int keyvalue = 0;
printf(“sigio signal!\r\n”);
}

/*
* @description : main主程序
* @param – argc : argv数组元素个数
* @param – argv : 具体参数
* @return : 0 成功;其他 失败
*/
int main(int argc, char *argv[])
{
int flags = 0;
char *filename;

if (argc != 2) {
printf(“Error Usage!\r\n”);
return -1;
}

filename = argv[1];
fd = open(filename, O_RDWR);
if (fd < 0) { printf("Can't open file %s\r\n", filename); return -1; } /* 设置信号SIGIO的处理函数 */ signal(SIGIO, sigio_signal_func); fcntl(fd, F_SETOWN, getpid()); /* 设置当前进程接收SIGIO信号 */ flags = fcntl(fd, F_GETFL); /* 获取当前的进程状态 */ fcntl(fd, F_SETFL, flags | FASYNC); /* 设置进程启用异步通知功能 */ while(1) { sleep(2); } close(fd); return 0; }

[linux]misc简单驱动

/*
*file name: misc_device.c
*/

#include #include #include #include #include #include #include #include #include #include #include #include

#define MISC_MINOR 255

static int hello_open(struct inode *inode, struct file *filp)
{
printk(“misc open!\n”);
return 0;
}

static ssize_t hello_write(struct file *filp, const char __user *buf,size_t cnt, loff_t *offt)
{
int ret = 0;
unsigned char data[16];

printk(“misc write\n”);
ret = copy_from_user(data, buf, cnt);
if(ret != 0)
printk(“hello misc write failed\n”);

return ret;
}

static ssize_t hello_read(struct file *filp, char __user *buf, size_t cnt, loff_t *offt)
{
int ret = 0;
unsigned char data[4] = {0x12, 0x03, 0x56, 0x11};

printk(“misc read\n”);

ret = copy_to_user(buf, &data, sizeof(data));
if(ret != 0)
printk(“hello misc read failed\n”);

return ret;
}

/*
* file operations
*/
struct file_operations hello_fops = {

.owner = THIS_MODULE,
.write = hello_write,
.read = hello_read,
.open = hello_open,
};

/*
* misc description
*/
struct miscdevice hello_misc = {
.minor = MISC_MINOR,
.name = “hello-misc”,
.fops = &hello_fops,
};

static int hello_init(void)
{
int ret = 0;

printk(” Hello World enter\n”);

ret = misc_register(&hello_misc);
if(ret != 0)
printk(“hello misc register failed!”);

return 0;
}

static void hello_exit(void)
{
printk(” Hello World exit\n “);
misc_deregister(&hello_misc);
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE(“Dual BSD/GPL”);
MODULE_DESCRIPTION(“A simple Hello World Module”);

[linux]GPIO 设备树

在/节点下添加
aledspx: aledspx {
compatible = “agpio-leds”;
pinctrl-names = “default”;
pinctrl-0 =<&aleds_gpio>;

led@1 {
gpios = <&gpio0 RK_PC1 GPIO_ACTIVE_HIGH>;
label = “astatus_led”;
};
};

pinctr中加入
awork-led {
aleds_gpio: aleds-gpio {
rockchip,pins = <0 RK_PC1 RK_FUNC_GPIO &pcfg_pull_none>;
};
};

——————————————————————-
多个IO可这样写
leds: leds {
compatible = “gpio-leds”;
pinctrl-names = “default”;
pinctrl-0 =<&leds_gpio>;

led = <&gpio0 RK_PC0 GPIO_ACTIVE_LOW>;
ledb = <&gpio0 RK_PC1 GPIO_ACTIVE_LOW>;
ledc = <&gpio0 RK_PC2 GPIO_ACTIVE_LOW>;

};

pinctr:

work-led {
leds_gpio: leds-gpio {
rockchip,pins = < 0 RK_PC0 RK_FUNC_GPIO &pcfg_pull_none>,
< 0 RK_PC1 RK_FUNC_GPIO &pcfg_pull_none>,
< 0 RK_PC2 RK_FUNC_GPIO &pcfg_pull_none>;
};
};

—————————–也可以这样写————————————
leds: leds {
compatible = “gpio-leds”;
pinctrl-names = “default”;
pinctrl-0 =<&leds_gpio>;

led@1 {
gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_HIGH>;
label = “status_led”;
linux,default-trigger = “heartbeat”;
};
leda {
gpios = <&gpio0 RK_PC1 GPIO_ACTIVE_HIGH>;
label = “astatus_led”;
};
ledb {
gpios = <&gpio0 RK_PC2 GPIO_ACTIVE_HIGH>;
label = “bstatus_led”;
};
};

pinctr:

work-led {
leds_gpio: leds-gpio {
rockchip,pins = < 0 RK_PC0 RK_FUNC_GPIO &pcfg_pull_none>,
< 0 RK_PC1 RK_FUNC_GPIO &pcfg_pull_none>,
< 0 RK_PC2 RK_FUNC_GPIO &pcfg_pull_none>;
};
};

编译设备树

[linux]ssh连不上

//检查状态
sudo service ssh status
//重启
sudo service ssh restart
//卸载重装
sudo apt-get remove –purge openssh-server
sudo apt-get update
sudo apt-get install openssh-server

[linux]ssh/scp传输失败

1.windows 连接linux失败
删除windos下的.ssh文件夹下的

2.scp失败
(1)删除源的~/.ssh/known_hosts
(2)ssh-keygen -f “/root/.ssh/known_hosts” -R “目标IP”