如果只内置luci-proto-wireguard,会出现cannot find dependency kmod-crypto-kpp for kmod-crypto-lib-curve25519错误,需要把kmod-crypto-kpp模块也内置
这个编译错误还是个老问题,参考这里:
https://forum.openwrt.org/t/build-fails-with-multiple-errors/124382
Views: 2
openwrt升级后原来安装的软件包就没有了,用这条命令可以重新安装所有丢失的软件包(前提是升级前对软件列表进行了备份)
opkg update && opkg list-installed | cut -f 1 -d ' '| sort -u > /tmp/currentpkg && cat /etc/backup/installed_packages.txt | cut -f 1 | sort -u > /tmp/oldpkg && grep -v -F -x -f /tmp/currentpkg /tmp/oldpkg > /tmp/inst && opkg install $(cat /tmp/inst | sort -u) && rm /tmp/currentpkg /tmp/oldpkg /tmp/inst
Views: 1
Views: 6
下载openwrt代码
git clone https://gitea.hetao.me/openwrt/openwrt
cd openwrt
curl https://downloads.openwrt.org/snapshots/targets/mediatek/filogic/config.buildinfo --output .config
curl https://downloads.openwrt.org/snapshots/targets/mediatek/filogic/feeds.buildinfo --output feeds.conf
config.buildinfo配置中已经包含了
CONFIG_ALL=y
CONFIG_ALL_KMODS=y
CONFIG_ALL_NONSHARED=y
对feeds.config中的域名替换为gitea.hetao.me,替换后如下
src-git packages https://gitea.hetao.me/feed/packages.git
src-git luci https://gitea.hetao.me/project/luci.git
src-git routing https://gitea.hetao.me/feed/routing.git
src-git telephony https://gitea.hetao.me/feed/telephony.git
./scripts/feeds update -a
./scripts/feeds install -a
对编译配置进行自定义修改,主要是编译目标板子改为bpi r3,集成luci和中文,开启ccache,修改opkg源和固件版本号,这是我用的配置
http://openwrt.hetao.me/snapshots/targets/mediatek/filogic/config.buildinfo
make menuconfig
sed -i '/is not set/d' .config
make defconfig
IGNORE_ERRORS=1 make -j 70
把编译后的镜像和ipk包复制到web服务器
rsync -avP bin/* root@openwrt.hetao.me:/opt/web/data/nginx/www/openwrt/snapshots/
这样就可以通过 https://openwrt.hetao.me/snapshots/ 访问openwrt源了
Views: 14
export PIP_INDEX_URL=https://mirrors.hetao.me/pypi/simple
export npm_config_registry=https://mirrors.hetao.me/npm-registry
export RUSTUP_DIST_SERVER=https://mirror.sjtu.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirror.sjtu.edu.cn/rust-static/rustup
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
export CARGO_REGISTRIES_MIRROR_INDEX=sparse+https://mirrors.sjtug.sjtu.edu.cn/crates.io-index/
export CARGO_REGISTRY_DEFAULT="mirror"
echo registry=https://mirrors.hetao.me/npm-registry > HOME/.npmrc
mkdir -pHOME/.config/pip
cat << EOF > HOME/.config/pip/pip.conf
[global]
index-url = https://mirrors.hetao.me/pypi/simple
format = columns
EOF
mkdir -vpHOME/.cargo
cat << EOF > HOME/.cargo/env
RUSTUP_DIST_SERVER=https://mirror.sjtu.edu.cn/rust-static
RUSTUP_UPDATE_ROOT=https://mirror.sjtu.edu.cn/rust-static/rustup
EOF
cat << EOF>HOME/.cargo/config
[source]
[source.mirror]
registry = "sparse+https://mirrors.sjtug.sjtu.edu.cn/crates.io-index/"
[source.crates-io]
replace-with = "mirror"
EOF
export http_proxy=http://192.168.33.6:3128
export https_proxy=http://192.168.33.6:3128
export no_proxy=127.0.0.1,172.16.0.0/12,192.168.0.0/16,.cn,.hetao.me,localhost,local,.local
Views: 2
iw dev wlan0 scan #扫描wif列表
iw dev wlan0 connect openwrt #连接到openwrt
dhclient wlan0 #分配IP地址
iw dev wlan0 disconnect #断开连接
iw仅支持wep密码,但是wep已经没有路由器支持了,所以iw只能用于无密码的wifi连接
– wpa_supplicant
apt install wpasupplicant
wpa_passphrase myssid my_very_secret_passphrase > /etc/wpa_supplicant/wpa_supplicant.conf
#在/etc/network/interfaces中添加如下内容
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid myssid
wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b
其中wpa-psk与wpa_supplicant.conf中的一致
systemctl enable wpa_supplicant
systemctl restart wpa_supplicant
ifup wlan0
iw dev wlan0 link #查看连接状态
参考:
https://wireless.wiki.kernel.org/en/users/documentation/iw
https://wiki.debian.org/WiFi/HowToUse
https://w1.fi/wpa_supplicant/
Views: 4
mk_image.sh -p mt7986a -d spim-nand -b openwrt-mediatek-filogic-bananapi_bpi-r3-snand-preloader.bin -f openwrt-mediatek-filogic-bananapi_bpi-r3-snand-bl31-uboot.fip -k openwrt-mediatek-mt7986-BPI-R3-NAND-WAN1-RJ45-squashfs-factory.bin -o -c nand.yaml r3.img
u-boot可以用自己编译的(参考:https://blog.hetao.me/2024/07/02/mtk-7986-7988%e6%9d%bf%e5%ad%90%e5%90%af%e5%8a%a8%e8%bf%87%e7%a8%8b%e5%8f%8au-boot%e7%bc%96%e8%af%91/),也可以从openwrt上下载(https://downloads.openwrt.org/snapshots/targets/mediatek/filogic/)
mk_image.sh内容
这个脚本是搬运的
#!/bin/bash
# Copyright (C) 2021-2022 SkyLake Huang
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Use this script to compose single image.
# Author: SkyLake Huang
# Email: skylake.huang@mediatek.com
#global variables:
bl2_start_dec=0
bl2_start_hex=0x0
rf_start_dec=0
rf_start_hex=0x0
fip_start_dec=0
fip_start_hex=0x0
kernel_start_dec=0
kernel_start_hex=0x0
rootfs_start_dec=0
rootfs_start_hex=0x0
rootfs_image=""
# Regular Colors
RED='\033[0;31m'
NC='\033[0m'
usage() {
printf 'Usage:\n'\
' ./mk_image -p <platform>\n'\
' -d <flash device type>\n'\
' -c <partition config>\n'\
' -b <BL2 image>, default=bl2.img\n'\
' -r <RF image>\n'\
' -f <FIP image>, default=fip.bin\n'\
' -k <kernel image>\n'\
' -g <GPT table>\n'\
' -h <usage menu>\n'\
' -o <single image name>\n'\
' example:\n'\
' ./mk_image.sh -p mt7986a -d emmc \\\n'\
' -g GPT_EMMC-iap-20220125 \\\n'\
' -f fip-iap-emmc-20220125.bin \\\n'\
' -k OF_openwrt-mediatek-mt7986-mt7986a-ax6000-emmc-rfb-squashfs-sysupgrade.bin\n'\
' ./mk_image.sh -p mt7986a -d spim-nand \\\n'\
' -b bl2-iap-snand-20220114.img \\\n'\
' -f fip-snand-20220114.bin \\\n'\
' -k OF_openwrt-mediatek-mt7986-mt7986a-ax6000-spim-nand-rfb-squashfs-factory.bin \\\n'
exit
}
parse_yaml() {
local prefix=2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=(echo @|tr @ '\034')
sed -ne "s|^\(s\):|\1|" \
-e "s|^\(s\)\(w\)s:s[\"']\(.*\)[\"']s\|\1fs\2fs\3|p" \
-e "s|^\(s\)\(w\)s:s\(.*\)s\|\1fs\2fs\3|p"1 |
awk -Ffs '{
indent = length(1)/2;
vname[indent] = 2;
for (i in vname) {if (i>indent) {delete vname[i]}}
if (length(3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s=%s\n", 2,3);
}
}'
}
load_partition() {
IFS='\r\n'
for line in `parse_yamlpartition_config`; do
IFS='=' read -ra arr <<< "line"
case "{arr[0]}" in
bl2_start )
bl2_start_hex={arr[1]}
bl2_start_dec=`printf '%d'bl2_start_hex`
;;
rf_start )
rf_start_hex={arr[1]}
rf_start_dec=`printf '%d'rf_start_hex`
;;
fip_start )
fip_start_hex={arr[1]}
fip_start_dec=`printf '%d'fip_start_hex`
;;
kernel_start )
kernel_start_hex={arr[1]}
kernel_start_dec=`printf '%d'kernel_start_hex`
;;
rootfs_start )
rootfs_start_hex={arr[1]}
rootfs_start_dec=`printf '%d'rootfs_start_hex`
esac
done
}
prepare_image() {
# Pad empty bytes to single image first
if [[ -z kernel_image ]]
then
if [[flash_type == "emmc" ]] || [[ flash_type == "sd" ]]
then
dd if=/dev/zero ibs=fip_start_dec count=1 status=none \
> single_image
else
dd if=/dev/zero ibs=fip_start_dec count=1 status=none \
| tr "\000" "\377" > single_image
fi
else
if [[flash_type == "emmc" ]] || [[ flash_type == "sd" ]]
then
dd if=/dev/zero ibs=kernel_start_dec count=1 status=none \
> single_image 2>&1
else
dd if=/dev/zero ibs=kernel_start_dec count=1 status=none \
| tr "\000" "\377" > single_image 2>&1
fi
fi
}
extract_sdmmc_kernel() {
output=`tar -xvfkernel_image | awk {'print 1'}`
IFS='\n' read -d "\034" -r -a output_arr <<< "output"
#For debugging
#echo "There are{#output_arr[*]}" next lines in the output.
for filename in "{output_arr[@]}";
do
if [[ "filename" == *"kernel" ]]
then
kernel_image=filename
elif [[ "filename" == *"root" ]]
then
rootfs_image=filename
fi
done
}
start_wrapping() {
printf "[Start wrapping %s single image......]\n"flash_type
if [[ flash_type != "emmc" ]]
then
printf "[wrapping BL2 image......]\n"
dd if=bl2_image of=single_image bs=512 \
seek=(( (bl2_start_dec/512) )) conv=notrunc status=none
fi
if [[flash_type == "emmc" ]] || [[ flash_type == "sd" ]]
then
printf "[wrapping GPT......]\n"
dd if=gpt of=single_image bs=512 seek=0 conv=notrunc status=none
fi
if [[ -nrf_image ]]
then
printf "[wrapping RF image......]\n"
dd if=rf_image of=single_image bs=512 \
seek=(( (rf_start_dec/512) )) conv=notrunc status=none
fi
printf "[wrapping FIP image......]\n"
dd if=fip_image of=single_image bs=512 \
seek=(( (fip_start_dec/512) )) conv=notrunc status=none
if [[ -n kernel_image ]]
then
printf "[wrapping kernel image......]\n"
if [[flash_type == "emmc" ]] || [[ flash_type == "sd" ]]
then
extract_sdmmc_kernel
dd if=kernel_image of=single_image bs=512 \
seek=(( (kernel_start_dec/512) )) conv=notrunc status=none
printf "[wrapping rootfs image......]\n"
dd if=rootfs_image of=single_image bs=512 \
seek=(( (rootfs_start_dec/512) )) conv=notrunc status=none
else
dd if=kernel_image of=single_image bs=512 \
seek=(( (kernel_start_dec/512) )) conv=notrunc status=none
fi
fi
}
if [# -lt 1 ]
then
usage
exit 1
fi
## We set default values for some arguments
bl2_image="bl2.img"
bl2_default=1
fip_image="fip.bin"
fip_default=1
partition_config=""
partition_config_default=1
while [ "1" != "" ]; do
case1 in
-h )
usage
;;
-p )
shift
platform=1
;;
-d )
shift
flash_type=1
;;
-c )
shift
partition_config=1
partition_config_default=0
;;
-b )
shift
bl2_image=1
bl2_default=0
;;
-f )
shift
fip_image=1
fip_default=0
;;
-k )
shift
kernel_image=1
;;
-g )
shift
gpt=1
;;
-o )
shift
single_image=1
;;
-r )
shift
rf_image=1
;;
esac
shift
done
######## Check if variables are valid ########
check_ok=1
if ! [[platform =~ ^(mt7981abd|mt7981c|mt7986a|mt7986b)]]; then
printf "{RED}Platform must be in mt7981abd|mt7981c|mt7986a|mt7986b\n{NC}"
usage
exit 1
fi
if ! [[flash_type =~ ^(snfi-nand|spim-nand|spim-nor|emmc|sd)]]; then
printf "{RED}Flash type must be in snfi-nand|spim-nand|spim-nor|emmc|sd\n{NC}"
usage
exit 1
fi
if [[partition_config_default -eq 1 ]]; then
partition_config="partitions/{flash_type}-default.yml"
fi
if [[flash_type =~ ^(emmc|sd)]] && [[ -zgpt ]]; then
printf "{RED}GPT table must be provided if flash type is emmc or sd\n{NC}"
usage
exit 1
fi
if [[ -n gpt ]] && ! [[ -fgpt ]]; then
printf "{RED}GPT table provided doesn't exist.\n{NC}"
exit 1
fi
if [[ -n rf_image ]] && ! [[ -frf_image ]]; then
printf "{RED}RF image provided doesn't exist.\n{NC}"
exit 1
fi
if [[ -n kernel_image ]] && ! [[ -fkernel_image ]]; then
printf "{RED}Kernel image provided doesn't exist.\n{NC}"
exit 1
fi
##############################################
if ! [[ -f partition_config ]]
then
if [[partition_config_default -eq 1 ]]
then
printf "{RED}Default partition config{NC}"
else
printf "{RED}Partition config provided{NC}"
fi
printf "{RED} doesn't exist: %s\n{NC}" partition_config
exit 1
fi
printf "* Partition config: %s\n"partition_config
if ! [[ -f bl2_image ]]
then
if [[bl2_default -eq 1 ]]
then
printf "{RED}Default BL2 image{NC}"
else
printf "{RED}BL2 image provided{NC}"
fi
printf "{RED} doesn't exist: %s\n{NC}" bl2_image
exit 1
fi
printf "* BL2 image name: %s\n"bl2_image
if ! [[ -f fip_image ]]
then
if [[fip_default -eq 1 ]]
then
printf "{RED}Default FIP image"
else
printf "{RED}FIP image provided"
fi
printf "{RED} doesn't exist: %s\n{NC}" fip_image
exit 1
fi
printf "* FIP image name: %s\n"fip_image
if [[ -z single_image ]]
then
single_image="platform-flash_type-(date +%Y%m%d)-single-image.bin"
printf "* Single image name: %s\n" single_image
fi
if [[check_ok == 1 ]]; then
#printf "./mk_image -p %s -d %s\n" platformflash_type
load_partition
prepare_image
start_wrapping
fi
nand镜像的分区配置文件(nand.yaml):
# Copyright (C) 2021-2022 SkyLake Huang
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# NAND flash layout:
# 0x0~0x100000: BL2, 1024K
# 0x100000~0x180000: Uboot env, 512K
# 0x180000~0x380000: RF, 2048K
# 0x380000~0x580000: FIP, 2048K
# 0x580000~ : firmware
spim-nand:
bl2_start: 0x0
rf_start: 0x180000
fip_start: 0x380000
kernel_start: 0x580000
Views: 11
系统上电后从BL1(存储在CPU内的BootRom中)开始执行,BL1会遍历所有可启动的设备(可以通过引脚改变引导顺序)
BL1启动后会对系统架构和平台进行初始化,注意BL1是在CPU内置的RAM中运行的,不使用外部DDR内存,然后BL1会从指定的存储设备上加载BL2程序(安全启动过程中也叫ATF),BL2也是在内置RAM中运行的,但BL2对DDR内存进行初始化,然后加载BL31(SRAM)和BL33(DDR内存),然后运行BL31对BL33进行初始化并把执行权限交给BL33(U-Boot本体)。
在mtk 7986板子上生成bl2,bl31,bl33镜像
https://downloads.openwrt.org/snapshots/targets/mediatek/filogic/
这里面preloader.bin 结尾的文件就是BL2,镜像格式是MediaTek BootROM Loadable Image
编译生成的bl2.bin是不能被mtk cpu识别的,需要用mkimage把bin封装为BootROM可解析的格式,即BootROM Image格式,里面有一个头部描述的bl2的基本信息。
查看BootROM镜像信息
bl31-uboot.fip 这个是BL31和BL33的合体,镜像格式是FIP(Firmware Image Package),FIP可以包含多个区段,每个区段一个镜像。查看fip的信息:
uboot编译
git clone https://github.com/frank-w/u-boot.git
git checkout 2022-10-r3
修改build.sh修改启动设备(board和device)
./build.sh importconfig
./build.sh build
git checkout r3-atf
修改build.sh中的启动设备(board和device)
./build.sh importconfig
./build.sh build
./build.sh rename
最后得到bpi-r3_spim_nand_bl2.img和bpi-r3_spim_nand_fip.bin
如果想要emmc,nor等介质的u-boot修改build.sh里在的device即可。
参考
https://www.cnblogs.com/arnoldlu/p/14175126.html
https://wiki.fw-web.de/doku.php?id=en:bpi-r3:uboot
Views: 16
squid控制缓存的主要是refresh-pattern参数,这个参数也是squid最复杂的一个参数,主要是缓存规则本身就复杂,要配置这个参数之前还需要了解一下HTTP缓存的机制。可以参考MDN上的HTTP缓存介绍。
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Caching
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cache-Control
然后首先看看refresh-pattern的语法:
usage: refresh_pattern [-i] regex min percent max [options]
官方介绍在这里:
http://www.squid-cache.org/Doc/config/refresh_pattern/
但是只看官方文档很多,很多东西还是弄不明白的。
这个refresh pattern可以翻译为新鲜度模式,这个参数配置的也就是缓存对象的新鲜度(refreshness)
regex: 配置中regex是一个正则表达式,对整 个URL进行匹配,包括前面的http或https。如果是匹配所有的URL可以用一个“.”(英文句号)表示。
-i: 是一个可选参数,表示大小写不敏感
min: 单位是分钟数,表示只要min小于缓存的Age(Age是当前请求时间减去缓存上一次更新的时间)缓存就会命中。
max: 单位是分钟数,表示只要max大于缓存的Age(Age是当前请求时间减去缓存上一次更新的时间)缓存就过期,会重新请求原始文件刷新缓存。
percent: 单位是百分比,这个参数就是LM-Factor(LM系数),对于时间落在min和max之间的请求用percent进行计算是否会命中缓存,LM系数是用来计算max-age的,max-age=( Date – Last-Modified ) * percent,其中Date缓存时间Last-Modified是原始HTTP头中的值,percent就是LM系数。如果计算出来的max-age小于缓存Age(这里的Age应该是相对于Last-Modified的,而不是在Cache中的存活时间)则命中,否者过期。或者换一种说法,LM-factor=(response age)/(resource age),如果LM-Factor小于percent配置的值则缓存命中,否则过期。
这个图展示了LM系数的计算规则,squid缓存了一个3小时前的对象,LM系统配置为50%,则对象将在1.5小时后过期。
LM系数生效的前提是HTTP响应头中有Last-Modified。
如果以上3个规则都不匹配则缓存过期。
如果没有额外的参数仅就min,max,percent这三个参数,那么只会影响没有明确缓存过期时间的请求,对于已经指定了缓存规则的请求这里的规则是不生效的。下面的一些选项可以改变HTTP请求中自带的缓存规则。
override-expire
使用min参数覆盖HTTP请求中的过期时间(Expires以及Max-Age)
override-lastmod
忽略LM系数检查,只要大于缓存Age大于min值就过期。这个参数没看到详细解释,我是这样理解的。
reload-into-ims
为no-cache请求增加If-Modified-Since
经过我的测试,如果请求头中没有Last-Modified的话会把当前时间作为If-Modified-Since时间添加到请求头中,这个选项只是在原有no-cache请求中增加一个ims字段,http服务器遇到ims字段在资源没有变更的时候会直接返回304状态码。而且reload-into-ims修改过的请求都会访问原始服务器。
ignore-reload
忽略no-cache请求
ignore-no-store
忽略no-store请求
refresh-ims
ims请求始终访问原始服务器,默认在配置refresh-pattern的情况下ims请求不会发送给原始服务器。
store-stale
即使没有refresh或缓存控制也存储到缓存中,这意味着即使永远不会命中或已经过期的对象仍然存储在缓存中(这不是画蛇添足吗,除非中途修改了refresh模式,可以利用之前存储下来的缓存)。
max-stale=NN
单位是秒,用来覆盖全局max-stale
其它相关的配置
minimum_expiry_time
最小过期时间,剩余过期时间小于这个时间的的对象不做缓存,这个主要是担心请求的过程中对象就过期了,缓存就没有意义了还浪费存储空间。默认值是60秒。
max-stale
这个配置具体是怎么用的官网没有详细介绍,google也搜不出来任何资料,经过我反复测试,这个配置指的是原始服务器挂掉以后即使缓存过期squid仍然返回内容的时间限制。如果设置为0,缓存过期后立马返回504错误。
refresh_all_ims
所有ims请求都检查原始服务器,相当于refresh-ims的全局配置
reload_into_ims
与上面的reload-into-ims选项意思相同,但这个是全局配置
光refresh-pattern这个命令我研究了一天,发现除了min percent max这三个参数外,其它可选项原理复杂但并没啥太大用处,我本来想用来缓存git仓库的,测试来看squid并不能缓存git仓库中的数据。
Views: 10