1717 lines · 44.6 KB · Perl
RawDownload
#!/usr/bin/env perl # Copyright (c) Mauro Carvalho Chehab <mchehab@infradead.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));} sub write_le32($){	my $val = shift;	my $l3 = ($val >> 24) & 0xff;	my $l2 = ($val >> 16) & 0xff;	my $l1 = ($val >> 8)  & 0xff;	my $l0 = $val         & 0xff; 	syswrite(OUTFILE, chr($l0).chr($l1).chr($l2).chr($l3));} sub write_le64($$){	my $msb_val = shift;	my $lsb_val = shift;	my $l7 = ($msb_val >> 24) & 0xff;	my $l6 = ($msb_val >> 16) & 0xff;	my $l5 = ($msb_val >> 8)  & 0xff;	my $l4 = $msb_val         & 0xff; 	my $l3 = ($lsb_val >> 24) & 0xff;	my $l2 = ($lsb_val >> 16) & 0xff;	my $l1 = ($lsb_val >> 8)  & 0xff;	my $l0 = $lsb_val         & 0xff; 	syswrite(OUTFILE,		 chr($l0).chr($l1).chr($l2).chr($l3).		 chr($l4).chr($l5).chr($l6).chr($l7));} sub write_hunk($$){	my ($offset, $length) = @_;	my $out = get_hunk($offset, $length); 	printf "(len %d) ",$length if ($debug); 	for (my $i=0;$i<$length;$i++) {		printf "%02x ",ord(substr($out,$i,1)) if ($debug);	}	printf "\n" if ($debug); 	syswrite(OUTFILE, $out);} sub write_hunk_fix_endian($$){	my ($offset, $length) = @_;	my $out = get_hunk($offset, $length); 	printf "(len_fix %d) ",$length if ($debug); 	for (my $i=0;$i<$length;$i++) {		printf "%02x ",ord(substr($out,$i,1)) if ($debug);	}	printf "\n" if ($debug); 	my $i=0;	while ($i<$length) {		my $size = ord(substr($out,$i,1))*256+ord(substr($out,$i+1,1));		syswrite(OUTFILE, substr($out,$i+1,1));		syswrite(OUTFILE, substr($out,$i,1));		$i+=2;		if ($size>0 && $size <0x8000) {			for (my $j=0;$j<$size;$j++) {				syswrite(OUTFILE, substr($out,$j+$i,1));			}			$i+=$size;		}	}} sub main_firmware_24($$$$){	my $out;	my $j=0;	my $outfile = shift;	my $name    = shift;	my $version = shift;	my $nr_desc = shift; 	for ($j = length($name); $j <32; $j++) {		$name = $name.chr(0);	} 	open OUTFILE, ">$outfile";	syswrite(OUTFILE, $name);	write_le16($version);	write_le16($nr_desc); 	#	# Firmware 0, type: BASE FW   F8MHZ (0x00000003), id: (0000000000000000), size: 6635	# 	write_le32(0x00000003);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(6635);			# Size	write_hunk_fix_endian(257752, 6635); 	#	# Firmware 1, type: BASE FW   F8MHZ MTS (0x00000007), id: (0000000000000000), size: 6635	# 	write_le32(0x00000007);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(6635);			# Size	write_hunk_fix_endian(264392, 6635); 	#	# Firmware 2, type: BASE FW   FM (0x00000401), id: (0000000000000000), size: 6525	# 	write_le32(0x00000401);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(6525);			# Size	write_hunk_fix_endian(271040, 6525); 	#	# Firmware 3, type: BASE FW   FM INPUT1 (0x00000c01), id: (0000000000000000), size: 6539	# 	write_le32(0x00000c01);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(6539);			# Size	write_hunk_fix_endian(277568, 6539); 	#	# Firmware 4, type: BASE FW   (0x00000001), id: (0000000000000000), size: 6633	# 	write_le32(0x00000001);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(6633);			# Size	write_hunk_fix_endian(284120, 6633); 	#	# Firmware 5, type: BASE FW   MTS (0x00000005), id: (0000000000000000), size: 6617	# 	write_le32(0x00000005);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(6617);			# Size	write_hunk_fix_endian(290760, 6617); 	#	# Firmware 6, type: STD FW    (0x00000000), id: PAL/BG A2/A (0000000100000007), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000001, 0x00000007);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(297384, 161); 	#	# Firmware 7, type: STD FW    MTS (0x00000004), id: PAL/BG A2/A (0000000100000007), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x00000001, 0x00000007);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(297552, 169); 	#	# Firmware 8, type: STD FW    (0x00000000), id: PAL/BG A2/B (0000000200000007), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000002, 0x00000007);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(297728, 161); 	#	# Firmware 9, type: STD FW    MTS (0x00000004), id: PAL/BG A2/B (0000000200000007), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x00000002, 0x00000007);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(297896, 169); 	#	# Firmware 10, type: STD FW    (0x00000000), id: PAL/BG NICAM/A (0000000400000007), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000004, 0x00000007);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(298072, 161); 	#	# Firmware 11, type: STD FW    MTS (0x00000004), id: PAL/BG NICAM/A (0000000400000007), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x00000004, 0x00000007);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(298240, 169); 	#	# Firmware 12, type: STD FW    (0x00000000), id: PAL/BG NICAM/B (0000000800000007), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000008, 0x00000007);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(298416, 161); 	#	# Firmware 13, type: STD FW    MTS (0x00000004), id: PAL/BG NICAM/B (0000000800000007), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x00000008, 0x00000007);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(298584, 169); 	#	# Firmware 14, type: STD FW    (0x00000000), id: PAL/DK A2 (00000003000000e0), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000003, 0x000000e0);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(298760, 161); 	#	# Firmware 15, type: STD FW    MTS (0x00000004), id: PAL/DK A2 (00000003000000e0), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x00000003, 0x000000e0);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(298928, 169); 	#	# Firmware 16, type: STD FW    (0x00000000), id: PAL/DK NICAM (0000000c000000e0), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x0000000c, 0x000000e0);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(299104, 161); 	#	# Firmware 17, type: STD FW    MTS (0x00000004), id: PAL/DK NICAM (0000000c000000e0), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x0000000c, 0x000000e0);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(299272, 169); 	#	# Firmware 18, type: STD FW    (0x00000000), id: SECAM/K1 (0000000000200000), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000000, 0x00200000);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(299448, 161); 	#	# Firmware 19, type: STD FW    MTS (0x00000004), id: SECAM/K1 (0000000000200000), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x00000000, 0x00200000);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(299616, 169); 	#	# Firmware 20, type: STD FW    (0x00000000), id: SECAM/K3 (0000000004000000), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000000, 0x04000000);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(299792, 161); 	#	# Firmware 21, type: STD FW    MTS (0x00000004), id: SECAM/K3 (0000000004000000), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x00000000, 0x04000000);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(299960, 169); 	#	# Firmware 22, type: STD FW    D2633 DTV6 ATSC (0x00010030), id: (0000000000000000), size: 149	# 	write_le32(0x00010030);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(300136, 149); 	#	# Firmware 23, type: STD FW    D2620 DTV6 QAM (0x00000068), id: (0000000000000000), size: 149	# 	write_le32(0x00000068);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(300296, 149); 	#	# Firmware 24, type: STD FW    D2633 DTV6 QAM (0x00000070), id: (0000000000000000), size: 149	# 	write_le32(0x00000070);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(300448, 149); 	#	# Firmware 25, type: STD FW    D2620 DTV7 (0x00000088), id: (0000000000000000), size: 149	# 	write_le32(0x00000088);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(300608, 149); 	#	# Firmware 26, type: STD FW    D2633 DTV7 (0x00000090), id: (0000000000000000), size: 149	# 	write_le32(0x00000090);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(300760, 149); 	#	# Firmware 27, type: STD FW    D2620 DTV78 (0x00000108), id: (0000000000000000), size: 149	# 	write_le32(0x00000108);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(300920, 149); 	#	# Firmware 28, type: STD FW    D2633 DTV78 (0x00000110), id: (0000000000000000), size: 149	# 	write_le32(0x00000110);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(301072, 149); 	#	# Firmware 29, type: STD FW    D2620 DTV8 (0x00000208), id: (0000000000000000), size: 149	# 	write_le32(0x00000208);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(301232, 149); 	#	# Firmware 30, type: STD FW    D2633 DTV8 (0x00000210), id: (0000000000000000), size: 149	# 	write_le32(0x00000210);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(149);			# Size	write_hunk_fix_endian(301384, 149); 	#	# Firmware 31, type: STD FW    FM (0x00000400), id: (0000000000000000), size: 135	# 	write_le32(0x00000400);			# Type	write_le64(0x00000000, 0x00000000);	# ID	write_le32(135);			# Size	write_hunk_fix_endian(301554, 135); 	#	# Firmware 32, type: STD FW    (0x00000000), id: PAL/I (0000000000000010), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000000, 0x00000010);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(301688, 161); 	#	# Firmware 33, type: STD FW    MTS (0x00000004), id: PAL/I (0000000000000010), size: 169	# 	write_le32(0x00000004);			# Type	write_le64(0x00000000, 0x00000010);	# ID	write_le32(169);			# Size	write_hunk_fix_endian(301856, 169); 	#	# Firmware 34, type: STD FW    (0x00000000), id: SECAM/L AM (0000001000400000), size: 169	# 	#	# Firmware 35, type: STD FW    (0x00000000), id: SECAM/L NICAM (0000000c00400000), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x0000000c, 0x00400000);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(302032, 161); 	#	# Firmware 36, type: STD FW    (0x00000000), id: SECAM/Lc (0000000000800000), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000000, 0x00800000);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(302200, 161); 	#	# Firmware 37, type: STD FW    (0x00000000), id: NTSC/M Kr (0000000000008000), size: 161	# 	write_le32(0x00000000);			# Type	write_le64(0x00000000, 0x00008000);	# ID	write_le32(161);			# Size	write_hunk_fix_endian(302368, 161); 	#	# Firmware 38, type: STD FW    LCD (0x00001000), id: NTSC/M Kr (0000000000008000), size: 161

Lines 1–500 of 1717.