From 11b309932d4edf2d257c4e39281d31130d93f278 Mon Sep 17 00:00:00 2001 From: Viktor <35473052+viktorxda@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:55:22 +0100 Subject: [PATCH] Add builder firmware repack script --- .gitignore | 8 +++++--- README.md | 8 ++++++-- repack.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100755 repack.sh diff --git a/.gitignore b/.gitignore index de8d4c8..3378aff 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ # https://www.atlassian.com/git/tutorials/saving-changes/gitignore # Assembly folders -/archive/ -/cache/ -/openipc/ +archive +cache +openipc +output +*.bin diff --git a/README.md b/README.md index 22ff6f7..9558fc6 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,6 @@ The file names contain variables with option names - **flavor, model, processor, - vendor - the name of the official equipment manufacturer; if there are several of them, a [description](https://github.com/OpenIPC/builder/tree/master#compatibility-and-clones) is created - version - usually this is an addition to the model, version or revision of hardware differences - ### Preparing and using the project ``` @@ -119,6 +118,12 @@ cd builder ./builder.sh ``` +### Create firmware with built-in credentials +- Usage: `repack.sh [uboot] [firmware] [ssid] [pass]` +``` +sh repack.sh ssc337de ssc337de_ultimate_foscam-x5-nor router password +``` + ### Existing problems - On some devices NOR flash 8M is small, and the WiFi driver is very large and the QR scanner currently does not fit into the firmware @@ -128,5 +133,4 @@ cd builder Please **_[support our project](https://openipc.org/support-open-source)_** with donations or orders for development or maintenance. Thank you! - [logo]: https://openipc.org/assets/openipc-logo-black.svg diff --git a/repack.sh b/repack.sh new file mode 100755 index 0000000..d9b7c4d --- /dev/null +++ b/repack.sh @@ -0,0 +1,50 @@ +#!/bin/sh +openipc=https://github.com/openipc/firmware/releases/download/latest +builder=https://github.com/openipc/builder/releases/download/latest + +if [ -z "$(dpkg -l | grep squashfs-tools)" ]; then + echo Install the following package: + echo sudo apt-get install squashfs-tools + exit 0 +fi + +if [ -z "$1" ]; then + echo "Usage: $0 [uboot] [firmware] [ssid] [pass]" + exit 0 +fi + +uboot=u-boot-$1-nor.bin +chipset=$(echo $2 | cut -d_ -f1) +release=openipc-$1-nor.bin + +mkdir -p output +if ! wget -q --show-progress $openipc/$uboot -O output/uboot.bin; then + echo "Download failed: $openipc/$uboot" + exit 1 +fi + +if ! wget -q --show-progress $builder/$2.tgz -O output/builder.tgz; then + echo "Download failed: $builder/$2.tgz" + exit 1 +fi + +tar -xf output/builder.tgz -C output +if [ -n "$3" ] && [ -n "$4" ]; then + file=output/squashfs/usr/share/openipc/wireless.sh + unsquashfs -d output/squashfs output/rootfs.squashfs.$chipset > /dev/null + echo "#!/bin/sh" >> $file + echo "fw_setenv wlanssid $3" >> $file + echo "fw_setenv wlanpass $4" >> $file + chmod 755 $file + mksquashfs output/squashfs output/rootfs.$chipset -comp xz > /dev/null +else + mv output/rootfs.squashfs.$chipset output/rootfs.$chipset +fi + +dd if=/dev/zero bs=1K count=5000 status=none | tr '\000' '\377' > $release +dd if=output/uboot.bin of=$release bs=1K seek=0 conv=notrunc status=none +dd if=output/uImage.$chipset of=$release bs=1K seek=320 conv=notrunc status=none +dd if=output/rootfs.$chipset of=$release bs=1K seek=2368 conv=notrunc status=none +rm -rf output + +echo "Created: $release"