User:Minou/RiscV

From Gentoo Wiki
Jump to:navigation Jump to:search

Create gentoo rootfs

The rootfs directory is created on /usr/src/riscv64

root #cd /usr/src
root #mkdir riscv64
root #cd riscv64
root #mkdir rootfs-riscv64
root #cd rootfs-riscv64
Once the rootfs is built we compress it in a file that can later be used
to create a gentoo installation for a particular riscv64 board
We then make specific updates for that particular board

Download stage3 and decompress in rootfs directory

root #tar --numeric-owner --xattrs -xvJpf stage3-rv64_lp64d-openrc-20250116T141832Z.tar.xz
root #rm -f stage3-rv64_lp64d-openrc-20250116T141832Z.tar.xz
root #cp /etc/resolv.conf etc
root #cd ..
Add the script 16-set-alias.bash on /usr/src/riscv64/rootfs-riscv64/etc/bashrc.d
# /etc/bash/bashrc.d/16-set-alias.bash
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

alias dir='ls -la -N --color'

alias rm='rm -i'
alias del='rm -i'

alias rd=rmdir
alias md='mkdir -p'

Prepare for chroot

In order to chroot on a riscv rootfs a few things have to be done.
First you need to make sure that the kernel supports it and emerge needed support
The build system's kernel must support miscellaneous binary formats.
This can be enabled  with CONFIG_BINFMT_MISC=m 
or CONFIG_BINFMT_MISC=y in the the kernel's .config file. 
Tip
A system restart is required after building this module before it can be used.
KERNEL Enable CONFIG_BINFMT_MISC
Executable file formats  --->
  <*> Kernel support for MISC binaries
Important
app-emulation/qemu must be emerged with USE=static-user to use user targets.
Warning
QEMU_SOFTMMU_TARGETS and QEMU_USER_TARGETS are empty by default and must be defined to utilize user targets.
Note
Activating the static-user will require supporting libraries to be build with static-libs support.
FILE /etc/portage/package.use/qemuEnable all user targets and static-libs in supporting libraries.
# Enable static-user and add the riscv64 and other targets
app-emulation/qemu static-user QEMU_SOFTMMU_TARGETS: * QEMU_USER_TARGETS: *
# required by app-emulation/qemu::gentoo[static,static-user]
# required by qemu (argument)
dev-libs/glib static-libs
# required by app-emulation/qemu::gentoo[-static,static-user]
# required by qemu (argument)
sys-libs/zlib static-libs
# required by app-emulation/qemu::gentoo[-static,static-user,xattr]
# required by qemu (argument)
sys-apps/attr static-libs
# required by dev-libs/glib::gentoo
# required by app-emulation/qemu::gentoo[-static,static-user]
# required by qemu (argument)
dev-libs/libpcre2 static-libs

Emerge needed packages

root #emerge --ask sys-block/bmap-tools sys-fs/genimage dev-libs/libyaml sys-fs/mtools
root #emerge --ask app-emulation/qemu --update --newuse --deep
root #emerge --ask sys-apps/arch-chroot
root #emerge --ask sys-fs/dosfstools
root #cd /usr/bin
root #ln -s mkfs.vfat mkdosfs
root #cd ~

Start the qemu-binfmt service

To start the qemu-binfmt service:

root #rc-service qemu-binfmt start

It may be wise for the services to be started by default on boot:

root #rc-update add qemu-binfmt default

To be able to chroot into a riscv64 rootfs while using an amd64 system, the QEMU static-user binary must be copied into the environment.

cp /usr/bin/qemu-riscv64 /usr/src/riscv64/rootfs-riscv64/usr/bin/

chroot in rootfs directory

Once the environment has been prepared, sys-apps/arch-chroot can be used:

root #arch-chroot /usr/src/riscv64/rootfs-riscv64
You will likely get this message which is nonsense. 
I have done this for years without any issue. 
Once the compiling is done I create a compressed file which will be decompressed
on the  micro SD.
 
==> WARNING: /usr/src/riscv64/rootfs-riscv64 is not a mountpoint. 
This may have undesirable side effects.
root #env-update
root #export PS1="(chroot) $PS1"
root #source /etc/profile

emerge needed files

root #emerge-webrsync
root #emerge --sync

Edit /etc/portage/make.conf file

