- # If this is the last variable size partition, then fill the rest of the space.
- if ($_->{'name'} eq $lastdisk->{'name'}) {
- $_->{'size'} = paddedSize($directory_offset + $flash_start - $pointer);
- $debug and printf("Padding last variable partition <%s> to 0x%08X bytes\n", $_->{'name'}, $_->{'size'});
- }
-
- # Handle requests for partition creation first.
- if (defined $_->{'size'} and not defined $_->{'data'} and ($_->{'name'} ne "FIS directory")) {
-
- # A zero size is a request to fill all available space.
- if ($_->{'size'} == 0) {
- # Grab the start of the FIS directory, and use all the space up to there.
- $_->{'size'} = paddedSize($directory_offset + $flash_start - $pointer);
-
- # Create an empty partition of the requested size.
- $_->{'data'} = padBytes("", $_->{'size'});
-
- $debug and printf("Creating empty partition <%s> of 0x%08X bytes\n", $_->{'name'}, $_->{'size'});
- }
-
- if (not defined $_->{'offset'}) {
- # Check to make sure that the requested size is not too large.
- if (($pointer + $_->{'size'}) > ($flash_start + $directory_offset)) {
- die "Ran out of flash space in <", $_->{'name'}, ">\n";
- }
- }
- else {
- # Check to make sure that the requested size is not too large.
- if (($_->{'offset'} + $_->{'size'}) > ($flash_start + $directory_offset)) {
- die "Ran out of flash space in <", $_->{'name'}, ">\n";
- }
+ # Determine the start and offset of the current partition.
+ if (defined $_->{'offset'}) {
+ $_->{'start'} = $flash_start + $_->{'offset'};
+ # Check for running past the defined start of the partition.
+ if (($pointer > $_->{'start'}) and not $_->{'pseudo'}) {
+ die sprintf("Ran out of flash space before <%s> - %s too large.\n", $_->{'name'},
+ sprintf("0x%05X bytes", ($pointer - $_->{'start'})));