File: nslu2_image.h

package info (click to toggle)
upslug2 11-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 612 kB
  • sloc: sh: 3,430; cpp: 2,142; makefile: 7
file content (75 lines) | stat: -rw-r--r-- 2,240 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*-
 * nslu2_image.h
 *  Return the bytes of an NSLU2 image, constructed on the fly if
 *  necessary.
 */
#ifndef NSLU2_IMAGE_H
#define NSLU2_IMAGE_H 1

#include <stdexcept>

#include "nslu2_protocol.h"

namespace NSLU2Image {
	typedef enum {
		Required,   /* required file not present */
		OpenError,  /* failed to open the file (str is name) */
		SizeError,  /* file too large (str is kernel/ramdisk/rootfs/payload) */
		ReadError,  /* IO error reading from file */
		DataError,  /* Error in the data in the file (e.g. bad signature) */
	} FileErrorType;

	class FileError : public std::exception {
	public:
		inline FileError(FileErrorType t, const char *s, int err) :
			type(t), str(s), errval(err) {
		}

		FileErrorType type;
		const char *  str;
		int           errval; /* OS errno value */
	};

	class Image {
	public:
		virtual ~Image() {
		}

		/* Get the next block of bytes, returns an address and length.
		 */
		virtual void GetBytes(char *buffer, size_t buffer_length,
				int &address, int &length) = 0;

		/* Rewind to the start of the image. */
		virtual void Rewind(void) = 0;

		/*-
		 * kernel_sex       - byte sex of kernel (determines FIS sex)
		 * data_sex         - byte sex of data (l, b or p for PDP!)
		 * directory_sex    - byte sex of numbers in FIS directory
		 * k(kernel)        - file containing a kernel image
		 * nr(noramdisk)    - causes the image to contain a zero length ramdisk
		 * ram(ramdisk)     - the ramdisk image (if nr this is just a payload)
		 * root(rootfs)     - the jffs2 rootfs image
		 * fis(fis_payload) - payload to follow the FIS Directory.
		 *
		 * Synthesises an image and writes this to flash (never overwrites the
		 * boot loader).
		 */
		static Image *MakeImage(char kernel_sex, char data_sex, char directory_sex,
			const char *k, bool nr,
			const char *ram, const char *root, const char *fis,
			unsigned short product_id, unsigned short protocol_id,
			unsigned short firmware_version, unsigned short extra_version);

		/*-
		 * r(reprogram) - write the whole image to flash (boot loader too)
		 * i(image)     - the image to write
		 *
		 * Writes exactly the given image to flash (no checking!)
		 */
		static Image *MakeImage(bool r, const char *i);
	};
};

#endif