FILE /etc/portage/make.conf
COMMON_FLAGS="-O2 -pipe"
 CFLAGS="${COMMON_FLAGS}"
 CXXFLAGS="${COMMON_FLAGS}"
 FCFLAGS="${COMMON_FLAGS}"
 FFLAGS="${COMMON_FLAGS}"
 
 CHOST="riscv64-unknown-linux-gnu"
 
 LINGUAS="fr fr_CA en en_US es es_AR es_BO es_CL es_CO es_CR es_CU
 es_DO es_EC es_ES es_GT es_HN es_MX es_NI es_PA es_PE
 es_PR es_PY es_SV es_US es_UY es_VE
 zh zh_CN zh_HK zh_SG zh_TW"
 
 L10N="fr fr-CA en en-US es es-AR es-BO es-CL es-CO es-CR es-CU
 es-DO es-EC es-ES es-GT es-HN es-MX es-NI es-PA es-PE
 es-PR es-PY es-SV es-US es-UY es-VE
 zh zh-CN zh-HK zh-SG zh-TW"
 
 ACCEPT_LICENSE="*"
 # NOTE: This stage was built with the bindist USE flag enabled
 
 # This sets the language of build output to English.
 # Please keep this setting intact when reporting bugs.
 LC_MESSAGES=C.utf8
 FEATURES="-test -pid-sandbox -network-sandbox -sandbox -usersandbox -ipc-sandbox -selinux -sesandbox -collision-detect"
 
 USE="-zeitgeist -beagle -pcmcia -selinux xinerama x265 x264 -test \
 contrib cups qt6 tinfo gtk++ -bindist scanner \
 static-ppds -mavx -msse4.2 gcode openmp perl hdf5 cxx alsa"
 I also added a list of mirrors which the wiki editor won't allow me 
 to put in here not realizing that those links are all gentoo links
 GENTOO_MIRRORS=" List of mirrors sites"

 PORTDIR_OVERLAY="/usr/local/portage/catu"

Setup locales

You need to uncomment the lines for the languages that you may want to use in the future in the locale.gen/usr/src/riscv64/rootfs-riscv64/usr/bin/

root #locale-gen]
After this you need to set the locale that you want 
If the locales aren't seen run locale-gen again
root #locale -a
If the default is not the one you want, you will need to change it
In my case I want the French Canadian locale to be set
root #eselect locale list
 [1]   C
 [2]   C.utf8
 [3]   POSIX
 [4]   en_AG
 [5]   en_AG.utf8
 [6]   en_AU.utf8
 [7]   en_BW.utf8
 [8]   en_CA.utf8
 [9]   en_DK.utf8
 [10]  en_GB.utf8
 [11]  en_HK.utf8
 [12]  en_IE.utf8
 [13]  en_IN
 [14]  en_IN.utf8
 [15]  en_NG
 [16]  en_NG.utf8
 [17]  en_NZ.utf8
 [18]  en_PH.utf8
 [19]  en_SG.utf8
 [20]  en_US.utf8
 [21]  en_ZA.utf8
 [22]  en_ZM
 [23]  en_ZM.utf8
 [24]  en_ZW.utf8
 [25]  es_AR.utf8
 [26]  es_BO.utf8
 [27]  es_CL.utf8
 [28]  es_CO.utf8
 [29]  es_CR.utf8
 [30]  es_CU
 [31]  es_CU.utf8
 [32]  es_DO.utf8
 [33]  es_EC.utf8
 [34]  es_ES.utf8
 [35]  es_GT.utf8
 [36]  es_HN.utf8
 [37]  es_MX.utf8
 [38]  es_NI.utf8
 [39]  es_PA.utf8
 [40]  es_PE.utf8
 [41]  es_PR.utf8
 [42]  es_PY.utf8
 [43]  es_SV.utf8
 [44]  es_US.utf8
 [45]  es_UY.utf8
 [46]  es_VE.utf8
 [47]  fr_BE.utf8
 [48]  fr_CA.utf8
 [49]  fr_FR.utf8
 [50]  fr_LU.utf8
 [51]  ru_RU.utf8
 [52]  ru_UA.utf8
 [53]  zh_CN
 [54]  zh_CN.gb18030
 [55]  zh_CN.gb2312
 [56]  zh_CN.gbk
 [57]  zh_CN.utf8
 [58]  zh_HK
 [59]  zh_HK.big5hkscs
 [60]  zh_HK.utf8
 [61]  zh_SG
 [62]  zh_SG.gb2312
 [63]  zh_SG.gbk
 [64]  zh_SG.utf8
 [65]  zh_TW
 [66]  zh_TW.big5
 [67]  zh_TW.euctw
 [68]  zh_TW.utf8
 [69]  C.UTF8 *
 [ ]   (free form)
