开辟一套SDK 第一弹

[复制链接]
发表于 2025-12-7 15:52:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

主动安装依靠包

添加条件使能
#ex: filetype=sh

bash_ls 辨认

到达预期,多个硬件情况


等候文件文件体系挂在完成
大概创建 /sys/class/ 属性文件灌入设置操纵
AI 提供的 netlink 调试方法,也是现在主流调用方法,socket yyds
  1. #include <linux/module.h>
  2. #include <linux/netlink.h>
  3. #include <linux/skbuff.h>
  4. #include <net/sock.h>
  5. #define NETLINK_USER 31
  6. #define NETLINK_CMD_DEBUG_INFO 100 // 调试命令
  7. struct sock *nl_sock = NULL;
  8. static void send_debug_info(struct sk_buff *skb, struct nlmsghdr *nlh) {
  9.     struct sk_buff *skb_out;
  10.     struct nlmsghdr *nlh_out;
  11.     char *debug_info = "Kernel Debug Info: Module is working correctly.";
  12.     int debug_info_len = strlen(debug_info);
  13.     int pid;
  14.     int res;
  15.     pid = nlh->nlmsg_pid; // 用户进程的 PID
  16.     // 创建响应消息
  17.     skb_out = nlmsg_new(debug_info_len, GFP_KERNEL);
  18.     if (!skb_out) {
  19.         pr_err("Failed to allocate new skb\n");
  20.         return;
  21.     }
  22.     nlh_out = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, debug_info_len, 0);
  23.     strncpy(nlmsg_data(nlh_out), debug_info, debug_info_len);
  24.     // 发送消息
  25.     res = nlmsg_unicast(nl_sock, skb_out, pid);
  26.     if (res < 0) {
  27.         pr_err("Failed to send debug info to user-space\n");
  28.     }
  29. }
  30. static void netlink_receive_msg(struct sk_buff *skb) {
  31.     struct nlmsghdr *nlh;
  32.     nlh = (struct nlmsghdr *)skb->data;
  33.     pr_info("Received Netlink message: %s\n", (char *)nlmsg_data(nlh));
  34.     // 根据命令类型处理消息
  35.     switch (nlh->nlmsg_type) {
  36.     case NETLINK_CMD_DEBUG_INFO:
  37.         send_debug_info(skb, nlh);
  38.         break;
  39.     default:
  40.         pr_warn("Unknown Netlink command: %d\n", nlh->nlmsg_type);
  41.         break;
  42.     }
  43. }
  44. static int __init netlink_debug_init(void) {
  45.     struct netlink_kernel_cfg cfg = {
  46.         .input = netlink_receive_msg, // 接收消息的回调函数
  47.     };
  48.     nl_sock = netlink_kernel_create(&init_net, NETLINK_USER, &cfg);
  49.     if (!nl_sock) {
  50.         pr_err("Failed to create Netlink socket\n");
  51.         return -ENOMEM;
  52.     }
  53.     pr_info("Netlink Debug Module initialized\n");
  54.     return 0;
  55. }
  56. static void __exit netlink_debug_exit(void) {
  57.     netlink_kernel_release(nl_sock);
  58.     pr_info("Netlink Debug Module exited\n");
  59. }
  60. module_init(netlink_debug_init);
  61. module_exit(netlink_debug_exit);
  62. MODULE_LICENSE("GPL");
  63. MODULE_AUTHOR("Your Name");
  64. 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 舒服 香 ,完事儿

buildroot 中主动编译 autoconf 的地方
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表