Tiny Core Base > TCB Tips & Tricks

IBM ThinkPad 560Z Core Project Pentium II

<< < (2/3) > >>

CardealRusso:
On a related note...UUID and LABEL don't work with pretce or am I doing something wrong?

linic:
I haven't tried this boot code. Interestingly, I can't find any reference in the core book or in the forum, but it is documented in the wiki: http://wiki.tinycorelinux.net/doku.php?id=wiki:pretce
At one point it states "The format of this [boot code] entry will depend on the bootloader you are currently using."
I haven't seen examples of pretce with a UUID anywhere. I found the thread where gerald_clark posted that he created the wiki page (reply#3): http://forum.tinycorelinux.net/index.php/topic,16927.msg101433.html#msg101433
maybe you will have better chance of finding an answer or hints to it there.

CardealRusso:

--- Quote from: linic on August 20, 2023, 06:24:39 AM ---I can't find any reference in the core book

--- End quote ---
yes pretce doesn't have good documentation.
it seems like a maze to make it work, since the function find_mountpoint(), which is responsible for finding the disk through the UUID or LABEL sets the MOUNTPOINT variable instead of simply returning the mountpoint... And I assume that MOUNTPOINT is already, somehow, being used during pretce, which would be inconvenient to define it again.

https://github.com/tinycorelinux/Core-scripts/blob/783944e165d4a12ae4815b362261e95a3e39f44d/etc/init.d/tc-functions#L97

linic:
Rust on PII
There is a rust.tcz extension available tce-load -wi rust.tcz, but it it throws an illegal operation when trying rustc --version on my 560Z or on my 600X. The illegal operation comes from opcodes that do not exist on PII. The solution is to build the rust toolchain programs without the invalid opcodes.

Great thanks to Adam that wrote this article https://ww1.thecodecache.net/projects/p2-rust/. Without his help, I may not have reached this point.

You may have to adjust some settings or to install more packages than me. I may have missed some details that made this work on my machine. Hopefully, the steps here will be enough for you to find your way.

DISCLAIMER: I got close to building programs in rust on the 560Z, but I'm hitting the 64 MB of RAM memory limit when running "cargo run" or when having my custom "rust-1.71.1-pii.tcz" loaded automatically via "onboot.lst". I tried to load it manually with "tce-load -i rust-1.71.1-pii.tcz" after booting since I have a 3 GB swap partition and I got an out of memory error displayed in the terminal. Since the "tce-load" seemed to have done something, I tried "rustc --version" and "cargo --version" worked. Then, I tried "cargo new hello-world-3" which worked. then, "cd hello-world-3" and "cargo run". I saw the drive LED flash intensely. The build of a simple program like the default "Hello world!" that cargo gives you won't build with only 64 MB of RAM. I am not sure if it would work with 128 MB of RAM. The 560Z can be upgraded to that. I even saw 128 MB RAM dimms available and maybe that could bring the RAM to 196 MB, but I can't try it as I don't have those parts. Still, if you compile a rust program with the compiler built from the instructions here, the compiled programs will run on the 560Z. I built an "Hello World!" program on my 600X and it ran fine on the 560Z. Happy reading!

Setting Up a Build Environment
My build environment is an FX9590/a 2TB Samsung SATA SSD (iirc it's a QVO model)/32GB RAM(I don't think the RAM amount matters much as long as you have 8 GB, I think it should be fine)/Debian 11 x64. The time to compile is about 1 hour 45 minutes when I use the 8 cores.

I needed to install several packages:

--- Code: ---sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install build-essential cmake gcc gcc-multilib g++ g++-multilib git lib32z1 zlib1g-dev zlib1g-dev:i386 libssl-dev libssl-dev:i386 openssl curl ninja-build python3

--- End code ---
Note that I installed some dependencies twice. For example, zlib1g-dev zlib1g-dev:i386. The first is the x64 version and the last is the x86 version. When I only had the x64 version, the rust build would fail as it would search for the x86 which was not installed.


--- Code: ---git clone https://github.com/rust-lang/rust
cd rust
git checkout stable
git submodule update --init --recursive

--- End code ---
stable is at rust version 1.71.1 at time of writing.

Environment Variables

--- Code: ---export CFLAGS="-march=pentium"
export CXXFLAGS="-march=pentium"
export RUST_BACKTRACE=full

--- End code ---

config.toml and starting the build

--- Code: ---./configure --set build.extended=true --set build.build=i686-unknown-linux-gnu --set build.host=i586-unknown-linux-gnu --set build.target=i586-unknown-linux-gnu --set llvm.cflags="-lz -fcf-protection=none" --set llvm.cxxflags="-lz -fcf-protection=none" --set llvm.ldflags="-lz -fcf-protection=none" --set llvm.targets=X86 --set llvm.download-ci-llvm=false
./x.py check
PKG_CONFIG_ALLOW_CROSS=1 ./x.py dist -j 8 2>&1 | tee date-time-rust-i586-build-log.txt

--- End code ---
The x.py check is optional, but it may give you hints about missing dependencies before starting the full build. I use "-j 8" to use all my 8 CPU cores. You may use a smaller number than your max number of cores if you're doing something else while the build runs and you need some CPU time.
For some reason, I got an error that build.host=i586-unknown-linux-gnu and build.target=i586-unknown-linux-gnu were not of type sequence in the config.toml file. I opened it using vim config.toml and added brackets [ ] around the values to get to

--- Code: ---host = ['i586-unknown-linux-gnu']
target = ['i586-unknown-linux-gnu']

--- End code ---
there's probaly a way to change the ./configure arguments so that a sequence gets set in the config.toml correctly.

Once the build is complete, you should have several .tar.gz files at rust/build/dist. You want rust-1.71.1-dev-i586-unknown-linux-gnu.tar.gz. You can extract it using tar -xf and you should be able to see that cargo and rustc are there along several other files.

Reaching the Hello World on the 600X
I didn't have enough memory to run mksquasfs on the 560Z. I put my drive in my 600X to work around this. You'll need to have the compiled rust-1.71.1-dev-i586-unknown-linux-gnu.tar.gz available on an ftp on your local network or you'll need some other means of transferring it to the computer. In my case

--- Code: ---ftpget -v -u replace_with_your_ftp_user -p replace_with_your_ftp_user_password replace_with_your_IP-192.168.0.155 rust-1.71.1-dev-i586-unknown-linux-gnu.tar.gz
md5sum rust-1.71.1-dev-i586-unknown-linux-gnu.tar.gz
tar -xf rust-1.71.1-dev-i586-unknown-linux-gnu.tar.gz
mkdir rust-1.71.1-i586
mkdir rust-1.71.1-i586/etc
cd rust-1.71.1-dev-i586-unknown-linux-gnu
sudo sh ./install.sh --verbose --destdir=/home/tc/rust-1.71.1-i586 --sysconfdir=/home/tc/rust-1.71.1-i586/etc
tce-load -wi squashfs-tools.tcz
mksquashfs rust-tcz rust-1.71.1-pii.tcz
sudo cp -v rust-1.71.1-pii.tcz /mnt/sda2/tce/optional/
sudo vi /mnt/sda2/tce/onboot.lst # and add rust-1.71.0-pii.tcz
sudo reboot

--- End code ---
After the reboot, you should be able to run

--- Code: ---rustc --version
cargo --version
cargo new hello-world
cd hello-world
cargo run

--- End code ---
If you get an error that cc is missing install these

--- Code: ---tce-load -wi gcc.tcz
tce-load -wi glibc_base-dev.tcz

--- End code ---
because you need a C linker. Sites that helped me understand that: http://forum.tinycorelinux.net/index.php/topic,22216.msg139089.html#msg139089 and https://stackoverflow.com/questions/52445961/how-do-i-fix-the-rust-error-linker-cc-not-found-for-debian-on-windows-10

Rustlings on 600X
My plan was to make rustlings work on the 600X first and then move over to the 560Z. It didn't work, but read on to see where I got to. It might help you get further than me.

--- Code: ---tce-load -wi git.tcz
git clone -b 5.5.1 --depth 1 https://github.com/rust-lang/rustlings
cd rustlings
cargo install --force --path .

--- End code ---
At this point, I get

--- Code: ---failed to download from https://index.crates.io/config.json
Caused by:
[60] SSL peer certificate or SSH remote key was not OK (SSL certificate problem: unable to get local issuer certificate)

--- End code ---
So I went looking for the certificate chain with this command

--- Code: ---openssl s_client -debug -showcerts -connect index.crates.io:443

--- End code ---
My plan is to make a bas64 encoded .crt file of the certificates I see from that command and I should be able to put it somewhere in TC so that it gets trusted correctly. Interestingly, curl doesn't seem to mind the error when I try

--- Code: ---curl https://index.crates.io/config.json

--- End code ---
so it might just be cargo that is not looking at the right place... From the messages appearing at boot, I see that /usr/local/etc/ssl/certs seems to be the place where the trusted certificates get loaded. I'll try to find out more about how certificates get loaded. Another option is that cargo has its own trusted certificates...

I also tried

--- Code: ---curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh -o install.sh
sh install.sh

--- End code ---
but got an error that "rustup does not seem to be installed. Please download rustup using https://rustup.rs". That won't work because of the illegal operation issue.

Bonus
Fixing the clock

--- Code: ---sudo date -s "2023-09-03 11:32:15"
sudo hwclock -w

--- End code ---
This will work if you are in UTC. For other timezones, you may have to search to adjust those commands.

Avoid these Pitfalls
During my search, I tried things that didn't work. Read-on if you are interested.
1. DO NOT install gcc:i386 using apt. Or at least, carefully read what it is going to uninstall. I ended up uninstalling my desktop environment. Fortunately, I was able to reinstall everything on the stop using apt-get and didn't suffer any noticeable consequences.
2. DO NOT forget --set build.extended=true otherwise parts of the rust distribution will be missing. For me cargo and some standard packages were missing.
3. DO NOT use the other tar.gz files. They have install scripts, but they are missing enough files that you won't be able to create a new project or build. The best I got was a rustc that I couldn't do anything with except ask its version with rustc --version. At least it confirmed that the illegal operation was fixed.
4. DO NOT use export CFLAGS="-march=pentium2" or export CXXFLAGS="-march=pentium" and build.host=i686-unknown-linux-gnu and build.target=i686-unknown-linux-gnu. I understand (maybe wrongly so) that the Pentium II is a 686, but I got illegal operation errors building with a compiler built like this.

Thanks!
Again, great thanks to Adam that wrote this article https://ww1.thecodecache.net/projects/p2-rust/

Thanks for chapter 14 and 15 of the Core Book which helped me create my custom rust-1.71.1-pii.tcz extension.

Thanks to juanito for gcc.tcz (http://tinycorelinux.net/14.x/x86/tcz/gcc.tcz.info) and for glibc_base-dev.tcz (http://tinycorelinux.net/14.x/x86/tcz/glibc_base-dev.tcz.info)

This is it for now!

Rich:
Hi linic

--- Quote from: linic on September 04, 2023, 07:17:03 AM --- ... since I have a 3 GB swap partition and I got an out of memory error displayed in the terminal. ...
--- End quote ---
Just a few of points on swap:
1. If you need to rely on swap to run, your machine will likely slow down
   due to data constantly being shuffled between RAM and swap.

2. This will only work as long as there is something in RAM that the system
   can temporarily do without. If you reach a point where everything
   that's in RAM is still needed, no amount of swap will save you.

3. Some things can't be swapped, such as the kernel, drivers, and the initrd
   which is the RAM based section of the file system to name a few. That's
   why a persistent /home and /opt are good choices in these cases.

You can try freeing up more RAM with this boot code:

--- Code: ---nozswap
--- End code ---
If you look in  /etc/init.d/tc-config  you'll find the following:

--- Code: ---        grep MemFree /proc/meminfo | awk '{print $2/4 "K"}' > /sys/block/zram0/disksize

        mkswap /dev/zram0 >/dev/null 2>&1
--- End code ---
That's the system taking 1/4 of your free RAM and using it for swap space.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version