The one with a * is the default one which I need to change to 48 which is fr_CA.utf8
root #eselect locale set 48
Setting LANG to fr_CA.utf8 ...
Run ". /etc/profile" to update the variable in your shell.
root #. /etc/profile
FILE /etc/env.d/02locale
Since I changed the locale from C.UTF8 I need to change something
  in the 02locale file on /etc/env.d
  
  The original content is this :
  LANG="fr_CA.utf8"

  I added one line to satisfy some program who do not recognize locales correctly
  and changed the utf8 line because a few programs do not recognize the .utf8 form

  LANG="fr_CA.UTF-8"
  LC_COLLATE="C.UTF-8"

  If you do not use the us keyboard you need to change /etc/conf.d/keymaps
  I changed 3 lines  
  Use French Canadian keyboard
   keymap="cf"
  Use the windows key to go to the command line
   windowkeys="yes"
  I have family in France so that is usefull to have 
  the € character by typing altgr and E
   fix_euro="yes"

Add new Turbo Vision package

 Add tvision ebuild to /etc/local/portage/catu/dev-libs/
 The local portage directory is not created by default
 On /usr/local/portage/catu/profiles 
 a file named repo_name with the text "catu" needs to be created
 On /usr/local/portage/catu/metadata
 a file named layout.conf with the text "masters = gentoo" need to be created
 If you want a different name make sure that the /etc/portage/make.conf 
 is updated to use the new name
   
root #cd /usr/local/portage/catu
root #tar xvf tvision.tar.gz
root #rm tvision.tar.gz

Unmask packages

Most usefull applications are masked by default because the gentoo maintainers
do not know if those applications work. So they assume that they do not work
and just like Microsoft they protect you against yourself.
You need to add some information in two directories on /etc/portage/
On directory package.accept_keywords you enter this in a file, 
I name the file misc but the name is not important:
>=x11-terms/mate-terminal-1.24.1 **
>=x11-themes/mate-backgrounds-1.24.1 **
>=x11-themes/mate-themes-3.22.21 **
>=x11-themes/mate-themes-meta-3-r3 **
>=app-arch/engrampa-1.24.1 **
>=app-editors/pluma-1.24.1 **
>=app-text/atril-1.24-r2 **
>=media-gfx/eom-1.24.1 **
>=x11-misc/mate-notification-daemon-1.24.1 **
>=media-libs/libcanberra-0.30-r5 **
>=dev-libs/libpeas-1.30.0 **
>=app-text/yelp-tools-40.0 **
>=gnome-extra/yelp-xsl-40.0 **
>=gnome-extra/yelp-40.0 **
>=app-text/rarian-0.8.1-r3 **
>=dev-libs/tinyxml-2.6.2-r4 **
>=dev-cpp/glibmm-2.26.68.1 **
>=dev-cpp/gtkmm-3.24.5 **
>=dev-libs/libsigc++-2.10.7 **
>=dev-cpp/atkmm-2.28.2 **
>=dev-cpp/cairomm-1.14.3 **
>=dev-cpp/pangomm-2.42.2 **
>=x11-apps/xrandr-1.5.1 **
>=x11-libs/libfakekey-0.3-r1 **
>=app-text/poppler-0.21.05.0 **
>=app-text/libspectre-0.2.9 **
>=x11-libs/gtksourceview-3.0.0 **
>=x11-themes/gtk-engines-2.15.3 **
>=x11-themes/gtk-engines-murrine-0.98.2-r1 **
>=x11-themes/murrine-themes-0.98.0-r1 **
>=media-libs/libmatemixer-1.10.0 **
>=x11-apps/xmodmap-1.0.10 **
>=dev-libs/libmateweather-1.17.0 **
>=gnome-extra/gucharmap-3.0 **
>=net-wireless/wireless-tools-28_pre9 **
>=sys-power/cpupower-5.4 **
>=sys-apps/pciutils-3.7.0 **
>=gnome-extra/zenity-3.32.0 **
>=x11-apps/xdpyinfo-1.3.2-r1 **
>=app-editors/joe-4.6-r2 **
>=dev-libs/tvision-2.3.0 **
In the directory package.use

# required by sys-libs/readline-8.1::gentoo
# required by sys-apps/util-linux-2.36.1-r1::gentoo[readline]
# required by sys-fs/eudev-3.2.9::gentoo
# required by virtual/udev-217-r2::gentoo
# required by sys-apps/hwids-20201207::gentoo[udev]
>=sys-libs/ncurses-6.2-r1 unicode
# required by x11-libs/gtk+-3.24.29::gentoo
# required by mate-base/caja-1.24.0-r2::gentoo
# required by mate-extra/caja-extensions-1.24.1::gentoo
# required by mate-extra/caja-extensions (argument)
>=x11-libs/cairo-1.16.0-r4 X
# required by media-libs/mesa-21.1.1::gentoo
# required by media-libs/libepoxy-1.5.8::gentoo[egl]
# required by x11-libs/gtk+-3.24.29::gentoo
# required by mate-base/caja-1.24.0-r2::gentoo
# required by mate-extra/caja-extensions-1.24.1::gentoo
# required by mate-extra/caja-extensions (argument)
>=media-libs/libglvnd-1.3.3 X
# required by mate-base/caja-1.24.0-r2::gentoo
# required by mate-extra/caja-extensions-1.24.1::gentoo
# required by mate-extra/caja-extensions (argument)
>=gnome-base/gvfs-1.48.1 udisks
# required by app-text/atril-1.24.0-r2::gentoo
# required by mate-base/mate-1.24::gentoo[extras]
# required by mate-base/mate (argument)
>=app-text/poppler-21.05.0 cairo
# required by media-video/vlc-9999::gentoo
# required by vlc (argument)
>=sys-libs/zlib-1.2.11-r4 minizip
# required by sys-libs/pam-1.5.1::gentoo
# required by sys-auth/passwdqc-2.0.2::gentoo
>=sys-auth/elogind-246.10-r1 pam
# required by dev-qt/qtbase-6.8.1::gentoo[gui]
# required by app-crypt/gpgme-1.24.1::gentoo[qt6]
# required by app-portage/portage-utils-0.97::gentoo[qmanifest,-static]
# required by app-admin/perl-cleaner-2.31-r2::gentoo[-pkgcore]
# required by dev-lang/perl-5.40.0-r1::gentoo[-minimal]
# required by virtual/perl-Locale-Maketext-1.330.0-r1::gentoo
# required by dev-perl/Locale-Maketext-Lexicon-1.0.0-r1::gentoo
# required by media-gfx/graphite2-1.3.14_p20210810-r3::gentoo[perl]
# required by media-libs/harfbuzz-10.2.0::gentoo[graphite]
>=x11-libs/libxkbcommon-1.7.0-r1 X
Those were the ones I used in a year or two ago on another riscv board
They may need to be updated if you have issues

Select desktop profile

There is no stable profile for desktop so we will use the dev version

root #eselect profile set 29

Update system

This will take a while, perhaps a couple of days, it will emerge a lot of packages
Assigning more cores to chroot might help to speed things up. 
root #emerge -avuDN @world

Set time zone

root #ln -sf /usr/share/zoneinfo/America/Detroit /etc/localtime
root #date
mer 22 jan 2025 17:11:24 EST

install packages

root #emerge app-editors/joe
root #emerge dev-vcs/git subversion
root #emerge x11-base/xorg-drivers
root #rc-update add dbus default
root #emerge net-misc/dhcpcd
root #rc-update add dhcpcd default
root #emerge net-misc/openssh
root #rc-update add sshd default
root #emerge x11-misc/lightdm
root #emerge gui-libs/display-manager-init
root #emerge mate-base/mate
root #emerge vlc
root #emerge tvision

Set LightDM as the default display manager

FILE /etc/lightdm/lightdm.conf"
Set the session to mate
 user-session=mate

To have autologin add your user to the autologin line

autologin-user= _your_user_
FILE /etc/conf.d/display-manager
DISPLAYMANAGER="lightdm"
root #exit
Add and start the display manager only after you boot on the micro SD
The reason is that you will need to create a user first
root #rc-update add display-manager default

Compress rootfs

root #cd /usr/src/riscv64
root #rm -f /usr/src/riscv64/rootfs-riscv64/var/cache/distfiles/*
root #tar cvfz rootfs-riscv64-20250123.tar.gz rootfs-riscv64

Select riscv64 board

BeagleV-Fire board
BeagleV-Ahead board