mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
Various, mostly cosmetic fixes (trivial).
Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@148 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
parent
02598fb2de
commit
0f7316cbfc
11 changed files with 54 additions and 66 deletions
|
@ -1,22 +1,22 @@
|
|||
##
|
||||
##
|
||||
## lar - LinuxBIOS archiver
|
||||
##
|
||||
##
|
||||
## Copyright (C) 2006 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
|
||||
##
|
||||
##
|
||||
|
||||
SOURCE := lar.c create.c extract.c list.c lib.c
|
||||
|
||||
|
@ -27,8 +27,8 @@ $(obj)/util/lar/lar: $(patsubst %,$(src)/util/lar/%,$(SOURCE))
|
|||
$(Q)printf "done\n"
|
||||
|
||||
|
||||
## --------------------------------------------------------------------
|
||||
## Stuff below this line is for debugging purposes only.
|
||||
# -----------------------------------------------------------------------------
|
||||
# Stuff below this line is for debugging purposes only.
|
||||
|
||||
ifdef DEBUG_LAR
|
||||
example: example.c
|
||||
|
@ -38,7 +38,7 @@ clean:
|
|||
$(Q)rm -rf lar tree.lar tree tree2 example
|
||||
|
||||
tree:
|
||||
$(Q)printf "creating sample tree... "
|
||||
$(Q)printf "Creating sample tree... "
|
||||
$(Q)rm -rf tree
|
||||
$(Q)mkdir tree
|
||||
$(Q)mkdir -p tree/compression
|
||||
|
@ -52,11 +52,11 @@ tree:
|
|||
$(Q)printf "done.\n"
|
||||
|
||||
tree.lar: lar tree
|
||||
$(Q)cd tree; ../lar c ../tree.lar `find . -type f|cut -c3-`
|
||||
$(Q)cd tree; ../lar c ../tree.lar `find . -type f | cut -c3-`
|
||||
|
||||
test: lar example tree.lar
|
||||
$(Q)mkdir tree2; cd tree2; ../lar x ../tree.lar
|
||||
$(Q)echo Comparing tree:
|
||||
$(Q)printf "Comparing tree:\n"
|
||||
$(Q)diff -urN tree tree2
|
||||
$(Q)rm -rf tree tree2
|
||||
$(Q)./example tree.lar
|
||||
|
|
|
@ -55,7 +55,7 @@ int create_lar(int argc, char *argv[])
|
|||
printf("Opening %s\n", archivename);
|
||||
archive = fopen(archivename, "w");
|
||||
if (!archive) {
|
||||
// error
|
||||
/* Error. */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -64,14 +64,14 @@ int create_lar(int argc, char *argv[])
|
|||
|
||||
ret = stat(argv[i], &statbuf);
|
||||
if (ret) {
|
||||
printf(" no such file %s\n", argv[i]);
|
||||
printf("No such file %s\n", argv[i]);
|
||||
exit(1);
|
||||
}
|
||||
filelen = statbuf.st_size;
|
||||
|
||||
tempmem = malloc(sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16);
|
||||
if (!tempmem) {
|
||||
printf("no memory\n");
|
||||
printf("No memory\n");
|
||||
return (1);
|
||||
}
|
||||
memset(tempmem, 0, sizeof(struct lar_header) + MAX_PATHLEN + filelen + 16);
|
||||
|
@ -79,24 +79,24 @@ int create_lar(int argc, char *argv[])
|
|||
header = (struct lar_header *)tempmem;
|
||||
pathname = tempmem + sizeof(struct lar_header);
|
||||
pathlen = sprintf(pathname, argv[i]) + 1;
|
||||
pathlen = (pathlen + 15) & 0xfffffff0; // align it to 16 bytes
|
||||
pathlen = (pathlen + 15) & 0xfffffff0; /* Align it to 16 bytes. */
|
||||
|
||||
/* read file into memory */
|
||||
/* Read file into memory. */
|
||||
filebuf = pathname + pathlen;
|
||||
source = fopen(argv[i], "r");
|
||||
if (!source) {
|
||||
printf(" no such file %s\n", argv[i]);
|
||||
printf("No such file %s\n", argv[i]);
|
||||
exit(1);
|
||||
}
|
||||
fread(filebuf, statbuf.st_size, 1, source);
|
||||
fclose(source);
|
||||
|
||||
/* create correct header */
|
||||
/* Create correct header. */
|
||||
memcpy(header, MAGIC, 8);
|
||||
header->len = htonl(statbuf.st_size);
|
||||
header->offset = htonl(sizeof(struct lar_header) + pathlen);
|
||||
|
||||
/* calculate checksum */
|
||||
/* Calculate checksum. */
|
||||
csum = 0;
|
||||
for (walk = (u32 *) tempmem;
|
||||
walk < (u32 *) (tempmem + statbuf.st_size +
|
||||
|
@ -105,13 +105,12 @@ int create_lar(int argc, char *argv[])
|
|||
}
|
||||
header->checksum = htonl(csum);
|
||||
|
||||
/* write out entry to archive */
|
||||
/* Write out entry to archive. */
|
||||
entrylen = (filelen + pathlen + sizeof(struct lar_header) + 15) & 0xfffffff0;
|
||||
|
||||
fwrite(tempmem, entrylen, 1, archive);
|
||||
|
||||
free(tempmem);
|
||||
|
||||
}
|
||||
|
||||
fclose(archive);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
#ifndef __LAR_CREATE_H
|
||||
#define __LAR_CREATE_H 1
|
||||
#define __LAR_CREATE_H
|
||||
|
||||
int create_lar(int argc, char *argv[]);
|
||||
|
||||
|
|
|
@ -52,14 +52,15 @@ int find_file(struct mem_file *archive, char *filename, struct mem_file *result)
|
|||
header = (struct lar_header *)walk;
|
||||
fullname = walk + sizeof(struct lar_header);
|
||||
|
||||
// FIXME: check checksum
|
||||
/* FIXME: check checksum. */
|
||||
|
||||
if (strcmp(fullname, filename) != 0) {
|
||||
result->start = walk + ntohl(header->offset);
|
||||
result->len = ntohl(header->len);
|
||||
return 0;
|
||||
}
|
||||
// skip file
|
||||
|
||||
/* Skip file. */
|
||||
walk += (ntohl(header->offset) + ntohl(header->len)
|
||||
+ 15) & 0xfffffff0;
|
||||
}
|
||||
|
@ -94,24 +95,26 @@ int main(int argc, char *argv[])
|
|||
|
||||
archive.start = mmap(NULL, statbuf.st_size, PROT_READ,
|
||||
MAP_SHARED, fd, 0);
|
||||
/* OS stuff ends here */
|
||||
|
||||
/* OS stuff ends here. */
|
||||
/* ------------------------------------------------- */
|
||||
|
||||
// find first compressor
|
||||
/* Find the first compressor. */
|
||||
ret = find_file(&archive, "compression/", &result);
|
||||
if (!ret)
|
||||
printf("file found.\n");
|
||||
printf("File found.\n");
|
||||
else
|
||||
printf("file not found.\n");
|
||||
printf("File not found.\n");
|
||||
|
||||
ret = find_file(&archive, "normal/initram", &result);
|
||||
if (!ret)
|
||||
printf("file found.\n");
|
||||
printf("File found.\n");
|
||||
else
|
||||
printf("file not found.\n");
|
||||
printf("File not found.\n");
|
||||
|
||||
/* ------------------------------------------------- */
|
||||
/* OS stuff starts again here */
|
||||
/* OS stuff starts again here. */
|
||||
|
||||
munmap(archive.start, archive.len);
|
||||
close(fd);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ int extract_lar(int argc, char *argv[])
|
|||
header = (struct lar_header *)walk;
|
||||
fullname = walk + sizeof(struct lar_header);
|
||||
|
||||
// FIXME: check checksum
|
||||
/* FIXME: check checksum. */
|
||||
|
||||
do_extract = 1;
|
||||
if (argc > 3) {
|
||||
|
@ -85,19 +85,20 @@ int extract_lar(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
}
|
||||
// dont extract this one, skip it.
|
||||
|
||||
/* Don't extract this one, skip it. */
|
||||
if (!do_extract)
|
||||
continue;
|
||||
|
||||
printf(" Extracting file %s\n",
|
||||
walk + sizeof(struct lar_header));
|
||||
|
||||
// Create the directory if it does not exist.
|
||||
/* Create the directory if it does not exist. */
|
||||
pathname = strdup(fullname);
|
||||
pos = strrchr(pathname, '/');
|
||||
if (pos) {
|
||||
pos[1] = 0;
|
||||
//printf("pathname %s\n",pathname);
|
||||
/* printf("Pathname %s\n",pathname); */
|
||||
mkdirp(pathname);
|
||||
}
|
||||
free(pathname);
|
||||
|
@ -107,12 +108,13 @@ int extract_lar(int argc, char *argv[])
|
|||
printf("error creating file.\n");
|
||||
exit(1);
|
||||
}
|
||||
//printf("starting offs=%d, len=%d\n", ntohl(header->offset),
|
||||
// ntohl(header->len));
|
||||
/* printf("Starting offs=%d, len=%d\n", ntohl(header->offset),
|
||||
ntohl(header->len)); */
|
||||
fwrite(walk + ntohl(header->offset), ntohl(header->len),
|
||||
1, file_to_extract);
|
||||
fclose(file_to_extract);
|
||||
}
|
||||
|
||||
munmap(inmap, statbuf.st_size);
|
||||
close(archivefile);
|
||||
printf("done.\n");
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
#ifndef __LAR_EXTRACT_H
|
||||
#define __LAR_EXTRACT_H 1
|
||||
#define __LAR_EXTRACT_H
|
||||
|
||||
int extract_lar(int argc, char *argv[]);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ int main(int argc, char *argv[])
|
|||
else if (strcmp(argv[1], "l") == 0)
|
||||
list_lar(argc, argv);
|
||||
else {
|
||||
printf("mode must be c or x\n");
|
||||
printf("Mode must be c, x, or l.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,10 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int mkdirp(char *dirpath)
|
||||
{
|
||||
#define MAX_PATH 1024
|
||||
|
||||
int mkdirp(const char *dirpath)
|
||||
{
|
||||
char *pos, *currpath, *path;
|
||||
char cwd[MAX_PATH];
|
||||
int ret = 0;
|
||||
|
@ -37,7 +38,7 @@ int mkdirp(char *dirpath)
|
|||
|
||||
if (!getcwd(cwd, MAX_PATH)) {
|
||||
free(path);
|
||||
printf("error getting cwd\n");
|
||||
printf("Error getting cwd.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -46,7 +47,7 @@ int mkdirp(char *dirpath)
|
|||
if (pos)
|
||||
*pos = 0;
|
||||
|
||||
//printf("cp=%s\n",currpath);
|
||||
/* printf("cp=%s\n", currpath); */
|
||||
mkdir(currpath, 0755);
|
||||
ret = chdir(currpath);
|
||||
|
||||
|
@ -59,22 +60,3 @@ int mkdirp(char *dirpath)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int main(void)
|
||||
{
|
||||
int ret;
|
||||
ret = mkdirp("a/b/c/d/");
|
||||
if (ret)
|
||||
printf("error! mkdir\n\n");
|
||||
else
|
||||
printf("jippie! mkdir\n\n");
|
||||
ret = mkdirp("a/b/c/d");
|
||||
if (ret)
|
||||
printf("error! mkdir\n");
|
||||
else
|
||||
printf("jippie! mkdir\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
*/
|
||||
|
||||
#ifndef __LAR_LIB_H
|
||||
#define __LAR_LIB_H 1
|
||||
#define __LAR_LIB_H
|
||||
|
||||
int mkdirp(char *dirpath);
|
||||
int mkdirp(const char *dirpath);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -81,7 +81,8 @@ int list_lar(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
}
|
||||
// dont extract this one, skip it.
|
||||
|
||||
/* Don't extract this one, skip it. */
|
||||
if (!do_extract)
|
||||
continue;
|
||||
|
||||
|
@ -90,6 +91,7 @@ int list_lar(int argc, char *argv[])
|
|||
printf("(%d bytes @0x%x)\n", ntohl(header->len),
|
||||
(walk - inmap) + ntohl(header->offset));
|
||||
}
|
||||
|
||||
munmap(inmap, statbuf.st_size);
|
||||
close(archivefile);
|
||||
printf("done.\n");
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
#ifndef __LAR_LIST_H
|
||||
#define __LAR_LIST_H 1
|
||||
#define __LAR_LIST_H
|
||||
|
||||
int list_lar(int argc, char *argv[]);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue