Mounting Linux ext partitions on OS X

I wanted to check some files on an SD Card formatted in ext that I had used on my Pi and wanted to check if I had left some files in the home dir before I reimaged it. OS X doesn’t support ext formatted drives by default, but you add support using OSXFuse.

  • Install Fuse for OS X
  • Install the ext plugin for Fuse
  • Find the partition you want to mount with: diskutil list
  • Make a mount point – not sure on Mac OS X where is the best place, but I added /mnt/sdcard
  • Mount with:


    [code]sudo fuse-ext2 /dev/disk1s2 /mnt/sdcard[/code]

  • (replace with the /dev/ to your device)

I’m not sure if it’s best practice on the Mac to mount with sudo, but this worked for me for what I needed to do. Fuse mounts on ext are r/o by default, but there is experimental r/w support that can be enabled, check the docs.

Done!

Calling C printf from ARM ASM

A while back I started to learn some ARM assembly on the Raspberry Pi. In my previous snippets, I was using SWI to do a system call to write to stdout, but it appears syscall 4 to write to stdout only writes Strings – if you have a byte value, this approach doesn’t work (without converting to a String first?)

From this question here, it appears you can call C functions like printf, which seems like cheating a bit, but I guess it gets the job done.

Here’s a quick snippet to add two numbers, and then print the result using printf with a string containing %d to substitute the result into the String:

[code]
.global main
.extern printf
main:
push {ip, lr}
mov r3, #1 /* move 1 to r3 */
mov r4, #2 /* move 2 to r4 */
add r4, r3, r4 /* r4 = r3 + r4 */
_ouput:
ldr r0,=output /* load address of output string */
mov r1, r4 /* move r4 result to r1 to include as param in string */
bl printf /* call printf */
_exit:
MOV R1, #0
MOV R7, #1
SWI 0
.data
output:
.asciz "Result: %d\n"
[/code]

Where previously I was compiling and linking in two steps with as and ld, it seems this doesn’t work if you are referencing C functions too, so for this example, compile with: ‘gcc add.s -o add’

This snippet and a few others I’ve started to collect I’ve shared in a github repo here: https://github.com/kevinhooke/learning-arm-asm

Writing Raspberry Pi disk images to SD cards on the Mac

Just as the dd command can be used to create a disk image of an SD card on the Mac (see here), you can use dd to write a downloaded (or backup) disk image to an SD card too:

sudo dd of=/dev/rdiskx if=/path/to/image bs=1m

where x is the disk number as shown by diskutils list.

How can you backup your SD cards for your Raspberry Pi?

Given that SD cards have a limited lifetime for writes, using an SD card for a harddrive for Pi may not be the smartest idea in terms of reliability or longevity, so asking how you back up your SD card is a good question. There’s some good answers here.

Specifically on the Mac, find out the disk number of the attached sd card with :

diskutil list

then use the dd command:

dd if=/dev/rdiskx of=/path/to/image bs=1m

where x is the disk number listed from diskutil.