Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is spare address? #204

Open
daniilfigasystems opened this issue Dec 22, 2024 · 20 comments
Open

What is spare address? #204

daniilfigasystems opened this issue Dec 22, 2024 · 20 comments
Labels
question Further information is requested

Comments

@daniilfigasystems
Copy link

I can't understand what is spare address and what is used for?

@devos50
Copy link
Owner

devos50 commented Dec 22, 2024

As far as I understand, each page has a main content and a spare area, which is a small area that is used to store some metadata regarding the block.

ChatGPT says the following about it: https://chatgpt.com/share/6767ee29-cb0c-8011-be7a-819375138b6e.

Does this answer your question? 😀

@devos50 devos50 added the question Further information is requested label Dec 22, 2024
@daniilfigasystems
Copy link
Author

daniilfigasystems commented Dec 22, 2024

As far as I understand, each page has a main content and a spare area, which is a small area that is used to store some metadata regarding the block.

ChatGPT says the following about it: https://chatgpt.com/share/6767ee29-cb0c-8011-be7a-819375138b6e.

Does this answer your question? 😀

Thanks! What about main address. When i change fread to fwrite (and add cpu_physical_memory_read(addr_out, , &s->addr_buff, sizeof(uint8_t)) (variables isn't correct as i typed without looking actual code)) it's drops into recovery console due to corrupt FS.

@devos50
Copy link
Owner

devos50 commented Dec 22, 2024

When i change fread to fwrite (and add cpu_physical_memory_read(addr_out, , &s->addr_buff, sizeof(uint8_t)) (variables isn't correct as i typed without looking actual code)) it's drops into recovery console due to corrupt FS.

Unfortunately, supporting NAND writes is not as simple as changing fread to fwrite. The issue here is that a page write triggers a rebalance, which is handled by the VFL and/or FTL. So far, I haven't been able to figure out how to do this correctly without a system crash.

@daniilfigasystems
Copy link
Author

When i change fread to fwrite (and add cpu_physical_memory_read(addr_out, , &s->addr_buff, sizeof(uint8_t)) (variables isn't correct as i typed without looking actual code)) it's drops into recovery console due to corrupt FS.

Unfortunately, supporting NAND writes is not as simple as changing fread to fwrite. The issue here is that a page write triggers a rebalance, which is handled by the VFL and/or FTL. So far, I haven't been able to figure out how to do this correctly without a system crash.

What is VFL and FTL?

@devos50
Copy link
Owner

devos50 commented Dec 22, 2024

VFL (Virtual Flash Layer) and FTL (Flash Translation Layer) are abstraction layers in the NAND management stack and are responsible for several tasks, including Bad Block Management and Wear Leveling. See for example this presentation, slide 31.

@daniilfigasystems
Copy link
Author

So we need to implement VFL and/or FTL for NAND writes?
P.S: i don't know what exactly happened but after i opened presentation second time i got access denied.

@devos50
Copy link
Owner

devos50 commented Dec 22, 2024

Well, some VFL/FTL stuff probably needs to happen. I remember that this was quite a challenge, even for to get reads up and running. I should probably write a blog post about this stuff...

@daniilfigasystems
Copy link
Author

So as i understand, VFL/TFL doing stuff like UART RTS/CTS which controls when to stop.

@daniilfigasystems
Copy link
Author

We have nand flash located in qemu emulator so we can use it as a reference

@daniilfigasystems
Copy link
Author

daniilfigasystems commented Dec 23, 2024

I CAN'T BELIEVE I DID IT! NAND WRITE WORKS A HALF. Now i am implementing spare store (metadata)
Now it's saves and works but after reboot, i got recovery because of missing spare (fixing right now)

@daniilfigasystems
Copy link
Author

As i understand, spare address located at end of page?

@daniilfigasystems
Copy link
Author

daniilfigasystems commented Dec 23, 2024

I think we can copy some code from qemu-ios_generate_nand and write metadata at write function

@devos50
Copy link
Owner

devos50 commented Dec 23, 2024

I CAN'T BELIEVE I DID IT! NAND WRITE WORKS A HALF. Now i am implementing spare store (metadata)
Now it's saves and works but after reboot, i got recovery because of missing spare (fixing right now)

That's awesome!

And yes, I believe spare addresses are usually at the end of the page. But to beware, I don't remember much about these specifics. It was also a lot of trial and error when I worked on that part 😁

@daniilfigasystems
Copy link
Author

Question. Does metadata change on write and does metadata creates at all pages?

@devos50
Copy link
Owner

devos50 commented Dec 23, 2024

I don't really know unfortunately, sorry.

@daniilfigasystems
Copy link
Author

daniilfigasystems commented Dec 24, 2024

I don't really know unfortunately, sorry.

I have reviewed your generate nand code. Why some pages have TFL metadata and some have VFL metadata (or any other metadata) why not on all? (in short, why pages like 0 or/and 1 have metadata different from page ex 104?)

@devos50
Copy link
Owner

devos50 commented Dec 24, 2024

@daniilfigasystems because they are abstraction layers. At the lowest level is VFL IIRC, so some pages only have VFL data. Then there are some designated pages for FTL management as well.

@daniilfigasystems
Copy link
Author

@daniilfigasystems because they are abstraction layers. At the lowest level is VFL IIRC, so some pages only have VFL data. Then there are some designated pages for FTL management as well.

Which pages have VFL and which FTL? (ex from 1 to 10)

@devos50
Copy link
Owner

devos50 commented Dec 24, 2024

Now that is a detail I unfortunately don't have from the top of my head. I reverse most of the logic based on the Samsung NAND drivers that were in the leaked iBoot source code so that would provide further hints about where VFL and FTL pages are expected to be. You can probably find this source code on the internet 😁

@daniilfigasystems
Copy link
Author

Now that is a detail I unfortunately don't have from the top of my head. I reverse most of the logic based on the Samsung NAND drivers that were in the leaked iBoot source code so that would provide further hints about where VFL and FTL pages are expected to be. You can probably find this source code on the internet 😁

Unfortunately almost all sites/repo containing iBoot was taken down due to DCMA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants