2026-01-06 09:48:38 +08:00
|
|
|
#include "common/printing.h"
|
|
|
|
|
#include "common/jsonconfig.h"
|
2026-05-28 15:58:08 +08:00
|
|
|
#include "common/strutil.h"
|
2024-05-15 21:36:15 +08:00
|
|
|
#include "detection/bootmgr/bootmgr.h"
|
|
|
|
|
#include "modules/bootmgr/bootmgr.h"
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
bool ffPrintBootmgr(FFBootmgrOptions* options) {
|
2025-08-18 13:38:30 +08:00
|
|
|
bool success = false;
|
2024-05-15 21:36:15 +08:00
|
|
|
FFBootmgrResult bootmgr = {
|
|
|
|
|
.name = ffStrbufCreate(),
|
|
|
|
|
.firmware = ffStrbufCreate(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char* error = ffDetectBootmgr(&bootmgr);
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (error) {
|
2026-08-14 23:33:54 +08:00
|
|
|
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(Bootmgr), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
2025-08-18 13:38:30 +08:00
|
|
|
goto exit;
|
2026-03-29 09:28:49 +08:00
|
|
|
} else {
|
2025-08-18 13:38:30 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY firmwareName = ffStrbufCreateCopy(&bootmgr.firmware);
|
2026-03-29 09:28:49 +08:00
|
|
|
#ifndef __APPLE__
|
2025-08-18 13:38:30 +08:00
|
|
|
ffStrbufSubstrAfterLastC(&firmwareName, '\\');
|
2026-03-29 09:28:49 +08:00
|
|
|
#else
|
2025-08-18 13:38:30 +08:00
|
|
|
ffStrbufSubstrAfterLastC(&firmwareName, '/');
|
2026-03-29 09:28:49 +08:00
|
|
|
#endif
|
2025-08-18 13:38:30 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (options->moduleArgs.outputFormat.length == 0) {
|
2026-08-14 23:33:54 +08:00
|
|
|
ffPrintLogoAndKey(FF_MODULE_GET_DISPLAY_NAME(Bootmgr), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
2025-08-18 13:38:30 +08:00
|
|
|
ffStrbufWriteTo(&bootmgr.name, stdout);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (firmwareName.length > 0) {
|
2025-08-18 13:38:30 +08:00
|
|
|
printf(" - %s\n", firmwareName.chars);
|
2026-03-29 09:28:49 +08:00
|
|
|
} else {
|
2025-08-18 13:38:30 +08:00
|
|
|
putchar('\n');
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
|
|
|
|
} else {
|
2026-08-14 23:33:54 +08:00
|
|
|
FF_PRINT_FORMAT_CHECKED(FF_MODULE_GET_DISPLAY_NAME(Bootmgr), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
|
2026-03-29 09:28:49 +08:00
|
|
|
FF_ARG(bootmgr.name, "name"),
|
|
|
|
|
FF_ARG(bootmgr.firmware, "firmware-path"),
|
|
|
|
|
FF_ARG(firmwareName, "firmware-name"),
|
|
|
|
|
FF_ARG(bootmgr.secureBoot, "secure-boot"),
|
|
|
|
|
FF_ARG(bootmgr.order, "order"),
|
|
|
|
|
}));
|
2025-08-18 13:38:30 +08:00
|
|
|
}
|
2024-05-15 21:36:15 +08:00
|
|
|
}
|
2025-08-18 13:38:30 +08:00
|
|
|
success = true;
|
2024-05-15 21:36:15 +08:00
|
|
|
|
2025-08-18 13:38:30 +08:00
|
|
|
exit:
|
2024-05-15 21:36:15 +08:00
|
|
|
ffStrbufDestroy(&bootmgr.name);
|
|
|
|
|
ffStrbufDestroy(&bootmgr.firmware);
|
2025-08-18 13:38:30 +08:00
|
|
|
|
|
|
|
|
return success;
|
2024-05-15 21:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffParseBootmgrJsonObject(FFBootmgrOptions* options, yyjson_val* module) {
|
2025-08-02 18:51:03 +08:00
|
|
|
yyjson_val *key, *val;
|
2024-05-15 21:36:15 +08:00
|
|
|
size_t idx, max;
|
2026-03-29 09:28:49 +08:00
|
|
|
yyjson_obj_foreach (module, idx, max, key, val) {
|
|
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
|
2024-05-15 21:36:15 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2024-05-15 21:36:15 +08:00
|
|
|
|
2026-08-14 23:33:54 +08:00
|
|
|
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(Bootmgr), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
|
2024-05-15 21:36:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-03 01:32:02 +08:00
|
|
|
[[gnu::cold]]
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffGenerateBootmgrJsonConfig(FFBootmgrOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2025-08-04 16:46:28 +08:00
|
|
|
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
2024-05-15 21:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-10 21:13:03 +08:00
|
|
|
bool ffGenerateBootmgrJsonResult([[maybe_unused]] FFBootmgrOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2025-08-18 13:38:30 +08:00
|
|
|
bool success = false;
|
2024-05-15 21:36:15 +08:00
|
|
|
FFBootmgrResult bootmgr = {
|
|
|
|
|
.name = ffStrbufCreate(),
|
|
|
|
|
.firmware = ffStrbufCreate(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char* error = ffDetectBootmgr(&bootmgr);
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (error) {
|
2024-05-15 21:36:15 +08:00
|
|
|
yyjson_mut_obj_add_str(doc, module, "error", error);
|
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
|
|
|
|
|
yyjson_mut_obj_add_strbuf(doc, obj, "name", &bootmgr.name);
|
|
|
|
|
yyjson_mut_obj_add_strbuf(doc, obj, "firmware", &bootmgr.firmware);
|
2025-03-23 21:30:53 +08:00
|
|
|
yyjson_mut_obj_add_uint(doc, obj, "order", bootmgr.order);
|
2024-05-15 21:36:15 +08:00
|
|
|
yyjson_mut_obj_add_bool(doc, obj, "secureBoot", bootmgr.secureBoot);
|
2025-08-18 13:38:30 +08:00
|
|
|
success = true;
|
2024-05-15 21:36:15 +08:00
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
ffStrbufDestroy(&bootmgr.name);
|
|
|
|
|
ffStrbufDestroy(&bootmgr.firmware);
|
2025-08-18 13:38:30 +08:00
|
|
|
return success;
|
2024-05-15 21:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffInitBootmgrOptions(FFBootmgrOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionInitModuleArg(&options->moduleArgs, "");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffDestroyBootmgrOptions(FFBootmgrOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 22:50:56 +08:00
|
|
|
FFModuleBaseInfo ffBootmgrModuleInfo = {
|
2026-08-14 23:33:54 +08:00
|
|
|
.name = "Bootmgr",
|
2026-04-16 18:27:11 +08:00
|
|
|
.description = "Print second-stage bootloader information (name, firmware, etc.)",
|
2026-08-14 20:38:58 +08:00
|
|
|
.displayName = {
|
|
|
|
|
.en = "Boot Manager",
|
2026-08-16 10:51:42 +08:00
|
|
|
.ar = "مدير الإقلاع",
|
2026-08-21 10:19:06 +08:00
|
|
|
.cs = "Správce spouštění",
|
2026-08-14 20:38:58 +08:00
|
|
|
.de = "Boot-Manager",
|
2026-08-21 00:31:42 +00:00
|
|
|
.es = "Gestor de arranque",
|
2026-10-03 13:35:56 +03:00
|
|
|
.fi = "Käynnistyslataaja",
|
2026-08-14 20:38:58 +08:00
|
|
|
.fr = "Gestionnaire de démarrage",
|
2026-08-20 16:25:32 +00:00
|
|
|
.gl = "Xestor de arranque",
|
2026-08-16 10:51:42 +08:00
|
|
|
.he = "מנהל אתחול",
|
2026-08-21 10:19:06 +08:00
|
|
|
.id = "Manajer Boot",
|
2026-08-14 20:38:58 +08:00
|
|
|
.it = "Gestore di avvio",
|
|
|
|
|
.ja = "ブートマネージャー",
|
|
|
|
|
.ko = "부트 매니저",
|
|
|
|
|
.pl = "Menedżer rozruchu",
|
2026-08-16 10:37:06 +08:00
|
|
|
.pt = "Gerenciador de inicialização",
|
2026-08-14 20:38:58 +08:00
|
|
|
.ru = "Менеджер загрузки",
|
2026-08-21 10:19:06 +08:00
|
|
|
.tr = "Önyükleme Yöneticisi",
|
|
|
|
|
.uk = "Менеджер завантаження",
|
|
|
|
|
.vi = "Trình quản lý khởi động",
|
2026-08-14 20:38:58 +08:00
|
|
|
.zh_CN = "启动管理器",
|
|
|
|
|
.zh_TW = "啟動管理器",
|
|
|
|
|
},
|
2025-08-03 18:39:41 +08:00
|
|
|
.initOptions = (void*) ffInitBootmgrOptions,
|
|
|
|
|
.destroyOptions = (void*) ffDestroyBootmgrOptions,
|
2024-12-11 10:47:02 +08:00
|
|
|
.parseJsonObject = (void*) ffParseBootmgrJsonObject,
|
|
|
|
|
.printModule = (void*) ffPrintBootmgr,
|
|
|
|
|
.generateJsonResult = (void*) ffGenerateBootmgrJsonResult,
|
|
|
|
|
.generateJsonConfig = (void*) ffGenerateBootmgrJsonConfig,
|
|
|
|
|
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
|
2026-03-30 10:27:23 +08:00
|
|
|
{ "Name / description", "name" },
|
|
|
|
|
{ "Firmware file path", "firmware-path" },
|
|
|
|
|
{ "Firmware file name", "firmware-name" },
|
|
|
|
|
{ "Is secure boot enabled", "secure-boot" },
|
|
|
|
|
{ "Boot order", "order" },
|
2026-07-31 10:56:13 +08:00
|
|
|
})),
|
|
|
|
|
.defaultOrder = 6,
|
2026-03-30 10:17:45 +08:00
|
|
|
};
|