Skip to content

Commit

Permalink
feat: boot from emmc
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan4yin committed Aug 15, 2023
1 parent 60bb1cc commit 3a3f082
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 111 deletions.
36 changes: 14 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Default user: `lp4a`, default password: `lp4a`.
- [x] release an image
- [x] build opensbi from source
- [x] build u-boot from source
- [ ] support flashing rootfs into emmc
- [x] support boot from emmc
- [ ] debug with qemu
- [ ] fix the sdImage's file size
- [ ] fix the sdImage's auto resize after the first boot.
Expand Down Expand Up @@ -112,34 +112,26 @@ Now insert the SD card into the board, and power on, you should see NixOS bootin
## Flash into eMMC

> :warning: TODO work in prgress, not working yet.
To flash the image into the board's eMMC, you need to flash the image into the board and start into NixOS first.

```shell
nix build .#boot -L --show-trace
cp result boot.ext4

nix build .#rootfs -L --show-trace
cp result rootfs.ext4
```

Flash boot and rootfs partition into eMMC:
Then, use the following command to flash the image into the board's eMMC:

```bash
# flash u-boot into spl partition
sudo fastboot flash ram u-boot-with-spl.bin
sudo fastboot reboot
# flash uboot partition
sudo fastboot flash uboot u-boot-with-spl.bin
# upload the sdImage to the NixOS system on the board
scp nixos-lp4a.img lp4a@<ip-of-your-board>:~/

# flash nixos's boot partition
sudo fastboot flash boot boot.ext4
# flash nixos's rootfs partition
sudo fastboot flash root rootfs.ext4
# login to the board via ssh or serial port
ssh lp4a@<ip-of-your-board>

# flash the image into the board's eMMC
sudo dd if=nixos-lp4a.img of=/dev/mmcblk0 bs=4M status=progress
```

All the partitions are predefined in the u-boot, so we have to flash the partitions into the right place.
After the flash is complete, remove the SD card and reboot, you should see NixOS booting from eMMC.

> Due to the problem of the image, you need to resize the rootfs manually after the first boot.
## Debug
## Debug via serial port

See [Debug.md](./Debug.md)

Expand Down
26 changes: 0 additions & 26 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,11 @@
];
};

# cross-build an sd-image
nixosConfigurations.lp4a-cross-emmc = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";

specialArgs = {
inherit nixpkgs;
pkgsKernel = pkgsKernelCross;
};
modules = [
{
# cross-compilation this flake.
nixpkgs.crossSystem = {
system = "riscv64-linux";
};
}

./modules/licheepi4a.nix
./modules/emmc-image-lp4a.nix
./modules/user-group.nix
];
};

packages.x86_64-linux = {
# u-boot & sdImage for boot from sdcard.
uboot = pkgsKernelCross.callPackage ./pkgs/u-boot {};
sdImage = self.nixosConfigurations.lp4a-cross.config.system.build.sdImage;

# (WIP)the rootfs and boot image for boot from emmc.
boot = self.nixosConfigurations.lp4a-cross-emmc.config.system.build.bootImage;
rootfs = self.nixosConfigurations.lp4a-cross-emmc.config.system.build.rootfsImage;

# the nixpkgs
pkgsKernelCross = pkgsKernelCross;
pkgsKernelNative = pkgsKernelNative;
Expand Down
63 changes: 0 additions & 63 deletions modules/emmc-image-lp4a.nix

This file was deleted.

0 comments on commit 3a3f082

Please sign in to comment.