Update of /cvsroot/blob/blob/utils/test
In directory usw-pr-cvs1:/tmp/cvs-serv27294/utils/test
Added Files:
.cvsignore Makefile load_kernel.c load_kernel_test.c
Log Message:
most of Russ's jffs2 code updated
--- NEW FILE: .cvsignore ---
load_kernel_test
--- NEW FILE: Makefile ---
DEFS = -DHAVE_CONFIG_H -I/usr/include -I. -I../../include
load_kernel_test_OBJECTS = \
load_kernel.o \
load_kernel_test.o \
mini_inflate.o \
jffs2.o \
compr_rtime.o \
compr_rubin.o \
compr_zlib.o \
cramfs.o zImage.o crc32.o
load_kernel_test_extra_SOURCES = \
mini_inflate.c \
jffs2.c \
compr_rtime.c \
compr_rubin.c \
compr_zlib.c \
cramfs.c zImage.c crc32.c
CC=gcc
#CFLAGS = -O2 -Wall -fomit-frame-pointer -g
CFLAGS = -O2 -Wall -g
COMPILE = $(CC) $(DEFS) $(CFLAGS) -DUSER_SPACE_TEST
LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@
all: load_kernel_test
load_kernel_test: $(load_kernel_test_OBJECTS)
@rm -f load_kernel_test
$(LINK) $(load_kernel_test_OBJECTS) -o $@
$(load_kernel_test_extra_SOURCES):
ln -s ../../src/*/$@
.c.o:
$(COMPILE) -c $<
maintainer-clean: clean
rm -f $(load_kernel_test_extra_SOURCES)
clean:
@rm -f *.o load_kernel_test
--- NEW FILE: load_kernel.c ---
/*-------------------------------------------------------------------------
* Filename: load_kernel.c
* Version: $Id: load_kernel.c,v 1.1 2002/02/14 09:59:34 timriker Exp $
* Copyright: Copyright (C) 2001, Russ Dill
* Author: Russ Dill <Rus...@as...>
* Description: interface between kernel loaders and boot loader.
if everything was done right, this *should be the only
file that needs changing for porting to different boot
loaders.
*-----------------------------------------------------------------------*/
/*
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <string.h>
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned char u8;
#include "blob/load_kernel.h"
#include "blob/config.h"
extern struct kernel_loader cramfs_load;
extern struct kernel_loader zImage_load;
extern struct kernel_loader jffs2_load;
const struct kernel_loader *loader[] = {
&cramfs_load,
&zImage_load,
&jffs2_load,
NULL
};
void *fodder_ram_base;
/* function calls for the user space testing app */
inline void ldr_update_progress(void)
{
putchar('.');
}
inline int ldr_strncmp(char *a, char *b, size_t n)
{
return strncmp(a, b, n);
}
inline void *ldr_memcpy(void *dst, void *src, size_t n)
{
return memcpy(dst, src, n);
}
inline void ldr_output_string(char *str)
{
printf("%s", str);
fflush(stdout);
}
inline void ldr_output_hex(u32 hex)
{
printf("%lx", hex);
fflush(stdout);
}
--- NEW FILE: load_kernel_test.c ---
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned char u8;
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <libgen.h>
#include "blob/load_kernel.h"
int main(int argc, char *argv[])
{
char *out;
FILE *fp;
struct stat st;
struct part_info part;
int i;
unsigned long size = 0;
part.erasesize = 0x20000;
fodder_ram_base = malloc(0x1000);
out = malloc(0xe00000);
if (argc < 2) {
printf("not enough arguments usage:\n");
printf("%s: <fs_image> <outfile>\n", basename(argv[0]));
return 0;
}
if (stat(argv[1], &st)) {
perror("could not stat fs_image");
return 0;
}
if (!(fp = fopen(argv[1], "r"))) {
perror("could not open fs_image");
return 0;
}
part.size = st.st_size + part.erasesize - ((st.st_size - 1) % part.erasesize) - 1;
part.offset = malloc(part.size);
fread(part.offset, 1, st.st_size, fp);
memset(part.offset + st.st_size, 0xff, part.size - st.st_size);
fclose(fp);
printf("flash emulation region is 0x%lx bytes\n", part.size);
for (i = 0; loader[i] && !loader[i]->check_magic(&part); i++);
if (!loader[i]) {
printf("unable to find magic\n");
} else {
printf("loading kernel from ");
printf(loader[i]->name);
if ((size = loader[i]->load_kernel((u32 *) out, &part)) == 0) {
printf(" error loading kernel!\n");
return 0;
}
}
printf("loaded 0x%08lx bytes\n", size);
if (!(fp = fopen(argv[2], "w"))) {
perror("could not open outfile");
return 0;
}
fwrite(out, 1, size, fp);
fclose(fp);
return 0;
}
|