Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
extract_xc3028.pl 44.60 KiB
#!/usr/bin/env perl

# Copyright (c) Mauro Carvalho Chehab <mchehab@kernel.org>
# Released under GPLv2
#
# In order to use, you need to:
#	1) Download the windows driver with something like:
#	Version 2.4
#		wget http://www.twinhan.com/files/AW/BDA T/20080303_V1.0.6.7.zip
#		or wget http://www.stefanringel.de/pub/20080303_V1.0.6.7.zip
#	Version 2.7
#		wget http://www.steventoth.net/linux/xc5000/HVR-12x0-14x0-17x0_1_25_25271_WHQL.zip
#	2) Extract the files from the zip into the current dir:
#		unzip -j 20080303_V1.0.6.7.zip 20080303_v1.0.6.7/UDXTTM6000.sys
#		unzip -j HVR-12x0-14x0-17x0_1_25_25271_WHQL.zip Driver85/hcw85bda.sys
#	3) run the script:
#		./extract_xc3028.pl
#	4) copy the generated files:
#		cp xc3028-v24.fw /lib/firmware
#		cp xc3028-v27.fw /lib/firmware

#use strict;
use IO::Handle;

my $debug=0;

sub verify ($$)
{
	my ($filename, $hash) = @_;
	my ($testhash);

	if (system("which md5sum > /dev/null 2>&1")) {
		die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
	}

	open(CMD, "md5sum ".$filename."|");
	$testhash = <CMD>;
	$testhash =~ /([a-zA-Z0-9]*)/;
	$testhash = $1;
	close CMD;
		die "Hash of extracted file does not match (found $testhash, expected $hash!\n" if ($testhash ne $hash);
}

sub get_hunk ($$)
{
	my ($offset, $length) = @_;
	my ($chunklength, $buf, $rcount, $out);

	sysseek(INFILE, $offset, SEEK_SET);
	while ($length > 0) {
	# Calc chunk size
		$chunklength = 2048;
		$chunklength = $length if ($chunklength > $length);

		$rcount = sysread(INFILE, $buf, $chunklength);
		die "Ran out of data\n" if ($rcount != $chunklength);
		$out .= $buf;
		$length -= $rcount;
	}
	return $out;
}

sub write_le16($)
{
	my $val = shift;
	my $msb = ($val >> 8) &0xff;
	my $lsb = $val & 0xff;

	syswrite(OUTFILE, chr($lsb).chr($msb));
}