This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
Check firmware update #665
This file contains 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
name: Check firmware update | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 12 * * *" | |
push: | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# BRI OMC (A52SXQ_CHN_TW) | |
- model: "SM-A528B" | |
region: "BRI" | |
# ODM OMC | |
- model: "SM-A528B" | |
region: "INS" | |
# OJM OMC | |
- model: "SM-A528B" | |
region: "EGY" | |
# OKR OMC | |
- model: "SM-A528N" | |
region: "KOO" | |
# OLE OMC | |
- model: "SM-A528B" | |
region: "XID" | |
# OLM OMC | |
- model: "SM-A528B" | |
region: "XSA" | |
# OWA OMC | |
- model: "SM-A528B" | |
region: "CDR" | |
# OWM OMC | |
- model: "SM-A528B" | |
region: "TGP" | |
# OWO OMC | |
- model: "SM-A528B" | |
region: "PEO" | |
# OXM OMC | |
- model: "SM-A528B" | |
region: "BTU" | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Compare latest version with current version | |
run: | | |
need_update=0 | |
latest=`curl --retry 5 --retry-delay 5 http://fota-cloud-dn.ospserver.net/firmware/${{ matrix.region }}/${{ matrix.model }}/version.xml | grep latest | sed 's/^[^>]*>//' | sed 's/<.*//'` | |
latest_short=`echo $latest | cut -d'/' -f1` | |
latest_csc=`echo $latest | cut -d'/' -f2` | |
latest_modem=`echo $latest | cut -d'/' -f3` | |
current=`cat current.${{ matrix.model }}_${{ matrix.region }}` || need_update=1 | |
[[ $latest != $current ]] && need_update=1 | |
echo "latest_version=$latest" >> $GITHUB_ENV | |
echo "latest_shortversion=$latest_short" >> $GITHUB_ENV | |
echo "latest_cscversion=$latest_csc" >> $GITHUB_ENV | |
echo "latest_modemversion=$latest_modem" >> $GITHUB_ENV | |
echo "need_update=$need_update" >> $GITHUB_ENV | |
- name: Set up Node.js | |
if: env.need_update == 1 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 'latest' | |
- name: Set up Python 3 | |
if: env.need_update == 1 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
if: env.need_update == 1 | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y liblz4-tool zip simg2img f2fs-tools | |
sudo wget -O /usr/bin/samfirm https://github.com/DavidArsene/samfirm.js/releases/download/v0.3.0/samfirm.js && sudo chmod +x /usr/bin/samfirm | |
- name: Fetch firmware | |
if: env.need_update == 1 | |
run: | | |
if [[ "${{ matrix.model }}" == "SM-A528N" ]]; then | |
imei="354049881234560" | |
else | |
imei="352599501234566" | |
fi | |
samfirm -m ${{ matrix.model }} -r ${{ matrix.region }} -i $imei | |
- name: Get path of files | |
if: env.need_update == 1 | |
run: | | |
echo "ap_tar=`find -name AP*`" >> $GITHUB_ENV | |
echo "bl_tar=`find -name BL*`" >> $GITHUB_ENV | |
echo "cp_tar=`find -name CP*`" >> $GITHUB_ENV | |
echo "csc_tar=`find -name CSC*`" >> $GITHUB_ENV | |
echo "home_csc_tar=`find -name HOME_CSC*`" >> $GITHUB_ENV | |
- name: Check downloaded firmware version | |
if: env.need_update == 1 | |
run: | | |
version_short=`echo ${{ env.ap_tar }} | cut -d'_' -f3` | |
version_csc=`echo ${{ env.csc_tar }} | cut -d'_' -f4` | |
version_modem=`echo ${{ env.cp_tar }} | cut -d'_' -f3` | |
[[ $version_short == ${{ env.latest_shortversion }} ]] | |
[[ $version_csc == ${{ env.latest_cscversion }} ]] | |
[[ $version_modem == ${{ env.latest_modemversion }} ]] | |
echo PDA version: $version_short > versions.txt | |
echo CSC version: $version_csc >> versions.txt | |
echo Modem version: $version_modem >> versions.txt | |
- name: Cleanup space | |
if: env.need_update == 1 | |
run: | | |
sudo apt-get remove --purge -y "php*" "dotnet*" "mysql*" "nodejs*" "clang*" "google*" | |
sudo apt-get autoremove -y | |
sudo apt-get clean | |
sudo rm -rf /usr/local | |
- name: Extract kernel images | |
if: env.need_update == 1 | |
env: | |
FILES: boot.img.lz4 dtbo.img.lz4 vbmeta.img.lz4 vendor_boot.img.lz4 | |
run: | | |
for file in $FILES; do tar xvf ${{ env.ap_tar }} ${file}; done | |
tar cvf ${{ env.latest_shortversion }}_kernel.tar *.lz4 | |
rm *.lz4 | |
- name: Extract PIT file | |
if: env.need_update == 1 | |
run: | | |
tar --wildcards --exclude='*/*' -xvf ${{ env.csc_tar }} '*.pit' | |
echo "pit_file=`find -name *.pit`" >> $GITHUB_ENV | |
- name: Generate patched vbmeta | |
if: env.need_update == 1 | |
run: | | |
tar xvf ${{ env.ap_tar }} vbmeta.img.lz4 | |
lz4 -d vbmeta.img.lz4 vbmeta.img | |
rm vbmeta.img.lz4 | |
printf "$(printf '\\x%02X' 3)" | dd of="vbmeta.img" bs=1 seek=123 count=1 conv=notrunc &> /dev/null | |
tar cvf ${{ env.latest_shortversion }}_patched_vbmeta.tar vbmeta.img | |
rm vbmeta.img | |
- name: Extract vendor partition | |
if: env.need_update == 1 | |
run: | | |
tar xvf ${{ env.ap_tar }} super.img.lz4 | |
lz4 -d super.img.lz4 super.img | |
rm super.img.lz4 | |
simg2img super.img super_raw.img | |
rm super.img | |
mv super_raw.img super.img | |
python3 tools/bin/lpunpack.py -p vendor super.img . | |
rm super.img | |
[[ -e vendor.img.ext4 ]] && mv vendor.img.ext4 vendor.img | |
[[ -e vendor.img ]] && zip ${{ env.latest_shortversion }}_vendor.zip vendor.img | |
[[ -e vendor.img ]] && rm vendor.img | |
- name: Update current version | |
if: env.need_update == 1 | |
run: | | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git pull origin ${{github.ref}} --ff-only | |
echo ${{ env.latest_version }} > current.${{ matrix.model }}_${{ matrix.region }} | |
git add current.${{ matrix.model }}_${{ matrix.region }} | |
git commit -m "${{ matrix.model }}: ${{ env.latest_version }}" | |
git tag "${{ env.latest_shortversion }}_${{ matrix.region }}" | |
- name: Push changes to repo | |
if: env.need_update == 1 | |
uses: ad-m/github-push-action@master | |
with: | |
tags: true | |
github_token: ${{ secrets.TOKEN }} | |
- name: Upload release assets | |
if: env.need_update == 1 | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
body_path: versions.txt | |
tag_name: "${{ env.latest_shortversion }}_${{ matrix.region }}" | |
name: "${{ env.latest_shortversion }} - ${{ matrix.model }} - ${{ matrix.region }}" | |
files: | | |
${{ env.bl_tar }} | |
${{ env.cp_tar }} | |
${{ env.home_csc_tar }} | |
${{ env.latest_shortversion }}_kernel.tar | |
${{ env.pit_file }} | |
${{ env.latest_shortversion }}_patched_vbmeta.tar | |
${{ env.latest_shortversion }}_vendor.zip |