【T113】buildroot增加app

发布时间:2026/10/30 15:43:46
【T113】buildroot增加app 文章目录新增app源码monitor_usb.cMakefilebuildroot 配置Config.inmonitor_usb.mkplatform/config/buildroot/Config.inplatform/config/buildroot/platform.mkbuildroot/buildroot-201902/configs/sun8iw20p1_t113_defconfig配置程序为默认启动S92monitor_usb.sh原文链接https://lixiaogang03.github.io/2023/12/05/Buildroot-Add-App/新增app源码目录t113_linux/platform/apps/monitor_usb$ tree.├── Makefile └── monitor_usb.cmonitor_usb.c#includeunistd.h#includestdio.h#includestring.h#includelibudev.h#includestdlib.h#includesys/reboot.h/** * swupdate ota */voidswupdate_ota(){constchar*filename/mnt/usb/sda1/update.swu;intresultaccess(filename,F_OK);if(result0){intresponsesystem(swupdate -v -i /mnt/usb/sda1/update.swu -e stable,now_A_next_B);if(response-1){printf(Failed to execute swupdate command\n);}else{printf(Rebooting the device...\n);sync();// 同步磁盘上的数据if(reboot(RB_AUTOBOOT)-1){printf(Failed to reboot the system\n);}}}else{printf(/mnt/usb/sda1/update.swu does not exits\n);}}intmain(){structudev*udev;structudev_monitor*mon;structudev_device*dev;intfd;/* 初始化 udev */udevudev_new();if(!udev){fprintf(stderr,Cant create udev\n);return1;}/* 创建 udev 监听器 */monudev_monitor_new_from_netlink(udev,udev);if(!mon){fprintf(stderr,Cant create udev monitor\n);return1;}/* 设置要监听的事件类型 */if(udev_monitor_filter_add_match_subsystem_devtype(mon,block,disk)0||udev_monitor_enable_receiving(mon)0){fprintf(stderr,Cant filter block subsystem or enable receiving\n);return1;}// 获取文件描述符fdudev_monitor_get_fd(mon);/* 循环监听并处理事件 */while(1){// 使用 select 系统调用来等待设备事件或超时fd_set fds;FD_ZERO(fds);FD_SET(fd,fds);structtimevaltimeout;timeout.tv_sec5;// 设置超时时间为 5 秒timeout.tv_usec0;// 使用 select() 设置超时时间if(select(fd1,fds,NULL,NULL,timeout)0){printf(Error waiting for device event\n);continue;}if(FD_ISSET(fd,fds)){// 当设备事件发生时从监视器接收设备对象devudev_monitor_receive_device(mon);if(devNULL){printf(Invalid device received from udev monitor\n);continue;}constchar*actionudev_device_get_action(dev);constchar*devpathudev_device_get_devnode(dev);printf(Action: %s, Device Path: %s\n,action,devpath);if(strcmp(add,action)0){swupdate_ota();}udev_device_unref(dev);}else{// 没有设备事件发生// printf(No device events received\n);}}/* 清理资源 */udev_monitor_unref(mon);udev_unref(udev);return0;}MakefileOBJSmonitor_usb.o OUT_BINmonitor_usb all:$(OBJS)$(CC)$(LDFLAGS)-g-o$(OUT_BIN)$^ %.o: %.c$(CC)$(CFLAGS)-c-o$$.PHONY: clean clean:rm-rf*.orm-rf$(OUT_BIN)rm-rf$(shellfind-name*.d)buildroot 配置t113_linux/platform/config/buildroot/monitor_usb$ tree.├── Config.in └── monitor_usb.mkConfig.inconfig BR2_PACKAGE_MONITOR_USB boolmonitor_usbselectBR2_PACKAGE_EUDEVhelpmonitor usbmonitor_usb.mk################################################################################## monitor usb#################################################################################MONITOR_USB_SITE_METHODlocalMONITOR_USB_SITE$(PLATFORM_PATH)/../../apps/monitor_usb MONITOR_USB_LICENSEGPLv2, GPLv3 MONITOR_USB_LICENSE_FILESCopyright COPYING MONITOR_USB_DEPENDENCIESudev MONITOR_USB_LDFLAGS-L$(TARGET_DIR)/usr/lib/-ludevdefine MONITOR_USB_BUILD_CMDS$(MAKE)CC$(TARGET_CC)CFLAGS$(MONITOR_USB_CFLAGS)\LDFLAGS$(MONITOR_USB_LDFLAGS)-C$(D)all endef define MONITOR_USB_INSTALL_TARGET_CMDS$(INSTALL)-D-m0755$(D)/monitor_usb$(TARGET_DIR)/usr/bin endef$(eval$(generic-package))platform/config/buildroot/Config.insource../../platform/config/buildroot/monitor_usb/Config.inplatform/config/buildroot/platform.mkinclude${PLATFORM_PATH}/monitor_usb/monitor_usb.mkbuildroot/buildroot-201902/configs/sun8iw20p1_t113_defconfigBR2_PACKAGE_MONITOR_USBy配置程序为默认启动t113_linux/platform/framework/auto/rootfs/etc/init.d$ tree.├── rcK ├── rcS ├── S01syslogd ├── S02klogd ├── S05mount_userdata ├── S10udev ├── S20urandom ├── S30dbus ├── S40network ├── S50bluetooth ├── S50postgresql ├── S52_4G-Daemon.sh ├── S80dnsmasq ├── S90alsa.sh └── S92monitor_usb.shS92monitor_usb.sh#!/bin/shcase$1instart)echoStarting monitor_usb/usr/bin/monitor_usb;;stop)echoStopping monitor_usbkillallmonitor_usb;;restart)$0stop$0start;;*)echoUsage:$0{start|stop|restart}exit1;;esacexit0

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询