util/: Replace GPLv2 boiler plate with SPDX header
Used commands:
perl -i -p0e 's|\/\*[\s*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-only */|' $(cat filelist)
perl -i -p0e 's|This[\s*]*program[\s*]*is[\s*]*free[\s*]*software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*either[\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License,[\s*]*or[\s*]*.at[\s*]*your[\s*]*option.*[\s*]*any[\s*]*later[\s*]*version.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-or-later */|' $(cat filelist)
perl -i -p0e 's|\/\*[\s*]*.*This[\s*#]*program[\s*#]*is[\s*#]*free[\s*#]*software[;:,][\s*#]*you[\s*#]*can[\s*#]*redistribute[\s*#]*it[\s*#]*and/or[\s*#]*modify[\s*#]*it[\s*#]*under[\s*#]*the[\s*#]*terms[\s*#]*of[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*as[\s*#]*published[\s*#]*by[\s*#]*the[\s*#]*Free[\s*#]*Software[\s*#]*Foundation[;:,][\s*#]*either[\s*#]*version[\s*#]*3[\s*#]*of[\s*#]*the[\s*#]*License[;:,][\s*#]*or[\s*#]*.at[\s*#]*your[\s*#]*option.*[\s*#]*any[\s*#]*later[\s*#]*version.[\s*#]*This[\s*#]*program[\s*#]*is[\s*#]*distributed[\s*#]*in[\s*#]*the[\s*#]*hope[\s*#]*that[\s*#]*it[\s*#]*will[\s*#]*be[\s*#]*useful[;:,][\s*#]*but[\s*#]*WITHOUT[\s*#]*ANY[\s*#]*WARRANTY[;:,][\s*#]*without[\s*#]*even[\s*#]*the[\s*#]*implied[\s*#]*warranty[\s*#]*of[\s*#]*MERCHANTABILITY[\s*#]*or[\s*#]*FITNESS[\s*#]*FOR[\s*#]*A[\s*#]*PARTICULAR[\s*#]*PURPOSE.[\s*#]*See[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*for[\s*#]*more[\s*#]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-3.0-or-later */|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w]*.*is free software[:;][\#\s]*you[\#\s]*can[\#\s]*redistribute[\#\s]*it[\#\s]*and\/or[\#\s]*modify[\#\s]*it[\s\#]*under[\s \#]*the[\s\#]*terms[\s\#]*of[\s\#]*the[\s\#]*GNU[\s\#]*General[\s\#]*Public[\s\#]*License[\s\#]*as[\s\#]*published[\s\#]*by[\s\#]*the[\s\#]*Free[\s\#]*Software[\s\#]*Foundation[;,][\s\#]*version[\s\#]*2[\s\#]*of[\s\#]*the[\s\#]*License.*[\s\#]*This[\s\#]*program[\s\#]*is[\s\#]*distributed[\s\#]*in[\s\#]*the[\s\#]*hope[\s\#]*that[\s\#]*it[\s\#]*will[\#\s]*be[\#\s]*useful,[\#\s]*but[\#\s]*WITHOUT[\#\s]*ANY[\#\s]*WARRANTY;[\#\s]*without[\#\s]*even[\#\s]*the[\#\s]*implied[\#\s]*warranty[\#\s]*of[\#\s]*MERCHANTABILITY[\#\s]*or[\#\s]*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.[\#\s]*See[\#\s]*the[\#\s]*GNU[\#\s]*General[\#\s]*Public[\#\s]*License[\#\s]*for[\#\s]*more[\#\s]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
Change-Id: I1008a63b804f355a916221ac994701d7584f60ff
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-08 20:48:04 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2011-01-21 08:24:08 +01:00
|
|
|
|
2012-10-22 10:41:42 +02:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
#include <winsock.h>
|
|
|
|
#else
|
2011-01-21 08:24:08 +01:00
|
|
|
#include <arpa/inet.h>
|
2012-10-22 10:41:42 +02:00
|
|
|
#endif
|
2011-01-21 08:24:08 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2012-10-22 10:41:42 +02:00
|
|
|
#ifndef __MINGW32__
|
2011-01-21 08:24:08 +01:00
|
|
|
#include <sys/mman.h>
|
2012-10-22 10:41:42 +02:00
|
|
|
#endif
|
2011-01-21 08:24:08 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "cbfs.h"
|
2012-10-22 10:41:42 +02:00
|
|
|
#include "common.h"
|
2011-01-21 08:24:08 +01:00
|
|
|
|
|
|
|
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
|
|
|
|
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
|
|
|
|
|
|
|
static void *cbfs_mapped;
|
2012-03-09 12:54:03 +01:00
|
|
|
static void *cbfs_offset;
|
2011-01-21 08:24:08 +01:00
|
|
|
static void* virt_to_phys(u32 virt)
|
|
|
|
{
|
2012-03-09 12:54:03 +01:00
|
|
|
return cbfs_offset + virt;
|
2011-01-21 08:24:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define debug(x...) printf(x)
|
|
|
|
#else
|
|
|
|
#define debug(x...) while(0) {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int cbfs_check_magic(struct cbfs_file *file)
|
|
|
|
{
|
|
|
|
return !strcmp(file->magic, CBFS_FILE_MAGIC) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cbfs_header *cbfs_master_header(void)
|
|
|
|
{
|
|
|
|
struct cbfs_header *header;
|
|
|
|
|
|
|
|
void *ptr = virt_to_phys(*((u32*)virt_to_phys(CBFS_HEADPTR_ADDR)));
|
|
|
|
debug("Check CBFS header at %p\n", ptr);
|
|
|
|
header = (struct cbfs_header *) ptr;
|
|
|
|
|
|
|
|
debug("magic is %08x\n", ntohl(header->magic));
|
|
|
|
if (ntohl(header->magic) != CBFS_HEADER_MAGIC) {
|
|
|
|
printf("ERROR: No valid CBFS header found!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("Found CBFS header at %p\n", ptr);
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cbfs_file *cbfs_find(const char *name)
|
|
|
|
{
|
|
|
|
struct cbfs_header *header = cbfs_master_header();
|
2012-03-09 12:54:03 +01:00
|
|
|
void *offset;
|
2011-01-21 08:24:08 +01:00
|
|
|
|
|
|
|
if (header == NULL)
|
|
|
|
return NULL;
|
2012-03-09 12:54:03 +01:00
|
|
|
offset = virt_to_phys(0 - ntohl(header->romsize) + ntohl(header->offset));
|
2011-01-21 08:24:08 +01:00
|
|
|
|
|
|
|
int align= ntohl(header->align);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
struct cbfs_file *file = (struct cbfs_file *) offset;
|
|
|
|
if (!cbfs_check_magic(file)) return NULL;
|
|
|
|
debug("Check %s\n", CBFS_NAME(file));
|
|
|
|
if (!strcmp(CBFS_NAME(file), name))
|
|
|
|
return file;
|
|
|
|
|
|
|
|
int flen = ntohl(file->len);
|
|
|
|
int foffset = ntohl(file->offset);
|
2012-03-09 12:54:03 +01:00
|
|
|
debug("CBFS: follow chain: %p + %x + %x + align -> ", offset, foffset, flen);
|
2011-01-21 08:24:08 +01:00
|
|
|
|
2012-03-09 12:54:03 +01:00
|
|
|
void *oldoffset = offset;
|
|
|
|
offset = (void*)ALIGN((uintptr_t)(offset + foffset + flen), align);
|
2011-01-21 08:24:08 +01:00
|
|
|
debug("%p\n", (void *)offset);
|
|
|
|
if (offset <= oldoffset) return NULL;
|
|
|
|
|
2012-03-09 12:54:03 +01:00
|
|
|
if (offset < virt_to_phys(0xFFFFFFFF - ntohl(header->romsize)))
|
2011-01-21 08:24:08 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *cbfs_find_file(const char *name, unsigned int type, unsigned int *len)
|
|
|
|
{
|
|
|
|
struct cbfs_file *file = cbfs_find(name);
|
|
|
|
|
|
|
|
if (file == NULL) {
|
|
|
|
printf("CBFS: Could not find file %s\n",
|
|
|
|
name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ntohl(file->type) != type) {
|
|
|
|
printf("CBFS: File %s is of type %x instead of"
|
|
|
|
"type %x\n", name, file->type, type);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (len != NULL) *len = file->len;
|
|
|
|
|
|
|
|
return (void *) CBFS_SUBHEADER(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_cbfs(const char *filename)
|
|
|
|
{
|
|
|
|
struct stat cbfs_stat;
|
|
|
|
int cbfs_fd;
|
|
|
|
|
|
|
|
cbfs_fd = open(filename, O_RDWR);
|
|
|
|
if (cbfs_fd == -1) {
|
|
|
|
printf("Couldn't open '%s'\n", filename);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if (fstat(cbfs_fd, &cbfs_stat) == -1) {
|
|
|
|
printf("Couldn't stat '%s'\n", filename);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
cbfs_mapped = mmap(NULL, cbfs_stat.st_size, PROT_READ | PROT_WRITE,
|
|
|
|
MAP_SHARED, cbfs_fd, 0);
|
2014-08-03 12:10:53 +02:00
|
|
|
close(cbfs_fd);
|
2011-01-21 08:24:08 +01:00
|
|
|
if (cbfs_mapped == MAP_FAILED) {
|
|
|
|
printf("Couldn't map '%s'\n", filename);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2012-03-09 12:54:03 +01:00
|
|
|
cbfs_offset = cbfs_mapped-(0xffffffff-cbfs_stat.st_size+1);
|
2011-01-21 08:24:08 +01:00
|
|
|
}
|