switch-coreboot/util/lar/bootblock.c
Stefan Reinauer d44bf71932 This is another LAR update. It changes the way a LinuxBIOS image is
built.
Instead of having a bootblock and a lar archive, the bootblock is now
part of the archive:

$ lar -l build/linuxbios.rom
  normal/initram (93 bytes @0x24)
  normal/payload (32768 bytes @0xb4)
  normal/stage2 (32028 bytes @0x80e4)
  linuxbios.bootblock (16384 bytes @0x3c000)

Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>



git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@240 f3766cd6-281f-0410-b1cd-43a5c92072e9
2007-03-11 13:55:36 +00:00

90 lines
2.2 KiB
C

/*
* lar - LinuxBIOS archiver
*
* Copyright (C) 2007 coresystems GmbH
* Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "lar.h"
#include "lib.h"
char *bootblock_code;
int bootblock_len;
int load_bootblock(const char *bootblock)
{
struct stat statbuf;
int ret, filelen;
FILE *fh;
ret = stat(bootblock, &statbuf);
if (ret) {
fprintf(stderr, "No such file %s\n", bootblock);
exit(1);
}
bootblock_len = statbuf.st_size;
/* We might want to find additional criteria
* for identifying a bootblock file
*/
if (bootblock_len != BOOTBLOCK_SIZE) {
printf("Warning: %s does not seem to be a bootblock, "
"so ignore it\n", bootblock);
bootblock_code=NULL;
bootblock_len=0;
// Is this an error condition?
}
bootblock_code = malloc(bootblock_len);
if (!bootblock_code) {
fprintf(stderr, "Out of memory.\n");
exit(1);
}
fh = fopen(bootblock, "r");
if (!fh) {
fprintf(stderr, "Error while reading file %s\n", bootblock);
exit(1);
}
fread(bootblock_code, bootblock_len, 1, fh);
fclose(fh);
return ret;
}
int fixup_bootblock(void)
{
/* Per definition the bootblock starts with 256 empty bytes.
* These are utilized to make the bootblock part of a lar file,
* and store the image size.
*
* We will also calculate a checksum here.
*/
/* first try. Clear out ugly left-over from ld hack */
bootblock_code[bootblock_len - 13] = '\0';
bootblock_code[bootblock_len - 12] = '\0';
return 0;
}