fastboot: Refactor bootimg_utils.cpp:mkbootimg()

Change mkbootimg() to return void, as we already have a |out| parameter.

Bug: 183455415
Test: Presubmit
Change-Id: I51439e273752ab9e21f8d7138e900ea55bdfdfc0
This commit is contained in:
Yi-Yo Chiang 2021-03-25 01:14:52 +08:00 committed by Yo Chiang
parent c0c9e3059c
commit ac4a136e59
3 changed files with 17 additions and 17 deletions

View file

@ -47,9 +47,9 @@ void bootimg_set_cmdline(boot_img_hdr_v2* h, const std::string& cmdline) {
strcpy(reinterpret_cast<char*>(h->cmdline), cmdline.c_str());
}
static boot_img_hdr_v3* mkbootimg_v3_and_above(const std::vector<char>& kernel,
const std::vector<char>& ramdisk,
const boot_img_hdr_v2& src, std::vector<char>* out) {
static void mkbootimg_v3_and_above(const std::vector<char>& kernel,
const std::vector<char>& ramdisk, const boot_img_hdr_v2& src,
std::vector<char>* out) {
#define V3_PAGE_SIZE 4096
const size_t page_mask = V3_PAGE_SIZE - 1;
int64_t kernel_actual = (kernel.size() + page_mask) & (~page_mask);
@ -74,20 +74,18 @@ static boot_img_hdr_v3* mkbootimg_v3_and_above(const std::vector<char>& kernel,
memcpy(hdr->magic + V3_PAGE_SIZE, kernel.data(), kernel.size());
memcpy(hdr->magic + V3_PAGE_SIZE + kernel_actual, ramdisk.data(), ramdisk.size());
return hdr;
}
boot_img_hdr_v2* mkbootimg(const std::vector<char>& kernel, const std::vector<char>& ramdisk,
const std::vector<char>& second, const std::vector<char>& dtb,
size_t base, const boot_img_hdr_v2& src, std::vector<char>* out) {
void mkbootimg(const std::vector<char>& kernel, const std::vector<char>& ramdisk,
const std::vector<char>& second, const std::vector<char>& dtb, size_t base,
const boot_img_hdr_v2& src, std::vector<char>* out) {
if (src.header_version >= 3) {
if (!second.empty() || !dtb.empty()) {
die("Second stage bootloader and dtb not supported in v%d boot image\n",
src.header_version);
}
return reinterpret_cast<boot_img_hdr_v2*>(
mkbootimg_v3_and_above(kernel, ramdisk, src, out));
mkbootimg_v3_and_above(kernel, ramdisk, src, out);
return;
}
const size_t page_mask = src.page_size - 1;
@ -129,5 +127,4 @@ boot_img_hdr_v2* mkbootimg(const std::vector<char>& kernel, const std::vector<ch
second.size());
memcpy(hdr->magic + hdr->page_size + kernel_actual + ramdisk_actual + second_actual, dtb.data(),
dtb.size());
return hdr;
}

View file

@ -35,7 +35,8 @@
#include <string>
#include <vector>
boot_img_hdr_v2* mkbootimg(const std::vector<char>& kernel, const std::vector<char>& ramdisk,
const std::vector<char>& second, const std::vector<char>& dtb,
size_t base, const boot_img_hdr_v2& src, std::vector<char>* out);
void mkbootimg(const std::vector<char>& kernel, const std::vector<char>& ramdisk,
const std::vector<char>& second, const std::vector<char>& dtb, size_t base,
const boot_img_hdr_v2& src, std::vector<char>* out);
void bootimg_set_cmdline(boot_img_hdr_v2* h, const std::string& cmdline);

View file

@ -523,10 +523,12 @@ static std::vector<char> LoadBootableImage(const std::string& kernel, const std:
fprintf(stderr,"creating boot image...\n");
std::vector<char> out;
boot_img_hdr_v2* boot_image_data = mkbootimg(kernel_data, ramdisk_data, second_stage_data,
dtb_data, g_base_addr, g_boot_img_hdr, &out);
mkbootimg(kernel_data, ramdisk_data, second_stage_data, dtb_data, g_base_addr, g_boot_img_hdr,
&out);
if (!g_cmdline.empty()) bootimg_set_cmdline(boot_image_data, g_cmdline);
if (!g_cmdline.empty()) {
bootimg_set_cmdline(reinterpret_cast<boot_img_hdr_v2*>(out.data()), g_cmdline);
}
fprintf(stderr, "creating boot image - %zu bytes\n", out.size());
return out;
}