# NAND write error



## balanga (Feb 24, 2019)

Apologies for this not necessarily relating to FreeBSD, but hopefully someone here will be able to shed some light on a problem I'm having writing to NAND.

I'm following some instructions for installing OpenWrt on a GoFlex Home device here https://openwrt.org/toh/seagate/goflexhome

in the section

*Install u-boot and OpenWrt 18.06.1 into NAND via serial cable and tftp-server*

It seems fairly straightforward:-


```
download from tftp-server u-boot.kwb file to RAM start offset 0x6400000

tftp 0x6400000 u-boot.kwb
or

tftpboot 0x6400000 u-boot.kwb
Bytes transferred = 607044 (94344 hex) ← this number is needed for nand write

erase nand start from 0x0 size 0x100000

nand erase 0x0 0x100000
write nand from RAM start offset 0x6400000 to nand start 0x0 size 0x94344

nand write 0x6400000 0x0 0x94344
reboot device

reset
now you are rebooting in the new u-boot
```
The problem was that I got:-


```
NAS>> nand write 0x640000 0x0 0x94344

NAND write: device 0 offset 0x0, size 0x94344
nand_write_ecc: Attempt to write not page aligned data
0 bytes written: ERROR
```
Someone mentioned that

0x94344 is not an integer division of 1024 (1K). NAND block is 128K.

but have no idea what that means, maybe someone could explain...

I keep wondering if it would be possible to install FreeBSD in NAND at some point, if I can get this working....


----------



## Phishfry (Feb 24, 2019)

balanga said:


> I keep wondering if it would be possible to install FreeBSD in NAND at some point, if I can get this working....


No. The NAND is simply for Uboot. Even your previous Linux installation was on the physical disk inside the device.
Only the first stage loader is called up from NAND.

These instructions erase the NAND. What you might need to do is build a FreeBSD compatible Uboot and copy it to NAND.
Because it is NAND based uboot, the build will be different than your normal uboot build.


----------



## Phishfry (Feb 24, 2019)

balanga said:


> I keep wondering if it would be possible to install FreeBSD in NAND at some point, if I can get this working....


No. The NAND is simply for Uboot. Even your previous Linux installation was on the physical disk inside the device.
Only the bootloader is loaded from NAND.

These instructions erase the NAND. What you might need to do is build a FreeBSD compatible Uboot and copy it to NAND.


----------



## balanga (Feb 25, 2019)

It looks like I have zapped Uboot!

When connecting to the device with a usb- serial cable and running `cu -l /dev/cuaU0 -s 115200` there is no input when I switch on....

I can boot using kwboot, so it doesn't looked bricked (yet).

Just wondering how to install Uboot via kwboot....


----------



## Phishfry (Feb 26, 2019)

That was uboot from the original box or did you put Arch Linux and its uboot on it?
Have you built FreeBSD Uboot for it yet?
With uboot now supporting USB-booting maybe you could load FreeBSD-capable uboot on NAND and use a usb stick for the FreeBSD installation.
Then it would work like a regular NAS.
If my memory serves me right this device used a small chunk of the HDD to hold the original OS.
Perhaps now you could do that with USB thumbdrive instead of HDD for the OS. 
What you really need to study is size of NAND and the size of uboot today.
Will it fit? uboot may have outgrown the device. That is where I would start looking. Determine NAND size.
Theoretically you should be able to create a bootable usb thumbdrive with uboot on it for this device with your custom ARM kernel..


----------



## Phishfry (Feb 26, 2019)

Looking at the Arch page I see it has 256MB NAND.
I don't know if they had all of Linux running off that or just the kernel.
That is enough size to host an entire FreeBSD install if you slim it down considerably. Strip out compilers.
So that should make it easier. One device to hold it all.
I would consider building a NanoBSD image for it. An appliance OS for an appliance.


----------



## balanga (Feb 26, 2019)

Phishfry said:


> Looking at the Arch page I see it has 256MB NAND.
> I don't know if they had all of Linux running off that or just the kernel.
> That is enough size to host an entire FreeBSD install if you slim it down considerably. Strip out compilers.
> So that should make it easier. One device to hold it all.
> I would consider building a NanoBSD image for it. An appliance OS for an appliance.



https://openwrt.org/toh/seagate/goflexhome shows:-


```
Flash Layout
Original FlashLayout
mtd#    mtd0    mtd1    mtd2    mtd3
start    0x000000    0x100000    0x500000    0x2500000
size    0x100000    0x400000    0x2000000    0xdb00000
in MiB    1    4    32    219
name    u-boot    uImage    root    data
file system    none    ???    JFFS2    ??
```

It was my hope to embed FreeBSD on this device, but whether that is possible, I don't know since I don't understand this partitioning.


----------



## Phishfry (Feb 26, 2019)

JFFS2 - Wikipedia
					






					en.wikipedia.org


----------



## balanga (Feb 26, 2019)

Phishfry said:


> That was uboot from the original box or did you put Arch Linux and its uboot on it?


It had the original uboot on it.


> Have you built FreeBSD Uboot for it yet?


Still contemplating this. Not sure how I would install it if I managed to build it.


> With uboot now supporting USB-booting maybe you could load FreeBSD-capable uboot on NAND and use a usb stick for the FreeBSD installation.
> Then it would work like a regular NAS.





> If my memory serves me right this device used a small chunk of the HDD to hold the original OS.


The device, as it comes, has some version of Linux embedded. Alternatives have a rootfs on either USB or HDD. The one alternative I've found is to use OpenWrt which can be installed on Flash.


> Perhaps now you could do that with USB thumbdrive instead of HDD for the OS.
> What you really need to study is size of NAND and the size of uboot today.
> Will it fit? uboot may have outgrown the device. That is where I would start looking. Determine NAND size.
> Theoretically you should be able to create a bootable usb thumbdrive with uboot on it for this device with your custom ARM kernel..


I have no idea how big/small uboot can be, but from my understanding it has to be installed in mtd0 which is limited to 1MB.


----------



## balanga (Feb 26, 2019)

Phishfry said:


> JFFS2 - Wikipedia
> 
> 
> 
> ...



Does FreeBSD support JFFS2 ?


----------



## balanga (Mar 2, 2019)

Phishfry said:


> Looking at the Arch page I see it has 256MB NAND.
> I don't know if they had all of Linux running off that or just the kernel.
> That is enough size to host an entire FreeBSD install if you slim it down considerably. Strip out compilers.
> So that should make it easier. One device to hold it all.
> I would consider building a NanoBSD image for it. An appliance OS for an appliance.




I've just come across this FreeBSD wiki which looks like someone has already attempted something along those lines



			NAND - FreeBSD Wiki


----------

