2023-11-09 22:42:47 +02:00
|
|
|
#include "ELF.h"
|
|
|
|
#include "GPT.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
using namespace std::string_view_literals;
|
|
|
|
|
2023-11-13 18:53:38 +02:00
|
|
|
if (argc != 4)
|
2023-11-09 22:42:47 +02:00
|
|
|
{
|
2023-11-13 18:53:38 +02:00
|
|
|
std::fprintf(stderr, "usage: %s BOOTLOADER DISK_IMAGE ROOT_PARTITION_GUID\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto root_partition_guid = GUID::from_string(argv[3]);
|
|
|
|
if (!root_partition_guid.has_value())
|
|
|
|
{
|
|
|
|
std::cerr << "invalid guid '" << argv[3] << '\'' << std::endl;
|
2023-11-09 22:42:47 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ELFFile bootloader(argv[1]);
|
|
|
|
if (!bootloader.success())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
auto stage1 = bootloader.find_section(".stage1"sv);
|
|
|
|
auto stage2 = bootloader.find_section(".stage2"sv);
|
|
|
|
if (!stage1.has_value() || !stage2.has_value())
|
|
|
|
{
|
|
|
|
std::cerr << bootloader.path() << " doesn't contain .stage1 and .stage2 sections" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPTFile disk_image(argv[2]);
|
|
|
|
if (!disk_image.success())
|
|
|
|
return 1;
|
|
|
|
|
2023-11-13 18:53:38 +02:00
|
|
|
if (!disk_image.install_bootloader(*stage1, *stage2, *root_partition_guid))
|
2023-11-09 22:42:47 +02:00
|
|
|
return 1;
|
2023-11-13 18:53:38 +02:00
|
|
|
std::cout << "bootloader installed" << std::endl;
|
2023-11-09 22:42:47 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|