|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# DreamShell IP.BIN updater |
| 4 | +# Copyright (C) 2025 SWAT |
| 5 | +# http://www.dc-swat.ru |
| 6 | +# |
| 7 | +# This script is used to update the IP.BIN file with the current version and date. |
| 8 | +# |
| 9 | + |
| 10 | +if [ $# -lt 6 ] || [ $# -gt 7 ]; then |
| 11 | + echo "Usage: $0 <source_ip_bin> <target_ip_bin> <major> <minor> <micro> <build_type> [type]" |
| 12 | + echo "Example: $0 resources/IP.BIN build/IP.BIN 4 0 2 30" |
| 13 | + echo " $0 resources/IP.BIN build/IP.BIN 2 8 0 30 bootloader" |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +SOURCE_IP="$1" |
| 18 | +TARGET_IP="$2" |
| 19 | +VER_MAJOR="$3" |
| 20 | +VER_MINOR="$4" |
| 21 | +VER_MICRO="$5" |
| 22 | +BUILD_TYPE="$6" |
| 23 | +IP_TYPE="${7:-main}" |
| 24 | + |
| 25 | +if [ ! -f "$SOURCE_IP" ]; then |
| 26 | + echo "Error: Source file $SOURCE_IP not found" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +# Create target directory if needed |
| 31 | +TARGET_DIR="$(dirname "$TARGET_IP")" |
| 32 | +if [ "$TARGET_DIR" != "." ] && [ ! -d "$TARGET_DIR" ]; then |
| 33 | + mkdir -p "$TARGET_DIR" |
| 34 | +fi |
| 35 | +cp "$SOURCE_IP" "$TARGET_IP" |
| 36 | + |
| 37 | +BUILD_TYPE_STR="" |
| 38 | +case "$BUILD_TYPE" in |
| 39 | + 0x0*) BUILD_TYPE_STR="ALP" ;; |
| 40 | + 0x1*) BUILD_TYPE_STR="BET" ;; |
| 41 | + 0x2*) BUILD_TYPE_STR="RC " ;; |
| 42 | + 0x3*) BUILD_TYPE_STR="REL" ;; |
| 43 | + *) BUILD_TYPE_STR="REL" ;; |
| 44 | +esac |
| 45 | + |
| 46 | +CURRENT_DATE=$(date +%Y%m%d) |
| 47 | + |
| 48 | +# Create version string with null byte separator |
| 49 | +if [ "$IP_TYPE" = "bootloader" ]; then |
| 50 | + VERSION_FIELD="DS-BOOTLD" |
| 51 | + BIN_NAME_FIELD="1DS_BOOT.BIN " |
| 52 | + DESC_FIELD="Bootloader ${VER_MAJOR}.${VER_MINOR}" |
| 53 | +else |
| 54 | + VERSION_FIELD="DS-${VER_MAJOR}${VER_MINOR}${VER_MICRO}${BUILD_TYPE_STR}" |
| 55 | + BIN_NAME_FIELD="1DS_CORE.BIN " |
| 56 | + DESC_FIELD="DreamShell ${VER_MAJOR}.${VER_MINOR}" |
| 57 | +fi |
| 58 | + |
| 59 | +# Create version string with null byte separator using printf directly |
| 60 | +VERSION_PART2="V${VER_MAJOR}.${VER_MINOR}${VER_MICRO}0" |
| 61 | + |
| 62 | +# Write version field (0x40-0x4F) with null byte separator |
| 63 | +printf "${VERSION_FIELD}\x00${VERSION_PART2}%*s" $((16 - ${#VERSION_FIELD} - 1 - ${#VERSION_PART2})) "" | \ |
| 64 | + dd of="$TARGET_IP" bs=1 seek=64 count=16 conv=notrunc 2>/dev/null |
| 65 | +# Write other fields |
| 66 | +printf "%-16.16s" "$CURRENT_DATE" | dd of="$TARGET_IP" bs=1 seek=80 count=16 conv=notrunc 2>/dev/null |
| 67 | +printf "%-16.16s" "$BIN_NAME_FIELD" | dd of="$TARGET_IP" bs=1 seek=96 count=16 conv=notrunc 2>/dev/null |
| 68 | +printf "%-16.16s" "$DESC_FIELD" | dd of="$TARGET_IP" bs=1 seek=128 count=16 conv=notrunc 2>/dev/null |
| 69 | + |
| 70 | +if [ "$IP_TYPE" = "bootloader" ]; then |
| 71 | + VERSION_STRING="DS-BOOTLD.V${VER_MAJOR}.${VER_MINOR}${VER_MICRO}0" |
| 72 | + BIN_NAME="1DS_BOOT.BIN" |
| 73 | + DESCRIPTION_STRING="Bootloader ${VER_MAJOR}.${VER_MINOR}" |
| 74 | +else |
| 75 | + VERSION_STRING="DS-${VER_MAJOR}${VER_MINOR}${VER_MICRO}${BUILD_TYPE_STR}.V${VER_MAJOR}.${VER_MINOR}${VER_MICRO}0" |
| 76 | + BIN_NAME="1DS_CORE.BIN" |
| 77 | + DESCRIPTION_STRING="DreamShell ${VER_MAJOR}.${VER_MINOR}" |
| 78 | +fi |
| 79 | + |
| 80 | +echo "Updated IP.BIN:" |
| 81 | +echo " Type: $IP_TYPE" |
| 82 | +echo " Version: $VERSION_STRING" |
| 83 | +echo " Date: $CURRENT_DATE" |
| 84 | +echo " Binary: $BIN_NAME" |
| 85 | +echo " Description: $DESCRIPTION_STRING" |
| 86 | +echo " Target: $TARGET_IP" |
0 commit comments