ssize_t rdev_relative_offset(const struct region_device *p, const struct region_device *c) { if (rdev_root(p) != rdev_root(c)) return -1; if (!region_is_subregion(&p->region, &c->region)) return -1; return region_device_offset(c) - region_device_offset(p); }
static void lb_boot_media_params(struct lb_header *header) { struct lb_boot_media_params *bmp; struct cbfs_props props; const struct region_device *boot_dev; struct region_device fmrd; boot_device_init(); if (cbfs_boot_region_properties(&props)) return; boot_dev = boot_device_ro(); if (boot_dev == NULL) return; bmp = (struct lb_boot_media_params *)lb_new_record(header); bmp->tag = LB_TAG_BOOT_MEDIA_PARAMS; bmp->size = sizeof(*bmp); bmp->cbfs_offset = props.offset; bmp->cbfs_size = props.size; bmp->boot_media_size = region_device_sz(boot_dev); bmp->fmap_offset = ~(uint64_t)0; if (find_fmap_directory(&fmrd) == 0) { bmp->fmap_offset = region_device_offset(&fmrd); } }
void vboot_fill_handoff(void) { int i; struct vboot_handoff *vh; struct vb2_shared_data *sd; struct region_device fw_main; struct vboot_components *fw_info; size_t metadata_sz; struct vb2_working_data *wd = vboot_get_working_data(); sd = vboot_get_work_buffer(wd); sd->workbuf_hash_offset = 0; sd->workbuf_hash_size = 0; printk(BIOS_INFO, "creating vboot_handoff structure\n"); vh = cbmem_add(CBMEM_ID_VBOOT_HANDOFF, sizeof(*vh)); if (vh == NULL) /* we don't need to failover gracefully here because this * shouldn't happen with the image that has passed QA. */ die("failed to allocate vboot_handoff structure\n"); memset(vh, 0, sizeof(*vh)); /* needed until we finish transtion to vboot2 for kernel verification */ fill_vboot_handoff(vh, sd); /* Nothing left to do in readonly path. */ if (vboot_is_readonly_path(wd)) return; if (vb2_get_selected_region(wd, &fw_main)) die("No component metadata.\n"); metadata_sz = sizeof(*fw_info); metadata_sz += MAX_PARSED_FW_COMPONENTS * sizeof(fw_info->entries[0]); fw_info = rdev_mmap(&fw_main, 0, metadata_sz); if (fw_info == NULL) die("failed to locate firmware components\n"); /* these offset & size are used to load a rw boot loader */ for (i = 0; i < fw_info->num_components; i++) { vh->components[i].address = region_device_offset(&fw_main); vh->components[i].address += fw_info->entries[i].offset; vh->components[i].size = fw_info->entries[i].size; } rdev_munmap(&fw_main, fw_info); }