#/usr/bin/perl -w # # Generator of single S3 records for EEPROM branding # # author: Ned Konz # date: Fri Nov 18 11:56:20 PST 2005 # license: public domain # sub usage { print STDERR "usage: perl srecord.pl [...] where start-address is a C number literal (1234, 0x1234, or 01234) and typeflags is a string of one or more Perl pack() codes, including: c 1 byte integer v unsigned short (2 byte) integer, little-endian V unsigned long (4 byte) integer, little-endian H* hex string of arbitrary length if data is '-' then number/hex string is read from stdin "; } # Main program if ($#ARGV < 2) { usage(); exit(1); } our $startAddress = shift(); $startAddress= oct($startAddress) if $startAddress =~ /^0/; our $typeFlag = shift(); our @data = (); foreach my $arg (@ARGV) { if ($arg eq '-') { $arg = ; } else { $arg = oct($arg) if $arg =~ /^0/; } push @data, $arg; } if ($type = ($typeFlag =~ m/[a-zA-Z]/)) { # first, pack both the data and start address my $packed = pack($typeFlag, @data); my $packedAddress = pack("V*", $startAddress); # so we can generate the checksum my $checksum = (~ unpack("%*A*", $packedAddress . $packed)) & 0xff; my $sLength = 5 + length($packed); printf("S3%02x%08x%s%02x\n", $sLength, $startAddress, unpack("H*", $packed), $checksum); } else { usage(); exit(2); }