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

Building X300 ZPU from source unable to generate COE file #760

Open
nmolinski opened this issue Jun 14, 2024 · 1 comment · May be fixed by #761
Open

Building X300 ZPU from source unable to generate COE file #760

nmolinski opened this issue Jun 14, 2024 · 1 comment · May be fixed by #761
Labels

Comments

@nmolinski
Copy link

nmolinski commented Jun 14, 2024

Issue Description

When building from source the X300 reference firmware with the ZPU (via zpugcc) the final make step runs bin_to_coe.py

While running make the python file fails to read the binary file properly since the 'rb' flag isn't specified.

#7 27.18 [ 95%] Generating x300_main.rom
#7 27.30 [100%] Generating x300_main.coe
#7 27.44 Traceback (most recent call last):
#7 27.44   File "/tmp/uhd/firmware/usrp3/utils/bin_to_coe.py", line 11, in <module>
#7 27.45     h = binascii.hexlify(open(bin_file).read()) + '0'*7
#7 27.45   File "/usr/lib/python3.10/codecs.py", line 322, in decode
#7 27.45     (result, consumed) = self._buffer_decode(data, self.errors, final)
#7 27.46 UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 2: invalid start byte
#7 27.50 make[2]: *** [x300/CMakeFiles/x300.dir/build.make:82: x300/x300_main.coe] Error 1
#7 27.50 make[1]: *** [CMakeFiles/Makefile2:170: x300/CMakeFiles/x300.dir/all] Error 2
#7 27.50 make: *** [Makefile:136: all] Error 2

Setup Details

Here is a dockerfile to run this test

docker build --no-cache --platform=linux/amd64 .

FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && apt install -y  \
  cmake                           \
  xz-utils                        \
  bsdmainutils                    \
  python3                         \
  git

WORKDIR /tmp

RUN git clone --depth 1 https://github.com/zylin/zpugcc.git                                              \
  && tar -xvJf  /tmp/zpugcc/releases/20150428/zpu-gcc-g++-multilib-linux64-20150428.tar.xz -C /usr/local \
  && export PATH="/usr/local/zpu-gcc-g++-multilib-linux64-20150428/bin:$PATH"                            \
  && git clone --depth 1 https://github.com/EttusResearch/uhd.git                                        \
  && cd /tmp/uhd/firmware/usrp3                                                                          \
  && mkdir build                                                                                         \
  && cd build                                                                                            \
  && cmake ..                                                                                            \
  && make

Note: I am running this on Apple Silicon, but the bug is irrespective of that.

Expected Behavior

the COE file generation to complete properly so my pipeline can pass. The binary file needs to be read and formatted into the COE format.

Actual Behaviour

'utf-8' codec can't decode byte
The file is being read as ascii instead of binary ('rb'), which causes failure due to non-utf-8 characters in binary file

Steps to reproduce the problem

Run the provided docker file above docker build --no-cache --platform=linux/amd64 .

Additional Information

Suggestions for fixes of firmware/usrp3/utils/bin_to_coe.py

  1. specify read binary flags to read the .bin file.
h = binascii.hexlify(open(bin_file, 'rb').read()) + b'0'*7 
  1. cast result of len(h)/8 to int (causes range error due to float specified in range)
out.write(',\n'.join([h[i*8:(i+1)*8].decode('ascii') for i in range(int(len(h)/8))]) + ';')
  1. Delete the line for variable d assignment, its not used

d = [h[i*8:(i+1)*8] for i in range(len(h)/8)]

@mbr0wn mbr0wn added the bug label Jun 17, 2024
@mbr0wn
Copy link
Contributor

mbr0wn commented Jun 17, 2024

Thanks for reporting!

@XhovaniM8 XhovaniM8 linked a pull request Jun 17, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants