Bi_rec "Library"
Greetings,
I was looking at all of the current bi_rec creation code and noticed
that there seemed to be a lot of work/code used to create the bi_recs. I thought it would be relatively easy to create a bi_rec "library" to clean things up and hide the messy details of bi_rec creation. I've attached a patch which adds the library (boot/common/bootinfo.c) and modified decompress_kernel in misc-simple.c to use it as an example. I realize that there may not be much interest at this point, but I thought I'd send it out anyway.
Randy Vinson
arch/ppc/boot/common/bootinfo.c new file +69 -0
@@ -0,0 +1,69 @@ +/* +* arch/ppc/common/bootinfo.c +* +* General bootinfo record utilities +* Author: Randy Vinson <[email protected]> +* +* 2002 (c) MontaVista Software, Inc. This file is licensed under the terms +* of the GNU General Public License version 2. This program is licensed +* "as is" without any warranty of any kind, whether express or implied. +*/ + +#include <linux/types.h> +#include <asm/bootinfo.h> + +#include "nonstdio.h" + +static struct bi_record * birec =NULL ; + +static struct bi_record * +__bootinfo_build (struct bi_record *rec,unsigned long tag,unsigned long size, +void *data) +{ +/* set the tag */ + rec->tag = tag; + +/* if the caller has any data, copy it */ +if (size) +memcpy (rec->data, (char *)data, size); + +/* set the record size */ + rec->size =sizeof (struct bi_record ) + size; + +/* advance to the next available space */ + rec = (struct bi_record *)((unsigned long )rec + rec->size); + +return rec; +} + +void +bootinfo_init (struct bi_record *rec) +{ + +/* save start of birec area */ + birec = rec; + +/* create an empty list */ + rec =__bootinfo_build (rec,BI_FIRST ,0 ,NULL ); + (void )__bootinfo_build (rec,BI_LAST ,0 ,NULL ); + +} + +void +bootinfo_append (unsigned long tag,unsigned long size,void * data) +{ + +struct bi_record *rec = birec; + +/* paranoia */ +if ((rec ==NULL ) || (rec->tag !=BI_FIRST )) +return ; + +/* find the last entry in the list */ +while (rec->tag !=BI_LAST ) + rec = (struct bi_record *)((ulong )rec + rec->size); + +/* overlay BI_LAST record with new one and tag on a new BI_LAST */ + rec =__bootinfo_build (rec, tag, size, data); + (void )__bootinfo_build (rec,BI_LAST ,0 ,NULL ); +}
arch/ppc/boot/common/misc-simple.c +18 -35
79 lines not on this page · raw message
arch/ppc/boot/simple/Makefile +1 -1
@@ -16,7 +16,7 @@ # Normally, we use the 'misc-simple.c' file for decompress_kernel and # whatnot. Sometimes we need to override this however. -MISC := ../common/misc-simple.o +MISC := ../common/misc-simple.o ../common/bootinfo.o # Additionally, we normally don't need to mess with the L2 / L3 caches # if present on 'classic' PPC. ifeq ($(CONFIG_6xx),y)
include/asm-ppc/bootinfo.h +10 -0
@@ -10,6 +10,7 @@#define _PPC_BOOTINFO_H#include <linux/config.h> +#include <asm/page.h> #if defined(CONFIG_APUS ) && !defined(__BOOTER__)#include <asm-m68k/bootinfo.h>
@@ -32,9 +33,18 @@#define BI_BOARD_INFO 0x1018extern struct bi_record *find_bootinfo (void ); +extern void bootinfo_init (struct bi_record *rec); +extern void bootinfo_append (unsigned long tag,unsigned long size,void * data);extern void parse_bootinfo (struct bi_record *rec);extern unsigned long boot_mem_size; +static inline struct bi_record * +bootinfo_addr (unsigned long offset) +{ + +return (struct bi_record *)_ALIGN ((offset) + (1 <<20 ) -1 , + (1 <<20 )); +}#endif /* CONFIG_APUS */