tomaka / redshirt

🧑‍🔬 Operating system
GNU General Public License v3.0
1.43k stars 37 forks source link

Have the kernel run on an actual Raspberry Pi #308

Open tomaka opened 4 years ago

tomaka commented 4 years ago

I'm mostly opening this issue for note tracking.

A known working point is doing cargo run -- build-image --target=arm-rpi3 --device-type sd-card --out foo.img --release in the standalone-builder, with the following diff:

diff --git a/kernel/standalone-builder/src/image.rs b/kernel/standalone-builder/src/image.rs
index 33b9855..dddfdc6 100644
--- a/kernel/standalone-builder/src/image.rs
+++ b/kernel/standalone-builder/src/image.rs
@@ -111,12 +111,12 @@ pub fn build_image(config: Config) -> Result<(), Error> {
                 .create(true)
                 .open(config.output_file)
                 .unwrap();
-            img_file.set_len(1 * 1024 * 1024 * 1024)?;
+            img_file.set_len(32 * 1024 * 1024)?;
             let img_file = fscommon::BufStream::new(img_file);
             build_raspberry_pi_sd_card(
                 img_file,
                 fs::File::open(build_dir.path().join("kernel7.img")).unwrap(),
-                fs::File::open(build_dir.path().join("kernel8.img")).unwrap(),
+                fs::File::open("../rust-raspi3-OS-tutorials/11_virtual_memory/kernel8.img").unwrap(),//build_dir.path().join("kernel8.img")).unwrap(),
             )?;
             Ok(())
         }
@@ -256,7 +256,7 @@ fn build_raspberry_pi_sd_card(
             buf
         };

-        {
+        /*{
             let mut file = root_dir.create_file("kernel.img")?;
             io::copy(&mut io::Cursor::new(&kernel_32bits), &mut file)?;
         }
@@ -267,7 +267,7 @@ fn build_raspberry_pi_sd_card(
         {
             let mut file = root_dir.create_file("kernel7l.img")?;
             io::copy(&mut io::Cursor::new(&kernel_32bits), &mut file)?;
-        }
+        }*/
         {
             let mut file = root_dir.create_file("kernel8.img")?;
             io::copy(&mut kernel_64bits, &mut file)?;

We copy-paste the kernel from tutorial 11 here. (beware that not all tutorials seem to work on real hardware, at least for me) The screen has to be started with screen /dev/ttyUSB0 230400.

In other words, the image builder works.

Now the next step is to progressively understand the difference between the tutorial code and ours, and try to get a minimal working example.

tomaka commented 4 years ago

287 also included a fix for ARM. Instead of doing memset(__bss_start, __bss_end, 0) we would do something like memset(value_written_at_bss_start, value_written_at_bss_end, 0), which at best doesn't do much and at worst is a pretty big UB.

tomaka commented 4 years ago

Note for self: if I don't comment out copying kernel.img, kernel7.img and kernel7l.img, the thing doesn't work. In other words, kernel8.img isn't picked over the others.

tomaka commented 4 years ago

I tried taking the known working code and replace the printing code with uart_init() and write_uart(). Doesn't work.

I also tried taking the known working point and replace the initialization code with our _start function that then jumps back to the working code. Doesn't work.

At this point I'm going to personally give up and won't try again without the help of someone familiar with Raspberry Pis, or unless I get linked to serious documentation that is known to be exact.