RISC-V: How to fix "file format not recognized" when disassembling a .img file? - objdump

I'm playing with RISC-V.
I have a .img file and I want to disassemble it into a .asm file, so I ran the following command:
> riscv64-unknown-elf-objdump -d xxx.img > xxx.asm
However, I got this issue:
riscv64-unknown-elf-objdump: xxx.img: file format not recognized
How can I fix it? I have no idea what to do with this issue.

If you run:
riscv64-unknown-elf-objdump --help
You'll see a line like:
riscv64-unknown-elf-objdump: supported architectures: riscv riscv:rv64 riscv:rv32
These are the supported architectures that you need to pass as the -m argument. Normally, an ELF file will encode this information so there's no guesswork, but in the case of using a flat file, there's no way for objdump to know how the instructions are supposed to be interpreted. The final command is:
riscv64-unknown-elf-objdump -b binary -m riscv:rv64 -D xxx.bin

Related

SSH opening file error - no idea why

Running Debian Linux - newest version.
cp /included/filename /usr/bin/
It gives me error "cannot stat '/included/filename': No such file or directory
I don't get why there should be an error. I am doing it as superuser.
From your latest comment i conclude you got the paths mixed up. If you want to copy the file install.sh located under /usr/bin/included/ you would need to do
cp /usr/bin/included/install.sh /usr/bin/
to make something similar to your provided command work, id assume you are in /usr/bin and the first argument needs to be a relative one
cd /usr/bin
cp ./included/install.sh /usr/bin/
Please provide more information on what you are trying to do and provide realworld example code.

How to create a PDF-out-of-Sphinx-documentation-tool

Followed this link to try and generate pdf from Sphinx:
https://www.quora.com/How-to-create-a-PDF-out-of-Sphinx-documentation-tool
$ sphinx-build -b pdf source build/pdf
Error: Cannot find source directory `/Users/seb/mydocs/source'.
$ make all-pdf
make: *** No rule to make target `all-pdf'. Stop.
$ make pdf
make: *** No rule to make target `pdf'. Stop.
Since tried in OSX:
$ conda install -c dfroger rst2pdf=0.93
Fetching package metadata .........
Solving package specifications: .
Error: Package missing in current osx-64 channels:
- rst2pdf 0.93*
You can search for packages on anaconda.org with
anaconda search -t conda rst2pdf
EDIT:
After pip install rst2pdf
install rst2pdf
register rst2pdf in your conf.py Sphinx config
extensions = ['sphinx.ext.autodoc','rst2pdf.pdfbuilder']
But adding 'rst2pdf.pdfbuilder' causes
Extension error:
Config value 'math_number_all' already present
make: *** [html] Error 1
$ sphinx-build -bpdf sourcedir outdir
But what do I specify as sourcedir and outdir? Example please.
EDIT:
Now after make html
and then:
$ rst2pdf index.rst output.pdf
index.rst:14: (ERROR/3) Unknown directive type "toctree".
.. toctree::
:maxdepth: 2
introduction
tutorial
multiple_jobs
deployment
project
index.rst:26: (ERROR/3) Unknown interpreted text role "ref".
index.rst:27: (ERROR/3) Unknown interpreted text role "ref".
index.rst:28: (ERROR/3) Unknown interpreted text role "ref".
Also:
$rst2pdf.py index.rst -o mydocument.pdf
Does produce a mydocument.pdf but completely different from html and toc to all the pages are not even there?
Image of pdf verse HTML same page
This is from the official Sphinx documentation. If you have pdfTex tool installed in your machine, all you need is:
$ make latexpdf
Then, the generated pdf file(s) will be under _build/latex/<PROJECT-NAME>.pdf
So, the complete process from scratch would be as follows:
$ pip install -U sphinx # install the package
$ sphinx-quickstart # create a new project (answer the questions)
$ make latexpdf # compile and generate pdf file
Note that you may also "optionally" install whatever extensions needed by editing the file config.py
NOTE: This answer assumes LaTeX engine is installed on your machine.
I have succeeded in generating a PDF file for the DevStack document by following the configuration changes in this link:
Here are the steps:
Edit your conf.py (edit or append values)
extensions = ['rst2pdf.pdfbuilder']
pdf_documents = [('index', u'rst2pdf', u'Sample rst2pdf doc', u'Your Name'),]
Install the "rst2pdf" if necessary
pip install rst2pdf
Build the PDF file like this:
sphinx-build -b pdf doc/source doc/build
Succeeded in Pdf Generation via Latex (for windows 10)... No need to change existing conf.py file in Sphinx... the best solution is install MiKTeX....install Perl (ActiveState).... after when running sphinx type 'make HTML' type 'make latex' and then make latexPdf... this solved my issue.
You could avoid rst2pdf and use make pdflatex to build pdf output via a latex file.
cf more info:
https://docs.typo3.org/typo3cms/extensions/sphinx/AdvancedUsersManual/RenderingPdf/
Make sure to have a look at http://rst2pdf.ralsina.me/handbook.html#sphinx.
Following applies to Ubuntu 16.
But it is probably less painful to install a full LaTex suite than to try to get this tool running; it is very sensitive to errors, and is difficult to use.
I took a look there (https://tex.stackexchange.com/a/95373) and it looks daunting...
this is more encouraging: https://milq.github.io/install-latex-ubuntu-debian/
And I did it:
sudo apt-get install texlive-full
make clean latexpdf
is worthwhile your patience (and disk space) to install. I got rid of rst2pdf.
Found this related post which discovers that rst2pdf breaks math rendering in Sphinx 1.4.1 because it imports a dummy math module.
In rst2pdf.pdfbuilder:setup(), it calls mathbase.setup() internally to install dummy math module. It causes conflicts and raise errors.
I had this same error when running sphinx-build -b pdf
Extension error:
Config value 'math_number_all' already present
Now looking at latex option, and exporting to pdf as #tfv posted. pdflatex is a larger universe of TeX distribution.
As an alternative to latexpdf: rinohtype
Once rinohtype is installed, sphinx-build -b rinoh . _build
Create a file documentation.md, and open it in Typora software. Navigate to the Sphynx documentation that you need, mark with mouse and copy inside Typora. Then inside typora export as PDF. Done.

Adding home-brew to PATH

I just installed Home-brew and now I'm trying to insert the home-brew directory at the top of my path environment variable by typing in two commands inside my terminal. My questions are these:
What is a path environment variable?
Are the two codes provided me correct?
echo "export Path=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
After this I am to type in brew doctor. Nothing is happening as far as I can see.
Can anyone offer me some advice or direction?
I installed brew in my new Mac M1 and ask me to put /opt/homebrew/bin in the path, so the right command for this case is:
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
TL;DR
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
is what you want.
To answer your first question; in order to run (execute) a program (executable) the shell must know exactly where it is in your filesystem in order to run it. The PATH environment variable is a list of directories that the shell uses to search for executables. When you use a command that is not built into the shell you are using the shell will search through these directories in order and will execute the first matching executable it finds.
For example when you type: mv foo bar the shell is almost certainly actually using an executable located in the /bin directory. Thus fully the command is
/bin/mv foo bar
The PATH environment variable therefore saves you some extra typing. You can see what is in your PATH currently (as you can with all environment variables) by entering:
echo $<NAME OF VARIABLE>
So in this instance:
echo $PATH
As I mentioned earlier, ordering is important. Adding /usr/local/bin to the beginning of PATH means that the shell will search there first and so if you have an executable foo in that folder it will be used in preference to any other foo executables you may have in the folders in your path. This means that any executables you install with brew will be used in preference to the system defaults.
On to your second question. What the command you have provided is trying to do is add a line to your .bash_profile and then source it. The .bash_profile is a text file stored in your home directory that is sourced (read) every time bash (your shell) starts. The mistake in the line you've provided is that only the first letter of PATH is capitalised. To your shell Path and PATH are very different things.
To fix it you want:
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
To explain
echo "export PATH=/usr/local/bin:$PATH"
simply prints or echoes what follows to stdout, which in the above instance is the terminal. (stdout, stderr and stdin are very important concepts on UNIX systems but rather off topic) Running this command produces the result:
export PATH=/usr/local/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
on my system because using $PATH within double quotes means bash will substitute it with its value. >> is then used to redirect stdout to the end of the ~/.bash_profile file. ~ is shorthand for your home directory. (NB be very careful as > will redirect to the file and overwrite it rather than appending.)
&& means run the next command is the previous is successful and
source ~/.bash_profile
simply carries out the actions contained in that file.
As per the latest documentation, you need to do this:
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/dhruv/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Now you should be able to run brew from anywhere.
When you type in a program somewhere and click enter, it checks certain locations to see if that program exists there.
Linux brew uses locations different from the normal linux programs, so we are adding these locations to the ~/.profile file which sets the paths.
Run this in your terminal, and it will place the correct code in the .profile file, automatically.
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
Don't use .bash_profile because when you use something different from bash, like zsh, it may not work. .profile is the correct location.

readelf error: not an elf file, wrong magic bytes at the start

I am trying to learn and use Elfreader by compiling a simple hello world program to a elf file as-
gcc -o test test.c
The file compiles correctly and runs perfect.
But when I try to run ReadElf on it by
readelf -h test
it returns
readelf: Error: Not and ELF file - it has the wrong magic bytes at the start
What do you think I am doing wrong, or is there a problem with my linker script?
Let me know if you need any additional info from me.
You can check file format type follow as :
$ objdump -t hello.exe
hello.exe: file format pei-i386
Maybe I guess your file is not elf format.

Mahout seqdirectory not making a new file

I am trying to convert a text file into a sequence file that I can run mahout kmeans on. When I run the seqdirectory utility, I do not get any errors and it says that the program is completed. However, when I look in the output directory, it is empty. I've looked around and can't find any solutions to this. Thoughts?
Here is what I run in the terminal:
hduser#ubuntu:~$ $MAHOUT_HOME/bin/mahout seqdirectory --input Downloads/google/ --output Downloads/sparsefiles/ -c UTF-8
This is the output I get:
12/07/06 06:24:19 INFO driver.MahoutDriver: Program took 1091 ms (Minutes: 0.018183333333333333)
I think it may be producing the output on hdfs. Try checking:
hadoop dfs -ls Downloads/sparsefiles/
Also, to ensure it produces in your local filesystem you can modify the command like:
$MAHOUT_HOME/bin/mahout seqdirectory --input file://<home path>/Downloads/google/ --output file://<home path>/Downloads/sparsefiles/ -c UTF-8