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

nvs_partition_gen.py to support utf-8 (IDFGH-14701) #15441

Open
crazydiamondzgy opened this issue Feb 21, 2025 · 0 comments
Open

nvs_partition_gen.py to support utf-8 (IDFGH-14701) #15441

crazydiamondzgy opened this issue Feb 21, 2025 · 0 comments
Labels
Status: Opened Issue is new Type: Feature Request Feature request for IDF

Comments

@crazydiamondzgy
Copy link

crazydiamondzgy commented Feb 21, 2025

Is your feature request related to a problem?

in components\nvs_flash\nvs_partition_generator folder, sample_val.csv is working well
I change some string to utf-8 as following,

# Sample csv file
key,type,encoding,value
storage,namespace,,
u8_key,data,u8,255
i8_key,data,i8,-128
u16_key,data,u16,65535
u32_key,data,u32,4294967295
i32_key,data,i32,-2147483648
str_key,data,string,"中文"

then generate the nvs binary file by

python C:\home\github\esp-idf\components\nvs_flash\nvs_partition_generator\nvs_partition_gen.py generate C:\home\github\esp-idf\components\nvs_flash\nvs_partition_generator\sample_val.csv nvs.bin 0x3000

from the hex view, we can see that the size is error, actural length of "中文" is 7, but the wrong length in nvs.bin is 3, so I double checked by some simple program to read the key-value item which is failed.

btw, by the original nvs_partition_gen.py, I tried everything, eg string, binary, hex2bin, every method can wrote the utf-8, but nothing can read from the nvs library (ESP_ERR_NVS_NOT_FOUND)

Describe the solution you'd like.

after all, i reviewed the nvs_partition_gen.py file and did little modification with AI, it seems like

    def write_entry(self, key, value, encoding):
        # Encoding-specific handling
        if encoding == 'hex2bin':
            value = value.strip()
            if len(value) % 2 != 0:
                raise InputError('%s: Invalid data length. Should be multiple of 2.' % key)
            value = binascii.a2b_hex(value)
        elif encoding == 'base64':
            value = binascii.a2b_base64(value)
        elif encoding == 'string':
            if type(value) == bytes:
                value = value.decode()
            value += '\0'
            value = value.encode("utf-8")  # added line

everything is ok now.
did I need to add a PR to the resposity ?

Describe alternatives you've considered.

No response

Additional context.

No response

@crazydiamondzgy crazydiamondzgy added the Type: Feature Request Feature request for IDF label Feb 21, 2025
@github-actions github-actions bot changed the title nvs_partition_gen.py to support utf-8 nvs_partition_gen.py to support utf-8 (IDFGH-14701) Feb 21, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests

2 participants