Newer
Older
if (fit_image_get_type(fit, noffset, &image_type))
return 0;
return (type == image_type);
}
/**
* fit_image_check_comp - check whether image node uses given compression
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @comp: requested image compression type
*
* fit_image_check_comp() reads image compression property and compares its
* numeric id with the requested compression type. Comparison result is
* returned to the caller.
*
* returns:
* 1 if image uses requested compression
* 0 otherwise (or on error)
*/
int fit_image_check_comp(const void *fit, int noffset, uint8_t comp)
{
uint8_t image_comp;
if (fit_image_get_comp(fit, noffset, &image_comp))
return 0;
return (comp == image_comp);
}
/**
* fit_check_format - sanity check FIT image format
* @fit: pointer to the FIT format image header
*
* fit_check_format() runs a basic sanity FIT image verification.
* Routine checks for mandatory properties, nodes, etc.
*
* returns:
* 1, on success
* 0, on failure
*/
{
/* mandatory / node 'description' property */
if (fdt_getprop(fit, 0, FIT_DESC_PROP, NULL) == NULL) {
debug("Wrong FIT format: no description\n");
return 0;
}
#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
/* mandatory / node 'timestamp' property */
if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
debug("Wrong FIT format: no timestamp\n");
return 0;
}
#endif
/* mandatory subimages parent '/images' node */
if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) {
debug("Wrong FIT format: no images parent node\n");
return 0;
}
return 1;
}
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
/**
* fit_conf_find_compat
* @fit: pointer to the FIT format image header
* @fdt: pointer to the device tree to compare against
*
* fit_conf_find_compat() attempts to find the configuration whose fdt is the
* most compatible with the passed in device tree.
*
* Example:
*
* / o image-tree
* |-o images
* | |-o fdt@1
* | |-o fdt@2
* |
* |-o configurations
* |-o config@1
* | |-fdt = fdt@1
* |
* |-o config@2
* |-fdt = fdt@2
*
* / o U-Boot fdt
* |-compatible = "foo,bar", "bim,bam"
*
* / o kernel fdt1
* |-compatible = "foo,bar",
*
* / o kernel fdt2
* |-compatible = "bim,bam", "baz,biz"
*
* Configuration 1 would be picked because the first string in U-Boot's
* compatible list, "foo,bar", matches a compatible string in the root of fdt1.
* "bim,bam" in fdt2 matches the second string which isn't as good as fdt1.
*
* returns:
* offset to the configuration to use if one was found
* -1 otherwise
*/
int fit_conf_find_compat(const void *fit, const void *fdt)
{
int ndepth = 0;
int noffset, confs_noffset, images_noffset;
const void *fdt_compat;
int fdt_compat_len;
int best_match_offset = 0;
int best_match_pos = 0;
confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
if (confs_noffset < 0 || images_noffset < 0) {
debug("Can't find configurations or images nodes.\n");
return -1;
}
fdt_compat = fdt_getprop(fdt, 0, "compatible", &fdt_compat_len);
if (!fdt_compat) {
debug("Fdt for comparison has no \"compatible\" property.\n");
return -1;
}
/*
* Loop over the configurations in the FIT image.
*/
for (noffset = fdt_next_node(fit, confs_noffset, &ndepth);
(noffset >= 0) && (ndepth > 0);
noffset = fdt_next_node(fit, noffset, &ndepth)) {
const void *kfdt;
const char *kfdt_name;
int kfdt_noffset;
const char *cur_fdt_compat;
int len;
size_t size;
int i;
if (ndepth > 1)
continue;
kfdt_name = fdt_getprop(fit, noffset, "fdt", &len);
if (!kfdt_name) {
debug("No fdt property found.\n");
continue;
}
kfdt_noffset = fdt_subnode_offset(fit, images_noffset,
kfdt_name);
if (kfdt_noffset < 0) {
debug("No image node named \"%s\" found.\n",
kfdt_name);
continue;
}
/*
* Get a pointer to this configuration's fdt.
*/
if (fit_image_get_data(fit, kfdt_noffset, &kfdt, &size)) {
debug("Failed to get fdt \"%s\".\n", kfdt_name);
continue;
}
len = fdt_compat_len;
cur_fdt_compat = fdt_compat;
/*
* Look for a match for each U-Boot compatibility string in
* turn in this configuration's fdt.
*/
for (i = 0; len > 0 &&
(!best_match_offset || best_match_pos > i); i++) {
int cur_len = strlen(cur_fdt_compat) + 1;
if (!fdt_node_check_compatible(kfdt, 0,
cur_fdt_compat)) {
best_match_offset = noffset;
best_match_pos = i;
break;
}
len -= cur_len;
cur_fdt_compat += cur_len;
}
}
if (!best_match_offset) {
debug("No match found.\n");
return -1;
}
return best_match_offset;
}
/**
* fit_conf_get_node - get node offset for configuration of a given unit name
* @fit: pointer to the FIT format image header
* @conf_uname: configuration node unit name
*
* fit_conf_get_node() finds a configuration (withing the '/configurations'
* parant node) of a provided unit name. If configuration is found its node offset
* is returned to the caller.
*
* When NULL is provided in second argument fit_conf_get_node() will search
* for a default configuration node instead. Default configuration node unit name
* is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
*
* returns:
* configuration node offset when found (>=0)
* negative number on failure (FDT_ERR_* code)
*/
int fit_conf_get_node(const void *fit, const char *conf_uname)
{
int noffset, confs_noffset;
int len;
confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
debug("Can't find configurations parent node '%s' (%s)\n",
FIT_CONFS_PATH, fdt_strerror(confs_noffset));
return confs_noffset;
}
if (conf_uname == NULL) {
/* get configuration unit name from the default property */
debug("No configuration specified, trying default...\n");
conf_uname = (char *)fdt_getprop(fit, confs_noffset,
FIT_DEFAULT_PROP, &len);
fit_get_debug(fit, confs_noffset, FIT_DEFAULT_PROP,
len);
debug("Found default configuration: '%s'\n", conf_uname);
noffset = fdt_subnode_offset(fit, confs_noffset, conf_uname);
debug("Can't get node offset for configuration unit name: "
"'%s' (%s)\n",
conf_uname, fdt_strerror(noffset));
}
return noffset;
}
static int __fit_conf_get_prop_node(const void *fit, int noffset,
const char *prop_name)
{
char *uname;
int len;
/* get kernel image unit name from configuration kernel property */
uname = (char *)fdt_getprop(fit, noffset, prop_name, &len);
if (uname == NULL)
return len;
}
/**
* fit_conf_get_kernel_node - get kernel image node offset that corresponds to
* a given configuration
* @fit: pointer to the FIT format image header
* @noffset: configuration node offset
*
* fit_conf_get_kernel_node() retrives kernel image node unit name from
* configuration FIT_KERNEL_PROP property and translates it to the node
* offset.
*
* returns:
* image node offset when found (>=0)
* negative number on failure (FDT_ERR_* code)
*/
int fit_conf_get_kernel_node(const void *fit, int noffset)
return __fit_conf_get_prop_node(fit, noffset, FIT_KERNEL_PROP);
}
/**
* fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
* a given configuration
* @fit: pointer to the FIT format image header
* @noffset: configuration node offset
*
* fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
* configuration FIT_KERNEL_PROP property and translates it to the node
* offset.
*
* returns:
* image node offset when found (>=0)
* negative number on failure (FDT_ERR_* code)
*/
int fit_conf_get_ramdisk_node(const void *fit, int noffset)
return __fit_conf_get_prop_node(fit, noffset, FIT_RAMDISK_PROP);
}
/**
* fit_conf_get_fdt_node - get fdt image node offset that corresponds to
* a given configuration
* @fit: pointer to the FIT format image header
* @noffset: configuration node offset
*
* fit_conf_get_fdt_node() retrives fdt image node unit name from
* configuration FIT_KERNEL_PROP property and translates it to the node
* offset.
*
* returns:
* image node offset when found (>=0)
* negative number on failure (FDT_ERR_* code)
*/
int fit_conf_get_fdt_node(const void *fit, int noffset)
return __fit_conf_get_prop_node(fit, noffset, FIT_FDT_PROP);
/**
* fit_conf_print - prints out the FIT configuration details
* @fit: pointer to the FIT format image header
Marian Balakowicz
committed
* @noffset: offset of the configuration node
* @p: pointer to prefix string
*
* fit_conf_print() lists all mandatory properies for the processed
* configuration node.
*
* returns:
* no returned results
*/
void fit_conf_print(const void *fit, int noffset, const char *p)
{
char *desc;
char *uname;
int ret;
/* Mandatory properties */
ret = fit_get_desc(fit, noffset, &desc);
printf("%s Description: ", p);
uname = (char *)fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL);
printf("%s Kernel: ", p);
/* Optional properties */
uname = (char *)fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL);
printf("%s Init Ramdisk: %s\n", p, uname);
uname = (char *)fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL);
/**
* fit_check_ramdisk - verify FIT format ramdisk subimage
* @fit_hdr: pointer to the FIT ramdisk header
* @rd_noffset: ramdisk subimage node offset within FIT image
* @arch: requested ramdisk image architecture type
* @verify: data CRC verification flag
*
* fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
* specified FIT image.
*
* returns:
* 1, on success
* 0, on failure
*/
#ifndef USE_HOSTCC
static int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
int verify)
if (verify) {
puts(" Verifying Hash Integrity ... ");
if (!fit_image_check_hashes(fit, rd_noffset)) {
puts("Bad Data Hash\n");
bootstage_error(BOOTSTAGE_ID_FIT_RD_HASH);
return 0;
}
}
bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
if (!fit_image_check_os(fit, rd_noffset, IH_OS_LINUX) ||
!fit_image_check_arch(fit, rd_noffset, arch) ||
!fit_image_check_type(fit, rd_noffset, IH_TYPE_RAMDISK)) {
printf("No Linux %s Ramdisk Image\n",
genimg_get_arch_name(arch));
bootstage_error(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
return 0;
}
bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK);
return 1;
}
#endif /* USE_HOSTCC */
#endif /* CONFIG_FIT */