first and last commit

This commit is contained in:
Chris Nutter committed 2023-07-08 13:03:17 -07:00
commit 1bf4efd552
2612 files changed
+636500

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef DERAPTICKET_H
#define DERAPTICKET_H
#include <stdbool.h>
#include <libDER/libDER.h>
/* AP Ticket */
typedef struct {
DERItem signatureAlgorithm; /* AlgorithmId */
DERItem body; /* SET OF OCTECT STRING, DER_DEC_SAVE_DER */
DERItem signature; /* OCTET STRING */
DERItem certificates; /* SEQUENCE of CERTIFICATE */
} DERApTicket;
/* Cert extension */
typedef struct {
DERItem version; /* current version is 0; omitted until version 1 */
DERItem override;
DERItem append; /* optional; unsupported in version 0 */
DERItem remove; /* optional; unsupported in version 0 */
} DERApTicketCertExtension;
/* DERItemSpecs to decode into a DERApTicket */
extern const DERItemSpec DERApTicketItemSpecs[];
extern const DERSize DERNumApTicketItemSpecs;
DERReturn
DERApTicketCopyTagData(
const DERItem *container,
DERTag tag,
uint8_t *buffer,
DERSize *ioLength );
DERReturn
DERApTicketDecode(
const DERItem * contents,
DERApTicket * outTicket,
DERSize * outNumUsedBytes );
DERReturn
DERApTicketValidate(
const DERApTicket *ticket,
bool isRestore );
DERReturn
DERApTicketParseLengthFromBuffer(
const uint8_t * buffer,
size_t length,
size_t * outTicketLength );
#endif /* DERAPTICKET_H */
+111
View File
@@ -0,0 +1,111 @@
/*
* Image2 on-media format.
*
* The I2 layout is described by the I2 superblock, which is located at
* kI2SuperblockOffset from the top of the media. The superblock is a write-once
* item; it should only be updated when the bootblock code is rewritten, implying
* a complete re-initialisation of the media.
*
* Following the superblock there is a reserved area for boot code, after which
* image headers describe individual images.
*
* 0 --------------------
*
* kI2SuperblockOffset Image2Superblock
*
* isImageGranule --------------------
* bootcode
* + isBootBlockSize --------------------
* ...
* + isImageOffset Image2Header
* ...
*
*/
#if !defined (__LIB_IMAGE2FORMAT_H)
#define __LIB_IMAGE2FORMAT_H 1
#include <sys/types.h>
__BEGIN_DECLS
/*
* XXX 7561698 isImageOffset is documented inconsistently
* and not used as described above.
*/
typedef struct {
u_int32_t isMagic;
#define kImage2SuperMagic 0x494d4732 /* "IMG2" */
u_int32_t isImageGranule; /* fundamental block size (bytes) */
u_int32_t isImageOffset; /* image header offset within granule (image granules) */
u_int32_t isBootBlockSize; /* size of the bootblock (image granules) */
u_int32_t isImageAvail; /* total granules available for images. */
u_int32_t isNvramGranule; /* size of NVRAM blocks (bytes) */
u_int32_t isNvramOffset; /* offset to first NVRAM block (nvram granules) */
u_int32_t isFlags; /* flags field reserved for future use */
u_int32_t isRsvd1; /* reserved 1 for future use */
u_int32_t isRsvd2; /* reserved 2 for future use */
u_int32_t isRsvd3; /* reserved 3 for future use */
u_int32_t isRsvd4; /* reserved 4 for future use */
u_int32_t isCheck; /* CRC-32 of header fields preceding this one */
} Image2Superblock;
/*
* Image types
*/
typedef u_int32_t Image2ImageType;
#define kImage2ImageTypeWildcard 0x2a2a2a2a /* **** */
#define kImage2ImageTypeIdent 0x49646e74 /* Idnt - ASCII string identifying the image
* collection */
#define kImage2ImageTypeDTree 0x64747265 /* dtre */
#define kImage2ImageTypeDiag 0x64696167 /* diag */
#define kImage2ImageTypeLogo 0x6c6f676f /* logo */
#define kImage2ImageTypeiBoot 0x69626f74 /* "ibot" => iBoot */
#define kImage2ImageTypeLLB 0x6c6c627a /* "llbz" => LLB */
#define kImage2ImageTypeEOT 0x04040404 /* EOT */
/*
* On-media image header.
*/
typedef struct {
u_int32_t ihMagic;
#define kImage2ImageMagic 0x496d6732 /* "Img2" */
Image2ImageType ihType;
u_int16_t ihRevision;
u_int16_t ihSecurityEpoch; /* Image is from this security epoch */
u_int32_t ihLoadAddress; /* preferred load address */
u_int32_t ihDataSize; /* payload data size (bytes) */
u_int32_t ihEncryptedDataSize; /* payload data size after decryption (bytes) */
u_int32_t ihAllocationSize; /* allocation size including header (granules) */
u_int32_t ihOptions;
#define kImage2OptionSignatureTypeExternal (1<<0) /* signature present elsewhere */
#define kImage2OptionSignatureTypeInternalSHA1 (1<<1) /* SHA-1 hash in ihSignatureData */
#define kImage2OptionSignatureTypeInternalCRC (1<<2) /* CRC-32 in first word of ihSignatureData*/
#define kImage2OptionsTrustedImage (1<<8) /* Image was written down with trust */
#define kImage2OptionsEncryptedImage (1<<9) /* Image body is encrypted */
#define kImage2OptionsInstalledWithSB (1<<24) /* Image was written with secure boot support */
#define kImage2OptionsExtensionPresent (1<<30) /* Extension header follows this main */
#define kImage2OptionsImmutable (1<<31)
u_int32_t ihSignatureData[16];
u_int32_t ihNextSize; /* Size in bytes of the next extension */
#define kImage2HeaderExtensionMaxSize 128
u_int32_t ihCheck; /* CRC-32 of the preceeding fields */
} Image2Header;
#define kImage2HeaderReservation 1024
typedef u_int32_t Image2HeaderExtensionType;
#define kImage2HeaderExtensionVersionString 0x76657273 /* "vers" => version string */
typedef struct {
u_int32_t iheCheck; /* CRC-32 of the preceeding fields */
u_int32_t iheNextSize; /* Size in bytes of te next extension */
Image2HeaderExtensionType iheType;
u_int32_t ihOptions;
/* Extension prese*/
u_int32_t iheData; /* extension data. This field is not
written, instead the actual data is. */
} Image2HeaderExtension;
__END_DECLS
#endif /* __LIB_IMAGE2FORMAT_H*/
+82
View File
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2006-2011 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_BLOCKDEV_H
#define __LIB_BLOCKDEV_H
#include <stdint.h>
#include <sys/types.h>
__BEGIN_DECLS
typedef uint32_t block_addr;
#define BLOCKDEV_FLAG_NEEDS_ERASE (1 << 0) /* writes do not implicitly erase */
#define BLOCKDEV_FLAG_UPGRADE_PARTITION (1 << 1)
struct blockdev {
struct blockdev *next;
uint32_t flags;
/* geometry */
uint32_t block_size;
uint32_t block_count;
uint32_t block_shift; /* calculated from the block size (assumes multiple of 2) */
uint64_t total_len;
uint32_t alignment; /* required alignment for source/destination buffers in bytes */
uint32_t alignment_shift;
/* io hooks */
int (*read_hook)(struct blockdev *, void *ptr, off_t offset, uint64_t len); // read bytes
int (*read_block_hook)(struct blockdev *, void *ptr, block_addr block, uint32_t count); // read count blocks
int (*write_hook)(struct blockdev *, const void *ptr, off_t offset, uint64_t len); // write bytes
int (*write_block_hook)(struct blockdev *, const void *ptr, block_addr block, uint32_t count); // write count blocks
int (*erase_hook)(struct blockdev *, off_t offset, uint64_t len);
/* name */
char name[16];
/* write-protected region */
off_t protect_start;
off_t protect_end;
};
struct blockdev *lookup_blockdev(const char *name);
int register_blockdev(struct blockdev *);
struct blockdev *first_blockdev(void);
struct blockdev *next_blockdev(struct blockdev *dev);
/* fill out a new blockdev structure with geometry data and default hooks */
int construct_blockdev(struct blockdev *, const char *name, uint64_t len, uint32_t block_size);
/* user api */
#define blockdev_read(bdev, ptr, off, len) (bdev)->read_hook((bdev), ptr, off, len)
#define blockdev_read_block(bdev, ptr, block, count) (bdev)->read_block_hook((bdev), ptr, block, count)
#define blockdev_write(bdev, ptr, off, len) blockdev_write_protected((bdev), ptr, off, len)
#define blockdev_write_block(bdev, ptr, block, count) blockdev_write_block_protected((bdev), ptr, block, count)
#define blockdev_erase(bdev, off, len) (bdev)->erase_hook((bdev), off, len)
int blockdev_compare(struct blockdev *dev, const void *ptr, off_t bdev_offset, uint64_t len);
int blockdev_set_protection(struct blockdev *dev, off_t offset, uint64_t length);
void blockdev_set_buffer_alignment(struct blockdev *dev, uint32_t alignment);
int blockdev_write_protected(struct blockdev *dev, const void *ptr, off_t offset, uint64_t len);
int blockdev_write_block_protected(struct blockdev *dev, const void *ptr, block_addr block, uint32_t count);
/* a default memory based block device */
struct blockdev *create_mem_blockdev(const char *name, void *ptr, uint64_t len, uint32_t block_size);
/* a subdevice device, which lets you access a range of a device as another device */
struct blockdev *create_subdev_blockdev(const char *name, struct blockdev *parent, off_t off, uint64_t len, uint32_t block_size);
__END_DECLS
#endif
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_CBUF_H
#define __LIB_CBUF_H
#include <sys/types.h>
#include <sys/task.h>
__BEGIN_DECLS
/* circular buffer implementation */
struct cbuf {
void *buf;
unsigned int head;
unsigned int tail;
size_t has;
size_t len;
uint32_t len_mask;
/* optional event for locking */
struct task_event *event;
};
/* create a circular buffer, len must be power of 2 */
struct cbuf *cbuf_create(size_t len, struct task_event *event); // event is optional
void cbuf_destroy(struct cbuf *);
/* read/write unstructured data */
ssize_t cbuf_write_raw(struct cbuf *, const void *data, size_t len);
ssize_t cbuf_read_raw(struct cbuf *, void *data, size_t len);
/* read/write individual chars */
ssize_t cbuf_write_char(struct cbuf *, char c);
ssize_t cbuf_read_char(struct cbuf *, char *c);
/* read/write strings */
ssize_t cbuf_write_string(struct cbuf *, const char *str);
ssize_t cbuf_read_string(struct cbuf *, char *str, size_t maxlen);
__END_DECLS
#endif
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_CKSUM_H
#define __LIB_CKSUM_H
#include <stdint.h>
#include <sys/types.h>
__BEGIN_DECLS
/* various checksum & crc routines */
/* POSIX 1003.2 checksum (same as cksum command) */
#define INITIAL_CRC (0)
uint32_t crc(const void *buf, size_t len);
/* same as above, but on a single byte */
uint32_t crc_byte(uint32_t thecrc, uint32_t byte_val);
/* adler32 */
uint32_t adler32(const uint8_t *buf, long len);
/* crc32 CCITT*/
uint32_t update_crc32(uint32_t crc, const uint8_t *buf, int len);
uint32_t crc32(const uint8_t *buf, int len);
void siphash(uint8_t *out, const uint8_t *in, size_t inlen, const uint8_t *k);
void siphash_aligned(uint64_t *out, const uint64_t *in_aligned, size_t inlen, const uint64_t *k);
#define SIPHASH_KEY_SIZE (16)
#define SIPHASH_HASH_SIZE (8)
__END_DECLS
#endif
+64
View File
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2008-2015 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef _BOOTX_DEVICE_TREE_H_
#define _BOOTX_DEVICE_TREE_H_
#include <stdint.h>
#include <sys.h>
#include <sys/types.h>
__BEGIN_DECLS
#define kPropNameLength (32)
#define kPropValueMaxLength (0x100000)
typedef struct DTProperty DTProperty, *DTPropertyPtr;
int dt_load(void);
int dt_load_file(const char *path);
extern addr_t gDeviceTreeAddr;
extern size_t gDeviceTreeSize;
typedef struct dtnode dt_node_t;
void dt_init(void);
dt_node_t *dt_deserialize(void *dtaddr, size_t dtlength);
void dt_serialize(dt_node_t *dt, void *buffer, size_t bufferlen);
size_t dt_get_size(void);
dt_node_t *dt_get_root(void);
bool dt_find_node(dt_node_t *root, const char *path, dt_node_t **node);
const char *dt_get_node_name(dt_node_t *node);
bool dt_get_prop(dt_node_t *node, char **prop_name, void **prop_data, uint32_t *prop_size);
bool dt_find_prop(dt_node_t *node, const char *prop_name, void **prop_data, uint32_t *prop_size);
bool dt_has_prop(dt_node_t *node, const char *prop_name);
void dt_set_prop(dt_node_t *node, const char *name, const void *data, uint32_t size);
void dt_set_prop_32(dt_node_t *node, const char *name, uint32_t value);
void dt_set_prop_64(dt_node_t *node, const char *name, uint64_t value);
void dt_set_prop_addr(dt_node_t *node, const char *name, uintptr_t value);
void dt_set_prop_str(dt_node_t *node, const char *name, const char *str);
bool dt_remove_prop(dt_node_t *node, const char *name);
bool dt_rename_prop(dt_node_t *node, const char *name, const char *new_name);
void dt_seal(void);
int dt_num_children(dt_node_t *node);
dt_node_t *dt_get_child(dt_node_t *node, int n);
dt_node_t *dt_get_next(dt_node_t *node);
// compatibility with legacy code
typedef dt_node_t DTNode;
typedef dt_node_t * DTNodePtr;
#define FindNode dt_find_node
#define FindProperty dt_get_prop
__END_DECLS
#endif /* ! _BOOTX_DEVICE_TREE_H_ */
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_ENV_H
#define __LIB_ENV_H
#include <sys/types.h>
__BEGIN_DECLS
/* systemwide environment variables */
struct env_var {
char *str;
size_t u;
uint32_t flags;
};
#define ENV_PERSISTENT 0x1 /* saved with 'saveenv' or not */
#define ENV_SHADOW 0x2 // hidden from env_get or not
const char *env_get(const char *name);
size_t env_get_uint(const char *name, size_t default_val);
bool env_get_bool(const char *name, bool default_val);
const struct env_var *env_get_etc(const char *name);
int env_set(const char *name, const char *val, uint32_t flags);
int env_set_uint(const char *name, size_t val, uint32_t flags);
int env_unset(const char *name);
/* supplied by code that wants to blacklist environment variables */
bool env_blacklist(const char *name, bool write);
bool env_blacklist_nvram(const char *name);
/* used by the nvram system */
size_t env_serialize(uint8_t *buf, size_t buf_len);
int env_unserialize(const uint8_t *buf, size_t buf_len);
/* get an ip address from the environment */
int env_get_ipaddr(const char *name, uint32_t *ip);
int env_get_ethaddr(const char *name, uint8_t ethaddr[6]);
__END_DECLS
#endif
+120
View File
@@ -0,0 +1,120 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_FS_H
#define __LIB_FS_H
#include <list.h>
#include <sys/types.h>
__BEGIN_DECLS
/* limits */
#define FS_MAXNAMLEN 255 /* maximum component name */
#define FS_MAXPATHLEN 512 /* maximum path length */
/* statfs structure. */
struct statfs {
uint32_t f_bsize; /* Size of a cluster in bytes. */
uint32_t f_blocks; /* Number of clusters. */
uint32_t f_bfree; /* Number of free clusters. */
};
enum file_type {
FILE_TYPE_UNKNOWN = 0,
FILE_TYPE_FILE,
FILE_TYPE_DIR,
};
/* directory entry. */
struct dirent {
uint32_t d_fileno;
uint32_t d_reclen;
uint8_t d_type;
uint8_t d_namlen;
char d_name[FS_MAXNAMLEN + 1];
int32_t d_ctime;
int32_t d_atime;
int32_t d_mtime;
};
/* stat structure. */
struct stat {
uint32_t st_ino; /* Inode number. */
uint32_t st_size; /* Lenght of file (bytes). */
uint32_t st_blocks; /* Length of file (blocks). */
enum file_type st_type;
uint32_t st_flags;
int32_t st_ctime; /* Creation time. */
int32_t st_mtime; /* Modification time. */
int32_t st_atime; /* Access time. */
};
/* File I/O */
#define FILE_SEEK_SET 0
#define FILE_SEEK_CUR 1
#define FILE_SEEK_END 2
/* read only fs ops */
struct fs_ops {
int (*mount)(void **ctxt, const char *dev);
void (*unmount)(void *ctxt);
int (*fsstat)(void *ctxt, struct statfs *stat);
void *(*open)(void *ctxt, const char *path, uint8_t flags);
int (*read)(void *filectxt, void *buf, size_t len);
int (*fstat)(void *filectxt, struct stat *st);
off_t (*seek)(void *filectxt, off_t offset, int whence);
void (*close)(void *filectxt);
void *(*opendir)(void *ctxt, const char *path);
int (*readdir)(void *dirctxt, struct dirent *ent);
void (*rewinddir)(void *dirctxt);
void (*closedir)(void *dirctxt);
};
struct fs_struct {
const char *name;
const struct fs_ops *ops;
};
/* user fs api */
int fs_mount(const char *dev, const char *fs_name, const char *mountpoint);
void fs_unmount(const char *dev);
int fs_fsstat(void *fscookie, struct statfs *stat);
int fs_open(const char *path, uint8_t flags);
int fs_read(int handle, void *buf, size_t len);
int fs_stat(int handle, struct stat *st);
off_t fs_seek(int handle, off_t offset, int whence);
int fs_close(int handle);
int fs_opendir(const char *path);
int fs_readdir(int handle, struct dirent *ent);
int fs_rewinddir(int handle);
int fs_closedir(int handle);
const char *fs_get_fsname(const int index);
/* some debug routines */
void fs_stat_dump(const struct stat *st);
void fs_statfs_dump(const struct statfs *st);
int fs_dump_dir(const char *dirpath, bool recurse);
void fs_dump_mounts(void);
/* convenience routines */
int fs_load_file(const char *path, addr_t addr, size_t *maxsize);
__END_DECLS
#endif
+101
View File
@@ -0,0 +1,101 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __HEAP_H
#define __HEAP_H
#include <sys/types.h>
__BEGIN_DECLS
/*
* The public heap allocation functions will never return NULL. The internal
* implementation will always call panic() if an allocation cannot be
* satisfied. You should not check for NULL being returned as this is a waste
* of code and gives other readers the incorrect impression that this is
* required.
*/
#define HEAP_COOKIE_SIZE 16
void heap_add_chunk(void *chunk, size_t size, bool clear_memory);
void heap_set_cookie(uint8_t *cookie);
u_int32_t heap_get_free_mem(void);
bool heap_is_initialized(void);
void *heap_malloc(size_t size, const char *caller_name);
void *heap_realloc(void *ptr, size_t size, const char *caller_name);
void *heap_memalign(size_t size, size_t alignment, const char *caller_name);
int heap_posix_memalign(void **memptr, size_t size, size_t alignment, const char *caller_name);
void *heap_calloc(size_t count, size_t size, const char *caller_name);
void heap_free(void *ptr);
void heap_verify(void);
#ifndef __clang_analyzer__
#ifndef HEAP_UNITTEST
# if DEBUG_BUILD
# define malloc(_s) heap_malloc(_s, __FUNCTION__)
# define realloc(_p, _s) heap_realloc(_p, _s, __FUNCTION__)
# define memalign(_s, _a) heap_memalign(_s, _a, __FUNCTION__)
# define posix_memalign(_m, _s, _a) heap_posix_memalign(_m, _s, _a, __FUNCTION__)
# define calloc(_c, _s) heap_calloc(_c, _s, __FUNCTION__)
# else
# define malloc(_s) heap_malloc(_s, NULL)
# define realloc(_p, _s) heap_realloc(_p, _s, NULL)
# define memalign(_s, _a) heap_memalign(_s, _a, NULL)
# define posix_memalign(_m, _s, _a) heap_posix_memalign(_m, _s, _a, NULL)
# define calloc(_c, _s) heap_calloc(_c, _s, NULL)
# endif
# define free(_p) heap_free(_p)
#endif // HEAP_UNITTEST
#else // __clang_analyzer__
// the clang static analyzer needs malloc and friends to have their normal
// names with underscores prepended in order to find things like use after free
void *malloc(size_t size);
void *realloc(void *ptr, size_t size);
void *memalign(size_t size, size_t alignment);
void *calloc(size_t count, size_t size);
void free(void *ptr);
int posix_memalign(void **memptr, size_t alignment, size_t size);
#endif
/* heap debugging features */
enum
{
HEAP_BLOCK__FREE,
HEAP_BLOCK__MALLOC,
HEAP_BLOCK__MEMALIGN,
HEAP_BLOCK__SENTINEL,
};
struct walker_info_t
{
unsigned block_type;
void *raw_block;
size_t block_size;
unsigned extended_info;
uint32_t checksum;
/* these are only meaningful for HEAP_BLOCK__MALLOC & HEAP_BLOCK__MEMALIGN */
void *user_block;
size_t user_size; /* only when extended_info != 0 */
utime_t timestamp; /* only when extended_info != 0 */
void *requestor; /* only when extended_info != 0 */
/* this is only meaningful for HEAP_BLOCK__MEMALIGN, set to zero for HEAP_BLOCK__MALLOC */
size_t alignment; /* only when extended_info != 0 */
};
typedef int (heap_walker_f)(void *cookie, struct walker_info_t const *);
__END_DECLS
#endif
+219
View File
@@ -0,0 +1,219 @@
/*
* Copyright (C) 2007-2013 Apple Inc. All rights reserved.
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef __LIB_IMAGE_H
#define __LIB_IMAGE_H
#include <sys/types.h>
#include <lib/blockdev.h>
#include <list.h>
__BEGIN_DECLS
struct image_info {
u_int32_t imageLength;
u_int32_t imageAllocation;
u_int32_t imageType;
u_int32_t imagePrivateMagic;
#define IMAGE_MEMORY_INFO_MAGIC 'Memz'
#define IMAGE2_IMAGE_INFO_MAGIC 'img2'
#define IMAGE3_IMAGE_INFO_MAGIC 'img3'
#define IMAGE4_IMAGE_INFO_MAGIC 'img4'
u_int32_t imageOptions;
void *imagePrivate;
};
// images we might be interested in
#define IMAGE_TYPE_ANY 0 // any image type
#define IMAGE_TYPE_DIAG 'diag' // diagnostics
#define IMAGE_TYPE_LLB 'illb' // iboot first-stage loader
#define IMAGE_TYPE_IBOOT 'ibot' // iboot second-stage loader
#define IMAGE_TYPE_IBSS 'ibss' // iboot single stage
#define IMAGE_TYPE_IBEC 'ibec' // iboot epoch change
#define IMAGE_TYPE_DALI 'dali' // dali
#define IMAGE_TYPE_DEVTREE 'dtre' // darwin device tree
#define IMAGE_TYPE_DEVTREE_RESTORE 'rdtr' // darwin device tree for restore
#define IMAGE_TYPE_RAMDISK 'rdsk' // darwin ram disk for restore
#define IMAGE_TYPE_KERNELCACHE 'krnl' // darwin kernel cache
#define IMAGE_TYPE_KERNELCACHE_RESTORE 'rkrn' // darwin kernel cache for restore
#define IMAGE_TYPE_LOGO 'logo' // boot logo image
#define IMAGE_TYPE_RECMODE 'recm' // recovery mode image
#define IMAGE_TYPE_NEEDSERVICE 'nsrv' // need service image
#define IMAGE_TYPE_GLYPHCHRG 'glyC' // glyph charge image
#define IMAGE_TYPE_GLYPHPLUGIN 'glyP' // glyph plug in image
#define IMAGE_TYPE_BATTERYCHARGING0 'chg0' // battery charging image - bright
#define IMAGE_TYPE_BATTERYCHARGING1 'chg1' // battery charging image - dim
#define IMAGE_TYPE_BATTERYLOW0 'bat0' // battery low image - empty
#define IMAGE_TYPE_BATTERYLOW1 'bat1' // battery low image - red (composed onto empty)
#define IMAGE_TYPE_BATTERYFULL 'batF' // battery full image list
#define IMAGE_TYPE_BATTERYFULL_N_TOTAL (18) // total number of images
#define IMAGE_TYPE_BATTERYFULL_N_START (2) // first image that's part of batF list (first two are bat0 and bat1)
#define IMAGE_TYPE_BATTERYFULL_N_RED (4) // last red battery image
#define IMAGE_TYPE_BATTERYFULL_N_FULL (IMAGE_TYPE_BATTERYFULL_N_TOTAL-1) // battery full image
#define IMAGE_TYPE_ENV 'ienv' // environment vars
#define IMAGE_TYPE_TSYS 'tsys' // tsys tester
#define IMAGE_TYPE_MONITOR 'hypr' // monitor/hypervisor
#define IMAGE_TYPE_OS_RESTORE 'rosi' // OS image for restore
#define IMAGE_TYPE_SEP_OS 'sepi' // SEP OS image
#define IMAGE_TYPE_SEP_OS_RESTORE 'rsep' // SEP OS image for restore
#define IMAGE_TYPE_CFE_LOADER 'cfel' // SiVal's CFE loader
#define IMAGE_TYPE_RBM 'rbmt' // SiVal's RBM test
#define IMAGE_TYPE_PHLEET 'phlt' // SiVal's PHLEET test
#define IMAGE_TYPE_PE_RTOS 'pert' // PE's RTOS environment
#define IMAGE_TYPE_HAMMER 'hmmr' // PE's Hammer test
#define IMAGE_TYPE_FDRT 'fdrt' // FDR Trust object for AP
#define IMAGE_TYPE_FDRS 'fdrs' // FDR Trust object for SEP
// image options
#define IMAGE_OPTION_GREATER_EPOCH (1 << 0) // Allow platform epoch or greater
#define IMAGE_OPTION_REQUIRE_TRUST (1 << 1) // Regardless of security, require image
// trust
#define IMAGE_OPTION_LOCAL_STORAGE (1 << 2) // Image came from local (personalised) storage
#define IMAGE_OPTION_NEW_TRUST_CHAIN (1 << 3) // New chain of trust. Image load library can use this information
// enforce various policies.
#define IMAGE_OPTION_JUST_LOAD (1 << 8) // Just load the whole image, don't validate or look for a payload
#define IMAGE_OPTION_MEMORY (1 << 9) // Image comes from a memory bdev, so its hash isn't personalized
// XXX backwards compatibility
#define IMAGE_OPTION_ANY_EPOCH IMAGE_OPTION_GREATER_EPOCH // Allow any epoch for this image
// image keybag selectors
#define IMAGE_KEYBAG_SELECTOR_PROD (1)
#define IMAGE_KEYBAG_SELECTOR_DEV (2)
/**
* Load an image from a file.
*
* \param[in] path Path including mountpoint from which to read.
* \param[inout] address Address for the buffer used both for file reading and into which
* the resulting image data will be placed. Referenced pointer will
* be zeroed on failure.
* \param[inout] length On input, the size of the buffer. The file must file entirely
* within this size. Updated on return to the size of the image
* data extracted from the image.
* \param[in] types An array of types that the image must conform to one of,
* or NULL if no type checking should be performed.
* \param[in] count The count of image types in the types array,
* or zero if NULL was passed.
* \param[out] actual A pointer to receive the actual type for given image.
* Optional if count is 0 or 1.
* \param[in] options Options to be passed when creating the image.
*
* \return 0 on success.
*/
int
image_load_file(
const char *path,
addr_t *address,
size_t *length,
const uint32_t *types,
uint32_t count,
uint32_t *actual,
uint32_t options);
/**
* Load an image from memory.
*
* \param[in] fromAddress Address of the buffer containing the image.
* \param[in] fromLength Size of the buffer containing the image.
* \param[inout] address Address for the buffer into which the resulting image data will
* be placed. Referenced pointer will be zeroed on failure.
* \param[inout] length On input, the size of the destination buffer. The image must file
* entirely within this size. Updated on return to the size of the image
* data extracted from the image.
* \param[in] types An array of types that the image must conform to one of,
* or NULL if no type checking should be performed.
* \param[in] count The count of image types in the types array,
* or zero if NULL was passed.
* \param[out] actual A pointer to receive the actual type for given image.
* Optional if count is 0 or 1.
* \param[in] options Options to be passed when creating the image.
*
* \return 0 on success.
*/
int
image_load_memory(
addr_t fromAddress,
size_t fromLength,
addr_t *address,
size_t *length,
const uint32_t *types,
uint32_t count,
uint32_t *actual,
uint32_t options);
/**
* Load an image of a given type from the set of known images.
*
* \param[inout] address Address for the buffer into which the resulting image data will
* be placed. Referenced pointer will be zeroed on failure.
* \param[inout] length On input, the size of the destination buffer. The image must file
* entirely within this size. Updated on return to the size of the image
* data extracted from the image.
* \param[in] type The image type to be looked up.
* \param[in] options Options to be passed when creating the image.
*
* \return 0 on success.
*/
int
image_load_type(
addr_t *address,
size_t *length,
uint32_t type,
uint32_t options);
/*
* Lower-level primitives - avoid when possible.
*/
int
image_search_bdev(
struct blockdev *bdev,
off_t map_offset,
uint32_t imageOptions);
void
image_free_bdev(
struct blockdev *bdev);
int
image_load(
struct image_info *image,
const uint32_t *types,
uint32_t count,
uint32_t *actual,
void **load_addr,
size_t *load_len);
struct image_info *
image_find(
u_int32_t type);
void
image_dump_list(
bool detailed);
struct image_info *
image_create_from_memory(
void *address,
size_t length,
uint32_t imageOptions);
void
image_free(
struct image_info *image);
__END_DECLS
#endif
+59
View File
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef __LIB_IMAGE4_SPI_H
#define __LIB_IMAGE4_SPI_H
/*
* An image of type 'image_type' is being loaded.
*
* Return true if you'd like its properties captured, false otherwise.
*/
typedef bool (*image4_start_capture_callback)(uint32_t image_type);
/*
* Property callbacks for supported property types:
*
* tag: 32-bit property tag (e.g. 'EPRO')
* is_object_property: true for object property, false for manifest property
*
* Note that for the string variant, 'buffer' is only valid within the scope of the callback.
*/
typedef void (*image4_boolean_property_callback)(uint32_t tag, bool is_object_property, bool val);
typedef void (*image4_integer_property_callback)(uint32_t tag, bool is_object_property, uint64_t val);
typedef void (*image4_string_property_callback)(uint32_t tag, bool is_object_property, uint8_t* buffer, size_t length);
/*
* Validity callback:
*
* true: Image has been validated -- captured properties can be used
* false: Image is not valid. You should zero out any previously captured properties!
*/
typedef void (*image4_validity_callback)(bool valid);
/*
* image4_register_property_capture_callbacks
*
* On some targets, we would like to stash away various image4 properties for a particular payload type.
* Register callbacks for property captures, as well as a callback to let you know whether or not the image ended
* up being valid.
*
* Note for security reasons, you are expected to zero out your stored properties if you find out that
* image4_validity_callback is called with false.
*/
extern void
image4_register_property_capture_callbacks(image4_start_capture_callback start_cb, image4_boolean_property_callback bool_cb,
image4_integer_property_callback int_cb, image4_string_property_callback string_cb,
image4_validity_callback validity);
#endif
+170
View File
@@ -0,0 +1,170 @@
/*
* Copyright (C) 2007-2009 Apple Inc. All rights reserved.
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef __LIB_LIBC_H
#define __LIB_LIBC_H
#include <sys/types.h>
#include <compiler.h>
#if !WITH_HOST_LIBC
#include <limits.h>
#include <stdarg.h>
#include <lib/heap.h>
#define LIBC_FUNC(x) x
// for compatibility with code that gets is_pow2, ROUNDUP, etc through
// the standard lib headers. new/updated code should include libiboot.h
// directly instead of getting it through libc.h
#include <lib/libiboot.h>
#else // WITH_HOST_LIBC
// Prefix function names with libc_ in order to not collide with the real functions
#define LIBC_FUNC(x) libc_##x
#endif
__BEGIN_DECLS
/* stdio stuff */
int LIBC_FUNC(puts)(const char *str);
int LIBC_FUNC(getchar)(void);
int LIBC_FUNC(putchar)(int c);
int LIBC_FUNC(printf)(const char *fmt, ...) __printflike(1, 2);
int LIBC_FUNC(vprintf)(const char *fmt, va_list ap);
int LIBC_FUNC(snprintf)(char *str, size_t size, const char *fmt, ...) __printflike(3, 4);
int LIBC_FUNC(vsnprintf)(char *str, size_t size, const char *fmt, va_list ap);
/* fake fprintf to accomodate AssertMacros.h */
#if !WITH_HOST_LIBC
#define stdout 0
#define stderr 0
#endif
int LIBC_FUNC(fprintf)(void *stream, const char *fmt, ...) __printflike(2, 3);
/* string */
void * LIBC_FUNC(memchr)(void const *, int, size_t);
int LIBC_FUNC(memcmp)(void const *, const void *, size_t);
int LIBC_FUNC(memcmp_secure)(void const *, const void *, size_t);
void * LIBC_FUNC(memcpy)(void *, void const *, size_t);
void * LIBC_FUNC(memmove)(void *, void const *, size_t);
void * LIBC_FUNC(memset)(void *, int, size_t);
char * LIBC_FUNC(strchr)(char const *, int);
int LIBC_FUNC(strcmp)(char const *, char const *);
size_t LIBC_FUNC(strlen)(char const *);
int LIBC_FUNC(strncmp)(char const *, char const *, size_t);
char * LIBC_FUNC(strpbrk)(char const *, char const *);
char * LIBC_FUNC(strrchr)(char const *, int);
size_t LIBC_FUNC(strspn)(char const *, char const *);
size_t LIBC_FUNC(strcspn)(const char *s, const char *);
char * LIBC_FUNC(strstr)(char const *, char const *);
char * LIBC_FUNC(strtok)(char *, char const *);
int LIBC_FUNC(strcoll)(const char *s1, const char *s2);
size_t LIBC_FUNC(strxfrm)(char *dest, const char *src, size_t n);
char * LIBC_FUNC(strdup)(const char *str);
/* non standard string */
void * LIBC_FUNC(bcopy)(void const *, void *, size_t);
void LIBC_FUNC(bzero)(void *, size_t);
size_t LIBC_FUNC(strlcat)(char *, char const *, size_t);
size_t LIBC_FUNC(strlcpy)(char *, char const *, size_t);
int LIBC_FUNC(strncasecmp)(char const *, char const *, size_t);
int LIBC_FUNC(strnicmp)(char const *, char const *, size_t);
size_t LIBC_FUNC(strnlen)(char const *s, size_t count);
char * LIBC_FUNC(strsep)(char **stringp, const char *delim);
/* secure string functions */
#if !WITH_HOST_LIBC
#if !defined(__cplusplus)
#if __has_builtin(__builtin___memcpy_chk)
#define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, __builtin_object_size(dest, 0))
#endif
#if __has_builtin(__builtin___memmove_chk)
#define memmove(dest, src, len) __builtin___memmove_chk(dest, src, len, __builtin_object_size(dest, 0))
#endif
#if __has_builtin(__builtin___memset_chk)
#define memset(dest, c, len) __builtin___memset_chk(dest, c, len, __builtin_object_size(dest, 0))
#endif
#define bcopy(src, dest, len) memcpy(dest, src, len)
#define bzero(dest, len) memset(dest, 0, len)
#if __has_builtin(__builtin___strlcat_chk)
#define strlcat(dest, src, len) __builtin___strlcat_chk(dest, src, len, __builtin_object_size(dest, 1))
#endif
#if __has_builtin(__builtin___strlcpy_chk)
#define strlcpy(dest, src, len) __builtin___strlcpy_chk(dest, src, len, __builtin_object_size(dest, 1))
#endif
#if __has_builtin(__builtin___snprintf_chk)
#define snprintf(dst, size, ...) __builtin___snprintf_chk(dst, size, 0, __builtin_object_size(dst, 1), __VA_ARGS__)
#endif
#if __has_builtin(__builtin___vsnprintf_chk)
#define vsnprintf(dst, size, fmt, ap) __builtin___vsnprintf_chk(dst, size, 0, __builtin_object_size(dst, 1), fmt, ap)
#endif
#endif // __cplusplus
#endif // !WITH_HOST_LIBC
/* ctype */
int LIBC_FUNC(isalnum)(int c);
int LIBC_FUNC(isalpha)(int c);
int LIBC_FUNC(iscntrl)(int c);
int LIBC_FUNC(isdigit)(int c);
int LIBC_FUNC(isgraph)(int c);
int LIBC_FUNC(islower)(int c);
int LIBC_FUNC(isprint)(int c);
int LIBC_FUNC(ispunct)(int c);
int LIBC_FUNC(isspace)(int c);
int LIBC_FUNC(isupper)(int c);
int LIBC_FUNC(isxdigit)(int c);
int LIBC_FUNC(isascii)(int c);
int LIBC_FUNC(toascii)(int c);
unsigned char LIBC_FUNC(tolower)(unsigned char c);
unsigned char LIBC_FUNC(toupper)(unsigned char c);
/* errno */
#if !WITH_HOST_LIBC
extern int errno;
#include <errno.h>
#endif
/* numbers */
long LIBC_FUNC(strtol)(const char *nptr, char **endptr, int base);
unsigned long LIBC_FUNC(strtoul)(const char *nptr, char **endptr, int base);
unsigned long long LIBC_FUNC(strtoull)(const char * __restrict nptr, char ** __restrict endptr, int base);
int LIBC_FUNC(atoi)(const char *nptr);
/* stdlib */
int LIBC_FUNC(system)(const char *command);
void LIBC_FUNC(exit)(int status);
void LIBC_FUNC(qsort)(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
void LIBC_FUNC(srand)(unsigned int seed);
int LIBC_FUNC(rand)(void);
#if !WITH_HOST_LIBC
uint32_t swap32(uint32_t x);
uint16_t swap16(uint16_t x);
/* ntohl and friends */
uint32_t LIBC_FUNC(htonl)(uint32_t hostlong);
uint16_t LIBC_FUNC(htons)(uint16_t hostshort);
uint32_t LIBC_FUNC(ntohl)(uint32_t netlong);
uint16_t LIBC_FUNC(ntohs)(uint16_t netshort);
#endif
__END_DECLS
#endif
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2007-2009 Apple Inc. All rights reserved.
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef __LIB_LIBIBOOT_H
#define __LIB_LIBIBOOT_H
#include <sys/types.h>
__BEGIN_DECLS
/* for powers of 2 only */
#define ROUNDUP(a, b) (((a) + ((b) - 1)) & (~((b) - 1)))
#define ROUNDDOWN(a, b) (((a) / (b)) * (b))
/* some of our own stuff */
void hexdump(const void *_ptr, size_t len);
#define is_pow2(n) ((((n)-1) & (n)) == 0)
int log2_int(unsigned int val);
__END_DECLS
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2007 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef __LIB_LZSS_H
#define __LIB_LZSS_H
#include <sys/types.h>
#include <sys.h>
__BEGIN_DECLS
uint32_t decompress_lzss(uint8_t * __restrict dst, uint32_t dstlen, const uint8_t * __restrict src, uint32_t srclen);
__END_DECLS
#endif
+115
View File
@@ -0,0 +1,115 @@
/*
* Copyright (C) 2006-2012 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_MACHO_H
#define __LIB_MACHO_H
#include <lib/image.h>
#include <sys/types.h>
__BEGIN_DECLS
/**
* load a kernelcache from memory, return the entry point
*
* \param[in] addr Address of the kernelcache in memory.
* \param[in] size Size of the kernelcache in memory.
* \param[in] type Type of kernelcache (restore or local boot).
* \param[out] entry Entrypoint recovered from the kernelcache.
* \param[out] boot_args_out Boot arguments to pass to the kernelcache entry point.
*
* \return 0 Kernelcache was loaded successfully.
* \return -2 Kernelcache is too large.
* \return -3 Kernelcache container failed validation (signature,
* wrong system, etc.)
* \return -4 Not a valid kernelcache (bad magic number).
* \return -5 Decompression failed.
* \return -6 Not a valid Mach-o image (bad magic number).
* \return -7 Mach-o load failed.
*/
int load_kernelcache(addr_t addr, size_t size, uint32_t type, addr_t *entry, addr_t *boot_args_out);
/**
* load a kernelcache from a path, return the entry point
*
* \param[in] path Filesystem path from which to read the kernelcache.
* \param[in] type Type of kernelcache (restore or local boot).
* \param[out] entry Entrypoint recovered from the kernelcache.
* \param[out] boot_args_out Boot arguments to pass to the kernelcache entry point.
*
* \return 0 Kernelcache was loaded successfully.
* \return -2 Kernelcache is too large.
* \return -3 Kernelcache container failed validation (signature,
* wrong system, etc.)
* \return -4 Not a valid kernelcache (bad magic number).
* \return -5 Decompression failed.
* \return -6 Not a valid Mach-o image (bad magic number).
* \return -7 Mach-o load failed.
*/
int load_kernelcache_file(const char *path, uint32_t type, addr_t *entry, addr_t *boot_args_out);
/**
* load a kernelcache from a known image, return the entry point
*
* \param[in] image Known image from which to read the kernelcache.
* \param[in] type Type of kernelcache (restore or local boot).
* \param[out] entry Entrypoint recovered from the kernelcache.
* \param[out] boot_args_out Boot arguments to pass to the kernelcache entry point.
*
* \return 0 Kernelcache was loaded successfully.
* \return -2 Kernelcache is too large.
* \return -3 Kernelcache container failed validation (signature,
* wrong system, etc.)
* \return -4 Not a valid kernelcache (bad magic number).
* \return -5 Decompression failed.
* \return -6 Not a valid Mach-o image (bad magic number).
* \return -7 Mach-o load failed.
*/
int load_kernelcache_image(struct image_info *image, uint32_t type, addr_t *entry, addr_t *boot_args_out);
/**
* load a monitor from a path
*
* A loaded monitor is recognised by the kernelcache loader; the
* appropriate entrypoint will be returned at kernelcache load time.
*
* \param[in] path Filesystem path from which to read the kernelcache.
*
* \return 0 Monitor was loaded successfully.
* \return -2 Monitor is too large.
* \return -3 Monitor container failed validation (signature,
* wrong system, etc.)
* \return -6 Not a valid Mach-o image (bad magic number).
* \return -7 Mach-o load failed.
*/
int load_monitor_file(const char *path);
/**
* load a monitor from a known image
*
* \param[in] address Known image address
* \param[in] size Known image size
*
* \return 0 Monitor was loaded successfully.
* \return -2 Monitor is too large.
* \return -3 Monitor container failed validation (signature,
* wrong system, etc.)
* \return -6 Not a valid Mach-o image (bad magic number).
* \return -7 Mach-o load failed.
*/
int load_monitor_image(addr_t address, size_t size);
bool macho_valid(addr_t addr);
bool macho_load(addr_t imageAddr, size_t imageSize, addr_t loadAddr, addr_t *virtualBase, addr_t *virtualEnd, addr_t *entryPoint, size_t slide);
__END_DECLS
#endif
+219
View File
@@ -0,0 +1,219 @@
/*
* Copyright (C) 2008-2015 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef _MIB_H
#define _MIB_H
#include <stdbool.h>
#include <lib/mib/mib_nodes.h>
#include <sys/linker_set.h>
#include <sys/types.h>
/*
* Standard MIB application/product definitions.
*/
#define MIB_APP_PROD_UNKNOWN (0)
#define MIB_APP_PROD_SECUREROM (1)
#define MIB_APP_PROD_IBSS (2)
#define MIB_APP_PROD_IBEC (3)
#define MIB_APP_PROD_IBOOT (4)
#define MIB_APP_PROD_LLB (5)
#define MIB_APP_PROD_EMBEDDEDIOP (8)
__BEGIN_DECLS
#define OID_SUBSYSTEM(_o) ((_o)>>24)
#define OID_NODE(_o) (((_o)>>16)&0xff)
#define OID_SUBSYSTEM_MASK (0xff<<24)
#define OID_NODE_MASK (0xff<<16)
typedef void (* mib_func_t)(uint32_t oid, void *arg, void *value);
struct mib_func_spec {
mib_func_t func;
void *arg;
};
union mib_value {
uint32_t v32;
uint64_t v64;
bool v_bool;
void *v_ptr;
struct mib_func_spec v_func;
};
struct mib_node {
uint32_t node_oid;
uint32_t node_type;
union mib_value node_data;
};
/* node data types */
#define kOIDTypeUInt32 (0x00<<16) /* node data is uint32_t */
#define kOIDTypeInt32 (0x01<<16) /* node data is int32_t */
#define kOIDTypeUInt64 (0x02<<16) /* node data is uint64_t */
#define kOIDTypeInt64 (0x03<<16) /* node data is int64_t */
#if defined(__LP64__)
#define kOIDTypeAddr kOIDTypeUInt64 /* node data is uint64_t */
#define kOIDTypeSize kOIDTypeUInt64 /* node data is uint64_t */
#else
#define kOIDTypeAddr kOIDTypeUInt32 /* node data is uint32_t */
#define kOIDTypeSize kOIDTypeUInt32 /* node data is uint32_t */
#endif
#define kOIDTypeBoolean (0x04<<16) /* node data is bool */
#define kOIDTypeString (0x05<<16) /* node data is const char * */
#define kOIDTypeStruct (0x06<<16) /* node data is void * */
#define kOIDTypeOIDIndirect (0x07<<16) /* node data is oid (reference to another node) */
#define kOIDTypeMask (0xff<<16)
#define kOIDStructSizeMask (0xffff)
/* node data qualifiers */
#define kOIDDataIndirect (1<<24) /* data is indirected through v_ptr */
#define kOIDFunction (2<<24) /* data is obtained by calling v_func */
#define kOIDWeak (4<<24) /* node only valid if no other node present */
# define MIB_CONSTANT(_oid, _type, _value) \
static const struct mib_node __attribute__((used)) \
__mib_node_ ## _oid = { \
.node_oid = _oid, \
.node_type = _type, \
.node_data.v64 = (uint64_t)(_value) \
}; \
LINKER_SET_ENTRY(mib, __mib_node_ ## _oid)
# define MIB_CONSTANT_WEAK(_oid, _type, _value) \
static const struct mib_node __attribute__((used)) \
__mib_node_weak_ ## _oid = { \
.node_oid = _oid, \
.node_type = _type | kOIDWeak, \
.node_data.v64 = (uint64_t)(_value) \
}; \
LINKER_SET_ENTRY(mib, __mib_node_weak_ ## _oid)
# define MIB_CONSTANT_PTR(_oid, _type, _value) \
static const struct mib_node __attribute__((used)) \
__mib_node_ ## _oid = { \
.node_oid = _oid, \
.node_type = _type, \
.node_data.v_ptr = (_value) \
}; \
LINKER_SET_ENTRY(mib, __mib_node_ ## _oid)
# define MIB_CONSTANT_PTR_WEAK(_oid, _type, _value) \
static const struct mib_node __attribute__((used)) \
__mib_node_weak_ ## _oid = { \
.node_oid = _oid, \
.node_type = _type | kOIDWeak, \
.node_data.v_ptr = (_value) \
}; \
LINKER_SET_ENTRY(mib, __mib_node_weak_ ## _oid)
# define MIB_VARIABLE(_oid, _type, _var) \
static const struct mib_node __attribute__((used)) \
__mib_node_##_oid = { \
.node_oid = _oid, \
.node_type = _type | kOIDDataIndirect, \
.node_data.v_ptr = (void *)(&_var) \
}; \
LINKER_SET_ENTRY(mib, __mib_node_ ## _oid)
# define MIB_VARIABLE_WEAK(_oid, _type, _var) \
static const struct mib_node __attribute__((used)) \
__mib_node_weak_ ## _oid = { \
.node_oid = _oid, \
.node_type = _type | kOIDDataIndirect | kOIDWeak, \
.node_data.v_ptr = (void *)(&_var) \
}; \
LINKER_SET_ENTRY(mib, __mib_node_weak_ ## _oid)
# define MIB_FUNCTION(_oid, _type, _func, _arg) \
static const struct mib_node __attribute__((used)) \
__mib_node_##_oid = { \
.node_oid = _oid, \
.node_type = _type | kOIDFunction, \
.node_data.v_func = {_func, _arg} \
}; \
LINKER_SET_ENTRY(mib, __mib_node_ ## _oid)
# define MIB_FUNCTION_WEAK(_oid, _type, _func, _arg) \
static const struct mib_node __attribute__((used)) \
__mib_node_weak_ ## _oid = { \
.node_oid = _oid, \
.node_type = _type | kOIDFunction | kOIDWeak, \
.node_data.v_func = {_func, _arg} \
}; \
LINKER_SET_ENTRY(mib, __mib_node_weak_ ## _oid)
/*
* Find a node in the MIB.
*/
union mib_value *mib_find_oid(uint32_t oid);
/*
* Find a node of an expected type in the MIB and return its value.
* Returns false if the OID is not present.
*
* This interface should only be used for optional nodes; if a node
* is expected to exist, use the mib_get_* interfaces to avoid duplicating
* error checking.
*/
bool _mib_find(uint32_t oid, uint32_t node_type, void *value);
bool mib_exists(uint32_t oid, void *value);
/*
* Return the value of an OID expected to be in the MIB; the
* MIB will panic on behalf of the caller if the node is not
* found.
*/
void _mib_get(uint32_t oid, uint32_t node_type, void *value);
#define MIB_GET_TEMPLATE(stype, type, oid_type) \
static inline type \
mib_get_##stype(uint32_t oid) { \
type ret; \
_mib_get(oid, oid_type, &ret); \
return ret; \
} \
\
static inline type \
mib_get_##stype##_opt(uint32_t oid, type def) { \
type ret = def; \
_mib_find(oid, oid_type, &ret); \
return ret; \
}
MIB_GET_TEMPLATE(u32, uint32_t, kOIDTypeUInt32)
MIB_GET_TEMPLATE(s32, int32_t, kOIDTypeInt32)
MIB_GET_TEMPLATE(u64, uint64_t, kOIDTypeUInt32)
MIB_GET_TEMPLATE(s64, int64_t, kOIDTypeInt64)
MIB_GET_TEMPLATE(addr, uintptr_t, kOIDTypeAddr)
MIB_GET_TEMPLATE(size, size_t, kOIDTypeSize)
MIB_GET_TEMPLATE(bool, bool, kOIDTypeBoolean)
MIB_GET_TEMPLATE(str, const char *, kOIDTypeString)
MIB_GET_TEMPLATE(ptr, const void *, kOIDTypeStruct)
#undef MIB_GET_TEMPLATE
/*
* MIB node descriptions are automatically generated at build time.
*/
struct mib_description {
uint32_t oid;
const char *desc;
};
extern struct mib_description mib_desc[];
__END_DECLS
#endif /* _MIB_H */
+143
View File
@@ -0,0 +1,143 @@
// Copyright (C) 2014-2015 Apple Inc. All rights reserved.
//
// This document is the property of Apple Inc.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// Apple Inc.
//
#ifndef _MIB_DEF_H
#define _MIB_DEF_H
#include <lib/mib.h>
#include <platform/memmap.h>
// Application/Product selection
#if PRODUCT_IBSS
#define MIB_APP_PROD MIB_APP_PROD_IBSS
#elif PRODUCT_IBEC
#define MIB_APP_PROD MIB_APP_PROD_IBEC
#elif PRODUCT_IBOOT
#define MIB_APP_PROD MIB_APP_PROD_IBOOT
#elif PRODUCT_LLB
#define MIB_APP_PROD MIB_APP_PROD_LLB
#elif APPLICATION_EMBEDDEDIOP
#define MIB_APP_PROD MIB_APP_PROD_EMBEDDEDIOP
#elif APPLICATION_SECUREROM
#define MIB_APP_PROD MIB_APP_PROD_SECUREROM
#else
#error "Unknown APPLICATION/PRODUCT"
#endif
// Standard MIB constants for all platforms and targets
MIB_CONSTANT(kMIBPlatformCacheLineSize, kOIDTypeSize, CPU_CACHELINE_SIZE);
MIB_CONSTANT(kMIBPlatformSDRAMBaseAddress, kOIDTypeAddr, SDRAM_BASE);
MIB_CONSTANT(kMIBPlatformSDRAMSize, kOIDTypeSize, (SDRAM_END - SDRAM_BASE));
MIB_CONSTANT(kMIBTargetApplicationProduct, kOIDTypeUInt32, MIB_APP_PROD);
MIB_CONSTANT(kMIBPlatformPageSize, kOIDTypeSize, PAGE_SIZE);
#if WITH_IMAGE4
MIB_CONSTANT(kMIBPlatformImageFormat, kOIDTypeUInt32, 4);
#elif WITH_IMAGE3
MIB_CONSTANT(kMIBPlatformImageFormat, kOIDTypeUInt32, 3);
#endif
#ifdef PLATFORM_ENTROPY_RATIO
MIB_CONSTANT(kMIBPlatformEntropyRatio, kOIDTypeUInt32, PLATFORM_ENTROPY_RATIO);
#endif
// All of the following depend upon INSECURE_MEMORY_BASE being defined
#ifdef INSECURE_MEMORY_BASE
#ifdef DEFAULT_DEVICETREE_ADDRESS
MIB_CONSTANT(kMIBTargetDefaultDeviceTreeAddress,kOIDTypeAddr, DEFAULT_DEVICETREE_ADDRESS);
#endif
#ifdef DEFAULT_DEVICETREE_SIZE
MIB_CONSTANT(kMIBTargetDefaultDeviceTreeSize, kOIDTypeSize, DEFAULT_DEVICETREE_SIZE);
#endif
#ifdef DEFAULT_FREE_ADDRESS
MIB_CONSTANT(kMIBTargetDefaultFreeAddress, kOIDTypeAddr, DEFAULT_FREE_ADDRESS);
#endif
#ifdef DEFAULT_LOAD_ADDRESS
MIB_CONSTANT(kMIBTargetDefaultLoadAddress, kOIDTypeAddr, DEFAULT_LOAD_ADDRESS);
#endif
#ifdef DEFAULT_LOAD_SIZE
MIB_CONSTANT(kMIBTargetDefaultLoadSize, kOIDTypeSize, DEFAULT_LOAD_SIZE);
#endif
#ifdef DEFAULT_KERNEL_ADDRESS
MIB_CONSTANT(kMIBTargetDefaultKernelAddress, kOIDTypeAddr, DEFAULT_KERNEL_ADDRESS);
#endif
#ifdef DEFAULT_KERNEL_SIZE
MIB_CONSTANT(kMIBTargetDefaultKernelSize, kOIDTypeSize, DEFAULT_KERNEL_SIZE);
#endif
#ifdef DEFAULT_RAMDISK_ADDRESS
MIB_CONSTANT(kMIBTargetDefaultRamdiskAddress, kOIDTypeAddr, DEFAULT_RAMDISK_ADDRESS);
#endif
#ifdef DEFAULT_RAMDISK_SIZE
MIB_CONSTANT(kMIBTargetDefaultRamdiskSize, kOIDTypeSize, DEFAULT_RAMDISK_SIZE);
#endif
#ifdef DISPLAY_BASE
MIB_CONSTANT(kMIBTargetDisplayBaseAddress, kOIDTypeAddr, DISPLAY_BASE);
#endif
#endif // INSECURE_MEMORY_BASE
#ifdef PANIC_BASE
MIB_CONSTANT(kMIBTargetPanicBufferAddress, kOIDTypeAddr, PANIC_BASE);
#endif
#ifdef PANIC_SIZE
MIB_CONSTANT(kMIBTargetPanicBufferSize, kOIDTypeSize, PANIC_SIZE);
#endif
#if (PRODUCT_LLB || APPLICATION_SECUREROM) && WITH_NO_RANDOM_HEAP_COOKIE
MIB_CONSTANT(kMIBTargetRandomHeapCookie, kOIDTypeBoolean, false);
#else
MIB_CONSTANT(kMIBTargetRandomHeapCookie, kOIDTypeBoolean, true);
#endif
// Target-specified MIB weak overrides
#if WITH_HW_ASP
MIB_CONSTANT(kMIBTargetWithHwAsp, kOIDTypeBoolean, true);
#endif
#if WITH_EFFACEABLE
MIB_CONSTANT(kMIBTargetWithEffaceable, kOIDTypeBoolean, true);
#endif
#if WITH_FS
MIB_CONSTANT(kMIBTargetWithFileSystem, kOIDTypeBoolean, true);
#endif
#if WITH_HW_FLASH_NAND
MIB_CONSTANT(kMIBTargetWithHwFlashNand, kOIDTypeBoolean, true);
#endif
#if WITH_HW_FLASH_NOR
MIB_CONSTANT(kMIBTargetWithHwFlashNor, kOIDTypeBoolean, true);
#endif
#if WITH_NVME
MIB_CONSTANT(kMIBTargetWithHwNvme, kOIDTypeBoolean, true);
#endif
#if WITH_LEGACY_PANIC_LOGS
MIB_CONSTANT(kMIBTargetWithLegacyPanicLogs, kOIDTypeBoolean, true);
#endif
// Get rid of intermediate abstractions
#undef MIB_APP_PROD
#endif /* _MIB_DEF_H */
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_NET_H
#define __LIB_NET_H
#include <sys/types.h>
__BEGIN_DECLS
int start_network_stack(void);
int stop_network_stack(void);
/* ip and mac address string manipulation routines */
void mac2str(uint8_t mac[6], char *ascii, size_t size);
void ip2str(const uint8_t *ip, char *str, size_t size);
__END_DECLS
#endif
+44
View File
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __ARP_H__
#define __ARP_H__
#include <sys/types.h>
__BEGIN_DECLS
#define ARP_OFFSET_HTYPE 0
#define ARP_OFFSET_PTYPE 2
#define ARP_OFFSET_HLEN 4
#define ARP_OFFSET_PLEN 5
#define ARP_OFFSET_OPER 6
#define ARP_OFFSET_SHA 8
int arp_layer(bool on);
int arp_get_macaddr(uint32_t ip,char *mac);
int arp_fill(uint32_t ip, utime_t timeout); /* send arp requests until it is satisfied or timeout */
void arp_dump_table(void);
#define ARP_CACHE_SIZE 32
typedef struct arp_cache_entry {
uint32_t ip;
char mac[6];
struct arp_cache_entry *next;
} arp_cache_entry_t;
typedef struct arp_cache {
arp_cache_entry_t cache[ARP_CACHE_SIZE];
} arp_cache_t;
__END_DECLS
#endif
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __CALLBACKS_H__
#define __CALLBACKS_H__
#include <sys/types.h>
__BEGIN_DECLS
typedef int (*callback_handler)(char *data,int offset,int len,void *prevlayerdata);
struct listentry;
typedef struct listentry {
int cb_id;
int port; //port/service/etc
callback_handler callback;
struct listentry *next;
} listentry_t;
typedef struct callbacks {
listentry_t *first;
}callbacks_t;
int registerCallback(callbacks_t *,int port,callback_handler cb);
int unregisterCallback(callbacks_t *cbs,int cb_id);
callback_handler find_callback(callbacks_t *cbs,int port);
__END_DECLS
#endif
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __ETHERNET_H__
#define __ETHERNET_H__
#include <sys/types.h>
#include <sys/callout.h>
#include "callbacks.h"
#include "xp.h"
__BEGIN_DECLS
#define ETHERTYPE_ARP 0x806
#define ETHERTYPE_IPV4 0x800
#define ETHERNET_OFFSET 14
int registerEtherTypeHandler(int type,callback_handler cb);
int unregisterEtherTypeHandler(int id);
int add_eth_and_transmit(mymbuf_t *,char *dstmac,int ethertype);
void ethernet_init(void);
void ethernet_uninit(void);
void ethernet_workloop(struct callout *c, void *param);
void ethernet_input(mymbuf_t *inputbuf);
__END_DECLS
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __ICMP_H___
#define __ICMP_H__
#include <sys/types.h>
#include "callbacks.h"
__BEGIN_DECLS
#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
int registerICMPHandler(int messagetype,callback_handler cb);
int unregisterICMPHandler(int id);
int icmp_layer(bool on);
__END_DECLS
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __IPV4_H__
#define __IPV4_H__
#include <sys/types.h>
#include "callbacks.h"
#include "xp.h"
__BEGIN_DECLS
#define IPV4_ICMP 1
#define IPV4_TCP 6
#define IPV4_UDP 17
int ipv4_layer(bool on);
int registerIPV4Handler(int protocol,callback_handler handler);
int unregisterIPV4Handler(int id);
uint32_t ipv4_get_ip();
void ipv4_set_ip(uint32_t ip);
int transmit_and_add_ipv4(mymbuf_t *mbuf,uint32_t dest,int protocol);
__END_DECLS
#endif
+54
View File
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_NET_MBUF_H
#define __LIB_NET_MBUF_H
#include <sys/types.h>
__BEGIN_DECLS
#define USE_BUILTIN_MBUF 1
#if defined(USE_BUILTIN_MBUF) && USE_BUILTIN_MBUF
struct mbufentry;
typedef struct mbufentry {
int flag;
int len;
char *data;
struct mbufentry *next;
} mbufentry_t;
typedef struct mymbuf {
mbufentry_t *first;
int allocated_length;
int current_length;
char *primarydata;
int offset;
}mymbuf_t;
#else
#error "Unsupported platform"
#endif
mymbuf_t * mbuf_initialize(int packetsize,int header,int trailer);
void mbuf_destroy(mymbuf_t *data);
char* mbuf_head(mymbuf_t *buffer, int len);
char* mbuf_tail(mymbuf_t *buffer, int len);
int mbuf_getlength(mymbuf_t *buffer);
char * mbuf_getlinear(mymbuf_t *buffer);
void mbuf_setlength(mymbuf_t *buffer,int len);
void mbuf_setoffset(mymbuf_t *buffer,int offset);
int mbuf_getallocatedlength(mymbuf_t *buffer);
int mbuf_copy(mymbuf_t *dest, const mymbuf_t *src);
__END_DECLS
#endif
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __UDP_H__
#define __UDP_H__
#include <sys/types.h>
__BEGIN_DECLS
int transmit_udp(mymbuf_t *data, uint32_t toip,int toport, int fromport);
int unregisterUDPHandler(int id);
int registerUDPHandler(int port,callback_handler cb);
int udp_layer(bool on);
typedef struct udpinfo {
uint32_t srcip;
uint16_t srcport;
uint16_t length;
} udpinfo_t;
__END_DECLS
#endif
+38
View File
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __XP_H__
#define __XP_H__
#include <sys/types.h>
#include <stdint.h>
#include <lib/net/mbuf.h>
__BEGIN_DECLS
//Card specific instructions.
int xp_initialize(void);
int xp_getmac(uint8_t *addr);
void xp_packet_input(void *ethptr, mymbuf_t *inputbuf);
//mymbuf_t * xp_get_packet(mymbuf_t *);
int xp_transmit_packet(mymbuf_t *buffer);
#define htons(A) ( (((A) & 0xff00) >> 8) | \
((A) & 0x00ff) << 8)
#define htonl(A) ( (((A) & 0xff000000) >> 24) | \
(((A) & 0x00ff0000) >> 8) | \
(((A) & 0x0000ff00) << 8) | \
(((A) & 0x000000ff) << 24))
#define ntohs htons
#define ntohl htonl
__END_DECLS
#endif
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2012, 2014-2015 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef _NONCE_H_
#define _NONCE_H_
// =============================================================================
#include <sys/hash.h>
#include <sys/types.h>
#if HASH_OUTPUT_SIZE > 32 // Bytes
#define NONCE_HASH_OUTPUT_SIZE (32)
#else
#define NONCE_HASH_OUTPUT_SIZE HASH_OUTPUT_SIZE
#endif
int mobile_ap_nonce_consume_nonce(uint64_t *nonce);
#endif /* _NONCE_H_ */
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_NVRAM_H
#define __LIB_NVRAM_H
#include <sys/types.h>
#include <lib/devicetree.h>
__BEGIN_DECLS
int nvram_load(void);
int nvram_save(void); // write out the environment
int nvram_set_panic(const void *base, size_t length); // copy panic log to staging
int nvram_update_devicetree(dt_node_t *node, const char *propname); // copy nvram content to devicetree
__END_DECLS
#endif
+204
View File
@@ -0,0 +1,204 @@
/*
* Copyright (C) 2007-2013 Apple Inc. All rights reserved.
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef __LIB_PAINT_H
#define __LIB_PAINT_H
#include <sys/types.h>
#include <lib/env.h>
#include <lib/image.h>
__BEGIN_DECLS
enum colorspace {
CS_4BPP,
CS_8BPP,
CS_RGB332,
CS_RGB565,
CS_ARGB1555,
CS_ARGB4444,
CS_RGB888,
CS_ARGB8888,
CS_ARGB8101010,
};
#define ColorIndec4BPP(color) (0)
#define ColorIndex8BPP(color) (0)
#define ColorRGB332(color) (((color >> 6) & 0x03) | ((color >> 11) & 0x1C) | ((color >> 16) & 0xE0))
#define ColorRGB565(color) (((color >> 3) & 0x001F) | ((color >> 5) & 0x07E0) | ((color >> 8) & 0xF800))
#define ColorRGB555(color) (((color >> 3) & 0x001F) | ((color >> 6) & 0x03E0) | ((color >> 9) & 0x7C00))
#define ColorRGB444(color) (((color >> 4) & 0x000F) | ((color >> 8) & 0x00F0) | ((color >> 12) & 0x0F00))
#define ColorRGB888(color) (color & 0x00FFFFFF)
#define ColorRGB101010(color) (color & 0x3FFFFFFF)
#define ColorA8(color) ((color >> 32)& 0xFF)
#define RGB(r,g,b) (((uint32_t)((r) & 0xFF) << 16) | ((uint32_t)((g) & 0xFF) << 8) | ((uint32_t)((b) & 0xFF) << 0))
#define RGB_MASK RBG(0xFF, 0xFF, 0xFF)
#define RGB_R(c) ((uint32_t)(((c) >> 16) & 0xFF))
#define RGB_G(c) ((uint32_t)(((c) >> 8) & 0xFF))
#define RGB_B(c) ((uint32_t)(((c) >> 0) & 0xFF))
#define RGB10(r,g,b) (((uint32_t)((r) & 0x3FF) << 20) | ((uint32_t)((g) & 0x3FF) << 10) | ((uint32_t)((b) & 0x3FF) << 0))
#define RGB10_MASK RBG10(0x3FF, 0x3FF, 0x3FF)
#define RGB10_R(c) ((uint32_t)(((c) >> 20) & 0x3FF))
#define RGB10_G(c) ((uint32_t)(((c) >> 10) & 0x3FF))
#define RGB10_B(c) ((uint32_t)(((c) >> 0) & 0x3FF))
#define DCLR_VERSION(major,minor) ((((major) & 0xFF) << 8) | (((minor) & 0xFF) << 0))
#define WpCl_Quotation_Denominator (16)
#define MAX_NUM_PLANES_PER_CANVAS 2
struct syscfg_wpcl {
u_int32_t version;
u_int32_t red;
u_int32_t green;
u_int32_t blue;
};
union syscfg_DCLr_RGB {
u_int32_t rgb;
struct {
u_int8_t blue;
u_int8_t green;
u_int8_t red;
u_int8_t reserved;
} component;
};
typedef struct syscfg_DClr {
u_int8_t minor_version;
u_int8_t major_version;
u_int8_t reserved_2;
u_int8_t reserved_3;
union syscfg_DCLr_RGB device_enclosure;
union syscfg_DCLr_RGB cover_glass;
u_int8_t reserved_C;
u_int8_t reserved_D;
u_int8_t reserved_E;
u_int8_t reserved_F;
} syscfg_DClr_t;
typedef enum {
clrcColorUnknown = -1,
clrcColorBlack = 0,
clrcColorWhite = 1,
clrcColorRed = 2,
clrcColorSilver = 3,
clrcColorPink = 4,
clrcColorBlue = 5,
clrcColorYellow = 6,
clrcColorGold = 7,
clrcColorSparrow = 8,
clrcColorCount
} clrcColor;
typedef struct syscfg_ClrC {
u_int8_t clrcColor; // clrcColor
u_int8_t reserved[15];
} syscfg_ClrC_t;
// Color remapping policy options a target may select
enum color_map_policy {
COLOR_MAP_POLICY_NONE, // Common remapping: No color remapping (legacy devices)
COLOR_MAP_POLICY_INVERT, // Common remapping: Invert colors
};
// Function pointer typedefs for color remappers.
typedef uint32_t (* map_color_t)(uint64_t color); // Target specific color remapping
// Color remapping policy data
typedef struct color_policy {
enum color_map_policy policy_type; // Color remapping policy type
void *color_table; // Pointer to policy-specific color table (e.g., a color_policy_invert_t)
uint32_t color_count; // Number of entries in the color table
map_color_t map_color; // Pointer to color remapping function
} color_policy_t;
// Color remapping table provided by the target for COLOR_MAP_POLICY_INVERT.
typedef struct color_policy_invert {
uint32_t cover_glass; // Cover glass color
bool invert; // Invert bg/fg colors if true
} color_policy_invert_t;
struct plane {
enum colorspace cs;
void *fb_virt;
void * db_virt; //draw buffer, start: fb_virt + frame size, align to next 4K
u_int32_t plane_size;
u_int32_t pixel_size;
u_int32_t pixel_size_per_channel;
u_int32_t line_x;
u_int32_t width;
u_int32_t height;
u_int32_t stride;
void (* plot)(struct plane *p, u_int32_t x, u_int32_t y, uint64_t color);
u_int32_t (* get_pixel)(struct plane *p, u_int32_t x, u_int32_t y);
void (* hline)(struct plane *p, u_int32_t x, u_int32_t y, u_int32_t len, uint64_t color);
void (* vline)(struct plane *p, u_int32_t x, u_int32_t y, u_int32_t len, uint64_t color);
};
struct canvas {
enum colorspace cs;
struct plane planes[MAX_NUM_PLANES_PER_CANVAS];
uint32_t num_of_active_planes;
void *fb_virt;
uintptr_t fb_phys;
u_int32_t x;
u_int32_t y;
map_color_t map_color;
};
int paint_init(void *window, addr_t scratch, size_t scratch_size);
int paint_set_bgcolor(uint16_t bg_red, uint16_t bg_green, uint16_t bg_blue);
int paint_set_picture_for_tag(u_int32_t image_tag);
int paint_set_picture_for_tag_list(u_int32_t image_tag, int image_offset, int image_count);
int paint_set_picture(struct image_info *pict_info);
int paint_set_picture_list(struct image_info *pict_info, int image_offset, int image_count);
int paint_set_picture_from_file(const char *path, uint32_t type);
int paint_update_image(void);
void paint_install_gamma_table(u_int32_t display_id,
u_int32_t entries,
volatile u_int32_t *red_lut,
volatile u_int32_t *green_lut,
volatile u_int32_t *blue_lut);
void paint_get_syscfg_wpcl(struct syscfg_wpcl *wpcl);
color_policy_t *paint_color_map_init(enum colorspace cs);
bool paint_color_map_enable(bool enable);
bool paint_color_map_is_desired(void);
bool paint_color_map_is_enabled(void);
bool paint_color_map_is_invalid(void);
enum color_map_policy paint_get_color_policy(void);
int paint_color_map_get_DClr(syscfg_DClr_t *DClr, size_t size, bool report);
int paint_displaytest(void);
struct canvas *get_canvas(void);
void set_canvas(struct canvas *c, void *fb, size_t region_size, uint32_t x, uint32_t y, uint32_t line_x, enum colorspace cs);
void move_canvas(struct canvas *c, void *fb);
struct plane *get_plane(uint32_t plane_num);
void plot(struct plane *p, u_int32_t x, u_int32_t y, uint64_t color);
u_int32_t get_pixel(struct plane *p, u_int32_t x, u_int32_t y);
void fill_rect(struct canvas *c, u_int32_t top_x, u_int32_t top_y, u_int32_t w, u_int32_t h, uint64_t color);
void display_paint_information();
void display_paint_canvas();
void display_paint_plane(uint32_t plane_num);
__END_DECLS
#endif /* __LIB_PAINT_H */
+24
View File
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2010 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef __LIB_PANICLOG_H
#define __LIB_PANICLOG_H
#include <sys/types.h>
__BEGIN_DECLS
void clear_panic_region(unsigned char pattern);
int save_panic_log(void); // move panic log from RAM to NVRAM
__END_DECLS
#endif
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_PARTITION_H
#define __LIB_PARTITION_H
#include <sys/types.h>
#include <lib/blockdev.h>
__BEGIN_DECLS
int partition_scan_and_publish_subdevices(const char *dev_name);
__END_DECLS
#endif
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef __LIB_PKI_H
#define __LIB_PKI_H
#include <sys/types.h>
__BEGIN_DECLS
int verify_signature_with_chain(
void *chain_blob, size_t chain_blob_length,
void *sig_blob, size_t sig_blob_len,
void *hash_blob, size_t hash_blob_len,
void **img3_spec_blob, size_t *img3_spec_blob_len,
void **ticket_spec_blob, size_t *ticket_spec_blob_len);
__END_DECLS
#endif
+52
View File
@@ -0,0 +1,52 @@
#ifndef __PROFILE_H
#define __PROFILE_H
#if WITH_PROFILE
#include <platform/memmap.h>
#include <sys/types.h>
struct profile_event {
uint32_t time;
addr_t pc;
uint32_t data1;
uint32_t data2;
};
struct profile_buffer {
uint32_t magic;
uint32_t count;
uint32_t pc_bytes;
uint32_t timer_ticks_per_sec;
struct profile_event events[];
};
#define PROFILE_2(_data1, _data2) \
do { \
addr_t current_pc = 0; \
__asm__ volatile ("L_%=: adr %0, L_%=" : "=r"(current_pc)); \
profile(current_pc, (_data1), (_data2)); \
} while(0)
#define PROFILE_INIT() profile_init()
#define PROFILE_HANDOFF() profile_handoff()
#else // !WITH_PROFILE
#define PROFILE_2(data1, data2) do {} while(0)
#define PROFILE_INIT() do {} while(0)
#define PROFILE_HANDOFF() do {} while(0)
#endif
#define PROFILE_1(data1) PROFILE_2((data1), 0)
#define PROFILE() PROFILE_2(0, 0)
#define PROFILE_ENTER(tag) PROFILE_2(((tag) & 0xFFFFFF) | ('<' << 24), 0)
#define PROFILE_EXIT(tag) PROFILE_2(((tag) & 0xFFFFFF) | ('>' << 24), 0)
void profile_init(void);
void profile(addr_t pc, uint32_t data1, uint32_t data2);
void profile_relocate(void);
void profile_handoff(void);
#endif
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef _RAMDISK_H
#define _RAMDISK_H
#include <sys/types.h>
extern int ramdisk_init(void);
extern int load_ramdisk_file(const char *path);
extern int load_ramdisk(addr_t *ramdisk_addr, size_t *ramdisk_size);
#endif /* _RAMDISK_H */
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef __LIB_RANDOM_H
#define __LIB_RANDOM_H
#include <sys/types.h>
__BEGIN_DECLS
// Fills the provided buffer with random data
int random_get_bytes(u_int8_t *buffer, size_t length);
int random_get_bytes_noheap(uint8_t *buffer, size_t length, void *entropy_buffer, size_t entropy_buffer_size);
#if DEBUG_BUILD
// Fills the provided buffer with random data
// Allows setting the entropy ratio
// This is for debug only
int random_get_bytes_debug(u_int8_t *buffer, size_t length, u_int32_t entropy_ratio);
#endif
__END_DECLS
#endif /* __LIB_RANDOM_H */
+101
View File
@@ -0,0 +1,101 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
/*
* Read-only support for iPod-style SysCfg data.
*/
#ifndef __SYSCFG_H
#define __SYSCFG_H
#include <sys/types.h>
__BEGIN_DECLS
/* where we expect to find the magic number in a bdev */
#define kSysCfgBdevOffset 0x4000
struct syscfgEntry {
u_int32_t seTag;
u_int8_t seData[16];
};
struct syscfgEntryCNTB {
u_int32_t seTag; /* 'CTNB' */
u_int32_t seRealTag;
u_int32_t seDataSize;
u_int32_t seDataOffset;
u_int32_t reserved;
};
struct syscfgMemEntry {
u_int32_t seTag;
u_int8_t seData[16];
u_int32_t seDataSize;
u_int32_t seDataOffset;
};
/*
* Attempt to initialise SysCfg from (bdevName)
*
* Returns true if successful.
*/
bool syscfgInitWithBdev(const char *bdevName);
/*
* Copy the data for an entry by tag
*
* Look up the provided tag, then copy the upto the size
* bytes into buffer.
*
* Returns -1 if the tag was not found, or the number of bytes copied.
*/
int syscfgCopyDataForTag(u_int32_t tag, u_int8_t *buffer, size_t size);
/*
* Look up an entry by tag.
*
* Returns false if the tag was not found. If the tag was found, returns true
* and copies the tag's entry into the provided pointer..
*/
bool syscfgFindByTag(u_int32_t tag, struct syscfgMemEntry *entry);
/*
* Look up an entry by index.
*
* Returns a pointer to a statically-allocated internal buffer, which
* will remain valid until the next call to syscfgFindByTag or syscfgFindByIndex.
*
* Returns NULL if the index was not found or not valid.
* Returns false if the index was not found or not valid. If the index was found,
* returns true and copies the tag's entry into the provided pointer..
*/
bool syscfgFindByIndex(u_int32_t index, struct syscfgMemEntry *result);
/*
* Gets a pointer to the data associated with an entry returned by
* syscfgFindByTag or syscfgFindByIndex
*
* Returns NULL if the entry was invalid
*/
void * syscfgGetData(struct syscfgMemEntry *entry);
/*
* Gets the size in bytes of the data associated with an entry returned by
* syscfgFindByTag or syscfgFindByIndex
*/
uint32_t syscfgGetSize(struct syscfgMemEntry *entry);
/* Returns true if the tag is found and populates the given pointers if they are non-NULL */
bool syscfg_find_tag(uint32_t tag, void **data_out, uint32_t *size_out);
__END_DECLS
#endif
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* This document is the property of Apple Computer, Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Computer, Inc.
*/
#ifndef __LIB_TFTP_H
#define __LIB_TFTP_H
#include <sys/types.h>
__BEGIN_DECLS
int tftp_transfer(const char *filename, uint32_t ipaddr, char *buffer, int *maxlen, bool write);
__END_DECLS
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2011, 2014 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#ifndef TICKET_H
#define TICKET_H
#include <sys/types.h>
#if 1
#define TICKETLOG(x, ...)
#else
#define TICKETLOG_ENABLED 1
#define TICKETLOG(x, ...) printf("%s: " x "\n", __FUNCTION__, ## __VA_ARGS__ )
#endif
bool ticket_validation_required();
bool ticket_get_hash( uint8_t *buffer, size_t length );
int ticket_load();
int ticket_load_file( const char *filePath, uintptr_t bufferAddress, size_t bufferLength );
bool ticket_validate_image3( uint32_t type, uint32_t expectedType, uint8_t *hashBuffer, size_t hashBufferSize, bool *outIsUntrusted );
int ticket_set( const uint8_t *buffer, size_t length, bool isRestore, size_t *outTicketLength );
#endif /* TICKET_H */