Last active
January 16, 2025 15:55
-
-
Save click0/597ebcb4bc2788beaaabbaf5a6dba84e to your computer and use it in GitHub Desktop.
Readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reboot -r для этого необязателен, а вот для чего он обязателен, у меня тоже есть тесткейс | |
то есть был | |
Фряха в виде nanobsd на 8-мегабайтном флеше с загрузчиком U-Boot, перепрошивка без консоли по сети | |
md формируется в RAM (в моём случае было 128M RAM), reboot -r, на md стартует кастомный /etc/rc, который качает по сети на md новый образ, льет его во флеш и делает полный ребут | |
Рабочий код для этого http://www.grosbein.net/freebsd/mips/upgrade/ | |
скрипт upgrade подготавливает md | |
скрипт rc.upgrade это и есть кастомный /etc/rc на md | |
https://lists.freebsd.org/pipermail/freebsd-mips/2016-February/004431.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
flashit=/bin/flashit | |
if [ -x $flashit ]; then | |
echo '' | |
echo 'REPROGRAMMING FLASH' | |
echo 'DO NOT REBOOT OR POWER OFF THE DEVICE' | |
if $flashit; then | |
echo 'FLASH REPROGRAMMING FINISHED SUCCESSFULLY' | |
else | |
echo 'FAILED' | |
sleep 3 | |
fi | |
else | |
echo "FLASH REPROGRAMMING ABORTED: $flashit not found" | |
sleep 3 | |
fi | |
echo '' | |
# quick reboot | |
kill -INT 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
PATH=/bin:/sbin:/usr/bin:/usr/sbin | |
mp="/tmp/upgrade.$$" | |
image='newimage' | |
cfg='/etc/upgrade.conf' | |
progs='/bin/dd /bin/kill /bin/sh /bin/sleep /libexec/ld-elf.so.1 /sbin/init' | |
roundup() { echo $(( (($1+256)/512+1)*512 )); } | |
load_files() { | |
local bdir f | |
for f | |
do | |
bdir=${f%/*} | |
mkdir -p $mp$bdir | |
cp -p $f $mp$bdir/ | |
done | |
} | |
# | |
# Main | |
# | |
[ -r $cfg ] && . $cfg || { echo $0: cannot read $cfg; exit 1; } | |
export FTP_USER FTP_PASSWORD HTTP_AUTH | |
echo "Verifying $url" | |
size=$(fetch -s "$url") | |
if [ -z "$size" -o "$size" = Unknown ]; then | |
echo Failed >&2 | |
exit 1 | |
fi | |
echo Size: $size bytes | |
size=$(roundup $size) | |
depends=$(ldd -f '%p\n' $progs 2>/dev/null | sort -u) | |
for f in $progs $depends | |
do | |
size=$(( $size + $(roundup `stat -f '%z' $f`) )) | |
done | |
size=$(($size*6/5)) | |
echo Allocating $(($size/1024))K for memory disk | |
if ! md=$(mdconfig -at malloc -o reserve -s ${size}b); then | |
echo Failed to allocate $size bytes >&2 | |
exit 1 | |
fi | |
md=/dev/$md | |
mkdir -p $mp; [ -d $mp ] || exit 1 | |
newfs -O1 -b 4096 -f 512 -m 0 -o space $md >/dev/null | |
mount -o async $md $mp | |
cd $mp | |
mkdir dev etc | |
load_files $progs $depends | |
cp -p /etc/rc.upgrade etc/rc | |
# silence init(8) moaning "login_getclass: unknown class" | |
cp -p /etc/login.conf.db etc | |
bsize=$(geom map list | awk '/Stripesize:/ {print $2; exit}') | |
iseek=''; off=''; skip=0; stage=1 | |
{ | |
echo '#!/bin/sh -e' | |
for part in $layout | |
do | |
size=$(sysctl kern.geom.conftxt | awk '$3=="map/'$part'" {print $4}') | |
blocks=$(($size/$bsize)) | |
[ -z "$off" ] && off=$(sysctl kern.geom.conftxt |\ | |
awk -vb=$bsize '$3=="map/'$part'" {printf "%d", $9/b}') | |
printf 'echo STAGE %s: WRITING BLOCKS %s-%s\n' \ | |
$stage $(($skip+$off)) $(($skip+$blocks+$off-1)) | |
printf 'dd if=/%s of=/dev/map/%s ibs=%s obs=%s conv=osync count=%s %s\n' \ | |
"$image" "$part" $bsize $bsize $blocks $iseek | |
skip=$(($skip+$blocks)) | |
iseek="iseek=$skip" | |
stage=$(($stage+1)) | |
done | |
} > bin/flashit | |
chmod +x bin/flashit | |
echo Downloading $url | |
fetch -vo $image $url | |
kenv vfs.root.mountfrom=ufs:$md | |
echo Closing network connections and unmounting flash... | |
reboot -r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment