Stephen Smith's Blog

Musings on Machine Learning…

Risc-V Assembly Language Hello World

leave a comment »

Introduction

Last time, we started talking about the Risc-V CPU. We looked at some background and now we are going to start to look at its Assembly Language. We’ll write a program to print “Hello World!” to the terminal window, cross-compile it with GCC and run it in a Risc-V emulator. This program lets us start discussing some features of the core Risc-V instruction set. Risc-V supports 32-bit, 64-bit or 128-bit implementations, here we’ll run using 64-bits.

We’ll start with the program, then discuss various aspects of the Assembly instructions it uses and finally discuss how to build and run the program.

Hello World

First let’s present the program and then we’ll discuss it. This program works by making Linux system calls and like all Linux programs starts execution at the globally exported _start label. The program uses the Assembly directives specified in the GCC documentation.

#
# Risc-V Assembler program to print "Hello World!"
# to stdout.
#
# a0-a2 - parameters to linux function services
# a7 - linux function number
#

.global _start      # Provide program starting address to linker

# Setup the parameters to print hello world
# and then call Linux to do it.

_start: addi  a0, x0, 1      # 1 = StdOut
        la    a1, helloworld # load address of helloworld
        addi  a2, x0, 13     # length of our string
        addi  a7, x0, 64     # linux write system call
        ecall                # Call linux to output the string

# Setup the parameters to exit the program
# and then call Linux to do it.

        addi    a0, x0, 0   # Use 0 return code
        addi    a7, x0, 93  # Service command code 93 terminates
        ecall               # Call linux to terminate the program

.data
helloworld:      .ascii "Hello World!\n"

The ‘#’ character is the comment character and anything after it on a line is a comment.

Registers

The Risc-V processor has 32 registers labeled x0 to x31 and a program counter (PC). x0 is a zero register, and x1-x31 can be used by programs as they wish. If you look at our listing for Hello World, you will notice that we are using registers a0, a1, a2 and a7. What are these? Since the Risc-V architecture provides no standards for register usage, and typical Assembly language programming requires a stack pointer, subroutine return register and some sort of function calling convention, these are defined in an Application Binary Interface (ABI). This is a software standard that the operating system defines so that programs and libraries can work together properly. Here GCC knows about the Risc-V Linux ABI where register usage is defined as:

 

Register ABI Use by convention Preserved?
x0 zero hardwired to 0, ignores writes n/a
x1 ra return address for jumps no
x2 sp stack pointer yes
x3 gp global pointer n/a
x4 tp thread pointer n/a
x5 t0 temporary register 0 no
x6 t1 temporary register 1 no
x7 t2 temporary register 2 no
x8 s0 or fp saved register 0 or frame pointer yes
x9 s1 saved register 1 yes
x10 a0 return value or function argument 0 no
x11 a1 return value or function argument 1 no
x12 a2 function argument 2 no
x13 a3 function argument 3 no
x14 a4 function argument 4 no
x15 a5 function argument 5 no
x16 a6 function argument 6 no
x17 a7 function argument 7 no
x18 s2 saved register 2 yes
x19 s3 saved register 3 yes
x20 s4 saved register 4 yes
x21 s5 saved register 5 yes
x22 s6 saved register 6 yes
x23 s7 saved register 7 yes
x24 s8 saved register 8 yes
x25 s9 saved register 9 yes
x26 s10 saved register 10 yes
x27 s11 saved register 11 yes
x28 t3 temporary register 3 no
x29 t4 temporary register 4 no
x30 t5 temporary register 5 no
x31 t6 temporary register 6 no
pc (none) program counter n/a

 

Which was taken from here. A0 to a7 are the registers used to pass function parameters (arguments), and a7 is used for Linux system calls where you specify the Linux function number from unistd.h.

Instructions

We only use three Assembly instructions in this program: LA, ADDI and ECALL. Risc-V works hard to define as few instructions as possible. As a result some instructions have multiple uses. For instance ADDI is add an intermediate to a register, which is of the form:

      ADDI RD, RS, imm

Where RD is the destination register, RS the source register and imm is a 12-bit immediate value. Instructions are 32-bits in length so the size of the immediate value tends to be whatever is leftover after setting the opcode and any required registers.

You can define a NOP instruction with:

      ADDI x0, x0, 0

Or load immediate with:

      ADDI RD, X0, imm

The Assembler will take opcodes like NOP or LI (Load Immediate) and translate them into the correct underlying instruction. Here we used ADDI, but when we decompile the compiled program we’ll see the decompiler uses these aliases. These do make your program more readable. All our ADDI instructions use the LI pattern.

Risc-V provides a separate opcode to call the operating system. This is the ECALL instruction. When calling Linux, A7 is the Linux service number and A0 to A6 contain any parameters. When calling write, we need the file descriptor (1 for stdout), the string to write and the length in bytes to write, which we put in registers A0, A1 and A2. The return code which we don’t check will be in A0. This differs from most other architectures that use the interrupt mechanism for this purpose. The Risc-V designers feel it is cleaner to separate operating system calls from interrupts, even though both cause kernel privileged instructions to execute.

The remaining instruction is LA, which isn’t a Risc-V instruction, but rather it tells the Assembler that we want to load an address into a register. Then we leave it up to the Assembler to figure out how to do this. If we are running with 64-bit addressing then this address will be 64-bits. We can’t load this with a single load immediate instruction since the biggest immediate value is 20-bits, with most smaller. This means to load the address we either need to do many instructions to load this address piece by piece using load immediates, shifts, logical operations and/or arithmetic operations. The Assembler has inside knowledge of the value of this address, so it can, say use PC relative addressing to load this address. There are a lot of tricks to deal with 64-bit values from 32-bit instructions, that we don’t have room to go into now, but perhaps in a future blog article.

Building

I don’t have a Risc-V processor, so I built the program using cross-compilation. The instructions on installing the GCC tools for this on a Debian based Linux are here. Then to build you run:

riscv64-linux-gnu-as -march=rv64imac -o HelloWorld.o HelloWorld.s
riscv64-linux-gnu-ld -o HelloWorld HelloWorld.o

We can run a Risc-V objdump to see what was produced with:

riscv64-linux-gnu-objdump -d HelloWorld

And get:

HelloWorld:     file format elf64-littleriscv

Disassembly of section .text:

00000000000100b0 <_start>:
   100b0: 00100513           li a0,1
   100b4: 00001597           auipc a1,0x1
   100b8: 02058593           addi a1,a1,32 # 110d4 <__DATA_BEGIN__>
   100bc: 00d00613           li a2,13
   100c0: 04000893           li a7,64
   100c4: 00000073           ecall
   100c8: 00000513           li a0,0
   100cc: 05d00893           li a7,93
   100d0: 00000073           ecall

We see it has interpreted the ADDI instructions that are just loading an immediate as LI. 

The “LA a1, helloworld” directive has been compiled to:

   100b4: 00001597           auipc a1,0x1
   100b8: 02058593           addi a1,a1,32 # 110d4 <__DATA_BEGIN__>

AUIPC is add immediate to PC, so it put PC+1 into A1 then the ADDI adds the offset to the beginning of the data section. Actually the Assembler set these as needing relocation and then the constants were filled in by the linker in the LD command. The good thing is that the Assembler and Linker took care of these details so we didn’t need to. Loading addresses and large integers is always a challenge in RISC processors.

Running

Now I have our HelloWorld executable on my Intel i3 laptop running Ubuntu Linux. To run it, I use the TinyEMU Risc-V emulator. There are instructions on running a mini version of Linux under the emulator, you can then mount your /tmp folder and copy the executable over. Then it runs.

The whole process is:

stephen@stephenubuntu:~/riscV/HelloWorld$ bash -x ./build
+ riscv64-linux-gnu-as -march=rv64imac -o HelloWorld.o HelloWorld.s
+ riscv64-linux-gnu-ld -o HelloWorld HelloWorld.o
stephen@stephenubuntu:~/riscV/HelloWorld$ cp HelloWorld /tmp
stephen@stephenubuntu:~/riscV/HelloWorld$ cd ../../Downloads/diskimage-linux-riscv-2018-09-23/
stephen@stephenubuntu:~/Downloads/diskimage-linux-riscv-2018-09-23$ temu root_9p-riscv64.cfg 
[    0.307640] NET: Registered protocol family 17
[    0.308079] 9pnet: Installing 9P2000 support
[    0.311914] EXT4-fs (vda): couldn't mount as ext3 due to feature incompatibilities
[    0.312757] EXT4-fs (vda): mounting ext2 file system using the ext4 subsystem
[    0.325269] EXT4-fs (vda): mounted filesystem without journal. Opts: (null)
[    0.325552] VFS: Mounted root (ext2 filesystem) on device 254:0.
[    0.326420] devtmpfs: mounted
[    0.326785] Freeing unused kernel memory: 80K
[    0.326949] This architecture does not have kernel memory protection.
~ # mount -t 9p /dev/root /mnt
~ # cp /mnt/HelloWorld .
~ # ./HelloWorld 
Hello World!
~ # 

Note: I had to add:

      kernel: "kernel-riscv64.bin",

To root_9p-riscv64.cfg in order for it to start properly.

Summary

This simple Hello World program showed us a basic Risc-V Assembly Language program that loads some registers and calls Linux to print a string and then exit. This was still a long blog posting since we needed to explain all the Assembly elements and then how to build and run the program without requiring any Risc-V hardware.

Advertisements

Written by smist08

September 7, 2019 at 10:38 pm

Posted in RiscV

Tagged with , , , ,

Introducing Risc-V

with one comment

Introduction

Risc-V (pronounced Risc Five) is an open source hardware Instruction Set Architecture (ISA) for Reduced Instruction Set Computers (RISC) developed by UC Berkeley. The Five is because this is Berkeley’s fifth RISC ISA design. This is a fully open standard, meaning that any chip manufacturer can create CPUs that use this instruction set without having to pay royalties. Currently the lion’s share of the CPU market is dominated by two camps, one is the CISC based x86 architecture from Intel with AMD as an alternate source, the other is the ARM camp where the designs come from ARM Holdings and then chip manufacturers can license the designs with royalty agreements.

The x86 architecture dominates server, workstation and laptop computers. These are quite powerful CPUs, but at the expense of using more power. The ARM architecture dominates cell phones, tables and Single Board Computers (SBCs) like the Raspberry Pi, these are usually a bit less powerful, but use far less power and are typically much cheaper.

Why do we need a third camp? What are the advantages and what are some of the features of Risc-V? This blog article will start to explore the Risc-V architecture and why people are excited about it.

Economies of Scale

The computer hardware business is competitive. For instance Western Digital harddrives each contain an ARM CPU to manage the controller functions and handle the caching. Saving a few dollars for each drive by saving the ARM royalty is a big deal. With Risc-V, Western Digital can make or buy a specialized Risc-V processor and then save the ARM royalty, either improving their profits or making their drives more price competitive.

The difficulty with introducing a new CPU architecture is to be price competitive you have to manufacture in huge quantities or your product will be very expensive. This means for there to be inexpensive Risc-V processors on the market, there has to be some large orders and that’s why adoption by large companies like Western Digital is so important.

Another giant boost to the Risc-V world is a direct result of Trump’s trade was with China. With the US restricting trade in ARM and x86 technology to China, Chinese computer manufacturers are madly investing in Risc-V, since it is open source and trade restrictions can’t be applied. If a major Chinese cell phone manufacturer can no longer get access to the latest ARM chips, then switching to Risc-V will be attractive. This is a big risk that Trump is taking, because if the rest of the world invests in Risc-V, then it might greatly reduce Intel, AMD and ARM’s influence and leadership, having the opposite effect to what Trump wants.

The Software Chicken & Egg Problem

If you create a wonderful new CPU, no matter how good it is, you still need software. At a start you need operating systems, compilers and debuggers. Developing these can be as expensive as developing the CPU chip itself. This is where open source comes to the rescue. UC Berkeley along with many other contributors added Risc-V support to the GNU Compiler Collection (GCC) and worked with Debian Linux to produce a Risc-V version of Linux.

Another big help is the availability of open source emulator technology. You are very limited in your choices of actual Risc-V hardware right now, but you can easily set up an emulator to play with. If you’ve ever played with RetroPie, you know the open source world can emulate pretty much any computer ever made. There are several emulator environments available for Risc-V so you can get going on learning the architecture and writing software as the hardware slowly starts to emerge.

Risc-V Basics

The Risc-V architecture is modular, where you start with a core simple arithmetic unit that can load/store registers, add, subtract, perform logical operations, compare and branch. There are 32 registers labeled x0 to x31. However x0 is a dedicated zero register. There is also a program counter (PC). The hardware doesn’t specify any other functionality to the registers, the rest is by software convention, such as which register is the stack pointer, which registers are used for passing function parameters, etc. Base instructions are 32-bits, but an extension module allows for 16-bit compressed instructions and extension modules can define longer instructions. The specification supports three different address sizes: 32-bit, 64-bit and 128-bit. This is quite forward thinking as we don’t expect the largest most powerful computer in the world to exceed 64-bits until 2030 or so.

Then you start adding modules like the multiply/divide module, atomic instruction module, various floating point modules, the compressed instruction module, and quite a few others. Some of these have their specifications frozen, others are still being worked on. The goal is to allow chip manufacturers to produce silicon that exactly meets their needs and keeps power utilization to a minimum.

Getting Started

Most of the current Risc-V hardware available for DIYers are small low power/low memory microcontrollers similar to Arduinos. I’m more interested in getting a Risc-V SBC similar to a Raspberry Pi or NVidia Jetson. As a result I don’t have a physical Risc-V computer to play with, but can still learn about Risc-V and play with Risc-V Assembly language programming in an emulator environment.

I’ll list the resources I found useful and the environment I’m using. Then in future blog articles, I’ll go into more detail.

  • The Risc-V Specifications. These are the documents on the ISA. I found them readable, and they give the rationale for the decisions they took along with the reasons for a number of roads they didn’t go down. The only thing missing are practical examples.
  • The Debian Risc-V Wiki Page. There is a lot of useful information here.  A very big help was how to install the Risc-V cross compilation tools on any Debian release. I used these instructions to install the Risc-V GCC tools on my Ubuntu laptop.
  • TinyEMU, a Risc-V Emulator. There are several Risc-V emulators, this is the first one I tried and its worked fine for me so far.
  • RV8 a Risc-V Emulator. This emulator looks good, but I haven’t had time to try it out yet. They have a good Risc-V instruction set summary.
  • SiFive Hardware. SiFive have produced a number of limited run Risc-V microcontrollers. Their website has lots of useful information and their employees are major contributors to various Risc-V open source projects. They have started a Risc-V Assembly Programmers Guide.

Summary

The Risc-V architecture is very interesting. It is always nice to start with a clean slate and learn from all that has gone before it. If this ISA gains enough steam to achieve volumes where it can compete with ARM, it is going to allow very powerful low cost computers. I’m very hopeful that perhaps next year we’ll see a $25 Risc-V based Raspberry Pi 4B competitor with 4Gig RAM and an M.2 SSD slot.

Written by smist08

September 6, 2019 at 6:07 pm

Posted in Business

Tagged with , , , ,

Raspberry Pi 4 as a Desktop Computer

leave a comment »

Introduction

The Raspberry Pi Foundation is promoting the Raspberry Pi 4 as a full desktop computer for only $35. I’ve had my Raspberry Pi 4 for about a month now and in this article we’ll discuss if it really is a full desktop computer replacement. This partly depends on what you use your desktop computer for. My answer is that the $35 price is misleading, you need to add quite a few other things to make it work well.

Making the Raspberry Pi 4 into a Decent Desktop

The Raspberry Pi has always been a barebones computer. You’ve always needed to add a case, a keyboard, a mouse, a monitor, a power supply, a video cable and a microSD card. Many people already have these kicking around, so they don’t need to buy them when they get their Pi. For instance, I already had a keyboard and monitor. The Raspberry Pi 4 even supports two monitors.

Beyond the bare bones, you need two more things for a decent desktop, namely:

  1. The 4GB version of the Raspberry Pi 4
  2. A good USB SSD drive

With these, it starts to feel like you are playing with a regular desktop computer. You now have enough RAM to run multiple programs and any good SSD will greatly enhance the performance of thee system, only using the microSD card to boot the Pi.

The Raspberry Pi 3 is a great little computer. Its main limitation is that if you run too many programs or open too many browser tabs, it bogs down and you have a painful process of closing windows (that aren’t responding well), until things pick up again. Now the Raspberry Pi 4 with 4GB of RAM really opens up the number of things you can do at once. Running multiple browser tabs, LibreOffice and a programming IDE are no problem.

The next thing you run into with the Raspberry Pi 4 is the performance of the SD card. Since I needed a video cable and a new case, I ordered a package deal that also included a microSD card containing Raspbian. Sadly, these bundled microSD cards are the cheapest, and hence slowest available. Having Raspbian bundled on a slow card is just a waste. Switching to a Sandisk Extreme 64GB made a huge difference. The speed was much better. When buying a microSD card watch the speed ratings, often the bigger cards (64GB or better) are twice as fast as the smaller cards (32GB or less). With a good microSD card the Raspberry Pi 4 can read and write microSD twice as fast as a Raspberry Pi 3.

I’ve never felt I could truly trust running off a microSD card. I’ve never had one fail, but people report problems all the time. Further, the performance of microSD cards is only a fraction of what you can get from good SSDs. The Raspberry Pi 4 comes with two USB 3 ports which have a theoretical performance ten times that of the microSD port. If you shop around you will find M.2 and SATA SSDs for prices less than those of microSD cards. I purchased a Kingston A1000 M.2 drive which was on sale cheap because the A2000 cards just started shipping. I had to get an M.2 USB caddy to contain it, but combined this was less than $100 and USB caddies are always useful.

Unfortunately, you can’t boot the Raspberry Pi 4 directly off a USB port yet. The Raspberry Pi foundation say this is coming, but not quite here yet. What you can do is have the entire root file system on the USB drive, but the boot partition must be on a microSD card. Setting up the SSD was easier than I thought it would be. I had to partition it, format it, copy everything over to the SSD and then edit /boot/config.txt to say where the root of the main file system is.

With this done, I feel like I’m using a real desktop computer. I’m confident my data is being stored reliably, the performance is great.

Overheating

The Raspberry Pi 4 uses more power than previous Pis. This means there is more heat to dissipate. The case I received with my Pi 4 didn’t have any ventilation holes and would get quite hot. I solved the problem by removing the top of the case. This let enough heat out that I could run fine for most things. People report that when using a USB SSD that the USB controller chip will overheat and the data throughput will be throttled. I haven’t run into this, but it is something to be aware of.

I installed Tensorflow, Google’s open source AI toolkit. Training a data model with Tensorflow does make my Pi 4 overheat. I suspect Tensorflow is keeping all four CPU cores busy and producing a maximum amount of heat. This might drive me to add a cooling fan. I like the way the Pi runs so quietly, with no fan, it makes no noise. I might try using a small fan blowing down on the Pi to see is that helps.

Summary

Is the Raspberry Pi 4 a complete desktop computer for $35? No. But if you get the 4GB model for $55 and then add a USB 3 SSD, then you do have a good workable desktop computer. The CPU power of the Pi has been compared to a typical 2012 desktop computer. But for the cost that is pretty good. I suspect the Wifi/Lan and SSD are quite a bit better than that 2012 computer.

Keep in mind the Raspberry Pi runs Linux, which isn’t for everyone. A typical low cost Windows desktop goes for around $500 these days. You can get a refurbished one for $200-$300. A refurbished desktop can be a good inexpensive option.

I like the Raspberry Pi, partly because you are cleanly out of the WinTel world. No Windows, no Intel. The processor is ARM and the operating system is Raspbian based on Debian Linux. A lot of things you do are DIY, but I enjoy that. With over 25 million Raspberry Pis sold worldwide, there is a lot of community support and you join quite an enthusiastic thriving group.

Written by smist08

August 26, 2019 at 8:17 pm

Playing the Kaggle Two Sigma Challenge 2018/2019

leave a comment »

 

Introduction

A couple of years ago, I entered a Kaggle data science competition sponsored by Two Sigma for stock market prediction. I blogged about this in part 1, part 2, part 3, part 4 and part 5. The upshot of this was that although I put in a lot of work, I performed quite poorly in the final stages. I learned a lot about machine learning and data science along the way and was keen to have another go, when another Two Sigma sponsored competition rolled around starting last year.

In this competition we had three months to create our models in the fall of 2018, then they used our models to predict the stock market through the first half of 2019. With my learnings from the last competition, I was able to do much better this time around.

Don’t Overfit

My big lesson from the first competition was to not overfit the model to the training data. This is equivalent to having ten data points and fitting them perfectly with a 9th degree polynomial. There is no error in predicting the ten points, but the model is useless at predicting anything else, and in fact gives about the worst predictions possible.

A more subtle form of overfitting is trying hundreds of models and fiddling with their parameters until they work really well with the training data. This is a lot of work and won’t help you on any data outside of the training data. I did this for the first competition, it was a lot of work, and it performed badly.

Avoiding overfitting means doing less work, which is good. I spent very little time on this competition and got quite good results.

Kaggle Virtual Environment

One of the things I like about this competition is that you play it in Google/Kaggle’s virtual environment. You have a fixed set of computer resources and everyone plays in the same environment. This levels the playing field with people who have access to very high powered equipment at corporations or Universities. This year the environment included a GPU and we could run for six hours on a high powered server.

This does limit the models you can use, I wasn’t successful at using a neural networks, probably because historical stock market data is very flat and it is hard to get these models to converge. I ended up using an Extra Trees model in SciKit Learn.

Make the Program Robust

Usually in this sort of competition, when you run your model, behind the scenes Kaggle runs it on the secret test data as well, so if you run successfully on the provided test data, you know you also run on the secret data you are going to be scored against. In this case the secret test data didn’t exist yet. This led to the worry that sometime in the six months that they would be running our program, something unexpected would appear in the data and cause my program to crash, knocking me out of the competition.

I was careful to put in try/catch statements and added extra checks to try and keep my program running. The other thing with Python programs, is that sometimes they work, but throw a memory exception when they shutdown. I spent some time tracking down a number of these bugs and made sure my program could exit gracefully without any errors.

From the message board for the competition, it appears quite a few competitors were knocked out during the run on the new data.

Don’t Cheat

Some people spend all their time trying to cheat. Trying to hack the system to gain access to the secret test data. For the purposes of the leaderboard, there was secret test data to give people a score during the model building phase, but this data wouldn’t be used in the real competition. There was no real protection on this data, since using it to cheat would be useless. However quite a few people did cheat to move to the top of the leaderboard before the real competition started. These programs crashed when the real competition started.

There are rumours that people have succeeded in other Kaggle competitions by cheating, but in this one, since it was based on stock market data generated after the models were frozen, it wasn’t going to work.

My Model

The intent of the competition was to try to use news data to enhance your stock prediction algorithm. I don’t think this worked well, I used an Extra Trees variation on a Random Forest, and the news data never seemed to contribute much. Many other competitors didn’t even use it. The competition metric was a Sharpe Ratio. A couple of observations about the Sharpe Ratio, one is that it has the standard deviation of the estimates in the denominator. This means volatile stocks will hurt you even if you predict them accurately. Second, you enter a confidence value on whether you think the stock will do well and this confidence can be negative if you think it will go down. If you get the sign wrong it will doubly hurt you.

Given the Sharpe Ratio as the metric, I decided to sort the stocks by standard deviation of their returns and then rate any with a high standard deviation as zero, which would exclude them from the model. This meant I was building a portfolio of a subset of all the stocks present. I wanted stocks I could predict accurately and that had a lower volatility.

In reading the discussion board after the competition, it appears many of the top performers took this approach.

Summary

I enjoyed this competition. I liked working with the high powered servers in the competition’s virtual environment. The lesson learned to not overfit, greatly reduced the amount of work. Whenever I was tempted to tune my model, I just said no. I ended up receiving a silver medal, coming in 145 out of 2927 competitors. With each competition I learn a bit more and I look forward to the next one.

Written by smist08

August 16, 2019 at 5:43 pm

Low Cost Linux Notebooks

leave a comment »

Introduction

Theoretically, a notebook running Linux should be inexpensive, since you don’t need a Windows license and Linux runs well without premium hardware. In reality, buying a Linux notebook tends to be expensive on premium hardware. There are companies like Purism and System76 that produce Linux only laptops but these are high-end expensive. Similarly, companies like Dell seem to charge extra if you want Linux. In this article we’ll look at some options for running Linux inexpensively. We’ll look at the tradeoffs, including privacy and security.

Used, Refurbished or Discounted Windows Notebooks

Windows Notebooks have the advantage of mass-production and competition. There are tons of companies producing Windows notebooks. You can find great deals on sale, plus there is a huge market of refurbished lease returns that offer great deals. Also, companies take returns from retailers like Amazon, make sure they are ok and then sell them at a big discount. You then need to install your favorite Linux distribution and then you are up and running. You can even set it up so you can dual boot either Linux or Windows.

If you are concerned about privacy and security, then the downside of Windows notebooks is that they run the UEFI BIOS. This BIOS has backdoors built in so the NSA, and probably other governments, can remotely take control of your computer.

All that being said, if a notebook runs Windows well, it will run Linux better. A great way to bring an old slow laptop or notebook back to life, is to wipe Windows and replace it with Linux. I’m writing this on an old HP laptop which became slower and slower running Windows 10. Now with Ubuntu Linux, it runs great. No more Windows bitrot and it has a whole new life.

Chromebooks

Even cheaper than Windows notebooks, are Chromebooks. These are notebooks designed to run Google’s ChromeOS. These notebooks are cheaper because they don’t require a Windows license and they usually don’t include a harddrive. Instead of a harddrive they have a small memory card usually 16Gig or 32Gig. Chrome OS is based on a Linux kernel, but restricts you in a few ways. You need to sign on using a Google ID, then you install Apps (basically Android apps) via the Google Play store.

Earlier versions couldn’t run regular Linux apps; however, Google has been relaxing this and now allows you to install and run many Linux apps and run a terminal window. Over time Chrome OS has been slowly morphing into full Linux. From being just a portal to Google’s web apps to being a full client operating system. However, I find Chrome OS is still too limiting and there is the issue of having to sign on with Google.

Out of the box, you can’t just install Linux on a Chromebook. The BIOS is locked to only running Chrome OS. The BIOS in Chromebooks is based on Coreboot the open source which is good, however they modified it without providing the source code, so we don’t know if they added hooks for the NSA to spy on you. The Google BIOS does provide a developer mode, this developer mode gives you a root access terminal session and allows you to install and run flavours of Linux from inside Chrome OS using a set of shell scripts called crouton. Many people prefer this method as they get both Linux and Chrome OS at the same time.

Upgrade the BIOS

If you want to boot directly into an alternate OS, you usually need to upgrade the Chromebook’s BIOS to allow this. I bought an inexpensive refurbished Dell Chromebook 11 off Amazon for $100 (CAD). There are two ways to do this, one is reversible, the other isn’t and you run the risk of bricking your device. The Dell’s BIOS is divided into two parts, one is upgradable, and can be reversed using a recovery USB stick. The other requires disassembling the notebook, removing a BIOS write protect tab and then burning the whole BIOS.

I went the reversible route. I made a recovery USB stick and upgraded the BIOS to support booting other operating systems. This isn’t perfect as you are still using Google’s unknown BIOS and you have to hit control-L everytime you boot to run your alternate operating system.

The reason people will risk replacing their whole BIOS is to get a pure version of Coreboot that hasn’t been tampered with by Google. You then have full control of your computer, no developer mode and no control-L to boot. Perhaps one day I’ll give this a try.

Once you have your BIOS updated, you can install Linux from a USB stick. I chose to install GalliumOS, which is tailored for Chromebooks. It installs a minimal Linux, since it knows Chromebooks don’t have much disk space. It also includes all the drivers needed for typical Chromebook trackpads, bluetooth and Wifi. The Gallium OS website has great information, with links to how to upgrade your BIOS and otherwise prepare and complete a successful upgrade.

Another choice is LUbuntu (Light Ubuntu), which is Ubuntu Linux optimized for low memory hardware. I didn’t like this distro as much, probably because it is so optimized for low memory, whereas I have 4GB memory, it is disk space I’m short of (only 16GB). So I didn’t really need the low memory desktop, and would have preferred LibreOffice being left out.

A great source of info on updating Chromebook BIOS’s is MrChromebox. Its interesting because they also have lots of information on how to install UEFI BIOS on a Chromebook, so you can use it as a cheap Windows notebook. You could install UEFI and then run Linux, but why would you want to? Unless you want to be helpful to the NSA and other government spy agencies.

Impressions/Summary

Sadly, running Linux on a converted Windows notebook gives the better experience. At this point, despite the privacy concerns, the UEFI BIOS works better with Linux than Coreboot. On the Chromebook, besides the nuisance of having to hit control-L every time it boots, I found some things just didn’t work well. The main problem I had was closing and opening the lid on the notebook, that Linux’s suspend function didn’t work properly. Often when I opened the lid, Linux didn’t unsuspend and I’d have to do a hard power off- power on which then resulted in a disk corruption scan.  Otherwise bluetooth, wifi and the trackpad work fine.

I also think the small memory cards are a problem. I think you’re better off booting from a regular SSD hard drive. These are inexpensive and give you way more space with better performance. I wish there was a cheap Chromebook with an M.2 interface. Or even one where the memory card isn’t glued to the motherboard and in an accessible location.

I really want an inexpensive notebook with privacy and security. The best option right now is to convert a Chromebook over to full Coreboot and then run a privacy oriented version of Linux like PureOS, but right now this is quite a DIY project.

 

Written by smist08

August 9, 2019 at 6:46 pm

Posted in Business

Tagged with , , , , , ,

Raspberry Pi 4 First Impressions

leave a comment »

Introduction

I’ve received my Raspberry Pi 4B with 4GB or RAM a few weeks ago. I’ve been using it to write my forthcoming book on Raspberry Pi Assembly Language Programming, so I thought I’d give a few of my first impressions. The biggest change for the Raspberry Pi 4 is the support for three memory sizes, 1GB, 2GB and 4GB. This overcomes the biggest complaint against the Raspberry Pi 3, that it bogs down too quickly as you run browser tabs and multiple windows.

Some of the other hardware improvements are:

  • Dual 4K monitor support with dual micro-HDMI ports.
  • Two of the four USB ports are USB-3.
  • The ethernet is now gigabit and the WiFi is faster.
  • A 1.5GHz quad-core 64-bit ARM Cortex-A72 CPU.
  • The SDRAM is now LPDDR4.
  • The GPU is upgraded to Broadcom’s VideoCore VI.
  • Hardware HEVC video support for 4Kp60 video.

On paper, this makes the Raspberry Pi 4 appear far superior to its predecessors, In this article, I’ll discuss what is much better and a few of the drawbacks. This release will squash a lot of the compatible Pi competitors, but I’ll compare it to my NVidia Jetson Nano and mention a few places where these products still surpass the Pi.

Raspbian Buster

At the same time the Raspberry Pi Foundation released the Raspberry Pi 4, they also released the new “Buster” version of Raspbian, the Debian Linux derived operating system tailored specifically to the Raspberry Pi. On the day this was announced, I ordered my Raspberry Pi 4, then went and downloaded the new Buster release, then installed it on my Raspberry Pi 3B.

If you have a Raspberry Pi 4, then you must run the Buster release as older versions of Raspbian don’t have support for the newer hardware. If you are running an older Pi then you can keep running the older version or upgrade as you like.

Is it 64-Bits?

The first rumour that was squashed was that Raspbian would move to 64-bits. This didn’t happen. Raspbian is a 32-bit operating system. The Raspberry Pi Foundation says it will stay this way for the foreseeable future. The first reason is that the Raspberry Pi 1 and Raspberry Pi Zero use a much older ARM processor that doesn’t support 64-bits. The Raspberry Pi Foundation still supports and sells these models and they are quite popular due to their low price. They don’t want to support two operating systems, so they stick to one 32-bit version that will run on every Raspberry Pi ever made. Perhaps other hardware vendors should look at this level of support for older models.

Even though 32-bit implies a 32-bit virtual address space for processes, which limits an individual process to 4GB of memory, the ARM SoC used in the Pi has memory access hardware for 48-bit addresses. This allows the operating system to give each process a different 4GB address space, so if Raspberry Pi models with more than 4GB of memory are released, Raspbian can utilize this memory.

Another problem with going to 64-bits is that all the previous Raspberry Pi models, and one version of the Raspberry Pi 4 only have 1GB of RAM. This isn’t sufficient to run a 64-bit operating system. You can do it, but the operating system takes all the RAM, and once you run a program or two, everything bogs down. This is due to all addresses and most integers becoming 64-bits, and hence twice as large. A definite nice feature of Raspbian is that it can run effectively in only 1GB or memory.

Based on Debian Buster

Raspbian is notorious for lagging behind the mainstream releases of Linux. The benefit of this is that Raspbian has always been very stable and reliable. It works well and avoids the problems that happen at the bleeding edge. The downside is that it can contain security vulnerabilities or bugs that are fixed in the newer versions.

With Buster, Raspbian released its version ahead of Debian releasing the main version. Linus Torvalds himself was involved in moving the Pi up to a newer version of the Linux kernel. His concern is that as other hardware platforms adopt proprietary software like UEFI firmware, with government mandated backdoors, that the benefits of open source are being lost. The Raspberry Pi, including its firmware are all open source and there is a feeling in the open source community that this is the future to fight for.

Some Software Not Ported Yet

As a result of the move to Buster, some software that Raspberry users are accustomed to is missing. The most notable case is Mathematica. A port of this is underway and it is promised to be included in a future upgrade.

I had problems with CubicSDR, a Software Defined Radio (SDR) program. It could detect my SDR USB device, but didn’t run properly, just displaying a blank screen when receiving.

Heat Dissipation

The Raspberry Pi 4 uses more power than previous models. It requires a USB-C power adapter which means you can’t use a power adapter from previous models. I bought my Pi 4 from buyapi.ca and got the bundle with a case, power adapter, heat sinks and micro-HDMI cable. I needed the cables. The case is their Raspberry Pi 3 case, with the holes for the cables moved for the slightly different Pi 4 configuration. The case lacked any ventilation holes and the Pi would throttle due to overheating fairly easily. My solution was to run it with the top of the case removed. This seems to provide enough air circulation that I haven’t seen any overheating since.

Some people claim the Raspberry Pi 4 requires a fan for cooling, but that hasn’t been my experience. I think the cases need properly thought out ventilation and that is all that is needed. I think a bigger heatsink like the one included with the NVidia Jetson Nano would be warranted as well. I don’t like fans and consider the quietness of the Pi as one of its biggest features.

Cons

All this sounds great, but what are the downsides of the Raspberry Pi 4?

All New Cables

I purchased an NVidia Jetson Nano and to run it, I just unplugged the cables from my Raspberry Pi 3 and plugged them into the Jetson and away it went. Not new cables required.

The Raspberry Pi required a new USB-C power supply and a lot has been made of how you can’t use Apple laptop power supplies, but I think the real issue is you can’t use an older Pi power supply, even if it can provide sufficient power.

To support dual monitors, the Pi went to micro-HDMI ports to fit both connectors. This means you need either new cables or at least micro- to regular-HDMI adapters. The NVidia Jetson supports dual monitors but annoyingly with two different cables, HDMI and a DisplayPort cable. At least the cables are the same for the two video ports.

Otherwise all my USB devices that I was using with the Raspberry Pi 3 seem to work with the Pi 4.

SDCard Bottleneck

They have improved the data transfer speed to and from the microSD card with the Pi 4, but this is still a bottleneck. I would have loved it if they had added a M.2 SSD interface to the board. You can improve on the microSD card speed by using a USB 3 external SSD. The problem is that you can’t boot from this USB 3 drive. You can copy the root filesystem over to the drive and run mostly from the USB and although I haven’t tried it yet, people report this is an improvement.

Raspberry Pi promote the 4 as a desktop computer replacement and it definitely has the processing power. However, I don’t think this really holds up without something better than running off a microSD card. The Raspberry Pi Foundation say they will add boot from USB support in a future firmware update, but it isn’t there yet. Although the speed of USB 3 is better than the microSD interface, it still isn’t nearly as good as you can obtain with M.2 and a good new SSD.

No 64-Bits Yet

The Raspberry Pi Foundation, caught everyone by surprise with their release. This included the people that maintain alternate operating systems for the Raspberry Pi. There is a good Ubuntu Mate 64-bit version that runs on the Raspberry Pi 3. It is slow and you can’t run many programs, but it does work and you can experiment with things like ARM 64-bit Assembly programming.

The person that maintains this had to order his Raspberry Pi 4, like everyone else and hasn’t produced a Pi 4 version yet. It would have been nice if the Raspberry Pi Foundation had seeded some early models to the people that develop alternate operating systems for the Pi.

As of this writing, Raspbian is the only operating system that runs on the Raspberry Pi, but hopefully the others won’t take too long to modify what they need to.

The Raspberry Pi 4 with 4GB is the first Raspberry Pi that has the power to run a true 64-bit operating system, so it would be nice to play with.

Cost

The Raspberry Pi 4 is still dirt cheap, $35 for the 1GB model and $55 for the 4Gig model. This upgrade is a bit more expensive since you need a new power adapter, new video cables and a new case as well. I think the extra $20 for the extra memory is well worth it.

Compared to the NVidia Jetson Nano

The Raspberry Pi 4 blows most of the current crop of Pi clones out of the water. One exception is the NVidia Jetson Nano. This single board computer has 4GB of memory and runs full 64-bit Ubuntu Linux and as a consequence feels more powerful than the Pi 4.

The Pi 4 has a more powerful ARM CPU, but the Jetson has 4 USB-C ports and a 128 core CUDA GPU. The CUDA GPU is used by software like CubicSDR for DSP like processing, along with most AI toolkits like Tensorflow.

The NVidia Jetson costs $99, so is nearly twice as expensive as a Pi 4. However if you want to experiment with AI, the 128-core CUDA GPU is an excellent entry level system. 

Summary

I got used to the Raspberry Pi 4 fairly quickly and after a couple of weeks thought it was pretty similar to the Raspberry Pi 3. I then needed to do something on my Raspberry 3 and booted it up. After using the Pi 4, going back to the Pi 3, felt like I was working in molasses, everything was so slow. This is a real testament to how good the new Pi is, especially with 4GB of memory.

Yes, there are some teething problems with the new model, as there often is at the bleeding edge. But overall the Raspberry Pi 4 is a solid upgrade, and once you adopt it, you really can’t go back. 

 

Written by smist08

August 2, 2019 at 7:09 pm

LinuxFest Northwest 2019

leave a comment »

Introduction

2019 is the 50th anniversary of Unix and the 25th anniversary of Linux. Last weekend, I attended the 20th LinuxFest Northwest 2019 show in Bellingham at the Bellingham Technical Conference. A great celebration with over 1200 attendees and 84 speakers. Most of the main Linux distributions were represented along with many hardware, software and service companies associated with Linux.

