iPXE
imgmgmt.c File Reference

Image management. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/image.h>
#include <ipxe/downloader.h>
#include <ipxe/monojob.h>
#include <ipxe/open.h>
#include <ipxe/uri.h>
#include <usr/imgmgmt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int imgdownload (struct uri *uri, unsigned long timeout, int quiet, struct image **image)
 Download a new image.
int imgdownload_string (const char *uri_string, unsigned long timeout, int quiet, struct image **image)
 Download a new image.
int imgacquire (const char *name_uri, unsigned long timeout, int quiet, struct image **image)
 Acquire an image.
void imgstat (struct image *image)
 Display status of an image.
int imgmem (const char *name, const void *data, size_t len)
 Create image from block of memory.

Detailed Description

Image management.

Definition in file imgmgmt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ imgdownload()

int imgdownload ( struct uri * uri,
unsigned long timeout,
int quiet,
struct image ** image )

Download a new image.

Parameters
uriURI
timeoutDownload timeout
quietDisplay only error messages
imageImage to fill in
Return values
rcReturn status code

Definition at line 54 of file imgmgmt.c.

55 {
56 char *uri_string_redacted = NULL;
57 struct uri uri_redacted;
58 int rc;
59
60 /* Construct redacted URI, if applicable */
61 if ( ! quiet ) {
62 memcpy ( &uri_redacted, uri, sizeof ( uri_redacted ) );
63 uri_redacted.user = NULL;
64 uri_redacted.password = NULL;
65 uri_redacted.equery = NULL;
66 uri_redacted.efragment = NULL;
67 uri_string_redacted = format_uri_alloc ( &uri_redacted );
68 if ( ! uri_string_redacted ) {
69 rc = -ENOMEM;
70 goto err_uri_string;
71 }
72 }
73
74 /* Resolve URI */
75 uri = resolve_uri ( cwuri, uri );
76 if ( ! uri ) {
77 rc = -ENOMEM;
78 goto err_resolve_uri;
79 }
80
81 /* Allocate image */
82 *image = alloc_image ( uri );
83 if ( ! *image ) {
84 rc = -ENOMEM;
85 goto err_alloc_image;
86 }
87
88 /* Create downloader */
89 if ( ( rc = create_downloader ( &monojob, *image ) ) != 0 ) {
90 printf ( "Could not start download: %s\n", strerror ( rc ) );
91 goto err_create_downloader;
92 }
93
94 /* Wait for download to complete */
95 if ( ( rc = monojob_wait ( uri_string_redacted, timeout ) ) != 0 )
96 goto err_monojob_wait;
97
98 /* Register image */
99 if ( ( rc = register_image ( *image ) ) != 0 ) {
100 printf ( "Could not register image: %s\n", strerror ( rc ) );
101 goto err_register_image;
102 }
103
104 err_register_image:
105 err_monojob_wait:
106 err_create_downloader:
107 image_put ( *image );
108 err_alloc_image:
109 uri_put ( uri );
110 err_resolve_uri:
111 free ( uri_string_redacted );
112 err_uri_string:
113 return rc;
114}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
void timeout(int)
struct uri * cwuri
Current working URI.
Definition cwuri.c:39
int create_downloader(struct interface *job, struct image *image)
Instantiate a downloader.
Definition downloader.c:256
#define ENOMEM
Not enough space.
Definition errno.h:535
struct image * alloc_image(struct uri *uri)
Allocate executable image.
Definition image.c:127
int register_image(struct image *image)
Register executable image.
Definition image.c:336
static void image_put(struct image *image)
Decrement reference count on an image.
Definition image.h:258
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct interface monojob
Definition monojob.c:57
int monojob_wait(const char *string, unsigned long timeout)
Wait for single foreground job to complete.
Definition monojob.c:82
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
An executable image.
Definition image.h:24
A Uniform Resource Identifier.
Definition uri.h:65
struct uri * resolve_uri(const struct uri *base_uri, struct uri *relative_uri)
Resolve base+relative URI.
Definition uri.c:696
char * format_uri_alloc(const struct uri *uri)
Format URI.
Definition uri.c:542
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition uri.h:206
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References alloc_image(), create_downloader(), cwuri, uri::efragment, ENOMEM, uri::equery, format_uri_alloc(), free, image_put(), memcpy(), monojob, monojob_wait(), NULL, uri::password, printf(), rc, register_image(), resolve_uri(), strerror(), timeout(), uri_put(), and uri::user.

Referenced by imgdownload_string(), and uriboot().

◆ imgdownload_string()

int imgdownload_string ( const char * uri_string,
unsigned long timeout,
int quiet,
struct image ** image )

Download a new image.

