Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
bootloader
Commits
59a373b4
Verified
Commit
59a373b4
authored
Mar 26, 2022
by
4lDO2
🖖
Browse files
Pass an external initfs image to the kernel.
parent
2f86d3a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
59a373b4
...
...
@@ -88,6 +88,9 @@ pub struct KernelArgs {
areas_base
:
u64
,
areas_size
:
u64
,
initfs_base
:
u64
,
initfs_size
:
u64
,
}
fn
select_mode
<
...
...
@@ -278,6 +281,48 @@ fn redoxfs<
panic!
(
"RedoxFS out of unlock attempts"
);
}
#[derive(PartialEq)]
enum
Filetype
{
Elf
,
Other
,
}
fn
load_to_memory
<
D
:
Disk
>
(
os
:
&
mut
dyn
Os
<
D
,
impl
Iterator
<
Item
=
OsVideoMode
>>
,
fs
:
&
mut
redoxfs
::
FileSystem
<
D
>
,
filename
:
&
str
,
filetype
:
Filetype
)
->
&
'static
mut
[
u8
]
{
fs
.tx
(|
tx
|
{
let
node
=
tx
.find_node
(
redoxfs
::
TreePtr
::
root
(),
filename
)
.expect
(
"Failed to find kernel file"
);
let
size
=
node
.data
()
.size
();
print!
(
"Kernel: 0/{} MiB"
,
size
/
MIBI
as
u64
);
let
ptr
=
os
.alloc_zeroed_page_aligned
(
size
as
usize
);
if
ptr
.is_null
()
{
panic!
(
"Failed to allocate memory for {}"
,
filename
);
}
let
slice
=
unsafe
{
slice
::
from_raw_parts_mut
(
ptr
,
size
as
usize
)
};
let
mut
i
=
0
;
for
chunk
in
slice
.chunks_mut
(
MIBI
)
{
print!
(
"
\r
{}: {}/{} MiB"
,
filename
,
i
/
MIBI
as
u64
,
size
/
MIBI
as
u64
);
i
+=
tx
.read_node_inner
(
&
node
,
i
,
chunk
)
.unwrap_or_else
(|
err
|
panic!
(
"Failed to read `{}` file: {}"
,
filename
,
err
))
as
u64
;
}
println!
(
"
\r
{}: {}/{} MiB"
,
filename
,
i
/
MIBI
as
u64
,
size
/
MIBI
as
u64
);
if
filetype
==
Filetype
::
Elf
{
let
magic
=
&
slice
[
..
4
];
if
magic
!=
b"
\x7F
ELF"
{
panic!
(
"{} has invalid magic number {:#X?}"
,
filename
,
magic
);
}
}
Ok
(
slice
)
})
.unwrap_or_else
(|
err
|
panic!
(
"RedoxFS transaction failed while loading `{}`: {}"
,
filename
,
err
))
}
fn
main
<
D
:
Disk
,
V
:
Iterator
<
Item
=
OsVideoMode
>
...
...
@@ -304,38 +349,11 @@ fn main<
panic!
(
"Failed to allocate memory for stack"
);
}
let
kernel
=
fs
.tx
(|
tx
|
{
let
node
=
tx
.find_node
(
redoxfs
::
TreePtr
::
root
(),
"kernel"
)
.expect
(
"Failed to find kernel file"
);
let
size
=
node
.data
()
.size
();
print!
(
"Kernel: 0/{} MiB"
,
size
/
MIBI
as
u64
);
let
ptr
=
os
.alloc_zeroed_page_aligned
(
size
as
usize
);
if
ptr
.is_null
()
{
panic!
(
"Failed to allocate memory for kernel"
);
}
let
kernel
=
unsafe
{
slice
::
from_raw_parts_mut
(
ptr
,
size
as
usize
)
};
let
mut
i
=
0
;
for
chunk
in
kernel
.chunks_mut
(
MIBI
)
{
print!
(
"
\r
Kernel: {}/{} MiB"
,
i
/
MIBI
as
u64
,
size
/
MIBI
as
u64
);
i
+=
tx
.read_node_inner
(
&
node
,
i
,
chunk
)
.expect
(
"Failed to read kernel file"
)
as
u64
;
}
println!
(
"
\r
Kernel: {}/{} MiB"
,
i
/
MIBI
as
u64
,
size
/
MIBI
as
u64
);
let
magic
=
&
kernel
[
..
4
];
if
magic
!=
b"
\x7F
ELF"
{
panic!
(
"Kernel has invalid magic number {:#X?}"
,
magic
);
}
Ok
(
kernel
)
})
.expect
(
"RedoxFS transaction failed"
);
let
kernel
=
load_to_memory
(
os
,
&
mut
fs
,
"kernel"
,
Filetype
::
Elf
);
let
(
initfs_size
,
initfs_base
)
=
{
let
slice
=
load_to_memory
(
os
,
&
mut
fs
,
"initfs"
,
Filetype
::
Other
);
(
slice
.len
()
as
u64
,
slice
.as_mut_ptr
()
as
u64
)
};
let
page_phys
=
unsafe
{
paging_create
(
os
,
kernel
.as_ptr
()
as
u64
,
kernel
.len
()
as
u64
)
...
...
@@ -447,6 +465,8 @@ fn main<
areas_size
:
unsafe
{
(
AREAS
.len
()
*
mem
::
size_of
::
<
OsMemoryEntry
>
())
as
u64
},
initfs_base
,
initfs_size
,
}
)
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment