Skip to content

Instantly share code, notes, and snippets.

@wangjiezhe
Forked from thesamesam/gentoo-crossdev.md
Created March 13, 2025 12:58
Show Gist options
  • Select an option

  • Save wangjiezhe/5d13485cd5bee5df85a9a4382099eee4 to your computer and use it in GitHub Desktop.

Select an option

Save wangjiezhe/5d13485cd5bee5df85a9a4382099eee4 to your computer and use it in GitHub Desktop.

Revisions

  1. @thesamesam thesamesam revised this gist Feb 13, 2024. 1 changed file with 2 additions and 9 deletions.
    11 changes: 2 additions & 9 deletions gentoo-crossdev.md
    Original file line number Diff line number Diff line change
    @@ -34,14 +34,6 @@ Pick a nice looking one, like `default/linux/riscv/20.0/rv64gc/lp64`.
    $ PORTAGE_CONFIGROOT=/usr/riscv64-unknown-linux-gnu eselect profile set default/linux/riscv/20.0/rv64gc/lp64
    ```

    ## Remove -pam nonsense

    Edit `/usr/riscv64-unknown-linux-gnu/etc/portage/make.conf` to remove `USE=-pam` because it'll conflict with `sys-apps/util-linux` being the default `su` provider:

    ```
    $ sed -i -e "s:-pam::" /usr/riscv64-unknown-linux-gnu/etc/portage/make.conf
    ```

    ## Avoid circular deps

    ```
    @@ -70,4 +62,5 @@ See https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_u
    ## Do it!

    1. chroot in to `/usr/riscv64-unknown-linux-gnu` using your preferred method
    2. `emerge -a -uvDU @world` (may need to do `@system` first)
    2. update `/etc/portage/make.conf` to drop ROOT, PORTAGE_TMPDIR, PKG_CONFIG_DIR
    3. `emerge -a -uvDU @world` (may need to do `@system` first)
  2. @thesamesam thesamesam revised this gist Oct 8, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gentoo-crossdev.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ These instructions cover:
    2. populating the new ROOT
    3. making it `chroot`able using qemu-user to easily run "native" builds or tests (this is like a stage3 at the end)

    You do not need to follow through to the end.
    You do not need to follow through to the end if you don't need a stage3-like root.

    ## Set up the toolchain
    ```
  3. @thesamesam thesamesam revised this gist Oct 8, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gentoo-crossdev.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,9 @@
    These instructions cover:
    1. building a cross toolchain
    2. populating the new ROOT
    3. making it `chroot`able using qemu-user to easily run "native" builds or tests
    3. making it `chroot`able using qemu-user to easily run "native" builds or tests (this is like a stage3 at the end)

    You do not need to follow through to the end.

    ## Set up the toolchain
    ```
  4. @thesamesam thesamesam renamed this gist Oct 3, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @thesamesam thesamesam revised this gist Oct 3, 2022. No changes.
  6. @thesamesam thesamesam revised this gist Jun 25, 2022. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -69,6 +69,3 @@ See https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_u

    1. chroot in to `/usr/riscv64-unknown-linux-gnu` using your preferred method
    2. `emerge -a -uvDU @world` (may need to do `@system` first)
    3. `emerge -v1 --with-test-deps --onlydeps sys-libs/glibc`
    4. `FEATURES=test emerge -v1 sys-libs/glibc`

  7. @thesamesam thesamesam revised this gist Jun 16, 2022. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,10 @@
    # Cross instructions

    These instructions cover:
    1. building a cross toolchain
    2. populating the new ROOT
    3. making it `chroot`able using qemu-user to easily run "native" builds or tests

    ## Set up the toolchain
    ```
    $ crossdev riscv64-unknown-linux-gnu
  8. @thesamesam thesamesam revised this gist Jun 16, 2022. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -41,3 +41,29 @@ $ sed -i -e "s:-pam::" /usr/riscv64-unknown-linux-gnu/etc/portage/make.conf
    $ USE="-filecaps" riscv64-unknown-linux-gnu-emerge -v1 @system
    ```

    # Chroot in

    ## Set up QEMU

    In `/etc/portage/package.use/qemu`, put:
    ```
    app-emulation/qemu static-user # optional but makes life easier
    */* QEMU_USER_TARGETS: riscv32 riscv64
    ```

    Then `emerge -v app-emulation/qemu`

    ## binfmt

    See https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot.

    1. Set up binfmt appropriately for `riscv64` (TODO: explain how, but wiki link above covers it pretty much)
    2. `cp /usr/bin/qemu-riscv64 /usr/riscv64-unknown-linux-gnu/usr/bin/`

    ## Do it!

    1. chroot in to `/usr/riscv64-unknown-linux-gnu` using your preferred method
    2. `emerge -a -uvDU @world` (may need to do `@system` first)
    3. `emerge -v1 --with-test-deps --onlydeps sys-libs/glibc`
    4. `FEATURES=test emerge -v1 sys-libs/glibc`

  9. @thesamesam thesamesam revised this gist Jun 16, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,8 @@ $ riscv64-unknown-linux-gnu-emerge -v1 sys-libs/glibc
    $ riscv64-unknown-linux-gnu-emerge -v1 @system
    ```

    There's now already a bunch of things in `/usr/riscv64-unknown-linux-gnu` but we want to make it useful to chroot into and do things.

    # Profile setup


  10. @thesamesam thesamesam renamed this gist Jun 16, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. @thesamesam thesamesam created this gist Jun 16, 2022.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    # Cross instructions

    ## Set up the toolchain
    ```
    $ crossdev riscv64-unknown-linux-gnu
    ```

    # Avoid dependency hell and populate the `ROOT`
    Emerge `sys-libs/glibc` (no, `@system` / `@world` won't make it realise it can/should do this, don't ask why, I don't know):

    ```
    $ riscv64-unknown-linux-gnu-emerge -v1 sys-libs/glibc
    $ riscv64-unknown-linux-gnu-emerge -v1 @system
    ```

    # Profile setup


    ## Choosing profile
    Run: `PORTAGE_CONFIGROOT=/usr/riscv64-unknown-linux-gnu eselect profile list`

    Pick a nice looking one, like `default/linux/riscv/20.0/rv64gc/lp64`.

    ```
    $ PORTAGE_CONFIGROOT=/usr/riscv64-unknown-linux-gnu eselect profile set default/linux/riscv/20.0/rv64gc/lp64
    ```

    ## Remove -pam nonsense

    Edit `/usr/riscv64-unknown-linux-gnu/etc/portage/make.conf` to remove `USE=-pam` because it'll conflict with `sys-apps/util-linux` being the default `su` provider:

    ```
    $ sed -i -e "s:-pam::" /usr/riscv64-unknown-linux-gnu/etc/portage/make.conf
    ```

    ## Avoid circular deps

    ```
    $ USE="-filecaps" riscv64-unknown-linux-gnu-emerge -v1 @system
    ```