patjak / facetimehd

Reverse engineered Linux driver for the FacetimeHD (Broadcom 1570) PCIe webcam
GNU General Public License v2.0
1.36k stars 161 forks source link

Add download and extraction script for the OS X firmware version 1.43 #27

Closed mauritiusdadd closed 8 years ago

mauritiusdadd commented 8 years ago

As I previously said in #23 and with the information in #14, I made a script that downloads the OS X .dmg file, extracts the AppleCameraInterface kext file and from it extracts the firmware of the camera. I added also a Makefile so everything one needs to do is to run make to download a extract the firmware and the run make install to install the firmware in /usr/lib/firmware/facetimehd/.

WhyNotHugo commented 8 years ago

Why not depend on the existing pbzx stream parser, rather than bundle our own python implementation?

I'm not a fan of bundling dependencies, especially if they're for helper scripts. Downstream packagers can deal with dependency issues themselves.

mauritiusdadd commented 8 years ago

Well I thought it would have been easier having a pbzx parser bundled into the repo, but if @patjak thinks it's better relying on an external dependency I'll update the script to use the latter.

mauritiusdadd commented 8 years ago

Well, @wvengen in #14 did a great job by figuring out which bytes must be retrieved from the remote file in order to get the kext file and his method does not require nor xar neither pbxz. What do you think? Shall we use his script to download the driver?

ockham commented 8 years ago

Running make on Ubuntu 15.10 gives

Error: No download agent found, use --help for more information.

even though I have both curl and wget installed, so the download agent detection logic seems to be flawed.

Jancis commented 8 years ago

You could just comment out the whole section and set the variable to wget, but i'd suggest using the other firmware download method from here https://github.com/patjak/bcwc_pcie/issues/14#issuecomment-167446787

I am running 15.10 as well, succeeded to install the driver yesterday quite easily:

  1. just download the firmware by using the method above (does not require downloading the whole image which is well over 1Gb).
  2. Edit out the checksum checking part from extract_from_osx.sh and run it to extract firmware.bin.
  3. Do the modprobe -r bdc_pci
  4. Follow the readme steps in wiki "Getting started" section - https://github.com/patjak/bcwc_pcie/wiki/Get-Started

I think this Pull Request can be cancelled and improved a bit. It works, but because it was not merged in time, there are few improvements floating around.

derjohn commented 8 years ago

On Ubuntu Trusty which ships GNU bash, Version 4.3.11(1)-release (x86_64-pc-linux-gnu) you need to deal with the array like that:

index 11d595f..ea74435 100755
--- a/firmware/download-osx.sh
+++ b/firmware/download-osx.sh
@@ -68,7 +68,7 @@ download()
   msg "Downloading the .dmg file..."
   if [[ -z "$DLOAD_AGENT" ]]; then
     msg2 "Cheching for available download agents..."  
-    for agent in $agents; do
+    for agent in ${agents[@]}; do
       if which "$agent" &> /dev/null; then
         msg2 "Found '$agent'"
         DLOAD_AGENT="$agent"

@ockham Simply change "for agent in $agents do" to " for agent in ${agents[@]}; do".

derjohn commented 8 years ago

BTW: ubuntu trusty doen't ship 'xar', but 7zip-full can process the xar format as well. I would opt to drop the requirement for 'xar', because 7zip (full) is already required.

diff --git a/firmware/extract-firmware.sh b/firmware/extract-firmware.sh
index 02c35c8..0c1c962 100755
--- a/firmware/extract-firmware.sh
+++ b/firmware/extract-firmware.sh
@@ -114,7 +114,6 @@ checkPrerequisites()
   hasProgram "python2"
   hasProgram "sha256sum"
   hasProgram "tail"
-  hasProgram "xar"
 }

 getCheckSum()
@@ -194,7 +193,7 @@ decompress_dmg()
   rm -f "5.hfs"

   msg2 "Uncompressing XAR archive..."
-  xar -x -f "OSXUpd.xar"
+  7z x -y "OSXUpd.xar"
   rm -f "OSXUpd.xar"
ockham commented 8 years ago

@derjohn Thanks for your suggestions! I've also noticed that xar is unavailable on Ubuntu, and that 7z is able to process .xar files. (So can xzcat, it seems btw.)

However, I'd agree with @Jancis that https://github.com/patjak/bcwc_pcie/issues/14#issuecomment-167446787 is probably the way to go :-)

mauritiusdadd commented 8 years ago

Ok, I like the @wvengen way too so I'm going to replace the download script, but I want to keep the ability to decompress the whole .dmg file, just in case.

@ockham: I would like remove as many dependencies as I can, but for me 7z does not work with .xar files, it tries to decompress the archive but then I only get a file named Payload~ of 512 bytes and xzcat just says the archive format is not recognized :confused:

mauritiusdadd commented 8 years ago

Just for the sake of the record:

wvengen commented 8 years ago

Thanks, looks good!

ockham commented 8 years ago

@ockham: I would like remove as many dependencies as I can, but for me 7z does not work with .xar files, it tries to decompress the archive but then I only get a file named Payload~ of 512 bytes and xzcat just says the archive format is not recognized :confused:

Hmm, depending on xar really is kind of a bummer on Ubuntu. Can you combine xzcat with cpio and dd like @wvengen did in #14? (Or maybe you can advise, @wvengen?)

mmlb commented 8 years ago

@ockham not sure what make xar a pain in ubuntu, fwiw bsdtar handles the xar files just fine and should work on the cpios also, would cut down on the number of dependencies.

wvengen commented 8 years ago

Nice point about bsdtar. Nevertheless, extracting the xar archive is only needed when the partial download (which is the default method) doesn't work - so perhaps this isn't such an issue at all.

wvengen commented 8 years ago

I would say, though, that the fallback method is more likely to work when it extracts the xar archive by unpacking it properly (instead of using offsets) - consider the unlikely case of Apple of changing the dmg.

patjak commented 8 years ago

This seems to work fine now. Thanks!