Skip to content

Instantly share code, notes, and snippets.

@b23prodtm
Last active January 26, 2023 13:40
Show Gist options
  • Save b23prodtm/6c3815ad668e50082de590bcf8af8169 to your computer and use it in GitHub Desktop.
Save b23prodtm/6c3815ad668e50082de590bcf8af8169 to your computer and use it in GitHub Desktop.
AMD Radeon 7xxx Rom creator for Mac UEFI port mapping (+apple gray screen+mojave)

dump bios from your 77xx-79xx card and save it into this folder as cardname.rom find your 4 digit deviceid (if its 697a1002, then obviously you need only 697a, since 1002 is ATI vendor id (dont be stupid here, please)) run script, replace 697a with your deviceid and cadname.rom with your actual original video bios file

./makerom.sh --efifile=7950mac.efi --romfile=efiromheader.rom --originalrom=cardname.rom --devid=697a

WARNING, if you have uefi part in bios already (e.g. if its much larger than 65kb) then it will be overwritten with new efi part ORIGINAL ROM CREATOR 7xxx Efi Test

Getting started

Download mega bundle application files (amvbflash only works on linux systems you might have a Live CD to get started with Linux environment)

  • Open a Mac OS Terminal session, enter cd then Go to bundle/ folder with the Finder and drag the folder onto the terminal and hit enter. You should be in bundle/ folder and then execute ./makerom.sh -h to get the command line printed that you can copy paste.
  • Make change to Hex Edit 7950mac.efi or 7870mac.efi (card product name's essential)
  • Change --originalrom=toyourcard.rom --devid=toperipheralpciid (the part beyond 0x1002 e.g. 0x6819). Use System profiler to get more information on specific card's PCIE extensions.

Here follow successful card patterns patched to Mac EFI from the 7950 efi:

HIS ICEQX 7850 2GB Dell HD 7450 4GB

Remember to rom-parser/rom-fixer checksum efi.rom files

#!/usr/bin/python
# FIXED: UnicodeDecodeError range 128 for ascii
class RawData:
data = []
def __init__(self, data, offset=0):
"""
simply copies data
"""
self.data = data[:]
def __repr__(self):
"""
represents the data as a string
"""
return "RawData (size=%d)" % len(self.data)
def dump(self, file):
"""
simple passthrough
"""
for i in self.data[:]:
try:
file.write(i)
except UnicodeDecodeError:
file.write(chr(ord(i) >> 1))
#return ''.join(self.data)
def fix(self):
"""
do nothing
"""
pass
class OpRom:
data = []
indicator_offset = 0
next_rom = None
def __init__(self, data, offset=0):
"""
splits the data stream in a chained list of OpRom objects
"""
if ord(data[0]) != 0x55 or ord(data[1]) != 0xaa:
raise TypeError("OpRom at %d is not valid" % offset)
rom_len = ord(data[2]) * 512
if len(data) < rom_len:
raise TypeError("OpRom at %d is too short" % offset)
self.data = list(data[:rom_len])
self.indicator_offset = ord(data[0x18]) + ord(data[0x19]) * 256 + 0x15
if len(data) > rom_len:
try:
self.next_rom = OpRom(data[rom_len:], offset + rom_len)
except TypeError:
self.next_rom = RawData(data[rom_len:], offset + rom_len)
def __repr__(self):
"""
represents the OpRom list as a string
"""
rom_repr = "OpRom (size=%d, indicator_offset=0x%x, "\
"indicator=0x%x, checksum=0x%x)"\
% (len(self.data), self.indicator_offset,
ord(self.data[self.indicator_offset]), ord(self.data[-1]))
if self.next_rom is not None:
rom_repr = '\n'.join([rom_repr, repr(self.next_rom)])
return rom_repr
def dump(self, file):
"""
dumps the list of OpRom objects
"""
for i in self.data[:]:
try:
file.write(i)
except UnicodeDecodeError:
file.write(chr(ord(i) >> 1))
if self.next_rom is not None:
self.next_rom.dump(file)
# return ''.join(self.data) + self.next_rom.dump()
#else:
# return ''.join(self.data)
def fix(self):
"""
fixes the last_rom_indicator and the checksum
"""
# last_rom_indicator
indicator = ord(self.data[self.indicator_offset])
if self.next_rom is not None and isinstance(self.next_rom, OpRom):
indicator &= 0x7F # force msb to 0
else:
indicator |= 0x80 # force msb to 1
indicator = indicator >> 1 # fix ascii range 128
self.data[self.indicator_offset] = chr(indicator)
# checksum
sum = 0
for i in self.data[:-1]:
sum = (sum + ord(i)) % 0xFF
self.data[-1] = chr(0xFF - sum)
if self.next_rom is not None:
self.next_rom.fix()
if __name__ == "__main__":
import sys, codecs
if len(sys.argv) != 3:
print("Usage: %s <infile> <outfile>\n" % sys.argv[0])
sys.exit(1)
f=codecs.open(sys.argv[1], "r", "latin_1")
op_rom = OpRom(f.read())
f.close()
print("Before:")
print(op_rom)
op_rom.fix()
print("\nAfter:")
print(op_rom)
f=codecs.open(sys.argv[2], "w", "latin_1")
op_rom.dump(f)
f.close()
#!/bin/bash
HELP=0
EFICOMPRESSNAME="EfiCompress.macosx"
if [ -n $PADDING ]; then
echo "..padding set $PADDING bytes"
else
PADDING=0
fi
for i in $*
do
case $i in
--romfile=*)
ROMFILE=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
--efifile=*)
EFIFILE=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
--devid=*)
DEVID=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
--originalrom=*)
ORIGROM=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
--help)
HELP=1
;;
*)
HELP=1
;;
esac
done
if [[ "$HELP" == 1 ]];
then
echo "Example: $0 --efifile=7950mac.efi --romfile=efiromheader.rom --originalrom=7950.rom --devid=6918"
exit -1
fi
echo "running on $EFIFILE, $ROMFILE with devid $DEVID"
java PatchRom "$EFIFILE" "$ROMFILE" "$DEVID"
if [ -a $EFICOMPRESSNAME ]
then
"$PWD/$EFICOMPRESSNAME" "$EFIFILE" "$EFIFILE.comp"
else
echo "$EFICOMPRESSNAME is missing, aborting"
exit -1
fi
cp "$ROMFILE" "$DEVID.efipart.rom"
dd if="$EFIFILE.comp" of="$DEVID.efipart.rom" bs=1 seek="$((0x160))" conv=notrunc
echo "EFI part is ready at $DEVID.efipart.rom"
size=`java getSize "$ORIGROM"`
origbytes=`wc -c < "$ORIGROM"`
EFIROM="$ORIGROM.efi.rom"
cp "$ORIGROM" "$EFIROM"
dd if="$DEVID.efipart.rom" of="$EFIROM" bs=1 seek="$(($PADDING + $size))" conv=notrunc
size=`java getSize "$EFIROM"`
python fixrom.py "$EFIROM" "$EFIROM"
size=`java getSize "$EFIROM"`
efirombytes=`wc -c < "$EFIROM"`
rm "$DEVID.efipart.rom" "$EFIFILE.comp"
if [ $efirombytes -ne $origbytes ]; then
echo "Final rom size ($efirombytes bytes) must match original rom ($origbytes bytes), fixing that..."
sleep 2
PADDING=$(($origbytes - $efirombytes)) "$0" "$*" > /dev/null
fi
echo "the rom is ready at $EFIROM"
@b23prodtm
Copy link
Author

Orignal bundle app to patch EFI http://rghost.ru/19375601

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment