mar
20
2011

Facebook “Like” button to any site

My dirty code to quickly add functionality of Facebook button to websites that I visit.

javascript:void(location.href=’http://www.facebook.com/plugins/like.php?href=’+encodeURIComponent(location.href))

To use just move the link below to your bookmarks bar.

I like

I don’t know if it’s the correct way… just opted for that because I want share some content that aren’t integrated with Facebook API.

jan
11
2011

re-generating ubi

If you need re-generate an UBIFS and don’t know the right parameters you can inspect dmesg output to filter UBI parameters.

If you need know the steps to creante an UBI/UBIFS check the official documentation or my ubifs tag on del.icio.us.

nov
19
2010

using ubi on u-boot: compiling issues

if you are adding support to ubifs on u-boot, you must add some include/configs/<CONFIG>.h

#define CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
#define CONFIG_RBTREE
#define CONFIG_LZO

to avoid errors like:

/uboot-imx/fs/ubifs/tnc.c:105: undefined reference to `rb_insert_color’
fs/ubifs/libubifs.a(orphan.o): In function `insert_dead_orphan’:
/uboot-imx/fs/ubifs/orphan.c:129: undefined reference to `rb_insert_color’
fs/ubifs/libubifs.a(recovery.o): In function `add_ino’:
/uboot-imx/fs/ubifs/recovery.c:1050: undefined reference to `rb_insert_color’
fs/ubifs/libubifs.a(recovery.o): In function `remove_ino’:
/uboot-imx/fs/ubifs/recovery.c:1088: undefined reference to `rb_erase’
fs/ubifs/libubifs.a(recovery.o): In function `ubifs_recover_size’:
/uboot-imx/fs/ubifs/recovery.c:1171: undefined reference to `rb_first’
/uboot-imx/fs/ubifs/recovery.c:1214: undefined reference to `rb_next’
/uboot-imx/fs/ubifs/recovery.c:1220: undefined reference to `rb_next’
/uboot-imx/fs/ubifs/recovery.c:1221: undefined reference to `rb_erase’
fs/ubifs/libubifs.a(replay.o): In function `insert_node’:
/uboot-imx/fs/ubifs/replay.c:373: undefined reference to `rb_insert_color’
fs/ubifs/libubifs.a(replay.o): In function `insert_dent’:
/uboot-imx/fs/ubifs/replay.c:448: undefined reference to `rb_insert_color’
fs/ubifs/libubifs.a(replay.o): In function `insert_ref_node’:
/uboot-imx/fs/ubifs/replay.c:689: undefined reference to `rb_insert_color’
fs/ubifs/libubifs.a(replay.o): In function `apply_replay_tree’:
/uboot-imx/fs/ubifs/replay.c:306: undefined reference to `rb_next’
/uboot-imx/fs/ubifs/replay.c:294: undefined reference to `rb_first’

obs.: probably you will need add MTD part support too :)

nov
08
2010

linux booting on ubifs partitions

UBIFS is relatively new on embedded systems but my guess is that they’ll become the standard on embedded market. To start, the first step is enable UBIFS support in kernel. I exaggerated on some debug options, fell free to avoid:

CONFIG_MTD_UBI=y
CONFIG_MTD_UBI_WL_THRESHOLD=4096
CONFIG_MTD_UBI_BEB_RESERVE=1
CONFIG_MTD_UBI_DEBUG=y
CONFIG_MTD_UBI_DEBUG_MSG=y
CONFIG_UBIFS_FS=y
CONFIG_UBIFS_FS_LZO=y
CONFIG_UBIFS_FS_ZLIB=y

Next I used a simple rootfs – basically busybox + mtd-utils – to create/format the partitions, suppose that you kernel divided the memory in the following parts:

# cat /proc/mtd
mtd0: 00300000 00020000 “bootloader” *
mtd1: 00500000 00020000 “nand.kernel” **
mtd2: 00100000 00020000 “nand.ramdisk”
mtd3: 06400000 00020000 “nand.system”

*,** The bootloader and nand.kernel I flashed via u-boot.

1. The first time

This is only needed when you create the partition for the first time. Steps are erasing the flash, detaching the UBI [if it was previously attached], format on UBI model, attach again, creating the volume (specifying a name) and finally mounting.

flash_eraseall /dev/mtd3

ubidetach /dev/ubi_ctrl -m 3
ubiformat /dev/mtd3 -y
ubiattach /dev/ubi_ctrl -m 3
ubimkvol /dev/ubi0 -N system -m
mount -t ubifs ubi0:system /mnt/ubi

[ copy your rootfs ]

umount /mnt/ubi

system is the name that I choose for partition, could be any.

2. Editing

Suppose that you need edit some files on your UBIFS , then you only need:

ubiattach /dev/ubi_ctrl -m 3
mount -t ubifs ubi0:system /mnt/ubi

3. Boot

In order to boot, you need add some parameters to u-boot.

setenv bootargs 'console=ttymxc0,115200 rootfstype=ubifs ubi.mtd=3 root=ubi0:system init=...'
nov
03
2010

mtd partitions: tips

there are two tips when initializing MTD partition struct:

  • use MTDPART_OFS_APPEND to define .offset
  • 1024 multiple to .size (4MB = 4194304 bytes or 4 * 1024 * 1024)

static struct mtd_partition nand_flash_partitions[] = {
{
.name = “bootloader”,
.offset = 0,
.size = 3 * 1024 * 1024},
{
.name = “nand.kernel”,
.offset = MTDPART_OFS_APPEND,
.size = 5 * 1024 * 1024},
{
.name = “nand.rootfs”,
.offset = MTDPART_OFS_APPEND,
.size = 256 * 1024 * 1024},
{
.name = “nand.userfs1″,
.offset = MTDPART_OFS_APPEND,
.size = 256 * 1024 * 1024},
{
.name = “nand.userfs2″,
.offset = MTDPART_OFS_APPEND,
.size = MTDPART_SIZ_FULL},
};

<strong>static</strong> <strong>struct</strong> <span style=”color: #2040a0;”>mtd_partition</span> <span style=”color: #2040a0;”>nand_flash_partitions</span><span style=”color: #4444ff;”>[</span><span style="color: #4444ff;">]</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #4444ff;”><strong>{</strong></span>
<span style=”color: #4444ff;”><strong>{</strong></span>
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>&amp;nbname</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #008000;”>”bootloader”</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>offset</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #ff0000;”>0</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>size</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #ff0000;”>3</span> <span style=”color: #4444ff;”>*</span> <span style=”color: #ff0000;”>1024</span> <span style=”color: #4444ff;”>*</span> <span style=”color: #ff0000;”>1024</span><span style=”color: #4444ff;”><strong>}</strong></span>,
<span style=”color: #4444ff;”><strong>{</strong></span>
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>name</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #008000;”>”nand.kernel”</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>offset</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #2040a0;”>MTDPART_OFS_APPEND</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>size</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #ff0000;”>5</span> <span style=”color: #4444ff;”>*</span> <span style=”color: #ff0000;”>1024</span> <span style=”color: #4444ff;”>*</span> <span style=”color: #ff0000;”>1024</span><span style=”color: #4444ff;”><strong>}</strong></span>,
<span style=”color: #4444ff;”><strong>{</strong></span>
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>name</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #008000;”>”nand.rootfs”</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>offset</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #2040a0;”>MTDPART_OFS_APPEND</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>size</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #ff0000;”>256</span> <span style=”color: #4444ff;”>*</span> <span style=”color: #ff0000;”>1024</span> <span style=”color: #4444ff;”>*</span> <span style=”color: #ff0000;”>1024</span><span style=”color: #4444ff;”><strong>}</strong></span>,
<span style=”color: #4444ff;”><strong>{</strong></span>
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>name</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #008000;”>”nand.userfs1″</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>offset</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #2040a0;”>MTDPART_OFS_APPEND</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>size</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #ff0000;”>256</span> <span style=”color: #4444ff;”>*</span> <span style=”color: #ff0000;”>1024</span> <span style=”color: #4444ff;”>*</span> <span style=”color: #ff0000;”>1024</span><span style=”color: #4444ff;”><strong>}</strong></span>,
<span style=”color: #4444ff;”><strong>{</strong></span>
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>name</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #008000;”>”nand.userfs2″</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>offset</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #2040a0;”>MTDPART_OFS_APPEND</span>,
&nbsp;&nbsp;&nbsp;&nbsp;.<span style=”color: #2040a0;”>size</span> <span style=”color: #4444ff;”>=</span> <span style=”color: #2040a0;”>MTDPART_SIZ_FULL</span><span style=”color: #4444ff;”><strong>}</strong></span>,
<span style=”color: #4444ff;”><strong>}</strong></span><span style=”color: #4444ff;”>;</span>
out
26
2010

using ubi on u-boot: part one

UBI stands for Unsorted Block Images. The shortest description for UBI is “LVM for NAND flash memory devices” and if you don’t know yet how it’s works I recommend check this presentation. I intend here describe my use with u-boot, starting with the steps to flash an kernel image. First of all, if you not defined MTDPARTS_DEFAULT on you u-boot config file, you must define (or redefine) on u-boot terminal.

> setenv mtdparts mtdparts=nand0:0x80000@0x0(uboot),0x400000@0x80000(kernel),-@0x480000(root)

If you type mtd you I’ll see:

device nand0 <nand0>, # parts = 3
 #: name        size        offset        mask_flags
 0: uboot     0x00080000    0x00000000    0
 1: kernel    0x00400000    0x00080000    0
 2: root      0x1fb80000    0x00480000    0

UBI deal with volume and not partitions. Let’s create one.

> ubi part kernel

If you got some -22 error, like:

UBI error: ubi_read_volume_table: the layout volume was not found
UBI error: ubi_init: cannot attach mtd1
UBI error: ubi_init: UBI error: cannot initialize UBI, error -22
UBI init error -22

you need erase the NAND region [ nand erase 0x00080000 0x400000 ] and ubi part command again.

Next step is create the volume:

> ubi create kernel_vol
Creating dynamic volume kernel_vol of size 3354624

The value in bold is the max size of that volume in bytes (~3MB). Note that is less than the 4MB (0×400000) defined in mtdparts. This happens because UBI works with logical blocks instead (LEB) of physical ones (PEB).

In order to write the kernel you need transfer the image to u-boot. Since Ethernet  isn’t working in my board I choose between serial or mmc.  As serial is too slow to large files I opted to write the image on FAT partition on SD card and load through:

> mmcinfo
> fatload mmc 0 ${loadaddr} uImage

The output will be something like

reading uImage
2845120 bytes read

Finally write it:

> ubi write ${loadaddr} kernel_vol 0x2b69c0

You can check if everything went fine comparing

> ubi read 0x90AC0000 kernel_vol
> cmp.b ${loadaddr} 0x90ac0000  0x2b69c0
Total of 2845120 bytes were the same

0×90AC0000 is some place on RAM different from ${loadaddr} (check using echo ${loadaddr}).

out
19
2010

tablets

Today I was curious about one tablet commercialized at Walgreens. Probably if you are looking for a really cheap tablet running Android you’ll check DealExtreme, FocalPrice, etc (see this, this and also this)  but when the largest drugstore chain in the EUA starts selling low cost tablets you just confirm the thesis that China is flooding world’s market with prices that make a lot of people re-think values. Even with low-quality China brands are gain market share. The uninitiated user don’t have the distinction about technical differences and mostly are taken by the price. If you search for Walgreen’s tablet specs you can note that instead following the trends in usability opting for a capacitive touchscreen they used a resistive one. The processor is a Via VM8505+ based on ARM9 core, this chip comes without multimidia capabilities like Texas Instruments OMAP355x or Freescales IMx51 series. Poor processing means that applications will not run smoothly and 256MB of RAM restricts the number of apps running simultaneously. If you are interested about Via processor check this link. Keep in mind that today everything is software, in Android case choose the most recent version is always recommended but the company is commited with updates? Is it Market available?

I’m not in favor of disposable objects, even for not short-term durability like mostly gadgets today.  Indeed every two or three years the technologies change forcing us to adapt. If you bought low quality designs you are accelerating this process not to mention that the true usability goes away. Watch your needs before buy, not always the most hardware capable is the best option, but poors designs always affect in some way…

out
16
2010

spliting files with dd

It’s just in case that you don’t have* want use split… (that is much easy). Suppose that you have a 20MB ogv movie and you want split in four parts of 5MB. You can just do:

dd if=MOVIE.ogv of=pt1 bs=1M count=5
dd if=MOVIE.ogv of=pt2 bs=1M skip=5 count=5
dd if=MOVIE.ogv of=pt3 bs=1M skip=10 count=5
dd if=MOVIE.ogv of=pt4 bs=1M skip=15

To merge again…

cp pt1 final.ogv # you can ommit this temporary file by using pt1 as final file
dd if=pt2 of=final.ogv bs=1M seek=5 count=5
dd if=pt3 of=final.ogv bs=1M seek=10 count=5
dd if=pt4 of=final.ogv bs=1M seek=15

After you can verify the integrity by using some hash generator, md5sum or sha1sum are examples.

$ md5sum final.ogv MOVIE.ogv
71ac8962779dcb733599dba1ce54d783  final.ogv
71ac8962779dcb733599dba1ce54d783  MOVIE.ogv

* this will never happen since both dd and split are on coreutils package.

Code

I wrote a simple proof-of-concept to demonstrate, just:

$ git clone git://gist.github.com/630395.git split-sh