mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 13:37:03 +03:00
WIP
This commit is contained in:
parent
4b257406e1
commit
9e1c817cf2
@ -113,17 +113,3 @@ def bytes2words(arr: List[int]) -> List[int]:
|
||||
words.append(word[0]+2**8*word[1]+2**16*word[2]+2**24*word[3])
|
||||
word = []
|
||||
return words
|
||||
|
||||
def get_content(filename: str) -> List[int]:
|
||||
content: List[int] = []
|
||||
|
||||
if filename.endswith(".bin"):
|
||||
content = parse_bin(filename)
|
||||
elif filename.endswith(".hex"):
|
||||
content = parse_hex(filename)[0]
|
||||
else:
|
||||
raise Exception("Unsupported file format")
|
||||
|
||||
return content
|
||||
|
||||
# parse_hex("mik32-uploader../test-roms/eeprom.hex")
|
||||
|
||||
@ -1,17 +1,19 @@
|
||||
import shlex
|
||||
from .tclrpc import OpenOcdTclRpc
|
||||
import argparse
|
||||
import sys
|
||||
import subprocess
|
||||
from .mik32_eeprom import *
|
||||
from .mik32_spifi import *
|
||||
from .mik32_ram import *
|
||||
from .mik32_parsers import *
|
||||
import os
|
||||
from typing import Iterable
|
||||
from enum import Enum
|
||||
from typing import List, Tuple
|
||||
from .drivers.tclrpc import OpenOcdTclRpc
|
||||
from .drivers.mik32_eeprom import *
|
||||
from .drivers.mik32_spifi import *
|
||||
from .drivers.mik32_ram import *
|
||||
from .mik32_parsers import *
|
||||
from .parsers.parser_hex import *
|
||||
|
||||
|
||||
# class bcolors:
|
||||
# class bcolors(Enum):
|
||||
# OK = '\033[92m'
|
||||
# WARNING = '\033[93m'
|
||||
# FAIL = '\033[91m'
|
||||
@ -19,20 +21,61 @@ from typing import Iterable
|
||||
# BOLD = '\033[1m'
|
||||
# UNDERLINE = '\033[4m'
|
||||
|
||||
|
||||
DEFAULT_OPENOCD_EXEC_FILE_PATH = os.path.join("openocd", "bin", "openocd.exe")
|
||||
DEFAULT_OPENOCD_SCRIPTS_PATH = os.path.join("openocd", "share", "openocd", "scripts")
|
||||
DEFAULT_OPENOCD_SCRIPTS_PATH = os.path.join(
|
||||
"openocd", "share", "openocd", "scripts")
|
||||
|
||||
supported_formats = [".hex"]
|
||||
|
||||
|
||||
def test_connection():
|
||||
output = ""
|
||||
with OpenOcdTclRpc() as openocd:
|
||||
output = openocd.run(f"capture \"reg\"")
|
||||
|
||||
|
||||
if output == "":
|
||||
raise Exception("ERROR: no regs found, check MCU connection")
|
||||
|
||||
|
||||
def upload_file(filename: str, boot_source: str = "eeprom", is_resume=True) -> int:
|
||||
def read_file(filename: str) -> List[Tuple[int, List[int]]] :
|
||||
segments: List[Tuple[int, List[int]]] = []
|
||||
lines: List[str] = []
|
||||
|
||||
file_name, file_extension = os.path.splitext(filename)
|
||||
if file_extension in supported_formats:
|
||||
with open(filename) as f:
|
||||
lines = f.readlines()
|
||||
elif file_extension == ".bin":
|
||||
with open(filename, "rb") as f:
|
||||
contents = list(f.read())
|
||||
segments[0] = (0, contents)
|
||||
else:
|
||||
raise Exception("Unsupported file format: %s" % (file_extension))
|
||||
|
||||
for line in lines:
|
||||
record: Tuple[RecordType, List[int]]
|
||||
if file_extension == ".hex":
|
||||
record =
|
||||
|
||||
|
||||
return segments
|
||||
|
||||
|
||||
def get_content(filename: str) -> List[int]:
|
||||
content: List[int] = []
|
||||
|
||||
if filename.endswith(".bin"):
|
||||
content = parse_bin(filename)
|
||||
elif filename.endswith(".hex"):
|
||||
content = parse_hex(filename)[0]
|
||||
else:
|
||||
|
||||
|
||||
return content
|
||||
|
||||
|
||||
def upload_file(filename: str, boot_source: str = "undefined", is_resume=True) -> int:
|
||||
"""
|
||||
Write ihex or binary file into MIK32 EEPROM or external flash memory
|
||||
|
||||
@ -76,13 +119,12 @@ def upload_file(filename: str, boot_source: str = "eeprom", is_resume=True) -> i
|
||||
result = spifi_write_file(get_content(filename), is_resume)
|
||||
elif boot_source == "ram":
|
||||
write_file(filename, is_resume)
|
||||
result = 0 # TODO
|
||||
result = 0 # TODO
|
||||
else:
|
||||
raise Exception("Unsupported boot source, use eeprom or spifi")
|
||||
result = 1
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
def show_file(filename: str, boot_source: str = "eeprom"):
|
||||
@ -104,7 +146,7 @@ def createParser():
|
||||
parser.add_argument('filepath', nargs='?')
|
||||
parser.add_argument('--show-file', action="store_const", const=True)
|
||||
parser.add_argument('--no-upload', action="store_const", const=True)
|
||||
parser.add_argument('-b', '--boot-mode', default='eeprom')
|
||||
parser.add_argument('-b', '--boot-mode', default='undefined')
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
3
parsers/parser_hex.py
Normal file
3
parsers/parser_hex.py
Normal file
@ -0,0 +1,3 @@
|
||||
from parsers import RecordType
|
||||
|
||||
def parse(str) ->
|
||||
16
parsers/parsers.py
Normal file
16
parsers/parsers.py
Normal file
@ -0,0 +1,16 @@
|
||||
from enum import Enum
|
||||
from typing import List, Tuple
|
||||
import parser_hex
|
||||
|
||||
|
||||
class RecordType(Enum):
|
||||
DATA = 1
|
||||
|
||||
|
||||
def parse_line(line: str, file_extension: str) -> Tuple[RecordType, List[int]]:
|
||||
record: Tuple[RecordType, List[int]]
|
||||
|
||||
if file_extension == ".hex":
|
||||
|
||||
|
||||
return record
|
||||
Loading…
Reference in New Issue
Block a user