开发一套SDK 第一弹

自动安装依赖包

添加条件使能

#ex: filetype=sh

bash_ls 识别

达到预期,多个硬件环境


等待文件文件系统挂在完成
或者创建 /sys/class/ 属性文件灌入配置操作
AI 提供的 netlink 调试方法,也是目前主流调用方法,socket yyds

c 复制代码
#include <linux/module.h>
#include <linux/netlink.h>
#include <linux/skbuff.h>
#include <net/sock.h>

#define NETLINK_USER 31
#define NETLINK_CMD_DEBUG_INFO 100 // 调试命令

struct sock *nl_sock = NULL;

static void send_debug_info(struct sk_buff *skb, struct nlmsghdr *nlh) {
    struct sk_buff *skb_out;
    struct nlmsghdr *nlh_out;
    char *debug_info = "Kernel Debug Info: Module is working correctly.";
    int debug_info_len = strlen(debug_info);
    int pid;
    int res;

    pid = nlh->nlmsg_pid; // 用户进程的 PID

    // 创建响应消息
    skb_out = nlmsg_new(debug_info_len, GFP_KERNEL);
    if (!skb_out) {
        pr_err("Failed to allocate new skb\n");
        return;
    }

    nlh_out = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, debug_info_len, 0);
    strncpy(nlmsg_data(nlh_out), debug_info, debug_info_len);

    // 发送消息
    res = nlmsg_unicast(nl_sock, skb_out, pid);
    if (res < 0) {
        pr_err("Failed to send debug info to user-space\n");
    }
}

static void netlink_receive_msg(struct sk_buff *skb) {
    struct nlmsghdr *nlh;

    nlh = (struct nlmsghdr *)skb->data;
    pr_info("Received Netlink message: %s\n", (char *)nlmsg_data(nlh));

    // 根据命令类型处理消息
    switch (nlh->nlmsg_type) {
    case NETLINK_CMD_DEBUG_INFO:
        send_debug_info(skb, nlh);
        break;
    default:
        pr_warn("Unknown Netlink command: %d\n", nlh->nlmsg_type);
        break;
    }
}

static int __init netlink_debug_init(void) {
    struct netlink_kernel_cfg cfg = {
        .input = netlink_receive_msg, // 接收消息的回调函数
    };

    nl_sock = netlink_kernel_create(&init_net, NETLINK_USER, &cfg);
    if (!nl_sock) {
        pr_err("Failed to create Netlink socket\n");
        return -ENOMEM;
    }

    pr_info("Netlink Debug Module initialized\n");
    return 0;
}

static void __exit netlink_debug_exit(void) {
    netlink_kernel_release(nl_sock);
    pr_info("Netlink Debug Module exited\n");
}

module_init(netlink_debug_init);
module_exit(netlink_debug_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("Netlink Debug Interface Example");

最方便的是直接访问内核,有bug 的时候非常容易内核崩溃
开发一些自定义的驱动还是很快乐的,使用netlink 接口完成热加载配置
简单的设备场景就完全可以配置进行,用户和多内核就在sysfs中配置使用
neovim + clangd 使用神器

使用yocto 来做qemu 会很方便
curl https://pyenv.run | bash #配置pyenv 切换python 环境
sudo apt install libssl-dev liblzma-dev
这就是为啥不想用 yocto 的原因


风扇转不停
毁灭吧
还是buildroot 舒服 香 ,完事儿

相关推荐
筑梦之路11 分钟前
深入linux的审计服务auditd —— 筑梦之路
linux·运维·服务器
hi_link20 分钟前
centos系统将/home分区的空间分配给/
linux·运维·centos
CSND74033 分钟前
linux离线环境局域网远程ssh连接vscode
linux·vscode·ssh
应用市场1 小时前
Linux驱动开发原理详解:从入门到实践
linux·运维·驱动开发
siriuuus1 小时前
Linux MySQL 多实例部署与配置实践
linux·运维·mysql
郝学胜-神的一滴1 小时前
深入解析Linux下的`lseek`函数:文件定位与操作的艺术
linux·运维·服务器·开发语言·c++·软件工程
冲上云霄的Jayden2 小时前
ubuntu 22一步步 安装docker和配置使用国内源
linux·ubuntu·docker·国内源
迎風吹頭髮2 小时前
Linux服务器编程实践20-TCP服务 vs UDP服务:核心差异对比
linux·服务器·tcp/ip
ajassi20002 小时前
开源 Linux 服务器与中间件(二)嵌入式Linux服务器和中间件
linux·服务器·开源
ajassi20002 小时前
开源 Linux 服务器与中间件(一)基本介绍
linux·服务器·开源