LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-08-2009, 09:32 PM   #1
BloodBlight
LQ Newbie
 
Registered: Jul 2008
Posts: 25

Rep: Reputation: 0
Coding Help – Apply Header to File


Hey everyone.

I have an Aruba AP61 Wireless node that loads its firmware files in an "APBoot" format. This file is a normal boot image, but with an extra header.

This header is built using an image.h file included at the bottom of the post.

It looks fairly simple, I'm assuming I just need to generate the output from this file, append the DD-WRT image that I am trying to use, and start my debugging away.

My knowledge in Linux is an average level, and I have some programming experience, but not in C. So what I need help with are these points:
  • A script to "compile" this source?
  • Additional source to combine the header and a selected file.
  • A script to run the program with my selected options (maybe even filling out some of the data automaticly, such as the data size [ih_size] and image CRC [ih_hcrc]).
  • Help with a few of the values. Such as: ih_load and ih_ep

Any help would be GREATLY apperciated. My self and a few other folks are all in the same boat, and I will be sharing the completed work back with a few other places:

image.h:
Code:
/*
 * (C) Copyright 2000
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * 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
 */

#ifndef __IMAGE_H__
#define __IMAGE_H__

/*
 * Operating System Codes
 */
#define IH_OS_INVALID		0	/* Invalid OS	*/
#define IH_OS_OPENBSD		1	/* OpenBSD	*/
#define IH_OS_NETBSD		2	/* NetBSD	*/
#define IH_OS_FREEBSD		3	/* FreeBSD	*/
#define IH_OS_4_4BSD		4	/* 4.4BSD	*/
#define IH_OS_LINUX		5	/* Linux	*/
#define IH_OS_SVR4		6	/* SVR4		*/
#define IH_OS_ESIX		7	/* Esix		*/
#define IH_OS_SOLARIS		8	/* Solaris	*/
#define IH_OS_IRIX		9	/* Irix		*/
#define IH_OS_SCO		10	/* SCO		*/
#define IH_OS_DELL		11	/* Dell		*/
#define IH_OS_NCR		12	/* NCR		*/
#define IH_OS_LYNXOS		13	/* LynxOS	*/
#define IH_OS_VXWORKS		14	/* VxWorks	*/
#define IH_OS_PSOS		15	/* pSOS		*/
#define IH_OS_QNX		16	/* QNX		*/
#define IH_OS_PPCBOOT		17	/* Firmware	*/

/*
 * CPU Architecture Codes (supported by Linux)
 */
#define IH_CPU_INVALID		0	/* Invalid CPU	*/
#define IH_CPU_ALPHA		1	/* Alpha	*/
#define IH_CPU_ARM		2	/* ARM		*/
#define IH_CPU_I386		3	/* Intel x86	*/
#define IH_CPU_IA64		4	/* IA64		*/
#define IH_CPU_MIPS		5	/* MIPS		*/
#define IH_CPU_MIPS64		6	/* MIPS	 64 Bit */
#define IH_CPU_PPC		7	/* PowerPC	*/
#define IH_CPU_S390		8	/* IBM S390	*/
#define IH_CPU_SH		9	/* SuperH	*/
#define IH_CPU_SPARC		10	/* Sparc	*/
#define IH_CPU_SPARC64		11	/* Sparc 64 Bit */

/*
 * Image Types
 *
 * "Standalone Programs" are directly runnable in the environment
 *	provided by PPCBoot; it is expected that (if they behave
 *	well) you can continue to work in PPCBoot after return from
 *	the Standalone Program.
 * "OS Kernel Images" are usually images of some Embedded OS which
 *	will take over control completely. Usually these programs
 *	will install their own set of exception handlers, device
 *	drivers, set up the MMU, etc. - this means, that you cannot
 *	expect to re-enter PPCBoot except by resetting the CPU.
 * "RAMDisk Images" are more or less just data blocks, and their
 *	parameters (address, size) are passed to an OS kernel that is
 *	being started.
 * "Multi-File Images" contain several images, typically an OS
 *	(Linux) kernel image and one or more data images like
 *	RAMDisks. This construct is useful for instance when you want
 *	to boot over the network using BOOTP etc., where the boot
 *	server provides just a single image file, but you want to get
 *	for instance an OS kernel and a RAMDisk image.
 *
 *	"Multi-File Images" start with a list of image sizes, each
 *	image size (in bytes) specified by an "uint32_t" in network
 *	byte order. This list is terminated by an "(uint32_t)0".
 *	Immediately after the terminating 0 follow the images, one by
 *	one, all aligned on "uint32_t" boundaries (size rounded up to
 *	a multiple of 4 bytes).
 *
 * "Firmware Images" are binary images containing firmware (like
 *	PPCBoot or FPGA images) which usually will be programmed to
 *	flash memory.
 *
 * "Script files" are command sequences that will be executed by
 *	PPCBoot's command interpreter; this feature is especially
 *	useful when you configure PPCBoot to use a real shell (hush)
 *	as command interpreter.
 */