Parameters
uri_stringURI string
timeoutDownload timeout
quietDisplay only error messages
imageImage to fill in
Return values
rcReturn status code

Definition at line 125 of file imgmgmt.c.

126 {
127 struct uri *uri;
128 int rc;
129
130 if ( ! ( uri = parse_uri ( uri_string ) ) )
131 return -ENOMEM;
132
133 rc = imgdownload ( uri, timeout, quiet, image );
134
135 uri_put ( uri );
136 return rc;
137}
int imgdownload(struct uri *uri, unsigned long timeout, int quiet, struct image **image)
Download a new image.
Definition imgmgmt.c:54
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition uri.c:297

References ENOMEM, imgdownload(), parse_uri(), rc, timeout(), and uri_put().

Referenced by comboot_fetch_kernel(), and imgacquire().

◆ imgacquire()

int imgacquire ( const char * name_uri,
unsigned long timeout,
int quiet,
struct image ** image )

Acquire an image.

Parameters
name_uriName or URI string
timeoutDownload timeout
quietDisplay only error messages
imageImage to fill in
Return values
rcReturn status code

Definition at line 148 of file imgmgmt.c.

149 {
150
151 /* If we already have an image with the specified name, use it */
152 *image = find_image ( name_uri );
153 if ( *image )
154 return 0;
155
156 /* Otherwise, download a new image */
157 return imgdownload_string ( name_uri, timeout, quiet, image );
158}
struct image * find_image(const char *name)
Find image by name.
Definition image.c:408
int imgdownload_string(const char *uri_string, unsigned long timeout, int quiet, struct image **image)
Download a new image.
Definition imgmgmt.c:125

References find_image(), imgdownload_string(), and timeout().

Referenced by cert_exec(), console_exec(), digest_exec(), efi_autoexec_filesystem(), efi_autoexec_network(), fdt_exec(), imgdecrypt_exec(), imgextract_exec(), imgset_exec(), imgverify_exec(), and shim_exec().

◆ imgstat()

void imgstat ( struct image * image)

Display status of an image.

Parameters
imageExecutable/loadable image

Definition at line 165 of file imgmgmt.c.

165 {
166 struct image_tag *tag;
167
168 printf ( "%s : %zd bytes", image->name, image->len );
169 if ( image->type )
170 printf ( " [%s]", image->type->name );
172 if ( tag->image == image )
173 printf ( " [%s]", tag->name );
174 }
175 if ( image->flags & IMAGE_TRUSTED )
176 printf ( " [TRUSTED]" );
178 printf ( " [AUTOFREE]" );
179 if ( image->flags & IMAGE_HIDDEN )
180 printf ( " [HIDDEN]" );
181 if ( image->cmdline )
182 printf ( " \"%s\"", image->cmdline );
183 printf ( "\n" );
184}
uint64_t tag
Identity tag.
Definition edd.h:1
#define IMAGE_TRUSTED
Image is trusted.
Definition image.h:87
#define IMAGE_TAGS
Image tag table.
Definition image.h:188
#define IMAGE_HIDDEN
Image will be hidden from enumeration.
Definition image.h:93
#define IMAGE_AUTO_UNREGISTER
Image will be automatically unregistered after execution.
Definition image.h:90
An image tag.
Definition image.h:180
char * name
Name of this image type.
Definition image.h:104
unsigned int flags
Flags.
Definition image.h:40
struct image_type * type
Image type, if known.
Definition image.h:66
char * name
Name.
Definition image.h:38
size_t len
Length of raw file image.
Definition image.h:63
char * cmdline
Command line to pass to image.
Definition image.h:43
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References image::cmdline, image::flags, for_each_table_entry, IMAGE_AUTO_UNREGISTER, IMAGE_HIDDEN, IMAGE_TAGS, IMAGE_TRUSTED, image::len, image::name, image_type::name, printf(), tag, and image::type.

Referenced by COMMAND(), imgstat_exec(), and uriboot().

◆ imgmem()

int imgmem ( const char * name,
const void * data,
size_t len )

Create image from block of memory.

Parameters
nameName
dataImage data
lenLength
Return values
rcReturn status code

Definition at line 194 of file imgmgmt.c.

194 {
195 struct image *image;
196
197 /* Create image */
199 if ( ! image ) {
200 printf ( "Could not create image\n" );
201 return -ENOMEM;
202 }
203
204 return 0;
205}
const char * name
Definition ath9k_hw.c:1986
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
struct image * image_memory(const char *name, const void *data, size_t len)
Create registered image from block of memory.
Definition image.c:641

References data, ENOMEM, image_memory(), len, name, and printf().

Referenced by COMMAND(), and imgmem_exec().