Git Product home page Git Product logo

nixos-licheepi4a's Introduction

NixOS on LicheePi 4A

This repo contains the code to get NixOS running on LicheePi 4A.

Default user: lp4a, default password: lp4a.

TODO

  • release an image
  • build opensbi from source
  • build u-boot from source
  • support for booting from emmc
  • fix the sdImage's file size
  • fix the sdImage's auto resize after the first boot.
  • Failed to enable firewall due to the error: firewall-start[2300]: iptables: Failed to initialize nft: Protocol not supported
  • verify all the hardware features available by th1520
    • ethernet (rj45)
    • wifi
    • bluetooth
    • audio
    • gpio
    • uart/ttl
    • gpu
      • The GPU driver of TH1520 is closed source, and it's high coupling with the operation system, make it quite difficult to make it work on NixOS.
    • npu
      • no one has seem to be done any work related to TH1520's NPU, and even licheepi4a's official docs does not contain any relevant contents(only a TODO).
    • ...

Build u-boot & sdImage

You can skip this step if you just want to flash the prebuilt image.

Build u-boot:

nix build .#uboot -L --show-trace

After the build is complete, the u-boot will be in result/u-boot-with-spl.bin, please copy it to another place for later use.

Build sdImage:

# I have uploaded the build cache to cachix, you can use it to speed up builds.
# which may take a long time without my cache, about 2 hours on my machine
nix run nixpkgs#cachix -- use licheepi4a

nix build .#sdImage -L --show-trace

After the build is complete, the image will be in result/sd-image/nixos-licheepi4a-sd-image-xxx-riscv64-linux.img.

The image has some problem currently, we need to fix the partition size by the following commands:

cp result/sd-image/nixos-licheepi4a-sd-image-*-riscv64-linux.img nixos-lp4a.img

chmod +w nixos-lp4a.img
# increase img's file size
dd if=/dev/zero bs=1M count=16 >> nixos-lp4a.img
sudo losetup --find --partscan nixos-lp4a.img

# check rootfs's status, it's broken.
sudo fsck /dev/loop0p2

echo w | sudo fdisk /dev/loop0
# increase the rootfs's partition size & file system size
nix shell nixpkgs#cloud-utils
sudo growpart /dev/loop0 2

# check rootfs's status again, it should be normal now.
sudo fsck /dev/loop0p2

# umount the image file
sudo losetup -d /dev/loop0

Flash into SD card

Official Docs: https://wiki.sipeed.com/hardware/en/lichee/th1520/lpi4a/4_burn_image.html

According to the official docs, the flash process of LicheePi 4A is as follows:

  1. Press and hold the BOOT button on the board, then plug in the USB-C cable to power on (the other end of the cable is connected to the PC), and you can enter the USB burning mode (fastboot).
    1. the command lsusb | grep T-HEAD should print ID 2345:7654 T-HEAD USB download gadget
  2. Then use the following command to flash the image into the board's eMMC.
    1. The fastboot program can be downloaded directly from Android Platform Tools, or installed from the package manager.

So first, download the prebuilt u-boot-with-spl.bin & nixos-licheepi4a-sd-image-xxx-riscv64-linux.img.zst from releases, or build them by yourself.

Then, flash into the board's spl partition and uboot partition:

# 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

Finally, flash boot & rootfs into SD card:

mv nixos-licheepi4a-sd-image-*-riscv64-linux.img.zst nixos-lp4a.img.zst
zstd -d nixos-lp4a.img.zst
# please replace `/dev/sdX` with your SD card's device name
sudo dd if=nixos-lp4a.img of=/dev/sdX bs=4M status=progress

# fix the wrong physical sector size
sudo parted /dev/sdb

Now insert the SD card into the board, and power on, you should see NixOS booting.

Due to the problem of the image, you need to resize the rootfs manually after the first boot.

Flash into eMMC

To flash the image into the board's eMMC, you need to flash the image into the board and start into NixOS first.

Then, use the following command to flash the image into the board's eMMC:

# upload the sdImage to the NixOS system on the board
scp nixos-lp4a.img lp4a@<ip-of-your-board>:~/

# login to the board via ssh or serial port
ssh lp4a@<ip-of-your-board>

# check all the block devices
# you should see mmcblk0(eMMC) & mmcblk1(SD card)
$ lsblk
NAME         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
mmcblk0      179:0    0  29.1G  0 disk 
├─mmcblk0p1  179:1    0   240M  0 part 
└─mmcblk0p2  179:2    0   1.6G  0 part 
mmcblk0boot0 179:8    0     4M  1 disk 
mmcblk0boot1 179:16   0     4M  1 disk 
mmcblk1      179:24   0 117.8G  0 disk 
├─mmcblk1p1  179:25   0   200M  0 part 
└─mmcblk1p2  179:26   0 117.5G  0 part /nix/store
                                       /

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

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 via serial port

See Debug.md

Custom Deployment

You can use this flake as an input to build your own configuration. Here is an example configuration that you can use as a starting point: Demo - Deployment

How this repo works

LicheePi 4A use RevyOS officially. The basic idea of this repo is to use revyos's kernel, u-boot and opensbi, with a NixOS rootfs, to get NixOS running on LicheePi 4A.

See Also

RevyOS's kernel, u-boot and opensbi:

And other efforts to bring Fedora to LicheePi 4A:

And other efforts to bring NixOS to RISC-V:

Special thanks to @NickCao, @revyos, @chainsx and @zhaofengli.

nixos-licheepi4a's People

Contributors

ryan4yin avatar twz123 avatar we-do-it-lu avatar

Stargazers

SeungheonOh avatar Fabian Thomas avatar Ethan Reece avatar  avatar Sergei Zimmerman avatar Sergei Zimmerman avatar *Kim Zick avatar  avatar  avatar KREYREN avatar  avatar Geir Okkenhaug Jerstad avatar  avatar  avatar Bryan A. S. avatar jason avatar Lu Hui avatar  avatar 5aaee9 avatar  avatar Alexei Robyn avatar Lev V. Babchenko avatar Federico Damián Schonborn avatar Gabriel Fontes avatar hiromasa avatar MonKey Lee avatar  avatar Vanilla avatar 苏业钦 avatar  avatar

Watchers

苏业钦 avatar  avatar  avatar  avatar  avatar

nixos-licheepi4a's Issues

GPU/NPU Support?

Hi,

You wrote in this projects readme that gpu as well as npu support may not be possible without going into detail on that assumption. I was wondering if there's any reasoning behind this/any technical blockers for supporting the platforms npu/gpu?

Cheers

Support for Vector Processor (RVV 1.0)

Hi, Is this OS has support for RVV 1.0 or in other words I can compile the code for vector extension using the risc-v toolchain compiler available in it?

Thank you

wrong image size

› sudo fdisk /dev/loop0

Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/loop0: 1.89 GiB, 2030879744 bytes, 3966562 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 46D4C0B1-70A6-ED42-BC9A-126E0E7D8F1D

Device        Start     End Sectors  Size Type
/dev/loop0p1  16384  425983  409600  200M Microsoft basic data
/dev/loop0p2 425984 3964927 3538944  1.7G Linux filesystem

Command (m for help): i
Partition number (1,2, default 2): 

         Device: /dev/loop0p2
          Start: 425984
            End: 3964927
        Sectors: 3538944
           Size: 1.7G
           Type: Linux filesystem
      Type-UUID: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
           UUID: A2387A89-08EE-5F4A-B9E0-1872FF75F49F

Command (m for help): q


› sudo fsck /dev/loop0p2
∙ 
fsck from util-linux 2.38.1
e2fsck 1.46.6 (1-Feb-2023)
The filesystem size (according to the superblock) is 442568 blocks
The physical size of the device is 442368 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? no


› sudo dumpe2fs /dev/loop0p2
dumpe2fs 1.46.6 (1-Feb-2023)
Filesystem volume name:   NIXOS_SD
Last mounted on:          <not available>
Filesystem UUID:          14e19a7b-0ae0-484d-9d54-43bd6fdc20c7
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              109760
Block count:              442568
Reserved block count:     22127
Free blocks:              94813
Free inodes:              59082
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      214
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         7840
Inode blocks per group:   490
Flex block group size:    16
Filesystem created:       Thu Jan  1 08:00:01 1970
Last mount time:          n/a
Last write time:          Sun Aug 27 13:35:05 2023
Mount count:              0
Maximum mount count:      -1
Last checked:             Sun Aug 27 13:35:05 2023
Check interval:           0 (<none>)
Lifetime writes:          1372 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      3e9d390f-4dd6-4cc4-b327-6769605baea7
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x4d95df7e
Journal features:         (none)
Total journal size:       32M
Total journal blocks:     8192
Max transaction length:   8192
Fast commit length:       0
Journal sequence:         0x00000001
Journal start:            0


Group 0: (Blocks 0-32767) csum 0x6c1a [ITABLE_ZEROED]
  Primary superblock at 0, Group descriptors at 1-1
  Reserved GDT blocks at 2-215
  Block bitmap at 216 (+216), csum 0x80276f90
  Inode bitmap at 230 (+230), csum 0xda127cfb
  Inode table at 244-733 (+244)
  0 free blocks, 0 free inodes, 1492 directories
  Free blocks: 
  Free inodes: 
Group 1: (Blocks 32768-65535) csum 0x9735 [ITABLE_ZEROED]
  Backup superblock at 32768, Group descriptors at 32769-32769
  Reserved GDT blocks at 32770-32983
  Block bitmap at 217 (bg #0 + 217), csum 0x80276f90
  Inode bitmap at 231 (bg #0 + 231), csum 0xda127cfb
  Inode table at 734-1223 (bg #0 + 734)
  0 free blocks, 0 free inodes, 150 directories
  Free blocks: 
  Free inodes: 
Group 2: (Blocks 65536-98303) csum 0xbf94 [ITABLE_ZEROED]
  Block bitmap at 218 (bg #0 + 218), csum 0x80276f90
  Inode bitmap at 232 (bg #0 + 232), csum 0xda127cfb
  Inode table at 1224-1713 (bg #0 + 1224)
  0 free blocks, 0 free inodes, 1174 directories
  Free blocks: 
  Free inodes: 
Group 3: (Blocks 98304-131071) csum 0xbd49 [ITABLE_ZEROED]
  Backup superblock at 98304, Group descriptors at 98305-98305
  Reserved GDT blocks at 98306-98519
  Block bitmap at 219 (bg #0 + 219), csum 0x80276f90
  Inode bitmap at 233 (bg #0 + 233), csum 0xda127cfb
  Inode table at 1714-2203 (bg #0 + 1714)
  0 free blocks, 0 free inodes, 1139 directories
  Free blocks: 
  Free inodes: 
Group 4: (Blocks 131072-163839) csum 0x1566 [ITABLE_ZEROED]
  Block bitmap at 220 (bg #0 + 220), csum 0x80276f90
  Inode bitmap at 234 (bg #0 + 234), csum 0xda127cfb
  Inode table at 2204-2693 (bg #0 + 2204)
  0 free blocks, 0 free inodes, 1055 directories
  Free blocks: 
  Free inodes: 
Group 5: (Blocks 163840-196607) csum 0xcaaf [ITABLE_ZEROED]
  Backup superblock at 163840, Group descriptors at 163841-163841
  Reserved GDT blocks at 163842-164055
  Block bitmap at 221 (bg #0 + 221), csum 0x80276f90
  Inode bitmap at 235 (bg #0 + 235), csum 0xda127cfb
  Inode table at 2694-3183 (bg #0 + 2694)
  0 free blocks, 0 free inodes, 1056 directories
  Free blocks: 
  Free inodes: 
Group 6: (Blocks 196608-229375) csum 0x5dff [ITABLE_ZEROED]
  Block bitmap at 222 (bg #0 + 222), csum 0x80276f90
  Inode bitmap at 236 (bg #0 + 236), csum 0xbc1fd864
  Inode table at 3184-3673 (bg #0 + 3184)
  0 free blocks, 4202 free inodes, 1005 directories, 4202 unused inodes
  Free blocks: 
  Free inodes: 50679-54880
Group 7: (Blocks 229376-262143) csum 0xa0a1 [INODE_UNINIT, ITABLE_ZEROED]
  Backup superblock at 229376, Group descriptors at 229377-229377
  Reserved GDT blocks at 229378-229591
  Block bitmap at 223 (bg #0 + 223), csum 0x80276f90
  Inode bitmap at 237 (bg #0 + 237), csum 0x00000000
  Inode table at 3674-4163 (bg #0 + 3674)
  0 free blocks, 7840 free inodes, 0 directories, 7840 unused inodes
  Free blocks: 
  Free inodes: 54881-62720
Group 8: (Blocks 262144-294911) csum 0xcfbf [INODE_UNINIT, ITABLE_ZEROED]
  Block bitmap at 224 (bg #0 + 224), csum 0x80276f90
  Inode bitmap at 238 (bg #0 + 238), csum 0x00000000
  Inode table at 4164-4653 (bg #0 + 4164)
  0 free blocks, 7840 free inodes, 0 directories, 7840 unused inodes
  Free blocks: 
  Free inodes: 62721-70560
Group 9: (Blocks 294912-327679) csum 0x8365 [INODE_UNINIT, ITABLE_ZEROED]
  Backup superblock at 294912, Group descriptors at 294913-294913
  Reserved GDT blocks at 294914-295127
  Block bitmap at 225 (bg #0 + 225), csum 0x80276f90
  Inode bitmap at 239 (bg #0 + 239), csum 0x00000000
  Inode table at 4654-5143 (bg #0 + 4654)
  0 free blocks, 7840 free inodes, 0 directories, 7840 unused inodes
  Free blocks: 
  Free inodes: 70561-78400
Group 10: (Blocks 327680-360447) csum 0xe44d [INODE_UNINIT, ITABLE_ZEROED]
  Block bitmap at 226 (bg #0 + 226), csum 0xca54ac7c
  Inode bitmap at 240 (bg #0 + 240), csum 0x00000000
  Inode table at 5144-5633 (bg #0 + 5144)
  12693 free blocks, 7840 free inodes, 0 directories, 7840 unused inodes
  Free blocks: 347755-360447
  Free inodes: 78401-86240
Group 11: (Blocks 360448-393215) csum 0xb5da [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
  Block bitmap at 227 (bg #0 + 227), csum 0x00000000
  Inode bitmap at 241 (bg #0 + 241), csum 0x00000000
  Inode table at 5634-6123 (bg #0 + 5634)
  32768 free blocks, 7840 free inodes, 0 directories, 7840 unused inodes
  Free blocks: 360448-393215
  Free inodes: 86241-94080
Group 12: (Blocks 393216-425983) csum 0xd4a8 [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
  Block bitmap at 228 (bg #0 + 228), csum 0x00000000
  Inode bitmap at 242 (bg #0 + 242), csum 0x00000000
  Inode table at 6124-6613 (bg #0 + 6124)
  32768 free blocks, 7840 free inodes, 0 directories, 7840 unused inodes
  Free blocks: 393216-425983
  Free inodes: 94081-101920
Group 13: (Blocks 425984-442567) csum 0x23e7 [INODE_UNINIT, ITABLE_ZEROED]
  Block bitmap at 229 (bg #0 + 229), csum 0x4365cc0f
  Inode bitmap at 243 (bg #0 + 243), csum 0x00000000
  Inode table at 6614-7103 (bg #0 + 6614)
  16584 free blocks, 7840 free inodes, 0 directories, 7840 unused inodes
  Free blocks: 425984-442567
  Free inodes: 101921-109760
  • superblock of ext4 filesystem(rootfs, /dev/loop0p2): has 442568 blocks, 4096 bytes per block.
    • dumpe2fs read the superblock and print its info.

Implementation for 16GB version

The 16GB version of LicheePi 4A requires the following changes to work correctly:

https://github.com/ryan4yin/nixos-licheepi4a/blob/main/pkgs/u-boot/default.nix#L22

Requires:

# https://github.com/chainsx/thead-u-boot/blob/extlinux/configs/light_lpi4a_16g_defconfig
defconfig = "light_lpi4a_16g_defconfig";

https://github.com/ryan4yin/nixos-licheepi4a/blob/main/modules/licheepi4a.nix#L34

Requires:

# https://github.com/revyos/thead-kernel/blob/lpi4a/arch/riscv/boot/dts/thead/light-lpi4a-16gb.dts
name = "thead/light-lpi4a-16gb.dtb";

I figured out the stupid way that using the 8GB version will allow the device to boot, but it will be unable to use the RAM and seems to have various issues associated with using the wrong configurations

Proposing to implement a handling that allows producing u-boot and DTS for the 16GB version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.