Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bootloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
bootloader
Commits
59a373b4
Verified
Commit
59a373b4
authored
3 years ago
by
Jacob Lorentzon
Browse files
Options
Downloads
Patches
Plain Diff
Pass an external initfs image to the kernel.
parent
2f86d3a7
No related branches found
No related tags found
1 merge request
!8
Pass an external initfs image to the kernel.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+52
-32
52 additions, 32 deletions
src/main.rs
with
52 additions
and
32 deletions
src/main.rs
+
52
−
32
View file @
59a373b4
...
@@ -88,6 +88,9 @@ pub struct KernelArgs {
...
@@ -88,6 +88,9 @@ pub struct KernelArgs {
areas_base
:
u64
,
areas_base
:
u64
,
areas_size
:
u64
,
areas_size
:
u64
,
initfs_base
:
u64
,
initfs_size
:
u64
,
}
}
fn
select_mode
<
fn
select_mode
<
...
@@ -278,6 +281,48 @@ fn redoxfs<
...
@@ -278,6 +281,48 @@ fn redoxfs<
panic!
(
"RedoxFS out of unlock attempts"
);
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
<
fn
main
<
D
:
Disk
,
D
:
Disk
,
V
:
Iterator
<
Item
=
OsVideoMode
>
V
:
Iterator
<
Item
=
OsVideoMode
>
...
@@ -304,38 +349,11 @@ fn main<
...
@@ -304,38 +349,11 @@ fn main<
panic!
(
"Failed to allocate memory for stack"
);
panic!
(
"Failed to allocate memory for stack"
);
}
}
let
kernel
=
fs
.tx
(|
tx
|
{
let
kernel
=
load_to_memory
(
os
,
&
mut
fs
,
"kernel"
,
Filetype
::
Elf
);
let
node
=
tx
.find_node
(
redoxfs
::
TreePtr
::
root
(),
"kernel"
)
let
(
initfs_size
,
initfs_base
)
=
{
.expect
(
"Failed to find kernel file"
);
let
slice
=
load_to_memory
(
os
,
&
mut
fs
,
"initfs"
,
Filetype
::
Other
);
(
slice
.len
()
as
u64
,
slice
.as_mut_ptr
()
as
u64
)
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
page_phys
=
unsafe
{
let
page_phys
=
unsafe
{
paging_create
(
os
,
kernel
.as_ptr
()
as
u64
,
kernel
.len
()
as
u64
)
paging_create
(
os
,
kernel
.as_ptr
()
as
u64
,
kernel
.len
()
as
u64
)
...
@@ -447,6 +465,8 @@ fn main<
...
@@ -447,6 +465,8 @@ fn main<
areas_size
:
unsafe
{
areas_size
:
unsafe
{
(
AREAS
.len
()
*
mem
::
size_of
::
<
OsMemoryEntry
>
())
as
u64
(
AREAS
.len
()
*
mem
::
size_of
::
<
OsMemoryEntry
>
())
as
u64
},
},
initfs_base
,
initfs_size
,
}
}
)
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment