summaryrefslogtreecommitdiffhomepage
path: root/dev/boot/modules/BootNet/BootNet.cc
blob: 4b7e5c30377a1c310816dc13982a8e237ac99cd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 *	========================================================
 *
 *	BootNet
 * 	Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved.
 *
 * 	========================================================
 */

#include <modules/BootNet/BootNet.h>
#include <BootKit/BootKit.h>
#include <BootKit/BootThread.h>

EXTERN_C Int32 ModuleMain(Kernel::HEL::BootInfoHeader* handover)
{
	NETBOOT_INTERNET_HEADER inet{};

	memset(&inet, 0, sizeof(NETBOOT_INTERNET_HEADER));

	/// TODO: Read packet from JSON file 'bootnet.json'

	if (inet.PatchLength < 1)
	{
		Boot::BootTextWriter writer;
		writer.Write("NetBootLauncher: No executable attached to the packet, aborting.\r");

		return kEfiFail;
	}

	if (!inet.EEPROM)
	{
		Boot::BootThread thread(inet.PatchData);

		if (thread.IsValid())
			return thread.Start(handover, YES);

		return kEfiFail;
	}
	else
	{
		Boot::BootTextWriter writer;
		writer.Write("NetBootLauncher: EEPROM flash is not available as of right now.\r");

		/// TODO: Program new firmware to EEPROM (if crc and size matches)

		return kEfiFail; // TODO: Add support for EEPROM firmware update.
	}

	return kEfiFail;
}