Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions scripts/download_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,23 @@ if [[ $? -ne 0 ]]; then
fi

local new_ap=$(ls "$fw_out"/AP_*.tar.md5 2>/dev/null | head -1)

# Check if sammyfirm used streaming mode (extracted files directly without .tar.md5)
if [[ -z "$new_ap" ]]; then
ERROR_EXIT "Download completed but AP file not found in $fw_out"
fi

if ! _VALIDATE_AP_FILE "$new_ap"; then
ERROR_EXIT "Downloaded AP file is corrupted or invalid"
LOG_INFO "AP tar file not found, checking for streaming mode extraction..."

# Check if key .lz4 file exists (indicates streaming mode was used)
if [[ -f "$fw_out"/super.img.lz4 ]]; then
LOG_INFO "Streaming mode detected - firmware files extracted directly"
LOG_END "Firmware downloaded successfully (streaming mode)"
else
ERROR_EXIT "Download completed but AP file not found in $fw_out"
fi
else
# Traditional mode: validate the tar.md5 file
if ! _VALIDATE_AP_FILE "$new_ap"; then
ERROR_EXIT "Downloaded AP file is corrupted or invalid"
fi
fi

rm -rf "$target" && mkdir -p "$target"
Expand Down
63 changes: 50 additions & 13 deletions scripts/unpack_fw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,33 @@ EXTRACT_FIRMWARE() {
mkdir -p "$work_model"

local ap_file
local streaming_mode=false
ap_file=$(find "$odin_dir" -maxdepth 1 \( -name "AP_*.tar.md5" -o -name "AP_*.tar" \) | head -1)
[[ -z "$ap_file" ]] && { ERROR_EXIT "AP package missing for $model"; return 1; }

# Check if streaming mode was used (no AP tar but extracted .lz4 files exist)
if [[ -z "$ap_file" ]]; then
if [[ -f "$odin_dir/super.img.lz4" ]]; then
LOG_INFO "Streaming mode detected - using extracted firmware files directly"
streaming_mode=true
else
ERROR_EXIT "AP package missing for $model"
return 1
fi
fi

# Check if we need to extract or not
local current_data

# Samsung saves the md5 at the last of the file , so it takes a lot of time in low end machines, instead i thought to use inode+mtime verify.
# Remove # on _GET_MD5_HASH to verify with md5.

#current_data=$(_GET_MD5_HASH "$ap_file")
current_data=$(_GET_FILE_STAT "$ap_file")
if [[ "$streaming_mode" == true ]]; then
# For streaming mode, use super.img.lz4 stats
current_data=$(_GET_FILE_STAT "$odin_dir/super.img.lz4")
else
#current_data=$(_GET_MD5_HASH "$ap_file")
current_data=$(_GET_FILE_STAT "$ap_file")
fi

if [[ -f "$UNPACK_CONF" ]]; then
local cached_data
Expand Down Expand Up @@ -200,17 +216,38 @@ EXTRACT_FIRMWARE() {

local super_img="${work_model}/super.img"

FETCH_FILE "$ap_file" "super.img" "$work_model" >/dev/null || {
rm -f "$UNPACK_CONF" "${work_model}/.extraction_complete"
ERROR_EXIT "Failed to extract super.img from $ap_file"
return 1
}
if [[ "$streaming_mode" == true ]]; then
# Streaming mode: decompress super.img.lz4 directly
LOG_INFO "Decompressing super.img.lz4..."
if [[ -f "$odin_dir/super.img.lz4" ]]; then
lz4 -d "$odin_dir/super.img.lz4" "$super_img" >/dev/null 2>&1 || {
rm -f "$UNPACK_CONF" "${work_model}/.extraction_complete"
ERROR_EXIT "Failed to decompress super.img.lz4"
return 1
}
# Delete the lz4 file after decompression to free space
LOG_INFO "Deleting super.img.lz4 to free disk space"
rm -f "$odin_dir/super.img.lz4"
sync
else
rm -f "$UNPACK_CONF" "${work_model}/.extraction_complete"
ERROR_EXIT "super.img.lz4 not found in $odin_dir"
return 1
fi
else
# Traditional mode: extract from AP tar archive
FETCH_FILE "$ap_file" "super.img" "$work_model" >/dev/null || {
rm -f "$UNPACK_CONF" "${work_model}/.extraction_complete"
ERROR_EXIT "Failed to extract super.img from $ap_file"
return 1
}

# Delete AP file immediately after extraction to free space
# This applies to all environments to maximize available disk space
LOG_INFO "Deleting AP archive to free disk space"
rm -f "$ap_file"
sync
# Delete AP file immediately after extraction to free space
# This applies to all environments to maximize available disk space
LOG_INFO "Deleting AP archive to free disk space"
rm -f "$ap_file"
sync
fi

[[ ! -f "$super_img" ]] && {
rm -f "$UNPACK_CONF" "${work_model}/.extraction_complete"
Expand Down