📄 wosfs_maker.pl
字号:
#!perl
#Copyright (C)1991-2003 Altera Corporation
#Any megafunction design, and related net list (encrypted or decrypted),
#support information, device programming or simulation file, and any other
#associated documentation or information provided by Altera or a partner
#under Altera's Megafunction Partnership Program may be used only to
#program PLD devices (but not masked PLD devices) from Altera. Any other
#use of such megafunction design, net list, support information, device
#programming or simulation file, or any other related documentation or
#information is prohibited for any other purpose, including, but not
#limited to modification, reverse engineering, de-compiling, or use with
#any other silicon devices, unless such use is explicitly licensed under
#a separate agreement with Altera or a megafunction partner. Title to
#the intellectual property, including patents, copyrights, trademarks,
#trade secrets, or maskworks, embodied in any such megafunction design,
#net list, support information, device programming or simulation file, or
#any other related documentation or information provided by Altera or a
#megafunction partner, remains with Altera, the megafunction partner, or
#their respective licensors. No other licenses, including any licenses
#needed under any third party's intellectual property, are provided herein.
#Copying or modifying any file, or portion thereof, to which this notice
#is attached violates this copyright.
#
# wosfs_maker is for authoring a wosfs file
# system.
#
#
use Strict;
my $kWOSFS_Signature = 0x89674523;
my $kWOSFS_FileNameSize = 32;
my $kWOSFS_VolumeHeaderSize = 8; # bytes
my $kWOSFS_DirectoryEntrySize = $kWOSFS_FileNameSize + 8;
my $kWOSFS_flashBegin = 0x160000;
my $kWOSFS_flashEnd = 0x180000;
$gDebug = 1;
$gDebug = 0;
sub dprint
{
print @_ if($gDebug);
}
sub usage
{
print <<EOP;
usage: wosfs_maker [--start <start address>] [--end <end address>] file1 [file2...]
wosfs_maker prints germsmon output for
creating a flash image in the wosfs format.
The image contains all the files in the
command line. WOSFS is a flat file system,
but the names of files can contain slashes.
For use with the nedk example web server,
this lets you create traditional-looking
URL's like
http://mynios.com/subdir/index.html. The
start and end addresses should be the
lowest and highest part of flash memory to
store the image in.
EOP
exit 0;
}
# ------------------------------------
# emitGermsWrites(flash_start, flash_end, content, filesList)
#
sub emitGermsWrites
{
my $address = shift;
my $address_end = shift;
my $content = shift;
my $i;
my $thisLine;
my $x;
print <<EOP;
#
# This file generated by wosfs_maker.pl
#
# Contains the following files in wosfs_format
#
EOP
while($i = shift)
{
print "# $i\n";
}
print <<EOP;
#
#
# Wosfs file system installed at locations
EOP
printf("# 0x%08x - 0x%08x\n#\n",$address,$address_end);
for($i = $address; $i < $address_end; $i += 0x10000)
{
printf("e%08x\n",$i);
if($i == 0x100000) # funniness at the bottom of flash "hahaha!"
{
print "e00104000\n";
print "e00106000\n";
print "e00108000\n";
}
}
while ($content)
{
$thisLine = length($content);
$thisLine = 16 if($thisLine > 16);
printf("m%08x:",$address);
$address += $thisLine;
$thisLine = $thisLine / 2;
for($i = 0; $i < $thisLine; $i++)
{
$x = substr($content,0,2);
$content = substr($content,2);
printf "%04x", unpack("S",$x);
print " " if ($i < $thisLine - 1);
}
print "\n";
}
}
# -------------------------------------
# parseArgs
#
# Given a list of arguments, return
# a hash where the keys and values
# are taken from those arguments of
# the form "--key=value". The hyphens
# disappear from the key name.
#
# A command line switch of "--key"
# is equivalent to "--key=1".
#
# a special key named _argc contains
# a count of non-dash-dash arguments,
# and they are in the hash as {0}, {1},
# and so on.
sub parseArgs
{
my $arg;
my $argVal;
my $argc;
my %hash;
$argc = 0;
while($arg = shift)
{
if($arg =~ /^--(.*)$/)
{
$arg = $1;
if($arg =~ /^(.*)\=(.*)$/)
{
$arg = $1;
$argVal = $2;
}
else
{
$argVal = 1;
}
$hash{$arg} = $argVal;
}
else
{
$hash{$argc++} = $arg;
}
}
$hash{_argc} = $argc;
return %hash;
}
# -------------------------------
# getSwitch(hashRef, switchName, defaultValue [, mustBeNumber])
#
# Look at a hash as returned by parseArgs, and
# give the value of the switch, or the defaultValue
# if it was not specified in the command line.
sub getSwitch
{
my $hashRef = shift;
my $switchName = shift;
my $defaultValue = shift;
my $mustBeNumber = shift;
my $switchValue;
$switchValue = $$hashRef{$switchName};
$switchValue = $defaultValue if ($switchValue eq "");
# |
# | Handle 0x Hex Numbers
# |
if($switchValue =~ /^0x(.*)$/)
{
$switchValue = hex($1);
}
$switchValue *= 1 if ($mustBeNumber);
return $switchValue;
}
# -------------------------------------
#
sub main
{
my %switches;
my $wosfs_flash_start;
my $wosfs_flash_end;
my $i;
my $volumeSize;
my @fileList;
my $fileCount;
my $allFilesContent = "";
my $aFileContent;
my $volumeHeader;
my $directoryEntry;
my $volumePosition;
my $volumeContent = "";
$volumeSize = $kWOSFS_VolumeHeaderSize;
%switches = parseArgs(@_);
$fileCount = getSwitch(\%switches,"_argc",0);
# |
# | --help? just show help and quit
# |
if(getSwitch(\%switches,"help",0) or $fileCount == 0)
{
usage();
exit 0;
}
# |
# | From the switches hash, extract start & end values
# |
$wosfs_flash_start = getSwitch(\%switches,"start",$kWOSFS_flashBegin);
$wosfs_flash_end = getSwitch(\%switches,"end",$kWOSFS_flashEnd);
# |
# | From the switches hash, extract the requested files
# |
$fileCount = getSwitch(\%switches,"_argc",0);
for($i = 0; $i < $fileCount; $i++)
{
push(@fileList,getSwitch(\%switches,$i,""));
}
$volumeContent = pack("LL",$kWOSFS_Signature,$fileCount);
$volumePosition = $kWOSFS_VolumeHeaderSize +
$fileCount * $kWOSFS_DirectoryEntrySize;
dprint "first file goes at $volumePosition\n";
dprint "$kWOSFS_VolumeHeaderSize + $fileCount * $kWOSFS_DirectoryEntrySize\n";
foreach $arg (@fileList)
{
open (FILE,$arg) or die "could not open $arg";
binmode(FILE);
read (FILE,$aFileContent,2000000); # maximum file size
close (FILE);
my $fileLength = length($aFileContent);
# Pad to even file size
if(length($aFileContent) & 1)
{
$aFileContent .= "\000";
$fileLength++;
}
# If the filename is too big, brutally truncate.
if (length($arg) > $kWOSFS_FileNameSize - 1)
{
print STDERR "truncating filename '$arg' to ";
$arg = substr($arg, 0, $kWOSFS_FileNameSize - 1);
print STDERR "'$arg'\n";
}
# append the directory entry to the volume
$volumeContent .= pack("a${kWOSFS_FileNameSize}LL",$arg,
$volumePosition,
$fileLength);
$volumePosition += $fileLength;
# save all the byte from this file
$allFilesContent .= $aFileContent;
}
#
# and lastly, append the file's bytes to the volume
#
$volumeContent .= $allFilesContent;
dprint $volumeContent,"\n";
emitGermsWrites($wosfs_flash_start,$wosfs_flash_end,$volumeContent,@fileList);
}
main(@ARGV);
# end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -