Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

News features #30

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7415078
unpack MStar bin firmware and mount *.img files to directory
Mar 21, 2019
61ad9c1
unpack MStar bin firmware and extract file from *.img files to directory
kasru Mar 31, 2019
e6378b3
unpack MStar bin firmware and extract file from *.img files to directory
kasru Mar 31, 2019
f3a541e
sparse support
sha-man-4pda Feb 15, 2020
0e296ba
binaries for sparse support
sha-man-4pda Feb 15, 2020
977b35d
SubSecureInfoGen.exe fixed
sha-man-4pda Feb 15, 2020
8ac6e95
CRC2 calculation method for TP.MS338E.PB803
sha-man-4pda Feb 15, 2020
27449f0
version number added
sha-man-4pda Feb 18, 2020
1ebeb6e
Contact info added
sha-man-4pda Feb 18, 2020
0e7774f
CRC_TYPE parameter added instead of USE_XGIMI_CRC2
sha-man-4pda Feb 18, 2020
5aa1161
Added Linux OS support
RockBomber Feb 21, 2020
0b494d1
Label customization added
sha-man-4pda Mar 18, 2020
acd376b
Example of customized label using
sha-man-4pda Mar 18, 2020
96dfbed
[patch] explicit 'iso-8859-1'
nwind21 Jan 26, 2021
9839677
multi2optee command support
sha-man-4pda May 18, 2021
21087fe
multi2optee command support, 'command' key added
sha-man-4pda May 18, 2021
804b075
multi2optee command support
sha-man-4pda May 18, 2021
bef5ade
'multi2optee' command and 'command' key config examples
sha-man-4pda May 18, 2021
025cbe2
Merge pull request #1 from sha-man-4pda/master
Thedemon007 Oct 28, 2023
5c52d2d
Merge pull request #2 from kasru/master
Thedemon007 Oct 28, 2023
63e510e
Merge from divx/mstar-bin-tool
Thedemon007 Oct 28, 2023
d9ef528
Delete bin/linux-x86/lzop
Thedemon007 Oct 28, 2023
bb0d879
Add .gitignore
Thedemon007 Oct 28, 2023
3a5450d
Add src of AESCrypt2
Thedemon007 Oct 28, 2023
9a488bd
Add android-simg2img source code
Thedemon007 Oct 28, 2023
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
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# NOTE! Don't add files that are generated in specific
# subdirectories here. Add them in the ".gitignore" file
# in that subdirectory instead.
#
# NOTE! Please use 'git ls-files -i --exclude-standard'
# command after changing this file, to see if there are
# any tracked files which get ignored after the change.
#
# Normal rules
#
.*
*.o
*.o.*
*.a
*.s
*.bin
*.tar
*.gz
*.bz2
*.lzma
*.xz
*.lz4
*.lzo
*.patch
*.c.[012]*.*

#
# Unpacked directory
#
/unpacked/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

#
# git files that we don't want to ignore even if they are dot-files
#
!.gitignore
!.mailmap
!.cocciconfig
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/android-simg2img"]
path = src/android-simg2img
url = https://github.com/anestisb/android-simg2img
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@
Command line tools to pack/unpack MStar bin firmware

Currently available tools:
- **extract.py** - unpack MStar bin firmware and extract file from *.img files to directory
- **extract.sh** - unpack MStar bin firmware and mount *.img files to directory
- **unpack.py** - unpack MStar bin firmware
- **pack.py** - pack MStar bin firmware
- **extract_keys.py** - extract AES and RSA-public keys from MBOOT binary
- **secure_partition.py** - encrypt image and generate signature file


## unpack MStar bin firmware and extract file from *.img files to directory

```
Usage: extract.py <firmware> <output folder [default: ./unpacked/]>
<firmware> - MStar bin firmware to unpack
<output folder> - directory to store unpacked stuff. Default value: ./unpacked/
```

## Unpack MStar bin firmware files and mount *.img to directory

```
Usage: extract.sh <firmware> <output folder [default: ./unpacked/]>
<firmware> - MStar bin firmware to unpack
<output folder> - directory to store unpacked stuff. Default value: ./unpacked/
```

## Umount directory

```
Usage: extract.sh umount <output folder [default: ./unpacked/]>
<output folder> - directory to store unpacked stuff. Default value: ./unpacked/
```

## Unpack MStar bin firmware files

```
Expand Down
Binary file removed __pycache__/utils.cpython-37.pyc
Binary file not shown.
Binary file added bin/linux-x86/img2simg
Binary file not shown.
Binary file added bin/linux-x86/simg2img
Binary file not shown.
Binary file added bin/linux-x86/simg2simg
Binary file not shown.
Binary file added bin/sparse/cygwin1.dll
Binary file not shown.
Binary file added bin/sparse/cygz.dll
Binary file not shown.
Binary file added bin/sparse/img2simg.exe
Binary file not shown.
Binary file added bin/sparse/simg2img.exe
Binary file not shown.
Binary file added bin/sparse/simg2simg.exe
Binary file not shown.
Binary file added bin/win32/7z.dll
Binary file not shown.
Binary file added bin/win32/7z.exe
Binary file not shown.
Binary file modified bin/win32/SubSecureInfoGen.exe
Binary file not shown.
33 changes: 33 additions & 0 deletions configs/command-example.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#With 'command' key in any 'part' section you can add any command right after the patition writing commands.
#Usually it's done to set environment variables.
#Number of command lines isn't limited.

[Main]
FirmwareFileName=example.bin
ProjectFolder=./pack
useHexValuesPrefix=true
SCRIPT_FIRMWARE_FILE_NAME=$$(UpgradeImage)
DRAM_BUF_ADDR=55000000
MAGIC_FOOTER=12345678
HEADER_SIZE=16KB

[HeaderScript]
Label: \#-------------USB Upgrade Bin Info----------------

Prefix:

Suffix:

[part/recovery]
erase=True
imageFile=${Main:ProjectFolder}/recovery.img
type=partitionImage
command=setenv recoverycmd mmc read.p 0x23000000 dtb 0x00100000\; mmc read.p 0x25000000 recovery 0x02000000\; bootm 0x25000000
saveenv

[part/boot]
erase=True
imageFile=${Main:ProjectFolder}/boot.img
type=partitionImage
command=setenv bootcmd mmc read.p 0x23000000 dtb 0x00100000\; mmc read.p 0x25000000 boot 0x02000000\; bootm 0x25000000
saveenv
32 changes: 32 additions & 0 deletions configs/label-example.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Example of using customized Label for your firmware.
# If Label variable is specified in the HeaderScript section then the default label will be replaced by yours.
# Sometimes it could be nesessary because the installer checks the label for the device name and the timestamp as Xgimi does.
#

[Main]
FirmwareFileName=GIMI_XHAD01_XHC05_MAXIM_YN_WMP.bin
ProjectFolder=./pack
useHexValuesPrefix=true

SCRIPT_FIRMWARE_FILE_NAME=$$(UpgradeImage)
DRAM_BUF_ADDR=20200000
MAGIC_FOOTER=12345678
HEADER_SIZE=16KB
#CRC_TYPE = [NORMAL, XGIMI, PB803]. For details see comments in pack.py file
CRC_TYPE=XGIMI

[HeaderScript]
Label: \#-------------USB Upgrade Bin Info----------------
\# Device : synsepalum_YN
\# Build PATH : /home/xgimi-dev/jenkins_node/workspace/838_H2/47_2019-07-27-172032_v1.12.36/android
\# Build TIME : {time:%Y-%m-%d %H:%M:%S}
\# Build TIME STAMP : {timestamp:d}

Prefix:

Suffix:
setenv MstarUpgrade_complete 1
setenv ResetAfterUpgrade 1
setenv ForcePowerOn 0
saveenv
28 changes: 28 additions & 0 deletions configs/multi2optee-example.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#Use 'type=multi2optee' key in the 'part' section to write partition with 'multi2optee' command.

[Main]
FirmwareFileName=example.bin
ProjectFolder=./pack
useHexValuesPrefix=true
SCRIPT_FIRMWARE_FILE_NAME=$$(UpgradeImage)
DRAM_BUF_ADDR=55000000
MAGIC_FOOTER=12345678
HEADER_SIZE=16KB

[HeaderScript]
Label: \#-------------USB Upgrade Bin Info----------------

Prefix:

Suffix:

[part/optee]
imageFile=${Main:ProjectFolder}/optee.bin
type=multi2optee
erase=true
command=setenv MMAP_ONE_BIN_SUPPORT 1

[part/armfw]
imageFile=${Main:ProjectFolder}/armfw.bin
type=multi2optee
erase=true
3 changes: 2 additions & 1 deletion configs/xgimi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ SCRIPT_FIRMWARE_FILE_NAME=${FirmwareFileName}
DRAM_BUF_ADDR=20200000
MAGIC_FOOTER=12345678
HEADER_SIZE=16KB
USE_XGIMI_CRC2=True
#CRC_TYPE = [NORMAL, XGIMI, PB803]. For details see comments in pack.py file
CRC_TYPE=XGIMI

[HeaderScript]
Prefix:
Expand Down
38 changes: 38 additions & 0 deletions extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys
import os
import re
import shutil
import subprocess

import utils

# Vars
DEBUG = False

# Parse args
if len(sys.argv) == 1:
print ("Usage: extract.py <firmware> <output folder [default: ./unpacked/]>")
quit()

inputFile = sys.argv[1]
if not os.path.exists(inputFile):
print ("No such file: {}".format(inputFile))
quit()

if len(sys.argv) == 3:
outputDirectory = sys.argv[2]
else:
outputDirectory = 'unpacked'

subprocess.run("unpack.py {} {}".format(inputFile, outputDirectory), shell=True)

if not os.path.exists(outputDirectory):
print ("No such folder: {}".format(outputDirectory))
quit()

files = os.listdir(outputDirectory)
images = filter(lambda x: x.endswith('.img'), files)
for img in images:
path = os.path.join(outputDirectory, os.path.splitext(img)[0])
os.mkdir(path)
utils.unpackImg(os.path.join(outputDirectory, img), path)
45 changes: 45 additions & 0 deletions extract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

usage()
{
echo "Usage: extract.sh <firmware> <output folder [default: ./unpacked/]>"
echo "Usage: extract.sh umount <output folder [default: ./unpacked/]>"
exit 1
}

main()
{
local UNPACK_DIR="unpacked"

if [ $# -lt 1 ]; then
usage
fi

local FIRMWARE=$1
if [ $# -ge 2 ]; then
UNPACK_DIR=$2
fi

if [ "$1" = "umount" ]; then
cd "$UNPACK_DIR"
for file in *.img; do
folder="${file%%.*}"
sudo umount "${folder}"
done
cd ..
exit 0
fi

python3 unpack.py "$FIRMWARE" "$UNPACK_DIR"

cd "$UNPACK_DIR"
for file in *.img; do
folder="${file%%.*}"
mkdir "${folder}"
sudo mount "${file}" "${folder}" -o loop
done
cd ..
}

main $*

Loading