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

Add VideoStrong KM5 (videostrong-km5) #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions videostrong-km5/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../gxl.inc
Binary file added videostrong-km5/acs.bin
Binary file not shown.
134 changes: 134 additions & 0 deletions videostrong-km5/acs_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# uncompyle6 version 3.2.4
# Python bytecode 2.7 (62211)
# Decompiled from: Python 3.6.7 (default, Nov 3 2018, 21:32:46)
# [GCC 8.2.0]
# Embedded file name: acs_tool.py
# Compiled at: 2015-09-17 07:30:19
import sys, os, os.path, json
from struct import *
import codecs, shutil, copy, collections
ENTRY_POINT_OFFSET = 4
BL2_HEADER_OFFSET = 4096
ACS_TOOL_VERSION = 1
acs_v1 = collections.OrderedDict()
acs_v1['acs_magic'] = 'acs__'
acs_v1['chip_type'] = 1
acs_v1['version'] = 2
acs_v1['acs_set_length'] = 8
acs_v1['ddr_magic'] = 'ddrs_'
acs_v1['ddr_set_version'] = 1
acs_v1['ddr_set_length'] = 2
acs_v1['ddr_set_addr'] = 8
acs_v1['ddrt_magic'] = 'ddrt_'
acs_v1['ddrt_set_version'] = 1
acs_v1['ddrt_set_length'] = 2
acs_v1['ddrt_set_addr'] = 8
acs_v1['pll_magic'] = 'pll__'
acs_v1['pll_set_version'] = 1
acs_v1['pll_set_length'] = 2
acs_v1['pll_set_addr'] = 8
check_excepts = [
'ddr_set_addr', 'ddrt_set_addr', 'pll_set_addr']
check_excepts_length = ['ddr_set_length', 'ddrt_set_length', 'pll_set_length']
key_versions = ['version', 'ddr_set_version', 'ddrt_set_version', 'pll_set_version']

class acs_tool(object):

def __init__(self, file_des, file_des_tmp, file_src, debug):
self.debug = int(debug)
self.file_des = file_des
self.file_src = file_src
self.file_des_tmp = file_des_tmp
self.acs_des = copy.deepcopy(acs_v1)
self.acs_src = copy.deepcopy(acs_v1)
self.acs_base = copy.deepcopy(acs_v1)

def init_acs(self, acs_struct, file_name, bl2):
seek_position = 0
file_handler = open(file_name, 'rb')
file_handler.seek(ENTRY_POINT_OFFSET)
acs_entry_point, = unpack('H', file_handler.read(2))
acs_entry_point -= bl2 * BL2_HEADER_OFFSET
seek_position = acs_entry_point
self.log_print(file_name)
for key in list(acs_struct.keys()):
file_handler.seek(seek_position)
if isinstance(acs_struct[key], str):
seek_position += len(acs_struct[key])
acs_struct[key] = file_handler.read(len(acs_struct[key])).decode('utf-8')
else:
if isinstance(acs_struct[key], int):
seek_position += acs_struct[key]
if 1 == acs_struct[key]:
acs_struct[key], = unpack('B', file_handler.read(1))
else:
acs_struct[key], = unpack('H', file_handler.read(2))
if key in check_excepts:
acs_struct[key] -= bl2 * BL2_HEADER_OFFSET
self.log_print(key + ' ' + str(acs_struct[key]))

file_handler.close()

def check_acs(self):
err_counter = 0
for key in list(self.acs_des.keys()):
if self.acs_des[key] != self.acs_src[key] and key not in check_excepts:
print("Warning! ACS %s doesn't match!! %s/%s" % (key, self.acs_des[key], self.acs_src[key]))

for key in key_versions:
if self.acs_des[key] > self.acs_src[key]:
self.acs_des[key] = self.acs_src[key]
print('Warning! ACS src %s too old!' % key)

for key in list(self.acs_base.keys()):
if isinstance(self.acs_base[key], str):
if self.acs_des[key] != self.acs_base[key]:
err_counter += 1
print('Error! ACS DES %s error!! Value: %s, Expect: %s' % (key, self.acs_des[key], self.acs_base[key]))
if self.acs_src[key] != self.acs_base[key]:
err_counter += 1
print('Error! ACS DES %s error!! Value: %s, Expect: %s' % (key, self.acs_src[key], self.acs_base[key]))

if self.acs_des['version'] > ACS_TOOL_VERSION:
print('Error! Please update acs tool! v%s>v%s' % (self.acs_des['version'], ACS_TOOL_VERSION))
err_counter += 1
return err_counter

def copy_data(self):
file_des = open(self.file_des_tmp, 'r+b')
file_src = open(self.file_src, 'rb')
for key_addr, key_length in zip(check_excepts, check_excepts_length):
file_des.seek(self.acs_des[key_addr])
file_src.seek(self.acs_src[key_addr])
file_des.write(file_src.read(self.acs_des[key_length]))

file_des.close()
file_src.close()
return 0

def run(self):
shutil.copyfile(self.file_des, self.file_des_tmp)
self.init_acs(self.acs_des, self.file_des_tmp, 1)
self.init_acs(self.acs_src, self.file_src, 0)
if self.check_acs():
print('ACS check failed! Compile Abort!')
return -1
self.copy_data()
print('ACS tool process done.')

def log_print(self, log):
if self.debug:
print(log)


if __name__ == '__main__':
if sys.argv[1] == '--help' or sys.argv[1] == '-help':
print('acs_tool.py [bl2.bin] [bl2_tmp.bin] [acs.bin] [debug(1/0)]')
exit(1)
if len(sys.argv) != 5:
print('acs_tool.py [bl2.bin] [bl2_tmp.bin] [acs.bin] [debug(1/0)]')
exit(1)
tool = acs_tool(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
if tool.run():
exit(1)
# okay decompiling acs_tool.pyc
Binary file added videostrong-km5/aml_encrypt_gxl
Binary file not shown.
Binary file added videostrong-km5/bl2.bin
Binary file not shown.
Binary file added videostrong-km5/bl21.bin
Binary file not shown.
Binary file added videostrong-km5/bl30.bin
Binary file not shown.
Binary file added videostrong-km5/bl301.bin
Binary file not shown.
Binary file added videostrong-km5/bl31.img
Binary file not shown.
40 changes: 40 additions & 0 deletions videostrong-km5/blx_fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

#bl2 file size 41K, bl21 file size 3K (file size not equal runtime size)
#total 44K
#after encrypt process, bl2 add 4K header, cut off 4K tail

#bl30 limit 41K
#bl301 limit 12K
#bl2 limit 41K
#bl21 limit 3K, but encrypt tool need 48K bl2.bin, so fix to 7168byte.

#$7:name flag
if [ "$7" = "bl30" ]; then
declare blx_bin_limit=40960
declare blx01_bin_limit=13312
elif [ "$7" = "bl2" ]; then
declare blx_bin_limit=41984
declare blx01_bin_limit=7168
else
echo "blx_fix name flag not supported!"
exit 1
fi

# blx_size: blx.bin size, zero_size: fill with zeros
declare -i blx_size=`du -b $1 | awk '{print int($1)}'`
declare -i zero_size=$blx_bin_limit-$blx_size
dd if=/dev/zero of=$2 bs=1 count=$zero_size
cat $1 $2 > $3
rm $2

declare -i blx01_size=`du -b $4 | awk '{print int($1)}'`
declare -i zero_size_01=$blx01_bin_limit-$blx01_size
dd if=/dev/zero of=$2 bs=1 count=$zero_size_01
cat $4 $2 > $5

cat $3 $5 > $6

rm $2

exit 0