Created
November 10, 2022 03:45
-
-
Save MrARM/0ea2e583958b576a7299c1fb4442c4bc to your computer and use it in GitHub Desktop.
Flash an "autobox" wireless carplay adapter with custom firmware
This file contains hidden or 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
# Notes, file size seems to cap around 4 mb, if you go over, the flash fails and you have to do a SPI flash (or find a way in the uart console) | |
import base64 | |
import json | |
import math | |
import requests | |
import time | |
import os | |
file = 'custom.tar' | |
presult = 1 | |
pversion = 375 | |
pitemsize = 32768 | |
file = open(file, 'br') | |
# get the file size | |
file.seek(0, os.SEEK_END) | |
pfilesize = file.tell() | |
file_inc_down = pfilesize | |
print("Size of file is:", pfilesize, "bytes") | |
print('DL', end='') | |
file.seek(0) | |
# Get page count | |
pcount = math.ceil(pfilesize / pitemsize) | |
requests.post('http://192.168.2.1/getupdatestatus') | |
# Run through all pages | |
ppos = 0 | |
while ppos < pcount: | |
payload = { | |
'result': presult, | |
'version': pversion, | |
'pos': ppos, | |
'itemsize': pitemsize, | |
'count': pcount, | |
'filesize': pfilesize | |
} | |
if file_inc_down < pitemsize: | |
# Set metadata | |
payload['datasize'] = file_inc_down | |
# Read in data | |
data = file.read(file_inc_down) | |
else: | |
# Set metadata | |
file_inc_down -= pitemsize | |
payload['datasize'] = pitemsize | |
# Read in data | |
data = file.read(pitemsize) | |
payload['data'] = base64.b64encode(data).decode('ascii') | |
# Upload file | |
r = requests.post('http://192.168.2.1/uploadappdatas', headers={'X-Requested-With': 'XMLHttpRequest', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}, data=json.dumps(payload, separators=(',', ':'))) | |
dat = r.json() | |
if dat['result'] == 0: | |
print('Err?') | |
print(dat) | |
print(payload) | |
time.sleep(1) | |
else: | |
print('.', end='') | |
ppos += 1 | |
# Perform the install | |
print('\ninstalling... ', end='') | |
start = requests.post('http://192.168.2.1/requestupdate').json() | |
if start['result'] == 0: | |
print('Err?') | |
print(start) | |
exit(1) | |
inst = 0 | |
while inst < 100: | |
prog = requests.post('http://192.168.2.1/getupdatestatus').json() | |
inst = prog['percent'] | |
print(" ", inst, end=' ') | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment