Skip to content

Commit

Permalink
Merge remote-tracking branch 'travis/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
roelandjansen committed Jul 9, 2019
2 parents b7e35cd + 1efea42 commit 5be66a3
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ md380tools@googlegroups.com. So feel free to put in your questions into it!

A few of us are also on the #md380 IRC channel on Freenode.

A helpful site is available at http://md380.tools/
A helpful site is available at http://md380.org/

There are also some related groups you may find interesting:
- https://www.facebook.com/groups/KD4ZToolkit/
Expand Down
22 changes: 17 additions & 5 deletions docs/macos.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# MacOS specifics #
# MacOS specifics #

## Preparing build environment ##

#### With Homebrew: ####

brew update
brew upgrade
brew install binutils libusb
brew cask install gcc-arm-embedded # This is where you get the ARM cross-compiling stuff
sudo easy_install pip
brew tap armmbed/formulae # This is where you get the ARM cross-compiling stuff
brew install binutils libusb armmbed/formulae/arm-none-eabi-gcc
sudo easy_install pip # See below for methods that don't require sudo access
sudo pip2 install pyusb

#### Fix the environment statements: ####
Expand All @@ -17,5 +17,17 @@ The scripts look for python2, but you likely just have that installed as (system

sudo ln -s /usr/bin/python /usr/bin/python2

#### Alternative no-`sudo` method - install Python 2 from Homebrew: ####

brew install python2
pip2 install pyusb

#### Alternative no-`sudo` method - use `virtualenv`: ####

python2 -m virtualenv path/to/md380-virtualenv # Modify to your environment
. path/to/md380-virtualenv/bin/activate
which python2 || ln -s python path/to/md380-virtualenv/bin/python2 # Most likely unnecessary
which pip2 || ln -s pip path/to/md380-virtualenv/bin/pip2 # Most likely unnecessary
pip2 install pyusb

After this, `make flash` as expected.

10 changes: 5 additions & 5 deletions firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ OPT = download
else
endif

all: unwrapped/D002.032.img unwrapped/S013.020.img unwrapped/D013.020.img unwrapped/D003.020.img
all: unwrapped/D002.032.img unwrapped/S013.020.img unwrapped/D013.020.img unwrapped/D003.020.img unwrapped/D14.07.img

clean:
"${MAKE}" -f Makefile_orig clean

download:
"${MAKE}" -f Makefile_orig download

unwrapped/%.img: $(OPT)
"${MAKE}" -f Makefile_orig $@
"${MAKE}" -f Makefile_orig $@
2 changes: 2 additions & 0 deletions firmware/firmware_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ MD280.002.018.bin https://md380.org/firmware/orig/MD280.002.018.bin MD280.002.01
MD446.D003.020.bin https://md380.org/firmware/orig/TYT-TFT-MD446-D3.20.bin TYT-TFT-MD446-D3.20.bin 996864 9892b2e95da0eee0ec87604007f157f6f9b249a9fb11ba0fc3798e78956e2587
MD446.D013.020.bin https://md380.org/firmware/orig/TYT-Vocoder-MD446-D13.20.bin TYT-TFT-MD446-D13.20.bin 995840 6b83a74b72df4b13f74f5ac7ef2472593809055fc252c0aabe4c9eeeef1f115c
D013.034.bin http://w2fbi.com/files/MD380/D013.034.bin D013.034.bin 996864 c375de54f172346d3f9aecc73cbfa024e753b482e484765b1a890182cfac157e
D14.07.bin https://md380.org/firmware/orig/TYT-Vocoder-MD380-D14.07.bin D14.07.bin 996864 e0a65ef4ba358abd66ce7041b571df5a1b3047b9f113d3cad6f8ab99b6e972be

21 changes: 13 additions & 8 deletions md380_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ def read_framebuf_line(self, y):
chr(0) + # x1 (x1,y1) = tile's upper left corner
chr(y) + # y1
chr(159) + # x2 (x2,y2) = tile's lower right corner
chr(y) # y2
chr(y) # y2
)
self._device.ctrl_transfer(0x21, Request.DNLOAD, 1, 0, cmdstr)
self.get_status() # this changes state
status = self.get_status() # this gets the status
# read 5-byte header (echo of cmdstr) followed by
# read 5-byte header (echo of cmdstr) followed by
# 160 pixels per line * 3 bytes per pixel (BLUE,GREEN,RED):
rd_result = self.upload(1, 160*3+5, 0);
if rd_result[4] == y: # y2 ok -> got the expected response
Expand Down Expand Up @@ -282,8 +282,8 @@ def custom(self, cmd):
status = self.get_status() # this gets the status

def reboot_to_bootloader(self):
"""Reboot into the bootloader with a DFU command.
This will erase (part of) the firmware from flash,
"""Reboot into the bootloader with a DFU command.
This will erase (part of) the firmware from flash,
so you must reprogram the firmware afterwards if you'd like a working radio.
"""
cmd = 0x86 # reboot_to_bootloader
Expand Down Expand Up @@ -427,8 +427,8 @@ def screenshot(dfu, filename="screenshot.bmp"):
with open(filename, 'wb') as f:
# Write a simple, hard-coded bitmap file header
# (14 byte "file header" + 40 byte "info block" + 3*160*128 byte "data",
# total size = 0x0000F036 bytes. Here written in little endian format:
f.write( "BM" + chr(0x36)+chr(0xF0)+chr(0x00)+chr(0x00)
# total size = 0x0000F036 bytes. Here written in little endian format:
f.write( "BM" + chr(0x36)+chr(0xF0)+chr(0x00)+chr(0x00)
+ chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)
+ chr( 54 )+chr(0x00)+chr(0x00)+chr(0x00) )
# Next: Write the "bitmap info header". Keep it simple, use 40 bytes.
Expand All @@ -446,7 +446,7 @@ def screenshot(dfu, filename="screenshot.bmp"):
# Write image data with 160 pixels per line, 3 bytes per pixel.
# For a start, just dump the pixels to the file unmodified.
y = 127; # bmp files begin with the 'bottom line' (y=127)
while y>=0:
while y>=0:
buf = dfu.read_framebuf_line(y)
f.write(buf)
y = y-1;
Expand Down Expand Up @@ -751,7 +751,7 @@ def usage():
md380-tool readword <0xcafebabe>
Dump 1kB from arbitrary address
md380-tool dump <filename.bin> <address>
Dump calibration data
Dump calibration data
md380-tool calibration
Reboot into the bootloader (erases application, you _must_ reflash firmware afterwards):
md380-tool reboot_to_bootloader
Expand Down Expand Up @@ -884,6 +884,11 @@ def main():
except RuntimeError as e:
print(e.args[0])
exit(1)
except usb.core.USBError as ue:
print(ue)
if ue[0] == 32:
print('Make sure the device is already flashed with custom firmware and NOT in DFU mode')
exit(1)
except Exception as e:
print(e)
# print(dfu.get_status())
Expand Down
9 changes: 5 additions & 4 deletions symbols/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.SECONDEXPANSION:


UNWRAPPED=../firmware/unwrapped
GOLD=../firmware/unwrapped/D013.020.img
GOLDSYM=../applet/src/symbols_d13.020
TEST=../firmware/unwrapped/D002.032.img

mangle = $(shell echo $(1) | sed -r "s/symbols_(.)(..)_(...)/\u\10\2\.\3\.img/")
mangle = $(shell echo $(1) | sed -r "s/symbols_(.)(..)_(...)/\u\10\2\.\3\.img/" | sed -r "s/symbols_(.)(..)_(..)/\u\1\2\.\3\.img/")

.PHONY: all clean imageclean run test

Expand All @@ -18,15 +19,15 @@ $(UNWRAPPED)/%:
cd ../firmware && "${MAKE}" unwrapped/$*

symgrate: symgrate.c
cc -std=c99 symgrate.c -o symgrate
cc -Wall -std=c99 symgrate.c -o symgrate

test: all $(GOLD) $(TEST) $(GOLDSYM)
./symgrate $(GOLD) $(TEST) <$(GOLDSYM)

symbols_%: $(UNWRAPPED)/$$(call mangle,symbols_%) symgrate $(GOLD) $(GOLDSYM)
./symgrate $(GOLD) $(UNWRAPPED)/$(call mangle,symbols_$*) <$(GOLDSYM) >$@

run: symbols_d02_034 symbols_d03_008 symbols_d03_020 symbols_d13_009 symbols_s03_012 symbols_s13_012 symbols_d13_014 symbols_s13_020 symbols_d13_020
run: symbols_d02_034 symbols_d03_008 symbols_d03_020 symbols_d13_009 symbols_s03_012 symbols_s13_012 symbols_d13_014 symbols_s13_020 symbols_d13_020 symbols_d14_07
@wc -l symbols_*
@echo "These are temporary symbol files that will be overwritten."
@echo "Move them elsewhere before editing."
@echo "Move them elsewhere before editing."
25 changes: 25 additions & 0 deletions symbols/symbols2ghidra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python

# This is a janky little parser for converting symbol files from the
# GNU LD format used in the MD380Tools project into the flat text
# files expected by GHIDRA's ImportSymbolsScript.py.

import sys;

for l in sys.stdin:
words=l.strip().split();

try:
name=words[0];
adrstr=words[2];
adr=int(adrstr.strip(";"),16);

#Fix up addresses in Flash that look like functions.
if(adr&0xFF000000==0x08000000):
adr=adr&~1;

print("%s 0x%x" % (name, adr))
except:
# Print warnings when our janky parser goes awry.
if len(words)>0 and words[0]!="/*" and words[0]!="*/":
print("#Warning in: %s\n"%words);
9 changes: 4 additions & 5 deletions symbols/symgrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int loadbuffer(char *buf, const char *filename){
//FIXME hardcoded size
len=fread(buf, 1024, 1024, f);

return 0;
return len;
}

//! Allocate the buffers.
Expand All @@ -96,8 +96,8 @@ int scorematch(int sadr, int dadr){
src16(sadr+i)==dst16(dadr+i)

//or halfwords partially agree and might be a BL.
|| ( src16(sadr+i)&0xF000 == 0xF000 &&
dst16(dadr+1)&0xF000 == 0xF000)
|| ( (src16(sadr+i)&0xF000) == 0xF000 &&
(dst16(dadr+1)&0xF000) == 0xF000)
)
&& i<1024);

Expand Down Expand Up @@ -128,7 +128,6 @@ int findsymbol(const char *name, int adr){
anything that matches a few bytes. The decision of whether to
accept the match comes later.
*/
short tofind=src16(adr);
int dadr=0, dscore=0;
for(int i=0;i<(MAXLEN);i+=2){
if(src16(adr)==dst16(BASE+i)){
Expand Down Expand Up @@ -192,7 +191,7 @@ int parseloop(){

static char name[1024];
int adr;
memset(name,1024,0);
memset(name,0,1024);

while(!feof(stdin)){
//Read the line.
Expand Down

0 comments on commit 5be66a3

Please sign in to comment.