I attended many great presentations and learned quite a lot. In this article, I’ll give a quick survey of what I got out of the conference. In each time slot there was typically ten talks to choose from and I chose the one that interested me the most. I tended to go to the security and overview presentations.

Computers are Broken

The first presentation I went to was “Computers are Broken (and we’re all going to die)” by Bryan Lunduke. This presentation laid out the problems with the continued increase in the complexity of all software. How this is slowing down current development, since programming teams need to be much larger and understanding what is already there is so difficult. He gave his presentation running Windows for Workgroups 3.11 and Powerpoint 4. His point was he can do everything he needs with this, but with way less RAM, disk space and processing power. Lots of arguments on how software gets into everything and how hard it is to test, it is getting quite dangerous. Just look at Boeing’s problems with the 737 Max.

50 Years of Unix

Next I went to Maddog’s presentation on “50 Years of Unix, the Internet and more”. Maddog has been around Unix the whole time and had a lot of great stories from the history of Unix, Linux and computers. He spent most of his career at DEC, but has done many other things along the way.

Freedom, Security and Privacy

Then I went to Kyle Rankin’s talk, which started with a slide on Oxford commas and why there is only one comma in the title of his presentation. The Linux community has some very paranoid people and maintaining security and privacy are major themes of the conference. One of the most hated items by the Linux community is the UEFI BIOS and how it gives corporations and governments backdoors into everyone’s computers. If you can, get a computer with a CoreBoot BIOS which is open source and lacks all these security problems. One claim is that security in Linux is better because there are so many eyes on it, but he makes the point that unless they are the right eyes, you don’t really gain anything. Getting the best security researchers to test and analyse Linux remains a challenge. Also people tend to be a bit complacent on where they get their software, even if it’s open source, they don’t build it themselves, leaving room for bad things to be inserted.

Early Technology and Ideas for the Future

Jeff Fitzmaurice gave a presentation that looked at some examples from the history of science and how various theoretical breakthroughs led to technological developments. Then there was speculation on what developments in Science happening now, will lead to future technological developments. We discussed AI, materials science, quantum computing among others.

Ubuntu 19.04+

I went to Simon Quigley’s presentation on Ubuntu. Mostly because I use Ubuntu, both on this laptop and on my NVidia Jetson Nano. This talk covered what is new in 19.04 (Disco Dingo) and how work is going towards 19.10 (note the version numbers are year.month of the release target). I’ve been running the LTS (long term support) version and I was surprised to find out they only do a LTS every two years, so when I got home, I changed my configuration to install any new released version. It was interesting on how they need to get open source contributors to commit to the five year support commitment of the LTS.

People were present that work on all the derivatives like Kubuntu and Lubuntu. Most of the work they do actually goes in the upstream Debian release, which benefits even more people.

The Fight for a Secure Linux Bios

David Spring gave this presentation on all the evils of UEFI and why we need CoreBoot so badly. He has a lot of stories on the evils done by the NSA, including causing the Deepwater Horizon disaster. When the NSA release the second version of Stuxnet to attack the Iranian nuclear program, it got away on them. The oil industry uses a lot of the same Siemens equipment and got infected. Before the disaster, Deepwater Horizons monitoring computers were all down, because of the NSA and Stuxnet. If not for the NSA, they would have detected the problem and resolved it without the disaster. For all the propaganda on Chinese and Russian hacking, the NSA employees 100 hackers for every single Chinese one. Their budget is huge.

Past, Present and Future of Blockchain

My friend Clive Boulton (from the GWT days) gave this presentation on the commercial uses of blockchain. This had nothing to do with cryptocurrencies and was on using the algorithms to secure and enable commercial transactions without third party intermediaries. The presentation covered a number of frameworks like Hyperledger and Openchain that enable blockchain for application developers.

Zero Knowledge Architecture

M4dz’s presentation showed how to limit access to application data, for instance to stop insurance companies seeing your medical records. Zero knowledge protocols find ways to tell if you have knowledge without getting that knowledge. For instance if you want to know if someone can access a room, you can watch them open the door, you don’t need to get a copy of the key. Similarly you can watch a service use a password, without giving you the password. These protocols are quite difficult, especially when you get into key recovery procedures, but ultimately if these gain traction we will all get better privacy.

Linux Gaming – the Dark Ages, Today and Beyond…

Ray Shimko’s presentation covered the state of Linux gaming from all the old console emulators to native ports of games where the source code has been released, to better packaging of all the layers required to run Windows games (right version of Wine, etc.). There are a lot of games on Linux now, but sadly the newest hot releases lag quite a while before showing up.

One interesting story is how the emulator contributors are trying to deal with games like “Duck Hunt”. Duck Hunt came with a gun, you pointed at the TV to shoot the ducks. The way this worked was that when you pressed the trigger, the game would flash the screen white. One a CRT this meant the refresh would scan down the screen in 1/60th of a second. A sensor in the gun would record when it saw white and by measuring the time difference, the software would know where the gun was pointing. The problem is that modern screens don’t work that way, so this whole aiming technique doesn’t work. Evidently a workaround is forthcoming.

Q&A

The conference ended with a Q&A session hosted by Maddog, Kyle Rankin and Simon Quigley. The audience could ask whatever they wanted and perhaps got an answer or perhaps got a story. Lots of why doesn’t Linux do X and how can I contribute to Y.

Summary

Hard to believe Linux is 25 years old all ready. This is a great show and in the spirit of free software the show is also free to attend. Lots of interesting discussion and its refreshing to see software developing where users really want, rather than what you see under various corporate agendas.

When you buy a new computer, make sure it uses Coreboot BIOS and not UEFI.

 

Written by smist08

April 30, 2019 at 7:01 pm

Posted in Life

Tagged with , , , ,