问一下台式机会有手机电池膨胀会爆炸吗吗

博客访问: 192557
博文数量: 48
博客积分: 15
博客等级: 民兵
技术积分: 110
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: 嵌入式
原文地址: 作者:
&&&&前些日子又搞起了OpenWRT,之前一直只是使用shell或者Lua实现自己的想法,随着C渐渐使用的顺畅了,打算学习下OpenWRT上程序的编写以及交叉编译。
首先列下目录结构
lee@ubuntu:~/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/package$ tree
|-- hiOpenWRT
|-- Makefile
|-- hiOpenwrt.c
`-- Makefile
|-- Makefile
`-- rules.mk
&&&&这是在OpenWRT-SDK/package下的文件结构,需要自己建的目录有hiOpenwrt/ 和hiOpenwrt/src/ ;需要自己建的文件有:
src下的hiOpenwrt.c
#include <stdlib.h>
#include <stdio.h>
int main(void){
&&&&printf("Hi,OpenWRT!\n");
&&&&return 0;
src下Makefile:src下Makefile:
# build hiOpenwrt executable when user executes "make"
hiOpenwrt: hiOpenwrt.o
$(CC) $(LDFLAGS) hiOpenwrt.o -o hiOpenwrt
hiOpenwrt.o: hiOpenwrt.c
$(CC) $(CFLAGS) -c hiOpenwrt.c
#remove object files and executable when user executes "make clean"
rm *.o hiOpenwrt
当然,在hiOpenwrt/Makefile也需要写,只不过这个要求比较多,格式如下:
#-----官方文档如下
This is the OpenWrt SDK. It contains a stripped-down version of the buildroot. You can use it to test/develop packages without having to compile your own toolchain or any of the libraries included with OpenWrt.
To use it, just put your buildroot-compatible package directory in the subdir 'package/' and run 'make' from this directory.
#------ OPENWRT集成非官方包之Makefile规则
include $(TOPDIR)/rules.mk
PKG_NAME:=[软件包名字 和文件夹名称一样]
PKG_VERSION:=[软件包版本 自己写个]
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=utils
CATEGORY:=[软件包在menuconfig里的位置 比如Base system]
DEPENDS:=[依赖包 两个之间通过空格分隔 前面加+为默认显示 选中该软件包自动选中依赖包 不加+为默认不显示 选中依赖包才显示]
TITLE:=[标题]
PKGARCH:=[平台 比如ar71xx 全部写all]
MAINTAINER:=[作者]
define Package/$(PKG_NAME)/description
[软件包简介]
#非本目录下的源码文件, 拷贝到此相应目录下.
# 如../../xucommon/xucommon.c, 则将 xucommon.c 拷贝到此目录下的源码的 ../../
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
define Build/Configure
define Build/Compile
define Package/$(PKG_NAME)/conffiles
[升级时保留文件/备份时备份文件 一个文件一行]
define Package/$(PKG_NAME)/install
$(CP) ./files/* $(1)/
define Package/$(PKG_NAME)/preinst
[安装前执行的脚本 记得加上#!/bin/sh 没有就空着]
uci -q batch </dev/null
delete ucitrack.@aria2[-1]
add ucitrack aria2
set ucitrack.@aria2[-1].init=aria2
commit ucitrack
define Package/$(PKG_NAME)/postinst
[安装后执行的脚本 记得加上#!/bin/sh 没有就空着]
rm -f /tmp/luci-indexcache
Package/$(PKG_NAME)/prerm
[删除前执行的脚本 记得加上#!/bin/sh 没有就空着]
Package/$(PKG_NAME)/postrm
[删除后执行的脚本 记得加上#!/bin/sh 没有就空着]
$(eval $(call BuildPackage,$(PKG_NAME)))
自己的hiOpenwrt的Makefile自己的hiOpenwrt的Makefile
##############################################
# OpenWrtMakefile for hiOpenwrt program
# Most ofthe variables used here are defined in
# theinclude directives below. We just need to
# specifya basic description of the package,
# whereto build our program, where to find
# thesource files, and where to install the
# compiled program on the router.
# Be verycareful of spacing in this file.
# Indentsshould be tabs, not spaces, and
# thereshould be no trailing whitespace in
# linesthat are not commented.
##############################################
include $(TOPDIR)/rules.mk
# Nameand release number of this package
PKG_NAME:=hiOpenWRT
PKG_RELEASE:=1
# Thisspecifies the directory where we're going to build the program.
# Theroot build directory, $(BUILD_DIR), is by default the build_mipsel
#directory in your OpenWrt SDK directory
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
# Specifypackage information for this program.
# Thevariables defined here should be self explanatory.
# If youare running Kamikaze, delete the DESCRIPTION
#variable below and uncomment the Kamikaze define
# directivefor the description below
define Package/$(PKG_NAME)
SECTION:=utils
CATEGORY:=Utilities
TITLE:=hiOpenwrt-- prints a snarky message
# Specifywhat needs to be done to prepare for building the package.
# In ourcase, we need to copy the source files to the build directory.
# This isNOT the default.
The default uses thePKG_SOURCE_URL and the
#PKG_SOURCE which is not defined here to download the source from the web.
# Inorder to just build a simple program that we have just written, it is
# mucheasier to do it this way.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
# We donot need to define Build/Configure or Build/Compile directives
# Thedefaults are appropriate for compiling a simple program such as this one
# Specifywhere and how to install the program. Since we only have one file,
# thehelloworld executable, install it by copying it to the /bin directory on
# therouter. The $(1) variable represents the root directory on the router running
#OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
#directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
# commandto copy the binary file from its current location (in our case the build
#directory) to the install directory.
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/hiOpenwrt $(1)/bin/
# Thisline executes the necessary commands to compile our program.
# Theabove define directives specify all the information needed, but this
# linecalls BuildPackage which in turn actually uses this information to
# build apackage.
$(eval $(call BuildPackage,$(PKG_NAME)))
生成ipk的命令:
make package/hiOpenWRT/compile V=s
加上V=s的目的是为了详细打印。
生成出来的ipk文件将在bin/ar71xx/packages/下,同时,也可以在build_dir/ build_dir/下找到可执行文件以及源码。
lee@ubuntu:~/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2$ tree | head -n 20
|-- ar71xx
`-- packages
`-- hiOpenWRT_1_ar71xx.ipk
`-- packages
|-- build_dir
`-- build_dir
`-- hiOpenWRT
|-- hiOpenwrt
|-- hiOpenwrt.c
|-- hiOpenwrt.o
|-- ipkg-ar71xx
`-- hiOpenWRT
`-- hiOpenwrt
`-- CONTROL
`-- control
`-- Makefile
|-- Config.in
一点总结:
&&&&目录结构很重要,如果目录结构不正确,那么Openwrt是不可能正确编译出ipk的。
&&&&在学习编译过程中出现了很多处错误,最让我头疼的是Makefile的格式,这部分很容易错误而编译失败。
Makefile编写规则:
target ... : prerequisites ...
target也就是一个目标文件,可以是Object File,也可以是执行文件。还可以是一个标签
(Label),对于标签这种特性,在后续的“伪目标”章节中会有叙述。
prerequisites就是,要生成那个target所需要的文件或是目标。
command也就是make需要执行的命令。(任意的Shell命令)
这是一个文件的依赖关系,也就是说,target这一个或多个的目标文件依赖于prerequisi
tes中的文件,其生成规则定义在command中。说白一点就是说,prerequisites中如果有一个以上的文件比target文件要新的话,command所定义的命令就会被执行。这就是 Makefile的规则。也就是Makefile中最核心的内容。
阅读(767) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。1218人阅读
openwrt(83)
1.查看Flash容量大小(存储空间,可以理解为电脑的硬盘)
root@OpenWrt:/# dmesg |grep spi |grep Kbytes& #查看Flash容量
[&&& 0.660000] m25p80 spi0.0: mx25l12805d (16384 Kbytes)
#=16M 既是16M的Flash
2.查看RAM容量大小(可以理解为电脑的内存条)
root@OpenWrt:/# cat /proc/meminfo |grep MemTotal&& #查看RAM大小
MemTotal:&&&&&&&&& 61348 kB
root@OpenWrt:/# free -h |grep Mem | awk -F ' ' '{print $2}'& #查看RAM大小 (单位kB)
root@OpenWrt:/# free -h |grep Mem | awk -F ' ' '{print $3}' #已使用的RAM大小(单位kB)
root@OpenWrt:/# free -h |grep Mem | awk -F ' ' '{print $4}' #空闲可用的RAM大小(单位kB)
3.CPU内存主频型号信
root@OpenWrt:/# dmesg |grep Clocks |awk -F ' ' '{print $4}'& #查看CPU主频
CPU:650.000MHz,
root@OpenWrt:/# dmesg |grep Clocks |awk -F ',' '{print $2}' #查看内存主频
DDR:421.997MHz
root@OpenWrt:/# cat /proc/cpuinfo |grep 'system type'& #查看系统类型
system type&&&&&&&&&&&& : Qualcomm Atheros QCA9533 rev 1
root@OpenWrt:/# cat /proc/cpuinfo |grep 'cpu model'& #查看CPU型号
cpu model&&&&&&&&&&&&&& : MIPS 24Kc V7.4
root@OpenWrt:/# cat /proc/cpuinfo |grep 'machine'&& #查看设备型号
machine&&&&&&&&&&&&&&&& : TP-LINK TL-WR841N/ND v9
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:27239次
积分:1259
积分:1259
排名:千里之外
原创:83篇
转载:130篇
(2)(6)(6)(14)(5)(18)(18)(30)(9)(1)(16)(7)(30)(52)【智能路由器】openwrt如何创建用户软件包
openwrt根目录
先看看openwrt初次编译好后的目录结构:
如上图所示:
arvik_note:本人更改软件包记录笔记,不必理会。
include:存放 *.mk 文件
build_dir:建立工具链时的临时目录,解压、编译、补丁等文件存放点
staging_dir:工具链的安装位置
target:平台相关代码及配置文件
dl:下载目录,编译期间从网上下载的数据包都会放在此目录,数据包会解压到build_dir目录下
package:包含了我们在配置文件里设定懂得所有编译好的软件包
feeds:执行.喎"/kf/ware/vc/" target="_blank" class="keylink">vc3JjaXB0cy9mZWVkcyBpbnN0YWxsuvO1xLu6tObOxLz+tOa3xbXjPGJyIC8+DQpiaW6jurbU06bGvcyoseDS67rDtcS2/r341sbOxLz+0tS8sM/gudhpcGvOxLz+PC9wPg0KPGhyIC8+DQo8aDEgaWQ9"创建软件包">创建软件包
&&&&&&&&&&&&&&&&&&&&&以下内容摘自官方WIKI &&&&&&&&&&&&&&&&&&&&&
openwrt靠Makefile文件来添加软件,Makefile文件最关键,一般来说它提供了下载、编译、安装这个软件包的步骤。
这里Makefile的格式跟一般的Makefile不一样,因为它的功能跟普通Makefile就是不一样的。它是一种编写方便的模板。
以package/bridge/Makefile文件为例:
include $(TOPDIR)/rules.mk
PKG_NAME:=bridge
PKG_VERSION:=1.0.6
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/bridge-utils-$(PKG_VERSION)
PKG_SOURCE:=bridge-utils-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/bridge
PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd
PKG_CAT:=zcat
include $(INCLUDE_DIR)/package.mk
define Package/bridge
SECTION:=base
CATEGORY:=Network
TITLE:=Ethernet bridging configuration utility
#DESCRIPTION:=This variable is obsolete. use the Package/name/description define instead!
URL:=http://bridge.sourceforge.net/
define Package/bridge/description
Ethernet bridging configuration utility
Mana a way to connect networks together to
form a larger network.
define Build/Configure
$(call Build/Configure/Default,--with-linux-headers=$(LINUX_DIR))
define Package/bridge/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/brctl/brctl $(1)/usr/sbin/
$(eval $(call BuildPackage,bridge))
软件包变量
建立一个软件包不需要太多工作;大部分工作都隐藏在其它的 makefiles 中,编写工作被抽象成对几个变量的赋值。
PKG_NAME -软件包的名字, 在 menuconfig 和 ipkg 显示
PKG_VERSION -软件包的版本,主干分支的版本正是我们要下载的
PKG_RELEASE -这个 makefile 的版本
PKG_BUILD_DIR -编译软件包的目录
PKG_SOURCE -要下载的软件包的名字,一般是由 PKG_NAME 和 PKG_VERSION 组成
PKG_SOURCE_URL -下载这个软件包的链接
PKG_MD5SUM -软件包的 MD5 值
PKG_CAT -解压软件包的方法 (zcat, bzcat, unzip)
PKG_BUILD_DEPENDS -需要预先构建的软件包,但只是在构建本软件包时,而不是运行的时候。它的语法和下面的DEPENDS一样。
PKG_*变量定义了从何处下载这个软件包;@SF是表示从sourceforge网站下载的一个特殊关键字。md5sum用来检查从网上下载的软件包是否完好无损。PKG_BUILD_DIR定义了软件包源代码的解压路径。
注意到上面示例文件底部的最后一行吗?这是最为关键的BuildPackage宏。它是在$(INCLUDE_DIR)/package.mk文件里定义的。BuildPackage宏只要求一个参数,即要编译的软件包名,在本例中是&bridge&。所有其他信息都通过宏来获得,这提供了一种内在的简洁性。比如BuildPackage需要软件包的一大串描述信息,我们并不要向它传递冗长的参数,因为我们已经约定描述信息定义在DESCRIPTION宏,BuildPackage从里面读取就可以了。
BuildPackage相关的宏
描述软件包在menuconfig和ipkg中的信息,可以定义如下变量:
SECTION - 软件包类型 (尚未使用)
CATEGORY - menuconfig中软件包所属的一级目录,如Network
SUBMENU - menuconfig中软件包所属的二级目录,如dial-in/up
TITLE - 软件包标题
DESCRIPTION - 软件包的详细说明
URL - 软件的原始位置,一般是软件作者的主页
MAINTAINER - (optional) 软件包维护人员
DEPENDS - (optional) 依赖项,运行本软件依赖的其他包
Package/conffiles (可选)
软件包需要复制的配置文件列表,一个文件占一行
Build/Prepare (可选)
一组解包源代码和打补丁的命令,一般不需要。
Build/Configure (可选)
如果源代码编译前需要configure且指定一些参数,就把这些参数放在这儿。否则可以不定义。
Build/Compile (可选)
编译源代码命令。
Package/install
软件安装命令,主要是把相关文件拷贝到指定目录,如配置文件。
Package/preinst
软件安装之前被执行的脚本,别忘了在第一句加上#!/bin/sh。如果脚本执行完毕要取消安装过程,直接让它返回false即可。
Package/postinst
软件安装之后被执行的脚本,别忘了在第一句加上#!/bin/sh。
Package/prerm
软件删除之前被执行的脚本,别忘了在第一句加上#!/bin/sh。如果脚本执行完毕要取消删除过程,直接让它返回false即可。
Package/postrm
软件删除之后被执行的脚本,别忘了在第一句加上#!/bin/sh。
为什么一些定义是&Package/&前缀,另一些定义却是&Build&前缀?这是因为我们支持一个特性:从单个源代码构建多个软件包。OpenWrt工作在一个Makefile对应一个源代码的假设之上,但是你可以把编译生成的程序分割成任意多个软件包。因为编译只要一次,所以使用全局的&Build&定义是最合适的。然后你可以增加很多&Package/&定义,为各软件包分别指定安装方法。建议你去看看dropbear包,这是一个很好的示范。
对于所有在pre/post, install/removal脚本中使用的变量,都应该使用&$$&代替&$&。这是告诉make暂时不要解析这个变量,而是把它当成普通字符串以及用&$&代替&$$&。
在编辑好Makefile文件,并放到指定目录后,这个新的软件包将在下次执行make menuconfig时出现,你可以选择这个软件包,保存退出,用make编译。现在就把一个软件成功移植到OpenWrt中了!
&&&&&&&&&&&&&&&&&&&&&&&&&&&以上内容摘自官方WIKI &&&&&&&&&&&&&&&&&&&&&&&&&&&
创建软件包arvik_hello
按照如下命令步骤:
先建一个软件集合的目录arvik_app
cd ./packet
mkdir arvik_app
在arvik_app目录下建立arvik_hello目录
cd ./arvik_app
mkdir arvik_hello
接着在arvik_hello中建立src目录和Makefile文件
cd ./arvik_hello
touch Makefile
该处Makefile文件内容如下,可参照上面软件包变量读懂每句含义,在此不赘述。需要注意的是代码里每行行末是没有空格的,否则可能会出错。 好了,openwrt就靠这个Makefile来添加我们的arvik_hello软件包了。
#########################################
#author:arvik
#csdn:http://blog.csdn.net/u
#########################################
include $(TOPDIR)/rules.mk
ARVIK_APP_DIR:=arvik_app
PKG_NAME:=arvik_hello
PKG_VERSION:=1.0.0
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(ARVIK_APP_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=Utilities
CATEGORY:=Arvik_Applications
TITLE:=a Test Program offer by arvik
MAINTAINER:=arvik
define Package/$(PKG_NAME)/description
This is a test program that provides a MAkefile template !
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
define Build/Configure
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/
$(eval $(call BuildPackage,$(PKG_NAME)))
下面就进入src目录来建立我们软件源文件和Makefile文件了。
touch hello.c
touch Makefile
hello.c内容如下:
int main()
printf(&arvik hello world!\n&);
此处Makefile文件内容如下:
#########################################
#author:arvik
#csdn:http://blog.csdn.net/u
#########################################
EXEC:=arvik_hello
SRC:=hello.c
all: $(EXEC)
$(EXEC): $(SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC) $(LDLIBS)
.PHONY:clean
-rm -f $(EXEC) *.elf *.gdb *.o
检验软件包
make menuconfig
退回openwrt根目录,执行make menuconfig,找到Arvik_Applications选项,进入
再选择arvik_hello
重新编译一次即可(或者单独只编译一次arvik_hello即可,命令 make package/arvik_app/arvik_hello/compile V=99)。
运行arvik_hello
root@OpenWrt:/# arvik_hello
arvik hello world!

我要回帖

更多关于 锂电池概念股投资机会 的文章

 

随机推荐