http://aboutchen.org/blog/compile-c-code-for-openwrt/
官方参考: https://dev.openwrt.org/wiki/GetSource
OpenWrt source repository downloads
You can either check out the OpenWrt source code via git or svn.
GIT
The recommended way of checking out the OpenWrt source code is cloning the Git repository using one of the following commands:
trunk (main development tree)
- Main repository
git clone git://git.openwrt.org/openwrt.git
14.07 branch (Barrier Breaker)
- Main repository
git clone git://git.openwrt.org/14.07/openwrt.git
12.09 branch (Attitude Adjustment)
- Main repository
git clone git://git.openwrt.org/12.09/openwrt.git
- Packages feed
git clone git://git.openwrt.org/12.09/packages.git
SVN
You can checkout the source from the OpenWrt Subversion repository using one of the following commands:
- Development branch: ChangeLog
svn co svn://svn.openwrt.org/openwrt/trunk/
- Barrier Breaker 14.07 branch: ChangeLog
svn co svn://svn.openwrt.org/openwrt/branches/barrier_breaker
- Attitude Adjustment 12.09 branch: ChangeLog
svn co svn://svn.openwrt.org/openwrt/branches/attitude_adjustment
- Backfire 10.03 branch: ChangeLog
svn co svn://svn.openwrt.org/openwrt/branches/backfire
- Kamikaze 8.09 branch: ChangeLog
svn co svn://svn.openwrt.org/openwrt/branches/8.09
- Kamikaze 7.09 branch: ChangeLog
svn co svn://svn.openwrt.org/openwrt/tags/kamikaze_7.09
#稳定分支版本 attitude_adjustment/12.09, 内核3.3.8, org.cn有镜像. 若在windows的共享目录下操作有N种意想不到的错误, 以下操作都在~目录
mkdir openwrt
cd openwrt
git clone git://git.openwrt.org/12.09/openwrt.git
svn co svn://svn.openwrt.org.cn/openwrt/branches/attitude_adjustment
cd attitude_adjustment
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig: 界面中选择如下
<*> lsusb
Editor:
<*> diff
Filesystem: kmod-fs-vfat, kmod-fs-ntfs, kmod-fs-ext4
SPI Support: 选中 kmod-spi-gpio
Sound Support: 选中kmod-sound-core, kmod-usb-audio
wireless support: kmod-rtl8187, 后面带USB的全选
make defconfig
make clean
rm -rf ./tmp #如果以前编译过一次,删除./tmp目录及该目录下的所有文件
#此时可以把备份的同版本的dl目录拷贝到本目录下的dl目录下, 可以大大加快编译的速度
xxg@xxg-desktop:~/openwrt/r31296/trunk$ make -j 2
#2014-11-18重新编译AA版本, make 不带-j的参数, 以避免发生意想不到的错误.
xxg@EmbeddedLab:~/openwrt/attitude_adjustment$ make clean
make[1] clean
make[2] target/linux/clean
make[3] -C target/linux clean
xxg@EmbeddedLab:~/openwrt/attitude_adjustment$ make
make[1] world
make[2] target/compile
make[3] -C target/linux compile
make[2] package/cleanup
make[2] package/compile
make[3] -C package/toolchain compile
make[3] -C package/libnl-tiny compile
make[3] -C package/libjson-c compile
make[3] -C package/lua compile
make[3] -C package/libubox compile
make[3] -C package/ubus compile
make[3] -C package/uci compile
make[3] -C package/netifd compile
make[3] -C package/opkg host-compile
make[3] -C package/base-files compile
make[3] -C package/ncurses compile
make[3] -C package/util-linux compile
make[3] -C package/block-mount compile
make[3] -C package/busybox compile
make[3] -C package/dnsmasq compile
make[3] -C package/dropbear compile
make[3] -C feeds/luci/freifunk-common compile
make[3] -C feeds/luci/community-profiles compile
make[3] -C feeds/routing/olsrd compile
make[3] -C package/iptables compile
make[3] -C package/firewall compile
make[3] -C package/iproute2 compile
make[3] -C feeds/luci/freifunk-gwcheck compile
make[3] -C feeds/luci/freifunk-mapupdate compile
make[3] -C package/iwinfo compile
make[3] -C package/lua host-compile
make[3] -C package/px5g compile
make[3] -C package/uhttpd compile
make[3] -C feeds/luci/luci compile
make[3] -C package/libtool compile
make[3] -C feeds/packages/libs/jpeg compile
make[3] -C package/uclibc++ compile
make[3] -C feeds/packages/libs/libusb compile
make[3] -C feeds/packages/multimedia/mjpg-streamer compile
make[3] -C package/fuse compile
make[3] -C package/librpc compile
make[3] -C feeds/packages/utils/owfs compile
make[3] -C package/gpio-button-hotplug compile
make[3] -C package/hostapd compile
make[3] -C package/hotplug2 compile
make[3] -C package/iw compile
make[3] -C package/kernel compile
make[3] -C package/mac80211 compile
make[3] -C package/mtd compile
make[3] -C package/opkg compile
make[3] -C package/libpcap compile
make[3] -C package/linux-atm compile
make[3] -C package/resolveip compile
make[3] -C package/ppp compile
make[3] -C package/swconfig compile
make[3] -C package/uboot-ar71xx compile
make[3] -C package/zlib compile
make[3] -C package/uboot-envtools compile
make[3] -C package/w1-gpio-custom compile
make[2] package/install
make[3] -C package/busybox install
make[3] -C package/dnsmasq install
make[3] -C package/dropbear install
make[3] -C package/firewall install
make[3] -C package/gpio-button-hotplug install
make[3] -C package/hostapd install
make[3] -C package/hotplug2 install
make[3] -C package/iptables install
make[3] -C package/iw install
make[3] -C package/kernel install
make[3] -C package/libjson-c install
make[3] -C package/libnl-tiny install
make[3] -C package/libubox install
make[3] -C package/mac80211 install
make[3] -C package/mtd install
make[3] -C package/netifd install
make[3] -C package/opkg install
make[3] -C package/ppp install
make[3] -C package/swconfig install
make[3] -C package/toolchain install
make[3] -C package/uboot-ar71xx install
make[3] -C package/uboot-envtools install
make[3] -C package/ubus install
make[3] -C package/uci install
make[3] -C package/base-files install
make[2] package/rootfs-prepare
make[3] package/preconfig
make[2] target/install
make[3] -C target/linux install
make[3] -C target/imagebuilder install
make[3] -C target/toolchain install
make[2] package/index
xxg@EmbeddedLab:~/openwrt/attitude_adjustment$
make image PROFILE=TLWR703 PACKAGES="block-mount librt libpthread luci luci-i18n-chinese luci-app-ddns luci-proto-3g luci-app-hd-idle luci-app-p910nd luci-app-qos luci-app-samba luci-app-upnp luci-app-wol openvpn openvpn-easy-rsa kmod-scsi-core kmod-scsi-generic kmod-fs-ext4 kmod-fs-ntfs kmod-fs-vfat kmod-nls-utf8 kmod-usb-storage-extras kmod-usb-ohci kmod-usb-storage kmod-usb-uhci kmod-usb-acm kmod-usb-serial kmod-usb-serial-ftdi kmod-usb-serial-pl2303 kmod-video-core kmod-video-uvc kmod-video-gspca-core kmod-video-gspca-zc3xx mjpg-streamer ser2net badblocks restorefactory coreutils transmission-daemon transmission-remote transmission-web vsftpd" FILES=wr703n
http://cadenwu.blog.chinaunix.net/uid-27194309-id-3408165.html
======================
注: dd下用 linux,openwrt下用 firmware
#--- mtd 源码中的相关部分:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
static
void
usage(
void
)
{
fprintf
(stderr,
"Usage: mtd [<options> ...] <command> [<arguments> ...] <device>[:<device>...]\n\n"
"The device is in the format of mtdX (eg: mtd4) or its label.\n"
"mtd recognizes these commands:\n"
" unlock unlock the device\n"
" refresh refresh mtd partition\n"
" erase erase all data on device\n"
" write <imagefile>|- write <imagefile> (use - for stdin) to device\n"
" jffs2write <file> append <file> to the jffs2 partition on the device\n"
);
if
(mtd_fixtrx) {
fprintf
(stderr,
" fixtrx fix the checksum in a trx header on first boot\n"
);
}
fprintf
(stderr,
"Following options are available:\n"
" -q quiet mode (once: no [w] on writing,\n"
" twice: no status messages)\n"
" -n write without first erasing the blocks\n"
" -r reboot after successful command\n"
" -f force write without trx checks\n"
" -e <device> erase <device> before executing the command\n"
" -d <name> directory for jffs2write, defaults to \"tmp\"\n"
" -j <name> integrate <file> into jffs2 data when writing an image\n"
);
if
(mtd_fixtrx) {
fprintf
(stderr,
" -o offset offset of the image header in the partition(for fixtrx)\n"
);
}
fprintf
(stderr,
#ifdef FIS_SUPPORT
" -F <part>[:<size>[:<entrypoint>]][,<part>...]\n"
" alter the fis partition table to create new partitions replacing\n"
" the partitions provided as argument to the write command\n"
" (only valid together with the write command)\n"
#endif
"\n"
"Example: To write linux.trx to mtd4 labeled as linux and reboot afterwards\n"
" mtd -r write linux.trx linux\n\n"
);
exit
(1);
}
|
1
|
|
Opkg 是一个轻量快速的套件管理系统,目前已成为 Opensource 界嵌入式系统标准。
常用于路由、交换机等嵌入式设备中,用来管理软件包的安装升级与下载。常用命令如下:opkg update 更新可以获取的软件包列表
opkg upgrade 对已经安装的软件包升级
opkg install 安装指定的软件包
opkg instal /tmp/xxx.ipk
opkg install http://openwrt.8800.org:82/nwan.ipk
opkg install http://openwrt.8800.org/luci-app-nwan.ipk
opkg install --force-reinstall http://192.168.1.224/uhttpd_32_ar71xx.ipk
opkg remove 卸载已经安装的指定的软件包. opkg remove luci-i18n-chinese
opkg list
opkg list-installed
Force Options:
--force-depends Install/remove despite failed dependencies
--force-maintainer Overwrite preexisting config files
--force-reinstall Reinstall package(s)
--force-overwrite Overwrite files from other package(s)
--force-downgrade Allow opkg to downgrade packages
--force-space Disable free space checks
--force-postinstall Run postinstall scripts even in offline mode
--force-remove Remove package even if prerm script fails
--noaction No action -- test only
--download-only No action -- download only
--nodeps Do not follow dependencies
--force-removal-of-dependent-packages
Remove package and all dependencies
--autoremove Remove packages that were installed
automatically to satisfy dependencies
-t Specify tmp-dir.
--tmp-dir Specify tmp-dir.
一般我们在openwrt下用opkg安装软件有两种:
1. 连上网络后从官方网站安装 opkg update; opkg install XXX.ipk;
opkg install http://openwrt.8800.org/luci-app-nwan.ipk
2. PC上把软件下载下来,传到路由器tmp目录安装 opkg install /tmp/XXX.ipk
对于1来说,如果路由暂时上不了网,就无法使用,方法2又有些麻烦. 这里提供的方法是:
1. 修改/etc/opkg.conf, 把里边第一行那个网址改成本地服务器放安装包的服务目录,
#src/gz snapshots http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages
src/gz snapshots http://192.168.1.224/packages-r31296
2. 把相关的 packages 目录下的文件都放在上步定义的目录下(packages-r31296为目录名)
3. 在本机上用 HTS 开启http服务, 添加上面的目录
4. 现在可以像方法1一样使用升级了
工作图片如下: