forked from StevenBaby/onix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dff0a3c
commit 8d50c90
Showing
8 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <onix/types.h> | ||
#include <onix/net/chksum.h> | ||
#include <onix/string.h> | ||
#include <onix/debug.h> | ||
|
||
static u32 __attribute__((section(".onix.addr"))) kernel_addr = 0x20000; | ||
static u32 __attribute__((section(".onix.size"))) kernel_size = 0; | ||
static u32 __attribute__((section(".onix.chksum"))) kernel_chksum = 0; | ||
static u32 __attribute__((section(".onix.magic"))) kernel_magic = ONIX_MAGIC; | ||
|
||
static u8 magic_msg[] = "kernel magic check failure!!!"; | ||
static u8 crc32_msg[] = "kernel crc32 check failure!!!"; | ||
static char *video = (char *)0xb8000; | ||
|
||
extern void hang(); | ||
|
||
static void show_message(char *msg, int len) | ||
{ | ||
for (int i = 0; i < len; i++) | ||
video[i * 2] = msg[i]; | ||
} | ||
|
||
err_t onix_init() | ||
{ | ||
if (kernel_magic != ONIX_MAGIC) | ||
{ | ||
show_message(magic_msg, sizeof(magic_msg)); | ||
goto failure; | ||
} | ||
|
||
u32 size = kernel_size; | ||
u32 chksum = kernel_chksum; | ||
|
||
kernel_chksum = 0; | ||
kernel_size = 0; | ||
|
||
u32 result = eth_fcs((void *)kernel_addr, size); | ||
if (result != chksum) | ||
{ | ||
show_message(crc32_msg, sizeof(crc32_msg)); | ||
goto failure; | ||
} | ||
return EOK; | ||
failure: | ||
hang(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# coding=utf-8 | ||
|
||
import os | ||
import binascii | ||
from elftools.elf.elffile import ELFFile | ||
|
||
DIRNAME = os.path.dirname(os.path.abspath(__file__)) | ||
BUILD = os.path.abspath(os.path.join(DIRNAME, "../../build")) | ||
KERNELBIN = os.path.join(BUILD, 'kernel.bin') | ||
SYSTEMBIN = os.path.join(BUILD, 'system.bin') | ||
|
||
|
||
def main(): | ||
start = 0x8000 | ||
size = os.path.getsize(SYSTEMBIN) - start | ||
|
||
with open(SYSTEMBIN, 'rb') as file: | ||
data = file.read() | ||
chksum = binascii.crc32(data[start:]) | ||
print(f"system.bin chksum: {chksum} size {size}") | ||
|
||
with open(KERNELBIN, 'rb+') as file: | ||
elf = ELFFile(file) | ||
section = elf.get_section_by_name(".onix.magic") | ||
offset = section["sh_offset"] | ||
file.seek(offset) | ||
magic = int.from_bytes(file.read(4), "little") | ||
if magic != 0x20220205: | ||
print("magic check error") | ||
return | ||
|
||
section = elf.get_section_by_name(".onix.size") | ||
offset = section["sh_offset"] | ||
file.seek(offset) | ||
file.write(size.to_bytes(4, "little")) | ||
print(f"write size {size} offset {offset:x} success") | ||
|
||
section = elf.get_section_by_name(".onix.chksum") | ||
offset = section["sh_offset"] | ||
file.seek(offset) | ||
file.write(chksum.to_bytes(4, "little")) | ||
print(f"write size {chksum:#x} offset {offset:x} success:") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters