Showing posts with label Mac. Show all posts
Showing posts with label Mac. Show all posts

Thursday, June 07, 2012

EDID

This post is about Extended Display Identification Data.
It's the information your monitor or TV sends to your PC or media player to let it know what video/audio formats are supported. Most of the time it's correct and everything works like you want it to. There are several reasons to modify or override the EDID data coming from your TV/monitor via the DDC2B protocol (I2C address 0x50 and 0x30).
  • Get higher refreshrates than 60Hz.
  • Solve ghosting or other quirks in 3D interlaced/checkerboard mode.
  • Tell attached equipment to pass DTS audio. Your TV often does not know that your audio receiver can handle DTS.
First, some fiddling with OSX to retrieve EDID data from attached display:


IORegistryExplorer
ioreg -l | grep -5 IODisplayEDID
IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/P0P2@1/IOPCI2PCIBridge/GFX0@0/ATY,Cattail@1/ATIFramebufferNI/display0/AppleDisplay

Returns some long number...
00ffffffffffff001e6d01000101010101150103801009780aee91a3544c99260f5054a10800714f8180010101010101010101010101023a801871382d40582c4500a05a0000001e1b2150a051001e3048883500a05a0000001c000000fd003a3e1e5310000a202020202020000000fc004c472054560a2020202020202001e2020337f14e101f8413051403021220212215012615075009570778030c001000b82d20c00e01400a3c08101810981058103810e3050301011d8018711c1620582c2500a05a0000009e011d007251d01e206e285500a05a0000001e023a801871382d40582c4500a05a0000001e00000000000000000000000000000000000031

Save that to EDID.txt or something and look at the details with edid-decode.
cat EDID.txt | xxd -r -p | ./edid-decode

Now we want to tinker with it! There are some options to do that.

Phoenix EDID Designer (Windows, yuck)This program accepts only files in a special format, so we need to convert it somehow.

cat EDID.txt | xxd -r -p | (echo 'EDID BYTES:';\
echo '0x   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F';\
echo '    ------------------------------------------------';\
xxd -g 1 -c 16 | sed -E 's/00000(..): (.{47}).*/\1 | \2/g'\
) | tr abcdef ABCEDF | sed 's/$'"/`printf '\r'`/g" > conv.dat

Compare the exported raw data with original:
cat EDID.txt | xxd -r -p | ./edid-decode > left.txt
cat exported.raw | ./edid-decode > right.txt
diff left.txt right.txt

The new data will show:
EDID block does NOT conform to EDID 1.3!
Missing monitor ranges
That's too bad!

010 Editor

I made a template file for 010 Editor, which is a nifty binary editor.
Download the template here.
Somehow they did not put the CRC fixing script (.1sc extension) there, but it's quite short:

file.checksum = -Checksum(CHECKSUM_SUM8, startof(file), startof(file.checksum) - startof(file));
local int i;
for (i=0; exists(file.extensions[i]); i++) file.extensions[i].checksum = -Checksum(CHECKSUM_SUM8, startof(file.extensions[i]), 127);



That's pretty neat uh?

Create EDID override file for OS X (method 1)

Assuming you have saved the modified exported.raw, generate a hex dump like so:


xxd -ps exported.raw

Create a plist file (without extension) and open with XCode or Property List Editor.
/System/Library/Displays/Overrides/DisplayVendorID-1e6d/DisplayProductID-1
The VID/PID in the directory/filename are in unpadded lowercase hexadecimal format.

DisplayProductName String "My modified display name"
DisplayProductID Number 1 (displayed in decimal)
DisplayVendorID Number 7789 (displayed in decimal)
IODisplayEDID Data <00ffffff...> (paste the data between brackets)

Create EDID override file for OS X (method 2)

Paste the result of
(echo -n '<data>'; (cat exported.raw | base64 | tr -d '\n'); echo '</data>')
into the override file (see method 1) where you can use the following as a base:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>DisplayProductID</key>
    <integer>1</integer>
    <key>DisplayProductName</key>
    <string>My modified display name</string>
    <key>DisplayVendorID</key>
    <integer>7789</integer>
    <key>IODisplayEDID</key>
    <data>AP///////wAdbgEAAQEBAQEVAQOAEAl4Ct2Ro1RMmSYPUFShCABxT4GAAQEBAQEBAQEBAQEBAjqAGHE4LkBYLEUAoFoAAAAdAjqAGHE4LkBYLEUAoFoAAAA8AAAAEAA6PR1TEAAKICAgICAgAAAAEABMRyBUVgogICAgICAgAco=</data>
</dict>
</plist>

todo...

Somehow, the resolution went back to 960x540 (HiDPI) whenever I change the EDID and replug my video connector.
Also, I have to find out how to reprogram my LG TV with new EDID data. There is some option in the service menu, but haven't looked how to do it yet.
It's nice that I can override EDID data in OS X, but I cannot override it on my PS3 for example. Thus, I need the optical audio output if I want DTS.

Links:
Video timing calculator
EDID 1.3 data format

Wednesday, April 28, 2010

Windows on Intel Mac and AHCI mode

My configuration:
single internal hard drive in iMac with a single NTFS partition. This is BIOS identifier (hd0,1). In linux, this will be SATA device /dev/sda. The SATA controller is from ICH8M and has PCI identifier 8086:2828. Please change these references to your system configuration.
Don't worry, I still have OS X on an external FW800 drive but that's not relevant here.

First of all, I tried loading Windows 7 on my Intel Mac and then came to a few conclusions:
  • BIOS mode boot has the negative side-effect that it disables AHCI mode in the SATA controller. This leads to degraded performance of hard drive access.
  • EFI mode boot of Windows 7 requires EFI 2.0 which isn't included in the firmware.
  • Macs don't like to boot from external devices. Windows doesn't like to be installed on external drives.
So I swapped my OS X drive with Windows drive in the process of undusting my iMac. It now can boot both OSes.
This post is all about getting the SATA controller back into AHCI mode after the compatibility layer in the intel Mac changed it. AHCI gives NCQ and might be somewhat faster so I really wanted to try that after my younger brother nagged me about it during our dayly Mac-vs-PC argues.

I can talk about what I did wrong during those attempts but I will try to keep it short:
  • Start regedit and locate the following key: HKLM\System\CurrentControlSet\Services\msahci
    Change the "Start" value to "0". This will make Windows attempt to load the AHCI driver stack when it boots.
  • Download a Linux live-CD with GRUB 1.98. (others might indicate 0.xx as grub and 1.xx as grub2). I decided on the latest Ubuntu live-CD. Older versions just won't do unless you want ugly patches. You want to have the setpci grub module.
  • Download the "Rapid Storage Technology" manager software (includes the driver) and the "RST Driver Files for F6 Install" from the Intel website.
    In my case the latest version for x64 Windows was iata96enu.exe and f6flpy96x64.zip
    The manager software will not install yet but you have to install at least the driver by unpacking it and force a device installation:
    Go to Device Manager, select Serial ATA Storage Controller, Update driver software, Browse, Pick from list, Have disk, Ignore the warning. This should be ok since the next time you'll boot Windows, the device will be different anyway.
  • Boot the Linux CD :-)
    Hold option key when booting the Mac to see it as a boot option. Load the System until you can start a terminal. Get root access:
    sudo -i
  • Because it booted from CD, it doesn't know much about the hard drive. Therefore create a device map file that maps (hd0) to /dev/sda.
    vi /boot/grub/device.map
    i(hd0)[tab]/dev/sda[esc]:wq
    If you know some linux, you know what I mean.
  • Mount your Windows partition in Linux.
    mkdir /mnt/win
    ntfs-3g /dev/sda1 /mnt/win
  • Install grub to the MBR and copy the data files too.
    grub-install --no-floppy --modules=ntfs --root-directory=/mnt/win /dev/sda
    This should report no error.
  • If you already had a Boot directory on your Windows partition (most likely), you'll now have two boot directories (-.-); Fix it by moving the contents.
    mv /mnt/win/boot/grub /mnt/win/Boot

    rmdir /mnt/win/boot
  • reboot
    reboot (duh)
  • At the grub prompt you should now be able to try some commands.
    lspci
    setpci -d 8086:2828 90.b=40
    lspci (should now show 2829 instead of 2828)
    root (hd0,1)
    chainloader +1
    boot
  • If Windows now boots, it should be in AHCI mode and hopefully go ask for the drivers.
    You can install the RST manager or just check the Device Manager to see if it's working as intended.
  • You can create a C:\Boot\grub\grub.cfg file to automate the booting process. (Note: 'Manual editing of /boot/grub/grub.cfg is not encouraged')
    set timeout=10
    set default=0
    menuentry "Windows 7 with AHCI" {
    setpci -d 8086:2828 90.b=40
    set root=(hd0,1)
    chainloader +1
    }
  • PS: If somehow Windows booting was not working in the first place or you don't want any of this anymore, you can use the Windows 7 DVD. Some recovery commands you then can use:
    bootrec /FixBoot

    bootrec /RebuildBcd

    bootrec /FixMbr
    (should erase grub again but I don't know why you would want that)
I this I have all my notes into this post and hope that besides me remembering how to do it, also will help you and other Mac fans :P