#define IH_TYPE_INVALID		0	/* Invalid Image		*/
#define IH_TYPE_STANDALONE	1	/* Standalone Program		*/
#define IH_TYPE_KERNEL		2	/* OS Kernel Image		*/
#define IH_TYPE_RAMDISK		3	/* RAMDisk Image		*/
#define IH_TYPE_MULTI		4	/* Multi-File Image		*/
#define IH_TYPE_FIRMWARE	5	/* Firmware Image		*/
#define IH_TYPE_SCRIPT		6	/* Script file			*/

/*
 * Compression Types
 */
#define IH_COMP_NONE		0	/*  No	 Compression Used	*/
#define IH_COMP_GZIP		1	/* gzip	 Compression Used	*/
#define IH_COMP_BZIP2		2	/* bzip2 Compression Used	*/

#define IH_MAGIC	0x27051956	/* Image Magic Number		*/
#define IH_NMLEN		32	/* Image Name Length		*/

#ifdef __CYGWIN__
typedef unsigned long uint32_t;
typedef unsigned char uint8_t;
#endif /* __CYGWIN__ */

/*
 * all data in network byte order (aka natural aka bigendian)
 */

typedef struct image_header {
	uint32_t	ih_magic;	/* Image Header Magic Number	*/
	uint32_t	ih_hcrc;	/* Image Header CRC Checksum	*/
	uint32_t	ih_time;	/* Image Creation Timestamp	*/
	uint32_t	ih_size;	/* Image Data Size		*/
	uint32_t	ih_load;	/* Data	 Load  Address		*/
	uint32_t	ih_ep;		/* Entry Point Address		*/
	uint32_t	ih_dcrc;	/* Image Data CRC Checksum	*/
	uint8_t		ih_os;		/* Operating System		*/
	uint8_t		ih_arch;	/* CPU architecture		*/
	uint8_t		ih_type;	/* Image Type			*/
	uint8_t		ih_comp;	/* Compression Type		*/
	uint8_t		ih_name[IH_NMLEN];	/* Image Name		*/
} image_header_t;


#endif	/* __IMAGE_H__ */

THANKS!!!!
 
Old 08-09-2009, 12:26 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
There's something missing here, I believe..

Quote:

This header is built using an image.h file included at the bottom of the post.
The file you included there is just a C header file. It is *part* of a program, or of some source code, but it is not actually "source code" itself; you cannot build (compile) anything from/with that file alone. Do you have the source-code of whatever it is that you're trying to compile? Or a link to it?

I followed the first link you provided above, to the ddwrt forum, but after having read the whole thread, I get the impression that you are talking about compiling a new firmware image for this device. If so, you need source code. The downloadable images mentioned on that other forum appear to be pre-built binary images (rom files, or firmware files) that are already built, i.e. by the manufacturer.

Writing a script, like maybe a bash script, to execute some compile commands, is not difficult, but still, we would need something to compile

Sorry if my understanding of the issue here is out of whack.. But could you give some more info about what's going on here, what the plan is?

Thanks,
Sasha
 
Old 08-09-2009, 10:41 AM   #3
BloodBlight
LQ Newbie
 
Registered: Jul 2008
Posts: 25

Original Poster
Rep: Reputation: 0
Sorry, yes, this is only one of the files from the code of the APBoot project.

http://sourceforge.net/projects/apboot/

There is a lot of code in this project that I'm not going to use. The only thing I need to do is to splice in a few bytes of data at the beginning of a file so it passes a check this application runs. I am going to look at the project again today, I was getting tiered yesterday.

I may be able to find the code that does this, maybe not. But if I can't find it, it shouldn't be much to recreate.

Read settings (via command line or settings file or even static in the script).
CRC source image.
Find source image size.
Build header.
Write header to target image.
Concatenate source image to target image.

I will do some more homework on this in a few hours.

Thanks!!!
 
Old 11-29-2009, 01:18 PM   #4
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Back to the orig. topic ... (I hope the hijack will be moved)

Quote:
Originally Posted by BloodBlight View Post
The only thing I need to do is to splice in a few bytes of data at the beginning of a file so it passes a check this application runs.
Did it turn out that "splice" was more complicated than using cat?

Quote:
Originally Posted by BloodBlight View Post
Read settings (via command line or settings file or even static in the script).
CRC source image.
Find source image size.
Build header.
Write header to target image.
Concatenate source image to target image.
Looks straight fwd. -- did you get it implemented? ... How?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you apply a .pat file? MaxxPower Linux - Newbie 1 04-18-2009 12:05 AM
Apply diff to a file powah Linux - Newbie 1 03-07-2006 02:00 PM
Changing coding of text file(LF -> CRLF) koyi Linux - General 2 10-18-2005 07:44 AM
samba file share in multi coding chungchungip Linux - Software 4 09-13-2005 09:43 AM
Shell and file/directory color coding? l0f33t Linux - General 9 08-07-2003 10:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration