<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.iagent.no/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Refactor_v3.0.2</id>
	<title>Refactor v3.0.2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.iagent.no/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Refactor_v3.0.2"/>
	<link rel="alternate" type="text/html" href="https://wiki.iagent.no/mediawiki/index.php?title=Refactor_v3.0.2&amp;action=history"/>
	<updated>2026-05-28T15:52:19Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.iagent.no/mediawiki/index.php?title=Refactor_v3.0.2&amp;diff=388&amp;oldid=prev</id>
		<title>Elias: Created page with &quot;The latest images for Recore and Replicape are available from github: https://github.com/intelligent-agent/Refactor  These instructions are for version v3.0.2 and older  ====...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.iagent.no/mediawiki/index.php?title=Refactor_v3.0.2&amp;diff=388&amp;oldid=prev"/>
		<updated>2021-12-08T12:55:55Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;The latest images for Recore and Replicape are available from github: https://github.com/intelligent-agent/Refactor  These instructions are for version v3.0.2 and older  ====...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The latest images for Recore and Replicape are available from github: https://github.com/intelligent-agent/Refactor&lt;br /&gt;
&lt;br /&gt;
These instructions are for version v3.0.2 and older&lt;br /&gt;
&lt;br /&gt;
==== ReFactor is the next generation of controller board software stack installation. ====&lt;br /&gt;
&lt;br /&gt;
It is meant to simplify the lives of new users when they begin using a Thing-Printer controller board. Pre-built images of ReFactor are available for users who want to get up and running quickly with Replicape or Recore.&lt;br /&gt;
&lt;br /&gt;
ReFactor is available for Replicape and Recore, with updates being propagated simultaneously for both platforms.&lt;br /&gt;
&lt;br /&gt;
ReFactor uses [https://www.ansible.com/ Ansible] as the underlying framework to describe the desired system state. &lt;br /&gt;
There are many reasons for this:&lt;br /&gt;
&lt;br /&gt;
# Ansible describes the system's end state, not individual actions to perform, so it is relatively easy to port across platforms (i.e. debian, arch, BSD...)&lt;br /&gt;
# The ReFactor repository can be updated from the git repository and Ansible will only change what has been updated from the previous version, not needing a complete reinstallation of the system for upgrades.&lt;br /&gt;
# Description of components is modular, making it easy to pick and choose different components for the end goal desired, while keeping each component's setup independent and reliable, and independently updatable.&lt;br /&gt;
&lt;br /&gt;
== Why? ==&lt;br /&gt;
&lt;br /&gt;
The ultimate goal is to have multiple decliations of ReFactor, providing the user the ability to choose which firmware/software stack to run on their hardware. The following pre-build declinations are planned:&lt;br /&gt;
* '''OctoPrint, Klipper, Replicape'''&lt;br /&gt;
* '''OctoPrint, Klipper, Recore'''&lt;br /&gt;
* OctoPrint, Klipper, Toggle, Replicape&lt;br /&gt;
* OctoPrint, Klipper, Toggle, Recore&lt;br /&gt;
* Duet Web Control, Klipper, Replicape&lt;br /&gt;
* Duet Web Control, Klipper, Recore&lt;br /&gt;
* OctoPrint, Klipper, Raspberry Pi [1-3]&lt;br /&gt;
* OctoPrint, Klipper, Raspberry Pi 4 (arm64 edition)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''Only the options in bold''''' have been implemented so far, while the others are undergoing various steps in development in the order shown in this list.&lt;br /&gt;
The ReFactor images with OctoPrint are meant to provide drop-in replacements for the previous Umikaze images, including all the extra goodies that were present in Umikaze, like mjpg-streamer, SMB server, and usbreset for the main ones.&lt;br /&gt;
&lt;br /&gt;
The default login is ''root'' with password ''kamikaze''. The system will prompt for an immediate password change, to prevent a massive IoT exploitation through the web. Wouldn't want your printer sending out spam or starting to print unauthorized objects, now would we?&lt;br /&gt;
&lt;br /&gt;
== So how do I use it? ==&lt;br /&gt;
&lt;br /&gt;
ReFactor will be usable differently depending on what platform you're running it from.&lt;br /&gt;
&lt;br /&gt;
=== Replicape ===&lt;br /&gt;
&lt;br /&gt;
The Replicape images will be meant to run from the micro SD you flash it to. You cannot boot the Replicape from a USB key at this time.&lt;br /&gt;
By default, ReFactor images do not flash to the eMMC the way Umikaze used to. Part of this is historical - the early betas of ReFactor did not fit on the eMMC, but there's another advantage as well: it allows you to test out ReFactor on an SD card while keeping your working Redeem config on the eMMC.&lt;br /&gt;
&lt;br /&gt;
==== Booting Refactor from USB ====&lt;br /&gt;
If you want to boot Refactor from a USB stick, you need to stop u-boot by pressing space during boot. &lt;br /&gt;
You must run these commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
setenv bootpart 0:1; setenv oldroot /dev/sda1; setenv devnum 0; run usb_boot&lt;br /&gt;
&lt;br /&gt;
load ${devtype} ${bootpart} ${loadaddr} /boot/uEnv.txt; env import -t ${loadaddr} ${filesize}&lt;br /&gt;
&lt;br /&gt;
run uname_boot&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recore ===&lt;br /&gt;
The Recore images will need to be flashed to a USB flash drive, as there is no SD slot on the board. Recore's uboot is designed to attempt to boot from a USB drive if there is no OS on the eMMC. &lt;br /&gt;
&lt;br /&gt;
There are several stages to booting Recore, and depending on which media is installed, the boot process will &lt;br /&gt;
try and boot either from eMMC, USB host or USB device. &lt;br /&gt;
===Booting Recore from eMMC (the normal way)===&lt;br /&gt;
# Turn on power&lt;br /&gt;
# The BROM will load u-boot SPL from eMMC&lt;br /&gt;
# The u-boot SPL will load u-boot&lt;br /&gt;
# u-boot will load Linux&lt;br /&gt;
# Linux will load the rootfs from eMMC.&lt;br /&gt;
&lt;br /&gt;
===Booting Recore from eMMC, but load rootfs from USB===&lt;br /&gt;
&amp;lt;div class=&amp;quot;alert alert-warning&amp;quot;&amp;gt;&lt;br /&gt;
===='''Note'''====&lt;br /&gt;
Using a root file system on a different drive work well if the kernel version is the same on both media. &lt;br /&gt;
The kernel version has changed between Refactor v3.0.2-RC3 and v3.0.2-RC4. The board will still boot, but will not load &lt;br /&gt;
kernel modules as expected, including nft that maps OctoPrint to the HTTP port (80). &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the board is working normally and you are able to log in through ssh, but want to try out a new &lt;br /&gt;
Refactor version you can let the rootfs be loaded from a USB drive (mass storage device):&lt;br /&gt;
# Download Refactor and flash it to a USB drive&lt;br /&gt;
# Insert the USB drive in the board. &lt;br /&gt;
# Boot the board normally&lt;br /&gt;
# Use SSH to log into the board: '''ssh root@recore.local'''&lt;br /&gt;
# Edit the commandline:&lt;br /&gt;
## '''nano /boot/armbianEnv.txt'''&lt;br /&gt;
## Add this line: '''extraargs=root=/dev/sda1'''&lt;br /&gt;
## Note: Starting from Refactor v3.0.2-RC4, the root partition is &lt;br /&gt;
number 2, so then instead use '''extraargs=root=/dev/sda2'''&lt;br /&gt;
# Reboot&lt;br /&gt;
The board should now be have the rootfs from the USB drive.&lt;br /&gt;
&lt;br /&gt;
===Booting Recore from USB, load Linux kernel from USB drive===&lt;br /&gt;
This method requires a UART to USB adapter that can plug into a host computer. &lt;br /&gt;
There is a 4 pin header on Recore marked '''DBG''', where UART 0 is routed. All u-boot and kernel &lt;br /&gt;
messages will appear here.&lt;br /&gt;
If the eMMC is partitioned and has an OS, u-boot will launch right into that. In order to override that and &lt;br /&gt;
load the boot script from a USB drive, stop u-boot by pressing a key and then write:  &lt;br /&gt;
&lt;br /&gt;
# Download Refactor and flash it to a USB drive&lt;br /&gt;
# Insert the USB drive in the board and apply power&lt;br /&gt;
# When the boot process gets to u-boot, you will see: '''Hit any key to stop autoboot:  '''&lt;br /&gt;
# Hit the Any key. &lt;br /&gt;
# Then write '''run bootcmd_usb0'''&lt;br /&gt;
This will load the U-boot script from the USB drive and use the USB drive as the rootfs.&lt;br /&gt;
&lt;br /&gt;
===Boot Recore from a USB stick, eMMC is blank===&lt;br /&gt;
Recore should come pre-flashed with Refactor image on the eMMC. If the eMMC has been wiped for some reason&lt;br /&gt;
and you need to do everything from scratch, here are the instructions:&lt;br /&gt;
# Flash the ReFactor Linux distro to a USB drive. &lt;br /&gt;
# Insert the USB drive in the Recore board.&lt;br /&gt;
# Insert the Recore board in a host computer with the USB-C connector. &lt;br /&gt;
# If the eMMC is blank or the &amp;quot;FEL&amp;quot; button is pressed, the board will go into bootloader mode. &lt;br /&gt;
# Upload SPL, EL3 and u-boot through the USB port:&lt;br /&gt;
## Download the Recore repository https://github.com/intelligent-agent/Recore&lt;br /&gt;
## Install the sunxi-tools program&lt;br /&gt;
## Run '''make fel'''&lt;br /&gt;
# The board will boot using the USB drive. &lt;br /&gt;
# Copy the contents of the USB drive into the eMMC/Internal flash.&lt;br /&gt;
You can read more about the steps needed to boot aboard in FEL mode on the Sunxi wiki: https://linux-sunxi.org/FEL&lt;br /&gt;
&lt;br /&gt;
===AR100 firmware===&lt;br /&gt;
The ar100 has a binary file that is loaded on startup by klipper.service&lt;br /&gt;
The binary file comes pre-compiled in Refactor, but can be recompiled on Recore (or on a host computer).&lt;br /&gt;
&lt;br /&gt;
====Cross compilation toolchain for ARM64====&lt;br /&gt;
The AR100 needs a cross compilation toolchain. For ARM64, it can be downloaded from feeds.iagent.no:&lt;br /&gt;
&lt;br /&gt;
http://feeds.iagent.no/toolchains/  &lt;br /&gt;
&lt;br /&gt;
The toolchain has been built with  &lt;br /&gt;
&lt;br /&gt;
https://github.com/richfelker/musl-cross-make&lt;br /&gt;
&lt;br /&gt;
GCC version: 9.2.0&lt;br /&gt;
&lt;br /&gt;
====Cross compilation toolchain for x86_64====&lt;br /&gt;
The toolchain used during automatic testing and is the same used for the CRUST firmware project: &lt;br /&gt;
&lt;br /&gt;
https://github.com/crust-firmware/crust#building-the-firmware&lt;br /&gt;
&lt;br /&gt;
====Compiling the ar100 binary====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://feeds.iagent.no/toolchains/or1k-linux-musl.tar.xz&lt;br /&gt;
tar xf or1k-linux-musl.tar.xz&lt;br /&gt;
export PATH=$PATH:/opt/output/bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To configure klipper for AR100 and build the binary:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /home/debian/klipper/&lt;br /&gt;
cp test/configs/ar100.config .config&lt;br /&gt;
make olddefconfig&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will produce a bin file located in out/ar100.bin, so it should be moved to /op/firmware&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mv out/ar100.bin /opt/firmware/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the same operation that happens from the klipper.service script, so it can also be done by running &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl restart klipper&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====STM32 firmware====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;alert alert-warning&amp;quot;&amp;gt;&lt;br /&gt;
===='''Note'''====&lt;br /&gt;
The latest Refactor now does automatic flashing of the STM32 firmware on first boot after a fresh install. This was merged with PR#199 in Refactor on Github. &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The firmware for the stm32f031 mcu that is responsible for ADC &lt;br /&gt;
conversions and PWM for heaters and fans comes pre-installed in the flash of the MCU. &lt;br /&gt;
It can be recreated on the board using the Klipper build system.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /home/debian/klipper&lt;br /&gt;
cp test/configs/stm32f031.config .config&lt;br /&gt;
make menuconfig&lt;br /&gt;
-&amp;gt; Enable extra low-level configuration options&lt;br /&gt;
-&amp;gt; Clock Reference internal&lt;br /&gt;
-&amp;gt; Communication interface (Serial (on USART2 PA15/PA14))&lt;br /&gt;
-&amp;gt; Baud rate for serial port: 38400&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Flashing STM32 firmware====&lt;br /&gt;
To flash the STM32 firmware:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl stop klipper&lt;br /&gt;
make recoreflash FLASH_DEVICE=/dev/ttyS4&lt;br /&gt;
systemctl start klipper&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Flashing ReFactor from a USB drive===&lt;br /&gt;
Get the latest ReFactor image from here: https://github.com/intelligent-agent/ReFactor/releases&lt;br /&gt;
for example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://github.com/intelligent-agent/Refactor/releases/download/v3.0.0/Refactor-recore-v3.0.0-2021-08-06.img.xz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Assuming you have managed to boot Recore from a USB flash drive and you have the ReFactor image available in the same folder, you can &lt;br /&gt;
use dd to do a direct transfer of the image from the USB drive to eMMC. On Replicape / BeagleBone this will be /dev/mmcblk1&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
xz -v -d -c Refactor-recore-v3.0.0-2021-08-06.img.xz  | dd of=/dev/mmcblk0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upgrading Refactor from the command line ===&lt;br /&gt;
Refactor has been set up using Ansible, so it should be possible to use the same setup to update Refactor after it has been installed. &lt;br /&gt;
&lt;br /&gt;
WORK IN PROGRESS:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /usr/src/&lt;br /&gt;
git clone https://github.com/intelligent-agent/Refactor.git&lt;br /&gt;
cd Refactor&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running Klipper===&lt;br /&gt;
While details are ironed out there is a script that can be used to restart Klipper that will handle &lt;br /&gt;
resetting things and setting up the steppers etc. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl restart klipper&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running OctoPrint===&lt;br /&gt;
OctoPrint should start and run on boot, but if there is a need to restart the daemon, use this command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
systemctl restart octoprint&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Update u-boot on Recore===&lt;br /&gt;
Place u-boot-sunxi-with-spl.bin in sector 15 (8KB offset)  &lt;br /&gt;
Clean 1M of the eMMC:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dd if=/dev/zero of=/dev/mmcblk0 bs=1k count=1023 seek=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Flash the binary &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8 conv=notrunc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: U-boot needs to be patched in order to use the eMMC as the first (and only) boot device. &lt;br /&gt;
The changes can be done in &amp;quot;spl_mmc_get_device_index&amp;quot; where dev_num should be 0 instead of 1.&lt;br /&gt;
&lt;br /&gt;
== Building a runnable image for Replicape ==&lt;br /&gt;
&lt;br /&gt;
The [[Replicape_Rev_B | Replicape]] runs on a Beaglebone black (or green, without video output), which has a single core ARM processor running at 1GHz with 512MB of RAM. While impressive for an embedded application, it's rather weak when trying to build a system, which can take a lot of time.&lt;br /&gt;
&lt;br /&gt;
There's a significant time gain when building the image from a more powerful host system, then flashing it to memory from an SD card.&lt;br /&gt;
&lt;br /&gt;
The host system can be any ARM v7 or above architecture machine. In this example, the Raspberry Pi 4 will be used as an example, as it has a quad-core arm64 1.5GHz processor with 1 to 4GB of RAM. Any standard linux platform will do, but you will need a build storage space of at least 5GB for the build to succeed. Using a fast SD or a USB3 flash drive can provide higher disk speeds, reducing build time significantly.&lt;br /&gt;
&lt;br /&gt;
To build an image from ReFactor for the Replicape, follow these steps:&lt;br /&gt;
# Browse to a folder on the pi where you wish to run the build&lt;br /&gt;
# Clone the [https://github.com/goeland86/ReFactor git repository] for ReFactor&lt;br /&gt;
# In the ReFactor folder, run the build-image-in-chroot-end-to-end.sh script. It may take some time, so you may want to consider using a screen or byobu session to protect against network drops if you're doing so through SSH.&lt;br /&gt;
# If the build completes successfully, you should be left with a file 'Umikaze-console.img.xz'&lt;br /&gt;
# Use etcher to write the .img.xz file to a micro SD card, insert it into the Beaglebone, power it up and wait for it to power down.&lt;br /&gt;
# Start using the ReFactor image on your printer&lt;br /&gt;
&lt;br /&gt;
== Installing a custom software stack with ReFactor from a base Debian image ==&lt;br /&gt;
&lt;br /&gt;
At the moment ReFactor only supports using a debian-based distribution as a basis. Further down the line it will be refactored so that many more packaging systems are supported - this is not an Ansible limitation, but rather simply a developer time limitation.&lt;br /&gt;
&lt;br /&gt;
The goal for ReFactor is to allow the end-user to choose a custom software stack, while making installation of those packages easier. In this case, the user will want to learn how to write a simple Ansible playbook - there are multiple examples available in the ReFactor base folder (build_full_klipper_octoprint.yml, install_klipper.yml, any yml file really).&lt;br /&gt;
&lt;br /&gt;
The files starting with &amp;quot;build_full_&amp;quot; are meant to be used for the image building described in the previous section. The files starting with &amp;quot;install_&amp;quot; are designed to be run on a printer platform exclusively - not on a host system.&lt;br /&gt;
&lt;br /&gt;
Each install_ file will install a specific component with its required dependencies. For instance, if you with install toggle, it will also install the Beaglebone's graphics drivers, required for video output, along with a number of libraries that Toggle is reliant on (such as a custom-built libclutter using the framebuffer output instead of the X11 driver).&lt;br /&gt;
&lt;br /&gt;
To install a specific component, make sure that you have installed ansible. Alternatively you can just run the prep_ubuntu.sh script - the only thing it does is make sure that Ansible is ready to execute any further tasks required.&lt;br /&gt;
&lt;br /&gt;
Once Ansible is installed, just run &amp;quot;ansible-playbook install_klipper.yml&amp;quot; for example. Let it run and it will go through to make sure everything is available upon the next reboot.&lt;br /&gt;
&lt;br /&gt;
After all packages have been installed as desired, reboot the system. A reboot is necessary, as depending on the software installed, kernel modules may be enabled / disabled, kernel versions may have changed etc. These are unfortunately not changes that can be done without a reboot.&lt;/div&gt;</summary>
		<author><name>Elias</name></author>
		
	</entry>
</feed>