Check firmware update #1863
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 | |
max-parallel: 2 | |
matrix: | |
include: | |
- model: "SM-N976N" | |
region: "KOO" | |
codename: "d2xks" | |
- model: "SM-N971N" | |
region: "KOO" | |
codename: "d1xks" | |
- model: "SM-N976B" | |
region: "XEU" | |
codename: "d2x" | |
- model: "SM-N970F" | |
region: "DBT" | |
codename: "d1" | |
- model: "SM-N975F" | |
region: "DBT" | |
codename: "d2s" | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
- name: Compare latest version with current version | |
id: check | |
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 }}` || 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: Install dependencies | |
if: env.need_update == 1 | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y liblz4-tool zip | |
sudo wget -O /usr/bin/dtc https://corsica.nu/dtc && sudo chmod +x /usr/bin/dtc | |
sudo wget -O /usr/bin/mkdtimg https://corsica.nu/mkdtimg && sudo chmod +x /usr/bin/mkdtimg | |
sudo wget -O /usr/bin/splitdt https://corsica.nu/splitdt && sudo chmod +x /usr/bin/splitdt | |
sudo wget -O /usr/bin/unpackbootimg https://corsica.nu/unpackbootimg && sudo chmod +x /usr/bin/unpackbootimg | |
sudo wget -O /usr/bin/extract-ikconfig https://corsica.nu/extract-ikconfig && sudo chmod +x /usr/bin/extract-ikconfig | |
sudo wget -O /usr/bin/samfirm https://github.com/ananjaser1211/SamFirm.NET/releases/latest/download/linux-x64 && sudo chmod +x /usr/bin/samfirm | |
- name: Fetch firmware | |
if: env.need_update == 1 | |
run: samfirm -m ${{ matrix.model }} -r ${{ matrix.region }} | |
- name: Print directory structure | |
if: env.need_update == 1 | |
run: ls -la ${{ matrix.model }}_${{ matrix.region }} | |
- name: Get path of files | |
if: env.need_update == 1 | |
id: files | |
run: | | |
echo "bl=`find -name BL*`" >> $GITHUB_ENV | |
echo "ap=`find -name AP*`" >> $GITHUB_ENV | |
echo "cp=`find -name CP*`" >> $GITHUB_ENV | |
echo "csc=`find -name HOME_CSC*`" >> $GITHUB_ENV | |
- name: Check downloaded firmware version | |
if: env.need_update == 1 | |
run: | | |
version_short=`echo ${{ env.ap }} | cut -d'_' -f3` | |
version_csc=`echo ${{ env.csc }} | cut -d'_' -f5` | |
version_modem=`echo ${{ env.cp }} | cut -d'_' -f3` | |
changelist=`echo ${{ env.ap }} | cut -d'_' -f4` | |
[[ $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 | |
echo Changelist: $changelist >> versions.txt | |
- name: Print available disk space | |
if: env.need_update == 1 | |
run: | | |
pwd | |
sudo df -h | |
- name: Create zip environment | |
if: env.need_update == 1 | |
run: | | |
target_device=`echo ${{ matrix.model }} | cut -d'-' -f2` | |
target_version=${{ env.latest_shortversion }} | |
mkdir -p $target_version configs tmp | |
cp -r bootloader_modem $target_version | |
cp -r device_tree $target_version | |
sed -i "s/target_device/$target_device/g" $target_version/bootloader_modem/META-INF/com/google/android/updater-script | |
sed -i "s/target_version/$target_version/g" $target_version/bootloader_modem/META-INF/com/google/android/updater-script | |
sed -i "s/target_device/$target_device/g" $target_version/device_tree/META-INF/com/google/android/updater-script | |
sed -i "s/target_version/$target_version/g" $target_version/device_tree/META-INF/com/google/android/updater-script | |
if echo $target_device | grep N97[05]F; then sed -i '/modem_5g/d' $target_version/bootloader_modem/META-INF/com/google/android/updater-script;fi | |
- name: Extract images from AP/BL, dump configs and create zips | |
if: env.need_update == 1 | |
id: releases | |
run: | | |
target_version=${{ env.latest_shortversion }} | |
bls=(cm.bin dt.img dtbo.img keystorage.bin modem.bin modem_5g.bin sboot.bin uh.bin up_param.bin) | |
tar xvf ${{ env.ap }} dt.img.lz4 dtbo.img.lz4 boot.img.lz4 recovery.img.lz4 | |
tar xvf ${{ env.bl }} | |
tar xvf ${{ env.cp }} | |
for i in `ls | grep lz4`; do lz4 -dm $i ; rm -rf $i; done | |
extract-ikconfig boot.img > configs/exynos9820-${{ matrix.codename }}_defconfig | |
cd tmp | |
unpackbootimg -i ../boot.img >> ../configs/bootimg.args && mkdtimg dump ../dt.img >> ../configs/exynos9825.cfg | |
splitdt ../dt.img && dtc dtbdump_* -I dtb -O dts -o ../configs/exynos9825.dts && rm -rf * | |
mkdtimg dump ../dtbo.img >> ../configs/${{ matrix.codename }}.cfg && splitdt ../dtbo.img | |
for i in `ls | grep dtbdump_`; do dtc $i -I dtb -O dts -o $i.txt; done | |
for i in `ls | grep txt`; | |
do mv $i ../configs/$(cat $i | grep "model =" | sed 's/Samsung //; s/\t//g; s/\"//g; s/model = //; s/\;//' | awk '{print tolower($8"-"$1"_"$2"_"$3"_"$4".dts")}'); | |
done | |
cd ../configs | |
for i in `ls | grep dts`; do sed -i 's/ /\t/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x0/0x/g; s/0x;/0x0;/g; s/0x>/0x0>/g; s/0x /0x0 /g; s/\\0/\", \"/g' $i; done; | |
zip -r ../$target_version-configs.zip * | |
cd .. | |
mv boot.img $target_version-stock_boot.img | |
mv recovery.img $target_version-stock_recovery.img | |
bls=(cm.bin keystorage.bin modem.bin modem_5g.bin sboot.bin uh.bin up_param.bin) | |
for i in ${bls[@]}; do [[ -e $i ]] && mv $i $target_version/bootloader_modem/$i; done | |
cd $target_version/bootloader_modem | |
zip -r ../../$target_version-bootloader_modem-twrp_flashable.zip * | |
rm -rf META-INF | |
tar cvf ../../$target_version-bootloader_modem-odin_flashable.tar * | |
cd ../../ | |
dts=(dt.img dtbo.img) | |
for i in ${dts[@]}; do [[ -e $i ]] && mv $i $target_version/device_tree/$i; done | |
cd $target_version/device_tree | |
zip -r ../../$target_version-device_tree-twrp_flashable.zip * | |
rm -rf META-INF | |
tar cvf ../../$target_version-device_tree-odin_flashable.tar * | |
cd ../../ | |
echo "blzip=`find -name $target_version-bootloader_modem-twrp_flashable.zip`" >> $GITHUB_ENV | |
echo "bltar=`find -name $target_version-bootloader_modem-odin_flashable.tar`" >> $GITHUB_ENV | |
echo "dtzip=`find -name $target_version-device_tree-twrp_flashable.zip`" >> $GITHUB_ENV | |
echo "dttar=`find -name $target_version-device_tree-odin_flashable.tar`" >> $GITHUB_ENV | |
echo "boot=`find -name $target_version-stock_boot.img`" >> $GITHUB_ENV | |
echo "recovery=`find -name $target_version-stock_recovery.img`" >> $GITHUB_ENV | |
echo "configs=`find -name $target_version-configs.zip`" >> $GITHUB_ENV | |
- 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 }} | |
git add current.${{ matrix.model }} | |
git commit -m "${{ matrix.model }}: ${{ env.latest_version }}" | |
git tag ${{ env.latest_shortversion }} | |
- 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: CaptainThrowback/action-gh-release@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
body_path: versions.txt | |
tag_name: ${{ env.latest_shortversion }} | |
files: | | |
${{ env.blzip }} | |
${{ env.bltar }} | |
${{ env.dtzip }} | |
${{ env.dttar }} | |
${{ env.boot }} | |
${{ env.recovery }} | |
${{ env.configs }} | |